aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acpi/Kconfig2
-rw-r--r--drivers/acpi/acpi_pad.c41
-rw-r--r--drivers/acpi/acpica/aclocal.h1
-rw-r--r--drivers/acpi/acpica/exutils.c2
-rw-r--r--drivers/acpi/acpica/rsutils.c2
-rw-r--r--drivers/acpi/apei/Kconfig2
-rw-r--r--drivers/acpi/apei/apei-base.c21
-rw-r--r--drivers/acpi/apei/einj.c4
-rw-r--r--drivers/acpi/apei/erst-dbg.c18
-rw-r--r--drivers/acpi/apei/erst.c29
-rw-r--r--drivers/acpi/apei/ghes.c2
-rw-r--r--drivers/acpi/apei/hest.c11
-rw-r--r--drivers/acpi/atomicio.c2
-rw-r--r--drivers/acpi/battery.c1
-rw-r--r--drivers/acpi/blacklist.c35
-rw-r--r--drivers/acpi/bus.c18
-rw-r--r--drivers/acpi/fan.c2
-rw-r--r--drivers/acpi/processor_core.c7
-rw-r--r--drivers/acpi/processor_driver.c2
-rw-r--r--drivers/acpi/processor_perflib.c4
-rw-r--r--drivers/acpi/sleep.c22
-rw-r--r--drivers/acpi/sysfs.c20
-rw-r--r--drivers/acpi/video_detect.c4
-rw-r--r--drivers/amba/bus.c2
-rw-r--r--drivers/ata/Makefile2
-rw-r--r--drivers/ata/ahci.c7
-rw-r--r--drivers/ata/ahci.h16
-rw-r--r--drivers/ata/ahci_platform.c9
-rw-r--r--drivers/ata/ata_generic.c54
-rw-r--r--drivers/ata/ata_piix.c34
-rw-r--r--drivers/ata/libahci.c210
-rw-r--r--drivers/ata/libata-core.c389
-rw-r--r--drivers/ata/libata-eh.c254
-rw-r--r--drivers/ata/libata-pmp.c66
-rw-r--r--drivers/ata/libata-scsi.c204
-rw-r--r--drivers/ata/libata-sff.c14
-rw-r--r--drivers/ata/libata-transport.c774
-rw-r--r--drivers/ata/libata-transport.h18
-rw-r--r--drivers/ata/libata.h21
-rw-r--r--drivers/ata/pata_bf54x.c6
-rw-r--r--drivers/ata/pata_cmd640.c12
-rw-r--r--drivers/ata/pata_pcmcia.c104
-rw-r--r--drivers/ata/pata_pdc202xx_old.c23
-rw-r--r--drivers/ata/pata_samsung_cf.c2
-rw-r--r--drivers/ata/pata_scc.c4
-rw-r--r--drivers/ata/pata_sil680.c16
-rw-r--r--drivers/ata/pata_sl82c105.c11
-rw-r--r--drivers/ata/sata_fsl.c27
-rw-r--r--drivers/ata/sata_inic162x.c2
-rw-r--r--drivers/ata/sata_mv.c25
-rw-r--r--drivers/ata/sata_nv.c57
-rw-r--r--drivers/ata/sata_sil24.c14
-rw-r--r--drivers/ata/sata_via.c2
-rw-r--r--drivers/atm/iphase.c6
-rw-r--r--drivers/atm/iphase.h2
-rw-r--r--drivers/atm/solos-pci.c8
-rw-r--r--drivers/base/power/Makefile1
-rw-r--r--drivers/base/power/generic_ops.c4
-rw-r--r--drivers/base/power/main.c21
-rw-r--r--drivers/base/power/opp.c628
-rw-r--r--drivers/base/power/power.h2
-rw-r--r--drivers/base/power/runtime.c944
-rw-r--r--drivers/base/power/sysfs.c217
-rw-r--r--drivers/base/power/trace.c36
-rw-r--r--drivers/base/power/wakeup.c613
-rw-r--r--drivers/base/topology.c16
-rw-r--r--drivers/block/DAC960.c11
-rw-r--r--drivers/block/Kconfig17
-rw-r--r--drivers/block/Makefile1
-rw-r--r--drivers/block/amiflop.c19
-rw-r--r--drivers/block/aoe/aoeblk.c9
-rw-r--r--drivers/block/aoe/aoechr.c9
-rw-r--r--drivers/block/ataflop.c15
-rw-r--r--drivers/block/brd.c7
-rw-r--r--drivers/block/cciss.c16
-rw-r--r--drivers/block/cpqarray.c15
-rw-r--r--drivers/block/drbd/drbd_main.c11
-rw-r--r--drivers/block/floppy.c16
-rw-r--r--drivers/block/loop.c11
-rw-r--r--drivers/block/nbd.c7
-rw-r--r--drivers/block/paride/pcd.c15
-rw-r--r--drivers/block/paride/pd.c15
-rw-r--r--drivers/block/paride/pf.c17
-rw-r--r--drivers/block/paride/pg.c7
-rw-r--r--drivers/block/paride/pt.c19
-rw-r--r--drivers/block/pktcdvd.c18
-rw-r--r--drivers/block/ps3disk.c2
-rw-r--r--drivers/block/rbd.c1841
-rw-r--r--drivers/block/rbd_types.h73
-rw-r--r--drivers/block/swim.c15
-rw-r--r--drivers/block/swim3.c15
-rw-r--r--drivers/block/ub.c15
-rw-r--r--drivers/block/viodasd.c11
-rw-r--r--drivers/block/virtio_blk.c23
-rw-r--r--drivers/block/xd.c7
-rw-r--r--drivers/block/xen-blkfront.c11
-rw-r--r--drivers/block/xsysace.c11
-rw-r--r--drivers/block/z2ram.c15
-rw-r--r--drivers/bluetooth/bluecard_cs.c12
-rw-r--r--drivers/bluetooth/bt3c_cs.c64
-rw-r--r--drivers/bluetooth/btuart_cs.c62
-rw-r--r--drivers/bluetooth/dtl1_cs.c27
-rw-r--r--drivers/bluetooth/hci_ldisc.c7
-rw-r--r--drivers/cdrom/gdrom.c15
-rw-r--r--drivers/cdrom/viocd.c15
-rw-r--r--drivers/char/agp/Kconfig2
-rw-r--r--drivers/char/agp/amd64-agp.c39
-rw-r--r--drivers/char/agp/generic.c4
-rw-r--r--drivers/char/agp/intel-agp.c2
-rw-r--r--drivers/char/agp/intel-agp.h2
-rw-r--r--drivers/char/apm-emulation.c11
-rw-r--r--drivers/char/applicom.c9
-rw-r--r--drivers/char/ds1302.c15
-rw-r--r--drivers/char/ds1620.c8
-rw-r--r--drivers/char/dsp56k.c27
-rw-r--r--drivers/char/dtlk.c8
-rw-r--r--drivers/char/generic_nvram.c7
-rw-r--r--drivers/char/genrtc.c13
-rw-r--r--drivers/char/hpet.c98
-rw-r--r--drivers/char/i8k.c7
-rw-r--r--drivers/char/ip2/ip2main.c8
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c14
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c17
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c8
-rw-r--r--drivers/char/lp.c15
-rw-r--r--drivers/char/mbcs.c8
-rw-r--r--drivers/char/mem.c3
-rw-r--r--drivers/char/mmtimer.c7
-rw-r--r--drivers/char/mwave/mwavedd.c44
-rw-r--r--drivers/char/nvram.c11
-rw-r--r--drivers/char/nwflash.c12
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c41
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c46
-rw-r--r--drivers/char/pcmcia/ipwireless/main.c117
-rw-r--r--drivers/char/pcmcia/ipwireless/main.h5
-rw-r--r--drivers/char/pcmcia/ipwireless/tty.h1
-rw-r--r--drivers/char/pcmcia/synclink_cs.c46
-rw-r--r--drivers/char/ppdev.c8
-rw-r--r--drivers/char/raw.c243
-rw-r--r--drivers/char/rio/rio_linux.c7
-rw-r--r--drivers/char/snsc.c9
-rw-r--r--drivers/char/tlclk.c6
-rw-r--r--drivers/char/toshiba.c9
-rw-r--r--drivers/char/tpm/tpm.c22
-rw-r--r--drivers/char/viotape.c11
-rw-r--r--drivers/char/virtio_console.c263
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c6
-rw-r--r--drivers/cpuidle/governors/menu.c2
-rw-r--r--drivers/dca/dca-core.c85
-rw-r--r--drivers/dma/ioat/dma_v2.c2
-rw-r--r--drivers/dma/mv_xor.c2
-rw-r--r--drivers/dma/shdma.c3
-rw-r--r--drivers/edac/Kconfig16
-rw-r--r--drivers/edac/Makefile3
-rw-r--r--drivers/edac/amd64_edac.c17
-rw-r--r--drivers/edac/amd64_edac.h5
-rw-r--r--drivers/edac/amd64_edac_dbg.c207
-rw-r--r--drivers/edac/edac_device_sysfs.c16
-rw-r--r--drivers/edac/edac_mc.c3
-rw-r--r--drivers/edac/edac_mc_sysfs.c11
-rw-r--r--drivers/edac/edac_mce_amd.c452
-rw-r--r--drivers/edac/edac_module.c79
-rw-r--r--drivers/edac/edac_module.h1
-rw-r--r--drivers/edac/edac_pci_sysfs.c10
-rw-r--r--drivers/edac/edac_stub.c51
-rw-r--r--drivers/edac/i7core_edac.c1
-rw-r--r--drivers/edac/mce_amd.c680
-rw-r--r--drivers/edac/mce_amd.h (renamed from drivers/edac/edac_mce_amd.h)59
-rw-r--r--drivers/edac/mce_amd_inj.c171
-rw-r--r--drivers/firewire/ohci.c20
-rw-r--r--drivers/firewire/ohci.h8
-rw-r--r--drivers/firmware/Kconfig2
-rw-r--r--drivers/gpio/tc35892-gpio.c8
-rw-r--r--drivers/gpu/drm/Kconfig5
-rw-r--r--drivers/gpu/drm/drm_buffer.c6
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c10
-rw-r--r--drivers/gpu/drm/drm_gem.c39
-rw-r--r--drivers/gpu/drm/drm_info.c2
-rw-r--r--drivers/gpu/drm/drm_pci.c4
-rw-r--r--drivers/gpu/drm/drm_platform.c5
-rw-r--r--drivers/gpu/drm/drm_sysfs.c2
-rw-r--r--drivers/gpu/drm/drm_vm.c28
-rw-r--r--drivers/gpu/drm/i810/i810_dma.c2
-rw-r--r--drivers/gpu/drm/i830/i830_dma.c2
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c9
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c1
-rw-r--r--drivers/gpu/drm/i915/i915_gem.c89
-rw-r--r--drivers/gpu/drm/i915/i915_gem_evict.c44
-rw-r--r--drivers/gpu/drm/i915/i915_suspend.c36
-rw-r--r--drivers/gpu/drm/i915/intel_crt.c10
-rw-r--r--drivers/gpu/drm/i915/intel_display.c70
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c21
-rw-r--r--drivers/gpu/drm/i915/intel_drv.h1
-rw-r--r--drivers/gpu/drm/i915/intel_dvo.c3
-rw-r--r--drivers/gpu/drm/i915/intel_fb.c4
-rw-r--r--drivers/gpu/drm/i915/intel_hdmi.c2
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c7
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c20
-rw-r--r--drivers/gpu/drm/i915/intel_tv.c11
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_connector.c12
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_gem.c6
-rw-r--r--drivers/gpu/drm/radeon/atombios.h2
-rw-r--r--drivers/gpu/drm/radeon/atombios_crtc.c5
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c32
-rw-r--r--drivers/gpu/drm/radeon/r100.c27
-rw-r--r--drivers/gpu/drm/radeon/r600.c9
-rw-r--r--drivers/gpu/drm/radeon/r600_blit_kms.c27
-rw-r--r--drivers/gpu/drm/radeon/r600_blit_shaders.h24
-rw-r--r--drivers/gpu/drm/radeon/r600_cs.c5
-rw-r--r--drivers/gpu/drm/radeon/radeon.h1
-rw-r--r--drivers/gpu/drm/radeon/radeon_atombios.c27
-rw-r--r--drivers/gpu/drm/radeon/radeon_combios.c73
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c15
-rw-r--r--drivers/gpu/drm/radeon/radeon_cursor.c28
-rw-r--r--drivers/gpu/drm/radeon/radeon_display.c14
-rw-r--r--drivers/gpu/drm/radeon/radeon_fb.c13
-rw-r--r--drivers/gpu/drm/radeon/radeon_gem.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c4
-rw-r--r--drivers/gpu/drm/radeon/radeon_mode.h3
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.h5
-rw-r--r--drivers/gpu/drm/radeon/rs600.c1
-rw-r--r--drivers/gpu/drm/radeon/rs690.c1
-rw-r--r--drivers/gpu/drm/radeon/rv770.c2
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo.c83
-rw-r--r--drivers/gpu/drm/ttm/ttm_bo_util.c1
-rw-r--r--drivers/gpu/drm/ttm/ttm_page_alloc.c8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c145
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h8
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c5
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c3
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_kms.c17
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c34
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_resource.c4
-rw-r--r--drivers/gpu/vga/vgaarb.c2
-rw-r--r--drivers/hid/hid-cando.c2
-rw-r--r--drivers/hid/hid-core.c5
-rw-r--r--drivers/hid/hid-ids.h6
-rw-r--r--drivers/hid/hid-mosart.c1
-rw-r--r--drivers/hid/hid-topseed.c1
-rw-r--r--drivers/hid/hidraw.c11
-rw-r--r--drivers/hid/usbhid/hid-core.c8
-rw-r--r--drivers/hid/usbhid/hid-quirks.c5
-rw-r--r--drivers/hid/usbhid/hiddev.c2
-rw-r--r--drivers/hid/usbhid/usbhid.h1
-rw-r--r--drivers/hwmon/Kconfig2
-rw-r--r--drivers/hwmon/adm1031.c43
-rw-r--r--drivers/hwmon/coretemp.c57
-rw-r--r--drivers/hwmon/emc1403.c1
-rw-r--r--drivers/hwmon/f71882fg.c32
-rw-r--r--drivers/hwmon/f75375s.c6
-rw-r--r--drivers/hwmon/fschmd.c6
-rw-r--r--drivers/hwmon/lis3lv02d.c4
-rw-r--r--drivers/hwmon/lis3lv02d_i2c.c4
-rw-r--r--drivers/hwmon/lis3lv02d_spi.c4
-rw-r--r--drivers/hwmon/lm95241.c21
-rw-r--r--drivers/hwmon/pkgtemp.c23
-rw-r--r--drivers/hwmon/w83627ehf.c1
-rw-r--r--drivers/hwmon/w83793.c6
-rw-r--r--drivers/i2c/busses/i2c-cpm.c5
-rw-r--r--drivers/i2c/busses/i2c-davinci.c24
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c3
-rw-r--r--drivers/i2c/busses/i2c-imx.c12
-rw-r--r--drivers/i2c/busses/i2c-mpc.c1
-rw-r--r--drivers/i2c/busses/i2c-octeon.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c2
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c12
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c11
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c4
-rw-r--r--drivers/i2c/i2c-core.c54
-rw-r--r--drivers/ide/ide-cd.c14
-rw-r--r--drivers/ide/ide-cs.c156
-rw-r--r--drivers/ide/ide-disk_ioctl.c7
-rw-r--r--drivers/ide/ide-floppy_ioctl.c7
-rw-r--r--drivers/ide/ide-gd.c10
-rw-r--r--drivers/ide/ide-probe.c12
-rw-r--r--drivers/ide/ide-tape.c19
-rw-r--r--[-rwxr-xr-x]drivers/idle/intel_idle.c39
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.c6
-rw-r--r--drivers/input/evdev.c10
-rw-r--r--drivers/input/joydev.c3
-rw-r--r--drivers/input/keyboard/Kconfig2
-rw-r--r--drivers/input/keyboard/pxa27x_keypad.c12
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c11
-rw-r--r--drivers/input/misc/uinput.c7
-rw-r--r--drivers/input/serio/hil_mlc.c6
-rw-r--r--drivers/input/serio/hp_sdc.c4
-rw-r--r--drivers/input/tablet/wacom_sys.c23
-rw-r--r--drivers/input/tablet/wacom_wac.c4
-rw-r--r--drivers/isdn/act2000/act2000.h6
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c83
-rw-r--r--drivers/isdn/hisax/avma1_cs.c97
-rw-r--r--drivers/isdn/hisax/config.c18
-rw-r--r--drivers/isdn/hisax/elsa_cs.c100
-rw-r--r--drivers/isdn/hisax/hisax.h1
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c168
-rw-r--r--drivers/isdn/hisax/teles_cs.c98
-rw-r--r--drivers/isdn/sc/interrupt.c18
-rw-r--r--drivers/leds/Kconfig11
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/leds-netxbig.c449
-rw-r--r--drivers/leds/leds-ns2.c18
-rw-r--r--drivers/macintosh/adb.c12
-rw-r--r--drivers/macintosh/smu.c6
-rw-r--r--drivers/macintosh/via-pmu-led.c4
-rw-r--r--drivers/macintosh/via-pmu.c11
-rw-r--r--drivers/md/bitmap.c9
-rw-r--r--drivers/md/dm.c10
-rw-r--r--drivers/md/md.c19
-rw-r--r--drivers/md/raid1.c4
-rw-r--r--drivers/media/IR/ir-keytable.c9
-rw-r--r--drivers/media/IR/ir-lirc-codec.c2
-rw-r--r--drivers/media/IR/ir-raw-event.c4
-rw-r--r--drivers/media/IR/ir-sysfs.c17
-rw-r--r--drivers/media/IR/keymaps/rc-rc6-mce.c3
-rw-r--r--drivers/media/IR/mceusb.c4
-rw-r--r--drivers/media/Kconfig1
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c7
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c17
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c8
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c9
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c17
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c3
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c56
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c4
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c8
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h5
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c31
-rw-r--r--drivers/media/radio/si470x/radio-si470x-i2c.c2
-rw-r--r--drivers/media/video/cx231xx/Makefile1
-rw-r--r--drivers/media/video/cx231xx/cx231xx-cards.c17
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c2
-rw-r--r--drivers/media/video/cx88/Kconfig2
-rw-r--r--drivers/media/video/dabusb.c18
-rw-r--r--drivers/media/video/gspca/gspca.c1
-rw-r--r--drivers/media/video/gspca/sn9c20x.c3
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c2
-rw-r--r--drivers/media/video/mem2mem_testdev.c3
-rw-r--r--drivers/media/video/mt9m111.c8
-rw-r--r--drivers/media/video/mt9v022.c3
-rw-r--r--drivers/media/video/mx2_camera.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c6
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c94
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c10
-rw-r--r--drivers/media/video/saa7164/saa7164-buffer.c5
-rw-r--r--drivers/media/video/uvc/uvc_driver.c24
-rw-r--r--drivers/media/video/uvc/uvcvideo.h1
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c32
-rw-r--r--drivers/media/video/videobuf-dma-contig.c6
-rw-r--r--drivers/media/video/videobuf-dma-sg.c11
-rw-r--r--drivers/memstick/core/mspro_block.c11
-rw-r--r--drivers/message/fusion/mptctl.c15
-rw-r--r--drivers/message/i2o/i2o_block.c15
-rw-r--r--drivers/message/i2o/i2o_config.c23
-rw-r--r--drivers/mfd/ab8500-spi.c5
-rw-r--r--drivers/mfd/max8925-core.c13
-rw-r--r--drivers/mfd/twl4030-irq.c4
-rw-r--r--drivers/mfd/wm831x-irq.c9
-rw-r--r--drivers/misc/Kconfig2
-rw-r--r--drivers/misc/Makefile2
-rw-r--r--drivers/misc/bh1780gli.c1
-rw-r--r--drivers/misc/phantom.c11
-rw-r--r--drivers/misc/vmw_balloon.c (renamed from drivers/misc/vmware_balloon.c)0
-rw-r--r--drivers/mmc/card/block.c10
-rw-r--r--drivers/mmc/core/core.c13
-rw-r--r--drivers/mmc/host/mmci.c62
-rw-r--r--drivers/mmc/host/mmci.h22
-rw-r--r--drivers/mmc/host/sdhci-s3c.c12
-rw-r--r--drivers/mmc/host/sdricoh_cs.c5
-rw-r--r--drivers/mtd/maps/pcmciamtd.c102
-rw-r--r--drivers/mtd/mtd_blkdevs.c14
-rw-r--r--drivers/mtd/mtdchar.c15
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c9
-rw-r--r--drivers/mtd/nand/mxc_nand.c137
-rw-r--r--drivers/mtd/nand/omap2.c2
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c6
-rw-r--r--drivers/mtd/onenand/samsung.c16
-rw-r--r--drivers/net/3c527.c2
-rw-r--r--drivers/net/3c59x.c17
-rw-r--r--drivers/net/Kconfig9
-rw-r--r--drivers/net/appletalk/Kconfig1
-rw-r--r--drivers/net/atlx/atl1.c11
-rw-r--r--drivers/net/b44.c4
-rw-r--r--drivers/net/bfin_mac.c1
-rw-r--r--drivers/net/bonding/bond_3ad.c3
-rw-r--r--drivers/net/bonding/bond_alb.c3
-rw-r--r--drivers/net/bonding/bond_main.c9
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c2
-rw-r--r--drivers/net/e1000e/hw.h1
-rw-r--r--drivers/net/e1000e/ich8lan.c197
-rw-r--r--drivers/net/e1000e/netdev.c29
-rw-r--r--drivers/net/ehea/ehea_main.c9
-rw-r--r--drivers/net/ehea/ehea_qmr.h1
-rw-r--r--drivers/net/eql.c2
-rw-r--r--drivers/net/fec.c44
-rw-r--r--drivers/net/hamradio/6pack.c2
-rw-r--r--drivers/net/hamradio/mkiss.c2
-rw-r--r--drivers/net/ibm_newemac/core.c4
-rw-r--r--drivers/net/irda/sir_dev.c2
-rw-r--r--drivers/net/ll_temac_main.c1
-rw-r--r--drivers/net/ll_temac_mdio.c1
-rw-r--r--drivers/net/netxen/netxen_nic_init.c3
-rw-r--r--drivers/net/pcmcia/3c574_cs.c35
-rw-r--r--drivers/net/pcmcia/3c589_cs.c47
-rw-r--r--drivers/net/pcmcia/axnet_cs.c87
-rw-r--r--drivers/net/pcmcia/com20020_cs.c43
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c67
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c89
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c42
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c253
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c114
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c161
-rw-r--r--drivers/net/phy/mdio_bus.c4
-rw-r--r--drivers/net/ppp_async.c2
-rw-r--r--drivers/net/ppp_generic.c9
-rw-r--r--drivers/net/qlcnic/qlcnic_init.c7
-rw-r--r--drivers/net/r8169.c70
-rw-r--r--drivers/net/rionet.c2
-rw-r--r--drivers/net/sgiseeq.c2
-rw-r--r--drivers/net/skge.c18
-rw-r--r--drivers/net/smc91x.c1
-rw-r--r--drivers/net/smsc911x.c1
-rw-r--r--drivers/net/tg3.c6
-rw-r--r--drivers/net/tg3.h2
-rw-r--r--drivers/net/tulip/de2104x.c43
-rw-r--r--drivers/net/usb/hso.c2
-rw-r--r--drivers/net/wan/cosa.c2
-rw-r--r--drivers/net/wimax/i2400m/rx.c26
-rw-r--r--drivers/net/wireless/airo_cs.c154
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.c2
-rw-r--r--drivers/net/wireless/atmel_cs.c135
-rw-r--r--drivers/net/wireless/b43/pcmcia.c24
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c102
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c2
-rw-r--r--drivers/net/wireless/libertas/if_cs.c58
-rw-r--r--drivers/net/wireless/orinoco/orinoco_cs.c137
-rw-r--r--drivers/net/wireless/orinoco/spectrum_cs.c134
-rw-r--r--drivers/net/wireless/ray_cs.c91
-rw-r--r--drivers/net/wireless/ray_cs.h2
-rw-r--r--drivers/net/wireless/wl3501_cs.c47
-rw-r--r--drivers/oprofile/oprof.c32
-rw-r--r--drivers/oprofile/oprof.h2
-rw-r--r--drivers/oprofile/oprofile_files.c7
-rw-r--r--drivers/oprofile/oprofile_perf.c328
-rw-r--r--drivers/oprofile/oprofilefs.c54
-rw-r--r--drivers/parport/parport_cs.c76
-rw-r--r--drivers/parport/share.c2
-rw-r--r--drivers/pci/dmar.c14
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c13
-rw-r--r--drivers/pci/htirq.c22
-rw-r--r--drivers/pci/intel-iommu.c117
-rw-r--r--drivers/pci/intr_remapping.c212
-rw-r--r--drivers/pci/iov.c2
-rw-r--r--drivers/pci/msi.c38
-rw-r--r--drivers/pci/pci.h5
-rw-r--r--drivers/pci/quirks.c20
-rw-r--r--drivers/pcmcia/au1000_generic.c3
-rw-r--r--drivers/pcmcia/au1000_generic.h1
-rw-r--r--drivers/pcmcia/au1000_pb1x00.c1
-rw-r--r--drivers/pcmcia/cistpl.c1
-rw-r--r--drivers/pcmcia/cs.c3
-rw-r--r--drivers/pcmcia/cs_internal.h9
-rw-r--r--drivers/pcmcia/ds.c37
-rw-r--r--drivers/pcmcia/i82092.c1
-rw-r--r--drivers/pcmcia/i82365.c1
-rw-r--r--drivers/pcmcia/m32r_cfc.c1
-rw-r--r--drivers/pcmcia/m32r_pcc.c1
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c1
-rw-r--r--drivers/pcmcia/o2micro.h4
-rw-r--r--drivers/pcmcia/pcmcia_cis.c117
-rw-r--r--drivers/pcmcia/pcmcia_resource.c448
-rw-r--r--drivers/pcmcia/pd6729.c3
-rw-r--r--drivers/pcmcia/rsrc_iodyn.c1
-rw-r--r--drivers/pcmcia/rsrc_mgr.c1
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c1
-rw-r--r--drivers/pcmcia/sa1100_generic.c1
-rw-r--r--drivers/pcmcia/soc_common.c4
-rw-r--r--drivers/pcmcia/soc_common.h1
-rw-r--r--drivers/pcmcia/socket_sysfs.c1
-rw-r--r--drivers/pcmcia/tcic.c1
-rw-r--r--drivers/pcmcia/vrc4173_cardu.c58
-rw-r--r--drivers/pcmcia/xxs1500_ss.c1
-rw-r--r--drivers/pcmcia/yenta_socket.c1
-rw-r--r--drivers/platform/x86/intel_ips.c122
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c5
-rw-r--r--drivers/pnp/isapnp/proc.c15
-rw-r--r--drivers/power/apm_power.c1
-rw-r--r--drivers/power/intel_mid_battery.c6
-rw-r--r--drivers/regulator/88pm8607.c4
-rw-r--r--drivers/regulator/ab3100.c5
-rw-r--r--drivers/regulator/ab8500.c9
-rw-r--r--drivers/regulator/ad5398.c13
-rw-r--r--drivers/regulator/core.c6
-rw-r--r--drivers/regulator/isl6271a-regulator.c4
-rw-r--r--drivers/regulator/max1586.c12
-rw-r--r--drivers/regulator/max8649.c2
-rw-r--r--drivers/regulator/max8998.c8
-rw-r--r--drivers/regulator/tps6507x-regulator.c6
-rw-r--r--drivers/regulator/tps6586x-regulator.c4
-rw-r--r--drivers/regulator/wm831x-ldo.c7
-rw-r--r--drivers/regulator/wm8350-regulator.c2
-rw-r--r--drivers/rtc/rtc-ab3100.c2
-rw-r--r--drivers/rtc/rtc-ds3232.c2
-rw-r--r--drivers/rtc/rtc-m41t80.c13
-rw-r--r--drivers/rtc/rtc-s3c.c13
-rw-r--r--drivers/s390/block/dasd.c6
-rw-r--r--drivers/s390/block/dasd_ioctl.c17
-rw-r--r--drivers/s390/block/dcssblk.c5
-rw-r--r--drivers/s390/char/sclp.c2
-rw-r--r--drivers/s390/char/tape_block.c13
-rw-r--r--drivers/s390/net/ctcm_main.c4
-rw-r--r--drivers/sbus/char/jsflash.c24
-rw-r--r--drivers/scsi/3w-9xxx.c7
-rw-r--r--drivers/scsi/3w-sas.c7
-rw-r--r--drivers/scsi/3w-xxxx.c9
-rw-r--r--drivers/scsi/aacraid/linit.c15
-rw-r--r--drivers/scsi/ch.c8
-rw-r--r--drivers/scsi/dpt_i2o.c18
-rw-r--r--drivers/scsi/gdth.c11
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c2
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c11
-rw-r--r--drivers/scsi/osst.c15
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c48
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c24
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c182
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c24
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c22
-rw-r--r--drivers/scsi/scsi.c4
-rw-r--r--drivers/scsi/scsi_tgt_if.c2
-rw-r--r--drivers/scsi/sg.c12
-rw-r--r--drivers/scsi/sr.c14
-rw-r--r--drivers/scsi/st.c12
-rw-r--r--drivers/serial/Kconfig7
-rw-r--r--drivers/serial/amba-pl010.c9
-rw-r--r--drivers/serial/ioc3_serial.c5
-rw-r--r--drivers/serial/mfd.c18
-rw-r--r--drivers/serial/mpc52xx_uart.c1
-rw-r--r--drivers/serial/mrst_max3110.c1
-rw-r--r--drivers/serial/samsung.c2
-rw-r--r--drivers/serial/serial_cs.c261
-rw-r--r--drivers/spi/Kconfig46
-rw-r--r--drivers/spi/Makefile9
-rw-r--r--drivers/spi/amba-pl022.c767
-rw-r--r--drivers/spi/atmel_spi.c14
-rw-r--r--drivers/spi/dw_spi.c24
-rw-r--r--drivers/spi/omap2_mcspi.c81
-rw-r--r--drivers/spi/orion_spi.c4
-rw-r--r--drivers/spi/spi.c14
-rw-r--r--drivers/spi/spi_bfin5xx.c844
-rw-r--r--drivers/spi/spi_fsl_espi.c748
-rw-r--r--drivers/spi/spi_fsl_lib.c237
-rw-r--r--drivers/spi/spi_fsl_lib.h124
-rw-r--r--drivers/spi/spi_fsl_spi.c (renamed from drivers/spi/spi_mpc8xxx.c)562
-rw-r--r--drivers/spi/spi_gpio.c2
-rw-r--r--drivers/spi/spi_imx.c402
-rw-r--r--drivers/spi/spi_s3c64xx.c195
-rw-r--r--drivers/spi/spi_topcliff_pch.c1303
-rw-r--r--drivers/ssb/main.c1
-rw-r--r--drivers/ssb/pcmcia.c1
-rw-r--r--drivers/ssb/scan.c1
-rw-r--r--drivers/staging/batman-adv/hard-interface.c13
-rw-r--r--drivers/staging/batman-adv/send.c8
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c58
-rw-r--r--drivers/staging/comedi/drivers/das08_cs.c129
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_700.c130
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_dio24.c130
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_cs.c144
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_cs.c23
-rw-r--r--drivers/staging/comedi/drivers/quatech_daqp_cs.c124
-rw-r--r--drivers/staging/cx25821/Kconfig1
-rw-r--r--drivers/staging/easycap/Kconfig1
-rw-r--r--drivers/staging/go7007/Kconfig1
-rw-r--r--drivers/staging/hv/blkvsc_drv.c11
-rw-r--r--drivers/staging/spectra/ffsport.c7
-rw-r--r--drivers/staging/ti-st/st.h1
-rw-r--r--drivers/staging/ti-st/st_core.c9
-rw-r--r--drivers/staging/ti-st/st_core.h2
-rw-r--r--drivers/staging/ti-st/st_kim.c22
-rw-r--r--drivers/staging/tm6000/Kconfig2
-rw-r--r--drivers/staging/tm6000/tm6000-input.c61
-rw-r--r--drivers/staging/usbip/Kconfig2
-rw-r--r--drivers/staging/vt6655/wpactl.c11
-rw-r--r--drivers/staging/wlags49_h2/wl_cs.c77
-rw-r--r--drivers/staging/wlags49_h2/wl_internal.h1
-rw-r--r--drivers/staging/wlags49_h2/wl_main.c19
-rw-r--r--drivers/telephony/ixj.c7
-rw-r--r--drivers/telephony/ixj_pcmcia.c41
-rw-r--r--drivers/usb/core/Kconfig6
-rw-r--r--drivers/usb/core/file.c35
-rw-r--r--drivers/usb/core/message.c1
-rw-r--r--drivers/usb/gadget/inode.c1
-rw-r--r--drivers/usb/host/ehci-pci.c5
-rw-r--r--drivers/usb/host/ohci-pxa27x.c7
-rw-r--r--drivers/usb/host/sl811_cs.c68
-rw-r--r--drivers/usb/musb/cppi_dma.c1
-rw-r--r--drivers/usb/musb/musb_debugfs.c5
-rw-r--r--drivers/usb/musb/musb_gadget.c75
-rw-r--r--drivers/usb/musb/musb_gadget.h2
-rw-r--r--drivers/usb/musb/musb_gadget_ep0.c9
-rw-r--r--drivers/usb/musb/musb_host.c6
-rw-r--r--drivers/usb/otg/twl4030-usb.c78
-rw-r--r--drivers/usb/serial/mos7720.c3
-rw-r--r--drivers/usb/serial/mos7840.c3
-rw-r--r--drivers/vhost/net.c18
-rw-r--r--drivers/vhost/vhost.c29
-rw-r--r--drivers/vhost/vhost.h10
-rw-r--r--drivers/video/console/fbcon.c5
-rw-r--r--drivers/video/efifb.c103
-rw-r--r--drivers/video/omap2/vram.c8
-rw-r--r--drivers/video/pxa168fb.c51
-rw-r--r--drivers/video/sis/sis_main.c3
-rw-r--r--drivers/video/via/ioctl.c2
-rw-r--r--drivers/vlynq/vlynq.c1
-rw-r--r--drivers/watchdog/Kconfig28
-rw-r--r--drivers/watchdog/booke_wdt.c47
-rw-r--r--drivers/watchdog/cpwd.c15
-rw-r--r--drivers/watchdog/octeon-wdt-main.c1
-rw-r--r--drivers/watchdog/sb_wdog.c12
-rw-r--r--drivers/watchdog/ts72xx_wdt.c3
-rw-r--r--drivers/xen/events.c23
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c9
627 files changed, 17123 insertions, 9840 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index ae473445ad6d..a2aea53a75ed 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -50,7 +50,7 @@ obj-$(CONFIG_SPI) += spi/
50obj-y += net/ 50obj-y += net/
51obj-$(CONFIG_ATM) += atm/ 51obj-$(CONFIG_ATM) += atm/
52obj-$(CONFIG_FUSION) += message/ 52obj-$(CONFIG_FUSION) += message/
53obj-$(CONFIG_FIREWIRE) += firewire/ 53obj-y += firewire/
54obj-y += ieee1394/ 54obj-y += ieee1394/
55obj-$(CONFIG_UIO) += uio/ 55obj-$(CONFIG_UIO) += uio/
56obj-y += cdrom/ 56obj-y += cdrom/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b811f2173f6f..88681aca88c5 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -105,7 +105,7 @@ config ACPI_EC_DEBUGFS
105 105
106 Be aware that using this interface can confuse your Embedded 106 Be aware that using this interface can confuse your Embedded
107 Controller in a way that a normal reboot is not enough. You then 107 Controller in a way that a normal reboot is not enough. You then
108 have to power of your system, and remove the laptop battery for 108 have to power off your system, and remove the laptop battery for
109 some seconds. 109 some seconds.
110 An Embedded Controller typically is available on laptops and reads 110 An Embedded Controller typically is available on laptops and reads
111 sensor values like battery state and temperature. 111 sensor values like battery state and temperature.
diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
index b76848c80be3..6afceb3d4034 100644
--- a/drivers/acpi/acpi_pad.c
+++ b/drivers/acpi/acpi_pad.c
@@ -30,18 +30,13 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <acpi/acpi_bus.h> 31#include <acpi/acpi_bus.h>
32#include <acpi/acpi_drivers.h> 32#include <acpi/acpi_drivers.h>
33#include <asm/mwait.h>
33 34
34#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad" 35#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
35#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator" 36#define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
36#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80 37#define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
37static DEFINE_MUTEX(isolated_cpus_lock); 38static DEFINE_MUTEX(isolated_cpus_lock);
38 39
39#define MWAIT_SUBSTATE_MASK (0xf)
40#define MWAIT_CSTATE_MASK (0xf)
41#define MWAIT_SUBSTATE_SIZE (4)
42#define CPUID_MWAIT_LEAF (5)
43#define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
44#define CPUID5_ECX_INTERRUPT_BREAK (0x2)
45static unsigned long power_saving_mwait_eax; 40static unsigned long power_saving_mwait_eax;
46 41
47static unsigned char tsc_detected_unstable; 42static unsigned char tsc_detected_unstable;
@@ -382,31 +377,32 @@ static void acpi_pad_remove_sysfs(struct acpi_device *device)
382 device_remove_file(&device->dev, &dev_attr_rrtime); 377 device_remove_file(&device->dev, &dev_attr_rrtime);
383} 378}
384 379
385/* Query firmware how many CPUs should be idle */ 380/*
386static int acpi_pad_pur(acpi_handle handle, int *num_cpus) 381 * Query firmware how many CPUs should be idle
382 * return -1 on failure
383 */
384static int acpi_pad_pur(acpi_handle handle)
387{ 385{
388 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; 386 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
389 union acpi_object *package; 387 union acpi_object *package;
390 int rev, num, ret = -EINVAL; 388 int num = -1;
391 389
392 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer))) 390 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PUR", NULL, &buffer)))
393 return -EINVAL; 391 return num;
394 392
395 if (!buffer.length || !buffer.pointer) 393 if (!buffer.length || !buffer.pointer)
396 return -EINVAL; 394 return num;
397 395
398 package = buffer.pointer; 396 package = buffer.pointer;
399 if (package->type != ACPI_TYPE_PACKAGE || package->package.count != 2) 397
400 goto out; 398 if (package->type == ACPI_TYPE_PACKAGE &&
401 rev = package->package.elements[0].integer.value; 399 package->package.count == 2 &&
402 num = package->package.elements[1].integer.value; 400 package->package.elements[0].integer.value == 1) /* rev 1 */
403 if (rev != 1 || num < 0) 401
404 goto out; 402 num = package->package.elements[1].integer.value;
405 *num_cpus = num; 403
406 ret = 0;
407out:
408 kfree(buffer.pointer); 404 kfree(buffer.pointer);
409 return ret; 405 return num;
410} 406}
411 407
412/* Notify firmware how many CPUs are idle */ 408/* Notify firmware how many CPUs are idle */
@@ -433,7 +429,8 @@ static void acpi_pad_handle_notify(acpi_handle handle)
433 uint32_t idle_cpus; 429 uint32_t idle_cpus;
434 430
435 mutex_lock(&isolated_cpus_lock); 431 mutex_lock(&isolated_cpus_lock);
436 if (acpi_pad_pur(handle, &num_cpus)) { 432 num_cpus = acpi_pad_pur(handle);
433 if (num_cpus < 0) {
437 mutex_unlock(&isolated_cpus_lock); 434 mutex_unlock(&isolated_cpus_lock);
438 return; 435 return;
439 } 436 }
diff --git a/drivers/acpi/acpica/aclocal.h b/drivers/acpi/acpica/aclocal.h
index df85b53a674f..7dad9160f209 100644
--- a/drivers/acpi/acpica/aclocal.h
+++ b/drivers/acpi/acpica/aclocal.h
@@ -854,6 +854,7 @@ struct acpi_bit_register_info {
854 ACPI_BITMASK_POWER_BUTTON_STATUS | \ 854 ACPI_BITMASK_POWER_BUTTON_STATUS | \
855 ACPI_BITMASK_SLEEP_BUTTON_STATUS | \ 855 ACPI_BITMASK_SLEEP_BUTTON_STATUS | \
856 ACPI_BITMASK_RT_CLOCK_STATUS | \ 856 ACPI_BITMASK_RT_CLOCK_STATUS | \
857 ACPI_BITMASK_PCIEXP_WAKE_DISABLE | \
857 ACPI_BITMASK_WAKE_STATUS) 858 ACPI_BITMASK_WAKE_STATUS)
858 859
859#define ACPI_BITMASK_TIMER_ENABLE 0x0001 860#define ACPI_BITMASK_TIMER_ENABLE 0x0001
diff --git a/drivers/acpi/acpica/exutils.c b/drivers/acpi/acpica/exutils.c
index 74c24d517f81..4093522eed45 100644
--- a/drivers/acpi/acpica/exutils.c
+++ b/drivers/acpi/acpica/exutils.c
@@ -109,7 +109,7 @@ void acpi_ex_enter_interpreter(void)
109 * 109 *
110 * DESCRIPTION: Reacquire the interpreter execution region from within the 110 * DESCRIPTION: Reacquire the interpreter execution region from within the
111 * interpreter code. Failure to enter the interpreter region is a 111 * interpreter code. Failure to enter the interpreter region is a
112 * fatal system error. Used in conjuction with 112 * fatal system error. Used in conjunction with
113 * relinquish_interpreter 113 * relinquish_interpreter
114 * 114 *
115 ******************************************************************************/ 115 ******************************************************************************/
diff --git a/drivers/acpi/acpica/rsutils.c b/drivers/acpi/acpica/rsutils.c
index 22cfcfbd9fff..491191e6cf69 100644
--- a/drivers/acpi/acpica/rsutils.c
+++ b/drivers/acpi/acpica/rsutils.c
@@ -149,7 +149,7 @@ acpi_rs_move_data(void *destination, void *source, u16 item_count, u8 move_type)
149 149
150 /* 150 /*
151 * 16-, 32-, and 64-bit cases must use the move macros that perform 151 * 16-, 32-, and 64-bit cases must use the move macros that perform
152 * endian conversion and/or accomodate hardware that cannot perform 152 * endian conversion and/or accommodate hardware that cannot perform
153 * misaligned memory transfers 153 * misaligned memory transfers
154 */ 154 */
155 case ACPI_RSC_MOVE16: 155 case ACPI_RSC_MOVE16:
diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig
index 907e350f1c7d..fca34ccfd294 100644
--- a/drivers/acpi/apei/Kconfig
+++ b/drivers/acpi/apei/Kconfig
@@ -34,6 +34,6 @@ config ACPI_APEI_ERST_DEBUG
34 depends on ACPI_APEI 34 depends on ACPI_APEI
35 help 35 help
36 ERST is a way provided by APEI to save and retrieve hardware 36 ERST is a way provided by APEI to save and retrieve hardware
37 error infomation to and from a persistent store. Enable this 37 error information to and from a persistent store. Enable this
38 if you want to debugging and testing the ERST kernel support 38 if you want to debugging and testing the ERST kernel support
39 and firmware implementation. 39 and firmware implementation.
diff --git a/drivers/acpi/apei/apei-base.c b/drivers/acpi/apei/apei-base.c
index 73fd0c7487c1..4a904a4bf05f 100644
--- a/drivers/acpi/apei/apei-base.c
+++ b/drivers/acpi/apei/apei-base.c
@@ -445,11 +445,15 @@ EXPORT_SYMBOL_GPL(apei_resources_sub);
445int apei_resources_request(struct apei_resources *resources, 445int apei_resources_request(struct apei_resources *resources,
446 const char *desc) 446 const char *desc)
447{ 447{
448 struct apei_res *res, *res_bak; 448 struct apei_res *res, *res_bak = NULL;
449 struct resource *r; 449 struct resource *r;
450 int rc;
450 451
451 apei_resources_sub(resources, &apei_resources_all); 452 rc = apei_resources_sub(resources, &apei_resources_all);
453 if (rc)
454 return rc;
452 455
456 rc = -EINVAL;
453 list_for_each_entry(res, &resources->iomem, list) { 457 list_for_each_entry(res, &resources->iomem, list) {
454 r = request_mem_region(res->start, res->end - res->start, 458 r = request_mem_region(res->start, res->end - res->start,
455 desc); 459 desc);
@@ -475,7 +479,11 @@ int apei_resources_request(struct apei_resources *resources,
475 } 479 }
476 } 480 }
477 481
478 apei_resources_merge(&apei_resources_all, resources); 482 rc = apei_resources_merge(&apei_resources_all, resources);
483 if (rc) {
484 pr_err(APEI_PFX "Fail to merge resources!\n");
485 goto err_unmap_ioport;
486 }
479 487
480 return 0; 488 return 0;
481err_unmap_ioport: 489err_unmap_ioport:
@@ -491,12 +499,13 @@ err_unmap_iomem:
491 break; 499 break;
492 release_mem_region(res->start, res->end - res->start); 500 release_mem_region(res->start, res->end - res->start);
493 } 501 }
494 return -EINVAL; 502 return rc;
495} 503}
496EXPORT_SYMBOL_GPL(apei_resources_request); 504EXPORT_SYMBOL_GPL(apei_resources_request);
497 505
498void apei_resources_release(struct apei_resources *resources) 506void apei_resources_release(struct apei_resources *resources)
499{ 507{
508 int rc;
500 struct apei_res *res; 509 struct apei_res *res;
501 510
502 list_for_each_entry(res, &resources->iomem, list) 511 list_for_each_entry(res, &resources->iomem, list)
@@ -504,7 +513,9 @@ void apei_resources_release(struct apei_resources *resources)
504 list_for_each_entry(res, &resources->ioport, list) 513 list_for_each_entry(res, &resources->ioport, list)
505 release_region(res->start, res->end - res->start); 514 release_region(res->start, res->end - res->start);
506 515
507 apei_resources_sub(&apei_resources_all, resources); 516 rc = apei_resources_sub(&apei_resources_all, resources);
517 if (rc)
518 pr_err(APEI_PFX "Fail to sub resources!\n");
508} 519}
509EXPORT_SYMBOL_GPL(apei_resources_release); 520EXPORT_SYMBOL_GPL(apei_resources_release);
510 521
diff --git a/drivers/acpi/apei/einj.c b/drivers/acpi/apei/einj.c
index 465c885938ee..cf29df69380b 100644
--- a/drivers/acpi/apei/einj.c
+++ b/drivers/acpi/apei/einj.c
@@ -426,7 +426,9 @@ DEFINE_SIMPLE_ATTRIBUTE(error_inject_fops, NULL,
426 426
427static int einj_check_table(struct acpi_table_einj *einj_tab) 427static int einj_check_table(struct acpi_table_einj *einj_tab)
428{ 428{
429 if (einj_tab->header_length != sizeof(struct acpi_table_einj)) 429 if ((einj_tab->header_length !=
430 (sizeof(struct acpi_table_einj) - sizeof(einj_tab->header)))
431 && (einj_tab->header_length != sizeof(struct acpi_table_einj)))
430 return -EINVAL; 432 return -EINVAL;
431 if (einj_tab->header.length < sizeof(struct acpi_table_einj)) 433 if (einj_tab->header.length < sizeof(struct acpi_table_einj))
432 return -EINVAL; 434 return -EINVAL;
diff --git a/drivers/acpi/apei/erst-dbg.c b/drivers/acpi/apei/erst-dbg.c
index cbab9b07bf28..de73caf3cebc 100644
--- a/drivers/acpi/apei/erst-dbg.c
+++ b/drivers/acpi/apei/erst-dbg.c
@@ -2,7 +2,7 @@
2 * APEI Error Record Serialization Table debug support 2 * APEI Error Record Serialization Table debug support
3 * 3 *
4 * ERST is a way provided by APEI to save and retrieve hardware error 4 * ERST is a way provided by APEI to save and retrieve hardware error
5 * infomation to and from a persistent store. This file provide the 5 * information to and from a persistent store. This file provide the
6 * debugging/testing support for ERST kernel support and firmware 6 * debugging/testing support for ERST kernel support and firmware
7 * implementation. 7 * implementation.
8 * 8 *
@@ -111,11 +111,13 @@ retry:
111 goto out; 111 goto out;
112 } 112 }
113 if (len > erst_dbg_buf_len) { 113 if (len > erst_dbg_buf_len) {
114 kfree(erst_dbg_buf); 114 void *p;
115 rc = -ENOMEM; 115 rc = -ENOMEM;
116 erst_dbg_buf = kmalloc(len, GFP_KERNEL); 116 p = kmalloc(len, GFP_KERNEL);
117 if (!erst_dbg_buf) 117 if (!p)
118 goto out; 118 goto out;
119 kfree(erst_dbg_buf);
120 erst_dbg_buf = p;
119 erst_dbg_buf_len = len; 121 erst_dbg_buf_len = len;
120 goto retry; 122 goto retry;
121 } 123 }
@@ -150,11 +152,13 @@ static ssize_t erst_dbg_write(struct file *filp, const char __user *ubuf,
150 if (mutex_lock_interruptible(&erst_dbg_mutex)) 152 if (mutex_lock_interruptible(&erst_dbg_mutex))
151 return -EINTR; 153 return -EINTR;
152 if (usize > erst_dbg_buf_len) { 154 if (usize > erst_dbg_buf_len) {
153 kfree(erst_dbg_buf); 155 void *p;
154 rc = -ENOMEM; 156 rc = -ENOMEM;
155 erst_dbg_buf = kmalloc(usize, GFP_KERNEL); 157 p = kmalloc(usize, GFP_KERNEL);
156 if (!erst_dbg_buf) 158 if (!p)
157 goto out; 159 goto out;
160 kfree(erst_dbg_buf);
161 erst_dbg_buf = p;
158 erst_dbg_buf_len = usize; 162 erst_dbg_buf_len = usize;
159 } 163 }
160 rc = copy_from_user(erst_dbg_buf, ubuf, usize); 164 rc = copy_from_user(erst_dbg_buf, ubuf, usize);
diff --git a/drivers/acpi/apei/erst.c b/drivers/acpi/apei/erst.c
index 18645f4e83cd..1211c03149e8 100644
--- a/drivers/acpi/apei/erst.c
+++ b/drivers/acpi/apei/erst.c
@@ -2,7 +2,7 @@
2 * APEI Error Record Serialization Table support 2 * APEI Error Record Serialization Table support
3 * 3 *
4 * ERST is a way provided by APEI to save and retrieve hardware error 4 * ERST is a way provided by APEI to save and retrieve hardware error
5 * infomation to and from a persistent store. 5 * information to and from a persistent store.
6 * 6 *
7 * For more information about ERST, please refer to ACPI Specification 7 * For more information about ERST, please refer to ACPI Specification
8 * version 4.0, section 17.4. 8 * version 4.0, section 17.4.
@@ -266,13 +266,30 @@ static int erst_exec_move_data(struct apei_exec_context *ctx,
266{ 266{
267 int rc; 267 int rc;
268 u64 offset; 268 u64 offset;
269 void *src, *dst;
270
271 /* ioremap does not work in interrupt context */
272 if (in_interrupt()) {
273 pr_warning(ERST_PFX
274 "MOVE_DATA can not be used in interrupt context");
275 return -EBUSY;
276 }
269 277
270 rc = __apei_exec_read_register(entry, &offset); 278 rc = __apei_exec_read_register(entry, &offset);
271 if (rc) 279 if (rc)
272 return rc; 280 return rc;
273 memmove((void *)ctx->dst_base + offset, 281
274 (void *)ctx->src_base + offset, 282 src = ioremap(ctx->src_base + offset, ctx->var2);
275 ctx->var2); 283 if (!src)
284 return -ENOMEM;
285 dst = ioremap(ctx->dst_base + offset, ctx->var2);
286 if (!dst)
287 return -ENOMEM;
288
289 memmove(dst, src, ctx->var2);
290
291 iounmap(src);
292 iounmap(dst);
276 293
277 return 0; 294 return 0;
278} 295}
@@ -750,7 +767,9 @@ __setup("erst_disable", setup_erst_disable);
750 767
751static int erst_check_table(struct acpi_table_erst *erst_tab) 768static int erst_check_table(struct acpi_table_erst *erst_tab)
752{ 769{
753 if (erst_tab->header_length != sizeof(struct acpi_table_erst)) 770 if ((erst_tab->header_length !=
771 (sizeof(struct acpi_table_erst) - sizeof(erst_tab->header)))
772 && (erst_tab->header_length != sizeof(struct acpi_table_einj)))
754 return -EINVAL; 773 return -EINVAL;
755 if (erst_tab->header.length < sizeof(struct acpi_table_erst)) 774 if (erst_tab->header.length < sizeof(struct acpi_table_erst))
756 return -EINVAL; 775 return -EINVAL;
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index 385a6059714a..0d505e59214d 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -302,7 +302,7 @@ static int __devinit ghes_probe(struct platform_device *ghes_dev)
302 struct ghes *ghes = NULL; 302 struct ghes *ghes = NULL;
303 int rc = -EINVAL; 303 int rc = -EINVAL;
304 304
305 generic = ghes_dev->dev.platform_data; 305 generic = *(struct acpi_hest_generic **)ghes_dev->dev.platform_data;
306 if (!generic->enabled) 306 if (!generic->enabled)
307 return -ENODEV; 307 return -ENODEV;
308 308
diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c
index 343168d18266..1a3508a7fe03 100644
--- a/drivers/acpi/apei/hest.c
+++ b/drivers/acpi/apei/hest.c
@@ -137,20 +137,23 @@ static int hest_parse_ghes_count(struct acpi_hest_header *hest_hdr, void *data)
137 137
138static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data) 138static int hest_parse_ghes(struct acpi_hest_header *hest_hdr, void *data)
139{ 139{
140 struct acpi_hest_generic *generic;
141 struct platform_device *ghes_dev; 140 struct platform_device *ghes_dev;
142 struct ghes_arr *ghes_arr = data; 141 struct ghes_arr *ghes_arr = data;
143 int rc; 142 int rc;
144 143
145 if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR) 144 if (hest_hdr->type != ACPI_HEST_TYPE_GENERIC_ERROR)
146 return 0; 145 return 0;
147 generic = (struct acpi_hest_generic *)hest_hdr; 146
148 if (!generic->enabled) 147 if (!((struct acpi_hest_generic *)hest_hdr)->enabled)
149 return 0; 148 return 0;
150 ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id); 149 ghes_dev = platform_device_alloc("GHES", hest_hdr->source_id);
151 if (!ghes_dev) 150 if (!ghes_dev)
152 return -ENOMEM; 151 return -ENOMEM;
153 ghes_dev->dev.platform_data = generic; 152
153 rc = platform_device_add_data(ghes_dev, &hest_hdr, sizeof(void *));
154 if (rc)
155 goto err;
156
154 rc = platform_device_add(ghes_dev); 157 rc = platform_device_add(ghes_dev);
155 if (rc) 158 if (rc)
156 goto err; 159 goto err;
diff --git a/drivers/acpi/atomicio.c b/drivers/acpi/atomicio.c
index 8f8bd736d4ff..542e53903891 100644
--- a/drivers/acpi/atomicio.c
+++ b/drivers/acpi/atomicio.c
@@ -142,7 +142,7 @@ static void __iomem *acpi_pre_map(phys_addr_t paddr,
142 list_add_tail_rcu(&map->list, &acpi_iomaps); 142 list_add_tail_rcu(&map->list, &acpi_iomaps);
143 spin_unlock_irqrestore(&acpi_iomaps_lock, flags); 143 spin_unlock_irqrestore(&acpi_iomaps_lock, flags);
144 144
145 return vaddr + (paddr - pg_off); 145 return map->vaddr + (paddr - map->paddr);
146err_unmap: 146err_unmap:
147 iounmap(vaddr); 147 iounmap(vaddr);
148 return NULL; 148 return NULL;
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index dc58402b0a17..98417201e9ce 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -273,7 +273,6 @@ static enum power_supply_property energy_battery_props[] = {
273 POWER_SUPPLY_PROP_CYCLE_COUNT, 273 POWER_SUPPLY_PROP_CYCLE_COUNT,
274 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, 274 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
275 POWER_SUPPLY_PROP_VOLTAGE_NOW, 275 POWER_SUPPLY_PROP_VOLTAGE_NOW,
276 POWER_SUPPLY_PROP_CURRENT_NOW,
277 POWER_SUPPLY_PROP_POWER_NOW, 276 POWER_SUPPLY_PROP_POWER_NOW,
278 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 277 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
279 POWER_SUPPLY_PROP_ENERGY_FULL, 278 POWER_SUPPLY_PROP_ENERGY_FULL,
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index 2bb28b9d91c4..af308d03f492 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -183,6 +183,8 @@ static int __init dmi_disable_osi_vista(const struct dmi_system_id *d)
183{ 183{
184 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident); 184 printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
185 acpi_osi_setup("!Windows 2006"); 185 acpi_osi_setup("!Windows 2006");
186 acpi_osi_setup("!Windows 2006 SP1");
187 acpi_osi_setup("!Windows 2006 SP2");
186 return 0; 188 return 0;
187} 189}
188static int __init dmi_disable_osi_win7(const struct dmi_system_id *d) 190static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
@@ -202,6 +204,23 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
202 }, 204 },
203 }, 205 },
204 { 206 {
207 /*
208 * There have a NVIF method in MSI GX723 DSDT need call by Nvidia
209 * driver (e.g. nouveau) when user press brightness hotkey.
210 * Currently, nouveau driver didn't do the job and it causes there
211 * have a infinite while loop in DSDT when user press hotkey.
212 * We add MSI GX723's dmi information to this table for workaround
213 * this issue.
214 * Will remove MSI GX723 from the table after nouveau grows support.
215 */
216 .callback = dmi_disable_osi_vista,
217 .ident = "MSI GX723",
218 .matches = {
219 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
220 DMI_MATCH(DMI_PRODUCT_NAME, "GX723"),
221 },
222 },
223 {
205 .callback = dmi_disable_osi_vista, 224 .callback = dmi_disable_osi_vista,
206 .ident = "Sony VGN-NS10J_S", 225 .ident = "Sony VGN-NS10J_S",
207 .matches = { 226 .matches = {
@@ -226,6 +245,14 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
226 }, 245 },
227 }, 246 },
228 { 247 {
248 .callback = dmi_disable_osi_vista,
249 .ident = "Toshiba Satellite L355",
250 .matches = {
251 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
252 DMI_MATCH(DMI_PRODUCT_VERSION, "Satellite L355"),
253 },
254 },
255 {
229 .callback = dmi_disable_osi_win7, 256 .callback = dmi_disable_osi_win7,
230 .ident = "ASUS K50IJ", 257 .ident = "ASUS K50IJ",
231 .matches = { 258 .matches = {
@@ -233,6 +260,14 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
233 DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"), 260 DMI_MATCH(DMI_PRODUCT_NAME, "K50IJ"),
234 }, 261 },
235 }, 262 },
263 {
264 .callback = dmi_disable_osi_vista,
265 .ident = "Toshiba P305D",
266 .matches = {
267 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
268 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite P305D"),
269 },
270 },
236 271
237 /* 272 /*
238 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug. 273 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 5c221ab535d5..310e3b9749cb 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -55,7 +55,7 @@ EXPORT_SYMBOL(acpi_root_dir);
55static int set_power_nocheck(const struct dmi_system_id *id) 55static int set_power_nocheck(const struct dmi_system_id *id)
56{ 56{
57 printk(KERN_NOTICE PREFIX "%s detected - " 57 printk(KERN_NOTICE PREFIX "%s detected - "
58 "disable power check in power transistion\n", id->ident); 58 "disable power check in power transition\n", id->ident);
59 acpi_power_nocheck = 1; 59 acpi_power_nocheck = 1;
60 return 0; 60 return 0;
61} 61}
@@ -80,23 +80,15 @@ static int set_copy_dsdt(const struct dmi_system_id *id)
80 80
81static struct dmi_system_id dsdt_dmi_table[] __initdata = { 81static struct dmi_system_id dsdt_dmi_table[] __initdata = {
82 /* 82 /*
83 * Insyde BIOS on some TOSHIBA machines corrupt the DSDT. 83 * Invoke DSDT corruption work-around on all Toshiba Satellite.
84 * https://bugzilla.kernel.org/show_bug.cgi?id=14679 84 * https://bugzilla.kernel.org/show_bug.cgi?id=14679
85 */ 85 */
86 { 86 {
87 .callback = set_copy_dsdt, 87 .callback = set_copy_dsdt,
88 .ident = "TOSHIBA Satellite A505", 88 .ident = "TOSHIBA Satellite",
89 .matches = { 89 .matches = {
90 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 90 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
91 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A505"), 91 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite"),
92 },
93 },
94 {
95 .callback = set_copy_dsdt,
96 .ident = "TOSHIBA Satellite L505D",
97 .matches = {
98 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
99 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L505D"),
100 }, 92 },
101 }, 93 },
102 {} 94 {}
@@ -1027,7 +1019,7 @@ static int __init acpi_init(void)
1027 1019
1028 /* 1020 /*
1029 * If the laptop falls into the DMI check table, the power state check 1021 * If the laptop falls into the DMI check table, the power state check
1030 * will be disabled in the course of device power transistion. 1022 * will be disabled in the course of device power transition.
1031 */ 1023 */
1032 dmi_check_system(power_nocheck_dmi_table); 1024 dmi_check_system(power_nocheck_dmi_table);
1033 1025
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 8a3b840c0bb2..d94d2953c974 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -369,7 +369,9 @@ static void __exit acpi_fan_exit(void)
369 369
370 acpi_bus_unregister_driver(&acpi_fan_driver); 370 acpi_bus_unregister_driver(&acpi_fan_driver);
371 371
372#ifdef CONFIG_ACPI_PROCFS
372 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir); 373 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
374#endif
373 375
374 return; 376 return;
375} 377}
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index e9699aaed109..bec561c14beb 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -29,12 +29,6 @@ static int set_no_mwait(const struct dmi_system_id *id)
29 29
30static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = { 30static struct dmi_system_id __cpuinitdata processor_idle_dmi_table[] = {
31 { 31 {
32 set_no_mwait, "IFL91 board", {
33 DMI_MATCH(DMI_BIOS_VENDOR, "COMPAL"),
34 DMI_MATCH(DMI_SYS_VENDOR, "ZEPTO"),
35 DMI_MATCH(DMI_PRODUCT_VERSION, "3215W"),
36 DMI_MATCH(DMI_BOARD_NAME, "IFL91") }, NULL},
37 {
38 set_no_mwait, "Extensa 5220", { 32 set_no_mwait, "Extensa 5220", {
39 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"), 33 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
40 DMI_MATCH(DMI_SYS_VENDOR, "Acer"), 34 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
@@ -352,4 +346,5 @@ void __init acpi_early_processor_set_pdc(void)
352 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, 346 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
353 ACPI_UINT32_MAX, 347 ACPI_UINT32_MAX,
354 early_init_pdc, NULL, NULL, NULL); 348 early_init_pdc, NULL, NULL, NULL);
349 acpi_get_devices("ACPI0007", early_init_pdc, NULL, NULL);
355} 350}
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 156021892389..347eb21b2353 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -850,7 +850,7 @@ static int __init acpi_processor_init(void)
850 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n", 850 printk(KERN_DEBUG "ACPI: %s registered with cpuidle\n",
851 acpi_idle_driver.name); 851 acpi_idle_driver.name);
852 } else { 852 } else {
853 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s", 853 printk(KERN_DEBUG "ACPI: acpi_idle yielding to %s\n",
854 cpuidle_get_driver()->name); 854 cpuidle_get_driver()->name);
855 } 855 }
856 856
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index ba1bd263d903..3a73a93596e8 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -447,8 +447,8 @@ int acpi_processor_notify_smm(struct module *calling_module)
447 if (!try_module_get(calling_module)) 447 if (!try_module_get(calling_module))
448 return -EINVAL; 448 return -EINVAL;
449 449
450 /* is_done is set to negative if an error occured, 450 /* is_done is set to negative if an error occurred,
451 * and to postitive if _no_ error occured, but SMM 451 * and to postitive if _no_ error occurred, but SMM
452 * was already notified. This avoids double notification 452 * was already notified. This avoids double notification
453 * which might lead to unexpected results... 453 * which might lead to unexpected results...
454 */ 454 */
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index cf82989ae756..4754ff6e70e6 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -363,6 +363,12 @@ static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
363 return 0; 363 return 0;
364} 364}
365 365
366static int __init init_nvs_nosave(const struct dmi_system_id *d)
367{
368 acpi_nvs_nosave();
369 return 0;
370}
371
366static struct dmi_system_id __initdata acpisleep_dmi_table[] = { 372static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
367 { 373 {
368 .callback = init_old_suspend_ordering, 374 .callback = init_old_suspend_ordering,
@@ -397,6 +403,22 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
397 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"), 403 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
398 }, 404 },
399 }, 405 },
406 {
407 .callback = init_nvs_nosave,
408 .ident = "Sony Vaio VGN-SR11M",
409 .matches = {
410 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
411 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
412 },
413 },
414 {
415 .callback = init_nvs_nosave,
416 .ident = "Everex StepNote Series",
417 .matches = {
418 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
419 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
420 },
421 },
400 {}, 422 {},
401}; 423};
402#endif /* CONFIG_SUSPEND */ 424#endif /* CONFIG_SUSPEND */
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 68e2e4582fa2..f8588f81048a 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -100,7 +100,7 @@ static const struct acpi_dlevel acpi_debug_levels[] = {
100 ACPI_DEBUG_INIT(ACPI_LV_EVENTS), 100 ACPI_DEBUG_INIT(ACPI_LV_EVENTS),
101}; 101};
102 102
103static int param_get_debug_layer(char *buffer, struct kernel_param *kp) 103static int param_get_debug_layer(char *buffer, const struct kernel_param *kp)
104{ 104{
105 int result = 0; 105 int result = 0;
106 int i; 106 int i;
@@ -128,7 +128,7 @@ static int param_get_debug_layer(char *buffer, struct kernel_param *kp)
128 return result; 128 return result;
129} 129}
130 130
131static int param_get_debug_level(char *buffer, struct kernel_param *kp) 131static int param_get_debug_level(char *buffer, const struct kernel_param *kp)
132{ 132{
133 int result = 0; 133 int result = 0;
134 int i; 134 int i;
@@ -149,10 +149,18 @@ static int param_get_debug_level(char *buffer, struct kernel_param *kp)
149 return result; 149 return result;
150} 150}
151 151
152module_param_call(debug_layer, param_set_uint, param_get_debug_layer, 152static struct kernel_param_ops param_ops_debug_layer = {
153 &acpi_dbg_layer, 0644); 153 .set = param_set_uint,
154module_param_call(debug_level, param_set_uint, param_get_debug_level, 154 .get = param_get_debug_layer,
155 &acpi_dbg_level, 0644); 155};
156
157static struct kernel_param_ops param_ops_debug_level = {
158 .set = param_set_uint,
159 .get = param_get_debug_level,
160};
161
162module_param_cb(debug_layer, &param_ops_debug_layer, &acpi_dbg_layer, 0644);
163module_param_cb(debug_level, &param_ops_debug_level, &acpi_dbg_level, 0644);
156 164
157static char trace_method_name[6]; 165static char trace_method_name[6];
158module_param_string(trace_method_name, trace_method_name, 6, 0644); 166module_param_string(trace_method_name, trace_method_name, 6, 0644);
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index c5fef01b3c95..b83676126598 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -59,8 +59,8 @@ acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
59 "support\n")); 59 "support\n"));
60 *cap |= ACPI_VIDEO_BACKLIGHT; 60 *cap |= ACPI_VIDEO_BACKLIGHT;
61 if (ACPI_FAILURE(acpi_get_handle(handle, "_BQC", &h_dummy))) 61 if (ACPI_FAILURE(acpi_get_handle(handle, "_BQC", &h_dummy)))
62 printk(KERN_WARNING FW_BUG PREFIX "ACPI brightness " 62 printk(KERN_WARNING FW_BUG PREFIX "No _BQC method, "
63 "control misses _BQC function\n"); 63 "cannot determine initial brightness\n");
64 /* We have backlight support, no need to scan further */ 64 /* We have backlight support, no need to scan further */
65 return AE_CTRL_TERMINATE; 65 return AE_CTRL_TERMINATE;
66 } 66 }
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index d31590e7011b..2737b9752205 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -298,7 +298,7 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
298 298
299 amba_put_disable_pclk(dev); 299 amba_put_disable_pclk(dev);
300 300
301 if (cid == 0xb105f00d) 301 if (cid == AMBA_CID)
302 dev->periphid = pid; 302 dev->periphid = pid;
303 303
304 if (!dev->periphid) 304 if (!dev->periphid)
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index d5df04a395ca..c501af5b12b9 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -99,7 +99,7 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o
99# Should be last libata driver 99# Should be last libata driver
100obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o 100obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o
101 101
102libata-objs := libata-core.o libata-scsi.o libata-eh.o 102libata-y := libata-core.o libata-scsi.o libata-eh.o libata-transport.o
103libata-$(CONFIG_ATA_SFF) += libata-sff.o 103libata-$(CONFIG_ATA_SFF) += libata-sff.o
104libata-$(CONFIG_SATA_PMP) += libata-pmp.o 104libata-$(CONFIG_SATA_PMP) += libata-pmp.o
105libata-$(CONFIG_ATA_ACPI) += libata-acpi.o 105libata-$(CONFIG_ATA_ACPI) += libata-acpi.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index ff1c945fba98..328826381a2d 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -90,6 +90,10 @@ static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
90static int ahci_pci_device_resume(struct pci_dev *pdev); 90static int ahci_pci_device_resume(struct pci_dev *pdev);
91#endif 91#endif
92 92
93static struct scsi_host_template ahci_sht = {
94 AHCI_SHT("ahci"),
95};
96
93static struct ata_port_operations ahci_vt8251_ops = { 97static struct ata_port_operations ahci_vt8251_ops = {
94 .inherits = &ahci_ops, 98 .inherits = &ahci_ops,
95 .hardreset = ahci_vt8251_hardreset, 99 .hardreset = ahci_vt8251_hardreset,
@@ -1204,9 +1208,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1204 ata_port_pbar_desc(ap, AHCI_PCI_BAR, 1208 ata_port_pbar_desc(ap, AHCI_PCI_BAR,
1205 0x100 + ap->port_no * 0x80, "port"); 1209 0x100 + ap->port_no * 0x80, "port");
1206 1210
1207 /* set initial link pm policy */
1208 ap->pm_policy = NOT_AVAILABLE;
1209
1210 /* set enclosure management message type */ 1211 /* set enclosure management message type */
1211 if (ap->flags & ATA_FLAG_EM) 1212 if (ap->flags & ATA_FLAG_EM)
1212 ap->em_message_type = hpriv->em_msg_type; 1213 ap->em_message_type = hpriv->em_msg_type;
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
index 474427b6f99f..329cbbb91284 100644
--- a/drivers/ata/ahci.h
+++ b/drivers/ata/ahci.h
@@ -72,6 +72,7 @@ enum {
72 AHCI_CMD_RESET = (1 << 8), 72 AHCI_CMD_RESET = (1 << 8),
73 AHCI_CMD_CLR_BUSY = (1 << 10), 73 AHCI_CMD_CLR_BUSY = (1 << 10),
74 74
75 RX_FIS_PIO_SETUP = 0x20, /* offset of PIO Setup FIS data */
75 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ 76 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */
76 RX_FIS_SDB = 0x58, /* offset of SDB FIS data */ 77 RX_FIS_SDB = 0x58, /* offset of SDB FIS data */
77 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */ 78 RX_FIS_UNK = 0x60, /* offset of Unknown FIS data */
@@ -201,7 +202,6 @@ enum {
201 AHCI_HFLAG_MV_PATA = (1 << 4), /* PATA port */ 202 AHCI_HFLAG_MV_PATA = (1 << 4), /* PATA port */
202 AHCI_HFLAG_NO_MSI = (1 << 5), /* no PCI MSI */ 203 AHCI_HFLAG_NO_MSI = (1 << 5), /* no PCI MSI */
203 AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */ 204 AHCI_HFLAG_NO_PMP = (1 << 6), /* no PMP */
204 AHCI_HFLAG_NO_HOTPLUG = (1 << 7), /* ignore PxSERR.DIAG.N */
205 AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */ 205 AHCI_HFLAG_SECT255 = (1 << 8), /* max 255 sectors */
206 AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */ 206 AHCI_HFLAG_YES_NCQ = (1 << 9), /* force NCQ cap on */
207 AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */ 207 AHCI_HFLAG_NO_SUSPEND = (1 << 10), /* don't suspend */
@@ -216,7 +216,7 @@ enum {
216 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 216 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
217 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 217 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
218 ATA_FLAG_ACPI_SATA | ATA_FLAG_AN | 218 ATA_FLAG_ACPI_SATA | ATA_FLAG_AN |
219 ATA_FLAG_IPM, 219 ATA_FLAG_LPM,
220 220
221 ICH_MAP = 0x90, /* ICH MAP register */ 221 ICH_MAP = 0x90, /* ICH MAP register */
222 222
@@ -298,7 +298,17 @@ struct ahci_host_priv {
298 298
299extern int ahci_ignore_sss; 299extern int ahci_ignore_sss;
300 300
301extern struct scsi_host_template ahci_sht; 301extern struct device_attribute *ahci_shost_attrs[];
302extern struct device_attribute *ahci_sdev_attrs[];
303
304#define AHCI_SHT(drv_name) \
305 ATA_NCQ_SHT(drv_name), \
306 .can_queue = AHCI_MAX_CMDS - 1, \
307 .sg_tablesize = AHCI_MAX_SG, \
308 .dma_boundary = AHCI_DMA_BOUNDARY, \
309 .shost_attrs = ahci_shost_attrs, \
310 .sdev_attrs = ahci_sdev_attrs
311
302extern struct ata_port_operations ahci_ops; 312extern struct ata_port_operations ahci_ops;
303 313
304void ahci_save_initial_config(struct device *dev, 314void ahci_save_initial_config(struct device *dev,
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index 4e97f33cca44..6fef1fa75c54 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -23,6 +23,10 @@
23#include <linux/ahci_platform.h> 23#include <linux/ahci_platform.h>
24#include "ahci.h" 24#include "ahci.h"
25 25
26static struct scsi_host_template ahci_platform_sht = {
27 AHCI_SHT("ahci_platform"),
28};
29
26static int __init ahci_probe(struct platform_device *pdev) 30static int __init ahci_probe(struct platform_device *pdev)
27{ 31{
28 struct device *dev = &pdev->dev; 32 struct device *dev = &pdev->dev;
@@ -125,9 +129,6 @@ static int __init ahci_probe(struct platform_device *pdev)
125 ata_port_desc(ap, "mmio %pR", mem); 129 ata_port_desc(ap, "mmio %pR", mem);
126 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80); 130 ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
127 131
128 /* set initial link pm policy */
129 ap->pm_policy = NOT_AVAILABLE;
130
131 /* set enclosure management message type */ 132 /* set enclosure management message type */
132 if (ap->flags & ATA_FLAG_EM) 133 if (ap->flags & ATA_FLAG_EM)
133 ap->em_message_type = hpriv->em_msg_type; 134 ap->em_message_type = hpriv->em_msg_type;
@@ -145,7 +146,7 @@ static int __init ahci_probe(struct platform_device *pdev)
145 ahci_print_info(host, "platform"); 146 ahci_print_info(host, "platform");
146 147
147 rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED, 148 rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
148 &ahci_sht); 149 &ahci_platform_sht);
149 if (rc) 150 if (rc)
150 goto err0; 151 goto err0;
151 152
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index cc5f7726bde7..6981f7680a00 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -35,6 +35,7 @@
35enum { 35enum {
36 ATA_GEN_CLASS_MATCH = (1 << 0), 36 ATA_GEN_CLASS_MATCH = (1 << 0),
37 ATA_GEN_FORCE_DMA = (1 << 1), 37 ATA_GEN_FORCE_DMA = (1 << 1),
38 ATA_GEN_INTEL_IDER = (1 << 2),
38}; 39};
39 40
40/** 41/**
@@ -109,6 +110,49 @@ static struct ata_port_operations generic_port_ops = {
109static int all_generic_ide; /* Set to claim all devices */ 110static int all_generic_ide; /* Set to claim all devices */
110 111
111/** 112/**
113 * is_intel_ider - identify intel IDE-R devices
114 * @dev: PCI device
115 *
116 * Distinguish Intel IDE-R controller devices from other Intel IDE
117 * devices. IDE-R devices have no timing registers and are in
118 * most respects virtual. They should be driven by the ata_generic
119 * driver.
120 *
121 * IDE-R devices have PCI offset 0xF8.L as zero, later Intel ATA has
122 * it non zero. All Intel ATA has 0x40 writable (timing), but it is
123 * not writable on IDE-R devices (this is guaranteed).
124 */
125
126static int is_intel_ider(struct pci_dev *dev)
127{
128 /* For Intel IDE the value at 0xF8 is only zero on IDE-R
129 interfaces */
130 u32 r;
131 u16 t;
132
133 /* Check the manufacturing ID, it will be zero for IDE-R */
134 pci_read_config_dword(dev, 0xF8, &r);
135 /* Not IDE-R: punt so that ata_(old)piix gets it */
136 if (r != 0)
137 return 0;
138 /* 0xF8 will also be zero on some early Intel IDE devices
139 but they will have a sane timing register */
140 pci_read_config_word(dev, 0x40, &t);
141 if (t != 0)
142 return 0;
143 /* Finally check if the timing register is writable so that
144 we eliminate any early devices hot-docked in a docking
145 station */
146 pci_write_config_word(dev, 0x40, 1);
147 pci_read_config_word(dev, 0x40, &t);
148 if (t) {
149 pci_write_config_word(dev, 0x40, 0);
150 return 0;
151 }
152 return 1;
153}
154
155/**
112 * ata_generic_init - attach generic IDE 156 * ata_generic_init - attach generic IDE
113 * @dev: PCI device found 157 * @dev: PCI device found
114 * @id: match entry 158 * @id: match entry
@@ -134,6 +178,10 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
134 if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0) 178 if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0)
135 return -ENODEV; 179 return -ENODEV;
136 180
181 if (id->driver_data & ATA_GEN_INTEL_IDER)
182 if (!is_intel_ider(dev))
183 return -ENODEV;
184
137 /* Devices that need care */ 185 /* Devices that need care */
138 if (dev->vendor == PCI_VENDOR_ID_UMC && 186 if (dev->vendor == PCI_VENDOR_ID_UMC &&
139 dev->device == PCI_DEVICE_ID_UMC_UM8886A && 187 dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
@@ -186,7 +234,11 @@ static struct pci_device_id ata_generic[] = {
186 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), }, 234 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
187 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), }, 235 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), },
188 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), }, 236 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), },
189#endif 237#endif
238 /* Intel, IDE class device */
239 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
240 PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL,
241 .driver_data = ATA_GEN_INTEL_IDER },
190 /* Must come last. If you add entries adjust this table appropriately */ 242 /* Must come last. If you add entries adjust this table appropriately */
191 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL), 243 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL),
192 .driver_data = ATA_GEN_CLASS_MATCH }, 244 .driver_data = ATA_GEN_CLASS_MATCH },
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index d712675d0a96..6cb14ca8ee85 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -158,7 +158,6 @@ struct piix_map_db {
158struct piix_host_priv { 158struct piix_host_priv {
159 const int *map; 159 const int *map;
160 u32 saved_iocfg; 160 u32 saved_iocfg;
161 spinlock_t sidpr_lock; /* FIXME: remove once locking in EH is fixed */
162 void __iomem *sidpr; 161 void __iomem *sidpr;
163}; 162};
164 163
@@ -175,6 +174,8 @@ static int piix_sidpr_scr_read(struct ata_link *link,
175 unsigned int reg, u32 *val); 174 unsigned int reg, u32 *val);
176static int piix_sidpr_scr_write(struct ata_link *link, 175static int piix_sidpr_scr_write(struct ata_link *link,
177 unsigned int reg, u32 val); 176 unsigned int reg, u32 val);
177static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
178 unsigned hints);
178static bool piix_irq_check(struct ata_port *ap); 179static bool piix_irq_check(struct ata_port *ap);
179#ifdef CONFIG_PM 180#ifdef CONFIG_PM
180static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 181static int piix_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
@@ -209,6 +210,8 @@ static const struct pci_device_id piix_pci_tbl[] = {
209 { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 210 { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
210 /* Intel ICH3 (E7500/1) UDMA 100 */ 211 /* Intel ICH3 (E7500/1) UDMA 100 */
211 { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 212 { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
213 /* Intel ICH4-L */
214 { 0x8086, 0x24C1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
212 /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */ 215 /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */
213 { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 216 { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
214 { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 217 { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
@@ -348,11 +351,22 @@ static struct ata_port_operations ich_pata_ops = {
348 .set_dmamode = ich_set_dmamode, 351 .set_dmamode = ich_set_dmamode,
349}; 352};
350 353
354static struct device_attribute *piix_sidpr_shost_attrs[] = {
355 &dev_attr_link_power_management_policy,
356 NULL
357};
358
359static struct scsi_host_template piix_sidpr_sht = {
360 ATA_BMDMA_SHT(DRV_NAME),
361 .shost_attrs = piix_sidpr_shost_attrs,
362};
363
351static struct ata_port_operations piix_sidpr_sata_ops = { 364static struct ata_port_operations piix_sidpr_sata_ops = {
352 .inherits = &piix_sata_ops, 365 .inherits = &piix_sata_ops,
353 .hardreset = sata_std_hardreset, 366 .hardreset = sata_std_hardreset,
354 .scr_read = piix_sidpr_scr_read, 367 .scr_read = piix_sidpr_scr_read,
355 .scr_write = piix_sidpr_scr_write, 368 .scr_write = piix_sidpr_scr_write,
369 .set_lpm = piix_sidpr_set_lpm,
356}; 370};
357 371
358static const struct piix_map_db ich5_map_db = { 372static const struct piix_map_db ich5_map_db = {
@@ -956,15 +970,12 @@ static int piix_sidpr_scr_read(struct ata_link *link,
956 unsigned int reg, u32 *val) 970 unsigned int reg, u32 *val)
957{ 971{
958 struct piix_host_priv *hpriv = link->ap->host->private_data; 972 struct piix_host_priv *hpriv = link->ap->host->private_data;
959 unsigned long flags;
960 973
961 if (reg >= ARRAY_SIZE(piix_sidx_map)) 974 if (reg >= ARRAY_SIZE(piix_sidx_map))
962 return -EINVAL; 975 return -EINVAL;
963 976
964 spin_lock_irqsave(&hpriv->sidpr_lock, flags);
965 piix_sidpr_sel(link, reg); 977 piix_sidpr_sel(link, reg);
966 *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA); 978 *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA);
967 spin_unlock_irqrestore(&hpriv->sidpr_lock, flags);
968 return 0; 979 return 0;
969} 980}
970 981
@@ -972,18 +983,21 @@ static int piix_sidpr_scr_write(struct ata_link *link,
972 unsigned int reg, u32 val) 983 unsigned int reg, u32 val)
973{ 984{
974 struct piix_host_priv *hpriv = link->ap->host->private_data; 985 struct piix_host_priv *hpriv = link->ap->host->private_data;
975 unsigned long flags;
976 986
977 if (reg >= ARRAY_SIZE(piix_sidx_map)) 987 if (reg >= ARRAY_SIZE(piix_sidx_map))
978 return -EINVAL; 988 return -EINVAL;
979 989
980 spin_lock_irqsave(&hpriv->sidpr_lock, flags);
981 piix_sidpr_sel(link, reg); 990 piix_sidpr_sel(link, reg);
982 iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA); 991 iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA);
983 spin_unlock_irqrestore(&hpriv->sidpr_lock, flags);
984 return 0; 992 return 0;
985} 993}
986 994
995static int piix_sidpr_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
996 unsigned hints)
997{
998 return sata_link_scr_lpm(link, policy, false);
999}
1000
987static bool piix_irq_check(struct ata_port *ap) 1001static bool piix_irq_check(struct ata_port *ap)
988{ 1002{
989 if (unlikely(!ap->ioaddr.bmdma_addr)) 1003 if (unlikely(!ap->ioaddr.bmdma_addr))
@@ -1543,6 +1557,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1543 struct device *dev = &pdev->dev; 1557 struct device *dev = &pdev->dev;
1544 struct ata_port_info port_info[2]; 1558 struct ata_port_info port_info[2];
1545 const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] }; 1559 const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
1560 struct scsi_host_template *sht = &piix_sht;
1546 unsigned long port_flags; 1561 unsigned long port_flags;
1547 struct ata_host *host; 1562 struct ata_host *host;
1548 struct piix_host_priv *hpriv; 1563 struct piix_host_priv *hpriv;
@@ -1577,7 +1592,6 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1577 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); 1592 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1578 if (!hpriv) 1593 if (!hpriv)
1579 return -ENOMEM; 1594 return -ENOMEM;
1580 spin_lock_init(&hpriv->sidpr_lock);
1581 1595
1582 /* Save IOCFG, this will be used for cable detection, quirk 1596 /* Save IOCFG, this will be used for cable detection, quirk
1583 * detection and restoration on detach. This is necessary 1597 * detection and restoration on detach. This is necessary
@@ -1612,6 +1626,8 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1612 rc = piix_init_sidpr(host); 1626 rc = piix_init_sidpr(host);
1613 if (rc) 1627 if (rc)
1614 return rc; 1628 return rc;
1629 if (host->ports[0]->ops == &piix_sidpr_sata_ops)
1630 sht = &piix_sidpr_sht;
1615 } 1631 }
1616 1632
1617 /* apply IOCFG bit18 quirk */ 1633 /* apply IOCFG bit18 quirk */
@@ -1638,7 +1654,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1638 host->flags |= ATA_HOST_PARALLEL_SCAN; 1654 host->flags |= ATA_HOST_PARALLEL_SCAN;
1639 1655
1640 pci_set_master(pdev); 1656 pci_set_master(pdev);
1641 return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, &piix_sht); 1657 return ata_pci_sff_activate_host(host, ata_bmdma_interrupt, sht);
1642} 1658}
1643 1659
1644static void piix_remove_one(struct pci_dev *pdev) 1660static void piix_remove_one(struct pci_dev *pdev)
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 68dc6785472f..ebc08d65b3dd 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -56,9 +56,8 @@ MODULE_PARM_DESC(skip_host_reset, "skip global host reset (0=don't skip, 1=skip)
56module_param_named(ignore_sss, ahci_ignore_sss, int, 0444); 56module_param_named(ignore_sss, ahci_ignore_sss, int, 0444);
57MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)"); 57MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)");
58 58
59static int ahci_enable_alpm(struct ata_port *ap, 59static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
60 enum link_pm policy); 60 unsigned hints);
61static void ahci_disable_alpm(struct ata_port *ap);
62static ssize_t ahci_led_show(struct ata_port *ap, char *buf); 61static ssize_t ahci_led_show(struct ata_port *ap, char *buf);
63static ssize_t ahci_led_store(struct ata_port *ap, const char *buf, 62static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
64 size_t size); 63 size_t size);
@@ -121,7 +120,7 @@ static DEVICE_ATTR(ahci_port_cmd, S_IRUGO, ahci_show_port_cmd, NULL);
121static DEVICE_ATTR(em_buffer, S_IWUSR | S_IRUGO, 120static DEVICE_ATTR(em_buffer, S_IWUSR | S_IRUGO,
122 ahci_read_em_buffer, ahci_store_em_buffer); 121 ahci_read_em_buffer, ahci_store_em_buffer);
123 122
124static struct device_attribute *ahci_shost_attrs[] = { 123struct device_attribute *ahci_shost_attrs[] = {
125 &dev_attr_link_power_management_policy, 124 &dev_attr_link_power_management_policy,
126 &dev_attr_em_message_type, 125 &dev_attr_em_message_type,
127 &dev_attr_em_message, 126 &dev_attr_em_message,
@@ -132,22 +131,14 @@ static struct device_attribute *ahci_shost_attrs[] = {
132 &dev_attr_em_buffer, 131 &dev_attr_em_buffer,
133 NULL 132 NULL
134}; 133};
134EXPORT_SYMBOL_GPL(ahci_shost_attrs);
135 135
136static struct device_attribute *ahci_sdev_attrs[] = { 136struct device_attribute *ahci_sdev_attrs[] = {
137 &dev_attr_sw_activity, 137 &dev_attr_sw_activity,
138 &dev_attr_unload_heads, 138 &dev_attr_unload_heads,
139 NULL 139 NULL
140}; 140};
141 141EXPORT_SYMBOL_GPL(ahci_sdev_attrs);
142struct scsi_host_template ahci_sht = {
143 ATA_NCQ_SHT("ahci"),
144 .can_queue = AHCI_MAX_CMDS - 1,
145 .sg_tablesize = AHCI_MAX_SG,
146 .dma_boundary = AHCI_DMA_BOUNDARY,
147 .shost_attrs = ahci_shost_attrs,
148 .sdev_attrs = ahci_sdev_attrs,
149};
150EXPORT_SYMBOL_GPL(ahci_sht);
151 142
152struct ata_port_operations ahci_ops = { 143struct ata_port_operations ahci_ops = {
153 .inherits = &sata_pmp_port_ops, 144 .inherits = &sata_pmp_port_ops,
@@ -172,8 +163,7 @@ struct ata_port_operations ahci_ops = {
172 .pmp_attach = ahci_pmp_attach, 163 .pmp_attach = ahci_pmp_attach,
173 .pmp_detach = ahci_pmp_detach, 164 .pmp_detach = ahci_pmp_detach,
174 165
175 .enable_pm = ahci_enable_alpm, 166 .set_lpm = ahci_set_lpm,
176 .disable_pm = ahci_disable_alpm,
177 .em_show = ahci_led_show, 167 .em_show = ahci_led_show,
178 .em_store = ahci_led_store, 168 .em_store = ahci_led_store,
179 .sw_activity_show = ahci_activity_show, 169 .sw_activity_show = ahci_activity_show,
@@ -577,7 +567,7 @@ int ahci_stop_engine(struct ata_port *ap)
577 writel(tmp, port_mmio + PORT_CMD); 567 writel(tmp, port_mmio + PORT_CMD);
578 568
579 /* wait for engine to stop. This could be as long as 500 msec */ 569 /* wait for engine to stop. This could be as long as 500 msec */
580 tmp = ata_wait_register(port_mmio + PORT_CMD, 570 tmp = ata_wait_register(ap, port_mmio + PORT_CMD,
581 PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500); 571 PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
582 if (tmp & PORT_CMD_LIST_ON) 572 if (tmp & PORT_CMD_LIST_ON)
583 return -EIO; 573 return -EIO;
@@ -624,7 +614,7 @@ static int ahci_stop_fis_rx(struct ata_port *ap)
624 writel(tmp, port_mmio + PORT_CMD); 614 writel(tmp, port_mmio + PORT_CMD);
625 615
626 /* wait for completion, spec says 500ms, give it 1000 */ 616 /* wait for completion, spec says 500ms, give it 1000 */
627 tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON, 617 tmp = ata_wait_register(ap, port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
628 PORT_CMD_FIS_ON, 10, 1000); 618 PORT_CMD_FIS_ON, 10, 1000);
629 if (tmp & PORT_CMD_FIS_ON) 619 if (tmp & PORT_CMD_FIS_ON)
630 return -EBUSY; 620 return -EBUSY;
@@ -650,127 +640,56 @@ static void ahci_power_up(struct ata_port *ap)
650 writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD); 640 writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD);
651} 641}
652 642
653static void ahci_disable_alpm(struct ata_port *ap) 643static int ahci_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
644 unsigned int hints)
654{ 645{
646 struct ata_port *ap = link->ap;
655 struct ahci_host_priv *hpriv = ap->host->private_data; 647 struct ahci_host_priv *hpriv = ap->host->private_data;
656 void __iomem *port_mmio = ahci_port_base(ap);
657 u32 cmd;
658 struct ahci_port_priv *pp = ap->private_data; 648 struct ahci_port_priv *pp = ap->private_data;
659
660 /* IPM bits should be disabled by libata-core */
661 /* get the existing command bits */
662 cmd = readl(port_mmio + PORT_CMD);
663
664 /* disable ALPM and ASP */
665 cmd &= ~PORT_CMD_ASP;
666 cmd &= ~PORT_CMD_ALPE;
667
668 /* force the interface back to active */
669 cmd |= PORT_CMD_ICC_ACTIVE;
670
671 /* write out new cmd value */
672 writel(cmd, port_mmio + PORT_CMD);
673 cmd = readl(port_mmio + PORT_CMD);
674
675 /* wait 10ms to be sure we've come out of any low power state */
676 msleep(10);
677
678 /* clear out any PhyRdy stuff from interrupt status */
679 writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT);
680
681 /* go ahead and clean out PhyRdy Change from Serror too */
682 ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
683
684 /*
685 * Clear flag to indicate that we should ignore all PhyRdy
686 * state changes
687 */
688 hpriv->flags &= ~AHCI_HFLAG_NO_HOTPLUG;
689
690 /*
691 * Enable interrupts on Phy Ready.
692 */
693 pp->intr_mask |= PORT_IRQ_PHYRDY;
694 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
695
696 /*
697 * don't change the link pm policy - we can be called
698 * just to turn of link pm temporarily
699 */
700}
701
702static int ahci_enable_alpm(struct ata_port *ap,
703 enum link_pm policy)
704{
705 struct ahci_host_priv *hpriv = ap->host->private_data;
706 void __iomem *port_mmio = ahci_port_base(ap); 649 void __iomem *port_mmio = ahci_port_base(ap);
707 u32 cmd;
708 struct ahci_port_priv *pp = ap->private_data;
709 u32 asp;
710
711 /* Make sure the host is capable of link power management */
712 if (!(hpriv->cap & HOST_CAP_ALPM))
713 return -EINVAL;
714 650
715 switch (policy) { 651 if (policy != ATA_LPM_MAX_POWER) {
716 case MAX_PERFORMANCE:
717 case NOT_AVAILABLE:
718 /* 652 /*
719 * if we came here with NOT_AVAILABLE, 653 * Disable interrupts on Phy Ready. This keeps us from
720 * it just means this is the first time we 654 * getting woken up due to spurious phy ready
721 * have tried to enable - default to max performance, 655 * interrupts.
722 * and let the user go to lower power modes on request.
723 */ 656 */
724 ahci_disable_alpm(ap); 657 pp->intr_mask &= ~PORT_IRQ_PHYRDY;
725 return 0; 658 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
726 case MIN_POWER: 659
727 /* configure HBA to enter SLUMBER */ 660 sata_link_scr_lpm(link, policy, false);
728 asp = PORT_CMD_ASP;
729 break;
730 case MEDIUM_POWER:
731 /* configure HBA to enter PARTIAL */
732 asp = 0;
733 break;
734 default:
735 return -EINVAL;
736 } 661 }
737 662
738 /* 663 if (hpriv->cap & HOST_CAP_ALPM) {
739 * Disable interrupts on Phy Ready. This keeps us from 664 u32 cmd = readl(port_mmio + PORT_CMD);
740 * getting woken up due to spurious phy ready interrupts
741 * TBD - Hot plug should be done via polling now, is
742 * that even supported?
743 */
744 pp->intr_mask &= ~PORT_IRQ_PHYRDY;
745 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
746 665
747 /* 666 if (policy == ATA_LPM_MAX_POWER || !(hints & ATA_LPM_HIPM)) {
748 * Set a flag to indicate that we should ignore all PhyRdy 667 cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE);
749 * state changes since these can happen now whenever we 668 cmd |= PORT_CMD_ICC_ACTIVE;
750 * change link state
751 */
752 hpriv->flags |= AHCI_HFLAG_NO_HOTPLUG;
753 669
754 /* get the existing command bits */ 670 writel(cmd, port_mmio + PORT_CMD);
755 cmd = readl(port_mmio + PORT_CMD); 671 readl(port_mmio + PORT_CMD);
756 672
757 /* 673 /* wait 10ms to be sure we've come out of LPM state */
758 * Set ASP based on Policy 674 ata_msleep(ap, 10);
759 */ 675 } else {
760 cmd |= asp; 676 cmd |= PORT_CMD_ALPE;
677 if (policy == ATA_LPM_MIN_POWER)
678 cmd |= PORT_CMD_ASP;
761 679
762 /* 680 /* write out new cmd value */
763 * Setting this bit will instruct the HBA to aggressively 681 writel(cmd, port_mmio + PORT_CMD);
764 * enter a lower power link state when it's appropriate and 682 }
765 * based on the value set above for ASP 683 }
766 */
767 cmd |= PORT_CMD_ALPE;
768 684
769 /* write out new cmd value */ 685 if (policy == ATA_LPM_MAX_POWER) {
770 writel(cmd, port_mmio + PORT_CMD); 686 sata_link_scr_lpm(link, policy, false);
771 cmd = readl(port_mmio + PORT_CMD); 687
688 /* turn PHYRDY IRQ back on */
689 pp->intr_mask |= PORT_IRQ_PHYRDY;
690 writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
691 }
772 692
773 /* IPM bits should be set by libata-core */
774 return 0; 693 return 0;
775} 694}
776 695
@@ -821,7 +740,7 @@ static void ahci_start_port(struct ata_port *ap)
821 emp->led_state, 740 emp->led_state,
822 4); 741 4);
823 if (rc == -EBUSY) 742 if (rc == -EBUSY)
824 msleep(1); 743 ata_msleep(ap, 1);
825 else 744 else
826 break; 745 break;
827 } 746 }
@@ -880,7 +799,7 @@ int ahci_reset_controller(struct ata_host *host)
880 * reset must complete within 1 second, or 799 * reset must complete within 1 second, or
881 * the hardware should be considered fried. 800 * the hardware should be considered fried.
882 */ 801 */
883 tmp = ata_wait_register(mmio + HOST_CTL, HOST_RESET, 802 tmp = ata_wait_register(NULL, mmio + HOST_CTL, HOST_RESET,
884 HOST_RESET, 10, 1000); 803 HOST_RESET, 10, 1000);
885 804
886 if (tmp & HOST_RESET) { 805 if (tmp & HOST_RESET) {
@@ -1260,7 +1179,7 @@ int ahci_kick_engine(struct ata_port *ap)
1260 writel(tmp, port_mmio + PORT_CMD); 1179 writel(tmp, port_mmio + PORT_CMD);
1261 1180
1262 rc = 0; 1181 rc = 0;
1263 tmp = ata_wait_register(port_mmio + PORT_CMD, 1182 tmp = ata_wait_register(ap, port_mmio + PORT_CMD,
1264 PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); 1183 PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
1265 if (tmp & PORT_CMD_CLO) 1184 if (tmp & PORT_CMD_CLO)
1266 rc = -EIO; 1185 rc = -EIO;
@@ -1290,8 +1209,8 @@ static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
1290 writel(1, port_mmio + PORT_CMD_ISSUE); 1209 writel(1, port_mmio + PORT_CMD_ISSUE);
1291 1210
1292 if (timeout_msec) { 1211 if (timeout_msec) {
1293 tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, 1212 tmp = ata_wait_register(ap, port_mmio + PORT_CMD_ISSUE,
1294 1, timeout_msec); 1213 0x1, 0x1, 1, timeout_msec);
1295 if (tmp & 0x1) { 1214 if (tmp & 0x1) {
1296 ahci_kick_engine(ap); 1215 ahci_kick_engine(ap);
1297 return -EBUSY; 1216 return -EBUSY;
@@ -1338,7 +1257,7 @@ int ahci_do_softreset(struct ata_link *link, unsigned int *class,
1338 } 1257 }
1339 1258
1340 /* spec says at least 5us, but be generous and sleep for 1ms */ 1259 /* spec says at least 5us, but be generous and sleep for 1ms */
1341 msleep(1); 1260 ata_msleep(ap, 1);
1342 1261
1343 /* issue the second D2H Register FIS */ 1262 /* issue the second D2H Register FIS */
1344 tf.ctl &= ~ATA_SRST; 1263 tf.ctl &= ~ATA_SRST;
@@ -1668,15 +1587,10 @@ static void ahci_port_intr(struct ata_port *ap)
1668 if (unlikely(resetting)) 1587 if (unlikely(resetting))
1669 status &= ~PORT_IRQ_BAD_PMP; 1588 status &= ~PORT_IRQ_BAD_PMP;
1670 1589
1671 /* If we are getting PhyRdy, this is 1590 /* if LPM is enabled, PHYRDY doesn't mean anything */
1672 * just a power state change, we should 1591 if (ap->link.lpm_policy > ATA_LPM_MAX_POWER) {
1673 * clear out this, plus the PhyRdy/Comm
1674 * Wake bits from Serror
1675 */
1676 if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) &&
1677 (status & PORT_IRQ_PHYRDY)) {
1678 status &= ~PORT_IRQ_PHYRDY; 1592 status &= ~PORT_IRQ_PHYRDY;
1679 ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18))); 1593 ahci_scr_write(&ap->link, SCR_ERROR, SERR_PHYRDY_CHG);
1680 } 1594 }
1681 1595
1682 if (unlikely(status & PORT_IRQ_ERROR)) { 1596 if (unlikely(status & PORT_IRQ_ERROR)) {
@@ -1838,12 +1752,24 @@ static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
1838static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc) 1752static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc)
1839{ 1753{
1840 struct ahci_port_priv *pp = qc->ap->private_data; 1754 struct ahci_port_priv *pp = qc->ap->private_data;
1841 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 1755 u8 *rx_fis = pp->rx_fis;
1842 1756
1843 if (pp->fbs_enabled) 1757 if (pp->fbs_enabled)
1844 d2h_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ; 1758 rx_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ;
1759
1760 /*
1761 * After a successful execution of an ATA PIO data-in command,
1762 * the device doesn't send D2H Reg FIS to update the TF and
1763 * the host should take TF and E_Status from the preceding PIO
1764 * Setup FIS.
1765 */
1766 if (qc->tf.protocol == ATA_PROT_PIO && qc->dma_dir == DMA_FROM_DEVICE &&
1767 !(qc->flags & ATA_QCFLAG_FAILED)) {
1768 ata_tf_from_fis(rx_fis + RX_FIS_PIO_SETUP, &qc->result_tf);
1769 qc->result_tf.command = (rx_fis + RX_FIS_PIO_SETUP)[15];
1770 } else
1771 ata_tf_from_fis(rx_fis + RX_FIS_D2H_REG, &qc->result_tf);
1845 1772
1846 ata_tf_from_fis(d2h_fis, &qc->result_tf);
1847 return true; 1773 return true;
1848} 1774}
1849 1775
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 932eaee50245..7f77c67d267c 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -68,7 +68,7 @@
68#include <linux/ratelimit.h> 68#include <linux/ratelimit.h>
69 69
70#include "libata.h" 70#include "libata.h"
71 71#include "libata-transport.h"
72 72
73/* debounce timing parameters in msecs { interval, duration, timeout } */ 73/* debounce timing parameters in msecs { interval, duration, timeout } */
74const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; 74const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 };
@@ -91,8 +91,6 @@ const struct ata_port_operations sata_port_ops = {
91static unsigned int ata_dev_init_params(struct ata_device *dev, 91static unsigned int ata_dev_init_params(struct ata_device *dev,
92 u16 heads, u16 sectors); 92 u16 heads, u16 sectors);
93static unsigned int ata_dev_set_xfermode(struct ata_device *dev); 93static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
94static unsigned int ata_dev_set_feature(struct ata_device *dev,
95 u8 enable, u8 feature);
96static void ata_dev_xfermask(struct ata_device *dev); 94static void ata_dev_xfermask(struct ata_device *dev);
97static unsigned long ata_dev_blacklisted(const struct ata_device *dev); 95static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
98 96
@@ -1017,7 +1015,7 @@ const char *ata_mode_string(unsigned long xfer_mask)
1017 return "<n/a>"; 1015 return "<n/a>";
1018} 1016}
1019 1017
1020static const char *sata_spd_string(unsigned int spd) 1018const char *sata_spd_string(unsigned int spd)
1021{ 1019{
1022 static const char * const spd_str[] = { 1020 static const char * const spd_str[] = {
1023 "1.5 Gbps", 1021 "1.5 Gbps",
@@ -1030,182 +1028,6 @@ static const char *sata_spd_string(unsigned int spd)
1030 return spd_str[spd - 1]; 1028 return spd_str[spd - 1];
1031} 1029}
1032 1030
1033static int ata_dev_set_dipm(struct ata_device *dev, enum link_pm policy)
1034{
1035 struct ata_link *link = dev->link;
1036 struct ata_port *ap = link->ap;
1037 u32 scontrol;
1038 unsigned int err_mask;
1039 int rc;
1040
1041 /*
1042 * disallow DIPM for drivers which haven't set
1043 * ATA_FLAG_IPM. This is because when DIPM is enabled,
1044 * phy ready will be set in the interrupt status on
1045 * state changes, which will cause some drivers to
1046 * think there are errors - additionally drivers will
1047 * need to disable hot plug.
1048 */
1049 if (!(ap->flags & ATA_FLAG_IPM) || !ata_dev_enabled(dev)) {
1050 ap->pm_policy = NOT_AVAILABLE;
1051 return -EINVAL;
1052 }
1053
1054 /*
1055 * For DIPM, we will only enable it for the
1056 * min_power setting.
1057 *
1058 * Why? Because Disks are too stupid to know that
1059 * If the host rejects a request to go to SLUMBER
1060 * they should retry at PARTIAL, and instead it
1061 * just would give up. So, for medium_power to
1062 * work at all, we need to only allow HIPM.
1063 */
1064 rc = sata_scr_read(link, SCR_CONTROL, &scontrol);
1065 if (rc)
1066 return rc;
1067
1068 switch (policy) {
1069 case MIN_POWER:
1070 /* no restrictions on IPM transitions */
1071 scontrol &= ~(0x3 << 8);
1072 rc = sata_scr_write(link, SCR_CONTROL, scontrol);
1073 if (rc)
1074 return rc;
1075
1076 /* enable DIPM */
1077 if (dev->flags & ATA_DFLAG_DIPM)
1078 err_mask = ata_dev_set_feature(dev,
1079 SETFEATURES_SATA_ENABLE, SATA_DIPM);
1080 break;
1081 case MEDIUM_POWER:
1082 /* allow IPM to PARTIAL */
1083 scontrol &= ~(0x1 << 8);
1084 scontrol |= (0x2 << 8);
1085 rc = sata_scr_write(link, SCR_CONTROL, scontrol);
1086 if (rc)
1087 return rc;
1088
1089 /*
1090 * we don't have to disable DIPM since IPM flags
1091 * disallow transitions to SLUMBER, which effectively
1092 * disable DIPM if it does not support PARTIAL
1093 */
1094 break;
1095 case NOT_AVAILABLE:
1096 case MAX_PERFORMANCE:
1097 /* disable all IPM transitions */
1098 scontrol |= (0x3 << 8);
1099 rc = sata_scr_write(link, SCR_CONTROL, scontrol);
1100 if (rc)
1101 return rc;
1102
1103 /*
1104 * we don't have to disable DIPM since IPM flags
1105 * disallow all transitions which effectively
1106 * disable DIPM anyway.
1107 */
1108 break;
1109 }
1110
1111 /* FIXME: handle SET FEATURES failure */
1112 (void) err_mask;
1113
1114 return 0;
1115}
1116
1117/**
1118 * ata_dev_enable_pm - enable SATA interface power management
1119 * @dev: device to enable power management
1120 * @policy: the link power management policy
1121 *
1122 * Enable SATA Interface power management. This will enable
1123 * Device Interface Power Management (DIPM) for min_power
1124 * policy, and then call driver specific callbacks for
1125 * enabling Host Initiated Power management.
1126 *
1127 * Locking: Caller.
1128 * Returns: -EINVAL if IPM is not supported, 0 otherwise.
1129 */
1130void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy)
1131{
1132 int rc = 0;
1133 struct ata_port *ap = dev->link->ap;
1134
1135 /* set HIPM first, then DIPM */
1136 if (ap->ops->enable_pm)
1137 rc = ap->ops->enable_pm(ap, policy);
1138 if (rc)
1139 goto enable_pm_out;
1140 rc = ata_dev_set_dipm(dev, policy);
1141
1142enable_pm_out:
1143 if (rc)
1144 ap->pm_policy = MAX_PERFORMANCE;
1145 else
1146 ap->pm_policy = policy;
1147 return /* rc */; /* hopefully we can use 'rc' eventually */
1148}
1149
1150#ifdef CONFIG_PM
1151/**
1152 * ata_dev_disable_pm - disable SATA interface power management
1153 * @dev: device to disable power management
1154 *
1155 * Disable SATA Interface power management. This will disable
1156 * Device Interface Power Management (DIPM) without changing
1157 * policy, call driver specific callbacks for disabling Host
1158 * Initiated Power management.
1159 *
1160 * Locking: Caller.
1161 * Returns: void
1162 */
1163static void ata_dev_disable_pm(struct ata_device *dev)
1164{
1165 struct ata_port *ap = dev->link->ap;
1166
1167 ata_dev_set_dipm(dev, MAX_PERFORMANCE);
1168 if (ap->ops->disable_pm)
1169 ap->ops->disable_pm(ap);
1170}
1171#endif /* CONFIG_PM */
1172
1173void ata_lpm_schedule(struct ata_port *ap, enum link_pm policy)
1174{
1175 ap->pm_policy = policy;
1176 ap->link.eh_info.action |= ATA_EH_LPM;
1177 ap->link.eh_info.flags |= ATA_EHI_NO_AUTOPSY;
1178 ata_port_schedule_eh(ap);
1179}
1180
1181#ifdef CONFIG_PM
1182static void ata_lpm_enable(struct ata_host *host)
1183{
1184 struct ata_link *link;
1185 struct ata_port *ap;
1186 struct ata_device *dev;
1187 int i;
1188
1189 for (i = 0; i < host->n_ports; i++) {
1190 ap = host->ports[i];
1191 ata_for_each_link(link, ap, EDGE) {
1192 ata_for_each_dev(dev, link, ALL)
1193 ata_dev_disable_pm(dev);
1194 }
1195 }
1196}
1197
1198static void ata_lpm_disable(struct ata_host *host)
1199{
1200 int i;
1201
1202 for (i = 0; i < host->n_ports; i++) {
1203 struct ata_port *ap = host->ports[i];
1204 ata_lpm_schedule(ap, ap->pm_policy);
1205 }
1206}
1207#endif /* CONFIG_PM */
1208
1209/** 1031/**
1210 * ata_dev_classify - determine device type based on ATA-spec signature 1032 * ata_dev_classify - determine device type based on ATA-spec signature
1211 * @tf: ATA taskfile register set for device to be identified 1033 * @tf: ATA taskfile register set for device to be identified
@@ -1806,8 +1628,14 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1806 } 1628 }
1807 } 1629 }
1808 1630
1631 if (ap->ops->error_handler)
1632 ata_eh_release(ap);
1633
1809 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout)); 1634 rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout));
1810 1635
1636 if (ap->ops->error_handler)
1637 ata_eh_acquire(ap);
1638
1811 ata_sff_flush_pio_task(ap); 1639 ata_sff_flush_pio_task(ap);
1812 1640
1813 if (!rc) { 1641 if (!rc) {
@@ -2564,13 +2392,6 @@ int ata_dev_configure(struct ata_device *dev)
2564 if (dev->flags & ATA_DFLAG_LBA48) 2392 if (dev->flags & ATA_DFLAG_LBA48)
2565 dev->max_sectors = ATA_MAX_SECTORS_LBA48; 2393 dev->max_sectors = ATA_MAX_SECTORS_LBA48;
2566 2394
2567 if (!(dev->horkage & ATA_HORKAGE_IPM)) {
2568 if (ata_id_has_hipm(dev->id))
2569 dev->flags |= ATA_DFLAG_HIPM;
2570 if (ata_id_has_dipm(dev->id))
2571 dev->flags |= ATA_DFLAG_DIPM;
2572 }
2573
2574 /* Limit PATA drive on SATA cable bridge transfers to udma5, 2395 /* Limit PATA drive on SATA cable bridge transfers to udma5,
2575 200 sectors */ 2396 200 sectors */
2576 if (ata_dev_knobble(dev)) { 2397 if (ata_dev_knobble(dev)) {
@@ -2591,13 +2412,6 @@ int ata_dev_configure(struct ata_device *dev)
2591 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, 2412 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
2592 dev->max_sectors); 2413 dev->max_sectors);
2593 2414
2594 if (ata_dev_blacklisted(dev) & ATA_HORKAGE_IPM) {
2595 dev->horkage |= ATA_HORKAGE_IPM;
2596
2597 /* reset link pm_policy for this port to no pm */
2598 ap->pm_policy = MAX_PERFORMANCE;
2599 }
2600
2601 if (ap->ops->dev_config) 2415 if (ap->ops->dev_config)
2602 ap->ops->dev_config(dev); 2416 ap->ops->dev_config(dev);
2603 2417
@@ -3596,7 +3410,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
3596 warned = 1; 3410 warned = 1;
3597 } 3411 }
3598 3412
3599 msleep(50); 3413 ata_msleep(link->ap, 50);
3600 } 3414 }
3601} 3415}
3602 3416
@@ -3617,7 +3431,7 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
3617int ata_wait_after_reset(struct ata_link *link, unsigned long deadline, 3431int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
3618 int (*check_ready)(struct ata_link *link)) 3432 int (*check_ready)(struct ata_link *link))
3619{ 3433{
3620 msleep(ATA_WAIT_AFTER_RESET); 3434 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);
3621 3435
3622 return ata_wait_ready(link, deadline, check_ready); 3436 return ata_wait_ready(link, deadline, check_ready);
3623} 3437}
@@ -3628,7 +3442,7 @@ int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
3628 * @params: timing parameters { interval, duratinon, timeout } in msec 3442 * @params: timing parameters { interval, duratinon, timeout } in msec
3629 * @deadline: deadline jiffies for the operation 3443 * @deadline: deadline jiffies for the operation
3630 * 3444 *
3631* Make sure SStatus of @link reaches stable state, determined by 3445 * Make sure SStatus of @link reaches stable state, determined by
3632 * holding the same value where DET is not 1 for @duration polled 3446 * holding the same value where DET is not 1 for @duration polled
3633 * every @interval, before @timeout. Timeout constraints the 3447 * every @interval, before @timeout. Timeout constraints the
3634 * beginning of the stable state. Because DET gets stuck at 1 on 3448 * beginning of the stable state. Because DET gets stuck at 1 on
@@ -3665,7 +3479,7 @@ int sata_link_debounce(struct ata_link *link, const unsigned long *params,
3665 last_jiffies = jiffies; 3479 last_jiffies = jiffies;
3666 3480
3667 while (1) { 3481 while (1) {
3668 msleep(interval); 3482 ata_msleep(link->ap, interval);
3669 if ((rc = sata_scr_read(link, SCR_STATUS, &cur))) 3483 if ((rc = sata_scr_read(link, SCR_STATUS, &cur)))
3670 return rc; 3484 return rc;
3671 cur &= 0xf; 3485 cur &= 0xf;
@@ -3730,7 +3544,7 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params,
3730 * immediately after resuming. Delay 200ms before 3544 * immediately after resuming. Delay 200ms before
3731 * debouncing. 3545 * debouncing.
3732 */ 3546 */
3733 msleep(200); 3547 ata_msleep(link->ap, 200);
3734 3548
3735 /* is SControl restored correctly? */ 3549 /* is SControl restored correctly? */
3736 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol))) 3550 if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
@@ -3760,6 +3574,72 @@ int sata_link_resume(struct ata_link *link, const unsigned long *params,
3760} 3574}
3761 3575
3762/** 3576/**
3577 * sata_link_scr_lpm - manipulate SControl IPM and SPM fields
3578 * @link: ATA link to manipulate SControl for
3579 * @policy: LPM policy to configure
3580 * @spm_wakeup: initiate LPM transition to active state
3581 *
3582 * Manipulate the IPM field of the SControl register of @link
3583 * according to @policy. If @policy is ATA_LPM_MAX_POWER and
3584 * @spm_wakeup is %true, the SPM field is manipulated to wake up
3585 * the link. This function also clears PHYRDY_CHG before
3586 * returning.
3587 *
3588 * LOCKING:
3589 * EH context.
3590 *
3591 * RETURNS:
3592 * 0 on succes, -errno otherwise.
3593 */
3594int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
3595 bool spm_wakeup)
3596{
3597 struct ata_eh_context *ehc = &link->eh_context;
3598 bool woken_up = false;
3599 u32 scontrol;
3600 int rc;
3601
3602 rc = sata_scr_read(link, SCR_CONTROL, &scontrol);
3603 if (rc)
3604 return rc;
3605
3606 switch (policy) {
3607 case ATA_LPM_MAX_POWER:
3608 /* disable all LPM transitions */
3609 scontrol |= (0x3 << 8);
3610 /* initiate transition to active state */
3611 if (spm_wakeup) {
3612 scontrol |= (0x4 << 12);
3613 woken_up = true;
3614 }
3615 break;
3616 case ATA_LPM_MED_POWER:
3617 /* allow LPM to PARTIAL */
3618 scontrol &= ~(0x1 << 8);
3619 scontrol |= (0x2 << 8);
3620 break;
3621 case ATA_LPM_MIN_POWER:
3622 /* no restrictions on LPM transitions */
3623 scontrol &= ~(0x3 << 8);
3624 break;
3625 default:
3626 WARN_ON(1);
3627 }
3628
3629 rc = sata_scr_write(link, SCR_CONTROL, scontrol);
3630 if (rc)
3631 return rc;
3632
3633 /* give the link time to transit out of LPM state */
3634 if (woken_up)
3635 msleep(10);
3636
3637 /* clear PHYRDY_CHG from SError */
3638 ehc->i.serror &= ~SERR_PHYRDY_CHG;
3639 return sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
3640}
3641
3642/**
3763 * ata_std_prereset - prepare for reset 3643 * ata_std_prereset - prepare for reset
3764 * @link: ATA link to be reset 3644 * @link: ATA link to be reset
3765 * @deadline: deadline jiffies for the operation 3645 * @deadline: deadline jiffies for the operation
@@ -3868,7 +3748,7 @@ int sata_link_hardreset(struct ata_link *link, const unsigned long *timing,
3868 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1 3748 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
3869 * 10.4.2 says at least 1 ms. 3749 * 10.4.2 says at least 1 ms.
3870 */ 3750 */
3871 msleep(1); 3751 ata_msleep(link->ap, 1);
3872 3752
3873 /* bring link back */ 3753 /* bring link back */
3874 rc = sata_link_resume(link, timing, deadline); 3754 rc = sata_link_resume(link, timing, deadline);
@@ -4551,6 +4431,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev)
4551 DPRINTK("EXIT, err_mask=%x\n", err_mask); 4431 DPRINTK("EXIT, err_mask=%x\n", err_mask);
4552 return err_mask; 4432 return err_mask;
4553} 4433}
4434
4554/** 4435/**
4555 * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES 4436 * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES
4556 * @dev: Device to which command will be sent 4437 * @dev: Device to which command will be sent
@@ -4566,8 +4447,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev)
4566 * RETURNS: 4447 * RETURNS:
4567 * 0 on success, AC_ERR_* mask otherwise. 4448 * 0 on success, AC_ERR_* mask otherwise.
4568 */ 4449 */
4569static unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, 4450unsigned int ata_dev_set_feature(struct ata_device *dev, u8 enable, u8 feature)
4570 u8 feature)
4571{ 4451{
4572 struct ata_taskfile tf; 4452 struct ata_taskfile tf;
4573 unsigned int err_mask; 4453 unsigned int err_mask;
@@ -4943,8 +4823,13 @@ static void ata_verify_xfer(struct ata_queued_cmd *qc)
4943 * ata_qc_complete - Complete an active ATA command 4823 * ata_qc_complete - Complete an active ATA command
4944 * @qc: Command to complete 4824 * @qc: Command to complete
4945 * 4825 *
4946 * Indicate to the mid and upper layers that an ATA 4826 * Indicate to the mid and upper layers that an ATA command has
4947 * command has completed, with either an ok or not-ok status. 4827 * completed, with either an ok or not-ok status.
4828 *
4829 * Refrain from calling this function multiple times when
4830 * successfully completing multiple NCQ commands.
4831 * ata_qc_complete_multiple() should be used instead, which will
4832 * properly update IRQ expect state.
4948 * 4833 *
4949 * LOCKING: 4834 * LOCKING:
4950 * spin_lock_irqsave(host lock) 4835 * spin_lock_irqsave(host lock)
@@ -5037,6 +4922,10 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
5037 * requests normally. ap->qc_active and @qc_active is compared 4922 * requests normally. ap->qc_active and @qc_active is compared
5038 * and commands are completed accordingly. 4923 * and commands are completed accordingly.
5039 * 4924 *
4925 * Always use this function when completing multiple NCQ commands
4926 * from IRQ handlers instead of calling ata_qc_complete()
4927 * multiple times to keep IRQ expect status properly in sync.
4928 *
5040 * LOCKING: 4929 * LOCKING:
5041 * spin_lock_irqsave(host lock) 4930 * spin_lock_irqsave(host lock)
5042 * 4931 *
@@ -5422,12 +5311,6 @@ int ata_host_suspend(struct ata_host *host, pm_message_t mesg)
5422 int rc; 5311 int rc;
5423 5312
5424 /* 5313 /*
5425 * disable link pm on all ports before requesting
5426 * any pm activity
5427 */
5428 ata_lpm_enable(host);
5429
5430 /*
5431 * On some hardware, device fails to respond after spun down 5314 * On some hardware, device fails to respond after spun down
5432 * for suspend. As the device won't be used before being 5315 * for suspend. As the device won't be used before being
5433 * resumed, we don't need to touch the device. Ask EH to skip 5316 * resumed, we don't need to touch the device. Ask EH to skip
@@ -5460,9 +5343,6 @@ void ata_host_resume(struct ata_host *host)
5460 ata_host_request_pm(host, PMSG_ON, ATA_EH_RESET, 5343 ata_host_request_pm(host, PMSG_ON, ATA_EH_RESET,
5461 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0); 5344 ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
5462 host->dev->power.power_state = PMSG_ON; 5345 host->dev->power.power_state = PMSG_ON;
5463
5464 /* reenable link pm */
5465 ata_lpm_disable(host);
5466} 5346}
5467#endif 5347#endif
5468 5348
@@ -5517,7 +5397,8 @@ void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
5517 int i; 5397 int i;
5518 5398
5519 /* clear everything except for devices */ 5399 /* clear everything except for devices */
5520 memset(link, 0, offsetof(struct ata_link, device[0])); 5400 memset((void *)link + ATA_LINK_CLEAR_BEGIN, 0,
5401 ATA_LINK_CLEAR_END - ATA_LINK_CLEAR_BEGIN);
5521 5402
5522 link->ap = ap; 5403 link->ap = ap;
5523 link->pmp = pmp; 5404 link->pmp = pmp;
@@ -5591,7 +5472,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
5591 ap = kzalloc(sizeof(*ap), GFP_KERNEL); 5472 ap = kzalloc(sizeof(*ap), GFP_KERNEL);
5592 if (!ap) 5473 if (!ap)
5593 return NULL; 5474 return NULL;
5594 5475
5595 ap->pflags |= ATA_PFLAG_INITIALIZING; 5476 ap->pflags |= ATA_PFLAG_INITIALIZING;
5596 ap->lock = &host->lock; 5477 ap->lock = &host->lock;
5597 ap->print_id = -1; 5478 ap->print_id = -1;
@@ -5695,6 +5576,7 @@ struct ata_host *ata_host_alloc(struct device *dev, int max_ports)
5695 dev_set_drvdata(dev, host); 5576 dev_set_drvdata(dev, host);
5696 5577
5697 spin_lock_init(&host->lock); 5578 spin_lock_init(&host->lock);
5579 mutex_init(&host->eh_mutex);
5698 host->dev = dev; 5580 host->dev = dev;
5699 host->n_ports = max_ports; 5581 host->n_ports = max_ports;
5700 5582
@@ -5992,6 +5874,7 @@ void ata_host_init(struct ata_host *host, struct device *dev,
5992 unsigned long flags, struct ata_port_operations *ops) 5874 unsigned long flags, struct ata_port_operations *ops)
5993{ 5875{
5994 spin_lock_init(&host->lock); 5876 spin_lock_init(&host->lock);
5877 mutex_init(&host->eh_mutex);
5995 host->dev = dev; 5878 host->dev = dev;
5996 host->flags = flags; 5879 host->flags = flags;
5997 host->ops = ops; 5880 host->ops = ops;
@@ -6022,7 +5905,7 @@ static void async_port_probe(void *data, async_cookie_t cookie)
6022 spin_lock_irqsave(ap->lock, flags); 5905 spin_lock_irqsave(ap->lock, flags);
6023 5906
6024 ehi->probe_mask |= ATA_ALL_DEVICES; 5907 ehi->probe_mask |= ATA_ALL_DEVICES;
6025 ehi->action |= ATA_EH_RESET | ATA_EH_LPM; 5908 ehi->action |= ATA_EH_RESET;
6026 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; 5909 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
6027 5910
6028 ap->pflags &= ~ATA_PFLAG_INITIALIZING; 5911 ap->pflags &= ~ATA_PFLAG_INITIALIZING;
@@ -6093,9 +5976,18 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6093 for (i = 0; i < host->n_ports; i++) 5976 for (i = 0; i < host->n_ports; i++)
6094 host->ports[i]->print_id = ata_print_id++; 5977 host->ports[i]->print_id = ata_print_id++;
6095 5978
5979
5980 /* Create associated sysfs transport objects */
5981 for (i = 0; i < host->n_ports; i++) {
5982 rc = ata_tport_add(host->dev,host->ports[i]);
5983 if (rc) {
5984 goto err_tadd;
5985 }
5986 }
5987
6096 rc = ata_scsi_add_hosts(host, sht); 5988 rc = ata_scsi_add_hosts(host, sht);
6097 if (rc) 5989 if (rc)
6098 return rc; 5990 goto err_tadd;
6099 5991
6100 /* associate with ACPI nodes */ 5992 /* associate with ACPI nodes */
6101 ata_acpi_associate(host); 5993 ata_acpi_associate(host);
@@ -6136,6 +6028,13 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6136 } 6028 }
6137 6029
6138 return 0; 6030 return 0;
6031
6032 err_tadd:
6033 while (--i >= 0) {
6034 ata_tport_delete(host->ports[i]);
6035 }
6036 return rc;
6037
6139} 6038}
6140 6039
6141/** 6040/**
@@ -6226,6 +6125,13 @@ static void ata_port_detach(struct ata_port *ap)
6226 cancel_rearming_delayed_work(&ap->hotplug_task); 6125 cancel_rearming_delayed_work(&ap->hotplug_task);
6227 6126
6228 skip_eh: 6127 skip_eh:
6128 if (ap->pmp_link) {
6129 int i;
6130 for (i = 0; i < SATA_PMP_MAX_PORTS; i++)
6131 ata_tlink_delete(&ap->pmp_link[i]);
6132 }
6133 ata_tport_delete(ap);
6134
6229 /* remove the associated SCSI host */ 6135 /* remove the associated SCSI host */
6230 scsi_remove_host(ap->scsi_host); 6136 scsi_remove_host(ap->scsi_host);
6231} 6137}
@@ -6542,7 +6448,7 @@ static void __init ata_parse_force_param(void)
6542 6448
6543static int __init ata_init(void) 6449static int __init ata_init(void)
6544{ 6450{
6545 int rc = -ENOMEM; 6451 int rc;
6546 6452
6547 ata_parse_force_param(); 6453 ata_parse_force_param();
6548 6454
@@ -6552,12 +6458,25 @@ static int __init ata_init(void)
6552 return rc; 6458 return rc;
6553 } 6459 }
6554 6460
6461 libata_transport_init();
6462 ata_scsi_transport_template = ata_attach_transport();
6463 if (!ata_scsi_transport_template) {
6464 ata_sff_exit();
6465 rc = -ENOMEM;
6466 goto err_out;
6467 }
6468
6555 printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n"); 6469 printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
6556 return 0; 6470 return 0;
6471
6472err_out:
6473 return rc;
6557} 6474}
6558 6475
6559static void __exit ata_exit(void) 6476static void __exit ata_exit(void)
6560{ 6477{
6478 ata_release_transport(ata_scsi_transport_template);
6479 libata_transport_exit();
6561 ata_sff_exit(); 6480 ata_sff_exit();
6562 kfree(ata_force_tbl); 6481 kfree(ata_force_tbl);
6563} 6482}
@@ -6573,7 +6492,35 @@ int ata_ratelimit(void)
6573} 6492}
6574 6493
6575/** 6494/**
6495 * ata_msleep - ATA EH owner aware msleep
6496 * @ap: ATA port to attribute the sleep to
6497 * @msecs: duration to sleep in milliseconds
6498 *
6499 * Sleeps @msecs. If the current task is owner of @ap's EH, the
6500 * ownership is released before going to sleep and reacquired
6501 * after the sleep is complete. IOW, other ports sharing the
6502 * @ap->host will be allowed to own the EH while this task is
6503 * sleeping.
6504 *
6505 * LOCKING:
6506 * Might sleep.
6507 */
6508void ata_msleep(struct ata_port *ap, unsigned int msecs)
6509{
6510 bool owns_eh = ap && ap->host->eh_owner == current;
6511
6512 if (owns_eh)
6513 ata_eh_release(ap);
6514
6515 msleep(msecs);
6516
6517 if (owns_eh)
6518 ata_eh_acquire(ap);
6519}
6520
6521/**
6576 * ata_wait_register - wait until register value changes 6522 * ata_wait_register - wait until register value changes
6523 * @ap: ATA port to wait register for, can be NULL
6577 * @reg: IO-mapped register 6524 * @reg: IO-mapped register
6578 * @mask: Mask to apply to read register value 6525 * @mask: Mask to apply to read register value
6579 * @val: Wait condition 6526 * @val: Wait condition
@@ -6595,7 +6542,7 @@ int ata_ratelimit(void)
6595 * RETURNS: 6542 * RETURNS:
6596 * The final register value. 6543 * The final register value.
6597 */ 6544 */
6598u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val, 6545u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask, u32 val,
6599 unsigned long interval, unsigned long timeout) 6546 unsigned long interval, unsigned long timeout)
6600{ 6547{
6601 unsigned long deadline; 6548 unsigned long deadline;
@@ -6610,7 +6557,7 @@ u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
6610 deadline = ata_deadline(jiffies, timeout); 6557 deadline = ata_deadline(jiffies, timeout);
6611 6558
6612 while ((tmp & mask) == val && time_before(jiffies, deadline)) { 6559 while ((tmp & mask) == val && time_before(jiffies, deadline)) {
6613 msleep(interval); 6560 ata_msleep(ap, interval);
6614 tmp = ioread32(reg); 6561 tmp = ioread32(reg);
6615 } 6562 }
6616 6563
@@ -6686,6 +6633,7 @@ EXPORT_SYMBOL_GPL(sata_set_spd);
6686EXPORT_SYMBOL_GPL(ata_wait_after_reset); 6633EXPORT_SYMBOL_GPL(ata_wait_after_reset);
6687EXPORT_SYMBOL_GPL(sata_link_debounce); 6634EXPORT_SYMBOL_GPL(sata_link_debounce);
6688EXPORT_SYMBOL_GPL(sata_link_resume); 6635EXPORT_SYMBOL_GPL(sata_link_resume);
6636EXPORT_SYMBOL_GPL(sata_link_scr_lpm);
6689EXPORT_SYMBOL_GPL(ata_std_prereset); 6637EXPORT_SYMBOL_GPL(ata_std_prereset);
6690EXPORT_SYMBOL_GPL(sata_link_hardreset); 6638EXPORT_SYMBOL_GPL(sata_link_hardreset);
6691EXPORT_SYMBOL_GPL(sata_std_hardreset); 6639EXPORT_SYMBOL_GPL(sata_std_hardreset);
@@ -6693,6 +6641,7 @@ EXPORT_SYMBOL_GPL(ata_std_postreset);
6693EXPORT_SYMBOL_GPL(ata_dev_classify); 6641EXPORT_SYMBOL_GPL(ata_dev_classify);
6694EXPORT_SYMBOL_GPL(ata_dev_pair); 6642EXPORT_SYMBOL_GPL(ata_dev_pair);
6695EXPORT_SYMBOL_GPL(ata_ratelimit); 6643EXPORT_SYMBOL_GPL(ata_ratelimit);
6644EXPORT_SYMBOL_GPL(ata_msleep);
6696EXPORT_SYMBOL_GPL(ata_wait_register); 6645EXPORT_SYMBOL_GPL(ata_wait_register);
6697EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 6646EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
6698EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 6647EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index e48302eae55f..5e590504f3aa 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -57,6 +57,7 @@ enum {
57 /* error flags */ 57 /* error flags */
58 ATA_EFLAG_IS_IO = (1 << 0), 58 ATA_EFLAG_IS_IO = (1 << 0),
59 ATA_EFLAG_DUBIOUS_XFER = (1 << 1), 59 ATA_EFLAG_DUBIOUS_XFER = (1 << 1),
60 ATA_EFLAG_OLD_ER = (1 << 31),
60 61
61 /* error categories */ 62 /* error categories */
62 ATA_ECAT_NONE = 0, 63 ATA_ECAT_NONE = 0,
@@ -396,14 +397,9 @@ static struct ata_ering_entry *ata_ering_top(struct ata_ering *ering)
396 return NULL; 397 return NULL;
397} 398}
398 399
399static void ata_ering_clear(struct ata_ering *ering) 400int ata_ering_map(struct ata_ering *ering,
400{ 401 int (*map_fn)(struct ata_ering_entry *, void *),
401 memset(ering, 0, sizeof(*ering)); 402 void *arg)
402}
403
404static int ata_ering_map(struct ata_ering *ering,
405 int (*map_fn)(struct ata_ering_entry *, void *),
406 void *arg)
407{ 403{
408 int idx, rc = 0; 404 int idx, rc = 0;
409 struct ata_ering_entry *ent; 405 struct ata_ering_entry *ent;
@@ -422,6 +418,17 @@ static int ata_ering_map(struct ata_ering *ering,
422 return rc; 418 return rc;
423} 419}
424 420
421int ata_ering_clear_cb(struct ata_ering_entry *ent, void *void_arg)
422{
423 ent->eflags |= ATA_EFLAG_OLD_ER;
424 return 0;
425}
426
427static void ata_ering_clear(struct ata_ering *ering)
428{
429 ata_ering_map(ering, ata_ering_clear_cb, NULL);
430}
431
425static unsigned int ata_eh_dev_action(struct ata_device *dev) 432static unsigned int ata_eh_dev_action(struct ata_device *dev)
426{ 433{
427 struct ata_eh_context *ehc = &dev->link->eh_context; 434 struct ata_eh_context *ehc = &dev->link->eh_context;
@@ -456,6 +463,41 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
456} 463}
457 464
458/** 465/**
466 * ata_eh_acquire - acquire EH ownership
467 * @ap: ATA port to acquire EH ownership for
468 *
469 * Acquire EH ownership for @ap. This is the basic exclusion
470 * mechanism for ports sharing a host. Only one port hanging off
471 * the same host can claim the ownership of EH.
472 *
473 * LOCKING:
474 * EH context.
475 */
476void ata_eh_acquire(struct ata_port *ap)
477{
478 mutex_lock(&ap->host->eh_mutex);
479 WARN_ON_ONCE(ap->host->eh_owner);
480 ap->host->eh_owner = current;
481}
482
483/**
484 * ata_eh_release - release EH ownership
485 * @ap: ATA port to release EH ownership for
486 *
487 * Release EH ownership for @ap if the caller. The caller must
488 * have acquired EH ownership using ata_eh_acquire() previously.
489 *
490 * LOCKING:
491 * EH context.
492 */
493void ata_eh_release(struct ata_port *ap)
494{
495 WARN_ON_ONCE(ap->host->eh_owner != current);
496 ap->host->eh_owner = NULL;
497 mutex_unlock(&ap->host->eh_mutex);
498}
499
500/**
459 * ata_scsi_timed_out - SCSI layer time out callback 501 * ata_scsi_timed_out - SCSI layer time out callback
460 * @cmd: timed out SCSI command 502 * @cmd: timed out SCSI command
461 * 503 *
@@ -572,19 +614,19 @@ void ata_scsi_error(struct Scsi_Host *host)
572 int nr_timedout = 0; 614 int nr_timedout = 0;
573 615
574 spin_lock_irqsave(ap->lock, flags); 616 spin_lock_irqsave(ap->lock, flags);
575 617
576 /* This must occur under the ap->lock as we don't want 618 /* This must occur under the ap->lock as we don't want
577 a polled recovery to race the real interrupt handler 619 a polled recovery to race the real interrupt handler
578 620
579 The lost_interrupt handler checks for any completed but 621 The lost_interrupt handler checks for any completed but
580 non-notified command and completes much like an IRQ handler. 622 non-notified command and completes much like an IRQ handler.
581 623
582 We then fall into the error recovery code which will treat 624 We then fall into the error recovery code which will treat
583 this as if normal completion won the race */ 625 this as if normal completion won the race */
584 626
585 if (ap->ops->lost_interrupt) 627 if (ap->ops->lost_interrupt)
586 ap->ops->lost_interrupt(ap); 628 ap->ops->lost_interrupt(ap);
587 629
588 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 630 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
589 struct ata_queued_cmd *qc; 631 struct ata_queued_cmd *qc;
590 632
@@ -628,15 +670,17 @@ void ata_scsi_error(struct Scsi_Host *host)
628 ap->eh_tries = ATA_EH_MAX_TRIES; 670 ap->eh_tries = ATA_EH_MAX_TRIES;
629 } else 671 } else
630 spin_unlock_wait(ap->lock); 672 spin_unlock_wait(ap->lock);
631 673
632 /* If we timed raced normal completion and there is nothing to 674 /* If we timed raced normal completion and there is nothing to
633 recover nr_timedout == 0 why exactly are we doing error recovery ? */ 675 recover nr_timedout == 0 why exactly are we doing error recovery ? */
634 676
635 repeat:
636 /* invoke error handler */ 677 /* invoke error handler */
637 if (ap->ops->error_handler) { 678 if (ap->ops->error_handler) {
638 struct ata_link *link; 679 struct ata_link *link;
639 680
681 /* acquire EH ownership */
682 ata_eh_acquire(ap);
683 repeat:
640 /* kill fast drain timer */ 684 /* kill fast drain timer */
641 del_timer_sync(&ap->fastdrain_timer); 685 del_timer_sync(&ap->fastdrain_timer);
642 686
@@ -711,6 +755,7 @@ void ata_scsi_error(struct Scsi_Host *host)
711 host->host_eh_scheduled = 0; 755 host->host_eh_scheduled = 0;
712 756
713 spin_unlock_irqrestore(ap->lock, flags); 757 spin_unlock_irqrestore(ap->lock, flags);
758 ata_eh_release(ap);
714 } else { 759 } else {
715 WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL); 760 WARN_ON(ata_qc_from_tag(ap, ap->link.active_tag) == NULL);
716 ap->ops->eng_timeout(ap); 761 ap->ops->eng_timeout(ap);
@@ -772,7 +817,7 @@ void ata_port_wait_eh(struct ata_port *ap)
772 817
773 /* make sure SCSI EH is complete */ 818 /* make sure SCSI EH is complete */
774 if (scsi_host_in_recovery(ap->scsi_host)) { 819 if (scsi_host_in_recovery(ap->scsi_host)) {
775 msleep(10); 820 ata_msleep(ap, 10);
776 goto retry; 821 goto retry;
777 } 822 }
778} 823}
@@ -1573,9 +1618,9 @@ static void ata_eh_analyze_serror(struct ata_link *link)
1573 * host links. For disabled PMP links, only N bit is 1618 * host links. For disabled PMP links, only N bit is
1574 * considered as X bit is left at 1 for link plugging. 1619 * considered as X bit is left at 1 for link plugging.
1575 */ 1620 */
1576 hotplug_mask = 0; 1621 if (link->lpm_policy != ATA_LPM_MAX_POWER)
1577 1622 hotplug_mask = 0; /* hotplug doesn't work w/ LPM */
1578 if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link)) 1623 else if (!(link->flags & ATA_LFLAG_DISABLED) || ata_is_host_link(link))
1579 hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG; 1624 hotplug_mask = SERR_PHYRDY_CHG | SERR_DEV_XCHG;
1580 else 1625 else
1581 hotplug_mask = SERR_PHYRDY_CHG; 1626 hotplug_mask = SERR_PHYRDY_CHG;
@@ -1755,7 +1800,7 @@ static int speed_down_verdict_cb(struct ata_ering_entry *ent, void *void_arg)
1755 struct speed_down_verdict_arg *arg = void_arg; 1800 struct speed_down_verdict_arg *arg = void_arg;
1756 int cat; 1801 int cat;
1757 1802
1758 if (ent->timestamp < arg->since) 1803 if ((ent->eflags & ATA_EFLAG_OLD_ER) || (ent->timestamp < arg->since))
1759 return -1; 1804 return -1;
1760 1805
1761 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask, 1806 cat = ata_eh_categorize_error(ent->eflags, ent->err_mask,
@@ -2777,8 +2822,9 @@ int ata_eh_reset(struct ata_link *link, int classify,
2777 ata_eh_done(link, NULL, ATA_EH_RESET); 2822 ata_eh_done(link, NULL, ATA_EH_RESET);
2778 if (slave) 2823 if (slave)
2779 ata_eh_done(slave, NULL, ATA_EH_RESET); 2824 ata_eh_done(slave, NULL, ATA_EH_RESET);
2780 ehc->last_reset = jiffies; /* update to completion time */ 2825 ehc->last_reset = jiffies; /* update to completion time */
2781 ehc->i.action |= ATA_EH_REVALIDATE; 2826 ehc->i.action |= ATA_EH_REVALIDATE;
2827 link->lpm_policy = ATA_LPM_UNKNOWN; /* reset LPM state */
2782 2828
2783 rc = 0; 2829 rc = 0;
2784 out: 2830 out:
@@ -2810,8 +2856,10 @@ int ata_eh_reset(struct ata_link *link, int classify,
2810 "reset failed (errno=%d), retrying in %u secs\n", 2856 "reset failed (errno=%d), retrying in %u secs\n",
2811 rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000)); 2857 rc, DIV_ROUND_UP(jiffies_to_msecs(delta), 1000));
2812 2858
2859 ata_eh_release(ap);
2813 while (delta) 2860 while (delta)
2814 delta = schedule_timeout_uninterruptible(delta); 2861 delta = schedule_timeout_uninterruptible(delta);
2862 ata_eh_acquire(ap);
2815 } 2863 }
2816 2864
2817 if (try == max_tries - 1) { 2865 if (try == max_tries - 1) {
@@ -3204,6 +3252,124 @@ static int ata_eh_maybe_retry_flush(struct ata_device *dev)
3204 return rc; 3252 return rc;
3205} 3253}
3206 3254
3255/**
3256 * ata_eh_set_lpm - configure SATA interface power management
3257 * @link: link to configure power management
3258 * @policy: the link power management policy
3259 * @r_failed_dev: out parameter for failed device
3260 *
3261 * Enable SATA Interface power management. This will enable
3262 * Device Interface Power Management (DIPM) for min_power
3263 * policy, and then call driver specific callbacks for
3264 * enabling Host Initiated Power management.
3265 *
3266 * LOCKING:
3267 * EH context.
3268 *
3269 * RETURNS:
3270 * 0 on success, -errno on failure.
3271 */
3272static int ata_eh_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
3273 struct ata_device **r_failed_dev)
3274{
3275 struct ata_port *ap = ata_is_host_link(link) ? link->ap : NULL;
3276 struct ata_eh_context *ehc = &link->eh_context;
3277 struct ata_device *dev, *link_dev = NULL, *lpm_dev = NULL;
3278 unsigned int hints = ATA_LPM_EMPTY | ATA_LPM_HIPM;
3279 unsigned int err_mask;
3280 int rc;
3281
3282 /* if the link or host doesn't do LPM, noop */
3283 if ((link->flags & ATA_LFLAG_NO_LPM) || (ap && !ap->ops->set_lpm))
3284 return 0;
3285
3286 /*
3287 * DIPM is enabled only for MIN_POWER as some devices
3288 * misbehave when the host NACKs transition to SLUMBER. Order
3289 * device and link configurations such that the host always
3290 * allows DIPM requests.
3291 */
3292 ata_for_each_dev(dev, link, ENABLED) {
3293 bool hipm = ata_id_has_hipm(dev->id);
3294 bool dipm = ata_id_has_dipm(dev->id);
3295
3296 /* find the first enabled and LPM enabled devices */
3297 if (!link_dev)
3298 link_dev = dev;
3299
3300 if (!lpm_dev && (hipm || dipm))
3301 lpm_dev = dev;
3302
3303 hints &= ~ATA_LPM_EMPTY;
3304 if (!hipm)
3305 hints &= ~ATA_LPM_HIPM;
3306
3307 /* disable DIPM before changing link config */
3308 if (policy != ATA_LPM_MIN_POWER && dipm) {
3309 err_mask = ata_dev_set_feature(dev,
3310 SETFEATURES_SATA_DISABLE, SATA_DIPM);
3311 if (err_mask && err_mask != AC_ERR_DEV) {
3312 ata_dev_printk(dev, KERN_WARNING,
3313 "failed to disable DIPM, Emask 0x%x\n",
3314 err_mask);
3315 rc = -EIO;
3316 goto fail;
3317 }
3318 }
3319 }
3320
3321 if (ap) {
3322 rc = ap->ops->set_lpm(link, policy, hints);
3323 if (!rc && ap->slave_link)
3324 rc = ap->ops->set_lpm(ap->slave_link, policy, hints);
3325 } else
3326 rc = sata_pmp_set_lpm(link, policy, hints);
3327
3328 /*
3329 * Attribute link config failure to the first (LPM) enabled
3330 * device on the link.
3331 */
3332 if (rc) {
3333 if (rc == -EOPNOTSUPP) {
3334 link->flags |= ATA_LFLAG_NO_LPM;
3335 return 0;
3336 }
3337 dev = lpm_dev ? lpm_dev : link_dev;
3338 goto fail;
3339 }
3340
3341 /* host config updated, enable DIPM if transitioning to MIN_POWER */
3342 ata_for_each_dev(dev, link, ENABLED) {
3343 if (policy == ATA_LPM_MIN_POWER && ata_id_has_dipm(dev->id)) {
3344 err_mask = ata_dev_set_feature(dev,
3345 SETFEATURES_SATA_ENABLE, SATA_DIPM);
3346 if (err_mask && err_mask != AC_ERR_DEV) {
3347 ata_dev_printk(dev, KERN_WARNING,
3348 "failed to enable DIPM, Emask 0x%x\n",
3349 err_mask);
3350 rc = -EIO;
3351 goto fail;
3352 }
3353 }
3354 }
3355
3356 link->lpm_policy = policy;
3357 if (ap && ap->slave_link)
3358 ap->slave_link->lpm_policy = policy;
3359 return 0;
3360
3361fail:
3362 /* if no device or only one more chance is left, disable LPM */
3363 if (!dev || ehc->tries[dev->devno] <= 2) {
3364 ata_link_printk(link, KERN_WARNING,
3365 "disabling LPM on the link\n");
3366 link->flags |= ATA_LFLAG_NO_LPM;
3367 }
3368 if (r_failed_dev)
3369 *r_failed_dev = dev;
3370 return rc;
3371}
3372
3207static int ata_link_nr_enabled(struct ata_link *link) 3373static int ata_link_nr_enabled(struct ata_link *link)
3208{ 3374{
3209 struct ata_device *dev; 3375 struct ata_device *dev;
@@ -3288,6 +3454,16 @@ static int ata_eh_schedule_probe(struct ata_device *dev)
3288 ehc->saved_xfer_mode[dev->devno] = 0; 3454 ehc->saved_xfer_mode[dev->devno] = 0;
3289 ehc->saved_ncq_enabled &= ~(1 << dev->devno); 3455 ehc->saved_ncq_enabled &= ~(1 << dev->devno);
3290 3456
3457 /* the link maybe in a deep sleep, wake it up */
3458 if (link->lpm_policy > ATA_LPM_MAX_POWER) {
3459 if (ata_is_host_link(link))
3460 link->ap->ops->set_lpm(link, ATA_LPM_MAX_POWER,
3461 ATA_LPM_EMPTY);
3462 else
3463 sata_pmp_set_lpm(link, ATA_LPM_MAX_POWER,
3464 ATA_LPM_EMPTY);
3465 }
3466
3291 /* Record and count probe trials on the ering. The specific 3467 /* Record and count probe trials on the ering. The specific
3292 * error mask used is irrelevant. Because a successful device 3468 * error mask used is irrelevant. Because a successful device
3293 * detection clears the ering, this count accumulates only if 3469 * detection clears the ering, this count accumulates only if
@@ -3389,8 +3565,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3389{ 3565{
3390 struct ata_link *link; 3566 struct ata_link *link;
3391 struct ata_device *dev; 3567 struct ata_device *dev;
3392 int nr_failed_devs; 3568 int rc, nr_fails;
3393 int rc;
3394 unsigned long flags, deadline; 3569 unsigned long flags, deadline;
3395 3570
3396 DPRINTK("ENTER\n"); 3571 DPRINTK("ENTER\n");
@@ -3431,7 +3606,6 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3431 3606
3432 retry: 3607 retry:
3433 rc = 0; 3608 rc = 0;
3434 nr_failed_devs = 0;
3435 3609
3436 /* if UNLOADING, finish immediately */ 3610 /* if UNLOADING, finish immediately */
3437 if (ap->pflags & ATA_PFLAG_UNLOADING) 3611 if (ap->pflags & ATA_PFLAG_UNLOADING)
@@ -3501,8 +3675,10 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3501 if (time_before_eq(deadline, now)) 3675 if (time_before_eq(deadline, now))
3502 break; 3676 break;
3503 3677
3678 ata_eh_release(ap);
3504 deadline = wait_for_completion_timeout(&ap->park_req_pending, 3679 deadline = wait_for_completion_timeout(&ap->park_req_pending,
3505 deadline - now); 3680 deadline - now);
3681 ata_eh_acquire(ap);
3506 } while (deadline); 3682 } while (deadline);
3507 ata_for_each_link(link, ap, EDGE) { 3683 ata_for_each_link(link, ap, EDGE) {
3508 ata_for_each_dev(dev, link, ALL) { 3684 ata_for_each_dev(dev, link, ALL) {
@@ -3516,13 +3692,17 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3516 } 3692 }
3517 3693
3518 /* the rest */ 3694 /* the rest */
3519 ata_for_each_link(link, ap, EDGE) { 3695 nr_fails = 0;
3696 ata_for_each_link(link, ap, PMP_FIRST) {
3520 struct ata_eh_context *ehc = &link->eh_context; 3697 struct ata_eh_context *ehc = &link->eh_context;
3521 3698
3699 if (sata_pmp_attached(ap) && ata_is_host_link(link))
3700 goto config_lpm;
3701
3522 /* revalidate existing devices and attach new ones */ 3702 /* revalidate existing devices and attach new ones */
3523 rc = ata_eh_revalidate_and_attach(link, &dev); 3703 rc = ata_eh_revalidate_and_attach(link, &dev);
3524 if (rc) 3704 if (rc)
3525 goto dev_fail; 3705 goto rest_fail;
3526 3706
3527 /* if PMP got attached, return, pmp EH will take care of it */ 3707 /* if PMP got attached, return, pmp EH will take care of it */
3528 if (link->device->class == ATA_DEV_PMP) { 3708 if (link->device->class == ATA_DEV_PMP) {
@@ -3534,7 +3714,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3534 if (ehc->i.flags & ATA_EHI_SETMODE) { 3714 if (ehc->i.flags & ATA_EHI_SETMODE) {
3535 rc = ata_set_mode(link, &dev); 3715 rc = ata_set_mode(link, &dev);
3536 if (rc) 3716 if (rc)
3537 goto dev_fail; 3717 goto rest_fail;
3538 ehc->i.flags &= ~ATA_EHI_SETMODE; 3718 ehc->i.flags &= ~ATA_EHI_SETMODE;
3539 } 3719 }
3540 3720
@@ -3547,7 +3727,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3547 continue; 3727 continue;
3548 rc = atapi_eh_clear_ua(dev); 3728 rc = atapi_eh_clear_ua(dev);
3549 if (rc) 3729 if (rc)
3550 goto dev_fail; 3730 goto rest_fail;
3551 } 3731 }
3552 } 3732 }
3553 3733
@@ -3557,21 +3737,25 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3557 continue; 3737 continue;
3558 rc = ata_eh_maybe_retry_flush(dev); 3738 rc = ata_eh_maybe_retry_flush(dev);
3559 if (rc) 3739 if (rc)
3560 goto dev_fail; 3740 goto rest_fail;
3561 } 3741 }
3562 3742
3743 config_lpm:
3563 /* configure link power saving */ 3744 /* configure link power saving */
3564 if (ehc->i.action & ATA_EH_LPM) 3745 if (link->lpm_policy != ap->target_lpm_policy) {
3565 ata_for_each_dev(dev, link, ALL) 3746 rc = ata_eh_set_lpm(link, ap->target_lpm_policy, &dev);
3566 ata_dev_enable_pm(dev, ap->pm_policy); 3747 if (rc)
3748 goto rest_fail;
3749 }
3567 3750
3568 /* this link is okay now */ 3751 /* this link is okay now */
3569 ehc->i.flags = 0; 3752 ehc->i.flags = 0;
3570 continue; 3753 continue;
3571 3754
3572dev_fail: 3755 rest_fail:
3573 nr_failed_devs++; 3756 nr_fails++;
3574 ata_eh_handle_dev_fail(dev, rc); 3757 if (dev)
3758 ata_eh_handle_dev_fail(dev, rc);
3575 3759
3576 if (ap->pflags & ATA_PFLAG_FROZEN) { 3760 if (ap->pflags & ATA_PFLAG_FROZEN) {
3577 /* PMP reset requires working host port. 3761 /* PMP reset requires working host port.
@@ -3583,7 +3767,7 @@ dev_fail:
3583 } 3767 }
3584 } 3768 }
3585 3769
3586 if (nr_failed_devs) 3770 if (nr_fails)
3587 goto retry; 3771 goto retry;
3588 3772
3589 out: 3773 out:
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 224faabd7b7e..3120596d4afc 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -11,6 +11,7 @@
11#include <linux/libata.h> 11#include <linux/libata.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include "libata.h" 13#include "libata.h"
14#include "libata-transport.h"
14 15
15const struct ata_port_operations sata_pmp_port_ops = { 16const struct ata_port_operations sata_pmp_port_ops = {
16 .inherits = &sata_port_ops, 17 .inherits = &sata_port_ops,
@@ -185,6 +186,27 @@ int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
185} 186}
186 187
187/** 188/**
189 * sata_pmp_set_lpm - configure LPM for a PMP link
190 * @link: PMP link to configure LPM for
191 * @policy: target LPM policy
192 * @hints: LPM hints
193 *
194 * Configure LPM for @link. This function will contain any PMP
195 * specific workarounds if necessary.
196 *
197 * LOCKING:
198 * EH context.
199 *
200 * RETURNS:
201 * 0 on success, -errno on failure.
202 */
203int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
204 unsigned hints)
205{
206 return sata_link_scr_lpm(link, policy, true);
207}
208
209/**
188 * sata_pmp_read_gscr - read GSCR block of SATA PMP 210 * sata_pmp_read_gscr - read GSCR block of SATA PMP
189 * @dev: PMP device 211 * @dev: PMP device
190 * @gscr: buffer to read GSCR block into 212 * @gscr: buffer to read GSCR block into
@@ -312,10 +334,10 @@ static int sata_pmp_configure(struct ata_device *dev, int print_info)
312 return rc; 334 return rc;
313} 335}
314 336
315static int sata_pmp_init_links(struct ata_port *ap, int nr_ports) 337static int sata_pmp_init_links (struct ata_port *ap, int nr_ports)
316{ 338{
317 struct ata_link *pmp_link = ap->pmp_link; 339 struct ata_link *pmp_link = ap->pmp_link;
318 int i; 340 int i, err;
319 341
320 if (!pmp_link) { 342 if (!pmp_link) {
321 pmp_link = kzalloc(sizeof(pmp_link[0]) * SATA_PMP_MAX_PORTS, 343 pmp_link = kzalloc(sizeof(pmp_link[0]) * SATA_PMP_MAX_PORTS,
@@ -327,6 +349,13 @@ static int sata_pmp_init_links(struct ata_port *ap, int nr_ports)
327 ata_link_init(ap, &pmp_link[i], i); 349 ata_link_init(ap, &pmp_link[i], i);
328 350
329 ap->pmp_link = pmp_link; 351 ap->pmp_link = pmp_link;
352
353 for (i = 0; i < SATA_PMP_MAX_PORTS; i++) {
354 err = ata_tlink_add(&pmp_link[i]);
355 if (err) {
356 goto err_tlink;
357 }
358 }
330 } 359 }
331 360
332 for (i = 0; i < nr_ports; i++) { 361 for (i = 0; i < nr_ports; i++) {
@@ -339,6 +368,12 @@ static int sata_pmp_init_links(struct ata_port *ap, int nr_ports)
339 } 368 }
340 369
341 return 0; 370 return 0;
371 err_tlink:
372 while (--i >= 0)
373 ata_tlink_delete(&pmp_link[i]);
374 kfree(pmp_link);
375 ap->pmp_link = NULL;
376 return err;
342} 377}
343 378
344static void sata_pmp_quirks(struct ata_port *ap) 379static void sata_pmp_quirks(struct ata_port *ap)
@@ -351,6 +386,9 @@ static void sata_pmp_quirks(struct ata_port *ap)
351 if (vendor == 0x1095 && devid == 0x3726) { 386 if (vendor == 0x1095 && devid == 0x3726) {
352 /* sil3726 quirks */ 387 /* sil3726 quirks */
353 ata_for_each_link(link, ap, EDGE) { 388 ata_for_each_link(link, ap, EDGE) {
389 /* link reports offline after LPM */
390 link->flags |= ATA_LFLAG_NO_LPM;
391
354 /* Class code report is unreliable and SRST 392 /* Class code report is unreliable and SRST
355 * times out under certain configurations. 393 * times out under certain configurations.
356 */ 394 */
@@ -366,6 +404,9 @@ static void sata_pmp_quirks(struct ata_port *ap)
366 } else if (vendor == 0x1095 && devid == 0x4723) { 404 } else if (vendor == 0x1095 && devid == 0x4723) {
367 /* sil4723 quirks */ 405 /* sil4723 quirks */
368 ata_for_each_link(link, ap, EDGE) { 406 ata_for_each_link(link, ap, EDGE) {
407 /* link reports offline after LPM */
408 link->flags |= ATA_LFLAG_NO_LPM;
409
369 /* class code report is unreliable */ 410 /* class code report is unreliable */
370 if (link->pmp < 2) 411 if (link->pmp < 2)
371 link->flags |= ATA_LFLAG_ASSUME_ATA; 412 link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -378,6 +419,9 @@ static void sata_pmp_quirks(struct ata_port *ap)
378 } else if (vendor == 0x1095 && devid == 0x4726) { 419 } else if (vendor == 0x1095 && devid == 0x4726) {
379 /* sil4726 quirks */ 420 /* sil4726 quirks */
380 ata_for_each_link(link, ap, EDGE) { 421 ata_for_each_link(link, ap, EDGE) {
422 /* link reports offline after LPM */
423 link->flags |= ATA_LFLAG_NO_LPM;
424
381 /* Class code report is unreliable and SRST 425 /* Class code report is unreliable and SRST
382 * times out under certain configurations. 426 * times out under certain configurations.
383 * Config device can be at port 0 or 5 and 427 * Config device can be at port 0 or 5 and
@@ -938,15 +982,25 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
938 if (rc) 982 if (rc)
939 goto link_fail; 983 goto link_fail;
940 984
941 /* Connection status might have changed while resetting other
942 * links, check SATA_PMP_GSCR_ERROR before returning.
943 */
944
945 /* clear SNotification */ 985 /* clear SNotification */
946 rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf); 986 rc = sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf);
947 if (rc == 0) 987 if (rc == 0)
948 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf); 988 sata_scr_write(&ap->link, SCR_NOTIFICATION, sntf);
949 989
990 /*
991 * If LPM is active on any fan-out port, hotplug wouldn't
992 * work. Return w/ PHY event notification disabled.
993 */
994 ata_for_each_link(link, ap, EDGE)
995 if (link->lpm_policy > ATA_LPM_MAX_POWER)
996 return 0;
997
998 /*
999 * Connection status might have changed while resetting other
1000 * links, enable notification and check SATA_PMP_GSCR_ERROR
1001 * before returning.
1002 */
1003
950 /* enable notification */ 1004 /* enable notification */
951 if (pmp_dev->flags & ATA_DFLAG_AN) { 1005 if (pmp_dev->flags & ATA_DFLAG_AN) {
952 gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY; 1006 gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index a89172c100f5..d050e073e570 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -51,8 +51,8 @@
51#include <asm/unaligned.h> 51#include <asm/unaligned.h>
52 52
53#include "libata.h" 53#include "libata.h"
54#include "libata-transport.h"
54 55
55#define SECTOR_SIZE 512
56#define ATA_SCSI_RBUF_SIZE 4096 56#define ATA_SCSI_RBUF_SIZE 4096
57 57
58static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); 58static DEFINE_SPINLOCK(ata_scsi_rbuf_lock);
@@ -64,9 +64,6 @@ static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap,
64 const struct scsi_device *scsidev); 64 const struct scsi_device *scsidev);
65static struct ata_device *ata_scsi_find_dev(struct ata_port *ap, 65static struct ata_device *ata_scsi_find_dev(struct ata_port *ap,
66 const struct scsi_device *scsidev); 66 const struct scsi_device *scsidev);
67static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
68 unsigned int id, unsigned int lun);
69
70 67
71#define RW_RECOVERY_MPAGE 0x1 68#define RW_RECOVERY_MPAGE 0x1
72#define RW_RECOVERY_MPAGE_LEN 12 69#define RW_RECOVERY_MPAGE_LEN 12
@@ -106,83 +103,55 @@ static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = {
106 0, 30 /* extended self test time, see 05-359r1 */ 103 0, 30 /* extended self test time, see 05-359r1 */
107}; 104};
108 105
109/* 106static const char *ata_lpm_policy_names[] = {
110 * libata transport template. libata doesn't do real transport stuff. 107 [ATA_LPM_UNKNOWN] = "max_performance",
111 * It just needs the eh_timed_out hook. 108 [ATA_LPM_MAX_POWER] = "max_performance",
112 */ 109 [ATA_LPM_MED_POWER] = "medium_power",
113static struct scsi_transport_template ata_scsi_transport_template = { 110 [ATA_LPM_MIN_POWER] = "min_power",
114 .eh_strategy_handler = ata_scsi_error,
115 .eh_timed_out = ata_scsi_timed_out,
116 .user_scan = ata_scsi_user_scan,
117};
118
119
120static const struct {
121 enum link_pm value;
122 const char *name;
123} link_pm_policy[] = {
124 { NOT_AVAILABLE, "max_performance" },
125 { MIN_POWER, "min_power" },
126 { MAX_PERFORMANCE, "max_performance" },
127 { MEDIUM_POWER, "medium_power" },
128}; 111};
129 112
130static const char *ata_scsi_lpm_get(enum link_pm policy) 113static ssize_t ata_scsi_lpm_store(struct device *dev,
131{ 114 struct device_attribute *attr,
132 int i; 115 const char *buf, size_t count)
133
134 for (i = 0; i < ARRAY_SIZE(link_pm_policy); i++)
135 if (link_pm_policy[i].value == policy)
136 return link_pm_policy[i].name;
137
138 return NULL;
139}
140
141static ssize_t ata_scsi_lpm_put(struct device *dev,
142 struct device_attribute *attr,
143 const char *buf, size_t count)
144{ 116{
145 struct Scsi_Host *shost = class_to_shost(dev); 117 struct Scsi_Host *shost = class_to_shost(dev);
146 struct ata_port *ap = ata_shost_to_port(shost); 118 struct ata_port *ap = ata_shost_to_port(shost);
147 enum link_pm policy = 0; 119 enum ata_lpm_policy policy;
148 int i; 120 unsigned long flags;
149 121
150 /* 122 /* UNKNOWN is internal state, iterate from MAX_POWER */
151 * we are skipping array location 0 on purpose - this 123 for (policy = ATA_LPM_MAX_POWER;
152 * is because a value of NOT_AVAILABLE is displayed 124 policy < ARRAY_SIZE(ata_lpm_policy_names); policy++) {
153 * to the user as max_performance, but when the user 125 const char *name = ata_lpm_policy_names[policy];
154 * writes "max_performance", they actually want the 126
155 * value to match MAX_PERFORMANCE. 127 if (strncmp(name, buf, strlen(name)) == 0)
156 */
157 for (i = 1; i < ARRAY_SIZE(link_pm_policy); i++) {
158 const int len = strlen(link_pm_policy[i].name);
159 if (strncmp(link_pm_policy[i].name, buf, len) == 0) {
160 policy = link_pm_policy[i].value;
161 break; 128 break;
162 }
163 } 129 }
164 if (!policy) 130 if (policy == ARRAY_SIZE(ata_lpm_policy_names))
165 return -EINVAL; 131 return -EINVAL;
166 132
167 ata_lpm_schedule(ap, policy); 133 spin_lock_irqsave(ap->lock, flags);
134 ap->target_lpm_policy = policy;
135 ata_port_schedule_eh(ap);
136 spin_unlock_irqrestore(ap->lock, flags);
137
168 return count; 138 return count;
169} 139}
170 140
171static ssize_t 141static ssize_t ata_scsi_lpm_show(struct device *dev,
172ata_scsi_lpm_show(struct device *dev, struct device_attribute *attr, char *buf) 142 struct device_attribute *attr, char *buf)
173{ 143{
174 struct Scsi_Host *shost = class_to_shost(dev); 144 struct Scsi_Host *shost = class_to_shost(dev);
175 struct ata_port *ap = ata_shost_to_port(shost); 145 struct ata_port *ap = ata_shost_to_port(shost);
176 const char *policy =
177 ata_scsi_lpm_get(ap->pm_policy);
178 146
179 if (!policy) 147 if (ap->target_lpm_policy >= ARRAY_SIZE(ata_lpm_policy_names))
180 return -EINVAL; 148 return -EINVAL;
181 149
182 return snprintf(buf, 23, "%s\n", policy); 150 return snprintf(buf, PAGE_SIZE, "%s\n",
151 ata_lpm_policy_names[ap->target_lpm_policy]);
183} 152}
184DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR, 153DEVICE_ATTR(link_power_management_policy, S_IRUGO | S_IWUSR,
185 ata_scsi_lpm_show, ata_scsi_lpm_put); 154 ata_scsi_lpm_show, ata_scsi_lpm_store);
186EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy); 155EXPORT_SYMBOL_GPL(dev_attr_link_power_management_policy);
187 156
188static ssize_t ata_scsi_park_show(struct device *device, 157static ssize_t ata_scsi_park_show(struct device *device,
@@ -516,7 +485,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
516 memset(scsi_cmd, 0, sizeof(scsi_cmd)); 485 memset(scsi_cmd, 0, sizeof(scsi_cmd));
517 486
518 if (args[3]) { 487 if (args[3]) {
519 argsize = SECTOR_SIZE * args[3]; 488 argsize = ATA_SECT_SIZE * args[3];
520 argbuf = kmalloc(argsize, GFP_KERNEL); 489 argbuf = kmalloc(argsize, GFP_KERNEL);
521 if (argbuf == NULL) { 490 if (argbuf == NULL) {
522 rc = -ENOMEM; 491 rc = -ENOMEM;
@@ -1150,8 +1119,9 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
1150 blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); 1119 blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN);
1151 } else { 1120 } else {
1152 /* ATA devices must be sector aligned */ 1121 /* ATA devices must be sector aligned */
1122 sdev->sector_size = ata_id_logical_sector_size(dev->id);
1153 blk_queue_update_dma_alignment(sdev->request_queue, 1123 blk_queue_update_dma_alignment(sdev->request_queue,
1154 ATA_SECT_SIZE - 1); 1124 sdev->sector_size - 1);
1155 sdev->manage_start_stop = 1; 1125 sdev->manage_start_stop = 1;
1156 } 1126 }
1157 1127
@@ -1166,6 +1136,7 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
1166 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); 1136 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
1167 } 1137 }
1168 1138
1139 dev->sdev = sdev;
1169 return 0; 1140 return 0;
1170} 1141}
1171 1142
@@ -1696,7 +1667,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
1696 goto nothing_to_do; 1667 goto nothing_to_do;
1697 1668
1698 qc->flags |= ATA_QCFLAG_IO; 1669 qc->flags |= ATA_QCFLAG_IO;
1699 qc->nbytes = n_block * ATA_SECT_SIZE; 1670 qc->nbytes = n_block * scmd->device->sector_size;
1700 1671
1701 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, 1672 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
1702 qc->tag); 1673 qc->tag);
@@ -2001,6 +1972,7 @@ static unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf)
2001 0x89, /* page 0x89, ata info page */ 1972 0x89, /* page 0x89, ata info page */
2002 0xb0, /* page 0xb0, block limits page */ 1973 0xb0, /* page 0xb0, block limits page */
2003 0xb1, /* page 0xb1, block device characteristics page */ 1974 0xb1, /* page 0xb1, block device characteristics page */
1975 0xb2, /* page 0xb2, thin provisioning page */
2004 }; 1976 };
2005 1977
2006 rbuf[3] = sizeof(pages); /* number of supported VPD pages */ 1978 rbuf[3] = sizeof(pages); /* number of supported VPD pages */
@@ -2123,7 +2095,7 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf)
2123 2095
2124static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) 2096static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf)
2125{ 2097{
2126 u32 min_io_sectors; 2098 u16 min_io_sectors;
2127 2099
2128 rbuf[1] = 0xb0; 2100 rbuf[1] = 0xb0;
2129 rbuf[3] = 0x3c; /* required VPD size with unmap support */ 2101 rbuf[3] = 0x3c; /* required VPD size with unmap support */
@@ -2135,10 +2107,7 @@ static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf)
2135 * logical than physical sector size we need to figure out what the 2107 * logical than physical sector size we need to figure out what the
2136 * latter is. 2108 * latter is.
2137 */ 2109 */
2138 if (ata_id_has_large_logical_sectors(args->id)) 2110 min_io_sectors = 1 << ata_id_log2_per_physical_sector(args->id);
2139 min_io_sectors = ata_id_logical_per_physical_sectors(args->id);
2140 else
2141 min_io_sectors = 1;
2142 put_unaligned_be16(min_io_sectors, &rbuf[6]); 2111 put_unaligned_be16(min_io_sectors, &rbuf[6]);
2143 2112
2144 /* 2113 /*
@@ -2172,6 +2141,16 @@ static unsigned int ata_scsiop_inq_b1(struct ata_scsi_args *args, u8 *rbuf)
2172 return 0; 2141 return 0;
2173} 2142}
2174 2143
2144static unsigned int ata_scsiop_inq_b2(struct ata_scsi_args *args, u8 *rbuf)
2145{
2146 /* SCSI Thin Provisioning VPD page: SBC-3 rev 22 or later */
2147 rbuf[1] = 0xb2;
2148 rbuf[3] = 0x4;
2149 rbuf[5] = 1 << 6; /* TPWS */
2150
2151 return 0;
2152}
2153
2175/** 2154/**
2176 * ata_scsiop_noop - Command handler that simply returns success. 2155 * ata_scsiop_noop - Command handler that simply returns success.
2177 * @args: device IDENTIFY data / SCSI command of interest. 2156 * @args: device IDENTIFY data / SCSI command of interest.
@@ -2397,21 +2376,13 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
2397{ 2376{
2398 struct ata_device *dev = args->dev; 2377 struct ata_device *dev = args->dev;
2399 u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */ 2378 u64 last_lba = dev->n_sectors - 1; /* LBA of the last block */
2400 u8 log_per_phys = 0; 2379 u32 sector_size; /* physical sector size in bytes */
2401 u16 lowest_aligned = 0; 2380 u8 log2_per_phys;
2402 u16 word_106 = dev->id[106]; 2381 u16 lowest_aligned;
2403 u16 word_209 = dev->id[209]; 2382
2404 2383 sector_size = ata_id_logical_sector_size(dev->id);
2405 if ((word_106 & 0xc000) == 0x4000) { 2384 log2_per_phys = ata_id_log2_per_physical_sector(dev->id);
2406 /* Number and offset of logical sectors per physical sector */ 2385 lowest_aligned = ata_id_logical_sector_offset(dev->id, log2_per_phys);
2407 if (word_106 & (1 << 13))
2408 log_per_phys = word_106 & 0xf;
2409 if ((word_209 & 0xc000) == 0x4000) {
2410 u16 first = dev->id[209] & 0x3fff;
2411 if (first > 0)
2412 lowest_aligned = (1 << log_per_phys) - first;
2413 }
2414 }
2415 2386
2416 VPRINTK("ENTER\n"); 2387 VPRINTK("ENTER\n");
2417 2388
@@ -2426,8 +2397,10 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
2426 rbuf[3] = last_lba; 2397 rbuf[3] = last_lba;
2427 2398
2428 /* sector size */ 2399 /* sector size */
2429 rbuf[6] = ATA_SECT_SIZE >> 8; 2400 rbuf[4] = sector_size >> (8 * 3);
2430 rbuf[7] = ATA_SECT_SIZE & 0xff; 2401 rbuf[5] = sector_size >> (8 * 2);
2402 rbuf[6] = sector_size >> (8 * 1);
2403 rbuf[7] = sector_size;
2431 } else { 2404 } else {
2432 /* sector count, 64-bit */ 2405 /* sector count, 64-bit */
2433 rbuf[0] = last_lba >> (8 * 7); 2406 rbuf[0] = last_lba >> (8 * 7);
@@ -2440,11 +2413,13 @@ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf)
2440 rbuf[7] = last_lba; 2413 rbuf[7] = last_lba;
2441 2414
2442 /* sector size */ 2415 /* sector size */
2443 rbuf[10] = ATA_SECT_SIZE >> 8; 2416 rbuf[ 8] = sector_size >> (8 * 3);
2444 rbuf[11] = ATA_SECT_SIZE & 0xff; 2417 rbuf[ 9] = sector_size >> (8 * 2);
2418 rbuf[10] = sector_size >> (8 * 1);
2419 rbuf[11] = sector_size;
2445 2420
2446 rbuf[12] = 0; 2421 rbuf[12] = 0;
2447 rbuf[13] = log_per_phys; 2422 rbuf[13] = log2_per_phys;
2448 rbuf[14] = (lowest_aligned >> 8) & 0x3f; 2423 rbuf[14] = (lowest_aligned >> 8) & 0x3f;
2449 rbuf[15] = lowest_aligned; 2424 rbuf[15] = lowest_aligned;
2450 2425
@@ -2888,9 +2863,8 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2888 tf->device = dev->devno ? 2863 tf->device = dev->devno ?
2889 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1; 2864 tf->device | ATA_DEV1 : tf->device & ~ATA_DEV1;
2890 2865
2891 /* READ/WRITE LONG use a non-standard sect_size */
2892 qc->sect_size = ATA_SECT_SIZE;
2893 switch (tf->command) { 2866 switch (tf->command) {
2867 /* READ/WRITE LONG use a non-standard sect_size */
2894 case ATA_CMD_READ_LONG: 2868 case ATA_CMD_READ_LONG:
2895 case ATA_CMD_READ_LONG_ONCE: 2869 case ATA_CMD_READ_LONG_ONCE:
2896 case ATA_CMD_WRITE_LONG: 2870 case ATA_CMD_WRITE_LONG:
@@ -2898,6 +2872,45 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2898 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1) 2872 if (tf->protocol != ATA_PROT_PIO || tf->nsect != 1)
2899 goto invalid_fld; 2873 goto invalid_fld;
2900 qc->sect_size = scsi_bufflen(scmd); 2874 qc->sect_size = scsi_bufflen(scmd);
2875 break;
2876
2877 /* commands using reported Logical Block size (e.g. 512 or 4K) */
2878 case ATA_CMD_CFA_WRITE_NE:
2879 case ATA_CMD_CFA_TRANS_SECT:
2880 case ATA_CMD_CFA_WRITE_MULT_NE:
2881 /* XXX: case ATA_CMD_CFA_WRITE_SECTORS_WITHOUT_ERASE: */
2882 case ATA_CMD_READ:
2883 case ATA_CMD_READ_EXT:
2884 case ATA_CMD_READ_QUEUED:
2885 /* XXX: case ATA_CMD_READ_QUEUED_EXT: */
2886 case ATA_CMD_FPDMA_READ:
2887 case ATA_CMD_READ_MULTI:
2888 case ATA_CMD_READ_MULTI_EXT:
2889 case ATA_CMD_PIO_READ:
2890 case ATA_CMD_PIO_READ_EXT:
2891 case ATA_CMD_READ_STREAM_DMA_EXT:
2892 case ATA_CMD_READ_STREAM_EXT:
2893 case ATA_CMD_VERIFY:
2894 case ATA_CMD_VERIFY_EXT:
2895 case ATA_CMD_WRITE:
2896 case ATA_CMD_WRITE_EXT:
2897 case ATA_CMD_WRITE_FUA_EXT:
2898 case ATA_CMD_WRITE_QUEUED:
2899 case ATA_CMD_WRITE_QUEUED_FUA_EXT:
2900 case ATA_CMD_FPDMA_WRITE:
2901 case ATA_CMD_WRITE_MULTI:
2902 case ATA_CMD_WRITE_MULTI_EXT:
2903 case ATA_CMD_WRITE_MULTI_FUA_EXT:
2904 case ATA_CMD_PIO_WRITE:
2905 case ATA_CMD_PIO_WRITE_EXT:
2906 case ATA_CMD_WRITE_STREAM_DMA_EXT:
2907 case ATA_CMD_WRITE_STREAM_EXT:
2908 qc->sect_size = scmd->device->sector_size;
2909 break;
2910
2911 /* Everything else uses 512 byte "sectors" */
2912 default:
2913 qc->sect_size = ATA_SECT_SIZE;
2901 } 2914 }
2902 2915
2903 /* 2916 /*
@@ -3250,6 +3263,9 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
3250 case 0xb1: 3263 case 0xb1:
3251 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1); 3264 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b1);
3252 break; 3265 break;
3266 case 0xb2:
3267 ata_scsi_rbuf_fill(&args, ata_scsiop_inq_b2);
3268 break;
3253 default: 3269 default:
3254 ata_scsi_invalid_field(cmd, done); 3270 ata_scsi_invalid_field(cmd, done);
3255 break; 3271 break;
@@ -3334,7 +3350,7 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
3334 *(struct ata_port **)&shost->hostdata[0] = ap; 3350 *(struct ata_port **)&shost->hostdata[0] = ap;
3335 ap->scsi_host = shost; 3351 ap->scsi_host = shost;
3336 3352
3337 shost->transportt = &ata_scsi_transport_template; 3353 shost->transportt = ata_scsi_transport_template;
3338 shost->unique_id = ap->print_id; 3354 shost->unique_id = ap->print_id;
3339 shost->max_id = 16; 3355 shost->max_id = 16;
3340 shost->max_lun = 1; 3356 shost->max_lun = 1;
@@ -3393,6 +3409,8 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3393 if (!IS_ERR(sdev)) { 3409 if (!IS_ERR(sdev)) {
3394 dev->sdev = sdev; 3410 dev->sdev = sdev;
3395 scsi_device_put(sdev); 3411 scsi_device_put(sdev);
3412 } else {
3413 dev->sdev = NULL;
3396 } 3414 }
3397 } 3415 }
3398 } 3416 }
@@ -3616,8 +3634,8 @@ void ata_scsi_hotplug(struct work_struct *work)
3616 * RETURNS: 3634 * RETURNS:
3617 * Zero. 3635 * Zero.
3618 */ 3636 */
3619static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, 3637int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3620 unsigned int id, unsigned int lun) 3638 unsigned int id, unsigned int lun)
3621{ 3639{
3622 struct ata_port *ap = ata_shost_to_port(shost); 3640 struct ata_port *ap = ata_shost_to_port(shost);
3623 unsigned long flags; 3641 unsigned long flags;
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index e30c537cce32..14d18bf81255 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -222,7 +222,7 @@ int ata_sff_busy_sleep(struct ata_port *ap,
222 timeout = ata_deadline(timer_start, tmout_pat); 222 timeout = ata_deadline(timer_start, tmout_pat);
223 while (status != 0xff && (status & ATA_BUSY) && 223 while (status != 0xff && (status & ATA_BUSY) &&
224 time_before(jiffies, timeout)) { 224 time_before(jiffies, timeout)) {
225 msleep(50); 225 ata_msleep(ap, 50);
226 status = ata_sff_busy_wait(ap, ATA_BUSY, 3); 226 status = ata_sff_busy_wait(ap, ATA_BUSY, 3);
227 } 227 }
228 228
@@ -234,7 +234,7 @@ int ata_sff_busy_sleep(struct ata_port *ap,
234 timeout = ata_deadline(timer_start, tmout); 234 timeout = ata_deadline(timer_start, tmout);
235 while (status != 0xff && (status & ATA_BUSY) && 235 while (status != 0xff && (status & ATA_BUSY) &&
236 time_before(jiffies, timeout)) { 236 time_before(jiffies, timeout)) {
237 msleep(50); 237 ata_msleep(ap, 50);
238 status = ap->ops->sff_check_status(ap); 238 status = ap->ops->sff_check_status(ap);
239 } 239 }
240 240
@@ -360,7 +360,7 @@ static void ata_dev_select(struct ata_port *ap, unsigned int device,
360 360
361 if (wait) { 361 if (wait) {
362 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI) 362 if (can_sleep && ap->link.device[device].class == ATA_DEV_ATAPI)
363 msleep(150); 363 ata_msleep(ap, 150);
364 ata_wait_idle(ap); 364 ata_wait_idle(ap);
365 } 365 }
366} 366}
@@ -1356,7 +1356,7 @@ fsm_start:
1356 */ 1356 */
1357 status = ata_sff_busy_wait(ap, ATA_BUSY, 5); 1357 status = ata_sff_busy_wait(ap, ATA_BUSY, 5);
1358 if (status & ATA_BUSY) { 1358 if (status & ATA_BUSY) {
1359 msleep(2); 1359 ata_msleep(ap, 2);
1360 status = ata_sff_busy_wait(ap, ATA_BUSY, 10); 1360 status = ata_sff_busy_wait(ap, ATA_BUSY, 10);
1361 if (status & ATA_BUSY) { 1361 if (status & ATA_BUSY) {
1362 ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE); 1362 ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE);
@@ -1937,7 +1937,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1937 unsigned int dev1 = devmask & (1 << 1); 1937 unsigned int dev1 = devmask & (1 << 1);
1938 int rc, ret = 0; 1938 int rc, ret = 0;
1939 1939
1940 msleep(ATA_WAIT_AFTER_RESET); 1940 ata_msleep(ap, ATA_WAIT_AFTER_RESET);
1941 1941
1942 /* always check readiness of the master device */ 1942 /* always check readiness of the master device */
1943 rc = ata_sff_wait_ready(link, deadline); 1943 rc = ata_sff_wait_ready(link, deadline);
@@ -1966,7 +1966,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1966 lbal = ioread8(ioaddr->lbal_addr); 1966 lbal = ioread8(ioaddr->lbal_addr);
1967 if ((nsect == 1) && (lbal == 1)) 1967 if ((nsect == 1) && (lbal == 1))
1968 break; 1968 break;
1969 msleep(50); /* give drive a breather */ 1969 ata_msleep(ap, 50); /* give drive a breather */
1970 } 1970 }
1971 1971
1972 rc = ata_sff_wait_ready(link, deadline); 1972 rc = ata_sff_wait_ready(link, deadline);
@@ -3342,7 +3342,7 @@ int __init ata_sff_init(void)
3342 return 0; 3342 return 0;
3343} 3343}
3344 3344
3345void __exit ata_sff_exit(void) 3345void ata_sff_exit(void)
3346{ 3346{
3347 destroy_workqueue(ata_sff_wq); 3347 destroy_workqueue(ata_sff_wq);
3348} 3348}
diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
new file mode 100644
index 000000000000..ce9dc6207f37
--- /dev/null
+++ b/drivers/ata/libata-transport.c
@@ -0,0 +1,774 @@
1/*
2 * Copyright 2008 ioogle, Inc. All rights reserved.
3 * Released under GPL v2.
4 *
5 * Libata transport class.
6 *
7 * The ATA transport class contains common code to deal with ATA HBAs,
8 * an approximated representation of ATA topologies in the driver model,
9 * and various sysfs attributes to expose these topologies and management
10 * interfaces to user-space.
11 *
12 * There are 3 objects defined in in this class:
13 * - ata_port
14 * - ata_link
15 * - ata_device
16 * Each port has a link object. Each link can have up to two devices for PATA
17 * and generally one for SATA.
18 * If there is SATA port multiplier [PMP], 15 additional ata_link object are
19 * created.
20 *
21 * These objects are created when the ata host is initialized and when a PMP is
22 * found. They are removed only when the HBA is removed, cleaned before the
23 * error handler runs.
24 */
25
26
27#include <linux/kernel.h>
28#include <linux/blkdev.h>
29#include <linux/spinlock.h>
30#include <linux/slab.h>
31#include <scsi/scsi_transport.h>
32#include <linux/libata.h>
33#include <linux/hdreg.h>
34#include <linux/uaccess.h>
35
36#include "libata.h"
37#include "libata-transport.h"
38
39#define ATA_PORT_ATTRS 2
40#define ATA_LINK_ATTRS 3
41#define ATA_DEV_ATTRS 9
42
43struct scsi_transport_template;
44struct scsi_transport_template *ata_scsi_transport_template;
45
46struct ata_internal {
47 struct scsi_transport_template t;
48
49 struct device_attribute private_port_attrs[ATA_PORT_ATTRS];
50 struct device_attribute private_link_attrs[ATA_LINK_ATTRS];
51 struct device_attribute private_dev_attrs[ATA_DEV_ATTRS];
52
53 struct transport_container link_attr_cont;
54 struct transport_container dev_attr_cont;
55
56 /*
57 * The array of null terminated pointers to attributes
58 * needed by scsi_sysfs.c
59 */
60 struct device_attribute *link_attrs[ATA_LINK_ATTRS + 1];
61 struct device_attribute *port_attrs[ATA_PORT_ATTRS + 1];
62 struct device_attribute *dev_attrs[ATA_DEV_ATTRS + 1];
63};
64#define to_ata_internal(tmpl) container_of(tmpl, struct ata_internal, t)
65
66
67#define tdev_to_device(d) \
68 container_of((d), struct ata_device, tdev)
69#define transport_class_to_dev(dev) \
70 tdev_to_device((dev)->parent)
71
72#define tdev_to_link(d) \
73 container_of((d), struct ata_link, tdev)
74#define transport_class_to_link(dev) \
75 tdev_to_link((dev)->parent)
76
77#define tdev_to_port(d) \
78 container_of((d), struct ata_port, tdev)
79#define transport_class_to_port(dev) \
80 tdev_to_port((dev)->parent)
81
82
83/* Device objects are always created whit link objects */
84static int ata_tdev_add(struct ata_device *dev);
85static void ata_tdev_delete(struct ata_device *dev);
86
87
88/*
89 * Hack to allow attributes of the same name in different objects.
90 */
91#define ATA_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
92 struct device_attribute device_attr_##_prefix##_##_name = \
93 __ATTR(_name,_mode,_show,_store)
94
95#define ata_bitfield_name_match(title, table) \
96static ssize_t \
97get_ata_##title##_names(u32 table_key, char *buf) \
98{ \
99 char *prefix = ""; \
100 ssize_t len = 0; \
101 int i; \
102 \
103 for (i = 0; i < ARRAY_SIZE(table); i++) { \
104 if (table[i].value & table_key) { \
105 len += sprintf(buf + len, "%s%s", \
106 prefix, table[i].name); \
107 prefix = ", "; \
108 } \
109 } \
110 len += sprintf(buf + len, "\n"); \
111 return len; \
112}
113
114#define ata_bitfield_name_search(title, table) \
115static ssize_t \
116get_ata_##title##_names(u32 table_key, char *buf) \
117{ \
118 ssize_t len = 0; \
119 int i; \
120 \
121 for (i = 0; i < ARRAY_SIZE(table); i++) { \
122 if (table[i].value == table_key) { \
123 len += sprintf(buf + len, "%s", \
124 table[i].name); \
125 break; \
126 } \
127 } \
128 len += sprintf(buf + len, "\n"); \
129 return len; \
130}
131
132static struct {
133 u32 value;
134 char *name;
135} ata_class_names[] = {
136 { ATA_DEV_UNKNOWN, "unknown" },
137 { ATA_DEV_ATA, "ata" },
138 { ATA_DEV_ATA_UNSUP, "ata" },
139 { ATA_DEV_ATAPI, "atapi" },
140 { ATA_DEV_ATAPI_UNSUP, "atapi" },
141 { ATA_DEV_PMP, "pmp" },
142 { ATA_DEV_PMP_UNSUP, "pmp" },
143 { ATA_DEV_SEMB, "semb" },
144 { ATA_DEV_SEMB_UNSUP, "semb" },
145 { ATA_DEV_NONE, "none" }
146};
147ata_bitfield_name_search(class, ata_class_names)
148
149
150static struct {
151 u32 value;
152 char *name;
153} ata_err_names[] = {
154 { AC_ERR_DEV, "DeviceError" },
155 { AC_ERR_HSM, "HostStateMachineError" },
156 { AC_ERR_TIMEOUT, "Timeout" },
157 { AC_ERR_MEDIA, "MediaError" },
158 { AC_ERR_ATA_BUS, "BusError" },
159 { AC_ERR_HOST_BUS, "HostBusError" },
160 { AC_ERR_SYSTEM, "SystemError" },
161 { AC_ERR_INVALID, "InvalidArg" },
162 { AC_ERR_OTHER, "Unknown" },
163 { AC_ERR_NODEV_HINT, "NoDeviceHint" },
164 { AC_ERR_NCQ, "NCQError" }
165};
166ata_bitfield_name_match(err, ata_err_names)
167
168static struct {
169 u32 value;
170 char *name;
171} ata_xfer_names[] = {
172 { XFER_UDMA_7, "XFER_UDMA_7" },
173 { XFER_UDMA_6, "XFER_UDMA_6" },
174 { XFER_UDMA_5, "XFER_UDMA_5" },
175 { XFER_UDMA_4, "XFER_UDMA_4" },
176 { XFER_UDMA_3, "XFER_UDMA_3" },
177 { XFER_UDMA_2, "XFER_UDMA_2" },
178 { XFER_UDMA_1, "XFER_UDMA_1" },
179 { XFER_UDMA_0, "XFER_UDMA_0" },
180 { XFER_MW_DMA_4, "XFER_MW_DMA_4" },
181 { XFER_MW_DMA_3, "XFER_MW_DMA_3" },
182 { XFER_MW_DMA_2, "XFER_MW_DMA_2" },
183 { XFER_MW_DMA_1, "XFER_MW_DMA_1" },
184 { XFER_MW_DMA_0, "XFER_MW_DMA_0" },
185 { XFER_SW_DMA_2, "XFER_SW_DMA_2" },
186 { XFER_SW_DMA_1, "XFER_SW_DMA_1" },
187 { XFER_SW_DMA_0, "XFER_SW_DMA_0" },
188 { XFER_PIO_6, "XFER_PIO_6" },
189 { XFER_PIO_5, "XFER_PIO_5" },
190 { XFER_PIO_4, "XFER_PIO_4" },
191 { XFER_PIO_3, "XFER_PIO_3" },
192 { XFER_PIO_2, "XFER_PIO_2" },
193 { XFER_PIO_1, "XFER_PIO_1" },
194 { XFER_PIO_0, "XFER_PIO_0" },
195 { XFER_PIO_SLOW, "XFER_PIO_SLOW" }
196};
197ata_bitfield_name_match(xfer,ata_xfer_names)
198
199/*
200 * ATA Port attributes
201 */
202#define ata_port_show_simple(field, name, format_string, cast) \
203static ssize_t \
204show_ata_port_##name(struct device *dev, \
205 struct device_attribute *attr, char *buf) \
206{ \
207 struct ata_port *ap = transport_class_to_port(dev); \
208 \
209 return snprintf(buf, 20, format_string, cast ap->field); \
210}
211
212#define ata_port_simple_attr(field, name, format_string, type) \
213 ata_port_show_simple(field, name, format_string, (type)) \
214static DEVICE_ATTR(name, S_IRUGO, show_ata_port_##name, NULL)
215
216ata_port_simple_attr(nr_pmp_links, nr_pmp_links, "%d\n", int);
217ata_port_simple_attr(stats.idle_irq, idle_irq, "%ld\n", unsigned long);
218
219static DECLARE_TRANSPORT_CLASS(ata_port_class,
220 "ata_port", NULL, NULL, NULL);
221
222static void ata_tport_release(struct device *dev)
223{
224 put_device(dev->parent);
225}
226
227/**
228 * ata_is_port -- check if a struct device represents a ATA port
229 * @dev: device to check
230 *
231 * Returns:
232 * %1 if the device represents a ATA Port, %0 else
233 */
234int ata_is_port(const struct device *dev)
235{
236 return dev->release == ata_tport_release;
237}
238
239static int ata_tport_match(struct attribute_container *cont,
240 struct device *dev)
241{
242 if (!ata_is_port(dev))
243 return 0;
244 return &ata_scsi_transport_template->host_attrs.ac == cont;
245}
246
247/**
248 * ata_tport_delete -- remove ATA PORT
249 * @port: ATA PORT to remove
250 *
251 * Removes the specified ATA PORT. Remove the associated link as well.
252 */
253void ata_tport_delete(struct ata_port *ap)
254{
255 struct device *dev = &ap->tdev;
256
257 ata_tlink_delete(&ap->link);
258
259 transport_remove_device(dev);
260 device_del(dev);
261 transport_destroy_device(dev);
262 put_device(dev);
263}
264
265/** ata_tport_add - initialize a transport ATA port structure
266 *
267 * @parent: parent device
268 * @ap: existing ata_port structure
269 *
270 * Initialize a ATA port structure for sysfs. It will be added to the device
271 * tree below the device specified by @parent which could be a PCI device.
272 *
273 * Returns %0 on success
274 */
275int ata_tport_add(struct device *parent,
276 struct ata_port *ap)
277{
278 int error;
279 struct device *dev = &ap->tdev;
280
281 device_initialize(dev);
282
283 dev->parent = get_device(parent);
284 dev->release = ata_tport_release;
285 dev_set_name(dev, "ata%d", ap->print_id);
286 transport_setup_device(dev);
287 error = device_add(dev);
288 if (error) {
289 goto tport_err;
290 }
291
292 transport_add_device(dev);
293 transport_configure_device(dev);
294
295 error = ata_tlink_add(&ap->link);
296 if (error) {
297 goto tport_link_err;
298 }
299 return 0;
300
301 tport_link_err:
302 transport_remove_device(dev);
303 device_del(dev);
304
305 tport_err:
306 transport_destroy_device(dev);
307 put_device(dev);
308 return error;
309}
310
311
312/*
313 * ATA link attributes
314 */
315
316
317#define ata_link_show_linkspeed(field) \
318static ssize_t \
319show_ata_link_##field(struct device *dev, \
320 struct device_attribute *attr, char *buf) \
321{ \
322 struct ata_link *link = transport_class_to_link(dev); \
323 \
324 return sprintf(buf,"%s\n", sata_spd_string(fls(link->field))); \
325}
326
327#define ata_link_linkspeed_attr(field) \
328 ata_link_show_linkspeed(field) \
329static DEVICE_ATTR(field, S_IRUGO, show_ata_link_##field, NULL)
330
331ata_link_linkspeed_attr(hw_sata_spd_limit);
332ata_link_linkspeed_attr(sata_spd_limit);
333ata_link_linkspeed_attr(sata_spd);
334
335
336static DECLARE_TRANSPORT_CLASS(ata_link_class,
337 "ata_link", NULL, NULL, NULL);
338
339static void ata_tlink_release(struct device *dev)
340{
341 put_device(dev->parent);
342}
343
344/**
345 * ata_is_link -- check if a struct device represents a ATA link
346 * @dev: device to check
347 *
348 * Returns:
349 * %1 if the device represents a ATA link, %0 else
350 */
351int ata_is_link(const struct device *dev)
352{
353 return dev->release == ata_tlink_release;
354}
355
356static int ata_tlink_match(struct attribute_container *cont,
357 struct device *dev)
358{
359 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
360 if (!ata_is_link(dev))
361 return 0;
362 return &i->link_attr_cont.ac == cont;
363}
364
365/**
366 * ata_tlink_delete -- remove ATA LINK
367 * @port: ATA LINK to remove
368 *
369 * Removes the specified ATA LINK. remove associated ATA device(s) as well.
370 */
371void ata_tlink_delete(struct ata_link *link)
372{
373 struct device *dev = &link->tdev;
374 struct ata_device *ata_dev;
375
376 ata_for_each_dev(ata_dev, link, ALL) {
377 ata_tdev_delete(ata_dev);
378 }
379
380 transport_remove_device(dev);
381 device_del(dev);
382 transport_destroy_device(dev);
383 put_device(dev);
384}
385
386/**
387 * ata_tlink_add -- initialize a transport ATA link structure
388 * @link: allocated ata_link structure.
389 *
390 * Initialize an ATA LINK structure for sysfs. It will be added in the
391 * device tree below the ATA PORT it belongs to.
392 *
393 * Returns %0 on success
394 */
395int ata_tlink_add(struct ata_link *link)
396{
397 struct device *dev = &link->tdev;
398 struct ata_port *ap = link->ap;
399 struct ata_device *ata_dev;
400 int error;
401
402 device_initialize(dev);
403 dev->parent = get_device(&ap->tdev);
404 dev->release = ata_tlink_release;
405 if (ata_is_host_link(link))
406 dev_set_name(dev, "link%d", ap->print_id);
407 else
408 dev_set_name(dev, "link%d.%d", ap->print_id, link->pmp);
409
410 transport_setup_device(dev);
411
412 error = device_add(dev);
413 if (error) {
414 goto tlink_err;
415 }
416
417 transport_add_device(dev);
418 transport_configure_device(dev);
419
420 ata_for_each_dev(ata_dev, link, ALL) {
421 error = ata_tdev_add(ata_dev);
422 if (error) {
423 goto tlink_dev_err;
424 }
425 }
426 return 0;
427 tlink_dev_err:
428 while (--ata_dev >= link->device) {
429 ata_tdev_delete(ata_dev);
430 }
431 transport_remove_device(dev);
432 device_del(dev);
433 tlink_err:
434 transport_destroy_device(dev);
435 put_device(dev);
436 return error;
437}
438
439/*
440 * ATA device attributes
441 */
442
443#define ata_dev_show_class(title, field) \
444static ssize_t \
445show_ata_dev_##field(struct device *dev, \
446 struct device_attribute *attr, char *buf) \
447{ \
448 struct ata_device *ata_dev = transport_class_to_dev(dev); \
449 \
450 return get_ata_##title##_names(ata_dev->field, buf); \
451}
452
453#define ata_dev_attr(title, field) \
454 ata_dev_show_class(title, field) \
455static DEVICE_ATTR(field, S_IRUGO, show_ata_dev_##field, NULL)
456
457ata_dev_attr(class, class);
458ata_dev_attr(xfer, pio_mode);
459ata_dev_attr(xfer, dma_mode);
460ata_dev_attr(xfer, xfer_mode);
461
462
463#define ata_dev_show_simple(field, format_string, cast) \
464static ssize_t \
465show_ata_dev_##field(struct device *dev, \
466 struct device_attribute *attr, char *buf) \
467{ \
468 struct ata_device *ata_dev = transport_class_to_dev(dev); \
469 \
470 return snprintf(buf, 20, format_string, cast ata_dev->field); \
471}
472
473#define ata_dev_simple_attr(field, format_string, type) \
474 ata_dev_show_simple(field, format_string, (type)) \
475static DEVICE_ATTR(field, S_IRUGO, \
476 show_ata_dev_##field, NULL)
477
478ata_dev_simple_attr(spdn_cnt, "%d\n", int);
479
480struct ata_show_ering_arg {
481 char* buf;
482 int written;
483};
484
485static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg)
486{
487 struct ata_show_ering_arg* arg = void_arg;
488 struct timespec time;
489
490 jiffies_to_timespec(ent->timestamp,&time);
491 arg->written += sprintf(arg->buf + arg->written,
492 "[%5lu.%06lu]",
493 time.tv_sec, time.tv_nsec);
494 arg->written += get_ata_err_names(ent->err_mask,
495 arg->buf + arg->written);
496 return 0;
497}
498
499static ssize_t
500show_ata_dev_ering(struct device *dev,
501 struct device_attribute *attr, char *buf)
502{
503 struct ata_device *ata_dev = transport_class_to_dev(dev);
504 struct ata_show_ering_arg arg = { buf, 0 };
505
506 ata_ering_map(&ata_dev->ering, ata_show_ering, &arg);
507 return arg.written;
508}
509
510
511static DEVICE_ATTR(ering, S_IRUGO, show_ata_dev_ering, NULL);
512
513static ssize_t
514show_ata_dev_id(struct device *dev,
515 struct device_attribute *attr, char *buf)
516{
517 struct ata_device *ata_dev = transport_class_to_dev(dev);
518 int written = 0, i = 0;
519
520 if (ata_dev->class == ATA_DEV_PMP)
521 return 0;
522 for(i=0;i<ATA_ID_WORDS;i++) {
523 written += snprintf(buf+written, 20, "%04x%c",
524 ata_dev->id[i],
525 ((i+1) & 7) ? ' ' : '\n');
526 }
527 return written;
528}
529
530static DEVICE_ATTR(id, S_IRUGO, show_ata_dev_id, NULL);
531
532static ssize_t
533show_ata_dev_gscr(struct device *dev,
534 struct device_attribute *attr, char *buf)
535{
536 struct ata_device *ata_dev = transport_class_to_dev(dev);
537 int written = 0, i = 0;
538
539 if (ata_dev->class != ATA_DEV_PMP)
540 return 0;
541 for(i=0;i<SATA_PMP_GSCR_DWORDS;i++) {
542 written += snprintf(buf+written, 20, "%08x%c",
543 ata_dev->gscr[i],
544 ((i+1) & 3) ? ' ' : '\n');
545 }
546 if (SATA_PMP_GSCR_DWORDS & 3)
547 buf[written-1] = '\n';
548 return written;
549}
550
551static DEVICE_ATTR(gscr, S_IRUGO, show_ata_dev_gscr, NULL);
552
553static DECLARE_TRANSPORT_CLASS(ata_dev_class,
554 "ata_device", NULL, NULL, NULL);
555
556static void ata_tdev_release(struct device *dev)
557{
558 put_device(dev->parent);
559}
560
561/**
562 * ata_is_ata_dev -- check if a struct device represents a ATA device
563 * @dev: device to check
564 *
565 * Returns:
566 * %1 if the device represents a ATA device, %0 else
567 */
568int ata_is_ata_dev(const struct device *dev)
569{
570 return dev->release == ata_tdev_release;
571}
572
573static int ata_tdev_match(struct attribute_container *cont,
574 struct device *dev)
575{
576 struct ata_internal* i = to_ata_internal(ata_scsi_transport_template);
577 if (!ata_is_ata_dev(dev))
578 return 0;
579 return &i->dev_attr_cont.ac == cont;
580}
581
582/**
583 * ata_tdev_free -- free a ATA LINK
584 * @dev: ATA PHY to free
585 *
586 * Frees the specified ATA PHY.
587 *
588 * Note:
589 * This function must only be called on a PHY that has not
590 * successfully been added using ata_tdev_add().
591 */
592static void ata_tdev_free(struct ata_device *dev)
593{
594 transport_destroy_device(&dev->tdev);
595 put_device(&dev->tdev);
596}
597
598/**
599 * ata_tdev_delete -- remove ATA device
600 * @port: ATA PORT to remove
601 *
602 * Removes the specified ATA device.
603 */
604static void ata_tdev_delete(struct ata_device *ata_dev)
605{
606 struct device *dev = &ata_dev->tdev;
607
608 transport_remove_device(dev);
609 device_del(dev);
610 ata_tdev_free(ata_dev);
611}
612
613
614/**
615 * ata_tdev_add -- initialize a transport ATA device structure.
616 * @ata_dev: ata_dev structure.
617 *
618 * Initialize an ATA device structure for sysfs. It will be added in the
619 * device tree below the ATA LINK device it belongs to.
620 *
621 * Returns %0 on success
622 */
623static int ata_tdev_add(struct ata_device *ata_dev)
624{
625 struct device *dev = &ata_dev->tdev;
626 struct ata_link *link = ata_dev->link;
627 struct ata_port *ap = link->ap;
628 int error;
629
630 device_initialize(dev);
631 dev->parent = get_device(&link->tdev);
632 dev->release = ata_tdev_release;
633 if (ata_is_host_link(link))
634 dev_set_name(dev, "dev%d.%d", ap->print_id,ata_dev->devno);
635 else
636 dev_set_name(dev, "dev%d.%d.0", ap->print_id, link->pmp);
637
638 transport_setup_device(dev);
639 error = device_add(dev);
640 if (error) {
641 ata_tdev_free(ata_dev);
642 return error;
643 }
644
645 transport_add_device(dev);
646 transport_configure_device(dev);
647 return 0;
648}
649
650
651/*
652 * Setup / Teardown code
653 */
654
655#define SETUP_TEMPLATE(attrb, field, perm, test) \
656 i->private_##attrb[count] = dev_attr_##field; \
657 i->private_##attrb[count].attr.mode = perm; \
658 i->attrb[count] = &i->private_##attrb[count]; \
659 if (test) \
660 count++
661
662#define SETUP_LINK_ATTRIBUTE(field) \
663 SETUP_TEMPLATE(link_attrs, field, S_IRUGO, 1)
664
665#define SETUP_PORT_ATTRIBUTE(field) \
666 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
667
668#define SETUP_DEV_ATTRIBUTE(field) \
669 SETUP_TEMPLATE(dev_attrs, field, S_IRUGO, 1)
670
671/**
672 * ata_attach_transport -- instantiate ATA transport template
673 */
674struct scsi_transport_template *ata_attach_transport(void)
675{
676 struct ata_internal *i;
677 int count;
678
679 i = kzalloc(sizeof(struct ata_internal), GFP_KERNEL);
680 if (!i)
681 return NULL;
682
683 i->t.eh_strategy_handler = ata_scsi_error;
684 i->t.eh_timed_out = ata_scsi_timed_out;
685 i->t.user_scan = ata_scsi_user_scan;
686
687 i->t.host_attrs.ac.attrs = &i->port_attrs[0];
688 i->t.host_attrs.ac.class = &ata_port_class.class;
689 i->t.host_attrs.ac.match = ata_tport_match;
690 transport_container_register(&i->t.host_attrs);
691
692 i->link_attr_cont.ac.class = &ata_link_class.class;
693 i->link_attr_cont.ac.attrs = &i->link_attrs[0];
694 i->link_attr_cont.ac.match = ata_tlink_match;
695 transport_container_register(&i->link_attr_cont);
696
697 i->dev_attr_cont.ac.class = &ata_dev_class.class;
698 i->dev_attr_cont.ac.attrs = &i->dev_attrs[0];
699 i->dev_attr_cont.ac.match = ata_tdev_match;
700 transport_container_register(&i->dev_attr_cont);
701
702 count = 0;
703 SETUP_PORT_ATTRIBUTE(nr_pmp_links);
704 SETUP_PORT_ATTRIBUTE(idle_irq);
705 BUG_ON(count > ATA_PORT_ATTRS);
706 i->port_attrs[count] = NULL;
707
708 count = 0;
709 SETUP_LINK_ATTRIBUTE(hw_sata_spd_limit);
710 SETUP_LINK_ATTRIBUTE(sata_spd_limit);
711 SETUP_LINK_ATTRIBUTE(sata_spd);
712 BUG_ON(count > ATA_LINK_ATTRS);
713 i->link_attrs[count] = NULL;
714
715 count = 0;
716 SETUP_DEV_ATTRIBUTE(class);
717 SETUP_DEV_ATTRIBUTE(pio_mode);
718 SETUP_DEV_ATTRIBUTE(dma_mode);
719 SETUP_DEV_ATTRIBUTE(xfer_mode);
720 SETUP_DEV_ATTRIBUTE(spdn_cnt);
721 SETUP_DEV_ATTRIBUTE(ering);
722 SETUP_DEV_ATTRIBUTE(id);
723 SETUP_DEV_ATTRIBUTE(gscr);
724 BUG_ON(count > ATA_DEV_ATTRS);
725 i->dev_attrs[count] = NULL;
726
727 return &i->t;
728}
729
730/**
731 * ata_release_transport -- release ATA transport template instance
732 * @t: transport template instance
733 */
734void ata_release_transport(struct scsi_transport_template *t)
735{
736 struct ata_internal *i = to_ata_internal(t);
737
738 transport_container_unregister(&i->t.host_attrs);
739 transport_container_unregister(&i->link_attr_cont);
740 transport_container_unregister(&i->dev_attr_cont);
741
742 kfree(i);
743}
744
745__init int libata_transport_init(void)
746{
747 int error;
748
749 error = transport_class_register(&ata_link_class);
750 if (error)
751 goto out_unregister_transport;
752 error = transport_class_register(&ata_port_class);
753 if (error)
754 goto out_unregister_link;
755 error = transport_class_register(&ata_dev_class);
756 if (error)
757 goto out_unregister_port;
758 return 0;
759
760 out_unregister_port:
761 transport_class_unregister(&ata_port_class);
762 out_unregister_link:
763 transport_class_unregister(&ata_link_class);
764 out_unregister_transport:
765 return error;
766
767}
768
769void __exit libata_transport_exit(void)
770{
771 transport_class_unregister(&ata_link_class);
772 transport_class_unregister(&ata_port_class);
773 transport_class_unregister(&ata_dev_class);
774}
diff --git a/drivers/ata/libata-transport.h b/drivers/ata/libata-transport.h
new file mode 100644
index 000000000000..2820cf864f11
--- /dev/null
+++ b/drivers/ata/libata-transport.h
@@ -0,0 +1,18 @@
1#ifndef _LIBATA_TRANSPORT_H
2#define _LIBATA_TRANSPORT_H
3
4
5extern struct scsi_transport_template *ata_scsi_transport_template;
6
7int ata_tlink_add(struct ata_link *link);
8void ata_tlink_delete(struct ata_link *link);
9
10int ata_tport_add(struct device *parent, struct ata_port *ap);
11void ata_tport_delete(struct ata_port *ap);
12
13struct scsi_transport_template *ata_attach_transport(void);
14void ata_release_transport(struct scsi_transport_template *t);
15
16__init int libata_transport_init(void);
17void __exit libata_transport_exit(void);
18#endif
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 9ce1ecc63e39..a9be110dbf51 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -86,6 +86,8 @@ extern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
86extern int ata_dev_configure(struct ata_device *dev); 86extern int ata_dev_configure(struct ata_device *dev);
87extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit); 87extern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit);
88extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel); 88extern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
89extern unsigned int ata_dev_set_feature(struct ata_device *dev,
90 u8 enable, u8 feature);
89extern void ata_sg_clean(struct ata_queued_cmd *qc); 91extern void ata_sg_clean(struct ata_queued_cmd *qc);
90extern void ata_qc_free(struct ata_queued_cmd *qc); 92extern void ata_qc_free(struct ata_queued_cmd *qc);
91extern void ata_qc_issue(struct ata_queued_cmd *qc); 93extern void ata_qc_issue(struct ata_queued_cmd *qc);
@@ -100,8 +102,7 @@ extern int sata_link_init_spd(struct ata_link *link);
100extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg); 102extern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
101extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg); 103extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
102extern struct ata_port *ata_port_alloc(struct ata_host *host); 104extern struct ata_port *ata_port_alloc(struct ata_host *host);
103extern void ata_dev_enable_pm(struct ata_device *dev, enum link_pm policy); 105extern const char *sata_spd_string(unsigned int spd);
104extern void ata_lpm_schedule(struct ata_port *ap, enum link_pm);
105 106
106/* libata-acpi.c */ 107/* libata-acpi.c */
107#ifdef CONFIG_ATA_ACPI 108#ifdef CONFIG_ATA_ACPI
@@ -137,10 +138,15 @@ extern void ata_scsi_hotplug(struct work_struct *work);
137extern void ata_schedule_scsi_eh(struct Scsi_Host *shost); 138extern void ata_schedule_scsi_eh(struct Scsi_Host *shost);
138extern void ata_scsi_dev_rescan(struct work_struct *work); 139extern void ata_scsi_dev_rescan(struct work_struct *work);
139extern int ata_bus_probe(struct ata_port *ap); 140extern int ata_bus_probe(struct ata_port *ap);
141extern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
142 unsigned int id, unsigned int lun);
143
140 144
141/* libata-eh.c */ 145/* libata-eh.c */
142extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd); 146extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd);
143extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd); 147extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd);
148extern void ata_eh_acquire(struct ata_port *ap);
149extern void ata_eh_release(struct ata_port *ap);
144extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); 150extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
145extern void ata_scsi_error(struct Scsi_Host *host); 151extern void ata_scsi_error(struct Scsi_Host *host);
146extern void ata_port_wait_eh(struct ata_port *ap); 152extern void ata_port_wait_eh(struct ata_port *ap);
@@ -164,11 +170,16 @@ extern int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
164 ata_postreset_fn_t postreset, 170 ata_postreset_fn_t postreset,
165 struct ata_link **r_failed_disk); 171 struct ata_link **r_failed_disk);
166extern void ata_eh_finish(struct ata_port *ap); 172extern void ata_eh_finish(struct ata_port *ap);
173extern int ata_ering_map(struct ata_ering *ering,
174 int (*map_fn)(struct ata_ering_entry *, void *),
175 void *arg);
167 176
168/* libata-pmp.c */ 177/* libata-pmp.c */
169#ifdef CONFIG_SATA_PMP 178#ifdef CONFIG_SATA_PMP
170extern int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val); 179extern int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val);
171extern int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val); 180extern int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val);
181extern int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
182 unsigned hints);
172extern int sata_pmp_attach(struct ata_device *dev); 183extern int sata_pmp_attach(struct ata_device *dev);
173#else /* CONFIG_SATA_PMP */ 184#else /* CONFIG_SATA_PMP */
174static inline int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val) 185static inline int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val)
@@ -181,6 +192,12 @@ static inline int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
181 return -EINVAL; 192 return -EINVAL;
182} 193}
183 194
195static inline int sata_pmp_set_lpm(struct ata_link *link,
196 enum ata_lpm_policy policy, unsigned hints)
197{
198 return -EINVAL;
199}
200
184static inline int sata_pmp_attach(struct ata_device *dev) 201static inline int sata_pmp_attach(struct ata_device *dev)
185{ 202{
186 return -EINVAL; 203 return -EINVAL;
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index 9cae65de750e..ec2c777fcdb0 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -826,7 +826,7 @@ static void bfin_dev_select(struct ata_port *ap, unsigned int device)
826 * @ctl: value to write 826 * @ctl: value to write
827 */ 827 */
828 828
829static u8 bfin_set_devctl(struct ata_port *ap, u8 ctl) 829static void bfin_set_devctl(struct ata_port *ap, u8 ctl)
830{ 830{
831 void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr; 831 void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
832 write_atapi_register(base, ATA_REG_CTRL, ctl); 832 write_atapi_register(base, ATA_REG_CTRL, ctl);
@@ -1046,7 +1046,7 @@ static void bfin_bus_post_reset(struct ata_port *ap, unsigned int devmask)
1046 dev1 = 0; 1046 dev1 = 0;
1047 break; 1047 break;
1048 } 1048 }
1049 msleep(50); /* give drive a breather */ 1049 ata_msleep(ap, 50); /* give drive a breather */
1050 } 1050 }
1051 if (dev1) 1051 if (dev1)
1052 ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 1052 ata_sff_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT);
@@ -1087,7 +1087,7 @@ static unsigned int bfin_bus_softreset(struct ata_port *ap,
1087 * 1087 *
1088 * Old drivers/ide uses the 2mS rule and then waits for ready 1088 * Old drivers/ide uses the 2mS rule and then waits for ready
1089 */ 1089 */
1090 msleep(150); 1090 ata_msleep(ap, 150);
1091 1091
1092 /* Before we perform post reset processing we want to see if 1092 /* Before we perform post reset processing we want to see if
1093 * the bus shows 0xFF because the odd clown forgets the D7 1093 * the bus shows 0xFF because the odd clown forgets the D7
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
index e5f289f59ca3..549d28dbf90d 100644
--- a/drivers/ata/pata_cmd640.c
+++ b/drivers/ata/pata_cmd640.c
@@ -161,6 +161,17 @@ static int cmd640_port_start(struct ata_port *ap)
161 return 0; 161 return 0;
162} 162}
163 163
164static bool cmd640_sff_irq_check(struct ata_port *ap)
165{
166 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
167 int irq_reg = ap->port_no ? ARTIM23 : CFR;
168 u8 irq_stat, irq_mask = ap->port_no ? 0x10 : 0x04;
169
170 pci_read_config_byte(pdev, irq_reg, &irq_stat);
171
172 return irq_stat & irq_mask;
173}
174
164static struct scsi_host_template cmd640_sht = { 175static struct scsi_host_template cmd640_sht = {
165 ATA_PIO_SHT(DRV_NAME), 176 ATA_PIO_SHT(DRV_NAME),
166}; 177};
@@ -169,6 +180,7 @@ static struct ata_port_operations cmd640_port_ops = {
169 .inherits = &ata_sff_port_ops, 180 .inherits = &ata_sff_port_ops,
170 /* In theory xfer_noirq is not needed once we kill the prefetcher */ 181 /* In theory xfer_noirq is not needed once we kill the prefetcher */
171 .sff_data_xfer = ata_sff_data_xfer_noirq, 182 .sff_data_xfer = ata_sff_data_xfer_noirq,
183 .sff_irq_check = cmd640_sff_irq_check,
172 .qc_issue = cmd640_qc_issue, 184 .qc_issue = cmd640_qc_issue,
173 .cable_detect = ata_cable_40wire, 185 .cable_detect = ata_cable_40wire,
174 .set_piomode = cmd640_set_piomode, 186 .set_piomode = cmd640_set_piomode,
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index e944aa0c5517..806292160b3f 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -34,7 +34,6 @@
34#include <linux/ata.h> 34#include <linux/ata.h>
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#include <pcmcia/cs.h>
38#include <pcmcia/cistpl.h> 37#include <pcmcia/cistpl.h>
39#include <pcmcia/ds.h> 38#include <pcmcia/ds.h>
40#include <pcmcia/cisreg.h> 39#include <pcmcia/cisreg.h>
@@ -168,63 +167,26 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
168}; 167};
169 168
170 169
171struct pcmcia_config_check { 170static int pcmcia_check_one_config(struct pcmcia_device *pdev, void *priv_data)
172 unsigned long ctl_base;
173 int skip_vcc;
174 int is_kme;
175};
176
177static int pcmcia_check_one_config(struct pcmcia_device *pdev,
178 cistpl_cftable_entry_t *cfg,
179 cistpl_cftable_entry_t *dflt,
180 unsigned int vcc,
181 void *priv_data)
182{ 171{
183 struct pcmcia_config_check *stk = priv_data; 172 int *is_kme = priv_data;
184 173
185 /* Check for matching Vcc, unless we're desperate */ 174 if (!(pdev->resource[0]->flags & IO_DATA_PATH_WIDTH_8)) {
186 if (!stk->skip_vcc) { 175 pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
187 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { 176 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
188 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
189 return -ENODEV;
190 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
191 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
192 return -ENODEV;
193 }
194 } 177 }
178 pdev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
179 pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
195 180
196 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 181 if (pdev->resource[1]->end) {
197 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 182 pdev->resource[0]->end = 8;
198 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM)) 183 pdev->resource[1]->end = (*is_kme) ? 2 : 1;
199 pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000; 184 } else {
200 185 if (pdev->resource[0]->end < 16)
201 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
202 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
203 pdev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
204 pdev->resource[0]->start = io->win[0].base;
205 if (!(io->flags & CISTPL_IO_16BIT)) {
206 pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
207 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
208 }
209 if (io->nwin == 2) {
210 pdev->resource[0]->end = 8;
211 pdev->resource[1]->start = io->win[1].base;
212 pdev->resource[1]->end = (stk->is_kme) ? 2 : 1;
213 if (pcmcia_request_io(pdev) != 0)
214 return -ENODEV;
215 stk->ctl_base = pdev->resource[1]->start;
216 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
217 pdev->resource[0]->end = io->win[0].len;
218 pdev->resource[1]->end = 0;
219 if (pcmcia_request_io(pdev) != 0)
220 return -ENODEV;
221 stk->ctl_base = pdev->resource[0]->start + 0x0e;
222 } else
223 return -ENODEV; 186 return -ENODEV;
224 /* If we've got this far, we're done */
225 return 0;
226 } 187 }
227 return -ENODEV; 188
189 return pcmcia_request_io(pdev);
228} 190}
229 191
230/** 192/**
@@ -239,7 +201,6 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
239{ 201{
240 struct ata_host *host; 202 struct ata_host *host;
241 struct ata_port *ap; 203 struct ata_port *ap;
242 struct pcmcia_config_check *stk = NULL;
243 int is_kme = 0, ret = -ENOMEM, p; 204 int is_kme = 0, ret = -ENOMEM, p;
244 unsigned long io_base, ctl_base; 205 unsigned long io_base, ctl_base;
245 void __iomem *io_addr, *ctl_addr; 206 void __iomem *io_addr, *ctl_addr;
@@ -247,10 +208,8 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
247 struct ata_port_operations *ops = &pcmcia_port_ops; 208 struct ata_port_operations *ops = &pcmcia_port_ops;
248 209
249 /* Set up attributes in order to probe card and get resources */ 210 /* Set up attributes in order to probe card and get resources */
250 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 211 pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
251 pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 212 CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
252 pdev->conf.Attributes = CONF_ENABLE_IRQ;
253 pdev->conf.IntType = INT_MEMORY_AND_IO;
254 213
255 /* See if we have a manufacturer identifier. Use it to set is_kme for 214 /* See if we have a manufacturer identifier. Use it to set is_kme for
256 vendor quirks */ 215 vendor quirks */
@@ -258,25 +217,21 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
258 ((pdev->card_id == PRODID_KME_KXLC005_A) || 217 ((pdev->card_id == PRODID_KME_KXLC005_A) ||
259 (pdev->card_id == PRODID_KME_KXLC005_B))); 218 (pdev->card_id == PRODID_KME_KXLC005_B)));
260 219
261 /* Allocate resoure probing structures */ 220 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, &is_kme)) {
262 221 pdev->config_flags &= ~CONF_AUTO_CHECK_VCC;
263 stk = kzalloc(sizeof(*stk), GFP_KERNEL); 222 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, &is_kme))
264 if (!stk)
265 goto out1;
266 stk->is_kme = is_kme;
267 stk->skip_vcc = io_base = ctl_base = 0;
268
269 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk)) {
270 stk->skip_vcc = 1;
271 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk))
272 goto failed; /* No suitable config found */ 223 goto failed; /* No suitable config found */
273 } 224 }
274 io_base = pdev->resource[0]->start; 225 io_base = pdev->resource[0]->start;
275 ctl_base = stk->ctl_base; 226 if (pdev->resource[1]->end)
227 ctl_base = pdev->resource[1]->start;
228 else
229 ctl_base = pdev->resource[0]->start + 0x0e;
230
276 if (!pdev->irq) 231 if (!pdev->irq)
277 goto failed; 232 goto failed;
278 233
279 ret = pcmcia_request_configuration(pdev, &pdev->conf); 234 ret = pcmcia_enable_device(pdev);
280 if (ret) 235 if (ret)
281 goto failed; 236 goto failed;
282 237
@@ -329,13 +284,10 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
329 goto failed; 284 goto failed;
330 285
331 pdev->priv = host; 286 pdev->priv = host;
332 kfree(stk);
333 return 0; 287 return 0;
334 288
335failed: 289failed:
336 kfree(stk);
337 pcmcia_disable_device(pdev); 290 pcmcia_disable_device(pdev);
338out1:
339 return ret; 291 return ret;
340} 292}
341 293
@@ -430,9 +382,7 @@ MODULE_DEVICE_TABLE(pcmcia, pcmcia_devices);
430 382
431static struct pcmcia_driver pcmcia_driver = { 383static struct pcmcia_driver pcmcia_driver = {
432 .owner = THIS_MODULE, 384 .owner = THIS_MODULE,
433 .drv = { 385 .name = DRV_NAME,
434 .name = DRV_NAME,
435 },
436 .id_table = pcmcia_devices, 386 .id_table = pcmcia_devices,
437 .probe = pcmcia_init_one, 387 .probe = pcmcia_init_one,
438 .remove = pcmcia_remove_one, 388 .remove = pcmcia_remove_one,
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index c39f213e1bbc..c2ed5868dda6 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -44,6 +44,27 @@ static void pdc202xx_exec_command(struct ata_port *ap,
44 ndelay(400); 44 ndelay(400);
45} 45}
46 46
47static bool pdc202xx_irq_check(struct ata_port *ap)
48{
49 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
50 unsigned long master = pci_resource_start(pdev, 4);
51 u8 sc1d = inb(master + 0x1d);
52
53 if (ap->port_no) {
54 /*
55 * bit 7: error, bit 6: interrupting,
56 * bit 5: FIFO full, bit 4: FIFO empty
57 */
58 return sc1d & 0x40;
59 } else {
60 /*
61 * bit 3: error, bit 2: interrupting,
62 * bit 1: FIFO full, bit 0: FIFO empty
63 */
64 return sc1d & 0x04;
65 }
66}
67
47/** 68/**
48 * pdc202xx_configure_piomode - set chip PIO timing 69 * pdc202xx_configure_piomode - set chip PIO timing
49 * @ap: ATA interface 70 * @ap: ATA interface
@@ -282,6 +303,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
282 .set_dmamode = pdc202xx_set_dmamode, 303 .set_dmamode = pdc202xx_set_dmamode,
283 304
284 .sff_exec_command = pdc202xx_exec_command, 305 .sff_exec_command = pdc202xx_exec_command,
306 .sff_irq_check = pdc202xx_irq_check,
285}; 307};
286 308
287static struct ata_port_operations pdc2026x_port_ops = { 309static struct ata_port_operations pdc2026x_port_ops = {
@@ -297,6 +319,7 @@ static struct ata_port_operations pdc2026x_port_ops = {
297 .port_start = pdc2026x_port_start, 319 .port_start = pdc2026x_port_start,
298 320
299 .sff_exec_command = pdc202xx_exec_command, 321 .sff_exec_command = pdc202xx_exec_command,
322 .sff_irq_check = pdc202xx_irq_check,
300}; 323};
301 324
302static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) 325static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_samsung_cf.c b/drivers/ata/pata_samsung_cf.c
index 6f9cfb24b751..8a51d673e5b2 100644
--- a/drivers/ata/pata_samsung_cf.c
+++ b/drivers/ata/pata_samsung_cf.c
@@ -322,7 +322,7 @@ static int pata_s3c_wait_after_reset(struct ata_link *link,
322{ 322{
323 int rc; 323 int rc;
324 324
325 msleep(ATA_WAIT_AFTER_RESET); 325 ata_msleep(link->ap, ATA_WAIT_AFTER_RESET);
326 326
327 /* always check readiness of the master device */ 327 /* always check readiness of the master device */
328 rc = ata_sff_wait_ready(link, deadline); 328 rc = ata_sff_wait_ready(link, deadline);
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index fe36966f7e34..093715c3273a 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -530,7 +530,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
530 * 530 *
531 * Old drivers/ide uses the 2mS rule and then waits for ready. 531 * Old drivers/ide uses the 2mS rule and then waits for ready.
532 */ 532 */
533 msleep(150); 533 ata_msleep(ap, 150);
534 534
535 /* always check readiness of the master device */ 535 /* always check readiness of the master device */
536 rc = ata_sff_wait_ready(link, deadline); 536 rc = ata_sff_wait_ready(link, deadline);
@@ -559,7 +559,7 @@ static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
559 lbal = in_be32(ioaddr->lbal_addr); 559 lbal = in_be32(ioaddr->lbal_addr);
560 if ((nsect == 1) && (lbal == 1)) 560 if ((nsect == 1) && (lbal == 1))
561 break; 561 break;
562 msleep(50); /* give drive a breather */ 562 ata_msleep(ap, 50); /* give drive a breather */
563 } 563 }
564 564
565 rc = ata_sff_wait_ready(link, deadline); 565 rc = ata_sff_wait_ready(link, deadline);
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index d3190d7ec304..00eefbd84b33 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -202,14 +202,25 @@ static void sil680_set_dmamode(struct ata_port *ap, struct ata_device *adev)
202 * LOCKING: 202 * LOCKING:
203 * spin_lock_irqsave(host lock) 203 * spin_lock_irqsave(host lock)
204 */ 204 */
205void sil680_sff_exec_command(struct ata_port *ap, 205static void sil680_sff_exec_command(struct ata_port *ap,
206 const struct ata_taskfile *tf) 206 const struct ata_taskfile *tf)
207{ 207{
208 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command); 208 DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
209 iowrite8(tf->command, ap->ioaddr.command_addr); 209 iowrite8(tf->command, ap->ioaddr.command_addr);
210 ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 210 ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
211} 211}
212 212
213static bool sil680_sff_irq_check(struct ata_port *ap)
214{
215 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
216 unsigned long addr = sil680_selreg(ap, 1);
217 u8 val;
218
219 pci_read_config_byte(pdev, addr, &val);
220
221 return val & 0x08;
222}
223
213static struct scsi_host_template sil680_sht = { 224static struct scsi_host_template sil680_sht = {
214 ATA_BMDMA_SHT(DRV_NAME), 225 ATA_BMDMA_SHT(DRV_NAME),
215}; 226};
@@ -218,6 +229,7 @@ static struct scsi_host_template sil680_sht = {
218static struct ata_port_operations sil680_port_ops = { 229static struct ata_port_operations sil680_port_ops = {
219 .inherits = &ata_bmdma32_port_ops, 230 .inherits = &ata_bmdma32_port_ops,
220 .sff_exec_command = sil680_sff_exec_command, 231 .sff_exec_command = sil680_sff_exec_command,
232 .sff_irq_check = sil680_sff_irq_check,
221 .cable_detect = sil680_cable_detect, 233 .cable_detect = sil680_cable_detect,
222 .set_piomode = sil680_set_piomode, 234 .set_piomode = sil680_set_piomode,
223 .set_dmamode = sil680_set_dmamode, 235 .set_dmamode = sil680_set_dmamode,
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index 98548f640c8e..7f5d020ed56c 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -227,6 +227,16 @@ static int sl82c105_qc_defer(struct ata_queued_cmd *qc)
227 return 0; 227 return 0;
228} 228}
229 229
230static bool sl82c105_sff_irq_check(struct ata_port *ap)
231{
232 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
233 u32 val, mask = ap->port_no ? CTRL_IDE_IRQB : CTRL_IDE_IRQA;
234
235 pci_read_config_dword(pdev, 0x40, &val);
236
237 return val & mask;
238}
239
230static struct scsi_host_template sl82c105_sht = { 240static struct scsi_host_template sl82c105_sht = {
231 ATA_BMDMA_SHT(DRV_NAME), 241 ATA_BMDMA_SHT(DRV_NAME),
232}; 242};
@@ -239,6 +249,7 @@ static struct ata_port_operations sl82c105_port_ops = {
239 .cable_detect = ata_cable_40wire, 249 .cable_detect = ata_cable_40wire,
240 .set_piomode = sl82c105_set_piomode, 250 .set_piomode = sl82c105_set_piomode,
241 .prereset = sl82c105_pre_reset, 251 .prereset = sl82c105_pre_reset,
252 .sff_irq_check = sl82c105_sff_irq_check,
242}; 253};
243 254
244/** 255/**
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 7325f77480dc..b0214d00d50b 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -678,7 +678,7 @@ static void sata_fsl_port_stop(struct ata_port *ap)
678 iowrite32(temp, hcr_base + HCONTROL); 678 iowrite32(temp, hcr_base + HCONTROL);
679 679
680 /* Poll for controller to go offline - should happen immediately */ 680 /* Poll for controller to go offline - should happen immediately */
681 ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1); 681 ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE, 1, 1);
682 682
683 ap->private_data = NULL; 683 ap->private_data = NULL;
684 dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ, 684 dma_free_coherent(dev, SATA_FSL_PORT_PRIV_DMA_SZ,
@@ -729,7 +729,8 @@ try_offline_again:
729 iowrite32(temp, hcr_base + HCONTROL); 729 iowrite32(temp, hcr_base + HCONTROL);
730 730
731 /* Poll for controller to go offline */ 731 /* Poll for controller to go offline */
732 temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, ONLINE, 1, 500); 732 temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, ONLINE,
733 1, 500);
733 734
734 if (temp & ONLINE) { 735 if (temp & ONLINE) {
735 ata_port_printk(ap, KERN_ERR, 736 ata_port_printk(ap, KERN_ERR,
@@ -752,7 +753,7 @@ try_offline_again:
752 /* 753 /*
753 * PHY reset should remain asserted for atleast 1ms 754 * PHY reset should remain asserted for atleast 1ms
754 */ 755 */
755 msleep(1); 756 ata_msleep(ap, 1);
756 757
757 /* 758 /*
758 * Now, bring the host controller online again, this can take time 759 * Now, bring the host controller online again, this can take time
@@ -766,7 +767,7 @@ try_offline_again:
766 temp |= HCONTROL_PMP_ATTACHED; 767 temp |= HCONTROL_PMP_ATTACHED;
767 iowrite32(temp, hcr_base + HCONTROL); 768 iowrite32(temp, hcr_base + HCONTROL);
768 769
769 temp = ata_wait_register(hcr_base + HSTATUS, ONLINE, 0, 1, 500); 770 temp = ata_wait_register(ap, hcr_base + HSTATUS, ONLINE, 0, 1, 500);
770 771
771 if (!(temp & ONLINE)) { 772 if (!(temp & ONLINE)) {
772 ata_port_printk(ap, KERN_ERR, 773 ata_port_printk(ap, KERN_ERR,
@@ -784,7 +785,7 @@ try_offline_again:
784 * presence 785 * presence
785 */ 786 */
786 787
787 temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0, 1, 500); 788 temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0, 1, 500);
788 if ((!(temp & 0x10)) || ata_link_offline(link)) { 789 if ((!(temp & 0x10)) || ata_link_offline(link)) {
789 ata_port_printk(ap, KERN_WARNING, 790 ata_port_printk(ap, KERN_WARNING,
790 "No Device OR PHYRDY change,Hstatus = 0x%x\n", 791 "No Device OR PHYRDY change,Hstatus = 0x%x\n",
@@ -797,7 +798,7 @@ try_offline_again:
797 * Wait for the first D2H from device,i.e,signature update notification 798 * Wait for the first D2H from device,i.e,signature update notification
798 */ 799 */
799 start_jiffies = jiffies; 800 start_jiffies = jiffies;
800 temp = ata_wait_register(hcr_base + HSTATUS, 0xFF, 0x10, 801 temp = ata_wait_register(ap, hcr_base + HSTATUS, 0xFF, 0x10,
801 500, jiffies_to_msecs(deadline - start_jiffies)); 802 500, jiffies_to_msecs(deadline - start_jiffies));
802 803
803 if ((temp & 0xFF) != 0x18) { 804 if ((temp & 0xFF) != 0x18) {
@@ -880,7 +881,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
880 iowrite32(pmp, CQPMP + hcr_base); 881 iowrite32(pmp, CQPMP + hcr_base);
881 iowrite32(1, CQ + hcr_base); 882 iowrite32(1, CQ + hcr_base);
882 883
883 temp = ata_wait_register(CQ + hcr_base, 0x1, 0x1, 1, 5000); 884 temp = ata_wait_register(ap, CQ + hcr_base, 0x1, 0x1, 1, 5000);
884 if (temp & 0x1) { 885 if (temp & 0x1) {
885 ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n"); 886 ata_port_printk(ap, KERN_WARNING, "ATA_SRST issue failed\n");
886 887
@@ -896,7 +897,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
896 goto err; 897 goto err;
897 } 898 }
898 899
899 msleep(1); 900 ata_msleep(ap, 1);
900 901
901 /* 902 /*
902 * SATA device enters reset state after receving a Control register 903 * SATA device enters reset state after receving a Control register
@@ -915,7 +916,7 @@ static int sata_fsl_softreset(struct ata_link *link, unsigned int *class,
915 if (pmp != SATA_PMP_CTRL_PORT) 916 if (pmp != SATA_PMP_CTRL_PORT)
916 iowrite32(pmp, CQPMP + hcr_base); 917 iowrite32(pmp, CQPMP + hcr_base);
917 iowrite32(1, CQ + hcr_base); 918 iowrite32(1, CQ + hcr_base);
918 msleep(150); /* ?? */ 919 ata_msleep(ap, 150); /* ?? */
919 920
920 /* 921 /*
921 * The above command would have signalled an interrupt on command 922 * The above command would have signalled an interrupt on command
@@ -1137,17 +1138,13 @@ static void sata_fsl_host_intr(struct ata_port *ap)
1137 ioread32(hcr_base + CE)); 1138 ioread32(hcr_base + CE));
1138 1139
1139 for (i = 0; i < SATA_FSL_QUEUE_DEPTH; i++) { 1140 for (i = 0; i < SATA_FSL_QUEUE_DEPTH; i++) {
1140 if (done_mask & (1 << i)) { 1141 if (done_mask & (1 << i))
1141 qc = ata_qc_from_tag(ap, i);
1142 if (qc) {
1143 ata_qc_complete(qc);
1144 }
1145 DPRINTK 1142 DPRINTK
1146 ("completing ncq cmd,tag=%d,CC=0x%x,CA=0x%x\n", 1143 ("completing ncq cmd,tag=%d,CC=0x%x,CA=0x%x\n",
1147 i, ioread32(hcr_base + CC), 1144 i, ioread32(hcr_base + CC),
1148 ioread32(hcr_base + CA)); 1145 ioread32(hcr_base + CA));
1149 }
1150 } 1146 }
1147 ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
1151 return; 1148 return;
1152 1149
1153 } else if ((ap->qc_active & (1 << ATA_TAG_INTERNAL))) { 1150 } else if ((ap->qc_active & (1 << ATA_TAG_INTERNAL))) {
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index a36149ebf4a2..83a44471b189 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -614,7 +614,7 @@ static int inic_hardreset(struct ata_link *link, unsigned int *class,
614 614
615 writew(IDMA_CTL_RST_ATA, idma_ctl); 615 writew(IDMA_CTL_RST_ATA, idma_ctl);
616 readw(idma_ctl); /* flush */ 616 readw(idma_ctl); /* flush */
617 msleep(1); 617 ata_msleep(ap, 1);
618 writew(0, idma_ctl); 618 writew(0, idma_ctl);
619 619
620 rc = sata_link_resume(link, timing, deadline); 620 rc = sata_link_resume(link, timing, deadline);
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index a9fd9709c262..bf74a36d3cc3 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -2743,18 +2743,11 @@ static void mv_err_intr(struct ata_port *ap)
2743 } 2743 }
2744} 2744}
2745 2745
2746static void mv_process_crpb_response(struct ata_port *ap, 2746static bool mv_process_crpb_response(struct ata_port *ap,
2747 struct mv_crpb *response, unsigned int tag, int ncq_enabled) 2747 struct mv_crpb *response, unsigned int tag, int ncq_enabled)
2748{ 2748{
2749 u8 ata_status; 2749 u8 ata_status;
2750 u16 edma_status = le16_to_cpu(response->flags); 2750 u16 edma_status = le16_to_cpu(response->flags);
2751 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
2752
2753 if (unlikely(!qc)) {
2754 ata_port_printk(ap, KERN_ERR, "%s: no qc for tag=%d\n",
2755 __func__, tag);
2756 return;
2757 }
2758 2751
2759 /* 2752 /*
2760 * edma_status from a response queue entry: 2753 * edma_status from a response queue entry:
@@ -2768,13 +2761,14 @@ static void mv_process_crpb_response(struct ata_port *ap,
2768 * Error will be seen/handled by 2761 * Error will be seen/handled by
2769 * mv_err_intr(). So do nothing at all here. 2762 * mv_err_intr(). So do nothing at all here.
2770 */ 2763 */
2771 return; 2764 return false;
2772 } 2765 }
2773 } 2766 }
2774 ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT; 2767 ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT;
2775 if (!ac_err_mask(ata_status)) 2768 if (!ac_err_mask(ata_status))
2776 ata_qc_complete(qc); 2769 return true;
2777 /* else: leave it for mv_err_intr() */ 2770 /* else: leave it for mv_err_intr() */
2771 return false;
2778} 2772}
2779 2773
2780static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp) 2774static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp)
@@ -2783,6 +2777,7 @@ static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp
2783 struct mv_host_priv *hpriv = ap->host->private_data; 2777 struct mv_host_priv *hpriv = ap->host->private_data;
2784 u32 in_index; 2778 u32 in_index;
2785 bool work_done = false; 2779 bool work_done = false;
2780 u32 done_mask = 0;
2786 int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN); 2781 int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN);
2787 2782
2788 /* Get the hardware queue position index */ 2783 /* Get the hardware queue position index */
@@ -2803,15 +2798,19 @@ static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp
2803 /* Gen II/IIE: get command tag from CRPB entry */ 2798 /* Gen II/IIE: get command tag from CRPB entry */
2804 tag = le16_to_cpu(response->id) & 0x1f; 2799 tag = le16_to_cpu(response->id) & 0x1f;
2805 } 2800 }
2806 mv_process_crpb_response(ap, response, tag, ncq_enabled); 2801 if (mv_process_crpb_response(ap, response, tag, ncq_enabled))
2802 done_mask |= 1 << tag;
2807 work_done = true; 2803 work_done = true;
2808 } 2804 }
2809 2805
2810 /* Update the software queue position index in hardware */ 2806 if (work_done) {
2811 if (work_done) 2807 ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
2808
2809 /* Update the software queue position index in hardware */
2812 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 2810 writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
2813 (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT), 2811 (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT),
2814 port_mmio + EDMA_RSP_Q_OUT_PTR); 2812 port_mmio + EDMA_RSP_Q_OUT_PTR);
2813 }
2815} 2814}
2816 2815
2817static void mv_port_intr(struct ata_port *ap, u32 port_cause) 2816static void mv_port_intr(struct ata_port *ap, u32 port_cause)
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index cb89ef8d99d9..7254e255fd78 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -873,29 +873,11 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
873 ata_port_freeze(ap); 873 ata_port_freeze(ap);
874 else 874 else
875 ata_port_abort(ap); 875 ata_port_abort(ap);
876 return 1; 876 return -1;
877 } 877 }
878 878
879 if (likely(flags & NV_CPB_RESP_DONE)) { 879 if (likely(flags & NV_CPB_RESP_DONE))
880 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num); 880 return 1;
881 VPRINTK("CPB flags done, flags=0x%x\n", flags);
882 if (likely(qc)) {
883 DPRINTK("Completing qc from tag %d\n", cpb_num);
884 ata_qc_complete(qc);
885 } else {
886 struct ata_eh_info *ehi = &ap->link.eh_info;
887 /* Notifier bits set without a command may indicate the drive
888 is misbehaving. Raise host state machine violation on this
889 condition. */
890 ata_port_printk(ap, KERN_ERR,
891 "notifier for tag %d with no cmd?\n",
892 cpb_num);
893 ehi->err_mask |= AC_ERR_HSM;
894 ehi->action |= ATA_EH_RESET;
895 ata_port_freeze(ap);
896 return 1;
897 }
898 }
899 return 0; 881 return 0;
900} 882}
901 883
@@ -1018,6 +1000,7 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
1018 NV_ADMA_STAT_CPBERR | 1000 NV_ADMA_STAT_CPBERR |
1019 NV_ADMA_STAT_CMD_COMPLETE)) { 1001 NV_ADMA_STAT_CMD_COMPLETE)) {
1020 u32 check_commands = notifier_clears[i]; 1002 u32 check_commands = notifier_clears[i];
1003 u32 done_mask = 0;
1021 int pos, rc; 1004 int pos, rc;
1022 1005
1023 if (status & NV_ADMA_STAT_CPBERR) { 1006 if (status & NV_ADMA_STAT_CPBERR) {
@@ -1034,10 +1017,13 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
1034 pos--; 1017 pos--;
1035 rc = nv_adma_check_cpb(ap, pos, 1018 rc = nv_adma_check_cpb(ap, pos,
1036 notifier_error & (1 << pos)); 1019 notifier_error & (1 << pos));
1037 if (unlikely(rc)) 1020 if (rc > 0)
1021 done_mask |= 1 << pos;
1022 else if (unlikely(rc < 0))
1038 check_commands = 0; 1023 check_commands = 0;
1039 check_commands &= ~(1 << pos); 1024 check_commands &= ~(1 << pos);
1040 } 1025 }
1026 ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
1041 } 1027 }
1042 } 1028 }
1043 1029
@@ -2132,7 +2118,6 @@ static int nv_swncq_sdbfis(struct ata_port *ap)
2132 struct ata_eh_info *ehi = &ap->link.eh_info; 2118 struct ata_eh_info *ehi = &ap->link.eh_info;
2133 u32 sactive; 2119 u32 sactive;
2134 u32 done_mask; 2120 u32 done_mask;
2135 int i;
2136 u8 host_stat; 2121 u8 host_stat;
2137 u8 lack_dhfis = 0; 2122 u8 lack_dhfis = 0;
2138 2123
@@ -2152,27 +2137,11 @@ static int nv_swncq_sdbfis(struct ata_port *ap)
2152 sactive = readl(pp->sactive_block); 2137 sactive = readl(pp->sactive_block);
2153 done_mask = pp->qc_active ^ sactive; 2138 done_mask = pp->qc_active ^ sactive;
2154 2139
2155 if (unlikely(done_mask & sactive)) { 2140 pp->qc_active &= ~done_mask;
2156 ata_ehi_clear_desc(ehi); 2141 pp->dhfis_bits &= ~done_mask;
2157 ata_ehi_push_desc(ehi, "illegal SWNCQ:qc_active transition" 2142 pp->dmafis_bits &= ~done_mask;
2158 "(%08x->%08x)", pp->qc_active, sactive); 2143 pp->sdbfis_bits |= done_mask;
2159 ehi->err_mask |= AC_ERR_HSM; 2144 ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask);
2160 ehi->action |= ATA_EH_RESET;
2161 return -EINVAL;
2162 }
2163 for (i = 0; i < ATA_MAX_QUEUE; i++) {
2164 if (!(done_mask & (1 << i)))
2165 continue;
2166
2167 qc = ata_qc_from_tag(ap, i);
2168 if (qc) {
2169 ata_qc_complete(qc);
2170 pp->qc_active &= ~(1 << i);
2171 pp->dhfis_bits &= ~(1 << i);
2172 pp->dmafis_bits &= ~(1 << i);
2173 pp->sdbfis_bits |= (1 << i);
2174 }
2175 }
2176 2145
2177 if (!ap->qc_active) { 2146 if (!ap->qc_active) {
2178 DPRINTK("over\n"); 2147 DPRINTK("over\n");
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index be7726d7686d..af41c6fd1254 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -589,9 +589,9 @@ static int sil24_init_port(struct ata_port *ap)
589 sil24_clear_pmp(ap); 589 sil24_clear_pmp(ap);
590 590
591 writel(PORT_CS_INIT, port + PORT_CTRL_STAT); 591 writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
592 ata_wait_register(port + PORT_CTRL_STAT, 592 ata_wait_register(ap, port + PORT_CTRL_STAT,
593 PORT_CS_INIT, PORT_CS_INIT, 10, 100); 593 PORT_CS_INIT, PORT_CS_INIT, 10, 100);
594 tmp = ata_wait_register(port + PORT_CTRL_STAT, 594 tmp = ata_wait_register(ap, port + PORT_CTRL_STAT,
595 PORT_CS_RDY, 0, 10, 100); 595 PORT_CS_RDY, 0, 10, 100);
596 596
597 if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY) { 597 if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY) {
@@ -631,7 +631,7 @@ static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp,
631 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); 631 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4);
632 632
633 irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; 633 irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
634 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, irq_mask, 0x0, 634 irq_stat = ata_wait_register(ap, port + PORT_IRQ_STAT, irq_mask, 0x0,
635 10, timeout_msec); 635 10, timeout_msec);
636 636
637 writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */ 637 writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */
@@ -719,9 +719,9 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class,
719 "state, performing PORT_RST\n"); 719 "state, performing PORT_RST\n");
720 720
721 writel(PORT_CS_PORT_RST, port + PORT_CTRL_STAT); 721 writel(PORT_CS_PORT_RST, port + PORT_CTRL_STAT);
722 msleep(10); 722 ata_msleep(ap, 10);
723 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); 723 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
724 ata_wait_register(port + PORT_CTRL_STAT, PORT_CS_RDY, 0, 724 ata_wait_register(ap, port + PORT_CTRL_STAT, PORT_CS_RDY, 0,
725 10, 5000); 725 10, 5000);
726 726
727 /* restore port configuration */ 727 /* restore port configuration */
@@ -740,7 +740,7 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class,
740 tout_msec = 5000; 740 tout_msec = 5000;
741 741
742 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT); 742 writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
743 tmp = ata_wait_register(port + PORT_CTRL_STAT, 743 tmp = ata_wait_register(ap, port + PORT_CTRL_STAT,
744 PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, 744 PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10,
745 tout_msec); 745 tout_msec);
746 746
@@ -1253,7 +1253,7 @@ static void sil24_init_controller(struct ata_host *host)
1253 tmp = readl(port + PORT_CTRL_STAT); 1253 tmp = readl(port + PORT_CTRL_STAT);
1254 if (tmp & PORT_CS_PORT_RST) { 1254 if (tmp & PORT_CS_PORT_RST) {
1255 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR); 1255 writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
1256 tmp = ata_wait_register(port + PORT_CTRL_STAT, 1256 tmp = ata_wait_register(NULL, port + PORT_CTRL_STAT,
1257 PORT_CS_PORT_RST, 1257 PORT_CS_PORT_RST,
1258 PORT_CS_PORT_RST, 10, 100); 1258 PORT_CS_PORT_RST, 10, 100);
1259 if (tmp & PORT_CS_PORT_RST) 1259 if (tmp & PORT_CS_PORT_RST)
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 4730c42a5ee5..c21589986c69 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -349,7 +349,7 @@ static int vt6420_prereset(struct ata_link *link, unsigned long deadline)
349 349
350 /* wait for phy to become ready, if necessary */ 350 /* wait for phy to become ready, if necessary */
351 do { 351 do {
352 msleep(200); 352 ata_msleep(link->ap, 200);
353 svia_scr_read(link, SCR_STATUS, &sstatus); 353 svia_scr_read(link, SCR_STATUS, &sstatus);
354 if ((sstatus & 0xf) != 1) 354 if ((sstatus & 0xf) != 1)
355 break; 355 break;
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index ee9ddeb53417..8cb0347dec28 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -3156,7 +3156,6 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
3156{ 3156{
3157 struct atm_dev *dev; 3157 struct atm_dev *dev;
3158 IADEV *iadev; 3158 IADEV *iadev;
3159 unsigned long flags;
3160 int ret; 3159 int ret;
3161 3160
3162 iadev = kzalloc(sizeof(*iadev), GFP_KERNEL); 3161 iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
@@ -3188,19 +3187,14 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
3188 ia_dev[iadev_count] = iadev; 3187 ia_dev[iadev_count] = iadev;
3189 _ia_dev[iadev_count] = dev; 3188 _ia_dev[iadev_count] = dev;
3190 iadev_count++; 3189 iadev_count++;
3191 spin_lock_init(&iadev->misc_lock);
3192 /* First fixes first. I don't want to think about this now. */
3193 spin_lock_irqsave(&iadev->misc_lock, flags);
3194 if (ia_init(dev) || ia_start(dev)) { 3190 if (ia_init(dev) || ia_start(dev)) {
3195 IF_INIT(printk("IA register failed!\n");) 3191 IF_INIT(printk("IA register failed!\n");)
3196 iadev_count--; 3192 iadev_count--;
3197 ia_dev[iadev_count] = NULL; 3193 ia_dev[iadev_count] = NULL;
3198 _ia_dev[iadev_count] = NULL; 3194 _ia_dev[iadev_count] = NULL;
3199 spin_unlock_irqrestore(&iadev->misc_lock, flags);
3200 ret = -EINVAL; 3195 ret = -EINVAL;
3201 goto err_out_deregister_dev; 3196 goto err_out_deregister_dev;
3202 } 3197 }
3203 spin_unlock_irqrestore(&iadev->misc_lock, flags);
3204 IF_EVENT(printk("iadev_count = %d\n", iadev_count);) 3198 IF_EVENT(printk("iadev_count = %d\n", iadev_count);)
3205 3199
3206 iadev->next_board = ia_boards; 3200 iadev->next_board = ia_boards;
diff --git a/drivers/atm/iphase.h b/drivers/atm/iphase.h
index b2cd20f549cb..077735e0e04b 100644
--- a/drivers/atm/iphase.h
+++ b/drivers/atm/iphase.h
@@ -1022,7 +1022,7 @@ typedef struct iadev_t {
1022 struct dle_q rx_dle_q; 1022 struct dle_q rx_dle_q;
1023 struct free_desc_q *rx_free_desc_qhead; 1023 struct free_desc_q *rx_free_desc_qhead;
1024 struct sk_buff_head rx_dma_q; 1024 struct sk_buff_head rx_dma_q;
1025 spinlock_t rx_lock, misc_lock; 1025 spinlock_t rx_lock;
1026 struct atm_vcc **rx_open; /* list of all open VCs */ 1026 struct atm_vcc **rx_open; /* list of all open VCs */
1027 u16 num_rx_desc, rx_buf_sz, rxing; 1027 u16 num_rx_desc, rx_buf_sz, rxing;
1028 u32 rx_pkt_ram, rx_tmp_cnt; 1028 u32 rx_pkt_ram, rx_tmp_cnt;
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index f916ddf63938..f46138ab38b6 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -444,6 +444,7 @@ static ssize_t console_show(struct device *dev, struct device_attribute *attr,
444 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev); 444 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
445 struct solos_card *card = atmdev->dev_data; 445 struct solos_card *card = atmdev->dev_data;
446 struct sk_buff *skb; 446 struct sk_buff *skb;
447 unsigned int len;
447 448
448 spin_lock(&card->cli_queue_lock); 449 spin_lock(&card->cli_queue_lock);
449 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]); 450 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
@@ -451,11 +452,12 @@ static ssize_t console_show(struct device *dev, struct device_attribute *attr,
451 if(skb == NULL) 452 if(skb == NULL)
452 return sprintf(buf, "No data.\n"); 453 return sprintf(buf, "No data.\n");
453 454
454 memcpy(buf, skb->data, skb->len); 455 len = skb->len;
455 dev_dbg(&card->dev->dev, "len: %d\n", skb->len); 456 memcpy(buf, skb->data, len);
457 dev_dbg(&card->dev->dev, "len: %d\n", len);
456 458
457 kfree_skb(skb); 459 kfree_skb(skb);
458 return skb->len; 460 return len;
459} 461}
460 462
461static int send_command(struct solos_card *card, int dev, const char *buf, size_t size) 463static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index cbccf9a3cee4..abe46edfe5b4 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -3,6 +3,7 @@ obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o
3obj-$(CONFIG_PM_RUNTIME) += runtime.o 3obj-$(CONFIG_PM_RUNTIME) += runtime.o
4obj-$(CONFIG_PM_OPS) += generic_ops.o 4obj-$(CONFIG_PM_OPS) += generic_ops.o
5obj-$(CONFIG_PM_TRACE_RTC) += trace.o 5obj-$(CONFIG_PM_TRACE_RTC) += trace.o
6obj-$(CONFIG_PM_OPP) += opp.o
6 7
7ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG 8ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG
8ccflags-$(CONFIG_PM_VERBOSE) += -DDEBUG 9ccflags-$(CONFIG_PM_VERBOSE) += -DDEBUG
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c
index 4b29d4981253..81f2c84697f4 100644
--- a/drivers/base/power/generic_ops.c
+++ b/drivers/base/power/generic_ops.c
@@ -46,7 +46,7 @@ int pm_generic_runtime_suspend(struct device *dev)
46 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 46 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
47 int ret; 47 int ret;
48 48
49 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : -EINVAL; 49 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
50 50
51 return ret; 51 return ret;
52} 52}
@@ -65,7 +65,7 @@ int pm_generic_runtime_resume(struct device *dev)
65 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 65 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
66 int ret; 66 int ret;
67 67
68 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : -EINVAL; 68 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
69 69
70 return ret; 70 return ret;
71} 71}
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 276d5a701dc3..31b526661ec4 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -51,6 +51,8 @@ static pm_message_t pm_transition;
51 */ 51 */
52static bool transition_started; 52static bool transition_started;
53 53
54static int async_error;
55
54/** 56/**
55 * device_pm_init - Initialize the PM-related part of a device object. 57 * device_pm_init - Initialize the PM-related part of a device object.
56 * @dev: Device object being initialized. 58 * @dev: Device object being initialized.
@@ -60,7 +62,8 @@ void device_pm_init(struct device *dev)
60 dev->power.status = DPM_ON; 62 dev->power.status = DPM_ON;
61 init_completion(&dev->power.completion); 63 init_completion(&dev->power.completion);
62 complete_all(&dev->power.completion); 64 complete_all(&dev->power.completion);
63 dev->power.wakeup_count = 0; 65 dev->power.wakeup = NULL;
66 spin_lock_init(&dev->power.lock);
64 pm_runtime_init(dev); 67 pm_runtime_init(dev);
65} 68}
66 69
@@ -120,6 +123,7 @@ void device_pm_remove(struct device *dev)
120 mutex_lock(&dpm_list_mtx); 123 mutex_lock(&dpm_list_mtx);
121 list_del_init(&dev->power.entry); 124 list_del_init(&dev->power.entry);
122 mutex_unlock(&dpm_list_mtx); 125 mutex_unlock(&dpm_list_mtx);
126 device_wakeup_disable(dev);
123 pm_runtime_remove(dev); 127 pm_runtime_remove(dev);
124} 128}
125 129
@@ -407,7 +411,7 @@ static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
407static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info) 411static void dpm_show_time(ktime_t starttime, pm_message_t state, char *info)
408{ 412{
409 ktime_t calltime; 413 ktime_t calltime;
410 s64 usecs64; 414 u64 usecs64;
411 int usecs; 415 int usecs;
412 416
413 calltime = ktime_get(); 417 calltime = ktime_get();
@@ -600,6 +604,7 @@ static void dpm_resume(pm_message_t state)
600 INIT_LIST_HEAD(&list); 604 INIT_LIST_HEAD(&list);
601 mutex_lock(&dpm_list_mtx); 605 mutex_lock(&dpm_list_mtx);
602 pm_transition = state; 606 pm_transition = state;
607 async_error = 0;
603 608
604 list_for_each_entry(dev, &dpm_list, power.entry) { 609 list_for_each_entry(dev, &dpm_list, power.entry) {
605 if (dev->power.status < DPM_OFF) 610 if (dev->power.status < DPM_OFF)
@@ -829,8 +834,6 @@ static int legacy_suspend(struct device *dev, pm_message_t state,
829 return error; 834 return error;
830} 835}
831 836
832static int async_error;
833
834/** 837/**
835 * device_suspend - Execute "suspend" callbacks for given device. 838 * device_suspend - Execute "suspend" callbacks for given device.
836 * @dev: Device to handle. 839 * @dev: Device to handle.
@@ -885,6 +888,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
885 device_unlock(dev); 888 device_unlock(dev);
886 complete_all(&dev->power.completion); 889 complete_all(&dev->power.completion);
887 890
891 if (error)
892 async_error = error;
893
888 return error; 894 return error;
889} 895}
890 896
@@ -894,10 +900,8 @@ static void async_suspend(void *data, async_cookie_t cookie)
894 int error; 900 int error;
895 901
896 error = __device_suspend(dev, pm_transition, true); 902 error = __device_suspend(dev, pm_transition, true);
897 if (error) { 903 if (error)
898 pm_dev_err(dev, pm_transition, " async", error); 904 pm_dev_err(dev, pm_transition, " async", error);
899 async_error = error;
900 }
901 905
902 put_device(dev); 906 put_device(dev);
903} 907}
@@ -1085,8 +1089,9 @@ EXPORT_SYMBOL_GPL(__suspend_report_result);
1085 * @dev: Device to wait for. 1089 * @dev: Device to wait for.
1086 * @subordinate: Device that needs to wait for @dev. 1090 * @subordinate: Device that needs to wait for @dev.
1087 */ 1091 */
1088void device_pm_wait_for_dev(struct device *subordinate, struct device *dev) 1092int device_pm_wait_for_dev(struct device *subordinate, struct device *dev)
1089{ 1093{
1090 dpm_wait(dev, subordinate->power.async_suspend); 1094 dpm_wait(dev, subordinate->power.async_suspend);
1095 return async_error;
1091} 1096}
1092EXPORT_SYMBOL_GPL(device_pm_wait_for_dev); 1097EXPORT_SYMBOL_GPL(device_pm_wait_for_dev);
diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
new file mode 100644
index 000000000000..2bb9b4cf59d7
--- /dev/null
+++ b/drivers/base/power/opp.c
@@ -0,0 +1,628 @@
1/*
2 * Generic OPP Interface
3 *
4 * Copyright (C) 2009-2010 Texas Instruments Incorporated.
5 * Nishanth Menon
6 * Romit Dasgupta
7 * Kevin Hilman
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/kernel.h>
15#include <linux/errno.h>
16#include <linux/err.h>
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/cpufreq.h>
20#include <linux/list.h>
21#include <linux/rculist.h>
22#include <linux/rcupdate.h>
23#include <linux/opp.h>
24
25/*
26 * Internal data structure organization with the OPP layer library is as
27 * follows:
28 * dev_opp_list (root)
29 * |- device 1 (represents voltage domain 1)
30 * | |- opp 1 (availability, freq, voltage)
31 * | |- opp 2 ..
32 * ... ...
33 * | `- opp n ..
34 * |- device 2 (represents the next voltage domain)
35 * ...
36 * `- device m (represents mth voltage domain)
37 * device 1, 2.. are represented by dev_opp structure while each opp
38 * is represented by the opp structure.
39 */
40
41/**
42 * struct opp - Generic OPP description structure
43 * @node: opp list node. The nodes are maintained throughout the lifetime
44 * of boot. It is expected only an optimal set of OPPs are
45 * added to the library by the SoC framework.
46 * RCU usage: opp list is traversed with RCU locks. node
47 * modification is possible realtime, hence the modifications
48 * are protected by the dev_opp_list_lock for integrity.
49 * IMPORTANT: the opp nodes should be maintained in increasing
50 * order.
51 * @available: true/false - marks if this OPP as available or not
52 * @rate: Frequency in hertz
53 * @u_volt: Nominal voltage in microvolts corresponding to this OPP
54 * @dev_opp: points back to the device_opp struct this opp belongs to
55 *
56 * This structure stores the OPP information for a given device.
57 */
58struct opp {
59 struct list_head node;
60
61 bool available;
62 unsigned long rate;
63 unsigned long u_volt;
64
65 struct device_opp *dev_opp;
66};
67
68/**
69 * struct device_opp - Device opp structure
70 * @node: list node - contains the devices with OPPs that
71 * have been registered. Nodes once added are not modified in this
72 * list.
73 * RCU usage: nodes are not modified in the list of device_opp,
74 * however addition is possible and is secured by dev_opp_list_lock
75 * @dev: device pointer
76 * @opp_list: list of opps
77 *
78 * This is an internal data structure maintaining the link to opps attached to
79 * a device. This structure is not meant to be shared to users as it is
80 * meant for book keeping and private to OPP library
81 */
82struct device_opp {
83 struct list_head node;
84
85 struct device *dev;
86 struct list_head opp_list;
87};
88
89/*
90 * The root of the list of all devices. All device_opp structures branch off
91 * from here, with each device_opp containing the list of opp it supports in
92 * various states of availability.
93 */
94static LIST_HEAD(dev_opp_list);
95/* Lock to allow exclusive modification to the device and opp lists */
96static DEFINE_MUTEX(dev_opp_list_lock);
97
98/**
99 * find_device_opp() - find device_opp struct using device pointer
100 * @dev: device pointer used to lookup device OPPs
101 *
102 * Search list of device OPPs for one containing matching device. Does a RCU
103 * reader operation to grab the pointer needed.
104 *
105 * Returns pointer to 'struct device_opp' if found, otherwise -ENODEV or
106 * -EINVAL based on type of error.
107 *
108 * Locking: This function must be called under rcu_read_lock(). device_opp
109 * is a RCU protected pointer. This means that device_opp is valid as long
110 * as we are under RCU lock.
111 */
112static struct device_opp *find_device_opp(struct device *dev)
113{
114 struct device_opp *tmp_dev_opp, *dev_opp = ERR_PTR(-ENODEV);
115
116 if (unlikely(IS_ERR_OR_NULL(dev))) {
117 pr_err("%s: Invalid parameters\n", __func__);
118 return ERR_PTR(-EINVAL);
119 }
120
121 list_for_each_entry_rcu(tmp_dev_opp, &dev_opp_list, node) {
122 if (tmp_dev_opp->dev == dev) {
123 dev_opp = tmp_dev_opp;
124 break;
125 }
126 }
127
128 return dev_opp;
129}
130
131/**
132 * opp_get_voltage() - Gets the voltage corresponding to an available opp
133 * @opp: opp for which voltage has to be returned for
134 *
135 * Return voltage in micro volt corresponding to the opp, else
136 * return 0
137 *
138 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
139 * protected pointer. This means that opp which could have been fetched by
140 * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are
141 * under RCU lock. The pointer returned by the opp_find_freq family must be
142 * used in the same section as the usage of this function with the pointer
143 * prior to unlocking with rcu_read_unlock() to maintain the integrity of the
144 * pointer.
145 */
146unsigned long opp_get_voltage(struct opp *opp)
147{
148 struct opp *tmp_opp;
149 unsigned long v = 0;
150
151 tmp_opp = rcu_dereference(opp);
152 if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
153 pr_err("%s: Invalid parameters\n", __func__);
154 else
155 v = tmp_opp->u_volt;
156
157 return v;
158}
159
160/**
161 * opp_get_freq() - Gets the frequency corresponding to an available opp
162 * @opp: opp for which frequency has to be returned for
163 *
164 * Return frequency in hertz corresponding to the opp, else
165 * return 0
166 *
167 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
168 * protected pointer. This means that opp which could have been fetched by
169 * opp_find_freq_{exact,ceil,floor} functions is valid as long as we are
170 * under RCU lock. The pointer returned by the opp_find_freq family must be
171 * used in the same section as the usage of this function with the pointer
172 * prior to unlocking with rcu_read_unlock() to maintain the integrity of the
173 * pointer.
174 */
175unsigned long opp_get_freq(struct opp *opp)
176{
177 struct opp *tmp_opp;
178 unsigned long f = 0;
179
180 tmp_opp = rcu_dereference(opp);
181 if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
182 pr_err("%s: Invalid parameters\n", __func__);
183 else
184 f = tmp_opp->rate;
185
186 return f;
187}
188
189/**
190 * opp_get_opp_count() - Get number of opps available in the opp list
191 * @dev: device for which we do this operation
192 *
193 * This function returns the number of available opps if there are any,
194 * else returns 0 if none or the corresponding error value.
195 *
196 * Locking: This function must be called under rcu_read_lock(). This function
197 * internally references two RCU protected structures: device_opp and opp which
198 * are safe as long as we are under a common RCU locked section.
199 */
200int opp_get_opp_count(struct device *dev)
201{
202 struct device_opp *dev_opp;
203 struct opp *temp_opp;
204 int count = 0;
205
206 dev_opp = find_device_opp(dev);
207 if (IS_ERR(dev_opp)) {
208 int r = PTR_ERR(dev_opp);
209 dev_err(dev, "%s: device OPP not found (%d)\n", __func__, r);
210 return r;
211 }
212
213 list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
214 if (temp_opp->available)
215 count++;
216 }
217
218 return count;
219}
220
221/**
222 * opp_find_freq_exact() - search for an exact frequency
223 * @dev: device for which we do this operation
224 * @freq: frequency to search for
225 * @is_available: true/false - match for available opp
226 *
227 * Searches for exact match in the opp list and returns pointer to the matching
228 * opp if found, else returns ERR_PTR in case of error and should be handled
229 * using IS_ERR.
230 *
231 * Note: available is a modifier for the search. if available=true, then the
232 * match is for exact matching frequency and is available in the stored OPP
233 * table. if false, the match is for exact frequency which is not available.
234 *
235 * This provides a mechanism to enable an opp which is not available currently
236 * or the opposite as well.
237 *
238 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
239 * protected pointer. The reason for the same is that the opp pointer which is
240 * returned will remain valid for use with opp_get_{voltage, freq} only while
241 * under the locked area. The pointer returned must be used prior to unlocking
242 * with rcu_read_unlock() to maintain the integrity of the pointer.
243 */
244struct opp *opp_find_freq_exact(struct device *dev, unsigned long freq,
245 bool available)
246{
247 struct device_opp *dev_opp;
248 struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
249
250 dev_opp = find_device_opp(dev);
251 if (IS_ERR(dev_opp)) {
252 int r = PTR_ERR(dev_opp);
253 dev_err(dev, "%s: device OPP not found (%d)\n", __func__, r);
254 return ERR_PTR(r);
255 }
256
257 list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
258 if (temp_opp->available == available &&
259 temp_opp->rate == freq) {
260 opp = temp_opp;
261 break;
262 }
263 }
264
265 return opp;
266}
267
268/**
269 * opp_find_freq_ceil() - Search for an rounded ceil freq
270 * @dev: device for which we do this operation
271 * @freq: Start frequency
272 *
273 * Search for the matching ceil *available* OPP from a starting freq
274 * for a device.
275 *
276 * Returns matching *opp and refreshes *freq accordingly, else returns
277 * ERR_PTR in case of error and should be handled using IS_ERR.
278 *
279 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
280 * protected pointer. The reason for the same is that the opp pointer which is
281 * returned will remain valid for use with opp_get_{voltage, freq} only while
282 * under the locked area. The pointer returned must be used prior to unlocking
283 * with rcu_read_unlock() to maintain the integrity of the pointer.
284 */
285struct opp *opp_find_freq_ceil(struct device *dev, unsigned long *freq)
286{
287 struct device_opp *dev_opp;
288 struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
289
290 if (!dev || !freq) {
291 dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
292 return ERR_PTR(-EINVAL);
293 }
294
295 dev_opp = find_device_opp(dev);
296 if (IS_ERR(dev_opp))
297 return opp;
298
299 list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
300 if (temp_opp->available && temp_opp->rate >= *freq) {
301 opp = temp_opp;
302 *freq = opp->rate;
303 break;
304 }
305 }
306
307 return opp;
308}
309
310/**
311 * opp_find_freq_floor() - Search for a rounded floor freq
312 * @dev: device for which we do this operation
313 * @freq: Start frequency
314 *
315 * Search for the matching floor *available* OPP from a starting freq
316 * for a device.
317 *
318 * Returns matching *opp and refreshes *freq accordingly, else returns
319 * ERR_PTR in case of error and should be handled using IS_ERR.
320 *
321 * Locking: This function must be called under rcu_read_lock(). opp is a rcu
322 * protected pointer. The reason for the same is that the opp pointer which is
323 * returned will remain valid for use with opp_get_{voltage, freq} only while
324 * under the locked area. The pointer returned must be used prior to unlocking
325 * with rcu_read_unlock() to maintain the integrity of the pointer.
326 */
327struct opp *opp_find_freq_floor(struct device *dev, unsigned long *freq)
328{
329 struct device_opp *dev_opp;
330 struct opp *temp_opp, *opp = ERR_PTR(-ENODEV);
331
332 if (!dev || !freq) {
333 dev_err(dev, "%s: Invalid argument freq=%p\n", __func__, freq);
334 return ERR_PTR(-EINVAL);
335 }
336
337 dev_opp = find_device_opp(dev);
338 if (IS_ERR(dev_opp))
339 return opp;
340
341 list_for_each_entry_rcu(temp_opp, &dev_opp->opp_list, node) {
342 if (temp_opp->available) {
343 /* go to the next node, before choosing prev */
344 if (temp_opp->rate > *freq)
345 break;
346 else
347 opp = temp_opp;
348 }
349 }
350 if (!IS_ERR(opp))
351 *freq = opp->rate;
352
353 return opp;
354}
355
356/**
357 * opp_add() - Add an OPP table from a table definitions
358 * @dev: device for which we do this operation
359 * @freq: Frequency in Hz for this OPP
360 * @u_volt: Voltage in uVolts for this OPP
361 *
362 * This function adds an opp definition to the opp list and returns status.
363 * The opp is made available by default and it can be controlled using
364 * opp_enable/disable functions.
365 *
366 * Locking: The internal device_opp and opp structures are RCU protected.
367 * Hence this function internally uses RCU updater strategy with mutex locks
368 * to keep the integrity of the internal data structures. Callers should ensure
369 * that this function is *NOT* called under RCU protection or in contexts where
370 * mutex cannot be locked.
371 */
372int opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
373{
374 struct device_opp *dev_opp = NULL;
375 struct opp *opp, *new_opp;
376 struct list_head *head;
377
378 /* allocate new OPP node */
379 new_opp = kzalloc(sizeof(struct opp), GFP_KERNEL);
380 if (!new_opp) {
381 dev_warn(dev, "%s: Unable to create new OPP node\n", __func__);
382 return -ENOMEM;
383 }
384
385 /* Hold our list modification lock here */
386 mutex_lock(&dev_opp_list_lock);
387
388 /* Check for existing list for 'dev' */
389 dev_opp = find_device_opp(dev);
390 if (IS_ERR(dev_opp)) {
391 /*
392 * Allocate a new device OPP table. In the infrequent case
393 * where a new device is needed to be added, we pay this
394 * penalty.
395 */
396 dev_opp = kzalloc(sizeof(struct device_opp), GFP_KERNEL);
397 if (!dev_opp) {
398 mutex_unlock(&dev_opp_list_lock);
399 kfree(new_opp);
400 dev_warn(dev,
401 "%s: Unable to create device OPP structure\n",
402 __func__);
403 return -ENOMEM;
404 }
405
406 dev_opp->dev = dev;
407 INIT_LIST_HEAD(&dev_opp->opp_list);
408
409 /* Secure the device list modification */
410 list_add_rcu(&dev_opp->node, &dev_opp_list);
411 }
412
413 /* populate the opp table */
414 new_opp->dev_opp = dev_opp;
415 new_opp->rate = freq;
416 new_opp->u_volt = u_volt;
417 new_opp->available = true;
418
419 /* Insert new OPP in order of increasing frequency */
420 head = &dev_opp->opp_list;
421 list_for_each_entry_rcu(opp, &dev_opp->opp_list, node) {
422 if (new_opp->rate < opp->rate)
423 break;
424 else
425 head = &opp->node;
426 }
427
428 list_add_rcu(&new_opp->node, head);
429 mutex_unlock(&dev_opp_list_lock);
430
431 return 0;
432}
433
434/**
435 * opp_set_availability() - helper to set the availability of an opp
436 * @dev: device for which we do this operation
437 * @freq: OPP frequency to modify availability
438 * @availability_req: availability status requested for this opp
439 *
440 * Set the availability of an OPP with an RCU operation, opp_{enable,disable}
441 * share a common logic which is isolated here.
442 *
443 * Returns -EINVAL for bad pointers, -ENOMEM if no memory available for the
444 * copy operation, returns 0 if no modifcation was done OR modification was
445 * successful.
446 *
447 * Locking: The internal device_opp and opp structures are RCU protected.
448 * Hence this function internally uses RCU updater strategy with mutex locks to
449 * keep the integrity of the internal data structures. Callers should ensure
450 * that this function is *NOT* called under RCU protection or in contexts where
451 * mutex locking or synchronize_rcu() blocking calls cannot be used.
452 */
453static int opp_set_availability(struct device *dev, unsigned long freq,
454 bool availability_req)
455{
456 struct device_opp *tmp_dev_opp, *dev_opp = NULL;
457 struct opp *new_opp, *tmp_opp, *opp = ERR_PTR(-ENODEV);
458 int r = 0;
459
460 /* keep the node allocated */
461 new_opp = kmalloc(sizeof(struct opp), GFP_KERNEL);
462 if (!new_opp) {
463 dev_warn(dev, "%s: Unable to create OPP\n", __func__);
464 return -ENOMEM;
465 }
466
467 mutex_lock(&dev_opp_list_lock);
468
469 /* Find the device_opp */
470 list_for_each_entry(tmp_dev_opp, &dev_opp_list, node) {
471 if (dev == tmp_dev_opp->dev) {
472 dev_opp = tmp_dev_opp;
473 break;
474 }
475 }
476 if (IS_ERR(dev_opp)) {
477 r = PTR_ERR(dev_opp);
478 dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
479 goto unlock;
480 }
481
482 /* Do we have the frequency? */
483 list_for_each_entry(tmp_opp, &dev_opp->opp_list, node) {
484 if (tmp_opp->rate == freq) {
485 opp = tmp_opp;
486 break;
487 }
488 }
489 if (IS_ERR(opp)) {
490 r = PTR_ERR(opp);
491 goto unlock;
492 }
493
494 /* Is update really needed? */
495 if (opp->available == availability_req)
496 goto unlock;
497 /* copy the old data over */
498 *new_opp = *opp;
499
500 /* plug in new node */
501 new_opp->available = availability_req;
502
503 list_replace_rcu(&opp->node, &new_opp->node);
504 mutex_unlock(&dev_opp_list_lock);
505 synchronize_rcu();
506
507 /* clean up old opp */
508 new_opp = opp;
509 goto out;
510
511unlock:
512 mutex_unlock(&dev_opp_list_lock);
513out:
514 kfree(new_opp);
515 return r;
516}
517
518/**
519 * opp_enable() - Enable a specific OPP
520 * @dev: device for which we do this operation
521 * @freq: OPP frequency to enable
522 *
523 * Enables a provided opp. If the operation is valid, this returns 0, else the
524 * corresponding error value. It is meant to be used for users an OPP available
525 * after being temporarily made unavailable with opp_disable.
526 *
527 * Locking: The internal device_opp and opp structures are RCU protected.
528 * Hence this function indirectly uses RCU and mutex locks to keep the
529 * integrity of the internal data structures. Callers should ensure that
530 * this function is *NOT* called under RCU protection or in contexts where
531 * mutex locking or synchronize_rcu() blocking calls cannot be used.
532 */
533int opp_enable(struct device *dev, unsigned long freq)
534{
535 return opp_set_availability(dev, freq, true);
536}
537
538/**
539 * opp_disable() - Disable a specific OPP
540 * @dev: device for which we do this operation
541 * @freq: OPP frequency to disable
542 *
543 * Disables a provided opp. If the operation is valid, this returns
544 * 0, else the corresponding error value. It is meant to be a temporary
545 * control by users to make this OPP not available until the circumstances are
546 * right to make it available again (with a call to opp_enable).
547 *
548 * Locking: The internal device_opp and opp structures are RCU protected.
549 * Hence this function indirectly uses RCU and mutex locks to keep the
550 * integrity of the internal data structures. Callers should ensure that
551 * this function is *NOT* called under RCU protection or in contexts where
552 * mutex locking or synchronize_rcu() blocking calls cannot be used.
553 */
554int opp_disable(struct device *dev, unsigned long freq)
555{
556 return opp_set_availability(dev, freq, false);
557}
558
559#ifdef CONFIG_CPU_FREQ
560/**
561 * opp_init_cpufreq_table() - create a cpufreq table for a device
562 * @dev: device for which we do this operation
563 * @table: Cpufreq table returned back to caller
564 *
565 * Generate a cpufreq table for a provided device- this assumes that the
566 * opp list is already initialized and ready for usage.
567 *
568 * This function allocates required memory for the cpufreq table. It is
569 * expected that the caller does the required maintenance such as freeing
570 * the table as required.
571 *
572 * Returns -EINVAL for bad pointers, -ENODEV if the device is not found, -ENOMEM
573 * if no memory available for the operation (table is not populated), returns 0
574 * if successful and table is populated.
575 *
576 * WARNING: It is important for the callers to ensure refreshing their copy of
577 * the table if any of the mentioned functions have been invoked in the interim.
578 *
579 * Locking: The internal device_opp and opp structures are RCU protected.
580 * To simplify the logic, we pretend we are updater and hold relevant mutex here
581 * Callers should ensure that this function is *NOT* called under RCU protection
582 * or in contexts where mutex locking cannot be used.
583 */
584int opp_init_cpufreq_table(struct device *dev,
585 struct cpufreq_frequency_table **table)
586{
587 struct device_opp *dev_opp;
588 struct opp *opp;
589 struct cpufreq_frequency_table *freq_table;
590 int i = 0;
591
592 /* Pretend as if I am an updater */
593 mutex_lock(&dev_opp_list_lock);
594
595 dev_opp = find_device_opp(dev);
596 if (IS_ERR(dev_opp)) {
597 int r = PTR_ERR(dev_opp);
598 mutex_unlock(&dev_opp_list_lock);
599 dev_err(dev, "%s: Device OPP not found (%d)\n", __func__, r);
600 return r;
601 }
602
603 freq_table = kzalloc(sizeof(struct cpufreq_frequency_table) *
604 (opp_get_opp_count(dev) + 1), GFP_KERNEL);
605 if (!freq_table) {
606 mutex_unlock(&dev_opp_list_lock);
607 dev_warn(dev, "%s: Unable to allocate frequency table\n",
608 __func__);
609 return -ENOMEM;
610 }
611
612 list_for_each_entry(opp, &dev_opp->opp_list, node) {
613 if (opp->available) {
614 freq_table[i].index = i;
615 freq_table[i].frequency = opp->rate / 1000;
616 i++;
617 }
618 }
619 mutex_unlock(&dev_opp_list_lock);
620
621 freq_table[i].index = i;
622 freq_table[i].frequency = CPUFREQ_TABLE_END;
623
624 *table = &freq_table[0];
625
626 return 0;
627}
628#endif /* CONFIG_CPU_FREQ */
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index c0bd03c83b9c..698dde742587 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -34,6 +34,7 @@ extern void device_pm_move_last(struct device *);
34 34
35static inline void device_pm_init(struct device *dev) 35static inline void device_pm_init(struct device *dev)
36{ 36{
37 spin_lock_init(&dev->power.lock);
37 pm_runtime_init(dev); 38 pm_runtime_init(dev);
38} 39}
39 40
@@ -59,6 +60,7 @@ static inline void device_pm_move_last(struct device *dev) {}
59 60
60extern int dpm_sysfs_add(struct device *); 61extern int dpm_sysfs_add(struct device *);
61extern void dpm_sysfs_remove(struct device *); 62extern void dpm_sysfs_remove(struct device *);
63extern void rpm_sysfs_remove(struct device *);
62 64
63#else /* CONFIG_PM */ 65#else /* CONFIG_PM */
64 66
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index b78c401ffa73..1dd8676d7f55 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -2,17 +2,55 @@
2 * drivers/base/power/runtime.c - Helper functions for device run-time PM 2 * drivers/base/power/runtime.c - Helper functions for device run-time PM
3 * 3 *
4 * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. 4 * Copyright (c) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
5 * Copyright (C) 2010 Alan Stern <stern@rowland.harvard.edu>
5 * 6 *
6 * This file is released under the GPLv2. 7 * This file is released under the GPLv2.
7 */ 8 */
8 9
9#include <linux/sched.h> 10#include <linux/sched.h>
10#include <linux/pm_runtime.h> 11#include <linux/pm_runtime.h>
11#include <linux/jiffies.h> 12#include "power.h"
12 13
13static int __pm_runtime_resume(struct device *dev, bool from_wq); 14static int rpm_resume(struct device *dev, int rpmflags);
14static int __pm_request_idle(struct device *dev); 15static int rpm_suspend(struct device *dev, int rpmflags);
15static int __pm_request_resume(struct device *dev); 16
17/**
18 * update_pm_runtime_accounting - Update the time accounting of power states
19 * @dev: Device to update the accounting for
20 *
21 * In order to be able to have time accounting of the various power states
22 * (as used by programs such as PowerTOP to show the effectiveness of runtime
23 * PM), we need to track the time spent in each state.
24 * update_pm_runtime_accounting must be called each time before the
25 * runtime_status field is updated, to account the time in the old state
26 * correctly.
27 */
28void update_pm_runtime_accounting(struct device *dev)
29{
30 unsigned long now = jiffies;
31 int delta;
32
33 delta = now - dev->power.accounting_timestamp;
34
35 if (delta < 0)
36 delta = 0;
37
38 dev->power.accounting_timestamp = now;
39
40 if (dev->power.disable_depth > 0)
41 return;
42
43 if (dev->power.runtime_status == RPM_SUSPENDED)
44 dev->power.suspended_jiffies += delta;
45 else
46 dev->power.active_jiffies += delta;
47}
48
49static void __update_runtime_status(struct device *dev, enum rpm_status status)
50{
51 update_pm_runtime_accounting(dev);
52 dev->power.runtime_status = status;
53}
16 54
17/** 55/**
18 * pm_runtime_deactivate_timer - Deactivate given device's suspend timer. 56 * pm_runtime_deactivate_timer - Deactivate given device's suspend timer.
@@ -40,62 +78,154 @@ static void pm_runtime_cancel_pending(struct device *dev)
40 dev->power.request = RPM_REQ_NONE; 78 dev->power.request = RPM_REQ_NONE;
41} 79}
42 80
43/** 81/*
44 * __pm_runtime_idle - Notify device bus type if the device can be suspended. 82 * pm_runtime_autosuspend_expiration - Get a device's autosuspend-delay expiration time.
45 * @dev: Device to notify the bus type about. 83 * @dev: Device to handle.
46 * 84 *
47 * This function must be called under dev->power.lock with interrupts disabled. 85 * Compute the autosuspend-delay expiration time based on the device's
86 * power.last_busy time. If the delay has already expired or is disabled
87 * (negative) or the power.use_autosuspend flag isn't set, return 0.
88 * Otherwise return the expiration time in jiffies (adjusted to be nonzero).
89 *
90 * This function may be called either with or without dev->power.lock held.
91 * Either way it can be racy, since power.last_busy may be updated at any time.
48 */ 92 */
49static int __pm_runtime_idle(struct device *dev) 93unsigned long pm_runtime_autosuspend_expiration(struct device *dev)
50 __releases(&dev->power.lock) __acquires(&dev->power.lock) 94{
95 int autosuspend_delay;
96 long elapsed;
97 unsigned long last_busy;
98 unsigned long expires = 0;
99
100 if (!dev->power.use_autosuspend)
101 goto out;
102
103 autosuspend_delay = ACCESS_ONCE(dev->power.autosuspend_delay);
104 if (autosuspend_delay < 0)
105 goto out;
106
107 last_busy = ACCESS_ONCE(dev->power.last_busy);
108 elapsed = jiffies - last_busy;
109 if (elapsed < 0)
110 goto out; /* jiffies has wrapped around. */
111
112 /*
113 * If the autosuspend_delay is >= 1 second, align the timer by rounding
114 * up to the nearest second.
115 */
116 expires = last_busy + msecs_to_jiffies(autosuspend_delay);
117 if (autosuspend_delay >= 1000)
118 expires = round_jiffies(expires);
119 expires += !expires;
120 if (elapsed >= expires - last_busy)
121 expires = 0; /* Already expired. */
122
123 out:
124 return expires;
125}
126EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
127
128/**
129 * rpm_check_suspend_allowed - Test whether a device may be suspended.
130 * @dev: Device to test.
131 */
132static int rpm_check_suspend_allowed(struct device *dev)
51{ 133{
52 int retval = 0; 134 int retval = 0;
53 135
54 if (dev->power.runtime_error) 136 if (dev->power.runtime_error)
55 retval = -EINVAL; 137 retval = -EINVAL;
56 else if (dev->power.idle_notification)
57 retval = -EINPROGRESS;
58 else if (atomic_read(&dev->power.usage_count) > 0 138 else if (atomic_read(&dev->power.usage_count) > 0
59 || dev->power.disable_depth > 0 139 || dev->power.disable_depth > 0)
60 || dev->power.runtime_status != RPM_ACTIVE)
61 retval = -EAGAIN; 140 retval = -EAGAIN;
62 else if (!pm_children_suspended(dev)) 141 else if (!pm_children_suspended(dev))
63 retval = -EBUSY; 142 retval = -EBUSY;
143
144 /* Pending resume requests take precedence over suspends. */
145 else if ((dev->power.deferred_resume
146 && dev->power.status == RPM_SUSPENDING)
147 || (dev->power.request_pending
148 && dev->power.request == RPM_REQ_RESUME))
149 retval = -EAGAIN;
150 else if (dev->power.runtime_status == RPM_SUSPENDED)
151 retval = 1;
152
153 return retval;
154}
155
156/**
157 * rpm_idle - Notify device bus type if the device can be suspended.
158 * @dev: Device to notify the bus type about.
159 * @rpmflags: Flag bits.
160 *
161 * Check if the device's run-time PM status allows it to be suspended. If
162 * another idle notification has been started earlier, return immediately. If
163 * the RPM_ASYNC flag is set then queue an idle-notification request; otherwise
164 * run the ->runtime_idle() callback directly.
165 *
166 * This function must be called under dev->power.lock with interrupts disabled.
167 */
168static int rpm_idle(struct device *dev, int rpmflags)
169{
170 int (*callback)(struct device *);
171 int retval;
172
173 retval = rpm_check_suspend_allowed(dev);
174 if (retval < 0)
175 ; /* Conditions are wrong. */
176
177 /* Idle notifications are allowed only in the RPM_ACTIVE state. */
178 else if (dev->power.runtime_status != RPM_ACTIVE)
179 retval = -EAGAIN;
180
181 /*
182 * Any pending request other than an idle notification takes
183 * precedence over us, except that the timer may be running.
184 */
185 else if (dev->power.request_pending &&
186 dev->power.request > RPM_REQ_IDLE)
187 retval = -EAGAIN;
188
189 /* Act as though RPM_NOWAIT is always set. */
190 else if (dev->power.idle_notification)
191 retval = -EINPROGRESS;
64 if (retval) 192 if (retval)
65 goto out; 193 goto out;
66 194
67 if (dev->power.request_pending) { 195 /* Pending requests need to be canceled. */
68 /* 196 dev->power.request = RPM_REQ_NONE;
69 * If an idle notification request is pending, cancel it. Any 197
70 * other pending request takes precedence over us. 198 if (dev->power.no_callbacks) {
71 */ 199 /* Assume ->runtime_idle() callback would have suspended. */
72 if (dev->power.request == RPM_REQ_IDLE) { 200 retval = rpm_suspend(dev, rpmflags);
73 dev->power.request = RPM_REQ_NONE; 201 goto out;
74 } else if (dev->power.request != RPM_REQ_NONE) { 202 }
75 retval = -EAGAIN; 203
76 goto out; 204 /* Carry out an asynchronous or a synchronous idle notification. */
205 if (rpmflags & RPM_ASYNC) {
206 dev->power.request = RPM_REQ_IDLE;
207 if (!dev->power.request_pending) {
208 dev->power.request_pending = true;
209 queue_work(pm_wq, &dev->power.work);
77 } 210 }
211 goto out;
78 } 212 }
79 213
80 dev->power.idle_notification = true; 214 dev->power.idle_notification = true;
81 215
82 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_idle) { 216 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_idle)
83 spin_unlock_irq(&dev->power.lock); 217 callback = dev->bus->pm->runtime_idle;
84 218 else if (dev->type && dev->type->pm && dev->type->pm->runtime_idle)
85 dev->bus->pm->runtime_idle(dev); 219 callback = dev->type->pm->runtime_idle;
86 220 else if (dev->class && dev->class->pm)
87 spin_lock_irq(&dev->power.lock); 221 callback = dev->class->pm->runtime_idle;
88 } else if (dev->type && dev->type->pm && dev->type->pm->runtime_idle) { 222 else
89 spin_unlock_irq(&dev->power.lock); 223 callback = NULL;
90
91 dev->type->pm->runtime_idle(dev);
92 224
93 spin_lock_irq(&dev->power.lock); 225 if (callback) {
94 } else if (dev->class && dev->class->pm
95 && dev->class->pm->runtime_idle) {
96 spin_unlock_irq(&dev->power.lock); 226 spin_unlock_irq(&dev->power.lock);
97 227
98 dev->class->pm->runtime_idle(dev); 228 callback(dev);
99 229
100 spin_lock_irq(&dev->power.lock); 230 spin_lock_irq(&dev->power.lock);
101 } 231 }
@@ -108,113 +238,99 @@ static int __pm_runtime_idle(struct device *dev)
108} 238}
109 239
110/** 240/**
111 * pm_runtime_idle - Notify device bus type if the device can be suspended. 241 * rpm_callback - Run a given runtime PM callback for a given device.
112 * @dev: Device to notify the bus type about. 242 * @cb: Runtime PM callback to run.
243 * @dev: Device to run the callback for.
113 */ 244 */
114int pm_runtime_idle(struct device *dev) 245static int rpm_callback(int (*cb)(struct device *), struct device *dev)
246 __releases(&dev->power.lock) __acquires(&dev->power.lock)
115{ 247{
116 int retval; 248 int retval;
117 249
118 spin_lock_irq(&dev->power.lock); 250 if (!cb)
119 retval = __pm_runtime_idle(dev); 251 return -ENOSYS;
120 spin_unlock_irq(&dev->power.lock);
121 252
122 return retval; 253 spin_unlock_irq(&dev->power.lock);
123}
124EXPORT_SYMBOL_GPL(pm_runtime_idle);
125
126
127/**
128 * update_pm_runtime_accounting - Update the time accounting of power states
129 * @dev: Device to update the accounting for
130 *
131 * In order to be able to have time accounting of the various power states
132 * (as used by programs such as PowerTOP to show the effectiveness of runtime
133 * PM), we need to track the time spent in each state.
134 * update_pm_runtime_accounting must be called each time before the
135 * runtime_status field is updated, to account the time in the old state
136 * correctly.
137 */
138void update_pm_runtime_accounting(struct device *dev)
139{
140 unsigned long now = jiffies;
141 int delta;
142
143 delta = now - dev->power.accounting_timestamp;
144
145 if (delta < 0)
146 delta = 0;
147 254
148 dev->power.accounting_timestamp = now; 255 retval = cb(dev);
149 256
150 if (dev->power.disable_depth > 0) 257 spin_lock_irq(&dev->power.lock);
151 return; 258 dev->power.runtime_error = retval;
152
153 if (dev->power.runtime_status == RPM_SUSPENDED)
154 dev->power.suspended_jiffies += delta;
155 else
156 dev->power.active_jiffies += delta;
157}
158 259
159static void __update_runtime_status(struct device *dev, enum rpm_status status) 260 return retval;
160{
161 update_pm_runtime_accounting(dev);
162 dev->power.runtime_status = status;
163} 261}
164 262
165/** 263/**
166 * __pm_runtime_suspend - Carry out run-time suspend of given device. 264 * rpm_suspend - Carry out run-time suspend of given device.
167 * @dev: Device to suspend. 265 * @dev: Device to suspend.
168 * @from_wq: If set, the function has been called via pm_wq. 266 * @rpmflags: Flag bits.
169 * 267 *
170 * Check if the device can be suspended and run the ->runtime_suspend() callback 268 * Check if the device's run-time PM status allows it to be suspended. If
171 * provided by its bus type. If another suspend has been started earlier, wait 269 * another suspend has been started earlier, either return immediately or wait
172 * for it to finish. If an idle notification or suspend request is pending or 270 * for it to finish, depending on the RPM_NOWAIT and RPM_ASYNC flags. Cancel a
173 * scheduled, cancel it. 271 * pending idle notification. If the RPM_ASYNC flag is set then queue a
272 * suspend request; otherwise run the ->runtime_suspend() callback directly.
273 * If a deferred resume was requested while the callback was running then carry
274 * it out; otherwise send an idle notification for the device (if the suspend
275 * failed) or for its parent (if the suspend succeeded).
174 * 276 *
175 * This function must be called under dev->power.lock with interrupts disabled. 277 * This function must be called under dev->power.lock with interrupts disabled.
176 */ 278 */
177int __pm_runtime_suspend(struct device *dev, bool from_wq) 279static int rpm_suspend(struct device *dev, int rpmflags)
178 __releases(&dev->power.lock) __acquires(&dev->power.lock) 280 __releases(&dev->power.lock) __acquires(&dev->power.lock)
179{ 281{
282 int (*callback)(struct device *);
180 struct device *parent = NULL; 283 struct device *parent = NULL;
181 bool notify = false; 284 int retval;
182 int retval = 0;
183 285
184 dev_dbg(dev, "__pm_runtime_suspend()%s!\n", 286 dev_dbg(dev, "%s flags 0x%x\n", __func__, rpmflags);
185 from_wq ? " from workqueue" : "");
186 287
187 repeat: 288 repeat:
188 if (dev->power.runtime_error) { 289 retval = rpm_check_suspend_allowed(dev);
189 retval = -EINVAL;
190 goto out;
191 }
192 290
193 /* Pending resume requests take precedence over us. */ 291 if (retval < 0)
194 if (dev->power.request_pending 292 ; /* Conditions are wrong. */
195 && dev->power.request == RPM_REQ_RESUME) { 293
294 /* Synchronous suspends are not allowed in the RPM_RESUMING state. */
295 else if (dev->power.runtime_status == RPM_RESUMING &&
296 !(rpmflags & RPM_ASYNC))
196 retval = -EAGAIN; 297 retval = -EAGAIN;
298 if (retval)
197 goto out; 299 goto out;
300
301 /* If the autosuspend_delay time hasn't expired yet, reschedule. */
302 if ((rpmflags & RPM_AUTO)
303 && dev->power.runtime_status != RPM_SUSPENDING) {
304 unsigned long expires = pm_runtime_autosuspend_expiration(dev);
305
306 if (expires != 0) {
307 /* Pending requests need to be canceled. */
308 dev->power.request = RPM_REQ_NONE;
309
310 /*
311 * Optimization: If the timer is already running and is
312 * set to expire at or before the autosuspend delay,
313 * avoid the overhead of resetting it. Just let it
314 * expire; pm_suspend_timer_fn() will take care of the
315 * rest.
316 */
317 if (!(dev->power.timer_expires && time_before_eq(
318 dev->power.timer_expires, expires))) {
319 dev->power.timer_expires = expires;
320 mod_timer(&dev->power.suspend_timer, expires);
321 }
322 dev->power.timer_autosuspends = 1;
323 goto out;
324 }
198 } 325 }
199 326
200 /* Other scheduled or pending requests need to be canceled. */ 327 /* Other scheduled or pending requests need to be canceled. */
201 pm_runtime_cancel_pending(dev); 328 pm_runtime_cancel_pending(dev);
202 329
203 if (dev->power.runtime_status == RPM_SUSPENDED)
204 retval = 1;
205 else if (dev->power.runtime_status == RPM_RESUMING
206 || dev->power.disable_depth > 0
207 || atomic_read(&dev->power.usage_count) > 0)
208 retval = -EAGAIN;
209 else if (!pm_children_suspended(dev))
210 retval = -EBUSY;
211 if (retval)
212 goto out;
213
214 if (dev->power.runtime_status == RPM_SUSPENDING) { 330 if (dev->power.runtime_status == RPM_SUSPENDING) {
215 DEFINE_WAIT(wait); 331 DEFINE_WAIT(wait);
216 332
217 if (from_wq) { 333 if (rpmflags & (RPM_ASYNC | RPM_NOWAIT)) {
218 retval = -EINPROGRESS; 334 retval = -EINPROGRESS;
219 goto out; 335 goto out;
220 } 336 }
@@ -236,46 +352,42 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)
236 goto repeat; 352 goto repeat;
237 } 353 }
238 354
239 __update_runtime_status(dev, RPM_SUSPENDING);
240 dev->power.deferred_resume = false; 355 dev->power.deferred_resume = false;
356 if (dev->power.no_callbacks)
357 goto no_callback; /* Assume success. */
358
359 /* Carry out an asynchronous or a synchronous suspend. */
360 if (rpmflags & RPM_ASYNC) {
361 dev->power.request = (rpmflags & RPM_AUTO) ?
362 RPM_REQ_AUTOSUSPEND : RPM_REQ_SUSPEND;
363 if (!dev->power.request_pending) {
364 dev->power.request_pending = true;
365 queue_work(pm_wq, &dev->power.work);
366 }
367 goto out;
368 }
241 369
242 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend) { 370 __update_runtime_status(dev, RPM_SUSPENDING);
243 spin_unlock_irq(&dev->power.lock);
244
245 retval = dev->bus->pm->runtime_suspend(dev);
246
247 spin_lock_irq(&dev->power.lock);
248 dev->power.runtime_error = retval;
249 } else if (dev->type && dev->type->pm
250 && dev->type->pm->runtime_suspend) {
251 spin_unlock_irq(&dev->power.lock);
252
253 retval = dev->type->pm->runtime_suspend(dev);
254
255 spin_lock_irq(&dev->power.lock);
256 dev->power.runtime_error = retval;
257 } else if (dev->class && dev->class->pm
258 && dev->class->pm->runtime_suspend) {
259 spin_unlock_irq(&dev->power.lock);
260
261 retval = dev->class->pm->runtime_suspend(dev);
262 371
263 spin_lock_irq(&dev->power.lock); 372 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend)
264 dev->power.runtime_error = retval; 373 callback = dev->bus->pm->runtime_suspend;
265 } else { 374 else if (dev->type && dev->type->pm && dev->type->pm->runtime_suspend)
266 retval = -ENOSYS; 375 callback = dev->type->pm->runtime_suspend;
267 } 376 else if (dev->class && dev->class->pm)
377 callback = dev->class->pm->runtime_suspend;
378 else
379 callback = NULL;
268 380
381 retval = rpm_callback(callback, dev);
269 if (retval) { 382 if (retval) {
270 __update_runtime_status(dev, RPM_ACTIVE); 383 __update_runtime_status(dev, RPM_ACTIVE);
271 if (retval == -EAGAIN || retval == -EBUSY) { 384 dev->power.deferred_resume = 0;
272 if (dev->power.timer_expires == 0) 385 if (retval == -EAGAIN || retval == -EBUSY)
273 notify = true;
274 dev->power.runtime_error = 0; 386 dev->power.runtime_error = 0;
275 } else { 387 else
276 pm_runtime_cancel_pending(dev); 388 pm_runtime_cancel_pending(dev);
277 }
278 } else { 389 } else {
390 no_callback:
279 __update_runtime_status(dev, RPM_SUSPENDED); 391 __update_runtime_status(dev, RPM_SUSPENDED);
280 pm_runtime_deactivate_timer(dev); 392 pm_runtime_deactivate_timer(dev);
281 393
@@ -287,14 +399,11 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)
287 wake_up_all(&dev->power.wait_queue); 399 wake_up_all(&dev->power.wait_queue);
288 400
289 if (dev->power.deferred_resume) { 401 if (dev->power.deferred_resume) {
290 __pm_runtime_resume(dev, false); 402 rpm_resume(dev, 0);
291 retval = -EAGAIN; 403 retval = -EAGAIN;
292 goto out; 404 goto out;
293 } 405 }
294 406
295 if (notify)
296 __pm_runtime_idle(dev);
297
298 if (parent && !parent->power.ignore_children) { 407 if (parent && !parent->power.ignore_children) {
299 spin_unlock_irq(&dev->power.lock); 408 spin_unlock_irq(&dev->power.lock);
300 409
@@ -304,72 +413,69 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)
304 } 413 }
305 414
306 out: 415 out:
307 dev_dbg(dev, "__pm_runtime_suspend() returns %d!\n", retval); 416 dev_dbg(dev, "%s returns %d\n", __func__, retval);
308
309 return retval;
310}
311
312/**
313 * pm_runtime_suspend - Carry out run-time suspend of given device.
314 * @dev: Device to suspend.
315 */
316int pm_runtime_suspend(struct device *dev)
317{
318 int retval;
319
320 spin_lock_irq(&dev->power.lock);
321 retval = __pm_runtime_suspend(dev, false);
322 spin_unlock_irq(&dev->power.lock);
323 417
324 return retval; 418 return retval;
325} 419}
326EXPORT_SYMBOL_GPL(pm_runtime_suspend);
327 420
328/** 421/**
329 * __pm_runtime_resume - Carry out run-time resume of given device. 422 * rpm_resume - Carry out run-time resume of given device.
330 * @dev: Device to resume. 423 * @dev: Device to resume.
331 * @from_wq: If set, the function has been called via pm_wq. 424 * @rpmflags: Flag bits.
332 * 425 *
333 * Check if the device can be woken up and run the ->runtime_resume() callback 426 * Check if the device's run-time PM status allows it to be resumed. Cancel
334 * provided by its bus type. If another resume has been started earlier, wait 427 * any scheduled or pending requests. If another resume has been started
335 * for it to finish. If there's a suspend running in parallel with this 428 * earlier, either return imediately or wait for it to finish, depending on the
336 * function, wait for it to finish and resume the device. Cancel any scheduled 429 * RPM_NOWAIT and RPM_ASYNC flags. Similarly, if there's a suspend running in
337 * or pending requests. 430 * parallel with this function, either tell the other process to resume after
431 * suspending (deferred_resume) or wait for it to finish. If the RPM_ASYNC
432 * flag is set then queue a resume request; otherwise run the
433 * ->runtime_resume() callback directly. Queue an idle notification for the
434 * device if the resume succeeded.
338 * 435 *
339 * This function must be called under dev->power.lock with interrupts disabled. 436 * This function must be called under dev->power.lock with interrupts disabled.
340 */ 437 */
341int __pm_runtime_resume(struct device *dev, bool from_wq) 438static int rpm_resume(struct device *dev, int rpmflags)
342 __releases(&dev->power.lock) __acquires(&dev->power.lock) 439 __releases(&dev->power.lock) __acquires(&dev->power.lock)
343{ 440{
441 int (*callback)(struct device *);
344 struct device *parent = NULL; 442 struct device *parent = NULL;
345 int retval = 0; 443 int retval = 0;
346 444
347 dev_dbg(dev, "__pm_runtime_resume()%s!\n", 445 dev_dbg(dev, "%s flags 0x%x\n", __func__, rpmflags);
348 from_wq ? " from workqueue" : "");
349 446
350 repeat: 447 repeat:
351 if (dev->power.runtime_error) { 448 if (dev->power.runtime_error)
352 retval = -EINVAL; 449 retval = -EINVAL;
450 else if (dev->power.disable_depth > 0)
451 retval = -EAGAIN;
452 if (retval)
353 goto out; 453 goto out;
354 }
355 454
356 pm_runtime_cancel_pending(dev); 455 /*
456 * Other scheduled or pending requests need to be canceled. Small
457 * optimization: If an autosuspend timer is running, leave it running
458 * rather than cancelling it now only to restart it again in the near
459 * future.
460 */
461 dev->power.request = RPM_REQ_NONE;
462 if (!dev->power.timer_autosuspends)
463 pm_runtime_deactivate_timer(dev);
357 464
358 if (dev->power.runtime_status == RPM_ACTIVE) 465 if (dev->power.runtime_status == RPM_ACTIVE) {
359 retval = 1; 466 retval = 1;
360 else if (dev->power.disable_depth > 0)
361 retval = -EAGAIN;
362 if (retval)
363 goto out; 467 goto out;
468 }
364 469
365 if (dev->power.runtime_status == RPM_RESUMING 470 if (dev->power.runtime_status == RPM_RESUMING
366 || dev->power.runtime_status == RPM_SUSPENDING) { 471 || dev->power.runtime_status == RPM_SUSPENDING) {
367 DEFINE_WAIT(wait); 472 DEFINE_WAIT(wait);
368 473
369 if (from_wq) { 474 if (rpmflags & (RPM_ASYNC | RPM_NOWAIT)) {
370 if (dev->power.runtime_status == RPM_SUSPENDING) 475 if (dev->power.runtime_status == RPM_SUSPENDING)
371 dev->power.deferred_resume = true; 476 dev->power.deferred_resume = true;
372 retval = -EINPROGRESS; 477 else
478 retval = -EINPROGRESS;
373 goto out; 479 goto out;
374 } 480 }
375 481
@@ -391,6 +497,34 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
391 goto repeat; 497 goto repeat;
392 } 498 }
393 499
500 /*
501 * See if we can skip waking up the parent. This is safe only if
502 * power.no_callbacks is set, because otherwise we don't know whether
503 * the resume will actually succeed.
504 */
505 if (dev->power.no_callbacks && !parent && dev->parent) {
506 spin_lock(&dev->parent->power.lock);
507 if (dev->parent->power.disable_depth > 0
508 || dev->parent->power.ignore_children
509 || dev->parent->power.runtime_status == RPM_ACTIVE) {
510 atomic_inc(&dev->parent->power.child_count);
511 spin_unlock(&dev->parent->power.lock);
512 goto no_callback; /* Assume success. */
513 }
514 spin_unlock(&dev->parent->power.lock);
515 }
516
517 /* Carry out an asynchronous or a synchronous resume. */
518 if (rpmflags & RPM_ASYNC) {
519 dev->power.request = RPM_REQ_RESUME;
520 if (!dev->power.request_pending) {
521 dev->power.request_pending = true;
522 queue_work(pm_wq, &dev->power.work);
523 }
524 retval = 0;
525 goto out;
526 }
527
394 if (!parent && dev->parent) { 528 if (!parent && dev->parent) {
395 /* 529 /*
396 * Increment the parent's resume counter and resume it if 530 * Increment the parent's resume counter and resume it if
@@ -408,7 +542,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
408 */ 542 */
409 if (!parent->power.disable_depth 543 if (!parent->power.disable_depth
410 && !parent->power.ignore_children) { 544 && !parent->power.ignore_children) {
411 __pm_runtime_resume(parent, false); 545 rpm_resume(parent, 0);
412 if (parent->power.runtime_status != RPM_ACTIVE) 546 if (parent->power.runtime_status != RPM_ACTIVE)
413 retval = -EBUSY; 547 retval = -EBUSY;
414 } 548 }
@@ -420,39 +554,26 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
420 goto repeat; 554 goto repeat;
421 } 555 }
422 556
423 __update_runtime_status(dev, RPM_RESUMING); 557 if (dev->power.no_callbacks)
424 558 goto no_callback; /* Assume success. */
425 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume) {
426 spin_unlock_irq(&dev->power.lock);
427
428 retval = dev->bus->pm->runtime_resume(dev);
429
430 spin_lock_irq(&dev->power.lock);
431 dev->power.runtime_error = retval;
432 } else if (dev->type && dev->type->pm
433 && dev->type->pm->runtime_resume) {
434 spin_unlock_irq(&dev->power.lock);
435
436 retval = dev->type->pm->runtime_resume(dev);
437 559
438 spin_lock_irq(&dev->power.lock); 560 __update_runtime_status(dev, RPM_RESUMING);
439 dev->power.runtime_error = retval;
440 } else if (dev->class && dev->class->pm
441 && dev->class->pm->runtime_resume) {
442 spin_unlock_irq(&dev->power.lock);
443
444 retval = dev->class->pm->runtime_resume(dev);
445 561
446 spin_lock_irq(&dev->power.lock); 562 if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume)
447 dev->power.runtime_error = retval; 563 callback = dev->bus->pm->runtime_resume;
448 } else { 564 else if (dev->type && dev->type->pm && dev->type->pm->runtime_resume)
449 retval = -ENOSYS; 565 callback = dev->type->pm->runtime_resume;
450 } 566 else if (dev->class && dev->class->pm)
567 callback = dev->class->pm->runtime_resume;
568 else
569 callback = NULL;
451 570
571 retval = rpm_callback(callback, dev);
452 if (retval) { 572 if (retval) {
453 __update_runtime_status(dev, RPM_SUSPENDED); 573 __update_runtime_status(dev, RPM_SUSPENDED);
454 pm_runtime_cancel_pending(dev); 574 pm_runtime_cancel_pending(dev);
455 } else { 575 } else {
576 no_callback:
456 __update_runtime_status(dev, RPM_ACTIVE); 577 __update_runtime_status(dev, RPM_ACTIVE);
457 if (parent) 578 if (parent)
458 atomic_inc(&parent->power.child_count); 579 atomic_inc(&parent->power.child_count);
@@ -460,7 +581,7 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
460 wake_up_all(&dev->power.wait_queue); 581 wake_up_all(&dev->power.wait_queue);
461 582
462 if (!retval) 583 if (!retval)
463 __pm_request_idle(dev); 584 rpm_idle(dev, RPM_ASYNC);
464 585
465 out: 586 out:
466 if (parent) { 587 if (parent) {
@@ -471,28 +592,12 @@ int __pm_runtime_resume(struct device *dev, bool from_wq)
471 spin_lock_irq(&dev->power.lock); 592 spin_lock_irq(&dev->power.lock);
472 } 593 }
473 594
474 dev_dbg(dev, "__pm_runtime_resume() returns %d!\n", retval); 595 dev_dbg(dev, "%s returns %d\n", __func__, retval);
475 596
476 return retval; 597 return retval;
477} 598}
478 599
479/** 600/**
480 * pm_runtime_resume - Carry out run-time resume of given device.
481 * @dev: Device to suspend.
482 */
483int pm_runtime_resume(struct device *dev)
484{
485 int retval;
486
487 spin_lock_irq(&dev->power.lock);
488 retval = __pm_runtime_resume(dev, false);
489 spin_unlock_irq(&dev->power.lock);
490
491 return retval;
492}
493EXPORT_SYMBOL_GPL(pm_runtime_resume);
494
495/**
496 * pm_runtime_work - Universal run-time PM work function. 601 * pm_runtime_work - Universal run-time PM work function.
497 * @work: Work structure used for scheduling the execution of this function. 602 * @work: Work structure used for scheduling the execution of this function.
498 * 603 *
@@ -517,13 +622,16 @@ static void pm_runtime_work(struct work_struct *work)
517 case RPM_REQ_NONE: 622 case RPM_REQ_NONE:
518 break; 623 break;
519 case RPM_REQ_IDLE: 624 case RPM_REQ_IDLE:
520 __pm_runtime_idle(dev); 625 rpm_idle(dev, RPM_NOWAIT);
521 break; 626 break;
522 case RPM_REQ_SUSPEND: 627 case RPM_REQ_SUSPEND:
523 __pm_runtime_suspend(dev, true); 628 rpm_suspend(dev, RPM_NOWAIT);
629 break;
630 case RPM_REQ_AUTOSUSPEND:
631 rpm_suspend(dev, RPM_NOWAIT | RPM_AUTO);
524 break; 632 break;
525 case RPM_REQ_RESUME: 633 case RPM_REQ_RESUME:
526 __pm_runtime_resume(dev, true); 634 rpm_resume(dev, RPM_NOWAIT);
527 break; 635 break;
528 } 636 }
529 637
@@ -532,117 +640,10 @@ static void pm_runtime_work(struct work_struct *work)
532} 640}
533 641
534/** 642/**
535 * __pm_request_idle - Submit an idle notification request for given device.
536 * @dev: Device to handle.
537 *
538 * Check if the device's run-time PM status is correct for suspending the device
539 * and queue up a request to run __pm_runtime_idle() for it.
540 *
541 * This function must be called under dev->power.lock with interrupts disabled.
542 */
543static int __pm_request_idle(struct device *dev)
544{
545 int retval = 0;
546
547 if (dev->power.runtime_error)
548 retval = -EINVAL;
549 else if (atomic_read(&dev->power.usage_count) > 0
550 || dev->power.disable_depth > 0
551 || dev->power.runtime_status == RPM_SUSPENDED
552 || dev->power.runtime_status == RPM_SUSPENDING)
553 retval = -EAGAIN;
554 else if (!pm_children_suspended(dev))
555 retval = -EBUSY;
556 if (retval)
557 return retval;
558
559 if (dev->power.request_pending) {
560 /* Any requests other then RPM_REQ_IDLE take precedence. */
561 if (dev->power.request == RPM_REQ_NONE)
562 dev->power.request = RPM_REQ_IDLE;
563 else if (dev->power.request != RPM_REQ_IDLE)
564 retval = -EAGAIN;
565 return retval;
566 }
567
568 dev->power.request = RPM_REQ_IDLE;
569 dev->power.request_pending = true;
570 queue_work(pm_wq, &dev->power.work);
571
572 return retval;
573}
574
575/**
576 * pm_request_idle - Submit an idle notification request for given device.
577 * @dev: Device to handle.
578 */
579int pm_request_idle(struct device *dev)
580{
581 unsigned long flags;
582 int retval;
583
584 spin_lock_irqsave(&dev->power.lock, flags);
585 retval = __pm_request_idle(dev);
586 spin_unlock_irqrestore(&dev->power.lock, flags);
587
588 return retval;
589}
590EXPORT_SYMBOL_GPL(pm_request_idle);
591
592/**
593 * __pm_request_suspend - Submit a suspend request for given device.
594 * @dev: Device to suspend.
595 *
596 * This function must be called under dev->power.lock with interrupts disabled.
597 */
598static int __pm_request_suspend(struct device *dev)
599{
600 int retval = 0;
601
602 if (dev->power.runtime_error)
603 return -EINVAL;
604
605 if (dev->power.runtime_status == RPM_SUSPENDED)
606 retval = 1;
607 else if (atomic_read(&dev->power.usage_count) > 0
608 || dev->power.disable_depth > 0)
609 retval = -EAGAIN;
610 else if (dev->power.runtime_status == RPM_SUSPENDING)
611 retval = -EINPROGRESS;
612 else if (!pm_children_suspended(dev))
613 retval = -EBUSY;
614 if (retval < 0)
615 return retval;
616
617 pm_runtime_deactivate_timer(dev);
618
619 if (dev->power.request_pending) {
620 /*
621 * Pending resume requests take precedence over us, but we can
622 * overtake any other pending request.
623 */
624 if (dev->power.request == RPM_REQ_RESUME)
625 retval = -EAGAIN;
626 else if (dev->power.request != RPM_REQ_SUSPEND)
627 dev->power.request = retval ?
628 RPM_REQ_NONE : RPM_REQ_SUSPEND;
629 return retval;
630 } else if (retval) {
631 return retval;
632 }
633
634 dev->power.request = RPM_REQ_SUSPEND;
635 dev->power.request_pending = true;
636 queue_work(pm_wq, &dev->power.work);
637
638 return 0;
639}
640
641/**
642 * pm_suspend_timer_fn - Timer function for pm_schedule_suspend(). 643 * pm_suspend_timer_fn - Timer function for pm_schedule_suspend().
643 * @data: Device pointer passed by pm_schedule_suspend(). 644 * @data: Device pointer passed by pm_schedule_suspend().
644 * 645 *
645 * Check if the time is right and execute __pm_request_suspend() in that case. 646 * Check if the time is right and queue a suspend request.
646 */ 647 */
647static void pm_suspend_timer_fn(unsigned long data) 648static void pm_suspend_timer_fn(unsigned long data)
648{ 649{
@@ -656,7 +657,8 @@ static void pm_suspend_timer_fn(unsigned long data)
656 /* If 'expire' is after 'jiffies' we've been called too early. */ 657 /* If 'expire' is after 'jiffies' we've been called too early. */
657 if (expires > 0 && !time_after(expires, jiffies)) { 658 if (expires > 0 && !time_after(expires, jiffies)) {
658 dev->power.timer_expires = 0; 659 dev->power.timer_expires = 0;
659 __pm_request_suspend(dev); 660 rpm_suspend(dev, dev->power.timer_autosuspends ?
661 (RPM_ASYNC | RPM_AUTO) : RPM_ASYNC);
660 } 662 }
661 663
662 spin_unlock_irqrestore(&dev->power.lock, flags); 664 spin_unlock_irqrestore(&dev->power.lock, flags);
@@ -670,47 +672,25 @@ static void pm_suspend_timer_fn(unsigned long data)
670int pm_schedule_suspend(struct device *dev, unsigned int delay) 672int pm_schedule_suspend(struct device *dev, unsigned int delay)
671{ 673{
672 unsigned long flags; 674 unsigned long flags;
673 int retval = 0; 675 int retval;
674 676
675 spin_lock_irqsave(&dev->power.lock, flags); 677 spin_lock_irqsave(&dev->power.lock, flags);
676 678
677 if (dev->power.runtime_error) {
678 retval = -EINVAL;
679 goto out;
680 }
681
682 if (!delay) { 679 if (!delay) {
683 retval = __pm_request_suspend(dev); 680 retval = rpm_suspend(dev, RPM_ASYNC);
684 goto out; 681 goto out;
685 } 682 }
686 683
687 pm_runtime_deactivate_timer(dev); 684 retval = rpm_check_suspend_allowed(dev);
688
689 if (dev->power.request_pending) {
690 /*
691 * Pending resume requests take precedence over us, but any
692 * other pending requests have to be canceled.
693 */
694 if (dev->power.request == RPM_REQ_RESUME) {
695 retval = -EAGAIN;
696 goto out;
697 }
698 dev->power.request = RPM_REQ_NONE;
699 }
700
701 if (dev->power.runtime_status == RPM_SUSPENDED)
702 retval = 1;
703 else if (atomic_read(&dev->power.usage_count) > 0
704 || dev->power.disable_depth > 0)
705 retval = -EAGAIN;
706 else if (!pm_children_suspended(dev))
707 retval = -EBUSY;
708 if (retval) 685 if (retval)
709 goto out; 686 goto out;
710 687
688 /* Other scheduled or pending requests need to be canceled. */
689 pm_runtime_cancel_pending(dev);
690
711 dev->power.timer_expires = jiffies + msecs_to_jiffies(delay); 691 dev->power.timer_expires = jiffies + msecs_to_jiffies(delay);
712 if (!dev->power.timer_expires) 692 dev->power.timer_expires += !dev->power.timer_expires;
713 dev->power.timer_expires = 1; 693 dev->power.timer_autosuspends = 0;
714 mod_timer(&dev->power.suspend_timer, dev->power.timer_expires); 694 mod_timer(&dev->power.suspend_timer, dev->power.timer_expires);
715 695
716 out: 696 out:
@@ -721,103 +701,88 @@ int pm_schedule_suspend(struct device *dev, unsigned int delay)
721EXPORT_SYMBOL_GPL(pm_schedule_suspend); 701EXPORT_SYMBOL_GPL(pm_schedule_suspend);
722 702
723/** 703/**
724 * pm_request_resume - Submit a resume request for given device. 704 * __pm_runtime_idle - Entry point for run-time idle operations.
725 * @dev: Device to resume. 705 * @dev: Device to send idle notification for.
706 * @rpmflags: Flag bits.
726 * 707 *
727 * This function must be called under dev->power.lock with interrupts disabled. 708 * If the RPM_GET_PUT flag is set, decrement the device's usage count and
709 * return immediately if it is larger than zero. Then carry out an idle
710 * notification, either synchronous or asynchronous.
711 *
712 * This routine may be called in atomic context if the RPM_ASYNC flag is set.
728 */ 713 */
729static int __pm_request_resume(struct device *dev) 714int __pm_runtime_idle(struct device *dev, int rpmflags)
730{ 715{
731 int retval = 0; 716 unsigned long flags;
732 717 int retval;
733 if (dev->power.runtime_error)
734 return -EINVAL;
735
736 if (dev->power.runtime_status == RPM_ACTIVE)
737 retval = 1;
738 else if (dev->power.runtime_status == RPM_RESUMING)
739 retval = -EINPROGRESS;
740 else if (dev->power.disable_depth > 0)
741 retval = -EAGAIN;
742 if (retval < 0)
743 return retval;
744
745 pm_runtime_deactivate_timer(dev);
746 718
747 if (dev->power.runtime_status == RPM_SUSPENDING) { 719 if (rpmflags & RPM_GET_PUT) {
748 dev->power.deferred_resume = true; 720 if (!atomic_dec_and_test(&dev->power.usage_count))
749 return retval; 721 return 0;
750 } 722 }
751 if (dev->power.request_pending) {
752 /* If non-resume request is pending, we can overtake it. */
753 dev->power.request = retval ? RPM_REQ_NONE : RPM_REQ_RESUME;
754 return retval;
755 }
756 if (retval)
757 return retval;
758 723
759 dev->power.request = RPM_REQ_RESUME; 724 spin_lock_irqsave(&dev->power.lock, flags);
760 dev->power.request_pending = true; 725 retval = rpm_idle(dev, rpmflags);
761 queue_work(pm_wq, &dev->power.work); 726 spin_unlock_irqrestore(&dev->power.lock, flags);
762 727
763 return retval; 728 return retval;
764} 729}
730EXPORT_SYMBOL_GPL(__pm_runtime_idle);
765 731
766/** 732/**
767 * pm_request_resume - Submit a resume request for given device. 733 * __pm_runtime_suspend - Entry point for run-time put/suspend operations.
768 * @dev: Device to resume. 734 * @dev: Device to suspend.
735 * @rpmflags: Flag bits.
736 *
737 * If the RPM_GET_PUT flag is set, decrement the device's usage count and
738 * return immediately if it is larger than zero. Then carry out a suspend,
739 * either synchronous or asynchronous.
740 *
741 * This routine may be called in atomic context if the RPM_ASYNC flag is set.
769 */ 742 */
770int pm_request_resume(struct device *dev) 743int __pm_runtime_suspend(struct device *dev, int rpmflags)
771{ 744{
772 unsigned long flags; 745 unsigned long flags;
773 int retval; 746 int retval;
774 747
748 if (rpmflags & RPM_GET_PUT) {
749 if (!atomic_dec_and_test(&dev->power.usage_count))
750 return 0;
751 }
752
775 spin_lock_irqsave(&dev->power.lock, flags); 753 spin_lock_irqsave(&dev->power.lock, flags);
776 retval = __pm_request_resume(dev); 754 retval = rpm_suspend(dev, rpmflags);
777 spin_unlock_irqrestore(&dev->power.lock, flags); 755 spin_unlock_irqrestore(&dev->power.lock, flags);
778 756
779 return retval; 757 return retval;
780} 758}
781EXPORT_SYMBOL_GPL(pm_request_resume); 759EXPORT_SYMBOL_GPL(__pm_runtime_suspend);
782 760
783/** 761/**
784 * __pm_runtime_get - Reference count a device and wake it up, if necessary. 762 * __pm_runtime_resume - Entry point for run-time resume operations.
785 * @dev: Device to handle. 763 * @dev: Device to resume.
786 * @sync: If set and the device is suspended, resume it synchronously. 764 * @rpmflags: Flag bits.
765 *
766 * If the RPM_GET_PUT flag is set, increment the device's usage count. Then
767 * carry out a resume, either synchronous or asynchronous.
787 * 768 *
788 * Increment the usage count of the device and resume it or submit a resume 769 * This routine may be called in atomic context if the RPM_ASYNC flag is set.
789 * request for it, depending on the value of @sync.
790 */ 770 */
791int __pm_runtime_get(struct device *dev, bool sync) 771int __pm_runtime_resume(struct device *dev, int rpmflags)
792{ 772{
773 unsigned long flags;
793 int retval; 774 int retval;
794 775
795 atomic_inc(&dev->power.usage_count); 776 if (rpmflags & RPM_GET_PUT)
796 retval = sync ? pm_runtime_resume(dev) : pm_request_resume(dev); 777 atomic_inc(&dev->power.usage_count);
797 778
798 return retval; 779 spin_lock_irqsave(&dev->power.lock, flags);
799} 780 retval = rpm_resume(dev, rpmflags);
800EXPORT_SYMBOL_GPL(__pm_runtime_get); 781 spin_unlock_irqrestore(&dev->power.lock, flags);
801
802/**
803 * __pm_runtime_put - Decrement the device's usage counter and notify its bus.
804 * @dev: Device to handle.
805 * @sync: If the device's bus type is to be notified, do that synchronously.
806 *
807 * Decrement the usage count of the device and if it reaches zero, carry out a
808 * synchronous idle notification or submit an idle notification request for it,
809 * depending on the value of @sync.
810 */
811int __pm_runtime_put(struct device *dev, bool sync)
812{
813 int retval = 0;
814
815 if (atomic_dec_and_test(&dev->power.usage_count))
816 retval = sync ? pm_runtime_idle(dev) : pm_request_idle(dev);
817 782
818 return retval; 783 return retval;
819} 784}
820EXPORT_SYMBOL_GPL(__pm_runtime_put); 785EXPORT_SYMBOL_GPL(__pm_runtime_resume);
821 786
822/** 787/**
823 * __pm_runtime_set_status - Set run-time PM status of a device. 788 * __pm_runtime_set_status - Set run-time PM status of a device.
@@ -968,7 +933,7 @@ int pm_runtime_barrier(struct device *dev)
968 933
969 if (dev->power.request_pending 934 if (dev->power.request_pending
970 && dev->power.request == RPM_REQ_RESUME) { 935 && dev->power.request == RPM_REQ_RESUME) {
971 __pm_runtime_resume(dev, false); 936 rpm_resume(dev, 0);
972 retval = 1; 937 retval = 1;
973 } 938 }
974 939
@@ -1017,7 +982,7 @@ void __pm_runtime_disable(struct device *dev, bool check_resume)
1017 */ 982 */
1018 pm_runtime_get_noresume(dev); 983 pm_runtime_get_noresume(dev);
1019 984
1020 __pm_runtime_resume(dev, false); 985 rpm_resume(dev, 0);
1021 986
1022 pm_runtime_put_noidle(dev); 987 pm_runtime_put_noidle(dev);
1023 } 988 }
@@ -1065,7 +1030,7 @@ void pm_runtime_forbid(struct device *dev)
1065 1030
1066 dev->power.runtime_auto = false; 1031 dev->power.runtime_auto = false;
1067 atomic_inc(&dev->power.usage_count); 1032 atomic_inc(&dev->power.usage_count);
1068 __pm_runtime_resume(dev, false); 1033 rpm_resume(dev, 0);
1069 1034
1070 out: 1035 out:
1071 spin_unlock_irq(&dev->power.lock); 1036 spin_unlock_irq(&dev->power.lock);
@@ -1086,7 +1051,7 @@ void pm_runtime_allow(struct device *dev)
1086 1051
1087 dev->power.runtime_auto = true; 1052 dev->power.runtime_auto = true;
1088 if (atomic_dec_and_test(&dev->power.usage_count)) 1053 if (atomic_dec_and_test(&dev->power.usage_count))
1089 __pm_runtime_idle(dev); 1054 rpm_idle(dev, RPM_AUTO);
1090 1055
1091 out: 1056 out:
1092 spin_unlock_irq(&dev->power.lock); 1057 spin_unlock_irq(&dev->power.lock);
@@ -1094,13 +1059,110 @@ void pm_runtime_allow(struct device *dev)
1094EXPORT_SYMBOL_GPL(pm_runtime_allow); 1059EXPORT_SYMBOL_GPL(pm_runtime_allow);
1095 1060
1096/** 1061/**
1062 * pm_runtime_no_callbacks - Ignore run-time PM callbacks for a device.
1063 * @dev: Device to handle.
1064 *
1065 * Set the power.no_callbacks flag, which tells the PM core that this
1066 * device is power-managed through its parent and has no run-time PM
1067 * callbacks of its own. The run-time sysfs attributes will be removed.
1068 *
1069 */
1070void pm_runtime_no_callbacks(struct device *dev)
1071{
1072 spin_lock_irq(&dev->power.lock);
1073 dev->power.no_callbacks = 1;
1074 spin_unlock_irq(&dev->power.lock);
1075 if (device_is_registered(dev))
1076 rpm_sysfs_remove(dev);
1077}
1078EXPORT_SYMBOL_GPL(pm_runtime_no_callbacks);
1079
1080/**
1081 * update_autosuspend - Handle a change to a device's autosuspend settings.
1082 * @dev: Device to handle.
1083 * @old_delay: The former autosuspend_delay value.
1084 * @old_use: The former use_autosuspend value.
1085 *
1086 * Prevent runtime suspend if the new delay is negative and use_autosuspend is
1087 * set; otherwise allow it. Send an idle notification if suspends are allowed.
1088 *
1089 * This function must be called under dev->power.lock with interrupts disabled.
1090 */
1091static void update_autosuspend(struct device *dev, int old_delay, int old_use)
1092{
1093 int delay = dev->power.autosuspend_delay;
1094
1095 /* Should runtime suspend be prevented now? */
1096 if (dev->power.use_autosuspend && delay < 0) {
1097
1098 /* If it used to be allowed then prevent it. */
1099 if (!old_use || old_delay >= 0) {
1100 atomic_inc(&dev->power.usage_count);
1101 rpm_resume(dev, 0);
1102 }
1103 }
1104
1105 /* Runtime suspend should be allowed now. */
1106 else {
1107
1108 /* If it used to be prevented then allow it. */
1109 if (old_use && old_delay < 0)
1110 atomic_dec(&dev->power.usage_count);
1111
1112 /* Maybe we can autosuspend now. */
1113 rpm_idle(dev, RPM_AUTO);
1114 }
1115}
1116
1117/**
1118 * pm_runtime_set_autosuspend_delay - Set a device's autosuspend_delay value.
1119 * @dev: Device to handle.
1120 * @delay: Value of the new delay in milliseconds.
1121 *
1122 * Set the device's power.autosuspend_delay value. If it changes to negative
1123 * and the power.use_autosuspend flag is set, prevent run-time suspends. If it
1124 * changes the other way, allow run-time suspends.
1125 */
1126void pm_runtime_set_autosuspend_delay(struct device *dev, int delay)
1127{
1128 int old_delay, old_use;
1129
1130 spin_lock_irq(&dev->power.lock);
1131 old_delay = dev->power.autosuspend_delay;
1132 old_use = dev->power.use_autosuspend;
1133 dev->power.autosuspend_delay = delay;
1134 update_autosuspend(dev, old_delay, old_use);
1135 spin_unlock_irq(&dev->power.lock);
1136}
1137EXPORT_SYMBOL_GPL(pm_runtime_set_autosuspend_delay);
1138
1139/**
1140 * __pm_runtime_use_autosuspend - Set a device's use_autosuspend flag.
1141 * @dev: Device to handle.
1142 * @use: New value for use_autosuspend.
1143 *
1144 * Set the device's power.use_autosuspend flag, and allow or prevent run-time
1145 * suspends as needed.
1146 */
1147void __pm_runtime_use_autosuspend(struct device *dev, bool use)
1148{
1149 int old_delay, old_use;
1150
1151 spin_lock_irq(&dev->power.lock);
1152 old_delay = dev->power.autosuspend_delay;
1153 old_use = dev->power.use_autosuspend;
1154 dev->power.use_autosuspend = use;
1155 update_autosuspend(dev, old_delay, old_use);
1156 spin_unlock_irq(&dev->power.lock);
1157}
1158EXPORT_SYMBOL_GPL(__pm_runtime_use_autosuspend);
1159
1160/**
1097 * pm_runtime_init - Initialize run-time PM fields in given device object. 1161 * pm_runtime_init - Initialize run-time PM fields in given device object.
1098 * @dev: Device object to initialize. 1162 * @dev: Device object to initialize.
1099 */ 1163 */
1100void pm_runtime_init(struct device *dev) 1164void pm_runtime_init(struct device *dev)
1101{ 1165{
1102 spin_lock_init(&dev->power.lock);
1103
1104 dev->power.runtime_status = RPM_SUSPENDED; 1166 dev->power.runtime_status = RPM_SUSPENDED;
1105 dev->power.idle_notification = false; 1167 dev->power.idle_notification = false;
1106 1168
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index e56b4388fe61..0b1e46bf3e56 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -75,12 +75,27 @@
75 * attribute is set to "enabled" by bus type code or device drivers and in 75 * attribute is set to "enabled" by bus type code or device drivers and in
76 * that cases it should be safe to leave the default value. 76 * that cases it should be safe to leave the default value.
77 * 77 *
78 * autosuspend_delay_ms - Report/change a device's autosuspend_delay value
79 *
80 * Some drivers don't want to carry out a runtime suspend as soon as a
81 * device becomes idle; they want it always to remain idle for some period
82 * of time before suspending it. This period is the autosuspend_delay
83 * value (expressed in milliseconds) and it can be controlled by the user.
84 * If the value is negative then the device will never be runtime
85 * suspended.
86 *
87 * NOTE: The autosuspend_delay_ms attribute and the autosuspend_delay
88 * value are used only if the driver calls pm_runtime_use_autosuspend().
89 *
78 * wakeup_count - Report the number of wakeup events related to the device 90 * wakeup_count - Report the number of wakeup events related to the device
79 */ 91 */
80 92
81static const char enabled[] = "enabled"; 93static const char enabled[] = "enabled";
82static const char disabled[] = "disabled"; 94static const char disabled[] = "disabled";
83 95
96const char power_group_name[] = "power";
97EXPORT_SYMBOL_GPL(power_group_name);
98
84#ifdef CONFIG_PM_RUNTIME 99#ifdef CONFIG_PM_RUNTIME
85static const char ctrl_auto[] = "auto"; 100static const char ctrl_auto[] = "auto";
86static const char ctrl_on[] = "on"; 101static const char ctrl_on[] = "on";
@@ -170,6 +185,33 @@ static ssize_t rtpm_status_show(struct device *dev,
170} 185}
171 186
172static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL); 187static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
188
189static ssize_t autosuspend_delay_ms_show(struct device *dev,
190 struct device_attribute *attr, char *buf)
191{
192 if (!dev->power.use_autosuspend)
193 return -EIO;
194 return sprintf(buf, "%d\n", dev->power.autosuspend_delay);
195}
196
197static ssize_t autosuspend_delay_ms_store(struct device *dev,
198 struct device_attribute *attr, const char *buf, size_t n)
199{
200 long delay;
201
202 if (!dev->power.use_autosuspend)
203 return -EIO;
204
205 if (strict_strtol(buf, 10, &delay) != 0 || delay != (int) delay)
206 return -EINVAL;
207
208 pm_runtime_set_autosuspend_delay(dev, delay);
209 return n;
210}
211
212static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show,
213 autosuspend_delay_ms_store);
214
173#endif 215#endif
174 216
175static ssize_t 217static ssize_t
@@ -210,11 +252,122 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
210static ssize_t wakeup_count_show(struct device *dev, 252static ssize_t wakeup_count_show(struct device *dev,
211 struct device_attribute *attr, char *buf) 253 struct device_attribute *attr, char *buf)
212{ 254{
213 return sprintf(buf, "%lu\n", dev->power.wakeup_count); 255 unsigned long count = 0;
256 bool enabled = false;
257
258 spin_lock_irq(&dev->power.lock);
259 if (dev->power.wakeup) {
260 count = dev->power.wakeup->event_count;
261 enabled = true;
262 }
263 spin_unlock_irq(&dev->power.lock);
264 return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
214} 265}
215 266
216static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL); 267static DEVICE_ATTR(wakeup_count, 0444, wakeup_count_show, NULL);
217#endif 268
269static ssize_t wakeup_active_count_show(struct device *dev,
270 struct device_attribute *attr, char *buf)
271{
272 unsigned long count = 0;
273 bool enabled = false;
274
275 spin_lock_irq(&dev->power.lock);
276 if (dev->power.wakeup) {
277 count = dev->power.wakeup->active_count;
278 enabled = true;
279 }
280 spin_unlock_irq(&dev->power.lock);
281 return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
282}
283
284static DEVICE_ATTR(wakeup_active_count, 0444, wakeup_active_count_show, NULL);
285
286static ssize_t wakeup_hit_count_show(struct device *dev,
287 struct device_attribute *attr, char *buf)
288{
289 unsigned long count = 0;
290 bool enabled = false;
291
292 spin_lock_irq(&dev->power.lock);
293 if (dev->power.wakeup) {
294 count = dev->power.wakeup->hit_count;
295 enabled = true;
296 }
297 spin_unlock_irq(&dev->power.lock);
298 return enabled ? sprintf(buf, "%lu\n", count) : sprintf(buf, "\n");
299}
300
301static DEVICE_ATTR(wakeup_hit_count, 0444, wakeup_hit_count_show, NULL);
302
303static ssize_t wakeup_active_show(struct device *dev,
304 struct device_attribute *attr, char *buf)
305{
306 unsigned int active = 0;
307 bool enabled = false;
308
309 spin_lock_irq(&dev->power.lock);
310 if (dev->power.wakeup) {
311 active = dev->power.wakeup->active;
312 enabled = true;
313 }
314 spin_unlock_irq(&dev->power.lock);
315 return enabled ? sprintf(buf, "%u\n", active) : sprintf(buf, "\n");
316}
317
318static DEVICE_ATTR(wakeup_active, 0444, wakeup_active_show, NULL);
319
320static ssize_t wakeup_total_time_show(struct device *dev,
321 struct device_attribute *attr, char *buf)
322{
323 s64 msec = 0;
324 bool enabled = false;
325
326 spin_lock_irq(&dev->power.lock);
327 if (dev->power.wakeup) {
328 msec = ktime_to_ms(dev->power.wakeup->total_time);
329 enabled = true;
330 }
331 spin_unlock_irq(&dev->power.lock);
332 return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
333}
334
335static DEVICE_ATTR(wakeup_total_time_ms, 0444, wakeup_total_time_show, NULL);
336
337static ssize_t wakeup_max_time_show(struct device *dev,
338 struct device_attribute *attr, char *buf)
339{
340 s64 msec = 0;
341 bool enabled = false;
342
343 spin_lock_irq(&dev->power.lock);
344 if (dev->power.wakeup) {
345 msec = ktime_to_ms(dev->power.wakeup->max_time);
346 enabled = true;
347 }
348 spin_unlock_irq(&dev->power.lock);
349 return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
350}
351
352static DEVICE_ATTR(wakeup_max_time_ms, 0444, wakeup_max_time_show, NULL);
353
354static ssize_t wakeup_last_time_show(struct device *dev,
355 struct device_attribute *attr, char *buf)
356{
357 s64 msec = 0;
358 bool enabled = false;
359
360 spin_lock_irq(&dev->power.lock);
361 if (dev->power.wakeup) {
362 msec = ktime_to_ms(dev->power.wakeup->last_time);
363 enabled = true;
364 }
365 spin_unlock_irq(&dev->power.lock);
366 return enabled ? sprintf(buf, "%lld\n", msec) : sprintf(buf, "\n");
367}
368
369static DEVICE_ATTR(wakeup_last_time_ms, 0444, wakeup_last_time_show, NULL);
370#endif /* CONFIG_PM_SLEEP */
218 371
219#ifdef CONFIG_PM_ADVANCED_DEBUG 372#ifdef CONFIG_PM_ADVANCED_DEBUG
220#ifdef CONFIG_PM_RUNTIME 373#ifdef CONFIG_PM_RUNTIME
@@ -279,19 +432,20 @@ static DEVICE_ATTR(async, 0644, async_show, async_store);
279#endif /* CONFIG_PM_ADVANCED_DEBUG */ 432#endif /* CONFIG_PM_ADVANCED_DEBUG */
280 433
281static struct attribute * power_attrs[] = { 434static struct attribute * power_attrs[] = {
282#ifdef CONFIG_PM_RUNTIME
283 &dev_attr_control.attr,
284 &dev_attr_runtime_status.attr,
285 &dev_attr_runtime_suspended_time.attr,
286 &dev_attr_runtime_active_time.attr,
287#endif
288 &dev_attr_wakeup.attr, 435 &dev_attr_wakeup.attr,
289#ifdef CONFIG_PM_SLEEP 436#ifdef CONFIG_PM_SLEEP
290 &dev_attr_wakeup_count.attr, 437 &dev_attr_wakeup_count.attr,
438 &dev_attr_wakeup_active_count.attr,
439 &dev_attr_wakeup_hit_count.attr,
440 &dev_attr_wakeup_active.attr,
441 &dev_attr_wakeup_total_time_ms.attr,
442 &dev_attr_wakeup_max_time_ms.attr,
443 &dev_attr_wakeup_last_time_ms.attr,
291#endif 444#endif
292#ifdef CONFIG_PM_ADVANCED_DEBUG 445#ifdef CONFIG_PM_ADVANCED_DEBUG
293 &dev_attr_async.attr, 446 &dev_attr_async.attr,
294#ifdef CONFIG_PM_RUNTIME 447#ifdef CONFIG_PM_RUNTIME
448 &dev_attr_runtime_status.attr,
295 &dev_attr_runtime_usage.attr, 449 &dev_attr_runtime_usage.attr,
296 &dev_attr_runtime_active_kids.attr, 450 &dev_attr_runtime_active_kids.attr,
297 &dev_attr_runtime_enabled.attr, 451 &dev_attr_runtime_enabled.attr,
@@ -300,10 +454,53 @@ static struct attribute * power_attrs[] = {
300 NULL, 454 NULL,
301}; 455};
302static struct attribute_group pm_attr_group = { 456static struct attribute_group pm_attr_group = {
303 .name = "power", 457 .name = power_group_name,
304 .attrs = power_attrs, 458 .attrs = power_attrs,
305}; 459};
306 460
461#ifdef CONFIG_PM_RUNTIME
462
463static struct attribute *runtime_attrs[] = {
464#ifndef CONFIG_PM_ADVANCED_DEBUG
465 &dev_attr_runtime_status.attr,
466#endif
467 &dev_attr_control.attr,
468 &dev_attr_runtime_suspended_time.attr,
469 &dev_attr_runtime_active_time.attr,
470 &dev_attr_autosuspend_delay_ms.attr,
471 NULL,
472};
473static struct attribute_group pm_runtime_attr_group = {
474 .name = power_group_name,
475 .attrs = runtime_attrs,
476};
477
478int dpm_sysfs_add(struct device *dev)
479{
480 int rc;
481
482 rc = sysfs_create_group(&dev->kobj, &pm_attr_group);
483 if (rc == 0 && !dev->power.no_callbacks) {
484 rc = sysfs_merge_group(&dev->kobj, &pm_runtime_attr_group);
485 if (rc)
486 sysfs_remove_group(&dev->kobj, &pm_attr_group);
487 }
488 return rc;
489}
490
491void rpm_sysfs_remove(struct device *dev)
492{
493 sysfs_unmerge_group(&dev->kobj, &pm_runtime_attr_group);
494}
495
496void dpm_sysfs_remove(struct device *dev)
497{
498 rpm_sysfs_remove(dev);
499 sysfs_remove_group(&dev->kobj, &pm_attr_group);
500}
501
502#else /* CONFIG_PM_RUNTIME */
503
307int dpm_sysfs_add(struct device * dev) 504int dpm_sysfs_add(struct device * dev)
308{ 505{
309 return sysfs_create_group(&dev->kobj, &pm_attr_group); 506 return sysfs_create_group(&dev->kobj, &pm_attr_group);
@@ -313,3 +510,5 @@ void dpm_sysfs_remove(struct device * dev)
313{ 510{
314 sysfs_remove_group(&dev->kobj, &pm_attr_group); 511 sysfs_remove_group(&dev->kobj, &pm_attr_group);
315} 512}
513
514#endif
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index 0a1a2c4dbc6e..9f4258df4cfd 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -188,8 +188,10 @@ static int show_file_hash(unsigned int value)
188static int show_dev_hash(unsigned int value) 188static int show_dev_hash(unsigned int value)
189{ 189{
190 int match = 0; 190 int match = 0;
191 struct list_head *entry = dpm_list.prev; 191 struct list_head *entry;
192 192
193 device_pm_lock();
194 entry = dpm_list.prev;
193 while (entry != &dpm_list) { 195 while (entry != &dpm_list) {
194 struct device * dev = to_device(entry); 196 struct device * dev = to_device(entry);
195 unsigned int hash = hash_string(DEVSEED, dev_name(dev), DEVHASH); 197 unsigned int hash = hash_string(DEVSEED, dev_name(dev), DEVHASH);
@@ -199,11 +201,43 @@ static int show_dev_hash(unsigned int value)
199 } 201 }
200 entry = entry->prev; 202 entry = entry->prev;
201 } 203 }
204 device_pm_unlock();
202 return match; 205 return match;
203} 206}
204 207
205static unsigned int hash_value_early_read; 208static unsigned int hash_value_early_read;
206 209
210int show_trace_dev_match(char *buf, size_t size)
211{
212 unsigned int value = hash_value_early_read / (USERHASH * FILEHASH);
213 int ret = 0;
214 struct list_head *entry;
215
216 /*
217 * It's possible that multiple devices will match the hash and we can't
218 * tell which is the culprit, so it's best to output them all.
219 */
220 device_pm_lock();
221 entry = dpm_list.prev;
222 while (size && entry != &dpm_list) {
223 struct device *dev = to_device(entry);
224 unsigned int hash = hash_string(DEVSEED, dev_name(dev),
225 DEVHASH);
226 if (hash == value) {
227 int len = snprintf(buf, size, "%s\n",
228 dev_driver_string(dev));
229 if (len > size)
230 len = size;
231 buf += len;
232 ret += len;
233 size -= len;
234 }
235 entry = entry->prev;
236 }
237 device_pm_unlock();
238 return ret;
239}
240
207static int early_resume_init(void) 241static int early_resume_init(void)
208{ 242{
209 hash_value_early_read = read_magic_time(); 243 hash_value_early_read = read_magic_time();
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index eb594facfc3f..71c5528e1c35 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -11,7 +11,12 @@
11#include <linux/sched.h> 11#include <linux/sched.h>
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/suspend.h> 13#include <linux/suspend.h>
14#include <linux/pm.h> 14#include <linux/seq_file.h>
15#include <linux/debugfs.h>
16
17#include "power.h"
18
19#define TIMEOUT 100
15 20
16/* 21/*
17 * If set, the suspend/hibernate code will abort transitions to a sleep state 22 * If set, the suspend/hibernate code will abort transitions to a sleep state
@@ -20,18 +25,244 @@
20bool events_check_enabled; 25bool events_check_enabled;
21 26
22/* The counter of registered wakeup events. */ 27/* The counter of registered wakeup events. */
23static unsigned long event_count; 28static atomic_t event_count = ATOMIC_INIT(0);
24/* A preserved old value of event_count. */ 29/* A preserved old value of event_count. */
25static unsigned long saved_event_count; 30static unsigned int saved_count;
26/* The counter of wakeup events being processed. */ 31/* The counter of wakeup events being processed. */
27static unsigned long events_in_progress; 32static atomic_t events_in_progress = ATOMIC_INIT(0);
28 33
29static DEFINE_SPINLOCK(events_lock); 34static DEFINE_SPINLOCK(events_lock);
30 35
31static void pm_wakeup_timer_fn(unsigned long data); 36static void pm_wakeup_timer_fn(unsigned long data);
32 37
33static DEFINE_TIMER(events_timer, pm_wakeup_timer_fn, 0, 0); 38static LIST_HEAD(wakeup_sources);
34static unsigned long events_timer_expires; 39
40/**
41 * wakeup_source_create - Create a struct wakeup_source object.
42 * @name: Name of the new wakeup source.
43 */
44struct wakeup_source *wakeup_source_create(const char *name)
45{
46 struct wakeup_source *ws;
47
48 ws = kzalloc(sizeof(*ws), GFP_KERNEL);
49 if (!ws)
50 return NULL;
51
52 spin_lock_init(&ws->lock);
53 if (name)
54 ws->name = kstrdup(name, GFP_KERNEL);
55
56 return ws;
57}
58EXPORT_SYMBOL_GPL(wakeup_source_create);
59
60/**
61 * wakeup_source_destroy - Destroy a struct wakeup_source object.
62 * @ws: Wakeup source to destroy.
63 */
64void wakeup_source_destroy(struct wakeup_source *ws)
65{
66 if (!ws)
67 return;
68
69 spin_lock_irq(&ws->lock);
70 while (ws->active) {
71 spin_unlock_irq(&ws->lock);
72
73 schedule_timeout_interruptible(msecs_to_jiffies(TIMEOUT));
74
75 spin_lock_irq(&ws->lock);
76 }
77 spin_unlock_irq(&ws->lock);
78
79 kfree(ws->name);
80 kfree(ws);
81}
82EXPORT_SYMBOL_GPL(wakeup_source_destroy);
83
84/**
85 * wakeup_source_add - Add given object to the list of wakeup sources.
86 * @ws: Wakeup source object to add to the list.
87 */
88void wakeup_source_add(struct wakeup_source *ws)
89{
90 if (WARN_ON(!ws))
91 return;
92
93 setup_timer(&ws->timer, pm_wakeup_timer_fn, (unsigned long)ws);
94 ws->active = false;
95
96 spin_lock_irq(&events_lock);
97 list_add_rcu(&ws->entry, &wakeup_sources);
98 spin_unlock_irq(&events_lock);
99 synchronize_rcu();
100}
101EXPORT_SYMBOL_GPL(wakeup_source_add);
102
103/**
104 * wakeup_source_remove - Remove given object from the wakeup sources list.
105 * @ws: Wakeup source object to remove from the list.
106 */
107void wakeup_source_remove(struct wakeup_source *ws)
108{
109 if (WARN_ON(!ws))
110 return;
111
112 spin_lock_irq(&events_lock);
113 list_del_rcu(&ws->entry);
114 spin_unlock_irq(&events_lock);
115 synchronize_rcu();
116}
117EXPORT_SYMBOL_GPL(wakeup_source_remove);
118
119/**
120 * wakeup_source_register - Create wakeup source and add it to the list.
121 * @name: Name of the wakeup source to register.
122 */
123struct wakeup_source *wakeup_source_register(const char *name)
124{
125 struct wakeup_source *ws;
126
127 ws = wakeup_source_create(name);
128 if (ws)
129 wakeup_source_add(ws);
130
131 return ws;
132}
133EXPORT_SYMBOL_GPL(wakeup_source_register);
134
135/**
136 * wakeup_source_unregister - Remove wakeup source from the list and remove it.
137 * @ws: Wakeup source object to unregister.
138 */
139void wakeup_source_unregister(struct wakeup_source *ws)
140{
141 wakeup_source_remove(ws);
142 wakeup_source_destroy(ws);
143}
144EXPORT_SYMBOL_GPL(wakeup_source_unregister);
145
146/**
147 * device_wakeup_attach - Attach a wakeup source object to a device object.
148 * @dev: Device to handle.
149 * @ws: Wakeup source object to attach to @dev.
150 *
151 * This causes @dev to be treated as a wakeup device.
152 */
153static int device_wakeup_attach(struct device *dev, struct wakeup_source *ws)
154{
155 spin_lock_irq(&dev->power.lock);
156 if (dev->power.wakeup) {
157 spin_unlock_irq(&dev->power.lock);
158 return -EEXIST;
159 }
160 dev->power.wakeup = ws;
161 spin_unlock_irq(&dev->power.lock);
162 return 0;
163}
164
165/**
166 * device_wakeup_enable - Enable given device to be a wakeup source.
167 * @dev: Device to handle.
168 *
169 * Create a wakeup source object, register it and attach it to @dev.
170 */
171int device_wakeup_enable(struct device *dev)
172{
173 struct wakeup_source *ws;
174 int ret;
175
176 if (!dev || !dev->power.can_wakeup)
177 return -EINVAL;
178
179 ws = wakeup_source_register(dev_name(dev));
180 if (!ws)
181 return -ENOMEM;
182
183 ret = device_wakeup_attach(dev, ws);
184 if (ret)
185 wakeup_source_unregister(ws);
186
187 return ret;
188}
189EXPORT_SYMBOL_GPL(device_wakeup_enable);
190
191/**
192 * device_wakeup_detach - Detach a device's wakeup source object from it.
193 * @dev: Device to detach the wakeup source object from.
194 *
195 * After it returns, @dev will not be treated as a wakeup device any more.
196 */
197static struct wakeup_source *device_wakeup_detach(struct device *dev)
198{
199 struct wakeup_source *ws;
200
201 spin_lock_irq(&dev->power.lock);
202 ws = dev->power.wakeup;
203 dev->power.wakeup = NULL;
204 spin_unlock_irq(&dev->power.lock);
205 return ws;
206}
207
208/**
209 * device_wakeup_disable - Do not regard a device as a wakeup source any more.
210 * @dev: Device to handle.
211 *
212 * Detach the @dev's wakeup source object from it, unregister this wakeup source
213 * object and destroy it.
214 */
215int device_wakeup_disable(struct device *dev)
216{
217 struct wakeup_source *ws;
218
219 if (!dev || !dev->power.can_wakeup)
220 return -EINVAL;
221
222 ws = device_wakeup_detach(dev);
223 if (ws)
224 wakeup_source_unregister(ws);
225
226 return 0;
227}
228EXPORT_SYMBOL_GPL(device_wakeup_disable);
229
230/**
231 * device_init_wakeup - Device wakeup initialization.
232 * @dev: Device to handle.
233 * @enable: Whether or not to enable @dev as a wakeup device.
234 *
235 * By default, most devices should leave wakeup disabled. The exceptions are
236 * devices that everyone expects to be wakeup sources: keyboards, power buttons,
237 * possibly network interfaces, etc.
238 */
239int device_init_wakeup(struct device *dev, bool enable)
240{
241 int ret = 0;
242
243 if (enable) {
244 device_set_wakeup_capable(dev, true);
245 ret = device_wakeup_enable(dev);
246 } else {
247 device_set_wakeup_capable(dev, false);
248 }
249
250 return ret;
251}
252EXPORT_SYMBOL_GPL(device_init_wakeup);
253
254/**
255 * device_set_wakeup_enable - Enable or disable a device to wake up the system.
256 * @dev: Device to handle.
257 */
258int device_set_wakeup_enable(struct device *dev, bool enable)
259{
260 if (!dev || !dev->power.can_wakeup)
261 return -EINVAL;
262
263 return enable ? device_wakeup_enable(dev) : device_wakeup_disable(dev);
264}
265EXPORT_SYMBOL_GPL(device_set_wakeup_enable);
35 266
36/* 267/*
37 * The functions below use the observation that each wakeup event starts a 268 * The functions below use the observation that each wakeup event starts a
@@ -55,118 +286,259 @@ static unsigned long events_timer_expires;
55 * knowledge, however, may not be available to it, so it can simply specify time 286 * knowledge, however, may not be available to it, so it can simply specify time
56 * to wait before the system can be suspended and pass it as the second 287 * to wait before the system can be suspended and pass it as the second
57 * argument of pm_wakeup_event(). 288 * argument of pm_wakeup_event().
289 *
290 * It is valid to call pm_relax() after pm_wakeup_event(), in which case the
291 * "no suspend" period will be ended either by the pm_relax(), or by the timer
292 * function executed when the timer expires, whichever comes first.
58 */ 293 */
59 294
60/** 295/**
296 * wakup_source_activate - Mark given wakeup source as active.
297 * @ws: Wakeup source to handle.
298 *
299 * Update the @ws' statistics and, if @ws has just been activated, notify the PM
300 * core of the event by incrementing the counter of of wakeup events being
301 * processed.
302 */
303static void wakeup_source_activate(struct wakeup_source *ws)
304{
305 ws->active = true;
306 ws->active_count++;
307 ws->timer_expires = jiffies;
308 ws->last_time = ktime_get();
309
310 atomic_inc(&events_in_progress);
311}
312
313/**
314 * __pm_stay_awake - Notify the PM core of a wakeup event.
315 * @ws: Wakeup source object associated with the source of the event.
316 *
317 * It is safe to call this function from interrupt context.
318 */
319void __pm_stay_awake(struct wakeup_source *ws)
320{
321 unsigned long flags;
322
323 if (!ws)
324 return;
325
326 spin_lock_irqsave(&ws->lock, flags);
327 ws->event_count++;
328 if (!ws->active)
329 wakeup_source_activate(ws);
330 spin_unlock_irqrestore(&ws->lock, flags);
331}
332EXPORT_SYMBOL_GPL(__pm_stay_awake);
333
334/**
61 * pm_stay_awake - Notify the PM core that a wakeup event is being processed. 335 * pm_stay_awake - Notify the PM core that a wakeup event is being processed.
62 * @dev: Device the wakeup event is related to. 336 * @dev: Device the wakeup event is related to.
63 * 337 *
64 * Notify the PM core of a wakeup event (signaled by @dev) by incrementing the 338 * Notify the PM core of a wakeup event (signaled by @dev) by calling
65 * counter of wakeup events being processed. If @dev is not NULL, the counter 339 * __pm_stay_awake for the @dev's wakeup source object.
66 * of wakeup events related to @dev is incremented too.
67 * 340 *
68 * Call this function after detecting of a wakeup event if pm_relax() is going 341 * Call this function after detecting of a wakeup event if pm_relax() is going
69 * to be called directly after processing the event (and possibly passing it to 342 * to be called directly after processing the event (and possibly passing it to
70 * user space for further processing). 343 * user space for further processing).
71 *
72 * It is safe to call this function from interrupt context.
73 */ 344 */
74void pm_stay_awake(struct device *dev) 345void pm_stay_awake(struct device *dev)
75{ 346{
76 unsigned long flags; 347 unsigned long flags;
77 348
78 spin_lock_irqsave(&events_lock, flags); 349 if (!dev)
79 if (dev) 350 return;
80 dev->power.wakeup_count++;
81 351
82 events_in_progress++; 352 spin_lock_irqsave(&dev->power.lock, flags);
83 spin_unlock_irqrestore(&events_lock, flags); 353 __pm_stay_awake(dev->power.wakeup);
354 spin_unlock_irqrestore(&dev->power.lock, flags);
84} 355}
356EXPORT_SYMBOL_GPL(pm_stay_awake);
85 357
86/** 358/**
87 * pm_relax - Notify the PM core that processing of a wakeup event has ended. 359 * wakup_source_deactivate - Mark given wakeup source as inactive.
360 * @ws: Wakeup source to handle.
88 * 361 *
89 * Notify the PM core that a wakeup event has been processed by decrementing 362 * Update the @ws' statistics and notify the PM core that the wakeup source has
90 * the counter of wakeup events being processed and incrementing the counter 363 * become inactive by decrementing the counter of wakeup events being processed
91 * of registered wakeup events. 364 * and incrementing the counter of registered wakeup events.
365 */
366static void wakeup_source_deactivate(struct wakeup_source *ws)
367{
368 ktime_t duration;
369 ktime_t now;
370
371 ws->relax_count++;
372 /*
373 * __pm_relax() may be called directly or from a timer function.
374 * If it is called directly right after the timer function has been
375 * started, but before the timer function calls __pm_relax(), it is
376 * possible that __pm_stay_awake() will be called in the meantime and
377 * will set ws->active. Then, ws->active may be cleared immediately
378 * by the __pm_relax() called from the timer function, but in such a
379 * case ws->relax_count will be different from ws->active_count.
380 */
381 if (ws->relax_count != ws->active_count) {
382 ws->relax_count--;
383 return;
384 }
385
386 ws->active = false;
387
388 now = ktime_get();
389 duration = ktime_sub(now, ws->last_time);
390 ws->total_time = ktime_add(ws->total_time, duration);
391 if (ktime_to_ns(duration) > ktime_to_ns(ws->max_time))
392 ws->max_time = duration;
393
394 del_timer(&ws->timer);
395
396 /*
397 * event_count has to be incremented before events_in_progress is
398 * modified, so that the callers of pm_check_wakeup_events() and
399 * pm_save_wakeup_count() don't see the old value of event_count and
400 * events_in_progress equal to zero at the same time.
401 */
402 atomic_inc(&event_count);
403 smp_mb__before_atomic_dec();
404 atomic_dec(&events_in_progress);
405}
406
407/**
408 * __pm_relax - Notify the PM core that processing of a wakeup event has ended.
409 * @ws: Wakeup source object associated with the source of the event.
92 * 410 *
93 * Call this function for wakeup events whose processing started with calling 411 * Call this function for wakeup events whose processing started with calling
94 * pm_stay_awake(). 412 * __pm_stay_awake().
95 * 413 *
96 * It is safe to call it from interrupt context. 414 * It is safe to call it from interrupt context.
97 */ 415 */
98void pm_relax(void) 416void __pm_relax(struct wakeup_source *ws)
99{ 417{
100 unsigned long flags; 418 unsigned long flags;
101 419
102 spin_lock_irqsave(&events_lock, flags); 420 if (!ws)
103 if (events_in_progress) { 421 return;
104 events_in_progress--; 422
105 event_count++; 423 spin_lock_irqsave(&ws->lock, flags);
106 } 424 if (ws->active)
107 spin_unlock_irqrestore(&events_lock, flags); 425 wakeup_source_deactivate(ws);
426 spin_unlock_irqrestore(&ws->lock, flags);
427}
428EXPORT_SYMBOL_GPL(__pm_relax);
429
430/**
431 * pm_relax - Notify the PM core that processing of a wakeup event has ended.
432 * @dev: Device that signaled the event.
433 *
434 * Execute __pm_relax() for the @dev's wakeup source object.
435 */
436void pm_relax(struct device *dev)
437{
438 unsigned long flags;
439
440 if (!dev)
441 return;
442
443 spin_lock_irqsave(&dev->power.lock, flags);
444 __pm_relax(dev->power.wakeup);
445 spin_unlock_irqrestore(&dev->power.lock, flags);
108} 446}
447EXPORT_SYMBOL_GPL(pm_relax);
109 448
110/** 449/**
111 * pm_wakeup_timer_fn - Delayed finalization of a wakeup event. 450 * pm_wakeup_timer_fn - Delayed finalization of a wakeup event.
451 * @data: Address of the wakeup source object associated with the event source.
112 * 452 *
113 * Decrease the counter of wakeup events being processed after it was increased 453 * Call __pm_relax() for the wakeup source whose address is stored in @data.
114 * by pm_wakeup_event().
115 */ 454 */
116static void pm_wakeup_timer_fn(unsigned long data) 455static void pm_wakeup_timer_fn(unsigned long data)
117{ 456{
457 __pm_relax((struct wakeup_source *)data);
458}
459
460/**
461 * __pm_wakeup_event - Notify the PM core of a wakeup event.
462 * @ws: Wakeup source object associated with the event source.
463 * @msec: Anticipated event processing time (in milliseconds).
464 *
465 * Notify the PM core of a wakeup event whose source is @ws that will take
466 * approximately @msec milliseconds to be processed by the kernel. If @ws is
467 * not active, activate it. If @msec is nonzero, set up the @ws' timer to
468 * execute pm_wakeup_timer_fn() in future.
469 *
470 * It is safe to call this function from interrupt context.
471 */
472void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
473{
118 unsigned long flags; 474 unsigned long flags;
475 unsigned long expires;
119 476
120 spin_lock_irqsave(&events_lock, flags); 477 if (!ws)
121 if (events_timer_expires 478 return;
122 && time_before_eq(events_timer_expires, jiffies)) { 479
123 events_in_progress--; 480 spin_lock_irqsave(&ws->lock, flags);
124 events_timer_expires = 0; 481
482 ws->event_count++;
483 if (!ws->active)
484 wakeup_source_activate(ws);
485
486 if (!msec) {
487 wakeup_source_deactivate(ws);
488 goto unlock;
125 } 489 }
126 spin_unlock_irqrestore(&events_lock, flags); 490
491 expires = jiffies + msecs_to_jiffies(msec);
492 if (!expires)
493 expires = 1;
494
495 if (time_after(expires, ws->timer_expires)) {
496 mod_timer(&ws->timer, expires);
497 ws->timer_expires = expires;
498 }
499
500 unlock:
501 spin_unlock_irqrestore(&ws->lock, flags);
127} 502}
503EXPORT_SYMBOL_GPL(__pm_wakeup_event);
504
128 505
129/** 506/**
130 * pm_wakeup_event - Notify the PM core of a wakeup event. 507 * pm_wakeup_event - Notify the PM core of a wakeup event.
131 * @dev: Device the wakeup event is related to. 508 * @dev: Device the wakeup event is related to.
132 * @msec: Anticipated event processing time (in milliseconds). 509 * @msec: Anticipated event processing time (in milliseconds).
133 * 510 *
134 * Notify the PM core of a wakeup event (signaled by @dev) that will take 511 * Call __pm_wakeup_event() for the @dev's wakeup source object.
135 * approximately @msec milliseconds to be processed by the kernel. Increment
136 * the counter of registered wakeup events and (if @msec is nonzero) set up
137 * the wakeup events timer to execute pm_wakeup_timer_fn() in future (if the
138 * timer has not been set up already, increment the counter of wakeup events
139 * being processed). If @dev is not NULL, the counter of wakeup events related
140 * to @dev is incremented too.
141 *
142 * It is safe to call this function from interrupt context.
143 */ 512 */
144void pm_wakeup_event(struct device *dev, unsigned int msec) 513void pm_wakeup_event(struct device *dev, unsigned int msec)
145{ 514{
146 unsigned long flags; 515 unsigned long flags;
147 516
148 spin_lock_irqsave(&events_lock, flags); 517 if (!dev)
149 event_count++; 518 return;
150 if (dev)
151 dev->power.wakeup_count++;
152
153 if (msec) {
154 unsigned long expires;
155 519
156 expires = jiffies + msecs_to_jiffies(msec); 520 spin_lock_irqsave(&dev->power.lock, flags);
157 if (!expires) 521 __pm_wakeup_event(dev->power.wakeup, msec);
158 expires = 1; 522 spin_unlock_irqrestore(&dev->power.lock, flags);
523}
524EXPORT_SYMBOL_GPL(pm_wakeup_event);
159 525
160 if (!events_timer_expires 526/**
161 || time_after(expires, events_timer_expires)) { 527 * pm_wakeup_update_hit_counts - Update hit counts of all active wakeup sources.
162 if (!events_timer_expires) 528 */
163 events_in_progress++; 529static void pm_wakeup_update_hit_counts(void)
530{
531 unsigned long flags;
532 struct wakeup_source *ws;
164 533
165 mod_timer(&events_timer, expires); 534 rcu_read_lock();
166 events_timer_expires = expires; 535 list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
167 } 536 spin_lock_irqsave(&ws->lock, flags);
537 if (ws->active)
538 ws->hit_count++;
539 spin_unlock_irqrestore(&ws->lock, flags);
168 } 540 }
169 spin_unlock_irqrestore(&events_lock, flags); 541 rcu_read_unlock();
170} 542}
171 543
172/** 544/**
@@ -184,10 +556,13 @@ bool pm_check_wakeup_events(void)
184 556
185 spin_lock_irqsave(&events_lock, flags); 557 spin_lock_irqsave(&events_lock, flags);
186 if (events_check_enabled) { 558 if (events_check_enabled) {
187 ret = (event_count == saved_event_count) && !events_in_progress; 559 ret = ((unsigned int)atomic_read(&event_count) == saved_count)
560 && !atomic_read(&events_in_progress);
188 events_check_enabled = ret; 561 events_check_enabled = ret;
189 } 562 }
190 spin_unlock_irqrestore(&events_lock, flags); 563 spin_unlock_irqrestore(&events_lock, flags);
564 if (!ret)
565 pm_wakeup_update_hit_counts();
191 return ret; 566 return ret;
192} 567}
193 568
@@ -202,24 +577,20 @@ bool pm_check_wakeup_events(void)
202 * drop down to zero has been interrupted by a signal (and the current number 577 * drop down to zero has been interrupted by a signal (and the current number
203 * of wakeup events being processed is still nonzero). Otherwise return true. 578 * of wakeup events being processed is still nonzero). Otherwise return true.
204 */ 579 */
205bool pm_get_wakeup_count(unsigned long *count) 580bool pm_get_wakeup_count(unsigned int *count)
206{ 581{
207 bool ret; 582 bool ret;
208 583
209 spin_lock_irq(&events_lock);
210 if (capable(CAP_SYS_ADMIN)) 584 if (capable(CAP_SYS_ADMIN))
211 events_check_enabled = false; 585 events_check_enabled = false;
212 586
213 while (events_in_progress && !signal_pending(current)) { 587 while (atomic_read(&events_in_progress) && !signal_pending(current)) {
214 spin_unlock_irq(&events_lock); 588 pm_wakeup_update_hit_counts();
215 589 schedule_timeout_interruptible(msecs_to_jiffies(TIMEOUT));
216 schedule_timeout_interruptible(msecs_to_jiffies(100));
217
218 spin_lock_irq(&events_lock);
219 } 590 }
220 *count = event_count; 591
221 ret = !events_in_progress; 592 ret = !atomic_read(&events_in_progress);
222 spin_unlock_irq(&events_lock); 593 *count = atomic_read(&event_count);
223 return ret; 594 return ret;
224} 595}
225 596
@@ -232,16 +603,102 @@ bool pm_get_wakeup_count(unsigned long *count)
232 * old number of registered wakeup events to be used by pm_check_wakeup_events() 603 * old number of registered wakeup events to be used by pm_check_wakeup_events()
233 * and return true. Otherwise return false. 604 * and return true. Otherwise return false.
234 */ 605 */
235bool pm_save_wakeup_count(unsigned long count) 606bool pm_save_wakeup_count(unsigned int count)
236{ 607{
237 bool ret = false; 608 bool ret = false;
238 609
239 spin_lock_irq(&events_lock); 610 spin_lock_irq(&events_lock);
240 if (count == event_count && !events_in_progress) { 611 if (count == (unsigned int)atomic_read(&event_count)
241 saved_event_count = count; 612 && !atomic_read(&events_in_progress)) {
613 saved_count = count;
242 events_check_enabled = true; 614 events_check_enabled = true;
243 ret = true; 615 ret = true;
244 } 616 }
245 spin_unlock_irq(&events_lock); 617 spin_unlock_irq(&events_lock);
618 if (!ret)
619 pm_wakeup_update_hit_counts();
620 return ret;
621}
622
623static struct dentry *wakeup_sources_stats_dentry;
624
625/**
626 * print_wakeup_source_stats - Print wakeup source statistics information.
627 * @m: seq_file to print the statistics into.
628 * @ws: Wakeup source object to print the statistics for.
629 */
630static int print_wakeup_source_stats(struct seq_file *m,
631 struct wakeup_source *ws)
632{
633 unsigned long flags;
634 ktime_t total_time;
635 ktime_t max_time;
636 unsigned long active_count;
637 ktime_t active_time;
638 int ret;
639
640 spin_lock_irqsave(&ws->lock, flags);
641
642 total_time = ws->total_time;
643 max_time = ws->max_time;
644 active_count = ws->active_count;
645 if (ws->active) {
646 active_time = ktime_sub(ktime_get(), ws->last_time);
647 total_time = ktime_add(total_time, active_time);
648 if (active_time.tv64 > max_time.tv64)
649 max_time = active_time;
650 } else {
651 active_time = ktime_set(0, 0);
652 }
653
654 ret = seq_printf(m, "%-12s\t%lu\t\t%lu\t\t%lu\t\t"
655 "%lld\t\t%lld\t\t%lld\t\t%lld\n",
656 ws->name, active_count, ws->event_count, ws->hit_count,
657 ktime_to_ms(active_time), ktime_to_ms(total_time),
658 ktime_to_ms(max_time), ktime_to_ms(ws->last_time));
659
660 spin_unlock_irqrestore(&ws->lock, flags);
661
246 return ret; 662 return ret;
247} 663}
664
665/**
666 * wakeup_sources_stats_show - Print wakeup sources statistics information.
667 * @m: seq_file to print the statistics into.
668 */
669static int wakeup_sources_stats_show(struct seq_file *m, void *unused)
670{
671 struct wakeup_source *ws;
672
673 seq_puts(m, "name\t\tactive_count\tevent_count\thit_count\t"
674 "active_since\ttotal_time\tmax_time\tlast_change\n");
675
676 rcu_read_lock();
677 list_for_each_entry_rcu(ws, &wakeup_sources, entry)
678 print_wakeup_source_stats(m, ws);
679 rcu_read_unlock();
680
681 return 0;
682}
683
684static int wakeup_sources_stats_open(struct inode *inode, struct file *file)
685{
686 return single_open(file, wakeup_sources_stats_show, NULL);
687}
688
689static const struct file_operations wakeup_sources_stats_fops = {
690 .owner = THIS_MODULE,
691 .open = wakeup_sources_stats_open,
692 .read = seq_read,
693 .llseek = seq_lseek,
694 .release = single_release,
695};
696
697static int __init wakeup_sources_debugfs_init(void)
698{
699 wakeup_sources_stats_dentry = debugfs_create_file("wakeup_sources",
700 S_IRUGO, NULL, NULL, &wakeup_sources_stats_fops);
701 return 0;
702}
703
704postcore_initcall(wakeup_sources_debugfs_init);
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index 9fc630ce1ddb..f6f37a05a0c3 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -45,7 +45,8 @@ static ssize_t show_##name(struct sys_device *dev, \
45 return sprintf(buf, "%d\n", topology_##name(cpu)); \ 45 return sprintf(buf, "%d\n", topology_##name(cpu)); \
46} 46}
47 47
48#if defined(topology_thread_cpumask) || defined(topology_core_cpumask) 48#if defined(topology_thread_cpumask) || defined(topology_core_cpumask) || \
49 defined(topology_book_cpumask)
49static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf) 50static ssize_t show_cpumap(int type, const struct cpumask *mask, char *buf)
50{ 51{
51 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf; 52 ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
@@ -114,6 +115,14 @@ define_siblings_show_func(core_cpumask);
114define_one_ro_named(core_siblings, show_core_cpumask); 115define_one_ro_named(core_siblings, show_core_cpumask);
115define_one_ro_named(core_siblings_list, show_core_cpumask_list); 116define_one_ro_named(core_siblings_list, show_core_cpumask_list);
116 117
118#ifdef CONFIG_SCHED_BOOK
119define_id_show_func(book_id);
120define_one_ro(book_id);
121define_siblings_show_func(book_cpumask);
122define_one_ro_named(book_siblings, show_book_cpumask);
123define_one_ro_named(book_siblings_list, show_book_cpumask_list);
124#endif
125
117static struct attribute *default_attrs[] = { 126static struct attribute *default_attrs[] = {
118 &attr_physical_package_id.attr, 127 &attr_physical_package_id.attr,
119 &attr_core_id.attr, 128 &attr_core_id.attr,
@@ -121,6 +130,11 @@ static struct attribute *default_attrs[] = {
121 &attr_thread_siblings_list.attr, 130 &attr_thread_siblings_list.attr,
122 &attr_core_siblings.attr, 131 &attr_core_siblings.attr,
123 &attr_core_siblings_list.attr, 132 &attr_core_siblings_list.attr,
133#ifdef CONFIG_SCHED_BOOK
134 &attr_book_id.attr,
135 &attr_book_siblings.attr,
136 &attr_book_siblings_list.attr,
137#endif
124 NULL 138 NULL
125}; 139};
126 140
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index dfcb33e8d405..1f286ab461d3 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -36,7 +36,7 @@
36#include <linux/ioport.h> 36#include <linux/ioport.h>
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/reboot.h> 42#include <linux/reboot.h>
@@ -54,6 +54,7 @@
54#define DAC960_GAM_MINOR 252 54#define DAC960_GAM_MINOR 252
55 55
56 56
57static DEFINE_MUTEX(DAC960_mutex);
57static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers]; 58static DAC960_Controller_T *DAC960_Controllers[DAC960_MaxControllers];
58static int DAC960_ControllerCount; 59static int DAC960_ControllerCount;
59static struct proc_dir_entry *DAC960_ProcDirectoryEntry; 60static struct proc_dir_entry *DAC960_ProcDirectoryEntry;
@@ -81,7 +82,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
81 int drive_nr = (long)disk->private_data; 82 int drive_nr = (long)disk->private_data;
82 int ret = -ENXIO; 83 int ret = -ENXIO;
83 84
84 lock_kernel(); 85 mutex_lock(&DAC960_mutex);
85 if (p->FirmwareType == DAC960_V1_Controller) { 86 if (p->FirmwareType == DAC960_V1_Controller) {
86 if (p->V1.LogicalDriveInformation[drive_nr]. 87 if (p->V1.LogicalDriveInformation[drive_nr].
87 LogicalDriveState == DAC960_V1_LogicalDrive_Offline) 88 LogicalDriveState == DAC960_V1_LogicalDrive_Offline)
@@ -99,7 +100,7 @@ static int DAC960_open(struct block_device *bdev, fmode_t mode)
99 goto out; 100 goto out;
100 ret = 0; 101 ret = 0;
101out: 102out:
102 unlock_kernel(); 103 mutex_unlock(&DAC960_mutex);
103 return ret; 104 return ret;
104} 105}
105 106
@@ -6625,7 +6626,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
6625 long ErrorCode = 0; 6626 long ErrorCode = 0;
6626 if (!capable(CAP_SYS_ADMIN)) return -EACCES; 6627 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
6627 6628
6628 lock_kernel(); 6629 mutex_lock(&DAC960_mutex);
6629 switch (Request) 6630 switch (Request)
6630 { 6631 {
6631 case DAC960_IOCTL_GET_CONTROLLER_COUNT: 6632 case DAC960_IOCTL_GET_CONTROLLER_COUNT:
@@ -7056,7 +7057,7 @@ static long DAC960_gam_ioctl(struct file *file, unsigned int Request,
7056 default: 7057 default:
7057 ErrorCode = -ENOTTY; 7058 ErrorCode = -ENOTTY;
7058 } 7059 }
7059 unlock_kernel(); 7060 mutex_unlock(&DAC960_mutex);
7060 return ErrorCode; 7061 return ErrorCode;
7061} 7062}
7062 7063
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index de277689da61..4b9359a6f6ca 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -488,4 +488,21 @@ config BLK_DEV_HD
488 488
489 If unsure, say N. 489 If unsure, say N.
490 490
491config BLK_DEV_RBD
492 tristate "Rados block device (RBD)"
493 depends on INET && EXPERIMENTAL && BLOCK
494 select CEPH_LIB
495 select LIBCRC32C
496 select CRYPTO_AES
497 select CRYPTO
498 default n
499 help
500 Say Y here if you want include the Rados block device, which stripes
501 a block device over objects stored in the Ceph distributed object
502 store.
503
504 More information at http://ceph.newdream.net/.
505
506 If unsure, say N.
507
491endif # BLK_DEV 508endif # BLK_DEV
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index aff5ac925c34..d7f463d6312d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -37,5 +37,6 @@ obj-$(CONFIG_BLK_DEV_HD) += hd.o
37 37
38obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o 38obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
39obj-$(CONFIG_BLK_DEV_DRBD) += drbd/ 39obj-$(CONFIG_BLK_DEV_DRBD) += drbd/
40obj-$(CONFIG_BLK_DEV_RBD) += rbd.o
40 41
41swim_mod-objs := swim.o swim_asm.o 42swim_mod-objs := swim.o swim_asm.o
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 76f114f0bba3..4b852c962266 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -60,7 +60,7 @@
60#include <linux/hdreg.h> 60#include <linux/hdreg.h>
61#include <linux/delay.h> 61#include <linux/delay.h>
62#include <linux/init.h> 62#include <linux/init.h>
63#include <linux/smp_lock.h> 63#include <linux/mutex.h>
64#include <linux/amifdreg.h> 64#include <linux/amifdreg.h>
65#include <linux/amifd.h> 65#include <linux/amifd.h>
66#include <linux/buffer_head.h> 66#include <linux/buffer_head.h>
@@ -109,6 +109,7 @@
109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */ 109#define FD_HD_3 0x55555555 /* high-density 3.5" (1760K) drive */
110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */ 110#define FD_DD_5 0xaaaaaaaa /* double-density 5.25" (440K) drive */
111 111
112static DEFINE_MUTEX(amiflop_mutex);
112static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */ 113static unsigned long int fd_def_df0 = FD_DD_3; /* default for df0 if it doesn't identify */
113 114
114module_param(fd_def_df0, ulong, 0); 115module_param(fd_def_df0, ulong, 0);
@@ -1506,9 +1507,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1506{ 1507{
1507 int ret; 1508 int ret;
1508 1509
1509 lock_kernel(); 1510 mutex_lock(&amiflop_mutex);
1510 ret = fd_locked_ioctl(bdev, mode, cmd, param); 1511 ret = fd_locked_ioctl(bdev, mode, cmd, param);
1511 unlock_kernel(); 1512 mutex_unlock(&amiflop_mutex);
1512 1513
1513 return ret; 1514 return ret;
1514} 1515}
@@ -1555,11 +1556,11 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1555 int old_dev; 1556 int old_dev;
1556 unsigned long flags; 1557 unsigned long flags;
1557 1558
1558 lock_kernel(); 1559 mutex_lock(&amiflop_mutex);
1559 old_dev = fd_device[drive]; 1560 old_dev = fd_device[drive];
1560 1561
1561 if (fd_ref[drive] && old_dev != system) { 1562 if (fd_ref[drive] && old_dev != system) {
1562 unlock_kernel(); 1563 mutex_unlock(&amiflop_mutex);
1563 return -EBUSY; 1564 return -EBUSY;
1564 } 1565 }
1565 1566
@@ -1575,7 +1576,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1575 rel_fdc(); 1576 rel_fdc();
1576 1577
1577 if (wrprot) { 1578 if (wrprot) {
1578 unlock_kernel(); 1579 mutex_unlock(&amiflop_mutex);
1579 return -EROFS; 1580 return -EROFS;
1580 } 1581 }
1581 } 1582 }
@@ -1594,7 +1595,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
1594 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive, 1595 printk(KERN_INFO "fd%d: accessing %s-disk with %s-layout\n",drive,
1595 unit[drive].type->name, data_types[system].name); 1596 unit[drive].type->name, data_types[system].name);
1596 1597
1597 unlock_kernel(); 1598 mutex_unlock(&amiflop_mutex);
1598 return 0; 1599 return 0;
1599} 1600}
1600 1601
@@ -1603,7 +1604,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1603 struct amiga_floppy_struct *p = disk->private_data; 1604 struct amiga_floppy_struct *p = disk->private_data;
1604 int drive = p - unit; 1605 int drive = p - unit;
1605 1606
1606 lock_kernel(); 1607 mutex_lock(&amiflop_mutex);
1607 if (unit[drive].dirty == 1) { 1608 if (unit[drive].dirty == 1) {
1608 del_timer (flush_track_timer + drive); 1609 del_timer (flush_track_timer + drive);
1609 non_int_flush_track (drive); 1610 non_int_flush_track (drive);
@@ -1617,7 +1618,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
1617/* the mod_use counter is handled this way */ 1618/* the mod_use counter is handled this way */
1618 floppy_off (drive | 0x40000000); 1619 floppy_off (drive | 0x40000000);
1619#endif 1620#endif
1620 unlock_kernel(); 1621 mutex_unlock(&amiflop_mutex);
1621 return 0; 1622 return 0;
1622} 1623}
1623 1624
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index a946929735a5..f21c237a9e5e 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -12,9 +12,10 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/genhd.h> 13#include <linux/genhd.h>
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/smp_lock.h> 15#include <linux/mutex.h>
16#include "aoe.h" 16#include "aoe.h"
17 17
18static DEFINE_MUTEX(aoeblk_mutex);
18static struct kmem_cache *buf_pool_cache; 19static struct kmem_cache *buf_pool_cache;
19 20
20static ssize_t aoedisk_show_state(struct device *dev, 21static ssize_t aoedisk_show_state(struct device *dev,
@@ -125,16 +126,16 @@ aoeblk_open(struct block_device *bdev, fmode_t mode)
125 struct aoedev *d = bdev->bd_disk->private_data; 126 struct aoedev *d = bdev->bd_disk->private_data;
126 ulong flags; 127 ulong flags;
127 128
128 lock_kernel(); 129 mutex_lock(&aoeblk_mutex);
129 spin_lock_irqsave(&d->lock, flags); 130 spin_lock_irqsave(&d->lock, flags);
130 if (d->flags & DEVFL_UP) { 131 if (d->flags & DEVFL_UP) {
131 d->nopen++; 132 d->nopen++;
132 spin_unlock_irqrestore(&d->lock, flags); 133 spin_unlock_irqrestore(&d->lock, flags);
133 unlock_kernel(); 134 mutex_unlock(&aoeblk_mutex);
134 return 0; 135 return 0;
135 } 136 }
136 spin_unlock_irqrestore(&d->lock, flags); 137 spin_unlock_irqrestore(&d->lock, flags);
137 unlock_kernel(); 138 mutex_unlock(&aoeblk_mutex);
138 return -ENODEV; 139 return -ENODEV;
139} 140}
140 141
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 32b484ba21bd..146296ca4965 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -9,7 +9,7 @@
9#include <linux/completion.h> 9#include <linux/completion.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/smp_lock.h> 12#include <linux/mutex.h>
13#include <linux/skbuff.h> 13#include <linux/skbuff.h>
14#include "aoe.h" 14#include "aoe.h"
15 15
@@ -37,6 +37,7 @@ struct ErrMsg {
37 char *msg; 37 char *msg;
38}; 38};
39 39
40static DEFINE_MUTEX(aoechr_mutex);
40static struct ErrMsg emsgs[NMSG]; 41static struct ErrMsg emsgs[NMSG];
41static int emsgs_head_idx, emsgs_tail_idx; 42static int emsgs_head_idx, emsgs_tail_idx;
42static struct completion emsgs_comp; 43static struct completion emsgs_comp;
@@ -183,16 +184,16 @@ aoechr_open(struct inode *inode, struct file *filp)
183{ 184{
184 int n, i; 185 int n, i;
185 186
186 lock_kernel(); 187 mutex_lock(&aoechr_mutex);
187 n = iminor(inode); 188 n = iminor(inode);
188 filp->private_data = (void *) (unsigned long) n; 189 filp->private_data = (void *) (unsigned long) n;
189 190
190 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 191 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
191 if (chardevs[i].minor == n) { 192 if (chardevs[i].minor == n) {
192 unlock_kernel(); 193 mutex_unlock(&aoechr_mutex);
193 return 0; 194 return 0;
194 } 195 }
195 unlock_kernel(); 196 mutex_unlock(&aoechr_mutex);
196 return -EINVAL; 197 return -EINVAL;
197} 198}
198 199
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index aceb96476524..8c021bb7a991 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -67,7 +67,7 @@
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/blkdev.h> 69#include <linux/blkdev.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71 71
72#include <asm/atafd.h> 72#include <asm/atafd.h>
73#include <asm/atafdreg.h> 73#include <asm/atafdreg.h>
@@ -79,6 +79,7 @@
79 79
80#undef DEBUG 80#undef DEBUG
81 81
82static DEFINE_MUTEX(ataflop_mutex);
82static struct request_queue *floppy_queue; 83static struct request_queue *floppy_queue;
83static struct request *fd_request; 84static struct request *fd_request;
84 85
@@ -1671,9 +1672,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1671{ 1672{
1672 int ret; 1673 int ret;
1673 1674
1674 lock_kernel(); 1675 mutex_lock(&ataflop_mutex);
1675 ret = fd_locked_ioctl(bdev, mode, cmd, arg); 1676 ret = fd_locked_ioctl(bdev, mode, cmd, arg);
1676 unlock_kernel(); 1677 mutex_unlock(&ataflop_mutex);
1677 1678
1678 return ret; 1679 return ret;
1679} 1680}
@@ -1854,9 +1855,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1854{ 1855{
1855 int ret; 1856 int ret;
1856 1857
1857 lock_kernel(); 1858 mutex_lock(&ataflop_mutex);
1858 ret = floppy_open(bdev, mode); 1859 ret = floppy_open(bdev, mode);
1859 unlock_kernel(); 1860 mutex_unlock(&ataflop_mutex);
1860 1861
1861 return ret; 1862 return ret;
1862} 1863}
@@ -1864,14 +1865,14 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
1864static int floppy_release(struct gendisk *disk, fmode_t mode) 1865static int floppy_release(struct gendisk *disk, fmode_t mode)
1865{ 1866{
1866 struct atari_floppy_struct *p = disk->private_data; 1867 struct atari_floppy_struct *p = disk->private_data;
1867 lock_kernel(); 1868 mutex_lock(&ataflop_mutex);
1868 if (p->ref < 0) 1869 if (p->ref < 0)
1869 p->ref = 0; 1870 p->ref = 0;
1870 else if (!p->ref--) { 1871 else if (!p->ref--) {
1871 printk(KERN_ERR "floppy_release with fd_ref == 0"); 1872 printk(KERN_ERR "floppy_release with fd_ref == 0");
1872 p->ref = 0; 1873 p->ref = 0;
1873 } 1874 }
1874 unlock_kernel(); 1875 mutex_unlock(&ataflop_mutex);
1875 return 0; 1876 return 0;
1876} 1877}
1877 1878
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 1c7f63792ff8..82bfd5bb4a97 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -15,7 +15,7 @@
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/smp_lock.h> 18#include <linux/mutex.h>
19#include <linux/radix-tree.h> 19#include <linux/radix-tree.h>
20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */ 20#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
21#include <linux/slab.h> 21#include <linux/slab.h>
@@ -55,6 +55,7 @@ struct brd_device {
55/* 55/*
56 * Look up and return a brd's page for a given sector. 56 * Look up and return a brd's page for a given sector.
57 */ 57 */
58static DEFINE_MUTEX(brd_mutex);
58static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector) 59static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
59{ 60{
60 pgoff_t idx; 61 pgoff_t idx;
@@ -402,7 +403,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
402 * ram device BLKFLSBUF has special semantics, we want to actually 403 * ram device BLKFLSBUF has special semantics, we want to actually
403 * release and destroy the ramdisk data. 404 * release and destroy the ramdisk data.
404 */ 405 */
405 lock_kernel(); 406 mutex_lock(&brd_mutex);
406 mutex_lock(&bdev->bd_mutex); 407 mutex_lock(&bdev->bd_mutex);
407 error = -EBUSY; 408 error = -EBUSY;
408 if (bdev->bd_openers <= 1) { 409 if (bdev->bd_openers <= 1) {
@@ -419,7 +420,7 @@ static int brd_ioctl(struct block_device *bdev, fmode_t mode,
419 error = 0; 420 error = 0;
420 } 421 }
421 mutex_unlock(&bdev->bd_mutex); 422 mutex_unlock(&bdev->bd_mutex);
422 unlock_kernel(); 423 mutex_unlock(&brd_mutex);
423 424
424 return error; 425 return error;
425} 426}
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 6124c2fd2d33..c484c96e22a6 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -26,7 +26,6 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/major.h> 30#include <linux/major.h>
32#include <linux/fs.h> 31#include <linux/fs.h>
@@ -66,6 +65,7 @@ MODULE_SUPPORTED_DEVICE("HP Smart Array Controllers");
66MODULE_VERSION("3.6.26"); 65MODULE_VERSION("3.6.26");
67MODULE_LICENSE("GPL"); 66MODULE_LICENSE("GPL");
68 67
68static DEFINE_MUTEX(cciss_mutex);
69static int cciss_allow_hpsa; 69static int cciss_allow_hpsa;
70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR); 70module_param(cciss_allow_hpsa, int, S_IRUGO|S_IWUSR);
71MODULE_PARM_DESC(cciss_allow_hpsa, 71MODULE_PARM_DESC(cciss_allow_hpsa,
@@ -1059,9 +1059,9 @@ static int cciss_unlocked_open(struct block_device *bdev, fmode_t mode)
1059{ 1059{
1060 int ret; 1060 int ret;
1061 1061
1062 lock_kernel(); 1062 mutex_lock(&cciss_mutex);
1063 ret = cciss_open(bdev, mode); 1063 ret = cciss_open(bdev, mode);
1064 unlock_kernel(); 1064 mutex_unlock(&cciss_mutex);
1065 1065
1066 return ret; 1066 return ret;
1067} 1067}
@@ -1074,13 +1074,13 @@ static int cciss_release(struct gendisk *disk, fmode_t mode)
1074 ctlr_info_t *h; 1074 ctlr_info_t *h;
1075 drive_info_struct *drv; 1075 drive_info_struct *drv;
1076 1076
1077 lock_kernel(); 1077 mutex_lock(&cciss_mutex);
1078 h = get_host(disk); 1078 h = get_host(disk);
1079 drv = get_drv(disk); 1079 drv = get_drv(disk);
1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name); 1080 dev_dbg(&h->pdev->dev, "cciss_release %s\n", disk->disk_name);
1081 drv->usage_count--; 1081 drv->usage_count--;
1082 h->usage_count--; 1082 h->usage_count--;
1083 unlock_kernel(); 1083 mutex_unlock(&cciss_mutex);
1084 return 0; 1084 return 0;
1085} 1085}
1086 1086
@@ -1088,9 +1088,9 @@ static int do_ioctl(struct block_device *bdev, fmode_t mode,
1088 unsigned cmd, unsigned long arg) 1088 unsigned cmd, unsigned long arg)
1089{ 1089{
1090 int ret; 1090 int ret;
1091 lock_kernel(); 1091 mutex_lock(&cciss_mutex);
1092 ret = cciss_ioctl(bdev, mode, cmd, arg); 1092 ret = cciss_ioctl(bdev, mode, cmd, arg);
1093 unlock_kernel(); 1093 mutex_unlock(&cciss_mutex);
1094 return ret; 1094 return ret;
1095} 1095}
1096 1096
@@ -4792,7 +4792,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
4792clean4: 4792clean4:
4793 kfree(h->cmd_pool_bits); 4793 kfree(h->cmd_pool_bits);
4794 /* Free up sg elements */ 4794 /* Free up sg elements */
4795 for (k = 0; k < h->nr_cmds; k++) 4795 for (k-- ; k >= 0; k--)
4796 kfree(h->scatter_list[k]); 4796 kfree(h->scatter_list[k]);
4797 kfree(h->scatter_list); 4797 kfree(h->scatter_list);
4798 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); 4798 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index d53b0291c44b..946dad4caef3 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -35,7 +35,7 @@
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/hdreg.h> 37#include <linux/hdreg.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/blkdev.h> 40#include <linux/blkdev.h>
41#include <linux/genhd.h> 41#include <linux/genhd.h>
@@ -68,6 +68,7 @@ MODULE_LICENSE("GPL");
68 68
69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */ 69#define CPQARRAY_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */
70 70
71static DEFINE_MUTEX(cpqarray_mutex);
71static int nr_ctlr; 72static int nr_ctlr;
72static ctlr_info_t *hba[MAX_CTLR]; 73static ctlr_info_t *hba[MAX_CTLR];
73 74
@@ -845,9 +846,9 @@ static int ida_unlocked_open(struct block_device *bdev, fmode_t mode)
845{ 846{
846 int ret; 847 int ret;
847 848
848 lock_kernel(); 849 mutex_lock(&cpqarray_mutex);
849 ret = ida_open(bdev, mode); 850 ret = ida_open(bdev, mode);
850 unlock_kernel(); 851 mutex_unlock(&cpqarray_mutex);
851 852
852 return ret; 853 return ret;
853} 854}
@@ -859,10 +860,10 @@ static int ida_release(struct gendisk *disk, fmode_t mode)
859{ 860{
860 ctlr_info_t *host; 861 ctlr_info_t *host;
861 862
862 lock_kernel(); 863 mutex_lock(&cpqarray_mutex);
863 host = get_host(disk); 864 host = get_host(disk);
864 host->usage_count--; 865 host->usage_count--;
865 unlock_kernel(); 866 mutex_unlock(&cpqarray_mutex);
866 867
867 return 0; 868 return 0;
868} 869}
@@ -1217,9 +1218,9 @@ static int ida_ioctl(struct block_device *bdev, fmode_t mode,
1217{ 1218{
1218 int ret; 1219 int ret;
1219 1220
1220 lock_kernel(); 1221 mutex_lock(&cpqarray_mutex);
1221 ret = ida_locked_ioctl(bdev, mode, cmd, param); 1222 ret = ida_locked_ioctl(bdev, mode, cmd, param);
1222 unlock_kernel(); 1223 mutex_unlock(&cpqarray_mutex);
1223 1224
1224 return ret; 1225 return ret;
1225} 1226}
diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
index fa650dd85b90..e4b56119866e 100644
--- a/drivers/block/drbd/drbd_main.c
+++ b/drivers/block/drbd/drbd_main.c
@@ -32,7 +32,7 @@
32#include <asm/types.h> 32#include <asm/types.h>
33#include <net/sock.h> 33#include <net/sock.h>
34#include <linux/ctype.h> 34#include <linux/ctype.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/fs.h> 36#include <linux/fs.h>
37#include <linux/file.h> 37#include <linux/file.h>
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
@@ -64,6 +64,7 @@ struct after_state_chg_work {
64 struct completion *done; 64 struct completion *done;
65}; 65};
66 66
67static DEFINE_MUTEX(drbd_main_mutex);
67int drbdd_init(struct drbd_thread *); 68int drbdd_init(struct drbd_thread *);
68int drbd_worker(struct drbd_thread *); 69int drbd_worker(struct drbd_thread *);
69int drbd_asender(struct drbd_thread *); 70int drbd_asender(struct drbd_thread *);
@@ -2536,7 +2537,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2536 unsigned long flags; 2537 unsigned long flags;
2537 int rv = 0; 2538 int rv = 0;
2538 2539
2539 lock_kernel(); 2540 mutex_lock(&drbd_main_mutex);
2540 spin_lock_irqsave(&mdev->req_lock, flags); 2541 spin_lock_irqsave(&mdev->req_lock, flags);
2541 /* to have a stable mdev->state.role 2542 /* to have a stable mdev->state.role
2542 * and no race with updating open_cnt */ 2543 * and no race with updating open_cnt */
@@ -2551,7 +2552,7 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2551 if (!rv) 2552 if (!rv)
2552 mdev->open_cnt++; 2553 mdev->open_cnt++;
2553 spin_unlock_irqrestore(&mdev->req_lock, flags); 2554 spin_unlock_irqrestore(&mdev->req_lock, flags);
2554 unlock_kernel(); 2555 mutex_unlock(&drbd_main_mutex);
2555 2556
2556 return rv; 2557 return rv;
2557} 2558}
@@ -2559,9 +2560,9 @@ static int drbd_open(struct block_device *bdev, fmode_t mode)
2559static int drbd_release(struct gendisk *gd, fmode_t mode) 2560static int drbd_release(struct gendisk *gd, fmode_t mode)
2560{ 2561{
2561 struct drbd_conf *mdev = gd->private_data; 2562 struct drbd_conf *mdev = gd->private_data;
2562 lock_kernel(); 2563 mutex_lock(&drbd_main_mutex);
2563 mdev->open_cnt--; 2564 mdev->open_cnt--;
2564 unlock_kernel(); 2565 mutex_unlock(&drbd_main_mutex);
2565 return 0; 2566 return 0;
2566} 2567}
2567 2568
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cf04c1b234ed..3b57459bb745 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -178,7 +178,6 @@ static int print_unex = 1;
178#include <linux/slab.h> 178#include <linux/slab.h>
179#include <linux/mm.h> 179#include <linux/mm.h>
180#include <linux/bio.h> 180#include <linux/bio.h>
181#include <linux/smp_lock.h>
182#include <linux/string.h> 181#include <linux/string.h>
183#include <linux/jiffies.h> 182#include <linux/jiffies.h>
184#include <linux/fcntl.h> 183#include <linux/fcntl.h>
@@ -199,6 +198,7 @@ static int print_unex = 1;
199 * It's been recommended that take about 1/4 of the default speed 198 * It's been recommended that take about 1/4 of the default speed
200 * in some more extreme cases. 199 * in some more extreme cases.
201 */ 200 */
201static DEFINE_MUTEX(floppy_mutex);
202static int slow_floppy; 202static int slow_floppy;
203 203
204#include <asm/dma.h> 204#include <asm/dma.h>
@@ -3553,9 +3553,9 @@ static int fd_ioctl(struct block_device *bdev, fmode_t mode,
3553{ 3553{
3554 int ret; 3554 int ret;
3555 3555
3556 lock_kernel(); 3556 mutex_lock(&floppy_mutex);
3557 ret = fd_locked_ioctl(bdev, mode, cmd, param); 3557 ret = fd_locked_ioctl(bdev, mode, cmd, param);
3558 unlock_kernel(); 3558 mutex_unlock(&floppy_mutex);
3559 3559
3560 return ret; 3560 return ret;
3561} 3561}
@@ -3616,7 +3616,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3616{ 3616{
3617 int drive = (long)disk->private_data; 3617 int drive = (long)disk->private_data;
3618 3618
3619 lock_kernel(); 3619 mutex_lock(&floppy_mutex);
3620 mutex_lock(&open_lock); 3620 mutex_lock(&open_lock);
3621 if (UDRS->fd_ref < 0) 3621 if (UDRS->fd_ref < 0)
3622 UDRS->fd_ref = 0; 3622 UDRS->fd_ref = 0;
@@ -3627,7 +3627,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
3627 if (!UDRS->fd_ref) 3627 if (!UDRS->fd_ref)
3628 opened_bdev[drive] = NULL; 3628 opened_bdev[drive] = NULL;
3629 mutex_unlock(&open_lock); 3629 mutex_unlock(&open_lock);
3630 unlock_kernel(); 3630 mutex_unlock(&floppy_mutex);
3631 3631
3632 return 0; 3632 return 0;
3633} 3633}
@@ -3645,7 +3645,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3645 int res = -EBUSY; 3645 int res = -EBUSY;
3646 char *tmp; 3646 char *tmp;
3647 3647
3648 lock_kernel(); 3648 mutex_lock(&floppy_mutex);
3649 mutex_lock(&open_lock); 3649 mutex_lock(&open_lock);
3650 old_dev = UDRS->fd_device; 3650 old_dev = UDRS->fd_device;
3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev) 3651 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
@@ -3722,7 +3722,7 @@ static int floppy_open(struct block_device *bdev, fmode_t mode)
3722 goto out; 3722 goto out;
3723 } 3723 }
3724 mutex_unlock(&open_lock); 3724 mutex_unlock(&open_lock);
3725 unlock_kernel(); 3725 mutex_unlock(&floppy_mutex);
3726 return 0; 3726 return 0;
3727out: 3727out:
3728 if (UDRS->fd_ref < 0) 3728 if (UDRS->fd_ref < 0)
@@ -3733,7 +3733,7 @@ out:
3733 opened_bdev[drive] = NULL; 3733 opened_bdev[drive] = NULL;
3734out2: 3734out2:
3735 mutex_unlock(&open_lock); 3735 mutex_unlock(&open_lock);
3736 unlock_kernel(); 3736 mutex_unlock(&floppy_mutex);
3737 return res; 3737 return res;
3738} 3738}
3739 3739
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 91797bbbe702..a10c8c9b6b78 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -67,7 +67,7 @@
67#include <linux/compat.h> 67#include <linux/compat.h>
68#include <linux/suspend.h> 68#include <linux/suspend.h>
69#include <linux/freezer.h> 69#include <linux/freezer.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71#include <linux/writeback.h> 71#include <linux/writeback.h>
72#include <linux/buffer_head.h> /* for invalidate_bdev() */ 72#include <linux/buffer_head.h> /* for invalidate_bdev() */
73#include <linux/completion.h> 73#include <linux/completion.h>
@@ -77,6 +77,7 @@
77 77
78#include <asm/uaccess.h> 78#include <asm/uaccess.h>
79 79
80static DEFINE_MUTEX(loop_mutex);
80static LIST_HEAD(loop_devices); 81static LIST_HEAD(loop_devices);
81static DEFINE_MUTEX(loop_devices_mutex); 82static DEFINE_MUTEX(loop_devices_mutex);
82 83
@@ -1409,11 +1410,11 @@ static int lo_open(struct block_device *bdev, fmode_t mode)
1409{ 1410{
1410 struct loop_device *lo = bdev->bd_disk->private_data; 1411 struct loop_device *lo = bdev->bd_disk->private_data;
1411 1412
1412 lock_kernel(); 1413 mutex_lock(&loop_mutex);
1413 mutex_lock(&lo->lo_ctl_mutex); 1414 mutex_lock(&lo->lo_ctl_mutex);
1414 lo->lo_refcnt++; 1415 lo->lo_refcnt++;
1415 mutex_unlock(&lo->lo_ctl_mutex); 1416 mutex_unlock(&lo->lo_ctl_mutex);
1416 unlock_kernel(); 1417 mutex_unlock(&loop_mutex);
1417 1418
1418 return 0; 1419 return 0;
1419} 1420}
@@ -1423,7 +1424,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1423 struct loop_device *lo = disk->private_data; 1424 struct loop_device *lo = disk->private_data;
1424 int err; 1425 int err;
1425 1426
1426 lock_kernel(); 1427 mutex_lock(&loop_mutex);
1427 mutex_lock(&lo->lo_ctl_mutex); 1428 mutex_lock(&lo->lo_ctl_mutex);
1428 1429
1429 if (--lo->lo_refcnt) 1430 if (--lo->lo_refcnt)
@@ -1448,7 +1449,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1448out: 1449out:
1449 mutex_unlock(&lo->lo_ctl_mutex); 1450 mutex_unlock(&lo->lo_ctl_mutex);
1450out_unlocked: 1451out_unlocked:
1451 lock_kernel(); 1452 mutex_unlock(&loop_mutex);
1452 return 0; 1453 return 0;
1453} 1454}
1454 1455
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0daa422aa281..a32fb41246f8 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -24,7 +24,7 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/file.h> 25#include <linux/file.h>
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28#include <linux/compiler.h> 28#include <linux/compiler.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
@@ -53,6 +53,7 @@
53#define DBG_BLKDEV 0x0100 53#define DBG_BLKDEV 0x0100
54#define DBG_RX 0x0200 54#define DBG_RX 0x0200
55#define DBG_TX 0x0400 55#define DBG_TX 0x0400
56static DEFINE_MUTEX(nbd_mutex);
56static unsigned int debugflags; 57static unsigned int debugflags;
57#endif /* NDEBUG */ 58#endif /* NDEBUG */
58 59
@@ -717,11 +718,11 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
717 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", 718 dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n",
718 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); 719 lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg);
719 720
720 lock_kernel(); 721 mutex_lock(&nbd_mutex);
721 mutex_lock(&lo->tx_lock); 722 mutex_lock(&lo->tx_lock);
722 error = __nbd_ioctl(bdev, lo, cmd, arg); 723 error = __nbd_ioctl(bdev, lo, cmd, arg);
723 mutex_unlock(&lo->tx_lock); 724 mutex_unlock(&lo->tx_lock);
724 unlock_kernel(); 725 mutex_unlock(&nbd_mutex);
725 726
726 return error; 727 return error;
727} 728}
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index 76f8565e1e8d..62cec6afd7ad 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -138,9 +138,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
138#include <linux/cdrom.h> 138#include <linux/cdrom.h>
139#include <linux/spinlock.h> 139#include <linux/spinlock.h>
140#include <linux/blkdev.h> 140#include <linux/blkdev.h>
141#include <linux/smp_lock.h> 141#include <linux/mutex.h>
142#include <asm/uaccess.h> 142#include <asm/uaccess.h>
143 143
144static DEFINE_MUTEX(pcd_mutex);
144static DEFINE_SPINLOCK(pcd_lock); 145static DEFINE_SPINLOCK(pcd_lock);
145 146
146module_param(verbose, bool, 0644); 147module_param(verbose, bool, 0644);
@@ -227,9 +228,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
227 struct pcd_unit *cd = bdev->bd_disk->private_data; 228 struct pcd_unit *cd = bdev->bd_disk->private_data;
228 int ret; 229 int ret;
229 230
230 lock_kernel(); 231 mutex_lock(&pcd_mutex);
231 ret = cdrom_open(&cd->info, bdev, mode); 232 ret = cdrom_open(&cd->info, bdev, mode);
232 unlock_kernel(); 233 mutex_unlock(&pcd_mutex);
233 234
234 return ret; 235 return ret;
235} 236}
@@ -237,9 +238,9 @@ static int pcd_block_open(struct block_device *bdev, fmode_t mode)
237static int pcd_block_release(struct gendisk *disk, fmode_t mode) 238static int pcd_block_release(struct gendisk *disk, fmode_t mode)
238{ 239{
239 struct pcd_unit *cd = disk->private_data; 240 struct pcd_unit *cd = disk->private_data;
240 lock_kernel(); 241 mutex_lock(&pcd_mutex);
241 cdrom_release(&cd->info, mode); 242 cdrom_release(&cd->info, mode);
242 unlock_kernel(); 243 mutex_unlock(&pcd_mutex);
243 return 0; 244 return 0;
244} 245}
245 246
@@ -249,9 +250,9 @@ static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
249 struct pcd_unit *cd = bdev->bd_disk->private_data; 250 struct pcd_unit *cd = bdev->bd_disk->private_data;
250 int ret; 251 int ret;
251 252
252 lock_kernel(); 253 mutex_lock(&pcd_mutex);
253 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg); 254 ret = cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
254 unlock_kernel(); 255 mutex_unlock(&pcd_mutex);
255 256
256 return ret; 257 return ret;
257} 258}
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 985f0d4f1d1e..c0ee1558b9bb 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -153,10 +153,11 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_GEO, D_SBY, D_DLY, D_SLV};
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/kernel.h> 155#include <linux/kernel.h>
156#include <linux/smp_lock.h> 156#include <linux/mutex.h>
157#include <asm/uaccess.h> 157#include <asm/uaccess.h>
158#include <linux/workqueue.h> 158#include <linux/workqueue.h>
159 159
160static DEFINE_MUTEX(pd_mutex);
160static DEFINE_SPINLOCK(pd_lock); 161static DEFINE_SPINLOCK(pd_lock);
161 162
162module_param(verbose, bool, 0); 163module_param(verbose, bool, 0);
@@ -736,14 +737,14 @@ static int pd_open(struct block_device *bdev, fmode_t mode)
736{ 737{
737 struct pd_unit *disk = bdev->bd_disk->private_data; 738 struct pd_unit *disk = bdev->bd_disk->private_data;
738 739
739 lock_kernel(); 740 mutex_lock(&pd_mutex);
740 disk->access++; 741 disk->access++;
741 742
742 if (disk->removable) { 743 if (disk->removable) {
743 pd_special_command(disk, pd_media_check); 744 pd_special_command(disk, pd_media_check);
744 pd_special_command(disk, pd_door_lock); 745 pd_special_command(disk, pd_door_lock);
745 } 746 }
746 unlock_kernel(); 747 mutex_unlock(&pd_mutex);
747 return 0; 748 return 0;
748} 749}
749 750
@@ -771,10 +772,10 @@ static int pd_ioctl(struct block_device *bdev, fmode_t mode,
771 772
772 switch (cmd) { 773 switch (cmd) {
773 case CDROMEJECT: 774 case CDROMEJECT:
774 lock_kernel(); 775 mutex_lock(&pd_mutex);
775 if (disk->access == 1) 776 if (disk->access == 1)
776 pd_special_command(disk, pd_eject); 777 pd_special_command(disk, pd_eject);
777 unlock_kernel(); 778 mutex_unlock(&pd_mutex);
778 return 0; 779 return 0;
779 default: 780 default:
780 return -EINVAL; 781 return -EINVAL;
@@ -785,10 +786,10 @@ static int pd_release(struct gendisk *p, fmode_t mode)
785{ 786{
786 struct pd_unit *disk = p->private_data; 787 struct pd_unit *disk = p->private_data;
787 788
788 lock_kernel(); 789 mutex_lock(&pd_mutex);
789 if (!--disk->access && disk->removable) 790 if (!--disk->access && disk->removable)
790 pd_special_command(disk, pd_door_unlock); 791 pd_special_command(disk, pd_door_unlock);
791 unlock_kernel(); 792 mutex_unlock(&pd_mutex);
792 793
793 return 0; 794 return 0;
794} 795}
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index 4457b494882a..635f25dd9e10 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -152,9 +152,10 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_LUN, D_DLY};
152#include <linux/spinlock.h> 152#include <linux/spinlock.h>
153#include <linux/blkdev.h> 153#include <linux/blkdev.h>
154#include <linux/blkpg.h> 154#include <linux/blkpg.h>
155#include <linux/smp_lock.h> 155#include <linux/mutex.h>
156#include <asm/uaccess.h> 156#include <asm/uaccess.h>
157 157
158static DEFINE_MUTEX(pf_mutex);
158static DEFINE_SPINLOCK(pf_spin_lock); 159static DEFINE_SPINLOCK(pf_spin_lock);
159 160
160module_param(verbose, bool, 0644); 161module_param(verbose, bool, 0644);
@@ -302,7 +303,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
302 struct pf_unit *pf = bdev->bd_disk->private_data; 303 struct pf_unit *pf = bdev->bd_disk->private_data;
303 int ret; 304 int ret;
304 305
305 lock_kernel(); 306 mutex_lock(&pf_mutex);
306 pf_identify(pf); 307 pf_identify(pf);
307 308
308 ret = -ENODEV; 309 ret = -ENODEV;
@@ -318,7 +319,7 @@ static int pf_open(struct block_device *bdev, fmode_t mode)
318 if (pf->removable) 319 if (pf->removable)
319 pf_lock(pf, 1); 320 pf_lock(pf, 1);
320out: 321out:
321 unlock_kernel(); 322 mutex_unlock(&pf_mutex);
322 return ret; 323 return ret;
323} 324}
324 325
@@ -349,9 +350,9 @@ static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, u
349 350
350 if (pf->access != 1) 351 if (pf->access != 1)
351 return -EBUSY; 352 return -EBUSY;
352 lock_kernel(); 353 mutex_lock(&pf_mutex);
353 pf_eject(pf); 354 pf_eject(pf);
354 unlock_kernel(); 355 mutex_unlock(&pf_mutex);
355 356
356 return 0; 357 return 0;
357} 358}
@@ -360,9 +361,9 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
360{ 361{
361 struct pf_unit *pf = disk->private_data; 362 struct pf_unit *pf = disk->private_data;
362 363
363 lock_kernel(); 364 mutex_lock(&pf_mutex);
364 if (pf->access <= 0) { 365 if (pf->access <= 0) {
365 unlock_kernel(); 366 mutex_unlock(&pf_mutex);
366 return -EINVAL; 367 return -EINVAL;
367 } 368 }
368 369
@@ -371,7 +372,7 @@ static int pf_release(struct gendisk *disk, fmode_t mode)
371 if (!pf->access && pf->removable) 372 if (!pf->access && pf->removable)
372 pf_lock(pf, 0); 373 pf_lock(pf, 0);
373 374
374 unlock_kernel(); 375 mutex_unlock(&pf_mutex);
375 return 0; 376 return 0;
376 377
377} 378}
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index aa27cd84f633..6b9a2000d56a 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -162,7 +162,7 @@ enum {D_PRT, D_PRO, D_UNI, D_MOD, D_SLV, D_DLY};
162#include <linux/pg.h> 162#include <linux/pg.h>
163#include <linux/device.h> 163#include <linux/device.h>
164#include <linux/sched.h> /* current, TASK_* */ 164#include <linux/sched.h> /* current, TASK_* */
165#include <linux/smp_lock.h> 165#include <linux/mutex.h>
166#include <linux/jiffies.h> 166#include <linux/jiffies.h>
167 167
168#include <asm/uaccess.h> 168#include <asm/uaccess.h>
@@ -193,6 +193,7 @@ module_param_array(drive3, int, NULL, 0);
193 193
194#define ATAPI_IDENTIFY 0x12 194#define ATAPI_IDENTIFY 0x12
195 195
196static DEFINE_MUTEX(pg_mutex);
196static int pg_open(struct inode *inode, struct file *file); 197static int pg_open(struct inode *inode, struct file *file);
197static int pg_release(struct inode *inode, struct file *file); 198static int pg_release(struct inode *inode, struct file *file);
198static ssize_t pg_read(struct file *filp, char __user *buf, 199static ssize_t pg_read(struct file *filp, char __user *buf,
@@ -519,7 +520,7 @@ static int pg_open(struct inode *inode, struct file *file)
519 struct pg *dev = &devices[unit]; 520 struct pg *dev = &devices[unit];
520 int ret = 0; 521 int ret = 0;
521 522
522 lock_kernel(); 523 mutex_lock(&pg_mutex);
523 if ((unit >= PG_UNITS) || (!dev->present)) { 524 if ((unit >= PG_UNITS) || (!dev->present)) {
524 ret = -ENODEV; 525 ret = -ENODEV;
525 goto out; 526 goto out;
@@ -548,7 +549,7 @@ static int pg_open(struct inode *inode, struct file *file)
548 file->private_data = dev; 549 file->private_data = dev;
549 550
550out: 551out:
551 unlock_kernel(); 552 mutex_unlock(&pg_mutex);
552 return ret; 553 return ret;
553} 554}
554 555
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index c372c32e0db3..7179f79d7468 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -146,7 +146,7 @@ static int (*drives[4])[6] = {&drive0, &drive1, &drive2, &drive3};
146#include <linux/mtio.h> 146#include <linux/mtio.h>
147#include <linux/device.h> 147#include <linux/device.h>
148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */ 148#include <linux/sched.h> /* current, TASK_*, schedule_timeout() */
149#include <linux/smp_lock.h> 149#include <linux/mutex.h>
150 150
151#include <asm/uaccess.h> 151#include <asm/uaccess.h>
152 152
@@ -189,6 +189,7 @@ module_param_array(drive3, int, NULL, 0);
189#define ATAPI_MODE_SENSE 0x1a 189#define ATAPI_MODE_SENSE 0x1a
190#define ATAPI_LOG_SENSE 0x4d 190#define ATAPI_LOG_SENSE 0x4d
191 191
192static DEFINE_MUTEX(pt_mutex);
192static int pt_open(struct inode *inode, struct file *file); 193static int pt_open(struct inode *inode, struct file *file);
193static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 194static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
194static int pt_release(struct inode *inode, struct file *file); 195static int pt_release(struct inode *inode, struct file *file);
@@ -651,9 +652,9 @@ static int pt_open(struct inode *inode, struct file *file)
651 struct pt_unit *tape = pt + unit; 652 struct pt_unit *tape = pt + unit;
652 int err; 653 int err;
653 654
654 lock_kernel(); 655 mutex_lock(&pt_mutex);
655 if (unit >= PT_UNITS || (!tape->present)) { 656 if (unit >= PT_UNITS || (!tape->present)) {
656 unlock_kernel(); 657 mutex_unlock(&pt_mutex);
657 return -ENODEV; 658 return -ENODEV;
658 } 659 }
659 660
@@ -682,12 +683,12 @@ static int pt_open(struct inode *inode, struct file *file)
682 } 683 }
683 684
684 file->private_data = tape; 685 file->private_data = tape;
685 unlock_kernel(); 686 mutex_unlock(&pt_mutex);
686 return 0; 687 return 0;
687 688
688out: 689out:
689 atomic_inc(&tape->available); 690 atomic_inc(&tape->available);
690 unlock_kernel(); 691 mutex_unlock(&pt_mutex);
691 return err; 692 return err;
692} 693}
693 694
@@ -705,15 +706,15 @@ static long pt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
705 switch (mtop.mt_op) { 706 switch (mtop.mt_op) {
706 707
707 case MTREW: 708 case MTREW:
708 lock_kernel(); 709 mutex_lock(&pt_mutex);
709 pt_rewind(tape); 710 pt_rewind(tape);
710 unlock_kernel(); 711 mutex_unlock(&pt_mutex);
711 return 0; 712 return 0;
712 713
713 case MTWEOF: 714 case MTWEOF:
714 lock_kernel(); 715 mutex_lock(&pt_mutex);
715 pt_write_fm(tape); 716 pt_write_fm(tape);
716 unlock_kernel(); 717 mutex_unlock(&pt_mutex);
717 return 0; 718 return 0;
718 719
719 default: 720 default:
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 6a4642dd8283..ef58fccadad3 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -57,7 +57,6 @@
57#include <linux/seq_file.h> 57#include <linux/seq_file.h>
58#include <linux/miscdevice.h> 58#include <linux/miscdevice.h>
59#include <linux/freezer.h> 59#include <linux/freezer.h>
60#include <linux/smp_lock.h>
61#include <linux/mutex.h> 60#include <linux/mutex.h>
62#include <linux/slab.h> 61#include <linux/slab.h>
63#include <scsi/scsi_cmnd.h> 62#include <scsi/scsi_cmnd.h>
@@ -86,6 +85,7 @@
86 85
87#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1)) 86#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
88 87
88static DEFINE_MUTEX(pktcdvd_mutex);
89static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 89static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
90static struct proc_dir_entry *pkt_proc; 90static struct proc_dir_entry *pkt_proc;
91static int pktdev_major; 91static int pktdev_major;
@@ -2369,7 +2369,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2369 pkt_shrink_pktlist(pd); 2369 pkt_shrink_pktlist(pd);
2370} 2370}
2371 2371
2372static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor) 2372static struct pktcdvd_device *pkt_find_dev_from_minor(unsigned int dev_minor)
2373{ 2373{
2374 if (dev_minor >= MAX_WRITERS) 2374 if (dev_minor >= MAX_WRITERS)
2375 return NULL; 2375 return NULL;
@@ -2383,7 +2383,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2383 2383
2384 VPRINTK(DRIVER_NAME": entering open\n"); 2384 VPRINTK(DRIVER_NAME": entering open\n");
2385 2385
2386 lock_kernel(); 2386 mutex_lock(&pktcdvd_mutex);
2387 mutex_lock(&ctl_mutex); 2387 mutex_lock(&ctl_mutex);
2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev)); 2388 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
2389 if (!pd) { 2389 if (!pd) {
@@ -2411,7 +2411,7 @@ static int pkt_open(struct block_device *bdev, fmode_t mode)
2411 } 2411 }
2412 2412
2413 mutex_unlock(&ctl_mutex); 2413 mutex_unlock(&ctl_mutex);
2414 unlock_kernel(); 2414 mutex_unlock(&pktcdvd_mutex);
2415 return 0; 2415 return 0;
2416 2416
2417out_dec: 2417out_dec:
@@ -2419,7 +2419,7 @@ out_dec:
2419out: 2419out:
2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret); 2420 VPRINTK(DRIVER_NAME": failed open (%d)\n", ret);
2421 mutex_unlock(&ctl_mutex); 2421 mutex_unlock(&ctl_mutex);
2422 unlock_kernel(); 2422 mutex_unlock(&pktcdvd_mutex);
2423 return ret; 2423 return ret;
2424} 2424}
2425 2425
@@ -2428,7 +2428,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2428 struct pktcdvd_device *pd = disk->private_data; 2428 struct pktcdvd_device *pd = disk->private_data;
2429 int ret = 0; 2429 int ret = 0;
2430 2430
2431 lock_kernel(); 2431 mutex_lock(&pktcdvd_mutex);
2432 mutex_lock(&ctl_mutex); 2432 mutex_lock(&ctl_mutex);
2433 pd->refcnt--; 2433 pd->refcnt--;
2434 BUG_ON(pd->refcnt < 0); 2434 BUG_ON(pd->refcnt < 0);
@@ -2437,7 +2437,7 @@ static int pkt_close(struct gendisk *disk, fmode_t mode)
2437 pkt_release_dev(pd, flush); 2437 pkt_release_dev(pd, flush);
2438 } 2438 }
2439 mutex_unlock(&ctl_mutex); 2439 mutex_unlock(&ctl_mutex);
2440 unlock_kernel(); 2440 mutex_unlock(&pktcdvd_mutex);
2441 return ret; 2441 return ret;
2442} 2442}
2443 2443
@@ -2773,7 +2773,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, 2773 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd,
2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); 2774 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
2775 2775
2776 lock_kernel(); 2776 mutex_lock(&pktcdvd_mutex);
2777 switch (cmd) { 2777 switch (cmd) {
2778 case CDROMEJECT: 2778 case CDROMEJECT:
2779 /* 2779 /*
@@ -2798,7 +2798,7 @@ static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd); 2798 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
2799 ret = -ENOTTY; 2799 ret = -ENOTTY;
2800 } 2800 }
2801 unlock_kernel(); 2801 mutex_unlock(&pktcdvd_mutex);
2802 2802
2803 return ret; 2803 return ret;
2804} 2804}
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index e9da874d0419..03688c2da319 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -113,7 +113,7 @@ static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
113 memcpy(buf, dev->bounce_buf+offset, size); 113 memcpy(buf, dev->bounce_buf+offset, size);
114 offset += size; 114 offset += size;
115 flush_kernel_dcache_page(bvec->bv_page); 115 flush_kernel_dcache_page(bvec->bv_page);
116 bvec_kunmap_irq(bvec, &flags); 116 bvec_kunmap_irq(buf, &flags);
117 i++; 117 i++;
118 } 118 }
119} 119}
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
new file mode 100644
index 000000000000..6ec9d53806c5
--- /dev/null
+++ b/drivers/block/rbd.c
@@ -0,0 +1,1841 @@
1/*
2 rbd.c -- Export ceph rados objects as a Linux block device
3
4
5 based on drivers/block/osdblk.c:
6
7 Copyright 2009 Red Hat, Inc.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22
23
24 Instructions for use
25 --------------------
26
27 1) Map a Linux block device to an existing rbd image.
28
29 Usage: <mon ip addr> <options> <pool name> <rbd image name> [snap name]
30
31 $ echo "192.168.0.1 name=admin rbd foo" > /sys/class/rbd/add
32
33 The snapshot name can be "-" or omitted to map the image read/write.
34
35 2) List all active blkdev<->object mappings.
36
37 In this example, we have performed step #1 twice, creating two blkdevs,
38 mapped to two separate rados objects in the rados rbd pool
39
40 $ cat /sys/class/rbd/list
41 #id major client_name pool name snap KB
42 0 254 client4143 rbd foo - 1024000
43
44 The columns, in order, are:
45 - blkdev unique id
46 - blkdev assigned major
47 - rados client id
48 - rados pool name
49 - rados block device name
50 - mapped snapshot ("-" if none)
51 - device size in KB
52
53
54 3) Create a snapshot.
55
56 Usage: <blkdev id> <snapname>
57
58 $ echo "0 mysnap" > /sys/class/rbd/snap_create
59
60
61 4) Listing a snapshot.
62
63 $ cat /sys/class/rbd/snaps_list
64 #id snap KB
65 0 - 1024000 (*)
66 0 foo 1024000
67
68 The columns, in order, are:
69 - blkdev unique id
70 - snapshot name, '-' means none (active read/write version)
71 - size of device at time of snapshot
72 - the (*) indicates this is the active version
73
74 5) Rollback to snapshot.
75
76 Usage: <blkdev id> <snapname>
77
78 $ echo "0 mysnap" > /sys/class/rbd/snap_rollback
79
80
81 6) Mapping an image using snapshot.
82
83 A snapshot mapping is read-only. This is being done by passing
84 snap=<snapname> to the options when adding a device.
85
86 $ echo "192.168.0.1 name=admin,snap=mysnap rbd foo" > /sys/class/rbd/add
87
88
89 7) Remove an active blkdev<->rbd image mapping.
90
91 In this example, we remove the mapping with blkdev unique id 1.
92
93 $ echo 1 > /sys/class/rbd/remove
94
95
96 NOTE: The actual creation and deletion of rados objects is outside the scope
97 of this driver.
98
99 */
100
101#include <linux/ceph/libceph.h>
102#include <linux/ceph/osd_client.h>
103#include <linux/ceph/mon_client.h>
104#include <linux/ceph/decode.h>
105
106#include <linux/kernel.h>
107#include <linux/device.h>
108#include <linux/module.h>
109#include <linux/fs.h>
110#include <linux/blkdev.h>
111
112#include "rbd_types.h"
113
114#define DRV_NAME "rbd"
115#define DRV_NAME_LONG "rbd (rados block device)"
116
117#define RBD_MINORS_PER_MAJOR 256 /* max minors per blkdev */
118
119#define RBD_MAX_MD_NAME_LEN (96 + sizeof(RBD_SUFFIX))
120#define RBD_MAX_POOL_NAME_LEN 64
121#define RBD_MAX_SNAP_NAME_LEN 32
122#define RBD_MAX_OPT_LEN 1024
123
124#define RBD_SNAP_HEAD_NAME "-"
125
126#define DEV_NAME_LEN 32
127
128/*
129 * block device image metadata (in-memory version)
130 */
131struct rbd_image_header {
132 u64 image_size;
133 char block_name[32];
134 __u8 obj_order;
135 __u8 crypt_type;
136 __u8 comp_type;
137 struct rw_semaphore snap_rwsem;
138 struct ceph_snap_context *snapc;
139 size_t snap_names_len;
140 u64 snap_seq;
141 u32 total_snaps;
142
143 char *snap_names;
144 u64 *snap_sizes;
145};
146
147/*
148 * an instance of the client. multiple devices may share a client.
149 */
150struct rbd_client {
151 struct ceph_client *client;
152 struct kref kref;
153 struct list_head node;
154};
155
156/*
157 * a single io request
158 */
159struct rbd_request {
160 struct request *rq; /* blk layer request */
161 struct bio *bio; /* cloned bio */
162 struct page **pages; /* list of used pages */
163 u64 len;
164};
165
166/*
167 * a single device
168 */
169struct rbd_device {
170 int id; /* blkdev unique id */
171
172 int major; /* blkdev assigned major */
173 struct gendisk *disk; /* blkdev's gendisk and rq */
174 struct request_queue *q;
175
176 struct ceph_client *client;
177 struct rbd_client *rbd_client;
178
179 char name[DEV_NAME_LEN]; /* blkdev name, e.g. rbd3 */
180
181 spinlock_t lock; /* queue lock */
182
183 struct rbd_image_header header;
184 char obj[RBD_MAX_OBJ_NAME_LEN]; /* rbd image name */
185 int obj_len;
186 char obj_md_name[RBD_MAX_MD_NAME_LEN]; /* hdr nm. */
187 char pool_name[RBD_MAX_POOL_NAME_LEN];
188 int poolid;
189
190 char snap_name[RBD_MAX_SNAP_NAME_LEN];
191 u32 cur_snap; /* index+1 of current snapshot within snap context
192 0 - for the head */
193 int read_only;
194
195 struct list_head node;
196};
197
198static spinlock_t node_lock; /* protects client get/put */
199
200static struct class *class_rbd; /* /sys/class/rbd */
201static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
202static LIST_HEAD(rbd_dev_list); /* devices */
203static LIST_HEAD(rbd_client_list); /* clients */
204
205
206static int rbd_open(struct block_device *bdev, fmode_t mode)
207{
208 struct gendisk *disk = bdev->bd_disk;
209 struct rbd_device *rbd_dev = disk->private_data;
210
211 set_device_ro(bdev, rbd_dev->read_only);
212
213 if ((mode & FMODE_WRITE) && rbd_dev->read_only)
214 return -EROFS;
215
216 return 0;
217}
218
219static const struct block_device_operations rbd_bd_ops = {
220 .owner = THIS_MODULE,
221 .open = rbd_open,
222};
223
224/*
225 * Initialize an rbd client instance.
226 * We own *opt.
227 */
228static struct rbd_client *rbd_client_create(struct ceph_options *opt)
229{
230 struct rbd_client *rbdc;
231 int ret = -ENOMEM;
232
233 dout("rbd_client_create\n");
234 rbdc = kmalloc(sizeof(struct rbd_client), GFP_KERNEL);
235 if (!rbdc)
236 goto out_opt;
237
238 kref_init(&rbdc->kref);
239 INIT_LIST_HEAD(&rbdc->node);
240
241 rbdc->client = ceph_create_client(opt, rbdc);
242 if (IS_ERR(rbdc->client))
243 goto out_rbdc;
244 opt = NULL; /* Now rbdc->client is responsible for opt */
245
246 ret = ceph_open_session(rbdc->client);
247 if (ret < 0)
248 goto out_err;
249
250 spin_lock(&node_lock);
251 list_add_tail(&rbdc->node, &rbd_client_list);
252 spin_unlock(&node_lock);
253
254 dout("rbd_client_create created %p\n", rbdc);
255 return rbdc;
256
257out_err:
258 ceph_destroy_client(rbdc->client);
259out_rbdc:
260 kfree(rbdc);
261out_opt:
262 if (opt)
263 ceph_destroy_options(opt);
264 return ERR_PTR(ret);
265}
266
267/*
268 * Find a ceph client with specific addr and configuration.
269 */
270static struct rbd_client *__rbd_client_find(struct ceph_options *opt)
271{
272 struct rbd_client *client_node;
273
274 if (opt->flags & CEPH_OPT_NOSHARE)
275 return NULL;
276
277 list_for_each_entry(client_node, &rbd_client_list, node)
278 if (ceph_compare_options(opt, client_node->client) == 0)
279 return client_node;
280 return NULL;
281}
282
283/*
284 * Get a ceph client with specific addr and configuration, if one does
285 * not exist create it.
286 */
287static int rbd_get_client(struct rbd_device *rbd_dev, const char *mon_addr,
288 char *options)
289{
290 struct rbd_client *rbdc;
291 struct ceph_options *opt;
292 int ret;
293
294 ret = ceph_parse_options(&opt, options, mon_addr,
295 mon_addr + strlen(mon_addr), NULL, NULL);
296 if (ret < 0)
297 return ret;
298
299 spin_lock(&node_lock);
300 rbdc = __rbd_client_find(opt);
301 if (rbdc) {
302 ceph_destroy_options(opt);
303
304 /* using an existing client */
305 kref_get(&rbdc->kref);
306 rbd_dev->rbd_client = rbdc;
307 rbd_dev->client = rbdc->client;
308 spin_unlock(&node_lock);
309 return 0;
310 }
311 spin_unlock(&node_lock);
312
313 rbdc = rbd_client_create(opt);
314 if (IS_ERR(rbdc))
315 return PTR_ERR(rbdc);
316
317 rbd_dev->rbd_client = rbdc;
318 rbd_dev->client = rbdc->client;
319 return 0;
320}
321
322/*
323 * Destroy ceph client
324 */
325static void rbd_client_release(struct kref *kref)
326{
327 struct rbd_client *rbdc = container_of(kref, struct rbd_client, kref);
328
329 dout("rbd_release_client %p\n", rbdc);
330 spin_lock(&node_lock);
331 list_del(&rbdc->node);
332 spin_unlock(&node_lock);
333
334 ceph_destroy_client(rbdc->client);
335 kfree(rbdc);
336}
337
338/*
339 * Drop reference to ceph client node. If it's not referenced anymore, release
340 * it.
341 */
342static void rbd_put_client(struct rbd_device *rbd_dev)
343{
344 kref_put(&rbd_dev->rbd_client->kref, rbd_client_release);
345 rbd_dev->rbd_client = NULL;
346 rbd_dev->client = NULL;
347}
348
349
350/*
351 * Create a new header structure, translate header format from the on-disk
352 * header.
353 */
354static int rbd_header_from_disk(struct rbd_image_header *header,
355 struct rbd_image_header_ondisk *ondisk,
356 int allocated_snaps,
357 gfp_t gfp_flags)
358{
359 int i;
360 u32 snap_count = le32_to_cpu(ondisk->snap_count);
361 int ret = -ENOMEM;
362
363 init_rwsem(&header->snap_rwsem);
364
365 header->snap_names_len = le64_to_cpu(ondisk->snap_names_len);
366 header->snapc = kmalloc(sizeof(struct ceph_snap_context) +
367 snap_count *
368 sizeof(struct rbd_image_snap_ondisk),
369 gfp_flags);
370 if (!header->snapc)
371 return -ENOMEM;
372 if (snap_count) {
373 header->snap_names = kmalloc(header->snap_names_len,
374 GFP_KERNEL);
375 if (!header->snap_names)
376 goto err_snapc;
377 header->snap_sizes = kmalloc(snap_count * sizeof(u64),
378 GFP_KERNEL);
379 if (!header->snap_sizes)
380 goto err_names;
381 } else {
382 header->snap_names = NULL;
383 header->snap_sizes = NULL;
384 }
385 memcpy(header->block_name, ondisk->block_name,
386 sizeof(ondisk->block_name));
387
388 header->image_size = le64_to_cpu(ondisk->image_size);
389 header->obj_order = ondisk->options.order;
390 header->crypt_type = ondisk->options.crypt_type;
391 header->comp_type = ondisk->options.comp_type;
392
393 atomic_set(&header->snapc->nref, 1);
394 header->snap_seq = le64_to_cpu(ondisk->snap_seq);
395 header->snapc->num_snaps = snap_count;
396 header->total_snaps = snap_count;
397
398 if (snap_count &&
399 allocated_snaps == snap_count) {
400 for (i = 0; i < snap_count; i++) {
401 header->snapc->snaps[i] =
402 le64_to_cpu(ondisk->snaps[i].id);
403 header->snap_sizes[i] =
404 le64_to_cpu(ondisk->snaps[i].image_size);
405 }
406
407 /* copy snapshot names */
408 memcpy(header->snap_names, &ondisk->snaps[i],
409 header->snap_names_len);
410 }
411
412 return 0;
413
414err_names:
415 kfree(header->snap_names);
416err_snapc:
417 kfree(header->snapc);
418 return ret;
419}
420
421static int snap_index(struct rbd_image_header *header, int snap_num)
422{
423 return header->total_snaps - snap_num;
424}
425
426static u64 cur_snap_id(struct rbd_device *rbd_dev)
427{
428 struct rbd_image_header *header = &rbd_dev->header;
429
430 if (!rbd_dev->cur_snap)
431 return 0;
432
433 return header->snapc->snaps[snap_index(header, rbd_dev->cur_snap)];
434}
435
436static int snap_by_name(struct rbd_image_header *header, const char *snap_name,
437 u64 *seq, u64 *size)
438{
439 int i;
440 char *p = header->snap_names;
441
442 for (i = 0; i < header->total_snaps; i++, p += strlen(p) + 1) {
443 if (strcmp(snap_name, p) == 0)
444 break;
445 }
446 if (i == header->total_snaps)
447 return -ENOENT;
448 if (seq)
449 *seq = header->snapc->snaps[i];
450
451 if (size)
452 *size = header->snap_sizes[i];
453
454 return i;
455}
456
457static int rbd_header_set_snap(struct rbd_device *dev,
458 const char *snap_name,
459 u64 *size)
460{
461 struct rbd_image_header *header = &dev->header;
462 struct ceph_snap_context *snapc = header->snapc;
463 int ret = -ENOENT;
464
465 down_write(&header->snap_rwsem);
466
467 if (!snap_name ||
468 !*snap_name ||
469 strcmp(snap_name, "-") == 0 ||
470 strcmp(snap_name, RBD_SNAP_HEAD_NAME) == 0) {
471 if (header->total_snaps)
472 snapc->seq = header->snap_seq;
473 else
474 snapc->seq = 0;
475 dev->cur_snap = 0;
476 dev->read_only = 0;
477 if (size)
478 *size = header->image_size;
479 } else {
480 ret = snap_by_name(header, snap_name, &snapc->seq, size);
481 if (ret < 0)
482 goto done;
483
484 dev->cur_snap = header->total_snaps - ret;
485 dev->read_only = 1;
486 }
487
488 ret = 0;
489done:
490 up_write(&header->snap_rwsem);
491 return ret;
492}
493
494static void rbd_header_free(struct rbd_image_header *header)
495{
496 kfree(header->snapc);
497 kfree(header->snap_names);
498 kfree(header->snap_sizes);
499}
500
501/*
502 * get the actual striped segment name, offset and length
503 */
504static u64 rbd_get_segment(struct rbd_image_header *header,
505 const char *block_name,
506 u64 ofs, u64 len,
507 char *seg_name, u64 *segofs)
508{
509 u64 seg = ofs >> header->obj_order;
510
511 if (seg_name)
512 snprintf(seg_name, RBD_MAX_SEG_NAME_LEN,
513 "%s.%012llx", block_name, seg);
514
515 ofs = ofs & ((1 << header->obj_order) - 1);
516 len = min_t(u64, len, (1 << header->obj_order) - ofs);
517
518 if (segofs)
519 *segofs = ofs;
520
521 return len;
522}
523
524/*
525 * bio helpers
526 */
527
528static void bio_chain_put(struct bio *chain)
529{
530 struct bio *tmp;
531
532 while (chain) {
533 tmp = chain;
534 chain = chain->bi_next;
535 bio_put(tmp);
536 }
537}
538
539/*
540 * zeros a bio chain, starting at specific offset
541 */
542static void zero_bio_chain(struct bio *chain, int start_ofs)
543{
544 struct bio_vec *bv;
545 unsigned long flags;
546 void *buf;
547 int i;
548 int pos = 0;
549
550 while (chain) {
551 bio_for_each_segment(bv, chain, i) {
552 if (pos + bv->bv_len > start_ofs) {
553 int remainder = max(start_ofs - pos, 0);
554 buf = bvec_kmap_irq(bv, &flags);
555 memset(buf + remainder, 0,
556 bv->bv_len - remainder);
557 bvec_kunmap_irq(buf, &flags);
558 }
559 pos += bv->bv_len;
560 }
561
562 chain = chain->bi_next;
563 }
564}
565
566/*
567 * bio_chain_clone - clone a chain of bios up to a certain length.
568 * might return a bio_pair that will need to be released.
569 */
570static struct bio *bio_chain_clone(struct bio **old, struct bio **next,
571 struct bio_pair **bp,
572 int len, gfp_t gfpmask)
573{
574 struct bio *tmp, *old_chain = *old, *new_chain = NULL, *tail = NULL;
575 int total = 0;
576
577 if (*bp) {
578 bio_pair_release(*bp);
579 *bp = NULL;
580 }
581
582 while (old_chain && (total < len)) {
583 tmp = bio_kmalloc(gfpmask, old_chain->bi_max_vecs);
584 if (!tmp)
585 goto err_out;
586
587 if (total + old_chain->bi_size > len) {
588 struct bio_pair *bp;
589
590 /*
591 * this split can only happen with a single paged bio,
592 * split_bio will BUG_ON if this is not the case
593 */
594 dout("bio_chain_clone split! total=%d remaining=%d"
595 "bi_size=%d\n",
596 (int)total, (int)len-total,
597 (int)old_chain->bi_size);
598
599 /* split the bio. We'll release it either in the next
600 call, or it will have to be released outside */
601 bp = bio_split(old_chain, (len - total) / 512ULL);
602 if (!bp)
603 goto err_out;
604
605 __bio_clone(tmp, &bp->bio1);
606
607 *next = &bp->bio2;
608 } else {
609 __bio_clone(tmp, old_chain);
610 *next = old_chain->bi_next;
611 }
612
613 tmp->bi_bdev = NULL;
614 gfpmask &= ~__GFP_WAIT;
615 tmp->bi_next = NULL;
616
617 if (!new_chain) {
618 new_chain = tail = tmp;
619 } else {
620 tail->bi_next = tmp;
621 tail = tmp;
622 }
623 old_chain = old_chain->bi_next;
624
625 total += tmp->bi_size;
626 }
627
628 BUG_ON(total < len);
629
630 if (tail)
631 tail->bi_next = NULL;
632
633 *old = old_chain;
634
635 return new_chain;
636
637err_out:
638 dout("bio_chain_clone with err\n");
639 bio_chain_put(new_chain);
640 return NULL;
641}
642
643/*
644 * helpers for osd request op vectors.
645 */
646static int rbd_create_rw_ops(struct ceph_osd_req_op **ops,
647 int num_ops,
648 int opcode,
649 u32 payload_len)
650{
651 *ops = kzalloc(sizeof(struct ceph_osd_req_op) * (num_ops + 1),
652 GFP_NOIO);
653 if (!*ops)
654 return -ENOMEM;
655 (*ops)[0].op = opcode;
656 /*
657 * op extent offset and length will be set later on
658 * in calc_raw_layout()
659 */
660 (*ops)[0].payload_len = payload_len;
661 return 0;
662}
663
664static void rbd_destroy_ops(struct ceph_osd_req_op *ops)
665{
666 kfree(ops);
667}
668
669/*
670 * Send ceph osd request
671 */
672static int rbd_do_request(struct request *rq,
673 struct rbd_device *dev,
674 struct ceph_snap_context *snapc,
675 u64 snapid,
676 const char *obj, u64 ofs, u64 len,
677 struct bio *bio,
678 struct page **pages,
679 int num_pages,
680 int flags,
681 struct ceph_osd_req_op *ops,
682 int num_reply,
683 void (*rbd_cb)(struct ceph_osd_request *req,
684 struct ceph_msg *msg))
685{
686 struct ceph_osd_request *req;
687 struct ceph_file_layout *layout;
688 int ret;
689 u64 bno;
690 struct timespec mtime = CURRENT_TIME;
691 struct rbd_request *req_data;
692 struct ceph_osd_request_head *reqhead;
693 struct rbd_image_header *header = &dev->header;
694
695 ret = -ENOMEM;
696 req_data = kzalloc(sizeof(*req_data), GFP_NOIO);
697 if (!req_data)
698 goto done;
699
700 dout("rbd_do_request len=%lld ofs=%lld\n", len, ofs);
701
702 down_read(&header->snap_rwsem);
703
704 req = ceph_osdc_alloc_request(&dev->client->osdc, flags,
705 snapc,
706 ops,
707 false,
708 GFP_NOIO, pages, bio);
709 if (IS_ERR(req)) {
710 up_read(&header->snap_rwsem);
711 ret = PTR_ERR(req);
712 goto done_pages;
713 }
714
715 req->r_callback = rbd_cb;
716
717 req_data->rq = rq;
718 req_data->bio = bio;
719 req_data->pages = pages;
720 req_data->len = len;
721
722 req->r_priv = req_data;
723
724 reqhead = req->r_request->front.iov_base;
725 reqhead->snapid = cpu_to_le64(CEPH_NOSNAP);
726
727 strncpy(req->r_oid, obj, sizeof(req->r_oid));
728 req->r_oid_len = strlen(req->r_oid);
729
730 layout = &req->r_file_layout;
731 memset(layout, 0, sizeof(*layout));
732 layout->fl_stripe_unit = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
733 layout->fl_stripe_count = cpu_to_le32(1);
734 layout->fl_object_size = cpu_to_le32(1 << RBD_MAX_OBJ_ORDER);
735 layout->fl_pg_preferred = cpu_to_le32(-1);
736 layout->fl_pg_pool = cpu_to_le32(dev->poolid);
737 ceph_calc_raw_layout(&dev->client->osdc, layout, snapid,
738 ofs, &len, &bno, req, ops);
739
740 ceph_osdc_build_request(req, ofs, &len,
741 ops,
742 snapc,
743 &mtime,
744 req->r_oid, req->r_oid_len);
745 up_read(&header->snap_rwsem);
746
747 ret = ceph_osdc_start_request(&dev->client->osdc, req, false);
748 if (ret < 0)
749 goto done_err;
750
751 if (!rbd_cb) {
752 ret = ceph_osdc_wait_request(&dev->client->osdc, req);
753 ceph_osdc_put_request(req);
754 }
755 return ret;
756
757done_err:
758 bio_chain_put(req_data->bio);
759 ceph_osdc_put_request(req);
760done_pages:
761 kfree(req_data);
762done:
763 if (rq)
764 blk_end_request(rq, ret, len);
765 return ret;
766}
767
768/*
769 * Ceph osd op callback
770 */
771static void rbd_req_cb(struct ceph_osd_request *req, struct ceph_msg *msg)
772{
773 struct rbd_request *req_data = req->r_priv;
774 struct ceph_osd_reply_head *replyhead;
775 struct ceph_osd_op *op;
776 __s32 rc;
777 u64 bytes;
778 int read_op;
779
780 /* parse reply */
781 replyhead = msg->front.iov_base;
782 WARN_ON(le32_to_cpu(replyhead->num_ops) == 0);
783 op = (void *)(replyhead + 1);
784 rc = le32_to_cpu(replyhead->result);
785 bytes = le64_to_cpu(op->extent.length);
786 read_op = (le32_to_cpu(op->op) == CEPH_OSD_OP_READ);
787
788 dout("rbd_req_cb bytes=%lld readop=%d rc=%d\n", bytes, read_op, rc);
789
790 if (rc == -ENOENT && read_op) {
791 zero_bio_chain(req_data->bio, 0);
792 rc = 0;
793 } else if (rc == 0 && read_op && bytes < req_data->len) {
794 zero_bio_chain(req_data->bio, bytes);
795 bytes = req_data->len;
796 }
797
798 blk_end_request(req_data->rq, rc, bytes);
799
800 if (req_data->bio)
801 bio_chain_put(req_data->bio);
802
803 ceph_osdc_put_request(req);
804 kfree(req_data);
805}
806
807/*
808 * Do a synchronous ceph osd operation
809 */
810static int rbd_req_sync_op(struct rbd_device *dev,
811 struct ceph_snap_context *snapc,
812 u64 snapid,
813 int opcode,
814 int flags,
815 struct ceph_osd_req_op *orig_ops,
816 int num_reply,
817 const char *obj,
818 u64 ofs, u64 len,
819 char *buf)
820{
821 int ret;
822 struct page **pages;
823 int num_pages;
824 struct ceph_osd_req_op *ops = orig_ops;
825 u32 payload_len;
826
827 num_pages = calc_pages_for(ofs , len);
828 pages = ceph_alloc_page_vector(num_pages, GFP_KERNEL);
829 if (IS_ERR(pages))
830 return PTR_ERR(pages);
831
832 if (!orig_ops) {
833 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? len : 0);
834 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len);
835 if (ret < 0)
836 goto done;
837
838 if ((flags & CEPH_OSD_FLAG_WRITE) && buf) {
839 ret = ceph_copy_to_page_vector(pages, buf, ofs, len);
840 if (ret < 0)
841 goto done_ops;
842 }
843 }
844
845 ret = rbd_do_request(NULL, dev, snapc, snapid,
846 obj, ofs, len, NULL,
847 pages, num_pages,
848 flags,
849 ops,
850 2,
851 NULL);
852 if (ret < 0)
853 goto done_ops;
854
855 if ((flags & CEPH_OSD_FLAG_READ) && buf)
856 ret = ceph_copy_from_page_vector(pages, buf, ofs, ret);
857
858done_ops:
859 if (!orig_ops)
860 rbd_destroy_ops(ops);
861done:
862 ceph_release_page_vector(pages, num_pages);
863 return ret;
864}
865
866/*
867 * Do an asynchronous ceph osd operation
868 */
869static int rbd_do_op(struct request *rq,
870 struct rbd_device *rbd_dev ,
871 struct ceph_snap_context *snapc,
872 u64 snapid,
873 int opcode, int flags, int num_reply,
874 u64 ofs, u64 len,
875 struct bio *bio)
876{
877 char *seg_name;
878 u64 seg_ofs;
879 u64 seg_len;
880 int ret;
881 struct ceph_osd_req_op *ops;
882 u32 payload_len;
883
884 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO);
885 if (!seg_name)
886 return -ENOMEM;
887
888 seg_len = rbd_get_segment(&rbd_dev->header,
889 rbd_dev->header.block_name,
890 ofs, len,
891 seg_name, &seg_ofs);
892
893 payload_len = (flags & CEPH_OSD_FLAG_WRITE ? seg_len : 0);
894
895 ret = rbd_create_rw_ops(&ops, 1, opcode, payload_len);
896 if (ret < 0)
897 goto done;
898
899 /* we've taken care of segment sizes earlier when we
900 cloned the bios. We should never have a segment
901 truncated at this point */
902 BUG_ON(seg_len < len);
903
904 ret = rbd_do_request(rq, rbd_dev, snapc, snapid,
905 seg_name, seg_ofs, seg_len,
906 bio,
907 NULL, 0,
908 flags,
909 ops,
910 num_reply,
911 rbd_req_cb);
912done:
913 kfree(seg_name);
914 return ret;
915}
916
917/*
918 * Request async osd write
919 */
920static int rbd_req_write(struct request *rq,
921 struct rbd_device *rbd_dev,
922 struct ceph_snap_context *snapc,
923 u64 ofs, u64 len,
924 struct bio *bio)
925{
926 return rbd_do_op(rq, rbd_dev, snapc, CEPH_NOSNAP,
927 CEPH_OSD_OP_WRITE,
928 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
929 2,
930 ofs, len, bio);
931}
932
933/*
934 * Request async osd read
935 */
936static int rbd_req_read(struct request *rq,
937 struct rbd_device *rbd_dev,
938 u64 snapid,
939 u64 ofs, u64 len,
940 struct bio *bio)
941{
942 return rbd_do_op(rq, rbd_dev, NULL,
943 (snapid ? snapid : CEPH_NOSNAP),
944 CEPH_OSD_OP_READ,
945 CEPH_OSD_FLAG_READ,
946 2,
947 ofs, len, bio);
948}
949
950/*
951 * Request sync osd read
952 */
953static int rbd_req_sync_read(struct rbd_device *dev,
954 struct ceph_snap_context *snapc,
955 u64 snapid,
956 const char *obj,
957 u64 ofs, u64 len,
958 char *buf)
959{
960 return rbd_req_sync_op(dev, NULL,
961 (snapid ? snapid : CEPH_NOSNAP),
962 CEPH_OSD_OP_READ,
963 CEPH_OSD_FLAG_READ,
964 NULL,
965 1, obj, ofs, len, buf);
966}
967
968/*
969 * Request sync osd read
970 */
971static int rbd_req_sync_rollback_obj(struct rbd_device *dev,
972 u64 snapid,
973 const char *obj)
974{
975 struct ceph_osd_req_op *ops;
976 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_ROLLBACK, 0);
977 if (ret < 0)
978 return ret;
979
980 ops[0].snap.snapid = snapid;
981
982 ret = rbd_req_sync_op(dev, NULL,
983 CEPH_NOSNAP,
984 0,
985 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
986 ops,
987 1, obj, 0, 0, NULL);
988
989 rbd_destroy_ops(ops);
990
991 if (ret < 0)
992 return ret;
993
994 return ret;
995}
996
997/*
998 * Request sync osd read
999 */
1000static int rbd_req_sync_exec(struct rbd_device *dev,
1001 const char *obj,
1002 const char *cls,
1003 const char *method,
1004 const char *data,
1005 int len)
1006{
1007 struct ceph_osd_req_op *ops;
1008 int cls_len = strlen(cls);
1009 int method_len = strlen(method);
1010 int ret = rbd_create_rw_ops(&ops, 1, CEPH_OSD_OP_CALL,
1011 cls_len + method_len + len);
1012 if (ret < 0)
1013 return ret;
1014
1015 ops[0].cls.class_name = cls;
1016 ops[0].cls.class_len = (__u8)cls_len;
1017 ops[0].cls.method_name = method;
1018 ops[0].cls.method_len = (__u8)method_len;
1019 ops[0].cls.argc = 0;
1020 ops[0].cls.indata = data;
1021 ops[0].cls.indata_len = len;
1022
1023 ret = rbd_req_sync_op(dev, NULL,
1024 CEPH_NOSNAP,
1025 0,
1026 CEPH_OSD_FLAG_WRITE | CEPH_OSD_FLAG_ONDISK,
1027 ops,
1028 1, obj, 0, 0, NULL);
1029
1030 rbd_destroy_ops(ops);
1031
1032 dout("cls_exec returned %d\n", ret);
1033 return ret;
1034}
1035
1036/*
1037 * block device queue callback
1038 */
1039static void rbd_rq_fn(struct request_queue *q)
1040{
1041 struct rbd_device *rbd_dev = q->queuedata;
1042 struct request *rq;
1043 struct bio_pair *bp = NULL;
1044
1045 rq = blk_fetch_request(q);
1046
1047 while (1) {
1048 struct bio *bio;
1049 struct bio *rq_bio, *next_bio = NULL;
1050 bool do_write;
1051 int size, op_size = 0;
1052 u64 ofs;
1053
1054 /* peek at request from block layer */
1055 if (!rq)
1056 break;
1057
1058 dout("fetched request\n");
1059
1060 /* filter out block requests we don't understand */
1061 if ((rq->cmd_type != REQ_TYPE_FS)) {
1062 __blk_end_request_all(rq, 0);
1063 goto next;
1064 }
1065
1066 /* deduce our operation (read, write) */
1067 do_write = (rq_data_dir(rq) == WRITE);
1068
1069 size = blk_rq_bytes(rq);
1070 ofs = blk_rq_pos(rq) * 512ULL;
1071 rq_bio = rq->bio;
1072 if (do_write && rbd_dev->read_only) {
1073 __blk_end_request_all(rq, -EROFS);
1074 goto next;
1075 }
1076
1077 spin_unlock_irq(q->queue_lock);
1078
1079 dout("%s 0x%x bytes at 0x%llx\n",
1080 do_write ? "write" : "read",
1081 size, blk_rq_pos(rq) * 512ULL);
1082
1083 do {
1084 /* a bio clone to be passed down to OSD req */
1085 dout("rq->bio->bi_vcnt=%d\n", rq->bio->bi_vcnt);
1086 op_size = rbd_get_segment(&rbd_dev->header,
1087 rbd_dev->header.block_name,
1088 ofs, size,
1089 NULL, NULL);
1090 bio = bio_chain_clone(&rq_bio, &next_bio, &bp,
1091 op_size, GFP_ATOMIC);
1092 if (!bio) {
1093 spin_lock_irq(q->queue_lock);
1094 __blk_end_request_all(rq, -ENOMEM);
1095 goto next;
1096 }
1097
1098 /* init OSD command: write or read */
1099 if (do_write)
1100 rbd_req_write(rq, rbd_dev,
1101 rbd_dev->header.snapc,
1102 ofs,
1103 op_size, bio);
1104 else
1105 rbd_req_read(rq, rbd_dev,
1106 cur_snap_id(rbd_dev),
1107 ofs,
1108 op_size, bio);
1109
1110 size -= op_size;
1111 ofs += op_size;
1112
1113 rq_bio = next_bio;
1114 } while (size > 0);
1115
1116 if (bp)
1117 bio_pair_release(bp);
1118
1119 spin_lock_irq(q->queue_lock);
1120next:
1121 rq = blk_fetch_request(q);
1122 }
1123}
1124
1125/*
1126 * a queue callback. Makes sure that we don't create a bio that spans across
1127 * multiple osd objects. One exception would be with a single page bios,
1128 * which we handle later at bio_chain_clone
1129 */
1130static int rbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd,
1131 struct bio_vec *bvec)
1132{
1133 struct rbd_device *rbd_dev = q->queuedata;
1134 unsigned int chunk_sectors = 1 << (rbd_dev->header.obj_order - 9);
1135 sector_t sector = bmd->bi_sector + get_start_sect(bmd->bi_bdev);
1136 unsigned int bio_sectors = bmd->bi_size >> 9;
1137 int max;
1138
1139 max = (chunk_sectors - ((sector & (chunk_sectors - 1))
1140 + bio_sectors)) << 9;
1141 if (max < 0)
1142 max = 0; /* bio_add cannot handle a negative return */
1143 if (max <= bvec->bv_len && bio_sectors == 0)
1144 return bvec->bv_len;
1145 return max;
1146}
1147
1148static void rbd_free_disk(struct rbd_device *rbd_dev)
1149{
1150 struct gendisk *disk = rbd_dev->disk;
1151
1152 if (!disk)
1153 return;
1154
1155 rbd_header_free(&rbd_dev->header);
1156
1157 if (disk->flags & GENHD_FL_UP)
1158 del_gendisk(disk);
1159 if (disk->queue)
1160 blk_cleanup_queue(disk->queue);
1161 put_disk(disk);
1162}
1163
1164/*
1165 * reload the ondisk the header
1166 */
1167static int rbd_read_header(struct rbd_device *rbd_dev,
1168 struct rbd_image_header *header)
1169{
1170 ssize_t rc;
1171 struct rbd_image_header_ondisk *dh;
1172 int snap_count = 0;
1173 u64 snap_names_len = 0;
1174
1175 while (1) {
1176 int len = sizeof(*dh) +
1177 snap_count * sizeof(struct rbd_image_snap_ondisk) +
1178 snap_names_len;
1179
1180 rc = -ENOMEM;
1181 dh = kmalloc(len, GFP_KERNEL);
1182 if (!dh)
1183 return -ENOMEM;
1184
1185 rc = rbd_req_sync_read(rbd_dev,
1186 NULL, CEPH_NOSNAP,
1187 rbd_dev->obj_md_name,
1188 0, len,
1189 (char *)dh);
1190 if (rc < 0)
1191 goto out_dh;
1192
1193 rc = rbd_header_from_disk(header, dh, snap_count, GFP_KERNEL);
1194 if (rc < 0)
1195 goto out_dh;
1196
1197 if (snap_count != header->total_snaps) {
1198 snap_count = header->total_snaps;
1199 snap_names_len = header->snap_names_len;
1200 rbd_header_free(header);
1201 kfree(dh);
1202 continue;
1203 }
1204 break;
1205 }
1206
1207out_dh:
1208 kfree(dh);
1209 return rc;
1210}
1211
1212/*
1213 * create a snapshot
1214 */
1215static int rbd_header_add_snap(struct rbd_device *dev,
1216 const char *snap_name,
1217 gfp_t gfp_flags)
1218{
1219 int name_len = strlen(snap_name);
1220 u64 new_snapid;
1221 int ret;
1222 void *data, *data_start, *data_end;
1223
1224 /* we should create a snapshot only if we're pointing at the head */
1225 if (dev->cur_snap)
1226 return -EINVAL;
1227
1228 ret = ceph_monc_create_snapid(&dev->client->monc, dev->poolid,
1229 &new_snapid);
1230 dout("created snapid=%lld\n", new_snapid);
1231 if (ret < 0)
1232 return ret;
1233
1234 data = kmalloc(name_len + 16, gfp_flags);
1235 if (!data)
1236 return -ENOMEM;
1237
1238 data_start = data;
1239 data_end = data + name_len + 16;
1240
1241 ceph_encode_string_safe(&data, data_end, snap_name, name_len, bad);
1242 ceph_encode_64_safe(&data, data_end, new_snapid, bad);
1243
1244 ret = rbd_req_sync_exec(dev, dev->obj_md_name, "rbd", "snap_add",
1245 data_start, data - data_start);
1246
1247 kfree(data_start);
1248
1249 if (ret < 0)
1250 return ret;
1251
1252 dev->header.snapc->seq = new_snapid;
1253
1254 return 0;
1255bad:
1256 return -ERANGE;
1257}
1258
1259/*
1260 * only read the first part of the ondisk header, without the snaps info
1261 */
1262static int rbd_update_snaps(struct rbd_device *rbd_dev)
1263{
1264 int ret;
1265 struct rbd_image_header h;
1266 u64 snap_seq;
1267
1268 ret = rbd_read_header(rbd_dev, &h);
1269 if (ret < 0)
1270 return ret;
1271
1272 down_write(&rbd_dev->header.snap_rwsem);
1273
1274 snap_seq = rbd_dev->header.snapc->seq;
1275
1276 kfree(rbd_dev->header.snapc);
1277 kfree(rbd_dev->header.snap_names);
1278 kfree(rbd_dev->header.snap_sizes);
1279
1280 rbd_dev->header.total_snaps = h.total_snaps;
1281 rbd_dev->header.snapc = h.snapc;
1282 rbd_dev->header.snap_names = h.snap_names;
1283 rbd_dev->header.snap_sizes = h.snap_sizes;
1284 rbd_dev->header.snapc->seq = snap_seq;
1285
1286 up_write(&rbd_dev->header.snap_rwsem);
1287
1288 return 0;
1289}
1290
1291static int rbd_init_disk(struct rbd_device *rbd_dev)
1292{
1293 struct gendisk *disk;
1294 struct request_queue *q;
1295 int rc;
1296 u64 total_size = 0;
1297
1298 /* contact OSD, request size info about the object being mapped */
1299 rc = rbd_read_header(rbd_dev, &rbd_dev->header);
1300 if (rc)
1301 return rc;
1302
1303 rc = rbd_header_set_snap(rbd_dev, rbd_dev->snap_name, &total_size);
1304 if (rc)
1305 return rc;
1306
1307 /* create gendisk info */
1308 rc = -ENOMEM;
1309 disk = alloc_disk(RBD_MINORS_PER_MAJOR);
1310 if (!disk)
1311 goto out;
1312
1313 sprintf(disk->disk_name, DRV_NAME "%d", rbd_dev->id);
1314 disk->major = rbd_dev->major;
1315 disk->first_minor = 0;
1316 disk->fops = &rbd_bd_ops;
1317 disk->private_data = rbd_dev;
1318
1319 /* init rq */
1320 rc = -ENOMEM;
1321 q = blk_init_queue(rbd_rq_fn, &rbd_dev->lock);
1322 if (!q)
1323 goto out_disk;
1324 blk_queue_merge_bvec(q, rbd_merge_bvec);
1325 disk->queue = q;
1326
1327 q->queuedata = rbd_dev;
1328
1329 rbd_dev->disk = disk;
1330 rbd_dev->q = q;
1331
1332 /* finally, announce the disk to the world */
1333 set_capacity(disk, total_size / 512ULL);
1334 add_disk(disk);
1335
1336 pr_info("%s: added with size 0x%llx\n",
1337 disk->disk_name, (unsigned long long)total_size);
1338 return 0;
1339
1340out_disk:
1341 put_disk(disk);
1342out:
1343 return rc;
1344}
1345
1346/********************************************************************
1347 * /sys/class/rbd/
1348 * add map rados objects to blkdev
1349 * remove unmap rados objects
1350 * list show mappings
1351 *******************************************************************/
1352
1353static void class_rbd_release(struct class *cls)
1354{
1355 kfree(cls);
1356}
1357
1358static ssize_t class_rbd_list(struct class *c,
1359 struct class_attribute *attr,
1360 char *data)
1361{
1362 int n = 0;
1363 struct list_head *tmp;
1364 int max = PAGE_SIZE;
1365
1366 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1367
1368 n += snprintf(data, max,
1369 "#id\tmajor\tclient_name\tpool\tname\tsnap\tKB\n");
1370
1371 list_for_each(tmp, &rbd_dev_list) {
1372 struct rbd_device *rbd_dev;
1373
1374 rbd_dev = list_entry(tmp, struct rbd_device, node);
1375 n += snprintf(data+n, max-n,
1376 "%d\t%d\tclient%lld\t%s\t%s\t%s\t%lld\n",
1377 rbd_dev->id,
1378 rbd_dev->major,
1379 ceph_client_id(rbd_dev->client),
1380 rbd_dev->pool_name,
1381 rbd_dev->obj, rbd_dev->snap_name,
1382 rbd_dev->header.image_size >> 10);
1383 if (n == max)
1384 break;
1385 }
1386
1387 mutex_unlock(&ctl_mutex);
1388 return n;
1389}
1390
1391static ssize_t class_rbd_add(struct class *c,
1392 struct class_attribute *attr,
1393 const char *buf, size_t count)
1394{
1395 struct ceph_osd_client *osdc;
1396 struct rbd_device *rbd_dev;
1397 ssize_t rc = -ENOMEM;
1398 int irc, new_id = 0;
1399 struct list_head *tmp;
1400 char *mon_dev_name;
1401 char *options;
1402
1403 if (!try_module_get(THIS_MODULE))
1404 return -ENODEV;
1405
1406 mon_dev_name = kmalloc(RBD_MAX_OPT_LEN, GFP_KERNEL);
1407 if (!mon_dev_name)
1408 goto err_out_mod;
1409
1410 options = kmalloc(RBD_MAX_OPT_LEN, GFP_KERNEL);
1411 if (!options)
1412 goto err_mon_dev;
1413
1414 /* new rbd_device object */
1415 rbd_dev = kzalloc(sizeof(*rbd_dev), GFP_KERNEL);
1416 if (!rbd_dev)
1417 goto err_out_opt;
1418
1419 /* static rbd_device initialization */
1420 spin_lock_init(&rbd_dev->lock);
1421 INIT_LIST_HEAD(&rbd_dev->node);
1422
1423 /* generate unique id: find highest unique id, add one */
1424 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1425
1426 list_for_each(tmp, &rbd_dev_list) {
1427 struct rbd_device *rbd_dev;
1428
1429 rbd_dev = list_entry(tmp, struct rbd_device, node);
1430 if (rbd_dev->id >= new_id)
1431 new_id = rbd_dev->id + 1;
1432 }
1433
1434 rbd_dev->id = new_id;
1435
1436 /* add to global list */
1437 list_add_tail(&rbd_dev->node, &rbd_dev_list);
1438
1439 /* parse add command */
1440 if (sscanf(buf, "%" __stringify(RBD_MAX_OPT_LEN) "s "
1441 "%" __stringify(RBD_MAX_OPT_LEN) "s "
1442 "%" __stringify(RBD_MAX_POOL_NAME_LEN) "s "
1443 "%" __stringify(RBD_MAX_OBJ_NAME_LEN) "s"
1444 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1445 mon_dev_name, options, rbd_dev->pool_name,
1446 rbd_dev->obj, rbd_dev->snap_name) < 4) {
1447 rc = -EINVAL;
1448 goto err_out_slot;
1449 }
1450
1451 if (rbd_dev->snap_name[0] == 0)
1452 rbd_dev->snap_name[0] = '-';
1453
1454 rbd_dev->obj_len = strlen(rbd_dev->obj);
1455 snprintf(rbd_dev->obj_md_name, sizeof(rbd_dev->obj_md_name), "%s%s",
1456 rbd_dev->obj, RBD_SUFFIX);
1457
1458 /* initialize rest of new object */
1459 snprintf(rbd_dev->name, DEV_NAME_LEN, DRV_NAME "%d", rbd_dev->id);
1460 rc = rbd_get_client(rbd_dev, mon_dev_name, options);
1461 if (rc < 0)
1462 goto err_out_slot;
1463
1464 mutex_unlock(&ctl_mutex);
1465
1466 /* pick the pool */
1467 osdc = &rbd_dev->client->osdc;
1468 rc = ceph_pg_poolid_by_name(osdc->osdmap, rbd_dev->pool_name);
1469 if (rc < 0)
1470 goto err_out_client;
1471 rbd_dev->poolid = rc;
1472
1473 /* register our block device */
1474 irc = register_blkdev(0, rbd_dev->name);
1475 if (irc < 0) {
1476 rc = irc;
1477 goto err_out_client;
1478 }
1479 rbd_dev->major = irc;
1480
1481 /* set up and announce blkdev mapping */
1482 rc = rbd_init_disk(rbd_dev);
1483 if (rc)
1484 goto err_out_blkdev;
1485
1486 return count;
1487
1488err_out_blkdev:
1489 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1490err_out_client:
1491 rbd_put_client(rbd_dev);
1492 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1493err_out_slot:
1494 list_del_init(&rbd_dev->node);
1495 mutex_unlock(&ctl_mutex);
1496
1497 kfree(rbd_dev);
1498err_out_opt:
1499 kfree(options);
1500err_mon_dev:
1501 kfree(mon_dev_name);
1502err_out_mod:
1503 dout("Error adding device %s\n", buf);
1504 module_put(THIS_MODULE);
1505 return rc;
1506}
1507
1508static struct rbd_device *__rbd_get_dev(unsigned long id)
1509{
1510 struct list_head *tmp;
1511 struct rbd_device *rbd_dev;
1512
1513 list_for_each(tmp, &rbd_dev_list) {
1514 rbd_dev = list_entry(tmp, struct rbd_device, node);
1515 if (rbd_dev->id == id)
1516 return rbd_dev;
1517 }
1518 return NULL;
1519}
1520
1521static ssize_t class_rbd_remove(struct class *c,
1522 struct class_attribute *attr,
1523 const char *buf,
1524 size_t count)
1525{
1526 struct rbd_device *rbd_dev = NULL;
1527 int target_id, rc;
1528 unsigned long ul;
1529
1530 rc = strict_strtoul(buf, 10, &ul);
1531 if (rc)
1532 return rc;
1533
1534 /* convert to int; abort if we lost anything in the conversion */
1535 target_id = (int) ul;
1536 if (target_id != ul)
1537 return -EINVAL;
1538
1539 /* remove object from list immediately */
1540 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1541
1542 rbd_dev = __rbd_get_dev(target_id);
1543 if (rbd_dev)
1544 list_del_init(&rbd_dev->node);
1545
1546 mutex_unlock(&ctl_mutex);
1547
1548 if (!rbd_dev)
1549 return -ENOENT;
1550
1551 rbd_put_client(rbd_dev);
1552
1553 /* clean up and free blkdev */
1554 rbd_free_disk(rbd_dev);
1555 unregister_blkdev(rbd_dev->major, rbd_dev->name);
1556 kfree(rbd_dev);
1557
1558 /* release module ref */
1559 module_put(THIS_MODULE);
1560
1561 return count;
1562}
1563
1564static ssize_t class_rbd_snaps_list(struct class *c,
1565 struct class_attribute *attr,
1566 char *data)
1567{
1568 struct rbd_device *rbd_dev = NULL;
1569 struct list_head *tmp;
1570 struct rbd_image_header *header;
1571 int i, n = 0, max = PAGE_SIZE;
1572 int ret;
1573
1574 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1575
1576 n += snprintf(data, max, "#id\tsnap\tKB\n");
1577
1578 list_for_each(tmp, &rbd_dev_list) {
1579 char *names, *p;
1580 struct ceph_snap_context *snapc;
1581
1582 rbd_dev = list_entry(tmp, struct rbd_device, node);
1583 header = &rbd_dev->header;
1584
1585 down_read(&header->snap_rwsem);
1586
1587 names = header->snap_names;
1588 snapc = header->snapc;
1589
1590 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1591 rbd_dev->id, RBD_SNAP_HEAD_NAME,
1592 header->image_size >> 10,
1593 (!rbd_dev->cur_snap ? " (*)" : ""));
1594 if (n == max)
1595 break;
1596
1597 p = names;
1598 for (i = 0; i < header->total_snaps; i++, p += strlen(p) + 1) {
1599 n += snprintf(data + n, max - n, "%d\t%s\t%lld%s\n",
1600 rbd_dev->id, p, header->snap_sizes[i] >> 10,
1601 (rbd_dev->cur_snap &&
1602 (snap_index(header, i) == rbd_dev->cur_snap) ?
1603 " (*)" : ""));
1604 if (n == max)
1605 break;
1606 }
1607
1608 up_read(&header->snap_rwsem);
1609 }
1610
1611
1612 ret = n;
1613 mutex_unlock(&ctl_mutex);
1614 return ret;
1615}
1616
1617static ssize_t class_rbd_snaps_refresh(struct class *c,
1618 struct class_attribute *attr,
1619 const char *buf,
1620 size_t count)
1621{
1622 struct rbd_device *rbd_dev = NULL;
1623 int target_id, rc;
1624 unsigned long ul;
1625 int ret = count;
1626
1627 rc = strict_strtoul(buf, 10, &ul);
1628 if (rc)
1629 return rc;
1630
1631 /* convert to int; abort if we lost anything in the conversion */
1632 target_id = (int) ul;
1633 if (target_id != ul)
1634 return -EINVAL;
1635
1636 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1637
1638 rbd_dev = __rbd_get_dev(target_id);
1639 if (!rbd_dev) {
1640 ret = -ENOENT;
1641 goto done;
1642 }
1643
1644 rc = rbd_update_snaps(rbd_dev);
1645 if (rc < 0)
1646 ret = rc;
1647
1648done:
1649 mutex_unlock(&ctl_mutex);
1650 return ret;
1651}
1652
1653static ssize_t class_rbd_snap_create(struct class *c,
1654 struct class_attribute *attr,
1655 const char *buf,
1656 size_t count)
1657{
1658 struct rbd_device *rbd_dev = NULL;
1659 int target_id, ret;
1660 char *name;
1661
1662 name = kmalloc(RBD_MAX_SNAP_NAME_LEN + 1, GFP_KERNEL);
1663 if (!name)
1664 return -ENOMEM;
1665
1666 /* parse snaps add command */
1667 if (sscanf(buf, "%d "
1668 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1669 &target_id,
1670 name) != 2) {
1671 ret = -EINVAL;
1672 goto done;
1673 }
1674
1675 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1676
1677 rbd_dev = __rbd_get_dev(target_id);
1678 if (!rbd_dev) {
1679 ret = -ENOENT;
1680 goto done_unlock;
1681 }
1682
1683 ret = rbd_header_add_snap(rbd_dev,
1684 name, GFP_KERNEL);
1685 if (ret < 0)
1686 goto done_unlock;
1687
1688 ret = rbd_update_snaps(rbd_dev);
1689 if (ret < 0)
1690 goto done_unlock;
1691
1692 ret = count;
1693done_unlock:
1694 mutex_unlock(&ctl_mutex);
1695done:
1696 kfree(name);
1697 return ret;
1698}
1699
1700static ssize_t class_rbd_rollback(struct class *c,
1701 struct class_attribute *attr,
1702 const char *buf,
1703 size_t count)
1704{
1705 struct rbd_device *rbd_dev = NULL;
1706 int target_id, ret;
1707 u64 snapid;
1708 char snap_name[RBD_MAX_SNAP_NAME_LEN];
1709 u64 cur_ofs;
1710 char *seg_name;
1711
1712 /* parse snaps add command */
1713 if (sscanf(buf, "%d "
1714 "%" __stringify(RBD_MAX_SNAP_NAME_LEN) "s",
1715 &target_id,
1716 snap_name) != 2) {
1717 return -EINVAL;
1718 }
1719
1720 ret = -ENOMEM;
1721 seg_name = kmalloc(RBD_MAX_SEG_NAME_LEN + 1, GFP_NOIO);
1722 if (!seg_name)
1723 return ret;
1724
1725 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
1726
1727 rbd_dev = __rbd_get_dev(target_id);
1728 if (!rbd_dev) {
1729 ret = -ENOENT;
1730 goto done_unlock;
1731 }
1732
1733 ret = snap_by_name(&rbd_dev->header, snap_name, &snapid, NULL);
1734 if (ret < 0)
1735 goto done_unlock;
1736
1737 dout("snapid=%lld\n", snapid);
1738
1739 cur_ofs = 0;
1740 while (cur_ofs < rbd_dev->header.image_size) {
1741 cur_ofs += rbd_get_segment(&rbd_dev->header,
1742 rbd_dev->obj,
1743 cur_ofs, (u64)-1,
1744 seg_name, NULL);
1745 dout("seg_name=%s\n", seg_name);
1746
1747 ret = rbd_req_sync_rollback_obj(rbd_dev, snapid, seg_name);
1748 if (ret < 0)
1749 pr_warning("could not roll back obj %s err=%d\n",
1750 seg_name, ret);
1751 }
1752
1753 ret = rbd_update_snaps(rbd_dev);
1754 if (ret < 0)
1755 goto done_unlock;
1756
1757 ret = count;
1758
1759done_unlock:
1760 mutex_unlock(&ctl_mutex);
1761 kfree(seg_name);
1762
1763 return ret;
1764}
1765
1766static struct class_attribute class_rbd_attrs[] = {
1767 __ATTR(add, 0200, NULL, class_rbd_add),
1768 __ATTR(remove, 0200, NULL, class_rbd_remove),
1769 __ATTR(list, 0444, class_rbd_list, NULL),
1770 __ATTR(snaps_refresh, 0200, NULL, class_rbd_snaps_refresh),
1771 __ATTR(snap_create, 0200, NULL, class_rbd_snap_create),
1772 __ATTR(snaps_list, 0444, class_rbd_snaps_list, NULL),
1773 __ATTR(snap_rollback, 0200, NULL, class_rbd_rollback),
1774 __ATTR_NULL
1775};
1776
1777/*
1778 * create control files in sysfs
1779 * /sys/class/rbd/...
1780 */
1781static int rbd_sysfs_init(void)
1782{
1783 int ret = -ENOMEM;
1784
1785 class_rbd = kzalloc(sizeof(*class_rbd), GFP_KERNEL);
1786 if (!class_rbd)
1787 goto out;
1788
1789 class_rbd->name = DRV_NAME;
1790 class_rbd->owner = THIS_MODULE;
1791 class_rbd->class_release = class_rbd_release;
1792 class_rbd->class_attrs = class_rbd_attrs;
1793
1794 ret = class_register(class_rbd);
1795 if (ret)
1796 goto out_class;
1797 return 0;
1798
1799out_class:
1800 kfree(class_rbd);
1801 class_rbd = NULL;
1802 pr_err(DRV_NAME ": failed to create class rbd\n");
1803out:
1804 return ret;
1805}
1806
1807static void rbd_sysfs_cleanup(void)
1808{
1809 if (class_rbd)
1810 class_destroy(class_rbd);
1811 class_rbd = NULL;
1812}
1813
1814int __init rbd_init(void)
1815{
1816 int rc;
1817
1818 rc = rbd_sysfs_init();
1819 if (rc)
1820 return rc;
1821 spin_lock_init(&node_lock);
1822 pr_info("loaded " DRV_NAME_LONG "\n");
1823 return 0;
1824}
1825
1826void __exit rbd_exit(void)
1827{
1828 rbd_sysfs_cleanup();
1829}
1830
1831module_init(rbd_init);
1832module_exit(rbd_exit);
1833
1834MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
1835MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
1836MODULE_DESCRIPTION("rados block device");
1837
1838/* following authorship retained from original osdblk.c */
1839MODULE_AUTHOR("Jeff Garzik <jeff@garzik.org>");
1840
1841MODULE_LICENSE("GPL");
diff --git a/drivers/block/rbd_types.h b/drivers/block/rbd_types.h
new file mode 100644
index 000000000000..fc6c678aa2cb
--- /dev/null
+++ b/drivers/block/rbd_types.h
@@ -0,0 +1,73 @@
1/*
2 * Ceph - scalable distributed file system
3 *
4 * Copyright (C) 2004-2010 Sage Weil <sage@newdream.net>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 *
11 */
12
13#ifndef CEPH_RBD_TYPES_H
14#define CEPH_RBD_TYPES_H
15
16#include <linux/types.h>
17
18/*
19 * rbd image 'foo' consists of objects
20 * foo.rbd - image metadata
21 * foo.00000000
22 * foo.00000001
23 * ... - data
24 */
25
26#define RBD_SUFFIX ".rbd"
27#define RBD_DIRECTORY "rbd_directory"
28#define RBD_INFO "rbd_info"
29
30#define RBD_DEFAULT_OBJ_ORDER 22 /* 4MB */
31#define RBD_MIN_OBJ_ORDER 16
32#define RBD_MAX_OBJ_ORDER 30
33
34#define RBD_MAX_OBJ_NAME_LEN 96
35#define RBD_MAX_SEG_NAME_LEN 128
36
37#define RBD_COMP_NONE 0
38#define RBD_CRYPT_NONE 0
39
40#define RBD_HEADER_TEXT "<<< Rados Block Device Image >>>\n"
41#define RBD_HEADER_SIGNATURE "RBD"
42#define RBD_HEADER_VERSION "001.005"
43
44struct rbd_info {
45 __le64 max_id;
46} __attribute__ ((packed));
47
48struct rbd_image_snap_ondisk {
49 __le64 id;
50 __le64 image_size;
51} __attribute__((packed));
52
53struct rbd_image_header_ondisk {
54 char text[40];
55 char block_name[24];
56 char signature[4];
57 char version[8];
58 struct {
59 __u8 order;
60 __u8 crypt_type;
61 __u8 comp_type;
62 __u8 unused;
63 } __attribute__((packed)) options;
64 __le64 image_size;
65 __le64 snap_seq;
66 __le32 snap_count;
67 __le32 reserved;
68 __le64 snap_names_len;
69 struct rbd_image_snap_ondisk snaps[0];
70} __attribute__((packed));
71
72
73#endif
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index 2e46815876df..75333d0a3327 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -20,7 +20,7 @@
20#include <linux/fd.h> 20#include <linux/fd.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/hdreg.h> 24#include <linux/hdreg.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
@@ -222,6 +222,7 @@ extern int swim_read_sector_header(struct swim __iomem *base,
222extern int swim_read_sector_data(struct swim __iomem *base, 222extern int swim_read_sector_data(struct swim __iomem *base,
223 unsigned char *data); 223 unsigned char *data);
224 224
225static DEFINE_MUTEX(swim_mutex);
225static inline void set_swim_mode(struct swim __iomem *base, int enable) 226static inline void set_swim_mode(struct swim __iomem *base, int enable)
226{ 227{
227 struct iwm __iomem *iwm_base; 228 struct iwm __iomem *iwm_base;
@@ -666,9 +667,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
666{ 667{
667 int ret; 668 int ret;
668 669
669 lock_kernel(); 670 mutex_lock(&swim_mutex);
670 ret = floppy_open(bdev, mode); 671 ret = floppy_open(bdev, mode);
671 unlock_kernel(); 672 mutex_unlock(&swim_mutex);
672 673
673 return ret; 674 return ret;
674} 675}
@@ -678,7 +679,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
678 struct floppy_state *fs = disk->private_data; 679 struct floppy_state *fs = disk->private_data;
679 struct swim __iomem *base = fs->swd->base; 680 struct swim __iomem *base = fs->swd->base;
680 681
681 lock_kernel(); 682 mutex_lock(&swim_mutex);
682 if (fs->ref_count < 0) 683 if (fs->ref_count < 0)
683 fs->ref_count = 0; 684 fs->ref_count = 0;
684 else if (fs->ref_count > 0) 685 else if (fs->ref_count > 0)
@@ -686,7 +687,7 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
686 687
687 if (fs->ref_count == 0) 688 if (fs->ref_count == 0)
688 swim_motor(base, OFF); 689 swim_motor(base, OFF);
689 unlock_kernel(); 690 mutex_unlock(&swim_mutex);
690 691
691 return 0; 692 return 0;
692} 693}
@@ -704,9 +705,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
704 case FDEJECT: 705 case FDEJECT:
705 if (fs->ref_count != 1) 706 if (fs->ref_count != 1)
706 return -EBUSY; 707 return -EBUSY;
707 lock_kernel(); 708 mutex_lock(&swim_mutex);
708 err = floppy_eject(fs); 709 err = floppy_eject(fs);
709 unlock_kernel(); 710 mutex_unlock(&swim_mutex);
710 return err; 711 return err;
711 712
712 case FDGETPRM: 713 case FDGETPRM:
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index cc6a3864822c..bf3a5b859299 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -25,7 +25,7 @@
25#include <linux/ioctl.h> 25#include <linux/ioctl.h>
26#include <linux/blkdev.h> 26#include <linux/blkdev.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <asm/io.h> 31#include <asm/io.h>
@@ -36,6 +36,7 @@
36#include <asm/machdep.h> 36#include <asm/machdep.h>
37#include <asm/pmac_feature.h> 37#include <asm/pmac_feature.h>
38 38
39static DEFINE_MUTEX(swim3_mutex);
39static struct request_queue *swim3_queue; 40static struct request_queue *swim3_queue;
40static struct gendisk *disks[2]; 41static struct gendisk *disks[2];
41static struct request *fd_req; 42static struct request *fd_req;
@@ -873,9 +874,9 @@ static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
873{ 874{
874 int ret; 875 int ret;
875 876
876 lock_kernel(); 877 mutex_lock(&swim3_mutex);
877 ret = floppy_locked_ioctl(bdev, mode, cmd, param); 878 ret = floppy_locked_ioctl(bdev, mode, cmd, param);
878 unlock_kernel(); 879 mutex_unlock(&swim3_mutex);
879 880
880 return ret; 881 return ret;
881} 882}
@@ -953,9 +954,9 @@ static int floppy_unlocked_open(struct block_device *bdev, fmode_t mode)
953{ 954{
954 int ret; 955 int ret;
955 956
956 lock_kernel(); 957 mutex_lock(&swim3_mutex);
957 ret = floppy_open(bdev, mode); 958 ret = floppy_open(bdev, mode);
958 unlock_kernel(); 959 mutex_unlock(&swim3_mutex);
959 960
960 return ret; 961 return ret;
961} 962}
@@ -964,13 +965,13 @@ static int floppy_release(struct gendisk *disk, fmode_t mode)
964{ 965{
965 struct floppy_state *fs = disk->private_data; 966 struct floppy_state *fs = disk->private_data;
966 struct swim3 __iomem *sw = fs->swim3; 967 struct swim3 __iomem *sw = fs->swim3;
967 lock_kernel(); 968 mutex_lock(&swim3_mutex);
968 if (fs->ref_count > 0 && --fs->ref_count == 0) { 969 if (fs->ref_count > 0 && --fs->ref_count == 0) {
969 swim3_action(fs, MOTOR_OFF); 970 swim3_action(fs, MOTOR_OFF);
970 out_8(&sw->control_bic, 0xff); 971 out_8(&sw->control_bic, 0xff);
971 swim3_select(fs, RELAX); 972 swim3_select(fs, RELAX);
972 } 973 }
973 unlock_kernel(); 974 mutex_unlock(&swim3_mutex);
974 return 0; 975 return 0;
975} 976}
976 977
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index c48e14878582..b5690a045a01 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -28,7 +28,7 @@
28#include <linux/timer.h> 28#include <linux/timer.h>
29#include <linux/scatterlist.h> 29#include <linux/scatterlist.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h> 31#include <linux/mutex.h>
32#include <scsi/scsi.h> 32#include <scsi/scsi.h>
33 33
34#define DRV_NAME "ub" 34#define DRV_NAME "ub"
@@ -248,6 +248,7 @@ struct ub_completion {
248 spinlock_t lock; 248 spinlock_t lock;
249}; 249};
250 250
251static DEFINE_MUTEX(ub_mutex);
251static inline void ub_init_completion(struct ub_completion *x) 252static inline void ub_init_completion(struct ub_completion *x)
252{ 253{
253 x->done = 0; 254 x->done = 0;
@@ -1715,9 +1716,9 @@ static int ub_bd_unlocked_open(struct block_device *bdev, fmode_t mode)
1715{ 1716{
1716 int ret; 1717 int ret;
1717 1718
1718 lock_kernel(); 1719 mutex_lock(&ub_mutex);
1719 ret = ub_bd_open(bdev, mode); 1720 ret = ub_bd_open(bdev, mode);
1720 unlock_kernel(); 1721 mutex_unlock(&ub_mutex);
1721 1722
1722 return ret; 1723 return ret;
1723} 1724}
@@ -1730,9 +1731,9 @@ static int ub_bd_release(struct gendisk *disk, fmode_t mode)
1730 struct ub_lun *lun = disk->private_data; 1731 struct ub_lun *lun = disk->private_data;
1731 struct ub_dev *sc = lun->udev; 1732 struct ub_dev *sc = lun->udev;
1732 1733
1733 lock_kernel(); 1734 mutex_lock(&ub_mutex);
1734 ub_put(sc); 1735 ub_put(sc);
1735 unlock_kernel(); 1736 mutex_unlock(&ub_mutex);
1736 1737
1737 return 0; 1738 return 0;
1738} 1739}
@@ -1747,9 +1748,9 @@ static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
1747 void __user *usermem = (void __user *) arg; 1748 void __user *usermem = (void __user *) arg;
1748 int ret; 1749 int ret;
1749 1750
1750 lock_kernel(); 1751 mutex_lock(&ub_mutex);
1751 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem); 1752 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
1752 unlock_kernel(); 1753 mutex_unlock(&ub_mutex);
1753 1754
1754 return ret; 1755 return ret;
1755} 1756}
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index f651e51a3319..e2ff697697c2 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -41,7 +41,7 @@
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/dma-mapping.h> 45#include <linux/dma-mapping.h>
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/device.h> 47#include <linux/device.h>
@@ -73,6 +73,7 @@ enum {
73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name) 73 MAX_DISK_NAME = FIELD_SIZEOF(struct gendisk, disk_name)
74}; 74};
75 75
76static DEFINE_MUTEX(viodasd_mutex);
76static DEFINE_SPINLOCK(viodasd_spinlock); 77static DEFINE_SPINLOCK(viodasd_spinlock);
77 78
78#define VIOMAXREQ 16 79#define VIOMAXREQ 16
@@ -180,9 +181,9 @@ static int viodasd_unlocked_open(struct block_device *bdev, fmode_t mode)
180{ 181{
181 int ret; 182 int ret;
182 183
183 lock_kernel(); 184 mutex_lock(&viodasd_mutex);
184 ret = viodasd_open(bdev, mode); 185 ret = viodasd_open(bdev, mode);
185 unlock_kernel(); 186 mutex_unlock(&viodasd_mutex);
186 187
187 return ret; 188 return ret;
188} 189}
@@ -196,7 +197,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
196 struct viodasd_device *d = disk->private_data; 197 struct viodasd_device *d = disk->private_data;
197 HvLpEvent_Rc hvrc; 198 HvLpEvent_Rc hvrc;
198 199
199 lock_kernel(); 200 mutex_lock(&viodasd_mutex);
200 /* Send the event to OS/400. We DON'T expect a response */ 201 /* Send the event to OS/400. We DON'T expect a response */
201 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp, 202 hvrc = HvCallEvent_signalLpEventFast(viopath_hostLp,
202 HvLpEvent_Type_VirtualIo, 203 HvLpEvent_Type_VirtualIo,
@@ -210,7 +211,7 @@ static int viodasd_release(struct gendisk *disk, fmode_t mode)
210 if (hvrc != 0) 211 if (hvrc != 0)
211 pr_warning("HV close call failed %d\n", (int)hvrc); 212 pr_warning("HV close call failed %d\n", (int)hvrc);
212 213
213 unlock_kernel(); 214 mutex_unlock(&viodasd_mutex);
214 215
215 return 0; 216 return 0;
216} 217}
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 2aafafca2b13..8320490226b7 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -2,7 +2,6 @@
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/slab.h> 3#include <linux/slab.h>
4#include <linux/blkdev.h> 4#include <linux/blkdev.h>
5#include <linux/smp_lock.h>
6#include <linux/hdreg.h> 5#include <linux/hdreg.h>
7#include <linux/virtio.h> 6#include <linux/virtio.h>
8#include <linux/virtio_blk.h> 7#include <linux/virtio_blk.h>
@@ -202,6 +201,7 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
202 struct virtio_blk *vblk = disk->private_data; 201 struct virtio_blk *vblk = disk->private_data;
203 struct request *req; 202 struct request *req;
204 struct bio *bio; 203 struct bio *bio;
204 int err;
205 205
206 bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES, 206 bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES,
207 GFP_KERNEL); 207 GFP_KERNEL);
@@ -215,11 +215,14 @@ static int virtblk_get_id(struct gendisk *disk, char *id_str)
215 } 215 }
216 216
217 req->cmd_type = REQ_TYPE_SPECIAL; 217 req->cmd_type = REQ_TYPE_SPECIAL;
218 return blk_execute_rq(vblk->disk->queue, vblk->disk, req, false); 218 err = blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
219 blk_put_request(req);
220
221 return err;
219} 222}
220 223
221static int virtblk_locked_ioctl(struct block_device *bdev, fmode_t mode, 224static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
222 unsigned cmd, unsigned long data) 225 unsigned int cmd, unsigned long data)
223{ 226{
224 struct gendisk *disk = bdev->bd_disk; 227 struct gendisk *disk = bdev->bd_disk;
225 struct virtio_blk *vblk = disk->private_data; 228 struct virtio_blk *vblk = disk->private_data;
@@ -234,18 +237,6 @@ static int virtblk_locked_ioctl(struct block_device *bdev, fmode_t mode,
234 (void __user *)data); 237 (void __user *)data);
235} 238}
236 239
237static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
238 unsigned int cmd, unsigned long param)
239{
240 int ret;
241
242 lock_kernel();
243 ret = virtblk_locked_ioctl(bdev, mode, cmd, param);
244 unlock_kernel();
245
246 return ret;
247}
248
249/* We provide getgeo only to please some old bootloader/partitioning tools */ 240/* We provide getgeo only to please some old bootloader/partitioning tools */
250static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) 241static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
251{ 242{
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index d5a3cd750561..4abd2bcd20fb 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -46,7 +46,7 @@
46#include <linux/init.h> 46#include <linux/init.h>
47#include <linux/wait.h> 47#include <linux/wait.h>
48#include <linux/blkdev.h> 48#include <linux/blkdev.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/blkpg.h> 50#include <linux/blkpg.h>
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/io.h> 52#include <linux/io.h>
@@ -58,6 +58,7 @@
58 58
59#include "xd.h" 59#include "xd.h"
60 60
61static DEFINE_MUTEX(xd_mutex);
61static void __init do_xd_setup (int *integers); 62static void __init do_xd_setup (int *integers);
62#ifdef MODULE 63#ifdef MODULE
63static int xd[5] = { -1,-1,-1,-1, }; 64static int xd[5] = { -1,-1,-1,-1, };
@@ -381,9 +382,9 @@ static int xd_ioctl(struct block_device *bdev, fmode_t mode,
381{ 382{
382 int ret; 383 int ret;
383 384
384 lock_kernel(); 385 mutex_lock(&xd_mutex);
385 ret = xd_locked_ioctl(bdev, mode, cmd, param); 386 ret = xd_locked_ioctl(bdev, mode, cmd, param);
386 unlock_kernel(); 387 mutex_unlock(&xd_mutex);
387 388
388 return ret; 389 return ret;
389} 390}
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index ab735a605cf3..3ff06f475eef 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -41,7 +41,7 @@
41#include <linux/cdrom.h> 41#include <linux/cdrom.h>
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/smp_lock.h> 44#include <linux/mutex.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46 46
47#include <xen/xen.h> 47#include <xen/xen.h>
@@ -69,6 +69,7 @@ struct blk_shadow {
69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 69 unsigned long frame[BLKIF_MAX_SEGMENTS_PER_REQUEST];
70}; 70};
71 71
72static DEFINE_MUTEX(blkfront_mutex);
72static const struct block_device_operations xlvbd_block_fops; 73static const struct block_device_operations xlvbd_block_fops;
73 74
74#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE) 75#define BLK_RING_SIZE __RING_SIZE((struct blkif_sring *)0, PAGE_SIZE)
@@ -1201,7 +1202,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1201 struct blkfront_info *info; 1202 struct blkfront_info *info;
1202 int err = 0; 1203 int err = 0;
1203 1204
1204 lock_kernel(); 1205 mutex_lock(&blkfront_mutex);
1205 1206
1206 info = disk->private_data; 1207 info = disk->private_data;
1207 if (!info) { 1208 if (!info) {
@@ -1219,7 +1220,7 @@ static int blkif_open(struct block_device *bdev, fmode_t mode)
1219 mutex_unlock(&info->mutex); 1220 mutex_unlock(&info->mutex);
1220 1221
1221out: 1222out:
1222 unlock_kernel(); 1223 mutex_unlock(&blkfront_mutex);
1223 return err; 1224 return err;
1224} 1225}
1225 1226
@@ -1229,7 +1230,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1229 struct block_device *bdev; 1230 struct block_device *bdev;
1230 struct xenbus_device *xbdev; 1231 struct xenbus_device *xbdev;
1231 1232
1232 lock_kernel(); 1233 mutex_lock(&blkfront_mutex);
1233 1234
1234 bdev = bdget_disk(disk, 0); 1235 bdev = bdget_disk(disk, 0);
1235 bdput(bdev); 1236 bdput(bdev);
@@ -1263,7 +1264,7 @@ static int blkif_release(struct gendisk *disk, fmode_t mode)
1263 } 1264 }
1264 1265
1265out: 1266out:
1266 unlock_kernel(); 1267 mutex_unlock(&blkfront_mutex);
1267 return 0; 1268 return 0;
1268} 1269}
1269 1270
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 057413bb16e2..6e968cd4893c 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -89,7 +89,7 @@
89#include <linux/delay.h> 89#include <linux/delay.h>
90#include <linux/slab.h> 90#include <linux/slab.h>
91#include <linux/blkdev.h> 91#include <linux/blkdev.h>
92#include <linux/smp_lock.h> 92#include <linux/mutex.h>
93#include <linux/ata.h> 93#include <linux/ata.h>
94#include <linux/hdreg.h> 94#include <linux/hdreg.h>
95#include <linux/platform_device.h> 95#include <linux/platform_device.h>
@@ -214,6 +214,7 @@ struct ace_device {
214 u16 cf_id[ATA_ID_WORDS]; 214 u16 cf_id[ATA_ID_WORDS];
215}; 215};
216 216
217static DEFINE_MUTEX(xsysace_mutex);
217static int ace_major; 218static int ace_major;
218 219
219/* --------------------------------------------------------------------- 220/* ---------------------------------------------------------------------
@@ -903,13 +904,13 @@ static int ace_open(struct block_device *bdev, fmode_t mode)
903 904
904 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1); 905 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
905 906
906 lock_kernel(); 907 mutex_lock(&xsysace_mutex);
907 spin_lock_irqsave(&ace->lock, flags); 908 spin_lock_irqsave(&ace->lock, flags);
908 ace->users++; 909 ace->users++;
909 spin_unlock_irqrestore(&ace->lock, flags); 910 spin_unlock_irqrestore(&ace->lock, flags);
910 911
911 check_disk_change(bdev); 912 check_disk_change(bdev);
912 unlock_kernel(); 913 mutex_unlock(&xsysace_mutex);
913 914
914 return 0; 915 return 0;
915} 916}
@@ -922,7 +923,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
922 923
923 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1); 924 dev_dbg(ace->dev, "ace_release() users=%i\n", ace->users - 1);
924 925
925 lock_kernel(); 926 mutex_lock(&xsysace_mutex);
926 spin_lock_irqsave(&ace->lock, flags); 927 spin_lock_irqsave(&ace->lock, flags);
927 ace->users--; 928 ace->users--;
928 if (ace->users == 0) { 929 if (ace->users == 0) {
@@ -930,7 +931,7 @@ static int ace_release(struct gendisk *disk, fmode_t mode)
930 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ); 931 ace_out(ace, ACE_CTRL, val & ~ACE_CTRL_LOCKREQ);
931 } 932 }
932 spin_unlock_irqrestore(&ace->lock, flags); 933 spin_unlock_irqrestore(&ace->lock, flags);
933 unlock_kernel(); 934 mutex_unlock(&xsysace_mutex);
934 return 0; 935 return 0;
935} 936}
936 937
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index d75b2bb601ad..dcd4cfcf4126 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -33,7 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/smp_lock.h> 36#include <linux/mutex.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38 38
39#include <asm/setup.h> 39#include <asm/setup.h>
@@ -57,6 +57,7 @@ extern struct mem_info m68k_memory[NUM_MEMINFO];
57 57
58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 ) 58#define Z2RAM_CHUNK1024 ( Z2RAM_CHUNKSIZE >> 10 )
59 59
60static DEFINE_MUTEX(z2ram_mutex);
60static u_long *z2ram_map = NULL; 61static u_long *z2ram_map = NULL;
61static u_long z2ram_size = 0; 62static u_long z2ram_size = 0;
62static int z2_count = 0; 63static int z2_count = 0;
@@ -154,7 +155,7 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
154 155
155 device = MINOR(bdev->bd_dev); 156 device = MINOR(bdev->bd_dev);
156 157
157 lock_kernel(); 158 mutex_lock(&z2ram_mutex);
158 if ( current_device != -1 && current_device != device ) 159 if ( current_device != -1 && current_device != device )
159 { 160 {
160 rc = -EBUSY; 161 rc = -EBUSY;
@@ -296,25 +297,25 @@ static int z2_open(struct block_device *bdev, fmode_t mode)
296 set_capacity(z2ram_gendisk, z2ram_size >> 9); 297 set_capacity(z2ram_gendisk, z2ram_size >> 9);
297 } 298 }
298 299
299 unlock_kernel(); 300 mutex_unlock(&z2ram_mutex);
300 return 0; 301 return 0;
301 302
302err_out_kfree: 303err_out_kfree:
303 kfree(z2ram_map); 304 kfree(z2ram_map);
304err_out: 305err_out:
305 unlock_kernel(); 306 mutex_unlock(&z2ram_mutex);
306 return rc; 307 return rc;
307} 308}
308 309
309static int 310static int
310z2_release(struct gendisk *disk, fmode_t mode) 311z2_release(struct gendisk *disk, fmode_t mode)
311{ 312{
312 lock_kernel(); 313 mutex_lock(&z2ram_mutex);
313 if ( current_device == -1 ) { 314 if ( current_device == -1 ) {
314 unlock_kernel(); 315 mutex_unlock(&z2ram_mutex);
315 return 0; 316 return 0;
316 } 317 }
317 unlock_kernel(); 318 mutex_unlock(&z2ram_mutex);
318 /* 319 /*
319 * FIXME: unmap memory 320 * FIXME: unmap memory
320 */ 321 */
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index d52e90a5a617..4104b7feae67 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -39,7 +39,6 @@
39#include <linux/skbuff.h> 39#include <linux/skbuff.h>
40#include <linux/io.h> 40#include <linux/io.h>
41 41
42#include <pcmcia/cs.h>
43#include <pcmcia/cistpl.h> 42#include <pcmcia/cistpl.h>
44#include <pcmcia/ciscode.h> 43#include <pcmcia/ciscode.h>
45#include <pcmcia/ds.h> 44#include <pcmcia/ds.h>
@@ -865,8 +864,7 @@ static int bluecard_probe(struct pcmcia_device *link)
865 info->p_dev = link; 864 info->p_dev = link;
866 link->priv = info; 865 link->priv = info;
867 866
868 link->conf.Attributes = CONF_ENABLE_IRQ; 867 link->config_flags |= CONF_ENABLE_IRQ;
869 link->conf.IntType = INT_MEMORY_AND_IO;
870 868
871 return bluecard_config(link); 869 return bluecard_config(link);
872} 870}
@@ -886,7 +884,7 @@ static int bluecard_config(struct pcmcia_device *link)
886 bluecard_info_t *info = link->priv; 884 bluecard_info_t *info = link->priv;
887 int i, n; 885 int i, n;
888 886
889 link->conf.ConfigIndex = 0x20; 887 link->config_index = 0x20;
890 888
891 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 889 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
892 link->resource[0]->end = 64; 890 link->resource[0]->end = 64;
@@ -906,7 +904,7 @@ static int bluecard_config(struct pcmcia_device *link)
906 if (i != 0) 904 if (i != 0)
907 goto failed; 905 goto failed;
908 906
909 i = pcmcia_request_configuration(link, &link->conf); 907 i = pcmcia_enable_device(link);
910 if (i != 0) 908 if (i != 0)
911 goto failed; 909 goto failed;
912 910
@@ -942,9 +940,7 @@ MODULE_DEVICE_TABLE(pcmcia, bluecard_ids);
942 940
943static struct pcmcia_driver bluecard_driver = { 941static struct pcmcia_driver bluecard_driver = {
944 .owner = THIS_MODULE, 942 .owner = THIS_MODULE,
945 .drv = { 943 .name = "bluecard_cs",
946 .name = "bluecard_cs",
947 },
948 .probe = bluecard_probe, 944 .probe = bluecard_probe,
949 .remove = bluecard_detach, 945 .remove = bluecard_detach,
950 .id_table = bluecard_ids, 946 .id_table = bluecard_ids,
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 7ab8f29d5e0d..0c8a65587491 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -45,7 +45,6 @@
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/firmware.h> 46#include <linux/firmware.h>
47 47
48#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
50#include <pcmcia/ciscode.h> 49#include <pcmcia/ciscode.h>
51#include <pcmcia/ds.h> 50#include <pcmcia/ds.h>
@@ -657,11 +656,8 @@ static int bt3c_probe(struct pcmcia_device *link)
657 info->p_dev = link; 656 info->p_dev = link;
658 link->priv = info; 657 link->priv = info;
659 658
660 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 659 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
661 link->resource[0]->end = 8; 660 CONF_AUTO_SET_IO;
662
663 link->conf.Attributes = CONF_ENABLE_IRQ;
664 link->conf.IntType = INT_MEMORY_AND_IO;
665 661
666 return bt3c_config(link); 662 return bt3c_config(link);
667} 663}
@@ -675,43 +671,41 @@ static void bt3c_detach(struct pcmcia_device *link)
675 kfree(info); 671 kfree(info);
676} 672}
677 673
678static int bt3c_check_config(struct pcmcia_device *p_dev, 674static int bt3c_check_config(struct pcmcia_device *p_dev, void *priv_data)
679 cistpl_cftable_entry_t *cf,
680 cistpl_cftable_entry_t *dflt,
681 unsigned int vcc,
682 void *priv_data)
683{ 675{
684 unsigned long try = (unsigned long) priv_data; 676 int *try = priv_data;
685 677
686 p_dev->io_lines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 678 if (try == 0)
679 p_dev->io_lines = 16;
687 680
688 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 681 if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
689 p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 682 return -EINVAL;
690 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && 683
691 (cf->io.win[0].base != 0)) { 684 p_dev->resource[0]->end = 8;
692 p_dev->resource[0]->start = cf->io.win[0].base; 685 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
693 if (!pcmcia_request_io(p_dev)) 686 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
694 return 0; 687
695 } 688 return pcmcia_request_io(p_dev);
696 return -ENODEV;
697} 689}
698 690
699static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev, 691static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
700 cistpl_cftable_entry_t *cf,
701 cistpl_cftable_entry_t *dflt,
702 unsigned int vcc,
703 void *priv_data) 692 void *priv_data)
704{ 693{
705 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 694 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
706 int j; 695 int j;
707 696
708 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 697 if (p_dev->io_lines > 3)
709 for (j = 0; j < 5; j++) { 698 return -ENODEV;
710 p_dev->resource[0]->start = base[j]; 699
711 p_dev->io_lines = base[j] ? 16 : 3; 700 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
712 if (!pcmcia_request_io(p_dev)) 701 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
713 return 0; 702 p_dev->resource[0]->end = 8;
714 } 703
704 for (j = 0; j < 5; j++) {
705 p_dev->resource[0]->start = base[j];
706 p_dev->io_lines = base[j] ? 16 : 3;
707 if (!pcmcia_request_io(p_dev))
708 return 0;
715 } 709 }
716 return -ENODEV; 710 return -ENODEV;
717} 711}
@@ -742,7 +736,7 @@ found_port:
742 if (i != 0) 736 if (i != 0)
743 goto failed; 737 goto failed;
744 738
745 i = pcmcia_request_configuration(link, &link->conf); 739 i = pcmcia_enable_device(link);
746 if (i != 0) 740 if (i != 0)
747 goto failed; 741 goto failed;
748 742
@@ -775,9 +769,7 @@ MODULE_DEVICE_TABLE(pcmcia, bt3c_ids);
775 769
776static struct pcmcia_driver bt3c_driver = { 770static struct pcmcia_driver bt3c_driver = {
777 .owner = THIS_MODULE, 771 .owner = THIS_MODULE,
778 .drv = { 772 .name = "bt3c_cs",
779 .name = "bt3c_cs",
780 },
781 .probe = bt3c_probe, 773 .probe = bt3c_probe,
782 .remove = bt3c_detach, 774 .remove = bt3c_detach,
783 .id_table = bt3c_ids, 775 .id_table = bt3c_ids,
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 1c4f5e863b03..f8a0708e2311 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -41,7 +41,6 @@
41#include <asm/system.h> 41#include <asm/system.h>
42#include <asm/io.h> 42#include <asm/io.h>
43 43
44#include <pcmcia/cs.h>
45#include <pcmcia/cistpl.h> 44#include <pcmcia/cistpl.h>
46#include <pcmcia/ciscode.h> 45#include <pcmcia/ciscode.h>
47#include <pcmcia/ds.h> 46#include <pcmcia/ds.h>
@@ -586,11 +585,8 @@ static int btuart_probe(struct pcmcia_device *link)
586 info->p_dev = link; 585 info->p_dev = link;
587 link->priv = info; 586 link->priv = info;
588 587
589 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 588 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
590 link->resource[0]->end = 8; 589 CONF_AUTO_SET_IO;
591
592 link->conf.Attributes = CONF_ENABLE_IRQ;
593 link->conf.IntType = INT_MEMORY_AND_IO;
594 590
595 return btuart_config(link); 591 return btuart_config(link);
596} 592}
@@ -604,43 +600,41 @@ static void btuart_detach(struct pcmcia_device *link)
604 kfree(info); 600 kfree(info);
605} 601}
606 602
607static int btuart_check_config(struct pcmcia_device *p_dev, 603static int btuart_check_config(struct pcmcia_device *p_dev, void *priv_data)
608 cistpl_cftable_entry_t *cf,
609 cistpl_cftable_entry_t *dflt,
610 unsigned int vcc,
611 void *priv_data)
612{ 604{
613 int *try = priv_data; 605 int *try = priv_data;
614 606
615 p_dev->io_lines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 607 if (try == 0)
608 p_dev->io_lines = 16;
616 609
617 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 610 if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
618 p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000; 611 return -EINVAL;
619 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && 612
620 (cf->io.win[0].base != 0)) { 613 p_dev->resource[0]->end = 8;
621 p_dev->resource[0]->start = cf->io.win[0].base; 614 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
622 if (!pcmcia_request_io(p_dev)) 615 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
623 return 0; 616
624 } 617 return pcmcia_request_io(p_dev);
625 return -ENODEV;
626} 618}
627 619
628static int btuart_check_config_notpicky(struct pcmcia_device *p_dev, 620static int btuart_check_config_notpicky(struct pcmcia_device *p_dev,
629 cistpl_cftable_entry_t *cf,
630 cistpl_cftable_entry_t *dflt,
631 unsigned int vcc,
632 void *priv_data) 621 void *priv_data)
633{ 622{
634 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 623 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
635 int j; 624 int j;
636 625
637 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 626 if (p_dev->io_lines > 3)
638 for (j = 0; j < 5; j++) { 627 return -ENODEV;
639 p_dev->resource[0]->start = base[j]; 628
640 p_dev->io_lines = base[j] ? 16 : 3; 629 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
641 if (!pcmcia_request_io(p_dev)) 630 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
642 return 0; 631 p_dev->resource[0]->end = 8;
643 } 632
633 for (j = 0; j < 5; j++) {
634 p_dev->resource[0]->start = base[j];
635 p_dev->io_lines = base[j] ? 16 : 3;
636 if (!pcmcia_request_io(p_dev))
637 return 0;
644 } 638 }
645 return -ENODEV; 639 return -ENODEV;
646} 640}
@@ -671,7 +665,7 @@ found_port:
671 if (i != 0) 665 if (i != 0)
672 goto failed; 666 goto failed;
673 667
674 i = pcmcia_request_configuration(link, &link->conf); 668 i = pcmcia_enable_device(link);
675 if (i != 0) 669 if (i != 0)
676 goto failed; 670 goto failed;
677 671
@@ -703,9 +697,7 @@ MODULE_DEVICE_TABLE(pcmcia, btuart_ids);
703 697
704static struct pcmcia_driver btuart_driver = { 698static struct pcmcia_driver btuart_driver = {
705 .owner = THIS_MODULE, 699 .owner = THIS_MODULE,
706 .drv = { 700 .name = "btuart_cs",
707 .name = "btuart_cs",
708 },
709 .probe = btuart_probe, 701 .probe = btuart_probe,
710 .remove = btuart_detach, 702 .remove = btuart_detach,
711 .id_table = btuart_ids, 703 .id_table = btuart_ids,
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index db7c8db695fc..26ee0cf88d20 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -41,7 +41,6 @@
41#include <asm/system.h> 41#include <asm/system.h>
42#include <asm/io.h> 42#include <asm/io.h>
43 43
44#include <pcmcia/cs.h>
45#include <pcmcia/cistpl.h> 44#include <pcmcia/cistpl.h>
46#include <pcmcia/ciscode.h> 45#include <pcmcia/ciscode.h>
47#include <pcmcia/ds.h> 46#include <pcmcia/ds.h>
@@ -572,11 +571,7 @@ static int dtl1_probe(struct pcmcia_device *link)
572 info->p_dev = link; 571 info->p_dev = link;
573 link->priv = info; 572 link->priv = info;
574 573
575 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 574 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
576 link->resource[0]->end = 8;
577
578 link->conf.Attributes = CONF_ENABLE_IRQ;
579 link->conf.IntType = INT_MEMORY_AND_IO;
580 575
581 return dtl1_config(link); 576 return dtl1_config(link);
582} 577}
@@ -591,18 +586,14 @@ static void dtl1_detach(struct pcmcia_device *link)
591 kfree(info); 586 kfree(info);
592} 587}
593 588
594static int dtl1_confcheck(struct pcmcia_device *p_dev, 589static int dtl1_confcheck(struct pcmcia_device *p_dev, void *priv_data)
595 cistpl_cftable_entry_t *cf,
596 cistpl_cftable_entry_t *dflt,
597 unsigned int vcc,
598 void *priv_data)
599{ 590{
600 if ((cf->io.nwin != 1) || (cf->io.win[0].len <= 8)) 591 if ((p_dev->resource[1]->end) || (p_dev->resource[1]->end < 8))
601 return -ENODEV; 592 return -ENODEV;
602 593
603 p_dev->resource[0]->start = cf->io.win[0].base; 594 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
604 p_dev->resource[0]->end = cf->io.win[0].len; /*yo */ 595 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
605 p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK; 596
606 return pcmcia_request_io(p_dev); 597 return pcmcia_request_io(p_dev);
607} 598}
608 599
@@ -620,7 +611,7 @@ static int dtl1_config(struct pcmcia_device *link)
620 if (i != 0) 611 if (i != 0)
621 goto failed; 612 goto failed;
622 613
623 i = pcmcia_request_configuration(link, &link->conf); 614 i = pcmcia_enable_device(link);
624 if (i != 0) 615 if (i != 0)
625 goto failed; 616 goto failed;
626 617
@@ -656,9 +647,7 @@ MODULE_DEVICE_TABLE(pcmcia, dtl1_ids);
656 647
657static struct pcmcia_driver dtl1_driver = { 648static struct pcmcia_driver dtl1_driver = {
658 .owner = THIS_MODULE, 649 .owner = THIS_MODULE,
659 .drv = { 650 .name = "dtl1_cs",
660 .name = "dtl1_cs",
661 },
662 .probe = dtl1_probe, 651 .probe = dtl1_probe,
663 .remove = dtl1_detach, 652 .remove = dtl1_detach,
664 .id_table = dtl1_ids, 653 .id_table = dtl1_ids,
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 998833d93c13..17361bad46dd 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -256,9 +256,16 @@ static int hci_uart_tty_open(struct tty_struct *tty)
256 256
257 BT_DBG("tty %p", tty); 257 BT_DBG("tty %p", tty);
258 258
259 /* FIXME: This btw is bogus, nothing requires the old ldisc to clear
260 the pointer */
259 if (hu) 261 if (hu)
260 return -EEXIST; 262 return -EEXIST;
261 263
264 /* Error if the tty has no write op instead of leaving an exploitable
265 hole */
266 if (tty->ops->write == NULL)
267 return -EOPNOTSUPP;
268
262 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) { 269 if (!(hu = kzalloc(sizeof(struct hci_uart), GFP_KERNEL))) {
263 BT_ERR("Can't allocate control structure"); 270 BT_ERR("Can't allocate control structure");
264 return -ENFILE; 271 return -ENFILE;
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 261107d1457c..3af6516919b7 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -34,7 +34,7 @@
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/smp_lock.h> 37#include <linux/mutex.h>
38#include <linux/wait.h> 38#include <linux/wait.h>
39#include <linux/workqueue.h> 39#include <linux/workqueue.h>
40#include <linux/platform_device.h> 40#include <linux/platform_device.h>
@@ -81,6 +81,7 @@
81 81
82#define GDROM_DEFAULT_TIMEOUT (HZ * 7) 82#define GDROM_DEFAULT_TIMEOUT (HZ * 7)
83 83
84static DEFINE_MUTEX(gdrom_mutex);
84static const struct { 85static const struct {
85 int sense_key; 86 int sense_key;
86 const char * const text; 87 const char * const text;
@@ -494,17 +495,17 @@ static struct cdrom_device_ops gdrom_ops = {
494static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode) 495static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
495{ 496{
496 int ret; 497 int ret;
497 lock_kernel(); 498 mutex_lock(&gdrom_mutex);
498 ret = cdrom_open(gd.cd_info, bdev, mode); 499 ret = cdrom_open(gd.cd_info, bdev, mode);
499 unlock_kernel(); 500 mutex_unlock(&gdrom_mutex);
500 return ret; 501 return ret;
501} 502}
502 503
503static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode) 504static int gdrom_bdops_release(struct gendisk *disk, fmode_t mode)
504{ 505{
505 lock_kernel(); 506 mutex_lock(&gdrom_mutex);
506 cdrom_release(gd.cd_info, mode); 507 cdrom_release(gd.cd_info, mode);
507 unlock_kernel(); 508 mutex_unlock(&gdrom_mutex);
508 return 0; 509 return 0;
509} 510}
510 511
@@ -518,9 +519,9 @@ static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode,
518{ 519{
519 int ret; 520 int ret;
520 521
521 lock_kernel(); 522 mutex_lock(&gdrom_mutex);
522 ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg); 523 ret = cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg);
523 unlock_kernel(); 524 mutex_unlock(&gdrom_mutex);
524 525
525 return ret; 526 return ret;
526} 527}
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 56bf9f44700c..be73a9b493a6 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -42,7 +42,7 @@
42#include <linux/module.h> 42#include <linux/module.h>
43#include <linux/completion.h> 43#include <linux/completion.h>
44#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
45#include <linux/smp_lock.h> 45#include <linux/mutex.h>
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/scatterlist.h> 47#include <linux/scatterlist.h>
48 48
@@ -61,6 +61,7 @@
61 */ 61 */
62#define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS 62#define VIOCD_MAX_CD HVMAXARCHITECTEDVIRTUALCDROMS
63 63
64static DEFINE_MUTEX(viocd_mutex);
64static const struct vio_error_entry viocd_err_table[] = { 65static const struct vio_error_entry viocd_err_table[] = {
65 {0x0201, EINVAL, "Invalid Range"}, 66 {0x0201, EINVAL, "Invalid Range"},
66 {0x0202, EINVAL, "Invalid Token"}, 67 {0x0202, EINVAL, "Invalid Token"},
@@ -156,9 +157,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
156 struct disk_info *di = bdev->bd_disk->private_data; 157 struct disk_info *di = bdev->bd_disk->private_data;
157 int ret; 158 int ret;
158 159
159 lock_kernel(); 160 mutex_lock(&viocd_mutex);
160 ret = cdrom_open(&di->viocd_info, bdev, mode); 161 ret = cdrom_open(&di->viocd_info, bdev, mode);
161 unlock_kernel(); 162 mutex_unlock(&viocd_mutex);
162 163
163 return ret; 164 return ret;
164} 165}
@@ -166,9 +167,9 @@ static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
166static int viocd_blk_release(struct gendisk *disk, fmode_t mode) 167static int viocd_blk_release(struct gendisk *disk, fmode_t mode)
167{ 168{
168 struct disk_info *di = disk->private_data; 169 struct disk_info *di = disk->private_data;
169 lock_kernel(); 170 mutex_lock(&viocd_mutex);
170 cdrom_release(&di->viocd_info, mode); 171 cdrom_release(&di->viocd_info, mode);
171 unlock_kernel(); 172 mutex_unlock(&viocd_mutex);
172 return 0; 173 return 0;
173} 174}
174 175
@@ -178,9 +179,9 @@ static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,
178 struct disk_info *di = bdev->bd_disk->private_data; 179 struct disk_info *di = bdev->bd_disk->private_data;
179 int ret; 180 int ret;
180 181
181 lock_kernel(); 182 mutex_lock(&viocd_mutex);
182 ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg); 183 ret = cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg);
183 unlock_kernel(); 184 mutex_unlock(&viocd_mutex);
184 185
185 return ret; 186 return ret;
186} 187}
diff --git a/drivers/char/agp/Kconfig b/drivers/char/agp/Kconfig
index 4b66c69eaf57..5ddf67e76f8b 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -57,7 +57,7 @@ config AGP_AMD
57 57
58config AGP_AMD64 58config AGP_AMD64
59 tristate "AMD Opteron/Athlon64 on-CPU GART support" 59 tristate "AMD Opteron/Athlon64 on-CPU GART support"
60 depends on AGP && X86 && K8_NB 60 depends on AGP && X86 && AMD_NB
61 help 61 help
62 This option gives you AGP support for the GLX component of 62 This option gives you AGP support for the GLX component of
63 X using the on-CPU northbridge of the AMD Athlon64/Opteron CPUs. 63 X using the on-CPU northbridge of the AMD Athlon64/Opteron CPUs.
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index 70312da4c968..42396df55556 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -15,7 +15,7 @@
15#include <linux/mmzone.h> 15#include <linux/mmzone.h>
16#include <asm/page.h> /* PAGE_SIZE */ 16#include <asm/page.h> /* PAGE_SIZE */
17#include <asm/e820.h> 17#include <asm/e820.h>
18#include <asm/k8.h> 18#include <asm/amd_nb.h>
19#include <asm/gart.h> 19#include <asm/gart.h>
20#include "agp.h" 20#include "agp.h"
21 21
@@ -124,7 +124,7 @@ static int amd64_fetch_size(void)
124 u32 temp; 124 u32 temp;
125 struct aper_size_info_32 *values; 125 struct aper_size_info_32 *values;
126 126
127 dev = k8_northbridges[0]; 127 dev = k8_northbridges.nb_misc[0];
128 if (dev==NULL) 128 if (dev==NULL)
129 return 0; 129 return 0;
130 130
@@ -181,10 +181,14 @@ static int amd_8151_configure(void)
181 unsigned long gatt_bus = virt_to_phys(agp_bridge->gatt_table_real); 181 unsigned long gatt_bus = virt_to_phys(agp_bridge->gatt_table_real);
182 int i; 182 int i;
183 183
184 if (!k8_northbridges.gart_supported)
185 return 0;
186
184 /* Configure AGP regs in each x86-64 host bridge. */ 187 /* Configure AGP regs in each x86-64 host bridge. */
185 for (i = 0; i < num_k8_northbridges; i++) { 188 for (i = 0; i < k8_northbridges.num; i++) {
186 agp_bridge->gart_bus_addr = 189 agp_bridge->gart_bus_addr =
187 amd64_configure(k8_northbridges[i], gatt_bus); 190 amd64_configure(k8_northbridges.nb_misc[i],
191 gatt_bus);
188 } 192 }
189 k8_flush_garts(); 193 k8_flush_garts();
190 return 0; 194 return 0;
@@ -195,11 +199,15 @@ static void amd64_cleanup(void)
195{ 199{
196 u32 tmp; 200 u32 tmp;
197 int i; 201 int i;
198 for (i = 0; i < num_k8_northbridges; i++) { 202
199 struct pci_dev *dev = k8_northbridges[i]; 203 if (!k8_northbridges.gart_supported)
204 return;
205
206 for (i = 0; i < k8_northbridges.num; i++) {
207 struct pci_dev *dev = k8_northbridges.nb_misc[i];
200 /* disable gart translation */ 208 /* disable gart translation */
201 pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &tmp); 209 pci_read_config_dword(dev, AMD64_GARTAPERTURECTL, &tmp);
202 tmp &= ~AMD64_GARTEN; 210 tmp &= ~GARTEN;
203 pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, tmp); 211 pci_write_config_dword(dev, AMD64_GARTAPERTURECTL, tmp);
204 } 212 }
205} 213}
@@ -313,22 +321,25 @@ static __devinit int fix_northbridge(struct pci_dev *nb, struct pci_dev *agp,
313 if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order)) 321 if (order < 0 || !agp_aperture_valid(aper, (32*1024*1024)<<order))
314 return -1; 322 return -1;
315 323
316 pci_write_config_dword(nb, AMD64_GARTAPERTURECTL, order << 1); 324 gart_set_size_and_enable(nb, order);
317 pci_write_config_dword(nb, AMD64_GARTAPERTUREBASE, aper >> 25); 325 pci_write_config_dword(nb, AMD64_GARTAPERTUREBASE, aper >> 25);
318 326
319 return 0; 327 return 0;
320} 328}
321 329
322static __devinit int cache_nbs (struct pci_dev *pdev, u32 cap_ptr) 330static __devinit int cache_nbs(struct pci_dev *pdev, u32 cap_ptr)
323{ 331{
324 int i; 332 int i;
325 333
326 if (cache_k8_northbridges() < 0) 334 if (cache_k8_northbridges() < 0)
327 return -ENODEV; 335 return -ENODEV;
328 336
337 if (!k8_northbridges.gart_supported)
338 return -ENODEV;
339
329 i = 0; 340 i = 0;
330 for (i = 0; i < num_k8_northbridges; i++) { 341 for (i = 0; i < k8_northbridges.num; i++) {
331 struct pci_dev *dev = k8_northbridges[i]; 342 struct pci_dev *dev = k8_northbridges.nb_misc[i];
332 if (fix_northbridge(dev, pdev, cap_ptr) < 0) { 343 if (fix_northbridge(dev, pdev, cap_ptr) < 0) {
333 dev_err(&dev->dev, "no usable aperture found\n"); 344 dev_err(&dev->dev, "no usable aperture found\n");
334#ifdef __x86_64__ 345#ifdef __x86_64__
@@ -405,7 +416,8 @@ static int __devinit uli_agp_init(struct pci_dev *pdev)
405 } 416 }
406 417
407 /* shadow x86-64 registers into ULi registers */ 418 /* shadow x86-64 registers into ULi registers */
408 pci_read_config_dword (k8_northbridges[0], AMD64_GARTAPERTUREBASE, &httfea); 419 pci_read_config_dword (k8_northbridges.nb_misc[0], AMD64_GARTAPERTUREBASE,
420 &httfea);
409 421
410 /* if x86-64 aperture base is beyond 4G, exit here */ 422 /* if x86-64 aperture base is beyond 4G, exit here */
411 if ((httfea & 0x7fff) >> (32 - 25)) { 423 if ((httfea & 0x7fff) >> (32 - 25)) {
@@ -472,7 +484,8 @@ static int nforce3_agp_init(struct pci_dev *pdev)
472 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, tmp); 484 pci_write_config_dword(dev1, NVIDIA_X86_64_1_APSIZE, tmp);
473 485
474 /* shadow x86-64 registers into NVIDIA registers */ 486 /* shadow x86-64 registers into NVIDIA registers */
475 pci_read_config_dword (k8_northbridges[0], AMD64_GARTAPERTUREBASE, &apbase); 487 pci_read_config_dword (k8_northbridges.nb_misc[0], AMD64_GARTAPERTUREBASE,
488 &apbase);
476 489
477 /* if x86-64 aperture base is beyond 4G, exit here */ 490 /* if x86-64 aperture base is beyond 4G, exit here */
478 if ( (apbase & 0x7fff) >> (32 - 25) ) { 491 if ( (apbase & 0x7fff) >> (32 - 25) ) {
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index d2abf5143983..64255cef8a7d 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -984,7 +984,9 @@ int agp_generic_create_gatt_table(struct agp_bridge_data *bridge)
984 984
985 bridge->driver->cache_flush(); 985 bridge->driver->cache_flush();
986#ifdef CONFIG_X86 986#ifdef CONFIG_X86
987 set_memory_uc((unsigned long)table, 1 << page_order); 987 if (set_memory_uc((unsigned long)table, 1 << page_order))
988 printk(KERN_WARNING "Could not set GATT table memory to UC!");
989
988 bridge->gatt_table = (void *)table; 990 bridge->gatt_table = (void *)table;
989#else 991#else
990 bridge->gatt_table = ioremap_nocache(virt_to_phys(table), 992 bridge->gatt_table = ioremap_nocache(virt_to_phys(table),
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index eab58db5f91c..cd18493c9527 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -806,6 +806,8 @@ static const struct intel_driver_description {
806 "G45/G43", NULL, &intel_i965_driver }, 806 "G45/G43", NULL, &intel_i965_driver },
807 { PCI_DEVICE_ID_INTEL_B43_HB, PCI_DEVICE_ID_INTEL_B43_IG, 807 { PCI_DEVICE_ID_INTEL_B43_HB, PCI_DEVICE_ID_INTEL_B43_IG,
808 "B43", NULL, &intel_i965_driver }, 808 "B43", NULL, &intel_i965_driver },
809 { PCI_DEVICE_ID_INTEL_B43_1_HB, PCI_DEVICE_ID_INTEL_B43_1_IG,
810 "B43", NULL, &intel_i965_driver },
809 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 811 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG,
810 "G41", NULL, &intel_i965_driver }, 812 "G41", NULL, &intel_i965_driver },
811 { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, 813 { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG,
diff --git a/drivers/char/agp/intel-agp.h b/drivers/char/agp/intel-agp.h
index ee189c74d345..d09b1ab7e8ab 100644
--- a/drivers/char/agp/intel-agp.h
+++ b/drivers/char/agp/intel-agp.h
@@ -186,6 +186,8 @@
186#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2 186#define PCI_DEVICE_ID_INTEL_Q33_IG 0x29D2
187#define PCI_DEVICE_ID_INTEL_B43_HB 0x2E40 187#define PCI_DEVICE_ID_INTEL_B43_HB 0x2E40
188#define PCI_DEVICE_ID_INTEL_B43_IG 0x2E42 188#define PCI_DEVICE_ID_INTEL_B43_IG 0x2E42
189#define PCI_DEVICE_ID_INTEL_B43_1_HB 0x2E90
190#define PCI_DEVICE_ID_INTEL_B43_1_IG 0x2E92
189#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40 191#define PCI_DEVICE_ID_INTEL_GM45_HB 0x2A40
190#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42 192#define PCI_DEVICE_ID_INTEL_GM45_IG 0x2A42
191#define PCI_DEVICE_ID_INTEL_EAGLELAKE_HB 0x2E00 193#define PCI_DEVICE_ID_INTEL_EAGLELAKE_HB 0x2E00
diff --git a/drivers/char/apm-emulation.c b/drivers/char/apm-emulation.c
index 5ffa6904ea6b..3022801669b1 100644
--- a/drivers/char/apm-emulation.c
+++ b/drivers/char/apm-emulation.c
@@ -13,7 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/poll.h> 14#include <linux/poll.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/smp_lock.h> 16#include <linux/mutex.h>
17#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
18#include <linux/seq_file.h> 18#include <linux/seq_file.h>
19#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
@@ -126,6 +126,7 @@ struct apm_user {
126/* 126/*
127 * Local variables 127 * Local variables
128 */ 128 */
129static DEFINE_MUTEX(apm_mutex);
129static atomic_t suspend_acks_pending = ATOMIC_INIT(0); 130static atomic_t suspend_acks_pending = ATOMIC_INIT(0);
130static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0); 131static atomic_t userspace_notification_inhibit = ATOMIC_INIT(0);
131static int apm_disabled; 132static int apm_disabled;
@@ -274,7 +275,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)
274 if (!as->suser || !as->writer) 275 if (!as->suser || !as->writer)
275 return -EPERM; 276 return -EPERM;
276 277
277 lock_kernel(); 278 mutex_lock(&apm_mutex);
278 switch (cmd) { 279 switch (cmd) {
279 case APM_IOC_SUSPEND: 280 case APM_IOC_SUSPEND:
280 mutex_lock(&state_lock); 281 mutex_lock(&state_lock);
@@ -335,7 +336,7 @@ apm_ioctl(struct file *filp, u_int cmd, u_long arg)
335 mutex_unlock(&state_lock); 336 mutex_unlock(&state_lock);
336 break; 337 break;
337 } 338 }
338 unlock_kernel(); 339 mutex_unlock(&apm_mutex);
339 340
340 return err; 341 return err;
341} 342}
@@ -370,7 +371,7 @@ static int apm_open(struct inode * inode, struct file * filp)
370{ 371{
371 struct apm_user *as; 372 struct apm_user *as;
372 373
373 lock_kernel(); 374 mutex_lock(&apm_mutex);
374 as = kzalloc(sizeof(*as), GFP_KERNEL); 375 as = kzalloc(sizeof(*as), GFP_KERNEL);
375 if (as) { 376 if (as) {
376 /* 377 /*
@@ -390,7 +391,7 @@ static int apm_open(struct inode * inode, struct file * filp)
390 391
391 filp->private_data = as; 392 filp->private_data = as;
392 } 393 }
393 unlock_kernel(); 394 mutex_unlock(&apm_mutex);
394 395
395 return as ? 0 : -ENOMEM; 396 return as ? 0 : -ENOMEM;
396} 397}
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index f4ae0e0fb631..e7ba774beda6 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -26,7 +26,7 @@
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
29#include <linux/smp_lock.h> 29#include <linux/mutex.h>
30#include <linux/miscdevice.h> 30#include <linux/miscdevice.h>
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/wait.h> 32#include <linux/wait.h>
@@ -60,6 +60,7 @@
60#define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003 60#define PCI_DEVICE_ID_APPLICOM_PCI2000PFB 0x0003
61#endif 61#endif
62 62
63static DEFINE_MUTEX(ac_mutex);
63static char *applicom_pci_devnames[] = { 64static char *applicom_pci_devnames[] = {
64 "PCI board", 65 "PCI board",
65 "PCI2000IBS / PCI2000CAN", 66 "PCI2000IBS / PCI2000CAN",
@@ -707,7 +708,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
707 if (IS_ERR(adgl)) 708 if (IS_ERR(adgl))
708 return PTR_ERR(adgl); 709 return PTR_ERR(adgl);
709 710
710 lock_kernel(); 711 mutex_lock(&ac_mutex);
711 IndexCard = adgl->num_card-1; 712 IndexCard = adgl->num_card-1;
712 713
713 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) { 714 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
@@ -717,7 +718,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
717 warncount--; 718 warncount--;
718 } 719 }
719 kfree(adgl); 720 kfree(adgl);
720 unlock_kernel(); 721 mutex_unlock(&ac_mutex);
721 return -EINVAL; 722 return -EINVAL;
722 } 723 }
723 724
@@ -835,7 +836,7 @@ static long ac_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
835 } 836 }
836 Dummy = readb(apbs[IndexCard].RamIO + VERS); 837 Dummy = readb(apbs[IndexCard].RamIO + VERS);
837 kfree(adgl); 838 kfree(adgl);
838 unlock_kernel(); 839 mutex_unlock(&ac_mutex);
839 return 0; 840 return 0;
840} 841}
841 842
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c
index 4f7aa364167c..ed8303f9890c 100644
--- a/drivers/char/ds1302.c
+++ b/drivers/char/ds1302.c
@@ -20,7 +20,7 @@
20#include <linux/miscdevice.h> 20#include <linux/miscdevice.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/bcd.h> 22#include <linux/bcd.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25#include <linux/io.h> 25#include <linux/io.h>
26 26
@@ -32,6 +32,7 @@
32 32
33#define RTC_MAJOR_NR 121 /* local major, change later */ 33#define RTC_MAJOR_NR 121 /* local major, change later */
34 34
35static DEFINE_MUTEX(rtc_mutex);
35static const char ds1302_name[] = "ds1302"; 36static const char ds1302_name[] = "ds1302";
36 37
37/* Send 8 bits. */ 38/* Send 8 bits. */
@@ -164,9 +165,9 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
164 struct rtc_time rtc_tm; 165 struct rtc_time rtc_tm;
165 166
166 memset(&rtc_tm, 0, sizeof (struct rtc_time)); 167 memset(&rtc_tm, 0, sizeof (struct rtc_time));
167 lock_kernel(); 168 mutex_lock(&rtc_mutex);
168 get_rtc_time(&rtc_tm); 169 get_rtc_time(&rtc_tm);
169 unlock_kernel(); 170 mutex_unlock(&rtc_mutex);
170 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time))) 171 if (copy_to_user((struct rtc_time*)arg, &rtc_tm, sizeof(struct rtc_time)))
171 return -EFAULT; 172 return -EFAULT;
172 return 0; 173 return 0;
@@ -218,7 +219,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
218 mon = bin2bcd(mon); 219 mon = bin2bcd(mon);
219 yrs = bin2bcd(yrs); 220 yrs = bin2bcd(yrs);
220 221
221 lock_kernel(); 222 mutex_lock(&rtc_mutex);
222 local_irq_save(flags); 223 local_irq_save(flags);
223 CMOS_WRITE(yrs, RTC_YEAR); 224 CMOS_WRITE(yrs, RTC_YEAR);
224 CMOS_WRITE(mon, RTC_MONTH); 225 CMOS_WRITE(mon, RTC_MONTH);
@@ -227,7 +228,7 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
227 CMOS_WRITE(min, RTC_MINUTES); 228 CMOS_WRITE(min, RTC_MINUTES);
228 CMOS_WRITE(sec, RTC_SECONDS); 229 CMOS_WRITE(sec, RTC_SECONDS);
229 local_irq_restore(flags); 230 local_irq_restore(flags);
230 unlock_kernel(); 231 mutex_unlock(&rtc_mutex);
231 232
232 /* Notice that at this point, the RTC is updated but 233 /* Notice that at this point, the RTC is updated but
233 * the kernel is still running with the old time. 234 * the kernel is still running with the old time.
@@ -247,10 +248,10 @@ static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
247 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int))) 248 if(copy_from_user(&tcs_val, (int*)arg, sizeof(int)))
248 return -EFAULT; 249 return -EFAULT;
249 250
250 lock_kernel(); 251 mutex_lock(&rtc_mutex);
251 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F); 252 tcs_val = RTC_TCR_PATTERN | (tcs_val & 0x0F);
252 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val); 253 ds1302_writereg(RTC_TRICKLECHARGER, tcs_val);
253 unlock_kernel(); 254 mutex_unlock(&rtc_mutex);
254 return 0; 255 return 0;
255 } 256 }
256 default: 257 default:
diff --git a/drivers/char/ds1620.c b/drivers/char/ds1620.c
index 50462b63e51b..aab9605f0b43 100644
--- a/drivers/char/ds1620.c
+++ b/drivers/char/ds1620.c
@@ -8,7 +8,7 @@
8#include <linux/proc_fs.h> 8#include <linux/proc_fs.h>
9#include <linux/capability.h> 9#include <linux/capability.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/smp_lock.h> 11#include <linux/mutex.h>
12 12
13#include <mach/hardware.h> 13#include <mach/hardware.h>
14#include <asm/mach-types.h> 14#include <asm/mach-types.h>
@@ -34,6 +34,7 @@
34#define CFG_CPU 2 34#define CFG_CPU 2
35#define CFG_1SHOT 1 35#define CFG_1SHOT 1
36 36
37static DEFINE_MUTEX(ds1620_mutex);
37static const char *fan_state[] = { "off", "on", "on (hardwired)" }; 38static const char *fan_state[] = { "off", "on", "on (hardwired)" };
38 39
39/* 40/*
@@ -210,7 +211,6 @@ static void ds1620_read_state(struct therm *therm)
210 211
211static int ds1620_open(struct inode *inode, struct file *file) 212static int ds1620_open(struct inode *inode, struct file *file)
212{ 213{
213 cycle_kernel_lock();
214 return nonseekable_open(inode, file); 214 return nonseekable_open(inode, file);
215} 215}
216 216
@@ -321,9 +321,9 @@ ds1620_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
321{ 321{
322 int ret; 322 int ret;
323 323
324 lock_kernel(); 324 mutex_lock(&ds1620_mutex);
325 ret = ds1620_ioctl(file, cmd, arg); 325 ret = ds1620_ioctl(file, cmd, arg);
326 unlock_kernel(); 326 mutex_unlock(&ds1620_mutex);
327 327
328 return ret; 328 return ret;
329} 329}
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 353be4707d92..052797b32bd3 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -32,7 +32,7 @@
32#include <linux/mm.h> 32#include <linux/mm.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/device.h> 34#include <linux/device.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/firmware.h> 36#include <linux/firmware.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38#include <linux/uaccess.h> /* For put_user and get_user */ 38#include <linux/uaccess.h> /* For put_user and get_user */
@@ -94,6 +94,7 @@
94 } \ 94 } \
95} 95}
96 96
97static DEFINE_MUTEX(dsp56k_mutex);
97static struct dsp56k_device { 98static struct dsp56k_device {
98 unsigned long in_use; 99 unsigned long in_use;
99 long maxio, timeout; 100 long maxio, timeout;
@@ -330,9 +331,9 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
330 if (len > DSP56K_MAX_BINARY_LENGTH) { 331 if (len > DSP56K_MAX_BINARY_LENGTH) {
331 return -EINVAL; 332 return -EINVAL;
332 } 333 }
333 lock_kernel(); 334 mutex_lock(&dsp56k_mutex);
334 r = dsp56k_upload(bin, len); 335 r = dsp56k_upload(bin, len);
335 unlock_kernel(); 336 mutex_unlock(&dsp56k_mutex);
336 if (r < 0) { 337 if (r < 0) {
337 return r; 338 return r;
338 } 339 }
@@ -342,16 +343,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
342 case DSP56K_SET_TX_WSIZE: 343 case DSP56K_SET_TX_WSIZE:
343 if (arg > 4 || arg < 1) 344 if (arg > 4 || arg < 1)
344 return -EINVAL; 345 return -EINVAL;
345 lock_kernel(); 346 mutex_lock(&dsp56k_mutex);
346 dsp56k.tx_wsize = (int) arg; 347 dsp56k.tx_wsize = (int) arg;
347 unlock_kernel(); 348 mutex_unlock(&dsp56k_mutex);
348 break; 349 break;
349 case DSP56K_SET_RX_WSIZE: 350 case DSP56K_SET_RX_WSIZE:
350 if (arg > 4 || arg < 1) 351 if (arg > 4 || arg < 1)
351 return -EINVAL; 352 return -EINVAL;
352 lock_kernel(); 353 mutex_lock(&dsp56k_mutex);
353 dsp56k.rx_wsize = (int) arg; 354 dsp56k.rx_wsize = (int) arg;
354 unlock_kernel(); 355 mutex_unlock(&dsp56k_mutex);
355 break; 356 break;
356 case DSP56K_HOST_FLAGS: 357 case DSP56K_HOST_FLAGS:
357 { 358 {
@@ -363,7 +364,7 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
363 if(get_user(out, &hf->out) < 0) 364 if(get_user(out, &hf->out) < 0)
364 return -EFAULT; 365 return -EFAULT;
365 366
366 lock_kernel(); 367 mutex_lock(&dsp56k_mutex);
367 if ((dir & 0x1) && (out & 0x1)) 368 if ((dir & 0x1) && (out & 0x1))
368 dsp56k_host_interface.icr |= DSP56K_ICR_HF0; 369 dsp56k_host_interface.icr |= DSP56K_ICR_HF0;
369 else if (dir & 0x1) 370 else if (dir & 0x1)
@@ -378,16 +379,16 @@ static long dsp56k_ioctl(struct file *file, unsigned int cmd,
378 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2; 379 if (dsp56k_host_interface.icr & DSP56K_ICR_HF1) status |= 0x2;
379 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4; 380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF2) status |= 0x4;
380 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8; 381 if (dsp56k_host_interface.isr & DSP56K_ISR_HF3) status |= 0x8;
381 unlock_kernel(); 382 mutex_unlock(&dsp56k_mutex);
382 return put_user(status, &hf->status); 383 return put_user(status, &hf->status);
383 } 384 }
384 case DSP56K_HOST_CMD: 385 case DSP56K_HOST_CMD:
385 if (arg > 31 || arg < 0) 386 if (arg > 31 || arg < 0)
386 return -EINVAL; 387 return -EINVAL;
387 lock_kernel(); 388 mutex_lock(&dsp56k_mutex);
388 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) | 389 dsp56k_host_interface.cvr = (u_char)((arg & DSP56K_CVR_HV_MASK) |
389 DSP56K_CVR_HC); 390 DSP56K_CVR_HC);
390 unlock_kernel(); 391 mutex_unlock(&dsp56k_mutex);
391 break; 392 break;
392 default: 393 default:
393 return -EINVAL; 394 return -EINVAL;
@@ -427,7 +428,7 @@ static int dsp56k_open(struct inode *inode, struct file *file)
427 int dev = iminor(inode) & 0x0f; 428 int dev = iminor(inode) & 0x0f;
428 int ret = 0; 429 int ret = 0;
429 430
430 lock_kernel(); 431 mutex_lock(&dsp56k_mutex);
431 switch(dev) 432 switch(dev)
432 { 433 {
433 case DSP56K_DEV_56001: 434 case DSP56K_DEV_56001:
@@ -454,7 +455,7 @@ static int dsp56k_open(struct inode *inode, struct file *file)
454 ret = -ENODEV; 455 ret = -ENODEV;
455 } 456 }
456out: 457out:
457 unlock_kernel(); 458 mutex_unlock(&dsp56k_mutex);
458 return ret; 459 return ret;
459} 460}
460 461
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index 007eca3ed77c..85156dd0caee 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -57,7 +57,7 @@
57#include <linux/ioport.h> /* for request_region */ 57#include <linux/ioport.h> /* for request_region */
58#include <linux/delay.h> /* for loops_per_jiffy */ 58#include <linux/delay.h> /* for loops_per_jiffy */
59#include <linux/sched.h> 59#include <linux/sched.h>
60#include <linux/smp_lock.h> /* cycle_kernel_lock() */ 60#include <linux/mutex.h>
61#include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */ 61#include <asm/io.h> /* for inb_p, outb_p, inb, outb, etc. */
62#include <asm/uaccess.h> /* for get_user, etc. */ 62#include <asm/uaccess.h> /* for get_user, etc. */
63#include <linux/wait.h> /* for wait_queue */ 63#include <linux/wait.h> /* for wait_queue */
@@ -73,6 +73,7 @@
73#define TRACE_RET ((void) 0) 73#define TRACE_RET ((void) 0)
74#endif /* TRACING */ 74#endif /* TRACING */
75 75
76static DEFINE_MUTEX(dtlk_mutex);
76static void dtlk_timer_tick(unsigned long data); 77static void dtlk_timer_tick(unsigned long data);
77 78
78static int dtlk_major; 79static int dtlk_major;
@@ -276,9 +277,9 @@ static long dtlk_ioctl(struct file *file,
276 switch (cmd) { 277 switch (cmd) {
277 278
278 case DTLK_INTERROGATE: 279 case DTLK_INTERROGATE:
279 lock_kernel(); 280 mutex_lock(&dtlk_mutex);
280 sp = dtlk_interrogate(); 281 sp = dtlk_interrogate();
281 unlock_kernel(); 282 mutex_unlock(&dtlk_mutex);
282 if (copy_to_user(argp, sp, sizeof(struct dtlk_settings))) 283 if (copy_to_user(argp, sp, sizeof(struct dtlk_settings)))
283 return -EINVAL; 284 return -EINVAL;
284 return 0; 285 return 0;
@@ -297,7 +298,6 @@ static int dtlk_open(struct inode *inode, struct file *file)
297{ 298{
298 TRACE_TEXT("(dtlk_open"); 299 TRACE_TEXT("(dtlk_open");
299 300
300 cycle_kernel_lock();
301 nonseekable_open(inode, file); 301 nonseekable_open(inode, file);
302 switch (iminor(inode)) { 302 switch (iminor(inode)) {
303 case DTLK_MINOR: 303 case DTLK_MINOR:
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 82b5a88a82d7..0e941b57482e 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -19,7 +19,7 @@
19#include <linux/miscdevice.h> 19#include <linux/miscdevice.h>
20#include <linux/fcntl.h> 20#include <linux/fcntl.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/smp_lock.h> 22#include <linux/mutex.h>
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <asm/nvram.h> 24#include <asm/nvram.h>
25#ifdef CONFIG_PPC_PMAC 25#ifdef CONFIG_PPC_PMAC
@@ -28,6 +28,7 @@
28 28
29#define NVRAM_SIZE 8192 29#define NVRAM_SIZE 8192
30 30
31static DEFINE_MUTEX(nvram_mutex);
31static ssize_t nvram_len; 32static ssize_t nvram_len;
32 33
33static loff_t nvram_llseek(struct file *file, loff_t offset, int origin) 34static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
@@ -120,9 +121,9 @@ static long nvram_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned l
120{ 121{
121 int ret; 122 int ret;
122 123
123 lock_kernel(); 124 mutex_lock(&nvram_mutex);
124 ret = nvram_ioctl(file, cmd, arg); 125 ret = nvram_ioctl(file, cmd, arg);
125 unlock_kernel(); 126 mutex_unlock(&nvram_mutex);
126 127
127 return ret; 128 return ret;
128} 129}
diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index eaa0e4264e16..f773a9dd14f3 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -52,7 +52,7 @@
52#include <linux/init.h> 52#include <linux/init.h>
53#include <linux/poll.h> 53#include <linux/poll.h>
54#include <linux/proc_fs.h> 54#include <linux/proc_fs.h>
55#include <linux/smp_lock.h> 55#include <linux/mutex.h>
56#include <linux/workqueue.h> 56#include <linux/workqueue.h>
57 57
58#include <asm/uaccess.h> 58#include <asm/uaccess.h>
@@ -66,6 +66,7 @@
66 * ioctls. 66 * ioctls.
67 */ 67 */
68 68
69static DEFINE_MUTEX(gen_rtc_mutex);
69static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait); 70static DECLARE_WAIT_QUEUE_HEAD(gen_rtc_wait);
70 71
71/* 72/*
@@ -337,9 +338,9 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,
337{ 338{
338 int ret; 339 int ret;
339 340
340 lock_kernel(); 341 mutex_lock(&gen_rtc_mutex);
341 ret = gen_rtc_ioctl(file, cmd, arg); 342 ret = gen_rtc_ioctl(file, cmd, arg);
342 unlock_kernel(); 343 mutex_unlock(&gen_rtc_mutex);
343 344
344 return ret; 345 return ret;
345} 346}
@@ -352,16 +353,16 @@ static long gen_rtc_unlocked_ioctl(struct file *file, unsigned int cmd,
352 353
353static int gen_rtc_open(struct inode *inode, struct file *file) 354static int gen_rtc_open(struct inode *inode, struct file *file)
354{ 355{
355 lock_kernel(); 356 mutex_lock(&gen_rtc_mutex);
356 if (gen_rtc_status & RTC_IS_OPEN) { 357 if (gen_rtc_status & RTC_IS_OPEN) {
357 unlock_kernel(); 358 mutex_unlock(&gen_rtc_mutex);
358 return -EBUSY; 359 return -EBUSY;
359 } 360 }
360 361
361 gen_rtc_status |= RTC_IS_OPEN; 362 gen_rtc_status |= RTC_IS_OPEN;
362 gen_rtc_irq_data = 0; 363 gen_rtc_irq_data = 0;
363 irq_active = 0; 364 irq_active = 0;
364 unlock_kernel(); 365 mutex_unlock(&gen_rtc_mutex);
365 366
366 return 0; 367 return 0;
367} 368}
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index a0a1829d3198..a4eee324eb1e 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -30,6 +30,7 @@
30#include <linux/bcd.h> 30#include <linux/bcd.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/bitops.h> 32#include <linux/bitops.h>
33#include <linux/compat.h>
33#include <linux/clocksource.h> 34#include <linux/clocksource.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35 36
@@ -67,6 +68,7 @@
67#define read_counter(MC) readl(MC) 68#define read_counter(MC) readl(MC)
68#endif 69#endif
69 70
71static DEFINE_MUTEX(hpet_mutex); /* replaces BKL */
70static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ; 72static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
71 73
72/* This clocksource driver currently only works on ia64 */ 74/* This clocksource driver currently only works on ia64 */
@@ -250,7 +252,7 @@ static int hpet_open(struct inode *inode, struct file *file)
250 if (file->f_mode & FMODE_WRITE) 252 if (file->f_mode & FMODE_WRITE)
251 return -EINVAL; 253 return -EINVAL;
252 254
253 lock_kernel(); 255 mutex_lock(&hpet_mutex);
254 spin_lock_irq(&hpet_lock); 256 spin_lock_irq(&hpet_lock);
255 257
256 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next) 258 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
@@ -264,7 +266,7 @@ static int hpet_open(struct inode *inode, struct file *file)
264 266
265 if (!devp) { 267 if (!devp) {
266 spin_unlock_irq(&hpet_lock); 268 spin_unlock_irq(&hpet_lock);
267 unlock_kernel(); 269 mutex_unlock(&hpet_mutex);
268 return -EBUSY; 270 return -EBUSY;
269 } 271 }
270 272
@@ -272,7 +274,7 @@ static int hpet_open(struct inode *inode, struct file *file)
272 devp->hd_irqdata = 0; 274 devp->hd_irqdata = 0;
273 devp->hd_flags |= HPET_OPEN; 275 devp->hd_flags |= HPET_OPEN;
274 spin_unlock_irq(&hpet_lock); 276 spin_unlock_irq(&hpet_lock);
275 unlock_kernel(); 277 mutex_unlock(&hpet_mutex);
276 278
277 hpet_timer_set_irq(devp); 279 hpet_timer_set_irq(devp);
278 280
@@ -429,22 +431,6 @@ static int hpet_release(struct inode *inode, struct file *file)
429 return 0; 431 return 0;
430} 432}
431 433
432static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
433
434static long hpet_ioctl(struct file *file, unsigned int cmd,
435 unsigned long arg)
436{
437 struct hpet_dev *devp;
438 int ret;
439
440 devp = file->private_data;
441 lock_kernel();
442 ret = hpet_ioctl_common(devp, cmd, arg, 0);
443 unlock_kernel();
444
445 return ret;
446}
447
448static int hpet_ioctl_ieon(struct hpet_dev *devp) 434static int hpet_ioctl_ieon(struct hpet_dev *devp)
449{ 435{
450 struct hpet_timer __iomem *timer; 436 struct hpet_timer __iomem *timer;
@@ -553,7 +539,8 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
553} 539}
554 540
555static int 541static int
556hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel) 542hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
543 struct hpet_info *info)
557{ 544{
558 struct hpet_timer __iomem *timer; 545 struct hpet_timer __iomem *timer;
559 struct hpet __iomem *hpet; 546 struct hpet __iomem *hpet;
@@ -594,23 +581,15 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
594 break; 581 break;
595 case HPET_INFO: 582 case HPET_INFO:
596 { 583 {
597 struct hpet_info info;
598
599 if (devp->hd_ireqfreq) 584 if (devp->hd_ireqfreq)
600 info.hi_ireqfreq = 585 info->hi_ireqfreq =
601 hpet_time_div(hpetp, devp->hd_ireqfreq); 586 hpet_time_div(hpetp, devp->hd_ireqfreq);
602 else 587 else
603 info.hi_ireqfreq = 0; 588 info->hi_ireqfreq = 0;
604 info.hi_flags = 589 info->hi_flags =
605 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK; 590 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
606 info.hi_hpet = hpetp->hp_which; 591 info->hi_hpet = hpetp->hp_which;
607 info.hi_timer = devp - hpetp->hp_dev; 592 info->hi_timer = devp - hpetp->hp_dev;
608 if (kernel)
609 memcpy((void *)arg, &info, sizeof(info));
610 else
611 if (copy_to_user((void __user *)arg, &info,
612 sizeof(info)))
613 err = -EFAULT;
614 break; 593 break;
615 } 594 }
616 case HPET_EPI: 595 case HPET_EPI:
@@ -636,7 +615,7 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
636 devp->hd_flags &= ~HPET_PERIODIC; 615 devp->hd_flags &= ~HPET_PERIODIC;
637 break; 616 break;
638 case HPET_IRQFREQ: 617 case HPET_IRQFREQ:
639 if (!kernel && (arg > hpet_max_freq) && 618 if ((arg > hpet_max_freq) &&
640 !capable(CAP_SYS_RESOURCE)) { 619 !capable(CAP_SYS_RESOURCE)) {
641 err = -EACCES; 620 err = -EACCES;
642 break; 621 break;
@@ -653,12 +632,63 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
653 return err; 632 return err;
654} 633}
655 634
635static long
636hpet_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
637{
638 struct hpet_info info;
639 int err;
640
641 mutex_lock(&hpet_mutex);
642 err = hpet_ioctl_common(file->private_data, cmd, arg, &info);
643 mutex_unlock(&hpet_mutex);
644
645 if ((cmd == HPET_INFO) && !err &&
646 (copy_to_user((void __user *)arg, &info, sizeof(info))))
647 err = -EFAULT;
648
649 return err;
650}
651
652#ifdef CONFIG_COMPAT
653struct compat_hpet_info {
654 compat_ulong_t hi_ireqfreq; /* Hz */
655 compat_ulong_t hi_flags; /* information */
656 unsigned short hi_hpet;
657 unsigned short hi_timer;
658};
659
660static long
661hpet_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
662{
663 struct hpet_info info;
664 int err;
665
666 mutex_lock(&hpet_mutex);
667 err = hpet_ioctl_common(file->private_data, cmd, arg, &info);
668 mutex_unlock(&hpet_mutex);
669
670 if ((cmd == HPET_INFO) && !err) {
671 struct compat_hpet_info __user *u = compat_ptr(arg);
672 if (put_user(info.hi_ireqfreq, &u->hi_ireqfreq) ||
673 put_user(info.hi_flags, &u->hi_flags) ||
674 put_user(info.hi_hpet, &u->hi_hpet) ||
675 put_user(info.hi_timer, &u->hi_timer))
676 err = -EFAULT;
677 }
678
679 return err;
680}
681#endif
682
656static const struct file_operations hpet_fops = { 683static const struct file_operations hpet_fops = {
657 .owner = THIS_MODULE, 684 .owner = THIS_MODULE,
658 .llseek = no_llseek, 685 .llseek = no_llseek,
659 .read = hpet_read, 686 .read = hpet_read,
660 .poll = hpet_poll, 687 .poll = hpet_poll,
661 .unlocked_ioctl = hpet_ioctl, 688 .unlocked_ioctl = hpet_ioctl,
689#ifdef CONFIG_COMPAT
690 .compat_ioctl = hpet_compat_ioctl,
691#endif
662 .open = hpet_open, 692 .open = hpet_open,
663 .release = hpet_release, 693 .release = hpet_release,
664 .fasync = hpet_fasync, 694 .fasync = hpet_fasync,
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 4cd8b227c11f..3bc0eef88717 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -23,7 +23,7 @@
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/dmi.h> 24#include <linux/dmi.h>
25#include <linux/capability.h> 25#include <linux/capability.h>
26#include <linux/smp_lock.h> 26#include <linux/mutex.h>
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/io.h> 28#include <asm/io.h>
29 29
@@ -56,6 +56,7 @@
56 56
57#define I8K_TEMPERATURE_BUG 1 57#define I8K_TEMPERATURE_BUG 1
58 58
59static DEFINE_MUTEX(i8k_mutex);
59static char bios_version[4]; 60static char bios_version[4];
60 61
61MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)"); 62MODULE_AUTHOR("Massimo Dal Zotto (dz@debian.org)");
@@ -399,9 +400,9 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
399{ 400{
400 long ret; 401 long ret;
401 402
402 lock_kernel(); 403 mutex_lock(&i8k_mutex);
403 ret = i8k_ioctl_unlocked(fp, cmd, arg); 404 ret = i8k_ioctl_unlocked(fp, cmd, arg);
404 unlock_kernel(); 405 mutex_unlock(&i8k_mutex);
405 406
406 return ret; 407 return ret;
407} 408}
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 2e49e515d8e7..64a439ce2f89 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -98,7 +98,7 @@
98#include <linux/major.h> 98#include <linux/major.h>
99#include <linux/wait.h> 99#include <linux/wait.h>
100#include <linux/device.h> 100#include <linux/device.h>
101#include <linux/smp_lock.h> 101#include <linux/mutex.h>
102#include <linux/firmware.h> 102#include <linux/firmware.h>
103#include <linux/platform_device.h> 103#include <linux/platform_device.h>
104 104
@@ -138,6 +138,7 @@
138#include <linux/proc_fs.h> 138#include <linux/proc_fs.h>
139#include <linux/seq_file.h> 139#include <linux/seq_file.h>
140 140
141static DEFINE_MUTEX(ip2_mutex);
141static const struct file_operations ip2mem_proc_fops; 142static const struct file_operations ip2mem_proc_fops;
142static const struct file_operations ip2_proc_fops; 143static const struct file_operations ip2_proc_fops;
143 144
@@ -2898,7 +2899,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2898 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg ); 2899 printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
2899#endif 2900#endif
2900 2901
2901 lock_kernel(); 2902 mutex_lock(&ip2_mutex);
2902 2903
2903 switch ( iplminor ) { 2904 switch ( iplminor ) {
2904 case 0: // IPL device 2905 case 0: // IPL device
@@ -2962,7 +2963,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2962 rc = -ENODEV; 2963 rc = -ENODEV;
2963 break; 2964 break;
2964 } 2965 }
2965 unlock_kernel(); 2966 mutex_unlock(&ip2_mutex);
2966 return rc; 2967 return rc;
2967} 2968}
2968 2969
@@ -2983,7 +2984,6 @@ ip2_ipl_open( struct inode *pInode, struct file *pFile )
2983#ifdef IP2DEBUG_IPL 2984#ifdef IP2DEBUG_IPL
2984 printk (KERN_DEBUG "IP2IPL: open\n" ); 2985 printk (KERN_DEBUG "IP2IPL: open\n" );
2985#endif 2986#endif
2986 cycle_kernel_lock();
2987 return 0; 2987 return 0;
2988} 2988}
2989 2989
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index c6709d6b0fd0..1fc8876af1f5 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -44,7 +44,6 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/compat.h> 46#include <linux/compat.h>
47#include <linux/smp_lock.h>
48 47
49struct ipmi_file_private 48struct ipmi_file_private
50{ 49{
@@ -59,6 +58,7 @@ struct ipmi_file_private
59 unsigned int default_retry_time_ms; 58 unsigned int default_retry_time_ms;
60}; 59};
61 60
61static DEFINE_MUTEX(ipmi_mutex);
62static void file_receive_handler(struct ipmi_recv_msg *msg, 62static void file_receive_handler(struct ipmi_recv_msg *msg,
63 void *handler_data) 63 void *handler_data)
64{ 64{
@@ -102,9 +102,9 @@ static int ipmi_fasync(int fd, struct file *file, int on)
102 struct ipmi_file_private *priv = file->private_data; 102 struct ipmi_file_private *priv = file->private_data;
103 int result; 103 int result;
104 104
105 lock_kernel(); /* could race against open() otherwise */ 105 mutex_lock(&ipmi_mutex); /* could race against open() otherwise */
106 result = fasync_helper(fd, file, on, &priv->fasync_queue); 106 result = fasync_helper(fd, file, on, &priv->fasync_queue);
107 unlock_kernel(); 107 mutex_unlock(&ipmi_mutex);
108 108
109 return (result); 109 return (result);
110} 110}
@@ -125,7 +125,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
125 if (!priv) 125 if (!priv)
126 return -ENOMEM; 126 return -ENOMEM;
127 127
128 lock_kernel(); 128 mutex_lock(&ipmi_mutex);
129 priv->file = file; 129 priv->file = file;
130 130
131 rv = ipmi_create_user(if_num, 131 rv = ipmi_create_user(if_num,
@@ -150,7 +150,7 @@ static int ipmi_open(struct inode *inode, struct file *file)
150 priv->default_retry_time_ms = 0; 150 priv->default_retry_time_ms = 0;
151 151
152out: 152out:
153 unlock_kernel(); 153 mutex_unlock(&ipmi_mutex);
154 return rv; 154 return rv;
155} 155}
156 156
@@ -639,9 +639,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
639{ 639{
640 int ret; 640 int ret;
641 641
642 lock_kernel(); 642 mutex_lock(&ipmi_mutex);
643 ret = ipmi_ioctl(file, cmd, data); 643 ret = ipmi_ioctl(file, cmd, data);
644 unlock_kernel(); 644 mutex_unlock(&ipmi_mutex);
645 645
646 return ret; 646 return ret;
647} 647}
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 3822b4f49c84..7bd7c45b53ef 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -305,6 +305,9 @@ static int num_force_kipmid;
305#ifdef CONFIG_PCI 305#ifdef CONFIG_PCI
306static int pci_registered; 306static int pci_registered;
307#endif 307#endif
308#ifdef CONFIG_ACPI
309static int pnp_registered;
310#endif
308#ifdef CONFIG_PPC_OF 311#ifdef CONFIG_PPC_OF
309static int of_registered; 312static int of_registered;
310#endif 313#endif
@@ -2126,7 +2129,7 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2126{ 2129{
2127 struct acpi_device *acpi_dev; 2130 struct acpi_device *acpi_dev;
2128 struct smi_info *info; 2131 struct smi_info *info;
2129 struct resource *res; 2132 struct resource *res, *res_second;
2130 acpi_handle handle; 2133 acpi_handle handle;
2131 acpi_status status; 2134 acpi_status status;
2132 unsigned long long tmp; 2135 unsigned long long tmp;
@@ -2182,13 +2185,13 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,
2182 info->io.addr_data = res->start; 2185 info->io.addr_data = res->start;
2183 2186
2184 info->io.regspacing = DEFAULT_REGSPACING; 2187 info->io.regspacing = DEFAULT_REGSPACING;
2185 res = pnp_get_resource(dev, 2188 res_second = pnp_get_resource(dev,
2186 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? 2189 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ?
2187 IORESOURCE_IO : IORESOURCE_MEM, 2190 IORESOURCE_IO : IORESOURCE_MEM,
2188 1); 2191 1);
2189 if (res) { 2192 if (res_second) {
2190 if (res->start > info->io.addr_data) 2193 if (res_second->start > info->io.addr_data)
2191 info->io.regspacing = res->start - info->io.addr_data; 2194 info->io.regspacing = res_second->start - info->io.addr_data;
2192 } 2195 }
2193 info->io.regsize = DEFAULT_REGSPACING; 2196 info->io.regsize = DEFAULT_REGSPACING;
2194 info->io.regshift = 0; 2197 info->io.regshift = 0;
@@ -3359,6 +3362,7 @@ static __devinit int init_ipmi_si(void)
3359 3362
3360#ifdef CONFIG_ACPI 3363#ifdef CONFIG_ACPI
3361 pnp_register_driver(&ipmi_pnp_driver); 3364 pnp_register_driver(&ipmi_pnp_driver);
3365 pnp_registered = 1;
3362#endif 3366#endif
3363 3367
3364#ifdef CONFIG_DMI 3368#ifdef CONFIG_DMI
@@ -3526,7 +3530,8 @@ static __exit void cleanup_ipmi_si(void)
3526 pci_unregister_driver(&ipmi_pci_driver); 3530 pci_unregister_driver(&ipmi_pci_driver);
3527#endif 3531#endif
3528#ifdef CONFIG_ACPI 3532#ifdef CONFIG_ACPI
3529 pnp_unregister_driver(&ipmi_pnp_driver); 3533 if (pnp_registered)
3534 pnp_unregister_driver(&ipmi_pnp_driver);
3530#endif 3535#endif
3531 3536
3532#ifdef CONFIG_PPC_OF 3537#ifdef CONFIG_PPC_OF
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index da041f88f64a..f4d334f2536e 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -35,7 +35,7 @@
35#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
36#include <linux/ipmi.h> 36#include <linux/ipmi.h>
37#include <linux/ipmi_smi.h> 37#include <linux/ipmi_smi.h>
38#include <linux/smp_lock.h> 38#include <linux/mutex.h>
39#include <linux/watchdog.h> 39#include <linux/watchdog.h>
40#include <linux/miscdevice.h> 40#include <linux/miscdevice.h>
41#include <linux/init.h> 41#include <linux/init.h>
@@ -149,6 +149,7 @@
149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int) 149#define WDIOC_GET_PRETIMEOUT _IOW(WATCHDOG_IOCTL_BASE, 22, int)
150#endif 150#endif
151 151
152static DEFINE_MUTEX(ipmi_watchdog_mutex);
152static int nowayout = WATCHDOG_NOWAYOUT; 153static int nowayout = WATCHDOG_NOWAYOUT;
153 154
154static ipmi_user_t watchdog_user; 155static ipmi_user_t watchdog_user;
@@ -748,9 +749,9 @@ static long ipmi_unlocked_ioctl(struct file *file,
748{ 749{
749 int ret; 750 int ret;
750 751
751 lock_kernel(); 752 mutex_lock(&ipmi_watchdog_mutex);
752 ret = ipmi_ioctl(file, cmd, arg); 753 ret = ipmi_ioctl(file, cmd, arg);
753 unlock_kernel(); 754 mutex_unlock(&ipmi_watchdog_mutex);
754 755
755 return ret; 756 return ret;
756} 757}
@@ -844,7 +845,6 @@ static int ipmi_open(struct inode *ino, struct file *filep)
844 if (test_and_set_bit(0, &ipmi_wdog_open)) 845 if (test_and_set_bit(0, &ipmi_wdog_open))
845 return -EBUSY; 846 return -EBUSY;
846 847
847 cycle_kernel_lock();
848 848
849 /* 849 /*
850 * Don't start the timer now, let it start on the 850 * Don't start the timer now, let it start on the
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index d2344117eaf5..97c3edb95ae7 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -126,7 +126,7 @@
126#include <linux/device.h> 126#include <linux/device.h>
127#include <linux/wait.h> 127#include <linux/wait.h>
128#include <linux/jiffies.h> 128#include <linux/jiffies.h>
129#include <linux/smp_lock.h> 129#include <linux/mutex.h>
130#include <linux/compat.h> 130#include <linux/compat.h>
131 131
132#include <linux/parport.h> 132#include <linux/parport.h>
@@ -140,6 +140,7 @@
140/* if you have more than 8 printers, remember to increase LP_NO */ 140/* if you have more than 8 printers, remember to increase LP_NO */
141#define LP_NO 8 141#define LP_NO 8
142 142
143static DEFINE_MUTEX(lp_mutex);
143static struct lp_struct lp_table[LP_NO]; 144static struct lp_struct lp_table[LP_NO];
144 145
145static unsigned int lp_count = 0; 146static unsigned int lp_count = 0;
@@ -493,7 +494,7 @@ static int lp_open(struct inode * inode, struct file * file)
493 unsigned int minor = iminor(inode); 494 unsigned int minor = iminor(inode);
494 int ret = 0; 495 int ret = 0;
495 496
496 lock_kernel(); 497 mutex_lock(&lp_mutex);
497 if (minor >= LP_NO) { 498 if (minor >= LP_NO) {
498 ret = -ENXIO; 499 ret = -ENXIO;
499 goto out; 500 goto out;
@@ -554,7 +555,7 @@ static int lp_open(struct inode * inode, struct file * file)
554 lp_release_parport (&lp_table[minor]); 555 lp_release_parport (&lp_table[minor]);
555 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT; 556 lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
556out: 557out:
557 unlock_kernel(); 558 mutex_unlock(&lp_mutex);
558 return ret; 559 return ret;
559} 560}
560 561
@@ -680,7 +681,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
680 int ret; 681 int ret;
681 682
682 minor = iminor(file->f_path.dentry->d_inode); 683 minor = iminor(file->f_path.dentry->d_inode);
683 lock_kernel(); 684 mutex_lock(&lp_mutex);
684 switch (cmd) { 685 switch (cmd) {
685 case LPSETTIMEOUT: 686 case LPSETTIMEOUT:
686 if (copy_from_user(&par_timeout, (void __user *)arg, 687 if (copy_from_user(&par_timeout, (void __user *)arg,
@@ -694,7 +695,7 @@ static long lp_ioctl(struct file *file, unsigned int cmd,
694 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg); 695 ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
695 break; 696 break;
696 } 697 }
697 unlock_kernel(); 698 mutex_unlock(&lp_mutex);
698 699
699 return ret; 700 return ret;
700} 701}
@@ -709,7 +710,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
709 int ret; 710 int ret;
710 711
711 minor = iminor(file->f_path.dentry->d_inode); 712 minor = iminor(file->f_path.dentry->d_inode);
712 lock_kernel(); 713 mutex_lock(&lp_mutex);
713 switch (cmd) { 714 switch (cmd) {
714 case LPSETTIMEOUT: 715 case LPSETTIMEOUT:
715 tc = compat_ptr(arg); 716 tc = compat_ptr(arg);
@@ -730,7 +731,7 @@ static long lp_compat_ioctl(struct file *file, unsigned int cmd,
730 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg)); 731 ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
731 break; 732 break;
732 } 733 }
733 unlock_kernel(); 734 mutex_unlock(&lp_mutex);
734 735
735 return ret; 736 return ret;
736} 737}
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 83bef4efe376..1aeaaba680d2 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -25,7 +25,6 @@
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/uio.h> 26#include <linux/uio.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/smp_lock.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
30#include <asm/io.h> 29#include <asm/io.h>
31#include <asm/uaccess.h> 30#include <asm/uaccess.h>
@@ -42,6 +41,7 @@
42#else 41#else
43#define DBG(fmt...) 42#define DBG(fmt...)
44#endif 43#endif
44static DEFINE_MUTEX(mbcs_mutex);
45static int mbcs_major; 45static int mbcs_major;
46 46
47static LIST_HEAD(soft_list); 47static LIST_HEAD(soft_list);
@@ -385,19 +385,19 @@ static int mbcs_open(struct inode *ip, struct file *fp)
385 struct mbcs_soft *soft; 385 struct mbcs_soft *soft;
386 int minor; 386 int minor;
387 387
388 lock_kernel(); 388 mutex_lock(&mbcs_mutex);
389 minor = iminor(ip); 389 minor = iminor(ip);
390 390
391 /* Nothing protects access to this list... */ 391 /* Nothing protects access to this list... */
392 list_for_each_entry(soft, &soft_list, list) { 392 list_for_each_entry(soft, &soft_list, list) {
393 if (soft->nasid == minor) { 393 if (soft->nasid == minor) {
394 fp->private_data = soft->cxdev; 394 fp->private_data = soft->cxdev;
395 unlock_kernel(); 395 mutex_unlock(&mbcs_mutex);
396 return 0; 396 return 0;
397 } 397 }
398 } 398 }
399 399
400 unlock_kernel(); 400 mutex_unlock(&mbcs_mutex);
401 return -ENODEV; 401 return -ENODEV;
402} 402}
403 403
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 8ebd232132fd..e985b1c2730e 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -788,10 +788,11 @@ static const struct file_operations zero_fops = {
788/* 788/*
789 * capabilities for /dev/zero 789 * capabilities for /dev/zero
790 * - permits private mappings, "copies" are taken of the source of zeros 790 * - permits private mappings, "copies" are taken of the source of zeros
791 * - no writeback happens
791 */ 792 */
792static struct backing_dev_info zero_bdi = { 793static struct backing_dev_info zero_bdi = {
793 .name = "char/mem", 794 .name = "char/mem",
794 .capabilities = BDI_CAP_MAP_COPY, 795 .capabilities = BDI_CAP_MAP_COPY | BDI_CAP_NO_ACCT_AND_WRITEBACK,
795}; 796};
796 797
797static const struct file_operations full_fops = { 798static const struct file_operations full_fops = {
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index 1c4070ced066..c070b53984e4 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -32,7 +32,7 @@
32#include <linux/interrupt.h> 32#include <linux/interrupt.h>
33#include <linux/time.h> 33#include <linux/time.h>
34#include <linux/math64.h> 34#include <linux/math64.h>
35#include <linux/smp_lock.h> 35#include <linux/mutex.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
38#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -59,6 +59,7 @@ extern unsigned long sn_rtc_cycles_per_second;
59 59
60#define rtc_time() (*RTC_COUNTER_ADDR) 60#define rtc_time() (*RTC_COUNTER_ADDR)
61 61
62static DEFINE_MUTEX(mmtimer_mutex);
62static long mmtimer_ioctl(struct file *file, unsigned int cmd, 63static long mmtimer_ioctl(struct file *file, unsigned int cmd,
63 unsigned long arg); 64 unsigned long arg);
64static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma); 65static int mmtimer_mmap(struct file *file, struct vm_area_struct *vma);
@@ -372,7 +373,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd,
372{ 373{
373 int ret = 0; 374 int ret = 0;
374 375
375 lock_kernel(); 376 mutex_lock(&mmtimer_mutex);
376 377
377 switch (cmd) { 378 switch (cmd) {
378 case MMTIMER_GETOFFSET: /* offset of the counter */ 379 case MMTIMER_GETOFFSET: /* offset of the counter */
@@ -415,7 +416,7 @@ static long mmtimer_ioctl(struct file *file, unsigned int cmd,
415 ret = -ENOTTY; 416 ret = -ENOTTY;
416 break; 417 break;
417 } 418 }
418 unlock_kernel(); 419 mutex_unlock(&mmtimer_mutex);
419 return ret; 420 return ret;
420} 421}
421 422
diff --git a/drivers/char/mwave/mwavedd.c b/drivers/char/mwave/mwavedd.c
index 0464822eac53..1d82d5838f0c 100644
--- a/drivers/char/mwave/mwavedd.c
+++ b/drivers/char/mwave/mwavedd.c
@@ -56,7 +56,7 @@
56#include <linux/serial.h> 56#include <linux/serial.h>
57#include <linux/sched.h> 57#include <linux/sched.h>
58#include <linux/spinlock.h> 58#include <linux/spinlock.h>
59#include <linux/smp_lock.h> 59#include <linux/mutex.h>
60#include <linux/delay.h> 60#include <linux/delay.h>
61#include <linux/serial_8250.h> 61#include <linux/serial_8250.h>
62#include "smapi.h" 62#include "smapi.h"
@@ -73,6 +73,7 @@ MODULE_LICENSE("GPL");
73* checks are made against other devices (ie. superio) for conflicts. 73* checks are made against other devices (ie. superio) for conflicts.
74* We'll depend on users using the tpctl utility to do that for now 74* We'll depend on users using the tpctl utility to do that for now
75*/ 75*/
76static DEFINE_MUTEX(mwave_mutex);
76int mwave_debug = 0; 77int mwave_debug = 0;
77int mwave_3780i_irq = 0; 78int mwave_3780i_irq = 0;
78int mwave_3780i_io = 0; 79int mwave_3780i_io = 0;
@@ -101,7 +102,6 @@ static int mwave_open(struct inode *inode, struct file *file)
101 PRINTK_2(TRACE_MWAVE, 102 PRINTK_2(TRACE_MWAVE,
102 "mwavedd::mwave_open, exit return retval %x\n", retval); 103 "mwavedd::mwave_open, exit return retval %x\n", retval);
103 104
104 cycle_kernel_lock();
105 return retval; 105 return retval;
106} 106}
107 107
@@ -136,9 +136,9 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
136 PRINTK_1(TRACE_MWAVE, 136 PRINTK_1(TRACE_MWAVE,
137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 137 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
138 " calling tp3780I_ResetDSP\n"); 138 " calling tp3780I_ResetDSP\n");
139 lock_kernel(); 139 mutex_lock(&mwave_mutex);
140 retval = tp3780I_ResetDSP(&pDrvData->rBDData); 140 retval = tp3780I_ResetDSP(&pDrvData->rBDData);
141 unlock_kernel(); 141 mutex_unlock(&mwave_mutex);
142 PRINTK_2(TRACE_MWAVE, 142 PRINTK_2(TRACE_MWAVE,
143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET" 143 "mwavedd::mwave_ioctl, IOCTL_MW_RESET"
144 " retval %x from tp3780I_ResetDSP\n", 144 " retval %x from tp3780I_ResetDSP\n",
@@ -149,9 +149,9 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
149 PRINTK_1(TRACE_MWAVE, 149 PRINTK_1(TRACE_MWAVE,
150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 150 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
151 " calling tp3780I_StartDSP\n"); 151 " calling tp3780I_StartDSP\n");
152 lock_kernel(); 152 mutex_lock(&mwave_mutex);
153 retval = tp3780I_StartDSP(&pDrvData->rBDData); 153 retval = tp3780I_StartDSP(&pDrvData->rBDData);
154 unlock_kernel(); 154 mutex_unlock(&mwave_mutex);
155 PRINTK_2(TRACE_MWAVE, 155 PRINTK_2(TRACE_MWAVE,
156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN" 156 "mwavedd::mwave_ioctl, IOCTL_MW_RUN"
157 " retval %x from tp3780I_StartDSP\n", 157 " retval %x from tp3780I_StartDSP\n",
@@ -165,10 +165,10 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
165 "mwavedd::mwave_ioctl," 165 "mwavedd::mwave_ioctl,"
166 " IOCTL_MW_DSP_ABILITIES calling" 166 " IOCTL_MW_DSP_ABILITIES calling"
167 " tp3780I_QueryAbilities\n"); 167 " tp3780I_QueryAbilities\n");
168 lock_kernel(); 168 mutex_lock(&mwave_mutex);
169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData, 169 retval = tp3780I_QueryAbilities(&pDrvData->rBDData,
170 &rAbilities); 170 &rAbilities);
171 unlock_kernel(); 171 mutex_unlock(&mwave_mutex);
172 PRINTK_2(TRACE_MWAVE, 172 PRINTK_2(TRACE_MWAVE,
173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES" 173 "mwavedd::mwave_ioctl, IOCTL_MW_DSP_ABILITIES"
174 " retval %x from tp3780I_QueryAbilities\n", 174 " retval %x from tp3780I_QueryAbilities\n",
@@ -199,13 +199,13 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA," 199 "mwavedd::mwave_ioctl IOCTL_MW_READ_DATA,"
200 " size %lx, ioarg %lx pusBuffer %p\n", 200 " size %lx, ioarg %lx pusBuffer %p\n",
201 rReadData.ulDataLength, ioarg, pusBuffer); 201 rReadData.ulDataLength, ioarg, pusBuffer);
202 lock_kernel(); 202 mutex_lock(&mwave_mutex);
203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 203 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
204 iocmd, 204 iocmd,
205 pusBuffer, 205 pusBuffer,
206 rReadData.ulDataLength, 206 rReadData.ulDataLength,
207 rReadData.usDspAddress); 207 rReadData.usDspAddress);
208 unlock_kernel(); 208 mutex_unlock(&mwave_mutex);
209 } 209 }
210 break; 210 break;
211 211
@@ -223,12 +223,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
223 " size %lx, ioarg %lx pusBuffer %p\n", 223 " size %lx, ioarg %lx pusBuffer %p\n",
224 rReadData.ulDataLength / 2, ioarg, 224 rReadData.ulDataLength / 2, ioarg,
225 pusBuffer); 225 pusBuffer);
226 lock_kernel(); 226 mutex_lock(&mwave_mutex);
227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 227 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
228 iocmd, pusBuffer, 228 iocmd, pusBuffer,
229 rReadData.ulDataLength / 2, 229 rReadData.ulDataLength / 2,
230 rReadData.usDspAddress); 230 rReadData.usDspAddress);
231 unlock_kernel(); 231 mutex_unlock(&mwave_mutex);
232 } 232 }
233 break; 233 break;
234 234
@@ -246,12 +246,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
246 " size %lx, ioarg %lx pusBuffer %p\n", 246 " size %lx, ioarg %lx pusBuffer %p\n",
247 rWriteData.ulDataLength, ioarg, 247 rWriteData.ulDataLength, ioarg,
248 pusBuffer); 248 pusBuffer);
249 lock_kernel(); 249 mutex_lock(&mwave_mutex);
250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData, 250 retval = tp3780I_ReadWriteDspDStore(&pDrvData->rBDData,
251 iocmd, pusBuffer, 251 iocmd, pusBuffer,
252 rWriteData.ulDataLength, 252 rWriteData.ulDataLength,
253 rWriteData.usDspAddress); 253 rWriteData.usDspAddress);
254 unlock_kernel(); 254 mutex_unlock(&mwave_mutex);
255 } 255 }
256 break; 256 break;
257 257
@@ -269,12 +269,12 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
269 " size %lx, ioarg %lx pusBuffer %p\n", 269 " size %lx, ioarg %lx pusBuffer %p\n",
270 rWriteData.ulDataLength, ioarg, 270 rWriteData.ulDataLength, ioarg,
271 pusBuffer); 271 pusBuffer);
272 lock_kernel(); 272 mutex_lock(&mwave_mutex);
273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData, 273 retval = tp3780I_ReadWriteDspIStore(&pDrvData->rBDData,
274 iocmd, pusBuffer, 274 iocmd, pusBuffer,
275 rWriteData.ulDataLength, 275 rWriteData.ulDataLength,
276 rWriteData.usDspAddress); 276 rWriteData.usDspAddress);
277 unlock_kernel(); 277 mutex_unlock(&mwave_mutex);
278 } 278 }
279 break; 279 break;
280 280
@@ -295,10 +295,10 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
295 ipcnum, 295 ipcnum,
296 pDrvData->IPCs[ipcnum].usIntCount); 296 pDrvData->IPCs[ipcnum].usIntCount);
297 297
298 lock_kernel(); 298 mutex_lock(&mwave_mutex);
299 pDrvData->IPCs[ipcnum].bIsHere = FALSE; 299 pDrvData->IPCs[ipcnum].bIsHere = FALSE;
300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE; 300 pDrvData->IPCs[ipcnum].bIsEnabled = TRUE;
301 unlock_kernel(); 301 mutex_unlock(&mwave_mutex);
302 302
303 PRINTK_2(TRACE_MWAVE, 303 PRINTK_2(TRACE_MWAVE,
304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC" 304 "mwavedd::mwave_ioctl IOCTL_MW_REGISTER_IPC"
@@ -323,7 +323,7 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
323 ipcnum, 323 ipcnum,
324 pDrvData->IPCs[ipcnum].usIntCount); 324 pDrvData->IPCs[ipcnum].usIntCount);
325 325
326 lock_kernel(); 326 mutex_lock(&mwave_mutex);
327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 327 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
328 DECLARE_WAITQUEUE(wait, current); 328 DECLARE_WAITQUEUE(wait, current);
329 329
@@ -364,7 +364,7 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
364 " processing\n", 364 " processing\n",
365 ipcnum); 365 ipcnum);
366 } 366 }
367 unlock_kernel(); 367 mutex_unlock(&mwave_mutex);
368 } 368 }
369 break; 369 break;
370 370
@@ -383,14 +383,14 @@ static long mwave_ioctl(struct file *file, unsigned int iocmd,
383 ipcnum); 383 ipcnum);
384 return -EINVAL; 384 return -EINVAL;
385 } 385 }
386 lock_kernel(); 386 mutex_lock(&mwave_mutex);
387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) { 387 if (pDrvData->IPCs[ipcnum].bIsEnabled == TRUE) {
388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE; 388 pDrvData->IPCs[ipcnum].bIsEnabled = FALSE;
389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) { 389 if (pDrvData->IPCs[ipcnum].bIsHere == TRUE) {
390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue); 390 wake_up_interruptible(&pDrvData->IPCs[ipcnum].ipc_wait_queue);
391 } 391 }
392 } 392 }
393 unlock_kernel(); 393 mutex_unlock(&mwave_mutex);
394 } 394 }
395 break; 395 break;
396 396
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 66d2917b003f..166f1e7aaa7e 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -109,10 +109,11 @@
109#include <linux/spinlock.h> 109#include <linux/spinlock.h>
110#include <linux/io.h> 110#include <linux/io.h>
111#include <linux/uaccess.h> 111#include <linux/uaccess.h>
112#include <linux/smp_lock.h> 112#include <linux/mutex.h>
113 113
114#include <asm/system.h> 114#include <asm/system.h>
115 115
116static DEFINE_MUTEX(nvram_mutex);
116static DEFINE_SPINLOCK(nvram_state_lock); 117static DEFINE_SPINLOCK(nvram_state_lock);
117static int nvram_open_cnt; /* #times opened */ 118static int nvram_open_cnt; /* #times opened */
118static int nvram_open_mode; /* special open modes */ 119static int nvram_open_mode; /* special open modes */
@@ -308,7 +309,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
308 if (!capable(CAP_SYS_ADMIN)) 309 if (!capable(CAP_SYS_ADMIN))
309 return -EACCES; 310 return -EACCES;
310 311
311 lock_kernel(); 312 mutex_lock(&nvram_mutex);
312 spin_lock_irq(&rtc_lock); 313 spin_lock_irq(&rtc_lock);
313 314
314 for (i = 0; i < NVRAM_BYTES; ++i) 315 for (i = 0; i < NVRAM_BYTES; ++i)
@@ -316,7 +317,7 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
316 __nvram_set_checksum(); 317 __nvram_set_checksum();
317 318
318 spin_unlock_irq(&rtc_lock); 319 spin_unlock_irq(&rtc_lock);
319 unlock_kernel(); 320 mutex_unlock(&nvram_mutex);
320 return 0; 321 return 0;
321 322
322 case NVRAM_SETCKS: 323 case NVRAM_SETCKS:
@@ -325,11 +326,11 @@ static long nvram_ioctl(struct file *file, unsigned int cmd,
325 if (!capable(CAP_SYS_ADMIN)) 326 if (!capable(CAP_SYS_ADMIN))
326 return -EACCES; 327 return -EACCES;
327 328
328 lock_kernel(); 329 mutex_lock(&nvram_mutex);
329 spin_lock_irq(&rtc_lock); 330 spin_lock_irq(&rtc_lock);
330 __nvram_set_checksum(); 331 __nvram_set_checksum();
331 spin_unlock_irq(&rtc_lock); 332 spin_unlock_irq(&rtc_lock);
332 unlock_kernel(); 333 mutex_unlock(&nvram_mutex);
333 return 0; 334 return 0;
334 335
335 default: 336 default:
diff --git a/drivers/char/nwflash.c b/drivers/char/nwflash.c
index 043a1c7b86be..a12f52400dbc 100644
--- a/drivers/char/nwflash.c
+++ b/drivers/char/nwflash.c
@@ -25,7 +25,6 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/rwsem.h> 26#include <linux/rwsem.h>
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/smp_lock.h>
29#include <linux/mutex.h> 28#include <linux/mutex.h>
30#include <linux/jiffies.h> 29#include <linux/jiffies.h>
31 30
@@ -41,6 +40,7 @@
41 40
42#define NWFLASH_VERSION "6.4" 41#define NWFLASH_VERSION "6.4"
43 42
43static DEFINE_MUTEX(flash_mutex);
44static void kick_open(void); 44static void kick_open(void);
45static int get_flash_id(void); 45static int get_flash_id(void);
46static int erase_block(int nBlock); 46static int erase_block(int nBlock);
@@ -96,7 +96,7 @@ static int get_flash_id(void)
96 96
97static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) 97static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
98{ 98{
99 lock_kernel(); 99 mutex_lock(&flash_mutex);
100 switch (cmd) { 100 switch (cmd) {
101 case CMD_WRITE_DISABLE: 101 case CMD_WRITE_DISABLE:
102 gbWriteBase64Enable = 0; 102 gbWriteBase64Enable = 0;
@@ -114,10 +114,10 @@ static long flash_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
114 default: 114 default:
115 gbWriteBase64Enable = 0; 115 gbWriteBase64Enable = 0;
116 gbWriteEnable = 0; 116 gbWriteEnable = 0;
117 unlock_kernel(); 117 mutex_unlock(&flash_mutex);
118 return -EINVAL; 118 return -EINVAL;
119 } 119 }
120 unlock_kernel(); 120 mutex_unlock(&flash_mutex);
121 return 0; 121 return 0;
122} 122}
123 123
@@ -282,7 +282,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
282{ 282{
283 loff_t ret; 283 loff_t ret;
284 284
285 lock_kernel(); 285 mutex_lock(&flash_mutex);
286 if (flashdebug) 286 if (flashdebug)
287 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n", 287 printk(KERN_DEBUG "flash_llseek: offset=0x%X, orig=0x%X.\n",
288 (unsigned int) offset, orig); 288 (unsigned int) offset, orig);
@@ -317,7 +317,7 @@ static loff_t flash_llseek(struct file *file, loff_t offset, int orig)
317 default: 317 default:
318 ret = -EINVAL; 318 ret = -EINVAL;
319 } 319 }
320 unlock_kernel(); 320 mutex_unlock(&flash_mutex);
321 return ret; 321 return ret;
322} 322}
323 323
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index c99f6997e5e7..6835c23e9a51 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -30,11 +30,10 @@
30#include <linux/fs.h> 30#include <linux/fs.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/bitrev.h> 32#include <linux/bitrev.h>
33#include <linux/smp_lock.h> 33#include <linux/mutex.h>
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35#include <linux/io.h> 35#include <linux/io.h>
36 36
37#include <pcmcia/cs.h>
38#include <pcmcia/cistpl.h> 37#include <pcmcia/cistpl.h>
39#include <pcmcia/cisreg.h> 38#include <pcmcia/cisreg.h>
40#include <pcmcia/ciscode.h> 39#include <pcmcia/ciscode.h>
@@ -55,7 +54,7 @@
55 __func__ , ## args); \ 54 __func__ , ## args); \
56 } while (0) 55 } while (0)
57 56
58static char *version = "cm4000_cs.c v2.4.0gm6 - All bugs added by Harald Welte"; 57static DEFINE_MUTEX(cmm_mutex);
59 58
60#define T_1SEC (HZ) 59#define T_1SEC (HZ)
61#define T_10MSEC msecs_to_jiffies(10) 60#define T_10MSEC msecs_to_jiffies(10)
@@ -1418,7 +1417,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1418 iminor(inode), ioctl_names[_IOC_NR(cmd)]); 1417 iminor(inode), ioctl_names[_IOC_NR(cmd)]);
1419#endif 1418#endif
1420 1419
1421 lock_kernel(); 1420 mutex_lock(&cmm_mutex);
1422 rc = -ENODEV; 1421 rc = -ENODEV;
1423 link = dev_table[iminor(inode)]; 1422 link = dev_table[iminor(inode)];
1424 if (!pcmcia_dev_present(link)) { 1423 if (!pcmcia_dev_present(link)) {
@@ -1626,7 +1625,7 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1626 rc = -ENOTTY; 1625 rc = -ENOTTY;
1627 } 1626 }
1628out: 1627out:
1629 unlock_kernel(); 1628 mutex_unlock(&cmm_mutex);
1630 return rc; 1629 return rc;
1631} 1630}
1632 1631
@@ -1640,7 +1639,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1640 if (minor >= CM4000_MAX_DEV) 1639 if (minor >= CM4000_MAX_DEV)
1641 return -ENODEV; 1640 return -ENODEV;
1642 1641
1643 lock_kernel(); 1642 mutex_lock(&cmm_mutex);
1644 link = dev_table[minor]; 1643 link = dev_table[minor];
1645 if (link == NULL || !pcmcia_dev_present(link)) { 1644 if (link == NULL || !pcmcia_dev_present(link)) {
1646 ret = -ENODEV; 1645 ret = -ENODEV;
@@ -1685,7 +1684,7 @@ static int cmm_open(struct inode *inode, struct file *filp)
1685 DEBUGP(2, dev, "<- cmm_open\n"); 1684 DEBUGP(2, dev, "<- cmm_open\n");
1686 ret = nonseekable_open(inode, filp); 1685 ret = nonseekable_open(inode, filp);
1687out: 1686out:
1688 unlock_kernel(); 1687 mutex_unlock(&cmm_mutex);
1689 return ret; 1688 return ret;
1690} 1689}
1691 1690
@@ -1742,20 +1741,8 @@ static void cmm_cm4000_release(struct pcmcia_device * link)
1742 1741
1743/*==== Interface to PCMCIA Layer =======================================*/ 1742/*==== Interface to PCMCIA Layer =======================================*/
1744 1743
1745static int cm4000_config_check(struct pcmcia_device *p_dev, 1744static int cm4000_config_check(struct pcmcia_device *p_dev, void *priv_data)
1746 cistpl_cftable_entry_t *cfg,
1747 cistpl_cftable_entry_t *dflt,
1748 unsigned int vcc,
1749 void *priv_data)
1750{ 1745{
1751 if (!cfg->io.nwin)
1752 return -ENODEV;
1753
1754 p_dev->resource[0]->start = cfg->io.win[0].base;
1755 p_dev->resource[0]->end = cfg->io.win[0].len;
1756 p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
1757 p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
1758
1759 return pcmcia_request_io(p_dev); 1746 return pcmcia_request_io(p_dev);
1760} 1747}
1761 1748
@@ -1763,13 +1750,13 @@ static int cm4000_config(struct pcmcia_device * link, int devno)
1763{ 1750{
1764 struct cm4000_dev *dev; 1751 struct cm4000_dev *dev;
1765 1752
1753 link->config_flags |= CONF_AUTO_SET_IO;
1754
1766 /* read the config-tuples */ 1755 /* read the config-tuples */
1767 if (pcmcia_loop_config(link, cm4000_config_check, NULL)) 1756 if (pcmcia_loop_config(link, cm4000_config_check, NULL))
1768 goto cs_release; 1757 goto cs_release;
1769 1758
1770 link->conf.IntType = 00000002; 1759 if (pcmcia_enable_device(link))
1771
1772 if (pcmcia_request_configuration(link, &link->conf))
1773 goto cs_release; 1760 goto cs_release;
1774 1761
1775 dev = link->priv; 1762 dev = link->priv;
@@ -1829,7 +1816,6 @@ static int cm4000_probe(struct pcmcia_device *link)
1829 1816
1830 dev->p_dev = link; 1817 dev->p_dev = link;
1831 link->priv = dev; 1818 link->priv = dev;
1832 link->conf.IntType = INT_MEMORY_AND_IO;
1833 dev_table[i] = link; 1819 dev_table[i] = link;
1834 1820
1835 init_waitqueue_head(&dev->devq); 1821 init_waitqueue_head(&dev->devq);
@@ -1892,9 +1878,7 @@ MODULE_DEVICE_TABLE(pcmcia, cm4000_ids);
1892 1878
1893static struct pcmcia_driver cm4000_driver = { 1879static struct pcmcia_driver cm4000_driver = {
1894 .owner = THIS_MODULE, 1880 .owner = THIS_MODULE,
1895 .drv = { 1881 .name = "cm4000_cs",
1896 .name = "cm4000_cs",
1897 },
1898 .probe = cm4000_probe, 1882 .probe = cm4000_probe,
1899 .remove = cm4000_detach, 1883 .remove = cm4000_detach,
1900 .suspend = cm4000_suspend, 1884 .suspend = cm4000_suspend,
@@ -1906,8 +1890,6 @@ static int __init cmm_init(void)
1906{ 1890{
1907 int rc; 1891 int rc;
1908 1892
1909 printk(KERN_INFO "%s\n", version);
1910
1911 cmm_class = class_create(THIS_MODULE, "cardman_4000"); 1893 cmm_class = class_create(THIS_MODULE, "cardman_4000");
1912 if (IS_ERR(cmm_class)) 1894 if (IS_ERR(cmm_class))
1913 return PTR_ERR(cmm_class); 1895 return PTR_ERR(cmm_class);
@@ -1932,7 +1914,6 @@ static int __init cmm_init(void)
1932 1914
1933static void __exit cmm_exit(void) 1915static void __exit cmm_exit(void)
1934{ 1916{
1935 printk(KERN_INFO MODULE_NAME ": unloading\n");
1936 pcmcia_unregister_driver(&cm4000_driver); 1917 pcmcia_unregister_driver(&cm4000_driver);
1937 unregister_chrdev(major, DEVICE_NAME); 1918 unregister_chrdev(major, DEVICE_NAME);
1938 class_destroy(cmm_class); 1919 class_destroy(cmm_class);
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 9ecc58baa8f3..5d8d59e865f4 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -24,12 +24,11 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/poll.h> 26#include <linux/poll.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28#include <linux/wait.h> 28#include <linux/wait.h>
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30#include <asm/io.h> 30#include <asm/io.h>
31 31
32#include <pcmcia/cs.h>
33#include <pcmcia/cistpl.h> 32#include <pcmcia/cistpl.h>
34#include <pcmcia/cisreg.h> 33#include <pcmcia/cisreg.h>
35#include <pcmcia/ciscode.h> 34#include <pcmcia/ciscode.h>
@@ -49,8 +48,7 @@
49 __func__ , ## args); \ 48 __func__ , ## args); \
50 } while (0) 49 } while (0)
51 50
52static char *version = 51static DEFINE_MUTEX(cm4040_mutex);
53"OMNIKEY CardMan 4040 v1.1.0gm5 - All bugs added by Harald Welte";
54 52
55#define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ) 53#define CCID_DRIVER_BULK_DEFAULT_TIMEOUT (150*HZ)
56#define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ) 54#define CCID_DRIVER_ASYNC_POWERUP_TIMEOUT (35*HZ)
@@ -444,7 +442,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
444 if (minor >= CM_MAX_DEV) 442 if (minor >= CM_MAX_DEV)
445 return -ENODEV; 443 return -ENODEV;
446 444
447 lock_kernel(); 445 mutex_lock(&cm4040_mutex);
448 link = dev_table[minor]; 446 link = dev_table[minor];
449 if (link == NULL || !pcmcia_dev_present(link)) { 447 if (link == NULL || !pcmcia_dev_present(link)) {
450 ret = -ENODEV; 448 ret = -ENODEV;
@@ -473,7 +471,7 @@ static int cm4040_open(struct inode *inode, struct file *filp)
473 DEBUGP(2, dev, "<- cm4040_open (successfully)\n"); 471 DEBUGP(2, dev, "<- cm4040_open (successfully)\n");
474 ret = nonseekable_open(inode, filp); 472 ret = nonseekable_open(inode, filp);
475out: 473out:
476 unlock_kernel(); 474 mutex_unlock(&cm4040_mutex);
477 return ret; 475 return ret;
478} 476}
479 477
@@ -516,26 +514,9 @@ static void cm4040_reader_release(struct pcmcia_device *link)
516 return; 514 return;
517} 515}
518 516
519static int cm4040_config_check(struct pcmcia_device *p_dev, 517static int cm4040_config_check(struct pcmcia_device *p_dev, void *priv_data)
520 cistpl_cftable_entry_t *cfg,
521 cistpl_cftable_entry_t *dflt,
522 unsigned int vcc,
523 void *priv_data)
524{ 518{
525 int rc; 519 return pcmcia_request_io(p_dev);
526 if (!cfg->io.nwin)
527 return -ENODEV;
528
529 /* Get the IOaddr */
530 p_dev->resource[0]->start = cfg->io.win[0].base;
531 p_dev->resource[0]->end = cfg->io.win[0].len;
532 p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
533 p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
534 rc = pcmcia_request_io(p_dev);
535
536 dev_printk(KERN_INFO, &p_dev->dev,
537 "pcmcia_request_io returned 0x%x\n", rc);
538 return rc;
539} 520}
540 521
541 522
@@ -544,15 +525,15 @@ static int reader_config(struct pcmcia_device *link, int devno)
544 struct reader_dev *dev; 525 struct reader_dev *dev;
545 int fail_rc; 526 int fail_rc;
546 527
528 link->config_flags |= CONF_AUTO_SET_IO;
529
547 if (pcmcia_loop_config(link, cm4040_config_check, NULL)) 530 if (pcmcia_loop_config(link, cm4040_config_check, NULL))
548 goto cs_release; 531 goto cs_release;
549 532
550 link->conf.IntType = 00000002; 533 fail_rc = pcmcia_enable_device(link);
551
552 fail_rc = pcmcia_request_configuration(link, &link->conf);
553 if (fail_rc != 0) { 534 if (fail_rc != 0) {
554 dev_printk(KERN_INFO, &link->dev, 535 dev_printk(KERN_INFO, &link->dev,
555 "pcmcia_request_configuration failed 0x%x\n", 536 "pcmcia_enable_device failed 0x%x\n",
556 fail_rc); 537 fail_rc);
557 goto cs_release; 538 goto cs_release;
558 } 539 }
@@ -599,7 +580,6 @@ static int reader_probe(struct pcmcia_device *link)
599 link->priv = dev; 580 link->priv = dev;
600 dev->p_dev = link; 581 dev->p_dev = link;
601 582
602 link->conf.IntType = INT_MEMORY_AND_IO;
603 dev_table[i] = link; 583 dev_table[i] = link;
604 584
605 init_waitqueue_head(&dev->devq); 585 init_waitqueue_head(&dev->devq);
@@ -663,9 +643,7 @@ MODULE_DEVICE_TABLE(pcmcia, cm4040_ids);
663 643
664static struct pcmcia_driver reader_driver = { 644static struct pcmcia_driver reader_driver = {
665 .owner = THIS_MODULE, 645 .owner = THIS_MODULE,
666 .drv = { 646 .name = "cm4040_cs",
667 .name = "cm4040_cs",
668 },
669 .probe = reader_probe, 647 .probe = reader_probe,
670 .remove = reader_detach, 648 .remove = reader_detach,
671 .id_table = cm4040_ids, 649 .id_table = cm4040_ids,
@@ -675,7 +653,6 @@ static int __init cm4040_init(void)
675{ 653{
676 int rc; 654 int rc;
677 655
678 printk(KERN_INFO "%s\n", version);
679 cmx_class = class_create(THIS_MODULE, "cardman_4040"); 656 cmx_class = class_create(THIS_MODULE, "cardman_4040");
680 if (IS_ERR(cmx_class)) 657 if (IS_ERR(cmx_class))
681 return PTR_ERR(cmx_class); 658 return PTR_ERR(cmx_class);
@@ -700,7 +677,6 @@ static int __init cm4040_init(void)
700 677
701static void __exit cm4040_exit(void) 678static void __exit cm4040_exit(void)
702{ 679{
703 printk(KERN_INFO MODULE_NAME ": unloading\n");
704 pcmcia_unregister_driver(&reader_driver); 680 pcmcia_unregister_driver(&reader_driver);
705 unregister_chrdev(major, DEVICE_NAME); 681 unregister_chrdev(major, DEVICE_NAME);
706 class_destroy(cmx_class); 682 class_destroy(cmx_class);
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
index 67bdb05798b1..94b8eb4d691d 100644
--- a/drivers/char/pcmcia/ipwireless/main.c
+++ b/drivers/char/pcmcia/ipwireless/main.c
@@ -32,7 +32,6 @@
32#include <pcmcia/device_id.h> 32#include <pcmcia/device_id.h>
33#include <pcmcia/ss.h> 33#include <pcmcia/ss.h>
34#include <pcmcia/ds.h> 34#include <pcmcia/ds.h>
35#include <pcmcia/cs.h>
36 35
37static struct pcmcia_device_id ipw_ids[] = { 36static struct pcmcia_device_id ipw_ids[] = {
38 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100), 37 PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
@@ -76,23 +75,18 @@ static void signalled_reboot_callback(void *callback_data)
76 schedule_work(&ipw->work_reboot); 75 schedule_work(&ipw->work_reboot);
77} 76}
78 77
79static int ipwireless_probe(struct pcmcia_device *p_dev, 78static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)
80 cistpl_cftable_entry_t *cfg,
81 cistpl_cftable_entry_t *dflt,
82 unsigned int vcc,
83 void *priv_data)
84{ 79{
85 struct ipw_dev *ipw = priv_data; 80 struct ipw_dev *ipw = priv_data;
86 struct resource *io_resource; 81 struct resource *io_resource;
87 int ret; 82 int ret;
88 83
84 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
89 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 85 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
90 p_dev->resource[0]->start = cfg->io.win[0].base;
91 p_dev->resource[0]->end = cfg->io.win[0].len;
92 86
93 /* 0x40 causes it to generate level mode interrupts. */ 87 /* 0x40 causes it to generate level mode interrupts. */
94 /* 0x04 enables IREQ pin. */ 88 /* 0x04 enables IREQ pin. */
95 p_dev->conf.ConfigIndex = cfg->index | 0x44; 89 p_dev->config_index |= 0x44;
96 p_dev->io_lines = 16; 90 p_dev->io_lines = 16;
97 ret = pcmcia_request_io(p_dev); 91 ret = pcmcia_request_io(p_dev);
98 if (ret) 92 if (ret)
@@ -102,65 +96,49 @@ static int ipwireless_probe(struct pcmcia_device *p_dev,
102 resource_size(p_dev->resource[0]), 96 resource_size(p_dev->resource[0]),
103 IPWIRELESS_PCCARD_NAME); 97 IPWIRELESS_PCCARD_NAME);
104 98
105 if (cfg->mem.nwin == 0) 99 p_dev->resource[2]->flags |=
106 return 0;
107
108 ipw->request_common_memory.Attributes =
109 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE; 100 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
110 ipw->request_common_memory.Base = cfg->mem.win[0].host_addr;
111 ipw->request_common_memory.Size = cfg->mem.win[0].len;
112 if (ipw->request_common_memory.Size < 0x1000)
113 ipw->request_common_memory.Size = 0x1000;
114 ipw->request_common_memory.AccessSpeed = 0;
115
116 ret = pcmcia_request_window(p_dev, &ipw->request_common_memory,
117 &ipw->handle_common_memory);
118 101
102 ret = pcmcia_request_window(p_dev, p_dev->resource[2], 0);
119 if (ret != 0) 103 if (ret != 0)
120 goto exit1; 104 goto exit1;
121 105
122 ret = pcmcia_map_mem_page(p_dev, ipw->handle_common_memory, 106 ret = pcmcia_map_mem_page(p_dev, p_dev->resource[2], p_dev->card_addr);
123 cfg->mem.win[0].card_addr);
124
125 if (ret != 0) 107 if (ret != 0)
126 goto exit2; 108 goto exit2;
127 109
128 ipw->is_v2_card = cfg->mem.win[0].len == 0x100; 110 ipw->is_v2_card = resource_size(p_dev->resource[2]) == 0x100;
129 111
130 ipw->common_memory = ioremap(ipw->request_common_memory.Base, 112 ipw->attr_memory = ioremap(p_dev->resource[2]->start,
131 ipw->request_common_memory.Size); 113 resource_size(p_dev->resource[2]));
132 request_mem_region(ipw->request_common_memory.Base, 114 request_mem_region(p_dev->resource[2]->start,
133 ipw->request_common_memory.Size, 115 resource_size(p_dev->resource[2]),
134 IPWIRELESS_PCCARD_NAME); 116 IPWIRELESS_PCCARD_NAME);
135 117
136 ipw->request_attr_memory.Attributes = 118 p_dev->resource[3]->flags |= WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM |
137 WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE; 119 WIN_ENABLE;
138 ipw->request_attr_memory.Base = 0; 120 p_dev->resource[3]->end = 0; /* this used to be 0x1000 */
139 ipw->request_attr_memory.Size = 0; /* this used to be 0x1000 */ 121 ret = pcmcia_request_window(p_dev, p_dev->resource[3], 0);
140 ipw->request_attr_memory.AccessSpeed = 0;
141
142 ret = pcmcia_request_window(p_dev, &ipw->request_attr_memory,
143 &ipw->handle_attr_memory);
144
145 if (ret != 0) 122 if (ret != 0)
146 goto exit2; 123 goto exit2;
147 124
148 ret = pcmcia_map_mem_page(p_dev, ipw->handle_attr_memory, 0); 125 ret = pcmcia_map_mem_page(p_dev, p_dev->resource[3], 0);
149 if (ret != 0) 126 if (ret != 0)
150 goto exit3; 127 goto exit3;
151 128
152 ipw->attr_memory = ioremap(ipw->request_attr_memory.Base, 129 ipw->attr_memory = ioremap(p_dev->resource[3]->start,
153 ipw->request_attr_memory.Size); 130 resource_size(p_dev->resource[3]));
154 request_mem_region(ipw->request_attr_memory.Base, 131 request_mem_region(p_dev->resource[3]->start,
155 ipw->request_attr_memory.Size, IPWIRELESS_PCCARD_NAME); 132 resource_size(p_dev->resource[3]),
133 IPWIRELESS_PCCARD_NAME);
156 134
157 return 0; 135 return 0;
158 136
159exit3: 137exit3:
160exit2: 138exit2:
161 if (ipw->common_memory) { 139 if (ipw->common_memory) {
162 release_mem_region(ipw->request_common_memory.Base, 140 release_mem_region(p_dev->resource[2]->start,
163 ipw->request_common_memory.Size); 141 resource_size(p_dev->resource[2]));
164 iounmap(ipw->common_memory); 142 iounmap(ipw->common_memory);
165 } 143 }
166exit1: 144exit1:
@@ -175,14 +153,13 @@ static int config_ipwireless(struct ipw_dev *ipw)
175 int ret = 0; 153 int ret = 0;
176 154
177 ipw->is_v2_card = 0; 155 ipw->is_v2_card = 0;
156 link->config_flags |= CONF_AUTO_SET_IO | CONF_AUTO_SET_IOMEM |
157 CONF_ENABLE_IRQ;
178 158
179 ret = pcmcia_loop_config(link, ipwireless_probe, ipw); 159 ret = pcmcia_loop_config(link, ipwireless_probe, ipw);
180 if (ret != 0) 160 if (ret != 0)
181 return ret; 161 return ret;
182 162
183 link->conf.Attributes = CONF_ENABLE_IRQ;
184 link->conf.IntType = INT_MEMORY_AND_IO;
185
186 INIT_WORK(&ipw->work_reboot, signalled_reboot_work); 163 INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
187 164
188 ipwireless_init_hardware_v1(ipw->hardware, link->resource[0]->start, 165 ipwireless_init_hardware_v1(ipw->hardware, link->resource[0]->start,
@@ -201,13 +178,9 @@ static int config_ipwireless(struct ipw_dev *ipw)
201 (unsigned int) link->irq); 178 (unsigned int) link->irq);
202 if (ipw->attr_memory && ipw->common_memory) 179 if (ipw->attr_memory && ipw->common_memory)
203 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 180 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
204 ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n", 181 ": attr memory %pR, common memory %pR\n",
205 ipw->request_attr_memory.Base, 182 link->resource[3],
206 ipw->request_attr_memory.Base 183 link->resource[2]);
207 + ipw->request_attr_memory.Size - 1,
208 ipw->request_common_memory.Base,
209 ipw->request_common_memory.Base
210 + ipw->request_common_memory.Size - 1);
211 184
212 ipw->network = ipwireless_network_create(ipw->hardware); 185 ipw->network = ipwireless_network_create(ipw->hardware);
213 if (!ipw->network) 186 if (!ipw->network)
@@ -223,25 +196,23 @@ static int config_ipwireless(struct ipw_dev *ipw)
223 * Do the RequestConfiguration last, because it enables interrupts. 196 * Do the RequestConfiguration last, because it enables interrupts.
224 * Then we don't get any interrupts before we're ready for them. 197 * Then we don't get any interrupts before we're ready for them.
225 */ 198 */
226 ret = pcmcia_request_configuration(link, &link->conf); 199 ret = pcmcia_enable_device(link);
227
228 if (ret != 0) 200 if (ret != 0)
229 goto exit; 201 goto exit;
230 202
231 return 0; 203 return 0;
232 204
233exit: 205exit:
234 if (ipw->attr_memory) {
235 release_mem_region(ipw->request_attr_memory.Base,
236 ipw->request_attr_memory.Size);
237 iounmap(ipw->attr_memory);
238
239 }
240 if (ipw->common_memory) { 206 if (ipw->common_memory) {
241 release_mem_region(ipw->request_common_memory.Base, 207 release_mem_region(link->resource[2]->start,
242 ipw->request_common_memory.Size); 208 resource_size(link->resource[2]));
243 iounmap(ipw->common_memory); 209 iounmap(ipw->common_memory);
244 } 210 }
211 if (ipw->attr_memory) {
212 release_mem_region(link->resource[3]->start,
213 resource_size(link->resource[3]));
214 iounmap(ipw->attr_memory);
215 }
245 pcmcia_disable_device(link); 216 pcmcia_disable_device(link);
246 return -1; 217 return -1;
247} 218}
@@ -249,13 +220,13 @@ exit:
249static void release_ipwireless(struct ipw_dev *ipw) 220static void release_ipwireless(struct ipw_dev *ipw)
250{ 221{
251 if (ipw->common_memory) { 222 if (ipw->common_memory) {
252 release_mem_region(ipw->request_common_memory.Base, 223 release_mem_region(ipw->link->resource[2]->start,
253 ipw->request_common_memory.Size); 224 resource_size(ipw->link->resource[2]));
254 iounmap(ipw->common_memory); 225 iounmap(ipw->common_memory);
255 } 226 }
256 if (ipw->attr_memory) { 227 if (ipw->attr_memory) {
257 release_mem_region(ipw->request_attr_memory.Base, 228 release_mem_region(ipw->link->resource[3]->start,
258 ipw->request_attr_memory.Size); 229 resource_size(ipw->link->resource[3]));
259 iounmap(ipw->attr_memory); 230 iounmap(ipw->attr_memory);
260 } 231 }
261 pcmcia_disable_device(ipw->link); 232 pcmcia_disable_device(ipw->link);
@@ -324,7 +295,7 @@ static struct pcmcia_driver me = {
324 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
325 .probe = ipwireless_attach, 296 .probe = ipwireless_attach,
326 .remove = ipwireless_detach, 297 .remove = ipwireless_detach,
327 .drv = { .name = IPWIRELESS_PCCARD_NAME }, 298 .name = IPWIRELESS_PCCARD_NAME,
328 .id_table = ipw_ids 299 .id_table = ipw_ids
329}; 300};
330 301
@@ -336,9 +307,6 @@ static int __init init_ipwireless(void)
336{ 307{
337 int ret; 308 int ret;
338 309
339 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
340 IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
341
342 ret = ipwireless_tty_init(); 310 ret = ipwireless_tty_init();
343 if (ret != 0) 311 if (ret != 0)
344 return ret; 312 return ret;
@@ -355,9 +323,6 @@ static int __init init_ipwireless(void)
355 */ 323 */
356static void __exit exit_ipwireless(void) 324static void __exit exit_ipwireless(void)
357{ 325{
358 printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
359 IPWIRELESS_PCMCIA_VERSION " removed\n");
360
361 pcmcia_unregister_driver(&me); 326 pcmcia_unregister_driver(&me);
362 ipwireless_tty_release(); 327 ipwireless_tty_release();
363} 328}
diff --git a/drivers/char/pcmcia/ipwireless/main.h b/drivers/char/pcmcia/ipwireless/main.h
index c207be87b597..f2cbb116bccb 100644
--- a/drivers/char/pcmcia/ipwireless/main.h
+++ b/drivers/char/pcmcia/ipwireless/main.h
@@ -21,7 +21,6 @@
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/types.h> 22#include <linux/types.h>
23 23
24#include <pcmcia/cs.h>
25#include <pcmcia/cistpl.h> 24#include <pcmcia/cistpl.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
27 26
@@ -45,13 +44,9 @@ struct ipw_dev {
45 struct pcmcia_device *link; 44 struct pcmcia_device *link;
46 int is_v2_card; 45 int is_v2_card;
47 46
48 window_handle_t handle_attr_memory;
49 void __iomem *attr_memory; 47 void __iomem *attr_memory;
50 win_req_t request_attr_memory;
51 48
52 window_handle_t handle_common_memory;
53 void __iomem *common_memory; 49 void __iomem *common_memory;
54 win_req_t request_common_memory;
55 50
56 /* Reference to attribute memory, containing CIS data */ 51 /* Reference to attribute memory, containing CIS data */
57 void *attribute_memory; 52 void *attribute_memory;
diff --git a/drivers/char/pcmcia/ipwireless/tty.h b/drivers/char/pcmcia/ipwireless/tty.h
index 3e163d4cab15..747b2d637860 100644
--- a/drivers/char/pcmcia/ipwireless/tty.h
+++ b/drivers/char/pcmcia/ipwireless/tty.h
@@ -21,7 +21,6 @@
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/sched.h> 22#include <linux/sched.h>
23 23
24#include <pcmcia/cs.h>
25#include <pcmcia/cistpl.h> 24#include <pcmcia/cistpl.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
27 26
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 9ecd6bef5d3b..be1810057607 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -70,7 +70,6 @@
70#include <linux/workqueue.h> 70#include <linux/workqueue.h>
71#include <linux/hdlc.h> 71#include <linux/hdlc.h>
72 72
73#include <pcmcia/cs.h>
74#include <pcmcia/cistpl.h> 73#include <pcmcia/cistpl.h>
75#include <pcmcia/cisreg.h> 74#include <pcmcia/cisreg.h>
76#include <pcmcia/ds.h> 75#include <pcmcia/ds.h>
@@ -550,9 +549,6 @@ static int mgslpc_probe(struct pcmcia_device *link)
550 549
551 /* Initialize the struct pcmcia_device structure */ 550 /* Initialize the struct pcmcia_device structure */
552 551
553 link->conf.Attributes = 0;
554 link->conf.IntType = INT_MEMORY_AND_IO;
555
556 ret = mgslpc_config(link); 552 ret = mgslpc_config(link);
557 if (ret) 553 if (ret)
558 return ret; 554 return ret;
@@ -565,20 +561,8 @@ static int mgslpc_probe(struct pcmcia_device *link)
565/* Card has been inserted. 561/* Card has been inserted.
566 */ 562 */
567 563
568static int mgslpc_ioprobe(struct pcmcia_device *p_dev, 564static int mgslpc_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
569 cistpl_cftable_entry_t *cfg,
570 cistpl_cftable_entry_t *dflt,
571 unsigned int vcc,
572 void *priv_data)
573{ 565{
574 if (!cfg->io.nwin)
575 return -ENODEV;
576
577 p_dev->resource[0]->start = cfg->io.win[0].base;
578 p_dev->resource[0]->end = cfg->io.win[0].len;
579 p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
580 p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
581
582 return pcmcia_request_io(p_dev); 566 return pcmcia_request_io(p_dev);
583} 567}
584 568
@@ -590,32 +574,24 @@ static int mgslpc_config(struct pcmcia_device *link)
590 if (debug_level >= DEBUG_LEVEL_INFO) 574 if (debug_level >= DEBUG_LEVEL_INFO)
591 printk("mgslpc_config(0x%p)\n", link); 575 printk("mgslpc_config(0x%p)\n", link);
592 576
577 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
578
593 ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL); 579 ret = pcmcia_loop_config(link, mgslpc_ioprobe, NULL);
594 if (ret != 0) 580 if (ret != 0)
595 goto failed; 581 goto failed;
596 582
597 link->conf.Attributes = CONF_ENABLE_IRQ; 583 link->config_index = 8;
598 link->conf.IntType = INT_MEMORY_AND_IO; 584 link->config_regs = PRESENT_OPTION;
599 link->conf.ConfigIndex = 8;
600 link->conf.Present = PRESENT_OPTION;
601 585
602 ret = pcmcia_request_irq(link, mgslpc_isr); 586 ret = pcmcia_request_irq(link, mgslpc_isr);
603 if (ret) 587 if (ret)
604 goto failed; 588 goto failed;
605 ret = pcmcia_request_configuration(link, &link->conf); 589 ret = pcmcia_enable_device(link);
606 if (ret) 590 if (ret)
607 goto failed; 591 goto failed;
608 592
609 info->io_base = link->resource[0]->start; 593 info->io_base = link->resource[0]->start;
610 info->irq_level = link->irq; 594 info->irq_level = link->irq;
611
612 dev_info(&link->dev, "index 0x%02x:",
613 link->conf.ConfigIndex);
614 if (link->conf.Attributes & CONF_ENABLE_IRQ)
615 printk(", irq %d", link->irq);
616 if (link->resource[0])
617 printk(", io %pR", link->resource[0]);
618 printk("\n");
619 return 0; 595 return 0;
620 596
621failed: 597failed:
@@ -2797,9 +2773,7 @@ MODULE_DEVICE_TABLE(pcmcia, mgslpc_ids);
2797 2773
2798static struct pcmcia_driver mgslpc_driver = { 2774static struct pcmcia_driver mgslpc_driver = {
2799 .owner = THIS_MODULE, 2775 .owner = THIS_MODULE,
2800 .drv = { 2776 .name = "synclink_cs",
2801 .name = "synclink_cs",
2802 },
2803 .probe = mgslpc_probe, 2777 .probe = mgslpc_probe,
2804 .remove = mgslpc_detach, 2778 .remove = mgslpc_detach,
2805 .id_table = mgslpc_ids, 2779 .id_table = mgslpc_ids,
@@ -2835,8 +2809,6 @@ static void synclink_cs_cleanup(void)
2835{ 2809{
2836 int rc; 2810 int rc;
2837 2811
2838 printk("Unloading %s: version %s\n", driver_name, driver_version);
2839
2840 while(mgslpc_device_list) 2812 while(mgslpc_device_list)
2841 mgslpc_remove_device(mgslpc_device_list); 2813 mgslpc_remove_device(mgslpc_device_list);
2842 2814
@@ -2859,8 +2831,6 @@ static int __init synclink_cs_init(void)
2859 BREAKPOINT(); 2831 BREAKPOINT();
2860 } 2832 }
2861 2833
2862 printk("%s %s\n", driver_name, driver_version);
2863
2864 if ((rc = pcmcia_register_driver(&mgslpc_driver)) < 0) 2834 if ((rc = pcmcia_register_driver(&mgslpc_driver)) < 0)
2865 return rc; 2835 return rc;
2866 2836
@@ -4127,6 +4097,8 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4127 if (cmd != SIOCWANDEV) 4097 if (cmd != SIOCWANDEV)
4128 return hdlc_ioctl(dev, ifr, cmd); 4098 return hdlc_ioctl(dev, ifr, cmd);
4129 4099
4100 memset(&new_line, 0, size);
4101
4130 switch(ifr->ifr_settings.type) { 4102 switch(ifr->ifr_settings.type) {
4131 case IF_GET_IFACE: /* return current sync_serial_settings */ 4103 case IF_GET_IFACE: /* return current sync_serial_settings */
4132 4104
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 02abfddce45a..723152d978a9 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -67,7 +67,7 @@
67#include <linux/slab.h> 67#include <linux/slab.h>
68#include <linux/major.h> 68#include <linux/major.h>
69#include <linux/ppdev.h> 69#include <linux/ppdev.h>
70#include <linux/smp_lock.h> 70#include <linux/mutex.h>
71#include <linux/uaccess.h> 71#include <linux/uaccess.h>
72 72
73#define PP_VERSION "ppdev: user-space parallel port driver" 73#define PP_VERSION "ppdev: user-space parallel port driver"
@@ -97,6 +97,7 @@ struct pp_struct {
97/* ROUND_UP macro from fs/select.c */ 97/* ROUND_UP macro from fs/select.c */
98#define ROUND_UP(x,y) (((x)+(y)-1)/(y)) 98#define ROUND_UP(x,y) (((x)+(y)-1)/(y))
99 99
100static DEFINE_MUTEX(pp_do_mutex);
100static inline void pp_enable_irq (struct pp_struct *pp) 101static inline void pp_enable_irq (struct pp_struct *pp)
101{ 102{
102 struct parport *port = pp->pdev->port; 103 struct parport *port = pp->pdev->port;
@@ -630,9 +631,9 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
630static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 631static long pp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
631{ 632{
632 long ret; 633 long ret;
633 lock_kernel(); 634 mutex_lock(&pp_do_mutex);
634 ret = pp_do_ioctl(file, cmd, arg); 635 ret = pp_do_ioctl(file, cmd, arg);
635 unlock_kernel(); 636 mutex_unlock(&pp_do_mutex);
636 return ret; 637 return ret;
637} 638}
638 639
@@ -641,7 +642,6 @@ static int pp_open (struct inode * inode, struct file * file)
641 unsigned int minor = iminor(inode); 642 unsigned int minor = iminor(inode);
642 struct pp_struct *pp; 643 struct pp_struct *pp;
643 644
644 cycle_kernel_lock();
645 if (minor >= PARPORT_MAX) 645 if (minor >= PARPORT_MAX)
646 return -ENXIO; 646 return -ENXIO;
647 647
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 28c0169e34da..bfe25ea9766b 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -19,8 +19,8 @@
19#include <linux/cdev.h> 19#include <linux/cdev.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/smp_lock.h>
23#include <linux/gfp.h> 22#include <linux/gfp.h>
23#include <linux/compat.h>
24 24
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26 26
@@ -55,7 +55,6 @@ static int raw_open(struct inode *inode, struct file *filp)
55 return 0; 55 return 0;
56 } 56 }
57 57
58 lock_kernel();
59 mutex_lock(&raw_mutex); 58 mutex_lock(&raw_mutex);
60 59
61 /* 60 /*
@@ -82,7 +81,6 @@ static int raw_open(struct inode *inode, struct file *filp)
82 bdev->bd_inode->i_mapping; 81 bdev->bd_inode->i_mapping;
83 filp->private_data = bdev; 82 filp->private_data = bdev;
84 mutex_unlock(&raw_mutex); 83 mutex_unlock(&raw_mutex);
85 unlock_kernel();
86 return 0; 84 return 0;
87 85
88out2: 86out2:
@@ -91,7 +89,6 @@ out1:
91 blkdev_put(bdev, filp->f_mode); 89 blkdev_put(bdev, filp->f_mode);
92out: 90out:
93 mutex_unlock(&raw_mutex); 91 mutex_unlock(&raw_mutex);
94 unlock_kernel();
95 return err; 92 return err;
96} 93}
97 94
@@ -125,20 +122,84 @@ static long
125raw_ioctl(struct file *filp, unsigned int command, unsigned long arg) 122raw_ioctl(struct file *filp, unsigned int command, unsigned long arg)
126{ 123{
127 struct block_device *bdev = filp->private_data; 124 struct block_device *bdev = filp->private_data;
128 int ret; 125 return blkdev_ioctl(bdev, 0, command, arg);
126}
127
128static int bind_set(int number, u64 major, u64 minor)
129{
130 dev_t dev = MKDEV(major, minor);
131 struct raw_device_data *rawdev;
132 int err = 0;
129 133
130 lock_kernel(); 134 if (number <= 0 || number >= MAX_RAW_MINORS)
131 ret = blkdev_ioctl(bdev, 0, command, arg); 135 return -EINVAL;
132 unlock_kernel();
133 136
134 return ret; 137 if (MAJOR(dev) != major || MINOR(dev) != minor)
138 return -EINVAL;
139
140 rawdev = &raw_devices[number];
141
142 /*
143 * This is like making block devices, so demand the
144 * same capability
145 */
146 if (!capable(CAP_SYS_ADMIN))
147 return -EPERM;
148
149 /*
150 * For now, we don't need to check that the underlying
151 * block device is present or not: we can do that when
152 * the raw device is opened. Just check that the
153 * major/minor numbers make sense.
154 */
155
156 if (MAJOR(dev) == 0 && dev != 0)
157 return -EINVAL;
158
159 mutex_lock(&raw_mutex);
160 if (rawdev->inuse) {
161 mutex_unlock(&raw_mutex);
162 return -EBUSY;
163 }
164 if (rawdev->binding) {
165 bdput(rawdev->binding);
166 module_put(THIS_MODULE);
167 }
168 if (!dev) {
169 /* unbind */
170 rawdev->binding = NULL;
171 device_destroy(raw_class, MKDEV(RAW_MAJOR, number));
172 } else {
173 rawdev->binding = bdget(dev);
174 if (rawdev->binding == NULL) {
175 err = -ENOMEM;
176 } else {
177 dev_t raw = MKDEV(RAW_MAJOR, number);
178 __module_get(THIS_MODULE);
179 device_destroy(raw_class, raw);
180 device_create(raw_class, NULL, raw, NULL,
181 "raw%d", number);
182 }
183 }
184 mutex_unlock(&raw_mutex);
185 return err;
135} 186}
136 187
137static void bind_device(struct raw_config_request *rq) 188static int bind_get(int number, dev_t *dev)
138{ 189{
139 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor)); 190 struct raw_device_data *rawdev;
140 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor), NULL, 191 struct block_device *bdev;
141 "raw%d", rq->raw_minor); 192
193 if (number <= 0 || number >= MAX_RAW_MINORS)
194 return -EINVAL;
195
196 rawdev = &raw_devices[number];
197
198 mutex_lock(&raw_mutex);
199 bdev = rawdev->binding;
200 *dev = bdev ? bdev->bd_dev : 0;
201 mutex_unlock(&raw_mutex);
202 return 0;
142} 203}
143 204
144/* 205/*
@@ -149,105 +210,78 @@ static long raw_ctl_ioctl(struct file *filp, unsigned int command,
149 unsigned long arg) 210 unsigned long arg)
150{ 211{
151 struct raw_config_request rq; 212 struct raw_config_request rq;
152 struct raw_device_data *rawdev; 213 dev_t dev;
153 int err = 0; 214 int err;
154 215
155 lock_kernel();
156 switch (command) { 216 switch (command) {
157 case RAW_SETBIND: 217 case RAW_SETBIND:
218 if (copy_from_user(&rq, (void __user *) arg, sizeof(rq)))
219 return -EFAULT;
220
221 return bind_set(rq.raw_minor, rq.block_major, rq.block_minor);
222
158 case RAW_GETBIND: 223 case RAW_GETBIND:
224 if (copy_from_user(&rq, (void __user *) arg, sizeof(rq)))
225 return -EFAULT;
159 226
160 /* First, find out which raw minor we want */ 227 err = bind_get(rq.raw_minor, &dev);
228 if (err)
229 return err;
161 230
162 if (copy_from_user(&rq, (void __user *) arg, sizeof(rq))) { 231 rq.block_major = MAJOR(dev);
163 err = -EFAULT; 232 rq.block_minor = MINOR(dev);
164 goto out;
165 }
166 233
167 if (rq.raw_minor <= 0 || rq.raw_minor >= MAX_RAW_MINORS) { 234 if (copy_to_user((void __user *)arg, &rq, sizeof(rq)))
168 err = -EINVAL; 235 return -EFAULT;
169 goto out; 236
170 } 237 return 0;
171 rawdev = &raw_devices[rq.raw_minor];
172
173 if (command == RAW_SETBIND) {
174 dev_t dev;
175
176 /*
177 * This is like making block devices, so demand the
178 * same capability
179 */
180 if (!capable(CAP_SYS_ADMIN)) {
181 err = -EPERM;
182 goto out;
183 }
184
185 /*
186 * For now, we don't need to check that the underlying
187 * block device is present or not: we can do that when
188 * the raw device is opened. Just check that the
189 * major/minor numbers make sense.
190 */
191
192 dev = MKDEV(rq.block_major, rq.block_minor);
193 if ((rq.block_major == 0 && rq.block_minor != 0) ||
194 MAJOR(dev) != rq.block_major ||
195 MINOR(dev) != rq.block_minor) {
196 err = -EINVAL;
197 goto out;
198 }
199
200 mutex_lock(&raw_mutex);
201 if (rawdev->inuse) {
202 mutex_unlock(&raw_mutex);
203 err = -EBUSY;
204 goto out;
205 }
206 if (rawdev->binding) {
207 bdput(rawdev->binding);
208 module_put(THIS_MODULE);
209 }
210 if (rq.block_major == 0 && rq.block_minor == 0) {
211 /* unbind */
212 rawdev->binding = NULL;
213 device_destroy(raw_class,
214 MKDEV(RAW_MAJOR, rq.raw_minor));
215 } else {
216 rawdev->binding = bdget(dev);
217 if (rawdev->binding == NULL)
218 err = -ENOMEM;
219 else {
220 __module_get(THIS_MODULE);
221 bind_device(&rq);
222 }
223 }
224 mutex_unlock(&raw_mutex);
225 } else {
226 struct block_device *bdev;
227
228 mutex_lock(&raw_mutex);
229 bdev = rawdev->binding;
230 if (bdev) {
231 rq.block_major = MAJOR(bdev->bd_dev);
232 rq.block_minor = MINOR(bdev->bd_dev);
233 } else {
234 rq.block_major = rq.block_minor = 0;
235 }
236 mutex_unlock(&raw_mutex);
237 if (copy_to_user((void __user *)arg, &rq, sizeof(rq))) {
238 err = -EFAULT;
239 goto out;
240 }
241 }
242 break;
243 default:
244 err = -EINVAL;
245 break;
246 } 238 }
247out: 239
248 unlock_kernel(); 240 return -EINVAL;
249 return err; 241}
242
243#ifdef CONFIG_COMPAT
244struct raw32_config_request {
245 compat_int_t raw_minor;
246 compat_u64 block_major;
247 compat_u64 block_minor;
248};
249
250static long raw_ctl_compat_ioctl(struct file *file, unsigned int cmd,
251 unsigned long arg)
252{
253 struct raw32_config_request __user *user_req = compat_ptr(arg);
254 struct raw32_config_request rq;
255 dev_t dev;
256 int err = 0;
257
258 switch (cmd) {
259 case RAW_SETBIND:
260 if (copy_from_user(&rq, user_req, sizeof(rq)))
261 return -EFAULT;
262
263 return bind_set(rq.raw_minor, rq.block_major, rq.block_minor);
264
265 case RAW_GETBIND:
266 if (copy_from_user(&rq, user_req, sizeof(rq)))
267 return -EFAULT;
268
269 err = bind_get(rq.raw_minor, &dev);
270 if (err)
271 return err;
272
273 rq.block_major = MAJOR(dev);
274 rq.block_minor = MINOR(dev);
275
276 if (copy_to_user(user_req, &rq, sizeof(rq)))
277 return -EFAULT;
278
279 return 0;
280 }
281
282 return -EINVAL;
250} 283}
284#endif
251 285
252static const struct file_operations raw_fops = { 286static const struct file_operations raw_fops = {
253 .read = do_sync_read, 287 .read = do_sync_read,
@@ -264,6 +298,9 @@ static const struct file_operations raw_fops = {
264 298
265static const struct file_operations raw_ctl_fops = { 299static const struct file_operations raw_ctl_fops = {
266 .unlocked_ioctl = raw_ctl_ioctl, 300 .unlocked_ioctl = raw_ctl_ioctl,
301#ifdef CONFIG_COMPAT
302 .compat_ioctl = raw_ctl_compat_ioctl,
303#endif
267 .open = raw_open, 304 .open = raw_open,
268 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
269 .llseek = noop_llseek, 306 .llseek = noop_llseek,
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index 1e87a93164bf..5e33293d24e3 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -44,7 +44,7 @@
44#include <linux/delay.h> 44#include <linux/delay.h>
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/smp_lock.h> 47#include <linux/mutex.h>
48#include <linux/miscdevice.h> 48#include <linux/miscdevice.h>
49#include <linux/init.h> 49#include <linux/init.h>
50 50
@@ -122,6 +122,7 @@ more than 512 ports.... */
122 122
123 123
124/* These constants are derived from SCO Source */ 124/* These constants are derived from SCO Source */
125static DEFINE_MUTEX(rio_fw_mutex);
125static struct Conf 126static struct Conf
126 RIOConf = { 127 RIOConf = {
127 /* locator */ "RIO Config here", 128 /* locator */ "RIO Config here",
@@ -567,9 +568,9 @@ static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
567 func_enter(); 568 func_enter();
568 569
569 /* The "dev" argument isn't used. */ 570 /* The "dev" argument isn't used. */
570 lock_kernel(); 571 mutex_lock(&rio_fw_mutex);
571 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN)); 572 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
572 unlock_kernel(); 573 mutex_unlock(&rio_fw_mutex);
573 574
574 func_exit(); 575 func_exit();
575 return rc; 576 return rc;
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 444ce17ac722..5816b39ff5a9 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -21,7 +21,7 @@
21#include <linux/poll.h> 21#include <linux/poll.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/smp_lock.h> 24#include <linux/mutex.h>
25#include <asm/sn/io.h> 25#include <asm/sn/io.h>
26#include <asm/sn/sn_sal.h> 26#include <asm/sn/sn_sal.h>
27#include <asm/sn/module.h> 27#include <asm/sn/module.h>
@@ -34,6 +34,7 @@
34#define SCDRV_BUFSZ 2048 34#define SCDRV_BUFSZ 2048
35#define SCDRV_TIMEOUT 1000 35#define SCDRV_TIMEOUT 1000
36 36
37static DEFINE_MUTEX(scdrv_mutex);
37static irqreturn_t 38static irqreturn_t
38scdrv_interrupt(int irq, void *subch_data) 39scdrv_interrupt(int irq, void *subch_data)
39{ 40{
@@ -105,7 +106,7 @@ scdrv_open(struct inode *inode, struct file *file)
105 file->private_data = sd; 106 file->private_data = sd;
106 107
107 /* hook this subchannel up to the system controller interrupt */ 108 /* hook this subchannel up to the system controller interrupt */
108 lock_kernel(); 109 mutex_lock(&scdrv_mutex);
109 rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt, 110 rv = request_irq(SGI_UART_VECTOR, scdrv_interrupt,
110 IRQF_SHARED | IRQF_DISABLED, 111 IRQF_SHARED | IRQF_DISABLED,
111 SYSCTL_BASENAME, sd); 112 SYSCTL_BASENAME, sd);
@@ -113,10 +114,10 @@ scdrv_open(struct inode *inode, struct file *file)
113 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch); 114 ia64_sn_irtr_close(sd->sd_nasid, sd->sd_subch);
114 kfree(sd); 115 kfree(sd);
115 printk("%s: irq request failed (%d)\n", __func__, rv); 116 printk("%s: irq request failed (%d)\n", __func__, rv);
116 unlock_kernel(); 117 mutex_unlock(&scdrv_mutex);
117 return -EBUSY; 118 return -EBUSY;
118 } 119 }
119 unlock_kernel(); 120 mutex_unlock(&scdrv_mutex);
120 return 0; 121 return 0;
121} 122}
122 123
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index d087532b29d7..0c964cdcc223 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -37,7 +37,7 @@
37#include <linux/ioport.h> 37#include <linux/ioport.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/smp_lock.h> 40#include <linux/mutex.h>
41#include <linux/timer.h> 41#include <linux/timer.h>
42#include <linux/sysfs.h> 42#include <linux/sysfs.h>
43#include <linux/device.h> 43#include <linux/device.h>
@@ -206,7 +206,7 @@ static int tlclk_open(struct inode *inode, struct file *filp)
206{ 206{
207 int result; 207 int result;
208 208
209 lock_kernel(); 209 mutex_lock(&tlclk_mutex);
210 if (test_and_set_bit(0, &useflags)) { 210 if (test_and_set_bit(0, &useflags)) {
211 result = -EBUSY; 211 result = -EBUSY;
212 /* this legacy device is always one per system and it doesn't 212 /* this legacy device is always one per system and it doesn't
@@ -229,7 +229,7 @@ static int tlclk_open(struct inode *inode, struct file *filp)
229 inb(TLCLK_REG6); /* Clear interrupt events */ 229 inb(TLCLK_REG6); /* Clear interrupt events */
230 230
231out: 231out:
232 unlock_kernel(); 232 mutex_unlock(&tlclk_mutex);
233 return result; 233 return result;
234} 234}
235 235
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index 3d6e96172453..014c9d90d297 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -68,7 +68,7 @@
68#include <linux/stat.h> 68#include <linux/stat.h>
69#include <linux/proc_fs.h> 69#include <linux/proc_fs.h>
70#include <linux/seq_file.h> 70#include <linux/seq_file.h>
71#include <linux/smp_lock.h> 71#include <linux/mutex.h>
72#include <linux/toshiba.h> 72#include <linux/toshiba.h>
73 73
74#define TOSH_MINOR_DEV 181 74#define TOSH_MINOR_DEV 181
@@ -78,6 +78,7 @@ MODULE_AUTHOR("Jonathan Buzzard <jonathan@buzzard.org.uk>");
78MODULE_DESCRIPTION("Toshiba laptop SMM driver"); 78MODULE_DESCRIPTION("Toshiba laptop SMM driver");
79MODULE_SUPPORTED_DEVICE("toshiba"); 79MODULE_SUPPORTED_DEVICE("toshiba");
80 80
81static DEFINE_MUTEX(tosh_mutex);
81static int tosh_fn; 82static int tosh_fn;
82module_param_named(fn, tosh_fn, int, 0); 83module_param_named(fn, tosh_fn, int, 0);
83MODULE_PARM_DESC(fn, "User specified Fn key detection port"); 84MODULE_PARM_DESC(fn, "User specified Fn key detection port");
@@ -275,16 +276,16 @@ static long tosh_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
275 return -EINVAL; 276 return -EINVAL;
276 277
277 /* do we need to emulate the fan ? */ 278 /* do we need to emulate the fan ? */
278 lock_kernel(); 279 mutex_lock(&tosh_mutex);
279 if (tosh_fan==1) { 280 if (tosh_fan==1) {
280 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) { 281 if (((ax==0xf300) || (ax==0xf400)) && (bx==0x0004)) {
281 err = tosh_emulate_fan(&regs); 282 err = tosh_emulate_fan(&regs);
282 unlock_kernel(); 283 mutex_unlock(&tosh_mutex);
283 break; 284 break;
284 } 285 }
285 } 286 }
286 err = tosh_smm(&regs); 287 err = tosh_smm(&regs);
287 unlock_kernel(); 288 mutex_unlock(&tosh_mutex);
288 break; 289 break;
289 default: 290 default:
290 return -EINVAL; 291 return -EINVAL;
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 05ad4a17a28f..7c4133582dba 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -47,6 +47,16 @@ enum tpm_duration {
47#define TPM_MAX_PROTECTED_ORDINAL 12 47#define TPM_MAX_PROTECTED_ORDINAL 12
48#define TPM_PROTECTED_ORDINAL_MASK 0xFF 48#define TPM_PROTECTED_ORDINAL_MASK 0xFF
49 49
50/*
51 * Bug workaround - some TPM's don't flush the most
52 * recently changed pcr on suspend, so force the flush
53 * with an extend to the selected _unused_ non-volatile pcr.
54 */
55static int tpm_suspend_pcr;
56module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
57MODULE_PARM_DESC(suspend_pcr,
58 "PCR to use for dummy writes to faciltate flush on suspend.");
59
50static LIST_HEAD(tpm_chip_list); 60static LIST_HEAD(tpm_chip_list);
51static DEFINE_SPINLOCK(driver_lock); 61static DEFINE_SPINLOCK(driver_lock);
52static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES); 62static DECLARE_BITMAP(dev_mask, TPM_NUM_DEVICES);
@@ -1077,18 +1087,6 @@ static struct tpm_input_header savestate_header = {
1077 .ordinal = TPM_ORD_SAVESTATE 1087 .ordinal = TPM_ORD_SAVESTATE
1078}; 1088};
1079 1089
1080/* Bug workaround - some TPM's don't flush the most
1081 * recently changed pcr on suspend, so force the flush
1082 * with an extend to the selected _unused_ non-volatile pcr.
1083 */
1084static int tpm_suspend_pcr;
1085static int __init tpm_suspend_setup(char *str)
1086{
1087 get_option(&str, &tpm_suspend_pcr);
1088 return 1;
1089}
1090__setup("tpm_suspend_pcr=", tpm_suspend_setup);
1091
1092/* 1090/*
1093 * We are about to suspend. Save the TPM state 1091 * We are about to suspend. Save the TPM state
1094 * so that it can be restored. 1092 * so that it can be restored.
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 442c3f5b642a..ad6e64a2912d 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -46,7 +46,7 @@
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/proc_fs.h> 47#include <linux/proc_fs.h>
48#include <linux/seq_file.h> 48#include <linux/seq_file.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51 51
52#include <asm/uaccess.h> 52#include <asm/uaccess.h>
@@ -64,6 +64,7 @@
64#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: " 64#define VIOTAPE_KERN_WARN KERN_WARNING "viotape: "
65#define VIOTAPE_KERN_INFO KERN_INFO "viotape: " 65#define VIOTAPE_KERN_INFO KERN_INFO "viotape: "
66 66
67static DEFINE_MUTEX(proc_viotape_mutex);
67static int viotape_numdev; 68static int viotape_numdev;
68 69
69/* 70/*
@@ -684,9 +685,9 @@ static long viotap_unlocked_ioctl(struct file *file,
684{ 685{
685 long rc; 686 long rc;
686 687
687 lock_kernel(); 688 mutex_lock(&proc_viotape_mutex);
688 rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg); 689 rc = viotap_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
689 unlock_kernel(); 690 mutex_unlock(&proc_viotape_mutex);
690 return rc; 691 return rc;
691} 692}
692 693
@@ -700,7 +701,7 @@ static int viotap_open(struct inode *inode, struct file *file)
700 if (op == NULL) 701 if (op == NULL)
701 return -ENOMEM; 702 return -ENOMEM;
702 703
703 lock_kernel(); 704 mutex_lock(&proc_viotape_mutex);
704 get_dev_info(file->f_path.dentry->d_inode, &devi); 705 get_dev_info(file->f_path.dentry->d_inode, &devi);
705 706
706 /* Note: We currently only support one mode! */ 707 /* Note: We currently only support one mode! */
@@ -731,7 +732,7 @@ static int viotap_open(struct inode *inode, struct file *file)
731 732
732free_op: 733free_op:
733 free_op_struct(op); 734 free_op_struct(op);
734 unlock_kernel(); 735 mutex_unlock(&proc_viotape_mutex);
735 return ret; 736 return ret;
736} 737}
737 738
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 942a9826bd23..6c1b676643a9 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -48,6 +48,9 @@ struct ports_driver_data {
48 /* Used for exporting per-port information to debugfs */ 48 /* Used for exporting per-port information to debugfs */
49 struct dentry *debugfs_dir; 49 struct dentry *debugfs_dir;
50 50
51 /* List of all the devices we're handling */
52 struct list_head portdevs;
53
51 /* Number of devices this driver is handling */ 54 /* Number of devices this driver is handling */
52 unsigned int index; 55 unsigned int index;
53 56
@@ -108,6 +111,9 @@ struct port_buffer {
108 * ports for that device (vdev->priv). 111 * ports for that device (vdev->priv).
109 */ 112 */
110struct ports_device { 113struct ports_device {
114 /* Next portdev in the list, head is in the pdrvdata struct */
115 struct list_head list;
116
111 /* 117 /*
112 * Workqueue handlers where we process deferred work after 118 * Workqueue handlers where we process deferred work after
113 * notification 119 * notification
@@ -178,15 +184,21 @@ struct port {
178 struct console cons; 184 struct console cons;
179 185
180 /* Each port associates with a separate char device */ 186 /* Each port associates with a separate char device */
181 struct cdev cdev; 187 struct cdev *cdev;
182 struct device *dev; 188 struct device *dev;
183 189
190 /* Reference-counting to handle port hot-unplugs and file operations */
191 struct kref kref;
192
184 /* A waitqueue for poll() or blocking read operations */ 193 /* A waitqueue for poll() or blocking read operations */
185 wait_queue_head_t waitqueue; 194 wait_queue_head_t waitqueue;
186 195
187 /* The 'name' of the port that we expose via sysfs properties */ 196 /* The 'name' of the port that we expose via sysfs properties */
188 char *name; 197 char *name;
189 198
199 /* We can notify apps of host connect / disconnect events via SIGIO */
200 struct fasync_struct *async_queue;
201
190 /* The 'id' to identify the port with the Host */ 202 /* The 'id' to identify the port with the Host */
191 u32 id; 203 u32 id;
192 204
@@ -221,6 +233,41 @@ out:
221 return port; 233 return port;
222} 234}
223 235
236static struct port *find_port_by_devt_in_portdev(struct ports_device *portdev,
237 dev_t dev)
238{
239 struct port *port;
240 unsigned long flags;
241
242 spin_lock_irqsave(&portdev->ports_lock, flags);
243 list_for_each_entry(port, &portdev->ports, list)
244 if (port->cdev->dev == dev)
245 goto out;
246 port = NULL;
247out:
248 spin_unlock_irqrestore(&portdev->ports_lock, flags);
249
250 return port;
251}
252
253static struct port *find_port_by_devt(dev_t dev)
254{
255 struct ports_device *portdev;
256 struct port *port;
257 unsigned long flags;
258
259 spin_lock_irqsave(&pdrvdata_lock, flags);
260 list_for_each_entry(portdev, &pdrvdata.portdevs, list) {
261 port = find_port_by_devt_in_portdev(portdev, dev);
262 if (port)
263 goto out;
264 }
265 port = NULL;
266out:
267 spin_unlock_irqrestore(&pdrvdata_lock, flags);
268 return port;
269}
270
224static struct port *find_port_by_id(struct ports_device *portdev, u32 id) 271static struct port *find_port_by_id(struct ports_device *portdev, u32 id)
225{ 272{
226 struct port *port; 273 struct port *port;
@@ -410,7 +457,10 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
410static ssize_t send_control_msg(struct port *port, unsigned int event, 457static ssize_t send_control_msg(struct port *port, unsigned int event,
411 unsigned int value) 458 unsigned int value)
412{ 459{
413 return __send_control_msg(port->portdev, port->id, event, value); 460 /* Did the port get unplugged before userspace closed it? */
461 if (port->portdev)
462 return __send_control_msg(port->portdev, port->id, event, value);
463 return 0;
414} 464}
415 465
416/* Callers must take the port->outvq_lock */ 466/* Callers must take the port->outvq_lock */
@@ -459,9 +509,12 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count,
459 509
460 /* 510 /*
461 * Wait till the host acknowledges it pushed out the data we 511 * Wait till the host acknowledges it pushed out the data we
462 * sent. This is done for ports in blocking mode or for data 512 * sent. This is done for data from the hvc_console; the tty
463 * from the hvc_console; the tty operations are performed with 513 * operations are performed with spinlocks held so we can't
464 * spinlocks held so we can't sleep here. 514 * sleep here. An alternative would be to copy the data to a
515 * buffer and relax the spinning requirement. The downside is
516 * we need to kmalloc a GFP_ATOMIC buffer each time the
517 * console driver writes something out.
465 */ 518 */
466 while (!virtqueue_get_buf(out_vq, &len)) 519 while (!virtqueue_get_buf(out_vq, &len))
467 cpu_relax(); 520 cpu_relax();
@@ -522,6 +575,10 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
522/* The condition that must be true for polling to end */ 575/* The condition that must be true for polling to end */
523static bool will_read_block(struct port *port) 576static bool will_read_block(struct port *port)
524{ 577{
578 if (!port->guest_connected) {
579 /* Port got hot-unplugged. Let's exit. */
580 return false;
581 }
525 return !port_has_data(port) && port->host_connected; 582 return !port_has_data(port) && port->host_connected;
526} 583}
527 584
@@ -572,6 +629,9 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
572 if (ret < 0) 629 if (ret < 0)
573 return ret; 630 return ret;
574 } 631 }
632 /* Port got hot-unplugged. */
633 if (!port->guest_connected)
634 return -ENODEV;
575 /* 635 /*
576 * We could've received a disconnection message while we were 636 * We could've received a disconnection message while we were
577 * waiting for more data. 637 * waiting for more data.
@@ -596,6 +656,10 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
596 ssize_t ret; 656 ssize_t ret;
597 bool nonblock; 657 bool nonblock;
598 658
659 /* Userspace could be out to fool us */
660 if (!count)
661 return 0;
662
599 port = filp->private_data; 663 port = filp->private_data;
600 664
601 nonblock = filp->f_flags & O_NONBLOCK; 665 nonblock = filp->f_flags & O_NONBLOCK;
@@ -609,6 +673,9 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
609 if (ret < 0) 673 if (ret < 0)
610 return ret; 674 return ret;
611 } 675 }
676 /* Port got hot-unplugged. */
677 if (!port->guest_connected)
678 return -ENODEV;
612 679
613 count = min((size_t)(32 * 1024), count); 680 count = min((size_t)(32 * 1024), count);
614 681
@@ -622,6 +689,14 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
622 goto free_buf; 689 goto free_buf;
623 } 690 }
624 691
692 /*
693 * We now ask send_buf() to not spin for generic ports -- we
694 * can re-use the same code path that non-blocking file
695 * descriptors take for blocking file descriptors since the
696 * wait is already done and we're certain the write will go
697 * through to the host.
698 */
699 nonblock = true;
625 ret = send_buf(port, buf, count, nonblock); 700 ret = send_buf(port, buf, count, nonblock);
626 701
627 if (nonblock && ret > 0) 702 if (nonblock && ret > 0)
@@ -641,8 +716,12 @@ static unsigned int port_fops_poll(struct file *filp, poll_table *wait)
641 port = filp->private_data; 716 port = filp->private_data;
642 poll_wait(filp, &port->waitqueue, wait); 717 poll_wait(filp, &port->waitqueue, wait);
643 718
719 if (!port->guest_connected) {
720 /* Port got unplugged */
721 return POLLHUP;
722 }
644 ret = 0; 723 ret = 0;
645 if (port->inbuf) 724 if (!will_read_block(port))
646 ret |= POLLIN | POLLRDNORM; 725 ret |= POLLIN | POLLRDNORM;
647 if (!will_write_block(port)) 726 if (!will_write_block(port))
648 ret |= POLLOUT; 727 ret |= POLLOUT;
@@ -652,6 +731,8 @@ static unsigned int port_fops_poll(struct file *filp, poll_table *wait)
652 return ret; 731 return ret;
653} 732}
654 733
734static void remove_port(struct kref *kref);
735
655static int port_fops_release(struct inode *inode, struct file *filp) 736static int port_fops_release(struct inode *inode, struct file *filp)
656{ 737{
657 struct port *port; 738 struct port *port;
@@ -672,6 +753,16 @@ static int port_fops_release(struct inode *inode, struct file *filp)
672 reclaim_consumed_buffers(port); 753 reclaim_consumed_buffers(port);
673 spin_unlock_irq(&port->outvq_lock); 754 spin_unlock_irq(&port->outvq_lock);
674 755
756 /*
757 * Locks aren't necessary here as a port can't be opened after
758 * unplug, and if a port isn't unplugged, a kref would already
759 * exist for the port. Plus, taking ports_lock here would
760 * create a dependency on other locks taken by functions
761 * inside remove_port if we're the last holder of the port,
762 * creating many problems.
763 */
764 kref_put(&port->kref, remove_port);
765
675 return 0; 766 return 0;
676} 767}
677 768
@@ -679,22 +770,31 @@ static int port_fops_open(struct inode *inode, struct file *filp)
679{ 770{
680 struct cdev *cdev = inode->i_cdev; 771 struct cdev *cdev = inode->i_cdev;
681 struct port *port; 772 struct port *port;
773 int ret;
682 774
683 port = container_of(cdev, struct port, cdev); 775 port = find_port_by_devt(cdev->dev);
684 filp->private_data = port; 776 filp->private_data = port;
685 777
778 /* Prevent against a port getting hot-unplugged at the same time */
779 spin_lock_irq(&port->portdev->ports_lock);
780 kref_get(&port->kref);
781 spin_unlock_irq(&port->portdev->ports_lock);
782
686 /* 783 /*
687 * Don't allow opening of console port devices -- that's done 784 * Don't allow opening of console port devices -- that's done
688 * via /dev/hvc 785 * via /dev/hvc
689 */ 786 */
690 if (is_console_port(port)) 787 if (is_console_port(port)) {
691 return -ENXIO; 788 ret = -ENXIO;
789 goto out;
790 }
692 791
693 /* Allow only one process to open a particular port at a time */ 792 /* Allow only one process to open a particular port at a time */
694 spin_lock_irq(&port->inbuf_lock); 793 spin_lock_irq(&port->inbuf_lock);
695 if (port->guest_connected) { 794 if (port->guest_connected) {
696 spin_unlock_irq(&port->inbuf_lock); 795 spin_unlock_irq(&port->inbuf_lock);
697 return -EMFILE; 796 ret = -EMFILE;
797 goto out;
698 } 798 }
699 799
700 port->guest_connected = true; 800 port->guest_connected = true;
@@ -709,10 +809,23 @@ static int port_fops_open(struct inode *inode, struct file *filp)
709 reclaim_consumed_buffers(port); 809 reclaim_consumed_buffers(port);
710 spin_unlock_irq(&port->outvq_lock); 810 spin_unlock_irq(&port->outvq_lock);
711 811
812 nonseekable_open(inode, filp);
813
712 /* Notify host of port being opened */ 814 /* Notify host of port being opened */
713 send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1); 815 send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1);
714 816
715 return 0; 817 return 0;
818out:
819 kref_put(&port->kref, remove_port);
820 return ret;
821}
822
823static int port_fops_fasync(int fd, struct file *filp, int mode)
824{
825 struct port *port;
826
827 port = filp->private_data;
828 return fasync_helper(fd, filp, mode, &port->async_queue);
716} 829}
717 830
718/* 831/*
@@ -728,6 +841,8 @@ static const struct file_operations port_fops = {
728 .write = port_fops_write, 841 .write = port_fops_write,
729 .poll = port_fops_poll, 842 .poll = port_fops_poll,
730 .release = port_fops_release, 843 .release = port_fops_release,
844 .fasync = port_fops_fasync,
845 .llseek = no_llseek,
731}; 846};
732 847
733/* 848/*
@@ -986,6 +1101,12 @@ static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
986 return nr_added_bufs; 1101 return nr_added_bufs;
987} 1102}
988 1103
1104static void send_sigio_to_port(struct port *port)
1105{
1106 if (port->async_queue && port->guest_connected)
1107 kill_fasync(&port->async_queue, SIGIO, POLL_OUT);
1108}
1109
989static int add_port(struct ports_device *portdev, u32 id) 1110static int add_port(struct ports_device *portdev, u32 id)
990{ 1111{
991 char debugfs_name[16]; 1112 char debugfs_name[16];
@@ -1000,6 +1121,7 @@ static int add_port(struct ports_device *portdev, u32 id)
1000 err = -ENOMEM; 1121 err = -ENOMEM;
1001 goto fail; 1122 goto fail;
1002 } 1123 }
1124 kref_init(&port->kref);
1003 1125
1004 port->portdev = portdev; 1126 port->portdev = portdev;
1005 port->id = id; 1127 port->id = id;
@@ -1007,6 +1129,7 @@ static int add_port(struct ports_device *portdev, u32 id)
1007 port->name = NULL; 1129 port->name = NULL;
1008 port->inbuf = NULL; 1130 port->inbuf = NULL;
1009 port->cons.hvc = NULL; 1131 port->cons.hvc = NULL;
1132 port->async_queue = NULL;
1010 1133
1011 port->cons.ws.ws_row = port->cons.ws.ws_col = 0; 1134 port->cons.ws.ws_row = port->cons.ws.ws_col = 0;
1012 1135
@@ -1017,14 +1140,20 @@ static int add_port(struct ports_device *portdev, u32 id)
1017 port->in_vq = portdev->in_vqs[port->id]; 1140 port->in_vq = portdev->in_vqs[port->id];
1018 port->out_vq = portdev->out_vqs[port->id]; 1141 port->out_vq = portdev->out_vqs[port->id];
1019 1142
1020 cdev_init(&port->cdev, &port_fops); 1143 port->cdev = cdev_alloc();
1144 if (!port->cdev) {
1145 dev_err(&port->portdev->vdev->dev, "Error allocating cdev\n");
1146 err = -ENOMEM;
1147 goto free_port;
1148 }
1149 port->cdev->ops = &port_fops;
1021 1150
1022 devt = MKDEV(portdev->chr_major, id); 1151 devt = MKDEV(portdev->chr_major, id);
1023 err = cdev_add(&port->cdev, devt, 1); 1152 err = cdev_add(port->cdev, devt, 1);
1024 if (err < 0) { 1153 if (err < 0) {
1025 dev_err(&port->portdev->vdev->dev, 1154 dev_err(&port->portdev->vdev->dev,
1026 "Error %d adding cdev for port %u\n", err, id); 1155 "Error %d adding cdev for port %u\n", err, id);
1027 goto free_port; 1156 goto free_cdev;
1028 } 1157 }
1029 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, 1158 port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev,
1030 devt, port, "vport%up%u", 1159 devt, port, "vport%up%u",
@@ -1089,7 +1218,7 @@ free_inbufs:
1089free_device: 1218free_device:
1090 device_destroy(pdrvdata.class, port->dev->devt); 1219 device_destroy(pdrvdata.class, port->dev->devt);
1091free_cdev: 1220free_cdev:
1092 cdev_del(&port->cdev); 1221 cdev_del(port->cdev);
1093free_port: 1222free_port:
1094 kfree(port); 1223 kfree(port);
1095fail: 1224fail:
@@ -1098,21 +1227,45 @@ fail:
1098 return err; 1227 return err;
1099} 1228}
1100 1229
1101/* Remove all port-specific data. */ 1230/* No users remain, remove all port-specific data. */
1102static int remove_port(struct port *port) 1231static void remove_port(struct kref *kref)
1232{
1233 struct port *port;
1234
1235 port = container_of(kref, struct port, kref);
1236
1237 sysfs_remove_group(&port->dev->kobj, &port_attribute_group);
1238 device_destroy(pdrvdata.class, port->dev->devt);
1239 cdev_del(port->cdev);
1240
1241 kfree(port->name);
1242
1243 debugfs_remove(port->debugfs_file);
1244
1245 kfree(port);
1246}
1247
1248/*
1249 * Port got unplugged. Remove port from portdev's list and drop the
1250 * kref reference. If no userspace has this port opened, it will
1251 * result in immediate removal the port.
1252 */
1253static void unplug_port(struct port *port)
1103{ 1254{
1104 struct port_buffer *buf; 1255 struct port_buffer *buf;
1105 1256
1257 spin_lock_irq(&port->portdev->ports_lock);
1258 list_del(&port->list);
1259 spin_unlock_irq(&port->portdev->ports_lock);
1260
1106 if (port->guest_connected) { 1261 if (port->guest_connected) {
1107 port->guest_connected = false; 1262 port->guest_connected = false;
1108 port->host_connected = false; 1263 port->host_connected = false;
1109 wake_up_interruptible(&port->waitqueue); 1264 wake_up_interruptible(&port->waitqueue);
1110 send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0);
1111 }
1112 1265
1113 spin_lock_irq(&port->portdev->ports_lock); 1266 /* Let the app know the port is going down. */
1114 list_del(&port->list); 1267 send_sigio_to_port(port);
1115 spin_unlock_irq(&port->portdev->ports_lock); 1268 }
1116 1269
1117 if (is_console_port(port)) { 1270 if (is_console_port(port)) {
1118 spin_lock_irq(&pdrvdata_lock); 1271 spin_lock_irq(&pdrvdata_lock);
@@ -1131,9 +1284,6 @@ static int remove_port(struct port *port)
1131 hvc_remove(port->cons.hvc); 1284 hvc_remove(port->cons.hvc);
1132#endif 1285#endif
1133 } 1286 }
1134 sysfs_remove_group(&port->dev->kobj, &port_attribute_group);
1135 device_destroy(pdrvdata.class, port->dev->devt);
1136 cdev_del(&port->cdev);
1137 1287
1138 /* Remove unused data this port might have received. */ 1288 /* Remove unused data this port might have received. */
1139 discard_port_data(port); 1289 discard_port_data(port);
@@ -1144,12 +1294,19 @@ static int remove_port(struct port *port)
1144 while ((buf = virtqueue_detach_unused_buf(port->in_vq))) 1294 while ((buf = virtqueue_detach_unused_buf(port->in_vq)))
1145 free_buf(buf); 1295 free_buf(buf);
1146 1296
1147 kfree(port->name); 1297 /*
1148 1298 * We should just assume the device itself has gone off --
1149 debugfs_remove(port->debugfs_file); 1299 * else a close on an open port later will try to send out a
1300 * control message.
1301 */
1302 port->portdev = NULL;
1150 1303
1151 kfree(port); 1304 /*
1152 return 0; 1305 * Locks around here are not necessary - a port can't be
1306 * opened after we removed the port struct from ports_list
1307 * above.
1308 */
1309 kref_put(&port->kref, remove_port);
1153} 1310}
1154 1311
1155/* Any private messages that the Host and Guest want to share */ 1312/* Any private messages that the Host and Guest want to share */
@@ -1188,7 +1345,7 @@ static void handle_control_message(struct ports_device *portdev,
1188 add_port(portdev, cpkt->id); 1345 add_port(portdev, cpkt->id);
1189 break; 1346 break;
1190 case VIRTIO_CONSOLE_PORT_REMOVE: 1347 case VIRTIO_CONSOLE_PORT_REMOVE:
1191 remove_port(port); 1348 unplug_port(port);
1192 break; 1349 break;
1193 case VIRTIO_CONSOLE_CONSOLE_PORT: 1350 case VIRTIO_CONSOLE_CONSOLE_PORT:
1194 if (!cpkt->value) 1351 if (!cpkt->value)
@@ -1230,6 +1387,12 @@ static void handle_control_message(struct ports_device *portdev,
1230 spin_lock_irq(&port->outvq_lock); 1387 spin_lock_irq(&port->outvq_lock);
1231 reclaim_consumed_buffers(port); 1388 reclaim_consumed_buffers(port);
1232 spin_unlock_irq(&port->outvq_lock); 1389 spin_unlock_irq(&port->outvq_lock);
1390
1391 /*
1392 * If the guest is connected, it'll be interested in
1393 * knowing the host connection state changed.
1394 */
1395 send_sigio_to_port(port);
1233 break; 1396 break;
1234 case VIRTIO_CONSOLE_PORT_NAME: 1397 case VIRTIO_CONSOLE_PORT_NAME:
1235 /* 1398 /*
@@ -1326,6 +1489,9 @@ static void in_intr(struct virtqueue *vq)
1326 1489
1327 wake_up_interruptible(&port->waitqueue); 1490 wake_up_interruptible(&port->waitqueue);
1328 1491
1492 /* Send a SIGIO indicating new data in case the process asked for it */
1493 send_sigio_to_port(port);
1494
1329 if (is_console_port(port) && hvc_poll(port->cons.hvc)) 1495 if (is_console_port(port) && hvc_poll(port->cons.hvc))
1330 hvc_kick(); 1496 hvc_kick();
1331} 1497}
@@ -1562,6 +1728,10 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
1562 add_port(portdev, 0); 1728 add_port(portdev, 0);
1563 } 1729 }
1564 1730
1731 spin_lock_irq(&pdrvdata_lock);
1732 list_add_tail(&portdev->list, &pdrvdata.portdevs);
1733 spin_unlock_irq(&pdrvdata_lock);
1734
1565 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, 1735 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
1566 VIRTIO_CONSOLE_DEVICE_READY, 1); 1736 VIRTIO_CONSOLE_DEVICE_READY, 1);
1567 return 0; 1737 return 0;
@@ -1585,23 +1755,41 @@ static void virtcons_remove(struct virtio_device *vdev)
1585{ 1755{
1586 struct ports_device *portdev; 1756 struct ports_device *portdev;
1587 struct port *port, *port2; 1757 struct port *port, *port2;
1588 struct port_buffer *buf;
1589 unsigned int len;
1590 1758
1591 portdev = vdev->priv; 1759 portdev = vdev->priv;
1592 1760
1761 spin_lock_irq(&pdrvdata_lock);
1762 list_del(&portdev->list);
1763 spin_unlock_irq(&pdrvdata_lock);
1764
1765 /* Disable interrupts for vqs */
1766 vdev->config->reset(vdev);
1767 /* Finish up work that's lined up */
1593 cancel_work_sync(&portdev->control_work); 1768 cancel_work_sync(&portdev->control_work);
1594 1769
1595 list_for_each_entry_safe(port, port2, &portdev->ports, list) 1770 list_for_each_entry_safe(port, port2, &portdev->ports, list)
1596 remove_port(port); 1771 unplug_port(port);
1597 1772
1598 unregister_chrdev(portdev->chr_major, "virtio-portsdev"); 1773 unregister_chrdev(portdev->chr_major, "virtio-portsdev");
1599 1774
1600 while ((buf = virtqueue_get_buf(portdev->c_ivq, &len))) 1775 /*
1601 free_buf(buf); 1776 * When yanking out a device, we immediately lose the
1777 * (device-side) queues. So there's no point in keeping the
1778 * guest side around till we drop our final reference. This
1779 * also means that any ports which are in an open state will
1780 * have to just stop using the port, as the vqs are going
1781 * away.
1782 */
1783 if (use_multiport(portdev)) {
1784 struct port_buffer *buf;
1785 unsigned int len;
1602 1786
1603 while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq))) 1787 while ((buf = virtqueue_get_buf(portdev->c_ivq, &len)))
1604 free_buf(buf); 1788 free_buf(buf);
1789
1790 while ((buf = virtqueue_detach_unused_buf(portdev->c_ivq)))
1791 free_buf(buf);
1792 }
1605 1793
1606 vdev->config->del_vqs(vdev); 1794 vdev->config->del_vqs(vdev);
1607 kfree(portdev->in_vqs); 1795 kfree(portdev->in_vqs);
@@ -1648,6 +1836,7 @@ static int __init init(void)
1648 PTR_ERR(pdrvdata.debugfs_dir)); 1836 PTR_ERR(pdrvdata.debugfs_dir));
1649 } 1837 }
1650 INIT_LIST_HEAD(&pdrvdata.consoles); 1838 INIT_LIST_HEAD(&pdrvdata.consoles);
1839 INIT_LIST_HEAD(&pdrvdata.portdevs);
1651 1840
1652 return register_virtio_driver(&virtio_console); 1841 return register_virtio_driver(&virtio_console);
1653} 1842}
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index be6d6fb47cc5..9f2272e6de1c 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -81,7 +81,6 @@
81#include <linux/poll.h> 81#include <linux/poll.h>
82#include <linux/proc_fs.h> 82#include <linux/proc_fs.h>
83#include <linux/mutex.h> 83#include <linux/mutex.h>
84#include <linux/smp_lock.h>
85#include <linux/sysctl.h> 84#include <linux/sysctl.h>
86#include <linux/fs.h> 85#include <linux/fs.h>
87#include <linux/cdev.h> 86#include <linux/cdev.h>
@@ -112,6 +111,7 @@
112#define HWICAP_DEVICES 1 111#define HWICAP_DEVICES 1
113 112
114/* An array, which is set to true when the device is registered. */ 113/* An array, which is set to true when the device is registered. */
114static DEFINE_MUTEX(hwicap_mutex);
115static bool probed_devices[HWICAP_DEVICES]; 115static bool probed_devices[HWICAP_DEVICES];
116static struct mutex icap_sem; 116static struct mutex icap_sem;
117 117
@@ -502,7 +502,7 @@ static int hwicap_open(struct inode *inode, struct file *file)
502 struct hwicap_drvdata *drvdata; 502 struct hwicap_drvdata *drvdata;
503 int status; 503 int status;
504 504
505 lock_kernel(); 505 mutex_lock(&hwicap_mutex);
506 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev); 506 drvdata = container_of(inode->i_cdev, struct hwicap_drvdata, cdev);
507 507
508 status = mutex_lock_interruptible(&drvdata->sem); 508 status = mutex_lock_interruptible(&drvdata->sem);
@@ -528,7 +528,7 @@ static int hwicap_open(struct inode *inode, struct file *file)
528 error: 528 error:
529 mutex_unlock(&drvdata->sem); 529 mutex_unlock(&drvdata->sem);
530 out: 530 out:
531 unlock_kernel(); 531 mutex_unlock(&hwicap_mutex);
532 return status; 532 return status;
533} 533}
534 534
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index c2408bbe9c2e..f508690eb958 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -80,7 +80,7 @@
80 * Limiting Performance Impact 80 * Limiting Performance Impact
81 * --------------------------- 81 * ---------------------------
82 * C states, especially those with large exit latencies, can have a real 82 * C states, especially those with large exit latencies, can have a real
83 * noticable impact on workloads, which is not acceptable for most sysadmins, 83 * noticeable impact on workloads, which is not acceptable for most sysadmins,
84 * and in addition, less performance has a power price of its own. 84 * and in addition, less performance has a power price of its own.
85 * 85 *
86 * As a general rule of thumb, menu assumes that the following heuristic 86 * As a general rule of thumb, menu assumes that the following heuristic
diff --git a/drivers/dca/dca-core.c b/drivers/dca/dca-core.c
index 8661c84a105d..b98c67664ae7 100644
--- a/drivers/dca/dca-core.c
+++ b/drivers/dca/dca-core.c
@@ -39,6 +39,10 @@ static DEFINE_SPINLOCK(dca_lock);
39 39
40static LIST_HEAD(dca_domains); 40static LIST_HEAD(dca_domains);
41 41
42static BLOCKING_NOTIFIER_HEAD(dca_provider_chain);
43
44static int dca_providers_blocked;
45
42static struct pci_bus *dca_pci_rc_from_dev(struct device *dev) 46static struct pci_bus *dca_pci_rc_from_dev(struct device *dev)
43{ 47{
44 struct pci_dev *pdev = to_pci_dev(dev); 48 struct pci_dev *pdev = to_pci_dev(dev);
@@ -70,6 +74,60 @@ static void dca_free_domain(struct dca_domain *domain)
70 kfree(domain); 74 kfree(domain);
71} 75}
72 76
77static int dca_provider_ioat_ver_3_0(struct device *dev)
78{
79 struct pci_dev *pdev = to_pci_dev(dev);
80
81 return ((pdev->vendor == PCI_VENDOR_ID_INTEL) &&
82 ((pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG0) ||
83 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG1) ||
84 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG2) ||
85 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG3) ||
86 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG4) ||
87 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG5) ||
88 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG6) ||
89 (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG7)));
90}
91
92static void unregister_dca_providers(void)
93{
94 struct dca_provider *dca, *_dca;
95 struct list_head unregistered_providers;
96 struct dca_domain *domain;
97 unsigned long flags;
98
99 blocking_notifier_call_chain(&dca_provider_chain,
100 DCA_PROVIDER_REMOVE, NULL);
101
102 INIT_LIST_HEAD(&unregistered_providers);
103
104 spin_lock_irqsave(&dca_lock, flags);
105
106 if (list_empty(&dca_domains)) {
107 spin_unlock_irqrestore(&dca_lock, flags);
108 return;
109 }
110
111 /* at this point only one domain in the list is expected */
112 domain = list_first_entry(&dca_domains, struct dca_domain, node);
113 if (!domain)
114 return;
115
116 list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node) {
117 list_del(&dca->node);
118 list_add(&dca->node, &unregistered_providers);
119 }
120
121 dca_free_domain(domain);
122
123 spin_unlock_irqrestore(&dca_lock, flags);
124
125 list_for_each_entry_safe(dca, _dca, &unregistered_providers, node) {
126 dca_sysfs_remove_provider(dca);
127 list_del(&dca->node);
128 }
129}
130
73static struct dca_domain *dca_find_domain(struct pci_bus *rc) 131static struct dca_domain *dca_find_domain(struct pci_bus *rc)
74{ 132{
75 struct dca_domain *domain; 133 struct dca_domain *domain;
@@ -90,9 +148,13 @@ static struct dca_domain *dca_get_domain(struct device *dev)
90 domain = dca_find_domain(rc); 148 domain = dca_find_domain(rc);
91 149
92 if (!domain) { 150 if (!domain) {
93 domain = dca_allocate_domain(rc); 151 if (dca_provider_ioat_ver_3_0(dev) && !list_empty(&dca_domains)) {
94 if (domain) 152 dca_providers_blocked = 1;
95 list_add(&domain->node, &dca_domains); 153 } else {
154 domain = dca_allocate_domain(rc);
155 if (domain)
156 list_add(&domain->node, &dca_domains);
157 }
96 } 158 }
97 159
98 return domain; 160 return domain;
@@ -293,8 +355,6 @@ void free_dca_provider(struct dca_provider *dca)
293} 355}
294EXPORT_SYMBOL_GPL(free_dca_provider); 356EXPORT_SYMBOL_GPL(free_dca_provider);
295 357
296static BLOCKING_NOTIFIER_HEAD(dca_provider_chain);
297
298/** 358/**
299 * register_dca_provider - register a dca provider 359 * register_dca_provider - register a dca provider
300 * @dca - struct created by alloc_dca_provider() 360 * @dca - struct created by alloc_dca_provider()
@@ -306,6 +366,13 @@ int register_dca_provider(struct dca_provider *dca, struct device *dev)
306 unsigned long flags; 366 unsigned long flags;
307 struct dca_domain *domain; 367 struct dca_domain *domain;
308 368
369 spin_lock_irqsave(&dca_lock, flags);
370 if (dca_providers_blocked) {
371 spin_unlock_irqrestore(&dca_lock, flags);
372 return -ENODEV;
373 }
374 spin_unlock_irqrestore(&dca_lock, flags);
375
309 err = dca_sysfs_add_provider(dca, dev); 376 err = dca_sysfs_add_provider(dca, dev);
310 if (err) 377 if (err)
311 return err; 378 return err;
@@ -313,7 +380,13 @@ int register_dca_provider(struct dca_provider *dca, struct device *dev)
313 spin_lock_irqsave(&dca_lock, flags); 380 spin_lock_irqsave(&dca_lock, flags);
314 domain = dca_get_domain(dev); 381 domain = dca_get_domain(dev);
315 if (!domain) { 382 if (!domain) {
316 spin_unlock_irqrestore(&dca_lock, flags); 383 if (dca_providers_blocked) {
384 spin_unlock_irqrestore(&dca_lock, flags);
385 dca_sysfs_remove_provider(dca);
386 unregister_dca_providers();
387 } else {
388 spin_unlock_irqrestore(&dca_lock, flags);
389 }
317 return -ENODEV; 390 return -ENODEV;
318 } 391 }
319 list_add(&dca->node, &domain->dca_providers); 392 list_add(&dca->node, &domain->dca_providers);
diff --git a/drivers/dma/ioat/dma_v2.c b/drivers/dma/ioat/dma_v2.c
index 216f9d383b5b..effd140fc042 100644
--- a/drivers/dma/ioat/dma_v2.c
+++ b/drivers/dma/ioat/dma_v2.c
@@ -879,7 +879,7 @@ int __devinit ioat2_dma_probe(struct ioatdma_device *device, int dca)
879 dma->device_issue_pending = ioat2_issue_pending; 879 dma->device_issue_pending = ioat2_issue_pending;
880 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources; 880 dma->device_alloc_chan_resources = ioat2_alloc_chan_resources;
881 dma->device_free_chan_resources = ioat2_free_chan_resources; 881 dma->device_free_chan_resources = ioat2_free_chan_resources;
882 dma->device_tx_status = ioat_tx_status; 882 dma->device_tx_status = ioat_dma_tx_status;
883 883
884 err = ioat_probe(device); 884 err = ioat_probe(device);
885 if (err) 885 if (err)
diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 86c5ae9fde34..411d5bf50fc4 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -162,7 +162,7 @@ static int mv_is_err_intr(u32 intr_cause)
162 162
163static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan) 163static void mv_xor_device_clear_eoc_cause(struct mv_xor_chan *chan)
164{ 164{
165 u32 val = (1 << (1 + (chan->idx * 16))); 165 u32 val = ~(1 << (chan->idx * 16));
166 dev_dbg(chan->device->common.dev, "%s, val 0x%08x\n", __func__, val); 166 dev_dbg(chan->device->common.dev, "%s, val 0x%08x\n", __func__, val);
167 __raw_writel(val, XOR_INTR_CAUSE(chan)); 167 __raw_writel(val, XOR_INTR_CAUSE(chan));
168} 168}
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index fb64cf36ba61..eb6b54dbb806 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -580,7 +580,6 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg(
580 580
581 sh_chan = to_sh_chan(chan); 581 sh_chan = to_sh_chan(chan);
582 param = chan->private; 582 param = chan->private;
583 slave_addr = param->config->addr;
584 583
585 /* Someone calling slave DMA on a public channel? */ 584 /* Someone calling slave DMA on a public channel? */
586 if (!param || !sg_len) { 585 if (!param || !sg_len) {
@@ -589,6 +588,8 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg(
589 return NULL; 588 return NULL;
590 } 589 }
591 590
591 slave_addr = param->config->addr;
592
592 /* 593 /*
593 * if (param != NULL), this is a successfully requested slave channel, 594 * if (param != NULL), this is a successfully requested slave channel,
594 * therefore param->config != NULL too. 595 * therefore param->config != NULL too.
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 70bb350de996..9dbb28b9559f 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -39,7 +39,7 @@ config EDAC_DEBUG
39 there're four debug levels (x=0,1,2,3 from low to high). 39 there're four debug levels (x=0,1,2,3 from low to high).
40 Usually you should select 'N'. 40 Usually you should select 'N'.
41 41
42 config EDAC_DECODE_MCE 42config EDAC_DECODE_MCE
43 tristate "Decode MCEs in human-readable form (only on AMD for now)" 43 tristate "Decode MCEs in human-readable form (only on AMD for now)"
44 depends on CPU_SUP_AMD && X86_MCE 44 depends on CPU_SUP_AMD && X86_MCE
45 default y 45 default y
@@ -51,6 +51,16 @@ config EDAC_DEBUG
51 which occur really early upon boot, before the module infrastructure 51 which occur really early upon boot, before the module infrastructure
52 has been initialized. 52 has been initialized.
53 53
54config EDAC_MCE_INJ
55 tristate "Simple MCE injection interface over /sysfs"
56 depends on EDAC_DECODE_MCE
57 default n
58 help
59 This is a simple interface to inject MCEs over /sysfs and test
60 the MCE decoding code in EDAC.
61
62 This is currently AMD-only.
63
54config EDAC_MM_EDAC 64config EDAC_MM_EDAC
55 tristate "Main Memory EDAC (Error Detection And Correction) reporting" 65 tristate "Main Memory EDAC (Error Detection And Correction) reporting"
56 help 66 help
@@ -66,13 +76,13 @@ config EDAC_MCE
66 76
67config EDAC_AMD64 77config EDAC_AMD64
68 tristate "AMD64 (Opteron, Athlon64) K8, F10h, F11h" 78 tristate "AMD64 (Opteron, Athlon64) K8, F10h, F11h"
69 depends on EDAC_MM_EDAC && K8_NB && X86_64 && PCI && EDAC_DECODE_MCE 79 depends on EDAC_MM_EDAC && AMD_NB && X86_64 && PCI && EDAC_DECODE_MCE
70 help 80 help
71 Support for error detection and correction on the AMD 64 81 Support for error detection and correction on the AMD 64
72 Families of Memory Controllers (K8, F10h and F11h) 82 Families of Memory Controllers (K8, F10h and F11h)
73 83
74config EDAC_AMD64_ERROR_INJECTION 84config EDAC_AMD64_ERROR_INJECTION
75 bool "Sysfs Error Injection facilities" 85 bool "Sysfs HW Error injection facilities"
76 depends on EDAC_AMD64 86 depends on EDAC_AMD64
77 help 87 help
78 Recent Opterons (Family 10h and later) provide for Memory Error 88 Recent Opterons (Family 10h and later) provide for Memory Error
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index ca6b1bb24ccc..32c7bc93c525 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -17,6 +17,9 @@ ifdef CONFIG_PCI
17edac_core-objs += edac_pci.o edac_pci_sysfs.o 17edac_core-objs += edac_pci.o edac_pci_sysfs.o
18endif 18endif
19 19
20obj-$(CONFIG_EDAC_MCE_INJ) += mce_amd_inj.o
21
22edac_mce_amd-objs := mce_amd.o
20obj-$(CONFIG_EDAC_DECODE_MCE) += edac_mce_amd.o 23obj-$(CONFIG_EDAC_DECODE_MCE) += edac_mce_amd.o
21 24
22obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o 25obj-$(CONFIG_EDAC_AMD76X) += amd76x_edac.o
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index e7d5d6b5dcf6..8521401bbd75 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -1,5 +1,5 @@
1#include "amd64_edac.h" 1#include "amd64_edac.h"
2#include <asm/k8.h> 2#include <asm/amd_nb.h>
3 3
4static struct edac_pci_ctl_info *amd64_ctl_pci; 4static struct edac_pci_ctl_info *amd64_ctl_pci;
5 5
@@ -2073,11 +2073,18 @@ static inline void __amd64_decode_bus_error(struct mem_ctl_info *mci,
2073 amd64_handle_ue(mci, info); 2073 amd64_handle_ue(mci, info);
2074} 2074}
2075 2075
2076void amd64_decode_bus_error(int node_id, struct err_regs *regs) 2076void amd64_decode_bus_error(int node_id, struct mce *m, u32 nbcfg)
2077{ 2077{
2078 struct mem_ctl_info *mci = mci_lookup[node_id]; 2078 struct mem_ctl_info *mci = mci_lookup[node_id];
2079 struct err_regs regs;
2079 2080
2080 __amd64_decode_bus_error(mci, regs); 2081 regs.nbsl = (u32) m->status;
2082 regs.nbsh = (u32)(m->status >> 32);
2083 regs.nbeal = (u32) m->addr;
2084 regs.nbeah = (u32)(m->addr >> 32);
2085 regs.nbcfg = nbcfg;
2086
2087 __amd64_decode_bus_error(mci, &regs);
2081 2088
2082 /* 2089 /*
2083 * Check the UE bit of the NB status high register, if set generate some 2090 * Check the UE bit of the NB status high register, if set generate some
@@ -2086,7 +2093,7 @@ void amd64_decode_bus_error(int node_id, struct err_regs *regs)
2086 * 2093 *
2087 * FIXME: this should go somewhere else, if at all. 2094 * FIXME: this should go somewhere else, if at all.
2088 */ 2095 */
2089 if (regs->nbsh & K8_NBSH_UC_ERR && !report_gart_errors) 2096 if (regs.nbsh & K8_NBSH_UC_ERR && !report_gart_errors)
2090 edac_mc_handle_ue_no_info(mci, "UE bit is set"); 2097 edac_mc_handle_ue_no_info(mci, "UE bit is set");
2091 2098
2092} 2099}
@@ -2927,7 +2934,7 @@ static int __init amd64_edac_init(void)
2927 * to finish initialization of the MC instances. 2934 * to finish initialization of the MC instances.
2928 */ 2935 */
2929 err = -ENODEV; 2936 err = -ENODEV;
2930 for (nb = 0; nb < num_k8_northbridges; nb++) { 2937 for (nb = 0; nb < k8_northbridges.num; nb++) {
2931 if (!pvt_lookup[nb]) 2938 if (!pvt_lookup[nb])
2932 continue; 2939 continue;
2933 2940
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index 613b9381e71a..044aee4f944d 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -72,7 +72,7 @@
72#include <linux/edac.h> 72#include <linux/edac.h>
73#include <asm/msr.h> 73#include <asm/msr.h>
74#include "edac_core.h" 74#include "edac_core.h"
75#include "edac_mce_amd.h" 75#include "mce_amd.h"
76 76
77#define amd64_printk(level, fmt, arg...) \ 77#define amd64_printk(level, fmt, arg...) \
78 edac_printk(level, "amd64", fmt, ##arg) 78 edac_printk(level, "amd64", fmt, ##arg)
@@ -482,11 +482,10 @@ extern const char *rrrr_msgs[16];
482extern const char *to_msgs[2]; 482extern const char *to_msgs[2];
483extern const char *pp_msgs[4]; 483extern const char *pp_msgs[4];
484extern const char *ii_msgs[4]; 484extern const char *ii_msgs[4];
485extern const char *ext_msgs[32];
486extern const char *htlink_msgs[8]; 485extern const char *htlink_msgs[8];
487 486
488#ifdef CONFIG_EDAC_DEBUG 487#ifdef CONFIG_EDAC_DEBUG
489#define NUM_DBG_ATTRS 9 488#define NUM_DBG_ATTRS 5
490#else 489#else
491#define NUM_DBG_ATTRS 0 490#define NUM_DBG_ATTRS 0
492#endif 491#endif
diff --git a/drivers/edac/amd64_edac_dbg.c b/drivers/edac/amd64_edac_dbg.c
index 59cf2cf6e11e..e3562288f4ce 100644
--- a/drivers/edac/amd64_edac_dbg.c
+++ b/drivers/edac/amd64_edac_dbg.c
@@ -1,167 +1,16 @@
1#include "amd64_edac.h" 1#include "amd64_edac.h"
2 2
3/* 3#define EDAC_DCT_ATTR_SHOW(reg) \
4 * accept a hex value and store it into the virtual error register file, field: 4static ssize_t amd64_##reg##_show(struct mem_ctl_info *mci, char *data) \
5 * nbeal and nbeah. Assume virtual error values have already been set for: NBSL, 5{ \
6 * NBSH and NBCFG. Then proceed to map the error values to a MC, CSROW and 6 struct amd64_pvt *pvt = mci->pvt_info; \
7 * CHANNEL 7 return sprintf(data, "0x%016llx\n", (u64)pvt->reg); \
8 */
9static ssize_t amd64_nbea_store(struct mem_ctl_info *mci, const char *data,
10 size_t count)
11{
12 struct amd64_pvt *pvt = mci->pvt_info;
13 unsigned long long value;
14 int ret = 0;
15
16 ret = strict_strtoull(data, 16, &value);
17 if (ret != -EINVAL) {
18 debugf0("received NBEA= 0x%llx\n", value);
19
20 /* place the value into the virtual error packet */
21 pvt->ctl_error_info.nbeal = (u32) value;
22 value >>= 32;
23 pvt->ctl_error_info.nbeah = (u32) value;
24
25 /* Process the Mapping request */
26 /* TODO: Add race prevention */
27 amd_decode_nb_mce(pvt->mc_node_id, &pvt->ctl_error_info, 1);
28
29 return count;
30 }
31 return ret;
32}
33
34/* display back what the last NBEA (MCA NB Address (MC4_ADDR)) was written */
35static ssize_t amd64_nbea_show(struct mem_ctl_info *mci, char *data)
36{
37 struct amd64_pvt *pvt = mci->pvt_info;
38 u64 value;
39
40 value = pvt->ctl_error_info.nbeah;
41 value <<= 32;
42 value |= pvt->ctl_error_info.nbeal;
43
44 return sprintf(data, "%llx\n", value);
45}
46
47/* store the NBSL (MCA NB Status Low (MC4_STATUS)) value user desires */
48static ssize_t amd64_nbsl_store(struct mem_ctl_info *mci, const char *data,
49 size_t count)
50{
51 struct amd64_pvt *pvt = mci->pvt_info;
52 unsigned long value;
53 int ret = 0;
54
55 ret = strict_strtoul(data, 16, &value);
56 if (ret != -EINVAL) {
57 debugf0("received NBSL= 0x%lx\n", value);
58
59 pvt->ctl_error_info.nbsl = (u32) value;
60
61 return count;
62 }
63 return ret;
64}
65
66/* display back what the last NBSL value written */
67static ssize_t amd64_nbsl_show(struct mem_ctl_info *mci, char *data)
68{
69 struct amd64_pvt *pvt = mci->pvt_info;
70 u32 value;
71
72 value = pvt->ctl_error_info.nbsl;
73
74 return sprintf(data, "%x\n", value);
75}
76
77/* store the NBSH (MCA NB Status High) value user desires */
78static ssize_t amd64_nbsh_store(struct mem_ctl_info *mci, const char *data,
79 size_t count)
80{
81 struct amd64_pvt *pvt = mci->pvt_info;
82 unsigned long value;
83 int ret = 0;
84
85 ret = strict_strtoul(data, 16, &value);
86 if (ret != -EINVAL) {
87 debugf0("received NBSH= 0x%lx\n", value);
88
89 pvt->ctl_error_info.nbsh = (u32) value;
90
91 return count;
92 }
93 return ret;
94}
95
96/* display back what the last NBSH value written */
97static ssize_t amd64_nbsh_show(struct mem_ctl_info *mci, char *data)
98{
99 struct amd64_pvt *pvt = mci->pvt_info;
100 u32 value;
101
102 value = pvt->ctl_error_info.nbsh;
103
104 return sprintf(data, "%x\n", value);
105} 8}
106 9
107/* accept and store the NBCFG (MCA NB Configuration) value user desires */ 10EDAC_DCT_ATTR_SHOW(dhar);
108static ssize_t amd64_nbcfg_store(struct mem_ctl_info *mci, 11EDAC_DCT_ATTR_SHOW(dbam0);
109 const char *data, size_t count) 12EDAC_DCT_ATTR_SHOW(top_mem);
110{ 13EDAC_DCT_ATTR_SHOW(top_mem2);
111 struct amd64_pvt *pvt = mci->pvt_info;
112 unsigned long value;
113 int ret = 0;
114
115 ret = strict_strtoul(data, 16, &value);
116 if (ret != -EINVAL) {
117 debugf0("received NBCFG= 0x%lx\n", value);
118
119 pvt->ctl_error_info.nbcfg = (u32) value;
120
121 return count;
122 }
123 return ret;
124}
125
126/* various show routines for the controls of a MCI */
127static ssize_t amd64_nbcfg_show(struct mem_ctl_info *mci, char *data)
128{
129 struct amd64_pvt *pvt = mci->pvt_info;
130
131 return sprintf(data, "%x\n", pvt->ctl_error_info.nbcfg);
132}
133
134
135static ssize_t amd64_dhar_show(struct mem_ctl_info *mci, char *data)
136{
137 struct amd64_pvt *pvt = mci->pvt_info;
138
139 return sprintf(data, "%x\n", pvt->dhar);
140}
141
142
143static ssize_t amd64_dbam_show(struct mem_ctl_info *mci, char *data)
144{
145 struct amd64_pvt *pvt = mci->pvt_info;
146
147 return sprintf(data, "%x\n", pvt->dbam0);
148}
149
150
151static ssize_t amd64_topmem_show(struct mem_ctl_info *mci, char *data)
152{
153 struct amd64_pvt *pvt = mci->pvt_info;
154
155 return sprintf(data, "%llx\n", pvt->top_mem);
156}
157
158
159static ssize_t amd64_topmem2_show(struct mem_ctl_info *mci, char *data)
160{
161 struct amd64_pvt *pvt = mci->pvt_info;
162
163 return sprintf(data, "%llx\n", pvt->top_mem2);
164}
165 14
166static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data) 15static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data)
167{ 16{
@@ -182,38 +31,6 @@ struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
182 31
183 { 32 {
184 .attr = { 33 .attr = {
185 .name = "nbea_ctl",
186 .mode = (S_IRUGO | S_IWUSR)
187 },
188 .show = amd64_nbea_show,
189 .store = amd64_nbea_store,
190 },
191 {
192 .attr = {
193 .name = "nbsl_ctl",
194 .mode = (S_IRUGO | S_IWUSR)
195 },
196 .show = amd64_nbsl_show,
197 .store = amd64_nbsl_store,
198 },
199 {
200 .attr = {
201 .name = "nbsh_ctl",
202 .mode = (S_IRUGO | S_IWUSR)
203 },
204 .show = amd64_nbsh_show,
205 .store = amd64_nbsh_store,
206 },
207 {
208 .attr = {
209 .name = "nbcfg_ctl",
210 .mode = (S_IRUGO | S_IWUSR)
211 },
212 .show = amd64_nbcfg_show,
213 .store = amd64_nbcfg_store,
214 },
215 {
216 .attr = {
217 .name = "dhar", 34 .name = "dhar",
218 .mode = (S_IRUGO) 35 .mode = (S_IRUGO)
219 }, 36 },
@@ -225,7 +42,7 @@ struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
225 .name = "dbam", 42 .name = "dbam",
226 .mode = (S_IRUGO) 43 .mode = (S_IRUGO)
227 }, 44 },
228 .show = amd64_dbam_show, 45 .show = amd64_dbam0_show,
229 .store = NULL, 46 .store = NULL,
230 }, 47 },
231 { 48 {
@@ -233,7 +50,7 @@ struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
233 .name = "topmem", 50 .name = "topmem",
234 .mode = (S_IRUGO) 51 .mode = (S_IRUGO)
235 }, 52 },
236 .show = amd64_topmem_show, 53 .show = amd64_top_mem_show,
237 .store = NULL, 54 .store = NULL,
238 }, 55 },
239 { 56 {
@@ -241,7 +58,7 @@ struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
241 .name = "topmem2", 58 .name = "topmem2",
242 .mode = (S_IRUGO) 59 .mode = (S_IRUGO)
243 }, 60 },
244 .show = amd64_topmem2_show, 61 .show = amd64_top_mem2_show,
245 .store = NULL, 62 .store = NULL,
246 }, 63 },
247 { 64 {
diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 070968178a24..2941dca91aae 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -13,6 +13,7 @@
13#include <linux/ctype.h> 13#include <linux/ctype.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/edac.h>
16 17
17#include "edac_core.h" 18#include "edac_core.h"
18#include "edac_module.h" 19#include "edac_module.h"
@@ -235,7 +236,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
235 debugf1("%s()\n", __func__); 236 debugf1("%s()\n", __func__);
236 237
237 /* get the /sys/devices/system/edac reference */ 238 /* get the /sys/devices/system/edac reference */
238 edac_class = edac_get_edac_class(); 239 edac_class = edac_get_sysfs_class();
239 if (edac_class == NULL) { 240 if (edac_class == NULL) {
240 debugf1("%s() no edac_class error\n", __func__); 241 debugf1("%s() no edac_class error\n", __func__);
241 err = -ENODEV; 242 err = -ENODEV;
@@ -255,7 +256,7 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
255 256
256 if (!try_module_get(edac_dev->owner)) { 257 if (!try_module_get(edac_dev->owner)) {
257 err = -ENODEV; 258 err = -ENODEV;
258 goto err_out; 259 goto err_mod_get;
259 } 260 }
260 261
261 /* register */ 262 /* register */
@@ -282,6 +283,9 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
282err_kobj_reg: 283err_kobj_reg:
283 module_put(edac_dev->owner); 284 module_put(edac_dev->owner);
284 285
286err_mod_get:
287 edac_put_sysfs_class();
288
285err_out: 289err_out:
286 return err; 290 return err;
287} 291}
@@ -290,12 +294,11 @@ err_out:
290 * edac_device_unregister_sysfs_main_kobj: 294 * edac_device_unregister_sysfs_main_kobj:
291 * the '..../edac/<name>' kobject 295 * the '..../edac/<name>' kobject
292 */ 296 */
293void edac_device_unregister_sysfs_main_kobj( 297void edac_device_unregister_sysfs_main_kobj(struct edac_device_ctl_info *dev)
294 struct edac_device_ctl_info *edac_dev)
295{ 298{
296 debugf0("%s()\n", __func__); 299 debugf0("%s()\n", __func__);
297 debugf4("%s() name of kobject is: %s\n", 300 debugf4("%s() name of kobject is: %s\n",
298 __func__, kobject_name(&edac_dev->kobj)); 301 __func__, kobject_name(&dev->kobj));
299 302
300 /* 303 /*
301 * Unregister the edac device's kobject and 304 * Unregister the edac device's kobject and
@@ -304,7 +307,8 @@ void edac_device_unregister_sysfs_main_kobj(
304 * a) module_put() this module 307 * a) module_put() this module
305 * b) 'kfree' the memory 308 * b) 'kfree' the memory
306 */ 309 */
307 kobject_put(&edac_dev->kobj); 310 kobject_put(&dev->kobj);
311 edac_put_sysfs_class();
308} 312}
309 313
310/* edac_dev -> instance information */ 314/* edac_dev -> instance information */
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 3630308e7b81..6b21e25f7a84 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -339,6 +339,9 @@ static void edac_mc_workq_teardown(struct mem_ctl_info *mci)
339{ 339{
340 int status; 340 int status;
341 341
342 if (mci->op_state != OP_RUNNING_POLL)
343 return;
344
342 status = cancel_delayed_work(&mci->work); 345 status = cancel_delayed_work(&mci->work);
343 if (status == 0) { 346 if (status == 0) {
344 debugf0("%s() not canceled, flush the queue\n", 347 debugf0("%s() not canceled, flush the queue\n",
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 8aad94d10c0c..a4135860149b 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/edac.h>
14#include <linux/bug.h> 15#include <linux/bug.h>
15 16
16#include "edac_core.h" 17#include "edac_core.h"
@@ -1011,13 +1012,13 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
1011 */ 1012 */
1012int edac_sysfs_setup_mc_kset(void) 1013int edac_sysfs_setup_mc_kset(void)
1013{ 1014{
1014 int err = 0; 1015 int err = -EINVAL;
1015 struct sysdev_class *edac_class; 1016 struct sysdev_class *edac_class;
1016 1017
1017 debugf1("%s()\n", __func__); 1018 debugf1("%s()\n", __func__);
1018 1019
1019 /* get the /sys/devices/system/edac class reference */ 1020 /* get the /sys/devices/system/edac class reference */
1020 edac_class = edac_get_edac_class(); 1021 edac_class = edac_get_sysfs_class();
1021 if (edac_class == NULL) { 1022 if (edac_class == NULL) {
1022 debugf1("%s() no edac_class error=%d\n", __func__, err); 1023 debugf1("%s() no edac_class error=%d\n", __func__, err);
1023 goto fail_out; 1024 goto fail_out;
@@ -1028,15 +1029,16 @@ int edac_sysfs_setup_mc_kset(void)
1028 if (!mc_kset) { 1029 if (!mc_kset) {
1029 err = -ENOMEM; 1030 err = -ENOMEM;
1030 debugf1("%s() Failed to register '.../edac/mc'\n", __func__); 1031 debugf1("%s() Failed to register '.../edac/mc'\n", __func__);
1031 goto fail_out; 1032 goto fail_kset;
1032 } 1033 }
1033 1034
1034 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__); 1035 debugf1("%s() Registered '.../edac/mc' kobject\n", __func__);
1035 1036
1036 return 0; 1037 return 0;
1037 1038
1039fail_kset:
1040 edac_put_sysfs_class();
1038 1041
1039 /* error unwind stack */
1040fail_out: 1042fail_out:
1041 return err; 1043 return err;
1042} 1044}
@@ -1049,5 +1051,6 @@ fail_out:
1049void edac_sysfs_teardown_mc_kset(void) 1051void edac_sysfs_teardown_mc_kset(void)
1050{ 1052{
1051 kset_unregister(mc_kset); 1053 kset_unregister(mc_kset);
1054 edac_put_sysfs_class();
1052} 1055}
1053 1056
diff --git a/drivers/edac/edac_mce_amd.c b/drivers/edac/edac_mce_amd.c
deleted file mode 100644
index 9014df6f605d..000000000000
--- a/drivers/edac/edac_mce_amd.c
+++ /dev/null
@@ -1,452 +0,0 @@
1#include <linux/module.h>
2#include "edac_mce_amd.h"
3
4static bool report_gart_errors;
5static void (*nb_bus_decoder)(int node_id, struct err_regs *regs);
6
7void amd_report_gart_errors(bool v)
8{
9 report_gart_errors = v;
10}
11EXPORT_SYMBOL_GPL(amd_report_gart_errors);
12
13void amd_register_ecc_decoder(void (*f)(int, struct err_regs *))
14{
15 nb_bus_decoder = f;
16}
17EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
18
19void amd_unregister_ecc_decoder(void (*f)(int, struct err_regs *))
20{
21 if (nb_bus_decoder) {
22 WARN_ON(nb_bus_decoder != f);
23
24 nb_bus_decoder = NULL;
25 }
26}
27EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
28
29/*
30 * string representation for the different MCA reported error types, see F3x48
31 * or MSR0000_0411.
32 */
33const char *tt_msgs[] = { /* transaction type */
34 "instruction",
35 "data",
36 "generic",
37 "reserved"
38};
39EXPORT_SYMBOL_GPL(tt_msgs);
40
41const char *ll_msgs[] = { /* cache level */
42 "L0",
43 "L1",
44 "L2",
45 "L3/generic"
46};
47EXPORT_SYMBOL_GPL(ll_msgs);
48
49const char *rrrr_msgs[] = {
50 "generic",
51 "generic read",
52 "generic write",
53 "data read",
54 "data write",
55 "inst fetch",
56 "prefetch",
57 "evict",
58 "snoop",
59 "reserved RRRR= 9",
60 "reserved RRRR= 10",
61 "reserved RRRR= 11",
62 "reserved RRRR= 12",
63 "reserved RRRR= 13",
64 "reserved RRRR= 14",
65 "reserved RRRR= 15"
66};
67EXPORT_SYMBOL_GPL(rrrr_msgs);
68
69const char *pp_msgs[] = { /* participating processor */
70 "local node originated (SRC)",
71 "local node responded to request (RES)",
72 "local node observed as 3rd party (OBS)",
73 "generic"
74};
75EXPORT_SYMBOL_GPL(pp_msgs);
76
77const char *to_msgs[] = {
78 "no timeout",
79 "timed out"
80};
81EXPORT_SYMBOL_GPL(to_msgs);
82
83const char *ii_msgs[] = { /* memory or i/o */
84 "mem access",
85 "reserved",
86 "i/o access",
87 "generic"
88};
89EXPORT_SYMBOL_GPL(ii_msgs);
90
91/*
92 * Map the 4 or 5 (family-specific) bits of Extended Error code to the
93 * string table.
94 */
95const char *ext_msgs[] = {
96 "K8 ECC error", /* 0_0000b */
97 "CRC error on link", /* 0_0001b */
98 "Sync error packets on link", /* 0_0010b */
99 "Master Abort during link operation", /* 0_0011b */
100 "Target Abort during link operation", /* 0_0100b */
101 "Invalid GART PTE entry during table walk", /* 0_0101b */
102 "Unsupported atomic RMW command received", /* 0_0110b */
103 "WDT error: NB transaction timeout", /* 0_0111b */
104 "ECC/ChipKill ECC error", /* 0_1000b */
105 "SVM DEV Error", /* 0_1001b */
106 "Link Data error", /* 0_1010b */
107 "Link/L3/Probe Filter Protocol error", /* 0_1011b */
108 "NB Internal Arrays Parity error", /* 0_1100b */
109 "DRAM Address/Control Parity error", /* 0_1101b */
110 "Link Transmission error", /* 0_1110b */
111 "GART/DEV Table Walk Data error" /* 0_1111b */
112 "Res 0x100 error", /* 1_0000b */
113 "Res 0x101 error", /* 1_0001b */
114 "Res 0x102 error", /* 1_0010b */
115 "Res 0x103 error", /* 1_0011b */
116 "Res 0x104 error", /* 1_0100b */
117 "Res 0x105 error", /* 1_0101b */
118 "Res 0x106 error", /* 1_0110b */
119 "Res 0x107 error", /* 1_0111b */
120 "Res 0x108 error", /* 1_1000b */
121 "Res 0x109 error", /* 1_1001b */
122 "Res 0x10A error", /* 1_1010b */
123 "Res 0x10B error", /* 1_1011b */
124 "ECC error in L3 Cache Data", /* 1_1100b */
125 "L3 Cache Tag error", /* 1_1101b */
126 "L3 Cache LRU Parity error", /* 1_1110b */
127 "Probe Filter error" /* 1_1111b */
128};
129EXPORT_SYMBOL_GPL(ext_msgs);
130
131static void amd_decode_dc_mce(u64 mc0_status)
132{
133 u32 ec = mc0_status & 0xffff;
134 u32 xec = (mc0_status >> 16) & 0xf;
135
136 pr_emerg("Data Cache Error");
137
138 if (xec == 1 && TLB_ERROR(ec))
139 pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
140 else if (xec == 0) {
141 if (mc0_status & (1ULL << 40))
142 pr_cont(" during Data Scrub.\n");
143 else if (TLB_ERROR(ec))
144 pr_cont(": %s TLB parity error.\n", LL_MSG(ec));
145 else if (MEM_ERROR(ec)) {
146 u8 ll = ec & 0x3;
147 u8 tt = (ec >> 2) & 0x3;
148 u8 rrrr = (ec >> 4) & 0xf;
149
150 /* see F10h BKDG (31116), Table 92. */
151 if (ll == 0x1) {
152 if (tt != 0x1)
153 goto wrong_dc_mce;
154
155 pr_cont(": Data/Tag %s error.\n", RRRR_MSG(ec));
156
157 } else if (ll == 0x2 && rrrr == 0x3)
158 pr_cont(" during L1 linefill from L2.\n");
159 else
160 goto wrong_dc_mce;
161 } else if (BUS_ERROR(ec) && boot_cpu_data.x86 == 0xf)
162 pr_cont(" during system linefill.\n");
163 else
164 goto wrong_dc_mce;
165 } else
166 goto wrong_dc_mce;
167
168 return;
169
170wrong_dc_mce:
171 pr_warning("Corrupted DC MCE info?\n");
172}
173
174static void amd_decode_ic_mce(u64 mc1_status)
175{
176 u32 ec = mc1_status & 0xffff;
177 u32 xec = (mc1_status >> 16) & 0xf;
178
179 pr_emerg("Instruction Cache Error");
180
181 if (xec == 1 && TLB_ERROR(ec))
182 pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
183 else if (xec == 0) {
184 if (TLB_ERROR(ec))
185 pr_cont(": %s TLB Parity error.\n", LL_MSG(ec));
186 else if (BUS_ERROR(ec)) {
187 if (boot_cpu_data.x86 == 0xf &&
188 (mc1_status & (1ULL << 58)))
189 pr_cont(" during system linefill.\n");
190 else
191 pr_cont(" during attempted NB data read.\n");
192 } else if (MEM_ERROR(ec)) {
193 u8 ll = ec & 0x3;
194 u8 rrrr = (ec >> 4) & 0xf;
195
196 if (ll == 0x2)
197 pr_cont(" during a linefill from L2.\n");
198 else if (ll == 0x1) {
199
200 switch (rrrr) {
201 case 0x5:
202 pr_cont(": Parity error during "
203 "data load.\n");
204 break;
205
206 case 0x7:
207 pr_cont(": Copyback Parity/Victim"
208 " error.\n");
209 break;
210
211 case 0x8:
212 pr_cont(": Tag Snoop error.\n");
213 break;
214
215 default:
216 goto wrong_ic_mce;
217 break;
218 }
219 }
220 } else
221 goto wrong_ic_mce;
222 } else
223 goto wrong_ic_mce;
224
225 return;
226
227wrong_ic_mce:
228 pr_warning("Corrupted IC MCE info?\n");
229}
230
231static void amd_decode_bu_mce(u64 mc2_status)
232{
233 u32 ec = mc2_status & 0xffff;
234 u32 xec = (mc2_status >> 16) & 0xf;
235
236 pr_emerg("Bus Unit Error");
237
238 if (xec == 0x1)
239 pr_cont(" in the write data buffers.\n");
240 else if (xec == 0x3)
241 pr_cont(" in the victim data buffers.\n");
242 else if (xec == 0x2 && MEM_ERROR(ec))
243 pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
244 else if (xec == 0x0) {
245 if (TLB_ERROR(ec))
246 pr_cont(": %s error in a Page Descriptor Cache or "
247 "Guest TLB.\n", TT_MSG(ec));
248 else if (BUS_ERROR(ec))
249 pr_cont(": %s/ECC error in data read from NB: %s.\n",
250 RRRR_MSG(ec), PP_MSG(ec));
251 else if (MEM_ERROR(ec)) {
252 u8 rrrr = (ec >> 4) & 0xf;
253
254 if (rrrr >= 0x7)
255 pr_cont(": %s error during data copyback.\n",
256 RRRR_MSG(ec));
257 else if (rrrr <= 0x1)
258 pr_cont(": %s parity/ECC error during data "
259 "access from L2.\n", RRRR_MSG(ec));
260 else
261 goto wrong_bu_mce;
262 } else
263 goto wrong_bu_mce;
264 } else
265 goto wrong_bu_mce;
266
267 return;
268
269wrong_bu_mce:
270 pr_warning("Corrupted BU MCE info?\n");
271}
272
273static void amd_decode_ls_mce(u64 mc3_status)
274{
275 u32 ec = mc3_status & 0xffff;
276 u32 xec = (mc3_status >> 16) & 0xf;
277
278 pr_emerg("Load Store Error");
279
280 if (xec == 0x0) {
281 u8 rrrr = (ec >> 4) & 0xf;
282
283 if (!BUS_ERROR(ec) || (rrrr != 0x3 && rrrr != 0x4))
284 goto wrong_ls_mce;
285
286 pr_cont(" during %s.\n", RRRR_MSG(ec));
287 }
288 return;
289
290wrong_ls_mce:
291 pr_warning("Corrupted LS MCE info?\n");
292}
293
294void amd_decode_nb_mce(int node_id, struct err_regs *regs, int handle_errors)
295{
296 u32 ec = ERROR_CODE(regs->nbsl);
297
298 if (!handle_errors)
299 return;
300
301 /*
302 * GART TLB error reporting is disabled by default. Bail out early.
303 */
304 if (TLB_ERROR(ec) && !report_gart_errors)
305 return;
306
307 pr_emerg("Northbridge Error, node %d", node_id);
308
309 /*
310 * F10h, revD can disable ErrCpu[3:0] so check that first and also the
311 * value encoding has changed so interpret those differently
312 */
313 if ((boot_cpu_data.x86 == 0x10) &&
314 (boot_cpu_data.x86_model > 7)) {
315 if (regs->nbsh & K8_NBSH_ERR_CPU_VAL)
316 pr_cont(", core: %u\n", (u8)(regs->nbsh & 0xf));
317 } else {
318 u8 assoc_cpus = regs->nbsh & 0xf;
319
320 if (assoc_cpus > 0)
321 pr_cont(", core: %d", fls(assoc_cpus) - 1);
322
323 pr_cont("\n");
324 }
325
326 pr_emerg("%s.\n", EXT_ERR_MSG(regs->nbsl));
327
328 if (BUS_ERROR(ec) && nb_bus_decoder)
329 nb_bus_decoder(node_id, regs);
330}
331EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
332
333static void amd_decode_fr_mce(u64 mc5_status)
334{
335 /* we have only one error signature so match all fields at once. */
336 if ((mc5_status & 0xffff) == 0x0f0f)
337 pr_emerg(" FR Error: CPU Watchdog timer expire.\n");
338 else
339 pr_warning("Corrupted FR MCE info?\n");
340}
341
342static inline void amd_decode_err_code(unsigned int ec)
343{
344 if (TLB_ERROR(ec)) {
345 pr_emerg("Transaction: %s, Cache Level %s\n",
346 TT_MSG(ec), LL_MSG(ec));
347 } else if (MEM_ERROR(ec)) {
348 pr_emerg("Transaction: %s, Type: %s, Cache Level: %s",
349 RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
350 } else if (BUS_ERROR(ec)) {
351 pr_emerg("Transaction type: %s(%s), %s, Cache Level: %s, "
352 "Participating Processor: %s\n",
353 RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
354 PP_MSG(ec));
355 } else
356 pr_warning("Huh? Unknown MCE error 0x%x\n", ec);
357}
358
359static int amd_decode_mce(struct notifier_block *nb, unsigned long val,
360 void *data)
361{
362 struct mce *m = (struct mce *)data;
363 struct err_regs regs;
364 int node, ecc;
365
366 pr_emerg("MC%d_STATUS: ", m->bank);
367
368 pr_cont("%sorrected error, other errors lost: %s, "
369 "CPU context corrupt: %s",
370 ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
371 ((m->status & MCI_STATUS_OVER) ? "yes" : "no"),
372 ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
373
374 /* do the two bits[14:13] together */
375 ecc = (m->status >> 45) & 0x3;
376 if (ecc)
377 pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
378
379 pr_cont("\n");
380
381 switch (m->bank) {
382 case 0:
383 amd_decode_dc_mce(m->status);
384 break;
385
386 case 1:
387 amd_decode_ic_mce(m->status);
388 break;
389
390 case 2:
391 amd_decode_bu_mce(m->status);
392 break;
393
394 case 3:
395 amd_decode_ls_mce(m->status);
396 break;
397
398 case 4:
399 regs.nbsl = (u32) m->status;
400 regs.nbsh = (u32)(m->status >> 32);
401 regs.nbeal = (u32) m->addr;
402 regs.nbeah = (u32)(m->addr >> 32);
403 node = amd_get_nb_id(m->extcpu);
404
405 amd_decode_nb_mce(node, &regs, 1);
406 break;
407
408 case 5:
409 amd_decode_fr_mce(m->status);
410 break;
411
412 default:
413 break;
414 }
415
416 amd_decode_err_code(m->status & 0xffff);
417
418 return NOTIFY_STOP;
419}
420
421static struct notifier_block amd_mce_dec_nb = {
422 .notifier_call = amd_decode_mce,
423};
424
425static int __init mce_amd_init(void)
426{
427 /*
428 * We can decode MCEs for K8, F10h and F11h CPUs:
429 */
430 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
431 return 0;
432
433 if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
434 return 0;
435
436 atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
437
438 return 0;
439}
440early_initcall(mce_amd_init);
441
442#ifdef MODULE
443static void __exit mce_amd_exit(void)
444{
445 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
446}
447
448MODULE_DESCRIPTION("AMD MCE decoder");
449MODULE_ALIAS("edac-mce-amd");
450MODULE_LICENSE("GPL");
451module_exit(mce_amd_exit);
452#endif
diff --git a/drivers/edac/edac_module.c b/drivers/edac/edac_module.c
index 7e1374afd967..be4b075c3098 100644
--- a/drivers/edac/edac_module.c
+++ b/drivers/edac/edac_module.c
@@ -27,15 +27,6 @@ EXPORT_SYMBOL_GPL(edac_debug_level);
27struct workqueue_struct *edac_workqueue; 27struct workqueue_struct *edac_workqueue;
28 28
29/* 29/*
30 * sysfs object: /sys/devices/system/edac
31 * need to export to other files in this modules
32 */
33static struct sysdev_class edac_class = {
34 .name = "edac",
35};
36static int edac_class_valid;
37
38/*
39 * edac_op_state_to_string() 30 * edac_op_state_to_string()
40 */ 31 */
41char *edac_op_state_to_string(int opstate) 32char *edac_op_state_to_string(int opstate)
@@ -55,60 +46,6 @@ char *edac_op_state_to_string(int opstate)
55} 46}
56 47
57/* 48/*
58 * edac_get_edac_class()
59 *
60 * return pointer to the edac class of 'edac'
61 */
62struct sysdev_class *edac_get_edac_class(void)
63{
64 struct sysdev_class *classptr = NULL;
65
66 if (edac_class_valid)
67 classptr = &edac_class;
68
69 return classptr;
70}
71
72/*
73 * edac_register_sysfs_edac_name()
74 *
75 * register the 'edac' into /sys/devices/system
76 *
77 * return:
78 * 0 success
79 * !0 error
80 */
81static int edac_register_sysfs_edac_name(void)
82{
83 int err;
84
85 /* create the /sys/devices/system/edac directory */
86 err = sysdev_class_register(&edac_class);
87
88 if (err) {
89 debugf1("%s() error=%d\n", __func__, err);
90 return err;
91 }
92
93 edac_class_valid = 1;
94 return 0;
95}
96
97/*
98 * sysdev_class_unregister()
99 *
100 * unregister the 'edac' from /sys/devices/system
101 */
102static void edac_unregister_sysfs_edac_name(void)
103{
104 /* only if currently registered, then unregister it */
105 if (edac_class_valid)
106 sysdev_class_unregister(&edac_class);
107
108 edac_class_valid = 0;
109}
110
111/*
112 * edac_workqueue_setup 49 * edac_workqueue_setup
113 * initialize the edac work queue for polling operations 50 * initialize the edac work queue for polling operations
114 */ 51 */
@@ -154,21 +91,11 @@ static int __init edac_init(void)
154 edac_pci_clear_parity_errors(); 91 edac_pci_clear_parity_errors();
155 92
156 /* 93 /*
157 * perform the registration of the /sys/devices/system/edac class object
158 */
159 if (edac_register_sysfs_edac_name()) {
160 edac_printk(KERN_ERR, EDAC_MC,
161 "Error initializing 'edac' kobject\n");
162 err = -ENODEV;
163 goto error;
164 }
165
166 /*
167 * now set up the mc_kset under the edac class object 94 * now set up the mc_kset under the edac class object
168 */ 95 */
169 err = edac_sysfs_setup_mc_kset(); 96 err = edac_sysfs_setup_mc_kset();
170 if (err) 97 if (err)
171 goto sysfs_setup_fail; 98 goto error;
172 99
173 /* Setup/Initialize the workq for this core */ 100 /* Setup/Initialize the workq for this core */
174 err = edac_workqueue_setup(); 101 err = edac_workqueue_setup();
@@ -183,9 +110,6 @@ static int __init edac_init(void)
183workq_fail: 110workq_fail:
184 edac_sysfs_teardown_mc_kset(); 111 edac_sysfs_teardown_mc_kset();
185 112
186sysfs_setup_fail:
187 edac_unregister_sysfs_edac_name();
188
189error: 113error:
190 return err; 114 return err;
191} 115}
@@ -201,7 +125,6 @@ static void __exit edac_exit(void)
201 /* tear down the various subsystems */ 125 /* tear down the various subsystems */
202 edac_workqueue_teardown(); 126 edac_workqueue_teardown();
203 edac_sysfs_teardown_mc_kset(); 127 edac_sysfs_teardown_mc_kset();
204 edac_unregister_sysfs_edac_name();
205} 128}
206 129
207/* 130/*
diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h
index 233d4798c3aa..17aabb7b90ec 100644
--- a/drivers/edac/edac_module.h
+++ b/drivers/edac/edac_module.h
@@ -42,7 +42,6 @@ extern void edac_device_unregister_sysfs_main_kobj(
42 struct edac_device_ctl_info *edac_dev); 42 struct edac_device_ctl_info *edac_dev);
43extern int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev); 43extern int edac_device_create_sysfs(struct edac_device_ctl_info *edac_dev);
44extern void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev); 44extern void edac_device_remove_sysfs(struct edac_device_ctl_info *edac_dev);
45extern struct sysdev_class *edac_get_edac_class(void);
46 45
47/* edac core workqueue: single CPU mode */ 46/* edac core workqueue: single CPU mode */
48extern struct workqueue_struct *edac_workqueue; 47extern struct workqueue_struct *edac_workqueue;
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index c39697df9cb4..023b01cb5175 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -7,7 +7,7 @@
7 * 7 *
8 */ 8 */
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/sysdev.h> 10#include <linux/edac.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/ctype.h> 12#include <linux/ctype.h>
13 13
@@ -354,7 +354,7 @@ static int edac_pci_main_kobj_setup(void)
354 /* First time, so create the main kobject and its 354 /* First time, so create the main kobject and its
355 * controls and atributes 355 * controls and atributes
356 */ 356 */
357 edac_class = edac_get_edac_class(); 357 edac_class = edac_get_sysfs_class();
358 if (edac_class == NULL) { 358 if (edac_class == NULL) {
359 debugf1("%s() no edac_class\n", __func__); 359 debugf1("%s() no edac_class\n", __func__);
360 err = -ENODEV; 360 err = -ENODEV;
@@ -368,7 +368,7 @@ static int edac_pci_main_kobj_setup(void)
368 if (!try_module_get(THIS_MODULE)) { 368 if (!try_module_get(THIS_MODULE)) {
369 debugf1("%s() try_module_get() failed\n", __func__); 369 debugf1("%s() try_module_get() failed\n", __func__);
370 err = -ENODEV; 370 err = -ENODEV;
371 goto decrement_count_fail; 371 goto mod_get_fail;
372 } 372 }
373 373
374 edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL); 374 edac_pci_top_main_kobj = kzalloc(sizeof(struct kobject), GFP_KERNEL);
@@ -403,6 +403,9 @@ kobject_init_and_add_fail:
403kzalloc_fail: 403kzalloc_fail:
404 module_put(THIS_MODULE); 404 module_put(THIS_MODULE);
405 405
406mod_get_fail:
407 edac_put_sysfs_class();
408
406decrement_count_fail: 409decrement_count_fail:
407 /* if are on this error exit, nothing to tear down */ 410 /* if are on this error exit, nothing to tear down */
408 atomic_dec(&edac_pci_sysfs_refcount); 411 atomic_dec(&edac_pci_sysfs_refcount);
@@ -429,6 +432,7 @@ static void edac_pci_main_kobj_teardown(void)
429 __func__); 432 __func__);
430 kobject_put(edac_pci_top_main_kobj); 433 kobject_put(edac_pci_top_main_kobj);
431 } 434 }
435 edac_put_sysfs_class();
432} 436}
433 437
434/* 438/*
diff --git a/drivers/edac/edac_stub.c b/drivers/edac/edac_stub.c
index 20b428aa155e..aab970760b75 100644
--- a/drivers/edac/edac_stub.c
+++ b/drivers/edac/edac_stub.c
@@ -3,10 +3,13 @@
3 * 3 *
4 * Author: Dave Jiang <djiang@mvista.com> 4 * Author: Dave Jiang <djiang@mvista.com>
5 * 5 *
6 * 2007 (c) MontaVista Software, Inc. This file is licensed under 6 * 2007 (c) MontaVista Software, Inc.
7 * the terms of the GNU General Public License version 2. This program 7 * 2010 (c) Advanced Micro Devices Inc.
8 * is licensed "as is" without any warranty of any kind, whether express 8 * Borislav Petkov <borislav.petkov@amd.com>
9 * or implied. 9 *
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
10 * 13 *
11 */ 14 */
12#include <linux/module.h> 15#include <linux/module.h>
@@ -23,6 +26,8 @@ EXPORT_SYMBOL_GPL(edac_handlers);
23int edac_err_assert = 0; 26int edac_err_assert = 0;
24EXPORT_SYMBOL_GPL(edac_err_assert); 27EXPORT_SYMBOL_GPL(edac_err_assert);
25 28
29static atomic_t edac_class_valid = ATOMIC_INIT(0);
30
26/* 31/*
27 * called to determine if there is an EDAC driver interested in 32 * called to determine if there is an EDAC driver interested in
28 * knowing an event (such as NMI) occurred 33 * knowing an event (such as NMI) occurred
@@ -44,3 +49,41 @@ void edac_atomic_assert_error(void)
44 edac_err_assert++; 49 edac_err_assert++;
45} 50}
46EXPORT_SYMBOL_GPL(edac_atomic_assert_error); 51EXPORT_SYMBOL_GPL(edac_atomic_assert_error);
52
53/*
54 * sysfs object: /sys/devices/system/edac
55 * need to export to other files
56 */
57struct sysdev_class edac_class = {
58 .name = "edac",
59};
60EXPORT_SYMBOL_GPL(edac_class);
61
62/* return pointer to the 'edac' node in sysfs */
63struct sysdev_class *edac_get_sysfs_class(void)
64{
65 int err = 0;
66
67 if (atomic_read(&edac_class_valid))
68 goto out;
69
70 /* create the /sys/devices/system/edac directory */
71 err = sysdev_class_register(&edac_class);
72 if (err) {
73 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
74 return NULL;
75 }
76
77out:
78 atomic_inc(&edac_class_valid);
79 return &edac_class;
80}
81EXPORT_SYMBOL_GPL(edac_get_sysfs_class);
82
83void edac_put_sysfs_class(void)
84{
85 /* last user unregisters it */
86 if (atomic_dec_and_test(&edac_class_valid))
87 sysdev_class_unregister(&edac_class);
88}
89EXPORT_SYMBOL_GPL(edac_put_sysfs_class);
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index e0187d16dd7c..0fd5b85a0f75 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -1140,6 +1140,7 @@ static struct mcidev_sysfs_attribute i7core_udimm_counters_attrs[] = {
1140 ATTR_COUNTER(0), 1140 ATTR_COUNTER(0),
1141 ATTR_COUNTER(1), 1141 ATTR_COUNTER(1),
1142 ATTR_COUNTER(2), 1142 ATTR_COUNTER(2),
1143 { .attr = { .name = NULL } }
1143}; 1144};
1144 1145
1145static struct mcidev_sysfs_group i7core_udimm_counters = { 1146static struct mcidev_sysfs_group i7core_udimm_counters = {
diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
new file mode 100644
index 000000000000..c0181093b490
--- /dev/null
+++ b/drivers/edac/mce_amd.c
@@ -0,0 +1,680 @@
1#include <linux/module.h>
2#include <linux/slab.h>
3
4#include "mce_amd.h"
5
6static struct amd_decoder_ops *fam_ops;
7
8static u8 nb_err_cpumask = 0xf;
9
10static bool report_gart_errors;
11static void (*nb_bus_decoder)(int node_id, struct mce *m, u32 nbcfg);
12
13void amd_report_gart_errors(bool v)
14{
15 report_gart_errors = v;
16}
17EXPORT_SYMBOL_GPL(amd_report_gart_errors);
18
19void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32))
20{
21 nb_bus_decoder = f;
22}
23EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
24
25void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32))
26{
27 if (nb_bus_decoder) {
28 WARN_ON(nb_bus_decoder != f);
29
30 nb_bus_decoder = NULL;
31 }
32}
33EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
34
35/*
36 * string representation for the different MCA reported error types, see F3x48
37 * or MSR0000_0411.
38 */
39
40/* transaction type */
41const char *tt_msgs[] = { "INSN", "DATA", "GEN", "RESV" };
42EXPORT_SYMBOL_GPL(tt_msgs);
43
44/* cache level */
45const char *ll_msgs[] = { "RESV", "L1", "L2", "L3/GEN" };
46EXPORT_SYMBOL_GPL(ll_msgs);
47
48/* memory transaction type */
49const char *rrrr_msgs[] = {
50 "GEN", "RD", "WR", "DRD", "DWR", "IRD", "PRF", "EV", "SNP"
51};
52EXPORT_SYMBOL_GPL(rrrr_msgs);
53
54/* participating processor */
55const char *pp_msgs[] = { "SRC", "RES", "OBS", "GEN" };
56EXPORT_SYMBOL_GPL(pp_msgs);
57
58/* request timeout */
59const char *to_msgs[] = { "no timeout", "timed out" };
60EXPORT_SYMBOL_GPL(to_msgs);
61
62/* memory or i/o */
63const char *ii_msgs[] = { "MEM", "RESV", "IO", "GEN" };
64EXPORT_SYMBOL_GPL(ii_msgs);
65
66static const char *f10h_nb_mce_desc[] = {
67 "HT link data error",
68 "Protocol error (link, L3, probe filter, etc.)",
69 "Parity error in NB-internal arrays",
70 "Link Retry due to IO link transmission error",
71 "L3 ECC data cache error",
72 "ECC error in L3 cache tag",
73 "L3 LRU parity bits error",
74 "ECC Error in the Probe Filter directory"
75};
76
77static bool f12h_dc_mce(u16 ec)
78{
79 bool ret = false;
80
81 if (MEM_ERROR(ec)) {
82 u8 ll = ec & 0x3;
83 ret = true;
84
85 if (ll == LL_L2)
86 pr_cont("during L1 linefill from L2.\n");
87 else if (ll == LL_L1)
88 pr_cont("Data/Tag %s error.\n", RRRR_MSG(ec));
89 else
90 ret = false;
91 }
92 return ret;
93}
94
95static bool f10h_dc_mce(u16 ec)
96{
97 u8 r4 = (ec >> 4) & 0xf;
98 u8 ll = ec & 0x3;
99
100 if (r4 == R4_GEN && ll == LL_L1) {
101 pr_cont("during data scrub.\n");
102 return true;
103 }
104 return f12h_dc_mce(ec);
105}
106
107static bool k8_dc_mce(u16 ec)
108{
109 if (BUS_ERROR(ec)) {
110 pr_cont("during system linefill.\n");
111 return true;
112 }
113
114 return f10h_dc_mce(ec);
115}
116
117static bool f14h_dc_mce(u16 ec)
118{
119 u8 r4 = (ec >> 4) & 0xf;
120 u8 ll = ec & 0x3;
121 u8 tt = (ec >> 2) & 0x3;
122 u8 ii = tt;
123 bool ret = true;
124
125 if (MEM_ERROR(ec)) {
126
127 if (tt != TT_DATA || ll != LL_L1)
128 return false;
129
130 switch (r4) {
131 case R4_DRD:
132 case R4_DWR:
133 pr_cont("Data/Tag parity error due to %s.\n",
134 (r4 == R4_DRD ? "load/hw prf" : "store"));
135 break;
136 case R4_EVICT:
137 pr_cont("Copyback parity error on a tag miss.\n");
138 break;
139 case R4_SNOOP:
140 pr_cont("Tag parity error during snoop.\n");
141 break;
142 default:
143 ret = false;
144 }
145 } else if (BUS_ERROR(ec)) {
146
147 if ((ii != II_MEM && ii != II_IO) || ll != LL_LG)
148 return false;
149
150 pr_cont("System read data error on a ");
151
152 switch (r4) {
153 case R4_RD:
154 pr_cont("TLB reload.\n");
155 break;
156 case R4_DWR:
157 pr_cont("store.\n");
158 break;
159 case R4_DRD:
160 pr_cont("load.\n");
161 break;
162 default:
163 ret = false;
164 }
165 } else {
166 ret = false;
167 }
168
169 return ret;
170}
171
172static void amd_decode_dc_mce(struct mce *m)
173{
174 u16 ec = m->status & 0xffff;
175 u8 xec = (m->status >> 16) & 0xf;
176
177 pr_emerg(HW_ERR "Data Cache Error: ");
178
179 /* TLB error signatures are the same across families */
180 if (TLB_ERROR(ec)) {
181 u8 tt = (ec >> 2) & 0x3;
182
183 if (tt == TT_DATA) {
184 pr_cont("%s TLB %s.\n", LL_MSG(ec),
185 (xec ? "multimatch" : "parity error"));
186 return;
187 }
188 else
189 goto wrong_dc_mce;
190 }
191
192 if (!fam_ops->dc_mce(ec))
193 goto wrong_dc_mce;
194
195 return;
196
197wrong_dc_mce:
198 pr_emerg(HW_ERR "Corrupted DC MCE info?\n");
199}
200
201static bool k8_ic_mce(u16 ec)
202{
203 u8 ll = ec & 0x3;
204 u8 r4 = (ec >> 4) & 0xf;
205 bool ret = true;
206
207 if (!MEM_ERROR(ec))
208 return false;
209
210 if (ll == 0x2)
211 pr_cont("during a linefill from L2.\n");
212 else if (ll == 0x1) {
213 switch (r4) {
214 case R4_IRD:
215 pr_cont("Parity error during data load.\n");
216 break;
217
218 case R4_EVICT:
219 pr_cont("Copyback Parity/Victim error.\n");
220 break;
221
222 case R4_SNOOP:
223 pr_cont("Tag Snoop error.\n");
224 break;
225
226 default:
227 ret = false;
228 break;
229 }
230 } else
231 ret = false;
232
233 return ret;
234}
235
236static bool f14h_ic_mce(u16 ec)
237{
238 u8 ll = ec & 0x3;
239 u8 tt = (ec >> 2) & 0x3;
240 u8 r4 = (ec >> 4) & 0xf;
241 bool ret = true;
242
243 if (MEM_ERROR(ec)) {
244 if (tt != 0 || ll != 1)
245 ret = false;
246
247 if (r4 == R4_IRD)
248 pr_cont("Data/tag array parity error for a tag hit.\n");
249 else if (r4 == R4_SNOOP)
250 pr_cont("Tag error during snoop/victimization.\n");
251 else
252 ret = false;
253 }
254 return ret;
255}
256
257static void amd_decode_ic_mce(struct mce *m)
258{
259 u16 ec = m->status & 0xffff;
260 u8 xec = (m->status >> 16) & 0xf;
261
262 pr_emerg(HW_ERR "Instruction Cache Error: ");
263
264 if (TLB_ERROR(ec))
265 pr_cont("%s TLB %s.\n", LL_MSG(ec),
266 (xec ? "multimatch" : "parity error"));
267 else if (BUS_ERROR(ec)) {
268 bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_64(58)));
269
270 pr_cont("during %s.\n", (k8 ? "system linefill" : "NB data read"));
271 } else if (fam_ops->ic_mce(ec))
272 ;
273 else
274 pr_emerg(HW_ERR "Corrupted IC MCE info?\n");
275}
276
277static void amd_decode_bu_mce(struct mce *m)
278{
279 u32 ec = m->status & 0xffff;
280 u32 xec = (m->status >> 16) & 0xf;
281
282 pr_emerg(HW_ERR "Bus Unit Error");
283
284 if (xec == 0x1)
285 pr_cont(" in the write data buffers.\n");
286 else if (xec == 0x3)
287 pr_cont(" in the victim data buffers.\n");
288 else if (xec == 0x2 && MEM_ERROR(ec))
289 pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
290 else if (xec == 0x0) {
291 if (TLB_ERROR(ec))
292 pr_cont(": %s error in a Page Descriptor Cache or "
293 "Guest TLB.\n", TT_MSG(ec));
294 else if (BUS_ERROR(ec))
295 pr_cont(": %s/ECC error in data read from NB: %s.\n",
296 RRRR_MSG(ec), PP_MSG(ec));
297 else if (MEM_ERROR(ec)) {
298 u8 rrrr = (ec >> 4) & 0xf;
299
300 if (rrrr >= 0x7)
301 pr_cont(": %s error during data copyback.\n",
302 RRRR_MSG(ec));
303 else if (rrrr <= 0x1)
304 pr_cont(": %s parity/ECC error during data "
305 "access from L2.\n", RRRR_MSG(ec));
306 else
307 goto wrong_bu_mce;
308 } else
309 goto wrong_bu_mce;
310 } else
311 goto wrong_bu_mce;
312
313 return;
314
315wrong_bu_mce:
316 pr_emerg(HW_ERR "Corrupted BU MCE info?\n");
317}
318
319static void amd_decode_ls_mce(struct mce *m)
320{
321 u16 ec = m->status & 0xffff;
322 u8 xec = (m->status >> 16) & 0xf;
323
324 if (boot_cpu_data.x86 == 0x14) {
325 pr_emerg("You shouldn't be seeing an LS MCE on this cpu family,"
326 " please report on LKML.\n");
327 return;
328 }
329
330 pr_emerg(HW_ERR "Load Store Error");
331
332 if (xec == 0x0) {
333 u8 r4 = (ec >> 4) & 0xf;
334
335 if (!BUS_ERROR(ec) || (r4 != R4_DRD && r4 != R4_DWR))
336 goto wrong_ls_mce;
337
338 pr_cont(" during %s.\n", RRRR_MSG(ec));
339 } else
340 goto wrong_ls_mce;
341
342 return;
343
344wrong_ls_mce:
345 pr_emerg(HW_ERR "Corrupted LS MCE info?\n");
346}
347
348static bool k8_nb_mce(u16 ec, u8 xec)
349{
350 bool ret = true;
351
352 switch (xec) {
353 case 0x1:
354 pr_cont("CRC error detected on HT link.\n");
355 break;
356
357 case 0x5:
358 pr_cont("Invalid GART PTE entry during GART table walk.\n");
359 break;
360
361 case 0x6:
362 pr_cont("Unsupported atomic RMW received from an IO link.\n");
363 break;
364
365 case 0x0:
366 case 0x8:
367 if (boot_cpu_data.x86 == 0x11)
368 return false;
369
370 pr_cont("DRAM ECC error detected on the NB.\n");
371 break;
372
373 case 0xd:
374 pr_cont("Parity error on the DRAM addr/ctl signals.\n");
375 break;
376
377 default:
378 ret = false;
379 break;
380 }
381
382 return ret;
383}
384
385static bool f10h_nb_mce(u16 ec, u8 xec)
386{
387 bool ret = true;
388 u8 offset = 0;
389
390 if (k8_nb_mce(ec, xec))
391 return true;
392
393 switch(xec) {
394 case 0xa ... 0xc:
395 offset = 10;
396 break;
397
398 case 0xe:
399 offset = 11;
400 break;
401
402 case 0xf:
403 if (TLB_ERROR(ec))
404 pr_cont("GART Table Walk data error.\n");
405 else if (BUS_ERROR(ec))
406 pr_cont("DMA Exclusion Vector Table Walk error.\n");
407 else
408 ret = false;
409
410 goto out;
411 break;
412
413 case 0x1c ... 0x1f:
414 offset = 24;
415 break;
416
417 default:
418 ret = false;
419
420 goto out;
421 break;
422 }
423
424 pr_cont("%s.\n", f10h_nb_mce_desc[xec - offset]);
425
426out:
427 return ret;
428}
429
430static bool nb_noop_mce(u16 ec, u8 xec)
431{
432 return false;
433}
434
435void amd_decode_nb_mce(int node_id, struct mce *m, u32 nbcfg)
436{
437 u8 xec = (m->status >> 16) & 0x1f;
438 u16 ec = m->status & 0xffff;
439 u32 nbsh = (u32)(m->status >> 32);
440
441 pr_emerg(HW_ERR "Northbridge Error, node %d: ", node_id);
442
443 /*
444 * F10h, revD can disable ErrCpu[3:0] so check that first and also the
445 * value encoding has changed so interpret those differently
446 */
447 if ((boot_cpu_data.x86 == 0x10) &&
448 (boot_cpu_data.x86_model > 7)) {
449 if (nbsh & K8_NBSH_ERR_CPU_VAL)
450 pr_cont(", core: %u", (u8)(nbsh & nb_err_cpumask));
451 } else {
452 u8 assoc_cpus = nbsh & nb_err_cpumask;
453
454 if (assoc_cpus > 0)
455 pr_cont(", core: %d", fls(assoc_cpus) - 1);
456 }
457
458 switch (xec) {
459 case 0x2:
460 pr_cont("Sync error (sync packets on HT link detected).\n");
461 return;
462
463 case 0x3:
464 pr_cont("HT Master abort.\n");
465 return;
466
467 case 0x4:
468 pr_cont("HT Target abort.\n");
469 return;
470
471 case 0x7:
472 pr_cont("NB Watchdog timeout.\n");
473 return;
474
475 case 0x9:
476 pr_cont("SVM DMA Exclusion Vector error.\n");
477 return;
478
479 default:
480 break;
481 }
482
483 if (!fam_ops->nb_mce(ec, xec))
484 goto wrong_nb_mce;
485
486 if (boot_cpu_data.x86 == 0xf || boot_cpu_data.x86 == 0x10)
487 if ((xec == 0x8 || xec == 0x0) && nb_bus_decoder)
488 nb_bus_decoder(node_id, m, nbcfg);
489
490 return;
491
492wrong_nb_mce:
493 pr_emerg(HW_ERR "Corrupted NB MCE info?\n");
494}
495EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
496
497static void amd_decode_fr_mce(struct mce *m)
498{
499 if (boot_cpu_data.x86 == 0xf ||
500 boot_cpu_data.x86 == 0x11)
501 goto wrong_fr_mce;
502
503 /* we have only one error signature so match all fields at once. */
504 if ((m->status & 0xffff) == 0x0f0f) {
505 pr_emerg(HW_ERR "FR Error: CPU Watchdog timer expire.\n");
506 return;
507 }
508
509wrong_fr_mce:
510 pr_emerg(HW_ERR "Corrupted FR MCE info?\n");
511}
512
513static inline void amd_decode_err_code(u16 ec)
514{
515 if (TLB_ERROR(ec)) {
516 pr_emerg(HW_ERR "Transaction: %s, Cache Level: %s\n",
517 TT_MSG(ec), LL_MSG(ec));
518 } else if (MEM_ERROR(ec)) {
519 pr_emerg(HW_ERR "Transaction: %s, Type: %s, Cache Level: %s\n",
520 RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
521 } else if (BUS_ERROR(ec)) {
522 pr_emerg(HW_ERR "Transaction: %s (%s), %s, Cache Level: %s, "
523 "Participating Processor: %s\n",
524 RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
525 PP_MSG(ec));
526 } else
527 pr_emerg(HW_ERR "Huh? Unknown MCE error 0x%x\n", ec);
528}
529
530/*
531 * Filter out unwanted MCE signatures here.
532 */
533static bool amd_filter_mce(struct mce *m)
534{
535 u8 xec = (m->status >> 16) & 0x1f;
536
537 /*
538 * NB GART TLB error reporting is disabled by default.
539 */
540 if (m->bank == 4 && xec == 0x5 && !report_gart_errors)
541 return true;
542
543 return false;
544}
545
546int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
547{
548 struct mce *m = (struct mce *)data;
549 int node, ecc;
550
551 if (amd_filter_mce(m))
552 return NOTIFY_STOP;
553
554 pr_emerg(HW_ERR "MC%d_STATUS: ", m->bank);
555
556 pr_cont("%sorrected error, other errors lost: %s, "
557 "CPU context corrupt: %s",
558 ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
559 ((m->status & MCI_STATUS_OVER) ? "yes" : "no"),
560 ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
561
562 /* do the two bits[14:13] together */
563 ecc = (m->status >> 45) & 0x3;
564 if (ecc)
565 pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
566
567 pr_cont("\n");
568
569 switch (m->bank) {
570 case 0:
571 amd_decode_dc_mce(m);
572 break;
573
574 case 1:
575 amd_decode_ic_mce(m);
576 break;
577
578 case 2:
579 amd_decode_bu_mce(m);
580 break;
581
582 case 3:
583 amd_decode_ls_mce(m);
584 break;
585
586 case 4:
587 node = amd_get_nb_id(m->extcpu);
588 amd_decode_nb_mce(node, m, 0);
589 break;
590
591 case 5:
592 amd_decode_fr_mce(m);
593 break;
594
595 default:
596 break;
597 }
598
599 amd_decode_err_code(m->status & 0xffff);
600
601 return NOTIFY_STOP;
602}
603EXPORT_SYMBOL_GPL(amd_decode_mce);
604
605static struct notifier_block amd_mce_dec_nb = {
606 .notifier_call = amd_decode_mce,
607};
608
609static int __init mce_amd_init(void)
610{
611 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
612 return 0;
613
614 if ((boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x12) &&
615 (boot_cpu_data.x86 != 0x14 || boot_cpu_data.x86_model > 0xf))
616 return 0;
617
618 fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL);
619 if (!fam_ops)
620 return -ENOMEM;
621
622 switch (boot_cpu_data.x86) {
623 case 0xf:
624 fam_ops->dc_mce = k8_dc_mce;
625 fam_ops->ic_mce = k8_ic_mce;
626 fam_ops->nb_mce = k8_nb_mce;
627 break;
628
629 case 0x10:
630 fam_ops->dc_mce = f10h_dc_mce;
631 fam_ops->ic_mce = k8_ic_mce;
632 fam_ops->nb_mce = f10h_nb_mce;
633 break;
634
635 case 0x11:
636 fam_ops->dc_mce = k8_dc_mce;
637 fam_ops->ic_mce = k8_ic_mce;
638 fam_ops->nb_mce = f10h_nb_mce;
639 break;
640
641 case 0x12:
642 fam_ops->dc_mce = f12h_dc_mce;
643 fam_ops->ic_mce = k8_ic_mce;
644 fam_ops->nb_mce = nb_noop_mce;
645 break;
646
647 case 0x14:
648 nb_err_cpumask = 0x3;
649 fam_ops->dc_mce = f14h_dc_mce;
650 fam_ops->ic_mce = f14h_ic_mce;
651 fam_ops->nb_mce = nb_noop_mce;
652 break;
653
654 default:
655 printk(KERN_WARNING "Huh? What family is that: %d?!\n",
656 boot_cpu_data.x86);
657 kfree(fam_ops);
658 return -EINVAL;
659 }
660
661 pr_info("MCE: In-kernel MCE decoding enabled.\n");
662
663 atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
664
665 return 0;
666}
667early_initcall(mce_amd_init);
668
669#ifdef MODULE
670static void __exit mce_amd_exit(void)
671{
672 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
673 kfree(fam_ops);
674}
675
676MODULE_DESCRIPTION("AMD MCE decoder");
677MODULE_ALIAS("edac-mce-amd");
678MODULE_LICENSE("GPL");
679module_exit(mce_amd_exit);
680#endif
diff --git a/drivers/edac/edac_mce_amd.h b/drivers/edac/mce_amd.h
index df23ee065f79..35f6e0e3b297 100644
--- a/drivers/edac/edac_mce_amd.h
+++ b/drivers/edac/mce_amd.h
@@ -1,11 +1,14 @@
1#ifndef _EDAC_MCE_AMD_H 1#ifndef _EDAC_MCE_AMD_H
2#define _EDAC_MCE_AMD_H 2#define _EDAC_MCE_AMD_H
3 3
4#include <linux/notifier.h>
5
4#include <asm/mce.h> 6#include <asm/mce.h>
5 7
8#define BIT_64(n) (U64_C(1) << (n))
9
6#define ERROR_CODE(x) ((x) & 0xffff) 10#define ERROR_CODE(x) ((x) & 0xffff)
7#define EXT_ERROR_CODE(x) (((x) >> 16) & 0x1f) 11#define EXT_ERROR_CODE(x) (((x) >> 16) & 0x1f)
8#define EXT_ERR_MSG(x) ext_msgs[EXT_ERROR_CODE(x)]
9 12
10#define LOW_SYNDROME(x) (((x) >> 15) & 0xff) 13#define LOW_SYNDROME(x) (((x) >> 15) & 0xff)
11#define HIGH_SYNDROME(x) (((x) >> 24) & 0xff) 14#define HIGH_SYNDROME(x) (((x) >> 24) & 0xff)
@@ -20,13 +23,14 @@
20#define II_MSG(x) ii_msgs[II(x)] 23#define II_MSG(x) ii_msgs[II(x)]
21#define LL(x) (((x) >> 0) & 0x3) 24#define LL(x) (((x) >> 0) & 0x3)
22#define LL_MSG(x) ll_msgs[LL(x)] 25#define LL_MSG(x) ll_msgs[LL(x)]
23#define RRRR(x) (((x) >> 4) & 0xf)
24#define RRRR_MSG(x) rrrr_msgs[RRRR(x)]
25#define TO(x) (((x) >> 8) & 0x1) 26#define TO(x) (((x) >> 8) & 0x1)
26#define TO_MSG(x) to_msgs[TO(x)] 27#define TO_MSG(x) to_msgs[TO(x)]
27#define PP(x) (((x) >> 9) & 0x3) 28#define PP(x) (((x) >> 9) & 0x3)
28#define PP_MSG(x) pp_msgs[PP(x)] 29#define PP_MSG(x) pp_msgs[PP(x)]
29 30
31#define RRRR(x) (((x) >> 4) & 0xf)
32#define RRRR_MSG(x) ((RRRR(x) < 9) ? rrrr_msgs[RRRR(x)] : "Wrong R4!")
33
30#define K8_NBSH 0x4C 34#define K8_NBSH 0x4C
31 35
32#define K8_NBSH_VALID_BIT BIT(31) 36#define K8_NBSH_VALID_BIT BIT(31)
@@ -41,13 +45,45 @@
41#define K8_NBSH_UECC BIT(13) 45#define K8_NBSH_UECC BIT(13)
42#define K8_NBSH_ERR_SCRUBER BIT(8) 46#define K8_NBSH_ERR_SCRUBER BIT(8)
43 47
48enum tt_ids {
49 TT_INSTR = 0,
50 TT_DATA,
51 TT_GEN,
52 TT_RESV,
53};
54
55enum ll_ids {
56 LL_RESV = 0,
57 LL_L1,
58 LL_L2,
59 LL_LG,
60};
61
62enum ii_ids {
63 II_MEM = 0,
64 II_RESV,
65 II_IO,
66 II_GEN,
67};
68
69enum rrrr_ids {
70 R4_GEN = 0,
71 R4_RD,
72 R4_WR,
73 R4_DRD,
74 R4_DWR,
75 R4_IRD,
76 R4_PREF,
77 R4_EVICT,
78 R4_SNOOP,
79};
80
44extern const char *tt_msgs[]; 81extern const char *tt_msgs[];
45extern const char *ll_msgs[]; 82extern const char *ll_msgs[];
46extern const char *rrrr_msgs[]; 83extern const char *rrrr_msgs[];
47extern const char *pp_msgs[]; 84extern const char *pp_msgs[];
48extern const char *to_msgs[]; 85extern const char *to_msgs[];
49extern const char *ii_msgs[]; 86extern const char *ii_msgs[];
50extern const char *ext_msgs[];
51 87
52/* 88/*
53 * relevant NB regs 89 * relevant NB regs
@@ -60,10 +96,19 @@ struct err_regs {
60 u32 nbeal; 96 u32 nbeal;
61}; 97};
62 98
99/*
100 * per-family decoder ops
101 */
102struct amd_decoder_ops {
103 bool (*dc_mce)(u16);
104 bool (*ic_mce)(u16);
105 bool (*nb_mce)(u16, u8);
106};
63 107
64void amd_report_gart_errors(bool); 108void amd_report_gart_errors(bool);
65void amd_register_ecc_decoder(void (*f)(int, struct err_regs *)); 109void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32));
66void amd_unregister_ecc_decoder(void (*f)(int, struct err_regs *)); 110void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32));
67void amd_decode_nb_mce(int, struct err_regs *, int); 111void amd_decode_nb_mce(int, struct mce *, u32);
112int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data);
68 113
69#endif /* _EDAC_MCE_AMD_H */ 114#endif /* _EDAC_MCE_AMD_H */
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
new file mode 100644
index 000000000000..8d0688f36d4c
--- /dev/null
+++ b/drivers/edac/mce_amd_inj.c
@@ -0,0 +1,171 @@
1/*
2 * A simple MCE injection facility for testing the MCE decoding code. This
3 * driver should be built as module so that it can be loaded on production
4 * kernels for testing purposes.
5 *
6 * This file may be distributed under the terms of the GNU General Public
7 * License version 2.
8 *
9 * Copyright (c) 2010: Borislav Petkov <borislav.petkov@amd.com>
10 * Advanced Micro Devices Inc.
11 */
12
13#include <linux/kobject.h>
14#include <linux/sysdev.h>
15#include <linux/edac.h>
16#include <asm/mce.h>
17
18#include "mce_amd.h"
19
20struct edac_mce_attr {
21 struct attribute attr;
22 ssize_t (*show) (struct kobject *kobj, struct edac_mce_attr *attr, char *buf);
23 ssize_t (*store)(struct kobject *kobj, struct edac_mce_attr *attr,
24 const char *buf, size_t count);
25};
26
27#define EDAC_MCE_ATTR(_name, _mode, _show, _store) \
28static struct edac_mce_attr mce_attr_##_name = __ATTR(_name, _mode, _show, _store)
29
30static struct kobject *mce_kobj;
31
32/*
33 * Collect all the MCi_XXX settings
34 */
35static struct mce i_mce;
36
37#define MCE_INJECT_STORE(reg) \
38static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \
39 struct edac_mce_attr *attr, \
40 const char *data, size_t count)\
41{ \
42 int ret = 0; \
43 unsigned long value; \
44 \
45 ret = strict_strtoul(data, 16, &value); \
46 if (ret < 0) \
47 printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \
48 \
49 i_mce.reg = value; \
50 \
51 return count; \
52}
53
54MCE_INJECT_STORE(status);
55MCE_INJECT_STORE(misc);
56MCE_INJECT_STORE(addr);
57
58#define MCE_INJECT_SHOW(reg) \
59static ssize_t edac_inject_##reg##_show(struct kobject *kobj, \
60 struct edac_mce_attr *attr, \
61 char *buf) \
62{ \
63 return sprintf(buf, "0x%016llx\n", i_mce.reg); \
64}
65
66MCE_INJECT_SHOW(status);
67MCE_INJECT_SHOW(misc);
68MCE_INJECT_SHOW(addr);
69
70EDAC_MCE_ATTR(status, 0644, edac_inject_status_show, edac_inject_status_store);
71EDAC_MCE_ATTR(misc, 0644, edac_inject_misc_show, edac_inject_misc_store);
72EDAC_MCE_ATTR(addr, 0644, edac_inject_addr_show, edac_inject_addr_store);
73
74/*
75 * This denotes into which bank we're injecting and triggers
76 * the injection, at the same time.
77 */
78static ssize_t edac_inject_bank_store(struct kobject *kobj,
79 struct edac_mce_attr *attr,
80 const char *data, size_t count)
81{
82 int ret = 0;
83 unsigned long value;
84
85 ret = strict_strtoul(data, 10, &value);
86 if (ret < 0) {
87 printk(KERN_ERR "Invalid bank value!\n");
88 return -EINVAL;
89 }
90
91 if (value > 5) {
92 printk(KERN_ERR "Non-existant MCE bank: %lu\n", value);
93 return -EINVAL;
94 }
95
96 i_mce.bank = value;
97
98 amd_decode_mce(NULL, 0, &i_mce);
99
100 return count;
101}
102
103static ssize_t edac_inject_bank_show(struct kobject *kobj,
104 struct edac_mce_attr *attr, char *buf)
105{
106 return sprintf(buf, "%d\n", i_mce.bank);
107}
108
109EDAC_MCE_ATTR(bank, 0644, edac_inject_bank_show, edac_inject_bank_store);
110
111static struct edac_mce_attr *sysfs_attrs[] = { &mce_attr_status, &mce_attr_misc,
112 &mce_attr_addr, &mce_attr_bank
113};
114
115static int __init edac_init_mce_inject(void)
116{
117 struct sysdev_class *edac_class = NULL;
118 int i, err = 0;
119
120 edac_class = edac_get_sysfs_class();
121 if (!edac_class)
122 return -EINVAL;
123
124 mce_kobj = kobject_create_and_add("mce", &edac_class->kset.kobj);
125 if (!mce_kobj) {
126 printk(KERN_ERR "Error creating a mce kset.\n");
127 err = -ENOMEM;
128 goto err_mce_kobj;
129 }
130
131 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) {
132 err = sysfs_create_file(mce_kobj, &sysfs_attrs[i]->attr);
133 if (err) {
134 printk(KERN_ERR "Error creating %s in sysfs.\n",
135 sysfs_attrs[i]->attr.name);
136 goto err_sysfs_create;
137 }
138 }
139 return 0;
140
141err_sysfs_create:
142 while (i-- >= 0)
143 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
144
145 kobject_del(mce_kobj);
146
147err_mce_kobj:
148 edac_put_sysfs_class();
149
150 return err;
151}
152
153static void __exit edac_exit_mce_inject(void)
154{
155 int i;
156
157 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++)
158 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
159
160 kobject_del(mce_kobj);
161
162 edac_put_sysfs_class();
163}
164
165module_init(edac_init_mce_inject);
166module_exit(edac_exit_mce_inject);
167
168MODULE_LICENSE("GPL");
169MODULE_AUTHOR("Borislav Petkov <borislav.petkov@amd.com>");
170MODULE_AUTHOR("AMD Inc.");
171MODULE_DESCRIPTION("MCE injection facility for testing MCE decoding");
diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
index be29b0bb2471..9dcb17d51aee 100644
--- a/drivers/firewire/ohci.c
+++ b/drivers/firewire/ohci.c
@@ -263,6 +263,7 @@ static const struct {
263 {PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_FW, QUIRK_NO_MSI}, 263 {PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB38X_FW, QUIRK_NO_MSI},
264 {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 264 {PCI_VENDOR_ID_NEC, PCI_ANY_ID, QUIRK_CYCLE_TIMER},
265 {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER}, 265 {PCI_VENDOR_ID_VIA, PCI_ANY_ID, QUIRK_CYCLE_TIMER},
266 {PCI_VENDOR_ID_RICOH, PCI_ANY_ID, QUIRK_CYCLE_TIMER},
266 {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS}, 267 {PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_FW, QUIRK_BE_HEADERS},
267}; 268};
268 269
@@ -2839,7 +2840,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
2839 const struct pci_device_id *ent) 2840 const struct pci_device_id *ent)
2840{ 2841{
2841 struct fw_ohci *ohci; 2842 struct fw_ohci *ohci;
2842 u32 bus_options, max_receive, link_speed, version, link_enh; 2843 u32 bus_options, max_receive, link_speed, version;
2843 u64 guid; 2844 u64 guid;
2844 int i, err, n_ir, n_it; 2845 int i, err, n_ir, n_it;
2845 size_t size; 2846 size_t size;
@@ -2893,23 +2894,6 @@ static int __devinit pci_probe(struct pci_dev *dev,
2893 if (param_quirks) 2894 if (param_quirks)
2894 ohci->quirks = param_quirks; 2895 ohci->quirks = param_quirks;
2895 2896
2896 /* TI OHCI-Lynx and compatible: set recommended configuration bits. */
2897 if (dev->vendor == PCI_VENDOR_ID_TI) {
2898 pci_read_config_dword(dev, PCI_CFG_TI_LinkEnh, &link_enh);
2899
2900 /* adjust latency of ATx FIFO: use 1.7 KB threshold */
2901 link_enh &= ~TI_LinkEnh_atx_thresh_mask;
2902 link_enh |= TI_LinkEnh_atx_thresh_1_7K;
2903
2904 /* use priority arbitration for asynchronous responses */
2905 link_enh |= TI_LinkEnh_enab_unfair;
2906
2907 /* required for aPhyEnhanceEnable to work */
2908 link_enh |= TI_LinkEnh_enab_accel;
2909
2910 pci_write_config_dword(dev, PCI_CFG_TI_LinkEnh, link_enh);
2911 }
2912
2913 ar_context_init(&ohci->ar_request_ctx, ohci, 2897 ar_context_init(&ohci->ar_request_ctx, ohci,
2914 OHCI1394_AsReqRcvContextControlSet); 2898 OHCI1394_AsReqRcvContextControlSet);
2915 2899
diff --git a/drivers/firewire/ohci.h b/drivers/firewire/ohci.h
index 0e6c5a466908..ef5e7336da68 100644
--- a/drivers/firewire/ohci.h
+++ b/drivers/firewire/ohci.h
@@ -155,12 +155,4 @@
155 155
156#define OHCI1394_phy_tcode 0xe 156#define OHCI1394_phy_tcode 0xe
157 157
158/* TI extensions */
159
160#define PCI_CFG_TI_LinkEnh 0xf4
161#define TI_LinkEnh_enab_accel 0x00000002
162#define TI_LinkEnh_enab_unfair 0x00000080
163#define TI_LinkEnh_atx_thresh_mask 0x00003000
164#define TI_LinkEnh_atx_thresh_1_7K 0x00001000
165
166#endif /* _FIREWIRE_OHCI_H */ 158#endif /* _FIREWIRE_OHCI_H */
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index 280c9b5ad9e3..88a3ae6cd023 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -125,7 +125,7 @@ config ISCSI_IBFT_FIND
125config ISCSI_IBFT 125config ISCSI_IBFT
126 tristate "iSCSI Boot Firmware Table Attributes module" 126 tristate "iSCSI Boot Firmware Table Attributes module"
127 select ISCSI_BOOT_SYSFS 127 select ISCSI_BOOT_SYSFS
128 depends on ISCSI_IBFT_FIND && SCSI 128 depends on ISCSI_IBFT_FIND && SCSI && SCSI_LOWLEVEL
129 default n 129 default n
130 help 130 help
131 This option enables support for detection and exposing of iSCSI 131 This option enables support for detection and exposing of iSCSI
diff --git a/drivers/gpio/tc35892-gpio.c b/drivers/gpio/tc35892-gpio.c
index 1be6288780de..7e10c935a047 100644
--- a/drivers/gpio/tc35892-gpio.c
+++ b/drivers/gpio/tc35892-gpio.c
@@ -322,6 +322,9 @@ static int __devinit tc35892_gpio_probe(struct platform_device *pdev)
322 goto out_freeirq; 322 goto out_freeirq;
323 } 323 }
324 324
325 if (pdata->setup)
326 pdata->setup(tc35892, tc35892_gpio->chip.base);
327
325 platform_set_drvdata(pdev, tc35892_gpio); 328 platform_set_drvdata(pdev, tc35892_gpio);
326 329
327 return 0; 330 return 0;
@@ -338,9 +341,14 @@ out_free:
338static int __devexit tc35892_gpio_remove(struct platform_device *pdev) 341static int __devexit tc35892_gpio_remove(struct platform_device *pdev)
339{ 342{
340 struct tc35892_gpio *tc35892_gpio = platform_get_drvdata(pdev); 343 struct tc35892_gpio *tc35892_gpio = platform_get_drvdata(pdev);
344 struct tc35892 *tc35892 = tc35892_gpio->tc35892;
345 struct tc35892_gpio_platform_data *pdata = tc35892->pdata->gpio;
341 int irq = platform_get_irq(pdev, 0); 346 int irq = platform_get_irq(pdev, 0);
342 int ret; 347 int ret;
343 348
349 if (pdata->remove)
350 pdata->remove(tc35892, tc35892_gpio->chip.base);
351
344 ret = gpiochip_remove(&tc35892_gpio->chip); 352 ret = gpiochip_remove(&tc35892_gpio->chip);
345 if (ret < 0) { 353 if (ret < 0) {
346 dev_err(tc35892_gpio->dev, 354 dev_err(tc35892_gpio->dev,
diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig
index 4cab0c6397e3..7af443672626 100644
--- a/drivers/gpu/drm/Kconfig
+++ b/drivers/gpu/drm/Kconfig
@@ -73,7 +73,8 @@ source "drivers/gpu/drm/radeon/Kconfig"
73 73
74config DRM_I810 74config DRM_I810
75 tristate "Intel I810" 75 tristate "Intel I810"
76 depends on DRM && AGP && AGP_INTEL 76 # BKL usage in order to avoid AB-BA deadlocks, may become BROKEN_ON_SMP
77 depends on DRM && AGP && AGP_INTEL && BKL
77 help 78 help
78 Choose this option if you have an Intel I810 graphics card. If M is 79 Choose this option if you have an Intel I810 graphics card. If M is
79 selected, the module will be called i810. AGP support is required 80 selected, the module will be called i810. AGP support is required
@@ -86,6 +87,8 @@ choice
86 87
87config DRM_I830 88config DRM_I830
88 tristate "i830 driver" 89 tristate "i830 driver"
90 # BKL usage in order to avoid AB-BA deadlocks, i830 may get removed
91 depends on BKL
89 help 92 help
90 Choose this option if you have a system that has Intel 830M, 845G, 93 Choose this option if you have a system that has Intel 830M, 845G,
91 852GM, 855GM or 865G integrated graphics. If M is selected, the 94 852GM, 855GM or 865G integrated graphics. If M is selected, the
diff --git a/drivers/gpu/drm/drm_buffer.c b/drivers/gpu/drm/drm_buffer.c
index 55d03ed05000..529a0dbe9fc6 100644
--- a/drivers/gpu/drm/drm_buffer.c
+++ b/drivers/gpu/drm/drm_buffer.c
@@ -98,8 +98,8 @@ EXPORT_SYMBOL(drm_buffer_alloc);
98 * user_data: A pointer the data that is copied to the buffer. 98 * user_data: A pointer the data that is copied to the buffer.
99 * size: The Number of bytes to copy. 99 * size: The Number of bytes to copy.
100 */ 100 */
101extern int drm_buffer_copy_from_user(struct drm_buffer *buf, 101int drm_buffer_copy_from_user(struct drm_buffer *buf,
102 void __user *user_data, int size) 102 void __user *user_data, int size)
103{ 103{
104 int nr_pages = size / PAGE_SIZE + 1; 104 int nr_pages = size / PAGE_SIZE + 1;
105 int idx; 105 int idx;
@@ -163,7 +163,7 @@ void *drm_buffer_read_object(struct drm_buffer *buf,
163{ 163{
164 int idx = drm_buffer_index(buf); 164 int idx = drm_buffer_index(buf);
165 int page = drm_buffer_page(buf); 165 int page = drm_buffer_page(buf);
166 void *obj = 0; 166 void *obj = NULL;
167 167
168 if (idx + objsize <= PAGE_SIZE) { 168 if (idx + objsize <= PAGE_SIZE) {
169 obj = &buf->data[page][idx]; 169 obj = &buf->data[page][idx];
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index d2ab01e90a96..dcbeb98f195a 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -103,8 +103,8 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector,
103 if (connector->funcs->force) 103 if (connector->funcs->force)
104 connector->funcs->force(connector); 104 connector->funcs->force(connector);
105 } else { 105 } else {
106 connector->status = connector->funcs->detect(connector); 106 connector->status = connector->funcs->detect(connector, true);
107 drm_helper_hpd_irq_event(dev); 107 drm_kms_helper_poll_enable(dev);
108 } 108 }
109 109
110 if (connector->status == connector_status_disconnected) { 110 if (connector->status == connector_status_disconnected) {
@@ -637,13 +637,13 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
637 mode_changed = true; 637 mode_changed = true;
638 638
639 if (mode_changed) { 639 if (mode_changed) {
640 old_fb = set->crtc->fb;
641 set->crtc->fb = set->fb;
642 set->crtc->enabled = (set->mode != NULL); 640 set->crtc->enabled = (set->mode != NULL);
643 if (set->mode != NULL) { 641 if (set->mode != NULL) {
644 DRM_DEBUG_KMS("attempting to set mode from" 642 DRM_DEBUG_KMS("attempting to set mode from"
645 " userspace\n"); 643 " userspace\n");
646 drm_mode_debug_printmodeline(set->mode); 644 drm_mode_debug_printmodeline(set->mode);
645 old_fb = set->crtc->fb;
646 set->crtc->fb = set->fb;
647 if (!drm_crtc_helper_set_mode(set->crtc, set->mode, 647 if (!drm_crtc_helper_set_mode(set->crtc, set->mode,
648 set->x, set->y, 648 set->x, set->y,
649 old_fb)) { 649 old_fb)) {
@@ -866,7 +866,7 @@ static void output_poll_execute(struct work_struct *work)
866 !(connector->polled & DRM_CONNECTOR_POLL_HPD)) 866 !(connector->polled & DRM_CONNECTOR_POLL_HPD))
867 continue; 867 continue;
868 868
869 status = connector->funcs->detect(connector); 869 status = connector->funcs->detect(connector, false);
870 if (old_status != status) 870 if (old_status != status)
871 changed = true; 871 changed = true;
872 } 872 }
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index bf92d07510df..5663d2719063 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -148,7 +148,7 @@ int drm_gem_object_init(struct drm_device *dev,
148 return -ENOMEM; 148 return -ENOMEM;
149 149
150 kref_init(&obj->refcount); 150 kref_init(&obj->refcount);
151 kref_init(&obj->handlecount); 151 atomic_set(&obj->handle_count, 0);
152 obj->size = size; 152 obj->size = size;
153 153
154 atomic_inc(&dev->object_count); 154 atomic_inc(&dev->object_count);
@@ -462,28 +462,6 @@ drm_gem_object_free(struct kref *kref)
462} 462}
463EXPORT_SYMBOL(drm_gem_object_free); 463EXPORT_SYMBOL(drm_gem_object_free);
464 464
465/**
466 * Called after the last reference to the object has been lost.
467 * Must be called without holding struct_mutex
468 *
469 * Frees the object
470 */
471void
472drm_gem_object_free_unlocked(struct kref *kref)
473{
474 struct drm_gem_object *obj = (struct drm_gem_object *) kref;
475 struct drm_device *dev = obj->dev;
476
477 if (dev->driver->gem_free_object_unlocked != NULL)
478 dev->driver->gem_free_object_unlocked(obj);
479 else if (dev->driver->gem_free_object != NULL) {
480 mutex_lock(&dev->struct_mutex);
481 dev->driver->gem_free_object(obj);
482 mutex_unlock(&dev->struct_mutex);
483 }
484}
485EXPORT_SYMBOL(drm_gem_object_free_unlocked);
486
487static void drm_gem_object_ref_bug(struct kref *list_kref) 465static void drm_gem_object_ref_bug(struct kref *list_kref)
488{ 466{
489 BUG(); 467 BUG();
@@ -496,12 +474,8 @@ static void drm_gem_object_ref_bug(struct kref *list_kref)
496 * called before drm_gem_object_free or we'll be touching 474 * called before drm_gem_object_free or we'll be touching
497 * freed memory 475 * freed memory
498 */ 476 */
499void 477void drm_gem_object_handle_free(struct drm_gem_object *obj)
500drm_gem_object_handle_free(struct kref *kref)
501{ 478{
502 struct drm_gem_object *obj = container_of(kref,
503 struct drm_gem_object,
504 handlecount);
505 struct drm_device *dev = obj->dev; 479 struct drm_device *dev = obj->dev;
506 480
507 /* Remove any name for this object */ 481 /* Remove any name for this object */
@@ -528,6 +502,10 @@ void drm_gem_vm_open(struct vm_area_struct *vma)
528 struct drm_gem_object *obj = vma->vm_private_data; 502 struct drm_gem_object *obj = vma->vm_private_data;
529 503
530 drm_gem_object_reference(obj); 504 drm_gem_object_reference(obj);
505
506 mutex_lock(&obj->dev->struct_mutex);
507 drm_vm_open_locked(vma);
508 mutex_unlock(&obj->dev->struct_mutex);
531} 509}
532EXPORT_SYMBOL(drm_gem_vm_open); 510EXPORT_SYMBOL(drm_gem_vm_open);
533 511
@@ -535,7 +513,10 @@ void drm_gem_vm_close(struct vm_area_struct *vma)
535{ 513{
536 struct drm_gem_object *obj = vma->vm_private_data; 514 struct drm_gem_object *obj = vma->vm_private_data;
537 515
538 drm_gem_object_unreference_unlocked(obj); 516 mutex_lock(&obj->dev->struct_mutex);
517 drm_vm_close_locked(vma);
518 drm_gem_object_unreference(obj);
519 mutex_unlock(&obj->dev->struct_mutex);
539} 520}
540EXPORT_SYMBOL(drm_gem_vm_close); 521EXPORT_SYMBOL(drm_gem_vm_close);
541 522
diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
index 2ef2c7827243..974e970ce3f8 100644
--- a/drivers/gpu/drm/drm_info.c
+++ b/drivers/gpu/drm/drm_info.c
@@ -255,7 +255,7 @@ int drm_gem_one_name_info(int id, void *ptr, void *data)
255 255
256 seq_printf(m, "%6d %8zd %7d %8d\n", 256 seq_printf(m, "%6d %8zd %7d %8d\n",
257 obj->name, obj->size, 257 obj->name, obj->size,
258 atomic_read(&obj->handlecount.refcount), 258 atomic_read(&obj->handle_count),
259 atomic_read(&obj->refcount.refcount)); 259 atomic_read(&obj->refcount.refcount));
260 return 0; 260 return 0;
261} 261}
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index e20f78b542a7..f5bd9e590c80 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -164,6 +164,8 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
164 dev->hose = pdev->sysdata; 164 dev->hose = pdev->sysdata;
165#endif 165#endif
166 166
167 mutex_lock(&drm_global_mutex);
168
167 if ((ret = drm_fill_in_dev(dev, ent, driver))) { 169 if ((ret = drm_fill_in_dev(dev, ent, driver))) {
168 printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); 170 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
169 goto err_g2; 171 goto err_g2;
@@ -199,6 +201,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
199 driver->name, driver->major, driver->minor, driver->patchlevel, 201 driver->name, driver->major, driver->minor, driver->patchlevel,
200 driver->date, pci_name(pdev), dev->primary->index); 202 driver->date, pci_name(pdev), dev->primary->index);
201 203
204 mutex_unlock(&drm_global_mutex);
202 return 0; 205 return 0;
203 206
204err_g4: 207err_g4:
@@ -210,6 +213,7 @@ err_g2:
210 pci_disable_device(pdev); 213 pci_disable_device(pdev);
211err_g1: 214err_g1:
212 kfree(dev); 215 kfree(dev);
216 mutex_unlock(&drm_global_mutex);
213 return ret; 217 return ret;
214} 218}
215EXPORT_SYMBOL(drm_get_pci_dev); 219EXPORT_SYMBOL(drm_get_pci_dev);
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index 460e9a3afa8d..92d1d0fb7b75 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -53,6 +53,8 @@ int drm_get_platform_dev(struct platform_device *platdev,
53 dev->platformdev = platdev; 53 dev->platformdev = platdev;
54 dev->dev = &platdev->dev; 54 dev->dev = &platdev->dev;
55 55
56 mutex_lock(&drm_global_mutex);
57
56 ret = drm_fill_in_dev(dev, NULL, driver); 58 ret = drm_fill_in_dev(dev, NULL, driver);
57 59
58 if (ret) { 60 if (ret) {
@@ -87,6 +89,8 @@ int drm_get_platform_dev(struct platform_device *platdev,
87 89
88 list_add_tail(&dev->driver_item, &driver->device_list); 90 list_add_tail(&dev->driver_item, &driver->device_list);
89 91
92 mutex_unlock(&drm_global_mutex);
93
90 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", 94 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
91 driver->name, driver->major, driver->minor, driver->patchlevel, 95 driver->name, driver->major, driver->minor, driver->patchlevel,
92 driver->date, dev->primary->index); 96 driver->date, dev->primary->index);
@@ -100,6 +104,7 @@ err_g2:
100 drm_put_minor(&dev->control); 104 drm_put_minor(&dev->control);
101err_g1: 105err_g1:
102 kfree(dev); 106 kfree(dev);
107 mutex_unlock(&drm_global_mutex);
103 return ret; 108 return ret;
104} 109}
105EXPORT_SYMBOL(drm_get_platform_dev); 110EXPORT_SYMBOL(drm_get_platform_dev);
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 86118a742231..85da4c40694c 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -159,7 +159,7 @@ static ssize_t status_show(struct device *device,
159 struct drm_connector *connector = to_drm_connector(device); 159 struct drm_connector *connector = to_drm_connector(device);
160 enum drm_connector_status status; 160 enum drm_connector_status status;
161 161
162 status = connector->funcs->detect(connector); 162 status = connector->funcs->detect(connector, true);
163 return snprintf(buf, PAGE_SIZE, "%s\n", 163 return snprintf(buf, PAGE_SIZE, "%s\n",
164 drm_get_connector_status_name(status)); 164 drm_get_connector_status_name(status));
165} 165}
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
index fda67468e603..5df450683aab 100644
--- a/drivers/gpu/drm/drm_vm.c
+++ b/drivers/gpu/drm/drm_vm.c
@@ -433,15 +433,7 @@ static void drm_vm_open(struct vm_area_struct *vma)
433 mutex_unlock(&dev->struct_mutex); 433 mutex_unlock(&dev->struct_mutex);
434} 434}
435 435
436/** 436void drm_vm_close_locked(struct vm_area_struct *vma)
437 * \c close method for all virtual memory types.
438 *
439 * \param vma virtual memory area.
440 *
441 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
442 * free it.
443 */
444static void drm_vm_close(struct vm_area_struct *vma)
445{ 437{
446 struct drm_file *priv = vma->vm_file->private_data; 438 struct drm_file *priv = vma->vm_file->private_data;
447 struct drm_device *dev = priv->minor->dev; 439 struct drm_device *dev = priv->minor->dev;
@@ -451,7 +443,6 @@ static void drm_vm_close(struct vm_area_struct *vma)
451 vma->vm_start, vma->vm_end - vma->vm_start); 443 vma->vm_start, vma->vm_end - vma->vm_start);
452 atomic_dec(&dev->vma_count); 444 atomic_dec(&dev->vma_count);
453 445
454 mutex_lock(&dev->struct_mutex);
455 list_for_each_entry_safe(pt, temp, &dev->vmalist, head) { 446 list_for_each_entry_safe(pt, temp, &dev->vmalist, head) {
456 if (pt->vma == vma) { 447 if (pt->vma == vma) {
457 list_del(&pt->head); 448 list_del(&pt->head);
@@ -459,6 +450,23 @@ static void drm_vm_close(struct vm_area_struct *vma)
459 break; 450 break;
460 } 451 }
461 } 452 }
453}
454
455/**
456 * \c close method for all virtual memory types.
457 *
458 * \param vma virtual memory area.
459 *
460 * Search the \p vma private data entry in drm_device::vmalist, unlink it, and
461 * free it.
462 */
463static void drm_vm_close(struct vm_area_struct *vma)
464{
465 struct drm_file *priv = vma->vm_file->private_data;
466 struct drm_device *dev = priv->minor->dev;
467
468 mutex_lock(&dev->struct_mutex);
469 drm_vm_close_locked(vma);
462 mutex_unlock(&dev->struct_mutex); 470 mutex_unlock(&dev->struct_mutex);
463} 471}
464 472
diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
index 00f1bdaa65cd..ff33e53bbbf8 100644
--- a/drivers/gpu/drm/i810/i810_dma.c
+++ b/drivers/gpu/drm/i810/i810_dma.c
@@ -116,7 +116,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
116static const struct file_operations i810_buffer_fops = { 116static const struct file_operations i810_buffer_fops = {
117 .open = drm_open, 117 .open = drm_open,
118 .release = drm_release, 118 .release = drm_release,
119 .unlocked_ioctl = drm_ioctl, 119 .unlocked_ioctl = i810_ioctl,
120 .mmap = i810_mmap_buffers, 120 .mmap = i810_mmap_buffers,
121 .fasync = drm_fasync, 121 .fasync = drm_fasync,
122 .llseek = noop_llseek, 122 .llseek = noop_llseek,
diff --git a/drivers/gpu/drm/i830/i830_dma.c b/drivers/gpu/drm/i830/i830_dma.c
index 5c6eb65f4e51..ca6f31ff0eec 100644
--- a/drivers/gpu/drm/i830/i830_dma.c
+++ b/drivers/gpu/drm/i830/i830_dma.c
@@ -118,7 +118,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
118static const struct file_operations i830_buffer_fops = { 118static const struct file_operations i830_buffer_fops = {
119 .open = drm_open, 119 .open = drm_open,
120 .release = drm_release, 120 .release = drm_release,
121 .unlocked_ioctl = drm_ioctl, 121 .unlocked_ioctl = i830_ioctl,
122 .mmap = i830_mmap_buffers, 122 .mmap = i830_mmap_buffers,
123 .fasync = drm_fasync, 123 .fasync = drm_fasync,
124 .llseek = noop_llseek, 124 .llseek = noop_llseek,
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 9d67b4853030..2dd2c93ebfa3 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1787,9 +1787,9 @@ unsigned long i915_chipset_val(struct drm_i915_private *dev_priv)
1787 } 1787 }
1788 } 1788 }
1789 1789
1790 div_u64(diff, diff1); 1790 diff = div_u64(diff, diff1);
1791 ret = ((m * diff) + c); 1791 ret = ((m * diff) + c);
1792 div_u64(ret, 10); 1792 ret = div_u64(ret, 10);
1793 1793
1794 dev_priv->last_count1 = total_count; 1794 dev_priv->last_count1 = total_count;
1795 dev_priv->last_time1 = now; 1795 dev_priv->last_time1 = now;
@@ -1858,7 +1858,7 @@ void i915_update_gfx_val(struct drm_i915_private *dev_priv)
1858 1858
1859 /* More magic constants... */ 1859 /* More magic constants... */
1860 diff = diff * 1181; 1860 diff = diff * 1181;
1861 div_u64(diff, diffms * 10); 1861 diff = div_u64(diff, diffms * 10);
1862 dev_priv->gfx_power = diff; 1862 dev_priv->gfx_power = diff;
1863} 1863}
1864 1864
@@ -2231,6 +2231,9 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
2231 dev_priv->mchdev_lock = &mchdev_lock; 2231 dev_priv->mchdev_lock = &mchdev_lock;
2232 spin_unlock(&mchdev_lock); 2232 spin_unlock(&mchdev_lock);
2233 2233
2234 /* XXX Prevent module unload due to memory corruption bugs. */
2235 __module_get(THIS_MODULE);
2236
2234 return 0; 2237 return 0;
2235 2238
2236out_workqueue_free: 2239out_workqueue_free:
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index a6fdb481500c..895ab896e336 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -170,6 +170,7 @@ static const struct pci_device_id pciidlist[] = { /* aka */
170 INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */ 170 INTEL_VGA_DEVICE(0x2e22, &intel_g45_info), /* G45_G */
171 INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */ 171 INTEL_VGA_DEVICE(0x2e32, &intel_g45_info), /* G41_G */
172 INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */ 172 INTEL_VGA_DEVICE(0x2e42, &intel_g45_info), /* B43_G */
173 INTEL_VGA_DEVICE(0x2e92, &intel_g45_info), /* B43_G.1 */
173 INTEL_VGA_DEVICE(0xa001, &intel_pineview_info), 174 INTEL_VGA_DEVICE(0xa001, &intel_pineview_info),
174 INTEL_VGA_DEVICE(0xa011, &intel_pineview_info), 175 INTEL_VGA_DEVICE(0xa011, &intel_pineview_info),
175 INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info), 176 INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info),
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 16fca1d1799a..90b1d6753b9d 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -136,14 +136,12 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data,
136 return -ENOMEM; 136 return -ENOMEM;
137 137
138 ret = drm_gem_handle_create(file_priv, obj, &handle); 138 ret = drm_gem_handle_create(file_priv, obj, &handle);
139 /* drop reference from allocate - handle holds it now */
140 drm_gem_object_unreference_unlocked(obj);
139 if (ret) { 141 if (ret) {
140 drm_gem_object_unreference_unlocked(obj);
141 return ret; 142 return ret;
142 } 143 }
143 144
144 /* Sink the floating reference from kref_init(handlecount) */
145 drm_gem_object_handle_unreference_unlocked(obj);
146
147 args->handle = handle; 145 args->handle = handle;
148 return 0; 146 return 0;
149} 147}
@@ -471,14 +469,17 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
471 return -ENOENT; 469 return -ENOENT;
472 obj_priv = to_intel_bo(obj); 470 obj_priv = to_intel_bo(obj);
473 471
474 /* Bounds check source. 472 /* Bounds check source. */
475 * 473 if (args->offset > obj->size || args->size > obj->size - args->offset) {
476 * XXX: This could use review for overflow issues... 474 ret = -EINVAL;
477 */ 475 goto err;
478 if (args->offset > obj->size || args->size > obj->size || 476 }
479 args->offset + args->size > obj->size) { 477
480 drm_gem_object_unreference_unlocked(obj); 478 if (!access_ok(VERIFY_WRITE,
481 return -EINVAL; 479 (char __user *)(uintptr_t)args->data_ptr,
480 args->size)) {
481 ret = -EFAULT;
482 goto err;
482 } 483 }
483 484
484 if (i915_gem_object_needs_bit17_swizzle(obj)) { 485 if (i915_gem_object_needs_bit17_swizzle(obj)) {
@@ -490,8 +491,8 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
490 file_priv); 491 file_priv);
491 } 492 }
492 493
494err:
493 drm_gem_object_unreference_unlocked(obj); 495 drm_gem_object_unreference_unlocked(obj);
494
495 return ret; 496 return ret;
496} 497}
497 498
@@ -580,8 +581,6 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev, struct drm_gem_object *obj,
580 581
581 user_data = (char __user *) (uintptr_t) args->data_ptr; 582 user_data = (char __user *) (uintptr_t) args->data_ptr;
582 remain = args->size; 583 remain = args->size;
583 if (!access_ok(VERIFY_READ, user_data, remain))
584 return -EFAULT;
585 584
586 585
587 mutex_lock(&dev->struct_mutex); 586 mutex_lock(&dev->struct_mutex);
@@ -934,14 +933,17 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
934 return -ENOENT; 933 return -ENOENT;
935 obj_priv = to_intel_bo(obj); 934 obj_priv = to_intel_bo(obj);
936 935
937 /* Bounds check destination. 936 /* Bounds check destination. */
938 * 937 if (args->offset > obj->size || args->size > obj->size - args->offset) {
939 * XXX: This could use review for overflow issues... 938 ret = -EINVAL;
940 */ 939 goto err;
941 if (args->offset > obj->size || args->size > obj->size || 940 }
942 args->offset + args->size > obj->size) { 941
943 drm_gem_object_unreference_unlocked(obj); 942 if (!access_ok(VERIFY_READ,
944 return -EINVAL; 943 (char __user *)(uintptr_t)args->data_ptr,
944 args->size)) {
945 ret = -EFAULT;
946 goto err;
945 } 947 }
946 948
947 /* We can only do the GTT pwrite on untiled buffers, as otherwise 949 /* We can only do the GTT pwrite on untiled buffers, as otherwise
@@ -975,8 +977,8 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
975 DRM_INFO("pwrite failed %d\n", ret); 977 DRM_INFO("pwrite failed %d\n", ret);
976#endif 978#endif
977 979
980err:
978 drm_gem_object_unreference_unlocked(obj); 981 drm_gem_object_unreference_unlocked(obj);
979
980 return ret; 982 return ret;
981} 983}
982 984
@@ -2351,14 +2353,21 @@ i915_gem_object_get_fence_reg(struct drm_gem_object *obj)
2351 2353
2352 reg->obj = obj; 2354 reg->obj = obj;
2353 2355
2354 if (IS_GEN6(dev)) 2356 switch (INTEL_INFO(dev)->gen) {
2357 case 6:
2355 sandybridge_write_fence_reg(reg); 2358 sandybridge_write_fence_reg(reg);
2356 else if (IS_I965G(dev)) 2359 break;
2360 case 5:
2361 case 4:
2357 i965_write_fence_reg(reg); 2362 i965_write_fence_reg(reg);
2358 else if (IS_I9XX(dev)) 2363 break;
2364 case 3:
2359 i915_write_fence_reg(reg); 2365 i915_write_fence_reg(reg);
2360 else 2366 break;
2367 case 2:
2361 i830_write_fence_reg(reg); 2368 i830_write_fence_reg(reg);
2369 break;
2370 }
2362 2371
2363 trace_i915_gem_object_get_fence(obj, obj_priv->fence_reg, 2372 trace_i915_gem_object_get_fence(obj, obj_priv->fence_reg,
2364 obj_priv->tiling_mode); 2373 obj_priv->tiling_mode);
@@ -2381,22 +2390,26 @@ i915_gem_clear_fence_reg(struct drm_gem_object *obj)
2381 struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); 2390 struct drm_i915_gem_object *obj_priv = to_intel_bo(obj);
2382 struct drm_i915_fence_reg *reg = 2391 struct drm_i915_fence_reg *reg =
2383 &dev_priv->fence_regs[obj_priv->fence_reg]; 2392 &dev_priv->fence_regs[obj_priv->fence_reg];
2393 uint32_t fence_reg;
2384 2394
2385 if (IS_GEN6(dev)) { 2395 switch (INTEL_INFO(dev)->gen) {
2396 case 6:
2386 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + 2397 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 +
2387 (obj_priv->fence_reg * 8), 0); 2398 (obj_priv->fence_reg * 8), 0);
2388 } else if (IS_I965G(dev)) { 2399 break;
2400 case 5:
2401 case 4:
2389 I915_WRITE64(FENCE_REG_965_0 + (obj_priv->fence_reg * 8), 0); 2402 I915_WRITE64(FENCE_REG_965_0 + (obj_priv->fence_reg * 8), 0);
2390 } else { 2403 break;
2391 uint32_t fence_reg; 2404 case 3:
2392 2405 if (obj_priv->fence_reg >= 8)
2393 if (obj_priv->fence_reg < 8) 2406 fence_reg = FENCE_REG_945_8 + (obj_priv->fence_reg - 8) * 4;
2394 fence_reg = FENCE_REG_830_0 + obj_priv->fence_reg * 4;
2395 else 2407 else
2396 fence_reg = FENCE_REG_945_8 + (obj_priv->fence_reg - 2408 case 2:
2397 8) * 4; 2409 fence_reg = FENCE_REG_830_0 + obj_priv->fence_reg * 4;
2398 2410
2399 I915_WRITE(fence_reg, 0); 2411 I915_WRITE(fence_reg, 0);
2412 break;
2400 } 2413 }
2401 2414
2402 reg->obj = NULL; 2415 reg->obj = NULL;
@@ -3247,6 +3260,8 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj,
3247 (int) reloc->offset, 3260 (int) reloc->offset,
3248 reloc->read_domains, 3261 reloc->read_domains,
3249 reloc->write_domain); 3262 reloc->write_domain);
3263 drm_gem_object_unreference(target_obj);
3264 i915_gem_object_unpin(obj);
3250 return -EINVAL; 3265 return -EINVAL;
3251 } 3266 }
3252 if (reloc->write_domain & I915_GEM_DOMAIN_CPU || 3267 if (reloc->write_domain & I915_GEM_DOMAIN_CPU ||
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index 72cae3cccad8..5c428fa3e0b3 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -79,6 +79,7 @@ mark_free(struct drm_i915_gem_object *obj_priv,
79 struct list_head *unwind) 79 struct list_head *unwind)
80{ 80{
81 list_add(&obj_priv->evict_list, unwind); 81 list_add(&obj_priv->evict_list, unwind);
82 drm_gem_object_reference(&obj_priv->base);
82 return drm_mm_scan_add_block(obj_priv->gtt_space); 83 return drm_mm_scan_add_block(obj_priv->gtt_space);
83} 84}
84 85
@@ -92,7 +93,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size, unsigned alignmen
92{ 93{
93 drm_i915_private_t *dev_priv = dev->dev_private; 94 drm_i915_private_t *dev_priv = dev->dev_private;
94 struct list_head eviction_list, unwind_list; 95 struct list_head eviction_list, unwind_list;
95 struct drm_i915_gem_object *obj_priv, *tmp_obj_priv; 96 struct drm_i915_gem_object *obj_priv;
96 struct list_head *render_iter, *bsd_iter; 97 struct list_head *render_iter, *bsd_iter;
97 int ret = 0; 98 int ret = 0;
98 99
@@ -165,6 +166,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size, unsigned alignmen
165 list_for_each_entry(obj_priv, &unwind_list, evict_list) { 166 list_for_each_entry(obj_priv, &unwind_list, evict_list) {
166 ret = drm_mm_scan_remove_block(obj_priv->gtt_space); 167 ret = drm_mm_scan_remove_block(obj_priv->gtt_space);
167 BUG_ON(ret); 168 BUG_ON(ret);
169 drm_gem_object_unreference(&obj_priv->base);
168 } 170 }
169 171
170 /* We expect the caller to unpin, evict all and try again, or give up. 172 /* We expect the caller to unpin, evict all and try again, or give up.
@@ -173,36 +175,34 @@ i915_gem_evict_something(struct drm_device *dev, int min_size, unsigned alignmen
173 return -ENOSPC; 175 return -ENOSPC;
174 176
175found: 177found:
178 /* drm_mm doesn't allow any other other operations while
179 * scanning, therefore store to be evicted objects on a
180 * temporary list. */
176 INIT_LIST_HEAD(&eviction_list); 181 INIT_LIST_HEAD(&eviction_list);
177 list_for_each_entry_safe(obj_priv, tmp_obj_priv, 182 while (!list_empty(&unwind_list)) {
178 &unwind_list, evict_list) { 183 obj_priv = list_first_entry(&unwind_list,
184 struct drm_i915_gem_object,
185 evict_list);
179 if (drm_mm_scan_remove_block(obj_priv->gtt_space)) { 186 if (drm_mm_scan_remove_block(obj_priv->gtt_space)) {
180 /* drm_mm doesn't allow any other other operations while
181 * scanning, therefore store to be evicted objects on a
182 * temporary list. */
183 list_move(&obj_priv->evict_list, &eviction_list); 187 list_move(&obj_priv->evict_list, &eviction_list);
188 continue;
184 } 189 }
190 list_del(&obj_priv->evict_list);
191 drm_gem_object_unreference(&obj_priv->base);
185 } 192 }
186 193
187 /* Unbinding will emit any required flushes */ 194 /* Unbinding will emit any required flushes */
188 list_for_each_entry_safe(obj_priv, tmp_obj_priv, 195 while (!list_empty(&eviction_list)) {
189 &eviction_list, evict_list) { 196 obj_priv = list_first_entry(&eviction_list,
190#if WATCH_LRU 197 struct drm_i915_gem_object,
191 DRM_INFO("%s: evicting %p\n", __func__, obj); 198 evict_list);
192#endif 199 if (ret == 0)
193 ret = i915_gem_object_unbind(&obj_priv->base); 200 ret = i915_gem_object_unbind(&obj_priv->base);
194 if (ret) 201 list_del(&obj_priv->evict_list);
195 return ret; 202 drm_gem_object_unreference(&obj_priv->base);
196 } 203 }
197 204
198 /* The just created free hole should be on the top of the free stack 205 return ret;
199 * maintained by drm_mm, so this BUG_ON actually executes in O(1).
200 * Furthermore all accessed data has just recently been used, so it
201 * should be really fast, too. */
202 BUG_ON(!drm_mm_search_free(&dev_priv->mm.gtt_space, min_size,
203 alignment, 0));
204
205 return 0;
206} 206}
207 207
208int 208int
diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c
index 2c6b98f2440e..31f08581e93a 100644
--- a/drivers/gpu/drm/i915/i915_suspend.c
+++ b/drivers/gpu/drm/i915/i915_suspend.c
@@ -789,16 +789,25 @@ int i915_save_state(struct drm_device *dev)
789 dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2)); 789 dev_priv->saveSWF2[i] = I915_READ(SWF30 + (i << 2));
790 790
791 /* Fences */ 791 /* Fences */
792 if (IS_I965G(dev)) { 792 switch (INTEL_INFO(dev)->gen) {
793 case 6:
794 for (i = 0; i < 16; i++)
795 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
796 break;
797 case 5:
798 case 4:
793 for (i = 0; i < 16; i++) 799 for (i = 0; i < 16; i++)
794 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_965_0 + (i * 8)); 800 dev_priv->saveFENCE[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
795 } else { 801 break;
796 for (i = 0; i < 8; i++) 802 case 3:
797 dev_priv->saveFENCE[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
798
799 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) 803 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
800 for (i = 0; i < 8; i++) 804 for (i = 0; i < 8; i++)
801 dev_priv->saveFENCE[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4)); 805 dev_priv->saveFENCE[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
806 case 2:
807 for (i = 0; i < 8; i++)
808 dev_priv->saveFENCE[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
809 break;
810
802 } 811 }
803 812
804 return 0; 813 return 0;
@@ -815,15 +824,24 @@ int i915_restore_state(struct drm_device *dev)
815 I915_WRITE(HWS_PGA, dev_priv->saveHWS); 824 I915_WRITE(HWS_PGA, dev_priv->saveHWS);
816 825
817 /* Fences */ 826 /* Fences */
818 if (IS_I965G(dev)) { 827 switch (INTEL_INFO(dev)->gen) {
828 case 6:
829 for (i = 0; i < 16; i++)
830 I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (i * 8), dev_priv->saveFENCE[i]);
831 break;
832 case 5:
833 case 4:
819 for (i = 0; i < 16; i++) 834 for (i = 0; i < 16; i++)
820 I915_WRITE64(FENCE_REG_965_0 + (i * 8), dev_priv->saveFENCE[i]); 835 I915_WRITE64(FENCE_REG_965_0 + (i * 8), dev_priv->saveFENCE[i]);
821 } else { 836 break;
822 for (i = 0; i < 8; i++) 837 case 3:
823 I915_WRITE(FENCE_REG_830_0 + (i * 4), dev_priv->saveFENCE[i]); 838 case 2:
824 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) 839 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
825 for (i = 0; i < 8; i++) 840 for (i = 0; i < 8; i++)
826 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]); 841 I915_WRITE(FENCE_REG_945_8 + (i * 4), dev_priv->saveFENCE[i+8]);
842 for (i = 0; i < 8; i++)
843 I915_WRITE(FENCE_REG_830_0 + (i * 4), dev_priv->saveFENCE[i]);
844 break;
827 } 845 }
828 846
829 i915_restore_display(dev); 847 i915_restore_display(dev);
diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c
index 4b7735196cd5..197d4f32585a 100644
--- a/drivers/gpu/drm/i915/intel_crt.c
+++ b/drivers/gpu/drm/i915/intel_crt.c
@@ -188,7 +188,7 @@ static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector)
188 188
189 if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0, 189 if (wait_for((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) == 0,
190 1000, 1)) 190 1000, 1))
191 DRM_ERROR("timed out waiting for FORCE_TRIGGER"); 191 DRM_DEBUG_KMS("timed out waiting for FORCE_TRIGGER");
192 192
193 if (turn_off_dac) { 193 if (turn_off_dac) {
194 I915_WRITE(PCH_ADPA, temp); 194 I915_WRITE(PCH_ADPA, temp);
@@ -245,7 +245,7 @@ static bool intel_crt_detect_hotplug(struct drm_connector *connector)
245 if (wait_for((I915_READ(PORT_HOTPLUG_EN) & 245 if (wait_for((I915_READ(PORT_HOTPLUG_EN) &
246 CRT_HOTPLUG_FORCE_DETECT) == 0, 246 CRT_HOTPLUG_FORCE_DETECT) == 0,
247 1000, 1)) 247 1000, 1))
248 DRM_ERROR("timed out waiting for FORCE_DETECT to go off"); 248 DRM_DEBUG_KMS("timed out waiting for FORCE_DETECT to go off");
249 } 249 }
250 250
251 stat = I915_READ(PORT_HOTPLUG_STAT); 251 stat = I915_READ(PORT_HOTPLUG_STAT);
@@ -400,7 +400,8 @@ intel_crt_load_detect(struct drm_crtc *crtc, struct intel_encoder *intel_encoder
400 return status; 400 return status;
401} 401}
402 402
403static enum drm_connector_status intel_crt_detect(struct drm_connector *connector) 403static enum drm_connector_status
404intel_crt_detect(struct drm_connector *connector, bool force)
404{ 405{
405 struct drm_device *dev = connector->dev; 406 struct drm_device *dev = connector->dev;
406 struct drm_encoder *encoder = intel_attached_encoder(connector); 407 struct drm_encoder *encoder = intel_attached_encoder(connector);
@@ -419,6 +420,9 @@ static enum drm_connector_status intel_crt_detect(struct drm_connector *connecto
419 if (intel_crt_detect_ddc(encoder)) 420 if (intel_crt_detect_ddc(encoder))
420 return connector_status_connected; 421 return connector_status_connected;
421 422
423 if (!force)
424 return connector->status;
425
422 /* for pre-945g platforms use load detect */ 426 /* for pre-945g platforms use load detect */
423 if (encoder->crtc && encoder->crtc->enabled) { 427 if (encoder->crtc && encoder->crtc->enabled) {
424 status = intel_crt_load_detect(encoder->crtc, intel_encoder); 428 status = intel_crt_load_detect(encoder->crtc, intel_encoder);
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 19daead5b525..979228594599 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -1013,8 +1013,8 @@ void intel_wait_for_vblank(struct drm_device *dev, int pipe)
1013 DRM_DEBUG_KMS("vblank wait timed out\n"); 1013 DRM_DEBUG_KMS("vblank wait timed out\n");
1014} 1014}
1015 1015
1016/** 1016/*
1017 * intel_wait_for_vblank_off - wait for vblank after disabling a pipe 1017 * intel_wait_for_pipe_off - wait for pipe to turn off
1018 * @dev: drm device 1018 * @dev: drm device
1019 * @pipe: pipe to wait for 1019 * @pipe: pipe to wait for
1020 * 1020 *
@@ -1022,25 +1022,39 @@ void intel_wait_for_vblank(struct drm_device *dev, int pipe)
1022 * spinning on the vblank interrupt status bit, since we won't actually 1022 * spinning on the vblank interrupt status bit, since we won't actually
1023 * see an interrupt when the pipe is disabled. 1023 * see an interrupt when the pipe is disabled.
1024 * 1024 *
1025 * So this function waits for the display line value to settle (it 1025 * On Gen4 and above:
1026 * usually ends up stopping at the start of the next frame). 1026 * wait for the pipe register state bit to turn off
1027 *
1028 * Otherwise:
1029 * wait for the display line value to settle (it usually
1030 * ends up stopping at the start of the next frame).
1031 *
1027 */ 1032 */
1028void intel_wait_for_vblank_off(struct drm_device *dev, int pipe) 1033static void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
1029{ 1034{
1030 struct drm_i915_private *dev_priv = dev->dev_private; 1035 struct drm_i915_private *dev_priv = dev->dev_private;
1031 int pipedsl_reg = (pipe == 0 ? PIPEADSL : PIPEBDSL); 1036
1032 unsigned long timeout = jiffies + msecs_to_jiffies(100); 1037 if (INTEL_INFO(dev)->gen >= 4) {
1033 u32 last_line; 1038 int pipeconf_reg = (pipe == 0 ? PIPEACONF : PIPEBCONF);
1034 1039
1035 /* Wait for the display line to settle */ 1040 /* Wait for the Pipe State to go off */
1036 do { 1041 if (wait_for((I915_READ(pipeconf_reg) & I965_PIPECONF_ACTIVE) == 0,
1037 last_line = I915_READ(pipedsl_reg) & DSL_LINEMASK; 1042 100, 0))
1038 mdelay(5); 1043 DRM_DEBUG_KMS("pipe_off wait timed out\n");
1039 } while (((I915_READ(pipedsl_reg) & DSL_LINEMASK) != last_line) && 1044 } else {
1040 time_after(timeout, jiffies)); 1045 u32 last_line;
1041 1046 int pipedsl_reg = (pipe == 0 ? PIPEADSL : PIPEBDSL);
1042 if (time_after(jiffies, timeout)) 1047 unsigned long timeout = jiffies + msecs_to_jiffies(100);
1043 DRM_DEBUG_KMS("vblank wait timed out\n"); 1048
1049 /* Wait for the display line to settle */
1050 do {
1051 last_line = I915_READ(pipedsl_reg) & DSL_LINEMASK;
1052 mdelay(5);
1053 } while (((I915_READ(pipedsl_reg) & DSL_LINEMASK) != last_line) &&
1054 time_after(timeout, jiffies));
1055 if (time_after(jiffies, timeout))
1056 DRM_DEBUG_KMS("pipe_off wait timed out\n");
1057 }
1044} 1058}
1045 1059
1046/* Parameters have changed, update FBC info */ 1060/* Parameters have changed, update FBC info */
@@ -2328,13 +2342,13 @@ static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
2328 I915_READ(dspbase_reg); 2342 I915_READ(dspbase_reg);
2329 } 2343 }
2330 2344
2331 /* Wait for vblank for the disable to take effect */
2332 intel_wait_for_vblank_off(dev, pipe);
2333
2334 /* Don't disable pipe A or pipe A PLLs if needed */ 2345 /* Don't disable pipe A or pipe A PLLs if needed */
2335 if (pipeconf_reg == PIPEACONF && 2346 if (pipeconf_reg == PIPEACONF &&
2336 (dev_priv->quirks & QUIRK_PIPEA_FORCE)) 2347 (dev_priv->quirks & QUIRK_PIPEA_FORCE)) {
2348 /* Wait for vblank for the disable to take effect */
2349 intel_wait_for_vblank(dev, pipe);
2337 goto skip_pipe_off; 2350 goto skip_pipe_off;
2351 }
2338 2352
2339 /* Next, disable display pipes */ 2353 /* Next, disable display pipes */
2340 temp = I915_READ(pipeconf_reg); 2354 temp = I915_READ(pipeconf_reg);
@@ -2343,8 +2357,8 @@ static void i9xx_crtc_dpms(struct drm_crtc *crtc, int mode)
2343 I915_READ(pipeconf_reg); 2357 I915_READ(pipeconf_reg);
2344 } 2358 }
2345 2359
2346 /* Wait for vblank for the disable to take effect. */ 2360 /* Wait for the pipe to turn off */
2347 intel_wait_for_vblank_off(dev, pipe); 2361 intel_wait_for_pipe_off(dev, pipe);
2348 2362
2349 temp = I915_READ(dpll_reg); 2363 temp = I915_READ(dpll_reg);
2350 if ((temp & DPLL_VCO_ENABLE) != 0) { 2364 if ((temp & DPLL_VCO_ENABLE) != 0) {
@@ -2463,11 +2477,19 @@ static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
2463 struct drm_display_mode *adjusted_mode) 2477 struct drm_display_mode *adjusted_mode)
2464{ 2478{
2465 struct drm_device *dev = crtc->dev; 2479 struct drm_device *dev = crtc->dev;
2480
2466 if (HAS_PCH_SPLIT(dev)) { 2481 if (HAS_PCH_SPLIT(dev)) {
2467 /* FDI link clock is fixed at 2.7G */ 2482 /* FDI link clock is fixed at 2.7G */
2468 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4) 2483 if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
2469 return false; 2484 return false;
2470 } 2485 }
2486
2487 /* XXX some encoders set the crtcinfo, others don't.
2488 * Obviously we need some form of conflict resolution here...
2489 */
2490 if (adjusted_mode->crtc_htotal == 0)
2491 drm_mode_set_crtcinfo(adjusted_mode, 0);
2492
2471 return true; 2493 return true;
2472} 2494}
2473 2495
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 51d142939a26..9ab8708ac6ba 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1138,18 +1138,14 @@ static bool
1138intel_dp_set_link_train(struct intel_dp *intel_dp, 1138intel_dp_set_link_train(struct intel_dp *intel_dp,
1139 uint32_t dp_reg_value, 1139 uint32_t dp_reg_value,
1140 uint8_t dp_train_pat, 1140 uint8_t dp_train_pat,
1141 uint8_t train_set[4], 1141 uint8_t train_set[4])
1142 bool first)
1143{ 1142{
1144 struct drm_device *dev = intel_dp->base.enc.dev; 1143 struct drm_device *dev = intel_dp->base.enc.dev;
1145 struct drm_i915_private *dev_priv = dev->dev_private; 1144 struct drm_i915_private *dev_priv = dev->dev_private;
1146 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.enc.crtc);
1147 int ret; 1145 int ret;
1148 1146
1149 I915_WRITE(intel_dp->output_reg, dp_reg_value); 1147 I915_WRITE(intel_dp->output_reg, dp_reg_value);
1150 POSTING_READ(intel_dp->output_reg); 1148 POSTING_READ(intel_dp->output_reg);
1151 if (first)
1152 intel_wait_for_vblank(dev, intel_crtc->pipe);
1153 1149
1154 intel_dp_aux_native_write_1(intel_dp, 1150 intel_dp_aux_native_write_1(intel_dp,
1155 DP_TRAINING_PATTERN_SET, 1151 DP_TRAINING_PATTERN_SET,
@@ -1174,10 +1170,15 @@ intel_dp_link_train(struct intel_dp *intel_dp)
1174 uint8_t voltage; 1170 uint8_t voltage;
1175 bool clock_recovery = false; 1171 bool clock_recovery = false;
1176 bool channel_eq = false; 1172 bool channel_eq = false;
1177 bool first = true;
1178 int tries; 1173 int tries;
1179 u32 reg; 1174 u32 reg;
1180 uint32_t DP = intel_dp->DP; 1175 uint32_t DP = intel_dp->DP;
1176 struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.enc.crtc);
1177
1178 /* Enable output, wait for it to become active */
1179 I915_WRITE(intel_dp->output_reg, intel_dp->DP);
1180 POSTING_READ(intel_dp->output_reg);
1181 intel_wait_for_vblank(dev, intel_crtc->pipe);
1181 1182
1182 /* Write the link configuration data */ 1183 /* Write the link configuration data */
1183 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET, 1184 intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
@@ -1210,9 +1211,8 @@ intel_dp_link_train(struct intel_dp *intel_dp)
1210 reg = DP | DP_LINK_TRAIN_PAT_1; 1211 reg = DP | DP_LINK_TRAIN_PAT_1;
1211 1212
1212 if (!intel_dp_set_link_train(intel_dp, reg, 1213 if (!intel_dp_set_link_train(intel_dp, reg,
1213 DP_TRAINING_PATTERN_1, train_set, first)) 1214 DP_TRAINING_PATTERN_1, train_set))
1214 break; 1215 break;
1215 first = false;
1216 /* Set training pattern 1 */ 1216 /* Set training pattern 1 */
1217 1217
1218 udelay(100); 1218 udelay(100);
@@ -1266,8 +1266,7 @@ intel_dp_link_train(struct intel_dp *intel_dp)
1266 1266
1267 /* channel eq pattern */ 1267 /* channel eq pattern */
1268 if (!intel_dp_set_link_train(intel_dp, reg, 1268 if (!intel_dp_set_link_train(intel_dp, reg,
1269 DP_TRAINING_PATTERN_2, train_set, 1269 DP_TRAINING_PATTERN_2, train_set))
1270 false))
1271 break; 1270 break;
1272 1271
1273 udelay(400); 1272 udelay(400);
@@ -1386,7 +1385,7 @@ ironlake_dp_detect(struct drm_connector *connector)
1386 * \return false if DP port is disconnected. 1385 * \return false if DP port is disconnected.
1387 */ 1386 */
1388static enum drm_connector_status 1387static enum drm_connector_status
1389intel_dp_detect(struct drm_connector *connector) 1388intel_dp_detect(struct drm_connector *connector, bool force)
1390{ 1389{
1391 struct drm_encoder *encoder = intel_attached_encoder(connector); 1390 struct drm_encoder *encoder = intel_attached_encoder(connector);
1392 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1391 struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index ad312ca6b3e5..8828b3ac6414 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -229,7 +229,6 @@ extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
229 struct drm_crtc *crtc); 229 struct drm_crtc *crtc);
230int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, 230int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
231 struct drm_file *file_priv); 231 struct drm_file *file_priv);
232extern void intel_wait_for_vblank_off(struct drm_device *dev, int pipe);
233extern void intel_wait_for_vblank(struct drm_device *dev, int pipe); 232extern void intel_wait_for_vblank(struct drm_device *dev, int pipe);
234extern struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe); 233extern struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe);
235extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder, 234extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder,
diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c
index a399f4b2c1c5..7c9ec1472d46 100644
--- a/drivers/gpu/drm/i915/intel_dvo.c
+++ b/drivers/gpu/drm/i915/intel_dvo.c
@@ -221,7 +221,8 @@ static void intel_dvo_mode_set(struct drm_encoder *encoder,
221 * 221 *
222 * Unimplemented. 222 * Unimplemented.
223 */ 223 */
224static enum drm_connector_status intel_dvo_detect(struct drm_connector *connector) 224static enum drm_connector_status
225intel_dvo_detect(struct drm_connector *connector, bool force)
225{ 226{
226 struct drm_encoder *encoder = intel_attached_encoder(connector); 227 struct drm_encoder *encoder = intel_attached_encoder(connector);
227 struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder); 228 struct intel_dvo *intel_dvo = enc_to_intel_dvo(encoder);
diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c
index 7bdc96256bf5..b61966c126d3 100644
--- a/drivers/gpu/drm/i915/intel_fb.c
+++ b/drivers/gpu/drm/i915/intel_fb.c
@@ -237,8 +237,10 @@ int intel_fbdev_destroy(struct drm_device *dev,
237 drm_fb_helper_fini(&ifbdev->helper); 237 drm_fb_helper_fini(&ifbdev->helper);
238 238
239 drm_framebuffer_cleanup(&ifb->base); 239 drm_framebuffer_cleanup(&ifb->base);
240 if (ifb->obj) 240 if (ifb->obj) {
241 drm_gem_object_unreference(ifb->obj); 241 drm_gem_object_unreference(ifb->obj);
242 ifb->obj = NULL;
243 }
242 244
243 return 0; 245 return 0;
244} 246}
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index ccd4c97e6524..926934a482ec 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -139,7 +139,7 @@ static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder,
139} 139}
140 140
141static enum drm_connector_status 141static enum drm_connector_status
142intel_hdmi_detect(struct drm_connector *connector) 142intel_hdmi_detect(struct drm_connector *connector, bool force)
143{ 143{
144 struct drm_encoder *encoder = intel_attached_encoder(connector); 144 struct drm_encoder *encoder = intel_attached_encoder(connector);
145 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder); 145 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index 4fbb0165b26f..6ec39a86ed06 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -445,7 +445,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder,
445 * connected and closed means disconnected. We also send hotplug events as 445 * connected and closed means disconnected. We also send hotplug events as
446 * needed, using lid status notification from the input layer. 446 * needed, using lid status notification from the input layer.
447 */ 447 */
448static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector) 448static enum drm_connector_status
449intel_lvds_detect(struct drm_connector *connector, bool force)
449{ 450{
450 struct drm_device *dev = connector->dev; 451 struct drm_device *dev = connector->dev;
451 enum drm_connector_status status = connector_status_connected; 452 enum drm_connector_status status = connector_status_connected;
@@ -540,7 +541,9 @@ static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
540 * the LID nofication event. 541 * the LID nofication event.
541 */ 542 */
542 if (connector) 543 if (connector)
543 connector->status = connector->funcs->detect(connector); 544 connector->status = connector->funcs->detect(connector,
545 false);
546
544 /* Don't force modeset on machines where it causes a GPU lockup */ 547 /* Don't force modeset on machines where it causes a GPU lockup */
545 if (dmi_check_system(intel_no_modeset_on_lid)) 548 if (dmi_check_system(intel_no_modeset_on_lid))
546 return NOTIFY_OK; 549 return NOTIFY_OK;
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index e3b7a7ee39cb..ee73e428a84a 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -1417,7 +1417,7 @@ intel_analog_is_connected(struct drm_device *dev)
1417 if (!analog_connector) 1417 if (!analog_connector)
1418 return false; 1418 return false;
1419 1419
1420 if (analog_connector->funcs->detect(analog_connector) == 1420 if (analog_connector->funcs->detect(analog_connector, false) ==
1421 connector_status_disconnected) 1421 connector_status_disconnected)
1422 return false; 1422 return false;
1423 1423
@@ -1486,7 +1486,8 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector)
1486 return status; 1486 return status;
1487} 1487}
1488 1488
1489static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connector) 1489static enum drm_connector_status
1490intel_sdvo_detect(struct drm_connector *connector, bool force)
1490{ 1491{
1491 uint16_t response; 1492 uint16_t response;
1492 struct drm_encoder *encoder = intel_attached_encoder(connector); 1493 struct drm_encoder *encoder = intel_attached_encoder(connector);
@@ -2169,8 +2170,7 @@ intel_sdvo_tv_init(struct intel_sdvo *intel_sdvo, int type)
2169 return true; 2170 return true;
2170 2171
2171err: 2172err:
2172 intel_sdvo_destroy_enhance_property(connector); 2173 intel_sdvo_destroy(connector);
2173 kfree(intel_sdvo_connector);
2174 return false; 2174 return false;
2175} 2175}
2176 2176
@@ -2242,8 +2242,7 @@ intel_sdvo_lvds_init(struct intel_sdvo *intel_sdvo, int device)
2242 return true; 2242 return true;
2243 2243
2244err: 2244err:
2245 intel_sdvo_destroy_enhance_property(connector); 2245 intel_sdvo_destroy(connector);
2246 kfree(intel_sdvo_connector);
2247 return false; 2246 return false;
2248} 2247}
2249 2248
@@ -2521,11 +2520,10 @@ static bool intel_sdvo_create_enhance_property(struct intel_sdvo *intel_sdvo,
2521 uint16_t response; 2520 uint16_t response;
2522 } enhancements; 2521 } enhancements;
2523 2522
2524 if (!intel_sdvo_get_value(intel_sdvo, 2523 enhancements.response = 0;
2525 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, 2524 intel_sdvo_get_value(intel_sdvo,
2526 &enhancements, sizeof(enhancements))) 2525 SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS,
2527 return false; 2526 &enhancements, sizeof(enhancements));
2528
2529 if (enhancements.response == 0) { 2527 if (enhancements.response == 0) {
2530 DRM_DEBUG_KMS("No enhancement is supported\n"); 2528 DRM_DEBUG_KMS("No enhancement is supported\n");
2531 return true; 2529 return true;
diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c
index c671f60ce80b..4a117e318a73 100644
--- a/drivers/gpu/drm/i915/intel_tv.c
+++ b/drivers/gpu/drm/i915/intel_tv.c
@@ -1341,7 +1341,7 @@ static void intel_tv_find_better_format(struct drm_connector *connector)
1341 * we have a pipe programmed in order to probe the TV. 1341 * we have a pipe programmed in order to probe the TV.
1342 */ 1342 */
1343static enum drm_connector_status 1343static enum drm_connector_status
1344intel_tv_detect(struct drm_connector *connector) 1344intel_tv_detect(struct drm_connector *connector, bool force)
1345{ 1345{
1346 struct drm_display_mode mode; 1346 struct drm_display_mode mode;
1347 struct drm_encoder *encoder = intel_attached_encoder(connector); 1347 struct drm_encoder *encoder = intel_attached_encoder(connector);
@@ -1353,7 +1353,7 @@ intel_tv_detect(struct drm_connector *connector)
1353 1353
1354 if (encoder->crtc && encoder->crtc->enabled) { 1354 if (encoder->crtc && encoder->crtc->enabled) {
1355 type = intel_tv_detect_type(intel_tv); 1355 type = intel_tv_detect_type(intel_tv);
1356 } else { 1356 } else if (force) {
1357 struct drm_crtc *crtc; 1357 struct drm_crtc *crtc;
1358 int dpms_mode; 1358 int dpms_mode;
1359 1359
@@ -1364,10 +1364,9 @@ intel_tv_detect(struct drm_connector *connector)
1364 intel_release_load_detect_pipe(&intel_tv->base, connector, 1364 intel_release_load_detect_pipe(&intel_tv->base, connector,
1365 dpms_mode); 1365 dpms_mode);
1366 } else 1366 } else
1367 type = -1; 1367 return connector_status_unknown;
1368 } 1368 } else
1369 1369 return connector->status;
1370 intel_tv->type = type;
1371 1370
1372 if (type < 0) 1371 if (type < 0)
1373 return connector_status_disconnected; 1372 return connector_status_disconnected;
diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c
index a1473fff06ac..fc737037f751 100644
--- a/drivers/gpu/drm/nouveau/nouveau_connector.c
+++ b/drivers/gpu/drm/nouveau/nouveau_connector.c
@@ -168,7 +168,7 @@ nouveau_connector_set_encoder(struct drm_connector *connector,
168} 168}
169 169
170static enum drm_connector_status 170static enum drm_connector_status
171nouveau_connector_detect(struct drm_connector *connector) 171nouveau_connector_detect(struct drm_connector *connector, bool force)
172{ 172{
173 struct drm_device *dev = connector->dev; 173 struct drm_device *dev = connector->dev;
174 struct nouveau_connector *nv_connector = nouveau_connector(connector); 174 struct nouveau_connector *nv_connector = nouveau_connector(connector);
@@ -246,7 +246,7 @@ detect_analog:
246} 246}
247 247
248static enum drm_connector_status 248static enum drm_connector_status
249nouveau_connector_detect_lvds(struct drm_connector *connector) 249nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
250{ 250{
251 struct drm_device *dev = connector->dev; 251 struct drm_device *dev = connector->dev;
252 struct drm_nouveau_private *dev_priv = dev->dev_private; 252 struct drm_nouveau_private *dev_priv = dev->dev_private;
@@ -267,7 +267,7 @@ nouveau_connector_detect_lvds(struct drm_connector *connector)
267 267
268 /* Try retrieving EDID via DDC */ 268 /* Try retrieving EDID via DDC */
269 if (!dev_priv->vbios.fp_no_ddc) { 269 if (!dev_priv->vbios.fp_no_ddc) {
270 status = nouveau_connector_detect(connector); 270 status = nouveau_connector_detect(connector, force);
271 if (status == connector_status_connected) 271 if (status == connector_status_connected)
272 goto out; 272 goto out;
273 } 273 }
@@ -558,8 +558,10 @@ nouveau_connector_get_modes(struct drm_connector *connector)
558 if (nv_encoder->dcb->type == OUTPUT_LVDS && 558 if (nv_encoder->dcb->type == OUTPUT_LVDS &&
559 (nv_encoder->dcb->lvdsconf.use_straps_for_mode || 559 (nv_encoder->dcb->lvdsconf.use_straps_for_mode ||
560 dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) { 560 dev_priv->vbios.fp_no_ddc) && nouveau_bios_fp_mode(dev, NULL)) {
561 nv_connector->native_mode = drm_mode_create(dev); 561 struct drm_display_mode mode;
562 nouveau_bios_fp_mode(dev, nv_connector->native_mode); 562
563 nouveau_bios_fp_mode(dev, &mode);
564 nv_connector->native_mode = drm_mode_duplicate(dev, &mode);
563 } 565 }
564 566
565 /* Find the native mode if this is a digital panel, if we didn't 567 /* Find the native mode if this is a digital panel, if we didn't
diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
index ead7b8fc53fc..19620a6709f5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
@@ -167,11 +167,9 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
167 goto out; 167 goto out;
168 168
169 ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle); 169 ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle);
170 /* drop reference from allocate - handle holds it now */
171 drm_gem_object_unreference_unlocked(nvbo->gem);
170out: 172out:
171 drm_gem_object_handle_unreference_unlocked(nvbo->gem);
172
173 if (ret)
174 drm_gem_object_unreference_unlocked(nvbo->gem);
175 return ret; 173 return ret;
176} 174}
177 175
diff --git a/drivers/gpu/drm/radeon/atombios.h b/drivers/gpu/drm/radeon/atombios.h
index 1bc72c3190a9..fe359a239df3 100644
--- a/drivers/gpu/drm/radeon/atombios.h
+++ b/drivers/gpu/drm/radeon/atombios.h
@@ -4999,7 +4999,7 @@ typedef struct _SW_I2C_IO_DATA_PARAMETERS
4999#define SW_I2C_CNTL_WRITE1BIT 6 4999#define SW_I2C_CNTL_WRITE1BIT 6
5000 5000
5001//==============================VESA definition Portion=============================== 5001//==============================VESA definition Portion===============================
5002#define VESA_OEM_PRODUCT_REV '01.00' 5002#define VESA_OEM_PRODUCT_REV "01.00"
5003#define VESA_MODE_ATTRIBUTE_MODE_SUPPORT 0xBB //refer to VBE spec p.32, no TTY support 5003#define VESA_MODE_ATTRIBUTE_MODE_SUPPORT 0xBB //refer to VBE spec p.32, no TTY support
5004#define VESA_MODE_WIN_ATTRIBUTE 7 5004#define VESA_MODE_WIN_ATTRIBUTE 7
5005#define VESA_WIN_SIZE 64 5005#define VESA_WIN_SIZE 64
diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c
index 464a81a1990f..cd0290f946cf 100644
--- a/drivers/gpu/drm/radeon/atombios_crtc.c
+++ b/drivers/gpu/drm/radeon/atombios_crtc.c
@@ -539,14 +539,15 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc,
539 pll->algo = PLL_ALGO_LEGACY; 539 pll->algo = PLL_ALGO_LEGACY;
540 pll->flags |= RADEON_PLL_PREFER_CLOSEST_LOWER; 540 pll->flags |= RADEON_PLL_PREFER_CLOSEST_LOWER;
541 } 541 }
542 /* There is some evidence (often anecdotal) that RV515 LVDS 542 /* There is some evidence (often anecdotal) that RV515/RV620 LVDS
543 * (on some boards at least) prefers the legacy algo. I'm not 543 * (on some boards at least) prefers the legacy algo. I'm not
544 * sure whether this should handled generically or on a 544 * sure whether this should handled generically or on a
545 * case-by-case quirk basis. Both algos should work fine in the 545 * case-by-case quirk basis. Both algos should work fine in the
546 * majority of cases. 546 * majority of cases.
547 */ 547 */
548 if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) && 548 if ((radeon_encoder->active_device & (ATOM_DEVICE_LCD_SUPPORT)) &&
549 (rdev->family == CHIP_RV515)) { 549 ((rdev->family == CHIP_RV515) ||
550 (rdev->family == CHIP_RV620))) {
550 /* allow the user to overrride just in case */ 551 /* allow the user to overrride just in case */
551 if (radeon_new_pll == 1) 552 if (radeon_new_pll == 1)
552 pll->algo = PLL_ALGO_NEW; 553 pll->algo = PLL_ALGO_NEW;
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index b8b7f010b25f..2f93d46ae69a 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -1137,7 +1137,7 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1137 1137
1138 WREG32(RCU_IND_INDEX, 0x203); 1138 WREG32(RCU_IND_INDEX, 0x203);
1139 efuse_straps_3 = RREG32(RCU_IND_DATA); 1139 efuse_straps_3 = RREG32(RCU_IND_DATA);
1140 efuse_box_bit_127_124 = (u8)(efuse_straps_3 & 0xF0000000) >> 28; 1140 efuse_box_bit_127_124 = (u8)((efuse_straps_3 & 0xF0000000) >> 28);
1141 1141
1142 switch(efuse_box_bit_127_124) { 1142 switch(efuse_box_bit_127_124) {
1143 case 0x0: 1143 case 0x0:
@@ -1160,14 +1160,25 @@ static void evergreen_gpu_init(struct radeon_device *rdev)
1160 EVERGREEN_MAX_BACKENDS_MASK)); 1160 EVERGREEN_MAX_BACKENDS_MASK));
1161 break; 1161 break;
1162 } 1162 }
1163 } else 1163 } else {
1164 gb_backend_map = 1164 switch (rdev->family) {
1165 evergreen_get_tile_pipe_to_backend_map(rdev, 1165 case CHIP_CYPRESS:
1166 rdev->config.evergreen.max_tile_pipes, 1166 case CHIP_HEMLOCK:
1167 rdev->config.evergreen.max_backends, 1167 gb_backend_map = 0x66442200;
1168 ((EVERGREEN_MAX_BACKENDS_MASK << 1168 break;
1169 rdev->config.evergreen.max_backends) & 1169 case CHIP_JUNIPER:
1170 EVERGREEN_MAX_BACKENDS_MASK)); 1170 gb_backend_map = 0x00006420;
1171 break;
1172 default:
1173 gb_backend_map =
1174 evergreen_get_tile_pipe_to_backend_map(rdev,
1175 rdev->config.evergreen.max_tile_pipes,
1176 rdev->config.evergreen.max_backends,
1177 ((EVERGREEN_MAX_BACKENDS_MASK <<
1178 rdev->config.evergreen.max_backends) &
1179 EVERGREEN_MAX_BACKENDS_MASK));
1180 }
1181 }
1171 1182
1172 rdev->config.evergreen.tile_config = gb_addr_config; 1183 rdev->config.evergreen.tile_config = gb_addr_config;
1173 WREG32(GB_BACKEND_MAP, gb_backend_map); 1184 WREG32(GB_BACKEND_MAP, gb_backend_map);
@@ -1396,6 +1407,7 @@ int evergreen_mc_init(struct radeon_device *rdev)
1396 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; 1407 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
1397 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; 1408 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024;
1398 rdev->mc.visible_vram_size = rdev->mc.aper_size; 1409 rdev->mc.visible_vram_size = rdev->mc.aper_size;
1410 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
1399 r600_vram_gtt_location(rdev, &rdev->mc); 1411 r600_vram_gtt_location(rdev, &rdev->mc);
1400 radeon_update_bandwidth_info(rdev); 1412 radeon_update_bandwidth_info(rdev);
1401 1413
@@ -1509,7 +1521,7 @@ void evergreen_disable_interrupt_state(struct radeon_device *rdev)
1509{ 1521{
1510 u32 tmp; 1522 u32 tmp;
1511 1523
1512 WREG32(CP_INT_CNTL, 0); 1524 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
1513 WREG32(GRBM_INT_CNTL, 0); 1525 WREG32(GRBM_INT_CNTL, 0);
1514 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); 1526 WREG32(INT_MASK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0);
1515 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); 1527 WREG32(INT_MASK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0);
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index e817a0bb5eb4..e59422320bb6 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -1030,6 +1030,7 @@ int r100_cp_init(struct radeon_device *rdev, unsigned ring_size)
1030 return r; 1030 return r;
1031 } 1031 }
1032 rdev->cp.ready = true; 1032 rdev->cp.ready = true;
1033 rdev->mc.active_vram_size = rdev->mc.real_vram_size;
1033 return 0; 1034 return 0;
1034} 1035}
1035 1036
@@ -1047,6 +1048,7 @@ void r100_cp_fini(struct radeon_device *rdev)
1047void r100_cp_disable(struct radeon_device *rdev) 1048void r100_cp_disable(struct radeon_device *rdev)
1048{ 1049{
1049 /* Disable ring */ 1050 /* Disable ring */
1051 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
1050 rdev->cp.ready = false; 1052 rdev->cp.ready = false;
1051 WREG32(RADEON_CP_CSQ_MODE, 0); 1053 WREG32(RADEON_CP_CSQ_MODE, 0);
1052 WREG32(RADEON_CP_CSQ_CNTL, 0); 1054 WREG32(RADEON_CP_CSQ_CNTL, 0);
@@ -2020,18 +2022,7 @@ bool r100_gpu_cp_is_lockup(struct radeon_device *rdev, struct r100_gpu_lockup *l
2020 return false; 2022 return false;
2021 } 2023 }
2022 elapsed = jiffies_to_msecs(cjiffies - lockup->last_jiffies); 2024 elapsed = jiffies_to_msecs(cjiffies - lockup->last_jiffies);
2023 if (elapsed >= 3000) { 2025 if (elapsed >= 10000) {
2024 /* very likely the improbable case where current
2025 * rptr is equal to last recorded, a while ago, rptr
2026 * this is more likely a false positive update tracking
2027 * information which should force us to be recall at
2028 * latter point
2029 */
2030 lockup->last_cp_rptr = cp->rptr;
2031 lockup->last_jiffies = jiffies;
2032 return false;
2033 }
2034 if (elapsed >= 1000) {
2035 dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed); 2026 dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed);
2036 return true; 2027 return true;
2037 } 2028 }
@@ -2306,6 +2297,7 @@ void r100_vram_init_sizes(struct radeon_device *rdev)
2306 /* FIXME we don't use the second aperture yet when we could use it */ 2297 /* FIXME we don't use the second aperture yet when we could use it */
2307 if (rdev->mc.visible_vram_size > rdev->mc.aper_size) 2298 if (rdev->mc.visible_vram_size > rdev->mc.aper_size)
2308 rdev->mc.visible_vram_size = rdev->mc.aper_size; 2299 rdev->mc.visible_vram_size = rdev->mc.aper_size;
2300 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
2309 config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE); 2301 config_aper_size = RREG32(RADEON_CONFIG_APER_SIZE);
2310 if (rdev->flags & RADEON_IS_IGP) { 2302 if (rdev->flags & RADEON_IS_IGP) {
2311 uint32_t tom; 2303 uint32_t tom;
@@ -3308,13 +3300,14 @@ int r100_cs_track_check(struct radeon_device *rdev, struct r100_cs_track *track)
3308 unsigned long size; 3300 unsigned long size;
3309 unsigned prim_walk; 3301 unsigned prim_walk;
3310 unsigned nverts; 3302 unsigned nverts;
3303 unsigned num_cb = track->num_cb;
3311 3304
3312 for (i = 0; i < track->num_cb; i++) { 3305 if (!track->zb_cb_clear && !track->color_channel_mask &&
3306 !track->blend_read_enable)
3307 num_cb = 0;
3308
3309 for (i = 0; i < num_cb; i++) {
3313 if (track->cb[i].robj == NULL) { 3310 if (track->cb[i].robj == NULL) {
3314 if (!(track->zb_cb_clear || track->color_channel_mask ||
3315 track->blend_read_enable)) {
3316 continue;
3317 }
3318 DRM_ERROR("[drm] No buffer for color buffer %d !\n", i); 3311 DRM_ERROR("[drm] No buffer for color buffer %d !\n", i);
3319 return -EINVAL; 3312 return -EINVAL;
3320 } 3313 }
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index afc18d87fdca..7b65e4efe8af 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -1248,6 +1248,7 @@ int r600_mc_init(struct radeon_device *rdev)
1248 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE); 1248 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
1249 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE); 1249 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
1250 rdev->mc.visible_vram_size = rdev->mc.aper_size; 1250 rdev->mc.visible_vram_size = rdev->mc.aper_size;
1251 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
1251 r600_vram_gtt_location(rdev, &rdev->mc); 1252 r600_vram_gtt_location(rdev, &rdev->mc);
1252 1253
1253 if (rdev->flags & RADEON_IS_IGP) { 1254 if (rdev->flags & RADEON_IS_IGP) {
@@ -1917,6 +1918,7 @@ void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
1917 */ 1918 */
1918void r600_cp_stop(struct radeon_device *rdev) 1919void r600_cp_stop(struct radeon_device *rdev)
1919{ 1920{
1921 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
1920 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1)); 1922 WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
1921} 1923}
1922 1924
@@ -2729,7 +2731,7 @@ int r600_ib_test(struct radeon_device *rdev)
2729 if (i < rdev->usec_timeout) { 2731 if (i < rdev->usec_timeout) {
2730 DRM_INFO("ib test succeeded in %u usecs\n", i); 2732 DRM_INFO("ib test succeeded in %u usecs\n", i);
2731 } else { 2733 } else {
2732 DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n", 2734 DRM_ERROR("radeon: ib test failed (scratch(0x%04X)=0x%08X)\n",
2733 scratch, tmp); 2735 scratch, tmp);
2734 r = -EINVAL; 2736 r = -EINVAL;
2735 } 2737 }
@@ -2910,7 +2912,7 @@ static void r600_disable_interrupt_state(struct radeon_device *rdev)
2910{ 2912{
2911 u32 tmp; 2913 u32 tmp;
2912 2914
2913 WREG32(CP_INT_CNTL, 0); 2915 WREG32(CP_INT_CNTL, CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE);
2914 WREG32(GRBM_INT_CNTL, 0); 2916 WREG32(GRBM_INT_CNTL, 0);
2915 WREG32(DxMODE_INT_MASK, 0); 2917 WREG32(DxMODE_INT_MASK, 0);
2916 if (ASIC_IS_DCE3(rdev)) { 2918 if (ASIC_IS_DCE3(rdev)) {
@@ -3528,7 +3530,8 @@ void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
3528 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read 3530 /* r7xx hw bug. write to HDP_DEBUG1 followed by fb read
3529 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL 3531 * rather than write to HDP_REG_COHERENCY_FLUSH_CNTL
3530 */ 3532 */
3531 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740)) { 3533 if ((rdev->family >= CHIP_RV770) && (rdev->family <= CHIP_RV740) &&
3534 rdev->vram_scratch.ptr) {
3532 void __iomem *ptr = (void *)rdev->vram_scratch.ptr; 3535 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
3533 u32 tmp; 3536 u32 tmp;
3534 3537
diff --git a/drivers/gpu/drm/radeon/r600_blit_kms.c b/drivers/gpu/drm/radeon/r600_blit_kms.c
index d13622ae74e9..3473c00781ff 100644
--- a/drivers/gpu/drm/radeon/r600_blit_kms.c
+++ b/drivers/gpu/drm/radeon/r600_blit_kms.c
@@ -1,3 +1,28 @@
1/*
2 * Copyright 2009 Advanced Micro Devices, Inc.
3 * Copyright 2009 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
25
1#include "drmP.h" 26#include "drmP.h"
2#include "drm.h" 27#include "drm.h"
3#include "radeon_drm.h" 28#include "radeon_drm.h"
@@ -507,6 +532,7 @@ int r600_blit_init(struct radeon_device *rdev)
507 memcpy(ptr + rdev->r600_blit.ps_offset, r6xx_ps, r6xx_ps_size * 4); 532 memcpy(ptr + rdev->r600_blit.ps_offset, r6xx_ps, r6xx_ps_size * 4);
508 radeon_bo_kunmap(rdev->r600_blit.shader_obj); 533 radeon_bo_kunmap(rdev->r600_blit.shader_obj);
509 radeon_bo_unreserve(rdev->r600_blit.shader_obj); 534 radeon_bo_unreserve(rdev->r600_blit.shader_obj);
535 rdev->mc.active_vram_size = rdev->mc.real_vram_size;
510 return 0; 536 return 0;
511} 537}
512 538
@@ -514,6 +540,7 @@ void r600_blit_fini(struct radeon_device *rdev)
514{ 540{
515 int r; 541 int r;
516 542
543 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
517 if (rdev->r600_blit.shader_obj == NULL) 544 if (rdev->r600_blit.shader_obj == NULL)
518 return; 545 return;
519 /* If we can't reserve the bo, unref should be enough to destroy 546 /* If we can't reserve the bo, unref should be enough to destroy
diff --git a/drivers/gpu/drm/radeon/r600_blit_shaders.h b/drivers/gpu/drm/radeon/r600_blit_shaders.h
index fdc3b378cbb0..f437d36dd98c 100644
--- a/drivers/gpu/drm/radeon/r600_blit_shaders.h
+++ b/drivers/gpu/drm/radeon/r600_blit_shaders.h
@@ -1,3 +1,27 @@
1/*
2 * Copyright 2009 Advanced Micro Devices, Inc.
3 * Copyright 2009 Red Hat Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 */
1 25
2#ifndef R600_BLIT_SHADERS_H 26#ifndef R600_BLIT_SHADERS_H
3#define R600_BLIT_SHADERS_H 27#define R600_BLIT_SHADERS_H
diff --git a/drivers/gpu/drm/radeon/r600_cs.c b/drivers/gpu/drm/radeon/r600_cs.c
index d8864949e387..250a3a918193 100644
--- a/drivers/gpu/drm/radeon/r600_cs.c
+++ b/drivers/gpu/drm/radeon/r600_cs.c
@@ -1170,9 +1170,8 @@ static inline int r600_check_texture_resource(struct radeon_cs_parser *p, u32 i
1170 /* using get ib will give us the offset into the mipmap bo */ 1170 /* using get ib will give us the offset into the mipmap bo */
1171 word0 = radeon_get_ib_value(p, idx + 3) << 8; 1171 word0 = radeon_get_ib_value(p, idx + 3) << 8;
1172 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) { 1172 if ((mipmap_size + word0) > radeon_bo_size(mipmap)) {
1173 dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n", 1173 /*dev_warn(p->dev, "mipmap bo too small (%d %d %d %d %d %d -> %d have %ld)\n",
1174 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture)); 1174 w0, h0, bpe, blevel, nlevels, word0, mipmap_size, radeon_bo_size(texture));*/
1175 return -EINVAL;
1176 } 1175 }
1177 return 0; 1176 return 0;
1178} 1177}
diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index a168d644bf9e..9ff38c99a6ea 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -344,6 +344,7 @@ struct radeon_mc {
344 * about vram size near mc fb location */ 344 * about vram size near mc fb location */
345 u64 mc_vram_size; 345 u64 mc_vram_size;
346 u64 visible_vram_size; 346 u64 visible_vram_size;
347 u64 active_vram_size;
347 u64 gtt_size; 348 u64 gtt_size;
348 u64 gtt_start; 349 u64 gtt_start;
349 u64 gtt_end; 350 u64 gtt_end;
diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
index ebae14c4b768..8e43ddae70cc 100644
--- a/drivers/gpu/drm/radeon/radeon_atombios.c
+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
@@ -317,6 +317,15 @@ static bool radeon_atom_apply_quirks(struct drm_device *dev,
317 *connector_type = DRM_MODE_CONNECTOR_DVID; 317 *connector_type = DRM_MODE_CONNECTOR_DVID;
318 } 318 }
319 319
320 /* MSI K9A2GM V2/V3 board has no HDMI or DVI */
321 if ((dev->pdev->device == 0x796e) &&
322 (dev->pdev->subsystem_vendor == 0x1462) &&
323 (dev->pdev->subsystem_device == 0x7302)) {
324 if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) ||
325 (supported_device == ATOM_DEVICE_DFP3_SUPPORT))
326 return false;
327 }
328
320 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */ 329 /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */
321 if ((dev->pdev->device == 0x7941) && 330 if ((dev->pdev->device == 0x7941) &&
322 (dev->pdev->subsystem_vendor == 0x147b) && 331 (dev->pdev->subsystem_vendor == 0x147b) &&
@@ -1549,39 +1558,39 @@ radeon_atombios_get_tv_info(struct radeon_device *rdev)
1549 switch (tv_info->ucTV_BootUpDefaultStandard) { 1558 switch (tv_info->ucTV_BootUpDefaultStandard) {
1550 case ATOM_TV_NTSC: 1559 case ATOM_TV_NTSC:
1551 tv_std = TV_STD_NTSC; 1560 tv_std = TV_STD_NTSC;
1552 DRM_INFO("Default TV standard: NTSC\n"); 1561 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
1553 break; 1562 break;
1554 case ATOM_TV_NTSCJ: 1563 case ATOM_TV_NTSCJ:
1555 tv_std = TV_STD_NTSC_J; 1564 tv_std = TV_STD_NTSC_J;
1556 DRM_INFO("Default TV standard: NTSC-J\n"); 1565 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
1557 break; 1566 break;
1558 case ATOM_TV_PAL: 1567 case ATOM_TV_PAL:
1559 tv_std = TV_STD_PAL; 1568 tv_std = TV_STD_PAL;
1560 DRM_INFO("Default TV standard: PAL\n"); 1569 DRM_DEBUG_KMS("Default TV standard: PAL\n");
1561 break; 1570 break;
1562 case ATOM_TV_PALM: 1571 case ATOM_TV_PALM:
1563 tv_std = TV_STD_PAL_M; 1572 tv_std = TV_STD_PAL_M;
1564 DRM_INFO("Default TV standard: PAL-M\n"); 1573 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
1565 break; 1574 break;
1566 case ATOM_TV_PALN: 1575 case ATOM_TV_PALN:
1567 tv_std = TV_STD_PAL_N; 1576 tv_std = TV_STD_PAL_N;
1568 DRM_INFO("Default TV standard: PAL-N\n"); 1577 DRM_DEBUG_KMS("Default TV standard: PAL-N\n");
1569 break; 1578 break;
1570 case ATOM_TV_PALCN: 1579 case ATOM_TV_PALCN:
1571 tv_std = TV_STD_PAL_CN; 1580 tv_std = TV_STD_PAL_CN;
1572 DRM_INFO("Default TV standard: PAL-CN\n"); 1581 DRM_DEBUG_KMS("Default TV standard: PAL-CN\n");
1573 break; 1582 break;
1574 case ATOM_TV_PAL60: 1583 case ATOM_TV_PAL60:
1575 tv_std = TV_STD_PAL_60; 1584 tv_std = TV_STD_PAL_60;
1576 DRM_INFO("Default TV standard: PAL-60\n"); 1585 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
1577 break; 1586 break;
1578 case ATOM_TV_SECAM: 1587 case ATOM_TV_SECAM:
1579 tv_std = TV_STD_SECAM; 1588 tv_std = TV_STD_SECAM;
1580 DRM_INFO("Default TV standard: SECAM\n"); 1589 DRM_DEBUG_KMS("Default TV standard: SECAM\n");
1581 break; 1590 break;
1582 default: 1591 default:
1583 tv_std = TV_STD_NTSC; 1592 tv_std = TV_STD_NTSC;
1584 DRM_INFO("Unknown TV standard; defaulting to NTSC\n"); 1593 DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n");
1585 break; 1594 break;
1586 } 1595 }
1587 } 1596 }
diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c
index bd74e428bd14..7b7ea269549c 100644
--- a/drivers/gpu/drm/radeon/radeon_combios.c
+++ b/drivers/gpu/drm/radeon/radeon_combios.c
@@ -913,47 +913,47 @@ radeon_combios_get_tv_info(struct radeon_device *rdev)
913 switch (RBIOS8(tv_info + 7) & 0xf) { 913 switch (RBIOS8(tv_info + 7) & 0xf) {
914 case 1: 914 case 1:
915 tv_std = TV_STD_NTSC; 915 tv_std = TV_STD_NTSC;
916 DRM_INFO("Default TV standard: NTSC\n"); 916 DRM_DEBUG_KMS("Default TV standard: NTSC\n");
917 break; 917 break;
918 case 2: 918 case 2:
919 tv_std = TV_STD_PAL; 919 tv_std = TV_STD_PAL;
920 DRM_INFO("Default TV standard: PAL\n"); 920 DRM_DEBUG_KMS("Default TV standard: PAL\n");
921 break; 921 break;
922 case 3: 922 case 3:
923 tv_std = TV_STD_PAL_M; 923 tv_std = TV_STD_PAL_M;
924 DRM_INFO("Default TV standard: PAL-M\n"); 924 DRM_DEBUG_KMS("Default TV standard: PAL-M\n");
925 break; 925 break;
926 case 4: 926 case 4:
927 tv_std = TV_STD_PAL_60; 927 tv_std = TV_STD_PAL_60;
928 DRM_INFO("Default TV standard: PAL-60\n"); 928 DRM_DEBUG_KMS("Default TV standard: PAL-60\n");
929 break; 929 break;
930 case 5: 930 case 5:
931 tv_std = TV_STD_NTSC_J; 931 tv_std = TV_STD_NTSC_J;
932 DRM_INFO("Default TV standard: NTSC-J\n"); 932 DRM_DEBUG_KMS("Default TV standard: NTSC-J\n");
933 break; 933 break;
934 case 6: 934 case 6:
935 tv_std = TV_STD_SCART_PAL; 935 tv_std = TV_STD_SCART_PAL;
936 DRM_INFO("Default TV standard: SCART-PAL\n"); 936 DRM_DEBUG_KMS("Default TV standard: SCART-PAL\n");
937 break; 937 break;
938 default: 938 default:
939 tv_std = TV_STD_NTSC; 939 tv_std = TV_STD_NTSC;
940 DRM_INFO 940 DRM_DEBUG_KMS
941 ("Unknown TV standard; defaulting to NTSC\n"); 941 ("Unknown TV standard; defaulting to NTSC\n");
942 break; 942 break;
943 } 943 }
944 944
945 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) { 945 switch ((RBIOS8(tv_info + 9) >> 2) & 0x3) {
946 case 0: 946 case 0:
947 DRM_INFO("29.498928713 MHz TV ref clk\n"); 947 DRM_DEBUG_KMS("29.498928713 MHz TV ref clk\n");
948 break; 948 break;
949 case 1: 949 case 1:
950 DRM_INFO("28.636360000 MHz TV ref clk\n"); 950 DRM_DEBUG_KMS("28.636360000 MHz TV ref clk\n");
951 break; 951 break;
952 case 2: 952 case 2:
953 DRM_INFO("14.318180000 MHz TV ref clk\n"); 953 DRM_DEBUG_KMS("14.318180000 MHz TV ref clk\n");
954 break; 954 break;
955 case 3: 955 case 3:
956 DRM_INFO("27.000000000 MHz TV ref clk\n"); 956 DRM_DEBUG_KMS("27.000000000 MHz TV ref clk\n");
957 break; 957 break;
958 default: 958 default:
959 break; 959 break;
@@ -1324,7 +1324,7 @@ bool radeon_legacy_get_tmds_info_from_combios(struct radeon_encoder *encoder,
1324 1324
1325 if (tmds_info) { 1325 if (tmds_info) {
1326 ver = RBIOS8(tmds_info); 1326 ver = RBIOS8(tmds_info);
1327 DRM_INFO("DFP table revision: %d\n", ver); 1327 DRM_DEBUG_KMS("DFP table revision: %d\n", ver);
1328 if (ver == 3) { 1328 if (ver == 3) {
1329 n = RBIOS8(tmds_info + 5) + 1; 1329 n = RBIOS8(tmds_info + 5) + 1;
1330 if (n > 4) 1330 if (n > 4)
@@ -1408,7 +1408,7 @@ bool radeon_legacy_get_ext_tmds_info_from_combios(struct radeon_encoder *encoder
1408 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE); 1408 offset = combios_get_table_offset(dev, COMBIOS_EXT_TMDS_INFO_TABLE);
1409 if (offset) { 1409 if (offset) {
1410 ver = RBIOS8(offset); 1410 ver = RBIOS8(offset);
1411 DRM_INFO("External TMDS Table revision: %d\n", ver); 1411 DRM_DEBUG_KMS("External TMDS Table revision: %d\n", ver);
1412 tmds->slave_addr = RBIOS8(offset + 4 + 2); 1412 tmds->slave_addr = RBIOS8(offset + 4 + 2);
1413 tmds->slave_addr >>= 1; /* 7 bit addressing */ 1413 tmds->slave_addr >>= 1; /* 7 bit addressing */
1414 gpio = RBIOS8(offset + 4 + 3); 1414 gpio = RBIOS8(offset + 4 + 3);
@@ -1485,6 +1485,11 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1485 /* PowerMac8,1 ? */ 1485 /* PowerMac8,1 ? */
1486 /* imac g5 isight */ 1486 /* imac g5 isight */
1487 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT; 1487 rdev->mode_info.connector_table = CT_IMAC_G5_ISIGHT;
1488 } else if ((rdev->pdev->device == 0x4a48) &&
1489 (rdev->pdev->subsystem_vendor == 0x1002) &&
1490 (rdev->pdev->subsystem_device == 0x4a48)) {
1491 /* Mac X800 */
1492 rdev->mode_info.connector_table = CT_MAC_X800;
1488 } else 1493 } else
1489#endif /* CONFIG_PPC_PMAC */ 1494#endif /* CONFIG_PPC_PMAC */
1490#ifdef CONFIG_PPC64 1495#ifdef CONFIG_PPC64
@@ -1961,6 +1966,48 @@ bool radeon_get_legacy_connector_info_from_table(struct drm_device *dev)
1961 CONNECTOR_OBJECT_ID_VGA, 1966 CONNECTOR_OBJECT_ID_VGA,
1962 &hpd); 1967 &hpd);
1963 break; 1968 break;
1969 case CT_MAC_X800:
1970 DRM_INFO("Connector Table: %d (mac x800)\n",
1971 rdev->mode_info.connector_table);
1972 /* DVI - primary dac, internal tmds */
1973 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_DVI, 0, 0);
1974 hpd.hpd = RADEON_HPD_1; /* ??? */
1975 radeon_add_legacy_encoder(dev,
1976 radeon_get_encoder_enum(dev,
1977 ATOM_DEVICE_DFP1_SUPPORT,
1978 0),
1979 ATOM_DEVICE_DFP1_SUPPORT);
1980 radeon_add_legacy_encoder(dev,
1981 radeon_get_encoder_enum(dev,
1982 ATOM_DEVICE_CRT1_SUPPORT,
1983 1),
1984 ATOM_DEVICE_CRT1_SUPPORT);
1985 radeon_add_legacy_connector(dev, 0,
1986 ATOM_DEVICE_DFP1_SUPPORT |
1987 ATOM_DEVICE_CRT1_SUPPORT,
1988 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
1989 CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I,
1990 &hpd);
1991 /* DVI - tv dac, dvo */
1992 ddc_i2c = combios_setup_i2c_bus(rdev, DDC_MONID, 0, 0);
1993 hpd.hpd = RADEON_HPD_2; /* ??? */
1994 radeon_add_legacy_encoder(dev,
1995 radeon_get_encoder_enum(dev,
1996 ATOM_DEVICE_DFP2_SUPPORT,
1997 0),
1998 ATOM_DEVICE_DFP2_SUPPORT);
1999 radeon_add_legacy_encoder(dev,
2000 radeon_get_encoder_enum(dev,
2001 ATOM_DEVICE_CRT2_SUPPORT,
2002 2),
2003 ATOM_DEVICE_CRT2_SUPPORT);
2004 radeon_add_legacy_connector(dev, 1,
2005 ATOM_DEVICE_DFP2_SUPPORT |
2006 ATOM_DEVICE_CRT2_SUPPORT,
2007 DRM_MODE_CONNECTOR_DVII, &ddc_i2c,
2008 CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I,
2009 &hpd);
2010 break;
1964 default: 2011 default:
1965 DRM_INFO("Connector table: %d (invalid)\n", 2012 DRM_INFO("Connector table: %d (invalid)\n",
1966 rdev->mode_info.connector_table); 2013 rdev->mode_info.connector_table);
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index a9dd7847d96e..ecc1a8fafbfd 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -481,7 +481,8 @@ static int radeon_lvds_mode_valid(struct drm_connector *connector,
481 return MODE_OK; 481 return MODE_OK;
482} 482}
483 483
484static enum drm_connector_status radeon_lvds_detect(struct drm_connector *connector) 484static enum drm_connector_status
485radeon_lvds_detect(struct drm_connector *connector, bool force)
485{ 486{
486 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 487 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
487 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 488 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
@@ -594,7 +595,8 @@ static int radeon_vga_mode_valid(struct drm_connector *connector,
594 return MODE_OK; 595 return MODE_OK;
595} 596}
596 597
597static enum drm_connector_status radeon_vga_detect(struct drm_connector *connector) 598static enum drm_connector_status
599radeon_vga_detect(struct drm_connector *connector, bool force)
598{ 600{
599 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 601 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
600 struct drm_encoder *encoder; 602 struct drm_encoder *encoder;
@@ -691,7 +693,8 @@ static int radeon_tv_mode_valid(struct drm_connector *connector,
691 return MODE_OK; 693 return MODE_OK;
692} 694}
693 695
694static enum drm_connector_status radeon_tv_detect(struct drm_connector *connector) 696static enum drm_connector_status
697radeon_tv_detect(struct drm_connector *connector, bool force)
695{ 698{
696 struct drm_encoder *encoder; 699 struct drm_encoder *encoder;
697 struct drm_encoder_helper_funcs *encoder_funcs; 700 struct drm_encoder_helper_funcs *encoder_funcs;
@@ -748,7 +751,8 @@ static int radeon_dvi_get_modes(struct drm_connector *connector)
748 * we have to check if this analog encoder is shared with anyone else (TV) 751 * we have to check if this analog encoder is shared with anyone else (TV)
749 * if its shared we have to set the other connector to disconnected. 752 * if its shared we have to set the other connector to disconnected.
750 */ 753 */
751static enum drm_connector_status radeon_dvi_detect(struct drm_connector *connector) 754static enum drm_connector_status
755radeon_dvi_detect(struct drm_connector *connector, bool force)
752{ 756{
753 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 757 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
754 struct drm_encoder *encoder = NULL; 758 struct drm_encoder *encoder = NULL;
@@ -972,7 +976,8 @@ static int radeon_dp_get_modes(struct drm_connector *connector)
972 return ret; 976 return ret;
973} 977}
974 978
975static enum drm_connector_status radeon_dp_detect(struct drm_connector *connector) 979static enum drm_connector_status
980radeon_dp_detect(struct drm_connector *connector, bool force)
976{ 981{
977 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 982 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
978 enum drm_connector_status ret = connector_status_disconnected; 983 enum drm_connector_status ret = connector_status_disconnected;
diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c
index 5731fc9b1ae3..3eef567b0421 100644
--- a/drivers/gpu/drm/radeon/radeon_cursor.c
+++ b/drivers/gpu/drm/radeon/radeon_cursor.c
@@ -203,6 +203,7 @@ int radeon_crtc_cursor_move(struct drm_crtc *crtc,
203 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); 203 struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc);
204 struct radeon_device *rdev = crtc->dev->dev_private; 204 struct radeon_device *rdev = crtc->dev->dev_private;
205 int xorigin = 0, yorigin = 0; 205 int xorigin = 0, yorigin = 0;
206 int w = radeon_crtc->cursor_width;
206 207
207 if (x < 0) 208 if (x < 0)
208 xorigin = -x + 1; 209 xorigin = -x + 1;
@@ -213,22 +214,7 @@ int radeon_crtc_cursor_move(struct drm_crtc *crtc,
213 if (yorigin >= CURSOR_HEIGHT) 214 if (yorigin >= CURSOR_HEIGHT)
214 yorigin = CURSOR_HEIGHT - 1; 215 yorigin = CURSOR_HEIGHT - 1;
215 216
216 radeon_lock_cursor(crtc, true); 217 if (ASIC_IS_AVIVO(rdev)) {
217 if (ASIC_IS_DCE4(rdev)) {
218 /* cursors are offset into the total surface */
219 x += crtc->x;
220 y += crtc->y;
221 DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y);
222
223 /* XXX: check if evergreen has the same issues as avivo chips */
224 WREG32(EVERGREEN_CUR_POSITION + radeon_crtc->crtc_offset,
225 ((xorigin ? 0 : x) << 16) |
226 (yorigin ? 0 : y));
227 WREG32(EVERGREEN_CUR_HOT_SPOT + radeon_crtc->crtc_offset, (xorigin << 16) | yorigin);
228 WREG32(EVERGREEN_CUR_SIZE + radeon_crtc->crtc_offset,
229 ((radeon_crtc->cursor_width - 1) << 16) | (radeon_crtc->cursor_height - 1));
230 } else if (ASIC_IS_AVIVO(rdev)) {
231 int w = radeon_crtc->cursor_width;
232 int i = 0; 218 int i = 0;
233 struct drm_crtc *crtc_p; 219 struct drm_crtc *crtc_p;
234 220
@@ -260,7 +246,17 @@ int radeon_crtc_cursor_move(struct drm_crtc *crtc,
260 if (w <= 0) 246 if (w <= 0)
261 w = 1; 247 w = 1;
262 } 248 }
249 }
263 250
251 radeon_lock_cursor(crtc, true);
252 if (ASIC_IS_DCE4(rdev)) {
253 WREG32(EVERGREEN_CUR_POSITION + radeon_crtc->crtc_offset,
254 ((xorigin ? 0 : x) << 16) |
255 (yorigin ? 0 : y));
256 WREG32(EVERGREEN_CUR_HOT_SPOT + radeon_crtc->crtc_offset, (xorigin << 16) | yorigin);
257 WREG32(EVERGREEN_CUR_SIZE + radeon_crtc->crtc_offset,
258 ((w - 1) << 16) | (radeon_crtc->cursor_height - 1));
259 } else if (ASIC_IS_AVIVO(rdev)) {
264 WREG32(AVIVO_D1CUR_POSITION + radeon_crtc->crtc_offset, 260 WREG32(AVIVO_D1CUR_POSITION + radeon_crtc->crtc_offset,
265 ((xorigin ? 0 : x) << 16) | 261 ((xorigin ? 0 : x) << 16) |
266 (yorigin ? 0 : y)); 262 (yorigin ? 0 : y));
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index 6dd434ad2429..b92d2f2fcbed 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -349,6 +349,8 @@ static void radeon_print_display_setup(struct drm_device *dev)
349 DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]); 349 DRM_INFO(" DFP4: %s\n", encoder_names[radeon_encoder->encoder_id]);
350 if (devices & ATOM_DEVICE_DFP5_SUPPORT) 350 if (devices & ATOM_DEVICE_DFP5_SUPPORT)
351 DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]); 351 DRM_INFO(" DFP5: %s\n", encoder_names[radeon_encoder->encoder_id]);
352 if (devices & ATOM_DEVICE_DFP6_SUPPORT)
353 DRM_INFO(" DFP6: %s\n", encoder_names[radeon_encoder->encoder_id]);
352 if (devices & ATOM_DEVICE_TV1_SUPPORT) 354 if (devices & ATOM_DEVICE_TV1_SUPPORT)
353 DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]); 355 DRM_INFO(" TV1: %s\n", encoder_names[radeon_encoder->encoder_id]);
354 if (devices & ATOM_DEVICE_CV_SUPPORT) 356 if (devices & ATOM_DEVICE_CV_SUPPORT)
@@ -841,8 +843,9 @@ static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb)
841{ 843{
842 struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb); 844 struct radeon_framebuffer *radeon_fb = to_radeon_framebuffer(fb);
843 845
844 if (radeon_fb->obj) 846 if (radeon_fb->obj) {
845 drm_gem_object_unreference_unlocked(radeon_fb->obj); 847 drm_gem_object_unreference_unlocked(radeon_fb->obj);
848 }
846 drm_framebuffer_cleanup(fb); 849 drm_framebuffer_cleanup(fb);
847 kfree(radeon_fb); 850 kfree(radeon_fb);
848} 851}
@@ -1140,17 +1143,18 @@ bool radeon_crtc_scaling_mode_fixup(struct drm_crtc *crtc,
1140 radeon_crtc->rmx_type = radeon_encoder->rmx_type; 1143 radeon_crtc->rmx_type = radeon_encoder->rmx_type;
1141 else 1144 else
1142 radeon_crtc->rmx_type = RMX_OFF; 1145 radeon_crtc->rmx_type = RMX_OFF;
1143 src_v = crtc->mode.vdisplay;
1144 dst_v = radeon_crtc->native_mode.vdisplay;
1145 src_h = crtc->mode.hdisplay;
1146 dst_h = radeon_crtc->native_mode.vdisplay;
1147 /* copy native mode */ 1146 /* copy native mode */
1148 memcpy(&radeon_crtc->native_mode, 1147 memcpy(&radeon_crtc->native_mode,
1149 &radeon_encoder->native_mode, 1148 &radeon_encoder->native_mode,
1150 sizeof(struct drm_display_mode)); 1149 sizeof(struct drm_display_mode));
1150 src_v = crtc->mode.vdisplay;
1151 dst_v = radeon_crtc->native_mode.vdisplay;
1152 src_h = crtc->mode.hdisplay;
1153 dst_h = radeon_crtc->native_mode.hdisplay;
1151 1154
1152 /* fix up for overscan on hdmi */ 1155 /* fix up for overscan on hdmi */
1153 if (ASIC_IS_AVIVO(rdev) && 1156 if (ASIC_IS_AVIVO(rdev) &&
1157 (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) &&
1154 ((radeon_encoder->underscan_type == UNDERSCAN_ON) || 1158 ((radeon_encoder->underscan_type == UNDERSCAN_ON) ||
1155 ((radeon_encoder->underscan_type == UNDERSCAN_AUTO) && 1159 ((radeon_encoder->underscan_type == UNDERSCAN_AUTO) &&
1156 drm_detect_hdmi_monitor(radeon_connector->edid) && 1160 drm_detect_hdmi_monitor(radeon_connector->edid) &&
diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c
index c74a8b20d941..40b0c087b592 100644
--- a/drivers/gpu/drm/radeon/radeon_fb.c
+++ b/drivers/gpu/drm/radeon/radeon_fb.c
@@ -94,6 +94,7 @@ static void radeonfb_destroy_pinned_object(struct drm_gem_object *gobj)
94 ret = radeon_bo_reserve(rbo, false); 94 ret = radeon_bo_reserve(rbo, false);
95 if (likely(ret == 0)) { 95 if (likely(ret == 0)) {
96 radeon_bo_kunmap(rbo); 96 radeon_bo_kunmap(rbo);
97 radeon_bo_unpin(rbo);
97 radeon_bo_unreserve(rbo); 98 radeon_bo_unreserve(rbo);
98 } 99 }
99 drm_gem_object_unreference_unlocked(gobj); 100 drm_gem_object_unreference_unlocked(gobj);
@@ -325,8 +326,6 @@ static int radeon_fbdev_destroy(struct drm_device *dev, struct radeon_fbdev *rfb
325{ 326{
326 struct fb_info *info; 327 struct fb_info *info;
327 struct radeon_framebuffer *rfb = &rfbdev->rfb; 328 struct radeon_framebuffer *rfb = &rfbdev->rfb;
328 struct radeon_bo *rbo;
329 int r;
330 329
331 if (rfbdev->helper.fbdev) { 330 if (rfbdev->helper.fbdev) {
332 info = rfbdev->helper.fbdev; 331 info = rfbdev->helper.fbdev;
@@ -338,14 +337,8 @@ static int radeon_fbdev_destroy(struct drm_device *dev, struct radeon_fbdev *rfb
338 } 337 }
339 338
340 if (rfb->obj) { 339 if (rfb->obj) {
341 rbo = rfb->obj->driver_private; 340 radeonfb_destroy_pinned_object(rfb->obj);
342 r = radeon_bo_reserve(rbo, false); 341 rfb->obj = NULL;
343 if (likely(r == 0)) {
344 radeon_bo_kunmap(rbo);
345 radeon_bo_unpin(rbo);
346 radeon_bo_unreserve(rbo);
347 }
348 drm_gem_object_unreference_unlocked(rfb->obj);
349 } 342 }
350 drm_fb_helper_fini(&rfbdev->helper); 343 drm_fb_helper_fini(&rfbdev->helper);
351 drm_framebuffer_cleanup(&rfb->base); 344 drm_framebuffer_cleanup(&rfb->base);
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index c578f265b24c..d1e595d91723 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -201,11 +201,11 @@ int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
201 return r; 201 return r;
202 } 202 }
203 r = drm_gem_handle_create(filp, gobj, &handle); 203 r = drm_gem_handle_create(filp, gobj, &handle);
204 /* drop reference from allocate - handle holds it now */
205 drm_gem_object_unreference_unlocked(gobj);
204 if (r) { 206 if (r) {
205 drm_gem_object_unreference_unlocked(gobj);
206 return r; 207 return r;
207 } 208 }
208 drm_gem_object_handle_unreference_unlocked(gobj);
209 args->handle = handle; 209 args->handle = handle;
210 return 0; 210 return 0;
211} 211}
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 5eee3c41d124..8fbbe1c6ebbd 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -203,6 +203,10 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
203 */ 203 */
204int radeon_driver_firstopen_kms(struct drm_device *dev) 204int radeon_driver_firstopen_kms(struct drm_device *dev)
205{ 205{
206 struct radeon_device *rdev = dev->dev_private;
207
208 if (rdev->powered_down)
209 return -EINVAL;
206 return 0; 210 return 0;
207} 211}
208 212
diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h
index efbe975312dc..17a6602b5885 100644
--- a/drivers/gpu/drm/radeon/radeon_mode.h
+++ b/drivers/gpu/drm/radeon/radeon_mode.h
@@ -204,7 +204,7 @@ struct radeon_i2c_chan {
204 204
205/* mostly for macs, but really any system without connector tables */ 205/* mostly for macs, but really any system without connector tables */
206enum radeon_connector_table { 206enum radeon_connector_table {
207 CT_NONE, 207 CT_NONE = 0,
208 CT_GENERIC, 208 CT_GENERIC,
209 CT_IBOOK, 209 CT_IBOOK,
210 CT_POWERBOOK_EXTERNAL, 210 CT_POWERBOOK_EXTERNAL,
@@ -215,6 +215,7 @@ enum radeon_connector_table {
215 CT_IMAC_G5_ISIGHT, 215 CT_IMAC_G5_ISIGHT,
216 CT_EMAC, 216 CT_EMAC,
217 CT_RN50_POWER, 217 CT_RN50_POWER,
218 CT_MAC_X800,
218}; 219};
219 220
220enum radeon_dvo_chip { 221enum radeon_dvo_chip {
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 0afd1e62347d..b3b5306bb578 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -69,7 +69,7 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
69 u32 c = 0; 69 u32 c = 0;
70 70
71 rbo->placement.fpfn = 0; 71 rbo->placement.fpfn = 0;
72 rbo->placement.lpfn = 0; 72 rbo->placement.lpfn = rbo->rdev->mc.active_vram_size >> PAGE_SHIFT;
73 rbo->placement.placement = rbo->placements; 73 rbo->placement.placement = rbo->placements;
74 rbo->placement.busy_placement = rbo->placements; 74 rbo->placement.busy_placement = rbo->placements;
75 if (domain & RADEON_GEM_DOMAIN_VRAM) 75 if (domain & RADEON_GEM_DOMAIN_VRAM)
diff --git a/drivers/gpu/drm/radeon/radeon_object.h b/drivers/gpu/drm/radeon/radeon_object.h
index 353998dc2c03..3481bc7f6f58 100644
--- a/drivers/gpu/drm/radeon/radeon_object.h
+++ b/drivers/gpu/drm/radeon/radeon_object.h
@@ -124,11 +124,8 @@ static inline int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type,
124 int r; 124 int r;
125 125
126 r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0); 126 r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, 0);
127 if (unlikely(r != 0)) { 127 if (unlikely(r != 0))
128 if (r != -ERESTARTSYS)
129 dev_err(bo->rdev->dev, "%p reserve failed for wait\n", bo);
130 return r; 128 return r;
131 }
132 spin_lock(&bo->tbo.lock); 129 spin_lock(&bo->tbo.lock);
133 if (mem_type) 130 if (mem_type)
134 *mem_type = bo->tbo.mem.mem_type; 131 *mem_type = bo->tbo.mem.mem_type;
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index cc05b230d7ef..51d5f7b5ab21 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -693,6 +693,7 @@ void rs600_mc_init(struct radeon_device *rdev)
693 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE); 693 rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
694 rdev->mc.mc_vram_size = rdev->mc.real_vram_size; 694 rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
695 rdev->mc.visible_vram_size = rdev->mc.aper_size; 695 rdev->mc.visible_vram_size = rdev->mc.aper_size;
696 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
696 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev); 697 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
697 base = RREG32_MC(R_000004_MC_FB_LOCATION); 698 base = RREG32_MC(R_000004_MC_FB_LOCATION);
698 base = G_000004_MC_FB_START(base) << 16; 699 base = G_000004_MC_FB_START(base) << 16;
diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
index 3e3f75718be3..4dc2a87ea680 100644
--- a/drivers/gpu/drm/radeon/rs690.c
+++ b/drivers/gpu/drm/radeon/rs690.c
@@ -157,6 +157,7 @@ void rs690_mc_init(struct radeon_device *rdev)
157 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0); 157 rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
158 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0); 158 rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
159 rdev->mc.visible_vram_size = rdev->mc.aper_size; 159 rdev->mc.visible_vram_size = rdev->mc.aper_size;
160 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
160 base = RREG32_MC(R_000100_MCCFG_FB_LOCATION); 161 base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
161 base = G_000100_MC_FB_START(base) << 16; 162 base = G_000100_MC_FB_START(base) << 16;
162 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev); 163 rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
diff --git a/drivers/gpu/drm/radeon/rv770.c b/drivers/gpu/drm/radeon/rv770.c
index bfa59db374d2..9490da700749 100644
--- a/drivers/gpu/drm/radeon/rv770.c
+++ b/drivers/gpu/drm/radeon/rv770.c
@@ -267,6 +267,7 @@ static void rv770_mc_program(struct radeon_device *rdev)
267 */ 267 */
268void r700_cp_stop(struct radeon_device *rdev) 268void r700_cp_stop(struct radeon_device *rdev)
269{ 269{
270 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
270 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT)); 271 WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
271} 272}
272 273
@@ -992,6 +993,7 @@ int rv770_mc_init(struct radeon_device *rdev)
992 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE); 993 rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
993 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE); 994 rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
994 rdev->mc.visible_vram_size = rdev->mc.aper_size; 995 rdev->mc.visible_vram_size = rdev->mc.aper_size;
996 rdev->mc.active_vram_size = rdev->mc.visible_vram_size;
995 r600_vram_gtt_location(rdev, &rdev->mc); 997 r600_vram_gtt_location(rdev, &rdev->mc);
996 radeon_update_bandwidth_info(rdev); 998 radeon_update_bandwidth_info(rdev);
997 999
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index cb4cf7ef4d1e..db809e034cc4 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -442,6 +442,43 @@ out_err:
442} 442}
443 443
444/** 444/**
445 * Call bo::reserved and with the lru lock held.
446 * Will release GPU memory type usage on destruction.
447 * This is the place to put in driver specific hooks.
448 * Will release the bo::reserved lock and the
449 * lru lock on exit.
450 */
451
452static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
453{
454 struct ttm_bo_global *glob = bo->glob;
455
456 if (bo->ttm) {
457
458 /**
459 * Release the lru_lock, since we don't want to have
460 * an atomic requirement on ttm_tt[unbind|destroy].
461 */
462
463 spin_unlock(&glob->lru_lock);
464 ttm_tt_unbind(bo->ttm);
465 ttm_tt_destroy(bo->ttm);
466 bo->ttm = NULL;
467 spin_lock(&glob->lru_lock);
468 }
469
470 if (bo->mem.mm_node) {
471 drm_mm_put_block(bo->mem.mm_node);
472 bo->mem.mm_node = NULL;
473 }
474
475 atomic_set(&bo->reserved, 0);
476 wake_up_all(&bo->event_queue);
477 spin_unlock(&glob->lru_lock);
478}
479
480
481/**
445 * If bo idle, remove from delayed- and lru lists, and unref. 482 * If bo idle, remove from delayed- and lru lists, and unref.
446 * If not idle, and already on delayed list, do nothing. 483 * If not idle, and already on delayed list, do nothing.
447 * If not idle, and not on delayed list, put on delayed list, 484 * If not idle, and not on delayed list, put on delayed list,
@@ -456,6 +493,7 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo, bool remove_all)
456 int ret; 493 int ret;
457 494
458 spin_lock(&bo->lock); 495 spin_lock(&bo->lock);
496retry:
459 (void) ttm_bo_wait(bo, false, false, !remove_all); 497 (void) ttm_bo_wait(bo, false, false, !remove_all);
460 498
461 if (!bo->sync_obj) { 499 if (!bo->sync_obj) {
@@ -464,31 +502,52 @@ static int ttm_bo_cleanup_refs(struct ttm_buffer_object *bo, bool remove_all)
464 spin_unlock(&bo->lock); 502 spin_unlock(&bo->lock);
465 503
466 spin_lock(&glob->lru_lock); 504 spin_lock(&glob->lru_lock);
467 put_count = ttm_bo_del_from_lru(bo); 505 ret = ttm_bo_reserve_locked(bo, false, !remove_all, false, 0);
506
507 /**
508 * Someone else has the object reserved. Bail and retry.
509 */
468 510
469 ret = ttm_bo_reserve_locked(bo, false, false, false, 0); 511 if (unlikely(ret == -EBUSY)) {
470 BUG_ON(ret); 512 spin_unlock(&glob->lru_lock);
471 if (bo->ttm) 513 spin_lock(&bo->lock);
472 ttm_tt_unbind(bo->ttm); 514 goto requeue;
515 }
516
517 /**
518 * We can re-check for sync object without taking
519 * the bo::lock since setting the sync object requires
520 * also bo::reserved. A busy object at this point may
521 * be caused by another thread starting an accelerated
522 * eviction.
523 */
524
525 if (unlikely(bo->sync_obj)) {
526 atomic_set(&bo->reserved, 0);
527 wake_up_all(&bo->event_queue);
528 spin_unlock(&glob->lru_lock);
529 spin_lock(&bo->lock);
530 if (remove_all)
531 goto retry;
532 else
533 goto requeue;
534 }
535
536 put_count = ttm_bo_del_from_lru(bo);
473 537
474 if (!list_empty(&bo->ddestroy)) { 538 if (!list_empty(&bo->ddestroy)) {
475 list_del_init(&bo->ddestroy); 539 list_del_init(&bo->ddestroy);
476 ++put_count; 540 ++put_count;
477 } 541 }
478 if (bo->mem.mm_node) {
479 drm_mm_put_block(bo->mem.mm_node);
480 bo->mem.mm_node = NULL;
481 }
482 spin_unlock(&glob->lru_lock);
483 542
484 atomic_set(&bo->reserved, 0); 543 ttm_bo_cleanup_memtype_use(bo);
485 544
486 while (put_count--) 545 while (put_count--)
487 kref_put(&bo->list_kref, ttm_bo_ref_bug); 546 kref_put(&bo->list_kref, ttm_bo_ref_bug);
488 547
489 return 0; 548 return 0;
490 } 549 }
491 550requeue:
492 spin_lock(&glob->lru_lock); 551 spin_lock(&glob->lru_lock);
493 if (list_empty(&bo->ddestroy)) { 552 if (list_empty(&bo->ddestroy)) {
494 void *sync_obj = bo->sync_obj; 553 void *sync_obj = bo->sync_obj;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 7cffb3e04232..3451a82adba7 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -351,6 +351,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo,
351 INIT_LIST_HEAD(&fbo->lru); 351 INIT_LIST_HEAD(&fbo->lru);
352 INIT_LIST_HEAD(&fbo->swap); 352 INIT_LIST_HEAD(&fbo->swap);
353 fbo->vm_node = NULL; 353 fbo->vm_node = NULL;
354 atomic_set(&fbo->cpu_writers, 0);
354 355
355 fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj); 356 fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj);
356 kref_init(&fbo->list_kref); 357 kref_init(&fbo->list_kref);
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index ca904799f018..b1e02fffd3cc 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -69,7 +69,7 @@ struct ttm_page_pool {
69 spinlock_t lock; 69 spinlock_t lock;
70 bool fill_lock; 70 bool fill_lock;
71 struct list_head list; 71 struct list_head list;
72 int gfp_flags; 72 gfp_t gfp_flags;
73 unsigned npages; 73 unsigned npages;
74 char *name; 74 char *name;
75 unsigned long nfrees; 75 unsigned long nfrees;
@@ -475,7 +475,7 @@ static void ttm_handle_caching_state_failure(struct list_head *pages,
475 * This function is reentrant if caller updates count depending on number of 475 * This function is reentrant if caller updates count depending on number of
476 * pages returned in pages array. 476 * pages returned in pages array.
477 */ 477 */
478static int ttm_alloc_new_pages(struct list_head *pages, int gfp_flags, 478static int ttm_alloc_new_pages(struct list_head *pages, gfp_t gfp_flags,
479 int ttm_flags, enum ttm_caching_state cstate, unsigned count) 479 int ttm_flags, enum ttm_caching_state cstate, unsigned count)
480{ 480{
481 struct page **caching_array; 481 struct page **caching_array;
@@ -666,7 +666,7 @@ int ttm_get_pages(struct list_head *pages, int flags,
666{ 666{
667 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); 667 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
668 struct page *p = NULL; 668 struct page *p = NULL;
669 int gfp_flags = GFP_USER; 669 gfp_t gfp_flags = GFP_USER;
670 int r; 670 int r;
671 671
672 /* set zero flag for page allocation if required */ 672 /* set zero flag for page allocation if required */
@@ -818,7 +818,7 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
818 return 0; 818 return 0;
819} 819}
820 820
821void ttm_page_alloc_fini() 821void ttm_page_alloc_fini(void)
822{ 822{
823 int i; 823 int i;
824 824
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index d237190b888a..2ef93df9e8ae 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -148,13 +148,16 @@ static struct pci_device_id vmw_pci_id_list[] = {
148 {0, 0, 0} 148 {0, 0, 0}
149}; 149};
150 150
151static char *vmw_devname = "vmwgfx"; 151static int enable_fbdev;
152 152
153static int vmw_probe(struct pci_dev *, const struct pci_device_id *); 153static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
154static void vmw_master_init(struct vmw_master *); 154static void vmw_master_init(struct vmw_master *);
155static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val, 155static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
156 void *ptr); 156 void *ptr);
157 157
158MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
159module_param_named(enable_fbdev, enable_fbdev, int, 0600);
160
158static void vmw_print_capabilities(uint32_t capabilities) 161static void vmw_print_capabilities(uint32_t capabilities)
159{ 162{
160 DRM_INFO("Capabilities:\n"); 163 DRM_INFO("Capabilities:\n");
@@ -192,8 +195,6 @@ static int vmw_request_device(struct vmw_private *dev_priv)
192{ 195{
193 int ret; 196 int ret;
194 197
195 vmw_kms_save_vga(dev_priv);
196
197 ret = vmw_fifo_init(dev_priv, &dev_priv->fifo); 198 ret = vmw_fifo_init(dev_priv, &dev_priv->fifo);
198 if (unlikely(ret != 0)) { 199 if (unlikely(ret != 0)) {
199 DRM_ERROR("Unable to initialize FIFO.\n"); 200 DRM_ERROR("Unable to initialize FIFO.\n");
@@ -206,9 +207,35 @@ static int vmw_request_device(struct vmw_private *dev_priv)
206static void vmw_release_device(struct vmw_private *dev_priv) 207static void vmw_release_device(struct vmw_private *dev_priv)
207{ 208{
208 vmw_fifo_release(dev_priv, &dev_priv->fifo); 209 vmw_fifo_release(dev_priv, &dev_priv->fifo);
209 vmw_kms_restore_vga(dev_priv);
210} 210}
211 211
212int vmw_3d_resource_inc(struct vmw_private *dev_priv)
213{
214 int ret = 0;
215
216 mutex_lock(&dev_priv->release_mutex);
217 if (unlikely(dev_priv->num_3d_resources++ == 0)) {
218 ret = vmw_request_device(dev_priv);
219 if (unlikely(ret != 0))
220 --dev_priv->num_3d_resources;
221 }
222 mutex_unlock(&dev_priv->release_mutex);
223 return ret;
224}
225
226
227void vmw_3d_resource_dec(struct vmw_private *dev_priv)
228{
229 int32_t n3d;
230
231 mutex_lock(&dev_priv->release_mutex);
232 if (unlikely(--dev_priv->num_3d_resources == 0))
233 vmw_release_device(dev_priv);
234 n3d = (int32_t) dev_priv->num_3d_resources;
235 mutex_unlock(&dev_priv->release_mutex);
236
237 BUG_ON(n3d < 0);
238}
212 239
213static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) 240static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
214{ 241{
@@ -228,6 +255,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
228 dev_priv->last_read_sequence = (uint32_t) -100; 255 dev_priv->last_read_sequence = (uint32_t) -100;
229 mutex_init(&dev_priv->hw_mutex); 256 mutex_init(&dev_priv->hw_mutex);
230 mutex_init(&dev_priv->cmdbuf_mutex); 257 mutex_init(&dev_priv->cmdbuf_mutex);
258 mutex_init(&dev_priv->release_mutex);
231 rwlock_init(&dev_priv->resource_lock); 259 rwlock_init(&dev_priv->resource_lock);
232 idr_init(&dev_priv->context_idr); 260 idr_init(&dev_priv->context_idr);
233 idr_init(&dev_priv->surface_idr); 261 idr_init(&dev_priv->surface_idr);
@@ -244,6 +272,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
244 dev_priv->vram_start = pci_resource_start(dev->pdev, 1); 272 dev_priv->vram_start = pci_resource_start(dev->pdev, 1);
245 dev_priv->mmio_start = pci_resource_start(dev->pdev, 2); 273 dev_priv->mmio_start = pci_resource_start(dev->pdev, 2);
246 274
275 dev_priv->enable_fb = enable_fbdev;
276
247 mutex_lock(&dev_priv->hw_mutex); 277 mutex_lock(&dev_priv->hw_mutex);
248 278
249 vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2); 279 vmw_write(dev_priv, SVGA_REG_ID, SVGA_ID_2);
@@ -343,17 +373,6 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
343 373
344 dev->dev_private = dev_priv; 374 dev->dev_private = dev_priv;
345 375
346 if (!dev->devname)
347 dev->devname = vmw_devname;
348
349 if (dev_priv->capabilities & SVGA_CAP_IRQMASK) {
350 ret = drm_irq_install(dev);
351 if (unlikely(ret != 0)) {
352 DRM_ERROR("Failed installing irq: %d\n", ret);
353 goto out_no_irq;
354 }
355 }
356
357 ret = pci_request_regions(dev->pdev, "vmwgfx probe"); 376 ret = pci_request_regions(dev->pdev, "vmwgfx probe");
358 dev_priv->stealth = (ret != 0); 377 dev_priv->stealth = (ret != 0);
359 if (dev_priv->stealth) { 378 if (dev_priv->stealth) {
@@ -369,26 +388,52 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
369 goto out_no_device; 388 goto out_no_device;
370 } 389 }
371 } 390 }
372 ret = vmw_request_device(dev_priv); 391 ret = vmw_kms_init(dev_priv);
373 if (unlikely(ret != 0)) 392 if (unlikely(ret != 0))
374 goto out_no_device; 393 goto out_no_kms;
375 vmw_kms_init(dev_priv);
376 vmw_overlay_init(dev_priv); 394 vmw_overlay_init(dev_priv);
377 vmw_fb_init(dev_priv); 395 if (dev_priv->enable_fb) {
396 ret = vmw_3d_resource_inc(dev_priv);
397 if (unlikely(ret != 0))
398 goto out_no_fifo;
399 vmw_kms_save_vga(dev_priv);
400 vmw_fb_init(dev_priv);
401 DRM_INFO("%s", vmw_fifo_have_3d(dev_priv) ?
402 "Detected device 3D availability.\n" :
403 "Detected no device 3D availability.\n");
404 } else {
405 DRM_INFO("Delayed 3D detection since we're not "
406 "running the device in SVGA mode yet.\n");
407 }
408
409 if (dev_priv->capabilities & SVGA_CAP_IRQMASK) {
410 ret = drm_irq_install(dev);
411 if (unlikely(ret != 0)) {
412 DRM_ERROR("Failed installing irq: %d\n", ret);
413 goto out_no_irq;
414 }
415 }
378 416
379 dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier; 417 dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier;
380 register_pm_notifier(&dev_priv->pm_nb); 418 register_pm_notifier(&dev_priv->pm_nb);
381 419
382 DRM_INFO("%s", vmw_fifo_have_3d(dev_priv) ? "Have 3D\n" : "No 3D\n");
383
384 return 0; 420 return 0;
385 421
386out_no_device:
387 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
388 drm_irq_uninstall(dev_priv->dev);
389 if (dev->devname == vmw_devname)
390 dev->devname = NULL;
391out_no_irq: 422out_no_irq:
423 if (dev_priv->enable_fb) {
424 vmw_fb_close(dev_priv);
425 vmw_kms_restore_vga(dev_priv);
426 vmw_3d_resource_dec(dev_priv);
427 }
428out_no_fifo:
429 vmw_overlay_close(dev_priv);
430 vmw_kms_close(dev_priv);
431out_no_kms:
432 if (dev_priv->stealth)
433 pci_release_region(dev->pdev, 2);
434 else
435 pci_release_regions(dev->pdev);
436out_no_device:
392 ttm_object_device_release(&dev_priv->tdev); 437 ttm_object_device_release(&dev_priv->tdev);
393out_err4: 438out_err4:
394 iounmap(dev_priv->mmio_virt); 439 iounmap(dev_priv->mmio_virt);
@@ -415,19 +460,20 @@ static int vmw_driver_unload(struct drm_device *dev)
415 460
416 unregister_pm_notifier(&dev_priv->pm_nb); 461 unregister_pm_notifier(&dev_priv->pm_nb);
417 462
418 vmw_fb_close(dev_priv); 463 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
464 drm_irq_uninstall(dev_priv->dev);
465 if (dev_priv->enable_fb) {
466 vmw_fb_close(dev_priv);
467 vmw_kms_restore_vga(dev_priv);
468 vmw_3d_resource_dec(dev_priv);
469 }
419 vmw_kms_close(dev_priv); 470 vmw_kms_close(dev_priv);
420 vmw_overlay_close(dev_priv); 471 vmw_overlay_close(dev_priv);
421 vmw_release_device(dev_priv);
422 if (dev_priv->stealth) 472 if (dev_priv->stealth)
423 pci_release_region(dev->pdev, 2); 473 pci_release_region(dev->pdev, 2);
424 else 474 else
425 pci_release_regions(dev->pdev); 475 pci_release_regions(dev->pdev);
426 476
427 if (dev_priv->capabilities & SVGA_CAP_IRQMASK)
428 drm_irq_uninstall(dev_priv->dev);
429 if (dev->devname == vmw_devname)
430 dev->devname = NULL;
431 ttm_object_device_release(&dev_priv->tdev); 477 ttm_object_device_release(&dev_priv->tdev);
432 iounmap(dev_priv->mmio_virt); 478 iounmap(dev_priv->mmio_virt);
433 drm_mtrr_del(dev_priv->mmio_mtrr, dev_priv->mmio_start, 479 drm_mtrr_del(dev_priv->mmio_mtrr, dev_priv->mmio_start,
@@ -500,7 +546,7 @@ static long vmw_unlocked_ioctl(struct file *filp, unsigned int cmd,
500 struct drm_ioctl_desc *ioctl = 546 struct drm_ioctl_desc *ioctl =
501 &vmw_ioctls[nr - DRM_COMMAND_BASE]; 547 &vmw_ioctls[nr - DRM_COMMAND_BASE];
502 548
503 if (unlikely(ioctl->cmd != cmd)) { 549 if (unlikely(ioctl->cmd_drv != cmd)) {
504 DRM_ERROR("Invalid command format, ioctl %d\n", 550 DRM_ERROR("Invalid command format, ioctl %d\n",
505 nr - DRM_COMMAND_BASE); 551 nr - DRM_COMMAND_BASE);
506 return -EINVAL; 552 return -EINVAL;
@@ -589,6 +635,16 @@ static int vmw_master_set(struct drm_device *dev,
589 struct vmw_master *vmaster = vmw_master(file_priv->master); 635 struct vmw_master *vmaster = vmw_master(file_priv->master);
590 int ret = 0; 636 int ret = 0;
591 637
638 if (!dev_priv->enable_fb) {
639 ret = vmw_3d_resource_inc(dev_priv);
640 if (unlikely(ret != 0))
641 return ret;
642 vmw_kms_save_vga(dev_priv);
643 mutex_lock(&dev_priv->hw_mutex);
644 vmw_write(dev_priv, SVGA_REG_TRACES, 0);
645 mutex_unlock(&dev_priv->hw_mutex);
646 }
647
592 if (active) { 648 if (active) {
593 BUG_ON(active != &dev_priv->fbdev_master); 649 BUG_ON(active != &dev_priv->fbdev_master);
594 ret = ttm_vt_lock(&active->lock, false, vmw_fp->tfile); 650 ret = ttm_vt_lock(&active->lock, false, vmw_fp->tfile);
@@ -617,7 +673,13 @@ static int vmw_master_set(struct drm_device *dev,
617 return 0; 673 return 0;
618 674
619out_no_active_lock: 675out_no_active_lock:
620 vmw_release_device(dev_priv); 676 if (!dev_priv->enable_fb) {
677 mutex_lock(&dev_priv->hw_mutex);
678 vmw_write(dev_priv, SVGA_REG_TRACES, 1);
679 mutex_unlock(&dev_priv->hw_mutex);
680 vmw_kms_restore_vga(dev_priv);
681 vmw_3d_resource_dec(dev_priv);
682 }
621 return ret; 683 return ret;
622} 684}
623 685
@@ -645,11 +707,23 @@ static void vmw_master_drop(struct drm_device *dev,
645 707
646 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM); 708 ttm_lock_set_kill(&vmaster->lock, true, SIGTERM);
647 709
710 if (!dev_priv->enable_fb) {
711 ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM);
712 if (unlikely(ret != 0))
713 DRM_ERROR("Unable to clean VRAM on master drop.\n");
714 mutex_lock(&dev_priv->hw_mutex);
715 vmw_write(dev_priv, SVGA_REG_TRACES, 1);
716 mutex_unlock(&dev_priv->hw_mutex);
717 vmw_kms_restore_vga(dev_priv);
718 vmw_3d_resource_dec(dev_priv);
719 }
720
648 dev_priv->active_master = &dev_priv->fbdev_master; 721 dev_priv->active_master = &dev_priv->fbdev_master;
649 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM); 722 ttm_lock_set_kill(&dev_priv->fbdev_master.lock, false, SIGTERM);
650 ttm_vt_unlock(&dev_priv->fbdev_master.lock); 723 ttm_vt_unlock(&dev_priv->fbdev_master.lock);
651 724
652 vmw_fb_on(dev_priv); 725 if (dev_priv->enable_fb)
726 vmw_fb_on(dev_priv);
653} 727}
654 728
655 729
@@ -722,6 +796,7 @@ static struct drm_driver driver = {
722 .irq_postinstall = vmw_irq_postinstall, 796 .irq_postinstall = vmw_irq_postinstall,
723 .irq_uninstall = vmw_irq_uninstall, 797 .irq_uninstall = vmw_irq_uninstall,
724 .irq_handler = vmw_irq_handler, 798 .irq_handler = vmw_irq_handler,
799 .get_vblank_counter = vmw_get_vblank_counter,
725 .reclaim_buffers_locked = NULL, 800 .reclaim_buffers_locked = NULL,
726 .get_map_ofs = drm_core_get_map_ofs, 801 .get_map_ofs = drm_core_get_map_ofs,
727 .get_reg_ofs = drm_core_get_reg_ofs, 802 .get_reg_ofs = drm_core_get_reg_ofs,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 429f917b60bf..58de6393f611 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -277,6 +277,7 @@ struct vmw_private {
277 277
278 bool stealth; 278 bool stealth;
279 bool is_opened; 279 bool is_opened;
280 bool enable_fb;
280 281
281 /** 282 /**
282 * Master management. 283 * Master management.
@@ -285,6 +286,9 @@ struct vmw_private {
285 struct vmw_master *active_master; 286 struct vmw_master *active_master;
286 struct vmw_master fbdev_master; 287 struct vmw_master fbdev_master;
287 struct notifier_block pm_nb; 288 struct notifier_block pm_nb;
289
290 struct mutex release_mutex;
291 uint32_t num_3d_resources;
288}; 292};
289 293
290static inline struct vmw_private *vmw_priv(struct drm_device *dev) 294static inline struct vmw_private *vmw_priv(struct drm_device *dev)
@@ -319,6 +323,9 @@ static inline uint32_t vmw_read(struct vmw_private *dev_priv,
319 return val; 323 return val;
320} 324}
321 325
326int vmw_3d_resource_inc(struct vmw_private *dev_priv);
327void vmw_3d_resource_dec(struct vmw_private *dev_priv);
328
322/** 329/**
323 * GMR utilities - vmwgfx_gmr.c 330 * GMR utilities - vmwgfx_gmr.c
324 */ 331 */
@@ -511,6 +518,7 @@ void vmw_kms_write_svga(struct vmw_private *vmw_priv,
511 unsigned bbp, unsigned depth); 518 unsigned bbp, unsigned depth);
512int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, 519int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
513 struct drm_file *file_priv); 520 struct drm_file *file_priv);
521u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
514 522
515/** 523/**
516 * Overlay control - vmwgfx_overlay.c 524 * Overlay control - vmwgfx_overlay.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index 870967a97c15..409e172f4abf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -615,6 +615,11 @@ int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
615 if (unlikely(ret != 0)) 615 if (unlikely(ret != 0))
616 goto err_unlock; 616 goto err_unlock;
617 617
618 if (bo->mem.mem_type == TTM_PL_VRAM &&
619 bo->mem.mm_node->start < bo->num_pages)
620 (void) ttm_bo_validate(bo, &vmw_sys_placement, false,
621 false, false);
622
618 ret = ttm_bo_validate(bo, &ne_placement, false, false, false); 623 ret = ttm_bo_validate(bo, &ne_placement, false, false, false);
619 624
620 /* Could probably bug on */ 625 /* Could probably bug on */
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
index e6a1eb7ea954..0fe31766e4cf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
@@ -106,6 +106,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
106 mutex_lock(&dev_priv->hw_mutex); 106 mutex_lock(&dev_priv->hw_mutex);
107 dev_priv->enable_state = vmw_read(dev_priv, SVGA_REG_ENABLE); 107 dev_priv->enable_state = vmw_read(dev_priv, SVGA_REG_ENABLE);
108 dev_priv->config_done_state = vmw_read(dev_priv, SVGA_REG_CONFIG_DONE); 108 dev_priv->config_done_state = vmw_read(dev_priv, SVGA_REG_CONFIG_DONE);
109 dev_priv->traces_state = vmw_read(dev_priv, SVGA_REG_TRACES);
109 vmw_write(dev_priv, SVGA_REG_ENABLE, 1); 110 vmw_write(dev_priv, SVGA_REG_ENABLE, 1);
110 111
111 min = 4; 112 min = 4;
@@ -175,6 +176,8 @@ void vmw_fifo_release(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
175 dev_priv->config_done_state); 176 dev_priv->config_done_state);
176 vmw_write(dev_priv, SVGA_REG_ENABLE, 177 vmw_write(dev_priv, SVGA_REG_ENABLE,
177 dev_priv->enable_state); 178 dev_priv->enable_state);
179 vmw_write(dev_priv, SVGA_REG_TRACES,
180 dev_priv->traces_state);
178 181
179 mutex_unlock(&dev_priv->hw_mutex); 182 mutex_unlock(&dev_priv->hw_mutex);
180 vmw_fence_queue_takedown(&fifo->fence_queue); 183 vmw_fence_queue_takedown(&fifo->fence_queue);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
index 64d7f47df868..e882ba099f0c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -898,7 +898,19 @@ int vmw_kms_save_vga(struct vmw_private *vmw_priv)
898 save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH); 898 save->width = vmw_read(vmw_priv, SVGA_REG_DISPLAY_WIDTH);
899 save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT); 899 save->height = vmw_read(vmw_priv, SVGA_REG_DISPLAY_HEIGHT);
900 vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID); 900 vmw_write(vmw_priv, SVGA_REG_DISPLAY_ID, SVGA_ID_INVALID);
901 if (i == 0 && vmw_priv->num_displays == 1 &&
902 save->width == 0 && save->height == 0) {
903
904 /*
905 * It should be fairly safe to assume that these
906 * values are uninitialized.
907 */
908
909 save->width = vmw_priv->vga_width - save->pos_x;
910 save->height = vmw_priv->vga_height - save->pos_y;
911 }
901 } 912 }
913
902 return 0; 914 return 0;
903} 915}
904 916
@@ -984,3 +996,8 @@ out_unlock:
984 ttm_read_unlock(&vmaster->lock); 996 ttm_read_unlock(&vmaster->lock);
985 return ret; 997 return ret;
986} 998}
999
1000u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc)
1001{
1002 return 0;
1003}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
index 2ff5cf78235f..11cb39e3accb 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c
@@ -27,6 +27,8 @@
27 27
28#include "vmwgfx_kms.h" 28#include "vmwgfx_kms.h"
29 29
30#define VMWGFX_LDU_NUM_DU 8
31
30#define vmw_crtc_to_ldu(x) \ 32#define vmw_crtc_to_ldu(x) \
31 container_of(x, struct vmw_legacy_display_unit, base.crtc) 33 container_of(x, struct vmw_legacy_display_unit, base.crtc)
32#define vmw_encoder_to_ldu(x) \ 34#define vmw_encoder_to_ldu(x) \
@@ -335,7 +337,8 @@ static void vmw_ldu_connector_restore(struct drm_connector *connector)
335} 337}
336 338
337static enum drm_connector_status 339static enum drm_connector_status
338 vmw_ldu_connector_detect(struct drm_connector *connector) 340 vmw_ldu_connector_detect(struct drm_connector *connector,
341 bool force)
339{ 342{
340 if (vmw_connector_to_ldu(connector)->pref_active) 343 if (vmw_connector_to_ldu(connector)->pref_active)
341 return connector_status_connected; 344 return connector_status_connected;
@@ -516,7 +519,7 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
516 519
517 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs, 520 drm_connector_init(dev, connector, &vmw_legacy_connector_funcs,
518 DRM_MODE_CONNECTOR_LVDS); 521 DRM_MODE_CONNECTOR_LVDS);
519 connector->status = vmw_ldu_connector_detect(connector); 522 connector->status = vmw_ldu_connector_detect(connector, true);
520 523
521 drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs, 524 drm_encoder_init(dev, encoder, &vmw_legacy_encoder_funcs,
522 DRM_MODE_ENCODER_LVDS); 525 DRM_MODE_ENCODER_LVDS);
@@ -535,6 +538,10 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
535 538
536int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv) 539int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv)
537{ 540{
541 struct drm_device *dev = dev_priv->dev;
542 int i;
543 int ret;
544
538 if (dev_priv->ldu_priv) { 545 if (dev_priv->ldu_priv) {
539 DRM_INFO("ldu system already on\n"); 546 DRM_INFO("ldu system already on\n");
540 return -EINVAL; 547 return -EINVAL;
@@ -552,23 +559,24 @@ int vmw_kms_init_legacy_display_system(struct vmw_private *dev_priv)
552 559
553 drm_mode_create_dirty_info_property(dev_priv->dev); 560 drm_mode_create_dirty_info_property(dev_priv->dev);
554 561
555 vmw_ldu_init(dev_priv, 0);
556 /* for old hardware without multimon only enable one display */
557 if (dev_priv->capabilities & SVGA_CAP_MULTIMON) { 562 if (dev_priv->capabilities & SVGA_CAP_MULTIMON) {
558 vmw_ldu_init(dev_priv, 1); 563 for (i = 0; i < VMWGFX_LDU_NUM_DU; ++i)
559 vmw_ldu_init(dev_priv, 2); 564 vmw_ldu_init(dev_priv, i);
560 vmw_ldu_init(dev_priv, 3); 565 ret = drm_vblank_init(dev, VMWGFX_LDU_NUM_DU);
561 vmw_ldu_init(dev_priv, 4); 566 } else {
562 vmw_ldu_init(dev_priv, 5); 567 /* for old hardware without multimon only enable one display */
563 vmw_ldu_init(dev_priv, 6); 568 vmw_ldu_init(dev_priv, 0);
564 vmw_ldu_init(dev_priv, 7); 569 ret = drm_vblank_init(dev, 1);
565 } 570 }
566 571
567 return 0; 572 return ret;
568} 573}
569 574
570int vmw_kms_close_legacy_display_system(struct vmw_private *dev_priv) 575int vmw_kms_close_legacy_display_system(struct vmw_private *dev_priv)
571{ 576{
577 struct drm_device *dev = dev_priv->dev;
578
579 drm_vblank_cleanup(dev);
572 if (!dev_priv->ldu_priv) 580 if (!dev_priv->ldu_priv)
573 return -ENOSYS; 581 return -ENOSYS;
574 582
@@ -610,7 +618,7 @@ int vmw_kms_ldu_update_layout(struct vmw_private *dev_priv, unsigned num,
610 ldu->pref_height = 600; 618 ldu->pref_height = 600;
611 ldu->pref_active = false; 619 ldu->pref_active = false;
612 } 620 }
613 con->status = vmw_ldu_connector_detect(con); 621 con->status = vmw_ldu_connector_detect(con, true);
614 } 622 }
615 623
616 mutex_unlock(&dev->mode_config.mutex); 624 mutex_unlock(&dev->mode_config.mutex);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
index 5f2d5df01e5c..c8c40e9979db 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c
@@ -211,6 +211,7 @@ static void vmw_hw_context_destroy(struct vmw_resource *res)
211 cmd->body.cid = cpu_to_le32(res->id); 211 cmd->body.cid = cpu_to_le32(res->id);
212 212
213 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 213 vmw_fifo_commit(dev_priv, sizeof(*cmd));
214 vmw_3d_resource_dec(dev_priv);
214} 215}
215 216
216static int vmw_context_init(struct vmw_private *dev_priv, 217static int vmw_context_init(struct vmw_private *dev_priv,
@@ -247,6 +248,7 @@ static int vmw_context_init(struct vmw_private *dev_priv,
247 cmd->body.cid = cpu_to_le32(res->id); 248 cmd->body.cid = cpu_to_le32(res->id);
248 249
249 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 250 vmw_fifo_commit(dev_priv, sizeof(*cmd));
251 (void) vmw_3d_resource_inc(dev_priv);
250 vmw_resource_activate(res, vmw_hw_context_destroy); 252 vmw_resource_activate(res, vmw_hw_context_destroy);
251 return 0; 253 return 0;
252} 254}
@@ -406,6 +408,7 @@ static void vmw_hw_surface_destroy(struct vmw_resource *res)
406 cmd->body.sid = cpu_to_le32(res->id); 408 cmd->body.sid = cpu_to_le32(res->id);
407 409
408 vmw_fifo_commit(dev_priv, sizeof(*cmd)); 410 vmw_fifo_commit(dev_priv, sizeof(*cmd));
411 vmw_3d_resource_dec(dev_priv);
409} 412}
410 413
411void vmw_surface_res_free(struct vmw_resource *res) 414void vmw_surface_res_free(struct vmw_resource *res)
@@ -473,6 +476,7 @@ int vmw_surface_init(struct vmw_private *dev_priv,
473 } 476 }
474 477
475 vmw_fifo_commit(dev_priv, submit_size); 478 vmw_fifo_commit(dev_priv, submit_size);
479 (void) vmw_3d_resource_inc(dev_priv);
476 vmw_resource_activate(res, vmw_hw_surface_destroy); 480 vmw_resource_activate(res, vmw_hw_surface_destroy);
477 return 0; 481 return 0;
478} 482}
diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
index 3b7e0acf8164..c380c65da417 100644
--- a/drivers/gpu/vga/vgaarb.c
+++ b/drivers/gpu/vga/vgaarb.c
@@ -598,7 +598,7 @@ static inline void vga_update_device_decodes(struct vga_device *vgadev,
598 pr_debug("vgaarb: decoding count now is: %d\n", vga_decode_count); 598 pr_debug("vgaarb: decoding count now is: %d\n", vga_decode_count);
599} 599}
600 600
601void __vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes, bool userspace) 601static void __vga_set_legacy_decoding(struct pci_dev *pdev, unsigned int decodes, bool userspace)
602{ 602{
603 struct vga_device *vgadev; 603 struct vga_device *vgadev;
604 unsigned long flags; 604 unsigned long flags;
diff --git a/drivers/hid/hid-cando.c b/drivers/hid/hid-cando.c
index 4267a6fdc277..5925bdcd417d 100644
--- a/drivers/hid/hid-cando.c
+++ b/drivers/hid/hid-cando.c
@@ -237,6 +237,8 @@ static const struct hid_device_id cando_devices[] = {
237 USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, 237 USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
238 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, 238 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
239 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, 239 USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
240 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO,
241 USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
240 { } 242 { }
241}; 243};
242MODULE_DEVICE_TABLE(hid, cando_devices); 244MODULE_DEVICE_TABLE(hid, cando_devices);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 0c52899be964..a0dea3d1296e 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1285,10 +1285,14 @@ static const struct hid_device_id hid_blacklist[] = {
1285 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1285 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1286 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1286 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1287 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1287 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1288 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
1289 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
1288 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) }, 1290 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1289 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 1291 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
1290 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) }, 1293 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH) },
1291 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) }, 1294 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6) },
1295 { HID_USB_DEVICE(USB_VENDOR_ID_CANDO, USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) }, 1296 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) }, 1297 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION_SOLAR) },
1294 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) }, 1298 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
@@ -1578,7 +1582,6 @@ static const struct hid_device_id hid_ignore_list[] = {
1578 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) }, 1582 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1579 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) }, 1583 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1580 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, 1584 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1581 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT)},
1582 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)}, 1585 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM)},
1583 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)}, 1586 { HID_USB_DEVICE(USB_VENDOR_ID_ASUSTEK, USB_DEVICE_ID_ASUSTEK_LCM2)},
1584 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, 1587 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 85c6d13c9ffa..c5ae5f1545bd 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -105,6 +105,7 @@
105 105
106#define USB_VENDOR_ID_ASUS 0x0486 106#define USB_VENDOR_ID_ASUS 0x0486
107#define USB_DEVICE_ID_ASUS_T91MT 0x0185 107#define USB_DEVICE_ID_ASUS_T91MT 0x0185
108#define USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO 0x0186
108 109
109#define USB_VENDOR_ID_ASUSTEK 0x0b05 110#define USB_VENDOR_ID_ASUSTEK 0x0b05
110#define USB_DEVICE_ID_ASUSTEK_LCM 0x1726 111#define USB_DEVICE_ID_ASUSTEK_LCM 0x1726
@@ -128,10 +129,12 @@
128 129
129#define USB_VENDOR_ID_BTC 0x046e 130#define USB_VENDOR_ID_BTC 0x046e
130#define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578 131#define USB_DEVICE_ID_BTC_EMPREX_REMOTE 0x5578
132#define USB_DEVICE_ID_BTC_EMPREX_REMOTE_2 0x5577
131 133
132#define USB_VENDOR_ID_CANDO 0x2087 134#define USB_VENDOR_ID_CANDO 0x2087
133#define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01 135#define USB_DEVICE_ID_CANDO_MULTI_TOUCH 0x0a01
134#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6 0x0b03 136#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_11_6 0x0b03
137#define USB_DEVICE_ID_CANDO_MULTI_TOUCH_15_6 0x0f01
135 138
136#define USB_VENDOR_ID_CH 0x068e 139#define USB_VENDOR_ID_CH 0x068e
137#define USB_DEVICE_ID_CH_PRO_PEDALS 0x00f2 140#define USB_DEVICE_ID_CH_PRO_PEDALS 0x00f2
@@ -149,6 +152,7 @@
149 152
150#define USB_VENDOR_ID_CHICONY 0x04f2 153#define USB_VENDOR_ID_CHICONY 0x04f2
151#define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418 154#define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
155#define USB_DEVICE_ID_CHICONY_MULTI_TOUCH 0xb19d
152 156
153#define USB_VENDOR_ID_CIDC 0x1677 157#define USB_VENDOR_ID_CIDC 0x1677
154 158
@@ -500,6 +504,7 @@
500 504
501#define USB_VENDOR_ID_TURBOX 0x062a 505#define USB_VENDOR_ID_TURBOX 0x062a
502#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201 506#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
507#define USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART 0x7100
503 508
504#define USB_VENDOR_ID_TWINHAN 0x6253 509#define USB_VENDOR_ID_TWINHAN 0x6253
505#define USB_DEVICE_ID_TWINHAN_IR_REMOTE 0x0100 510#define USB_DEVICE_ID_TWINHAN_IR_REMOTE 0x0100
@@ -507,6 +512,7 @@
507#define USB_VENDOR_ID_UCLOGIC 0x5543 512#define USB_VENDOR_ID_UCLOGIC 0x5543
508#define USB_DEVICE_ID_UCLOGIC_TABLET_PF1209 0x0042 513#define USB_DEVICE_ID_UCLOGIC_TABLET_PF1209 0x0042
509#define USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U 0x0003 514#define USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U 0x0003
515#define USB_DEVICE_ID_UCLOGIC_TABLET_KNA5 0x6001
510 516
511#define USB_VENDOR_ID_VERNIER 0x08f7 517#define USB_VENDOR_ID_VERNIER 0x08f7
512#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001 518#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
diff --git a/drivers/hid/hid-mosart.c b/drivers/hid/hid-mosart.c
index e91437c18906..ac5421d568f1 100644
--- a/drivers/hid/hid-mosart.c
+++ b/drivers/hid/hid-mosart.c
@@ -239,6 +239,7 @@ static void mosart_remove(struct hid_device *hdev)
239 239
240static const struct hid_device_id mosart_devices[] = { 240static const struct hid_device_id mosart_devices[] = {
241 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) }, 241 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
242 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUSTEK_MULTITOUCH_YFO) },
242 { } 243 { }
243}; 244};
244MODULE_DEVICE_TABLE(hid, mosart_devices); 245MODULE_DEVICE_TABLE(hid, mosart_devices);
diff --git a/drivers/hid/hid-topseed.c b/drivers/hid/hid-topseed.c
index 5771f851f856..956ed9ac19d4 100644
--- a/drivers/hid/hid-topseed.c
+++ b/drivers/hid/hid-topseed.c
@@ -64,6 +64,7 @@ static int ts_input_mapping(struct hid_device *hdev, struct hid_input *hi,
64static const struct hid_device_id ts_devices[] = { 64static const struct hid_device_id ts_devices[] = {
65 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) }, 65 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED, USB_DEVICE_ID_TOPSEED_CYBERLINK) },
66 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) }, 66 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE) },
67 { HID_USB_DEVICE(USB_VENDOR_ID_BTC, USB_DEVICE_ID_BTC_EMPREX_REMOTE_2) },
67 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) }, 68 { HID_USB_DEVICE(USB_VENDOR_ID_TOPSEED2, USB_DEVICE_ID_TOPSEED2_RF_COMBO) },
68 { } 69 { }
69}; 70};
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index bb98fa87aa86..925992f549f0 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -109,6 +109,12 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
109 int ret = 0; 109 int ret = 0;
110 110
111 mutex_lock(&minors_lock); 111 mutex_lock(&minors_lock);
112
113 if (!hidraw_table[minor]) {
114 ret = -ENODEV;
115 goto out;
116 }
117
112 dev = hidraw_table[minor]->hid; 118 dev = hidraw_table[minor]->hid;
113 119
114 if (!dev->hid_output_raw_report) { 120 if (!dev->hid_output_raw_report) {
@@ -244,6 +250,10 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
244 250
245 mutex_lock(&minors_lock); 251 mutex_lock(&minors_lock);
246 dev = hidraw_table[minor]; 252 dev = hidraw_table[minor];
253 if (!dev) {
254 ret = -ENODEV;
255 goto out;
256 }
247 257
248 switch (cmd) { 258 switch (cmd) {
249 case HIDIOCGRDESCSIZE: 259 case HIDIOCGRDESCSIZE:
@@ -317,6 +327,7 @@ static long hidraw_ioctl(struct file *file, unsigned int cmd,
317 327
318 ret = -ENOTTY; 328 ret = -ENOTTY;
319 } 329 }
330out:
320 mutex_unlock(&minors_lock); 331 mutex_unlock(&minors_lock);
321 return ret; 332 return ret;
322} 333}
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index b729c0286679..599041a7f670 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -828,6 +828,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
828 } 828 }
829 } else { 829 } else {
830 int skipped_report_id = 0; 830 int skipped_report_id = 0;
831 int report_id = buf[0];
831 if (buf[0] == 0x0) { 832 if (buf[0] == 0x0) {
832 /* Don't send the Report ID */ 833 /* Don't send the Report ID */
833 buf++; 834 buf++;
@@ -837,7 +838,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co
837 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 838 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
838 HID_REQ_SET_REPORT, 839 HID_REQ_SET_REPORT,
839 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, 840 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
840 ((report_type + 1) << 8) | *buf, 841 ((report_type + 1) << 8) | report_id,
841 interface->desc.bInterfaceNumber, buf, count, 842 interface->desc.bInterfaceNumber, buf, count,
842 USB_CTRL_SET_TIMEOUT); 843 USB_CTRL_SET_TIMEOUT);
843 /* count also the report id, if this was a numbered report. */ 844 /* count also the report id, if this was a numbered report. */
@@ -1445,6 +1446,11 @@ static const struct hid_device_id hid_usb_table[] = {
1445 { } 1446 { }
1446}; 1447};
1447 1448
1449struct usb_interface *usbhid_find_interface(int minor)
1450{
1451 return usb_find_interface(&hid_driver, minor);
1452}
1453
1448static struct hid_driver hid_usb_driver = { 1454static struct hid_driver hid_usb_driver = {
1449 .name = "generic-usb", 1455 .name = "generic-usb",
1450 .id_table = hid_usb_table, 1456 .id_table = hid_usb_table,
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 2643d3147621..f0260c699adb 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -33,8 +33,10 @@ static const struct hid_blacklist {
33 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, 33 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
34 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, 34 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
35 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 35 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
36 { USB_VENDOR_ID_DWAV, USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER, HID_QUIRK_MULTI_INPUT | HID_QUIRK_NOGET },
36 { USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH, HID_QUIRK_MULTI_INPUT }, 37 { USB_VENDOR_ID_DWAV, USB_DEVICE_ID_DWAV_EGALAX_MULTITOUCH, HID_QUIRK_MULTI_INPUT },
37 { USB_VENDOR_ID_MOJO, USB_DEVICE_ID_RETRO_ADAPTER, HID_QUIRK_MULTI_INPUT }, 38 { USB_VENDOR_ID_MOJO, USB_DEVICE_ID_RETRO_ADAPTER, HID_QUIRK_MULTI_INPUT },
39 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_TOUCHSCREEN_MOSART, HID_QUIRK_MULTI_INPUT },
38 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 40 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
39 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 41 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
40 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 42 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
@@ -69,6 +71,7 @@ static const struct hid_blacklist {
69 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 71 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
70 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT }, 72 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_PF1209, HID_QUIRK_MULTI_INPUT },
71 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U, HID_QUIRK_MULTI_INPUT }, 73 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_WP4030U, HID_QUIRK_MULTI_INPUT },
74 { USB_VENDOR_ID_UCLOGIC, USB_DEVICE_ID_UCLOGIC_TABLET_KNA5, HID_QUIRK_MULTI_INPUT },
72 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 75 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
73 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 76 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
74 77
@@ -77,6 +80,8 @@ static const struct hid_blacklist {
77 80
78 { USB_VENDOR_ID_PI_ENGINEERING, USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL, HID_QUIRK_HIDINPUT_FORCE }, 81 { USB_VENDOR_ID_PI_ENGINEERING, USB_DEVICE_ID_PI_ENGINEERING_VEC_USB_FOOTPEDAL, HID_QUIRK_HIDINPUT_FORCE },
79 82
83 { USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_MULTI_TOUCH, HID_QUIRK_MULTI_INPUT },
84
80 { 0, 0 } 85 { 0, 0 }
81}; 86};
82 87
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index e8f45d7ef3b2..dfcb27613ec5 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -270,7 +270,7 @@ static int hiddev_open(struct inode *inode, struct file *file)
270 struct hiddev *hiddev; 270 struct hiddev *hiddev;
271 int res; 271 int res;
272 272
273 intf = usb_find_interface(&hiddev_driver, iminor(inode)); 273 intf = usbhid_find_interface(iminor(inode));
274 if (!intf) 274 if (!intf)
275 return -ENODEV; 275 return -ENODEV;
276 hid = usb_get_intfdata(intf); 276 hid = usb_get_intfdata(intf);
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 693fd3e720df..89d2e847dcc6 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -42,6 +42,7 @@ void usbhid_submit_report
42(struct hid_device *hid, struct hid_report *report, unsigned char dir); 42(struct hid_device *hid, struct hid_report *report, unsigned char dir);
43int usbhid_get_power(struct hid_device *hid); 43int usbhid_get_power(struct hid_device *hid);
44void usbhid_put_power(struct hid_device *hid); 44void usbhid_put_power(struct hid_device *hid);
45struct usb_interface *usbhid_find_interface(int minor);
45 46
46/* iofl flags */ 47/* iofl flags */
47#define HID_CTRL_RUNNING 1 48#define HID_CTRL_RUNNING 1
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 4d4d09bdec0a..97499d00615a 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -409,7 +409,7 @@ config SENSORS_CORETEMP
409 409
410config SENSORS_PKGTEMP 410config SENSORS_PKGTEMP
411 tristate "Intel processor package temperature sensor" 411 tristate "Intel processor package temperature sensor"
412 depends on X86 && PCI && EXPERIMENTAL 412 depends on X86 && EXPERIMENTAL
413 help 413 help
414 If you say yes here you get support for the package level temperature 414 If you say yes here you get support for the package level temperature
415 sensor inside your CPU. Check documentation/driver for details. 415 sensor inside your CPU. Check documentation/driver for details.
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 15c1a9616af3..0683e6be662c 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -79,7 +79,7 @@ struct adm1031_data {
79 int chip_type; 79 int chip_type;
80 char valid; /* !=0 if following fields are valid */ 80 char valid; /* !=0 if following fields are valid */
81 unsigned long last_updated; /* In jiffies */ 81 unsigned long last_updated; /* In jiffies */
82 unsigned int update_rate; /* In milliseconds */ 82 unsigned int update_interval; /* In milliseconds */
83 /* The chan_select_table contains the possible configurations for 83 /* The chan_select_table contains the possible configurations for
84 * auto fan control. 84 * auto fan control.
85 */ 85 */
@@ -743,23 +743,23 @@ static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
743static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13); 743static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
744static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14); 744static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
745 745
746/* Update Rate */ 746/* Update Interval */
747static const unsigned int update_rates[] = { 747static const unsigned int update_intervals[] = {
748 16000, 8000, 4000, 2000, 1000, 500, 250, 125, 748 16000, 8000, 4000, 2000, 1000, 500, 250, 125,
749}; 749};
750 750
751static ssize_t show_update_rate(struct device *dev, 751static ssize_t show_update_interval(struct device *dev,
752 struct device_attribute *attr, char *buf) 752 struct device_attribute *attr, char *buf)
753{ 753{
754 struct i2c_client *client = to_i2c_client(dev); 754 struct i2c_client *client = to_i2c_client(dev);
755 struct adm1031_data *data = i2c_get_clientdata(client); 755 struct adm1031_data *data = i2c_get_clientdata(client);
756 756
757 return sprintf(buf, "%u\n", data->update_rate); 757 return sprintf(buf, "%u\n", data->update_interval);
758} 758}
759 759
760static ssize_t set_update_rate(struct device *dev, 760static ssize_t set_update_interval(struct device *dev,
761 struct device_attribute *attr, 761 struct device_attribute *attr,
762 const char *buf, size_t count) 762 const char *buf, size_t count)
763{ 763{
764 struct i2c_client *client = to_i2c_client(dev); 764 struct i2c_client *client = to_i2c_client(dev);
765 struct adm1031_data *data = i2c_get_clientdata(client); 765 struct adm1031_data *data = i2c_get_clientdata(client);
@@ -771,12 +771,15 @@ static ssize_t set_update_rate(struct device *dev,
771 if (err) 771 if (err)
772 return err; 772 return err;
773 773
774 /* find the nearest update rate from the table */ 774 /*
775 for (i = 0; i < ARRAY_SIZE(update_rates) - 1; i++) { 775 * Find the nearest update interval from the table.
776 if (val >= update_rates[i]) 776 * Use it to determine the matching update rate.
777 */
778 for (i = 0; i < ARRAY_SIZE(update_intervals) - 1; i++) {
779 if (val >= update_intervals[i])
777 break; 780 break;
778 } 781 }
779 /* if not found, we point to the last entry (lowest update rate) */ 782 /* if not found, we point to the last entry (lowest update interval) */
780 783
781 /* set the new update rate while preserving other settings */ 784 /* set the new update rate while preserving other settings */
782 reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); 785 reg = adm1031_read_value(client, ADM1031_REG_FAN_FILTER);
@@ -785,14 +788,14 @@ static ssize_t set_update_rate(struct device *dev,
785 adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg); 788 adm1031_write_value(client, ADM1031_REG_FAN_FILTER, reg);
786 789
787 mutex_lock(&data->update_lock); 790 mutex_lock(&data->update_lock);
788 data->update_rate = update_rates[i]; 791 data->update_interval = update_intervals[i];
789 mutex_unlock(&data->update_lock); 792 mutex_unlock(&data->update_lock);
790 793
791 return count; 794 return count;
792} 795}
793 796
794static DEVICE_ATTR(update_rate, S_IRUGO | S_IWUSR, show_update_rate, 797static DEVICE_ATTR(update_interval, S_IRUGO | S_IWUSR, show_update_interval,
795 set_update_rate); 798 set_update_interval);
796 799
797static struct attribute *adm1031_attributes[] = { 800static struct attribute *adm1031_attributes[] = {
798 &sensor_dev_attr_fan1_input.dev_attr.attr, 801 &sensor_dev_attr_fan1_input.dev_attr.attr,
@@ -830,7 +833,7 @@ static struct attribute *adm1031_attributes[] = {
830 833
831 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr, 834 &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr,
832 835
833 &dev_attr_update_rate.attr, 836 &dev_attr_update_interval.attr,
834 &dev_attr_alarms.attr, 837 &dev_attr_alarms.attr,
835 838
836 NULL 839 NULL
@@ -981,7 +984,8 @@ static void adm1031_init_client(struct i2c_client *client)
981 mask = ADM1031_UPDATE_RATE_MASK; 984 mask = ADM1031_UPDATE_RATE_MASK;
982 read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER); 985 read_val = adm1031_read_value(client, ADM1031_REG_FAN_FILTER);
983 i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT; 986 i = (read_val & mask) >> ADM1031_UPDATE_RATE_SHIFT;
984 data->update_rate = update_rates[i]; 987 /* Save it as update interval */
988 data->update_interval = update_intervals[i];
985} 989}
986 990
987static struct adm1031_data *adm1031_update_device(struct device *dev) 991static struct adm1031_data *adm1031_update_device(struct device *dev)
@@ -993,7 +997,8 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
993 997
994 mutex_lock(&data->update_lock); 998 mutex_lock(&data->update_lock);
995 999
996 next_update = data->last_updated + msecs_to_jiffies(data->update_rate); 1000 next_update = data->last_updated
1001 + msecs_to_jiffies(data->update_interval);
997 if (time_after(jiffies, next_update) || !data->valid) { 1002 if (time_after(jiffies, next_update) || !data->valid) {
998 1003
999 dev_dbg(&client->dev, "Starting adm1031 update\n"); 1004 dev_dbg(&client->dev, "Starting adm1031 update\n");
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index de8111114f46..a23b17a78ace 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -36,6 +36,7 @@
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <asm/msr.h> 37#include <asm/msr.h>
38#include <asm/processor.h> 38#include <asm/processor.h>
39#include <asm/smp.h>
39 40
40#define DRVNAME "coretemp" 41#define DRVNAME "coretemp"
41 42
@@ -423,9 +424,18 @@ static int __cpuinit coretemp_device_add(unsigned int cpu)
423 int err; 424 int err;
424 struct platform_device *pdev; 425 struct platform_device *pdev;
425 struct pdev_entry *pdev_entry; 426 struct pdev_entry *pdev_entry;
426#ifdef CONFIG_SMP
427 struct cpuinfo_x86 *c = &cpu_data(cpu); 427 struct cpuinfo_x86 *c = &cpu_data(cpu);
428#endif 428
429 /*
430 * CPUID.06H.EAX[0] indicates whether the CPU has thermal
431 * sensors. We check this bit only, all the early CPUs
432 * without thermal sensors will be filtered out.
433 */
434 if (!cpu_has(c, X86_FEATURE_DTS)) {
435 printk(KERN_INFO DRVNAME ": CPU (model=0x%x)"
436 " has no thermal sensor.\n", c->x86_model);
437 return 0;
438 }
429 439
430 mutex_lock(&pdev_list_mutex); 440 mutex_lock(&pdev_list_mutex);
431 441
@@ -482,14 +492,22 @@ exit:
482 492
483static void coretemp_device_remove(unsigned int cpu) 493static void coretemp_device_remove(unsigned int cpu)
484{ 494{
485 struct pdev_entry *p, *n; 495 struct pdev_entry *p;
496 unsigned int i;
497
486 mutex_lock(&pdev_list_mutex); 498 mutex_lock(&pdev_list_mutex);
487 list_for_each_entry_safe(p, n, &pdev_list, list) { 499 list_for_each_entry(p, &pdev_list, list) {
488 if (p->cpu == cpu) { 500 if (p->cpu != cpu)
489 platform_device_unregister(p->pdev); 501 continue;
490 list_del(&p->list); 502
491 kfree(p); 503 platform_device_unregister(p->pdev);
492 } 504 list_del(&p->list);
505 mutex_unlock(&pdev_list_mutex);
506 kfree(p);
507 for_each_cpu(i, cpu_sibling_mask(cpu))
508 if (i != cpu && !coretemp_device_add(i))
509 break;
510 return;
493 } 511 }
494 mutex_unlock(&pdev_list_mutex); 512 mutex_unlock(&pdev_list_mutex);
495} 513}
@@ -527,30 +545,21 @@ static int __init coretemp_init(void)
527 if (err) 545 if (err)
528 goto exit; 546 goto exit;
529 547
530 for_each_online_cpu(i) { 548 for_each_online_cpu(i)
531 struct cpuinfo_x86 *c = &cpu_data(i); 549 coretemp_device_add(i);
532 /* 550
533 * CPUID.06H.EAX[0] indicates whether the CPU has thermal 551#ifndef CONFIG_HOTPLUG_CPU
534 * sensors. We check this bit only, all the early CPUs
535 * without thermal sensors will be filtered out.
536 */
537 if (c->cpuid_level >= 6 && (cpuid_eax(0x06) & 0x01))
538 coretemp_device_add(i);
539 else {
540 printk(KERN_INFO DRVNAME ": CPU (model=0x%x)"
541 " has no thermal sensor.\n", c->x86_model);
542 }
543 }
544 if (list_empty(&pdev_list)) { 552 if (list_empty(&pdev_list)) {
545 err = -ENODEV; 553 err = -ENODEV;
546 goto exit_driver_unreg; 554 goto exit_driver_unreg;
547 } 555 }
556#endif
548 557
549 register_hotcpu_notifier(&coretemp_cpu_notifier); 558 register_hotcpu_notifier(&coretemp_cpu_notifier);
550 return 0; 559 return 0;
551 560
552exit_driver_unreg:
553#ifndef CONFIG_HOTPLUG_CPU 561#ifndef CONFIG_HOTPLUG_CPU
562exit_driver_unreg:
554 platform_driver_unregister(&coretemp_driver); 563 platform_driver_unregister(&coretemp_driver);
555#endif 564#endif
556exit: 565exit:
diff --git a/drivers/hwmon/emc1403.c b/drivers/hwmon/emc1403.c
index 5b58b20dead1..8dee3f38fdfb 100644
--- a/drivers/hwmon/emc1403.c
+++ b/drivers/hwmon/emc1403.c
@@ -308,7 +308,6 @@ static int emc1403_probe(struct i2c_client *client,
308 res = sysfs_create_group(&client->dev.kobj, &m_thermal_gr); 308 res = sysfs_create_group(&client->dev.kobj, &m_thermal_gr);
309 if (res) { 309 if (res) {
310 dev_warn(&client->dev, "create group failed\n"); 310 dev_warn(&client->dev, "create group failed\n");
311 hwmon_device_unregister(data->hwmon_dev);
312 goto thermal_error1; 311 goto thermal_error1;
313 } 312 }
314 data->hwmon_dev = hwmon_device_register(&client->dev); 313 data->hwmon_dev = hwmon_device_register(&client->dev);
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 537841ef44b9..75afb3b0e076 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -111,7 +111,7 @@ static struct platform_device *f71882fg_pdev;
111/* Super-I/O Function prototypes */ 111/* Super-I/O Function prototypes */
112static inline int superio_inb(int base, int reg); 112static inline int superio_inb(int base, int reg);
113static inline int superio_inw(int base, int reg); 113static inline int superio_inw(int base, int reg);
114static inline void superio_enter(int base); 114static inline int superio_enter(int base);
115static inline void superio_select(int base, int ld); 115static inline void superio_select(int base, int ld);
116static inline void superio_exit(int base); 116static inline void superio_exit(int base);
117 117
@@ -861,11 +861,20 @@ static int superio_inw(int base, int reg)
861 return val; 861 return val;
862} 862}
863 863
864static inline void superio_enter(int base) 864static inline int superio_enter(int base)
865{ 865{
866 /* Don't step on other drivers' I/O space by accident */
867 if (!request_muxed_region(base, 2, DRVNAME)) {
868 printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
869 base);
870 return -EBUSY;
871 }
872
866 /* according to the datasheet the key must be send twice! */ 873 /* according to the datasheet the key must be send twice! */
867 outb(SIO_UNLOCK_KEY, base); 874 outb(SIO_UNLOCK_KEY, base);
868 outb(SIO_UNLOCK_KEY, base); 875 outb(SIO_UNLOCK_KEY, base);
876
877 return 0;
869} 878}
870 879
871static inline void superio_select(int base, int ld) 880static inline void superio_select(int base, int ld)
@@ -877,6 +886,7 @@ static inline void superio_select(int base, int ld)
877static inline void superio_exit(int base) 886static inline void superio_exit(int base)
878{ 887{
879 outb(SIO_LOCK_KEY, base); 888 outb(SIO_LOCK_KEY, base);
889 release_region(base, 2);
880} 890}
881 891
882static inline int fan_from_reg(u16 reg) 892static inline int fan_from_reg(u16 reg)
@@ -2175,21 +2185,15 @@ static int f71882fg_remove(struct platform_device *pdev)
2175static int __init f71882fg_find(int sioaddr, unsigned short *address, 2185static int __init f71882fg_find(int sioaddr, unsigned short *address,
2176 struct f71882fg_sio_data *sio_data) 2186 struct f71882fg_sio_data *sio_data)
2177{ 2187{
2178 int err = -ENODEV;
2179 u16 devid; 2188 u16 devid;
2180 2189 int err = superio_enter(sioaddr);
2181 /* Don't step on other drivers' I/O space by accident */ 2190 if (err)
2182 if (!request_region(sioaddr, 2, DRVNAME)) { 2191 return err;
2183 printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
2184 (int)sioaddr);
2185 return -EBUSY;
2186 }
2187
2188 superio_enter(sioaddr);
2189 2192
2190 devid = superio_inw(sioaddr, SIO_REG_MANID); 2193 devid = superio_inw(sioaddr, SIO_REG_MANID);
2191 if (devid != SIO_FINTEK_ID) { 2194 if (devid != SIO_FINTEK_ID) {
2192 pr_debug(DRVNAME ": Not a Fintek device\n"); 2195 pr_debug(DRVNAME ": Not a Fintek device\n");
2196 err = -ENODEV;
2193 goto exit; 2197 goto exit;
2194 } 2198 }
2195 2199
@@ -2213,6 +2217,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2213 default: 2217 default:
2214 printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n", 2218 printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n",
2215 (unsigned int)devid); 2219 (unsigned int)devid);
2220 err = -ENODEV;
2216 goto exit; 2221 goto exit;
2217 } 2222 }
2218 2223
@@ -2223,12 +2228,14 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2223 2228
2224 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { 2229 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2225 printk(KERN_WARNING DRVNAME ": Device not activated\n"); 2230 printk(KERN_WARNING DRVNAME ": Device not activated\n");
2231 err = -ENODEV;
2226 goto exit; 2232 goto exit;
2227 } 2233 }
2228 2234
2229 *address = superio_inw(sioaddr, SIO_REG_ADDR); 2235 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2230 if (*address == 0) { 2236 if (*address == 0) {
2231 printk(KERN_WARNING DRVNAME ": Base address not set\n"); 2237 printk(KERN_WARNING DRVNAME ": Base address not set\n");
2238 err = -ENODEV;
2232 goto exit; 2239 goto exit;
2233 } 2240 }
2234 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ 2241 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
@@ -2239,7 +2246,6 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2239 (int)superio_inb(sioaddr, SIO_REG_DEVREV)); 2246 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2240exit: 2247exit:
2241 superio_exit(sioaddr); 2248 superio_exit(sioaddr);
2242 release_region(sioaddr, 2);
2243 return err; 2249 return err;
2244} 2250}
2245 2251
diff --git a/drivers/hwmon/f75375s.c b/drivers/hwmon/f75375s.c
index 0f58ecc5334d..9638d58f99fd 100644
--- a/drivers/hwmon/f75375s.c
+++ b/drivers/hwmon/f75375s.c
@@ -79,7 +79,7 @@ enum chips { f75373, f75375 };
79#define F75375_REG_PWM2_DROP_DUTY 0x6C 79#define F75375_REG_PWM2_DROP_DUTY 0x6C
80 80
81#define FAN_CTRL_LINEAR(nr) (4 + nr) 81#define FAN_CTRL_LINEAR(nr) (4 + nr)
82#define FAN_CTRL_MODE(nr) (5 + ((nr) * 2)) 82#define FAN_CTRL_MODE(nr) (4 + ((nr) * 2))
83 83
84/* 84/*
85 * Data structures and manipulation thereof 85 * Data structures and manipulation thereof
@@ -298,7 +298,7 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
298 return -EINVAL; 298 return -EINVAL;
299 299
300 fanmode = f75375_read8(client, F75375_REG_FAN_TIMER); 300 fanmode = f75375_read8(client, F75375_REG_FAN_TIMER);
301 fanmode = ~(3 << FAN_CTRL_MODE(nr)); 301 fanmode &= ~(3 << FAN_CTRL_MODE(nr));
302 302
303 switch (val) { 303 switch (val) {
304 case 0: /* Full speed */ 304 case 0: /* Full speed */
@@ -350,7 +350,7 @@ static ssize_t set_pwm_mode(struct device *dev, struct device_attribute *attr,
350 350
351 mutex_lock(&data->update_lock); 351 mutex_lock(&data->update_lock);
352 conf = f75375_read8(client, F75375_REG_CONFIG1); 352 conf = f75375_read8(client, F75375_REG_CONFIG1);
353 conf = ~(1 << FAN_CTRL_LINEAR(nr)); 353 conf &= ~(1 << FAN_CTRL_LINEAR(nr));
354 354
355 if (val == 0) 355 if (val == 0)
356 conf |= (1 << FAN_CTRL_LINEAR(nr)) ; 356 conf |= (1 << FAN_CTRL_LINEAR(nr)) ;
diff --git a/drivers/hwmon/fschmd.c b/drivers/hwmon/fschmd.c
index b7ca2a9676cf..d4d4ca65d371 100644
--- a/drivers/hwmon/fschmd.c
+++ b/drivers/hwmon/fschmd.c
@@ -38,7 +38,6 @@
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h> 40#include <linux/hwmon-sysfs.h>
41#include <linux/smp_lock.h>
42#include <linux/err.h> 41#include <linux/err.h>
43#include <linux/mutex.h> 42#include <linux/mutex.h>
44#include <linux/sysfs.h> 43#include <linux/sysfs.h>
@@ -50,6 +49,7 @@
50#include <linux/kref.h> 49#include <linux/kref.h>
51 50
52/* Addresses to scan */ 51/* Addresses to scan */
52static DEFINE_MUTEX(watchdog_mutex);
53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END }; 53static const unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
54 54
55/* Insmod parameters */ 55/* Insmod parameters */
@@ -858,7 +858,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
858 int i, ret = 0; 858 int i, ret = 0;
859 struct fschmd_data *data = filp->private_data; 859 struct fschmd_data *data = filp->private_data;
860 860
861 lock_kernel(); 861 mutex_lock(&watchdog_mutex);
862 switch (cmd) { 862 switch (cmd) {
863 case WDIOC_GETSUPPORT: 863 case WDIOC_GETSUPPORT:
864 ident.firmware_version = data->revision; 864 ident.firmware_version = data->revision;
@@ -915,7 +915,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
915 default: 915 default:
916 ret = -ENOTTY; 916 ret = -ENOTTY;
917 } 917 }
918 unlock_kernel(); 918 mutex_unlock(&watchdog_mutex);
919 return ret; 919 return ret;
920} 920}
921 921
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
index 6138f036b159..fc591ae53107 100644
--- a/drivers/hwmon/lis3lv02d.c
+++ b/drivers/hwmon/lis3lv02d.c
@@ -277,7 +277,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
277 wake_up_interruptible(&lis3_dev.misc_wait); 277 wake_up_interruptible(&lis3_dev.misc_wait);
278 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN); 278 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
279out: 279out:
280 if (lis3_dev.whoami == WAI_8B && lis3_dev.idev && 280 if (lis3_dev.pdata && lis3_dev.whoami == WAI_8B && lis3_dev.idev &&
281 lis3_dev.idev->input->users) 281 lis3_dev.idev->input->users)
282 return IRQ_WAKE_THREAD; 282 return IRQ_WAKE_THREAD;
283 return IRQ_HANDLED; 283 return IRQ_HANDLED;
@@ -718,7 +718,7 @@ int lis3lv02d_init_device(struct lis3lv02d *dev)
718 * io-apic is not configurable (and generates a warning) but I keep it 718 * io-apic is not configurable (and generates a warning) but I keep it
719 * in case of support for other hardware. 719 * in case of support for other hardware.
720 */ 720 */
721 if (dev->whoami == WAI_8B) 721 if (dev->pdata && dev->whoami == WAI_8B)
722 thread_fn = lis302dl_interrupt_thread1_8b; 722 thread_fn = lis302dl_interrupt_thread1_8b;
723 else 723 else
724 thread_fn = NULL; 724 thread_fn = NULL;
diff --git a/drivers/hwmon/lis3lv02d_i2c.c b/drivers/hwmon/lis3lv02d_i2c.c
index dc1f5402c1d7..8e5933b72d19 100644
--- a/drivers/hwmon/lis3lv02d_i2c.c
+++ b/drivers/hwmon/lis3lv02d_i2c.c
@@ -121,7 +121,7 @@ static int lis3lv02d_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
121{ 121{
122 struct lis3lv02d *lis3 = i2c_get_clientdata(client); 122 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
123 123
124 if (!lis3->pdata->wakeup_flags) 124 if (!lis3->pdata || !lis3->pdata->wakeup_flags)
125 lis3lv02d_poweroff(lis3); 125 lis3lv02d_poweroff(lis3);
126 return 0; 126 return 0;
127} 127}
@@ -130,7 +130,7 @@ static int lis3lv02d_i2c_resume(struct i2c_client *client)
130{ 130{
131 struct lis3lv02d *lis3 = i2c_get_clientdata(client); 131 struct lis3lv02d *lis3 = i2c_get_clientdata(client);
132 132
133 if (!lis3->pdata->wakeup_flags) 133 if (!lis3->pdata || !lis3->pdata->wakeup_flags)
134 lis3lv02d_poweron(lis3); 134 lis3lv02d_poweron(lis3);
135 return 0; 135 return 0;
136} 136}
diff --git a/drivers/hwmon/lis3lv02d_spi.c b/drivers/hwmon/lis3lv02d_spi.c
index 82b16808a274..b9be5e3a22b3 100644
--- a/drivers/hwmon/lis3lv02d_spi.c
+++ b/drivers/hwmon/lis3lv02d_spi.c
@@ -92,7 +92,7 @@ static int lis3lv02d_spi_suspend(struct spi_device *spi, pm_message_t mesg)
92{ 92{
93 struct lis3lv02d *lis3 = spi_get_drvdata(spi); 93 struct lis3lv02d *lis3 = spi_get_drvdata(spi);
94 94
95 if (!lis3->pdata->wakeup_flags) 95 if (!lis3->pdata || !lis3->pdata->wakeup_flags)
96 lis3lv02d_poweroff(&lis3_dev); 96 lis3lv02d_poweroff(&lis3_dev);
97 97
98 return 0; 98 return 0;
@@ -102,7 +102,7 @@ static int lis3lv02d_spi_resume(struct spi_device *spi)
102{ 102{
103 struct lis3lv02d *lis3 = spi_get_drvdata(spi); 103 struct lis3lv02d *lis3 = spi_get_drvdata(spi);
104 104
105 if (!lis3->pdata->wakeup_flags) 105 if (!lis3->pdata || !lis3->pdata->wakeup_flags)
106 lis3lv02d_poweron(lis3); 106 lis3lv02d_poweron(lis3);
107 107
108 return 0; 108 return 0;
diff --git a/drivers/hwmon/lm95241.c b/drivers/hwmon/lm95241.c
index 94741d42112d..464340f25496 100644
--- a/drivers/hwmon/lm95241.c
+++ b/drivers/hwmon/lm95241.c
@@ -91,7 +91,7 @@ static struct lm95241_data *lm95241_update_device(struct device *dev);
91struct lm95241_data { 91struct lm95241_data {
92 struct device *hwmon_dev; 92 struct device *hwmon_dev;
93 struct mutex update_lock; 93 struct mutex update_lock;
94 unsigned long last_updated, rate; /* in jiffies */ 94 unsigned long last_updated, interval; /* in jiffies */
95 char valid; /* zero until following fields are valid */ 95 char valid; /* zero until following fields are valid */
96 /* registers values */ 96 /* registers values */
97 u8 local_h, local_l; /* local */ 97 u8 local_h, local_l; /* local */
@@ -114,23 +114,23 @@ show_temp(local);
114show_temp(remote1); 114show_temp(remote1);
115show_temp(remote2); 115show_temp(remote2);
116 116
117static ssize_t show_rate(struct device *dev, struct device_attribute *attr, 117static ssize_t show_interval(struct device *dev, struct device_attribute *attr,
118 char *buf) 118 char *buf)
119{ 119{
120 struct lm95241_data *data = lm95241_update_device(dev); 120 struct lm95241_data *data = lm95241_update_device(dev);
121 121
122 snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->rate / HZ); 122 snprintf(buf, PAGE_SIZE - 1, "%lu\n", 1000 * data->interval / HZ);
123 return strlen(buf); 123 return strlen(buf);
124} 124}
125 125
126static ssize_t set_rate(struct device *dev, struct device_attribute *attr, 126static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
127 const char *buf, size_t count) 127 const char *buf, size_t count)
128{ 128{
129 struct i2c_client *client = to_i2c_client(dev); 129 struct i2c_client *client = to_i2c_client(dev);
130 struct lm95241_data *data = i2c_get_clientdata(client); 130 struct lm95241_data *data = i2c_get_clientdata(client);
131 131
132 strict_strtol(buf, 10, &data->rate); 132 strict_strtol(buf, 10, &data->interval);
133 data->rate = data->rate * HZ / 1000; 133 data->interval = data->interval * HZ / 1000;
134 134
135 return count; 135 return count;
136} 136}
@@ -286,7 +286,8 @@ static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_min1, set_min1);
286static DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min2, set_min2); 286static DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_min2, set_min2);
287static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max1, set_max1); 287static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_max1, set_max1);
288static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max2, set_max2); 288static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_max2, set_max2);
289static DEVICE_ATTR(rate, S_IWUSR | S_IRUGO, show_rate, set_rate); 289static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
290 set_interval);
290 291
291static struct attribute *lm95241_attributes[] = { 292static struct attribute *lm95241_attributes[] = {
292 &dev_attr_temp1_input.attr, 293 &dev_attr_temp1_input.attr,
@@ -298,7 +299,7 @@ static struct attribute *lm95241_attributes[] = {
298 &dev_attr_temp3_min.attr, 299 &dev_attr_temp3_min.attr,
299 &dev_attr_temp2_max.attr, 300 &dev_attr_temp2_max.attr,
300 &dev_attr_temp3_max.attr, 301 &dev_attr_temp3_max.attr,
301 &dev_attr_rate.attr, 302 &dev_attr_update_interval.attr,
302 NULL 303 NULL
303}; 304};
304 305
@@ -376,7 +377,7 @@ static void lm95241_init_client(struct i2c_client *client)
376{ 377{
377 struct lm95241_data *data = i2c_get_clientdata(client); 378 struct lm95241_data *data = i2c_get_clientdata(client);
378 379
379 data->rate = HZ; /* 1 sec default */ 380 data->interval = HZ; /* 1 sec default */
380 data->valid = 0; 381 data->valid = 0;
381 data->config = CFG_CR0076; 382 data->config = CFG_CR0076;
382 data->model = 0; 383 data->model = 0;
@@ -410,7 +411,7 @@ static struct lm95241_data *lm95241_update_device(struct device *dev)
410 411
411 mutex_lock(&data->update_lock); 412 mutex_lock(&data->update_lock);
412 413
413 if (time_after(jiffies, data->last_updated + data->rate) || 414 if (time_after(jiffies, data->last_updated + data->interval) ||
414 !data->valid) { 415 !data->valid) {
415 dev_dbg(&client->dev, "Updating lm95241 data.\n"); 416 dev_dbg(&client->dev, "Updating lm95241 data.\n");
416 data->local_h = 417 data->local_h =
diff --git a/drivers/hwmon/pkgtemp.c b/drivers/hwmon/pkgtemp.c
index 74157fcda6ed..f11903936c8b 100644
--- a/drivers/hwmon/pkgtemp.c
+++ b/drivers/hwmon/pkgtemp.c
@@ -33,7 +33,6 @@
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/cpu.h> 35#include <linux/cpu.h>
36#include <linux/pci.h>
37#include <asm/msr.h> 36#include <asm/msr.h>
38#include <asm/processor.h> 37#include <asm/processor.h>
39 38
@@ -224,7 +223,7 @@ static int __devinit pkgtemp_probe(struct platform_device *pdev)
224 223
225 err = sysfs_create_group(&pdev->dev.kobj, &pkgtemp_group); 224 err = sysfs_create_group(&pdev->dev.kobj, &pkgtemp_group);
226 if (err) 225 if (err)
227 goto exit_free; 226 goto exit_dev;
228 227
229 data->hwmon_dev = hwmon_device_register(&pdev->dev); 228 data->hwmon_dev = hwmon_device_register(&pdev->dev);
230 if (IS_ERR(data->hwmon_dev)) { 229 if (IS_ERR(data->hwmon_dev)) {
@@ -238,6 +237,8 @@ static int __devinit pkgtemp_probe(struct platform_device *pdev)
238 237
239exit_class: 238exit_class:
240 sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); 239 sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group);
240exit_dev:
241 device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr);
241exit_free: 242exit_free:
242 kfree(data); 243 kfree(data);
243exit: 244exit:
@@ -250,6 +251,7 @@ static int __devexit pkgtemp_remove(struct platform_device *pdev)
250 251
251 hwmon_device_unregister(data->hwmon_dev); 252 hwmon_device_unregister(data->hwmon_dev);
252 sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group); 253 sysfs_remove_group(&pdev->dev.kobj, &pkgtemp_group);
254 device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr);
253 platform_set_drvdata(pdev, NULL); 255 platform_set_drvdata(pdev, NULL);
254 kfree(data); 256 kfree(data);
255 return 0; 257 return 0;
@@ -281,9 +283,10 @@ static int __cpuinit pkgtemp_device_add(unsigned int cpu)
281 int err; 283 int err;
282 struct platform_device *pdev; 284 struct platform_device *pdev;
283 struct pdev_entry *pdev_entry; 285 struct pdev_entry *pdev_entry;
284#ifdef CONFIG_SMP
285 struct cpuinfo_x86 *c = &cpu_data(cpu); 286 struct cpuinfo_x86 *c = &cpu_data(cpu);
286#endif 287
288 if (!cpu_has(c, X86_FEATURE_PTS))
289 return 0;
287 290
288 mutex_lock(&pdev_list_mutex); 291 mutex_lock(&pdev_list_mutex);
289 292
@@ -339,17 +342,18 @@ exit:
339#ifdef CONFIG_HOTPLUG_CPU 342#ifdef CONFIG_HOTPLUG_CPU
340static void pkgtemp_device_remove(unsigned int cpu) 343static void pkgtemp_device_remove(unsigned int cpu)
341{ 344{
342 struct pdev_entry *p, *n; 345 struct pdev_entry *p;
343 unsigned int i; 346 unsigned int i;
344 int err; 347 int err;
345 348
346 mutex_lock(&pdev_list_mutex); 349 mutex_lock(&pdev_list_mutex);
347 list_for_each_entry_safe(p, n, &pdev_list, list) { 350 list_for_each_entry(p, &pdev_list, list) {
348 if (p->cpu != cpu) 351 if (p->cpu != cpu)
349 continue; 352 continue;
350 353
351 platform_device_unregister(p->pdev); 354 platform_device_unregister(p->pdev);
352 list_del(&p->list); 355 list_del(&p->list);
356 mutex_unlock(&pdev_list_mutex);
353 kfree(p); 357 kfree(p);
354 for_each_cpu(i, cpu_core_mask(cpu)) { 358 for_each_cpu(i, cpu_core_mask(cpu)) {
355 if (i != cpu) { 359 if (i != cpu) {
@@ -358,7 +362,7 @@ static void pkgtemp_device_remove(unsigned int cpu)
358 break; 362 break;
359 } 363 }
360 } 364 }
361 break; 365 return;
362 } 366 }
363 mutex_unlock(&pdev_list_mutex); 367 mutex_unlock(&pdev_list_mutex);
364} 368}
@@ -399,11 +403,6 @@ static int __init pkgtemp_init(void)
399 goto exit; 403 goto exit;
400 404
401 for_each_online_cpu(i) { 405 for_each_online_cpu(i) {
402 struct cpuinfo_x86 *c = &cpu_data(i);
403
404 if (!cpu_has(c, X86_FEATURE_PTS))
405 continue;
406
407 err = pkgtemp_device_add(i); 406 err = pkgtemp_device_add(i);
408 if (err) 407 if (err)
409 goto exit_devices_unreg; 408 goto exit_devices_unreg;
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index e96e69dd36fb..072c58008a63 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -127,6 +127,7 @@ superio_enter(int ioreg)
127static inline void 127static inline void
128superio_exit(int ioreg) 128superio_exit(int ioreg)
129{ 129{
130 outb(0xaa, ioreg);
130 outb(0x02, ioreg); 131 outb(0x02, ioreg);
131 outb(0x02, ioreg + 1); 132 outb(0x02, ioreg + 1);
132} 133}
diff --git a/drivers/hwmon/w83793.c b/drivers/hwmon/w83793.c
index 697202e27891..8e540ada47d2 100644
--- a/drivers/hwmon/w83793.c
+++ b/drivers/hwmon/w83793.c
@@ -35,7 +35,6 @@
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/hwmon.h> 37#include <linux/hwmon.h>
38#include <linux/smp_lock.h>
39#include <linux/hwmon-vid.h> 38#include <linux/hwmon-vid.h>
40#include <linux/hwmon-sysfs.h> 39#include <linux/hwmon-sysfs.h>
41#include <linux/err.h> 40#include <linux/err.h>
@@ -52,6 +51,7 @@
52#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */ 51#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
53 52
54/* Addresses to scan */ 53/* Addresses to scan */
54static DEFINE_MUTEX(watchdog_mutex);
55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 55static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
56 I2C_CLIENT_END }; 56 I2C_CLIENT_END };
57 57
@@ -1333,7 +1333,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1333 int val, ret = 0; 1333 int val, ret = 0;
1334 struct w83793_data *data = filp->private_data; 1334 struct w83793_data *data = filp->private_data;
1335 1335
1336 lock_kernel(); 1336 mutex_lock(&watchdog_mutex);
1337 switch (cmd) { 1337 switch (cmd) {
1338 case WDIOC_GETSUPPORT: 1338 case WDIOC_GETSUPPORT:
1339 if (!nowayout) 1339 if (!nowayout)
@@ -1387,7 +1387,7 @@ static long watchdog_ioctl(struct file *filp, unsigned int cmd,
1387 default: 1387 default:
1388 ret = -ENOTTY; 1388 ret = -ENOTTY;
1389 } 1389 }
1390 unlock_kernel(); 1390 mutex_unlock(&watchdog_mutex);
1391 return ret; 1391 return ret;
1392} 1392}
1393 1393
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index f7bd2613cecc..f2de3be35df3 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -677,6 +677,11 @@ static int __devinit cpm_i2c_probe(struct platform_device *ofdev,
677 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n", 677 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
678 cpm->adap.name); 678 cpm->adap.name);
679 679
680 /*
681 * register OF I2C devices
682 */
683 of_i2c_register_devices(&cpm->adap);
684
680 return 0; 685 return 0;
681out_shut: 686out_shut:
682 cpm_i2c_shutdown(cpm); 687 cpm_i2c_shutdown(cpm);
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 2222c87876b9..5795c8398c7c 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -331,21 +331,16 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
331 INIT_COMPLETION(dev->cmd_complete); 331 INIT_COMPLETION(dev->cmd_complete);
332 dev->cmd_err = 0; 332 dev->cmd_err = 0;
333 333
334 /* Take I2C out of reset, configure it as master and set the 334 /* Take I2C out of reset and configure it as master */
335 * start bit */ 335 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST;
336 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST | DAVINCI_I2C_MDR_STT;
337 336
338 /* if the slave address is ten bit address, enable XA bit */ 337 /* if the slave address is ten bit address, enable XA bit */
339 if (msg->flags & I2C_M_TEN) 338 if (msg->flags & I2C_M_TEN)
340 flag |= DAVINCI_I2C_MDR_XA; 339 flag |= DAVINCI_I2C_MDR_XA;
341 if (!(msg->flags & I2C_M_RD)) 340 if (!(msg->flags & I2C_M_RD))
342 flag |= DAVINCI_I2C_MDR_TRX; 341 flag |= DAVINCI_I2C_MDR_TRX;
343 if (stop) 342 if (msg->len == 0)
344 flag |= DAVINCI_I2C_MDR_STP;
345 if (msg->len == 0) {
346 flag |= DAVINCI_I2C_MDR_RM; 343 flag |= DAVINCI_I2C_MDR_RM;
347 flag &= ~DAVINCI_I2C_MDR_STP;
348 }
349 344
350 /* Enable receive or transmit interrupts */ 345 /* Enable receive or transmit interrupts */
351 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG); 346 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
@@ -357,7 +352,11 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
357 352
358 dev->terminate = 0; 353 dev->terminate = 0;
359 354
360 /* write the data into mode register */ 355 /*
356 * Write mode register first as needed for correct behaviour
357 * on OMAP-L138, but don't set STT yet to avoid a race with XRDY
358 * occuring before we have loaded DXR
359 */
361 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 360 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
362 361
363 /* 362 /*
@@ -365,12 +364,19 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
365 * because transmit-data-ready interrupt can come before 364 * because transmit-data-ready interrupt can come before
366 * NACK-interrupt during sending of previous message and 365 * NACK-interrupt during sending of previous message and
367 * ICDXR may have wrong data 366 * ICDXR may have wrong data
367 * It also saves us one interrupt, slightly faster
368 */ 368 */
369 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) { 369 if ((!(msg->flags & I2C_M_RD)) && dev->buf_len) {
370 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++); 370 davinci_i2c_write_reg(dev, DAVINCI_I2C_DXR_REG, *dev->buf++);
371 dev->buf_len--; 371 dev->buf_len--;
372 } 372 }
373 373
374 /* Set STT to begin transmit now DXR is loaded */
375 flag |= DAVINCI_I2C_MDR_STT;
376 if (stop && msg->len != 0)
377 flag |= DAVINCI_I2C_MDR_STP;
378 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
379
374 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 380 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
375 dev->adapter.timeout); 381 dev->adapter.timeout);
376 if (r == 0) { 382 if (r == 0) {
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 43ca32fddde2..89eedf45d30e 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -761,6 +761,9 @@ static int __devinit iic_probe(struct platform_device *ofdev,
761 dev_info(&ofdev->dev, "using %s mode\n", 761 dev_info(&ofdev->dev, "using %s mode\n",
762 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 762 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
763 763
764 /* Now register all the child nodes */
765 of_i2c_register_devices(adap);
766
764 return 0; 767 return 0;
765 768
766error_cleanup: 769error_cleanup:
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index d1ff9408dc1f..4c2a62b75b5c 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -159,15 +159,9 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
159 159
160static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx) 160static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
161{ 161{
162 int result; 162 wait_event_timeout(i2c_imx->queue, i2c_imx->i2csr & I2SR_IIF, HZ / 10);
163
164 result = wait_event_interruptible_timeout(i2c_imx->queue,
165 i2c_imx->i2csr & I2SR_IIF, HZ / 10);
166 163
167 if (unlikely(result < 0)) { 164 if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
168 dev_dbg(&i2c_imx->adapter.dev, "<%s> result < 0\n", __func__);
169 return result;
170 } else if (unlikely(!(i2c_imx->i2csr & I2SR_IIF))) {
171 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__); 165 dev_dbg(&i2c_imx->adapter.dev, "<%s> Timeout\n", __func__);
172 return -ETIMEDOUT; 166 return -ETIMEDOUT;
173 } 167 }
@@ -295,7 +289,7 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
295 i2c_imx->i2csr = temp; 289 i2c_imx->i2csr = temp;
296 temp &= ~I2SR_IIF; 290 temp &= ~I2SR_IIF;
297 writeb(temp, i2c_imx->base + IMX_I2C_I2SR); 291 writeb(temp, i2c_imx->base + IMX_I2C_I2SR);
298 wake_up_interruptible(&i2c_imx->queue); 292 wake_up(&i2c_imx->queue);
299 return IRQ_HANDLED; 293 return IRQ_HANDLED;
300 } 294 }
301 295
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index a1c419a716af..b74e6dc6886c 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -632,6 +632,7 @@ static int __devinit fsl_i2c_probe(struct platform_device *op,
632 dev_err(i2c->dev, "failed to add adapter\n"); 632 dev_err(i2c->dev, "failed to add adapter\n");
633 goto fail_add; 633 goto fail_add;
634 } 634 }
635 of_i2c_register_devices(&i2c->adap);
635 636
636 return result; 637 return result;
637 638
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index 0e9f85d0a835..56dbe54e8811 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -218,7 +218,7 @@ static int octeon_i2c_wait(struct octeon_i2c *i2c)
218 return result; 218 return result;
219 } else if (result == 0) { 219 } else if (result == 0) {
220 dev_dbg(i2c->dev, "%s: timeout\n", __func__); 220 dev_dbg(i2c->dev, "%s: timeout\n", __func__);
221 result = -ETIMEDOUT; 221 return -ETIMEDOUT;
222 } 222 }
223 223
224 return 0; 224 return 0;
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 7674efb55378..b33c78586bfc 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -680,6 +680,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
680 680
681 if (r == 0) 681 if (r == 0)
682 r = num; 682 r = num;
683
684 omap_i2c_wait_for_bb(dev);
683out: 685out:
684 omap_i2c_idle(dev); 686 omap_i2c_idle(dev);
685 return r; 687 return r;
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 4174101660c9..837b8c1aa02a 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -88,7 +88,7 @@ static void pasemi_smb_clear(struct pasemi_smbus *smbus)
88 reg_write(smbus, REG_SMSTA, status); 88 reg_write(smbus, REG_SMSTA, status);
89} 89}
90 90
91static unsigned int pasemi_smb_waitready(struct pasemi_smbus *smbus) 91static int pasemi_smb_waitready(struct pasemi_smbus *smbus)
92{ 92{
93 int timeout = 10; 93 int timeout = 10;
94 unsigned int status; 94 unsigned int status;
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index bbd77603a417..29933f87d8fa 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -71,8 +71,8 @@ static int pca_isa_readbyte(void *pd, int reg)
71 71
72static int pca_isa_waitforcompletion(void *pd) 72static int pca_isa_waitforcompletion(void *pd)
73{ 73{
74 long ret = ~0;
75 unsigned long timeout; 74 unsigned long timeout;
75 long ret;
76 76
77 if (irq > -1) { 77 if (irq > -1) {
78 ret = wait_event_timeout(pca_wait, 78 ret = wait_event_timeout(pca_wait,
@@ -81,11 +81,15 @@ static int pca_isa_waitforcompletion(void *pd)
81 } else { 81 } else {
82 /* Do polling */ 82 /* Do polling */
83 timeout = jiffies + pca_isa_ops.timeout; 83 timeout = jiffies + pca_isa_ops.timeout;
84 while (((pca_isa_readbyte(pd, I2C_PCA_CON) 84 do {
85 & I2C_PCA_CON_SI) == 0) 85 ret = time_before(jiffies, timeout);
86 && (ret = time_before(jiffies, timeout))) 86 if (pca_isa_readbyte(pd, I2C_PCA_CON)
87 & I2C_PCA_CON_SI)
88 break;
87 udelay(100); 89 udelay(100);
90 } while (ret);
88 } 91 }
92
89 return ret > 0; 93 return ret > 0;
90} 94}
91 95
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index ef5c78487eb7..5f6d7f89e225 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -80,8 +80,8 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
80static int i2c_pca_pf_waitforcompletion(void *pd) 80static int i2c_pca_pf_waitforcompletion(void *pd)
81{ 81{
82 struct i2c_pca_pf_data *i2c = pd; 82 struct i2c_pca_pf_data *i2c = pd;
83 long ret = ~0;
84 unsigned long timeout; 83 unsigned long timeout;
84 long ret;
85 85
86 if (i2c->irq) { 86 if (i2c->irq) {
87 ret = wait_event_timeout(i2c->wait, 87 ret = wait_event_timeout(i2c->wait,
@@ -90,10 +90,13 @@ static int i2c_pca_pf_waitforcompletion(void *pd)
90 } else { 90 } else {
91 /* Do polling */ 91 /* Do polling */
92 timeout = jiffies + i2c->adap.timeout; 92 timeout = jiffies + i2c->adap.timeout;
93 while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON) 93 do {
94 & I2C_PCA_CON_SI) == 0) 94 ret = time_before(jiffies, timeout);
95 && (ret = time_before(jiffies, timeout))) 95 if (i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
96 & I2C_PCA_CON_SI)
97 break;
96 udelay(100); 98 udelay(100);
99 } while (ret);
97 } 100 }
98 101
99 return ret > 0; 102 return ret > 0;
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 72902e0bbfa7..bf831bf81587 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -662,8 +662,8 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
662 unsigned long sda_delay; 662 unsigned long sda_delay;
663 663
664 if (pdata->sda_delay) { 664 if (pdata->sda_delay) {
665 sda_delay = (freq / 1000) * pdata->sda_delay; 665 sda_delay = clkin * pdata->sda_delay;
666 sda_delay /= 1000000; 666 sda_delay = DIV_ROUND_UP(sda_delay, 1000000);
667 sda_delay = DIV_ROUND_UP(sda_delay, 5); 667 sda_delay = DIV_ROUND_UP(sda_delay, 5);
668 if (sda_delay > 3) 668 if (sda_delay > 3)
669 sda_delay = 3; 669 sda_delay = 3;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 6649176de940..bea4c5021d26 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -32,7 +32,6 @@
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/idr.h> 33#include <linux/idr.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/of_i2c.h>
36#include <linux/of_device.h> 35#include <linux/of_device.h>
37#include <linux/completion.h> 36#include <linux/completion.h>
38#include <linux/hardirq.h> 37#include <linux/hardirq.h>
@@ -197,11 +196,12 @@ static int i2c_device_pm_suspend(struct device *dev)
197{ 196{
198 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 197 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
199 198
200 if (pm_runtime_suspended(dev)) 199 if (pm) {
201 return 0; 200 if (pm_runtime_suspended(dev))
202 201 return 0;
203 if (pm) 202 else
204 return pm->suspend ? pm->suspend(dev) : 0; 203 return pm->suspend ? pm->suspend(dev) : 0;
204 }
205 205
206 return i2c_legacy_suspend(dev, PMSG_SUSPEND); 206 return i2c_legacy_suspend(dev, PMSG_SUSPEND);
207} 207}
@@ -216,12 +216,6 @@ static int i2c_device_pm_resume(struct device *dev)
216 else 216 else
217 ret = i2c_legacy_resume(dev); 217 ret = i2c_legacy_resume(dev);
218 218
219 if (!ret) {
220 pm_runtime_disable(dev);
221 pm_runtime_set_active(dev);
222 pm_runtime_enable(dev);
223 }
224
225 return ret; 219 return ret;
226} 220}
227 221
@@ -229,11 +223,12 @@ static int i2c_device_pm_freeze(struct device *dev)
229{ 223{
230 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 224 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
231 225
232 if (pm_runtime_suspended(dev)) 226 if (pm) {
233 return 0; 227 if (pm_runtime_suspended(dev))
234 228 return 0;
235 if (pm) 229 else
236 return pm->freeze ? pm->freeze(dev) : 0; 230 return pm->freeze ? pm->freeze(dev) : 0;
231 }
237 232
238 return i2c_legacy_suspend(dev, PMSG_FREEZE); 233 return i2c_legacy_suspend(dev, PMSG_FREEZE);
239} 234}
@@ -242,11 +237,12 @@ static int i2c_device_pm_thaw(struct device *dev)
242{ 237{
243 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 238 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
244 239
245 if (pm_runtime_suspended(dev)) 240 if (pm) {
246 return 0; 241 if (pm_runtime_suspended(dev))
247 242 return 0;
248 if (pm) 243 else
249 return pm->thaw ? pm->thaw(dev) : 0; 244 return pm->thaw ? pm->thaw(dev) : 0;
245 }
250 246
251 return i2c_legacy_resume(dev); 247 return i2c_legacy_resume(dev);
252} 248}
@@ -255,11 +251,12 @@ static int i2c_device_pm_poweroff(struct device *dev)
255{ 251{
256 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; 252 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
257 253
258 if (pm_runtime_suspended(dev)) 254 if (pm) {
259 return 0; 255 if (pm_runtime_suspended(dev))
260 256 return 0;
261 if (pm) 257 else
262 return pm->poweroff ? pm->poweroff(dev) : 0; 258 return pm->poweroff ? pm->poweroff(dev) : 0;
259 }
263 260
264 return i2c_legacy_suspend(dev, PMSG_HIBERNATE); 261 return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
265} 262}
@@ -876,9 +873,6 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
876 if (adap->nr < __i2c_first_dynamic_bus_num) 873 if (adap->nr < __i2c_first_dynamic_bus_num)
877 i2c_scan_static_board_info(adap); 874 i2c_scan_static_board_info(adap);
878 875
879 /* Register devices from the device tree */
880 of_i2c_register_devices(adap);
881
882 /* Notify drivers */ 876 /* Notify drivers */
883 mutex_lock(&core_lock); 877 mutex_lock(&core_lock);
884 bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter); 878 bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 31fc76960a8f..0c73fe39a236 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -31,7 +31,6 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34#include <linux/smp_lock.h>
35#include <linux/slab.h> 34#include <linux/slab.h>
36#include <linux/interrupt.h> 35#include <linux/interrupt.h>
37#include <linux/errno.h> 36#include <linux/errno.h>
@@ -52,6 +51,7 @@
52 51
53#include "ide-cd.h" 52#include "ide-cd.h"
54 53
54static DEFINE_MUTEX(ide_cd_mutex);
55static DEFINE_MUTEX(idecd_ref_mutex); 55static DEFINE_MUTEX(idecd_ref_mutex);
56 56
57static void ide_cd_release(struct device *); 57static void ide_cd_release(struct device *);
@@ -1602,7 +1602,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)
1602 struct cdrom_info *info; 1602 struct cdrom_info *info;
1603 int rc = -ENXIO; 1603 int rc = -ENXIO;
1604 1604
1605 lock_kernel(); 1605 mutex_lock(&ide_cd_mutex);
1606 info = ide_cd_get(bdev->bd_disk); 1606 info = ide_cd_get(bdev->bd_disk);
1607 if (!info) 1607 if (!info)
1608 goto out; 1608 goto out;
@@ -1611,7 +1611,7 @@ static int idecd_open(struct block_device *bdev, fmode_t mode)
1611 if (rc < 0) 1611 if (rc < 0)
1612 ide_cd_put(info); 1612 ide_cd_put(info);
1613out: 1613out:
1614 unlock_kernel(); 1614 mutex_unlock(&ide_cd_mutex);
1615 return rc; 1615 return rc;
1616} 1616}
1617 1617
@@ -1619,11 +1619,11 @@ static int idecd_release(struct gendisk *disk, fmode_t mode)
1619{ 1619{
1620 struct cdrom_info *info = ide_drv_g(disk, cdrom_info); 1620 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
1621 1621
1622 lock_kernel(); 1622 mutex_lock(&ide_cd_mutex);
1623 cdrom_release(&info->devinfo, mode); 1623 cdrom_release(&info->devinfo, mode);
1624 1624
1625 ide_cd_put(info); 1625 ide_cd_put(info);
1626 unlock_kernel(); 1626 mutex_unlock(&ide_cd_mutex);
1627 1627
1628 return 0; 1628 return 0;
1629} 1629}
@@ -1694,9 +1694,9 @@ static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
1694{ 1694{
1695 int ret; 1695 int ret;
1696 1696
1697 lock_kernel(); 1697 mutex_lock(&ide_cd_mutex);
1698 ret = idecd_locked_ioctl(bdev, mode, cmd, arg); 1698 ret = idecd_locked_ioctl(bdev, mode, cmd, arg);
1699 unlock_kernel(); 1699 mutex_unlock(&ide_cd_mutex);
1700 1700
1701 return ret; 1701 return ret;
1702} 1702}
diff --git a/drivers/ide/ide-cs.c b/drivers/ide/ide-cs.c
index 2a4cb9c18f01..404843e8611b 100644
--- a/drivers/ide/ide-cs.c
+++ b/drivers/ide/ide-cs.c
@@ -43,7 +43,6 @@
43#include <asm/io.h> 43#include <asm/io.h>
44#include <asm/system.h> 44#include <asm/system.h>
45 45
46#include <pcmcia/cs.h>
47#include <pcmcia/cistpl.h> 46#include <pcmcia/cistpl.h>
48#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
49#include <pcmcia/cisreg.h> 48#include <pcmcia/cisreg.h>
@@ -72,17 +71,6 @@ static int ide_config(struct pcmcia_device *);
72 71
73static void ide_detach(struct pcmcia_device *p_dev); 72static void ide_detach(struct pcmcia_device *p_dev);
74 73
75
76
77
78/*======================================================================
79
80 ide_attach() creates an "instance" of the driver, allocating
81 local data structures for one device. The device is registered
82 with Card Services.
83
84======================================================================*/
85
86static int ide_probe(struct pcmcia_device *link) 74static int ide_probe(struct pcmcia_device *link)
87{ 75{
88 ide_info_t *info; 76 ide_info_t *info;
@@ -97,23 +85,12 @@ static int ide_probe(struct pcmcia_device *link)
97 info->p_dev = link; 85 info->p_dev = link;
98 link->priv = info; 86 link->priv = info;
99 87
100 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 88 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
101 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 89 CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
102 link->conf.Attributes = CONF_ENABLE_IRQ;
103 link->conf.IntType = INT_MEMORY_AND_IO;
104 90
105 return ide_config(link); 91 return ide_config(link);
106} /* ide_attach */ 92} /* ide_attach */
107 93
108/*======================================================================
109
110 This deletes a driver "instance". The device is de-registered
111 with Card Services. If it has been released, all local data
112 structures are freed. Otherwise, the structures will be freed
113 when the device is released.
114
115======================================================================*/
116
117static void ide_detach(struct pcmcia_device *link) 94static void ide_detach(struct pcmcia_device *link)
118{ 95{
119 ide_info_t *info = link->priv; 96 ide_info_t *info = link->priv;
@@ -187,79 +164,31 @@ out_release:
187 return NULL; 164 return NULL;
188} 165}
189 166
190/*====================================================================== 167static int pcmcia_check_one_config(struct pcmcia_device *pdev, void *priv_data)
191
192 ide_config() is scheduled to run after a CARD_INSERTION event
193 is received, to configure the PCMCIA socket, and to make the
194 ide device available to the system.
195
196======================================================================*/
197
198struct pcmcia_config_check {
199 unsigned long ctl_base;
200 int skip_vcc;
201 int is_kme;
202};
203
204static int pcmcia_check_one_config(struct pcmcia_device *pdev,
205 cistpl_cftable_entry_t *cfg,
206 cistpl_cftable_entry_t *dflt,
207 unsigned int vcc,
208 void *priv_data)
209{ 168{
210 struct pcmcia_config_check *stk = priv_data; 169 int *is_kme = priv_data;
211
212 /* Check for matching Vcc, unless we're desperate */
213 if (!stk->skip_vcc) {
214 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
215 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
216 return -ENODEV;
217 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
218 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
219 return -ENODEV;
220 }
221 }
222 170
223 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 171 if (!(pdev->resource[0]->flags & IO_DATA_PATH_WIDTH_8)) {
224 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 172 pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
225 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM)) 173 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
226 pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000; 174 }
227 175 pdev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
228 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { 176 pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
229 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; 177
230 pdev->io_lines = io->flags & CISTPL_IO_LINES_MASK; 178 if (pdev->resource[1]->end) {
231 179 pdev->resource[0]->end = 8;
232 pdev->conf.ConfigIndex = cfg->index; 180 pdev->resource[1]->end = (*is_kme) ? 2 : 1;
233 pdev->resource[0]->start = io->win[0].base; 181 } else {
234 if (!(io->flags & CISTPL_IO_16BIT)) { 182 if (pdev->resource[0]->end < 16)
235 pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
236 pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
237 }
238 if (io->nwin == 2) {
239 pdev->resource[0]->end = 8;
240 pdev->resource[1]->start = io->win[1].base;
241 pdev->resource[1]->end = (stk->is_kme) ? 2 : 1;
242 if (pcmcia_request_io(pdev) != 0)
243 return -ENODEV;
244 stk->ctl_base = pdev->resource[1]->start;
245 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
246 pdev->resource[0]->end = io->win[0].len;
247 pdev->resource[1]->end = 0;
248 if (pcmcia_request_io(pdev) != 0)
249 return -ENODEV;
250 stk->ctl_base = pdev->resource[0]->start + 0x0e;
251 } else
252 return -ENODEV; 183 return -ENODEV;
253 /* If we've got this far, we're done */
254 return 0;
255 } 184 }
256 return -ENODEV; 185
186 return pcmcia_request_io(pdev);
257} 187}
258 188
259static int ide_config(struct pcmcia_device *link) 189static int ide_config(struct pcmcia_device *link)
260{ 190{
261 ide_info_t *info = link->priv; 191 ide_info_t *info = link->priv;
262 struct pcmcia_config_check *stk = NULL;
263 int ret = 0, is_kme = 0; 192 int ret = 0, is_kme = 0;
264 unsigned long io_base, ctl_base; 193 unsigned long io_base, ctl_base;
265 struct ide_host *host; 194 struct ide_host *host;
@@ -270,23 +199,21 @@ static int ide_config(struct pcmcia_device *link)
270 ((link->card_id == PRODID_KME_KXLC005_A) || 199 ((link->card_id == PRODID_KME_KXLC005_A) ||
271 (link->card_id == PRODID_KME_KXLC005_B))); 200 (link->card_id == PRODID_KME_KXLC005_B)));
272 201
273 stk = kzalloc(sizeof(*stk), GFP_KERNEL); 202 if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme)) {
274 if (!stk) 203 link->config_flags &= ~CONF_AUTO_CHECK_VCC;
275 goto err_mem; 204 if (pcmcia_loop_config(link, pcmcia_check_one_config, &is_kme))
276 stk->is_kme = is_kme;
277 stk->skip_vcc = io_base = ctl_base = 0;
278
279 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk)) {
280 stk->skip_vcc = 1;
281 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk))
282 goto failed; /* No suitable config found */ 205 goto failed; /* No suitable config found */
283 } 206 }
284 io_base = link->resource[0]->start; 207 io_base = link->resource[0]->start;
285 ctl_base = stk->ctl_base; 208 if (link->resource[1]->end)
209 ctl_base = link->resource[1]->start;
210 else
211 ctl_base = link->resource[0]->start + 0x0e;
286 212
287 if (!link->irq) 213 if (!link->irq)
288 goto failed; 214 goto failed;
289 ret = pcmcia_request_configuration(link, &link->conf); 215
216 ret = pcmcia_enable_device(link);
290 if (ret) 217 if (ret)
291 goto failed; 218 goto failed;
292 219
@@ -311,29 +238,15 @@ static int ide_config(struct pcmcia_device *link)
311 info->host = host; 238 info->host = host;
312 dev_info(&link->dev, "ide-cs: hd%c: Vpp = %d.%d\n", 239 dev_info(&link->dev, "ide-cs: hd%c: Vpp = %d.%d\n",
313 'a' + host->ports[0]->index * 2, 240 'a' + host->ports[0]->index * 2,
314 link->conf.Vpp / 10, link->conf.Vpp % 10); 241 link->vpp / 10, link->vpp % 10);
315 242
316 kfree(stk);
317 return 0; 243 return 0;
318 244
319err_mem:
320 printk(KERN_NOTICE "ide-cs: ide_config failed memory allocation\n");
321 goto failed;
322
323failed: 245failed:
324 kfree(stk);
325 ide_release(link); 246 ide_release(link);
326 return -ENODEV; 247 return -ENODEV;
327} /* ide_config */ 248} /* ide_config */
328 249
329/*======================================================================
330
331 After a card is removed, ide_release() will unregister the net
332 device, and release the PCMCIA configuration. If the device is
333 still open, this will be postponed until it is closed.
334
335======================================================================*/
336
337static void ide_release(struct pcmcia_device *link) 250static void ide_release(struct pcmcia_device *link)
338{ 251{
339 ide_info_t *info = link->priv; 252 ide_info_t *info = link->priv;
@@ -359,15 +272,6 @@ static void ide_release(struct pcmcia_device *link)
359} /* ide_release */ 272} /* ide_release */
360 273
361 274
362/*======================================================================
363
364 The card status event handler. Mostly, this schedules other
365 stuff to run after an event is received. A CARD_REMOVAL event
366 also sets some flags to discourage the ide drivers from
367 talking to the ports.
368
369======================================================================*/
370
371static struct pcmcia_device_id ide_ids[] = { 275static struct pcmcia_device_id ide_ids[] = {
372 PCMCIA_DEVICE_FUNC_ID(4), 276 PCMCIA_DEVICE_FUNC_ID(4),
373 PCMCIA_DEVICE_MANF_CARD(0x0000, 0x0000), /* Corsair */ 277 PCMCIA_DEVICE_MANF_CARD(0x0000, 0x0000), /* Corsair */
@@ -440,9 +344,7 @@ MODULE_DEVICE_TABLE(pcmcia, ide_ids);
440 344
441static struct pcmcia_driver ide_cs_driver = { 345static struct pcmcia_driver ide_cs_driver = {
442 .owner = THIS_MODULE, 346 .owner = THIS_MODULE,
443 .drv = { 347 .name = "ide-cs",
444 .name = "ide-cs",
445 },
446 .probe = ide_probe, 348 .probe = ide_probe,
447 .remove = ide_detach, 349 .remove = ide_detach,
448 .id_table = ide_ids, 350 .id_table = ide_ids,
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
index ec94c66918f6..da36f729ff32 100644
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -1,10 +1,11 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h> 3#include <linux/hdreg.h>
4#include <linux/smp_lock.h> 4#include <linux/mutex.h>
5 5
6#include "ide-disk.h" 6#include "ide-disk.h"
7 7
8static DEFINE_MUTEX(ide_disk_ioctl_mutex);
8static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = { 9static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
9{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address }, 10{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
10{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount }, 11{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
@@ -19,13 +20,13 @@ int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode,
19{ 20{
20 int err; 21 int err;
21 22
22 lock_kernel(); 23 mutex_lock(&ide_disk_ioctl_mutex);
23 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); 24 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
24 if (err != -EOPNOTSUPP) 25 if (err != -EOPNOTSUPP)
25 goto out; 26 goto out;
26 27
27 err = generic_ide_ioctl(drive, bdev, cmd, arg); 28 err = generic_ide_ioctl(drive, bdev, cmd, arg);
28out: 29out:
29 unlock_kernel(); 30 mutex_unlock(&ide_disk_ioctl_mutex);
30 return err; 31 return err;
31} 32}
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index fd3d05ab3417..d267b7affad6 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -5,7 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/ide.h> 6#include <linux/ide.h>
7#include <linux/cdrom.h> 7#include <linux/cdrom.h>
8#include <linux/smp_lock.h> 8#include <linux/mutex.h>
9 9
10#include <asm/unaligned.h> 10#include <asm/unaligned.h>
11 11
@@ -32,6 +32,7 @@
32 * On exit we set nformats to the number of records we've actually initialized. 32 * On exit we set nformats to the number of records we've actually initialized.
33 */ 33 */
34 34
35static DEFINE_MUTEX(ide_floppy_ioctl_mutex);
35static int ide_floppy_get_format_capacities(ide_drive_t *drive, 36static int ide_floppy_get_format_capacities(ide_drive_t *drive,
36 struct ide_atapi_pc *pc, 37 struct ide_atapi_pc *pc,
37 int __user *arg) 38 int __user *arg)
@@ -276,7 +277,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
276 void __user *argp = (void __user *)arg; 277 void __user *argp = (void __user *)arg;
277 int err; 278 int err;
278 279
279 lock_kernel(); 280 mutex_lock(&ide_floppy_ioctl_mutex);
280 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) { 281 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
281 err = ide_floppy_lockdoor(drive, &pc, arg, cmd); 282 err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
282 goto out; 283 goto out;
@@ -298,6 +299,6 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
298 err = generic_ide_ioctl(drive, bdev, cmd, arg); 299 err = generic_ide_ioctl(drive, bdev, cmd, arg);
299 300
300out: 301out:
301 unlock_kernel(); 302 mutex_unlock(&ide_floppy_ioctl_mutex);
302 return err; 303 return err;
303} 304}
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index 70aeeb18833e..35c4b43585e3 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -1,4 +1,3 @@
1#include <linux/smp_lock.h>
2#include <linux/module.h> 1#include <linux/module.h>
3#include <linux/types.h> 2#include <linux/types.h>
4#include <linux/string.h> 3#include <linux/string.h>
@@ -23,6 +22,7 @@
23#define IDE_GD_VERSION "1.18" 22#define IDE_GD_VERSION "1.18"
24 23
25/* module parameters */ 24/* module parameters */
25static DEFINE_MUTEX(ide_gd_mutex);
26static unsigned long debug_mask; 26static unsigned long debug_mask;
27module_param(debug_mask, ulong, 0644); 27module_param(debug_mask, ulong, 0644);
28 28
@@ -242,9 +242,9 @@ static int ide_gd_unlocked_open(struct block_device *bdev, fmode_t mode)
242{ 242{
243 int ret; 243 int ret;
244 244
245 lock_kernel(); 245 mutex_lock(&ide_gd_mutex);
246 ret = ide_gd_open(bdev, mode); 246 ret = ide_gd_open(bdev, mode);
247 unlock_kernel(); 247 mutex_unlock(&ide_gd_mutex);
248 248
249 return ret; 249 return ret;
250} 250}
@@ -257,7 +257,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
257 257
258 ide_debug_log(IDE_DBG_FUNC, "enter"); 258 ide_debug_log(IDE_DBG_FUNC, "enter");
259 259
260 lock_kernel(); 260 mutex_lock(&ide_gd_mutex);
261 if (idkp->openers == 1) 261 if (idkp->openers == 1)
262 drive->disk_ops->flush(drive); 262 drive->disk_ops->flush(drive);
263 263
@@ -269,7 +269,7 @@ static int ide_gd_release(struct gendisk *disk, fmode_t mode)
269 idkp->openers--; 269 idkp->openers--;
270 270
271 ide_disk_put(idkp); 271 ide_disk_put(idkp);
272 unlock_kernel(); 272 mutex_unlock(&ide_gd_mutex);
273 273
274 return 0; 274 return 0;
275} 275}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 4c3d1bfec0c5..068cef0a987a 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1448,19 +1448,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1448 if (hwif == NULL) 1448 if (hwif == NULL)
1449 continue; 1449 continue;
1450 1450
1451 if (hwif->present)
1452 hwif_register_devices(hwif);
1453 }
1454
1455 ide_host_for_each_port(i, hwif, host) {
1456 if (hwif == NULL)
1457 continue;
1458
1459 ide_sysfs_register_port(hwif); 1451 ide_sysfs_register_port(hwif);
1460 ide_proc_register_port(hwif); 1452 ide_proc_register_port(hwif);
1461 1453
1462 if (hwif->present) 1454 if (hwif->present) {
1463 ide_proc_port_register_devices(hwif); 1455 ide_proc_port_register_devices(hwif);
1456 hwif_register_devices(hwif);
1457 }
1464 } 1458 }
1465 1459
1466 return j ? 0 : -1; 1460 return j ? 0 : -1;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 23d1d1c5587c..7ecb1ade8874 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -32,11 +32,9 @@
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/genhd.h> 33#include <linux/genhd.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/smp_lock.h>
36#include <linux/slab.h> 35#include <linux/slab.h>
37#include <linux/pci.h> 36#include <linux/pci.h>
38#include <linux/ide.h> 37#include <linux/ide.h>
39#include <linux/smp_lock.h>
40#include <linux/completion.h> 38#include <linux/completion.h>
41#include <linux/bitops.h> 39#include <linux/bitops.h>
42#include <linux/mutex.h> 40#include <linux/mutex.h>
@@ -220,6 +218,7 @@ typedef struct ide_tape_obj {
220 char write_prot; 218 char write_prot;
221} idetape_tape_t; 219} idetape_tape_t;
222 220
221static DEFINE_MUTEX(ide_tape_mutex);
223static DEFINE_MUTEX(idetape_ref_mutex); 222static DEFINE_MUTEX(idetape_ref_mutex);
224 223
225static DEFINE_MUTEX(idetape_chrdev_mutex); 224static DEFINE_MUTEX(idetape_chrdev_mutex);
@@ -1426,9 +1425,9 @@ static long idetape_chrdev_ioctl(struct file *file,
1426 unsigned int cmd, unsigned long arg) 1425 unsigned int cmd, unsigned long arg)
1427{ 1426{
1428 long ret; 1427 long ret;
1429 lock_kernel(); 1428 mutex_lock(&ide_tape_mutex);
1430 ret = do_idetape_chrdev_ioctl(file, cmd, arg); 1429 ret = do_idetape_chrdev_ioctl(file, cmd, arg);
1431 unlock_kernel(); 1430 mutex_unlock(&ide_tape_mutex);
1432 return ret; 1431 return ret;
1433} 1432}
1434 1433
@@ -1910,9 +1909,9 @@ static int idetape_open(struct block_device *bdev, fmode_t mode)
1910{ 1909{
1911 struct ide_tape_obj *tape; 1910 struct ide_tape_obj *tape;
1912 1911
1913 lock_kernel(); 1912 mutex_lock(&ide_tape_mutex);
1914 tape = ide_tape_get(bdev->bd_disk, false, 0); 1913 tape = ide_tape_get(bdev->bd_disk, false, 0);
1915 unlock_kernel(); 1914 mutex_unlock(&ide_tape_mutex);
1916 1915
1917 if (!tape) 1916 if (!tape)
1918 return -ENXIO; 1917 return -ENXIO;
@@ -1924,9 +1923,9 @@ static int idetape_release(struct gendisk *disk, fmode_t mode)
1924{ 1923{
1925 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); 1924 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
1926 1925
1927 lock_kernel(); 1926 mutex_lock(&ide_tape_mutex);
1928 ide_tape_put(tape); 1927 ide_tape_put(tape);
1929 unlock_kernel(); 1928 mutex_unlock(&ide_tape_mutex);
1930 1929
1931 return 0; 1930 return 0;
1932} 1931}
@@ -1938,11 +1937,11 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
1938 ide_drive_t *drive = tape->drive; 1937 ide_drive_t *drive = tape->drive;
1939 int err; 1938 int err;
1940 1939
1941 lock_kernel(); 1940 mutex_lock(&ide_tape_mutex);
1942 err = generic_ide_ioctl(drive, bdev, cmd, arg); 1941 err = generic_ide_ioctl(drive, bdev, cmd, arg);
1943 if (err == -EINVAL) 1942 if (err == -EINVAL)
1944 err = idetape_blkdev_ioctl(drive, cmd, arg); 1943 err = idetape_blkdev_ioctl(drive, cmd, arg);
1945 unlock_kernel(); 1944 mutex_unlock(&ide_tape_mutex);
1946 1945
1947 return err; 1946 return err;
1948} 1947}
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index a10152bb1427..cb3ccf3ed221 100755..100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -59,18 +59,11 @@
59#include <linux/hrtimer.h> /* ktime_get_real() */ 59#include <linux/hrtimer.h> /* ktime_get_real() */
60#include <trace/events/power.h> 60#include <trace/events/power.h>
61#include <linux/sched.h> 61#include <linux/sched.h>
62#include <asm/mwait.h>
62 63
63#define INTEL_IDLE_VERSION "0.4" 64#define INTEL_IDLE_VERSION "0.4"
64#define PREFIX "intel_idle: " 65#define PREFIX "intel_idle: "
65 66
66#define MWAIT_SUBSTATE_MASK (0xf)
67#define MWAIT_CSTATE_MASK (0xf)
68#define MWAIT_SUBSTATE_SIZE (4)
69#define MWAIT_MAX_NUM_CSTATES 8
70#define CPUID_MWAIT_LEAF (5)
71#define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
72#define CPUID5_ECX_INTERRUPT_BREAK (0x2)
73
74static struct cpuidle_driver intel_idle_driver = { 67static struct cpuidle_driver intel_idle_driver = {
75 .name = "intel_idle", 68 .name = "intel_idle",
76 .owner = THIS_MODULE, 69 .owner = THIS_MODULE,
@@ -83,7 +76,7 @@ static unsigned int mwait_substates;
83/* Reliable LAPIC Timer States, bit 1 for C1 etc. */ 76/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
84static unsigned int lapic_timer_reliable_states; 77static unsigned int lapic_timer_reliable_states;
85 78
86static struct cpuidle_device *intel_idle_cpuidle_devices; 79static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
87static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state); 80static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state);
88 81
89static struct cpuidle_state *cpuidle_state_table; 82static struct cpuidle_state *cpuidle_state_table;
@@ -108,7 +101,7 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
108 .name = "NHM-C3", 101 .name = "NHM-C3",
109 .desc = "MWAIT 0x10", 102 .desc = "MWAIT 0x10",
110 .driver_data = (void *) 0x10, 103 .driver_data = (void *) 0x10,
111 .flags = CPUIDLE_FLAG_TIME_VALID, 104 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
112 .exit_latency = 20, 105 .exit_latency = 20,
113 .power_usage = 500, 106 .power_usage = 500,
114 .target_residency = 80, 107 .target_residency = 80,
@@ -117,7 +110,7 @@ static struct cpuidle_state nehalem_cstates[MWAIT_MAX_NUM_CSTATES] = {
117 .name = "NHM-C6", 110 .name = "NHM-C6",
118 .desc = "MWAIT 0x20", 111 .desc = "MWAIT 0x20",
119 .driver_data = (void *) 0x20, 112 .driver_data = (void *) 0x20,
120 .flags = CPUIDLE_FLAG_TIME_VALID, 113 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
121 .exit_latency = 200, 114 .exit_latency = 200,
122 .power_usage = 350, 115 .power_usage = 350,
123 .target_residency = 800, 116 .target_residency = 800,
@@ -149,7 +142,7 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
149 .name = "ATM-C4", 142 .name = "ATM-C4",
150 .desc = "MWAIT 0x30", 143 .desc = "MWAIT 0x30",
151 .driver_data = (void *) 0x30, 144 .driver_data = (void *) 0x30,
152 .flags = CPUIDLE_FLAG_TIME_VALID, 145 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
153 .exit_latency = 100, 146 .exit_latency = 100,
154 .power_usage = 250, 147 .power_usage = 250,
155 .target_residency = 400, 148 .target_residency = 400,
@@ -157,13 +150,13 @@ static struct cpuidle_state atom_cstates[MWAIT_MAX_NUM_CSTATES] = {
157 { /* MWAIT C5 */ }, 150 { /* MWAIT C5 */ },
158 { /* MWAIT C6 */ 151 { /* MWAIT C6 */
159 .name = "ATM-C6", 152 .name = "ATM-C6",
160 .desc = "MWAIT 0x40", 153 .desc = "MWAIT 0x52",
161 .driver_data = (void *) 0x40, 154 .driver_data = (void *) 0x52,
162 .flags = CPUIDLE_FLAG_TIME_VALID, 155 .flags = CPUIDLE_FLAG_TIME_VALID | CPUIDLE_FLAG_TLB_FLUSHED,
163 .exit_latency = 200, 156 .exit_latency = 140,
164 .power_usage = 150, 157 .power_usage = 150,
165 .target_residency = 800, 158 .target_residency = 560,
166 .enter = NULL }, /* disabled */ 159 .enter = &intel_idle },
167}; 160};
168 161
169/** 162/**
@@ -185,6 +178,16 @@ static int intel_idle(struct cpuidle_device *dev, struct cpuidle_state *state)
185 178
186 local_irq_disable(); 179 local_irq_disable();
187 180
181 /*
182 * If the state flag indicates that the TLB will be flushed or if this
183 * is the deepest c-state supported, do a voluntary leave mm to avoid
184 * costly and mostly unnecessary wakeups for flushing the user TLB's
185 * associated with the active mm.
186 */
187 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED ||
188 (&dev->states[dev->state_count - 1] == state))
189 leave_mm(cpu);
190
188 if (!(lapic_timer_reliable_states & (1 << (cstate)))) 191 if (!(lapic_timer_reliable_states & (1 << (cstate))))
189 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu); 192 clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
190 193
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index d88077a21994..13c88871dc3b 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -463,7 +463,8 @@ static int send_connect(struct iwch_ep *ep)
463 V_MSS_IDX(mtu_idx) | 463 V_MSS_IDX(mtu_idx) |
464 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx); 464 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
465 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10); 465 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
466 opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor); 466 opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
467 V_CONG_CONTROL_FLAVOR(cong_flavor);
467 skb->priority = CPL_PRIORITY_SETUP; 468 skb->priority = CPL_PRIORITY_SETUP;
468 set_arp_failure_handler(skb, act_open_req_arp_failure); 469 set_arp_failure_handler(skb, act_open_req_arp_failure);
469 470
@@ -1280,7 +1281,8 @@ static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb)
1280 V_MSS_IDX(mtu_idx) | 1281 V_MSS_IDX(mtu_idx) |
1281 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx); 1282 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
1282 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10); 1283 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
1283 opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor); 1284 opt2 = F_RX_COALESCE_VALID | V_RX_COALESCE(0) | V_FLAVORS_VALID(1) |
1285 V_CONG_CONTROL_FLAVOR(cong_flavor);
1284 1286
1285 rpl = cplhdr(skb); 1287 rpl = cplhdr(skb);
1286 rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); 1288 rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 51330363c0eb..535fea4fe67f 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -28,7 +28,7 @@ struct evdev {
28 int minor; 28 int minor;
29 struct input_handle handle; 29 struct input_handle handle;
30 wait_queue_head_t wait; 30 wait_queue_head_t wait;
31 struct evdev_client *grab; 31 struct evdev_client __rcu *grab;
32 struct list_head client_list; 32 struct list_head client_list;
33 spinlock_t client_lock; /* protects client_list */ 33 spinlock_t client_lock; /* protects client_list */
34 struct mutex mutex; 34 struct mutex mutex;
@@ -669,6 +669,9 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
669 669
670 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { 670 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) {
671 671
672 if (!dev->absinfo)
673 return -EINVAL;
674
672 t = _IOC_NR(cmd) & ABS_MAX; 675 t = _IOC_NR(cmd) & ABS_MAX;
673 abs = dev->absinfo[t]; 676 abs = dev->absinfo[t];
674 677
@@ -680,10 +683,13 @@ static long evdev_do_ioctl(struct file *file, unsigned int cmd,
680 } 683 }
681 } 684 }
682 685
683 if (_IOC_DIR(cmd) == _IOC_READ) { 686 if (_IOC_DIR(cmd) == _IOC_WRITE) {
684 687
685 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) { 688 if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCSABS(0))) {
686 689
690 if (!dev->absinfo)
691 return -EINVAL;
692
687 t = _IOC_NR(cmd) & ABS_MAX; 693 t = _IOC_NR(cmd) & ABS_MAX;
688 694
689 if (copy_from_user(&abs, p, min_t(size_t, 695 if (copy_from_user(&abs, p, min_t(size_t,
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 502b2f73b434..9d424cebfd2c 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -483,6 +483,9 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
483 483
484 memcpy(joydev->abspam, abspam, len); 484 memcpy(joydev->abspam, abspam, len);
485 485
486 for (i = 0; i < joydev->nabs; i++)
487 joydev->absmap[joydev->abspam[i]] = i;
488
486 out: 489 out:
487 kfree(abspam); 490 kfree(abspam);
488 return retval; 491 return retval;
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 9cc488d21490..aa037fec2f86 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -338,7 +338,7 @@ config KEYBOARD_OPENCORES
338 338
339config KEYBOARD_PXA27x 339config KEYBOARD_PXA27x
340 tristate "PXA27x/PXA3xx keypad support" 340 tristate "PXA27x/PXA3xx keypad support"
341 depends on PXA27x || PXA3xx 341 depends on PXA27x || PXA3xx || ARCH_MMP
342 help 342 help
343 Enable support for PXA27x/PXA3xx keypad controller. 343 Enable support for PXA27x/PXA3xx keypad controller.
344 344
diff --git a/drivers/input/keyboard/pxa27x_keypad.c b/drivers/input/keyboard/pxa27x_keypad.c
index f32404f99189..4b0ec35259a1 100644
--- a/drivers/input/keyboard/pxa27x_keypad.c
+++ b/drivers/input/keyboard/pxa27x_keypad.c
@@ -32,7 +32,7 @@
32#include <asm/mach/map.h> 32#include <asm/mach/map.h>
33 33
34#include <mach/hardware.h> 34#include <mach/hardware.h>
35#include <mach/pxa27x_keypad.h> 35#include <plat/pxa27x_keypad.h>
36/* 36/*
37 * Keypad Controller registers 37 * Keypad Controller registers
38 */ 38 */
@@ -330,11 +330,21 @@ static void pxa27x_keypad_scan_direct(struct pxa27x_keypad *keypad)
330 keypad->direct_key_state = new_state; 330 keypad->direct_key_state = new_state;
331} 331}
332 332
333static void clear_wakeup_event(struct pxa27x_keypad *keypad)
334{
335 struct pxa27x_keypad_platform_data *pdata = keypad->pdata;
336
337 if (pdata->clear_wakeup_event)
338 (pdata->clear_wakeup_event)();
339}
340
333static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id) 341static irqreturn_t pxa27x_keypad_irq_handler(int irq, void *dev_id)
334{ 342{
335 struct pxa27x_keypad *keypad = dev_id; 343 struct pxa27x_keypad *keypad = dev_id;
336 unsigned long kpc = keypad_readl(KPC); 344 unsigned long kpc = keypad_readl(KPC);
337 345
346 clear_wakeup_event(keypad);
347
338 if (kpc & KPC_DI) 348 if (kpc & KPC_DI)
339 pxa27x_keypad_scan_direct(keypad); 349 pxa27x_keypad_scan_direct(keypad);
340 350
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index c19066479057..0b4f54265f62 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -43,7 +43,7 @@
43#include <linux/proc_fs.h> 43#include <linux/proc_fs.h>
44#include <linux/poll.h> 44#include <linux/poll.h>
45#include <linux/rtc.h> 45#include <linux/rtc.h>
46#include <linux/smp_lock.h> 46#include <linux/mutex.h>
47#include <linux/semaphore.h> 47#include <linux/semaphore.h>
48 48
49MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>"); 49MODULE_AUTHOR("Brian S. Julin <bri@calyx.com>");
@@ -52,6 +52,7 @@ MODULE_LICENSE("Dual BSD/GPL");
52 52
53#define RTC_VERSION "1.10d" 53#define RTC_VERSION "1.10d"
54 54
55static DEFINE_MUTEX(hp_sdc_rtc_mutex);
55static unsigned long epoch = 2000; 56static unsigned long epoch = 2000;
56 57
57static struct semaphore i8042tregs; 58static struct semaphore i8042tregs;
@@ -104,7 +105,7 @@ static int hp_sdc_rtc_do_read_bbrtc (struct rtc_time *rtctm)
104 t.endidx = 91; 105 t.endidx = 91;
105 t.seq = tseq; 106 t.seq = tseq;
106 t.act.semaphore = &tsem; 107 t.act.semaphore = &tsem;
107 init_MUTEX_LOCKED(&tsem); 108 sema_init(&tsem, 0);
108 109
109 if (hp_sdc_enqueue_transaction(&t)) return -1; 110 if (hp_sdc_enqueue_transaction(&t)) return -1;
110 111
@@ -665,9 +666,9 @@ static long hp_sdc_rtc_unlocked_ioctl(struct file *file,
665{ 666{
666 int ret; 667 int ret;
667 668
668 lock_kernel(); 669 mutex_lock(&hp_sdc_rtc_mutex);
669 ret = hp_sdc_rtc_ioctl(file, cmd, arg); 670 ret = hp_sdc_rtc_ioctl(file, cmd, arg);
670 unlock_kernel(); 671 mutex_unlock(&hp_sdc_rtc_mutex);
671 672
672 return ret; 673 return ret;
673} 674}
@@ -698,7 +699,7 @@ static int __init hp_sdc_rtc_init(void)
698 return -ENODEV; 699 return -ENODEV;
699#endif 700#endif
700 701
701 init_MUTEX(&i8042tregs); 702 sema_init(&i8042tregs, 1);
702 703
703 if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr))) 704 if ((ret = hp_sdc_request_timer_irq(&hp_sdc_rtc_isr)))
704 return ret; 705 return ret;
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 2771ea778d34..b9410784e6a1 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -404,6 +404,13 @@ static int uinput_setup_device(struct uinput_device *udev, const char __user *bu
404 retval = uinput_validate_absbits(dev); 404 retval = uinput_validate_absbits(dev);
405 if (retval < 0) 405 if (retval < 0)
406 goto exit; 406 goto exit;
407 if (test_bit(ABS_MT_SLOT, dev->absbit)) {
408 int nslot = input_abs_get_max(dev, ABS_MT_SLOT) + 1;
409 input_mt_create_slots(dev, nslot);
410 input_set_events_per_packet(dev, 6 * nslot);
411 } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) {
412 input_set_events_per_packet(dev, 60);
413 }
407 } 414 }
408 415
409 udev->state = UIST_SETUP_COMPLETE; 416 udev->state = UIST_SETUP_COMPLETE;
diff --git a/drivers/input/serio/hil_mlc.c b/drivers/input/serio/hil_mlc.c
index c92f4edfee7b..e5624d8f1709 100644
--- a/drivers/input/serio/hil_mlc.c
+++ b/drivers/input/serio/hil_mlc.c
@@ -915,15 +915,15 @@ int hil_mlc_register(hil_mlc *mlc)
915 mlc->ostarted = 0; 915 mlc->ostarted = 0;
916 916
917 rwlock_init(&mlc->lock); 917 rwlock_init(&mlc->lock);
918 init_MUTEX(&mlc->osem); 918 sema_init(&mlc->osem, 1);
919 919
920 init_MUTEX(&mlc->isem); 920 sema_init(&mlc->isem, 1);
921 mlc->icount = -1; 921 mlc->icount = -1;
922 mlc->imatch = 0; 922 mlc->imatch = 0;
923 923
924 mlc->opercnt = 0; 924 mlc->opercnt = 0;
925 925
926 init_MUTEX_LOCKED(&(mlc->csem)); 926 sema_init(&(mlc->csem), 0);
927 927
928 hil_mlc_clear_di_scratch(mlc); 928 hil_mlc_clear_di_scratch(mlc);
929 hil_mlc_clear_di_map(mlc, 0); 929 hil_mlc_clear_di_map(mlc, 0);
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index bcc2d30ec245..8c0b51c31424 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -905,7 +905,7 @@ static int __init hp_sdc_init(void)
905 ts_sync[1] = 0x0f; 905 ts_sync[1] = 0x0f;
906 ts_sync[2] = ts_sync[3] = ts_sync[4] = ts_sync[5] = 0; 906 ts_sync[2] = ts_sync[3] = ts_sync[4] = ts_sync[5] = 0;
907 t_sync.act.semaphore = &s_sync; 907 t_sync.act.semaphore = &s_sync;
908 init_MUTEX_LOCKED(&s_sync); 908 sema_init(&s_sync, 0);
909 hp_sdc_enqueue_transaction(&t_sync); 909 hp_sdc_enqueue_transaction(&t_sync);
910 down(&s_sync); /* Wait for t_sync to complete */ 910 down(&s_sync); /* Wait for t_sync to complete */
911 911
@@ -1039,7 +1039,7 @@ static int __init hp_sdc_register(void)
1039 return hp_sdc.dev_err; 1039 return hp_sdc.dev_err;
1040 } 1040 }
1041 1041
1042 init_MUTEX_LOCKED(&tq_init_sem); 1042 sema_init(&tq_init_sem, 0);
1043 1043
1044 tq_init.actidx = 0; 1044 tq_init.actidx = 0;
1045 tq_init.idx = 1; 1045 tq_init.idx = 1;
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 42ba3691d908..b35876ee6908 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -103,27 +103,26 @@ static void wacom_sys_irq(struct urb *urb)
103static int wacom_open(struct input_dev *dev) 103static int wacom_open(struct input_dev *dev)
104{ 104{
105 struct wacom *wacom = input_get_drvdata(dev); 105 struct wacom *wacom = input_get_drvdata(dev);
106 int retval = 0;
106 107
107 mutex_lock(&wacom->lock); 108 if (usb_autopm_get_interface(wacom->intf) < 0)
108
109 wacom->irq->dev = wacom->usbdev;
110
111 if (usb_autopm_get_interface(wacom->intf) < 0) {
112 mutex_unlock(&wacom->lock);
113 return -EIO; 109 return -EIO;
114 } 110
111 mutex_lock(&wacom->lock);
115 112
116 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) { 113 if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
117 usb_autopm_put_interface(wacom->intf); 114 retval = -EIO;
118 mutex_unlock(&wacom->lock); 115 goto out;
119 return -EIO;
120 } 116 }
121 117
122 wacom->open = true; 118 wacom->open = true;
123 wacom->intf->needs_remote_wakeup = 1; 119 wacom->intf->needs_remote_wakeup = 1;
124 120
121out:
125 mutex_unlock(&wacom->lock); 122 mutex_unlock(&wacom->lock);
126 return 0; 123 if (retval)
124 usb_autopm_put_interface(wacom->intf);
125 return retval;
127} 126}
128 127
129static void wacom_close(struct input_dev *dev) 128static void wacom_close(struct input_dev *dev)
@@ -135,6 +134,8 @@ static void wacom_close(struct input_dev *dev)
135 wacom->open = false; 134 wacom->open = false;
136 wacom->intf->needs_remote_wakeup = 0; 135 wacom->intf->needs_remote_wakeup = 0;
137 mutex_unlock(&wacom->lock); 136 mutex_unlock(&wacom->lock);
137
138 usb_autopm_put_interface(wacom->intf);
138} 139}
139 140
140static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc, 141static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 6e29badb969e..47fd7a041c52 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -442,8 +442,10 @@ static void wacom_intuos_general(struct wacom_wac *wacom)
442 /* general pen packet */ 442 /* general pen packet */
443 if ((data[1] & 0xb8) == 0xa0) { 443 if ((data[1] & 0xb8) == 0xa0) {
444 t = (data[6] << 2) | ((data[7] >> 6) & 3); 444 t = (data[6] << 2) | ((data[7] >> 6) & 3);
445 if (features->type >= INTUOS4S && features->type <= INTUOS4L) 445 if ((features->type >= INTUOS4S && features->type <= INTUOS4L) ||
446 features->type == WACOM_21UX2) {
446 t = (t << 1) | (data[1] & 1); 447 t = (t << 1) | (data[1] & 1);
448 }
447 input_report_abs(input, ABS_PRESSURE, t); 449 input_report_abs(input, ABS_PRESSURE, t);
448 input_report_abs(input, ABS_TILT_X, 450 input_report_abs(input, ABS_TILT_X,
449 ((data[7] << 1) & 0x7e) | (data[8] >> 7)); 451 ((data[7] << 1) & 0x7e) | (data[8] >> 7));
diff --git a/drivers/isdn/act2000/act2000.h b/drivers/isdn/act2000/act2000.h
index d4c50512a1ff..88c9423500d8 100644
--- a/drivers/isdn/act2000/act2000.h
+++ b/drivers/isdn/act2000/act2000.h
@@ -141,9 +141,9 @@ typedef struct irq_data_isa {
141 __u8 rcvhdr[8]; 141 __u8 rcvhdr[8];
142} irq_data_isa; 142} irq_data_isa;
143 143
144typedef union irq_data { 144typedef union act2000_irq_data {
145 irq_data_isa isa; 145 irq_data_isa isa;
146} irq_data; 146} act2000_irq_data;
147 147
148/* 148/*
149 * Per card driver data 149 * Per card driver data
@@ -176,7 +176,7 @@ typedef struct act2000_card {
176 char *status_buf_read; 176 char *status_buf_read;
177 char *status_buf_write; 177 char *status_buf_write;
178 char *status_buf_end; 178 char *status_buf_end;
179 irq_data idat; /* Data used for IRQ handler */ 179 act2000_irq_data idat; /* Data used for IRQ handler */
180 isdn_if interface; /* Interface to upper layer */ 180 isdn_if interface; /* Interface to upper layer */
181 char regname[35]; /* Name used for request_region */ 181 char regname[35]; /* Name used for request_region */
182} act2000_card; 182} act2000_card;
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index 09b1795516f4..91f06a3ef002 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -20,7 +20,6 @@
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/system.h> 21#include <asm/system.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/ciscode.h> 24#include <pcmcia/ciscode.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
@@ -39,87 +38,32 @@ MODULE_LICENSE("GPL");
39 38
40/*====================================================================*/ 39/*====================================================================*/
41 40
42/*
43 The event() function is this driver's Card Services event handler.
44 It will be called by Card Services when an appropriate card status
45 event is received. The config() and release() entry points are
46 used to configure or release a socket, in response to card insertion
47 and ejection events. They are invoked from the skeleton event
48 handler.
49*/
50
51static int avmcs_config(struct pcmcia_device *link); 41static int avmcs_config(struct pcmcia_device *link);
52static void avmcs_release(struct pcmcia_device *link); 42static void avmcs_release(struct pcmcia_device *link);
53
54/*
55 The attach() and detach() entry points are used to create and destroy
56 "instances" of the driver, where each instance represents everything
57 needed to manage one actual PCMCIA card.
58*/
59
60static void avmcs_detach(struct pcmcia_device *p_dev); 43static void avmcs_detach(struct pcmcia_device *p_dev);
61 44
62/*======================================================================
63
64 avmcs_attach() creates an "instance" of the driver, allocating
65 local data structures for one device. The device is registered
66 with Card Services.
67
68 The dev_link structure is initialized, but we don't actually
69 configure the card at this point -- we wait until we receive a
70 card insertion event.
71
72======================================================================*/
73
74static int avmcs_probe(struct pcmcia_device *p_dev) 45static int avmcs_probe(struct pcmcia_device *p_dev)
75{ 46{
76
77 /* The io structure describes IO port mapping */
78 p_dev->resource[0]->end = 16;
79 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
80
81 /* General socket configuration */ 47 /* General socket configuration */
82 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 48 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
83 p_dev->conf.IntType = INT_MEMORY_AND_IO; 49 p_dev->config_index = 1;
84 p_dev->conf.ConfigIndex = 1; 50 p_dev->config_regs = PRESENT_OPTION;
85 p_dev->conf.Present = PRESENT_OPTION;
86 51
87 return avmcs_config(p_dev); 52 return avmcs_config(p_dev);
88} /* avmcs_attach */ 53} /* avmcs_attach */
89 54
90/*======================================================================
91
92 This deletes a driver "instance". The device is de-registered
93 with Card Services. If it has been released, all local data
94 structures are freed. Otherwise, the structures will be freed
95 when the device is released.
96
97======================================================================*/
98 55
99static void avmcs_detach(struct pcmcia_device *link) 56static void avmcs_detach(struct pcmcia_device *link)
100{ 57{
101 avmcs_release(link); 58 avmcs_release(link);
102} /* avmcs_detach */ 59} /* avmcs_detach */
103 60
104/*====================================================================== 61static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
105
106 avmcs_config() is scheduled to run after a CARD_INSERTION event
107 is received, to configure the PCMCIA socket, and to make the
108 ethernet device available to the system.
109
110======================================================================*/
111
112static int avmcs_configcheck(struct pcmcia_device *p_dev,
113 cistpl_cftable_entry_t *cf,
114 cistpl_cftable_entry_t *dflt,
115 unsigned int vcc,
116 void *priv_data)
117{ 62{
118 if (cf->io.nwin <= 0) 63 p_dev->resource[0]->end = 16;
119 return -ENODEV; 64 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
65 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
120 66
121 p_dev->resource[0]->start = cf->io.win[0].base;
122 p_dev->resource[0]->end = cf->io.win[0].len;
123 return pcmcia_request_io(p_dev); 67 return pcmcia_request_io(p_dev);
124} 68}
125 69
@@ -150,7 +94,7 @@ static int avmcs_config(struct pcmcia_device *link)
150 /* 94 /*
151 * configure the PCMCIA socket 95 * configure the PCMCIA socket
152 */ 96 */
153 i = pcmcia_request_configuration(link, &link->conf); 97 i = pcmcia_enable_device(link);
154 if (i != 0) { 98 if (i != 0) {
155 pcmcia_disable_device(link); 99 pcmcia_disable_device(link);
156 break; 100 break;
@@ -197,13 +141,6 @@ static int avmcs_config(struct pcmcia_device *link)
197 141
198} /* avmcs_config */ 142} /* avmcs_config */
199 143
200/*======================================================================
201
202 After a card is removed, avmcs_release() will unregister the net
203 device, and release the PCMCIA configuration. If the device is
204 still open, this will be postponed until it is closed.
205
206======================================================================*/
207 144
208static void avmcs_release(struct pcmcia_device *link) 145static void avmcs_release(struct pcmcia_device *link)
209{ 146{
@@ -222,9 +159,7 @@ MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
222 159
223static struct pcmcia_driver avmcs_driver = { 160static struct pcmcia_driver avmcs_driver = {
224 .owner = THIS_MODULE, 161 .owner = THIS_MODULE,
225 .drv = { 162 .name = "avm_cs",
226 .name = "avm_cs",
227 },
228 .probe = avmcs_probe, 163 .probe = avmcs_probe,
229 .remove = avmcs_detach, 164 .remove = avmcs_detach,
230 .id_table = avmcs_ids, 165 .id_table = avmcs_ids,
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 94263c22b874..ac4dd7857cbd 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -20,7 +20,6 @@
20#include <asm/io.h> 20#include <asm/io.h>
21#include <asm/system.h> 21#include <asm/system.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h> 24#include <pcmcia/ds.h>
26#include "hisax_cfg.h" 25#include "hisax_cfg.h"
@@ -40,67 +39,22 @@ module_param(isdnprot, int, 0);
40 39
41/*====================================================================*/ 40/*====================================================================*/
42 41
43/*
44 The event() function is this driver's Card Services event handler.
45 It will be called by Card Services when an appropriate card status
46 event is received. The config() and release() entry points are
47 used to configure or release a socket, in response to card insertion
48 and ejection events. They are invoked from the skeleton event
49 handler.
50*/
51
52static int avma1cs_config(struct pcmcia_device *link) __devinit ; 42static int avma1cs_config(struct pcmcia_device *link) __devinit ;
53static void avma1cs_release(struct pcmcia_device *link); 43static void avma1cs_release(struct pcmcia_device *link);
54
55/*
56 The attach() and detach() entry points are used to create and destroy
57 "instances" of the driver, where each instance represents everything
58 needed to manage one actual PCMCIA card.
59*/
60
61static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ; 44static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
62 45
63
64/*======================================================================
65
66 avma1cs_attach() creates an "instance" of the driver, allocating
67 local data structures for one device. The device is registered
68 with Card Services.
69
70 The dev_link structure is initialized, but we don't actually
71 configure the card at this point -- we wait until we receive a
72 card insertion event.
73
74======================================================================*/
75
76static int __devinit avma1cs_probe(struct pcmcia_device *p_dev) 46static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
77{ 47{
78 dev_dbg(&p_dev->dev, "avma1cs_attach()\n"); 48 dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
79 49
80 /* The io structure describes IO port mapping */
81 p_dev->resource[0]->end = 16;
82 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
83 p_dev->resource[1]->end = 16;
84 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_16;
85
86 /* General socket configuration */ 50 /* General socket configuration */
87 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 51 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
88 p_dev->conf.IntType = INT_MEMORY_AND_IO; 52 p_dev->config_index = 1;
89 p_dev->conf.ConfigIndex = 1; 53 p_dev->config_regs = PRESENT_OPTION;
90 p_dev->conf.Present = PRESENT_OPTION;
91 54
92 return avma1cs_config(p_dev); 55 return avma1cs_config(p_dev);
93} /* avma1cs_attach */ 56} /* avma1cs_attach */
94 57
95/*======================================================================
96
97 This deletes a driver "instance". The device is de-registered
98 with Card Services. If it has been released, all local data
99 structures are freed. Otherwise, the structures will be freed
100 when the device is released.
101
102======================================================================*/
103
104static void __devexit avma1cs_detach(struct pcmcia_device *link) 58static void __devexit avma1cs_detach(struct pcmcia_device *link)
105{ 59{
106 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link); 60 dev_dbg(&link->dev, "avma1cs_detach(0x%p)\n", link);
@@ -108,26 +62,13 @@ static void __devexit avma1cs_detach(struct pcmcia_device *link)
108 kfree(link->priv); 62 kfree(link->priv);
109} /* avma1cs_detach */ 63} /* avma1cs_detach */
110 64
111/*====================================================================== 65static int avma1cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
112
113 avma1cs_config() is scheduled to run after a CARD_INSERTION event
114 is received, to configure the PCMCIA socket, and to make the
115 ethernet device available to the system.
116
117======================================================================*/
118
119static int avma1cs_configcheck(struct pcmcia_device *p_dev,
120 cistpl_cftable_entry_t *cf,
121 cistpl_cftable_entry_t *dflt,
122 unsigned int vcc,
123 void *priv_data)
124{ 66{
125 if (cf->io.nwin <= 0) 67 p_dev->resource[0]->end = 16;
126 return -ENODEV; 68 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
127 69 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
128 p_dev->resource[0]->start = cf->io.win[0].base;
129 p_dev->resource[0]->end = cf->io.win[0].len;
130 p_dev->io_lines = 5; 70 p_dev->io_lines = 5;
71
131 return pcmcia_request_io(p_dev); 72 return pcmcia_request_io(p_dev);
132} 73}
133 74
@@ -161,7 +102,7 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
161 /* 102 /*
162 * configure the PCMCIA socket 103 * configure the PCMCIA socket
163 */ 104 */
164 i = pcmcia_request_configuration(link, &link->conf); 105 i = pcmcia_enable_device(link);
165 if (i != 0) { 106 if (i != 0) {
166 pcmcia_disable_device(link); 107 pcmcia_disable_device(link);
167 break; 108 break;
@@ -175,9 +116,6 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
175 return -ENODEV; 116 return -ENODEV;
176 } 117 }
177 118
178 printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
179 (unsigned int) link->resource[0]->start, link->irq);
180
181 icard.para[0] = link->irq; 119 icard.para[0] = link->irq;
182 icard.para[1] = link->resource[0]->start; 120 icard.para[1] = link->resource[0]->start;
183 icard.protocol = isdnprot; 121 icard.protocol = isdnprot;
@@ -196,14 +134,6 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
196 return 0; 134 return 0;
197} /* avma1cs_config */ 135} /* avma1cs_config */
198 136
199/*======================================================================
200
201 After a card is removed, avma1cs_release() will unregister the net
202 device, and release the PCMCIA configuration. If the device is
203 still open, this will be postponed until it is closed.
204
205======================================================================*/
206
207static void avma1cs_release(struct pcmcia_device *link) 137static void avma1cs_release(struct pcmcia_device *link)
208{ 138{
209 unsigned long minor = (unsigned long) link->priv; 139 unsigned long minor = (unsigned long) link->priv;
@@ -216,7 +146,6 @@ static void avma1cs_release(struct pcmcia_device *link)
216 pcmcia_disable_device(link); 146 pcmcia_disable_device(link);
217} /* avma1cs_release */ 147} /* avma1cs_release */
218 148
219
220static struct pcmcia_device_id avma1cs_ids[] = { 149static struct pcmcia_device_id avma1cs_ids[] = {
221 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb), 150 PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN A", 0x95d42008, 0xadc9d4bb),
222 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b), 151 PCMCIA_DEVICE_PROD_ID12("ISDN", "CARD", 0x8d9761c8, 0x01c5aa7b),
@@ -226,19 +155,15 @@ MODULE_DEVICE_TABLE(pcmcia, avma1cs_ids);
226 155
227static struct pcmcia_driver avma1cs_driver = { 156static struct pcmcia_driver avma1cs_driver = {
228 .owner = THIS_MODULE, 157 .owner = THIS_MODULE,
229 .drv = { 158 .name = "avma1_cs",
230 .name = "avma1_cs",
231 },
232 .probe = avma1cs_probe, 159 .probe = avma1cs_probe,
233 .remove = __devexit_p(avma1cs_detach), 160 .remove = __devexit_p(avma1cs_detach),
234 .id_table = avma1cs_ids, 161 .id_table = avma1cs_ids,
235}; 162};
236 163
237/*====================================================================*/
238
239static int __init init_avma1_cs(void) 164static int __init init_avma1_cs(void)
240{ 165{
241 return(pcmcia_register_driver(&avma1cs_driver)); 166 return pcmcia_register_driver(&avma1cs_driver);
242} 167}
243 168
244static void __exit exit_avma1_cs(void) 169static void __exit exit_avma1_cs(void)
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index 6f9afcd5ca4e..b133378d4dc9 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -801,6 +801,16 @@ static void closecard(int cardnr)
801 ll_unload(csta); 801 ll_unload(csta);
802} 802}
803 803
804static irqreturn_t card_irq(int intno, void *dev_id)
805{
806 struct IsdnCardState *cs = dev_id;
807 irqreturn_t ret = cs->irq_func(intno, cs);
808
809 if (ret == IRQ_HANDLED)
810 cs->irq_cnt++;
811 return ret;
812}
813
804static int init_card(struct IsdnCardState *cs) 814static int init_card(struct IsdnCardState *cs)
805{ 815{
806 int irq_cnt, cnt = 3, ret; 816 int irq_cnt, cnt = 3, ret;
@@ -809,10 +819,10 @@ static int init_card(struct IsdnCardState *cs)
809 ret = cs->cardmsg(cs, CARD_INIT, NULL); 819 ret = cs->cardmsg(cs, CARD_INIT, NULL);
810 return(ret); 820 return(ret);
811 } 821 }
812 irq_cnt = kstat_irqs(cs->irq); 822 irq_cnt = cs->irq_cnt = 0;
813 printk(KERN_INFO "%s: IRQ %d count %d\n", CardType[cs->typ], 823 printk(KERN_INFO "%s: IRQ %d count %d\n", CardType[cs->typ],
814 cs->irq, irq_cnt); 824 cs->irq, irq_cnt);
815 if (request_irq(cs->irq, cs->irq_func, cs->irq_flags, "HiSax", cs)) { 825 if (request_irq(cs->irq, card_irq, cs->irq_flags, "HiSax", cs)) {
816 printk(KERN_WARNING "HiSax: couldn't get interrupt %d\n", 826 printk(KERN_WARNING "HiSax: couldn't get interrupt %d\n",
817 cs->irq); 827 cs->irq);
818 return 1; 828 return 1;
@@ -822,8 +832,8 @@ static int init_card(struct IsdnCardState *cs)
822 /* Timeout 10ms */ 832 /* Timeout 10ms */
823 msleep(10); 833 msleep(10);
824 printk(KERN_INFO "%s: IRQ %d count %d\n", 834 printk(KERN_INFO "%s: IRQ %d count %d\n",
825 CardType[cs->typ], cs->irq, kstat_irqs(cs->irq)); 835 CardType[cs->typ], cs->irq, cs->irq_cnt);
826 if (kstat_irqs(cs->irq) == irq_cnt) { 836 if (cs->irq_cnt == irq_cnt) {
827 printk(KERN_WARNING 837 printk(KERN_WARNING
828 "%s: IRQ(%d) getting no interrupts during init %d\n", 838 "%s: IRQ(%d) getting no interrupts during init %d\n",
829 CardType[cs->typ], cs->irq, 4 - cnt); 839 CardType[cs->typ], cs->irq, 4 - cnt);
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index b3c08aaf41c4..496d477af0f8 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -46,7 +46,6 @@
46#include <asm/io.h> 46#include <asm/io.h>
47#include <asm/system.h> 47#include <asm/system.h>
48 48
49#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h> 49#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h> 50#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h> 51#include <pcmcia/ds.h>
@@ -64,26 +63,8 @@ MODULE_LICENSE("Dual MPL/GPL");
64static int protocol = 2; /* EURO-ISDN Default */ 63static int protocol = 2; /* EURO-ISDN Default */
65module_param(protocol, int, 0); 64module_param(protocol, int, 0);
66 65
67/*====================================================================*/
68
69/*
70 The event() function is this driver's Card Services event handler.
71 It will be called by Card Services when an appropriate card status
72 event is received. The config() and release() entry points are
73 used to configure or release a socket, in response to card insertion
74 and ejection events. They are invoked from the elsa_cs event
75 handler.
76*/
77
78static int elsa_cs_config(struct pcmcia_device *link) __devinit ; 66static int elsa_cs_config(struct pcmcia_device *link) __devinit ;
79static void elsa_cs_release(struct pcmcia_device *link); 67static void elsa_cs_release(struct pcmcia_device *link);
80
81/*
82 The attach() and detach() entry points are used to create and destroy
83 "instances" of the driver, where each instance represents everything
84 needed to manage one actual PCMCIA card.
85*/
86
87static void elsa_cs_detach(struct pcmcia_device *p_dev) __devexit; 68static void elsa_cs_detach(struct pcmcia_device *p_dev) __devexit;
88 69
89typedef struct local_info_t { 70typedef struct local_info_t {
@@ -92,18 +73,6 @@ typedef struct local_info_t {
92 int cardnr; 73 int cardnr;
93} local_info_t; 74} local_info_t;
94 75
95/*======================================================================
96
97 elsa_cs_attach() creates an "instance" of the driver, allocatingx
98 local data structures for one device. The device is registered
99 with Card Services.
100
101 The dev_link structure is initialized, but we don't actually
102 configure the card at this point -- we wait until we receive a
103 card insertion event.
104
105======================================================================*/
106
107static int __devinit elsa_cs_probe(struct pcmcia_device *link) 76static int __devinit elsa_cs_probe(struct pcmcia_device *link)
108{ 77{
109 local_info_t *local; 78 local_info_t *local;
@@ -119,31 +88,9 @@ static int __devinit elsa_cs_probe(struct pcmcia_device *link)
119 88
120 local->cardnr = -1; 89 local->cardnr = -1;
121 90
122 /*
123 General socket configuration defaults can go here. In this
124 client, we assume very little, and rely on the CIS for almost
125 everything. In most clients, many details (i.e., number, sizes,
126 and attributes of IO windows) are fixed by the nature of the
127 device, and can be hard-wired here.
128 */
129 link->resource[0]->end = 8;
130 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
131
132 link->conf.Attributes = CONF_ENABLE_IRQ;
133 link->conf.IntType = INT_MEMORY_AND_IO;
134
135 return elsa_cs_config(link); 91 return elsa_cs_config(link);
136} /* elsa_cs_attach */ 92} /* elsa_cs_attach */
137 93
138/*======================================================================
139
140 This deletes a driver "instance". The device is de-registered
141 with Card Services. If it has been released, all local data
142 structures are freed. Otherwise, the structures will be freed
143 when the device is released.
144
145======================================================================*/
146
147static void __devexit elsa_cs_detach(struct pcmcia_device *link) 94static void __devexit elsa_cs_detach(struct pcmcia_device *link)
148{ 95{
149 local_info_t *info = link->priv; 96 local_info_t *info = link->priv;
@@ -156,27 +103,17 @@ static void __devexit elsa_cs_detach(struct pcmcia_device *link)
156 kfree(info); 103 kfree(info);
157} /* elsa_cs_detach */ 104} /* elsa_cs_detach */
158 105
159/*====================================================================== 106static int elsa_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
160
161 elsa_cs_config() is scheduled to run after a CARD_INSERTION event
162 is received, to configure the PCMCIA socket, and to make the
163 device available to the system.
164
165======================================================================*/
166
167static int elsa_cs_configcheck(struct pcmcia_device *p_dev,
168 cistpl_cftable_entry_t *cf,
169 cistpl_cftable_entry_t *dflt,
170 unsigned int vcc,
171 void *priv_data)
172{ 107{
173 int j; 108 int j;
174 109
175 p_dev->io_lines = 3; 110 p_dev->io_lines = 3;
111 p_dev->resource[0]->end = 8;
112 p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
113 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
176 114
177 if ((cf->io.nwin > 0) && cf->io.win[0].base) { 115 if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
178 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n"); 116 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
179 p_dev->resource[0]->start = cf->io.win[0].base;
180 if (!pcmcia_request_io(p_dev)) 117 if (!pcmcia_request_io(p_dev))
181 return 0; 118 return 0;
182 } else { 119 } else {
@@ -199,6 +136,8 @@ static int __devinit elsa_cs_config(struct pcmcia_device *link)
199 dev_dbg(&link->dev, "elsa_config(0x%p)\n", link); 136 dev_dbg(&link->dev, "elsa_config(0x%p)\n", link);
200 dev = link->priv; 137 dev = link->priv;
201 138
139 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
140
202 i = pcmcia_loop_config(link, elsa_cs_configcheck, NULL); 141 i = pcmcia_loop_config(link, elsa_cs_configcheck, NULL);
203 if (i != 0) 142 if (i != 0)
204 goto failed; 143 goto failed;
@@ -206,21 +145,10 @@ static int __devinit elsa_cs_config(struct pcmcia_device *link)
206 if (!link->irq) 145 if (!link->irq)
207 goto failed; 146 goto failed;
208 147
209 i = pcmcia_request_configuration(link, &link->conf); 148 i = pcmcia_enable_device(link);
210 if (i != 0) 149 if (i != 0)
211 goto failed; 150 goto failed;
212 151
213 /* Finally, report what we've done */
214 dev_info(&link->dev, "index 0x%02x: ",
215 link->conf.ConfigIndex);
216 if (link->conf.Attributes & CONF_ENABLE_IRQ)
217 printk(", irq %d", link->irq);
218 if (link->resource[0])
219 printk(" & %pR", link->resource[0]);
220 if (link->resource[1])
221 printk(" & %pR", link->resource[1]);
222 printk("\n");
223
224 icard.para[0] = link->irq; 152 icard.para[0] = link->irq;
225 icard.para[1] = link->resource[0]->start; 153 icard.para[1] = link->resource[0]->start;
226 icard.protocol = protocol; 154 icard.protocol = protocol;
@@ -240,14 +168,6 @@ failed:
240 return -ENODEV; 168 return -ENODEV;
241} /* elsa_cs_config */ 169} /* elsa_cs_config */
242 170
243/*======================================================================
244
245 After a card is removed, elsa_cs_release() will unregister the net
246 device, and release the PCMCIA configuration. If the device is
247 still open, this will be postponed until it is closed.
248
249======================================================================*/
250
251static void elsa_cs_release(struct pcmcia_device *link) 171static void elsa_cs_release(struct pcmcia_device *link)
252{ 172{
253 local_info_t *local = link->priv; 173 local_info_t *local = link->priv;
@@ -291,9 +211,7 @@ MODULE_DEVICE_TABLE(pcmcia, elsa_ids);
291 211
292static struct pcmcia_driver elsa_cs_driver = { 212static struct pcmcia_driver elsa_cs_driver = {
293 .owner = THIS_MODULE, 213 .owner = THIS_MODULE,
294 .drv = { 214 .name = "elsa_cs",
295 .name = "elsa_cs",
296 },
297 .probe = elsa_cs_probe, 215 .probe = elsa_cs_probe,
298 .remove = __devexit_p(elsa_cs_detach), 216 .remove = __devexit_p(elsa_cs_detach),
299 .id_table = elsa_ids, 217 .id_table = elsa_ids,
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 832a87855ffb..32ab3924aa73 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -959,6 +959,7 @@ struct IsdnCardState {
959 u_long event; 959 u_long event;
960 struct work_struct tqueue; 960 struct work_struct tqueue;
961 struct timer_list dbusytimer; 961 struct timer_list dbusytimer;
962 unsigned int irq_cnt;
962#ifdef ERROR_STATISTIC 963#ifdef ERROR_STATISTIC
963 int err_crc; 964 int err_crc;
964 int err_tx; 965 int err_tx;
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index a024192b672a..360204bc2777 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -46,7 +46,6 @@
46#include <asm/io.h> 46#include <asm/io.h>
47#include <asm/system.h> 47#include <asm/system.h>
48 48
49#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h> 49#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h> 50#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h> 51#include <pcmcia/ds.h>
@@ -64,26 +63,9 @@ MODULE_LICENSE("Dual MPL/GPL");
64static int protocol = 2; /* EURO-ISDN Default */ 63static int protocol = 2; /* EURO-ISDN Default */
65module_param(protocol, int, 0); 64module_param(protocol, int, 0);
66 65
67/*====================================================================*/
68
69/*
70 The event() function is this driver's Card Services event handler.
71 It will be called by Card Services when an appropriate card status
72 event is received. The config() and release() entry points are
73 used to configure or release a socket, in response to card
74 insertion and ejection events. They are invoked from the sedlbauer
75 event handler.
76*/
77
78static int sedlbauer_config(struct pcmcia_device *link) __devinit ; 66static int sedlbauer_config(struct pcmcia_device *link) __devinit ;
79static void sedlbauer_release(struct pcmcia_device *link); 67static void sedlbauer_release(struct pcmcia_device *link);
80 68
81/*
82 The attach() and detach() entry points are used to create and destroy
83 "instances" of the driver, where each instance represents everything
84 needed to manage one actual PCMCIA card.
85*/
86
87static void sedlbauer_detach(struct pcmcia_device *p_dev) __devexit; 69static void sedlbauer_detach(struct pcmcia_device *p_dev) __devexit;
88 70
89typedef struct local_info_t { 71typedef struct local_info_t {
@@ -92,18 +74,6 @@ typedef struct local_info_t {
92 int cardnr; 74 int cardnr;
93} local_info_t; 75} local_info_t;
94 76
95/*======================================================================
96
97 sedlbauer_attach() creates an "instance" of the driver, allocating
98 local data structures for one device. The device is registered
99 with Card Services.
100
101 The dev_link structure is initialized, but we don't actually
102 configure the card at this point -- we wait until we receive a
103 card insertion event.
104
105======================================================================*/
106
107static int __devinit sedlbauer_probe(struct pcmcia_device *link) 77static int __devinit sedlbauer_probe(struct pcmcia_device *link)
108{ 78{
109 local_info_t *local; 79 local_info_t *local;
@@ -118,35 +88,9 @@ static int __devinit sedlbauer_probe(struct pcmcia_device *link)
118 local->p_dev = link; 88 local->p_dev = link;
119 link->priv = local; 89 link->priv = local;
120 90
121 /*
122 General socket configuration defaults can go here. In this
123 client, we assume very little, and rely on the CIS for almost
124 everything. In most clients, many details (i.e., number, sizes,
125 and attributes of IO windows) are fixed by the nature of the
126 device, and can be hard-wired here.
127 */
128
129 /* from old sedl_cs
130 */
131 /* The io structure describes IO port mapping */
132 link->resource[0]->end = 8;
133 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
134
135 link->conf.Attributes = 0;
136 link->conf.IntType = INT_MEMORY_AND_IO;
137
138 return sedlbauer_config(link); 91 return sedlbauer_config(link);
139} /* sedlbauer_attach */ 92} /* sedlbauer_attach */
140 93
141/*======================================================================
142
143 This deletes a driver "instance". The device is de-registered
144 with Card Services. If it has been released, all local data
145 structures are freed. Otherwise, the structures will be freed
146 when the device is released.
147
148======================================================================*/
149
150static void __devexit sedlbauer_detach(struct pcmcia_device *link) 94static void __devexit sedlbauer_detach(struct pcmcia_device *link)
151{ 95{
152 dev_dbg(&link->dev, "sedlbauer_detach(0x%p)\n", link); 96 dev_dbg(&link->dev, "sedlbauer_detach(0x%p)\n", link);
@@ -158,70 +102,15 @@ static void __devexit sedlbauer_detach(struct pcmcia_device *link)
158 kfree(link->priv); 102 kfree(link->priv);
159} /* sedlbauer_detach */ 103} /* sedlbauer_detach */
160 104
161/*====================================================================== 105static int sedlbauer_config_check(struct pcmcia_device *p_dev, void *priv_data)
162
163 sedlbauer_config() is scheduled to run after a CARD_INSERTION event
164 is received, to configure the PCMCIA socket, and to make the
165 device available to the system.
166
167======================================================================*/
168static int sedlbauer_config_check(struct pcmcia_device *p_dev,
169 cistpl_cftable_entry_t *cfg,
170 cistpl_cftable_entry_t *dflt,
171 unsigned int vcc,
172 void *priv_data)
173{ 106{
174 if (cfg->index == 0) 107 if (p_dev->config_index == 0)
175 return -ENODEV; 108 return -EINVAL;
176
177 /* Does this card need audio output? */
178 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
179 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
180 p_dev->conf.Status = CCSR_AUDIO_ENA;
181 }
182 109
183 /* Use power settings for Vcc and Vpp if present */ 110 p_dev->io_lines = 3;
184 /* Note that the CIS values need to be rescaled */ 111 return pcmcia_request_io(p_dev);
185 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
186 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
187 return -ENODEV;
188 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
189 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
190 return -ENODEV;
191 }
192
193 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
194 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
195 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
196 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
197
198 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
199
200 /* IO window settings */
201 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
202 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
203 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
204 p_dev->resource[0]->start = io->win[0].base;
205 p_dev->resource[0]->end = io->win[0].len;
206 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
207 p_dev->resource[0]->flags |=
208 pcmcia_io_cfg_data_width(io->flags);
209 if (io->nwin > 1) {
210 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
211 p_dev->resource[1]->start = io->win[1].base;
212 p_dev->resource[1]->end = io->win[1].len;
213 }
214 /* This reserves IO space but doesn't actually enable it */
215 p_dev->io_lines = 3;
216 if (pcmcia_request_io(p_dev) != 0)
217 return -ENODEV;
218 }
219
220 return 0;
221} 112}
222 113
223
224
225static int __devinit sedlbauer_config(struct pcmcia_device *link) 114static int __devinit sedlbauer_config(struct pcmcia_device *link)
226{ 115{
227 int ret; 116 int ret;
@@ -229,44 +118,17 @@ static int __devinit sedlbauer_config(struct pcmcia_device *link)
229 118
230 dev_dbg(&link->dev, "sedlbauer_config(0x%p)\n", link); 119 dev_dbg(&link->dev, "sedlbauer_config(0x%p)\n", link);
231 120
232 /* 121 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_CHECK_VCC |
233 In this loop, we scan the CIS for configuration table entries, 122 CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
234 each of which describes a valid card configuration, including 123
235 voltage, IO window, memory window, and interrupt settings.
236
237 We make no assumptions about the card to be configured: we use
238 just the information available in the CIS. In an ideal world,
239 this would work for any PCMCIA card, but it requires a complete
240 and accurate CIS. In practice, a driver usually "knows" most of
241 these things without consulting the CIS, and most client drivers
242 will only use the CIS to fill in implementation-defined details.
243 */
244 ret = pcmcia_loop_config(link, sedlbauer_config_check, NULL); 124 ret = pcmcia_loop_config(link, sedlbauer_config_check, NULL);
245 if (ret) 125 if (ret)
246 goto failed; 126 goto failed;
247 127
248 /* 128 ret = pcmcia_enable_device(link);
249 This actually configures the PCMCIA socket -- setting up
250 the I/O windows and the interrupt mapping, and putting the
251 card and host interface into "Memory and IO" mode.
252 */
253 ret = pcmcia_request_configuration(link, &link->conf);
254 if (ret) 129 if (ret)
255 goto failed; 130 goto failed;
256 131
257 /* Finally, report what we've done */
258 dev_info(&link->dev, "index 0x%02x:",
259 link->conf.ConfigIndex);
260 if (link->conf.Vpp)
261 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
262 if (link->conf.Attributes & CONF_ENABLE_IRQ)
263 printk(", irq %d", link->irq);
264 if (link->resource[0])
265 printk(" & %pR", link->resource[0]);
266 if (link->resource[1])
267 printk(" & %pR", link->resource[1]);
268 printk("\n");
269
270 icard.para[0] = link->irq; 132 icard.para[0] = link->irq;
271 icard.para[1] = link->resource[0]->start; 133 icard.para[1] = link->resource[0]->start;
272 icard.protocol = protocol; 134 icard.protocol = protocol;
@@ -290,14 +152,6 @@ failed:
290 152
291} /* sedlbauer_config */ 153} /* sedlbauer_config */
292 154
293/*======================================================================
294
295 After a card is removed, sedlbauer_release() will unregister the
296 device, and release the PCMCIA configuration. If the device is
297 still open, this will be postponed until it is closed.
298
299======================================================================*/
300
301static void sedlbauer_release(struct pcmcia_device *link) 155static void sedlbauer_release(struct pcmcia_device *link)
302{ 156{
303 local_info_t *local = link->priv; 157 local_info_t *local = link->priv;
@@ -346,9 +200,7 @@ MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
346 200
347static struct pcmcia_driver sedlbauer_driver = { 201static struct pcmcia_driver sedlbauer_driver = {
348 .owner = THIS_MODULE, 202 .owner = THIS_MODULE,
349 .drv = { 203 .name = "sedlbauer_cs",
350 .name = "sedlbauer_cs",
351 },
352 .probe = sedlbauer_probe, 204 .probe = sedlbauer_probe,
353 .remove = __devexit_p(sedlbauer_detach), 205 .remove = __devexit_p(sedlbauer_detach),
354 .id_table = sedlbauer_ids, 206 .id_table = sedlbauer_ids,
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 7296102ca255..282a4467ef19 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -27,7 +27,6 @@
27#include <asm/io.h> 27#include <asm/io.h>
28#include <asm/system.h> 28#include <asm/system.h>
29 29
30#include <pcmcia/cs.h>
31#include <pcmcia/cistpl.h> 30#include <pcmcia/cistpl.h>
32#include <pcmcia/cisreg.h> 31#include <pcmcia/cisreg.h>
33#include <pcmcia/ds.h> 32#include <pcmcia/ds.h>
@@ -45,26 +44,8 @@ MODULE_LICENSE("GPL");
45static int protocol = 2; /* EURO-ISDN Default */ 44static int protocol = 2; /* EURO-ISDN Default */
46module_param(protocol, int, 0); 45module_param(protocol, int, 0);
47 46
48/*====================================================================*/
49
50/*
51 The event() function is this driver's Card Services event handler.
52 It will be called by Card Services when an appropriate card status
53 event is received. The config() and release() entry points are
54 used to configure or release a socket, in response to card insertion
55 and ejection events. They are invoked from the teles_cs event
56 handler.
57*/
58
59static int teles_cs_config(struct pcmcia_device *link) __devinit ; 47static int teles_cs_config(struct pcmcia_device *link) __devinit ;
60static void teles_cs_release(struct pcmcia_device *link); 48static void teles_cs_release(struct pcmcia_device *link);
61
62/*
63 The attach() and detach() entry points are used to create and destroy
64 "instances" of the driver, where each instance represents everything
65 needed to manage one actual PCMCIA card.
66*/
67
68static void teles_detach(struct pcmcia_device *p_dev) __devexit ; 49static void teles_detach(struct pcmcia_device *p_dev) __devexit ;
69 50
70typedef struct local_info_t { 51typedef struct local_info_t {
@@ -73,18 +54,6 @@ typedef struct local_info_t {
73 int cardnr; 54 int cardnr;
74} local_info_t; 55} local_info_t;
75 56
76/*======================================================================
77
78 teles_attach() creates an "instance" of the driver, allocatingx
79 local data structures for one device. The device is registered
80 with Card Services.
81
82 The dev_link structure is initialized, but we don't actually
83 configure the card at this point -- we wait until we receive a
84 card insertion event.
85
86======================================================================*/
87
88static int __devinit teles_probe(struct pcmcia_device *link) 57static int __devinit teles_probe(struct pcmcia_device *link)
89{ 58{
90 local_info_t *local; 59 local_info_t *local;
@@ -99,31 +68,11 @@ static int __devinit teles_probe(struct pcmcia_device *link)
99 local->p_dev = link; 68 local->p_dev = link;
100 link->priv = local; 69 link->priv = local;
101 70
102 /* 71 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
103 General socket configuration defaults can go here. In this
104 client, we assume very little, and rely on the CIS for almost
105 everything. In most clients, many details (i.e., number, sizes,
106 and attributes of IO windows) are fixed by the nature of the
107 device, and can be hard-wired here.
108 */
109 link->resource[0]->end = 96;
110 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
111
112 link->conf.Attributes = CONF_ENABLE_IRQ;
113 link->conf.IntType = INT_MEMORY_AND_IO;
114 72
115 return teles_cs_config(link); 73 return teles_cs_config(link);
116} /* teles_attach */ 74} /* teles_attach */
117 75
118/*======================================================================
119
120 This deletes a driver "instance". The device is de-registered
121 with Card Services. If it has been released, all local data
122 structures are freed. Otherwise, the structures will be freed
123 when the device is released.
124
125======================================================================*/
126
127static void __devexit teles_detach(struct pcmcia_device *link) 76static void __devexit teles_detach(struct pcmcia_device *link)
128{ 77{
129 local_info_t *info = link->priv; 78 local_info_t *info = link->priv;
@@ -136,27 +85,17 @@ static void __devexit teles_detach(struct pcmcia_device *link)
136 kfree(info); 85 kfree(info);
137} /* teles_detach */ 86} /* teles_detach */
138 87
139/*====================================================================== 88static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
140
141 teles_cs_config() is scheduled to run after a CARD_INSERTION event
142 is received, to configure the PCMCIA socket, and to make the
143 device available to the system.
144
145======================================================================*/
146
147static int teles_cs_configcheck(struct pcmcia_device *p_dev,
148 cistpl_cftable_entry_t *cf,
149 cistpl_cftable_entry_t *dflt,
150 unsigned int vcc,
151 void *priv_data)
152{ 89{
153 int j; 90 int j;
154 91
155 p_dev->io_lines = 5; 92 p_dev->io_lines = 5;
93 p_dev->resource[0]->end = 96;
94 p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
95 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
156 96
157 if ((cf->io.nwin > 0) && cf->io.win[0].base) { 97 if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
158 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n"); 98 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
159 p_dev->resource[0]->start = cf->io.win[0].base;
160 if (!pcmcia_request_io(p_dev)) 99 if (!pcmcia_request_io(p_dev))
161 return 0; 100 return 0;
162 } else { 101 } else {
@@ -186,21 +125,10 @@ static int __devinit teles_cs_config(struct pcmcia_device *link)
186 if (!link->irq) 125 if (!link->irq)
187 goto cs_failed; 126 goto cs_failed;
188 127
189 i = pcmcia_request_configuration(link, &link->conf); 128 i = pcmcia_enable_device(link);
190 if (i != 0) 129 if (i != 0)
191 goto cs_failed; 130 goto cs_failed;
192 131
193 /* Finally, report what we've done */
194 dev_info(&link->dev, "index 0x%02x:",
195 link->conf.ConfigIndex);
196 if (link->conf.Attributes & CONF_ENABLE_IRQ)
197 printk(", irq %d", link->irq);
198 if (link->resource[0])
199 printk(" & %pR", link->resource[0]);
200 if (link->resource[1])
201 printk(" & %pR", link->resource[1]);
202 printk("\n");
203
204 icard.para[0] = link->irq; 132 icard.para[0] = link->irq;
205 icard.para[1] = link->resource[0]->start; 133 icard.para[1] = link->resource[0]->start;
206 icard.protocol = protocol; 134 icard.protocol = protocol;
@@ -222,14 +150,6 @@ cs_failed:
222 return -ENODEV; 150 return -ENODEV;
223} /* teles_cs_config */ 151} /* teles_cs_config */
224 152
225/*======================================================================
226
227 After a card is removed, teles_cs_release() will unregister the net
228 device, and release the PCMCIA configuration. If the device is
229 still open, this will be postponed until it is closed.
230
231======================================================================*/
232
233static void teles_cs_release(struct pcmcia_device *link) 153static void teles_cs_release(struct pcmcia_device *link)
234{ 154{
235 local_info_t *local = link->priv; 155 local_info_t *local = link->priv;
@@ -273,9 +193,7 @@ MODULE_DEVICE_TABLE(pcmcia, teles_ids);
273 193
274static struct pcmcia_driver teles_cs_driver = { 194static struct pcmcia_driver teles_cs_driver = {
275 .owner = THIS_MODULE, 195 .owner = THIS_MODULE,
276 .drv = { 196 .name = "teles_cs",
277 .name = "teles_cs",
278 },
279 .probe = teles_probe, 197 .probe = teles_probe,
280 .remove = __devexit_p(teles_detach), 198 .remove = __devexit_p(teles_detach),
281 .id_table = teles_ids, 199 .id_table = teles_ids,
diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
index 485be8b1e1b3..f0225bc0f267 100644
--- a/drivers/isdn/sc/interrupt.c
+++ b/drivers/isdn/sc/interrupt.c
@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
112 } 112 }
113 else if(callid>=0x0000 && callid<=0x7FFF) 113 else if(callid>=0x0000 && callid<=0x7FFF)
114 { 114 {
115 int len;
116
115 pr_debug("%s: Got Incoming Call\n", 117 pr_debug("%s: Got Incoming Call\n",
116 sc_adapter[card]->devicename); 118 sc_adapter[card]->devicename);
117 strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4])); 119 len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
118 strcpy(setup.eazmsn, 120 sizeof(setup.phone));
119 sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn); 121 if (len >= sizeof(setup.phone))
122 continue;
123 len = strlcpy(setup.eazmsn,
124 sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
125 sizeof(setup.eazmsn));
126 if (len >= sizeof(setup.eazmsn))
127 continue;
120 setup.si1 = 7; 128 setup.si1 = 7;
121 setup.si2 = 0; 129 setup.si2 = 0;
122 setup.plan = 0; 130 setup.plan = 0;
@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
176 * Handle a GetMyNumber Rsp 184 * Handle a GetMyNumber Rsp
177 */ 185 */
178 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){ 186 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
179 strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array); 187 strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
188 rcvmsg.msg_data.byte_array,
189 sizeof(rcvmsg.msg_data.byte_array));
180 continue; 190 continue;
181 } 191 }
182 192
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index e4112622e5a2..cc2a88d5192f 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -304,13 +304,22 @@ config LEDS_MC13783
304 304
305config LEDS_NS2 305config LEDS_NS2
306 tristate "LED support for Network Space v2 GPIO LEDs" 306 tristate "LED support for Network Space v2 GPIO LEDs"
307 depends on MACH_NETSPACE_V2 || MACH_INETSPACE_V2 || MACH_NETSPACE_MAX_V2 307 depends on MACH_NETSPACE_V2 || MACH_INETSPACE_V2 || MACH_NETSPACE_MAX_V2 || D2NET_V2
308 default y 308 default y
309 help 309 help
310 This option enable support for the dual-GPIO LED found on the 310 This option enable support for the dual-GPIO LED found on the
311 Network Space v2 board (and parents). This include Internet Space v2, 311 Network Space v2 board (and parents). This include Internet Space v2,
312 Network Space (Max) v2 and d2 Network v2 boards. 312 Network Space (Max) v2 and d2 Network v2 boards.
313 313
314config LEDS_NETXBIG
315 tristate "LED support for Big Network series LEDs"
316 depends on MACH_NET2BIG_V2 || MACH_NET5BIG_V2
317 default y
318 help
319 This option enable support for LEDs found on the LaCie 2Big
320 and 5Big Network v2 boards. The LEDs are wired to a CPLD and are
321 controlled through a GPIO extension bus.
322
314config LEDS_TRIGGERS 323config LEDS_TRIGGERS
315 bool "LED Trigger support" 324 bool "LED Trigger support"
316 help 325 help
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 7d6b95831f8e..9c96db40ef6d 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_LEDS_ADP5520) += leds-adp5520.o
38obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o 38obj-$(CONFIG_LEDS_DELL_NETBOOKS) += dell-led.o
39obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o 39obj-$(CONFIG_LEDS_MC13783) += leds-mc13783.o
40obj-$(CONFIG_LEDS_NS2) += leds-ns2.o 40obj-$(CONFIG_LEDS_NS2) += leds-ns2.o
41obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o
41 42
42# LED SPI Drivers 43# LED SPI Drivers
43obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o 44obj-$(CONFIG_LEDS_DAC124S085) += leds-dac124s085.o
diff --git a/drivers/leds/leds-netxbig.c b/drivers/leds/leds-netxbig.c
new file mode 100644
index 000000000000..f2e51c134399
--- /dev/null
+++ b/drivers/leds/leds-netxbig.c
@@ -0,0 +1,449 @@
1/*
2 * leds-netxbig.c - Driver for the 2Big and 5Big Network series LEDs
3 *
4 * Copyright (C) 2010 LaCie
5 *
6 * Author: Simon Guinot <sguinot@lacie.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/irq.h>
26#include <linux/slab.h>
27#include <linux/spinlock.h>
28#include <linux/platform_device.h>
29#include <linux/gpio.h>
30#include <linux/leds.h>
31#include <mach/leds-netxbig.h>
32
33/*
34 * GPIO extension bus.
35 */
36
37static DEFINE_SPINLOCK(gpio_ext_lock);
38
39static void gpio_ext_set_addr(struct netxbig_gpio_ext *gpio_ext, int addr)
40{
41 int pin;
42
43 for (pin = 0; pin < gpio_ext->num_addr; pin++)
44 gpio_set_value(gpio_ext->addr[pin], (addr >> pin) & 1);
45}
46
47static void gpio_ext_set_data(struct netxbig_gpio_ext *gpio_ext, int data)
48{
49 int pin;
50
51 for (pin = 0; pin < gpio_ext->num_data; pin++)
52 gpio_set_value(gpio_ext->data[pin], (data >> pin) & 1);
53}
54
55static void gpio_ext_enable_select(struct netxbig_gpio_ext *gpio_ext)
56{
57 /* Enable select is done on the raising edge. */
58 gpio_set_value(gpio_ext->enable, 0);
59 gpio_set_value(gpio_ext->enable, 1);
60}
61
62static void gpio_ext_set_value(struct netxbig_gpio_ext *gpio_ext,
63 int addr, int value)
64{
65 unsigned long flags;
66
67 spin_lock_irqsave(&gpio_ext_lock, flags);
68 gpio_ext_set_addr(gpio_ext, addr);
69 gpio_ext_set_data(gpio_ext, value);
70 gpio_ext_enable_select(gpio_ext);
71 spin_unlock_irqrestore(&gpio_ext_lock, flags);
72}
73
74static int __devinit gpio_ext_init(struct netxbig_gpio_ext *gpio_ext)
75{
76 int err;
77 int i;
78
79 if (unlikely(!gpio_ext))
80 return -EINVAL;
81
82 /* Configure address GPIOs. */
83 for (i = 0; i < gpio_ext->num_addr; i++) {
84 err = gpio_request(gpio_ext->addr[i], "GPIO extension addr");
85 if (err)
86 goto err_free_addr;
87 err = gpio_direction_output(gpio_ext->addr[i], 0);
88 if (err) {
89 gpio_free(gpio_ext->addr[i]);
90 goto err_free_addr;
91 }
92 }
93 /* Configure data GPIOs. */
94 for (i = 0; i < gpio_ext->num_data; i++) {
95 err = gpio_request(gpio_ext->data[i], "GPIO extension data");
96 if (err)
97 goto err_free_data;
98 err = gpio_direction_output(gpio_ext->data[i], 0);
99 if (err) {
100 gpio_free(gpio_ext->data[i]);
101 goto err_free_data;
102 }
103 }
104 /* Configure "enable select" GPIO. */
105 err = gpio_request(gpio_ext->enable, "GPIO extension enable");
106 if (err)
107 goto err_free_data;
108 err = gpio_direction_output(gpio_ext->enable, 0);
109 if (err) {
110 gpio_free(gpio_ext->enable);
111 goto err_free_data;
112 }
113
114 return 0;
115
116err_free_data:
117 for (i = i - 1; i >= 0; i--)
118 gpio_free(gpio_ext->data[i]);
119 i = gpio_ext->num_addr;
120err_free_addr:
121 for (i = i - 1; i >= 0; i--)
122 gpio_free(gpio_ext->addr[i]);
123
124 return err;
125}
126
127static void __devexit gpio_ext_free(struct netxbig_gpio_ext *gpio_ext)
128{
129 int i;
130
131 gpio_free(gpio_ext->enable);
132 for (i = gpio_ext->num_addr - 1; i >= 0; i--)
133 gpio_free(gpio_ext->addr[i]);
134 for (i = gpio_ext->num_data - 1; i >= 0; i--)
135 gpio_free(gpio_ext->data[i]);
136}
137
138/*
139 * Class LED driver.
140 */
141
142struct netxbig_led_data {
143 struct netxbig_gpio_ext *gpio_ext;
144 struct led_classdev cdev;
145 int mode_addr;
146 int *mode_val;
147 int bright_addr;
148 int bright_max;
149 struct netxbig_led_timer *timer;
150 int num_timer;
151 enum netxbig_led_mode mode;
152 int sata;
153 spinlock_t lock;
154};
155
156static int netxbig_led_get_timer_mode(enum netxbig_led_mode *mode,
157 unsigned long delay_on,
158 unsigned long delay_off,
159 struct netxbig_led_timer *timer,
160 int num_timer)
161{
162 int i;
163
164 for (i = 0; i < num_timer; i++) {
165 if (timer[i].delay_on == delay_on &&
166 timer[i].delay_off == delay_off) {
167 *mode = timer[i].mode;
168 return 0;
169 }
170 }
171 return -EINVAL;
172}
173
174static int netxbig_led_blink_set(struct led_classdev *led_cdev,
175 unsigned long *delay_on,
176 unsigned long *delay_off)
177{
178 struct netxbig_led_data *led_dat =
179 container_of(led_cdev, struct netxbig_led_data, cdev);
180 enum netxbig_led_mode mode;
181 int mode_val;
182 int ret;
183
184 /* Look for a LED mode with the requested timer frequency. */
185 ret = netxbig_led_get_timer_mode(&mode, *delay_on, *delay_off,
186 led_dat->timer, led_dat->num_timer);
187 if (ret < 0)
188 return ret;
189
190 mode_val = led_dat->mode_val[mode];
191 if (mode_val == NETXBIG_LED_INVALID_MODE)
192 return -EINVAL;
193
194 spin_lock_irq(&led_dat->lock);
195
196 gpio_ext_set_value(led_dat->gpio_ext, led_dat->mode_addr, mode_val);
197 led_dat->mode = mode;
198
199 spin_unlock_irq(&led_dat->lock);
200
201 return 0;
202}
203
204static void netxbig_led_set(struct led_classdev *led_cdev,
205 enum led_brightness value)
206{
207 struct netxbig_led_data *led_dat =
208 container_of(led_cdev, struct netxbig_led_data, cdev);
209 enum netxbig_led_mode mode;
210 int mode_val, bright_val;
211 int set_brightness = 1;
212 unsigned long flags;
213
214 spin_lock_irqsave(&led_dat->lock, flags);
215
216 if (value == LED_OFF) {
217 mode = NETXBIG_LED_OFF;
218 set_brightness = 0;
219 } else {
220 if (led_dat->sata)
221 mode = NETXBIG_LED_SATA;
222 else if (led_dat->mode == NETXBIG_LED_OFF)
223 mode = NETXBIG_LED_ON;
224 else /* Keep 'timer' mode. */
225 mode = led_dat->mode;
226 }
227 mode_val = led_dat->mode_val[mode];
228
229 gpio_ext_set_value(led_dat->gpio_ext, led_dat->mode_addr, mode_val);
230 led_dat->mode = mode;
231 /*
232 * Note that the brightness register is shared between all the
233 * SATA LEDs. So, change the brightness setting for a single
234 * SATA LED will affect all the others.
235 */
236 if (set_brightness) {
237 bright_val = DIV_ROUND_UP(value * led_dat->bright_max,
238 LED_FULL);
239 gpio_ext_set_value(led_dat->gpio_ext,
240 led_dat->bright_addr, bright_val);
241 }
242
243 spin_unlock_irqrestore(&led_dat->lock, flags);
244}
245
246static ssize_t netxbig_led_sata_store(struct device *dev,
247 struct device_attribute *attr,
248 const char *buff, size_t count)
249{
250 struct led_classdev *led_cdev = dev_get_drvdata(dev);
251 struct netxbig_led_data *led_dat =
252 container_of(led_cdev, struct netxbig_led_data, cdev);
253 unsigned long enable;
254 enum netxbig_led_mode mode;
255 int mode_val;
256 int ret;
257
258 ret = strict_strtoul(buff, 10, &enable);
259 if (ret < 0)
260 return ret;
261
262 enable = !!enable;
263
264 spin_lock_irq(&led_dat->lock);
265
266 if (led_dat->sata == enable) {
267 ret = count;
268 goto exit_unlock;
269 }
270
271 if (led_dat->mode != NETXBIG_LED_ON &&
272 led_dat->mode != NETXBIG_LED_SATA)
273 mode = led_dat->mode; /* Keep modes 'off' and 'timer'. */
274 else if (enable)
275 mode = NETXBIG_LED_SATA;
276 else
277 mode = NETXBIG_LED_ON;
278
279 mode_val = led_dat->mode_val[mode];
280 if (mode_val == NETXBIG_LED_INVALID_MODE) {
281 ret = -EINVAL;
282 goto exit_unlock;
283 }
284
285 gpio_ext_set_value(led_dat->gpio_ext, led_dat->mode_addr, mode_val);
286 led_dat->mode = mode;
287 led_dat->sata = enable;
288
289 ret = count;
290
291exit_unlock:
292 spin_unlock_irq(&led_dat->lock);
293
294 return ret;
295}
296
297static ssize_t netxbig_led_sata_show(struct device *dev,
298 struct device_attribute *attr, char *buf)
299{
300 struct led_classdev *led_cdev = dev_get_drvdata(dev);
301 struct netxbig_led_data *led_dat =
302 container_of(led_cdev, struct netxbig_led_data, cdev);
303
304 return sprintf(buf, "%d\n", led_dat->sata);
305}
306
307static DEVICE_ATTR(sata, 0644, netxbig_led_sata_show, netxbig_led_sata_store);
308
309static void __devexit delete_netxbig_led(struct netxbig_led_data *led_dat)
310{
311 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE)
312 device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
313 led_classdev_unregister(&led_dat->cdev);
314}
315
316static int __devinit
317create_netxbig_led(struct platform_device *pdev,
318 struct netxbig_led_data *led_dat,
319 const struct netxbig_led *template)
320{
321 struct netxbig_led_platform_data *pdata = pdev->dev.platform_data;
322 int ret;
323
324 spin_lock_init(&led_dat->lock);
325 led_dat->gpio_ext = pdata->gpio_ext;
326 led_dat->cdev.name = template->name;
327 led_dat->cdev.default_trigger = template->default_trigger;
328 led_dat->cdev.blink_set = netxbig_led_blink_set;
329 led_dat->cdev.brightness_set = netxbig_led_set;
330 /*
331 * Because the GPIO extension bus don't allow to read registers
332 * value, there is no way to probe the LED initial state.
333 * So, the initial sysfs LED value for the "brightness" and "sata"
334 * attributes are inconsistent.
335 *
336 * Note that the initial LED state can't be reconfigured.
337 * The reason is that the LED behaviour must stay uniform during
338 * the whole boot process (bootloader+linux).
339 */
340 led_dat->sata = 0;
341 led_dat->cdev.brightness = LED_OFF;
342 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
343 led_dat->mode_addr = template->mode_addr;
344 led_dat->mode_val = template->mode_val;
345 led_dat->bright_addr = template->bright_addr;
346 led_dat->bright_max = (1 << pdata->gpio_ext->num_data) - 1;
347 led_dat->timer = pdata->timer;
348 led_dat->num_timer = pdata->num_timer;
349
350 ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
351 if (ret < 0)
352 return ret;
353
354 /*
355 * If available, expose the SATA activity blink capability through
356 * a "sata" sysfs attribute.
357 */
358 if (led_dat->mode_val[NETXBIG_LED_SATA] != NETXBIG_LED_INVALID_MODE) {
359 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
360 if (ret)
361 led_classdev_unregister(&led_dat->cdev);
362 }
363
364 return ret;
365}
366
367static int __devinit netxbig_led_probe(struct platform_device *pdev)
368{
369 struct netxbig_led_platform_data *pdata = pdev->dev.platform_data;
370 struct netxbig_led_data *leds_data;
371 int i;
372 int ret;
373
374 if (!pdata)
375 return -EINVAL;
376
377 leds_data = kzalloc(sizeof(struct netxbig_led_data) * pdata->num_leds,
378 GFP_KERNEL);
379 if (!leds_data)
380 return -ENOMEM;
381
382 ret = gpio_ext_init(pdata->gpio_ext);
383 if (ret < 0)
384 goto err_free_data;
385
386 for (i = 0; i < pdata->num_leds; i++) {
387 ret = create_netxbig_led(pdev, &leds_data[i], &pdata->leds[i]);
388 if (ret < 0)
389 goto err_free_leds;
390 }
391
392 platform_set_drvdata(pdev, leds_data);
393
394 return 0;
395
396err_free_leds:
397 for (i = i - 1; i >= 0; i--)
398 delete_netxbig_led(&leds_data[i]);
399
400 gpio_ext_free(pdata->gpio_ext);
401err_free_data:
402 kfree(leds_data);
403
404 return ret;
405}
406
407static int __devexit netxbig_led_remove(struct platform_device *pdev)
408{
409 struct netxbig_led_platform_data *pdata = pdev->dev.platform_data;
410 struct netxbig_led_data *leds_data;
411 int i;
412
413 leds_data = platform_get_drvdata(pdev);
414
415 for (i = 0; i < pdata->num_leds; i++)
416 delete_netxbig_led(&leds_data[i]);
417
418 gpio_ext_free(pdata->gpio_ext);
419 kfree(leds_data);
420
421 return 0;
422}
423
424static struct platform_driver netxbig_led_driver = {
425 .probe = netxbig_led_probe,
426 .remove = __devexit_p(netxbig_led_remove),
427 .driver = {
428 .name = "leds-netxbig",
429 .owner = THIS_MODULE,
430 },
431};
432MODULE_ALIAS("platform:leds-netxbig");
433
434static int __init netxbig_led_init(void)
435{
436 return platform_driver_register(&netxbig_led_driver);
437}
438
439static void __exit netxbig_led_exit(void)
440{
441 platform_driver_unregister(&netxbig_led_driver);
442}
443
444module_init(netxbig_led_init);
445module_exit(netxbig_led_exit);
446
447MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
448MODULE_DESCRIPTION("LED driver for LaCie xBig Network boards");
449MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 74dce4ba0262..f77d48d0b3e4 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -81,7 +81,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
81 int cmd_level; 81 int cmd_level;
82 int slow_level; 82 int slow_level;
83 83
84 read_lock(&led_dat->rw_lock); 84 read_lock_irq(&led_dat->rw_lock);
85 85
86 cmd_level = gpio_get_value(led_dat->cmd); 86 cmd_level = gpio_get_value(led_dat->cmd);
87 slow_level = gpio_get_value(led_dat->slow); 87 slow_level = gpio_get_value(led_dat->slow);
@@ -95,7 +95,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
95 } 95 }
96 } 96 }
97 97
98 read_unlock(&led_dat->rw_lock); 98 read_unlock_irq(&led_dat->rw_lock);
99 99
100 return ret; 100 return ret;
101} 101}
@@ -104,8 +104,9 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
104 enum ns2_led_modes mode) 104 enum ns2_led_modes mode)
105{ 105{
106 int i; 106 int i;
107 unsigned long flags;
107 108
108 write_lock(&led_dat->rw_lock); 109 write_lock_irqsave(&led_dat->rw_lock, flags);
109 110
110 for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) { 111 for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
111 if (mode == ns2_led_modval[i].mode) { 112 if (mode == ns2_led_modval[i].mode) {
@@ -116,7 +117,7 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
116 } 117 }
117 } 118 }
118 119
119 write_unlock(&led_dat->rw_lock); 120 write_unlock_irqrestore(&led_dat->rw_lock, flags);
120} 121}
121 122
122static void ns2_led_set(struct led_classdev *led_cdev, 123static void ns2_led_set(struct led_classdev *led_cdev,
@@ -140,10 +141,12 @@ static ssize_t ns2_led_sata_store(struct device *dev,
140 struct device_attribute *attr, 141 struct device_attribute *attr,
141 const char *buff, size_t count) 142 const char *buff, size_t count)
142{ 143{
144 struct led_classdev *led_cdev = dev_get_drvdata(dev);
145 struct ns2_led_data *led_dat =
146 container_of(led_cdev, struct ns2_led_data, cdev);
143 int ret; 147 int ret;
144 unsigned long enable; 148 unsigned long enable;
145 enum ns2_led_modes mode; 149 enum ns2_led_modes mode;
146 struct ns2_led_data *led_dat = dev_get_drvdata(dev);
147 150
148 ret = strict_strtoul(buff, 10, &enable); 151 ret = strict_strtoul(buff, 10, &enable);
149 if (ret < 0) 152 if (ret < 0)
@@ -171,7 +174,9 @@ static ssize_t ns2_led_sata_store(struct device *dev,
171static ssize_t ns2_led_sata_show(struct device *dev, 174static ssize_t ns2_led_sata_show(struct device *dev,
172 struct device_attribute *attr, char *buf) 175 struct device_attribute *attr, char *buf)
173{ 176{
174 struct ns2_led_data *led_dat = dev_get_drvdata(dev); 177 struct led_classdev *led_cdev = dev_get_drvdata(dev);
178 struct ns2_led_data *led_dat =
179 container_of(led_cdev, struct ns2_led_data, cdev);
175 180
176 return sprintf(buf, "%d\n", led_dat->sata); 181 return sprintf(buf, "%d\n", led_dat->sata);
177} 182}
@@ -233,7 +238,6 @@ create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
233 if (ret < 0) 238 if (ret < 0)
234 goto err_free_slow; 239 goto err_free_slow;
235 240
236 dev_set_drvdata(led_dat->cdev.dev, led_dat);
237 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata); 241 ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
238 if (ret < 0) 242 if (ret < 0)
239 goto err_free_cdev; 243 goto err_free_cdev;
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 1c4ee6e77937..75049e765191 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -24,7 +24,6 @@
24#include <linux/fs.h> 24#include <linux/fs.h>
25#include <linux/mm.h> 25#include <linux/mm.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/smp_lock.h>
28#include <linux/adb.h> 27#include <linux/adb.h>
29#include <linux/cuda.h> 28#include <linux/cuda.h>
30#include <linux/pmu.h> 29#include <linux/pmu.h>
@@ -55,6 +54,7 @@ extern struct adb_driver adb_iop_driver;
55extern struct adb_driver via_pmu_driver; 54extern struct adb_driver via_pmu_driver;
56extern struct adb_driver macio_adb_driver; 55extern struct adb_driver macio_adb_driver;
57 56
57static DEFINE_MUTEX(adb_mutex);
58static struct adb_driver *adb_driver_list[] = { 58static struct adb_driver *adb_driver_list[] = {
59#ifdef CONFIG_ADB_MACII 59#ifdef CONFIG_ADB_MACII
60 &via_macii_driver, 60 &via_macii_driver,
@@ -83,7 +83,7 @@ static struct adb_driver *adb_controller;
83BLOCKING_NOTIFIER_HEAD(adb_client_list); 83BLOCKING_NOTIFIER_HEAD(adb_client_list);
84static int adb_got_sleep; 84static int adb_got_sleep;
85static int adb_inited; 85static int adb_inited;
86static DECLARE_MUTEX(adb_probe_mutex); 86static DEFINE_SEMAPHORE(adb_probe_mutex);
87static int sleepy_trackpad; 87static int sleepy_trackpad;
88static int autopoll_devs; 88static int autopoll_devs;
89int __adb_probe_sync; 89int __adb_probe_sync;
@@ -647,7 +647,7 @@ static int adb_open(struct inode *inode, struct file *file)
647 struct adbdev_state *state; 647 struct adbdev_state *state;
648 int ret = 0; 648 int ret = 0;
649 649
650 lock_kernel(); 650 mutex_lock(&adb_mutex);
651 if (iminor(inode) > 0 || adb_controller == NULL) { 651 if (iminor(inode) > 0 || adb_controller == NULL) {
652 ret = -ENXIO; 652 ret = -ENXIO;
653 goto out; 653 goto out;
@@ -665,7 +665,7 @@ static int adb_open(struct inode *inode, struct file *file)
665 state->inuse = 1; 665 state->inuse = 1;
666 666
667out: 667out:
668 unlock_kernel(); 668 mutex_unlock(&adb_mutex);
669 return ret; 669 return ret;
670} 670}
671 671
@@ -674,7 +674,7 @@ static int adb_release(struct inode *inode, struct file *file)
674 struct adbdev_state *state = file->private_data; 674 struct adbdev_state *state = file->private_data;
675 unsigned long flags; 675 unsigned long flags;
676 676
677 lock_kernel(); 677 mutex_lock(&adb_mutex);
678 if (state) { 678 if (state) {
679 file->private_data = NULL; 679 file->private_data = NULL;
680 spin_lock_irqsave(&state->lock, flags); 680 spin_lock_irqsave(&state->lock, flags);
@@ -687,7 +687,7 @@ static int adb_release(struct inode *inode, struct file *file)
687 spin_unlock_irqrestore(&state->lock, flags); 687 spin_unlock_irqrestore(&state->lock, flags);
688 } 688 }
689 } 689 }
690 unlock_kernel(); 690 mutex_unlock(&adb_mutex);
691 return 0; 691 return 0;
692} 692}
693 693
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index e58c3d33e035..290cb325a94c 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -19,7 +19,6 @@
19 * the userland interface 19 * the userland interface
20 */ 20 */
21 21
22#include <linux/smp_lock.h>
23#include <linux/types.h> 22#include <linux/types.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/device.h> 24#include <linux/device.h>
@@ -97,6 +96,7 @@ struct smu_device {
97 * I don't think there will ever be more than one SMU, so 96 * I don't think there will ever be more than one SMU, so
98 * for now, just hard code that 97 * for now, just hard code that
99 */ 98 */
99static DEFINE_MUTEX(smu_mutex);
100static struct smu_device *smu; 100static struct smu_device *smu;
101static DEFINE_MUTEX(smu_part_access); 101static DEFINE_MUTEX(smu_part_access);
102static int smu_irq_inited; 102static int smu_irq_inited;
@@ -1095,12 +1095,12 @@ static int smu_open(struct inode *inode, struct file *file)
1095 pp->mode = smu_file_commands; 1095 pp->mode = smu_file_commands;
1096 init_waitqueue_head(&pp->wait); 1096 init_waitqueue_head(&pp->wait);
1097 1097
1098 lock_kernel(); 1098 mutex_lock(&smu_mutex);
1099 spin_lock_irqsave(&smu_clist_lock, flags); 1099 spin_lock_irqsave(&smu_clist_lock, flags);
1100 list_add(&pp->list, &smu_clist); 1100 list_add(&pp->list, &smu_clist);
1101 spin_unlock_irqrestore(&smu_clist_lock, flags); 1101 spin_unlock_irqrestore(&smu_clist_lock, flags);
1102 file->private_data = pp; 1102 file->private_data = pp;
1103 unlock_kernel(); 1103 mutex_unlock(&smu_mutex);
1104 1104
1105 return 0; 1105 return 0;
1106} 1106}
diff --git a/drivers/macintosh/via-pmu-led.c b/drivers/macintosh/via-pmu-led.c
index d242976bcfe7..19c371809d77 100644
--- a/drivers/macintosh/via-pmu-led.c
+++ b/drivers/macintosh/via-pmu-led.c
@@ -92,8 +92,10 @@ static int __init via_pmu_led_init(void)
92 if (dt == NULL) 92 if (dt == NULL)
93 return -ENODEV; 93 return -ENODEV;
94 model = of_get_property(dt, "model", NULL); 94 model = of_get_property(dt, "model", NULL);
95 if (model == NULL) 95 if (model == NULL) {
96 of_node_put(dt);
96 return -ENODEV; 97 return -ENODEV;
98 }
97 if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 && 99 if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
98 strncmp(model, "iBook", strlen("iBook")) != 0 && 100 strncmp(model, "iBook", strlen("iBook")) != 0 &&
99 strcmp(model, "PowerMac7,2") != 0 && 101 strcmp(model, "PowerMac7,2") != 0 &&
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 44d171cc2252..cd29c8248386 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -18,7 +18,7 @@
18 * 18 *
19 */ 19 */
20#include <stdarg.h> 20#include <stdarg.h>
21#include <linux/smp_lock.h> 21#include <linux/mutex.h>
22#include <linux/types.h> 22#include <linux/types.h>
23#include <linux/errno.h> 23#include <linux/errno.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
@@ -73,6 +73,7 @@
73/* How many iterations between battery polls */ 73/* How many iterations between battery polls */
74#define BATTERY_POLLING_COUNT 2 74#define BATTERY_POLLING_COUNT 2
75 75
76static DEFINE_MUTEX(pmu_info_proc_mutex);
76static volatile unsigned char __iomem *via; 77static volatile unsigned char __iomem *via;
77 78
78/* VIA registers - spaced 0x200 bytes apart */ 79/* VIA registers - spaced 0x200 bytes apart */
@@ -2078,7 +2079,7 @@ pmu_open(struct inode *inode, struct file *file)
2078 pp->rb_get = pp->rb_put = 0; 2079 pp->rb_get = pp->rb_put = 0;
2079 spin_lock_init(&pp->lock); 2080 spin_lock_init(&pp->lock);
2080 init_waitqueue_head(&pp->wait); 2081 init_waitqueue_head(&pp->wait);
2081 lock_kernel(); 2082 mutex_lock(&pmu_info_proc_mutex);
2082 spin_lock_irqsave(&all_pvt_lock, flags); 2083 spin_lock_irqsave(&all_pvt_lock, flags);
2083#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) 2084#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
2084 pp->backlight_locker = 0; 2085 pp->backlight_locker = 0;
@@ -2086,7 +2087,7 @@ pmu_open(struct inode *inode, struct file *file)
2086 list_add(&pp->list, &all_pmu_pvt); 2087 list_add(&pp->list, &all_pmu_pvt);
2087 spin_unlock_irqrestore(&all_pvt_lock, flags); 2088 spin_unlock_irqrestore(&all_pvt_lock, flags);
2088 file->private_data = pp; 2089 file->private_data = pp;
2089 unlock_kernel(); 2090 mutex_unlock(&pmu_info_proc_mutex);
2090 return 0; 2091 return 0;
2091} 2092}
2092 2093
@@ -2343,9 +2344,9 @@ static long pmu_unlocked_ioctl(struct file *filp,
2343{ 2344{
2344 int ret; 2345 int ret;
2345 2346
2346 lock_kernel(); 2347 mutex_lock(&pmu_info_proc_mutex);
2347 ret = pmu_ioctl(filp, cmd, arg); 2348 ret = pmu_ioctl(filp, cmd, arg);
2348 unlock_kernel(); 2349 mutex_unlock(&pmu_info_proc_mutex);
2349 2350
2350 return ret; 2351 return ret;
2351} 2352}
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index ed4900ade93a..e4fb58db5454 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1000,10 +1000,11 @@ static int bitmap_init_from_disk(struct bitmap *bitmap, sector_t start)
1000 page = bitmap->sb_page; 1000 page = bitmap->sb_page;
1001 offset = sizeof(bitmap_super_t); 1001 offset = sizeof(bitmap_super_t);
1002 if (!file) 1002 if (!file)
1003 read_sb_page(bitmap->mddev, 1003 page = read_sb_page(
1004 bitmap->mddev->bitmap_info.offset, 1004 bitmap->mddev,
1005 page, 1005 bitmap->mddev->bitmap_info.offset,
1006 index, count); 1006 page,
1007 index, count);
1007 } else if (file) { 1008 } else if (file) {
1008 page = read_page(file, index, bitmap, count); 1009 page = read_page(file, index, bitmap, count);
1009 offset = 0; 1010 offset = 0;
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index ac384b2a6a33..7967eca5a2d5 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -15,7 +15,6 @@
15#include <linux/blkpg.h> 15#include <linux/blkpg.h>
16#include <linux/bio.h> 16#include <linux/bio.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/smp_lock.h>
19#include <linux/mempool.h> 18#include <linux/mempool.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/idr.h> 20#include <linux/idr.h>
@@ -33,6 +32,7 @@
33#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE" 32#define DM_COOKIE_ENV_VAR_NAME "DM_COOKIE"
34#define DM_COOKIE_LENGTH 24 33#define DM_COOKIE_LENGTH 24
35 34
35static DEFINE_MUTEX(dm_mutex);
36static const char *_name = DM_NAME; 36static const char *_name = DM_NAME;
37 37
38static unsigned int major = 0; 38static unsigned int major = 0;
@@ -344,7 +344,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
344{ 344{
345 struct mapped_device *md; 345 struct mapped_device *md;
346 346
347 lock_kernel(); 347 mutex_lock(&dm_mutex);
348 spin_lock(&_minor_lock); 348 spin_lock(&_minor_lock);
349 349
350 md = bdev->bd_disk->private_data; 350 md = bdev->bd_disk->private_data;
@@ -362,7 +362,7 @@ static int dm_blk_open(struct block_device *bdev, fmode_t mode)
362 362
363out: 363out:
364 spin_unlock(&_minor_lock); 364 spin_unlock(&_minor_lock);
365 unlock_kernel(); 365 mutex_unlock(&dm_mutex);
366 366
367 return md ? 0 : -ENXIO; 367 return md ? 0 : -ENXIO;
368} 368}
@@ -371,10 +371,10 @@ static int dm_blk_close(struct gendisk *disk, fmode_t mode)
371{ 371{
372 struct mapped_device *md = disk->private_data; 372 struct mapped_device *md = disk->private_data;
373 373
374 lock_kernel(); 374 mutex_lock(&dm_mutex);
375 atomic_dec(&md->open_count); 375 atomic_dec(&md->open_count);
376 dm_put(md); 376 dm_put(md);
377 unlock_kernel(); 377 mutex_unlock(&dm_mutex);
378 378
379 return 0; 379 return 0;
380} 380}
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 43cf9cc9c1df..dbf822df942a 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -36,7 +36,7 @@
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/sysctl.h> 37#include <linux/sysctl.h>
38#include <linux/seq_file.h> 38#include <linux/seq_file.h>
39#include <linux/smp_lock.h> 39#include <linux/mutex.h>
40#include <linux/buffer_head.h> /* for invalidate_bdev */ 40#include <linux/buffer_head.h> /* for invalidate_bdev */
41#include <linux/poll.h> 41#include <linux/poll.h>
42#include <linux/ctype.h> 42#include <linux/ctype.h>
@@ -57,6 +57,7 @@
57#define DEBUG 0 57#define DEBUG 0
58#define dprintk(x...) ((void)(DEBUG && printk(x))) 58#define dprintk(x...) ((void)(DEBUG && printk(x)))
59 59
60static DEFINE_MUTEX(md_mutex);
60 61
61#ifndef MODULE 62#ifndef MODULE
62static void autostart_arrays(int part); 63static void autostart_arrays(int part);
@@ -1643,7 +1644,9 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
1643 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1; 1644 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
1644 if (rdev->sb_size & bmask) 1645 if (rdev->sb_size & bmask)
1645 rdev->sb_size = (rdev->sb_size | bmask) + 1; 1646 rdev->sb_size = (rdev->sb_size | bmask) + 1;
1646 } 1647 } else
1648 max_dev = le32_to_cpu(sb->max_dev);
1649
1647 for (i=0; i<max_dev;i++) 1650 for (i=0; i<max_dev;i++)
1648 sb->dev_roles[i] = cpu_to_le16(0xfffe); 1651 sb->dev_roles[i] = cpu_to_le16(0xfffe);
1649 1652
@@ -5949,7 +5952,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5949 mddev_t *mddev = mddev_find(bdev->bd_dev); 5952 mddev_t *mddev = mddev_find(bdev->bd_dev);
5950 int err; 5953 int err;
5951 5954
5952 lock_kernel(); 5955 mutex_lock(&md_mutex);
5953 if (mddev->gendisk != bdev->bd_disk) { 5956 if (mddev->gendisk != bdev->bd_disk) {
5954 /* we are racing with mddev_put which is discarding this 5957 /* we are racing with mddev_put which is discarding this
5955 * bd_disk. 5958 * bd_disk.
@@ -5958,7 +5961,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5958 /* Wait until bdev->bd_disk is definitely gone */ 5961 /* Wait until bdev->bd_disk is definitely gone */
5959 flush_scheduled_work(); 5962 flush_scheduled_work();
5960 /* Then retry the open from the top */ 5963 /* Then retry the open from the top */
5961 unlock_kernel(); 5964 mutex_unlock(&md_mutex);
5962 return -ERESTARTSYS; 5965 return -ERESTARTSYS;
5963 } 5966 }
5964 BUG_ON(mddev != bdev->bd_disk->private_data); 5967 BUG_ON(mddev != bdev->bd_disk->private_data);
@@ -5972,7 +5975,7 @@ static int md_open(struct block_device *bdev, fmode_t mode)
5972 5975
5973 check_disk_size_change(mddev->gendisk, bdev); 5976 check_disk_size_change(mddev->gendisk, bdev);
5974 out: 5977 out:
5975 unlock_kernel(); 5978 mutex_unlock(&md_mutex);
5976 return err; 5979 return err;
5977} 5980}
5978 5981
@@ -5981,10 +5984,10 @@ static int md_release(struct gendisk *disk, fmode_t mode)
5981 mddev_t *mddev = disk->private_data; 5984 mddev_t *mddev = disk->private_data;
5982 5985
5983 BUG_ON(!mddev); 5986 BUG_ON(!mddev);
5984 lock_kernel(); 5987 mutex_lock(&md_mutex);
5985 atomic_dec(&mddev->openers); 5988 atomic_dec(&mddev->openers);
5986 mddev_put(mddev); 5989 mddev_put(mddev);
5987 unlock_kernel(); 5990 mutex_unlock(&md_mutex);
5988 5991
5989 return 0; 5992 return 0;
5990} 5993}
@@ -7069,7 +7072,7 @@ void md_check_recovery(mddev_t *mddev)
7069 if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) 7072 if (mddev->ro && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
7070 return; 7073 return;
7071 if ( ! ( 7074 if ( ! (
7072 (mddev->flags && !mddev->external) || 7075 (mddev->flags & ~ (1<<MD_CHANGE_PENDING)) ||
7073 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) || 7076 test_bit(MD_RECOVERY_NEEDED, &mddev->recovery) ||
7074 test_bit(MD_RECOVERY_DONE, &mddev->recovery) || 7077 test_bit(MD_RECOVERY_DONE, &mddev->recovery) ||
7075 (mddev->external == 0 && mddev->safemode == 1) || 7078 (mddev->external == 0 && mddev->safemode == 1) ||
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index ad83a4dcadc3..0b830bbe1d8b 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1839,7 +1839,9 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1839 1839
1840 /* take from bio_init */ 1840 /* take from bio_init */
1841 bio->bi_next = NULL; 1841 bio->bi_next = NULL;
1842 bio->bi_flags &= ~(BIO_POOL_MASK-1);
1842 bio->bi_flags |= 1 << BIO_UPTODATE; 1843 bio->bi_flags |= 1 << BIO_UPTODATE;
1844 bio->bi_comp_cpu = -1;
1843 bio->bi_rw = READ; 1845 bio->bi_rw = READ;
1844 bio->bi_vcnt = 0; 1846 bio->bi_vcnt = 0;
1845 bio->bi_idx = 0; 1847 bio->bi_idx = 0;
@@ -1912,7 +1914,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *skipped, i
1912 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery)) 1914 !test_bit(MD_RECOVERY_REQUESTED, &mddev->recovery))
1913 break; 1915 break;
1914 BUG_ON(sync_blocks < (PAGE_SIZE>>9)); 1916 BUG_ON(sync_blocks < (PAGE_SIZE>>9));
1915 if (len > (sync_blocks<<9)) 1917 if ((len >> 9) > sync_blocks)
1916 len = sync_blocks<<9; 1918 len = sync_blocks<<9;
1917 } 1919 }
1918 1920
diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c
index 7e82a9df726b..7961d59f5cac 100644
--- a/drivers/media/IR/ir-keytable.c
+++ b/drivers/media/IR/ir-keytable.c
@@ -319,7 +319,7 @@ static void ir_timer_keyup(unsigned long cookie)
319 * a keyup event might follow immediately after the keydown. 319 * a keyup event might follow immediately after the keydown.
320 */ 320 */
321 spin_lock_irqsave(&ir->keylock, flags); 321 spin_lock_irqsave(&ir->keylock, flags);
322 if (time_is_after_eq_jiffies(ir->keyup_jiffies)) 322 if (time_is_before_eq_jiffies(ir->keyup_jiffies))
323 ir_keyup(ir); 323 ir_keyup(ir);
324 spin_unlock_irqrestore(&ir->keylock, flags); 324 spin_unlock_irqrestore(&ir->keylock, flags);
325} 325}
@@ -510,6 +510,13 @@ int __ir_input_register(struct input_dev *input_dev,
510 (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ? 510 (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_IR_RAW) ?
511 " in raw mode" : ""); 511 " in raw mode" : "");
512 512
513 /*
514 * Default delay of 250ms is too short for some protocols, expecially
515 * since the timeout is currently set to 250ms. Increase it to 500ms,
516 * to avoid wrong repetition of the keycodes.
517 */
518 input_dev->rep[REP_DELAY] = 500;
519
513 return 0; 520 return 0;
514 521
515out_event: 522out_event:
diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c
index 8a128934e605..1983cd3f3994 100644
--- a/drivers/media/IR/ir-lirc-codec.c
+++ b/drivers/media/IR/ir-lirc-codec.c
@@ -268,7 +268,7 @@ static int ir_lirc_register(struct input_dev *input_dev)
268 features |= LIRC_CAN_SET_SEND_CARRIER; 268 features |= LIRC_CAN_SET_SEND_CARRIER;
269 269
270 if (ir_dev->props->s_tx_duty_cycle) 270 if (ir_dev->props->s_tx_duty_cycle)
271 features |= LIRC_CAN_SET_REC_DUTY_CYCLE; 271 features |= LIRC_CAN_SET_SEND_DUTY_CYCLE;
272 } 272 }
273 273
274 if (ir_dev->props->s_rx_carrier_range) 274 if (ir_dev->props->s_rx_carrier_range)
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
index 43094e7eccfa..8e0e1b1f8c87 100644
--- a/drivers/media/IR/ir-raw-event.c
+++ b/drivers/media/IR/ir-raw-event.c
@@ -279,9 +279,11 @@ int ir_raw_event_register(struct input_dev *input_dev)
279 "rc%u", (unsigned int)ir->devno); 279 "rc%u", (unsigned int)ir->devno);
280 280
281 if (IS_ERR(ir->raw->thread)) { 281 if (IS_ERR(ir->raw->thread)) {
282 int ret = PTR_ERR(ir->raw->thread);
283
282 kfree(ir->raw); 284 kfree(ir->raw);
283 ir->raw = NULL; 285 ir->raw = NULL;
284 return PTR_ERR(ir->raw->thread); 286 return ret;
285 } 287 }
286 288
287 mutex_lock(&ir_raw_handler_lock); 289 mutex_lock(&ir_raw_handler_lock);
diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c
index 96dafc425c8e..46d42467f9b4 100644
--- a/drivers/media/IR/ir-sysfs.c
+++ b/drivers/media/IR/ir-sysfs.c
@@ -67,13 +67,14 @@ static ssize_t show_protocols(struct device *d,
67 char *tmp = buf; 67 char *tmp = buf;
68 int i; 68 int i;
69 69
70 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { 70 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
71 enabled = ir_dev->rc_tab.ir_type; 71 enabled = ir_dev->rc_tab.ir_type;
72 allowed = ir_dev->props->allowed_protos; 72 allowed = ir_dev->props->allowed_protos;
73 } else { 73 } else if (ir_dev->raw) {
74 enabled = ir_dev->raw->enabled_protocols; 74 enabled = ir_dev->raw->enabled_protocols;
75 allowed = ir_raw_get_allowed_protocols(); 75 allowed = ir_raw_get_allowed_protocols();
76 } 76 } else
77 return sprintf(tmp, "[builtin]\n");
77 78
78 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n", 79 IR_dprintk(1, "allowed - 0x%llx, enabled - 0x%llx\n",
79 (long long)allowed, 80 (long long)allowed,
@@ -121,10 +122,14 @@ static ssize_t store_protocols(struct device *d,
121 int rc, i, count = 0; 122 int rc, i, count = 0;
122 unsigned long flags; 123 unsigned long flags;
123 124
124 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) 125 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
125 type = ir_dev->rc_tab.ir_type; 126 type = ir_dev->rc_tab.ir_type;
126 else 127 else if (ir_dev->raw)
127 type = ir_dev->raw->enabled_protocols; 128 type = ir_dev->raw->enabled_protocols;
129 else {
130 IR_dprintk(1, "Protocol switching not supported\n");
131 return -EINVAL;
132 }
128 133
129 while ((tmp = strsep((char **) &data, " \n")) != NULL) { 134 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
130 if (!*tmp) 135 if (!*tmp)
@@ -185,7 +190,7 @@ static ssize_t store_protocols(struct device *d,
185 } 190 }
186 } 191 }
187 192
188 if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE) { 193 if (ir_dev->props && ir_dev->props->driver_type == RC_DRIVER_SCANCODE) {
189 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags); 194 spin_lock_irqsave(&ir_dev->rc_tab.lock, flags);
190 ir_dev->rc_tab.ir_type = type; 195 ir_dev->rc_tab.ir_type = type;
191 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags); 196 spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags);
diff --git a/drivers/media/IR/keymaps/rc-rc6-mce.c b/drivers/media/IR/keymaps/rc-rc6-mce.c
index 64264f7f838f..39557ad401b6 100644
--- a/drivers/media/IR/keymaps/rc-rc6-mce.c
+++ b/drivers/media/IR/keymaps/rc-rc6-mce.c
@@ -19,6 +19,7 @@ static struct ir_scancode rc6_mce[] = {
19 19
20 { 0x800f0416, KEY_PLAY }, 20 { 0x800f0416, KEY_PLAY },
21 { 0x800f0418, KEY_PAUSE }, 21 { 0x800f0418, KEY_PAUSE },
22 { 0x800f046e, KEY_PLAYPAUSE },
22 { 0x800f0419, KEY_STOP }, 23 { 0x800f0419, KEY_STOP },
23 { 0x800f0417, KEY_RECORD }, 24 { 0x800f0417, KEY_RECORD },
24 25
@@ -37,6 +38,8 @@ static struct ir_scancode rc6_mce[] = {
37 { 0x800f0411, KEY_VOLUMEDOWN }, 38 { 0x800f0411, KEY_VOLUMEDOWN },
38 { 0x800f0412, KEY_CHANNELUP }, 39 { 0x800f0412, KEY_CHANNELUP },
39 { 0x800f0413, KEY_CHANNELDOWN }, 40 { 0x800f0413, KEY_CHANNELDOWN },
41 { 0x800f043a, KEY_BRIGHTNESSUP },
42 { 0x800f0480, KEY_BRIGHTNESSDOWN },
40 43
41 { 0x800f0401, KEY_NUMERIC_1 }, 44 { 0x800f0401, KEY_NUMERIC_1 },
42 { 0x800f0402, KEY_NUMERIC_2 }, 45 { 0x800f0402, KEY_NUMERIC_2 },
diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c
index ac6bb2c01a48..bc620e10ef77 100644
--- a/drivers/media/IR/mceusb.c
+++ b/drivers/media/IR/mceusb.c
@@ -120,6 +120,10 @@ static struct usb_device_id mceusb_dev_table[] = {
120 { USB_DEVICE(VENDOR_PHILIPS, 0x0613) }, 120 { USB_DEVICE(VENDOR_PHILIPS, 0x0613) },
121 /* Philips eHome Infrared Transceiver */ 121 /* Philips eHome Infrared Transceiver */
122 { USB_DEVICE(VENDOR_PHILIPS, 0x0815) }, 122 { USB_DEVICE(VENDOR_PHILIPS, 0x0815) },
123 /* Philips/Spinel plus IR transceiver for ASUS */
124 { USB_DEVICE(VENDOR_PHILIPS, 0x206c) },
125 /* Philips/Spinel plus IR transceiver for ASUS */
126 { USB_DEVICE(VENDOR_PHILIPS, 0x2088) },
123 /* Realtek MCE IR Receiver */ 127 /* Realtek MCE IR Receiver */
124 { USB_DEVICE(VENDOR_REALTEK, 0x0161) }, 128 { USB_DEVICE(VENDOR_REALTEK, 0x0161) },
125 /* SMK/Toshiba G83C0004D410 */ 129 /* SMK/Toshiba G83C0004D410 */
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index a28541b2b1a2..bad2cedb8d96 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -19,6 +19,7 @@ comment "Multimedia core support"
19 19
20config VIDEO_DEV 20config VIDEO_DEV
21 tristate "Video For Linux" 21 tristate "Video For Linux"
22 depends on BKL # used in many drivers for ioctl handling, need to kill
22 ---help--- 23 ---help---
23 V4L core support for video capture and overlay devices, webcams and 24 V4L core support for video capture and overlay devices, webcams and
24 AM/FM radio cards. 25 AM/FM radio cards.
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index 7ed74dfc6b92..48e48e8af55a 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -22,7 +22,7 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/smp_lock.h> 25#include <linux/mutex.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/dvb/ca.h> 27#include <linux/dvb/ca.h>
28#include "dvbdev.h" 28#include "dvbdev.h"
@@ -52,6 +52,7 @@
52} while(0) 52} while(0)
53 53
54 54
55static DEFINE_MUTEX(dst_ca_mutex);
55static unsigned int verbose = 5; 56static unsigned int verbose = 5;
56module_param(verbose, int, 0644); 57module_param(verbose, int, 0644);
57MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)"); 58MODULE_PARM_DESC(verbose, "verbose startup messages, default is 1 (yes)");
@@ -564,7 +565,7 @@ static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioct
564 void __user *arg = (void __user *)ioctl_arg; 565 void __user *arg = (void __user *)ioctl_arg;
565 int result = 0; 566 int result = 0;
566 567
567 lock_kernel(); 568 mutex_lock(&dst_ca_mutex);
568 dvbdev = file->private_data; 569 dvbdev = file->private_data;
569 state = (struct dst_state *)dvbdev->priv; 570 state = (struct dst_state *)dvbdev->priv;
570 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL); 571 p_ca_message = kmalloc(sizeof (struct ca_msg), GFP_KERNEL);
@@ -652,7 +653,7 @@ static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioct
652 kfree (p_ca_slot_info); 653 kfree (p_ca_slot_info);
653 kfree (p_ca_caps); 654 kfree (p_ca_caps);
654 655
655 unlock_kernel(); 656 mutex_unlock(&dst_ca_mutex);
656 return result; 657 return result;
657} 658}
658 659
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 75c20ac82c0f..ad1f61d301e1 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/smp_lock.h>
29#include <linux/poll.h> 28#include <linux/poll.h>
30#include <linux/ioctl.h> 29#include <linux/ioctl.h>
31#include <linux/wait.h> 30#include <linux/wait.h>
@@ -1088,13 +1087,7 @@ static int dvb_demux_do_ioctl(struct file *file,
1088static long dvb_demux_ioctl(struct file *file, unsigned int cmd, 1087static long dvb_demux_ioctl(struct file *file, unsigned int cmd,
1089 unsigned long arg) 1088 unsigned long arg)
1090{ 1089{
1091 int ret; 1090 return dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
1092
1093 lock_kernel();
1094 ret = dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
1095 unlock_kernel();
1096
1097 return ret;
1098} 1091}
1099 1092
1100static unsigned int dvb_demux_poll(struct file *file, poll_table *wait) 1093static unsigned int dvb_demux_poll(struct file *file, poll_table *wait)
@@ -1187,13 +1180,7 @@ static int dvb_dvr_do_ioctl(struct file *file,
1187static long dvb_dvr_ioctl(struct file *file, 1180static long dvb_dvr_ioctl(struct file *file,
1188 unsigned int cmd, unsigned long arg) 1181 unsigned int cmd, unsigned long arg)
1189{ 1182{
1190 int ret; 1183 return dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
1191
1192 lock_kernel();
1193 ret = dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
1194 unlock_kernel();
1195
1196 return ret;
1197} 1184}
1198 1185
1199static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait) 1186static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index ff8921dd737f..4d0646da6087 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -1259,13 +1259,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct file *file,
1259static long dvb_ca_en50221_io_ioctl(struct file *file, 1259static long dvb_ca_en50221_io_ioctl(struct file *file,
1260 unsigned int cmd, unsigned long arg) 1260 unsigned int cmd, unsigned long arg)
1261{ 1261{
1262 int ret; 1262 return dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
1263
1264 lock_kernel();
1265 ret = dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
1266 unlock_kernel();
1267
1268 return ret;
1269} 1263}
1270 1264
1271 1265
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 82636f517b9e..4df42aaae7f7 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -59,7 +59,6 @@
59#include <linux/netdevice.h> 59#include <linux/netdevice.h>
60#include <linux/etherdevice.h> 60#include <linux/etherdevice.h>
61#include <linux/dvb/net.h> 61#include <linux/dvb/net.h>
62#include <linux/smp_lock.h>
63#include <linux/uio.h> 62#include <linux/uio.h>
64#include <asm/uaccess.h> 63#include <asm/uaccess.h>
65#include <linux/crc32.h> 64#include <linux/crc32.h>
@@ -1445,13 +1444,7 @@ static int dvb_net_do_ioctl(struct file *file,
1445static long dvb_net_ioctl(struct file *file, 1444static long dvb_net_ioctl(struct file *file,
1446 unsigned int cmd, unsigned long arg) 1445 unsigned int cmd, unsigned long arg)
1447{ 1446{
1448 int ret; 1447 return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
1449
1450 lock_kernel();
1451 ret = dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
1452 unlock_kernel();
1453
1454 return ret;
1455} 1448}
1456 1449
1457static int dvb_net_close(struct inode *inode, struct file *file) 1450static int dvb_net_close(struct inode *inode, struct file *file)
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 774b40e4f589..f73287775953 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -32,9 +32,9 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/cdev.h> 33#include <linux/cdev.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/smp_lock.h>
36#include "dvbdev.h" 35#include "dvbdev.h"
37 36
37static DEFINE_MUTEX(dvbdev_mutex);
38static int dvbdev_debug; 38static int dvbdev_debug;
39 39
40module_param(dvbdev_debug, int, 0644); 40module_param(dvbdev_debug, int, 0644);
@@ -68,7 +68,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
68{ 68{
69 struct dvb_device *dvbdev; 69 struct dvb_device *dvbdev;
70 70
71 lock_kernel(); 71 mutex_lock(&dvbdev_mutex);
72 down_read(&minor_rwsem); 72 down_read(&minor_rwsem);
73 dvbdev = dvb_minors[iminor(inode)]; 73 dvbdev = dvb_minors[iminor(inode)];
74 74
@@ -91,12 +91,12 @@ static int dvb_device_open(struct inode *inode, struct file *file)
91 } 91 }
92 fops_put(old_fops); 92 fops_put(old_fops);
93 up_read(&minor_rwsem); 93 up_read(&minor_rwsem);
94 unlock_kernel(); 94 mutex_unlock(&dvbdev_mutex);
95 return err; 95 return err;
96 } 96 }
97fail: 97fail:
98 up_read(&minor_rwsem); 98 up_read(&minor_rwsem);
99 unlock_kernel(); 99 mutex_unlock(&dvbdev_mutex);
100 return -ENODEV; 100 return -ENODEV;
101} 101}
102 102
@@ -159,7 +159,6 @@ long dvb_generic_ioctl(struct file *file,
159 unsigned int cmd, unsigned long arg) 159 unsigned int cmd, unsigned long arg)
160{ 160{
161 struct dvb_device *dvbdev = file->private_data; 161 struct dvb_device *dvbdev = file->private_data;
162 int ret;
163 162
164 if (!dvbdev) 163 if (!dvbdev)
165 return -ENODEV; 164 return -ENODEV;
@@ -167,11 +166,7 @@ long dvb_generic_ioctl(struct file *file,
167 if (!dvbdev->kernel_ioctl) 166 if (!dvbdev->kernel_ioctl)
168 return -EINVAL; 167 return -EINVAL;
169 168
170 lock_kernel(); 169 return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
171 ret = dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
172 unlock_kernel();
173
174 return ret;
175} 170}
176EXPORT_SYMBOL(dvb_generic_ioctl); 171EXPORT_SYMBOL(dvb_generic_ioctl);
177 172
@@ -422,8 +417,10 @@ int dvb_usercopy(struct file *file,
422 } 417 }
423 418
424 /* call driver */ 419 /* call driver */
420 mutex_lock(&dvbdev_mutex);
425 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD) 421 if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
426 err = -EINVAL; 422 err = -EINVAL;
423 mutex_unlock(&dvbdev_mutex);
427 424
428 if (err < 0) 425 if (err < 0)
429 goto out; 426 goto out;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index fe818348b8a3..48397f103d32 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -673,9 +673,6 @@ static int dib0700_probe(struct usb_interface *intf,
673 else 673 else
674 dev->props.rc.core.bulk_mode = false; 674 dev->props.rc.core.bulk_mode = false;
675 675
676 /* Need a higher delay, to avoid wrong repeat */
677 dev->rc_input_dev->rep[REP_DELAY] = 500;
678
679 dib0700_rc_setup(dev); 676 dib0700_rc_setup(dev);
680 677
681 return 0; 678 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index f634d2e784b2..e06acd1fecb6 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -940,6 +940,58 @@ static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
940 return adap->fe == NULL ? -ENODEV : 0; 940 return adap->fe == NULL ? -ENODEV : 0;
941} 941}
942 942
943/* STK7770P */
944static struct dib7000p_config dib7770p_dib7000p_config = {
945 .output_mpeg2_in_188_bytes = 1,
946
947 .agc_config_count = 1,
948 .agc = &dib7070_agc_config,
949 .bw = &dib7070_bw_config_12_mhz,
950 .tuner_is_baseband = 1,
951 .spur_protect = 1,
952
953 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
954 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
955 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
956
957 .hostbus_diversity = 1,
958 .enable_current_mirror = 1,
959 .disable_sample_and_hold = 0,
960};
961
962static int stk7770p_frontend_attach(struct dvb_usb_adapter *adap)
963{
964 struct usb_device_descriptor *p = &adap->dev->udev->descriptor;
965 if (p->idVendor == cpu_to_le16(USB_VID_PINNACLE) &&
966 p->idProduct == cpu_to_le16(USB_PID_PINNACLE_PCTV72E))
967 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
968 else
969 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
970 msleep(10);
971 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
972 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
973 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
974 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
975
976 dib0700_ctrl_clock(adap->dev, 72, 1);
977
978 msleep(10);
979 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
980 msleep(10);
981 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
982
983 if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
984 &dib7770p_dib7000p_config) != 0) {
985 err("%s: dib7000p_i2c_enumeration failed. Cannot continue\n",
986 __func__);
987 return -ENODEV;
988 }
989
990 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
991 &dib7770p_dib7000p_config);
992 return adap->fe == NULL ? -ENODEV : 0;
993}
994
943/* DIB807x generic */ 995/* DIB807x generic */
944static struct dibx000_agc_config dib807x_agc_config[2] = { 996static struct dibx000_agc_config dib807x_agc_config[2] = {
945 { 997 {
@@ -1781,7 +1833,7 @@ struct usb_device_id dib0700_usb_id_table[] = {
1781/* 60 */{ USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_XXS_2) }, 1833/* 60 */{ USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_XXS_2) },
1782 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK807XPVR) }, 1834 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK807XPVR) },
1783 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK807XP) }, 1835 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK807XP) },
1784 { USB_DEVICE(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD) }, 1836 { USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x000, 0x3f00) },
1785 { USB_DEVICE(USB_VID_EVOLUTEPC, USB_PID_TVWAY_PLUS) }, 1837 { USB_DEVICE(USB_VID_EVOLUTEPC, USB_PID_TVWAY_PLUS) },
1786/* 65 */{ USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV73ESE) }, 1838/* 65 */{ USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV73ESE) },
1787 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV282E) }, 1839 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV282E) },
@@ -2406,7 +2458,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
2406 .pid_filter_count = 32, 2458 .pid_filter_count = 32,
2407 .pid_filter = stk70x0p_pid_filter, 2459 .pid_filter = stk70x0p_pid_filter,
2408 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl, 2460 .pid_filter_ctrl = stk70x0p_pid_filter_ctrl,
2409 .frontend_attach = stk7070p_frontend_attach, 2461 .frontend_attach = stk7770p_frontend_attach,
2410 .tuner_attach = dib7770p_tuner_attach, 2462 .tuner_attach = dib7770p_tuner_attach,
2411 2463
2412 DIB0700_DEFAULT_STREAMING_CONFIG(0x02), 2464 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index 6b22ec64ab0c..f896337b4535 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -483,9 +483,7 @@ static int opera1_xilinx_load_firmware(struct usb_device *dev,
483 } 483 }
484 } 484 }
485 kfree(p); 485 kfree(p);
486 if (fw) { 486 release_firmware(fw);
487 release_firmware(fw);
488 }
489 return ret; 487 return ret;
490} 488}
491 489
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 2e28b973dfd3..3aed0d433921 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -260,6 +260,9 @@ static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_ad
260 260
261// dprintk( "908: %x, 909: %x\n", reg_908, reg_909); 261// dprintk( "908: %x, 909: %x\n", reg_908, reg_909);
262 262
263 reg_909 |= (state->cfg.disable_sample_and_hold & 1) << 4;
264 reg_908 |= (state->cfg.enable_current_mirror & 1) << 7;
265
263 dib7000p_write_word(state, 908, reg_908); 266 dib7000p_write_word(state, 908, reg_908);
264 dib7000p_write_word(state, 909, reg_909); 267 dib7000p_write_word(state, 909, reg_909);
265} 268}
@@ -778,7 +781,10 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_fronte
778 default: 781 default:
779 case GUARD_INTERVAL_1_32: value *= 1; break; 782 case GUARD_INTERVAL_1_32: value *= 1; break;
780 } 783 }
781 state->div_sync_wait = (value * 3) / 2 + 32; // add 50% SFN margin + compensate for one DVSY-fifo TODO 784 if (state->cfg.diversity_delay == 0)
785 state->div_sync_wait = (value * 3) / 2 + 48; // add 50% SFN margin + compensate for one DVSY-fifo
786 else
787 state->div_sync_wait = (value * 3) / 2 + state->cfg.diversity_delay; // add 50% SFN margin + compensate for one DVSY-fifo
782 788
783 /* deactive the possibility of diversity reception if extended interleaver */ 789 /* deactive the possibility of diversity reception if extended interleaver */
784 state->div_force_off = !1 && ch->u.ofdm.transmission_mode != TRANSMISSION_MODE_8K; 790 state->div_force_off = !1 && ch->u.ofdm.transmission_mode != TRANSMISSION_MODE_8K;
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index 805dd13a97ee..da17345bf5bd 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -33,6 +33,11 @@ struct dib7000p_config {
33 int (*agc_control) (struct dvb_frontend *, u8 before); 33 int (*agc_control) (struct dvb_frontend *, u8 before);
34 34
35 u8 output_mode; 35 u8 output_mode;
36 u8 disable_sample_and_hold : 1;
37
38 u8 enable_current_mirror : 1;
39 u8 diversity_delay;
40
36}; 41};
37 42
38#define DEFAULT_DIB7000P_I2C_ADDRESS 18 43#define DEFAULT_DIB7000P_I2C_ADDRESS 18
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index d93468cd3a85..ff3b0fa901b3 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -1098,33 +1098,26 @@ EXPORT_SYMBOL_GPL(smscore_onresponse);
1098 * 1098 *
1099 * @return pointer to descriptor on success, NULL on error. 1099 * @return pointer to descriptor on success, NULL on error.
1100 */ 1100 */
1101struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev) 1101
1102struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
1102{ 1103{
1103 struct smscore_buffer_t *cb = NULL; 1104 struct smscore_buffer_t *cb = NULL;
1104 unsigned long flags; 1105 unsigned long flags;
1105 1106
1106 DEFINE_WAIT(wait);
1107
1108 spin_lock_irqsave(&coredev->bufferslock, flags); 1107 spin_lock_irqsave(&coredev->bufferslock, flags);
1109 1108 if (!list_empty(&coredev->buffers)) {
1110 /* This function must return a valid buffer, since the buffer list is 1109 cb = (struct smscore_buffer_t *) coredev->buffers.next;
1111 * finite, we check that there is an available buffer, if not, we wait 1110 list_del(&cb->entry);
1112 * until such buffer become available.
1113 */
1114
1115 prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE);
1116 if (list_empty(&coredev->buffers)) {
1117 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1118 schedule();
1119 spin_lock_irqsave(&coredev->bufferslock, flags);
1120 } 1111 }
1112 spin_unlock_irqrestore(&coredev->bufferslock, flags);
1113 return cb;
1114}
1121 1115
1122 finish_wait(&coredev->buffer_mng_waitq, &wait); 1116struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
1123 1117{
1124 cb = (struct smscore_buffer_t *) coredev->buffers.next; 1118 struct smscore_buffer_t *cb = NULL;
1125 list_del(&cb->entry);
1126 1119
1127 spin_unlock_irqrestore(&coredev->bufferslock, flags); 1120 wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
1128 1121
1129 return cb; 1122 return cb;
1130} 1123}
diff --git a/drivers/media/radio/si470x/radio-si470x-i2c.c b/drivers/media/radio/si470x/radio-si470x-i2c.c
index 67a4ec8768a6..4ce541a5eb47 100644
--- a/drivers/media/radio/si470x/radio-si470x-i2c.c
+++ b/drivers/media/radio/si470x/radio-si470x-i2c.c
@@ -395,7 +395,7 @@ static int __devinit si470x_i2c_probe(struct i2c_client *client,
395 radio->registers[POWERCFG] = POWERCFG_ENABLE; 395 radio->registers[POWERCFG] = POWERCFG_ENABLE;
396 if (si470x_set_register(radio, POWERCFG) < 0) { 396 if (si470x_set_register(radio, POWERCFG) < 0) {
397 retval = -EIO; 397 retval = -EIO;
398 goto err_all; 398 goto err_video;
399 } 399 }
400 msleep(110); 400 msleep(110);
401 401
diff --git a/drivers/media/video/cx231xx/Makefile b/drivers/media/video/cx231xx/Makefile
index 755dd0ce65ff..6f2b57384488 100644
--- a/drivers/media/video/cx231xx/Makefile
+++ b/drivers/media/video/cx231xx/Makefile
@@ -11,4 +11,5 @@ EXTRA_CFLAGS += -Idrivers/media/video
11EXTRA_CFLAGS += -Idrivers/media/common/tuners 11EXTRA_CFLAGS += -Idrivers/media/common/tuners
12EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 12EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
13EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 13EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
14EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-usb
14 15
diff --git a/drivers/media/video/cx231xx/cx231xx-cards.c b/drivers/media/video/cx231xx/cx231xx-cards.c
index 6bdc0ef18119..f2a4900014bc 100644
--- a/drivers/media/video/cx231xx/cx231xx-cards.c
+++ b/drivers/media/video/cx231xx/cx231xx-cards.c
@@ -32,6 +32,7 @@
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
33 33
34#include <media/cx25840.h> 34#include <media/cx25840.h>
35#include "dvb-usb-ids.h"
35#include "xc5000.h" 36#include "xc5000.h"
36 37
37#include "cx231xx.h" 38#include "cx231xx.h"
@@ -175,6 +176,8 @@ struct usb_device_id cx231xx_id_table[] = {
175 .driver_info = CX231XX_BOARD_CNXT_RDE_250}, 176 .driver_info = CX231XX_BOARD_CNXT_RDE_250},
176 {USB_DEVICE(0x0572, 0x58A1), 177 {USB_DEVICE(0x0572, 0x58A1),
177 .driver_info = CX231XX_BOARD_CNXT_RDU_250}, 178 .driver_info = CX231XX_BOARD_CNXT_RDU_250},
179 {USB_DEVICE_VER(USB_VID_PIXELVIEW, USB_PID_PIXELVIEW_SBTVD, 0x4000,0x4fff),
180 .driver_info = CX231XX_BOARD_UNKNOWN},
178 {}, 181 {},
179}; 182};
180 183
@@ -226,14 +229,16 @@ void cx231xx_pre_card_setup(struct cx231xx *dev)
226 dev->board.name, dev->model); 229 dev->board.name, dev->model);
227 230
228 /* set the direction for GPIO pins */ 231 /* set the direction for GPIO pins */
229 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1); 232 if (dev->board.tuner_gpio) {
230 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1); 233 cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1);
231 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); 234 cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1);
235 cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1);
232 236
233 /* request some modules if any required */ 237 /* request some modules if any required */
234 238
235 /* reset the Tuner */ 239 /* reset the Tuner */
236 cx231xx_gpio_set(dev, dev->board.tuner_gpio); 240 cx231xx_gpio_set(dev, dev->board.tuner_gpio);
241 }
237 242
238 /* set the mode to Analog mode initially */ 243 /* set the mode to Analog mode initially */
239 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); 244 cx231xx_set_mode(dev, CX231XX_ANALOG_MODE);
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 86ca8c2359dd..f5a3e74c3c7c 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -1996,7 +1996,7 @@ static int cx25840_probe(struct i2c_client *client,
1996 1996
1997 state->volume = v4l2_ctrl_new_std(&state->hdl, 1997 state->volume = v4l2_ctrl_new_std(&state->hdl,
1998 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME, 1998 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_VOLUME,
1999 0, 65335, 65535 / 100, default_volume); 1999 0, 65535, 65535 / 100, default_volume);
2000 state->mute = v4l2_ctrl_new_std(&state->hdl, 2000 state->mute = v4l2_ctrl_new_std(&state->hdl,
2001 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_MUTE, 2001 &cx25840_audio_ctrl_ops, V4L2_CID_AUDIO_MUTE,
2002 0, 1, 1, 0); 2002 0, 1, 1, 0);
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 99dbae117591..0fa85cbefbb1 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -17,7 +17,7 @@ config VIDEO_CX88
17 17
18config VIDEO_CX88_ALSA 18config VIDEO_CX88_ALSA
19 tristate "Conexant 2388x DMA audio support" 19 tristate "Conexant 2388x DMA audio support"
20 depends on VIDEO_CX88 && SND && EXPERIMENTAL 20 depends on VIDEO_CX88 && SND
21 select SND_PCM 21 select SND_PCM
22 ---help--- 22 ---help---
23 This is a video4linux driver for direct (DMA) audio on 23 This is a video4linux driver for direct (DMA) audio on
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index 5b176bd7afdb..f3e25e91366d 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -32,7 +32,6 @@
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/smp_lock.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <asm/uaccess.h> 36#include <asm/uaccess.h>
38#include <asm/atomic.h> 37#include <asm/atomic.h>
@@ -621,7 +620,6 @@ static int dabusb_open (struct inode *inode, struct file *file)
621 if (devnum < DABUSB_MINOR || devnum >= (DABUSB_MINOR + NRDABUSB)) 620 if (devnum < DABUSB_MINOR || devnum >= (DABUSB_MINOR + NRDABUSB))
622 return -EIO; 621 return -EIO;
623 622
624 lock_kernel();
625 s = &dabusb[devnum - DABUSB_MINOR]; 623 s = &dabusb[devnum - DABUSB_MINOR];
626 624
627 dbg("dabusb_open"); 625 dbg("dabusb_open");
@@ -630,21 +628,17 @@ static int dabusb_open (struct inode *inode, struct file *file)
630 while (!s->usbdev || s->opened) { 628 while (!s->usbdev || s->opened) {
631 mutex_unlock(&s->mutex); 629 mutex_unlock(&s->mutex);
632 630
633 if (file->f_flags & O_NONBLOCK) { 631 if (file->f_flags & O_NONBLOCK)
634 return -EBUSY; 632 return -EBUSY;
635 }
636 msleep_interruptible(500); 633 msleep_interruptible(500);
637 634
638 if (signal_pending (current)) { 635 if (signal_pending (current))
639 unlock_kernel();
640 return -EAGAIN; 636 return -EAGAIN;
641 }
642 mutex_lock(&s->mutex); 637 mutex_lock(&s->mutex);
643 } 638 }
644 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) { 639 if (usb_set_interface (s->usbdev, _DABUSB_IF, 1) < 0) {
645 mutex_unlock(&s->mutex); 640 mutex_unlock(&s->mutex);
646 dev_err(&s->usbdev->dev, "set_interface failed\n"); 641 dev_err(&s->usbdev->dev, "set_interface failed\n");
647 unlock_kernel();
648 return -EINVAL; 642 return -EINVAL;
649 } 643 }
650 s->opened = 1; 644 s->opened = 1;
@@ -654,7 +648,6 @@ static int dabusb_open (struct inode *inode, struct file *file)
654 file->private_data = s; 648 file->private_data = s;
655 649
656 r = nonseekable_open(inode, file); 650 r = nonseekable_open(inode, file);
657 unlock_kernel();
658 return r; 651 return r;
659} 652}
660 653
@@ -689,17 +682,13 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
689 682
690 dbg("dabusb_ioctl"); 683 dbg("dabusb_ioctl");
691 684
692 lock_kernel(); 685 if (s->remove_pending)
693 if (s->remove_pending) {
694 unlock_kernel();
695 return -EIO; 686 return -EIO;
696 }
697 687
698 mutex_lock(&s->mutex); 688 mutex_lock(&s->mutex);
699 689
700 if (!s->usbdev) { 690 if (!s->usbdev) {
701 mutex_unlock(&s->mutex); 691 mutex_unlock(&s->mutex);
702 unlock_kernel();
703 return -EIO; 692 return -EIO;
704 } 693 }
705 694
@@ -735,7 +724,6 @@ static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg
735 break; 724 break;
736 } 725 }
737 mutex_unlock(&s->mutex); 726 mutex_unlock(&s->mutex);
738 unlock_kernel();
739 return ret; 727 return ret;
740} 728}
741 729
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index b9846106913e..78abc1c1f9d5 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -223,6 +223,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
223 usb_rcvintpipe(dev, ep->bEndpointAddress), 223 usb_rcvintpipe(dev, ep->bEndpointAddress),
224 buffer, buffer_len, 224 buffer, buffer_len,
225 int_irq, (void *)gspca_dev, interval); 225 int_irq, (void *)gspca_dev, interval);
226 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
226 gspca_dev->int_urb = urb; 227 gspca_dev->int_urb = urb;
227 ret = usb_submit_urb(urb, GFP_KERNEL); 228 ret = usb_submit_urb(urb, GFP_KERNEL);
228 if (ret < 0) { 229 if (ret < 0) {
diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c
index 83a718f0f3f9..9052d5702556 100644
--- a/drivers/media/video/gspca/sn9c20x.c
+++ b/drivers/media/video/gspca/sn9c20x.c
@@ -2357,8 +2357,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2357 (data[33] << 10); 2357 (data[33] << 10);
2358 avg_lum >>= 9; 2358 avg_lum >>= 9;
2359 atomic_set(&sd->avg_lum, avg_lum); 2359 atomic_set(&sd->avg_lum, avg_lum);
2360 gspca_frame_add(gspca_dev, LAST_PACKET, 2360 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
2361 data, len);
2362 return; 2361 return;
2363 } 2362 }
2364 if (gspca_dev->last_packet_type == LAST_PACKET) { 2363 if (gspca_dev->last_packet_type == LAST_PACKET) {
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index be03a712731c..f0316d02f09f 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -466,6 +466,8 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
466 struct fb_vblank vblank; 466 struct fb_vblank vblank;
467 u32 trace; 467 u32 trace;
468 468
469 memset(&vblank, 0, sizeof(struct fb_vblank));
470
469 vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT | 471 vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
470 FB_VBLANK_HAVE_VSYNC; 472 FB_VBLANK_HAVE_VSYNC;
471 trace = read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16; 473 trace = read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16;
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index 4525335f9bd4..a7210d981388 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -239,7 +239,7 @@ static int device_process(struct m2mtest_ctx *ctx,
239 return -EFAULT; 239 return -EFAULT;
240 } 240 }
241 241
242 if (in_buf->vb.size < out_buf->vb.size) { 242 if (in_buf->vb.size > out_buf->vb.size) {
243 v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n"); 243 v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n");
244 return -EINVAL; 244 return -EINVAL;
245 } 245 }
@@ -1014,6 +1014,7 @@ static int m2mtest_remove(struct platform_device *pdev)
1014 v4l2_m2m_release(dev->m2m_dev); 1014 v4l2_m2m_release(dev->m2m_dev);
1015 del_timer_sync(&dev->timer); 1015 del_timer_sync(&dev->timer);
1016 video_unregister_device(dev->vfd); 1016 video_unregister_device(dev->vfd);
1017 video_device_release(dev->vfd);
1017 v4l2_device_unregister(&dev->v4l2_dev); 1018 v4l2_device_unregister(&dev->v4l2_dev);
1018 kfree(dev); 1019 kfree(dev);
1019 1020
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 758a4db27d65..c71af4e0e517 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -447,6 +447,9 @@ static int mt9m111_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
447 dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n", 447 dev_dbg(&client->dev, "%s left=%d, top=%d, width=%d, height=%d\n",
448 __func__, rect.left, rect.top, rect.width, rect.height); 448 __func__, rect.left, rect.top, rect.width, rect.height);
449 449
450 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
451 return -EINVAL;
452
450 ret = mt9m111_make_rect(client, &rect); 453 ret = mt9m111_make_rect(client, &rect);
451 if (!ret) 454 if (!ret)
452 mt9m111->rect = rect; 455 mt9m111->rect = rect;
@@ -466,12 +469,14 @@ static int mt9m111_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
466 469
467static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) 470static int mt9m111_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
468{ 471{
472 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
473 return -EINVAL;
474
469 a->bounds.left = MT9M111_MIN_DARK_COLS; 475 a->bounds.left = MT9M111_MIN_DARK_COLS;
470 a->bounds.top = MT9M111_MIN_DARK_ROWS; 476 a->bounds.top = MT9M111_MIN_DARK_ROWS;
471 a->bounds.width = MT9M111_MAX_WIDTH; 477 a->bounds.width = MT9M111_MAX_WIDTH;
472 a->bounds.height = MT9M111_MAX_HEIGHT; 478 a->bounds.height = MT9M111_MAX_HEIGHT;
473 a->defrect = a->bounds; 479 a->defrect = a->bounds;
474 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
475 a->pixelaspect.numerator = 1; 480 a->pixelaspect.numerator = 1;
476 a->pixelaspect.denominator = 1; 481 a->pixelaspect.denominator = 1;
477 482
@@ -487,6 +492,7 @@ static int mt9m111_g_fmt(struct v4l2_subdev *sd,
487 mf->width = mt9m111->rect.width; 492 mf->width = mt9m111->rect.width;
488 mf->height = mt9m111->rect.height; 493 mf->height = mt9m111->rect.height;
489 mf->code = mt9m111->fmt->code; 494 mf->code = mt9m111->fmt->code;
495 mf->colorspace = mt9m111->fmt->colorspace;
490 mf->field = V4L2_FIELD_NONE; 496 mf->field = V4L2_FIELD_NONE;
491 497
492 return 0; 498 return 0;
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index e7cd23cd6394..b48473c7896b 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -402,9 +402,6 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd,
402 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC) 402 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
403 return -EINVAL; 403 return -EINVAL;
404 break; 404 break;
405 case 0:
406 /* No format change, only geometry */
407 break;
408 default: 405 default:
409 return -EINVAL; 406 return -EINVAL;
410 } 407 }
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index 66ff174151b5..b6ea67221d1d 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -378,6 +378,9 @@ static void mx25_camera_frame_done(struct mx2_camera_dev *pcdev, int fb,
378 378
379 spin_lock_irqsave(&pcdev->lock, flags); 379 spin_lock_irqsave(&pcdev->lock, flags);
380 380
381 if (*fb_active == NULL)
382 goto out;
383
381 vb = &(*fb_active)->vb; 384 vb = &(*fb_active)->vb;
382 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, 385 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
383 vb, vb->baddr, vb->bsize); 386 vb, vb->baddr, vb->bsize);
@@ -402,6 +405,7 @@ static void mx25_camera_frame_done(struct mx2_camera_dev *pcdev, int fb,
402 405
403 *fb_active = buf; 406 *fb_active = buf;
404 407
408out:
405 spin_unlock_irqrestore(&pcdev->lock, flags); 409 spin_unlock_irqrestore(&pcdev->lock, flags);
406} 410}
407 411
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 1b992b847198..55ea914c7fcd 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -513,7 +513,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
513 if (ret >= 0) { 513 if (ret >= 0) {
514 ret = pvr2_ctrl_range_check(cptr,*valptr); 514 ret = pvr2_ctrl_range_check(cptr,*valptr);
515 } 515 }
516 if (maskptr) *maskptr = ~0; 516 *maskptr = ~0;
517 } else if (cptr->info->type == pvr2_ctl_bool) { 517 } else if (cptr->info->type == pvr2_ctl_bool) {
518 ret = parse_token(ptr,len,valptr,boolNames, 518 ret = parse_token(ptr,len,valptr,boolNames,
519 ARRAY_SIZE(boolNames)); 519 ARRAY_SIZE(boolNames));
@@ -522,7 +522,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
522 } else if (ret == 0) { 522 } else if (ret == 0) {
523 *valptr = (*valptr & 1) ? !0 : 0; 523 *valptr = (*valptr & 1) ? !0 : 0;
524 } 524 }
525 if (maskptr) *maskptr = 1; 525 *maskptr = 1;
526 } else if (cptr->info->type == pvr2_ctl_enum) { 526 } else if (cptr->info->type == pvr2_ctl_enum) {
527 ret = parse_token( 527 ret = parse_token(
528 ptr,len,valptr, 528 ptr,len,valptr,
@@ -531,7 +531,7 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
531 if (ret >= 0) { 531 if (ret >= 0) {
532 ret = pvr2_ctrl_range_check(cptr,*valptr); 532 ret = pvr2_ctrl_range_check(cptr,*valptr);
533 } 533 }
534 if (maskptr) *maskptr = ~0; 534 *maskptr = ~0;
535 } else if (cptr->info->type == pvr2_ctl_bitmask) { 535 } else if (cptr->info->type == pvr2_ctl_bitmask) {
536 ret = parse_tlist( 536 ret = parse_tlist(
537 ptr,len,maskptr,valptr, 537 ptr,len,maskptr,valptr,
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index b151c7be8a50..6961c55baf9b 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -393,6 +393,37 @@ static void fimc_set_yuv_order(struct fimc_ctx *ctx)
393 dbg("ctx->out_order_1p= %d", ctx->out_order_1p); 393 dbg("ctx->out_order_1p= %d", ctx->out_order_1p);
394} 394}
395 395
396static void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f)
397{
398 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
399
400 f->dma_offset.y_h = f->offs_h;
401 if (!variant->pix_hoff)
402 f->dma_offset.y_h *= (f->fmt->depth >> 3);
403
404 f->dma_offset.y_v = f->offs_v;
405
406 f->dma_offset.cb_h = f->offs_h;
407 f->dma_offset.cb_v = f->offs_v;
408
409 f->dma_offset.cr_h = f->offs_h;
410 f->dma_offset.cr_v = f->offs_v;
411
412 if (!variant->pix_hoff) {
413 if (f->fmt->planes_cnt == 3) {
414 f->dma_offset.cb_h >>= 1;
415 f->dma_offset.cr_h >>= 1;
416 }
417 if (f->fmt->color == S5P_FIMC_YCBCR420) {
418 f->dma_offset.cb_v >>= 1;
419 f->dma_offset.cr_v >>= 1;
420 }
421 }
422
423 dbg("in_offset: color= %d, y_h= %d, y_v= %d",
424 f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v);
425}
426
396/** 427/**
397 * fimc_prepare_config - check dimensions, operation and color mode 428 * fimc_prepare_config - check dimensions, operation and color mode
398 * and pre-calculate offset and the scaling coefficients. 429 * and pre-calculate offset and the scaling coefficients.
@@ -406,7 +437,6 @@ static int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
406{ 437{
407 struct fimc_frame *s_frame, *d_frame; 438 struct fimc_frame *s_frame, *d_frame;
408 struct fimc_vid_buffer *buf = NULL; 439 struct fimc_vid_buffer *buf = NULL;
409 struct samsung_fimc_variant *variant = ctx->fimc_dev->variant;
410 int ret = 0; 440 int ret = 0;
411 441
412 s_frame = &ctx->s_frame; 442 s_frame = &ctx->s_frame;
@@ -419,61 +449,16 @@ static int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags)
419 swap(d_frame->width, d_frame->height); 449 swap(d_frame->width, d_frame->height);
420 } 450 }
421 451
422 /* Prepare the output offset ratios for scaler. */ 452 /* Prepare the DMA offset ratios for scaler. */
423 d_frame->dma_offset.y_h = d_frame->offs_h; 453 fimc_prepare_dma_offset(ctx, &ctx->s_frame);
424 if (!variant->pix_hoff) 454 fimc_prepare_dma_offset(ctx, &ctx->d_frame);
425 d_frame->dma_offset.y_h *= (d_frame->fmt->depth >> 3);
426
427 d_frame->dma_offset.y_v = d_frame->offs_v;
428
429 d_frame->dma_offset.cb_h = d_frame->offs_h;
430 d_frame->dma_offset.cb_v = d_frame->offs_v;
431
432 d_frame->dma_offset.cr_h = d_frame->offs_h;
433 d_frame->dma_offset.cr_v = d_frame->offs_v;
434 455
435 if (!variant->pix_hoff && d_frame->fmt->planes_cnt == 3) {
436 d_frame->dma_offset.cb_h >>= 1;
437 d_frame->dma_offset.cb_v >>= 1;
438 d_frame->dma_offset.cr_h >>= 1;
439 d_frame->dma_offset.cr_v >>= 1;
440 }
441
442 dbg("out offset: color= %d, y_h= %d, y_v= %d",
443 d_frame->fmt->color,
444 d_frame->dma_offset.y_h, d_frame->dma_offset.y_v);
445
446 /* Prepare the input offset ratios for scaler. */
447 s_frame->dma_offset.y_h = s_frame->offs_h;
448 if (!variant->pix_hoff)
449 s_frame->dma_offset.y_h *= (s_frame->fmt->depth >> 3);
450 s_frame->dma_offset.y_v = s_frame->offs_v;
451
452 s_frame->dma_offset.cb_h = s_frame->offs_h;
453 s_frame->dma_offset.cb_v = s_frame->offs_v;
454
455 s_frame->dma_offset.cr_h = s_frame->offs_h;
456 s_frame->dma_offset.cr_v = s_frame->offs_v;
457
458 if (!variant->pix_hoff && s_frame->fmt->planes_cnt == 3) {
459 s_frame->dma_offset.cb_h >>= 1;
460 s_frame->dma_offset.cb_v >>= 1;
461 s_frame->dma_offset.cr_h >>= 1;
462 s_frame->dma_offset.cr_v >>= 1;
463 }
464
465 dbg("in offset: color= %d, y_h= %d, y_v= %d",
466 s_frame->fmt->color, s_frame->dma_offset.y_h,
467 s_frame->dma_offset.y_v);
468
469 fimc_set_yuv_order(ctx);
470
471 /* Check against the scaler ratio. */
472 if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) || 456 if (s_frame->height > (SCALER_MAX_VRATIO * d_frame->height) ||
473 s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) { 457 s_frame->width > (SCALER_MAX_HRATIO * d_frame->width)) {
474 err("out of scaler range"); 458 err("out of scaler range");
475 return -EINVAL; 459 return -EINVAL;
476 } 460 }
461 fimc_set_yuv_order(ctx);
477 } 462 }
478 463
479 /* Input DMA mode is not allowed when the scaler is disabled. */ 464 /* Input DMA mode is not allowed when the scaler is disabled. */
@@ -822,7 +807,8 @@ static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f)
822 } else { 807 } else {
823 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, 808 v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev,
824 "Wrong buffer/video queue type (%d)\n", f->type); 809 "Wrong buffer/video queue type (%d)\n", f->type);
825 return -EINVAL; 810 ret = -EINVAL;
811 goto s_fmt_out;
826 } 812 }
827 813
828 pix = &f->fmt.pix; 814 pix = &f->fmt.pix;
@@ -1414,8 +1400,10 @@ static int fimc_probe(struct platform_device *pdev)
1414 } 1400 }
1415 1401
1416 fimc->work_queue = create_workqueue(dev_name(&fimc->pdev->dev)); 1402 fimc->work_queue = create_workqueue(dev_name(&fimc->pdev->dev));
1417 if (!fimc->work_queue) 1403 if (!fimc->work_queue) {
1404 ret = -ENOMEM;
1418 goto err_irq; 1405 goto err_irq;
1406 }
1419 1407
1420 ret = fimc_register_m2m_device(fimc); 1408 ret = fimc_register_m2m_device(fimc);
1421 if (ret) 1409 if (ret)
@@ -1492,6 +1480,7 @@ static struct samsung_fimc_variant fimc2_variant_s5p = {
1492}; 1480};
1493 1481
1494static struct samsung_fimc_variant fimc01_variant_s5pv210 = { 1482static struct samsung_fimc_variant fimc01_variant_s5pv210 = {
1483 .pix_hoff = 1,
1495 .has_inp_rot = 1, 1484 .has_inp_rot = 1,
1496 .has_out_rot = 1, 1485 .has_out_rot = 1,
1497 .min_inp_pixsize = 16, 1486 .min_inp_pixsize = 16,
@@ -1506,6 +1495,7 @@ static struct samsung_fimc_variant fimc01_variant_s5pv210 = {
1506}; 1495};
1507 1496
1508static struct samsung_fimc_variant fimc2_variant_s5pv210 = { 1497static struct samsung_fimc_variant fimc2_variant_s5pv210 = {
1498 .pix_hoff = 1,
1509 .min_inp_pixsize = 16, 1499 .min_inp_pixsize = 16,
1510 .min_out_pixsize = 32, 1500 .min_out_pixsize = 32,
1511 1501
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index ec697fcd406e..bb8d83d8ddaf 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -4323,13 +4323,13 @@ struct saa7134_board saa7134_boards[] = {
4323 }, 4323 },
4324 [SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM] = { 4324 [SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM] = {
4325 /* Beholder Intl. Ltd. 2008 */ 4325 /* Beholder Intl. Ltd. 2008 */
4326 /*Dmitry Belimov <d.belimov@gmail.com> */ 4326 /* Dmitry Belimov <d.belimov@gmail.com> */
4327 .name = "Beholder BeholdTV Columbus TVFM", 4327 .name = "Beholder BeholdTV Columbus TV/FM",
4328 .audio_clock = 0x00187de7, 4328 .audio_clock = 0x00187de7,
4329 .tuner_type = TUNER_ALPS_TSBE5_PAL, 4329 .tuner_type = TUNER_ALPS_TSBE5_PAL,
4330 .radio_type = UNSET, 4330 .radio_type = TUNER_TEA5767,
4331 .tuner_addr = ADDR_UNSET, 4331 .tuner_addr = 0xc2 >> 1,
4332 .radio_addr = ADDR_UNSET, 4332 .radio_addr = 0xc0 >> 1,
4333 .tda9887_conf = TDA9887_PRESENT, 4333 .tda9887_conf = TDA9887_PRESENT,
4334 .gpiomask = 0x000A8004, 4334 .gpiomask = 0x000A8004,
4335 .inputs = {{ 4335 .inputs = {{
diff --git a/drivers/media/video/saa7164/saa7164-buffer.c b/drivers/media/video/saa7164/saa7164-buffer.c
index 5713f3a4b76c..ddd25d32723d 100644
--- a/drivers/media/video/saa7164/saa7164-buffer.c
+++ b/drivers/media/video/saa7164/saa7164-buffer.c
@@ -136,10 +136,11 @@ ret:
136int saa7164_buffer_dealloc(struct saa7164_tsport *port, 136int saa7164_buffer_dealloc(struct saa7164_tsport *port,
137 struct saa7164_buffer *buf) 137 struct saa7164_buffer *buf)
138{ 138{
139 struct saa7164_dev *dev = port->dev; 139 struct saa7164_dev *dev;
140 140
141 if ((buf == 0) || (port == 0)) 141 if (!buf || !port)
142 return SAA_ERR_BAD_PARAMETER; 142 return SAA_ERR_BAD_PARAMETER;
143 dev = port->dev;
143 144
144 dprintk(DBGLVL_BUF, "%s() deallocating buffer @ 0x%p\n", __func__, buf); 145 dprintk(DBGLVL_BUF, "%s() deallocating buffer @ 0x%p\n", __func__, buf);
145 146
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 8bdd940f32e6..2ac85d8984f0 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -486,6 +486,12 @@ static int uvc_parse_format(struct uvc_device *dev,
486 max(frame->dwFrameInterval[0], 486 max(frame->dwFrameInterval[0],
487 frame->dwDefaultFrameInterval)); 487 frame->dwDefaultFrameInterval));
488 488
489 if (dev->quirks & UVC_QUIRK_RESTRICT_FRAME_RATE) {
490 frame->bFrameIntervalType = 1;
491 frame->dwFrameInterval[0] =
492 frame->dwDefaultFrameInterval;
493 }
494
489 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n", 495 uvc_trace(UVC_TRACE_DESCR, "- %ux%u (%u.%u fps)\n",
490 frame->wWidth, frame->wHeight, 496 frame->wWidth, frame->wHeight,
491 10000000/frame->dwDefaultFrameInterval, 497 10000000/frame->dwDefaultFrameInterval,
@@ -2026,6 +2032,15 @@ static struct usb_device_id uvc_ids[] = {
2026 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 2032 .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
2027 .bInterfaceSubClass = 1, 2033 .bInterfaceSubClass = 1,
2028 .bInterfaceProtocol = 0 }, 2034 .bInterfaceProtocol = 0 },
2035 /* Chicony CNF7129 (Asus EEE 100HE) */
2036 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2037 | USB_DEVICE_ID_MATCH_INT_INFO,
2038 .idVendor = 0x04f2,
2039 .idProduct = 0xb071,
2040 .bInterfaceClass = USB_CLASS_VIDEO,
2041 .bInterfaceSubClass = 1,
2042 .bInterfaceProtocol = 0,
2043 .driver_info = UVC_QUIRK_RESTRICT_FRAME_RATE },
2029 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */ 2044 /* Alcor Micro AU3820 (Future Boy PC USB Webcam) */
2030 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2045 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2031 | USB_DEVICE_ID_MATCH_INT_INFO, 2046 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -2091,6 +2106,15 @@ static struct usb_device_id uvc_ids[] = {
2091 .bInterfaceProtocol = 0, 2106 .bInterfaceProtocol = 0,
2092 .driver_info = UVC_QUIRK_PROBE_MINMAX 2107 .driver_info = UVC_QUIRK_PROBE_MINMAX
2093 | UVC_QUIRK_PROBE_DEF }, 2108 | UVC_QUIRK_PROBE_DEF },
2109 /* IMC Networks (Medion Akoya) */
2110 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2111 | USB_DEVICE_ID_MATCH_INT_INFO,
2112 .idVendor = 0x13d3,
2113 .idProduct = 0x5103,
2114 .bInterfaceClass = USB_CLASS_VIDEO,
2115 .bInterfaceSubClass = 1,
2116 .bInterfaceProtocol = 0,
2117 .driver_info = UVC_QUIRK_STREAM_NO_FID },
2094 /* Syntek (HP Spartan) */ 2118 /* Syntek (HP Spartan) */
2095 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 2119 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
2096 | USB_DEVICE_ID_MATCH_INT_INFO, 2120 | USB_DEVICE_ID_MATCH_INT_INFO,
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index bdacf3beabf5..892e0e51916c 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -182,6 +182,7 @@ struct uvc_xu_control {
182#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020 182#define UVC_QUIRK_IGNORE_SELECTOR_UNIT 0x00000020
183#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080 183#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080
184#define UVC_QUIRK_PROBE_DEF 0x00000100 184#define UVC_QUIRK_PROBE_DEF 0x00000100
185#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
185 186
186/* Format flags */ 187/* Format flags */
187#define UVC_FMT_FLAG_COMPRESSED 0x00000001 188#define UVC_FMT_FLAG_COMPRESSED 0x00000001
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 073f01390cdd..86294ed35c9b 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -193,17 +193,24 @@ static int put_video_window32(struct video_window *kp, struct video_window32 __u
193struct video_code32 { 193struct video_code32 {
194 char loadwhat[16]; /* name or tag of file being passed */ 194 char loadwhat[16]; /* name or tag of file being passed */
195 compat_int_t datasize; 195 compat_int_t datasize;
196 unsigned char *data; 196 compat_uptr_t data;
197}; 197};
198 198
199static int get_microcode32(struct video_code *kp, struct video_code32 __user *up) 199static struct video_code __user *get_microcode32(struct video_code32 *kp)
200{ 200{
201 if (!access_ok(VERIFY_READ, up, sizeof(struct video_code32)) || 201 struct video_code __user *up;
202 copy_from_user(kp->loadwhat, up->loadwhat, sizeof(up->loadwhat)) || 202
203 get_user(kp->datasize, &up->datasize) || 203 up = compat_alloc_user_space(sizeof(*up));
204 copy_from_user(kp->data, up->data, up->datasize)) 204
205 return -EFAULT; 205 /*
206 return 0; 206 * NOTE! We don't actually care if these fail. If the
207 * user address is invalid, the native ioctl will do
208 * the error handling for us
209 */
210 (void) copy_to_user(up->loadwhat, kp->loadwhat, sizeof(up->loadwhat));
211 (void) put_user(kp->datasize, &up->datasize);
212 (void) put_user(compat_ptr(kp->data), &up->data);
213 return up;
207} 214}
208 215
209#define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32) 216#define VIDIOCGTUNER32 _IOWR('v', 4, struct video_tuner32)
@@ -739,7 +746,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
739 struct video_tuner vt; 746 struct video_tuner vt;
740 struct video_buffer vb; 747 struct video_buffer vb;
741 struct video_window vw; 748 struct video_window vw;
742 struct video_code vc; 749 struct video_code32 vc;
743 struct video_audio va; 750 struct video_audio va;
744#endif 751#endif
745 struct v4l2_format v2f; 752 struct v4l2_format v2f;
@@ -818,8 +825,11 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
818 break; 825 break;
819 826
820 case VIDIOCSMICROCODE: 827 case VIDIOCSMICROCODE:
821 err = get_microcode32(&karg.vc, up); 828 /* Copy the 32-bit "video_code32" to kernel space */
822 compatible_arg = 0; 829 if (copy_from_user(&karg.vc, up, sizeof(karg.vc)))
830 return -EFAULT;
831 /* Convert the 32-bit version to a 64-bit version in user space */
832 up = get_microcode32(&karg.vc);
823 break; 833 break;
824 834
825 case VIDIOCSFREQ: 835 case VIDIOCSFREQ:
diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
index 372b87efcd05..6ff9e4bac3ea 100644
--- a/drivers/media/video/videobuf-dma-contig.c
+++ b/drivers/media/video/videobuf-dma-contig.c
@@ -393,8 +393,10 @@ void videobuf_dma_contig_free(struct videobuf_queue *q,
393 } 393 }
394 394
395 /* read() method */ 395 /* read() method */
396 dma_free_coherent(q->dev, mem->size, mem->vaddr, mem->dma_handle); 396 if (mem->vaddr) {
397 mem->vaddr = NULL; 397 dma_free_coherent(q->dev, mem->size, mem->vaddr, mem->dma_handle);
398 mem->vaddr = NULL;
399 }
398} 400}
399EXPORT_SYMBOL_GPL(videobuf_dma_contig_free); 401EXPORT_SYMBOL_GPL(videobuf_dma_contig_free);
400 402
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 06f9a9c2a39a..2ad0bc252b0e 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -94,7 +94,7 @@ err:
94 * must free the memory. 94 * must free the memory.
95 */ 95 */
96static struct scatterlist *videobuf_pages_to_sg(struct page **pages, 96static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
97 int nr_pages, int offset) 97 int nr_pages, int offset, size_t size)
98{ 98{
99 struct scatterlist *sglist; 99 struct scatterlist *sglist;
100 int i; 100 int i;
@@ -110,12 +110,14 @@ static struct scatterlist *videobuf_pages_to_sg(struct page **pages,
110 /* DMA to highmem pages might not work */ 110 /* DMA to highmem pages might not work */
111 goto highmem; 111 goto highmem;
112 sg_set_page(&sglist[0], pages[0], PAGE_SIZE - offset, offset); 112 sg_set_page(&sglist[0], pages[0], PAGE_SIZE - offset, offset);
113 size -= PAGE_SIZE - offset;
113 for (i = 1; i < nr_pages; i++) { 114 for (i = 1; i < nr_pages; i++) {
114 if (NULL == pages[i]) 115 if (NULL == pages[i])
115 goto nopage; 116 goto nopage;
116 if (PageHighMem(pages[i])) 117 if (PageHighMem(pages[i]))
117 goto highmem; 118 goto highmem;
118 sg_set_page(&sglist[i], pages[i], PAGE_SIZE, 0); 119 sg_set_page(&sglist[i], pages[i], min(PAGE_SIZE, size), 0);
120 size -= min(PAGE_SIZE, size);
119 } 121 }
120 return sglist; 122 return sglist;
121 123
@@ -170,7 +172,8 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
170 172
171 first = (data & PAGE_MASK) >> PAGE_SHIFT; 173 first = (data & PAGE_MASK) >> PAGE_SHIFT;
172 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT; 174 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
173 dma->offset = data & ~PAGE_MASK; 175 dma->offset = data & ~PAGE_MASK;
176 dma->size = size;
174 dma->nr_pages = last-first+1; 177 dma->nr_pages = last-first+1;
175 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL); 178 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
176 if (NULL == dma->pages) 179 if (NULL == dma->pages)
@@ -252,7 +255,7 @@ int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
252 255
253 if (dma->pages) { 256 if (dma->pages) {
254 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages, 257 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
255 dma->offset); 258 dma->offset, dma->size);
256 } 259 }
257 if (dma->vaddr) { 260 if (dma->vaddr) {
258 dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr, 261 dma->sglist = videobuf_vmalloc_to_sg(dma->vaddr,
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index d3f1a087eced..02362eccc588 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -18,11 +18,12 @@
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/smp_lock.h> 21#include <linux/mutex.h>
22#include <linux/memstick.h> 22#include <linux/memstick.h>
23 23
24#define DRIVER_NAME "mspro_block" 24#define DRIVER_NAME "mspro_block"
25 25
26static DEFINE_MUTEX(mspro_block_mutex);
26static int major; 27static int major;
27module_param(major, int, 0644); 28module_param(major, int, 0644);
28 29
@@ -180,7 +181,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
180 struct mspro_block_data *msb = disk->private_data; 181 struct mspro_block_data *msb = disk->private_data;
181 int rc = -ENXIO; 182 int rc = -ENXIO;
182 183
183 lock_kernel(); 184 mutex_lock(&mspro_block_mutex);
184 mutex_lock(&mspro_block_disk_lock); 185 mutex_lock(&mspro_block_disk_lock);
185 186
186 if (msb && msb->card) { 187 if (msb && msb->card) {
@@ -192,7 +193,7 @@ static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
192 } 193 }
193 194
194 mutex_unlock(&mspro_block_disk_lock); 195 mutex_unlock(&mspro_block_disk_lock);
195 unlock_kernel(); 196 mutex_unlock(&mspro_block_mutex);
196 197
197 return rc; 198 return rc;
198} 199}
@@ -225,9 +226,9 @@ static int mspro_block_disk_release(struct gendisk *disk)
225static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode) 226static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
226{ 227{
227 int ret; 228 int ret;
228 lock_kernel(); 229 mutex_lock(&mspro_block_mutex);
229 ret = mspro_block_disk_release(disk); 230 ret = mspro_block_disk_release(disk);
230 unlock_kernel(); 231 mutex_unlock(&mspro_block_mutex);
231 return ret; 232 return ret;
232} 233}
233 234
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index d8ddfdf8be14..a3856ed90aef 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -54,7 +54,7 @@
54#include <linux/pci.h> 54#include <linux/pci.h>
55#include <linux/delay.h> /* for mdelay */ 55#include <linux/delay.h> /* for mdelay */
56#include <linux/miscdevice.h> 56#include <linux/miscdevice.h>
57#include <linux/smp_lock.h> 57#include <linux/mutex.h>
58#include <linux/compat.h> 58#include <linux/compat.h>
59 59
60#include <asm/io.h> 60#include <asm/io.h>
@@ -83,6 +83,7 @@ MODULE_VERSION(my_VERSION);
83 83
84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 84/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
85 85
86static DEFINE_MUTEX(mpctl_mutex);
86static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS; 87static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
87static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS; 88static u8 mptctl_taskmgmt_id = MPT_MAX_PROTOCOL_DRIVERS;
88 89
@@ -601,12 +602,12 @@ mptctl_fasync(int fd, struct file *filep, int mode)
601 MPT_ADAPTER *ioc; 602 MPT_ADAPTER *ioc;
602 int ret; 603 int ret;
603 604
604 lock_kernel(); 605 mutex_lock(&mpctl_mutex);
605 list_for_each_entry(ioc, &ioc_list, list) 606 list_for_each_entry(ioc, &ioc_list, list)
606 ioc->aen_event_read_flag=0; 607 ioc->aen_event_read_flag=0;
607 608
608 ret = fasync_helper(fd, filep, mode, &async_queue); 609 ret = fasync_helper(fd, filep, mode, &async_queue);
609 unlock_kernel(); 610 mutex_unlock(&mpctl_mutex);
610 return ret; 611 return ret;
611} 612}
612 613
@@ -698,9 +699,9 @@ static long
698mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 699mptctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
699{ 700{
700 long ret; 701 long ret;
701 lock_kernel(); 702 mutex_lock(&mpctl_mutex);
702 ret = __mptctl_ioctl(file, cmd, arg); 703 ret = __mptctl_ioctl(file, cmd, arg);
703 unlock_kernel(); 704 mutex_unlock(&mpctl_mutex);
704 return ret; 705 return ret;
705} 706}
706 707
@@ -2926,7 +2927,7 @@ compat_mpt_command(struct file *filp, unsigned int cmd,
2926static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 2927static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
2927{ 2928{
2928 long ret; 2929 long ret;
2929 lock_kernel(); 2930 mutex_lock(&mpctl_mutex);
2930 switch (cmd) { 2931 switch (cmd) {
2931 case MPTIOCINFO: 2932 case MPTIOCINFO:
2932 case MPTIOCINFO1: 2933 case MPTIOCINFO1:
@@ -2951,7 +2952,7 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a
2951 ret = -ENOIOCTLCMD; 2952 ret = -ENOIOCTLCMD;
2952 break; 2953 break;
2953 } 2954 }
2954 unlock_kernel(); 2955 mutex_unlock(&mpctl_mutex);
2955 return ret; 2956 return ret;
2956} 2957}
2957 2958
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index f0f1e667000f..f87a9d405a5e 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -53,7 +53,7 @@
53#include <linux/module.h> 53#include <linux/module.h>
54#include <linux/slab.h> 54#include <linux/slab.h>
55#include <linux/i2o.h> 55#include <linux/i2o.h>
56#include <linux/smp_lock.h> 56#include <linux/mutex.h>
57 57
58#include <linux/mempool.h> 58#include <linux/mempool.h>
59 59
@@ -69,6 +69,7 @@
69#define OSM_VERSION "1.325" 69#define OSM_VERSION "1.325"
70#define OSM_DESCRIPTION "I2O Block Device OSM" 70#define OSM_DESCRIPTION "I2O Block Device OSM"
71 71
72static DEFINE_MUTEX(i2o_block_mutex);
72static struct i2o_driver i2o_block_driver; 73static struct i2o_driver i2o_block_driver;
73 74
74/* global Block OSM request mempool */ 75/* global Block OSM request mempool */
@@ -578,7 +579,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
578 if (!dev->i2o_dev) 579 if (!dev->i2o_dev)
579 return -ENODEV; 580 return -ENODEV;
580 581
581 lock_kernel(); 582 mutex_lock(&i2o_block_mutex);
582 if (dev->power > 0x1f) 583 if (dev->power > 0x1f)
583 i2o_block_device_power(dev, 0x02); 584 i2o_block_device_power(dev, 0x02);
584 585
@@ -587,7 +588,7 @@ static int i2o_block_open(struct block_device *bdev, fmode_t mode)
587 i2o_block_device_lock(dev->i2o_dev, -1); 588 i2o_block_device_lock(dev->i2o_dev, -1);
588 589
589 osm_debug("Ready.\n"); 590 osm_debug("Ready.\n");
590 unlock_kernel(); 591 mutex_unlock(&i2o_block_mutex);
591 592
592 return 0; 593 return 0;
593}; 594};
@@ -618,7 +619,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
618 if (!dev->i2o_dev) 619 if (!dev->i2o_dev)
619 return 0; 620 return 0;
620 621
621 lock_kernel(); 622 mutex_lock(&i2o_block_mutex);
622 i2o_block_device_flush(dev->i2o_dev); 623 i2o_block_device_flush(dev->i2o_dev);
623 624
624 i2o_block_device_unlock(dev->i2o_dev, -1); 625 i2o_block_device_unlock(dev->i2o_dev, -1);
@@ -629,7 +630,7 @@ static int i2o_block_release(struct gendisk *disk, fmode_t mode)
629 operation = 0x24; 630 operation = 0x24;
630 631
631 i2o_block_device_power(dev, operation); 632 i2o_block_device_power(dev, operation);
632 unlock_kernel(); 633 mutex_unlock(&i2o_block_mutex);
633 634
634 return 0; 635 return 0;
635} 636}
@@ -664,7 +665,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
664 if (!capable(CAP_SYS_ADMIN)) 665 if (!capable(CAP_SYS_ADMIN))
665 return -EPERM; 666 return -EPERM;
666 667
667 lock_kernel(); 668 mutex_lock(&i2o_block_mutex);
668 switch (cmd) { 669 switch (cmd) {
669 case BLKI2OGRSTRAT: 670 case BLKI2OGRSTRAT:
670 ret = put_user(dev->rcache, (int __user *)arg); 671 ret = put_user(dev->rcache, (int __user *)arg);
@@ -688,7 +689,7 @@ static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
688 ret = 0; 689 ret = 0;
689 break; 690 break;
690 } 691 }
691 unlock_kernel(); 692 mutex_unlock(&i2o_block_mutex);
692 693
693 return ret; 694 return ret;
694}; 695};
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 068ba0785bb4..7d3cc575c361 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -31,7 +31,7 @@
31 */ 31 */
32 32
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
34#include <linux/smp_lock.h> 34#include <linux/mutex.h>
35#include <linux/compat.h> 35#include <linux/compat.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37 37
@@ -41,6 +41,7 @@
41 41
42#define SG_TABLESIZE 30 42#define SG_TABLESIZE 30
43 43
44static DEFINE_MUTEX(i2o_cfg_mutex);
44static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long); 45static long i2o_cfg_ioctl(struct file *, unsigned int, unsigned long);
45 46
46static spinlock_t i2o_config_lock; 47static spinlock_t i2o_config_lock;
@@ -741,7 +742,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
741 unsigned long arg) 742 unsigned long arg)
742{ 743{
743 int ret; 744 int ret;
744 lock_kernel(); 745 mutex_lock(&i2o_cfg_mutex);
745 switch (cmd) { 746 switch (cmd) {
746 case I2OGETIOPS: 747 case I2OGETIOPS:
747 ret = i2o_cfg_ioctl(file, cmd, arg); 748 ret = i2o_cfg_ioctl(file, cmd, arg);
@@ -753,7 +754,7 @@ static long i2o_cfg_compat_ioctl(struct file *file, unsigned cmd,
753 ret = -ENOIOCTLCMD; 754 ret = -ENOIOCTLCMD;
754 break; 755 break;
755 } 756 }
756 unlock_kernel(); 757 mutex_unlock(&i2o_cfg_mutex);
757 return ret; 758 return ret;
758} 759}
759 760
@@ -981,7 +982,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
981{ 982{
982 int ret; 983 int ret;
983 984
984 lock_kernel(); 985 mutex_lock(&i2o_cfg_mutex);
985 switch (cmd) { 986 switch (cmd) {
986 case I2OGETIOPS: 987 case I2OGETIOPS:
987 ret = i2o_cfg_getiops(arg); 988 ret = i2o_cfg_getiops(arg);
@@ -1037,7 +1038,7 @@ static long i2o_cfg_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
1037 osm_debug("unknown ioctl called!\n"); 1038 osm_debug("unknown ioctl called!\n");
1038 ret = -EINVAL; 1039 ret = -EINVAL;
1039 } 1040 }
1040 unlock_kernel(); 1041 mutex_unlock(&i2o_cfg_mutex);
1041 return ret; 1042 return ret;
1042} 1043}
1043 1044
@@ -1051,7 +1052,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1051 if (!tmp) 1052 if (!tmp)
1052 return -ENOMEM; 1053 return -ENOMEM;
1053 1054
1054 lock_kernel(); 1055 mutex_lock(&i2o_cfg_mutex);
1055 file->private_data = (void *)(i2o_cfg_info_id++); 1056 file->private_data = (void *)(i2o_cfg_info_id++);
1056 tmp->fp = file; 1057 tmp->fp = file;
1057 tmp->fasync = NULL; 1058 tmp->fasync = NULL;
@@ -1065,7 +1066,7 @@ static int cfg_open(struct inode *inode, struct file *file)
1065 spin_lock_irqsave(&i2o_config_lock, flags); 1066 spin_lock_irqsave(&i2o_config_lock, flags);
1066 open_files = tmp; 1067 open_files = tmp;
1067 spin_unlock_irqrestore(&i2o_config_lock, flags); 1068 spin_unlock_irqrestore(&i2o_config_lock, flags);
1068 unlock_kernel(); 1069 mutex_unlock(&i2o_cfg_mutex);
1069 1070
1070 return 0; 1071 return 0;
1071} 1072}
@@ -1076,14 +1077,14 @@ static int cfg_fasync(int fd, struct file *fp, int on)
1076 struct i2o_cfg_info *p; 1077 struct i2o_cfg_info *p;
1077 int ret = -EBADF; 1078 int ret = -EBADF;
1078 1079
1079 lock_kernel(); 1080 mutex_lock(&i2o_cfg_mutex);
1080 for (p = open_files; p; p = p->next) 1081 for (p = open_files; p; p = p->next)
1081 if (p->q_id == id) 1082 if (p->q_id == id)
1082 break; 1083 break;
1083 1084
1084 if (p) 1085 if (p)
1085 ret = fasync_helper(fd, fp, on, &p->fasync); 1086 ret = fasync_helper(fd, fp, on, &p->fasync);
1086 unlock_kernel(); 1087 mutex_unlock(&i2o_cfg_mutex);
1087 return ret; 1088 return ret;
1088} 1089}
1089 1090
@@ -1093,7 +1094,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1093 struct i2o_cfg_info *p, **q; 1094 struct i2o_cfg_info *p, **q;
1094 unsigned long flags; 1095 unsigned long flags;
1095 1096
1096 lock_kernel(); 1097 mutex_lock(&i2o_cfg_mutex);
1097 spin_lock_irqsave(&i2o_config_lock, flags); 1098 spin_lock_irqsave(&i2o_config_lock, flags);
1098 for (q = &open_files; (p = *q) != NULL; q = &p->next) { 1099 for (q = &open_files; (p = *q) != NULL; q = &p->next) {
1099 if (p->q_id == id) { 1100 if (p->q_id == id) {
@@ -1103,7 +1104,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1103 } 1104 }
1104 } 1105 }
1105 spin_unlock_irqrestore(&i2o_config_lock, flags); 1106 spin_unlock_irqrestore(&i2o_config_lock, flags);
1106 unlock_kernel(); 1107 mutex_unlock(&i2o_cfg_mutex);
1107 1108
1108 return 0; 1109 return 0;
1109} 1110}
diff --git a/drivers/mfd/ab8500-spi.c b/drivers/mfd/ab8500-spi.c
index e1c8b62b086d..01b6d584442c 100644
--- a/drivers/mfd/ab8500-spi.c
+++ b/drivers/mfd/ab8500-spi.c
@@ -83,6 +83,11 @@ static int __devinit ab8500_spi_probe(struct spi_device *spi)
83 struct ab8500 *ab8500; 83 struct ab8500 *ab8500;
84 int ret; 84 int ret;
85 85
86 spi->bits_per_word = 24;
87 ret = spi_setup(spi);
88 if (ret < 0)
89 return ret;
90
86 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL); 91 ab8500 = kzalloc(sizeof *ab8500, GFP_KERNEL);
87 if (!ab8500) 92 if (!ab8500)
88 return -ENOMEM; 93 return -ENOMEM;
diff --git a/drivers/mfd/max8925-core.c b/drivers/mfd/max8925-core.c
index 04028a9ee082..428377a5a6f5 100644
--- a/drivers/mfd/max8925-core.c
+++ b/drivers/mfd/max8925-core.c
@@ -429,24 +429,25 @@ static void max8925_irq_sync_unlock(unsigned int irq)
429 irq_tsc = cache_tsc; 429 irq_tsc = cache_tsc;
430 for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) { 430 for (i = 0; i < ARRAY_SIZE(max8925_irqs); i++) {
431 irq_data = &max8925_irqs[i]; 431 irq_data = &max8925_irqs[i];
432 /* 1 -- disable, 0 -- enable */
432 switch (irq_data->mask_reg) { 433 switch (irq_data->mask_reg) {
433 case MAX8925_CHG_IRQ1_MASK: 434 case MAX8925_CHG_IRQ1_MASK:
434 irq_chg[0] &= irq_data->enable; 435 irq_chg[0] &= ~irq_data->enable;
435 break; 436 break;
436 case MAX8925_CHG_IRQ2_MASK: 437 case MAX8925_CHG_IRQ2_MASK:
437 irq_chg[1] &= irq_data->enable; 438 irq_chg[1] &= ~irq_data->enable;
438 break; 439 break;
439 case MAX8925_ON_OFF_IRQ1_MASK: 440 case MAX8925_ON_OFF_IRQ1_MASK:
440 irq_on[0] &= irq_data->enable; 441 irq_on[0] &= ~irq_data->enable;
441 break; 442 break;
442 case MAX8925_ON_OFF_IRQ2_MASK: 443 case MAX8925_ON_OFF_IRQ2_MASK:
443 irq_on[1] &= irq_data->enable; 444 irq_on[1] &= ~irq_data->enable;
444 break; 445 break;
445 case MAX8925_RTC_IRQ_MASK: 446 case MAX8925_RTC_IRQ_MASK:
446 irq_rtc &= irq_data->enable; 447 irq_rtc &= ~irq_data->enable;
447 break; 448 break;
448 case MAX8925_TSC_IRQ_MASK: 449 case MAX8925_TSC_IRQ_MASK:
449 irq_tsc &= irq_data->enable; 450 irq_tsc &= ~irq_data->enable;
450 break; 451 break;
451 default: 452 default:
452 dev_err(chip->dev, "wrong IRQ\n"); 453 dev_err(chip->dev, "wrong IRQ\n");
diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
index 097f24d8bceb..b9fda7018cef 100644
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -78,7 +78,7 @@ struct sih {
78 u8 irq_lines; /* number of supported irq lines */ 78 u8 irq_lines; /* number of supported irq lines */
79 79
80 /* SIR ignored -- set interrupt, for testing only */ 80 /* SIR ignored -- set interrupt, for testing only */
81 struct irq_data { 81 struct sih_irq_data {
82 u8 isr_offset; 82 u8 isr_offset;
83 u8 imr_offset; 83 u8 imr_offset;
84 } mask[2]; 84 } mask[2];
@@ -810,7 +810,7 @@ int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
810 twl4030_irq_chip = dummy_irq_chip; 810 twl4030_irq_chip = dummy_irq_chip;
811 twl4030_irq_chip.name = "twl4030"; 811 twl4030_irq_chip.name = "twl4030";
812 812
813 twl4030_sih_irq_chip.ack = dummy_irq_chip.ack; 813 twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
814 814
815 for (i = irq_base; i < irq_end; i++) { 815 for (i = irq_base; i < irq_end; i++) {
816 set_irq_chip_and_handler(i, &twl4030_irq_chip, 816 set_irq_chip_and_handler(i, &twl4030_irq_chip,
diff --git a/drivers/mfd/wm831x-irq.c b/drivers/mfd/wm831x-irq.c
index 7dabe4dbd373..294183b6260b 100644
--- a/drivers/mfd/wm831x-irq.c
+++ b/drivers/mfd/wm831x-irq.c
@@ -394,8 +394,13 @@ static int wm831x_irq_set_type(unsigned int irq, unsigned int type)
394 394
395 irq = irq - wm831x->irq_base; 395 irq = irq - wm831x->irq_base;
396 396
397 if (irq < WM831X_IRQ_GPIO_1 || irq > WM831X_IRQ_GPIO_11) 397 if (irq < WM831X_IRQ_GPIO_1 || irq > WM831X_IRQ_GPIO_11) {
398 return -EINVAL; 398 /* Ignore internal-only IRQs */
399 if (irq >= 0 && irq < WM831X_NUM_IRQS)
400 return 0;
401 else
402 return -EINVAL;
403 }
399 404
400 switch (type) { 405 switch (type) {
401 case IRQ_TYPE_EDGE_BOTH: 406 case IRQ_TYPE_EDGE_BOTH:
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 0b591b658243..b74331260744 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -368,7 +368,7 @@ config VMWARE_BALLOON
368 If unsure, say N. 368 If unsure, say N.
369 369
370 To compile this driver as a module, choose M here: the 370 To compile this driver as a module, choose M here: the
371 module will be called vmware_balloon. 371 module will be called vmw_balloon.
372 372
373config ARM_CHARLCD 373config ARM_CHARLCD
374 bool "ARM Ltd. Character LCD Driver" 374 bool "ARM Ltd. Character LCD Driver"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 255a80dc9d73..42eab95cde2a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -33,5 +33,5 @@ obj-$(CONFIG_IWMC3200TOP) += iwmc3200top/
33obj-$(CONFIG_HMC6352) += hmc6352.o 33obj-$(CONFIG_HMC6352) += hmc6352.o
34obj-y += eeprom/ 34obj-y += eeprom/
35obj-y += cb710/ 35obj-y += cb710/
36obj-$(CONFIG_VMWARE_BALLOON) += vmware_balloon.o 36obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
37obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o 37obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
index 714c6b487313..d5f3a3fd2319 100644
--- a/drivers/misc/bh1780gli.c
+++ b/drivers/misc/bh1780gli.c
@@ -190,7 +190,6 @@ static int __devexit bh1780_remove(struct i2c_client *client)
190 190
191 ddata = i2c_get_clientdata(client); 191 ddata = i2c_get_clientdata(client);
192 sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group); 192 sysfs_remove_group(&client->dev.kobj, &bh1780_attr_group);
193 i2c_set_clientdata(client, NULL);
194 kfree(ddata); 193 kfree(ddata);
195 194
196 return 0; 195 return 0;
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 6b38b5964294..4197a3cb26ba 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/phantom.h> 25#include <linux/phantom.h>
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/smp_lock.h> 27#include <linux/mutex.h>
28 28
29#include <asm/atomic.h> 29#include <asm/atomic.h>
30#include <asm/io.h> 30#include <asm/io.h>
@@ -38,6 +38,7 @@
38#define PHB_RUNNING 1 38#define PHB_RUNNING 1
39#define PHB_NOT_OH 2 39#define PHB_NOT_OH 2
40 40
41static DEFINE_MUTEX(phantom_mutex);
41static struct class *phantom_class; 42static struct class *phantom_class;
42static int phantom_major; 43static int phantom_major;
43 44
@@ -215,17 +216,17 @@ static int phantom_open(struct inode *inode, struct file *file)
215 struct phantom_device *dev = container_of(inode->i_cdev, 216 struct phantom_device *dev = container_of(inode->i_cdev,
216 struct phantom_device, cdev); 217 struct phantom_device, cdev);
217 218
218 lock_kernel(); 219 mutex_lock(&phantom_mutex);
219 nonseekable_open(inode, file); 220 nonseekable_open(inode, file);
220 221
221 if (mutex_lock_interruptible(&dev->open_lock)) { 222 if (mutex_lock_interruptible(&dev->open_lock)) {
222 unlock_kernel(); 223 mutex_unlock(&phantom_mutex);
223 return -ERESTARTSYS; 224 return -ERESTARTSYS;
224 } 225 }
225 226
226 if (dev->opened) { 227 if (dev->opened) {
227 mutex_unlock(&dev->open_lock); 228 mutex_unlock(&dev->open_lock);
228 unlock_kernel(); 229 mutex_unlock(&phantom_mutex);
229 return -EINVAL; 230 return -EINVAL;
230 } 231 }
231 232
@@ -236,7 +237,7 @@ static int phantom_open(struct inode *inode, struct file *file)
236 atomic_set(&dev->counter, 0); 237 atomic_set(&dev->counter, 0);
237 dev->opened++; 238 dev->opened++;
238 mutex_unlock(&dev->open_lock); 239 mutex_unlock(&dev->open_lock);
239 unlock_kernel(); 240 mutex_unlock(&phantom_mutex);
240 return 0; 241 return 0;
241} 242}
242 243
diff --git a/drivers/misc/vmware_balloon.c b/drivers/misc/vmw_balloon.c
index 2a1e804a71aa..2a1e804a71aa 100644
--- a/drivers/misc/vmware_balloon.c
+++ b/drivers/misc/vmw_balloon.c
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index d545f79f6000..00073b7c0368 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -29,7 +29,6 @@
29#include <linux/kdev_t.h> 29#include <linux/kdev_t.h>
30#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/smp_lock.h>
33#include <linux/scatterlist.h> 32#include <linux/scatterlist.h>
34#include <linux/string_helpers.h> 33#include <linux/string_helpers.h>
35 34
@@ -51,6 +50,7 @@ MODULE_ALIAS("mmc:block");
51#define MMC_SHIFT 3 50#define MMC_SHIFT 3
52#define MMC_NUM_MINORS (256 >> MMC_SHIFT) 51#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
53 52
53static DEFINE_MUTEX(block_mutex);
54static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS); 54static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
55 55
56/* 56/*
@@ -108,7 +108,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
108 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk); 108 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
109 int ret = -ENXIO; 109 int ret = -ENXIO;
110 110
111 lock_kernel(); 111 mutex_lock(&block_mutex);
112 if (md) { 112 if (md) {
113 if (md->usage == 2) 113 if (md->usage == 2)
114 check_disk_change(bdev); 114 check_disk_change(bdev);
@@ -119,7 +119,7 @@ static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
119 ret = -EROFS; 119 ret = -EROFS;
120 } 120 }
121 } 121 }
122 unlock_kernel(); 122 mutex_unlock(&block_mutex);
123 123
124 return ret; 124 return ret;
125} 125}
@@ -128,9 +128,9 @@ static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
128{ 128{
129 struct mmc_blk_data *md = disk->private_data; 129 struct mmc_blk_data *md = disk->private_data;
130 130
131 lock_kernel(); 131 mutex_lock(&block_mutex);
132 mmc_blk_put(md); 132 mmc_blk_put(md);
133 unlock_kernel(); 133 mutex_unlock(&block_mutex);
134 return 0; 134 return 0;
135} 135}
136 136
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5db49b124ffa..09eee6df0653 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1631,6 +1631,19 @@ int mmc_suspend_host(struct mmc_host *host)
1631 if (host->bus_ops && !host->bus_dead) { 1631 if (host->bus_ops && !host->bus_dead) {
1632 if (host->bus_ops->suspend) 1632 if (host->bus_ops->suspend)
1633 err = host->bus_ops->suspend(host); 1633 err = host->bus_ops->suspend(host);
1634 if (err == -ENOSYS || !host->bus_ops->resume) {
1635 /*
1636 * We simply "remove" the card in this case.
1637 * It will be redetected on resume.
1638 */
1639 if (host->bus_ops->remove)
1640 host->bus_ops->remove(host);
1641 mmc_claim_host(host);
1642 mmc_detach_bus(host);
1643 mmc_release_host(host);
1644 host->pm_flags = 0;
1645 err = 0;
1646 }
1634 } 1647 }
1635 mmc_bus_put(host); 1648 mmc_bus_put(host);
1636 1649
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 840b301b5671..f2e02d7d9f3d 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -41,23 +41,35 @@ static unsigned int fmax = 515633;
41 * @clkreg: default value for MCICLOCK register 41 * @clkreg: default value for MCICLOCK register
42 * @clkreg_enable: enable value for MMCICLOCK register 42 * @clkreg_enable: enable value for MMCICLOCK register
43 * @datalength_bits: number of bits in the MMCIDATALENGTH register 43 * @datalength_bits: number of bits in the MMCIDATALENGTH register
44 * @fifosize: number of bytes that can be written when MMCI_TXFIFOEMPTY
45 * is asserted (likewise for RX)
46 * @fifohalfsize: number of bytes that can be written when MCI_TXFIFOHALFEMPTY
47 * is asserted (likewise for RX)
44 */ 48 */
45struct variant_data { 49struct variant_data {
46 unsigned int clkreg; 50 unsigned int clkreg;
47 unsigned int clkreg_enable; 51 unsigned int clkreg_enable;
48 unsigned int datalength_bits; 52 unsigned int datalength_bits;
53 unsigned int fifosize;
54 unsigned int fifohalfsize;
49}; 55};
50 56
51static struct variant_data variant_arm = { 57static struct variant_data variant_arm = {
58 .fifosize = 16 * 4,
59 .fifohalfsize = 8 * 4,
52 .datalength_bits = 16, 60 .datalength_bits = 16,
53}; 61};
54 62
55static struct variant_data variant_u300 = { 63static struct variant_data variant_u300 = {
64 .fifosize = 16 * 4,
65 .fifohalfsize = 8 * 4,
56 .clkreg_enable = 1 << 13, /* HWFCEN */ 66 .clkreg_enable = 1 << 13, /* HWFCEN */
57 .datalength_bits = 16, 67 .datalength_bits = 16,
58}; 68};
59 69
60static struct variant_data variant_ux500 = { 70static struct variant_data variant_ux500 = {
71 .fifosize = 30 * 4,
72 .fifohalfsize = 8 * 4,
61 .clkreg = MCI_CLK_ENABLE, 73 .clkreg = MCI_CLK_ENABLE,
62 .clkreg_enable = 1 << 14, /* HWFCEN */ 74 .clkreg_enable = 1 << 14, /* HWFCEN */
63 .datalength_bits = 24, 75 .datalength_bits = 24,
@@ -138,6 +150,7 @@ static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
138 150
139static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) 151static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
140{ 152{
153 struct variant_data *variant = host->variant;
141 unsigned int datactrl, timeout, irqmask; 154 unsigned int datactrl, timeout, irqmask;
142 unsigned long long clks; 155 unsigned long long clks;
143 void __iomem *base; 156 void __iomem *base;
@@ -173,7 +186,7 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
173 * If we have less than a FIFOSIZE of bytes to transfer, 186 * If we have less than a FIFOSIZE of bytes to transfer,
174 * trigger a PIO interrupt as soon as any data is available. 187 * trigger a PIO interrupt as soon as any data is available.
175 */ 188 */
176 if (host->size < MCI_FIFOSIZE) 189 if (host->size < variant->fifosize)
177 irqmask |= MCI_RXDATAAVLBLMASK; 190 irqmask |= MCI_RXDATAAVLBLMASK;
178 } else { 191 } else {
179 /* 192 /*
@@ -332,13 +345,15 @@ static int mmci_pio_read(struct mmci_host *host, char *buffer, unsigned int rema
332 345
333static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status) 346static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int remain, u32 status)
334{ 347{
348 struct variant_data *variant = host->variant;
335 void __iomem *base = host->base; 349 void __iomem *base = host->base;
336 char *ptr = buffer; 350 char *ptr = buffer;
337 351
338 do { 352 do {
339 unsigned int count, maxcnt; 353 unsigned int count, maxcnt;
340 354
341 maxcnt = status & MCI_TXFIFOEMPTY ? MCI_FIFOSIZE : MCI_FIFOHALFSIZE; 355 maxcnt = status & MCI_TXFIFOEMPTY ?
356 variant->fifosize : variant->fifohalfsize;
342 count = min(remain, maxcnt); 357 count = min(remain, maxcnt);
343 358
344 writesl(base + MMCIFIFO, ptr, count >> 2); 359 writesl(base + MMCIFIFO, ptr, count >> 2);
@@ -362,6 +377,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
362{ 377{
363 struct mmci_host *host = dev_id; 378 struct mmci_host *host = dev_id;
364 struct sg_mapping_iter *sg_miter = &host->sg_miter; 379 struct sg_mapping_iter *sg_miter = &host->sg_miter;
380 struct variant_data *variant = host->variant;
365 void __iomem *base = host->base; 381 void __iomem *base = host->base;
366 unsigned long flags; 382 unsigned long flags;
367 u32 status; 383 u32 status;
@@ -420,7 +436,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
420 * If we're nearing the end of the read, switch to 436 * If we're nearing the end of the read, switch to
421 * "any data available" mode. 437 * "any data available" mode.
422 */ 438 */
423 if (status & MCI_RXACTIVE && host->size < MCI_FIFOSIZE) 439 if (status & MCI_RXACTIVE && host->size < variant->fifosize)
424 writel(MCI_RXDATAAVLBLMASK, base + MMCIMASK1); 440 writel(MCI_RXDATAAVLBLMASK, base + MMCIMASK1);
425 441
426 /* 442 /*
@@ -564,18 +580,23 @@ static int mmci_get_ro(struct mmc_host *mmc)
564 if (host->gpio_wp == -ENOSYS) 580 if (host->gpio_wp == -ENOSYS)
565 return -ENOSYS; 581 return -ENOSYS;
566 582
567 return gpio_get_value(host->gpio_wp); 583 return gpio_get_value_cansleep(host->gpio_wp);
568} 584}
569 585
570static int mmci_get_cd(struct mmc_host *mmc) 586static int mmci_get_cd(struct mmc_host *mmc)
571{ 587{
572 struct mmci_host *host = mmc_priv(mmc); 588 struct mmci_host *host = mmc_priv(mmc);
589 struct mmci_platform_data *plat = host->plat;
573 unsigned int status; 590 unsigned int status;
574 591
575 if (host->gpio_cd == -ENOSYS) 592 if (host->gpio_cd == -ENOSYS) {
576 status = host->plat->status(mmc_dev(host->mmc)); 593 if (!plat->status)
577 else 594 return 1; /* Assume always present */
578 status = !gpio_get_value(host->gpio_cd); 595
596 status = plat->status(mmc_dev(host->mmc));
597 } else
598 status = !!gpio_get_value_cansleep(host->gpio_cd)
599 ^ plat->cd_invert;
579 600
580 /* 601 /*
581 * Use positive logic throughout - status is zero for no card, 602 * Use positive logic throughout - status is zero for no card,
@@ -584,6 +605,15 @@ static int mmci_get_cd(struct mmc_host *mmc)
584 return status; 605 return status;
585} 606}
586 607
608static irqreturn_t mmci_cd_irq(int irq, void *dev_id)
609{
610 struct mmci_host *host = dev_id;
611
612 mmc_detect_change(host->mmc, msecs_to_jiffies(500));
613
614 return IRQ_HANDLED;
615}
616
587static const struct mmc_host_ops mmci_ops = { 617static const struct mmc_host_ops mmci_ops = {
588 .request = mmci_request, 618 .request = mmci_request,
589 .set_ios = mmci_set_ios, 619 .set_ios = mmci_set_ios,
@@ -620,6 +650,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
620 650
621 host->gpio_wp = -ENOSYS; 651 host->gpio_wp = -ENOSYS;
622 host->gpio_cd = -ENOSYS; 652 host->gpio_cd = -ENOSYS;
653 host->gpio_cd_irq = -1;
623 654
624 host->hw_designer = amba_manf(dev); 655 host->hw_designer = amba_manf(dev);
625 host->hw_revision = amba_rev(dev); 656 host->hw_revision = amba_rev(dev);
@@ -699,7 +730,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
699 if (host->vcc == NULL) 730 if (host->vcc == NULL)
700 mmc->ocr_avail = plat->ocr_mask; 731 mmc->ocr_avail = plat->ocr_mask;
701 mmc->caps = plat->capabilities; 732 mmc->caps = plat->capabilities;
702 mmc->caps |= MMC_CAP_NEEDS_POLL;
703 733
704 /* 734 /*
705 * We can do SGIO 735 * We can do SGIO
@@ -744,6 +774,12 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
744 host->gpio_cd = plat->gpio_cd; 774 host->gpio_cd = plat->gpio_cd;
745 else if (ret != -ENOSYS) 775 else if (ret != -ENOSYS)
746 goto err_gpio_cd; 776 goto err_gpio_cd;
777
778 ret = request_any_context_irq(gpio_to_irq(plat->gpio_cd),
779 mmci_cd_irq, 0,
780 DRIVER_NAME " (cd)", host);
781 if (ret >= 0)
782 host->gpio_cd_irq = gpio_to_irq(plat->gpio_cd);
747 } 783 }
748 if (gpio_is_valid(plat->gpio_wp)) { 784 if (gpio_is_valid(plat->gpio_wp)) {
749 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)"); 785 ret = gpio_request(plat->gpio_wp, DRIVER_NAME " (wp)");
@@ -755,6 +791,10 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
755 goto err_gpio_wp; 791 goto err_gpio_wp;
756 } 792 }
757 793
794 if ((host->plat->status || host->gpio_cd != -ENOSYS)
795 && host->gpio_cd_irq < 0)
796 mmc->caps |= MMC_CAP_NEEDS_POLL;
797
758 ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host); 798 ret = request_irq(dev->irq[0], mmci_irq, IRQF_SHARED, DRIVER_NAME " (cmd)", host);
759 if (ret) 799 if (ret)
760 goto unmap; 800 goto unmap;
@@ -781,6 +821,8 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
781 if (host->gpio_wp != -ENOSYS) 821 if (host->gpio_wp != -ENOSYS)
782 gpio_free(host->gpio_wp); 822 gpio_free(host->gpio_wp);
783 err_gpio_wp: 823 err_gpio_wp:
824 if (host->gpio_cd_irq >= 0)
825 free_irq(host->gpio_cd_irq, host);
784 if (host->gpio_cd != -ENOSYS) 826 if (host->gpio_cd != -ENOSYS)
785 gpio_free(host->gpio_cd); 827 gpio_free(host->gpio_cd);
786 err_gpio_cd: 828 err_gpio_cd:
@@ -819,6 +861,8 @@ static int __devexit mmci_remove(struct amba_device *dev)
819 861
820 if (host->gpio_wp != -ENOSYS) 862 if (host->gpio_wp != -ENOSYS)
821 gpio_free(host->gpio_wp); 863 gpio_free(host->gpio_wp);
864 if (host->gpio_cd_irq >= 0)
865 free_irq(host->gpio_cd_irq, host);
822 if (host->gpio_cd != -ENOSYS) 866 if (host->gpio_cd != -ENOSYS)
823 gpio_free(host->gpio_cd); 867 gpio_free(host->gpio_cd);
824 868
diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h
index 68970cfb81e1..4ae887fc0189 100644
--- a/drivers/mmc/host/mmci.h
+++ b/drivers/mmc/host/mmci.h
@@ -54,10 +54,16 @@
54#define MCI_DPSM_MODE (1 << 2) 54#define MCI_DPSM_MODE (1 << 2)
55#define MCI_DPSM_DMAENABLE (1 << 3) 55#define MCI_DPSM_DMAENABLE (1 << 3)
56#define MCI_DPSM_BLOCKSIZE (1 << 4) 56#define MCI_DPSM_BLOCKSIZE (1 << 4)
57#define MCI_DPSM_RWSTART (1 << 8) 57/* Control register extensions in the ST Micro U300 and Ux500 versions */
58#define MCI_DPSM_RWSTOP (1 << 9) 58#define MCI_ST_DPSM_RWSTART (1 << 8)
59#define MCI_DPSM_RWMOD (1 << 10) 59#define MCI_ST_DPSM_RWSTOP (1 << 9)
60#define MCI_DPSM_SDIOEN (1 << 11) 60#define MCI_ST_DPSM_RWMOD (1 << 10)
61#define MCI_ST_DPSM_SDIOEN (1 << 11)
62/* Control register extensions in the ST Micro Ux500 versions */
63#define MCI_ST_DPSM_DMAREQCTL (1 << 12)
64#define MCI_ST_DPSM_DBOOTMODEEN (1 << 13)
65#define MCI_ST_DPSM_BUSYMODE (1 << 14)
66#define MCI_ST_DPSM_DDRMODE (1 << 15)
61 67
62#define MMCIDATACNT 0x030 68#define MMCIDATACNT 0x030
63#define MMCISTATUS 0x034 69#define MMCISTATUS 0x034
@@ -133,13 +139,6 @@
133 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \ 139 MCI_DATATIMEOUTMASK|MCI_TXUNDERRUNMASK|MCI_RXOVERRUNMASK| \
134 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATABLOCKENDMASK) 140 MCI_CMDRESPENDMASK|MCI_CMDSENTMASK|MCI_DATABLOCKENDMASK)
135 141
136/*
137 * The size of the FIFO in bytes.
138 */
139#define MCI_FIFOSIZE (16*4)
140
141#define MCI_FIFOHALFSIZE (MCI_FIFOSIZE / 2)
142
143#define NR_SG 16 142#define NR_SG 16
144 143
145struct clk; 144struct clk;
@@ -154,6 +153,7 @@ struct mmci_host {
154 struct clk *clk; 153 struct clk *clk;
155 int gpio_cd; 154 int gpio_cd;
156 int gpio_wp; 155 int gpio_wp;
156 int gpio_cd_irq;
157 157
158 unsigned int data_xfered; 158 unsigned int data_xfered;
159 159
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 71ad4163b95e..aacb862ecc8a 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -241,8 +241,10 @@ static struct sdhci_ops sdhci_s3c_ops = {
241static void sdhci_s3c_notify_change(struct platform_device *dev, int state) 241static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
242{ 242{
243 struct sdhci_host *host = platform_get_drvdata(dev); 243 struct sdhci_host *host = platform_get_drvdata(dev);
244 unsigned long flags;
245
244 if (host) { 246 if (host) {
245 spin_lock(&host->lock); 247 spin_lock_irqsave(&host->lock, flags);
246 if (state) { 248 if (state) {
247 dev_dbg(&dev->dev, "card inserted.\n"); 249 dev_dbg(&dev->dev, "card inserted.\n");
248 host->flags &= ~SDHCI_DEVICE_DEAD; 250 host->flags &= ~SDHCI_DEVICE_DEAD;
@@ -253,7 +255,7 @@ static void sdhci_s3c_notify_change(struct platform_device *dev, int state)
253 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION; 255 host->quirks &= ~SDHCI_QUIRK_BROKEN_CARD_DETECTION;
254 } 256 }
255 tasklet_schedule(&host->card_tasklet); 257 tasklet_schedule(&host->card_tasklet);
256 spin_unlock(&host->lock); 258 spin_unlock_irqrestore(&host->lock, flags);
257 } 259 }
258} 260}
259 261
@@ -481,8 +483,10 @@ static int __devexit sdhci_s3c_remove(struct platform_device *pdev)
481 sdhci_remove_host(host, 1); 483 sdhci_remove_host(host, 1);
482 484
483 for (ptr = 0; ptr < 3; ptr++) { 485 for (ptr = 0; ptr < 3; ptr++) {
484 clk_disable(sc->clk_bus[ptr]); 486 if (sc->clk_bus[ptr]) {
485 clk_put(sc->clk_bus[ptr]); 487 clk_disable(sc->clk_bus[ptr]);
488 clk_put(sc->clk_bus[ptr]);
489 }
486 } 490 }
487 clk_disable(sc->clk_io); 491 clk_disable(sc->clk_io);
488 clk_put(sc->clk_io); 492 clk_put(sc->clk_io);
diff --git a/drivers/mmc/host/sdricoh_cs.c b/drivers/mmc/host/sdricoh_cs.c
index 7aa65bb2af4a..f472c2714eb8 100644
--- a/drivers/mmc/host/sdricoh_cs.c
+++ b/drivers/mmc/host/sdricoh_cs.c
@@ -30,7 +30,6 @@
30#include <linux/ioport.h> 30#include <linux/ioport.h>
31#include <linux/scatterlist.h> 31#include <linux/scatterlist.h>
32 32
33#include <pcmcia/cs.h>
34#include <pcmcia/cistpl.h> 33#include <pcmcia/cistpl.h>
35#include <pcmcia/ds.h> 34#include <pcmcia/ds.h>
36#include <linux/io.h> 35#include <linux/io.h>
@@ -536,9 +535,7 @@ static int sdricoh_pcmcia_resume(struct pcmcia_device *link)
536#endif 535#endif
537 536
538static struct pcmcia_driver sdricoh_driver = { 537static struct pcmcia_driver sdricoh_driver = {
539 .drv = { 538 .name = DRIVER_NAME,
540 .name = DRIVER_NAME,
541 },
542 .probe = sdricoh_pcmcia_probe, 539 .probe = sdricoh_pcmcia_probe,
543 .remove = sdricoh_pcmcia_detach, 540 .remove = sdricoh_pcmcia_detach,
544 .id_table = pcmcia_ids, 541 .id_table = pcmcia_ids,
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index e9ca5ba7d9d2..57a1acfe22c4 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -16,7 +16,6 @@
16#include <asm/io.h> 16#include <asm/io.h>
17#include <asm/system.h> 17#include <asm/system.h>
18 18
19#include <pcmcia/cs.h>
20#include <pcmcia/cistpl.h> 19#include <pcmcia/cistpl.h>
21#include <pcmcia/ds.h> 20#include <pcmcia/ds.h>
22 21
@@ -101,7 +100,7 @@ MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)")
101static caddr_t remap_window(struct map_info *map, unsigned long to) 100static caddr_t remap_window(struct map_info *map, unsigned long to)
102{ 101{
103 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 102 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
104 window_handle_t win = (window_handle_t)map->map_priv_2; 103 struct resource *win = (struct resource *) map->map_priv_2;
105 unsigned int offset; 104 unsigned int offset;
106 int ret; 105 int ret;
107 106
@@ -316,30 +315,19 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
316{ 315{
317 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; 316 struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
318 struct pcmcia_device *link = dev->p_dev; 317 struct pcmcia_device *link = dev->p_dev;
319 modconf_t mod;
320 int ret;
321
322 mod.Attributes = CONF_VPP1_CHANGE_VALID | CONF_VPP2_CHANGE_VALID;
323 mod.Vcc = 0;
324 mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0;
325 318
326 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); 319 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
327 ret = pcmcia_modify_configuration(link, &mod); 320 pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
328} 321}
329 322
330 323
331/* After a card is removed, pcmciamtd_release() will unregister the
332 * device, and release the PCMCIA configuration. If the device is
333 * still open, this will be postponed until it is closed.
334 */
335
336static void pcmciamtd_release(struct pcmcia_device *link) 324static void pcmciamtd_release(struct pcmcia_device *link)
337{ 325{
338 struct pcmciamtd_dev *dev = link->priv; 326 struct pcmciamtd_dev *dev = link->priv;
339 327
340 DEBUG(3, "link = 0x%p", link); 328 DEBUG(3, "link = 0x%p", link);
341 329
342 if (link->win) { 330 if (link->resource[2]->end) {
343 if(dev->win_base) { 331 if(dev->win_base) {
344 iounmap(dev->win_base); 332 iounmap(dev->win_base);
345 dev->win_base = NULL; 333 dev->win_base = NULL;
@@ -482,18 +470,12 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev
482} 470}
483 471
484 472
485/* pcmciamtd_config() is scheduled to run after a CARD_INSERTION event
486 * is received, to configure the PCMCIA socket, and to make the
487 * MTD device available to the system.
488 */
489
490static int pcmciamtd_config(struct pcmcia_device *link) 473static int pcmciamtd_config(struct pcmcia_device *link)
491{ 474{
492 struct pcmciamtd_dev *dev = link->priv; 475 struct pcmciamtd_dev *dev = link->priv;
493 struct mtd_info *mtd = NULL; 476 struct mtd_info *mtd = NULL;
494 win_req_t req;
495 int ret; 477 int ret;
496 int i; 478 int i, j = 0;
497 static char *probes[] = { "jedec_probe", "cfi_probe" }; 479 static char *probes[] = { "jedec_probe", "cfi_probe" };
498 int new_name = 0; 480 int new_name = 0;
499 481
@@ -520,28 +502,34 @@ static int pcmciamtd_config(struct pcmcia_device *link)
520 * smaller windows until we succeed 502 * smaller windows until we succeed
521 */ 503 */
522 504
523 req.Attributes = WIN_MEMORY_TYPE_CM | WIN_ENABLE; 505 link->resource[2]->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE;
524 req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; 506 link->resource[2]->flags |= (dev->pcmcia_map.bankwidth == 1) ?
525 req.Base = 0; 507 WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16;
526 req.AccessSpeed = mem_speed; 508 link->resource[2]->start = 0;
527 link->win = (window_handle_t)link; 509 link->resource[2]->end = (force_size) ? force_size << 20 :
528 req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR; 510 MAX_PCMCIA_ADDR;
529 dev->win_size = 0; 511 dev->win_size = 0;
530 512
531 do { 513 do {
532 int ret; 514 int ret;
533 DEBUG(2, "requesting window with size = %dKiB memspeed = %d", 515 DEBUG(2, "requesting window with size = %luKiB memspeed = %d",
534 req.Size >> 10, req.AccessSpeed); 516 (unsigned long) resource_size(link->resource[2]) >> 10,
535 ret = pcmcia_request_window(link, &req, &link->win); 517 mem_speed);
518 ret = pcmcia_request_window(link, link->resource[2], mem_speed);
536 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); 519 DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size);
537 if(ret) { 520 if(ret) {
538 req.Size >>= 1; 521 j++;
522 link->resource[2]->start = 0;
523 link->resource[2]->end = (force_size) ?
524 force_size << 20 : MAX_PCMCIA_ADDR;
525 link->resource[2]->end >>= j;
539 } else { 526 } else {
540 DEBUG(2, "Got window of size %dKiB", req.Size >> 10); 527 DEBUG(2, "Got window of size %luKiB", (unsigned long)
541 dev->win_size = req.Size; 528 resource_size(link->resource[2]) >> 10);
529 dev->win_size = resource_size(link->resource[2]);
542 break; 530 break;
543 } 531 }
544 } while(req.Size >= 0x1000); 532 } while (link->resource[2]->end >= 0x1000);
545 533
546 DEBUG(2, "dev->win_size = %d", dev->win_size); 534 DEBUG(2, "dev->win_size = %d", dev->win_size);
547 535
@@ -553,33 +541,31 @@ static int pcmciamtd_config(struct pcmcia_device *link)
553 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); 541 DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10);
554 542
555 /* Get write protect status */ 543 /* Get write protect status */
556 DEBUG(2, "window handle = 0x%8.8lx", (unsigned long)link->win); 544 dev->win_base = ioremap(link->resource[2]->start,
557 dev->win_base = ioremap(req.Base, req.Size); 545 resource_size(link->resource[2]));
558 if(!dev->win_base) { 546 if(!dev->win_base) {
559 dev_err(&dev->p_dev->dev, "ioremap(%lu, %u) failed\n", 547 dev_err(&dev->p_dev->dev, "ioremap(%pR) failed\n",
560 req.Base, req.Size); 548 link->resource[2]);
561 pcmciamtd_release(link); 549 pcmciamtd_release(link);
562 return -ENODEV; 550 return -ENODEV;
563 } 551 }
564 DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x", 552 DEBUG(1, "mapped window dev = %p @ %pR, base = %p",
565 dev, req.Base, dev->win_base, req.Size); 553 dev, link->resource[2], dev->win_base);
566 554
567 dev->offset = 0; 555 dev->offset = 0;
568 dev->pcmcia_map.map_priv_1 = (unsigned long)dev; 556 dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
569 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; 557 dev->pcmcia_map.map_priv_2 = (unsigned long)link->resource[2];
570 558
571 dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp; 559 dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp;
572 link->conf.Attributes = 0;
573 if(setvpp == 2) { 560 if(setvpp == 2) {
574 link->conf.Vpp = dev->vpp; 561 link->vpp = dev->vpp;
575 } else { 562 } else {
576 link->conf.Vpp = 0; 563 link->vpp = 0;
577 } 564 }
578 565
579 link->conf.IntType = INT_MEMORY; 566 link->config_index = 0;
580 link->conf.ConfigIndex = 0;
581 DEBUG(2, "Setting Configuration"); 567 DEBUG(2, "Setting Configuration");
582 ret = pcmcia_request_configuration(link, &link->conf); 568 ret = pcmcia_enable_device(link);
583 if (ret != 0) { 569 if (ret != 0) {
584 if (dev->win_base) { 570 if (dev->win_base) {
585 iounmap(dev->win_base); 571 iounmap(dev->win_base);
@@ -680,12 +666,6 @@ static int pcmciamtd_resume(struct pcmcia_device *dev)
680} 666}
681 667
682 668
683/* This deletes a driver "instance". The device is de-registered
684 * with Card Services. If it has been released, all local data
685 * structures are freed. Otherwise, the structures will be freed
686 * when the device is released.
687 */
688
689static void pcmciamtd_detach(struct pcmcia_device *link) 669static void pcmciamtd_detach(struct pcmcia_device *link)
690{ 670{
691 struct pcmciamtd_dev *dev = link->priv; 671 struct pcmciamtd_dev *dev = link->priv;
@@ -703,11 +683,6 @@ static void pcmciamtd_detach(struct pcmcia_device *link)
703} 683}
704 684
705 685
706/* pcmciamtd_attach() creates an "instance" of the driver, allocating
707 * local data structures for one device. The device is registered
708 * with Card Services.
709 */
710
711static int pcmciamtd_probe(struct pcmcia_device *link) 686static int pcmciamtd_probe(struct pcmcia_device *link)
712{ 687{
713 struct pcmciamtd_dev *dev; 688 struct pcmciamtd_dev *dev;
@@ -720,9 +695,6 @@ static int pcmciamtd_probe(struct pcmcia_device *link)
720 dev->p_dev = link; 695 dev->p_dev = link;
721 link->priv = dev; 696 link->priv = dev;
722 697
723 link->conf.Attributes = 0;
724 link->conf.IntType = INT_MEMORY;
725
726 return pcmciamtd_config(link); 698 return pcmciamtd_config(link);
727} 699}
728 700
@@ -757,9 +729,7 @@ static struct pcmcia_device_id pcmciamtd_ids[] = {
757MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids); 729MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids);
758 730
759static struct pcmcia_driver pcmciamtd_driver = { 731static struct pcmcia_driver pcmciamtd_driver = {
760 .drv = { 732 .name = "pcmciamtd",
761 .name = "pcmciamtd"
762 },
763 .probe = pcmciamtd_probe, 733 .probe = pcmciamtd_probe,
764 .remove = pcmciamtd_detach, 734 .remove = pcmciamtd_detach,
765 .owner = THIS_MODULE, 735 .owner = THIS_MODULE,
@@ -771,8 +741,6 @@ static struct pcmcia_driver pcmciamtd_driver = {
771 741
772static int __init init_pcmciamtd(void) 742static int __init init_pcmciamtd(void)
773{ 743{
774 info(DRIVER_DESC);
775
776 if(bankwidth && bankwidth != 1 && bankwidth != 2) { 744 if(bankwidth && bankwidth != 1 && bankwidth != 2) {
777 info("bad bankwidth (%d), using default", bankwidth); 745 info("bad bankwidth (%d), using default", bankwidth);
778 bankwidth = 2; 746 bankwidth = 2;
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 62e68707b07f..50ab431b24eb 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -29,7 +29,6 @@
29#include <linux/blkdev.h> 29#include <linux/blkdev.h>
30#include <linux/blkpg.h> 30#include <linux/blkpg.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/smp_lock.h>
33#include <linux/hdreg.h> 32#include <linux/hdreg.h>
34#include <linux/init.h> 33#include <linux/init.h>
35#include <linux/mutex.h> 34#include <linux/mutex.h>
@@ -38,6 +37,7 @@
38 37
39#include "mtdcore.h" 38#include "mtdcore.h"
40 39
40static DEFINE_MUTEX(mtd_blkdevs_mutex);
41static LIST_HEAD(blktrans_majors); 41static LIST_HEAD(blktrans_majors);
42static DEFINE_MUTEX(blktrans_ref_mutex); 42static DEFINE_MUTEX(blktrans_ref_mutex);
43 43
@@ -181,7 +181,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
181 if (!dev) 181 if (!dev)
182 return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ 182 return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/
183 183
184 lock_kernel(); 184 mutex_lock(&mtd_blkdevs_mutex);
185 mutex_lock(&dev->lock); 185 mutex_lock(&dev->lock);
186 186
187 if (!dev->mtd) { 187 if (!dev->mtd) {
@@ -198,7 +198,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
198unlock: 198unlock:
199 mutex_unlock(&dev->lock); 199 mutex_unlock(&dev->lock);
200 blktrans_dev_put(dev); 200 blktrans_dev_put(dev);
201 unlock_kernel(); 201 mutex_unlock(&mtd_blkdevs_mutex);
202 return ret; 202 return ret;
203} 203}
204 204
@@ -210,7 +210,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
210 if (!dev) 210 if (!dev)
211 return ret; 211 return ret;
212 212
213 lock_kernel(); 213 mutex_lock(&mtd_blkdevs_mutex);
214 mutex_lock(&dev->lock); 214 mutex_lock(&dev->lock);
215 215
216 /* Release one reference, we sure its not the last one here*/ 216 /* Release one reference, we sure its not the last one here*/
@@ -223,7 +223,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode)
223unlock: 223unlock:
224 mutex_unlock(&dev->lock); 224 mutex_unlock(&dev->lock);
225 blktrans_dev_put(dev); 225 blktrans_dev_put(dev);
226 unlock_kernel(); 226 mutex_unlock(&mtd_blkdevs_mutex);
227 return ret; 227 return ret;
228} 228}
229 229
@@ -256,7 +256,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
256 if (!dev) 256 if (!dev)
257 return ret; 257 return ret;
258 258
259 lock_kernel(); 259 mutex_lock(&mtd_blkdevs_mutex);
260 mutex_lock(&dev->lock); 260 mutex_lock(&dev->lock);
261 261
262 if (!dev->mtd) 262 if (!dev->mtd)
@@ -271,7 +271,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
271 } 271 }
272unlock: 272unlock:
273 mutex_unlock(&dev->lock); 273 mutex_unlock(&dev->lock);
274 unlock_kernel(); 274 mutex_unlock(&mtd_blkdevs_mutex);
275 blktrans_dev_put(dev); 275 blktrans_dev_put(dev);
276 return ret; 276 return ret;
277} 277}
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index a825002123c8..5ef45487b65f 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -26,7 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/smp_lock.h> 29#include <linux/mutex.h>
30#include <linux/backing-dev.h> 30#include <linux/backing-dev.h>
31#include <linux/compat.h> 31#include <linux/compat.h>
32#include <linux/mount.h> 32#include <linux/mount.h>
@@ -37,6 +37,7 @@
37#include <asm/uaccess.h> 37#include <asm/uaccess.h>
38 38
39#define MTD_INODE_FS_MAGIC 0x11307854 39#define MTD_INODE_FS_MAGIC 0x11307854
40static DEFINE_MUTEX(mtd_mutex);
40static struct vfsmount *mtd_inode_mnt __read_mostly; 41static struct vfsmount *mtd_inode_mnt __read_mostly;
41 42
42/* 43/*
@@ -90,7 +91,7 @@ static int mtd_open(struct inode *inode, struct file *file)
90 if ((file->f_mode & FMODE_WRITE) && (minor & 1)) 91 if ((file->f_mode & FMODE_WRITE) && (minor & 1))
91 return -EACCES; 92 return -EACCES;
92 93
93 lock_kernel(); 94 mutex_lock(&mtd_mutex);
94 mtd = get_mtd_device(NULL, devnum); 95 mtd = get_mtd_device(NULL, devnum);
95 96
96 if (IS_ERR(mtd)) { 97 if (IS_ERR(mtd)) {
@@ -138,7 +139,7 @@ static int mtd_open(struct inode *inode, struct file *file)
138 file->private_data = mfi; 139 file->private_data = mfi;
139 140
140out: 141out:
141 unlock_kernel(); 142 mutex_unlock(&mtd_mutex);
142 return ret; 143 return ret;
143} /* mtd_open */ 144} /* mtd_open */
144 145
@@ -866,9 +867,9 @@ static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
866{ 867{
867 int ret; 868 int ret;
868 869
869 lock_kernel(); 870 mutex_lock(&mtd_mutex);
870 ret = mtd_ioctl(file, cmd, arg); 871 ret = mtd_ioctl(file, cmd, arg);
871 unlock_kernel(); 872 mutex_unlock(&mtd_mutex);
872 873
873 return ret; 874 return ret;
874} 875}
@@ -892,7 +893,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,
892 void __user *argp = compat_ptr(arg); 893 void __user *argp = compat_ptr(arg);
893 int ret = 0; 894 int ret = 0;
894 895
895 lock_kernel(); 896 mutex_lock(&mtd_mutex);
896 897
897 switch (cmd) { 898 switch (cmd) {
898 case MEMWRITEOOB32: 899 case MEMWRITEOOB32:
@@ -927,7 +928,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd,
927 ret = mtd_ioctl(file, cmd, (unsigned long)argp); 928 ret = mtd_ioctl(file, cmd, (unsigned long)argp);
928 } 929 }
929 930
930 unlock_kernel(); 931 mutex_unlock(&mtd_mutex);
931 932
932 return ret; 933 return ret;
933} 934}
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index a382e3dd0a5d..6fbeefa3a766 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -682,7 +682,6 @@ static int __devinit bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
682static int __devexit bf5xx_nand_remove(struct platform_device *pdev) 682static int __devexit bf5xx_nand_remove(struct platform_device *pdev)
683{ 683{
684 struct bf5xx_nand_info *info = to_nand_info(pdev); 684 struct bf5xx_nand_info *info = to_nand_info(pdev);
685 struct mtd_info *mtd = NULL;
686 685
687 platform_set_drvdata(pdev, NULL); 686 platform_set_drvdata(pdev, NULL);
688 687
@@ -690,11 +689,7 @@ static int __devexit bf5xx_nand_remove(struct platform_device *pdev)
690 * and their partitions, then go through freeing the 689 * and their partitions, then go through freeing the
691 * resources used 690 * resources used
692 */ 691 */
693 mtd = &info->mtd; 692 nand_release(&info->mtd);
694 if (mtd) {
695 nand_release(mtd);
696 kfree(mtd);
697 }
698 693
699 peripheral_free_list(bfin_nfc_pin_req); 694 peripheral_free_list(bfin_nfc_pin_req);
700 bf5xx_nand_dma_remove(info); 695 bf5xx_nand_dma_remove(info);
@@ -710,7 +705,7 @@ static int bf5xx_nand_scan(struct mtd_info *mtd)
710 struct nand_chip *chip = mtd->priv; 705 struct nand_chip *chip = mtd->priv;
711 int ret; 706 int ret;
712 707
713 ret = nand_scan_ident(mtd, 1); 708 ret = nand_scan_ident(mtd, 1, NULL);
714 if (ret) 709 if (ret)
715 return ret; 710 return ret;
716 711
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index fcf8ceb277d4..214b03afdd48 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -30,6 +30,8 @@
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/irq.h>
34#include <linux/completion.h>
33 35
34#include <asm/mach/flash.h> 36#include <asm/mach/flash.h>
35#include <mach/mxc_nand.h> 37#include <mach/mxc_nand.h>
@@ -67,7 +69,9 @@
67#define NFC_V1_V2_CONFIG1_BIG (1 << 5) 69#define NFC_V1_V2_CONFIG1_BIG (1 << 5)
68#define NFC_V1_V2_CONFIG1_RST (1 << 6) 70#define NFC_V1_V2_CONFIG1_RST (1 << 6)
69#define NFC_V1_V2_CONFIG1_CE (1 << 7) 71#define NFC_V1_V2_CONFIG1_CE (1 << 7)
70#define NFC_V1_V2_CONFIG1_ONE_CYCLE (1 << 8) 72#define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
73#define NFC_V2_CONFIG1_PPB(x) (((x) & 0x3) << 9)
74#define NFC_V2_CONFIG1_FP_INT (1 << 11)
71 75
72#define NFC_V1_V2_CONFIG2_INT (1 << 15) 76#define NFC_V1_V2_CONFIG2_INT (1 << 15)
73 77
@@ -149,7 +153,7 @@ struct mxc_nand_host {
149 int irq; 153 int irq;
150 int eccsize; 154 int eccsize;
151 155
152 wait_queue_head_t irq_waitq; 156 struct completion op_completion;
153 157
154 uint8_t *data_buf; 158 uint8_t *data_buf;
155 unsigned int buf_start; 159 unsigned int buf_start;
@@ -162,6 +166,7 @@ struct mxc_nand_host {
162 void (*send_read_id)(struct mxc_nand_host *); 166 void (*send_read_id)(struct mxc_nand_host *);
163 uint16_t (*get_dev_status)(struct mxc_nand_host *); 167 uint16_t (*get_dev_status)(struct mxc_nand_host *);
164 int (*check_int)(struct mxc_nand_host *); 168 int (*check_int)(struct mxc_nand_host *);
169 void (*irq_control)(struct mxc_nand_host *, int);
165}; 170};
166 171
167/* OOB placement block for use with hardware ecc generation */ 172/* OOB placement block for use with hardware ecc generation */
@@ -214,9 +219,12 @@ static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
214{ 219{
215 struct mxc_nand_host *host = dev_id; 220 struct mxc_nand_host *host = dev_id;
216 221
217 disable_irq_nosync(irq); 222 if (!host->check_int(host))
223 return IRQ_NONE;
218 224
219 wake_up(&host->irq_waitq); 225 host->irq_control(host, 0);
226
227 complete(&host->op_completion);
220 228
221 return IRQ_HANDLED; 229 return IRQ_HANDLED;
222} 230}
@@ -243,11 +251,54 @@ static int check_int_v1_v2(struct mxc_nand_host *host)
243 if (!(tmp & NFC_V1_V2_CONFIG2_INT)) 251 if (!(tmp & NFC_V1_V2_CONFIG2_INT))
244 return 0; 252 return 0;
245 253
246 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2); 254 if (!cpu_is_mx21())
255 writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
247 256
248 return 1; 257 return 1;
249} 258}
250 259
260/*
261 * It has been observed that the i.MX21 cannot read the CONFIG2:INT bit
262 * if interrupts are masked (CONFIG1:INT_MSK is set). To handle this, the
263 * driver can enable/disable the irq line rather than simply masking the
264 * interrupts.
265 */
266static void irq_control_mx21(struct mxc_nand_host *host, int activate)
267{
268 if (activate)
269 enable_irq(host->irq);
270 else
271 disable_irq_nosync(host->irq);
272}
273
274static void irq_control_v1_v2(struct mxc_nand_host *host, int activate)
275{
276 uint16_t tmp;
277
278 tmp = readw(NFC_V1_V2_CONFIG1);
279
280 if (activate)
281 tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK;
282 else
283 tmp |= NFC_V1_V2_CONFIG1_INT_MSK;
284
285 writew(tmp, NFC_V1_V2_CONFIG1);
286}
287
288static void irq_control_v3(struct mxc_nand_host *host, int activate)
289{
290 uint32_t tmp;
291
292 tmp = readl(NFC_V3_CONFIG2);
293
294 if (activate)
295 tmp &= ~NFC_V3_CONFIG2_INT_MSK;
296 else
297 tmp |= NFC_V3_CONFIG2_INT_MSK;
298
299 writel(tmp, NFC_V3_CONFIG2);
300}
301
251/* This function polls the NANDFC to wait for the basic operation to 302/* This function polls the NANDFC to wait for the basic operation to
252 * complete by checking the INT bit of config2 register. 303 * complete by checking the INT bit of config2 register.
253 */ 304 */
@@ -257,10 +308,9 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq)
257 308
258 if (useirq) { 309 if (useirq) {
259 if (!host->check_int(host)) { 310 if (!host->check_int(host)) {
260 311 INIT_COMPLETION(host->op_completion);
261 enable_irq(host->irq); 312 host->irq_control(host, 1);
262 313 wait_for_completion(&host->op_completion);
263 wait_event(host->irq_waitq, host->check_int(host));
264 } 314 }
265 } else { 315 } else {
266 while (max_retries-- > 0) { 316 while (max_retries-- > 0) {
@@ -402,16 +452,16 @@ static void send_read_id_v1_v2(struct mxc_nand_host *host)
402 /* Wait for operation to complete */ 452 /* Wait for operation to complete */
403 wait_op_done(host, true); 453 wait_op_done(host, true);
404 454
455 memcpy(host->data_buf, host->main_area0, 16);
456
405 if (this->options & NAND_BUSWIDTH_16) { 457 if (this->options & NAND_BUSWIDTH_16) {
406 void __iomem *main_buf = host->main_area0;
407 /* compress the ID info */ 458 /* compress the ID info */
408 writeb(readb(main_buf + 2), main_buf + 1); 459 host->data_buf[1] = host->data_buf[2];
409 writeb(readb(main_buf + 4), main_buf + 2); 460 host->data_buf[2] = host->data_buf[4];
410 writeb(readb(main_buf + 6), main_buf + 3); 461 host->data_buf[3] = host->data_buf[6];
411 writeb(readb(main_buf + 8), main_buf + 4); 462 host->data_buf[4] = host->data_buf[8];
412 writeb(readb(main_buf + 10), main_buf + 5); 463 host->data_buf[5] = host->data_buf[10];
413 } 464 }
414 memcpy(host->data_buf, host->main_area0, 16);
415} 465}
416 466
417static uint16_t get_dev_status_v3(struct mxc_nand_host *host) 467static uint16_t get_dev_status_v3(struct mxc_nand_host *host)
@@ -729,27 +779,30 @@ static void preset_v1_v2(struct mtd_info *mtd)
729{ 779{
730 struct nand_chip *nand_chip = mtd->priv; 780 struct nand_chip *nand_chip = mtd->priv;
731 struct mxc_nand_host *host = nand_chip->priv; 781 struct mxc_nand_host *host = nand_chip->priv;
732 uint16_t tmp; 782 uint16_t config1 = 0;
733 783
734 /* enable interrupt, disable spare enable */ 784 if (nand_chip->ecc.mode == NAND_ECC_HW)
735 tmp = readw(NFC_V1_V2_CONFIG1); 785 config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
736 tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK; 786
737 tmp &= ~NFC_V1_V2_CONFIG1_SP_EN; 787 if (nfc_is_v21())
738 if (nand_chip->ecc.mode == NAND_ECC_HW) { 788 config1 |= NFC_V2_CONFIG1_FP_INT;
739 tmp |= NFC_V1_V2_CONFIG1_ECC_EN; 789
740 } else { 790 if (!cpu_is_mx21())
741 tmp &= ~NFC_V1_V2_CONFIG1_ECC_EN; 791 config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
742 }
743 792
744 if (nfc_is_v21() && mtd->writesize) { 793 if (nfc_is_v21() && mtd->writesize) {
794 uint16_t pages_per_block = mtd->erasesize / mtd->writesize;
795
745 host->eccsize = get_eccsize(mtd); 796 host->eccsize = get_eccsize(mtd);
746 if (host->eccsize == 4) 797 if (host->eccsize == 4)
747 tmp |= NFC_V2_CONFIG1_ECC_MODE_4; 798 config1 |= NFC_V2_CONFIG1_ECC_MODE_4;
799
800 config1 |= NFC_V2_CONFIG1_PPB(ffs(pages_per_block) - 6);
748 } else { 801 } else {
749 host->eccsize = 1; 802 host->eccsize = 1;
750 } 803 }
751 804
752 writew(tmp, NFC_V1_V2_CONFIG1); 805 writew(config1, NFC_V1_V2_CONFIG1);
753 /* preset operation */ 806 /* preset operation */
754 807
755 /* Unlock the internal RAM Buffer */ 808 /* Unlock the internal RAM Buffer */
@@ -794,6 +847,7 @@ static void preset_v3(struct mtd_info *mtd)
794 NFC_V3_CONFIG2_2CMD_PHASES | 847 NFC_V3_CONFIG2_2CMD_PHASES |
795 NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) | 848 NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) |
796 NFC_V3_CONFIG2_ST_CMD(0x70) | 849 NFC_V3_CONFIG2_ST_CMD(0x70) |
850 NFC_V3_CONFIG2_INT_MSK |
797 NFC_V3_CONFIG2_NUM_ADDR_PHASE0; 851 NFC_V3_CONFIG2_NUM_ADDR_PHASE0;
798 852
799 if (chip->ecc.mode == NAND_ECC_HW) 853 if (chip->ecc.mode == NAND_ECC_HW)
@@ -1019,6 +1073,10 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1019 host->send_read_id = send_read_id_v1_v2; 1073 host->send_read_id = send_read_id_v1_v2;
1020 host->get_dev_status = get_dev_status_v1_v2; 1074 host->get_dev_status = get_dev_status_v1_v2;
1021 host->check_int = check_int_v1_v2; 1075 host->check_int = check_int_v1_v2;
1076 if (cpu_is_mx21())
1077 host->irq_control = irq_control_mx21;
1078 else
1079 host->irq_control = irq_control_v1_v2;
1022 } 1080 }
1023 1081
1024 if (nfc_is_v21()) { 1082 if (nfc_is_v21()) {
@@ -1057,6 +1115,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1057 host->send_read_id = send_read_id_v3; 1115 host->send_read_id = send_read_id_v3;
1058 host->check_int = check_int_v3; 1116 host->check_int = check_int_v3;
1059 host->get_dev_status = get_dev_status_v3; 1117 host->get_dev_status = get_dev_status_v3;
1118 host->irq_control = irq_control_v3;
1060 oob_smallpage = &nandv2_hw_eccoob_smallpage; 1119 oob_smallpage = &nandv2_hw_eccoob_smallpage;
1061 oob_largepage = &nandv2_hw_eccoob_largepage; 1120 oob_largepage = &nandv2_hw_eccoob_largepage;
1062 } else 1121 } else
@@ -1088,14 +1147,34 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1088 this->options |= NAND_USE_FLASH_BBT; 1147 this->options |= NAND_USE_FLASH_BBT;
1089 } 1148 }
1090 1149
1091 init_waitqueue_head(&host->irq_waitq); 1150 init_completion(&host->op_completion);
1092 1151
1093 host->irq = platform_get_irq(pdev, 0); 1152 host->irq = platform_get_irq(pdev, 0);
1094 1153
1154 /*
1155 * mask the interrupt. For i.MX21 explicitely call
1156 * irq_control_v1_v2 to use the mask bit. We can't call
1157 * disable_irq_nosync() for an interrupt we do not own yet.
1158 */
1159 if (cpu_is_mx21())
1160 irq_control_v1_v2(host, 0);
1161 else
1162 host->irq_control(host, 0);
1163
1095 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host); 1164 err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host);
1096 if (err) 1165 if (err)
1097 goto eirq; 1166 goto eirq;
1098 1167
1168 host->irq_control(host, 0);
1169
1170 /*
1171 * Now that the interrupt is disabled make sure the interrupt
1172 * mask bit is cleared on i.MX21. Otherwise we can't read
1173 * the interrupt status bit on this machine.
1174 */
1175 if (cpu_is_mx21())
1176 irq_control_v1_v2(host, 1);
1177
1099 /* first scan to find the device and get the page size */ 1178 /* first scan to find the device and get the page size */
1100 if (nand_scan_ident(mtd, 1, NULL)) { 1179 if (nand_scan_ident(mtd, 1, NULL)) {
1101 err = -ENXIO; 1180 err = -ENXIO;
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 133d51528f8d..513e0a76a4a7 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -413,7 +413,7 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr,
413 prefetch_status = gpmc_read_status(GPMC_PREFETCH_COUNT); 413 prefetch_status = gpmc_read_status(GPMC_PREFETCH_COUNT);
414 } while (prefetch_status); 414 } while (prefetch_status);
415 /* disable and stop the PFPW engine */ 415 /* disable and stop the PFPW engine */
416 gpmc_prefetch_reset(); 416 gpmc_prefetch_reset(info->gpmc_cs);
417 417
418 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); 418 dma_unmap_single(&info->pdev->dev, dma_addr, len, dir);
419 return 0; 419 return 0;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 4d89f3780207..4d01cda68844 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1320,6 +1320,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1320 goto fail_free_irq; 1320 goto fail_free_irq;
1321 } 1321 }
1322 1322
1323#ifdef CONFIG_MTD_PARTITIONS
1323 if (mtd_has_cmdlinepart()) { 1324 if (mtd_has_cmdlinepart()) {
1324 static const char *probes[] = { "cmdlinepart", NULL }; 1325 static const char *probes[] = { "cmdlinepart", NULL };
1325 struct mtd_partition *parts; 1326 struct mtd_partition *parts;
@@ -1332,6 +1333,9 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1332 } 1333 }
1333 1334
1334 return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); 1335 return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
1336#else
1337 return 0;
1338#endif
1335 1339
1336fail_free_irq: 1340fail_free_irq:
1337 free_irq(irq, info); 1341 free_irq(irq, info);
@@ -1364,7 +1368,9 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1364 platform_set_drvdata(pdev, NULL); 1368 platform_set_drvdata(pdev, NULL);
1365 1369
1366 del_mtd_device(mtd); 1370 del_mtd_device(mtd);
1371#ifdef CONFIG_MTD_PARTITIONS
1367 del_mtd_partitions(mtd); 1372 del_mtd_partitions(mtd);
1373#endif
1368 irq = platform_get_irq(pdev, 0); 1374 irq = platform_get_irq(pdev, 0);
1369 if (irq >= 0) 1375 if (irq >= 0)
1370 free_irq(irq, info); 1376 free_irq(irq, info);
diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c
index cb443af3d45f..a460f1b748c2 100644
--- a/drivers/mtd/onenand/samsung.c
+++ b/drivers/mtd/onenand/samsung.c
@@ -554,14 +554,13 @@ static int s5pc110_dma_ops(void *dst, void *src, size_t count, int direction)
554 554
555 do { 555 do {
556 status = readl(base + S5PC110_DMA_TRANS_STATUS); 556 status = readl(base + S5PC110_DMA_TRANS_STATUS);
557 if (status & S5PC110_DMA_TRANS_STATUS_TE) {
558 writel(S5PC110_DMA_TRANS_CMD_TEC,
559 base + S5PC110_DMA_TRANS_CMD);
560 return -EIO;
561 }
557 } while (!(status & S5PC110_DMA_TRANS_STATUS_TD)); 562 } while (!(status & S5PC110_DMA_TRANS_STATUS_TD));
558 563
559 if (status & S5PC110_DMA_TRANS_STATUS_TE) {
560 writel(S5PC110_DMA_TRANS_CMD_TEC, base + S5PC110_DMA_TRANS_CMD);
561 writel(S5PC110_DMA_TRANS_CMD_TDC, base + S5PC110_DMA_TRANS_CMD);
562 return -EIO;
563 }
564
565 writel(S5PC110_DMA_TRANS_CMD_TDC, base + S5PC110_DMA_TRANS_CMD); 564 writel(S5PC110_DMA_TRANS_CMD_TDC, base + S5PC110_DMA_TRANS_CMD);
566 565
567 return 0; 566 return 0;
@@ -571,13 +570,12 @@ static int s5pc110_read_bufferram(struct mtd_info *mtd, int area,
571 unsigned char *buffer, int offset, size_t count) 570 unsigned char *buffer, int offset, size_t count)
572{ 571{
573 struct onenand_chip *this = mtd->priv; 572 struct onenand_chip *this = mtd->priv;
574 void __iomem *bufferram;
575 void __iomem *p; 573 void __iomem *p;
576 void *buf = (void *) buffer; 574 void *buf = (void *) buffer;
577 dma_addr_t dma_src, dma_dst; 575 dma_addr_t dma_src, dma_dst;
578 int err; 576 int err;
579 577
580 p = bufferram = this->base + area; 578 p = this->base + area;
581 if (ONENAND_CURRENT_BUFFERRAM(this)) { 579 if (ONENAND_CURRENT_BUFFERRAM(this)) {
582 if (area == ONENAND_DATARAM) 580 if (area == ONENAND_DATARAM)
583 p += this->writesize; 581 p += this->writesize;
@@ -621,7 +619,7 @@ static int s5pc110_read_bufferram(struct mtd_info *mtd, int area,
621normal: 619normal:
622 if (count != mtd->writesize) { 620 if (count != mtd->writesize) {
623 /* Copy the bufferram to memory to prevent unaligned access */ 621 /* Copy the bufferram to memory to prevent unaligned access */
624 memcpy(this->page_buf, bufferram, mtd->writesize); 622 memcpy(this->page_buf, p, mtd->writesize);
625 p = this->page_buf + offset; 623 p = this->page_buf + offset;
626 } 624 }
627 625
diff --git a/drivers/net/3c527.c b/drivers/net/3c527.c
index 70705d1306b9..eca55c52bdfd 100644
--- a/drivers/net/3c527.c
+++ b/drivers/net/3c527.c
@@ -522,7 +522,7 @@ static int __init mc32_probe1(struct net_device *dev, int slot)
522 lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */ 522 lp->tx_len = lp->exec_box->data[9]; /* Transmit list count */
523 lp->rx_len = lp->exec_box->data[11]; /* Receive list count */ 523 lp->rx_len = lp->exec_box->data[11]; /* Receive list count */
524 524
525 init_MUTEX_LOCKED(&lp->cmd_mutex); 525 sema_init(&lp->cmd_mutex, 0);
526 init_completion(&lp->execution_cmd); 526 init_completion(&lp->execution_cmd);
527 init_completion(&lp->xceiver_cmd); 527 init_completion(&lp->xceiver_cmd);
528 528
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 85671adae455..179871d9e71f 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -635,6 +635,9 @@ struct vortex_private {
635 must_free_region:1, /* Flag: if zero, Cardbus owns the I/O region */ 635 must_free_region:1, /* Flag: if zero, Cardbus owns the I/O region */
636 large_frames:1, /* accept large frames */ 636 large_frames:1, /* accept large frames */
637 handling_irq:1; /* private in_irq indicator */ 637 handling_irq:1; /* private in_irq indicator */
638 /* {get|set}_wol operations are already serialized by rtnl.
639 * no additional locking is required for the enable_wol and acpi_set_WOL()
640 */
638 int drv_flags; 641 int drv_flags;
639 u16 status_enable; 642 u16 status_enable;
640 u16 intr_enable; 643 u16 intr_enable;
@@ -2939,28 +2942,31 @@ static void vortex_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2939{ 2942{
2940 struct vortex_private *vp = netdev_priv(dev); 2943 struct vortex_private *vp = netdev_priv(dev);
2941 2944
2942 spin_lock_irq(&vp->lock); 2945 if (!VORTEX_PCI(vp))
2946 return;
2947
2943 wol->supported = WAKE_MAGIC; 2948 wol->supported = WAKE_MAGIC;
2944 2949
2945 wol->wolopts = 0; 2950 wol->wolopts = 0;
2946 if (vp->enable_wol) 2951 if (vp->enable_wol)
2947 wol->wolopts |= WAKE_MAGIC; 2952 wol->wolopts |= WAKE_MAGIC;
2948 spin_unlock_irq(&vp->lock);
2949} 2953}
2950 2954
2951static int vortex_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) 2955static int vortex_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
2952{ 2956{
2953 struct vortex_private *vp = netdev_priv(dev); 2957 struct vortex_private *vp = netdev_priv(dev);
2958
2959 if (!VORTEX_PCI(vp))
2960 return -EOPNOTSUPP;
2961
2954 if (wol->wolopts & ~WAKE_MAGIC) 2962 if (wol->wolopts & ~WAKE_MAGIC)
2955 return -EINVAL; 2963 return -EINVAL;
2956 2964
2957 spin_lock_irq(&vp->lock);
2958 if (wol->wolopts & WAKE_MAGIC) 2965 if (wol->wolopts & WAKE_MAGIC)
2959 vp->enable_wol = 1; 2966 vp->enable_wol = 1;
2960 else 2967 else
2961 vp->enable_wol = 0; 2968 vp->enable_wol = 0;
2962 acpi_set_WOL(dev); 2969 acpi_set_WOL(dev);
2963 spin_unlock_irq(&vp->lock);
2964 2970
2965 return 0; 2971 return 0;
2966} 2972}
@@ -3202,6 +3208,9 @@ static void acpi_set_WOL(struct net_device *dev)
3202 return; 3208 return;
3203 } 3209 }
3204 3210
3211 if (VORTEX_PCI(vp)->current_state < PCI_D3hot)
3212 return;
3213
3205 /* Change the power state to D3; RxEnable doesn't take effect. */ 3214 /* Change the power state to D3; RxEnable doesn't take effect. */
3206 pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot); 3215 pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
3207 } 3216 }
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 2cc81a54cbf3..77efe462b921 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2,6 +2,9 @@
2# Network device configuration 2# Network device configuration
3# 3#
4 4
5config HAVE_NET_MACB
6 bool
7
5menuconfig NETDEVICES 8menuconfig NETDEVICES
6 default y if UML 9 default y if UML
7 depends on NET 10 depends on NET
@@ -221,7 +224,7 @@ config MII
221 224
222config MACB 225config MACB
223 tristate "Atmel MACB support" 226 tristate "Atmel MACB support"
224 depends on AVR32 || ARCH_AT91SAM9260 || ARCH_AT91SAM9263 || ARCH_AT91SAM9G20 || ARCH_AT91SAM9G45 || ARCH_AT91CAP9 227 depends on HAVE_NET_MACB
225 select PHYLIB 228 select PHYLIB
226 help 229 help
227 The Atmel MACB ethernet interface is found on many AT32 and AT91 230 The Atmel MACB ethernet interface is found on many AT32 and AT91
@@ -2428,7 +2431,7 @@ config UGETH_TX_ON_DEMAND
2428 2431
2429config MV643XX_ETH 2432config MV643XX_ETH
2430 tristate "Marvell Discovery (643XX) and Orion ethernet support" 2433 tristate "Marvell Discovery (643XX) and Orion ethernet support"
2431 depends on MV64X60 || PPC32 || PLAT_ORION 2434 depends on (MV64X60 || PPC32 || PLAT_ORION) && INET
2432 select INET_LRO 2435 select INET_LRO
2433 select PHYLIB 2436 select PHYLIB
2434 help 2437 help
@@ -2803,7 +2806,7 @@ config NIU
2803 2806
2804config PASEMI_MAC 2807config PASEMI_MAC
2805 tristate "PA Semi 1/10Gbit MAC" 2808 tristate "PA Semi 1/10Gbit MAC"
2806 depends on PPC_PASEMI && PCI 2809 depends on PPC_PASEMI && PCI && INET
2807 select PHYLIB 2810 select PHYLIB
2808 select INET_LRO 2811 select INET_LRO
2809 help 2812 help
diff --git a/drivers/net/appletalk/Kconfig b/drivers/net/appletalk/Kconfig
index 0a0e0cd81a23..20f97e7017ce 100644
--- a/drivers/net/appletalk/Kconfig
+++ b/drivers/net/appletalk/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4config ATALK 4config ATALK
5 tristate "Appletalk protocol support" 5 tristate "Appletalk protocol support"
6 depends on BKL # waiting to be removed from net/appletalk/ddp.c
6 select LLC 7 select LLC
7 ---help--- 8 ---help---
8 AppleTalk is the protocol that Apple computers can use to communicate 9 AppleTalk is the protocol that Apple computers can use to communicate
diff --git a/drivers/net/atlx/atl1.c b/drivers/net/atlx/atl1.c
index 63b9ba0cc67e..c73be2848319 100644
--- a/drivers/net/atlx/atl1.c
+++ b/drivers/net/atlx/atl1.c
@@ -1251,6 +1251,12 @@ static void atl1_free_ring_resources(struct atl1_adapter *adapter)
1251 1251
1252 rrd_ring->desc = NULL; 1252 rrd_ring->desc = NULL;
1253 rrd_ring->dma = 0; 1253 rrd_ring->dma = 0;
1254
1255 adapter->cmb.dma = 0;
1256 adapter->cmb.cmb = NULL;
1257
1258 adapter->smb.dma = 0;
1259 adapter->smb.smb = NULL;
1254} 1260}
1255 1261
1256static void atl1_setup_mac_ctrl(struct atl1_adapter *adapter) 1262static void atl1_setup_mac_ctrl(struct atl1_adapter *adapter)
@@ -2847,10 +2853,11 @@ static int atl1_resume(struct pci_dev *pdev)
2847 pci_enable_wake(pdev, PCI_D3cold, 0); 2853 pci_enable_wake(pdev, PCI_D3cold, 0);
2848 2854
2849 atl1_reset_hw(&adapter->hw); 2855 atl1_reset_hw(&adapter->hw);
2850 adapter->cmb.cmb->int_stats = 0;
2851 2856
2852 if (netif_running(netdev)) 2857 if (netif_running(netdev)) {
2858 adapter->cmb.cmb->int_stats = 0;
2853 atl1_up(adapter); 2859 atl1_up(adapter);
2860 }
2854 netif_device_attach(netdev); 2861 netif_device_attach(netdev);
2855 2862
2856 return 0; 2863 return 0;
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 1e620e287ae0..efeffdf9e5fa 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -2170,8 +2170,6 @@ static int __devinit b44_init_one(struct ssb_device *sdev,
2170 dev->irq = sdev->irq; 2170 dev->irq = sdev->irq;
2171 SET_ETHTOOL_OPS(dev, &b44_ethtool_ops); 2171 SET_ETHTOOL_OPS(dev, &b44_ethtool_ops);
2172 2172
2173 netif_carrier_off(dev);
2174
2175 err = ssb_bus_powerup(sdev->bus, 0); 2173 err = ssb_bus_powerup(sdev->bus, 0);
2176 if (err) { 2174 if (err) {
2177 dev_err(sdev->dev, 2175 dev_err(sdev->dev,
@@ -2213,6 +2211,8 @@ static int __devinit b44_init_one(struct ssb_device *sdev,
2213 goto err_out_powerdown; 2211 goto err_out_powerdown;
2214 } 2212 }
2215 2213
2214 netif_carrier_off(dev);
2215
2216 ssb_set_drvdata(sdev, dev); 2216 ssb_set_drvdata(sdev, dev);
2217 2217
2218 /* Chip reset provides power to the b44 MAC & PCI cores, which 2218 /* Chip reset provides power to the b44 MAC & PCI cores, which
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 012613fde3f4..03d063554b7f 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -38,6 +38,7 @@
38#include <asm/blackfin.h> 38#include <asm/blackfin.h>
39#include <asm/cacheflush.h> 39#include <asm/cacheflush.h>
40#include <asm/portmux.h> 40#include <asm/portmux.h>
41#include <mach/pll.h>
41 42
42#include "bfin_mac.h" 43#include "bfin_mac.h"
43 44
diff --git a/drivers/net/bonding/bond_3ad.c b/drivers/net/bonding/bond_3ad.c
index 822f586d72af..0ddf4c66afe2 100644
--- a/drivers/net/bonding/bond_3ad.c
+++ b/drivers/net/bonding/bond_3ad.c
@@ -2466,6 +2466,9 @@ int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct pac
2466 if (!(dev->flags & IFF_MASTER)) 2466 if (!(dev->flags & IFF_MASTER))
2467 goto out; 2467 goto out;
2468 2468
2469 if (!pskb_may_pull(skb, sizeof(struct lacpdu)))
2470 goto out;
2471
2469 read_lock(&bond->lock); 2472 read_lock(&bond->lock);
2470 slave = bond_get_slave_by_dev((struct bonding *)netdev_priv(dev), 2473 slave = bond_get_slave_by_dev((struct bonding *)netdev_priv(dev),
2471 orig_dev); 2474 orig_dev);
diff --git a/drivers/net/bonding/bond_alb.c b/drivers/net/bonding/bond_alb.c
index c746b331771d..26bb118c4533 100644
--- a/drivers/net/bonding/bond_alb.c
+++ b/drivers/net/bonding/bond_alb.c
@@ -362,6 +362,9 @@ static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct
362 goto out; 362 goto out;
363 } 363 }
364 364
365 if (!pskb_may_pull(skb, arp_hdr_len(bond_dev)))
366 goto out;
367
365 if (skb->len < sizeof(struct arp_pkt)) { 368 if (skb->len < sizeof(struct arp_pkt)) {
366 pr_debug("Packet is too small to be an ARP\n"); 369 pr_debug("Packet is too small to be an ARP\n");
367 goto out; 370 goto out;
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 3b16f62d5606..e953c6ad6e6d 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -5164,6 +5164,15 @@ int bond_create(struct net *net, const char *name)
5164 res = dev_alloc_name(bond_dev, "bond%d"); 5164 res = dev_alloc_name(bond_dev, "bond%d");
5165 if (res < 0) 5165 if (res < 0)
5166 goto out; 5166 goto out;
5167 } else {
5168 /*
5169 * If we're given a name to register
5170 * we need to ensure that its not already
5171 * registered
5172 */
5173 res = -EEXIST;
5174 if (__dev_get_by_name(net, name) != NULL)
5175 goto out;
5167 } 5176 }
5168 5177
5169 res = register_netdevice(bond_dev); 5178 res = register_netdevice(bond_dev);
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index ad19585d960b..f208712c0b90 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -2296,6 +2296,8 @@ static int cxgb_extension_ioctl(struct net_device *dev, void __user *useraddr)
2296 case CHELSIO_GET_QSET_NUM:{ 2296 case CHELSIO_GET_QSET_NUM:{
2297 struct ch_reg edata; 2297 struct ch_reg edata;
2298 2298
2299 memset(&edata, 0, sizeof(struct ch_reg));
2300
2299 edata.cmd = CHELSIO_GET_QSET_NUM; 2301 edata.cmd = CHELSIO_GET_QSET_NUM;
2300 edata.val = pi->nqsets; 2302 edata.val = pi->nqsets;
2301 if (copy_to_user(useraddr, &edata, sizeof(edata))) 2303 if (copy_to_user(useraddr, &edata, sizeof(edata)))
diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
index 66ed08f726fb..ba302a5c2c30 100644
--- a/drivers/net/e1000e/hw.h
+++ b/drivers/net/e1000e/hw.h
@@ -57,6 +57,7 @@ enum e1e_registers {
57 E1000_SCTL = 0x00024, /* SerDes Control - RW */ 57 E1000_SCTL = 0x00024, /* SerDes Control - RW */
58 E1000_FCAL = 0x00028, /* Flow Control Address Low - RW */ 58 E1000_FCAL = 0x00028, /* Flow Control Address Low - RW */
59 E1000_FCAH = 0x0002C, /* Flow Control Address High -RW */ 59 E1000_FCAH = 0x0002C, /* Flow Control Address High -RW */
60 E1000_FEXTNVM4 = 0x00024, /* Future Extended NVM 4 - RW */
60 E1000_FEXTNVM = 0x00028, /* Future Extended NVM - RW */ 61 E1000_FEXTNVM = 0x00028, /* Future Extended NVM - RW */
61 E1000_FCT = 0x00030, /* Flow Control Type - RW */ 62 E1000_FCT = 0x00030, /* Flow Control Type - RW */
62 E1000_VET = 0x00038, /* VLAN Ether Type - RW */ 63 E1000_VET = 0x00038, /* VLAN Ether Type - RW */
diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
index 63930d12711c..57b5435599ab 100644
--- a/drivers/net/e1000e/ich8lan.c
+++ b/drivers/net/e1000e/ich8lan.c
@@ -105,6 +105,10 @@
105#define E1000_FEXTNVM_SW_CONFIG 1 105#define E1000_FEXTNVM_SW_CONFIG 1
106#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */ 106#define E1000_FEXTNVM_SW_CONFIG_ICH8M (1 << 27) /* Bit redefined for ICH8M :/ */
107 107
108#define E1000_FEXTNVM4_BEACON_DURATION_MASK 0x7
109#define E1000_FEXTNVM4_BEACON_DURATION_8USEC 0x7
110#define E1000_FEXTNVM4_BEACON_DURATION_16USEC 0x3
111
108#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL 112#define PCIE_ICH8_SNOOP_ALL PCIE_NO_SNOOP_ALL
109 113
110#define E1000_ICH_RAR_ENTRIES 7 114#define E1000_ICH_RAR_ENTRIES 7
@@ -125,6 +129,7 @@
125 129
126/* SMBus Address Phy Register */ 130/* SMBus Address Phy Register */
127#define HV_SMB_ADDR PHY_REG(768, 26) 131#define HV_SMB_ADDR PHY_REG(768, 26)
132#define HV_SMB_ADDR_MASK 0x007F
128#define HV_SMB_ADDR_PEC_EN 0x0200 133#define HV_SMB_ADDR_PEC_EN 0x0200
129#define HV_SMB_ADDR_VALID 0x0080 134#define HV_SMB_ADDR_VALID 0x0080
130 135
@@ -237,6 +242,8 @@ static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
237static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw); 242static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
238static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw); 243static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
239static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw); 244static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
245static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
246static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
240 247
241static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg) 248static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
242{ 249{
@@ -272,7 +279,7 @@ static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
272static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw) 279static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
273{ 280{
274 struct e1000_phy_info *phy = &hw->phy; 281 struct e1000_phy_info *phy = &hw->phy;
275 u32 ctrl; 282 u32 ctrl, fwsm;
276 s32 ret_val = 0; 283 s32 ret_val = 0;
277 284
278 phy->addr = 1; 285 phy->addr = 1;
@@ -294,7 +301,8 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
294 * disabled, then toggle the LANPHYPC Value bit to force 301 * disabled, then toggle the LANPHYPC Value bit to force
295 * the interconnect to PCIe mode. 302 * the interconnect to PCIe mode.
296 */ 303 */
297 if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) { 304 fwsm = er32(FWSM);
305 if (!(fwsm & E1000_ICH_FWSM_FW_VALID)) {
298 ctrl = er32(CTRL); 306 ctrl = er32(CTRL);
299 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE; 307 ctrl |= E1000_CTRL_LANPHYPC_OVERRIDE;
300 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE; 308 ctrl &= ~E1000_CTRL_LANPHYPC_VALUE;
@@ -303,6 +311,13 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
303 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE; 311 ctrl &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
304 ew32(CTRL, ctrl); 312 ew32(CTRL, ctrl);
305 msleep(50); 313 msleep(50);
314
315 /*
316 * Gate automatic PHY configuration by hardware on
317 * non-managed 82579
318 */
319 if (hw->mac.type == e1000_pch2lan)
320 e1000_gate_hw_phy_config_ich8lan(hw, true);
306 } 321 }
307 322
308 /* 323 /*
@@ -315,6 +330,13 @@ static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
315 if (ret_val) 330 if (ret_val)
316 goto out; 331 goto out;
317 332
333 /* Ungate automatic PHY configuration on non-managed 82579 */
334 if ((hw->mac.type == e1000_pch2lan) &&
335 !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
336 msleep(10);
337 e1000_gate_hw_phy_config_ich8lan(hw, false);
338 }
339
318 phy->id = e1000_phy_unknown; 340 phy->id = e1000_phy_unknown;
319 ret_val = e1000e_get_phy_id(hw); 341 ret_val = e1000e_get_phy_id(hw);
320 if (ret_val) 342 if (ret_val)
@@ -561,13 +583,10 @@ static s32 e1000_init_mac_params_ich8lan(struct e1000_adapter *adapter)
561 if (mac->type == e1000_ich8lan) 583 if (mac->type == e1000_ich8lan)
562 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true); 584 e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
563 585
564 /* Disable PHY configuration by hardware, config by software */ 586 /* Gate automatic PHY configuration by hardware on managed 82579 */
565 if (mac->type == e1000_pch2lan) { 587 if ((mac->type == e1000_pch2lan) &&
566 u32 extcnf_ctrl = er32(EXTCNF_CTRL); 588 (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
567 589 e1000_gate_hw_phy_config_ich8lan(hw, true);
568 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
569 ew32(EXTCNF_CTRL, extcnf_ctrl);
570 }
571 590
572 return 0; 591 return 0;
573} 592}
@@ -652,6 +671,12 @@ static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
652 goto out; 671 goto out;
653 } 672 }
654 673
674 if (hw->mac.type == e1000_pch2lan) {
675 ret_val = e1000_k1_workaround_lv(hw);
676 if (ret_val)
677 goto out;
678 }
679
655 /* 680 /*
656 * Check if there was DownShift, must be checked 681 * Check if there was DownShift, must be checked
657 * immediately after link-up 682 * immediately after link-up
@@ -895,6 +920,34 @@ static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
895} 920}
896 921
897/** 922/**
923 * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
924 * @hw: pointer to the HW structure
925 *
926 * Assumes semaphore already acquired.
927 *
928 **/
929static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
930{
931 u16 phy_data;
932 u32 strap = er32(STRAP);
933 s32 ret_val = 0;
934
935 strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
936
937 ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
938 if (ret_val)
939 goto out;
940
941 phy_data &= ~HV_SMB_ADDR_MASK;
942 phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
943 phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
944 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
945
946out:
947 return ret_val;
948}
949
950/**
898 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration 951 * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
899 * @hw: pointer to the HW structure 952 * @hw: pointer to the HW structure
900 * 953 *
@@ -903,7 +956,6 @@ static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
903 **/ 956 **/
904static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw) 957static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
905{ 958{
906 struct e1000_adapter *adapter = hw->adapter;
907 struct e1000_phy_info *phy = &hw->phy; 959 struct e1000_phy_info *phy = &hw->phy;
908 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask; 960 u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
909 s32 ret_val = 0; 961 s32 ret_val = 0;
@@ -921,7 +973,8 @@ static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
921 if (phy->type != e1000_phy_igp_3) 973 if (phy->type != e1000_phy_igp_3)
922 return ret_val; 974 return ret_val;
923 975
924 if (adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) { 976 if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
977 (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
925 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG; 978 sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
926 break; 979 break;
927 } 980 }
@@ -961,21 +1014,16 @@ static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
961 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK; 1014 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
962 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT; 1015 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
963 1016
964 if (!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) && 1017 if ((!(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE) &&
965 ((hw->mac.type == e1000_pchlan) || 1018 (hw->mac.type == e1000_pchlan)) ||
966 (hw->mac.type == e1000_pch2lan))) { 1019 (hw->mac.type == e1000_pch2lan)) {
967 /* 1020 /*
968 * HW configures the SMBus address and LEDs when the 1021 * HW configures the SMBus address and LEDs when the
969 * OEM and LCD Write Enable bits are set in the NVM. 1022 * OEM and LCD Write Enable bits are set in the NVM.
970 * When both NVM bits are cleared, SW will configure 1023 * When both NVM bits are cleared, SW will configure
971 * them instead. 1024 * them instead.
972 */ 1025 */
973 data = er32(STRAP); 1026 ret_val = e1000_write_smbus_addr(hw);
974 data &= E1000_STRAP_SMBUS_ADDRESS_MASK;
975 reg_data = data >> E1000_STRAP_SMBUS_ADDRESS_SHIFT;
976 reg_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
977 ret_val = e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR,
978 reg_data);
979 if (ret_val) 1027 if (ret_val)
980 goto out; 1028 goto out;
981 1029
@@ -1440,10 +1488,6 @@ s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1440 goto out; 1488 goto out;
1441 1489
1442 /* Enable jumbo frame workaround in the PHY */ 1490 /* Enable jumbo frame workaround in the PHY */
1443 e1e_rphy(hw, PHY_REG(769, 20), &data);
1444 ret_val = e1e_wphy(hw, PHY_REG(769, 20), data & ~(1 << 14));
1445 if (ret_val)
1446 goto out;
1447 e1e_rphy(hw, PHY_REG(769, 23), &data); 1491 e1e_rphy(hw, PHY_REG(769, 23), &data);
1448 data &= ~(0x7F << 5); 1492 data &= ~(0x7F << 5);
1449 data |= (0x37 << 5); 1493 data |= (0x37 << 5);
@@ -1452,7 +1496,6 @@ s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1452 goto out; 1496 goto out;
1453 e1e_rphy(hw, PHY_REG(769, 16), &data); 1497 e1e_rphy(hw, PHY_REG(769, 16), &data);
1454 data &= ~(1 << 13); 1498 data &= ~(1 << 13);
1455 data |= (1 << 12);
1456 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data); 1499 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1457 if (ret_val) 1500 if (ret_val)
1458 goto out; 1501 goto out;
@@ -1477,7 +1520,7 @@ s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1477 1520
1478 mac_reg = er32(RCTL); 1521 mac_reg = er32(RCTL);
1479 mac_reg &= ~E1000_RCTL_SECRC; 1522 mac_reg &= ~E1000_RCTL_SECRC;
1480 ew32(FFLT_DBG, mac_reg); 1523 ew32(RCTL, mac_reg);
1481 1524
1482 ret_val = e1000e_read_kmrn_reg(hw, 1525 ret_val = e1000e_read_kmrn_reg(hw,
1483 E1000_KMRNCTRLSTA_CTRL_OFFSET, 1526 E1000_KMRNCTRLSTA_CTRL_OFFSET,
@@ -1503,17 +1546,12 @@ s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
1503 goto out; 1546 goto out;
1504 1547
1505 /* Write PHY register values back to h/w defaults */ 1548 /* Write PHY register values back to h/w defaults */
1506 e1e_rphy(hw, PHY_REG(769, 20), &data);
1507 ret_val = e1e_wphy(hw, PHY_REG(769, 20), data & ~(1 << 14));
1508 if (ret_val)
1509 goto out;
1510 e1e_rphy(hw, PHY_REG(769, 23), &data); 1549 e1e_rphy(hw, PHY_REG(769, 23), &data);
1511 data &= ~(0x7F << 5); 1550 data &= ~(0x7F << 5);
1512 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data); 1551 ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
1513 if (ret_val) 1552 if (ret_val)
1514 goto out; 1553 goto out;
1515 e1e_rphy(hw, PHY_REG(769, 16), &data); 1554 e1e_rphy(hw, PHY_REG(769, 16), &data);
1516 data &= ~(1 << 12);
1517 data |= (1 << 13); 1555 data |= (1 << 13);
1518 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data); 1556 ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
1519 if (ret_val) 1557 if (ret_val)
@@ -1559,6 +1597,69 @@ out:
1559} 1597}
1560 1598
1561/** 1599/**
1600 * e1000_k1_gig_workaround_lv - K1 Si workaround
1601 * @hw: pointer to the HW structure
1602 *
1603 * Workaround to set the K1 beacon duration for 82579 parts
1604 **/
1605static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
1606{
1607 s32 ret_val = 0;
1608 u16 status_reg = 0;
1609 u32 mac_reg;
1610
1611 if (hw->mac.type != e1000_pch2lan)
1612 goto out;
1613
1614 /* Set K1 beacon duration based on 1Gbps speed or otherwise */
1615 ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
1616 if (ret_val)
1617 goto out;
1618
1619 if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
1620 == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
1621 mac_reg = er32(FEXTNVM4);
1622 mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
1623
1624 if (status_reg & HV_M_STATUS_SPEED_1000)
1625 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_8USEC;
1626 else
1627 mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
1628
1629 ew32(FEXTNVM4, mac_reg);
1630 }
1631
1632out:
1633 return ret_val;
1634}
1635
1636/**
1637 * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
1638 * @hw: pointer to the HW structure
1639 * @gate: boolean set to true to gate, false to ungate
1640 *
1641 * Gate/ungate the automatic PHY configuration via hardware; perform
1642 * the configuration via software instead.
1643 **/
1644static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
1645{
1646 u32 extcnf_ctrl;
1647
1648 if (hw->mac.type != e1000_pch2lan)
1649 return;
1650
1651 extcnf_ctrl = er32(EXTCNF_CTRL);
1652
1653 if (gate)
1654 extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1655 else
1656 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
1657
1658 ew32(EXTCNF_CTRL, extcnf_ctrl);
1659 return;
1660}
1661
1662/**
1562 * e1000_lan_init_done_ich8lan - Check for PHY config completion 1663 * e1000_lan_init_done_ich8lan - Check for PHY config completion
1563 * @hw: pointer to the HW structure 1664 * @hw: pointer to the HW structure
1564 * 1665 *
@@ -1602,6 +1703,9 @@ static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
1602 if (e1000_check_reset_block(hw)) 1703 if (e1000_check_reset_block(hw))
1603 goto out; 1704 goto out;
1604 1705
1706 /* Allow time for h/w to get to quiescent state after reset */
1707 msleep(10);
1708
1605 /* Perform any necessary post-reset workarounds */ 1709 /* Perform any necessary post-reset workarounds */
1606 switch (hw->mac.type) { 1710 switch (hw->mac.type) {
1607 case e1000_pchlan: 1711 case e1000_pchlan:
@@ -1630,6 +1734,13 @@ static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
1630 /* Configure the LCD with the OEM bits in NVM */ 1734 /* Configure the LCD with the OEM bits in NVM */
1631 ret_val = e1000_oem_bits_config_ich8lan(hw, true); 1735 ret_val = e1000_oem_bits_config_ich8lan(hw, true);
1632 1736
1737 /* Ungate automatic PHY configuration on non-managed 82579 */
1738 if ((hw->mac.type == e1000_pch2lan) &&
1739 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
1740 msleep(10);
1741 e1000_gate_hw_phy_config_ich8lan(hw, false);
1742 }
1743
1633out: 1744out:
1634 return ret_val; 1745 return ret_val;
1635} 1746}
@@ -1646,6 +1757,11 @@ static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
1646{ 1757{
1647 s32 ret_val = 0; 1758 s32 ret_val = 0;
1648 1759
1760 /* Gate automatic PHY configuration by hardware on non-managed 82579 */
1761 if ((hw->mac.type == e1000_pch2lan) &&
1762 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
1763 e1000_gate_hw_phy_config_ich8lan(hw, true);
1764
1649 ret_val = e1000e_phy_hw_reset_generic(hw); 1765 ret_val = e1000e_phy_hw_reset_generic(hw);
1650 if (ret_val) 1766 if (ret_val)
1651 goto out; 1767 goto out;
@@ -2910,6 +3026,14 @@ static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
2910 * external PHY is reset. 3026 * external PHY is reset.
2911 */ 3027 */
2912 ctrl |= E1000_CTRL_PHY_RST; 3028 ctrl |= E1000_CTRL_PHY_RST;
3029
3030 /*
3031 * Gate automatic PHY configuration by hardware on
3032 * non-managed 82579
3033 */
3034 if ((hw->mac.type == e1000_pch2lan) &&
3035 !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
3036 e1000_gate_hw_phy_config_ich8lan(hw, true);
2913 } 3037 }
2914 ret_val = e1000_acquire_swflag_ich8lan(hw); 3038 ret_val = e1000_acquire_swflag_ich8lan(hw);
2915 e_dbg("Issuing a global reset to ich8lan\n"); 3039 e_dbg("Issuing a global reset to ich8lan\n");
@@ -3460,13 +3584,20 @@ void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
3460void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw) 3584void e1000e_disable_gig_wol_ich8lan(struct e1000_hw *hw)
3461{ 3585{
3462 u32 phy_ctrl; 3586 u32 phy_ctrl;
3587 s32 ret_val;
3463 3588
3464 phy_ctrl = er32(PHY_CTRL); 3589 phy_ctrl = er32(PHY_CTRL);
3465 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU | E1000_PHY_CTRL_GBE_DISABLE; 3590 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU | E1000_PHY_CTRL_GBE_DISABLE;
3466 ew32(PHY_CTRL, phy_ctrl); 3591 ew32(PHY_CTRL, phy_ctrl);
3467 3592
3468 if (hw->mac.type >= e1000_pchlan) 3593 if (hw->mac.type >= e1000_pchlan) {
3469 e1000_phy_hw_reset_ich8lan(hw); 3594 e1000_oem_bits_config_ich8lan(hw, true);
3595 ret_val = hw->phy.ops.acquire(hw);
3596 if (ret_val)
3597 return;
3598 e1000_write_smbus_addr(hw);
3599 hw->phy.ops.release(hw);
3600 }
3470} 3601}
3471 3602
3472/** 3603/**
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 2b8ef44bd2b1..e561d15c3eb1 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -2704,6 +2704,16 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
2704 u32 psrctl = 0; 2704 u32 psrctl = 0;
2705 u32 pages = 0; 2705 u32 pages = 0;
2706 2706
2707 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2708 if (hw->mac.type == e1000_pch2lan) {
2709 s32 ret_val;
2710
2711 if (adapter->netdev->mtu > ETH_DATA_LEN)
2712 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2713 else
2714 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2715 }
2716
2707 /* Program MC offset vector base */ 2717 /* Program MC offset vector base */
2708 rctl = er32(RCTL); 2718 rctl = er32(RCTL);
2709 rctl &= ~(3 << E1000_RCTL_MO_SHIFT); 2719 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
@@ -2744,16 +2754,6 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
2744 e1e_wphy(hw, 22, phy_data); 2754 e1e_wphy(hw, 22, phy_data);
2745 } 2755 }
2746 2756
2747 /* Workaround Si errata on 82579 - configure jumbo frame flow */
2748 if (hw->mac.type == e1000_pch2lan) {
2749 s32 ret_val;
2750
2751 if (rctl & E1000_RCTL_LPE)
2752 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
2753 else
2754 ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
2755 }
2756
2757 /* Setup buffer sizes */ 2757 /* Setup buffer sizes */
2758 rctl &= ~E1000_RCTL_SZ_4096; 2758 rctl &= ~E1000_RCTL_SZ_4096;
2759 rctl |= E1000_RCTL_BSEX; 2759 rctl |= E1000_RCTL_BSEX;
@@ -4833,6 +4833,15 @@ static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
4833 return -EINVAL; 4833 return -EINVAL;
4834 } 4834 }
4835 4835
4836 /* Jumbo frame workaround on 82579 requires CRC be stripped */
4837 if ((adapter->hw.mac.type == e1000_pch2lan) &&
4838 !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
4839 (new_mtu > ETH_DATA_LEN)) {
4840 e_err("Jumbo Frames not supported on 82579 when CRC "
4841 "stripping is disabled.\n");
4842 return -EINVAL;
4843 }
4844
4836 /* 82573 Errata 17 */ 4845 /* 82573 Errata 17 */
4837 if (((adapter->hw.mac.type == e1000_82573) || 4846 if (((adapter->hw.mac.type == e1000_82573) ||
4838 (adapter->hw.mac.type == e1000_82574)) && 4847 (adapter->hw.mac.type == e1000_82574)) &&
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index a333b42111b8..6372610ed240 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -533,8 +533,15 @@ static inline void ehea_fill_skb(struct net_device *dev,
533 int length = cqe->num_bytes_transfered - 4; /*remove CRC */ 533 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
534 534
535 skb_put(skb, length); 535 skb_put(skb, length);
536 skb->ip_summed = CHECKSUM_UNNECESSARY;
537 skb->protocol = eth_type_trans(skb, dev); 536 skb->protocol = eth_type_trans(skb, dev);
537
538 /* The packet was not an IPV4 packet so a complemented checksum was
539 calculated. The value is found in the Internet Checksum field. */
540 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
541 skb->ip_summed = CHECKSUM_COMPLETE;
542 skb->csum = csum_unfold(~cqe->inet_checksum_value);
543 } else
544 skb->ip_summed = CHECKSUM_UNNECESSARY;
538} 545}
539 546
540static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array, 547static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
diff --git a/drivers/net/ehea/ehea_qmr.h b/drivers/net/ehea/ehea_qmr.h
index f608a6c54af5..38104734a3be 100644
--- a/drivers/net/ehea/ehea_qmr.h
+++ b/drivers/net/ehea/ehea_qmr.h
@@ -150,6 +150,7 @@ struct ehea_rwqe {
150#define EHEA_CQE_TYPE_RQ 0x60 150#define EHEA_CQE_TYPE_RQ 0x60
151#define EHEA_CQE_STAT_ERR_MASK 0x700F 151#define EHEA_CQE_STAT_ERR_MASK 0x700F
152#define EHEA_CQE_STAT_FAT_ERR_MASK 0xF 152#define EHEA_CQE_STAT_FAT_ERR_MASK 0xF
153#define EHEA_CQE_BLIND_CKSUM 0x8000
153#define EHEA_CQE_STAT_ERR_TCP 0x4000 154#define EHEA_CQE_STAT_ERR_TCP 0x4000
154#define EHEA_CQE_STAT_ERR_IP 0x2000 155#define EHEA_CQE_STAT_ERR_IP 0x2000
155#define EHEA_CQE_STAT_ERR_CRC 0x1000 156#define EHEA_CQE_STAT_ERR_CRC 0x1000
diff --git a/drivers/net/eql.c b/drivers/net/eql.c
index dda2c7944da9..0cb1cf9cf4b0 100644
--- a/drivers/net/eql.c
+++ b/drivers/net/eql.c
@@ -555,6 +555,8 @@ static int eql_g_master_cfg(struct net_device *dev, master_config_t __user *mcp)
555 equalizer_t *eql; 555 equalizer_t *eql;
556 master_config_t mc; 556 master_config_t mc;
557 557
558 memset(&mc, 0, sizeof(master_config_t));
559
558 if (eql_is_master(dev)) { 560 if (eql_is_master(dev)) {
559 eql = netdev_priv(dev); 561 eql = netdev_priv(dev);
560 mc.max_slaves = eql->max_slaves; 562 mc.max_slaves = eql->max_slaves;
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 768b840aeb6b..cce32d43175f 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -678,24 +678,37 @@ static int fec_enet_mii_probe(struct net_device *dev)
678{ 678{
679 struct fec_enet_private *fep = netdev_priv(dev); 679 struct fec_enet_private *fep = netdev_priv(dev);
680 struct phy_device *phy_dev = NULL; 680 struct phy_device *phy_dev = NULL;
681 int ret; 681 char mdio_bus_id[MII_BUS_ID_SIZE];
682 char phy_name[MII_BUS_ID_SIZE + 3];
683 int phy_id;
682 684
683 fep->phy_dev = NULL; 685 fep->phy_dev = NULL;
684 686
685 /* find the first phy */ 687 /* check for attached phy */
686 phy_dev = phy_find_first(fep->mii_bus); 688 for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) {
687 if (!phy_dev) { 689 if ((fep->mii_bus->phy_mask & (1 << phy_id)))
688 printk(KERN_ERR "%s: no PHY found\n", dev->name); 690 continue;
689 return -ENODEV; 691 if (fep->mii_bus->phy_map[phy_id] == NULL)
692 continue;
693 if (fep->mii_bus->phy_map[phy_id]->phy_id == 0)
694 continue;
695 strncpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE);
696 break;
690 } 697 }
691 698
692 /* attach the mac to the phy */ 699 if (phy_id >= PHY_MAX_ADDR) {
693 ret = phy_connect_direct(dev, phy_dev, 700 printk(KERN_INFO "%s: no PHY, assuming direct connection "
694 &fec_enet_adjust_link, 0, 701 "to switch\n", dev->name);
695 PHY_INTERFACE_MODE_MII); 702 strncpy(mdio_bus_id, "0", MII_BUS_ID_SIZE);
696 if (ret) { 703 phy_id = 0;
697 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); 704 }
698 return ret; 705
706 snprintf(phy_name, MII_BUS_ID_SIZE, PHY_ID_FMT, mdio_bus_id, phy_id);
707 phy_dev = phy_connect(dev, phy_name, &fec_enet_adjust_link, 0,
708 PHY_INTERFACE_MODE_MII);
709 if (IS_ERR(phy_dev)) {
710 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name);
711 return PTR_ERR(phy_dev);
699 } 712 }
700 713
701 /* mask with MAC supported features */ 714 /* mask with MAC supported features */
@@ -738,7 +751,7 @@ static int fec_enet_mii_init(struct platform_device *pdev)
738 fep->mii_bus->read = fec_enet_mdio_read; 751 fep->mii_bus->read = fec_enet_mdio_read;
739 fep->mii_bus->write = fec_enet_mdio_write; 752 fep->mii_bus->write = fec_enet_mdio_write;
740 fep->mii_bus->reset = fec_enet_mdio_reset; 753 fep->mii_bus->reset = fec_enet_mdio_reset;
741 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); 754 snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id + 1);
742 fep->mii_bus->priv = fep; 755 fep->mii_bus->priv = fep;
743 fep->mii_bus->parent = &pdev->dev; 756 fep->mii_bus->parent = &pdev->dev;
744 757
@@ -1311,6 +1324,9 @@ fec_probe(struct platform_device *pdev)
1311 if (ret) 1324 if (ret)
1312 goto failed_mii_init; 1325 goto failed_mii_init;
1313 1326
1327 /* Carrier starts down, phylib will bring it up */
1328 netif_carrier_off(ndev);
1329
1314 ret = register_netdev(ndev); 1330 ret = register_netdev(ndev);
1315 if (ret) 1331 if (ret)
1316 goto failed_register; 1332 goto failed_register;
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 4b52c767ad05..3e5d0b6b6516 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -608,7 +608,7 @@ static int sixpack_open(struct tty_struct *tty)
608 608
609 spin_lock_init(&sp->lock); 609 spin_lock_init(&sp->lock);
610 atomic_set(&sp->refcnt, 1); 610 atomic_set(&sp->refcnt, 1);
611 init_MUTEX_LOCKED(&sp->dead_sem); 611 sema_init(&sp->dead_sem, 0);
612 612
613 /* !!! length of the buffers. MTU is IP MTU, not PACLEN! */ 613 /* !!! length of the buffers. MTU is IP MTU, not PACLEN! */
614 614
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 66e88bd59caa..4c628393c8b1 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -747,7 +747,7 @@ static int mkiss_open(struct tty_struct *tty)
747 747
748 spin_lock_init(&ax->buflock); 748 spin_lock_init(&ax->buflock);
749 atomic_set(&ax->refcnt, 1); 749 atomic_set(&ax->refcnt, 1);
750 init_MUTEX_LOCKED(&ax->dead_sem); 750 sema_init(&ax->dead_sem, 0);
751 751
752 ax->tty = tty; 752 ax->tty = tty;
753 tty->disc_data = ax; 753 tty->disc_data = ax;
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 3506fd6ad726..519e19e23955 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -2928,7 +2928,7 @@ static int __devinit emac_probe(struct platform_device *ofdev,
2928 if (dev->emac_irq != NO_IRQ) 2928 if (dev->emac_irq != NO_IRQ)
2929 irq_dispose_mapping(dev->emac_irq); 2929 irq_dispose_mapping(dev->emac_irq);
2930 err_free: 2930 err_free:
2931 kfree(ndev); 2931 free_netdev(ndev);
2932 err_gone: 2932 err_gone:
2933 /* if we were on the bootlist, remove us as we won't show up and 2933 /* if we were on the bootlist, remove us as we won't show up and
2934 * wake up all waiters to notify them in case they were waiting 2934 * wake up all waiters to notify them in case they were waiting
@@ -2971,7 +2971,7 @@ static int __devexit emac_remove(struct platform_device *ofdev)
2971 if (dev->emac_irq != NO_IRQ) 2971 if (dev->emac_irq != NO_IRQ)
2972 irq_dispose_mapping(dev->emac_irq); 2972 irq_dispose_mapping(dev->emac_irq);
2973 2973
2974 kfree(dev->ndev); 2974 free_netdev(dev->ndev);
2975 2975
2976 return 0; 2976 return 0;
2977} 2977}
diff --git a/drivers/net/irda/sir_dev.c b/drivers/net/irda/sir_dev.c
index 1b051dab7b29..51d74447f8f8 100644
--- a/drivers/net/irda/sir_dev.c
+++ b/drivers/net/irda/sir_dev.c
@@ -909,7 +909,7 @@ struct sir_dev * sirdev_get_instance(const struct sir_driver *drv, const char *n
909 dev->tx_skb = NULL; 909 dev->tx_skb = NULL;
910 910
911 spin_lock_init(&dev->tx_lock); 911 spin_lock_init(&dev->tx_lock);
912 init_MUTEX(&dev->fsm.sem); 912 sema_init(&dev->fsm.sem, 1);
913 913
914 dev->drv = drv; 914 dev->drv = drv;
915 dev->netdev = ndev; 915 dev->netdev = ndev;
diff --git a/drivers/net/ll_temac_main.c b/drivers/net/ll_temac_main.c
index bdf2149e5296..87f0a93b165c 100644
--- a/drivers/net/ll_temac_main.c
+++ b/drivers/net/ll_temac_main.c
@@ -38,6 +38,7 @@
38#include <linux/of_device.h> 38#include <linux/of_device.h>
39#include <linux/of_mdio.h> 39#include <linux/of_mdio.h>
40#include <linux/of_platform.h> 40#include <linux/of_platform.h>
41#include <linux/of_address.h>
41#include <linux/skbuff.h> 42#include <linux/skbuff.h>
42#include <linux/spinlock.h> 43#include <linux/spinlock.h>
43#include <linux/tcp.h> /* needed for sizeof(tcphdr) */ 44#include <linux/tcp.h> /* needed for sizeof(tcphdr) */
diff --git a/drivers/net/ll_temac_mdio.c b/drivers/net/ll_temac_mdio.c
index 5ae28c975b38..8cf9d4f56bb2 100644
--- a/drivers/net/ll_temac_mdio.c
+++ b/drivers/net/ll_temac_mdio.c
@@ -10,6 +10,7 @@
10#include <linux/phy.h> 10#include <linux/phy.h>
11#include <linux/of.h> 11#include <linux/of.h>
12#include <linux/of_device.h> 12#include <linux/of_device.h>
13#include <linux/of_address.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/of_mdio.h> 15#include <linux/of_mdio.h>
15 16
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index cabae7bb1fc6..b075a35b85d4 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -1540,7 +1540,6 @@ netxen_process_rcv(struct netxen_adapter *adapter,
1540 if (pkt_offset) 1540 if (pkt_offset)
1541 skb_pull(skb, pkt_offset); 1541 skb_pull(skb, pkt_offset);
1542 1542
1543 skb->truesize = skb->len + sizeof(struct sk_buff);
1544 skb->protocol = eth_type_trans(skb, netdev); 1543 skb->protocol = eth_type_trans(skb, netdev);
1545 1544
1546 napi_gro_receive(&sds_ring->napi, skb); 1545 napi_gro_receive(&sds_ring->napi, skb);
@@ -1602,8 +1601,6 @@ netxen_process_lro(struct netxen_adapter *adapter,
1602 1601
1603 skb_put(skb, lro_length + data_offset); 1602 skb_put(skb, lro_length + data_offset);
1604 1603
1605 skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb);
1606
1607 skb_pull(skb, l2_hdr_offset); 1604 skb_pull(skb, l2_hdr_offset);
1608 skb->protocol = eth_type_trans(skb, netdev); 1605 skb->protocol = eth_type_trans(skb, netdev);
1609 1606
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index c683f77c6f42..ff824e11f0b6 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -87,7 +87,6 @@ earlier 3Com products.
87#include <linux/bitops.h> 87#include <linux/bitops.h>
88#include <linux/mii.h> 88#include <linux/mii.h>
89 89
90#include <pcmcia/cs.h>
91#include <pcmcia/cistpl.h> 90#include <pcmcia/cistpl.h>
92#include <pcmcia/cisreg.h> 91#include <pcmcia/cisreg.h>
93#include <pcmcia/ciscode.h> 92#include <pcmcia/ciscode.h>
@@ -280,25 +279,15 @@ static int tc574_probe(struct pcmcia_device *link)
280 spin_lock_init(&lp->window_lock); 279 spin_lock_init(&lp->window_lock);
281 link->resource[0]->end = 32; 280 link->resource[0]->end = 32;
282 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 281 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
283 link->conf.Attributes = CONF_ENABLE_IRQ; 282 link->config_flags |= CONF_ENABLE_IRQ;
284 link->conf.IntType = INT_MEMORY_AND_IO; 283 link->config_index = 1;
285 link->conf.ConfigIndex = 1;
286 284
287 dev->netdev_ops = &el3_netdev_ops; 285 dev->netdev_ops = &el3_netdev_ops;
288 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 286 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
289 dev->watchdog_timeo = TX_TIMEOUT; 287 dev->watchdog_timeo = TX_TIMEOUT;
290 288
291 return tc574_config(link); 289 return tc574_config(link);
292} /* tc574_attach */ 290}
293
294/*
295
296 This deletes a driver "instance". The device is de-registered
297 with Card Services. If it has been released, all local data
298 structures are freed. Otherwise, the structures will be freed
299 when the device is released.
300
301*/
302 291
303static void tc574_detach(struct pcmcia_device *link) 292static void tc574_detach(struct pcmcia_device *link)
304{ 293{
@@ -313,12 +302,6 @@ static void tc574_detach(struct pcmcia_device *link)
313 free_netdev(dev); 302 free_netdev(dev);
314} /* tc574_detach */ 303} /* tc574_detach */
315 304
316/*
317 tc574_config() is scheduled to run after a CARD_INSERTION event
318 is received, to configure the PCMCIA socket, and to make the
319 ethernet device available to the system.
320*/
321
322static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"}; 305static const char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
323 306
324static int tc574_config(struct pcmcia_device *link) 307static int tc574_config(struct pcmcia_device *link)
@@ -352,7 +335,7 @@ static int tc574_config(struct pcmcia_device *link)
352 if (ret) 335 if (ret)
353 goto failed; 336 goto failed;
354 337
355 ret = pcmcia_request_configuration(link, &link->conf); 338 ret = pcmcia_enable_device(link);
356 if (ret) 339 if (ret)
357 goto failed; 340 goto failed;
358 341
@@ -465,12 +448,6 @@ failed:
465 448
466} /* tc574_config */ 449} /* tc574_config */
467 450
468/*
469 After a card is removed, tc574_release() will unregister the net
470 device, and release the PCMCIA configuration. If the device is
471 still open, this will be postponed until it is closed.
472*/
473
474static void tc574_release(struct pcmcia_device *link) 451static void tc574_release(struct pcmcia_device *link)
475{ 452{
476 pcmcia_disable_device(link); 453 pcmcia_disable_device(link);
@@ -1198,9 +1175,7 @@ MODULE_DEVICE_TABLE(pcmcia, tc574_ids);
1198 1175
1199static struct pcmcia_driver tc574_driver = { 1176static struct pcmcia_driver tc574_driver = {
1200 .owner = THIS_MODULE, 1177 .owner = THIS_MODULE,
1201 .drv = { 1178 .name = "3c574_cs",
1202 .name = "3c574_cs",
1203 },
1204 .probe = tc574_probe, 1179 .probe = tc574_probe,
1205 .remove = tc574_detach, 1180 .remove = tc574_detach,
1206 .id_table = tc574_ids, 1181 .id_table = tc574_ids,
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 61f9cf2100ff..a07e22295330 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -41,7 +41,6 @@
41#include <linux/bitops.h> 41#include <linux/bitops.h>
42#include <linux/jiffies.h> 42#include <linux/jiffies.h>
43 43
44#include <pcmcia/cs.h>
45#include <pcmcia/cistpl.h> 44#include <pcmcia/cistpl.h>
46#include <pcmcia/cisreg.h> 45#include <pcmcia/cisreg.h>
47#include <pcmcia/ciscode.h> 46#include <pcmcia/ciscode.h>
@@ -176,14 +175,6 @@ static const struct ethtool_ops netdev_ethtool_ops;
176 175
177static void tc589_detach(struct pcmcia_device *p_dev); 176static void tc589_detach(struct pcmcia_device *p_dev);
178 177
179/*======================================================================
180
181 tc589_attach() creates an "instance" of the driver, allocating
182 local data structures for one device. The device is registered
183 with Card Services.
184
185======================================================================*/
186
187static const struct net_device_ops el3_netdev_ops = { 178static const struct net_device_ops el3_netdev_ops = {
188 .ndo_open = el3_open, 179 .ndo_open = el3_open,
189 .ndo_stop = el3_close, 180 .ndo_stop = el3_close,
@@ -216,9 +207,8 @@ static int tc589_probe(struct pcmcia_device *link)
216 link->resource[0]->end = 16; 207 link->resource[0]->end = 16;
217 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16; 208 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
218 209
219 link->conf.Attributes = CONF_ENABLE_IRQ; 210 link->config_flags |= CONF_ENABLE_IRQ;
220 link->conf.IntType = INT_MEMORY_AND_IO; 211 link->config_index = 1;
221 link->conf.ConfigIndex = 1;
222 212
223 dev->netdev_ops = &el3_netdev_ops; 213 dev->netdev_ops = &el3_netdev_ops;
224 dev->watchdog_timeo = TX_TIMEOUT; 214 dev->watchdog_timeo = TX_TIMEOUT;
@@ -226,16 +216,7 @@ static int tc589_probe(struct pcmcia_device *link)
226 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); 216 SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
227 217
228 return tc589_config(link); 218 return tc589_config(link);
229} /* tc589_attach */ 219}
230
231/*======================================================================
232
233 This deletes a driver "instance". The device is de-registered
234 with Card Services. If it has been released, all local data
235 structures are freed. Otherwise, the structures will be freed
236 when the device is released.
237
238======================================================================*/
239 220
240static void tc589_detach(struct pcmcia_device *link) 221static void tc589_detach(struct pcmcia_device *link)
241{ 222{
@@ -250,14 +231,6 @@ static void tc589_detach(struct pcmcia_device *link)
250 free_netdev(dev); 231 free_netdev(dev);
251} /* tc589_detach */ 232} /* tc589_detach */
252 233
253/*======================================================================
254
255 tc589_config() is scheduled to run after a CARD_INSERTION event
256 is received, to configure the PCMCIA socket, and to make the
257 ethernet device available to the system.
258
259======================================================================*/
260
261static int tc589_config(struct pcmcia_device *link) 234static int tc589_config(struct pcmcia_device *link)
262{ 235{
263 struct net_device *dev = link->priv; 236 struct net_device *dev = link->priv;
@@ -294,7 +267,7 @@ static int tc589_config(struct pcmcia_device *link)
294 if (ret) 267 if (ret)
295 goto failed; 268 goto failed;
296 269
297 ret = pcmcia_request_configuration(link, &link->conf); 270 ret = pcmcia_enable_device(link);
298 if (ret) 271 if (ret)
299 goto failed; 272 goto failed;
300 273
@@ -352,14 +325,6 @@ failed:
352 return -ENODEV; 325 return -ENODEV;
353} /* tc589_config */ 326} /* tc589_config */
354 327
355/*======================================================================
356
357 After a card is removed, tc589_release() will unregister the net
358 device, and release the PCMCIA configuration. If the device is
359 still open, this will be postponed until it is closed.
360
361======================================================================*/
362
363static void tc589_release(struct pcmcia_device *link) 328static void tc589_release(struct pcmcia_device *link)
364{ 329{
365 pcmcia_disable_device(link); 330 pcmcia_disable_device(link);
@@ -955,9 +920,7 @@ MODULE_DEVICE_TABLE(pcmcia, tc589_ids);
955 920
956static struct pcmcia_driver tc589_driver = { 921static struct pcmcia_driver tc589_driver = {
957 .owner = THIS_MODULE, 922 .owner = THIS_MODULE,
958 .drv = { 923 .name = "3c589_cs",
959 .name = "3c589_cs",
960 },
961 .probe = tc589_probe, 924 .probe = tc589_probe,
962 .remove = tc589_detach, 925 .remove = tc589_detach,
963 .id_table = tc589_ids, 926 .id_table = tc589_ids,
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 5f05ffb240cc..9e8b28b271ae 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -39,7 +39,6 @@
39#include <linux/mii.h> 39#include <linux/mii.h>
40#include "../8390.h" 40#include "../8390.h"
41 41
42#include <pcmcia/cs.h>
43#include <pcmcia/cistpl.h> 42#include <pcmcia/cistpl.h>
44#include <pcmcia/ciscode.h> 43#include <pcmcia/ciscode.h>
45#include <pcmcia/ds.h> 44#include <pcmcia/ds.h>
@@ -140,14 +139,6 @@ static const struct net_device_ops axnet_netdev_ops = {
140 .ndo_validate_addr = eth_validate_addr, 139 .ndo_validate_addr = eth_validate_addr,
141}; 140};
142 141
143/*======================================================================
144
145 axnet_attach() creates an "instance" of the driver, allocating
146 local data structures for one device. The device is registered
147 with Card Services.
148
149======================================================================*/
150
151static int axnet_probe(struct pcmcia_device *link) 142static int axnet_probe(struct pcmcia_device *link)
152{ 143{
153 axnet_dev_t *info; 144 axnet_dev_t *info;
@@ -166,8 +157,7 @@ static int axnet_probe(struct pcmcia_device *link)
166 info = PRIV(dev); 157 info = PRIV(dev);
167 info->p_dev = link; 158 info->p_dev = link;
168 link->priv = dev; 159 link->priv = dev;
169 link->conf.Attributes = CONF_ENABLE_IRQ; 160 link->config_flags |= CONF_ENABLE_IRQ;
170 link->conf.IntType = INT_MEMORY_AND_IO;
171 161
172 dev->netdev_ops = &axnet_netdev_ops; 162 dev->netdev_ops = &axnet_netdev_ops;
173 163
@@ -177,15 +167,6 @@ static int axnet_probe(struct pcmcia_device *link)
177 return axnet_config(link); 167 return axnet_config(link);
178} /* axnet_attach */ 168} /* axnet_attach */
179 169
180/*======================================================================
181
182 This deletes a driver "instance". The device is de-registered
183 with Card Services. If it has been released, all local data
184 structures are freed. Otherwise, the structures will be freed
185 when the device is released.
186
187======================================================================*/
188
189static void axnet_detach(struct pcmcia_device *link) 170static void axnet_detach(struct pcmcia_device *link)
190{ 171{
191 struct net_device *dev = link->priv; 172 struct net_device *dev = link->priv;
@@ -231,7 +212,7 @@ static int get_prom(struct pcmcia_device *link)
231 }; 212 };
232 213
233 /* Not much of a test, but the alternatives are messy */ 214 /* Not much of a test, but the alternatives are messy */
234 if (link->conf.ConfigBase != 0x03c0) 215 if (link->config_base != 0x03c0)
235 return 0; 216 return 0;
236 217
237 axnet_reset_8390(dev); 218 axnet_reset_8390(dev);
@@ -248,14 +229,6 @@ static int get_prom(struct pcmcia_device *link)
248 return 1; 229 return 1;
249} /* get_prom */ 230} /* get_prom */
250 231
251/*======================================================================
252
253 axnet_config() is scheduled to run after a CARD_INSERTION event
254 is received, to configure the PCMCIA socket, and to make the
255 ethernet device available to the system.
256
257======================================================================*/
258
259static int try_io_port(struct pcmcia_device *link) 232static int try_io_port(struct pcmcia_device *link)
260{ 233{
261 int j, ret; 234 int j, ret;
@@ -286,35 +259,16 @@ static int try_io_port(struct pcmcia_device *link)
286 } 259 }
287} 260}
288 261
289static int axnet_configcheck(struct pcmcia_device *p_dev, 262static int axnet_configcheck(struct pcmcia_device *p_dev, void *priv_data)
290 cistpl_cftable_entry_t *cfg,
291 cistpl_cftable_entry_t *dflt,
292 unsigned int vcc,
293 void *priv_data)
294{ 263{
295 int i; 264 if (p_dev->config_index == 0)
296 cistpl_io_t *io = &cfg->io; 265 return -EINVAL;
297 266
298 if (cfg->index == 0 || cfg->io.nwin == 0) 267 p_dev->config_index = 0x05;
268 if (p_dev->resource[0]->end + p_dev->resource[1]->end < 32)
299 return -ENODEV; 269 return -ENODEV;
300 270
301 p_dev->conf.ConfigIndex = 0x05; 271 return try_io_port(p_dev);
302 /* For multifunction cards, by convention, we configure the
303 network function with window 0, and serial with window 1 */
304 if (io->nwin > 1) {
305 i = (io->win[1].len > io->win[0].len);
306 p_dev->resource[1]->start = io->win[1-i].base;
307 p_dev->resource[1]->end = io->win[1-i].len;
308 } else {
309 i = p_dev->resource[1]->end = 0;
310 }
311 p_dev->resource[0]->start = io->win[i].base;
312 p_dev->resource[0]->end = io->win[i].len;
313 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
314 if (p_dev->resource[0]->end + p_dev->resource[1]->end >= 32)
315 return try_io_port(p_dev);
316
317 return -ENODEV;
318} 272}
319 273
320static int axnet_config(struct pcmcia_device *link) 274static int axnet_config(struct pcmcia_device *link)
@@ -326,20 +280,19 @@ static int axnet_config(struct pcmcia_device *link)
326 dev_dbg(&link->dev, "axnet_config(0x%p)\n", link); 280 dev_dbg(&link->dev, "axnet_config(0x%p)\n", link);
327 281
328 /* don't trust the CIS on this; Linksys got it wrong */ 282 /* don't trust the CIS on this; Linksys got it wrong */
329 link->conf.Present = 0x63; 283 link->config_regs = 0x63;
284 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
330 ret = pcmcia_loop_config(link, axnet_configcheck, NULL); 285 ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
331 if (ret != 0) 286 if (ret != 0)
332 goto failed; 287 goto failed;
333 288
334 if (!link->irq) 289 if (!link->irq)
335 goto failed; 290 goto failed;
291
292 if (resource_size(link->resource[1]) == 8)
293 link->config_flags |= CONF_ENABLE_SPKR;
336 294
337 if (resource_size(link->resource[1]) == 8) { 295 ret = pcmcia_enable_device(link);
338 link->conf.Attributes |= CONF_ENABLE_SPKR;
339 link->conf.Status = CCSR_AUDIO_ENA;
340 }
341
342 ret = pcmcia_request_configuration(link, &link->conf);
343 if (ret) 296 if (ret)
344 goto failed; 297 goto failed;
345 298
@@ -414,14 +367,6 @@ failed:
414 return -ENODEV; 367 return -ENODEV;
415} /* axnet_config */ 368} /* axnet_config */
416 369
417/*======================================================================
418
419 After a card is removed, axnet_release() will unregister the net
420 device, and release the PCMCIA configuration. If the device is
421 still open, this will be postponed until it is closed.
422
423======================================================================*/
424
425static void axnet_release(struct pcmcia_device *link) 370static void axnet_release(struct pcmcia_device *link)
426{ 371{
427 pcmcia_disable_device(link); 372 pcmcia_disable_device(link);
@@ -783,9 +728,7 @@ MODULE_DEVICE_TABLE(pcmcia, axnet_ids);
783 728
784static struct pcmcia_driver axnet_cs_driver = { 729static struct pcmcia_driver axnet_cs_driver = {
785 .owner = THIS_MODULE, 730 .owner = THIS_MODULE,
786 .drv = { 731 .name = "axnet_cs",
787 .name = "axnet_cs",
788 },
789 .probe = axnet_probe, 732 .probe = axnet_probe,
790 .remove = axnet_detach, 733 .remove = axnet_detach,
791 .id_table = axnet_ids, 734 .id_table = axnet_ids,
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index 3c400cfa82ae..b706a7249477 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -43,7 +43,6 @@
43#include <linux/arcdevice.h> 43#include <linux/arcdevice.h>
44#include <linux/com20020.h> 44#include <linux/com20020.h>
45 45
46#include <pcmcia/cs.h>
47#include <pcmcia/cistpl.h> 46#include <pcmcia/cistpl.h>
48#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
49 48
@@ -123,14 +122,6 @@ typedef struct com20020_dev_t {
123 struct net_device *dev; 122 struct net_device *dev;
124} com20020_dev_t; 123} com20020_dev_t;
125 124
126/*======================================================================
127
128 com20020_attach() creates an "instance" of the driver, allocating
129 local data structures for one device. The device is registered
130 with Card Services.
131
132======================================================================*/
133
134static int com20020_probe(struct pcmcia_device *p_dev) 125static int com20020_probe(struct pcmcia_device *p_dev)
135{ 126{
136 com20020_dev_t *info; 127 com20020_dev_t *info;
@@ -160,8 +151,7 @@ static int com20020_probe(struct pcmcia_device *p_dev)
160 151
161 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 152 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
162 p_dev->resource[0]->end = 16; 153 p_dev->resource[0]->end = 16;
163 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 154 p_dev->config_flags |= CONF_ENABLE_IRQ;
164 p_dev->conf.IntType = INT_MEMORY_AND_IO;
165 155
166 info->dev = dev; 156 info->dev = dev;
167 p_dev->priv = info; 157 p_dev->priv = info;
@@ -174,15 +164,6 @@ fail_alloc_info:
174 return -ENOMEM; 164 return -ENOMEM;
175} /* com20020_attach */ 165} /* com20020_attach */
176 166
177/*======================================================================
178
179 This deletes a driver "instance". The device is de-registered
180 with Card Services. If it has been released, all local data
181 structures are freed. Otherwise, the structures will be freed
182 when the device is released.
183
184======================================================================*/
185
186static void com20020_detach(struct pcmcia_device *link) 167static void com20020_detach(struct pcmcia_device *link)
187{ 168{
188 struct com20020_dev_t *info = link->priv; 169 struct com20020_dev_t *info = link->priv;
@@ -221,14 +202,6 @@ static void com20020_detach(struct pcmcia_device *link)
221 202
222} /* com20020_detach */ 203} /* com20020_detach */
223 204
224/*======================================================================
225
226 com20020_config() is scheduled to run after a CARD_INSERTION event
227 is received, to configure the PCMCIA socket, and to make the
228 device available to the system.
229
230======================================================================*/
231
232static int com20020_config(struct pcmcia_device *link) 205static int com20020_config(struct pcmcia_device *link)
233{ 206{
234 struct arcnet_local *lp; 207 struct arcnet_local *lp;
@@ -282,7 +255,7 @@ static int com20020_config(struct pcmcia_device *link)
282 255
283 dev->irq = link->irq; 256 dev->irq = link->irq;
284 257
285 ret = pcmcia_request_configuration(link, &link->conf); 258 ret = pcmcia_enable_device(link);
286 if (ret) 259 if (ret)
287 goto failed; 260 goto failed;
288 261
@@ -316,14 +289,6 @@ failed:
316 return -ENODEV; 289 return -ENODEV;
317} /* com20020_config */ 290} /* com20020_config */
318 291
319/*======================================================================
320
321 After a card is removed, com20020_release() will unregister the net
322 device, and release the PCMCIA configuration. If the device is
323 still open, this will be postponed until it is closed.
324
325======================================================================*/
326
327static void com20020_release(struct pcmcia_device *link) 292static void com20020_release(struct pcmcia_device *link)
328{ 293{
329 dev_dbg(&link->dev, "com20020_release\n"); 294 dev_dbg(&link->dev, "com20020_release\n");
@@ -366,9 +331,7 @@ MODULE_DEVICE_TABLE(pcmcia, com20020_ids);
366 331
367static struct pcmcia_driver com20020_cs_driver = { 332static struct pcmcia_driver com20020_cs_driver = {
368 .owner = THIS_MODULE, 333 .owner = THIS_MODULE,
369 .drv = { 334 .name = "com20020_cs",
370 .name = "com20020_cs",
371 },
372 .probe = com20020_probe, 335 .probe = com20020_probe,
373 .remove = com20020_detach, 336 .remove = com20020_detach,
374 .id_table = com20020_ids, 337 .id_table = com20020_ids,
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index 98fffb03ecd7..1c327598bbe8 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -49,7 +49,6 @@
49#include <linux/ioport.h> 49#include <linux/ioport.h>
50#include <linux/crc32.h> 50#include <linux/crc32.h>
51 51
52#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
54#include <pcmcia/ciscode.h> 53#include <pcmcia/ciscode.h>
55#include <pcmcia/ds.h> 54#include <pcmcia/ds.h>
@@ -252,8 +251,7 @@ static int fmvj18x_probe(struct pcmcia_device *link)
252 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 251 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
253 252
254 /* General socket configuration */ 253 /* General socket configuration */
255 link->conf.Attributes = CONF_ENABLE_IRQ; 254 link->config_flags |= CONF_ENABLE_IRQ;
256 link->conf.IntType = INT_MEMORY_AND_IO;
257 255
258 dev->netdev_ops = &fjn_netdev_ops; 256 dev->netdev_ops = &fjn_netdev_ops;
259 dev->watchdog_timeo = TX_TIMEOUT; 257 dev->watchdog_timeo = TX_TIMEOUT;
@@ -313,7 +311,7 @@ static int ungermann_try_io_port(struct pcmcia_device *link)
313 ret = pcmcia_request_io(link); 311 ret = pcmcia_request_io(link);
314 if (ret == 0) { 312 if (ret == 0) {
315 /* calculate ConfigIndex value */ 313 /* calculate ConfigIndex value */
316 link->conf.ConfigIndex = 314 link->config_index =
317 ((link->resource[0]->start & 0x0f0) >> 3) | 0x22; 315 ((link->resource[0]->start & 0x0f0) >> 3) | 0x22;
318 return ret; 316 return ret;
319 } 317 }
@@ -321,11 +319,7 @@ static int ungermann_try_io_port(struct pcmcia_device *link)
321 return ret; /* RequestIO failed */ 319 return ret; /* RequestIO failed */
322} 320}
323 321
324static int fmvj18x_ioprobe(struct pcmcia_device *p_dev, 322static int fmvj18x_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
325 cistpl_cftable_entry_t *cfg,
326 cistpl_cftable_entry_t *dflt,
327 unsigned int vcc,
328 void *priv_data)
329{ 323{
330 return 0; /* strange, but that's what the code did already before... */ 324 return 0; /* strange, but that's what the code did already before... */
331} 325}
@@ -362,28 +356,28 @@ static int fmvj18x_config(struct pcmcia_device *link)
362 link->card_id == PRODID_TDK_NP9610 || 356 link->card_id == PRODID_TDK_NP9610 ||
363 link->card_id == PRODID_TDK_MN3200) { 357 link->card_id == PRODID_TDK_MN3200) {
364 /* MultiFunction Card */ 358 /* MultiFunction Card */
365 link->conf.ConfigBase = 0x800; 359 link->config_base = 0x800;
366 link->conf.ConfigIndex = 0x47; 360 link->config_index = 0x47;
367 link->resource[1]->end = 8; 361 link->resource[1]->end = 8;
368 } 362 }
369 break; 363 break;
370 case MANFID_NEC: 364 case MANFID_NEC:
371 cardtype = NEC; /* MultiFunction Card */ 365 cardtype = NEC; /* MultiFunction Card */
372 link->conf.ConfigBase = 0x800; 366 link->config_base = 0x800;
373 link->conf.ConfigIndex = 0x47; 367 link->config_index = 0x47;
374 link->resource[1]->end = 8; 368 link->resource[1]->end = 8;
375 break; 369 break;
376 case MANFID_KME: 370 case MANFID_KME:
377 cardtype = KME; /* MultiFunction Card */ 371 cardtype = KME; /* MultiFunction Card */
378 link->conf.ConfigBase = 0x800; 372 link->config_base = 0x800;
379 link->conf.ConfigIndex = 0x47; 373 link->config_index = 0x47;
380 link->resource[1]->end = 8; 374 link->resource[1]->end = 8;
381 break; 375 break;
382 case MANFID_CONTEC: 376 case MANFID_CONTEC:
383 cardtype = CONTEC; 377 cardtype = CONTEC;
384 break; 378 break;
385 case MANFID_FUJITSU: 379 case MANFID_FUJITSU:
386 if (link->conf.ConfigBase == 0x0fe0) 380 if (link->config_base == 0x0fe0)
387 cardtype = MBH10302; 381 cardtype = MBH10302;
388 else if (link->card_id == PRODID_FUJITSU_MBH10302) 382 else if (link->card_id == PRODID_FUJITSU_MBH10302)
389 /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302), 383 /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302),
@@ -403,10 +397,10 @@ static int fmvj18x_config(struct pcmcia_device *link)
403 case MANFID_FUJITSU: 397 case MANFID_FUJITSU:
404 if (link->card_id == PRODID_FUJITSU_MBH10304) { 398 if (link->card_id == PRODID_FUJITSU_MBH10304) {
405 cardtype = XXX10304; /* MBH10304 with buggy CIS */ 399 cardtype = XXX10304; /* MBH10304 with buggy CIS */
406 link->conf.ConfigIndex = 0x20; 400 link->config_index = 0x20;
407 } else { 401 } else {
408 cardtype = MBH10302; /* NextCom NC5310, etc. */ 402 cardtype = MBH10302; /* NextCom NC5310, etc. */
409 link->conf.ConfigIndex = 1; 403 link->config_index = 1;
410 } 404 }
411 break; 405 break;
412 case MANFID_UNGERMANN: 406 case MANFID_UNGERMANN:
@@ -414,7 +408,7 @@ static int fmvj18x_config(struct pcmcia_device *link)
414 break; 408 break;
415 default: 409 default:
416 cardtype = MBH10302; 410 cardtype = MBH10302;
417 link->conf.ConfigIndex = 1; 411 link->config_index = 1;
418 } 412 }
419 } 413 }
420 414
@@ -432,7 +426,7 @@ static int fmvj18x_config(struct pcmcia_device *link)
432 ret = pcmcia_request_irq(link, fjn_interrupt); 426 ret = pcmcia_request_irq(link, fjn_interrupt);
433 if (ret) 427 if (ret)
434 goto failed; 428 goto failed;
435 ret = pcmcia_request_configuration(link, &link->conf); 429 ret = pcmcia_enable_device(link);
436 if (ret) 430 if (ret)
437 goto failed; 431 goto failed;
438 432
@@ -544,20 +538,18 @@ failed:
544 538
545static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id) 539static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
546{ 540{
547 win_req_t req;
548 u_char __iomem *base; 541 u_char __iomem *base;
549 int i, j; 542 int i, j;
550 543
551 /* Allocate a small memory window */ 544 /* Allocate a small memory window */
552 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 545 link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
553 req.Base = 0; req.Size = 0; 546 link->resource[2]->start = 0; link->resource[2]->end = 0;
554 req.AccessSpeed = 0; 547 i = pcmcia_request_window(link, link->resource[2], 0);
555 i = pcmcia_request_window(link, &req, &link->win);
556 if (i != 0) 548 if (i != 0)
557 return -1; 549 return -1;
558 550
559 base = ioremap(req.Base, req.Size); 551 base = ioremap(link->resource[2]->start, resource_size(link->resource[2]));
560 pcmcia_map_mem_page(link, link->win, 0); 552 pcmcia_map_mem_page(link, link->resource[2], 0);
561 553
562 /* 554 /*
563 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format 555 * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format
@@ -582,7 +574,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
582 } 574 }
583 575
584 iounmap(base); 576 iounmap(base);
585 j = pcmcia_release_window(link, link->win); 577 j = pcmcia_release_window(link, link->resource[2]);
586 return (i != 0x200) ? 0 : -1; 578 return (i != 0x200) ? 0 : -1;
587 579
588} /* fmvj18x_get_hwinfo */ 580} /* fmvj18x_get_hwinfo */
@@ -590,27 +582,26 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
590 582
591static int fmvj18x_setup_mfc(struct pcmcia_device *link) 583static int fmvj18x_setup_mfc(struct pcmcia_device *link)
592{ 584{
593 win_req_t req;
594 int i; 585 int i;
595 struct net_device *dev = link->priv; 586 struct net_device *dev = link->priv;
596 unsigned int ioaddr; 587 unsigned int ioaddr;
597 local_info_t *lp = netdev_priv(dev); 588 local_info_t *lp = netdev_priv(dev);
598 589
599 /* Allocate a small memory window */ 590 /* Allocate a small memory window */
600 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 591 link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
601 req.Base = 0; req.Size = 0; 592 link->resource[3]->start = link->resource[3]->end = 0;
602 req.AccessSpeed = 0; 593 i = pcmcia_request_window(link, link->resource[3], 0);
603 i = pcmcia_request_window(link, &req, &link->win);
604 if (i != 0) 594 if (i != 0)
605 return -1; 595 return -1;
606 596
607 lp->base = ioremap(req.Base, req.Size); 597 lp->base = ioremap(link->resource[3]->start,
598 resource_size(link->resource[3]));
608 if (lp->base == NULL) { 599 if (lp->base == NULL) {
609 printk(KERN_NOTICE "fmvj18x_cs: ioremap failed\n"); 600 printk(KERN_NOTICE "fmvj18x_cs: ioremap failed\n");
610 return -1; 601 return -1;
611 } 602 }
612 603
613 i = pcmcia_map_mem_page(link, link->win, 0); 604 i = pcmcia_map_mem_page(link, link->resource[3], 0);
614 if (i != 0) { 605 if (i != 0) {
615 iounmap(lp->base); 606 iounmap(lp->base);
616 lp->base = NULL; 607 lp->base = NULL;
@@ -638,7 +629,6 @@ static void fmvj18x_release(struct pcmcia_device *link)
638 struct net_device *dev = link->priv; 629 struct net_device *dev = link->priv;
639 local_info_t *lp = netdev_priv(dev); 630 local_info_t *lp = netdev_priv(dev);
640 u_char __iomem *tmp; 631 u_char __iomem *tmp;
641 int j;
642 632
643 dev_dbg(&link->dev, "fmvj18x_release\n"); 633 dev_dbg(&link->dev, "fmvj18x_release\n");
644 634
@@ -646,7 +636,6 @@ static void fmvj18x_release(struct pcmcia_device *link)
646 tmp = lp->base; 636 tmp = lp->base;
647 lp->base = NULL; /* set NULL before iounmap */ 637 lp->base = NULL; /* set NULL before iounmap */
648 iounmap(tmp); 638 iounmap(tmp);
649 j = pcmcia_release_window(link, link->win);
650 } 639 }
651 640
652 pcmcia_disable_device(link); 641 pcmcia_disable_device(link);
@@ -708,9 +697,7 @@ MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids);
708 697
709static struct pcmcia_driver fmvj18x_cs_driver = { 698static struct pcmcia_driver fmvj18x_cs_driver = {
710 .owner = THIS_MODULE, 699 .owner = THIS_MODULE,
711 .drv = { 700 .name = "fmvj18x_cs",
712 .name = "fmvj18x_cs",
713 },
714 .probe = fmvj18x_probe, 701 .probe = fmvj18x_probe,
715 .remove = fmvj18x_detach, 702 .remove = fmvj18x_detach,
716 .id_table = fmvj18x_ids, 703 .id_table = fmvj18x_ids,
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index b0d06a3d962f..bf7dff96d881 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -57,7 +57,6 @@
57#include <linux/trdevice.h> 57#include <linux/trdevice.h>
58#include <linux/ibmtr.h> 58#include <linux/ibmtr.h>
59 59
60#include <pcmcia/cs.h>
61#include <pcmcia/cistpl.h> 60#include <pcmcia/cistpl.h>
62#include <pcmcia/ds.h> 61#include <pcmcia/ds.h>
63 62
@@ -102,9 +101,8 @@ static void ibmtr_detach(struct pcmcia_device *p_dev);
102 101
103typedef struct ibmtr_dev_t { 102typedef struct ibmtr_dev_t {
104 struct pcmcia_device *p_dev; 103 struct pcmcia_device *p_dev;
105 struct net_device *dev; 104 struct net_device *dev;
106 window_handle_t sram_win_handle; 105 struct tok_info *ti;
107 struct tok_info *ti;
108} ibmtr_dev_t; 106} ibmtr_dev_t;
109 107
110static void netdev_get_drvinfo(struct net_device *dev, 108static void netdev_get_drvinfo(struct net_device *dev,
@@ -123,14 +121,6 @@ static irqreturn_t ibmtr_interrupt(int irq, void *dev_id) {
123 return tok_interrupt(irq, dev); 121 return tok_interrupt(irq, dev);
124}; 122};
125 123
126/*======================================================================
127
128 ibmtr_attach() creates an "instance" of the driver, allocating
129 local data structures for one device. The device is registered
130 with Card Services.
131
132======================================================================*/
133
134static int __devinit ibmtr_attach(struct pcmcia_device *link) 124static int __devinit ibmtr_attach(struct pcmcia_device *link)
135{ 125{
136 ibmtr_dev_t *info; 126 ibmtr_dev_t *info;
@@ -153,9 +143,8 @@ static int __devinit ibmtr_attach(struct pcmcia_device *link)
153 143
154 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 144 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
155 link->resource[0]->end = 4; 145 link->resource[0]->end = 4;
156 link->conf.Attributes = CONF_ENABLE_IRQ; 146 link->config_flags |= CONF_ENABLE_IRQ;
157 link->conf.IntType = INT_MEMORY_AND_IO; 147 link->config_regs = PRESENT_OPTION;
158 link->conf.Present = PRESENT_OPTION;
159 148
160 info->dev = dev; 149 info->dev = dev;
161 150
@@ -164,15 +153,6 @@ static int __devinit ibmtr_attach(struct pcmcia_device *link)
164 return ibmtr_config(link); 153 return ibmtr_config(link);
165} /* ibmtr_attach */ 154} /* ibmtr_attach */
166 155
167/*======================================================================
168
169 This deletes a driver "instance". The device is de-registered
170 with Card Services. If it has been released, all local data
171 structures are freed. Otherwise, the structures will be freed
172 when the device is released.
173
174======================================================================*/
175
176static void ibmtr_detach(struct pcmcia_device *link) 156static void ibmtr_detach(struct pcmcia_device *link)
177{ 157{
178 struct ibmtr_dev_t *info = link->priv; 158 struct ibmtr_dev_t *info = link->priv;
@@ -197,26 +177,17 @@ static void ibmtr_detach(struct pcmcia_device *link)
197 kfree(info); 177 kfree(info);
198} /* ibmtr_detach */ 178} /* ibmtr_detach */
199 179
200/*======================================================================
201
202 ibmtr_config() is scheduled to run after a CARD_INSERTION event
203 is received, to configure the PCMCIA socket, and to make the
204 token-ring device available to the system.
205
206======================================================================*/
207
208static int __devinit ibmtr_config(struct pcmcia_device *link) 180static int __devinit ibmtr_config(struct pcmcia_device *link)
209{ 181{
210 ibmtr_dev_t *info = link->priv; 182 ibmtr_dev_t *info = link->priv;
211 struct net_device *dev = info->dev; 183 struct net_device *dev = info->dev;
212 struct tok_info *ti = netdev_priv(dev); 184 struct tok_info *ti = netdev_priv(dev);
213 win_req_t req;
214 int i, ret; 185 int i, ret;
215 186
216 dev_dbg(&link->dev, "ibmtr_config\n"); 187 dev_dbg(&link->dev, "ibmtr_config\n");
217 188
218 link->conf.ConfigIndex = 0x61;
219 link->io_lines = 16; 189 link->io_lines = 16;
190 link->config_index = 0x61;
220 191
221 /* Determine if this is PRIMARY or ALTERNATE. */ 192 /* Determine if this is PRIMARY or ALTERNATE. */
222 193
@@ -240,39 +211,39 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
240 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq); 211 ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
241 212
242 /* Allocate the MMIO memory window */ 213 /* Allocate the MMIO memory window */
243 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 214 link->resource[2]->flags |= WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
244 req.Attributes |= WIN_USE_WAIT; 215 link->resource[2]->flags |= WIN_USE_WAIT;
245 req.Base = 0; 216 link->resource[2]->start = 0;
246 req.Size = 0x2000; 217 link->resource[2]->end = 0x2000;
247 req.AccessSpeed = 250; 218 ret = pcmcia_request_window(link, link->resource[2], 250);
248 ret = pcmcia_request_window(link, &req, &link->win);
249 if (ret) 219 if (ret)
250 goto failed; 220 goto failed;
251 221
252 ret = pcmcia_map_mem_page(link, link->win, mmiobase); 222 ret = pcmcia_map_mem_page(link, link->resource[2], mmiobase);
253 if (ret) 223 if (ret)
254 goto failed; 224 goto failed;
255 ti->mmio = ioremap(req.Base, req.Size); 225 ti->mmio = ioremap(link->resource[2]->start,
226 resource_size(link->resource[2]));
256 227
257 /* Allocate the SRAM memory window */ 228 /* Allocate the SRAM memory window */
258 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 229 link->resource[3]->flags = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
259 req.Attributes |= WIN_USE_WAIT; 230 link->resource[3]->flags |= WIN_USE_WAIT;
260 req.Base = 0; 231 link->resource[3]->start = 0;
261 req.Size = sramsize * 1024; 232 link->resource[3]->end = sramsize * 1024;
262 req.AccessSpeed = 250; 233 ret = pcmcia_request_window(link, link->resource[3], 250);
263 ret = pcmcia_request_window(link, &req, &info->sram_win_handle);
264 if (ret) 234 if (ret)
265 goto failed; 235 goto failed;
266 236
267 ret = pcmcia_map_mem_page(link, info->sram_win_handle, srambase); 237 ret = pcmcia_map_mem_page(link, link->resource[3], srambase);
268 if (ret) 238 if (ret)
269 goto failed; 239 goto failed;
270 240
271 ti->sram_base = srambase >> 12; 241 ti->sram_base = srambase >> 12;
272 ti->sram_virt = ioremap(req.Base, req.Size); 242 ti->sram_virt = ioremap(link->resource[3]->start,
273 ti->sram_phys = req.Base; 243 resource_size(link->resource[3]));
244 ti->sram_phys = link->resource[3]->start;
274 245
275 ret = pcmcia_request_configuration(link, &link->conf); 246 ret = pcmcia_enable_device(link);
276 if (ret) 247 if (ret)
277 goto failed; 248 goto failed;
278 249
@@ -301,14 +272,6 @@ failed:
301 return -ENODEV; 272 return -ENODEV;
302} /* ibmtr_config */ 273} /* ibmtr_config */
303 274
304/*======================================================================
305
306 After a card is removed, ibmtr_release() will unregister the net
307 device, and release the PCMCIA configuration. If the device is
308 still open, this will be postponed until it is closed.
309
310======================================================================*/
311
312static void ibmtr_release(struct pcmcia_device *link) 275static void ibmtr_release(struct pcmcia_device *link)
313{ 276{
314 ibmtr_dev_t *info = link->priv; 277 ibmtr_dev_t *info = link->priv;
@@ -316,7 +279,7 @@ static void ibmtr_release(struct pcmcia_device *link)
316 279
317 dev_dbg(&link->dev, "ibmtr_release\n"); 280 dev_dbg(&link->dev, "ibmtr_release\n");
318 281
319 if (link->win) { 282 if (link->resource[2]->end) {
320 struct tok_info *ti = netdev_priv(dev); 283 struct tok_info *ti = netdev_priv(dev);
321 iounmap(ti->mmio); 284 iounmap(ti->mmio);
322 } 285 }
@@ -398,9 +361,7 @@ MODULE_DEVICE_TABLE(pcmcia, ibmtr_ids);
398 361
399static struct pcmcia_driver ibmtr_cs_driver = { 362static struct pcmcia_driver ibmtr_cs_driver = {
400 .owner = THIS_MODULE, 363 .owner = THIS_MODULE,
401 .drv = { 364 .name = "ibmtr_cs",
402 .name = "ibmtr_cs",
403 },
404 .probe = ibmtr_attach, 365 .probe = ibmtr_attach,
405 .remove = ibmtr_detach, 366 .remove = ibmtr_detach,
406 .id_table = ibmtr_ids, 367 .id_table = ibmtr_ids,
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index 68f2deeb3ade..1eca4f5a6e78 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -146,7 +146,6 @@ Include Files
146#include <linux/ioport.h> 146#include <linux/ioport.h>
147#include <linux/bitops.h> 147#include <linux/bitops.h>
148 148
149#include <pcmcia/cs.h>
150#include <pcmcia/cisreg.h> 149#include <pcmcia/cisreg.h>
151#include <pcmcia/cistpl.h> 150#include <pcmcia/cistpl.h>
152#include <pcmcia/ds.h> 151#include <pcmcia/ds.h>
@@ -435,13 +434,6 @@ static const struct net_device_ops mace_netdev_ops = {
435 .ndo_validate_addr = eth_validate_addr, 434 .ndo_validate_addr = eth_validate_addr,
436}; 435};
437 436
438/* ----------------------------------------------------------------------------
439nmclan_attach
440 Creates an "instance" of the driver, allocating local data
441 structures for one device. The device is registered with Card
442 Services.
443---------------------------------------------------------------------------- */
444
445static int nmclan_probe(struct pcmcia_device *link) 437static int nmclan_probe(struct pcmcia_device *link)
446{ 438{
447 mace_private *lp; 439 mace_private *lp;
@@ -460,10 +452,9 @@ static int nmclan_probe(struct pcmcia_device *link)
460 spin_lock_init(&lp->bank_lock); 452 spin_lock_init(&lp->bank_lock);
461 link->resource[0]->end = 32; 453 link->resource[0]->end = 32;
462 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 454 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
463 link->conf.Attributes = CONF_ENABLE_IRQ; 455 link->config_flags |= CONF_ENABLE_IRQ;
464 link->conf.IntType = INT_MEMORY_AND_IO; 456 link->config_index = 1;
465 link->conf.ConfigIndex = 1; 457 link->config_regs = PRESENT_OPTION;
466 link->conf.Present = PRESENT_OPTION;
467 458
468 lp->tx_free_frames=AM2150_MAX_TX_FRAMES; 459 lp->tx_free_frames=AM2150_MAX_TX_FRAMES;
469 460
@@ -474,14 +465,6 @@ static int nmclan_probe(struct pcmcia_device *link)
474 return nmclan_config(link); 465 return nmclan_config(link);
475} /* nmclan_attach */ 466} /* nmclan_attach */
476 467
477/* ----------------------------------------------------------------------------
478nmclan_detach
479 This deletes a driver "instance". The device is de-registered
480 with Card Services. If it has been released, all local data
481 structures are freed. Otherwise, the structures will be freed
482 when the device is released.
483---------------------------------------------------------------------------- */
484
485static void nmclan_detach(struct pcmcia_device *link) 468static void nmclan_detach(struct pcmcia_device *link)
486{ 469{
487 struct net_device *dev = link->priv; 470 struct net_device *dev = link->priv;
@@ -625,13 +608,6 @@ static int mace_init(mace_private *lp, unsigned int ioaddr, char *enet_addr)
625 return 0; 608 return 0;
626} /* mace_init */ 609} /* mace_init */
627 610
628/* ----------------------------------------------------------------------------
629nmclan_config
630 This routine is scheduled to run after a CARD_INSERTION event
631 is received, to configure the PCMCIA socket, and to make the
632 ethernet device available to the system.
633---------------------------------------------------------------------------- */
634
635static int nmclan_config(struct pcmcia_device *link) 611static int nmclan_config(struct pcmcia_device *link)
636{ 612{
637 struct net_device *dev = link->priv; 613 struct net_device *dev = link->priv;
@@ -650,7 +626,7 @@ static int nmclan_config(struct pcmcia_device *link)
650 ret = pcmcia_request_exclusive_irq(link, mace_interrupt); 626 ret = pcmcia_request_exclusive_irq(link, mace_interrupt);
651 if (ret) 627 if (ret)
652 goto failed; 628 goto failed;
653 ret = pcmcia_request_configuration(link, &link->conf); 629 ret = pcmcia_enable_device(link);
654 if (ret) 630 if (ret)
655 goto failed; 631 goto failed;
656 632
@@ -712,12 +688,6 @@ failed:
712 return -ENODEV; 688 return -ENODEV;
713} /* nmclan_config */ 689} /* nmclan_config */
714 690
715/* ----------------------------------------------------------------------------
716nmclan_release
717 After a card is removed, nmclan_release() will unregister the
718 net device, and release the PCMCIA configuration. If the device
719 is still open, this will be postponed until it is closed.
720---------------------------------------------------------------------------- */
721static void nmclan_release(struct pcmcia_device *link) 691static void nmclan_release(struct pcmcia_device *link)
722{ 692{
723 dev_dbg(&link->dev, "nmclan_release\n"); 693 dev_dbg(&link->dev, "nmclan_release\n");
@@ -1535,9 +1505,7 @@ MODULE_DEVICE_TABLE(pcmcia, nmclan_ids);
1535 1505
1536static struct pcmcia_driver nmclan_cs_driver = { 1506static struct pcmcia_driver nmclan_cs_driver = {
1537 .owner = THIS_MODULE, 1507 .owner = THIS_MODULE,
1538 .drv = { 1508 .name = "nmclan_cs",
1539 .name = "nmclan_cs",
1540 },
1541 .probe = nmclan_probe, 1509 .probe = nmclan_probe,
1542 .remove = nmclan_detach, 1510 .remove = nmclan_detach,
1543 .id_table = nmclan_ids, 1511 .id_table = nmclan_ids,
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index 49279b0ee526..5d7d1d3088ae 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -42,7 +42,6 @@
42#include <linux/mii.h> 42#include <linux/mii.h>
43#include "../8390.h" 43#include "../8390.h"
44 44
45#include <pcmcia/cs.h>
46#include <pcmcia/cistpl.h> 45#include <pcmcia/cistpl.h>
47#include <pcmcia/ciscode.h> 46#include <pcmcia/ciscode.h>
48#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
@@ -238,14 +237,6 @@ static const struct net_device_ops pcnet_netdev_ops = {
238#endif 237#endif
239}; 238};
240 239
241/*======================================================================
242
243 pcnet_attach() creates an "instance" of the driver, allocating
244 local data structures for one device. The device is registered
245 with Card Services.
246
247======================================================================*/
248
249static int pcnet_probe(struct pcmcia_device *link) 240static int pcnet_probe(struct pcmcia_device *link)
250{ 241{
251 pcnet_dev_t *info; 242 pcnet_dev_t *info;
@@ -260,23 +251,13 @@ static int pcnet_probe(struct pcmcia_device *link)
260 info->p_dev = link; 251 info->p_dev = link;
261 link->priv = dev; 252 link->priv = dev;
262 253
263 link->conf.Attributes = CONF_ENABLE_IRQ; 254 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
264 link->conf.IntType = INT_MEMORY_AND_IO;
265 255
266 dev->netdev_ops = &pcnet_netdev_ops; 256 dev->netdev_ops = &pcnet_netdev_ops;
267 257
268 return pcnet_config(link); 258 return pcnet_config(link);
269} /* pcnet_attach */ 259} /* pcnet_attach */
270 260
271/*======================================================================
272
273 This deletes a driver "instance". The device is de-registered
274 with Card Services. If it has been released, all local data
275 structures are freed. Otherwise, the structures will be freed
276 when the device is released.
277
278======================================================================*/
279
280static void pcnet_detach(struct pcmcia_device *link) 261static void pcnet_detach(struct pcmcia_device *link)
281{ 262{
282 struct net_device *dev = link->priv; 263 struct net_device *dev = link->priv;
@@ -300,22 +281,22 @@ static void pcnet_detach(struct pcmcia_device *link)
300static hw_info_t *get_hwinfo(struct pcmcia_device *link) 281static hw_info_t *get_hwinfo(struct pcmcia_device *link)
301{ 282{
302 struct net_device *dev = link->priv; 283 struct net_device *dev = link->priv;
303 win_req_t req;
304 u_char __iomem *base, *virt; 284 u_char __iomem *base, *virt;
305 int i, j; 285 int i, j;
306 286
307 /* Allocate a small memory window */ 287 /* Allocate a small memory window */
308 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 288 link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
309 req.Base = 0; req.Size = 0; 289 link->resource[2]->start = 0; link->resource[2]->end = 0;
310 req.AccessSpeed = 0; 290 i = pcmcia_request_window(link, link->resource[2], 0);
311 i = pcmcia_request_window(link, &req, &link->win);
312 if (i != 0) 291 if (i != 0)
313 return NULL; 292 return NULL;
314 293
315 virt = ioremap(req.Base, req.Size); 294 virt = ioremap(link->resource[2]->start,
295 resource_size(link->resource[2]));
316 for (i = 0; i < NR_INFO; i++) { 296 for (i = 0; i < NR_INFO; i++) {
317 pcmcia_map_mem_page(link, link->win, hw_info[i].offset & ~(req.Size-1)); 297 pcmcia_map_mem_page(link, link->resource[2],
318 base = &virt[hw_info[i].offset & (req.Size-1)]; 298 hw_info[i].offset & ~(resource_size(link->resource[2])-1));
299 base = &virt[hw_info[i].offset & (resource_size(link->resource[2])-1)];
319 if ((readb(base+0) == hw_info[i].a0) && 300 if ((readb(base+0) == hw_info[i].a0) &&
320 (readb(base+2) == hw_info[i].a1) && 301 (readb(base+2) == hw_info[i].a1) &&
321 (readb(base+4) == hw_info[i].a2)) { 302 (readb(base+4) == hw_info[i].a2)) {
@@ -326,7 +307,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
326 } 307 }
327 308
328 iounmap(virt); 309 iounmap(virt);
329 j = pcmcia_release_window(link, link->win); 310 j = pcmcia_release_window(link, link->resource[2]);
330 return (i < NR_INFO) ? hw_info+i : NULL; 311 return (i < NR_INFO) ? hw_info+i : NULL;
331} /* get_hwinfo */ 312} /* get_hwinfo */
332 313
@@ -421,7 +402,7 @@ static hw_info_t *get_ax88190(struct pcmcia_device *link)
421 int i, j; 402 int i, j;
422 403
423 /* Not much of a test, but the alternatives are messy */ 404 /* Not much of a test, but the alternatives are messy */
424 if (link->conf.ConfigBase != 0x03c0) 405 if (link->config_base != 0x03c0)
425 return NULL; 406 return NULL;
426 407
427 outb_p(0x01, ioaddr + EN0_DCFG); /* Set word-wide access. */ 408 outb_p(0x01, ioaddr + EN0_DCFG); /* Set word-wide access. */
@@ -463,14 +444,6 @@ static hw_info_t *get_hwired(struct pcmcia_device *link)
463 return &default_info; 444 return &default_info;
464} /* get_hwired */ 445} /* get_hwired */
465 446
466/*======================================================================
467
468 pcnet_config() is scheduled to run after a CARD_INSERTION event
469 is received, to configure the PCMCIA socket, and to make the
470 ethernet device available to the system.
471
472======================================================================*/
473
474static int try_io_port(struct pcmcia_device *link) 447static int try_io_port(struct pcmcia_device *link)
475{ 448{
476 int j, ret; 449 int j, ret;
@@ -502,100 +475,105 @@ static int try_io_port(struct pcmcia_device *link)
502 } 475 }
503} 476}
504 477
505static int pcnet_confcheck(struct pcmcia_device *p_dev, 478static int pcnet_confcheck(struct pcmcia_device *p_dev, void *priv_data)
506 cistpl_cftable_entry_t *cfg,
507 cistpl_cftable_entry_t *dflt,
508 unsigned int vcc,
509 void *priv_data)
510{ 479{
511 int *has_shmem = priv_data; 480 int *priv = priv_data;
512 int i; 481 int try = (*priv & 0x1);
513 cistpl_io_t *io = &cfg->io; 482
483 *priv &= (p_dev->resource[2]->end >= 0x4000) ? 0x10 : ~0x10;
514 484
515 if (cfg->index == 0 || cfg->io.nwin == 0) 485 if (p_dev->config_index == 0)
516 return -EINVAL; 486 return -EINVAL;
517 487
518 /* For multifunction cards, by convention, we configure the 488 if (p_dev->resource[0]->end + p_dev->resource[1]->end < 32)
519 network function with window 0, and serial with window 1 */ 489 return -EINVAL;
520 if (io->nwin > 1) { 490
521 i = (io->win[1].len > io->win[0].len); 491 if (try)
522 p_dev->resource[1]->start = io->win[1-i].base; 492 p_dev->io_lines = 16;
523 p_dev->resource[1]->end = io->win[1-i].len; 493 return try_io_port(p_dev);
524 } else { 494}
525 i = p_dev->resource[1]->end = 0; 495
496static hw_info_t *pcnet_try_config(struct pcmcia_device *link,
497 int *has_shmem, int try)
498{
499 struct net_device *dev = link->priv;
500 hw_info_t *local_hw_info;
501 pcnet_dev_t *info = PRIV(dev);
502 int priv = try;
503 int ret;
504
505 ret = pcmcia_loop_config(link, pcnet_confcheck, &priv);
506 if (ret) {
507 dev_warn(&link->dev, "no useable port range found\n");
508 return NULL;
526 } 509 }
510 *has_shmem = (priv & 0x10);
527 511
528 *has_shmem = ((cfg->mem.nwin == 1) && 512 if (!link->irq)
529 (cfg->mem.win[0].len >= 0x4000)); 513 return NULL;
530 p_dev->resource[0]->start = io->win[i].base;
531 p_dev->resource[0]->end = io->win[i].len;
532 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
533 if (p_dev->resource[0]->end + p_dev->resource[1]->end >= 32)
534 return try_io_port(p_dev);
535 514
536 return 0; 515 if (resource_size(link->resource[1]) == 8)
516 link->config_flags |= CONF_ENABLE_SPKR;
517
518 if ((link->manf_id == MANFID_IBM) &&
519 (link->card_id == PRODID_IBM_HOME_AND_AWAY))
520 link->config_index |= 0x10;
521
522 ret = pcmcia_enable_device(link);
523 if (ret)
524 return NULL;
525
526 dev->irq = link->irq;
527 dev->base_addr = link->resource[0]->start;
528
529 if (info->flags & HAS_MISC_REG) {
530 if ((if_port == 1) || (if_port == 2))
531 dev->if_port = if_port;
532 else
533 dev_notice(&link->dev, "invalid if_port requested\n");
534 } else
535 dev->if_port = 0;
536
537 if ((link->config_base == 0x03c0) &&
538 (link->manf_id == 0x149) && (link->card_id == 0xc1ab)) {
539 dev_info(&link->dev,
540 "this is an AX88190 card - use axnet_cs instead.\n");
541 return NULL;
542 }
543
544 local_hw_info = get_hwinfo(link);
545 if (!local_hw_info)
546 local_hw_info = get_prom(link);
547 if (!local_hw_info)
548 local_hw_info = get_dl10019(link);
549 if (!local_hw_info)
550 local_hw_info = get_ax88190(link);
551 if (!local_hw_info)
552 local_hw_info = get_hwired(link);
553
554 return local_hw_info;
537} 555}
538 556
539static int pcnet_config(struct pcmcia_device *link) 557static int pcnet_config(struct pcmcia_device *link)
540{ 558{
541 struct net_device *dev = link->priv; 559 struct net_device *dev = link->priv;
542 pcnet_dev_t *info = PRIV(dev); 560 pcnet_dev_t *info = PRIV(dev);
543 int ret, start_pg, stop_pg, cm_offset; 561 int start_pg, stop_pg, cm_offset;
544 int has_shmem = 0; 562 int has_shmem = 0;
545 hw_info_t *local_hw_info; 563 hw_info_t *local_hw_info;
546 564
547 dev_dbg(&link->dev, "pcnet_config\n"); 565 dev_dbg(&link->dev, "pcnet_config\n");
548 566
549 ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem); 567 local_hw_info = pcnet_try_config(link, &has_shmem, 0);
550 if (ret) 568 if (!local_hw_info) {
551 goto failed; 569 /* check whether forcing io_lines to 16 helps... */
552 570 pcmcia_disable_device(link);
553 if (!link->irq) 571 local_hw_info = pcnet_try_config(link, &has_shmem, 1);
554 goto failed; 572 if (local_hw_info == NULL) {
555 573 dev_notice(&link->dev, "unable to read hardware net"
556 if (resource_size(link->resource[1]) == 8) { 574 " address for io base %#3lx\n", dev->base_addr);
557 link->conf.Attributes |= CONF_ENABLE_SPKR; 575 goto failed;
558 link->conf.Status = CCSR_AUDIO_ENA; 576 }
559 }
560 if ((link->manf_id == MANFID_IBM) &&
561 (link->card_id == PRODID_IBM_HOME_AND_AWAY))
562 link->conf.ConfigIndex |= 0x10;
563
564 ret = pcmcia_request_configuration(link, &link->conf);
565 if (ret)
566 goto failed;
567 dev->irq = link->irq;
568 dev->base_addr = link->resource[0]->start;
569 if (info->flags & HAS_MISC_REG) {
570 if ((if_port == 1) || (if_port == 2))
571 dev->if_port = if_port;
572 else
573 printk(KERN_NOTICE "pcnet_cs: invalid if_port requested\n");
574 } else {
575 dev->if_port = 0;
576 }
577
578 if ((link->conf.ConfigBase == 0x03c0) &&
579 (link->manf_id == 0x149) && (link->card_id == 0xc1ab)) {
580 printk(KERN_INFO "pcnet_cs: this is an AX88190 card!\n");
581 printk(KERN_INFO "pcnet_cs: use axnet_cs instead.\n");
582 goto failed;
583 }
584
585 local_hw_info = get_hwinfo(link);
586 if (local_hw_info == NULL)
587 local_hw_info = get_prom(link);
588 if (local_hw_info == NULL)
589 local_hw_info = get_dl10019(link);
590 if (local_hw_info == NULL)
591 local_hw_info = get_ax88190(link);
592 if (local_hw_info == NULL)
593 local_hw_info = get_hwired(link);
594
595 if (local_hw_info == NULL) {
596 printk(KERN_NOTICE "pcnet_cs: unable to read hardware net"
597 " address for io base %#3lx\n", dev->base_addr);
598 goto failed;
599 } 577 }
600 578
601 info->flags = local_hw_info->flags; 579 info->flags = local_hw_info->flags;
@@ -662,14 +640,6 @@ failed:
662 return -ENODEV; 640 return -ENODEV;
663} /* pcnet_config */ 641} /* pcnet_config */
664 642
665/*======================================================================
666
667 After a card is removed, pcnet_release() will unregister the net
668 device, and release the PCMCIA configuration. If the device is
669 still open, this will be postponed until it is closed.
670
671======================================================================*/
672
673static void pcnet_release(struct pcmcia_device *link) 643static void pcnet_release(struct pcmcia_device *link)
674{ 644{
675 pcnet_dev_t *info = PRIV(link->priv); 645 pcnet_dev_t *info = PRIV(link->priv);
@@ -682,15 +652,6 @@ static void pcnet_release(struct pcmcia_device *link)
682 pcmcia_disable_device(link); 652 pcmcia_disable_device(link);
683} 653}
684 654
685/*======================================================================
686
687 The card status event handler. Mostly, this schedules other
688 stuff to run after an event is received. A CARD_REMOVAL event
689 also sets some flags to discourage the net drivers from trying
690 to talk to the card any more.
691
692======================================================================*/
693
694static int pcnet_suspend(struct pcmcia_device *link) 655static int pcnet_suspend(struct pcmcia_device *link)
695{ 656{
696 struct net_device *dev = link->priv; 657 struct net_device *dev = link->priv;
@@ -1459,7 +1420,6 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1459{ 1420{
1460 struct net_device *dev = link->priv; 1421 struct net_device *dev = link->priv;
1461 pcnet_dev_t *info = PRIV(dev); 1422 pcnet_dev_t *info = PRIV(dev);
1462 win_req_t req;
1463 int i, window_size, offset, ret; 1423 int i, window_size, offset, ret;
1464 1424
1465 window_size = (stop_pg - start_pg) << 8; 1425 window_size = (stop_pg - start_pg) << 8;
@@ -1470,22 +1430,22 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1470 window_size = roundup_pow_of_two(window_size); 1430 window_size = roundup_pow_of_two(window_size);
1471 1431
1472 /* Allocate a memory window */ 1432 /* Allocate a memory window */
1473 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE; 1433 link->resource[3]->flags |= WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
1474 req.Attributes |= WIN_USE_WAIT; 1434 link->resource[3]->flags |= WIN_USE_WAIT;
1475 req.Base = 0; req.Size = window_size; 1435 link->resource[3]->start = 0; link->resource[3]->end = window_size;
1476 req.AccessSpeed = mem_speed; 1436 ret = pcmcia_request_window(link, link->resource[3], mem_speed);
1477 ret = pcmcia_request_window(link, &req, &link->win);
1478 if (ret) 1437 if (ret)
1479 goto failed; 1438 goto failed;
1480 1439
1481 offset = (start_pg << 8) + cm_offset; 1440 offset = (start_pg << 8) + cm_offset;
1482 offset -= offset % window_size; 1441 offset -= offset % window_size;
1483 ret = pcmcia_map_mem_page(link, link->win, offset); 1442 ret = pcmcia_map_mem_page(link, link->resource[3], offset);
1484 if (ret) 1443 if (ret)
1485 goto failed; 1444 goto failed;
1486 1445
1487 /* Try scribbling on the buffer */ 1446 /* Try scribbling on the buffer */
1488 info->base = ioremap(req.Base, window_size); 1447 info->base = ioremap(link->resource[3]->start,
1448 resource_size(link->resource[3]));
1489 for (i = 0; i < (TX_PAGES<<8); i += 2) 1449 for (i = 0; i < (TX_PAGES<<8); i += 2)
1490 __raw_writew((i>>1), info->base+offset+i); 1450 __raw_writew((i>>1), info->base+offset+i);
1491 udelay(100); 1451 udelay(100);
@@ -1494,19 +1454,20 @@ static int setup_shmem_window(struct pcmcia_device *link, int start_pg,
1494 pcnet_reset_8390(dev); 1454 pcnet_reset_8390(dev);
1495 if (i != (TX_PAGES<<8)) { 1455 if (i != (TX_PAGES<<8)) {
1496 iounmap(info->base); 1456 iounmap(info->base);
1497 pcmcia_release_window(link, link->win); 1457 pcmcia_release_window(link, link->resource[3]);
1498 info->base = NULL; link->win = 0; 1458 info->base = NULL;
1499 goto failed; 1459 goto failed;
1500 } 1460 }
1501 1461
1502 ei_status.mem = info->base + offset; 1462 ei_status.mem = info->base + offset;
1503 ei_status.priv = req.Size; 1463 ei_status.priv = resource_size(link->resource[3]);
1504 dev->mem_start = (u_long)ei_status.mem; 1464 dev->mem_start = (u_long)ei_status.mem;
1505 dev->mem_end = dev->mem_start + req.Size; 1465 dev->mem_end = dev->mem_start + resource_size(link->resource[3]);
1506 1466
1507 ei_status.tx_start_page = start_pg; 1467 ei_status.tx_start_page = start_pg;
1508 ei_status.rx_start_page = start_pg + TX_PAGES; 1468 ei_status.rx_start_page = start_pg + TX_PAGES;
1509 ei_status.stop_page = start_pg + ((req.Size - offset) >> 8); 1469 ei_status.stop_page = start_pg + (
1470 (resource_size(link->resource[3]) - offset) >> 8);
1510 1471
1511 /* set up block i/o functions */ 1472 /* set up block i/o functions */
1512 ei_status.get_8390_hdr = &shmem_get_8390_hdr; 1473 ei_status.get_8390_hdr = &shmem_get_8390_hdr;
@@ -1745,9 +1706,7 @@ MODULE_FIRMWARE("cis/PE-200.cis");
1745MODULE_FIRMWARE("cis/tamarack.cis"); 1706MODULE_FIRMWARE("cis/tamarack.cis");
1746 1707
1747static struct pcmcia_driver pcnet_driver = { 1708static struct pcmcia_driver pcnet_driver = {
1748 .drv = { 1709 .name = "pcnet_cs",
1749 .name = "pcnet_cs",
1750 },
1751 .probe = pcnet_probe, 1710 .probe = pcnet_probe,
1752 .remove = pcnet_detach, 1711 .remove = pcnet_detach,
1753 .owner = THIS_MODULE, 1712 .owner = THIS_MODULE,
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 377367d03b41..0af2fc8ec164 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -44,7 +44,6 @@
44#include <linux/jiffies.h> 44#include <linux/jiffies.h>
45#include <linux/firmware.h> 45#include <linux/firmware.h>
46 46
47#include <pcmcia/cs.h>
48#include <pcmcia/cistpl.h> 47#include <pcmcia/cistpl.h>
49#include <pcmcia/cisreg.h> 48#include <pcmcia/cisreg.h>
50#include <pcmcia/ciscode.h> 49#include <pcmcia/ciscode.h>
@@ -300,14 +299,6 @@ static const struct net_device_ops smc_netdev_ops = {
300 .ndo_validate_addr = eth_validate_addr, 299 .ndo_validate_addr = eth_validate_addr,
301}; 300};
302 301
303/*======================================================================
304
305 smc91c92_attach() creates an "instance" of the driver, allocating
306 local data structures for one device. The device is registered
307 with Card Services.
308
309======================================================================*/
310
311static int smc91c92_probe(struct pcmcia_device *link) 302static int smc91c92_probe(struct pcmcia_device *link)
312{ 303{
313 struct smc_private *smc; 304 struct smc_private *smc;
@@ -324,10 +315,6 @@ static int smc91c92_probe(struct pcmcia_device *link)
324 link->priv = dev; 315 link->priv = dev;
325 316
326 spin_lock_init(&smc->lock); 317 spin_lock_init(&smc->lock);
327 link->resource[0]->end = 16;
328 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
329 link->conf.Attributes = CONF_ENABLE_IRQ;
330 link->conf.IntType = INT_MEMORY_AND_IO;
331 318
332 /* The SMC91c92-specific entries in the device structure. */ 319 /* The SMC91c92-specific entries in the device structure. */
333 dev->netdev_ops = &smc_netdev_ops; 320 dev->netdev_ops = &smc_netdev_ops;
@@ -343,15 +330,6 @@ static int smc91c92_probe(struct pcmcia_device *link)
343 return smc91c92_config(link); 330 return smc91c92_config(link);
344} /* smc91c92_attach */ 331} /* smc91c92_attach */
345 332
346/*======================================================================
347
348 This deletes a driver "instance". The device is de-registered
349 with Card Services. If it has been released, all local data
350 structures are freed. Otherwise, the structures will be freed
351 when the device is released.
352
353======================================================================*/
354
355static void smc91c92_detach(struct pcmcia_device *link) 333static void smc91c92_detach(struct pcmcia_device *link)
356{ 334{
357 struct net_device *dev = link->priv; 335 struct net_device *dev = link->priv;
@@ -412,26 +390,28 @@ static int mhz_3288_power(struct pcmcia_device *link)
412 mdelay(200); 390 mdelay(200);
413 391
414 /* Now read and write the COR... */ 392 /* Now read and write the COR... */
415 tmp = readb(smc->base + link->conf.ConfigBase + CISREG_COR); 393 tmp = readb(smc->base + link->config_base + CISREG_COR);
416 udelay(5); 394 udelay(5);
417 writeb(tmp, smc->base + link->conf.ConfigBase + CISREG_COR); 395 writeb(tmp, smc->base + link->config_base + CISREG_COR);
418 396
419 return 0; 397 return 0;
420} 398}
421 399
422static int mhz_mfc_config_check(struct pcmcia_device *p_dev, 400static int mhz_mfc_config_check(struct pcmcia_device *p_dev, void *priv_data)
423 cistpl_cftable_entry_t *cf,
424 cistpl_cftable_entry_t *dflt,
425 unsigned int vcc,
426 void *priv_data)
427{ 401{
428 int k; 402 int k;
429 p_dev->resource[1]->start = cf->io.win[0].base; 403 p_dev->io_lines = 16;
404 p_dev->resource[1]->start = p_dev->resource[0]->start;
405 p_dev->resource[1]->end = 8;
406 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
407 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
408 p_dev->resource[0]->end = 16;
409 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
410 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
430 for (k = 0; k < 0x400; k += 0x10) { 411 for (k = 0; k < 0x400; k += 0x10) {
431 if (k & 0x80) 412 if (k & 0x80)
432 continue; 413 continue;
433 p_dev->resource[0]->start = k ^ 0x300; 414 p_dev->resource[0]->start = k ^ 0x300;
434 p_dev->io_lines = 16;
435 if (!pcmcia_request_io(p_dev)) 415 if (!pcmcia_request_io(p_dev))
436 return 0; 416 return 0;
437 } 417 }
@@ -442,14 +422,11 @@ static int mhz_mfc_config(struct pcmcia_device *link)
442{ 422{
443 struct net_device *dev = link->priv; 423 struct net_device *dev = link->priv;
444 struct smc_private *smc = netdev_priv(dev); 424 struct smc_private *smc = netdev_priv(dev);
445 win_req_t req;
446 unsigned int offset; 425 unsigned int offset;
447 int i; 426 int i;
448 427
449 link->conf.Attributes |= CONF_ENABLE_SPKR; 428 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ |
450 link->conf.Status = CCSR_AUDIO_ENA; 429 CONF_AUTO_SET_IO;
451 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
452 link->resource[1]->end = 8;
453 430
454 /* The Megahertz combo cards have modem-like CIS entries, so 431 /* The Megahertz combo cards have modem-like CIS entries, so
455 we have to explicitly try a bunch of port combinations. */ 432 we have to explicitly try a bunch of port combinations. */
@@ -459,16 +436,16 @@ static int mhz_mfc_config(struct pcmcia_device *link)
459 dev->base_addr = link->resource[0]->start; 436 dev->base_addr = link->resource[0]->start;
460 437
461 /* Allocate a memory window, for accessing the ISR */ 438 /* Allocate a memory window, for accessing the ISR */
462 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 439 link->resource[2]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
463 req.Base = req.Size = 0; 440 link->resource[2]->start = link->resource[2]->end = 0;
464 req.AccessSpeed = 0; 441 i = pcmcia_request_window(link, link->resource[2], 0);
465 i = pcmcia_request_window(link, &req, &link->win);
466 if (i != 0) 442 if (i != 0)
467 return -ENODEV; 443 return -ENODEV;
468 444
469 smc->base = ioremap(req.Base, req.Size); 445 smc->base = ioremap(link->resource[2]->start,
470 offset = (smc->manfid == MANFID_MOTOROLA) ? link->conf.ConfigBase : 0; 446 resource_size(link->resource[2]));
471 i = pcmcia_map_mem_page(link, link->win, offset); 447 offset = (smc->manfid == MANFID_MOTOROLA) ? link->config_base : 0;
448 i = pcmcia_map_mem_page(link, link->resource[2], offset);
472 if ((i == 0) && 449 if ((i == 0) &&
473 (smc->manfid == MANFID_MEGAHERTZ) && 450 (smc->manfid == MANFID_MEGAHERTZ) &&
474 (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 451 (smc->cardid == PRODID_MEGAHERTZ_EM3288))
@@ -591,14 +568,12 @@ static int mot_setup(struct pcmcia_device *link)
591 568
592/*====================================================================*/ 569/*====================================================================*/
593 570
594static int smc_configcheck(struct pcmcia_device *p_dev, 571static int smc_configcheck(struct pcmcia_device *p_dev, void *priv_data)
595 cistpl_cftable_entry_t *cf,
596 cistpl_cftable_entry_t *dflt,
597 unsigned int vcc,
598 void *priv_data)
599{ 572{
600 p_dev->resource[0]->start = cf->io.win[0].base; 573 p_dev->resource[0]->end = 16;
601 p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK; 574 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
575 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
576
602 return pcmcia_request_io(p_dev); 577 return pcmcia_request_io(p_dev);
603} 578}
604 579
@@ -607,7 +582,8 @@ static int smc_config(struct pcmcia_device *link)
607 struct net_device *dev = link->priv; 582 struct net_device *dev = link->priv;
608 int i; 583 int i;
609 584
610 link->resource[0]->end = 16; 585 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
586
611 i = pcmcia_loop_config(link, smc_configcheck, NULL); 587 i = pcmcia_loop_config(link, smc_configcheck, NULL);
612 if (!i) 588 if (!i)
613 dev->base_addr = link->resource[0]->start; 589 dev->base_addr = link->resource[0]->start;
@@ -640,15 +616,14 @@ static int osi_config(struct pcmcia_device *link)
640 static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; 616 static const unsigned int com[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
641 int i, j; 617 int i, j;
642 618
643 link->conf.Attributes |= CONF_ENABLE_SPKR; 619 link->config_flags |= CONF_ENABLE_SPKR | CONF_ENABLE_IRQ;
644 link->conf.Status = CCSR_AUDIO_ENA;
645 link->resource[0]->end = 64; 620 link->resource[0]->end = 64;
646 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; 621 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
647 link->resource[1]->end = 8; 622 link->resource[1]->end = 8;
648 623
649 /* Enable Hard Decode, LAN, Modem */ 624 /* Enable Hard Decode, LAN, Modem */
650 link->conf.ConfigIndex = 0x23;
651 link->io_lines = 16; 625 link->io_lines = 16;
626 link->config_index = 0x23;
652 627
653 for (i = j = 0; j < 4; j++) { 628 for (i = j = 0; j < 4; j++) {
654 link->resource[1]->start = com[j]; 629 link->resource[1]->start = com[j];
@@ -658,7 +633,7 @@ static int osi_config(struct pcmcia_device *link)
658 } 633 }
659 if (i != 0) { 634 if (i != 0) {
660 /* Fallback: turn off hard decode */ 635 /* Fallback: turn off hard decode */
661 link->conf.ConfigIndex = 0x03; 636 link->config_index = 0x03;
662 link->resource[1]->end = 0; 637 link->resource[1]->end = 0;
663 i = pcmcia_request_io(link); 638 i = pcmcia_request_io(link);
664 } 639 }
@@ -817,27 +792,16 @@ static int check_sig(struct pcmcia_device *link)
817 } 792 }
818 793
819 if (width) { 794 if (width) {
820 modconf_t mod = {
821 .Attributes = CONF_IO_CHANGE_WIDTH,
822 };
823 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n"); 795 printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
824 796
825 smc91c92_suspend(link); 797 smc91c92_suspend(link);
826 pcmcia_modify_configuration(link, &mod); 798 pcmcia_fixup_iowidth(link);
827 smc91c92_resume(link); 799 smc91c92_resume(link);
828 return check_sig(link); 800 return check_sig(link);
829 } 801 }
830 return -ENODEV; 802 return -ENODEV;
831} 803}
832 804
833/*======================================================================
834
835 smc91c92_config() is scheduled to run after a CARD_INSERTION event
836 is received, to configure the PCMCIA socket, and to make the
837 ethernet device available to the system.
838
839======================================================================*/
840
841static int smc91c92_config(struct pcmcia_device *link) 805static int smc91c92_config(struct pcmcia_device *link)
842{ 806{
843 struct net_device *dev = link->priv; 807 struct net_device *dev = link->priv;
@@ -869,7 +833,7 @@ static int smc91c92_config(struct pcmcia_device *link)
869 i = pcmcia_request_irq(link, smc_interrupt); 833 i = pcmcia_request_irq(link, smc_interrupt);
870 if (i) 834 if (i)
871 goto config_failed; 835 goto config_failed;
872 i = pcmcia_request_configuration(link, &link->conf); 836 i = pcmcia_enable_device(link);
873 if (i) 837 if (i)
874 goto config_failed; 838 goto config_failed;
875 839
@@ -988,18 +952,10 @@ config_failed:
988 return -ENODEV; 952 return -ENODEV;
989} /* smc91c92_config */ 953} /* smc91c92_config */
990 954
991/*======================================================================
992
993 After a card is removed, smc91c92_release() will unregister the net
994 device, and release the PCMCIA configuration. If the device is
995 still open, this will be postponed until it is closed.
996
997======================================================================*/
998
999static void smc91c92_release(struct pcmcia_device *link) 955static void smc91c92_release(struct pcmcia_device *link)
1000{ 956{
1001 dev_dbg(&link->dev, "smc91c92_release\n"); 957 dev_dbg(&link->dev, "smc91c92_release\n");
1002 if (link->win) { 958 if (link->resource[2]->end) {
1003 struct net_device *dev = link->priv; 959 struct net_device *dev = link->priv;
1004 struct smc_private *smc = netdev_priv(dev); 960 struct smc_private *smc = netdev_priv(dev);
1005 iounmap(smc->base); 961 iounmap(smc->base);
@@ -2101,9 +2057,7 @@ MODULE_DEVICE_TABLE(pcmcia, smc91c92_ids);
2101 2057
2102static struct pcmcia_driver smc91c92_cs_driver = { 2058static struct pcmcia_driver smc91c92_cs_driver = {
2103 .owner = THIS_MODULE, 2059 .owner = THIS_MODULE,
2104 .drv = { 2060 .name = "smc91c92_cs",
2105 .name = "smc91c92_cs",
2106 },
2107 .probe = smc91c92_probe, 2061 .probe = smc91c92_probe,
2108 .remove = smc91c92_detach, 2062 .remove = smc91c92_detach,
2109 .id_table = smc91c92_ids, 2063 .id_table = smc91c92_ids,
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index f5819526b5ee..1fece617c069 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -82,7 +82,6 @@
82#include <linux/bitops.h> 82#include <linux/bitops.h>
83#include <linux/mii.h> 83#include <linux/mii.h>
84 84
85#include <pcmcia/cs.h>
86#include <pcmcia/cistpl.h> 85#include <pcmcia/cistpl.h>
87#include <pcmcia/cisreg.h> 86#include <pcmcia/cisreg.h>
88#include <pcmcia/ciscode.h> 87#include <pcmcia/ciscode.h>
@@ -267,33 +266,11 @@ static unsigned mii_rd(unsigned int ioaddr, u_char phyaddr, u_char phyreg);
267static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg, 266static void mii_wr(unsigned int ioaddr, u_char phyaddr, u_char phyreg,
268 unsigned data, int len); 267 unsigned data, int len);
269 268
270/*
271 * The event() function is this driver's Card Services event handler.
272 * It will be called by Card Services when an appropriate card status
273 * event is received. The config() and release() entry points are
274 * used to configure or release a socket, in response to card insertion
275 * and ejection events. They are invoked from the event handler.
276 */
277
278static int has_ce2_string(struct pcmcia_device * link); 269static int has_ce2_string(struct pcmcia_device * link);
279static int xirc2ps_config(struct pcmcia_device * link); 270static int xirc2ps_config(struct pcmcia_device * link);
280static void xirc2ps_release(struct pcmcia_device * link); 271static void xirc2ps_release(struct pcmcia_device * link);
281
282/****************
283 * The attach() and detach() entry points are used to create and destroy
284 * "instances" of the driver, where each instance represents everything
285 * needed to manage one actual PCMCIA card.
286 */
287
288static void xirc2ps_detach(struct pcmcia_device *p_dev); 272static void xirc2ps_detach(struct pcmcia_device *p_dev);
289 273
290/****************
291 * You'll also need to prototype all the functions that will actually
292 * be used to talk to your device. See 'pcmem_cs' for a good example
293 * of a fully self-sufficient driver; the other drivers rely more or
294 * less on other parts of the kernel.
295 */
296
297static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id); 274static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
298 275
299typedef struct local_info_t { 276typedef struct local_info_t {
@@ -501,16 +478,6 @@ static const struct net_device_ops netdev_ops = {
501 .ndo_validate_addr = eth_validate_addr, 478 .ndo_validate_addr = eth_validate_addr,
502}; 479};
503 480
504/****************
505 * xirc2ps_attach() creates an "instance" of the driver, allocating
506 * local data structures for one device. The device is registered
507 * with Card Services.
508 *
509 * The dev_link structure is initialized, but we don't actually
510 * configure the card at this point -- we wait until we receive a
511 * card insertion event.
512 */
513
514static int 481static int
515xirc2ps_probe(struct pcmcia_device *link) 482xirc2ps_probe(struct pcmcia_device *link)
516{ 483{
@@ -529,9 +496,7 @@ xirc2ps_probe(struct pcmcia_device *link)
529 link->priv = dev; 496 link->priv = dev;
530 497
531 /* General socket configuration */ 498 /* General socket configuration */
532 link->conf.Attributes = CONF_ENABLE_IRQ; 499 link->config_index = 1;
533 link->conf.IntType = INT_MEMORY_AND_IO;
534 link->conf.ConfigIndex = 1;
535 500
536 /* Fill in card specific entries */ 501 /* Fill in card specific entries */
537 dev->netdev_ops = &netdev_ops; 502 dev->netdev_ops = &netdev_ops;
@@ -542,13 +507,6 @@ xirc2ps_probe(struct pcmcia_device *link)
542 return xirc2ps_config(link); 507 return xirc2ps_config(link);
543} /* xirc2ps_attach */ 508} /* xirc2ps_attach */
544 509
545/****************
546 * This deletes a driver "instance". The device is de-registered
547 * with Card Services. If it has been released, all local data
548 * structures are freed. Otherwise, the structures will be freed
549 * when the device is released.
550 */
551
552static void 510static void
553xirc2ps_detach(struct pcmcia_device *link) 511xirc2ps_detach(struct pcmcia_device *link)
554{ 512{
@@ -667,44 +625,53 @@ has_ce2_string(struct pcmcia_device * p_dev)
667} 625}
668 626
669static int 627static int
670xirc2ps_config_modem(struct pcmcia_device *p_dev, 628xirc2ps_config_modem(struct pcmcia_device *p_dev, void *priv_data)
671 cistpl_cftable_entry_t *cf,
672 cistpl_cftable_entry_t *dflt,
673 unsigned int vcc,
674 void *priv_data)
675{ 629{
676 unsigned int ioaddr; 630 unsigned int ioaddr;
677 631
678 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) { 632 if ((p_dev->resource[0]->start & 0xf) == 8)
679 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 633 return -ENODEV;
680 p_dev->resource[1]->start = cf->io.win[0].base; 634
681 p_dev->resource[0]->start = ioaddr; 635 p_dev->resource[0]->end = 16;
682 if (!pcmcia_request_io(p_dev)) 636 p_dev->resource[1]->end = 8;
683 return 0; 637 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
684 } 638 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
639 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
640 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
641 p_dev->io_lines = 10;
642
643 p_dev->resource[1]->start = p_dev->resource[0]->start;
644 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
645 p_dev->resource[0]->start = ioaddr;
646 if (!pcmcia_request_io(p_dev))
647 return 0;
685 } 648 }
686 return -ENODEV; 649 return -ENODEV;
687} 650}
688 651
689static int 652static int
690xirc2ps_config_check(struct pcmcia_device *p_dev, 653xirc2ps_config_check(struct pcmcia_device *p_dev, void *priv_data)
691 cistpl_cftable_entry_t *cf,
692 cistpl_cftable_entry_t *dflt,
693 unsigned int vcc,
694 void *priv_data)
695{ 654{
696 int *pass = priv_data; 655 int *pass = priv_data;
656 resource_size_t tmp = p_dev->resource[1]->start;
697 657
698 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) { 658 tmp += (*pass ? (p_dev->config_index & 0x20 ? -24 : 8)
699 p_dev->resource[1]->start = cf->io.win[0].base; 659 : (p_dev->config_index & 0x20 ? 8 : -24));
700 p_dev->resource[0]->start = p_dev->resource[1]->start 660
701 + (*pass ? (cf->index & 0x20 ? -24:8) 661 if ((p_dev->resource[0]->start & 0xf) == 8)
702 : (cf->index & 0x20 ? 8:-24)); 662 return -ENODEV;
703 if (!pcmcia_request_io(p_dev)) 663
704 return 0; 664 p_dev->resource[0]->end = 18;
705 } 665 p_dev->resource[1]->end = 8;
706 return -ENODEV; 666 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
667 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
668 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
669 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
670 p_dev->io_lines = 10;
707 671
672 p_dev->resource[1]->start = p_dev->resource[0]->start;
673 p_dev->resource[0]->start = tmp;
674 return pcmcia_request_io(p_dev);
708} 675}
709 676
710 677
@@ -727,11 +694,6 @@ static int pcmcia_get_mac_ce(struct pcmcia_device *p_dev,
727}; 694};
728 695
729 696
730/****************
731 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
732 * is received, to configure the PCMCIA socket, and to make the
733 * ethernet device available to the system.
734 */
735static int 697static int
736xirc2ps_config(struct pcmcia_device * link) 698xirc2ps_config(struct pcmcia_device * link)
737{ 699{
@@ -807,32 +769,24 @@ xirc2ps_config(struct pcmcia_device * link)
807 goto failure; 769 goto failure;
808 } 770 }
809 771
810 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
811 link->io_lines = 10;
812 if (local->modem) { 772 if (local->modem) {
813 int pass; 773 int pass;
774 link->config_flags |= CONF_AUTO_SET_IO;
814 775
815 if (do_sound) {
816 link->conf.Attributes |= CONF_ENABLE_SPKR;
817 link->conf.Status |= CCSR_AUDIO_ENA;
818 }
819 link->resource[1]->end = 8;
820 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
821 if (local->dingo) { 776 if (local->dingo) {
822 /* Take the Modem IO port from the CIS and scan for a free 777 /* Take the Modem IO port from the CIS and scan for a free
823 * Ethernet port */ 778 * Ethernet port */
824 link->resource[0]->end = 16; /* no Mako stuff anymore */
825 if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL)) 779 if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
826 goto port_found; 780 goto port_found;
827 } else { 781 } else {
828 link->resource[0]->end = 18;
829 /* We do 2 passes here: The first one uses the regular mapping and 782 /* We do 2 passes here: The first one uses the regular mapping and
830 * the second tries again, thereby considering that the 32 ports are 783 * the second tries again, thereby considering that the 32 ports are
831 * mirrored every 32 bytes. Actually we use a mirrored port for 784 * mirrored every 32 bytes. Actually we use a mirrored port for
832 * the Mako if (on the first pass) the COR bit 5 is set. 785 * the Mako if (on the first pass) the COR bit 5 is set.
833 */ 786 */
834 for (pass=0; pass < 2; pass++) 787 for (pass=0; pass < 2; pass++)
835 if (!pcmcia_loop_config(link, xirc2ps_config_check, &pass)) 788 if (!pcmcia_loop_config(link, xirc2ps_config_check,
789 &pass))
836 goto port_found; 790 goto port_found;
837 /* if special option: 791 /* if special option:
838 * try to configure as Ethernet only. 792 * try to configure as Ethernet only.
@@ -840,7 +794,9 @@ xirc2ps_config(struct pcmcia_device * link)
840 } 794 }
841 printk(KNOT_XIRC "no ports available\n"); 795 printk(KNOT_XIRC "no ports available\n");
842 } else { 796 } else {
797 link->io_lines = 10;
843 link->resource[0]->end = 16; 798 link->resource[0]->end = 16;
799 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
844 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) { 800 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
845 link->resource[0]->start = ioaddr; 801 link->resource[0]->start = ioaddr;
846 if (!(err = pcmcia_request_io(link))) 802 if (!(err = pcmcia_request_io(link)))
@@ -861,16 +817,14 @@ xirc2ps_config(struct pcmcia_device * link)
861 if ((err=pcmcia_request_irq(link, xirc2ps_interrupt))) 817 if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
862 goto config_error; 818 goto config_error;
863 819
864 /**************** 820 link->config_flags |= CONF_ENABLE_IRQ;
865 * This actually configures the PCMCIA socket -- setting up 821 if (do_sound)
866 * the I/O windows and the interrupt mapping. 822 link->config_flags |= CONF_ENABLE_SPKR;
867 */ 823
868 if ((err=pcmcia_request_configuration(link, &link->conf))) 824 if ((err = pcmcia_enable_device(link)))
869 goto config_error; 825 goto config_error;
870 826
871 if (local->dingo) { 827 if (local->dingo) {
872 win_req_t req;
873
874 /* Reset the modem's BAR to the correct value 828 /* Reset the modem's BAR to the correct value
875 * This is necessary because in the RequestConfiguration call, 829 * This is necessary because in the RequestConfiguration call,
876 * the base address of the ethernet port (BasePort1) is written 830 * the base address of the ethernet port (BasePort1) is written
@@ -890,14 +844,14 @@ xirc2ps_config(struct pcmcia_device * link)
890 * is at 0x0800. So we allocate a window into the attribute 844 * is at 0x0800. So we allocate a window into the attribute
891 * memory and write direct to the CIS registers 845 * memory and write direct to the CIS registers
892 */ 846 */
893 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; 847 link->resource[2]->flags = WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM |
894 req.Base = req.Size = 0; 848 WIN_ENABLE;
895 req.AccessSpeed = 0; 849 link->resource[2]->start = link->resource[2]->end = 0;
896 if ((err = pcmcia_request_window(link, &req, &link->win))) 850 if ((err = pcmcia_request_window(link, link->resource[2], 0)))
897 goto config_error; 851 goto config_error;
898 852
899 local->dingo_ccr = ioremap(req.Base,0x1000) + 0x0800; 853 local->dingo_ccr = ioremap(link->resource[2]->start, 0x1000) + 0x0800;
900 if ((err = pcmcia_map_mem_page(link, link->win, 0))) 854 if ((err = pcmcia_map_mem_page(link, link->resource[2], 0)))
901 goto config_error; 855 goto config_error;
902 856
903 /* Setup the CCRs; there are no infos in the CIS about the Ethernet 857 /* Setup the CCRs; there are no infos in the CIS about the Ethernet
@@ -978,17 +932,12 @@ xirc2ps_config(struct pcmcia_device * link)
978 return -ENODEV; 932 return -ENODEV;
979} /* xirc2ps_config */ 933} /* xirc2ps_config */
980 934
981/****************
982 * After a card is removed, xirc2ps_release() will unregister the net
983 * device, and release the PCMCIA configuration. If the device is
984 * still open, this will be postponed until it is closed.
985 */
986static void 935static void
987xirc2ps_release(struct pcmcia_device *link) 936xirc2ps_release(struct pcmcia_device *link)
988{ 937{
989 dev_dbg(&link->dev, "release\n"); 938 dev_dbg(&link->dev, "release\n");
990 939
991 if (link->win) { 940 if (link->resource[2]->end) {
992 struct net_device *dev = link->priv; 941 struct net_device *dev = link->priv;
993 local_info_t *local = netdev_priv(dev); 942 local_info_t *local = netdev_priv(dev);
994 if (local->dingo) 943 if (local->dingo)
@@ -1830,9 +1779,7 @@ MODULE_DEVICE_TABLE(pcmcia, xirc2ps_ids);
1830 1779
1831static struct pcmcia_driver xirc2ps_cs_driver = { 1780static struct pcmcia_driver xirc2ps_cs_driver = {
1832 .owner = THIS_MODULE, 1781 .owner = THIS_MODULE,
1833 .drv = { 1782 .name = "xirc2ps_cs",
1834 .name = "xirc2ps_cs",
1835 },
1836 .probe = xirc2ps_probe, 1783 .probe = xirc2ps_probe,
1837 .remove = xirc2ps_detach, 1784 .remove = xirc2ps_detach,
1838 .id_table = xirc2ps_ids, 1785 .id_table = xirc2ps_ids,
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6a6b8199a0d6..6c58da2b882c 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -308,7 +308,7 @@ static int mdio_bus_suspend(struct device *dev)
308 * may call phy routines that try to grab the same lock, and that may 308 * may call phy routines that try to grab the same lock, and that may
309 * lead to a deadlock. 309 * lead to a deadlock.
310 */ 310 */
311 if (phydev->attached_dev) 311 if (phydev->attached_dev && phydev->adjust_link)
312 phy_stop_machine(phydev); 312 phy_stop_machine(phydev);
313 313
314 if (!mdio_bus_phy_may_suspend(phydev)) 314 if (!mdio_bus_phy_may_suspend(phydev))
@@ -331,7 +331,7 @@ static int mdio_bus_resume(struct device *dev)
331 return ret; 331 return ret;
332 332
333no_resume: 333no_resume:
334 if (phydev->attached_dev) 334 if (phydev->attached_dev && phydev->adjust_link)
335 phy_start_machine(phydev, NULL); 335 phy_start_machine(phydev, NULL);
336 336
337 return 0; 337 return 0;
diff --git a/drivers/net/ppp_async.c b/drivers/net/ppp_async.c
index af50a530daee..78d70a6481bf 100644
--- a/drivers/net/ppp_async.c
+++ b/drivers/net/ppp_async.c
@@ -184,7 +184,7 @@ ppp_asynctty_open(struct tty_struct *tty)
184 tasklet_init(&ap->tsk, ppp_async_process, (unsigned long) ap); 184 tasklet_init(&ap->tsk, ppp_async_process, (unsigned long) ap);
185 185
186 atomic_set(&ap->refcnt, 1); 186 atomic_set(&ap->refcnt, 1);
187 init_MUTEX_LOCKED(&ap->dead_sem); 187 sema_init(&ap->dead_sem, 0);
188 188
189 ap->chan.private = ap; 189 ap->chan.private = ap;
190 ap->chan.ops = &async_ops; 190 ap->chan.ops = &async_ops;
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 323e81e9e808..4bddb2afdd15 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -1315,8 +1315,13 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1315 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN; 1315 hdrlen = (ppp->flags & SC_MP_XSHORTSEQ)? MPHDRLEN_SSN: MPHDRLEN;
1316 i = 0; 1316 i = 0;
1317 list_for_each_entry(pch, &ppp->channels, clist) { 1317 list_for_each_entry(pch, &ppp->channels, clist) {
1318 navail += pch->avail = (pch->chan != NULL); 1318 if (pch->chan) {
1319 pch->speed = pch->chan->speed; 1319 pch->avail = 1;
1320 navail++;
1321 pch->speed = pch->chan->speed;
1322 } else {
1323 pch->avail = 0;
1324 }
1320 if (pch->avail) { 1325 if (pch->avail) {
1321 if (skb_queue_empty(&pch->file.xq) || 1326 if (skb_queue_empty(&pch->file.xq) ||
1322 !pch->had_frag) { 1327 !pch->had_frag) {
diff --git a/drivers/net/qlcnic/qlcnic_init.c b/drivers/net/qlcnic/qlcnic_init.c
index 75ba744b173c..2c7cf0b64811 100644
--- a/drivers/net/qlcnic/qlcnic_init.c
+++ b/drivers/net/qlcnic/qlcnic_init.c
@@ -1316,7 +1316,7 @@ qlcnic_alloc_rx_skb(struct qlcnic_adapter *adapter,
1316 return -ENOMEM; 1316 return -ENOMEM;
1317 } 1317 }
1318 1318
1319 skb_reserve(skb, 2); 1319 skb_reserve(skb, NET_IP_ALIGN);
1320 1320
1321 dma = pci_map_single(pdev, skb->data, 1321 dma = pci_map_single(pdev, skb->data,
1322 rds_ring->dma_size, PCI_DMA_FROMDEVICE); 1322 rds_ring->dma_size, PCI_DMA_FROMDEVICE);
@@ -1404,7 +1404,6 @@ qlcnic_process_rcv(struct qlcnic_adapter *adapter,
1404 if (pkt_offset) 1404 if (pkt_offset)
1405 skb_pull(skb, pkt_offset); 1405 skb_pull(skb, pkt_offset);
1406 1406
1407 skb->truesize = skb->len + sizeof(struct sk_buff);
1408 skb->protocol = eth_type_trans(skb, netdev); 1407 skb->protocol = eth_type_trans(skb, netdev);
1409 1408
1410 napi_gro_receive(&sds_ring->napi, skb); 1409 napi_gro_receive(&sds_ring->napi, skb);
@@ -1466,8 +1465,6 @@ qlcnic_process_lro(struct qlcnic_adapter *adapter,
1466 1465
1467 skb_put(skb, lro_length + data_offset); 1466 skb_put(skb, lro_length + data_offset);
1468 1467
1469 skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb);
1470
1471 skb_pull(skb, l2_hdr_offset); 1468 skb_pull(skb, l2_hdr_offset);
1472 skb->protocol = eth_type_trans(skb, netdev); 1469 skb->protocol = eth_type_trans(skb, netdev);
1473 1470
@@ -1700,8 +1697,6 @@ qlcnic_process_rcv_diag(struct qlcnic_adapter *adapter,
1700 if (pkt_offset) 1697 if (pkt_offset)
1701 skb_pull(skb, pkt_offset); 1698 skb_pull(skb, pkt_offset);
1702 1699
1703 skb->truesize = skb->len + sizeof(struct sk_buff);
1704
1705 if (!qlcnic_check_loopback_buff(skb->data)) 1700 if (!qlcnic_check_loopback_buff(skb->data))
1706 adapter->diag_cnt++; 1701 adapter->diag_cnt++;
1707 1702
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 078bbf4e6f19..992db2fa136e 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -1212,7 +1212,8 @@ static void rtl8169_update_counters(struct net_device *dev)
1212 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) 1212 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0)
1213 return; 1213 return;
1214 1214
1215 counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr); 1215 counters = dma_alloc_coherent(&tp->pci_dev->dev, sizeof(*counters),
1216 &paddr, GFP_KERNEL);
1216 if (!counters) 1217 if (!counters)
1217 return; 1218 return;
1218 1219
@@ -1233,7 +1234,8 @@ static void rtl8169_update_counters(struct net_device *dev)
1233 RTL_W32(CounterAddrLow, 0); 1234 RTL_W32(CounterAddrLow, 0);
1234 RTL_W32(CounterAddrHigh, 0); 1235 RTL_W32(CounterAddrHigh, 0);
1235 1236
1236 pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr); 1237 dma_free_coherent(&tp->pci_dev->dev, sizeof(*counters), counters,
1238 paddr);
1237} 1239}
1238 1240
1239static void rtl8169_get_ethtool_stats(struct net_device *dev, 1241static void rtl8169_get_ethtool_stats(struct net_device *dev,
@@ -2934,7 +2936,7 @@ static const struct rtl_cfg_info {
2934 .hw_start = rtl_hw_start_8168, 2936 .hw_start = rtl_hw_start_8168,
2935 .region = 2, 2937 .region = 2,
2936 .align = 8, 2938 .align = 8,
2937 .intr_event = SYSErr | LinkChg | RxOverflow | 2939 .intr_event = SYSErr | RxFIFOOver | LinkChg | RxOverflow |
2938 TxErr | TxOK | RxOK | RxErr, 2940 TxErr | TxOK | RxOK | RxErr,
2939 .napi_event = TxErr | TxOK | RxOK | RxOverflow, 2941 .napi_event = TxErr | TxOK | RxOK | RxOverflow,
2940 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, 2942 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI,
@@ -3292,15 +3294,15 @@ static int rtl8169_open(struct net_device *dev)
3292 3294
3293 /* 3295 /*
3294 * Rx and Tx desscriptors needs 256 bytes alignment. 3296 * Rx and Tx desscriptors needs 256 bytes alignment.
3295 * pci_alloc_consistent provides more. 3297 * dma_alloc_coherent provides more.
3296 */ 3298 */
3297 tp->TxDescArray = pci_alloc_consistent(pdev, R8169_TX_RING_BYTES, 3299 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES,
3298 &tp->TxPhyAddr); 3300 &tp->TxPhyAddr, GFP_KERNEL);
3299 if (!tp->TxDescArray) 3301 if (!tp->TxDescArray)
3300 goto err_pm_runtime_put; 3302 goto err_pm_runtime_put;
3301 3303
3302 tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES, 3304 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES,
3303 &tp->RxPhyAddr); 3305 &tp->RxPhyAddr, GFP_KERNEL);
3304 if (!tp->RxDescArray) 3306 if (!tp->RxDescArray)
3305 goto err_free_tx_0; 3307 goto err_free_tx_0;
3306 3308
@@ -3334,12 +3336,12 @@ out:
3334err_release_ring_2: 3336err_release_ring_2:
3335 rtl8169_rx_clear(tp); 3337 rtl8169_rx_clear(tp);
3336err_free_rx_1: 3338err_free_rx_1:
3337 pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, 3339 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
3338 tp->RxPhyAddr); 3340 tp->RxPhyAddr);
3339 tp->RxDescArray = NULL; 3341 tp->RxDescArray = NULL;
3340err_free_tx_0: 3342err_free_tx_0:
3341 pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, 3343 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
3342 tp->TxPhyAddr); 3344 tp->TxPhyAddr);
3343 tp->TxDescArray = NULL; 3345 tp->TxDescArray = NULL;
3344err_pm_runtime_put: 3346err_pm_runtime_put:
3345 pm_runtime_put_noidle(&pdev->dev); 3347 pm_runtime_put_noidle(&pdev->dev);
@@ -3975,7 +3977,7 @@ static void rtl8169_free_rx_skb(struct rtl8169_private *tp,
3975{ 3977{
3976 struct pci_dev *pdev = tp->pci_dev; 3978 struct pci_dev *pdev = tp->pci_dev;
3977 3979
3978 pci_unmap_single(pdev, le64_to_cpu(desc->addr), tp->rx_buf_sz, 3980 dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz,
3979 PCI_DMA_FROMDEVICE); 3981 PCI_DMA_FROMDEVICE);
3980 dev_kfree_skb(*sk_buff); 3982 dev_kfree_skb(*sk_buff);
3981 *sk_buff = NULL; 3983 *sk_buff = NULL;
@@ -4000,7 +4002,7 @@ static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping,
4000static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev, 4002static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
4001 struct net_device *dev, 4003 struct net_device *dev,
4002 struct RxDesc *desc, int rx_buf_sz, 4004 struct RxDesc *desc, int rx_buf_sz,
4003 unsigned int align) 4005 unsigned int align, gfp_t gfp)
4004{ 4006{
4005 struct sk_buff *skb; 4007 struct sk_buff *skb;
4006 dma_addr_t mapping; 4008 dma_addr_t mapping;
@@ -4008,13 +4010,13 @@ static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev,
4008 4010
4009 pad = align ? align : NET_IP_ALIGN; 4011 pad = align ? align : NET_IP_ALIGN;
4010 4012
4011 skb = netdev_alloc_skb(dev, rx_buf_sz + pad); 4013 skb = __netdev_alloc_skb(dev, rx_buf_sz + pad, gfp);
4012 if (!skb) 4014 if (!skb)
4013 goto err_out; 4015 goto err_out;
4014 4016
4015 skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad); 4017 skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad);
4016 4018
4017 mapping = pci_map_single(pdev, skb->data, rx_buf_sz, 4019 mapping = dma_map_single(&pdev->dev, skb->data, rx_buf_sz,
4018 PCI_DMA_FROMDEVICE); 4020 PCI_DMA_FROMDEVICE);
4019 4021
4020 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); 4022 rtl8169_map_to_asic(desc, mapping, rx_buf_sz);
@@ -4039,7 +4041,7 @@ static void rtl8169_rx_clear(struct rtl8169_private *tp)
4039} 4041}
4040 4042
4041static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev, 4043static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
4042 u32 start, u32 end) 4044 u32 start, u32 end, gfp_t gfp)
4043{ 4045{
4044 u32 cur; 4046 u32 cur;
4045 4047
@@ -4054,7 +4056,7 @@ static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev,
4054 4056
4055 skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev, 4057 skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev,
4056 tp->RxDescArray + i, 4058 tp->RxDescArray + i,
4057 tp->rx_buf_sz, tp->align); 4059 tp->rx_buf_sz, tp->align, gfp);
4058 if (!skb) 4060 if (!skb)
4059 break; 4061 break;
4060 4062
@@ -4082,7 +4084,7 @@ static int rtl8169_init_ring(struct net_device *dev)
4082 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); 4084 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info));
4083 memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *)); 4085 memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *));
4084 4086
4085 if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC) 4087 if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC, GFP_KERNEL) != NUM_RX_DESC)
4086 goto err_out; 4088 goto err_out;
4087 4089
4088 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); 4090 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1);
@@ -4099,7 +4101,8 @@ static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb,
4099{ 4101{
4100 unsigned int len = tx_skb->len; 4102 unsigned int len = tx_skb->len;
4101 4103
4102 pci_unmap_single(pdev, le64_to_cpu(desc->addr), len, PCI_DMA_TODEVICE); 4104 dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), len,
4105 PCI_DMA_TODEVICE);
4103 desc->opts1 = 0x00; 4106 desc->opts1 = 0x00;
4104 desc->opts2 = 0x00; 4107 desc->opts2 = 0x00;
4105 desc->addr = 0x00; 4108 desc->addr = 0x00;
@@ -4243,7 +4246,8 @@ static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb,
4243 txd = tp->TxDescArray + entry; 4246 txd = tp->TxDescArray + entry;
4244 len = frag->size; 4247 len = frag->size;
4245 addr = ((void *) page_address(frag->page)) + frag->page_offset; 4248 addr = ((void *) page_address(frag->page)) + frag->page_offset;
4246 mapping = pci_map_single(tp->pci_dev, addr, len, PCI_DMA_TODEVICE); 4249 mapping = dma_map_single(&tp->pci_dev->dev, addr, len,
4250 PCI_DMA_TODEVICE);
4247 4251
4248 /* anti gcc 2.95.3 bugware (sic) */ 4252 /* anti gcc 2.95.3 bugware (sic) */
4249 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); 4253 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC));
@@ -4313,7 +4317,8 @@ static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb,
4313 tp->tx_skb[entry].skb = skb; 4317 tp->tx_skb[entry].skb = skb;
4314 } 4318 }
4315 4319
4316 mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE); 4320 mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len,
4321 PCI_DMA_TODEVICE);
4317 4322
4318 tp->tx_skb[entry].len = len; 4323 tp->tx_skb[entry].len = len;
4319 txd->addr = cpu_to_le64(mapping); 4324 txd->addr = cpu_to_le64(mapping);
@@ -4477,8 +4482,8 @@ static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff,
4477 if (!skb) 4482 if (!skb)
4478 goto out; 4483 goto out;
4479 4484
4480 pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size, 4485 dma_sync_single_for_cpu(&tp->pci_dev->dev, addr, pkt_size,
4481 PCI_DMA_FROMDEVICE); 4486 PCI_DMA_FROMDEVICE);
4482 skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size); 4487 skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size);
4483 *sk_buff = skb; 4488 *sk_buff = skb;
4484 done = true; 4489 done = true;
@@ -4549,11 +4554,11 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
4549 rtl8169_rx_csum(skb, desc); 4554 rtl8169_rx_csum(skb, desc);
4550 4555
4551 if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) { 4556 if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) {
4552 pci_dma_sync_single_for_device(pdev, addr, 4557 dma_sync_single_for_device(&pdev->dev, addr,
4553 pkt_size, PCI_DMA_FROMDEVICE); 4558 pkt_size, PCI_DMA_FROMDEVICE);
4554 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); 4559 rtl8169_mark_to_asic(desc, tp->rx_buf_sz);
4555 } else { 4560 } else {
4556 pci_unmap_single(pdev, addr, tp->rx_buf_sz, 4561 dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz,
4557 PCI_DMA_FROMDEVICE); 4562 PCI_DMA_FROMDEVICE);
4558 tp->Rx_skbuff[entry] = NULL; 4563 tp->Rx_skbuff[entry] = NULL;
4559 } 4564 }
@@ -4583,7 +4588,7 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
4583 count = cur_rx - tp->cur_rx; 4588 count = cur_rx - tp->cur_rx;
4584 tp->cur_rx = cur_rx; 4589 tp->cur_rx = cur_rx;
4585 4590
4586 delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx); 4591 delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx, GFP_ATOMIC);
4587 if (!delta && count) 4592 if (!delta && count)
4588 netif_info(tp, intr, dev, "no Rx buffer allocated\n"); 4593 netif_info(tp, intr, dev, "no Rx buffer allocated\n");
4589 tp->dirty_rx += delta; 4594 tp->dirty_rx += delta;
@@ -4625,8 +4630,7 @@ static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance)
4625 } 4630 }
4626 4631
4627 /* Work around for rx fifo overflow */ 4632 /* Work around for rx fifo overflow */
4628 if (unlikely(status & RxFIFOOver) && 4633 if (unlikely(status & RxFIFOOver)) {
4629 (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
4630 netif_stop_queue(dev); 4634 netif_stop_queue(dev);
4631 rtl8169_tx_timeout(dev); 4635 rtl8169_tx_timeout(dev);
4632 break; 4636 break;
@@ -4770,10 +4774,10 @@ static int rtl8169_close(struct net_device *dev)
4770 4774
4771 free_irq(dev->irq, dev); 4775 free_irq(dev->irq, dev);
4772 4776
4773 pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, 4777 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray,
4774 tp->RxPhyAddr); 4778 tp->RxPhyAddr);
4775 pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, 4779 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray,
4776 tp->TxPhyAddr); 4780 tp->TxPhyAddr);
4777 tp->TxDescArray = NULL; 4781 tp->TxDescArray = NULL;
4778 tp->RxDescArray = NULL; 4782 tp->RxDescArray = NULL;
4779 4783
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
index 07eb884ff982..44150f2f7bfd 100644
--- a/drivers/net/rionet.c
+++ b/drivers/net/rionet.c
@@ -384,7 +384,7 @@ static void rionet_remove(struct rio_dev *rdev)
384 free_pages((unsigned long)rionet_active, rdev->net->hport->sys_size ? 384 free_pages((unsigned long)rionet_active, rdev->net->hport->sys_size ?
385 __ilog2(sizeof(void *)) + 4 : 0); 385 __ilog2(sizeof(void *)) + 4 : 0);
386 unregister_netdev(ndev); 386 unregister_netdev(ndev);
387 kfree(ndev); 387 free_netdev(ndev);
388 388
389 list_for_each_entry_safe(peer, tmp, &rionet_peers, node) { 389 list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
390 list_del(&peer->node); 390 list_del(&peer->node);
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index cc4bd8c65f8b..9265315baa0b 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -804,7 +804,7 @@ static int __devinit sgiseeq_probe(struct platform_device *pdev)
804err_out_free_page: 804err_out_free_page:
805 free_page((unsigned long) sp->srings); 805 free_page((unsigned long) sp->srings);
806err_out_free_dev: 806err_out_free_dev:
807 kfree(dev); 807 free_netdev(dev);
808 808
809err_out: 809err_out:
810 return err; 810 return err;
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 40e5c46e7571..465ae7e84507 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -43,6 +43,7 @@
43#include <linux/seq_file.h> 43#include <linux/seq_file.h>
44#include <linux/mii.h> 44#include <linux/mii.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/dmi.h>
46#include <asm/irq.h> 47#include <asm/irq.h>
47 48
48#include "skge.h" 49#include "skge.h"
@@ -3868,6 +3869,8 @@ static void __devinit skge_show_addr(struct net_device *dev)
3868 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr); 3869 netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
3869} 3870}
3870 3871
3872static int only_32bit_dma;
3873
3871static int __devinit skge_probe(struct pci_dev *pdev, 3874static int __devinit skge_probe(struct pci_dev *pdev,
3872 const struct pci_device_id *ent) 3875 const struct pci_device_id *ent)
3873{ 3876{
@@ -3889,7 +3892,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
3889 3892
3890 pci_set_master(pdev); 3893 pci_set_master(pdev);
3891 3894
3892 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { 3895 if (!only_32bit_dma && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
3893 using_dac = 1; 3896 using_dac = 1;
3894 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 3897 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
3895 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) { 3898 } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
@@ -4147,8 +4150,21 @@ static struct pci_driver skge_driver = {
4147 .shutdown = skge_shutdown, 4150 .shutdown = skge_shutdown,
4148}; 4151};
4149 4152
4153static struct dmi_system_id skge_32bit_dma_boards[] = {
4154 {
4155 .ident = "Gigabyte nForce boards",
4156 .matches = {
4157 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co"),
4158 DMI_MATCH(DMI_BOARD_NAME, "nForce"),
4159 },
4160 },
4161 {}
4162};
4163
4150static int __init skge_init_module(void) 4164static int __init skge_init_module(void)
4151{ 4165{
4166 if (dmi_check_system(skge_32bit_dma_boards))
4167 only_32bit_dma = 1;
4152 skge_debug_init(); 4168 skge_debug_init();
4153 return pci_register_driver(&skge_driver); 4169 return pci_register_driver(&skge_driver);
4154} 4170}
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index 10cf0cbc2185..726df611ee17 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -72,6 +72,7 @@ static const char version[] =
72#include <linux/sched.h> 72#include <linux/sched.h>
73#include <linux/delay.h> 73#include <linux/delay.h>
74#include <linux/interrupt.h> 74#include <linux/interrupt.h>
75#include <linux/irq.h>
75#include <linux/errno.h> 76#include <linux/errno.h>
76#include <linux/ioport.h> 77#include <linux/ioport.h>
77#include <linux/crc32.h> 78#include <linux/crc32.h>
diff --git a/drivers/net/smsc911x.c b/drivers/net/smsc911x.c
index 0909ae934ad0..8150ba154116 100644
--- a/drivers/net/smsc911x.c
+++ b/drivers/net/smsc911x.c
@@ -58,6 +58,7 @@
58 58
59MODULE_LICENSE("GPL"); 59MODULE_LICENSE("GPL");
60MODULE_VERSION(SMSC_DRV_VERSION); 60MODULE_VERSION(SMSC_DRV_VERSION);
61MODULE_ALIAS("platform:smsc911x");
61 62
62#if USE_DEBUG > 0 63#if USE_DEBUG > 0
63static int debug = 16; 64static int debug = 16;
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index bc3af78a869f..1ec4b9e0239a 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -4666,7 +4666,7 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
4666 desc_idx, *post_ptr); 4666 desc_idx, *post_ptr);
4667 drop_it_no_recycle: 4667 drop_it_no_recycle:
4668 /* Other statistics kept track of by card. */ 4668 /* Other statistics kept track of by card. */
4669 tp->net_stats.rx_dropped++; 4669 tp->rx_dropped++;
4670 goto next_pkt; 4670 goto next_pkt;
4671 } 4671 }
4672 4672
@@ -4726,7 +4726,7 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
4726 if (len > (tp->dev->mtu + ETH_HLEN) && 4726 if (len > (tp->dev->mtu + ETH_HLEN) &&
4727 skb->protocol != htons(ETH_P_8021Q)) { 4727 skb->protocol != htons(ETH_P_8021Q)) {
4728 dev_kfree_skb(skb); 4728 dev_kfree_skb(skb);
4729 goto next_pkt; 4729 goto drop_it_no_recycle;
4730 } 4730 }
4731 4731
4732 if (desc->type_flags & RXD_FLAG_VLAN && 4732 if (desc->type_flags & RXD_FLAG_VLAN &&
@@ -9240,6 +9240,8 @@ static struct rtnl_link_stats64 *tg3_get_stats64(struct net_device *dev,
9240 stats->rx_missed_errors = old_stats->rx_missed_errors + 9240 stats->rx_missed_errors = old_stats->rx_missed_errors +
9241 get_stat64(&hw_stats->rx_discards); 9241 get_stat64(&hw_stats->rx_discards);
9242 9242
9243 stats->rx_dropped = tp->rx_dropped;
9244
9243 return stats; 9245 return stats;
9244} 9246}
9245 9247
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 4937bd190964..be7ff138a7f9 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2759,7 +2759,7 @@ struct tg3 {
2759 2759
2760 2760
2761 /* begin "everything else" cacheline(s) section */ 2761 /* begin "everything else" cacheline(s) section */
2762 struct rtnl_link_stats64 net_stats; 2762 unsigned long rx_dropped;
2763 struct rtnl_link_stats64 net_stats_prev; 2763 struct rtnl_link_stats64 net_stats_prev;
2764 struct tg3_ethtool_stats estats; 2764 struct tg3_ethtool_stats estats;
2765 struct tg3_ethtool_stats estats_prev; 2765 struct tg3_ethtool_stats estats_prev;
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index 5efa57757a2c..6888e3d41462 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -243,6 +243,7 @@ enum {
243 NWayState = (1 << 14) | (1 << 13) | (1 << 12), 243 NWayState = (1 << 14) | (1 << 13) | (1 << 12),
244 NWayRestart = (1 << 12), 244 NWayRestart = (1 << 12),
245 NonselPortActive = (1 << 9), 245 NonselPortActive = (1 << 9),
246 SelPortActive = (1 << 8),
246 LinkFailStatus = (1 << 2), 247 LinkFailStatus = (1 << 2),
247 NetCxnErr = (1 << 1), 248 NetCxnErr = (1 << 1),
248}; 249};
@@ -363,7 +364,9 @@ static u16 t21040_csr15[] = { 0, 0, 0x0006, 0x0000, 0x0000, };
363 364
364/* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/ 365/* 21041 transceiver register settings: TP AUTO, BNC, AUI, TP, TP FD*/
365static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, }; 366static u16 t21041_csr13[] = { 0xEF01, 0xEF09, 0xEF09, 0xEF01, 0xEF09, };
366static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x6F3F, 0x6F3D, }; 367static u16 t21041_csr14[] = { 0xFFFF, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
368/* If on-chip autonegotiation is broken, use half-duplex (FF3F) instead */
369static u16 t21041_csr14_brk[] = { 0xFF3F, 0xF7FD, 0xF7FD, 0x7F3F, 0x7F3D, };
367static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, }; 370static u16 t21041_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
368 371
369 372
@@ -1064,6 +1067,9 @@ static void de21041_media_timer (unsigned long data)
1064 unsigned int carrier; 1067 unsigned int carrier;
1065 unsigned long flags; 1068 unsigned long flags;
1066 1069
1070 /* clear port active bits */
1071 dw32(SIAStatus, NonselPortActive | SelPortActive);
1072
1067 carrier = (status & NetCxnErr) ? 0 : 1; 1073 carrier = (status & NetCxnErr) ? 0 : 1;
1068 1074
1069 if (carrier) { 1075 if (carrier) {
@@ -1158,14 +1164,29 @@ no_link_yet:
1158static void de_media_interrupt (struct de_private *de, u32 status) 1164static void de_media_interrupt (struct de_private *de, u32 status)
1159{ 1165{
1160 if (status & LinkPass) { 1166 if (status & LinkPass) {
1167 /* Ignore if current media is AUI or BNC and we can't use TP */
1168 if ((de->media_type == DE_MEDIA_AUI ||
1169 de->media_type == DE_MEDIA_BNC) &&
1170 (de->media_lock ||
1171 !de_ok_to_advertise(de, DE_MEDIA_TP_AUTO)))
1172 return;
1173 /* If current media is not TP, change it to TP */
1174 if ((de->media_type == DE_MEDIA_AUI ||
1175 de->media_type == DE_MEDIA_BNC)) {
1176 de->media_type = DE_MEDIA_TP_AUTO;
1177 de_stop_rxtx(de);
1178 de_set_media(de);
1179 de_start_rxtx(de);
1180 }
1161 de_link_up(de); 1181 de_link_up(de);
1162 mod_timer(&de->media_timer, jiffies + DE_TIMER_LINK); 1182 mod_timer(&de->media_timer, jiffies + DE_TIMER_LINK);
1163 return; 1183 return;
1164 } 1184 }
1165 1185
1166 BUG_ON(!(status & LinkFail)); 1186 BUG_ON(!(status & LinkFail));
1167 1187 /* Mark the link as down only if current media is TP */
1168 if (netif_carrier_ok(de->dev)) { 1188 if (netif_carrier_ok(de->dev) && de->media_type != DE_MEDIA_AUI &&
1189 de->media_type != DE_MEDIA_BNC) {
1169 de_link_down(de); 1190 de_link_down(de);
1170 mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK); 1191 mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK);
1171 } 1192 }
@@ -1229,6 +1250,7 @@ static void de_adapter_sleep (struct de_private *de)
1229 if (de->de21040) 1250 if (de->de21040)
1230 return; 1251 return;
1231 1252
1253 dw32(CSR13, 0); /* Reset phy */
1232 pci_read_config_dword(de->pdev, PCIPM, &pmctl); 1254 pci_read_config_dword(de->pdev, PCIPM, &pmctl);
1233 pmctl |= PM_Sleep; 1255 pmctl |= PM_Sleep;
1234 pci_write_config_dword(de->pdev, PCIPM, pmctl); 1256 pci_write_config_dword(de->pdev, PCIPM, pmctl);
@@ -1574,12 +1596,15 @@ static int __de_set_settings(struct de_private *de, struct ethtool_cmd *ecmd)
1574 return 0; /* nothing to change */ 1596 return 0; /* nothing to change */
1575 1597
1576 de_link_down(de); 1598 de_link_down(de);
1599 mod_timer(&de->media_timer, jiffies + DE_TIMER_NO_LINK);
1577 de_stop_rxtx(de); 1600 de_stop_rxtx(de);
1578 1601
1579 de->media_type = new_media; 1602 de->media_type = new_media;
1580 de->media_lock = media_lock; 1603 de->media_lock = media_lock;
1581 de->media_advertise = ecmd->advertising; 1604 de->media_advertise = ecmd->advertising;
1582 de_set_media(de); 1605 de_set_media(de);
1606 if (netif_running(de->dev))
1607 de_start_rxtx(de);
1583 1608
1584 return 0; 1609 return 0;
1585} 1610}
@@ -1911,8 +1936,14 @@ fill_defaults:
1911 for (i = 0; i < DE_MAX_MEDIA; i++) { 1936 for (i = 0; i < DE_MAX_MEDIA; i++) {
1912 if (de->media[i].csr13 == 0xffff) 1937 if (de->media[i].csr13 == 0xffff)
1913 de->media[i].csr13 = t21041_csr13[i]; 1938 de->media[i].csr13 = t21041_csr13[i];
1914 if (de->media[i].csr14 == 0xffff) 1939 if (de->media[i].csr14 == 0xffff) {
1915 de->media[i].csr14 = t21041_csr14[i]; 1940 /* autonegotiation is broken at least on some chip
1941 revisions - rev. 0x21 works, 0x11 does not */
1942 if (de->pdev->revision < 0x20)
1943 de->media[i].csr14 = t21041_csr14_brk[i];
1944 else
1945 de->media[i].csr14 = t21041_csr14[i];
1946 }
1916 if (de->media[i].csr15 == 0xffff) 1947 if (de->media[i].csr15 == 0xffff)
1917 de->media[i].csr15 = t21041_csr15[i]; 1948 de->media[i].csr15 = t21041_csr15[i];
1918 } 1949 }
@@ -2158,6 +2189,8 @@ static int de_resume (struct pci_dev *pdev)
2158 dev_err(&dev->dev, "pci_enable_device failed in resume\n"); 2189 dev_err(&dev->dev, "pci_enable_device failed in resume\n");
2159 goto out; 2190 goto out;
2160 } 2191 }
2192 pci_set_master(pdev);
2193 de_init_rings(de);
2161 de_init_hw(de); 2194 de_init_hw(de);
2162out_attach: 2195out_attach:
2163 netif_device_attach(dev); 2196 netif_device_attach(dev);
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 6efca66b8766..1cd752f9a6e1 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1652,6 +1652,8 @@ static int hso_get_count(struct hso_serial *serial,
1652 struct uart_icount cnow; 1652 struct uart_icount cnow;
1653 struct hso_tiocmget *tiocmget = serial->tiocmget; 1653 struct hso_tiocmget *tiocmget = serial->tiocmget;
1654 1654
1655 memset(&icount, 0, sizeof(struct serial_icounter_struct));
1656
1655 if (!tiocmget) 1657 if (!tiocmget)
1656 return -ENOENT; 1658 return -ENOENT;
1657 spin_lock_irq(&serial->serial_lock); 1659 spin_lock_irq(&serial->serial_lock);
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 04c6cd4333f1..10bafd59f9c3 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -575,7 +575,7 @@ static int cosa_probe(int base, int irq, int dma)
575 575
576 /* Initialize the chardev data structures */ 576 /* Initialize the chardev data structures */
577 mutex_init(&chan->rlock); 577 mutex_init(&chan->rlock);
578 init_MUTEX(&chan->wsem); 578 sema_init(&chan->wsem, 1);
579 579
580 /* Register the network interface */ 580 /* Register the network interface */
581 if (!(chan->netdev = alloc_hdlcdev(chan))) { 581 if (!(chan->netdev = alloc_hdlcdev(chan))) {
diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
index 8cc9e319f435..1737d1488b35 100644
--- a/drivers/net/wimax/i2400m/rx.c
+++ b/drivers/net/wimax/i2400m/rx.c
@@ -1244,16 +1244,16 @@ int i2400m_rx(struct i2400m *i2400m, struct sk_buff *skb)
1244 int i, result; 1244 int i, result;
1245 struct device *dev = i2400m_dev(i2400m); 1245 struct device *dev = i2400m_dev(i2400m);
1246 const struct i2400m_msg_hdr *msg_hdr; 1246 const struct i2400m_msg_hdr *msg_hdr;
1247 size_t pl_itr, pl_size, skb_len; 1247 size_t pl_itr, pl_size;
1248 unsigned long flags; 1248 unsigned long flags;
1249 unsigned num_pls, single_last; 1249 unsigned num_pls, single_last, skb_len;
1250 1250
1251 skb_len = skb->len; 1251 skb_len = skb->len;
1252 d_fnstart(4, dev, "(i2400m %p skb %p [size %zu])\n", 1252 d_fnstart(4, dev, "(i2400m %p skb %p [size %u])\n",
1253 i2400m, skb, skb_len); 1253 i2400m, skb, skb_len);
1254 result = -EIO; 1254 result = -EIO;
1255 msg_hdr = (void *) skb->data; 1255 msg_hdr = (void *) skb->data;
1256 result = i2400m_rx_msg_hdr_check(i2400m, msg_hdr, skb->len); 1256 result = i2400m_rx_msg_hdr_check(i2400m, msg_hdr, skb_len);
1257 if (result < 0) 1257 if (result < 0)
1258 goto error_msg_hdr_check; 1258 goto error_msg_hdr_check;
1259 result = -EIO; 1259 result = -EIO;
@@ -1261,10 +1261,10 @@ int i2400m_rx(struct i2400m *i2400m, struct sk_buff *skb)
1261 pl_itr = sizeof(*msg_hdr) + /* Check payload descriptor(s) */ 1261 pl_itr = sizeof(*msg_hdr) + /* Check payload descriptor(s) */
1262 num_pls * sizeof(msg_hdr->pld[0]); 1262 num_pls * sizeof(msg_hdr->pld[0]);
1263 pl_itr = ALIGN(pl_itr, I2400M_PL_ALIGN); 1263 pl_itr = ALIGN(pl_itr, I2400M_PL_ALIGN);
1264 if (pl_itr > skb->len) { /* got all the payload descriptors? */ 1264 if (pl_itr > skb_len) { /* got all the payload descriptors? */
1265 dev_err(dev, "RX: HW BUG? message too short (%u bytes) for " 1265 dev_err(dev, "RX: HW BUG? message too short (%u bytes) for "
1266 "%u payload descriptors (%zu each, total %zu)\n", 1266 "%u payload descriptors (%zu each, total %zu)\n",
1267 skb->len, num_pls, sizeof(msg_hdr->pld[0]), pl_itr); 1267 skb_len, num_pls, sizeof(msg_hdr->pld[0]), pl_itr);
1268 goto error_pl_descr_short; 1268 goto error_pl_descr_short;
1269 } 1269 }
1270 /* Walk each payload payload--check we really got it */ 1270 /* Walk each payload payload--check we really got it */
@@ -1272,7 +1272,7 @@ int i2400m_rx(struct i2400m *i2400m, struct sk_buff *skb)
1272 /* work around old gcc warnings */ 1272 /* work around old gcc warnings */
1273 pl_size = i2400m_pld_size(&msg_hdr->pld[i]); 1273 pl_size = i2400m_pld_size(&msg_hdr->pld[i]);
1274 result = i2400m_rx_pl_descr_check(i2400m, &msg_hdr->pld[i], 1274 result = i2400m_rx_pl_descr_check(i2400m, &msg_hdr->pld[i],
1275 pl_itr, skb->len); 1275 pl_itr, skb_len);
1276 if (result < 0) 1276 if (result < 0)
1277 goto error_pl_descr_check; 1277 goto error_pl_descr_check;
1278 single_last = num_pls == 1 || i == num_pls - 1; 1278 single_last = num_pls == 1 || i == num_pls - 1;
@@ -1290,16 +1290,16 @@ int i2400m_rx(struct i2400m *i2400m, struct sk_buff *skb)
1290 if (i < i2400m->rx_pl_min) 1290 if (i < i2400m->rx_pl_min)
1291 i2400m->rx_pl_min = i; 1291 i2400m->rx_pl_min = i;
1292 i2400m->rx_num++; 1292 i2400m->rx_num++;
1293 i2400m->rx_size_acc += skb->len; 1293 i2400m->rx_size_acc += skb_len;
1294 if (skb->len < i2400m->rx_size_min) 1294 if (skb_len < i2400m->rx_size_min)
1295 i2400m->rx_size_min = skb->len; 1295 i2400m->rx_size_min = skb_len;
1296 if (skb->len > i2400m->rx_size_max) 1296 if (skb_len > i2400m->rx_size_max)
1297 i2400m->rx_size_max = skb->len; 1297 i2400m->rx_size_max = skb_len;
1298 spin_unlock_irqrestore(&i2400m->rx_lock, flags); 1298 spin_unlock_irqrestore(&i2400m->rx_lock, flags);
1299error_pl_descr_check: 1299error_pl_descr_check:
1300error_pl_descr_short: 1300error_pl_descr_short:
1301error_msg_hdr_check: 1301error_msg_hdr_check:
1302 d_fnend(4, dev, "(i2400m %p skb %p [size %zu]) = %d\n", 1302 d_fnend(4, dev, "(i2400m %p skb %p [size %u]) = %d\n",
1303 i2400m, skb, skb_len, result); 1303 i2400m, skb, skb_len, result);
1304 return result; 1304 return result;
1305} 1305}
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index 9a121a5b787c..df2484d45474 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -32,7 +32,6 @@
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/netdevice.h> 33#include <linux/netdevice.h>
34 34
35#include <pcmcia/cs.h>
36#include <pcmcia/cistpl.h> 35#include <pcmcia/cistpl.h>
37#include <pcmcia/cisreg.h> 36#include <pcmcia/cisreg.h>
38#include <pcmcia/ds.h> 37#include <pcmcia/ds.h>
@@ -54,58 +53,21 @@ MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340 PCMCIA cards");
54 53
55/*====================================================================*/ 54/*====================================================================*/
56 55
57/*
58 The event() function is this driver's Card Services event handler.
59 It will be called by Card Services when an appropriate card status
60 event is received. The config() and release() entry points are
61 used to configure or release a socket, in response to card
62 insertion and ejection events. They are invoked from the airo_cs
63 event handler.
64*/
65
66static int airo_config(struct pcmcia_device *link); 56static int airo_config(struct pcmcia_device *link);
67static void airo_release(struct pcmcia_device *link); 57static void airo_release(struct pcmcia_device *link);
68 58
69/*
70 The attach() and detach() entry points are used to create and destroy
71 "instances" of the driver, where each instance represents everything
72 needed to manage one actual PCMCIA card.
73*/
74
75static void airo_detach(struct pcmcia_device *p_dev); 59static void airo_detach(struct pcmcia_device *p_dev);
76 60
77typedef struct local_info_t { 61typedef struct local_info_t {
78 struct net_device *eth_dev; 62 struct net_device *eth_dev;
79} local_info_t; 63} local_info_t;
80 64
81/*======================================================================
82
83 airo_attach() creates an "instance" of the driver, allocating
84 local data structures for one device. The device is registered
85 with Card Services.
86
87 The dev_link structure is initialized, but we don't actually
88 configure the card at this point -- we wait until we receive a
89 card insertion event.
90
91 ======================================================================*/
92
93static int airo_probe(struct pcmcia_device *p_dev) 65static int airo_probe(struct pcmcia_device *p_dev)
94{ 66{
95 local_info_t *local; 67 local_info_t *local;
96 68
97 dev_dbg(&p_dev->dev, "airo_attach()\n"); 69 dev_dbg(&p_dev->dev, "airo_attach()\n");
98 70
99 /*
100 General socket configuration defaults can go here. In this
101 client, we assume very little, and rely on the CIS for almost
102 everything. In most clients, many details (i.e., number, sizes,
103 and attributes of IO windows) are fixed by the nature of the
104 device, and can be hard-wired here.
105 */
106 p_dev->conf.Attributes = 0;
107 p_dev->conf.IntType = INT_MEMORY_AND_IO;
108
109 /* Allocate space for private device-specific data */ 71 /* Allocate space for private device-specific data */
110 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 72 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
111 if (!local) { 73 if (!local) {
@@ -117,15 +79,6 @@ static int airo_probe(struct pcmcia_device *p_dev)
117 return airo_config(p_dev); 79 return airo_config(p_dev);
118} /* airo_attach */ 80} /* airo_attach */
119 81
120/*======================================================================
121
122 This deletes a driver "instance". The device is de-registered
123 with Card Services. If it has been released, all local data
124 structures are freed. Otherwise, the structures will be freed
125 when the device is released.
126
127 ======================================================================*/
128
129static void airo_detach(struct pcmcia_device *link) 82static void airo_detach(struct pcmcia_device *link)
130{ 83{
131 dev_dbg(&link->dev, "airo_detach\n"); 84 dev_dbg(&link->dev, "airo_detach\n");
@@ -140,60 +93,12 @@ static void airo_detach(struct pcmcia_device *link)
140 kfree(link->priv); 93 kfree(link->priv);
141} /* airo_detach */ 94} /* airo_detach */
142 95
143/*====================================================================== 96static int airo_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
144
145 airo_config() is scheduled to run after a CARD_INSERTION event
146 is received, to configure the PCMCIA socket, and to make the
147 device available to the system.
148
149 ======================================================================*/
150
151static int airo_cs_config_check(struct pcmcia_device *p_dev,
152 cistpl_cftable_entry_t *cfg,
153 cistpl_cftable_entry_t *dflt,
154 unsigned int vcc,
155 void *priv_data)
156{ 97{
157 if (cfg->index == 0) 98 if (p_dev->config_index == 0)
158 return -ENODEV; 99 return -EINVAL;
159
160 /* Does this card need audio output? */
161 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
162 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
163 p_dev->conf.Status = CCSR_AUDIO_ENA;
164 }
165
166 /* Use power settings for Vcc and Vpp if present */
167 /* Note that the CIS values need to be rescaled */
168 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
169 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
170 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
171 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
172
173 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
174
175 /* IO window settings */
176 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
177 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
178 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
179 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
180 p_dev->resource[0]->flags |=
181 pcmcia_io_cfg_data_width(io->flags);
182 p_dev->resource[0]->start = io->win[0].base;
183 p_dev->resource[0]->end = io->win[0].len;
184 if (io->nwin > 1) {
185 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
186 p_dev->resource[1]->start = io->win[1].base;
187 p_dev->resource[1]->end = io->win[1].len;
188 }
189 }
190 100
191 /* This reserves IO space but doesn't actually enable it */ 101 return pcmcia_request_io(p_dev);
192 if (pcmcia_request_io(p_dev) != 0)
193 return -ENODEV;
194
195 /* If we got this far, we're cool! */
196 return 0;
197} 102}
198 103
199 104
@@ -206,20 +111,9 @@ static int airo_config(struct pcmcia_device *link)
206 111
207 dev_dbg(&link->dev, "airo_config\n"); 112 dev_dbg(&link->dev, "airo_config\n");
208 113
209 /* 114 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
210 * In this loop, we scan the CIS for configuration table 115 CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
211 * entries, each of which describes a valid card 116
212 * configuration, including voltage, IO window, memory window,
213 * and interrupt settings.
214 *
215 * We make no assumptions about the card to be configured: we
216 * use just the information available in the CIS. In an ideal
217 * world, this would work for any PCMCIA card, but it requires
218 * a complete and accurate CIS. In practice, a driver usually
219 * "knows" most of these things without consulting the CIS,
220 * and most client drivers will only use the CIS to fill in
221 * implementation-defined details.
222 */
223 ret = pcmcia_loop_config(link, airo_cs_config_check, NULL); 117 ret = pcmcia_loop_config(link, airo_cs_config_check, NULL);
224 if (ret) 118 if (ret)
225 goto failed; 119 goto failed;
@@ -227,12 +121,7 @@ static int airo_config(struct pcmcia_device *link)
227 if (!link->irq) 121 if (!link->irq)
228 goto failed; 122 goto failed;
229 123
230 /* 124 ret = pcmcia_enable_device(link);
231 This actually configures the PCMCIA socket -- setting up
232 the I/O windows and the interrupt mapping, and putting the
233 card and host interface into "Memory and IO" mode.
234 */
235 ret = pcmcia_request_configuration(link, &link->conf);
236 if (ret) 125 if (ret)
237 goto failed; 126 goto failed;
238 ((local_info_t *)link->priv)->eth_dev = 127 ((local_info_t *)link->priv)->eth_dev =
@@ -241,17 +130,6 @@ static int airo_config(struct pcmcia_device *link)
241 if (!((local_info_t *)link->priv)->eth_dev) 130 if (!((local_info_t *)link->priv)->eth_dev)
242 goto failed; 131 goto failed;
243 132
244 /* Finally, report what we've done */
245 dev_info(&link->dev, "index 0x%02x: ",
246 link->conf.ConfigIndex);
247 if (link->conf.Vpp)
248 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
249 printk(", irq %d", link->irq);
250 if (link->resource[0])
251 printk(" & %pR", link->resource[0]);
252 if (link->resource[1])
253 printk(" & %pR", link->resource[1]);
254 printk("\n");
255 return 0; 133 return 0;
256 134
257 failed: 135 failed:
@@ -259,14 +137,6 @@ static int airo_config(struct pcmcia_device *link)
259 return -ENODEV; 137 return -ENODEV;
260} /* airo_config */ 138} /* airo_config */
261 139
262/*======================================================================
263
264 After a card is removed, airo_release() will unregister the
265 device, and release the PCMCIA configuration. If the device is
266 still open, this will be postponed until it is closed.
267
268 ======================================================================*/
269
270static void airo_release(struct pcmcia_device *link) 140static void airo_release(struct pcmcia_device *link)
271{ 141{
272 dev_dbg(&link->dev, "airo_release\n"); 142 dev_dbg(&link->dev, "airo_release\n");
@@ -305,9 +175,7 @@ MODULE_DEVICE_TABLE(pcmcia, airo_ids);
305 175
306static struct pcmcia_driver airo_driver = { 176static struct pcmcia_driver airo_driver = {
307 .owner = THIS_MODULE, 177 .owner = THIS_MODULE,
308 .drv = { 178 .name = "airo_cs",
309 .name = "airo_cs",
310 },
311 .probe = airo_probe, 179 .probe = airo_probe,
312 .remove = airo_detach, 180 .remove = airo_detach,
313 .id_table = airo_ids, 181 .id_table = airo_ids,
@@ -315,12 +183,12 @@ static struct pcmcia_driver airo_driver = {
315 .resume = airo_resume, 183 .resume = airo_resume,
316}; 184};
317 185
318static int airo_cs_init(void) 186static int __init airo_cs_init(void)
319{ 187{
320 return pcmcia_register_driver(&airo_driver); 188 return pcmcia_register_driver(&airo_driver);
321} 189}
322 190
323static void airo_cs_cleanup(void) 191static void __exit airo_cs_cleanup(void)
324{ 192{
325 pcmcia_unregister_driver(&airo_driver); 193 pcmcia_unregister_driver(&airo_driver);
326} 194}
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index cc648b6ae31c..a3d95cca8f0c 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -543,7 +543,7 @@ static u8 ath9k_hw_chan_2_clockrate_mhz(struct ath_hw *ah)
543 if (conf_is_ht40(conf)) 543 if (conf_is_ht40(conf))
544 return clockrate * 2; 544 return clockrate * 2;
545 545
546 return clockrate * 2; 546 return clockrate;
547} 547}
548 548
549static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah) 549static int32_t ath9k_hw_ani_get_listen_time(struct ath_hw *ah)
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index 3b632161c106..c96e19da2949 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -42,7 +42,6 @@
42#include <linux/moduleparam.h> 42#include <linux/moduleparam.h>
43#include <linux/device.h> 43#include <linux/device.h>
44 44
45#include <pcmcia/cs.h>
46#include <pcmcia/cistpl.h> 45#include <pcmcia/cistpl.h>
47#include <pcmcia/cisreg.h> 46#include <pcmcia/cisreg.h>
48#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
@@ -64,58 +63,21 @@ MODULE_SUPPORTED_DEVICE("Atmel at76c50x PCMCIA cards");
64 63
65/*====================================================================*/ 64/*====================================================================*/
66 65
67/*
68 The event() function is this driver's Card Services event handler.
69 It will be called by Card Services when an appropriate card status
70 event is received. The config() and release() entry points are
71 used to configure or release a socket, in response to card
72 insertion and ejection events. They are invoked from the atmel_cs
73 event handler.
74*/
75
76static int atmel_config(struct pcmcia_device *link); 66static int atmel_config(struct pcmcia_device *link);
77static void atmel_release(struct pcmcia_device *link); 67static void atmel_release(struct pcmcia_device *link);
78 68
79/*
80 The attach() and detach() entry points are used to create and destroy
81 "instances" of the driver, where each instance represents everything
82 needed to manage one actual PCMCIA card.
83*/
84
85static void atmel_detach(struct pcmcia_device *p_dev); 69static void atmel_detach(struct pcmcia_device *p_dev);
86 70
87typedef struct local_info_t { 71typedef struct local_info_t {
88 struct net_device *eth_dev; 72 struct net_device *eth_dev;
89} local_info_t; 73} local_info_t;
90 74
91/*======================================================================
92
93 atmel_attach() creates an "instance" of the driver, allocating
94 local data structures for one device. The device is registered
95 with Card Services.
96
97 The dev_link structure is initialized, but we don't actually
98 configure the card at this point -- we wait until we receive a
99 card insertion event.
100
101 ======================================================================*/
102
103static int atmel_probe(struct pcmcia_device *p_dev) 75static int atmel_probe(struct pcmcia_device *p_dev)
104{ 76{
105 local_info_t *local; 77 local_info_t *local;
106 78
107 dev_dbg(&p_dev->dev, "atmel_attach()\n"); 79 dev_dbg(&p_dev->dev, "atmel_attach()\n");
108 80
109 /*
110 General socket configuration defaults can go here. In this
111 client, we assume very little, and rely on the CIS for almost
112 everything. In most clients, many details (i.e., number, sizes,
113 and attributes of IO windows) are fixed by the nature of the
114 device, and can be hard-wired here.
115 */
116 p_dev->conf.Attributes = 0;
117 p_dev->conf.IntType = INT_MEMORY_AND_IO;
118
119 /* Allocate space for private device-specific data */ 81 /* Allocate space for private device-specific data */
120 local = kzalloc(sizeof(local_info_t), GFP_KERNEL); 82 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
121 if (!local) { 83 if (!local) {
@@ -127,15 +89,6 @@ static int atmel_probe(struct pcmcia_device *p_dev)
127 return atmel_config(p_dev); 89 return atmel_config(p_dev);
128} /* atmel_attach */ 90} /* atmel_attach */
129 91
130/*======================================================================
131
132 This deletes a driver "instance". The device is de-registered
133 with Card Services. If it has been released, all local data
134 structures are freed. Otherwise, the structures will be freed
135 when the device is released.
136
137 ======================================================================*/
138
139static void atmel_detach(struct pcmcia_device *link) 92static void atmel_detach(struct pcmcia_device *link)
140{ 93{
141 dev_dbg(&link->dev, "atmel_detach\n"); 94 dev_dbg(&link->dev, "atmel_detach\n");
@@ -145,14 +98,6 @@ static void atmel_detach(struct pcmcia_device *link)
145 kfree(link->priv); 98 kfree(link->priv);
146} 99}
147 100
148/*======================================================================
149
150 atmel_config() is scheduled to run after a CARD_INSERTION event
151 is received, to configure the PCMCIA socket, and to make the
152 device available to the system.
153
154 ======================================================================*/
155
156/* Call-back function to interrogate PCMCIA-specific information 101/* Call-back function to interrogate PCMCIA-specific information
157 about the current existance of the card */ 102 about the current existance of the card */
158static int card_present(void *arg) 103static int card_present(void *arg)
@@ -165,47 +110,11 @@ static int card_present(void *arg)
165 return 0; 110 return 0;
166} 111}
167 112
168static int atmel_config_check(struct pcmcia_device *p_dev, 113static int atmel_config_check(struct pcmcia_device *p_dev, void *priv_data)
169 cistpl_cftable_entry_t *cfg,
170 cistpl_cftable_entry_t *dflt,
171 unsigned int vcc,
172 void *priv_data)
173{ 114{
174 if (cfg->index == 0) 115 if (p_dev->config_index == 0)
175 return -ENODEV; 116 return -EINVAL;
176
177 /* Does this card need audio output? */
178 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
179 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
180 p_dev->conf.Status = CCSR_AUDIO_ENA;
181 }
182 117
183 /* Use power settings for Vcc and Vpp if present */
184 /* Note that the CIS values need to be rescaled */
185 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
186 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
187 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
188 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
189
190 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
191
192 /* IO window settings */
193 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
194 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
195 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
196 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
197 p_dev->resource[0]->flags |=
198 pcmcia_io_cfg_data_width(io->flags);
199 p_dev->resource[0]->start = io->win[0].base;
200 p_dev->resource[0]->end = io->win[0].len;
201 if (io->nwin > 1) {
202 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
203 p_dev->resource[1]->start = io->win[1].base;
204 p_dev->resource[1]->end = io->win[1].len;
205 }
206 }
207
208 /* This reserves IO space but doesn't actually enable it */
209 return pcmcia_request_io(p_dev); 118 return pcmcia_request_io(p_dev);
210} 119}
211 120
@@ -220,18 +129,9 @@ static int atmel_config(struct pcmcia_device *link)
220 129
221 dev_dbg(&link->dev, "atmel_config\n"); 130 dev_dbg(&link->dev, "atmel_config\n");
222 131
223 /* 132 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
224 In this loop, we scan the CIS for configuration table entries, 133 CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
225 each of which describes a valid card configuration, including 134
226 voltage, IO window, memory window, and interrupt settings.
227
228 We make no assumptions about the card to be configured: we use
229 just the information available in the CIS. In an ideal world,
230 this would work for any PCMCIA card, but it requires a complete
231 and accurate CIS. In practice, a driver usually "knows" most of
232 these things without consulting the CIS, and most client drivers
233 will only use the CIS to fill in implementation-defined details.
234 */
235 if (pcmcia_loop_config(link, atmel_config_check, NULL)) 135 if (pcmcia_loop_config(link, atmel_config_check, NULL))
236 goto failed; 136 goto failed;
237 137
@@ -240,12 +140,7 @@ static int atmel_config(struct pcmcia_device *link)
240 goto failed; 140 goto failed;
241 } 141 }
242 142
243 /* 143 ret = pcmcia_enable_device(link);
244 This actually configures the PCMCIA socket -- setting up
245 the I/O windows and the interrupt mapping, and putting the
246 card and host interface into "Memory and IO" mode.
247 */
248 ret = pcmcia_request_configuration(link, &link->conf);
249 if (ret) 144 if (ret)
250 goto failed; 145 goto failed;
251 146
@@ -267,14 +162,6 @@ static int atmel_config(struct pcmcia_device *link)
267 return -ENODEV; 162 return -ENODEV;
268} 163}
269 164
270/*======================================================================
271
272 After a card is removed, atmel_release() will unregister the
273 device, and release the PCMCIA configuration. If the device is
274 still open, this will be postponed until it is closed.
275
276 ======================================================================*/
277
278static void atmel_release(struct pcmcia_device *link) 165static void atmel_release(struct pcmcia_device *link)
279{ 166{
280 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev; 167 struct net_device *dev = ((local_info_t*)link->priv)->eth_dev;
@@ -353,9 +240,7 @@ MODULE_DEVICE_TABLE(pcmcia, atmel_ids);
353 240
354static struct pcmcia_driver atmel_driver = { 241static struct pcmcia_driver atmel_driver = {
355 .owner = THIS_MODULE, 242 .owner = THIS_MODULE,
356 .drv = { 243 .name = "atmel_cs",
357 .name = "atmel_cs",
358 },
359 .probe = atmel_probe, 244 .probe = atmel_probe,
360 .remove = atmel_detach, 245 .remove = atmel_detach,
361 .id_table = atmel_ids, 246 .id_table = atmel_ids,
@@ -363,12 +248,12 @@ static struct pcmcia_driver atmel_driver = {
363 .resume = atmel_resume, 248 .resume = atmel_resume,
364}; 249};
365 250
366static int atmel_cs_init(void) 251static int __init atmel_cs_init(void)
367{ 252{
368 return pcmcia_register_driver(&atmel_driver); 253 return pcmcia_register_driver(&atmel_driver);
369} 254}
370 255
371static void atmel_cs_cleanup(void) 256static void __exit atmel_cs_cleanup(void)
372{ 257{
373 pcmcia_unregister_driver(&atmel_driver); 258 pcmcia_unregister_driver(&atmel_driver);
374} 259}
diff --git a/drivers/net/wireless/b43/pcmcia.c b/drivers/net/wireless/b43/pcmcia.c
index dfbc41d431ff..7dcba5fafdc7 100644
--- a/drivers/net/wireless/b43/pcmcia.c
+++ b/drivers/net/wireless/b43/pcmcia.c
@@ -26,7 +26,6 @@
26#include <linux/ssb/ssb.h> 26#include <linux/ssb/ssb.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28 28
29#include <pcmcia/cs.h>
30#include <pcmcia/cistpl.h> 29#include <pcmcia/cistpl.h>
31#include <pcmcia/ciscode.h> 30#include <pcmcia/ciscode.h>
32#include <pcmcia/ds.h> 31#include <pcmcia/ds.h>
@@ -63,7 +62,6 @@ static int b43_pcmcia_resume(struct pcmcia_device *dev)
63static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev) 62static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
64{ 63{
65 struct ssb_bus *ssb; 64 struct ssb_bus *ssb;
66 win_req_t win;
67 int err = -ENOMEM; 65 int err = -ENOMEM;
68 int res = 0; 66 int res = 0;
69 67
@@ -73,30 +71,28 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
73 71
74 err = -ENODEV; 72 err = -ENODEV;
75 73
76 dev->conf.Attributes = CONF_ENABLE_IRQ; 74 dev->config_flags |= CONF_ENABLE_IRQ;
77 dev->conf.IntType = INT_MEMORY_AND_IO;
78 75
79 win.Attributes = WIN_ENABLE | WIN_DATA_WIDTH_16 | 76 dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
80 WIN_USE_WAIT; 77 WIN_USE_WAIT;
81 win.Base = 0; 78 dev->resource[2]->start = 0;
82 win.Size = SSB_CORE_SIZE; 79 dev->resource[2]->end = SSB_CORE_SIZE;
83 win.AccessSpeed = 250; 80 res = pcmcia_request_window(dev, dev->resource[2], 250);
84 res = pcmcia_request_window(dev, &win, &dev->win);
85 if (res != 0) 81 if (res != 0)
86 goto err_kfree_ssb; 82 goto err_kfree_ssb;
87 83
88 res = pcmcia_map_mem_page(dev, dev->win, 0); 84 res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
89 if (res != 0) 85 if (res != 0)
90 goto err_disable; 86 goto err_disable;
91 87
92 if (!dev->irq) 88 if (!dev->irq)
93 goto err_disable; 89 goto err_disable;
94 90
95 res = pcmcia_request_configuration(dev, &dev->conf); 91 res = pcmcia_enable_device(dev);
96 if (res != 0) 92 if (res != 0)
97 goto err_disable; 93 goto err_disable;
98 94
99 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base); 95 err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
100 if (err) 96 if (err)
101 goto err_disable; 97 goto err_disable;
102 dev->priv = ssb; 98 dev->priv = ssb;
@@ -125,9 +121,7 @@ static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
125 121
126static struct pcmcia_driver b43_pcmcia_driver = { 122static struct pcmcia_driver b43_pcmcia_driver = {
127 .owner = THIS_MODULE, 123 .owner = THIS_MODULE,
128 .drv = { 124 .name = "b43-pcmcia",
129 .name = "b43-pcmcia",
130 },
131 .id_table = b43_pcmcia_tbl, 125 .id_table = b43_pcmcia_tbl,
132 .probe = b43_pcmcia_probe, 126 .probe = b43_pcmcia_probe,
133 .remove = __devexit_p(b43_pcmcia_remove), 127 .remove = __devexit_p(b43_pcmcia_remove),
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index ba54d1b04d22..bd8a4134edeb 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -12,7 +12,6 @@
12#include <linux/wireless.h> 12#include <linux/wireless.h>
13#include <net/iw_handler.h> 13#include <net/iw_handler.h>
14 14
15#include <pcmcia/cs.h>
16#include <pcmcia/cistpl.h> 15#include <pcmcia/cistpl.h>
17#include <pcmcia/cisreg.h> 16#include <pcmcia/cisreg.h>
18#include <pcmcia/ds.h> 17#include <pcmcia/ds.h>
@@ -437,7 +436,6 @@ static int hostap_cs_probe(struct pcmcia_device *p_dev)
437 int ret; 436 int ret;
438 437
439 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); 438 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
440 p_dev->conf.IntType = INT_MEMORY_AND_IO;
441 439
442 ret = prism2_config(p_dev); 440 ret = prism2_config(p_dev);
443 if (ret) { 441 if (ret) {
@@ -468,74 +466,11 @@ static void prism2_detach(struct pcmcia_device *link)
468} 466}
469 467
470 468
471/* run after a CARD_INSERTION event is received to configure the PCMCIA 469static int prism2_config_check(struct pcmcia_device *p_dev, void *priv_data)
472 * socket and make the device available to the system */
473
474static int prism2_config_check(struct pcmcia_device *p_dev,
475 cistpl_cftable_entry_t *cfg,
476 cistpl_cftable_entry_t *dflt,
477 unsigned int vcc,
478 void *priv_data)
479{ 470{
480 if (cfg->index == 0) 471 if (p_dev->config_index == 0)
481 return -ENODEV; 472 return -EINVAL;
482
483 PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
484 "(default 0x%02X)\n", cfg->index, dflt->index);
485
486 /* Does this card need audio output? */
487 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
488 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
489 p_dev->conf.Status = CCSR_AUDIO_ENA;
490 }
491
492 /* Use power settings for Vcc and Vpp if present */
493 /* Note that the CIS values need to be rescaled */
494 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
495 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
496 10000 && !ignore_cis_vcc) {
497 PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
498 " this entry\n");
499 return -ENODEV;
500 }
501 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
502 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] /
503 10000 && !ignore_cis_vcc) {
504 PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
505 "- skipping this entry\n");
506 return -ENODEV;
507 }
508 }
509 473
510 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
511 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
512 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
513 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
514
515 /* Do we need to allocate an interrupt? */
516 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
517
518 /* IO window settings */
519 PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
520 "dflt->io.nwin=%d\n",
521 cfg->io.nwin, dflt->io.nwin);
522 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
523 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
524 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
525 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
526 p_dev->resource[0]->flags |=
527 pcmcia_io_cfg_data_width(io->flags);
528 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
529 p_dev->resource[0]->start = io->win[0].base;
530 p_dev->resource[0]->end = io->win[0].len;
531 if (io->nwin > 1) {
532 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
533 p_dev->resource[1]->start = io->win[1].base;
534 p_dev->resource[1]->end = io->win[1].len;
535 }
536 }
537
538 /* This reserves IO space but doesn't actually enable it */
539 return pcmcia_request_io(p_dev); 474 return pcmcia_request_io(p_dev);
540} 475}
541 476
@@ -557,6 +492,10 @@ static int prism2_config(struct pcmcia_device *link)
557 } 492 }
558 493
559 /* Look for an appropriate configuration table entry in the CIS */ 494 /* Look for an appropriate configuration table entry in the CIS */
495 link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO |
496 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
497 if (ignore_cis_vcc)
498 link->config_flags &= ~CONF_AUTO_CHECK_VCC;
560 ret = pcmcia_loop_config(link, prism2_config_check, NULL); 499 ret = pcmcia_loop_config(link, prism2_config_check, NULL);
561 if (ret) { 500 if (ret) {
562 if (!ignore_cis_vcc) 501 if (!ignore_cis_vcc)
@@ -588,12 +527,7 @@ static int prism2_config(struct pcmcia_device *link)
588 if (ret) 527 if (ret)
589 goto failed_unlock; 528 goto failed_unlock;
590 529
591 /* 530 ret = pcmcia_enable_device(link);
592 * This actually configures the PCMCIA socket -- setting up
593 * the I/O windows and the interrupt mapping, and putting the
594 * card and host interface into "Memory and IO" mode.
595 */
596 ret = pcmcia_request_configuration(link, &link->conf);
597 if (ret) 531 if (ret)
598 goto failed_unlock; 532 goto failed_unlock;
599 533
@@ -602,20 +536,6 @@ static int prism2_config(struct pcmcia_device *link)
602 536
603 spin_unlock_irqrestore(&local->irq_init_lock, flags); 537 spin_unlock_irqrestore(&local->irq_init_lock, flags);
604 538
605 /* Finally, report what we've done */
606 printk(KERN_INFO "%s: index 0x%02x: ",
607 dev_info, link->conf.ConfigIndex);
608 if (link->conf.Vpp)
609 printk(", Vpp %d.%d", link->conf.Vpp / 10,
610 link->conf.Vpp % 10);
611 if (link->conf.Attributes & CONF_ENABLE_IRQ)
612 printk(", irq %d", link->irq);
613 if (link->resource[0])
614 printk(" & %pR", link->resource[0]);
615 if (link->resource[1])
616 printk(" & %pR", link->resource[1]);
617 printk("\n");
618
619 local->shutdown = 0; 539 local->shutdown = 0;
620 540
621 sandisk_enable_wireless(dev); 541 sandisk_enable_wireless(dev);
@@ -627,7 +547,7 @@ static int prism2_config(struct pcmcia_device *link)
627 return ret; 547 return ret;
628 548
629 failed_unlock: 549 failed_unlock:
630 spin_unlock_irqrestore(&local->irq_init_lock, flags); 550 spin_unlock_irqrestore(&local->irq_init_lock, flags);
631 failed: 551 failed:
632 kfree(hw_priv); 552 kfree(hw_priv);
633 prism2_release((u_long)link); 553 prism2_release((u_long)link);
@@ -779,9 +699,7 @@ MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
779 699
780 700
781static struct pcmcia_driver hostap_driver = { 701static struct pcmcia_driver hostap_driver = {
782 .drv = { 702 .name = "hostap_cs",
783 .name = "hostap_cs",
784 },
785 .probe = hostap_cs_probe, 703 .probe = hostap_cs_probe,
786 .remove = prism2_detach, 704 .remove = prism2_detach,
787 .owner = THIS_MODULE, 705 .owner = THIS_MODULE,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index 9dd9e64c2b0b..8fd00a6e5120 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -1411,7 +1411,7 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1411 clear_bit(STATUS_SCAN_HW, &priv->status); 1411 clear_bit(STATUS_SCAN_HW, &priv->status);
1412 clear_bit(STATUS_SCANNING, &priv->status); 1412 clear_bit(STATUS_SCANNING, &priv->status);
1413 /* inform mac80211 scan aborted */ 1413 /* inform mac80211 scan aborted */
1414 queue_work(priv->workqueue, &priv->scan_completed); 1414 queue_work(priv->workqueue, &priv->abort_scan);
1415} 1415}
1416 1416
1417int iwlagn_manage_ibss_station(struct iwl_priv *priv, 1417int iwlagn_manage_ibss_station(struct iwl_priv *priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index 07dbc2796448..e23c4060a0f0 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -2613,6 +2613,11 @@ int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
2613 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2613 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2614 return -EINVAL; 2614 return -EINVAL;
2615 2615
2616 if (test_bit(STATUS_SCANNING, &priv->status)) {
2617 IWL_DEBUG_INFO(priv, "scan in progress.\n");
2618 return -EINVAL;
2619 }
2620
2616 if (mode >= IWL_MAX_FORCE_RESET) { 2621 if (mode >= IWL_MAX_FORCE_RESET) {
2617 IWL_DEBUG_INFO(priv, "invalid reset request.\n"); 2622 IWL_DEBUG_INFO(priv, "invalid reset request.\n");
2618 return -EINVAL; 2623 return -EINVAL;
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 59a308b02f95..d31661c1ce77 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -3018,7 +3018,7 @@ void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
3018 clear_bit(STATUS_SCANNING, &priv->status); 3018 clear_bit(STATUS_SCANNING, &priv->status);
3019 3019
3020 /* inform mac80211 scan aborted */ 3020 /* inform mac80211 scan aborted */
3021 queue_work(priv->workqueue, &priv->scan_completed); 3021 queue_work(priv->workqueue, &priv->abort_scan);
3022} 3022}
3023 3023
3024static void iwl3945_bg_restart(struct work_struct *data) 3024static void iwl3945_bg_restart(struct work_struct *data)
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index 9c298396be50..ff1280f41336 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -28,7 +28,6 @@
28#include <linux/firmware.h> 28#include <linux/firmware.h>
29#include <linux/netdevice.h> 29#include <linux/netdevice.h>
30 30
31#include <pcmcia/cs.h>
32#include <pcmcia/cistpl.h> 31#include <pcmcia/cistpl.h>
33#include <pcmcia/ds.h> 32#include <pcmcia/ds.h>
34 33
@@ -761,15 +760,6 @@ static int if_cs_host_to_card(struct lbs_private *priv,
761} 760}
762 761
763 762
764/********************************************************************/
765/* Card Services */
766/********************************************************************/
767
768/*
769 * After a card is removed, if_cs_release() will unregister the
770 * device, and release the PCMCIA configuration. If the device is
771 * still open, this will be postponed until it is closed.
772 */
773static void if_cs_release(struct pcmcia_device *p_dev) 763static void if_cs_release(struct pcmcia_device *p_dev)
774{ 764{
775 struct if_cs_card *card = p_dev->priv; 765 struct if_cs_card *card = p_dev->priv;
@@ -785,31 +775,12 @@ static void if_cs_release(struct pcmcia_device *p_dev)
785} 775}
786 776
787 777
788/* 778static int if_cs_ioprobe(struct pcmcia_device *p_dev, void *priv_data)
789 * This creates an "instance" of the driver, allocating local data
790 * structures for one device. The device is registered with Card
791 * Services.
792 *
793 * The dev_link structure is initialized, but we don't actually
794 * configure the card at this point -- we wait until we receive a card
795 * insertion event.
796 */
797
798static int if_cs_ioprobe(struct pcmcia_device *p_dev,
799 cistpl_cftable_entry_t *cfg,
800 cistpl_cftable_entry_t *dflt,
801 unsigned int vcc,
802 void *priv_data)
803{ 779{
780 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
804 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 781 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
805 p_dev->resource[0]->start = cfg->io.win[0].base;
806 p_dev->resource[0]->end = cfg->io.win[0].len;
807
808 /* Do we need to allocate an interrupt? */
809 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
810 782
811 /* IO window settings */ 783 if (p_dev->resource[1]->end) {
812 if (cfg->io.nwin != 1) {
813 lbs_pr_err("wrong CIS (check number of IO windows)\n"); 784 lbs_pr_err("wrong CIS (check number of IO windows)\n");
814 return -ENODEV; 785 return -ENODEV;
815 } 786 }
@@ -835,15 +806,13 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
835 card->p_dev = p_dev; 806 card->p_dev = p_dev;
836 p_dev->priv = card; 807 p_dev->priv = card;
837 808
838 p_dev->conf.Attributes = 0; 809 p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
839 p_dev->conf.IntType = INT_MEMORY_AND_IO;
840 810
841 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) { 811 if (pcmcia_loop_config(p_dev, if_cs_ioprobe, NULL)) {
842 lbs_pr_err("error in pcmcia_loop_config\n"); 812 lbs_pr_err("error in pcmcia_loop_config\n");
843 goto out1; 813 goto out1;
844 } 814 }
845 815
846
847 /* 816 /*
848 * Allocate an interrupt line. Note that this does not assign 817 * Allocate an interrupt line. Note that this does not assign
849 * a handler to the interrupt, unless the 'Handler' member of 818 * a handler to the interrupt, unless the 'Handler' member of
@@ -861,14 +830,9 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
861 goto out1; 830 goto out1;
862 } 831 }
863 832
864 /* 833 ret = pcmcia_enable_device(p_dev);
865 * This actually configures the PCMCIA socket -- setting up
866 * the I/O windows and the interrupt mapping, and putting the
867 * card and host interface into "Memory and IO" mode.
868 */
869 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
870 if (ret) { 834 if (ret) {
871 lbs_pr_err("error in pcmcia_request_configuration\n"); 835 lbs_pr_err("error in pcmcia_enable_device\n");
872 goto out2; 836 goto out2;
873 } 837 }
874 838
@@ -962,12 +926,6 @@ out:
962} 926}
963 927
964 928
965/*
966 * This deletes a driver "instance". The device is de-registered with
967 * Card Services. If it has been released, all local data structures
968 * are freed. Otherwise, the structures will be freed when the device
969 * is released.
970 */
971static void if_cs_detach(struct pcmcia_device *p_dev) 929static void if_cs_detach(struct pcmcia_device *p_dev)
972{ 930{
973 struct if_cs_card *card = p_dev->priv; 931 struct if_cs_card *card = p_dev->priv;
@@ -1000,9 +958,7 @@ MODULE_DEVICE_TABLE(pcmcia, if_cs_ids);
1000 958
1001static struct pcmcia_driver lbs_driver = { 959static struct pcmcia_driver lbs_driver = {
1002 .owner = THIS_MODULE, 960 .owner = THIS_MODULE,
1003 .drv = { 961 .name = DRV_NAME,
1004 .name = DRV_NAME,
1005 },
1006 .probe = if_cs_probe, 962 .probe = if_cs_probe,
1007 .remove = if_cs_detach, 963 .remove = if_cs_detach,
1008 .id_table = if_cs_ids, 964 .id_table = if_cs_ids,
diff --git a/drivers/net/wireless/orinoco/orinoco_cs.c b/drivers/net/wireless/orinoco/orinoco_cs.c
index ef46a2d88539..71b3d68b9403 100644
--- a/drivers/net/wireless/orinoco/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco/orinoco_cs.c
@@ -17,7 +17,6 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h> 20#include <pcmcia/cistpl.h>
22#include <pcmcia/cisreg.h> 21#include <pcmcia/cisreg.h>
23#include <pcmcia/ds.h> 22#include <pcmcia/ds.h>
@@ -93,14 +92,6 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
93/* PCMCIA stuff */ 92/* PCMCIA stuff */
94/********************************************************************/ 93/********************************************************************/
95 94
96/*
97 * This creates an "instance" of the driver, allocating local data
98 * structures for one device. The device is registered with Card
99 * Services.
100 *
101 * The dev_link structure is initialized, but we don't actually
102 * configure the card at this point -- we wait until we receive a card
103 * insertion event. */
104static int 95static int
105orinoco_cs_probe(struct pcmcia_device *link) 96orinoco_cs_probe(struct pcmcia_device *link)
106{ 97{
@@ -117,23 +108,9 @@ orinoco_cs_probe(struct pcmcia_device *link)
117 card->p_dev = link; 108 card->p_dev = link;
118 link->priv = priv; 109 link->priv = priv;
119 110
120 /* General socket configuration defaults can go here. In this
121 * client, we assume very little, and rely on the CIS for
122 * almost everything. In most clients, many details (i.e.,
123 * number, sizes, and attributes of IO windows) are fixed by
124 * the nature of the device, and can be hard-wired here. */
125 link->conf.Attributes = 0;
126 link->conf.IntType = INT_MEMORY_AND_IO;
127
128 return orinoco_cs_config(link); 111 return orinoco_cs_config(link);
129} /* orinoco_cs_attach */ 112} /* orinoco_cs_attach */
130 113
131/*
132 * This deletes a driver "instance". The device is de-registered with
133 * Card Services. If it has been released, all local data structures
134 * are freed. Otherwise, the structures will be freed when the device
135 * is released.
136 */
137static void orinoco_cs_detach(struct pcmcia_device *link) 114static void orinoco_cs_detach(struct pcmcia_device *link)
138{ 115{
139 struct orinoco_private *priv = link->priv; 116 struct orinoco_private *priv = link->priv;
@@ -145,76 +122,12 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
145 free_orinocodev(priv); 122 free_orinocodev(priv);
146} /* orinoco_cs_detach */ 123} /* orinoco_cs_detach */
147 124
148/* 125static int orinoco_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
149 * orinoco_cs_config() is scheduled to run after a CARD_INSERTION
150 * event is received, to configure the PCMCIA socket, and to make the
151 * device available to the system.
152 */
153
154static int orinoco_cs_config_check(struct pcmcia_device *p_dev,
155 cistpl_cftable_entry_t *cfg,
156 cistpl_cftable_entry_t *dflt,
157 unsigned int vcc,
158 void *priv_data)
159{ 126{
160 if (cfg->index == 0) 127 if (p_dev->config_index == 0)
161 goto next_entry; 128 return -EINVAL;
162
163 /* Use power settings for Vcc and Vpp if present */
164 /* Note that the CIS values need to be rescaled */
165 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
166 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
167 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
168 __func__, vcc,
169 cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
170 if (!ignore_cis_vcc)
171 goto next_entry;
172 }
173 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
174 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
175 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
176 __func__, vcc,
177 dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
178 if (!ignore_cis_vcc)
179 goto next_entry;
180 }
181 }
182 129
183 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 130 return pcmcia_request_io(p_dev);
184 p_dev->conf.Vpp =
185 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
186 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
187 p_dev->conf.Vpp =
188 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
189
190 /* Do we need to allocate an interrupt? */
191 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
192
193 /* IO window settings */
194 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
195 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
196 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
197 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
198 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
199 p_dev->resource[0]->flags |=
200 pcmcia_io_cfg_data_width(io->flags);
201 p_dev->resource[0]->start = io->win[0].base;
202 p_dev->resource[0]->end = io->win[0].len;
203 if (io->nwin > 1) {
204 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
205 p_dev->resource[1]->start = io->win[1].base;
206 p_dev->resource[1]->end = io->win[1].len;
207 }
208
209 /* This reserves IO space but doesn't actually enable it */
210 if (pcmcia_request_io(p_dev) != 0)
211 goto next_entry;
212 }
213 return 0;
214
215next_entry:
216 pcmcia_disable_device(p_dev);
217 return -ENODEV;
218}; 131};
219 132
220static int 133static int
@@ -225,20 +138,10 @@ orinoco_cs_config(struct pcmcia_device *link)
225 int ret; 138 int ret;
226 void __iomem *mem; 139 void __iomem *mem;
227 140
228 /* 141 link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC |
229 * In this loop, we scan the CIS for configuration table 142 CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
230 * entries, each of which describes a valid card 143 if (ignore_cis_vcc)
231 * configuration, including voltage, IO window, memory window, 144 link->config_flags &= ~CONF_AUTO_CHECK_VCC;
232 * and interrupt settings.
233 *
234 * We make no assumptions about the card to be configured: we
235 * use just the information available in the CIS. In an ideal
236 * world, this would work for any PCMCIA card, but it requires
237 * a complete and accurate CIS. In practice, a driver usually
238 * "knows" most of these things without consulting the CIS,
239 * and most client drivers will only use the CIS to fill in
240 * implementation-defined details.
241 */
242 ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL); 145 ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL);
243 if (ret) { 146 if (ret) {
244 if (!ignore_cis_vcc) 147 if (!ignore_cis_vcc)
@@ -262,12 +165,7 @@ orinoco_cs_config(struct pcmcia_device *link)
262 165
263 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 166 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
264 167
265 /* 168 ret = pcmcia_enable_device(link);
266 * This actually configures the PCMCIA socket -- setting up
267 * the I/O windows and the interrupt mapping, and putting the
268 * card and host interface into "Memory and IO" mode.
269 */
270 ret = pcmcia_request_configuration(link, &link->conf);
271 if (ret) 169 if (ret)
272 goto failed; 170 goto failed;
273 171
@@ -291,11 +189,6 @@ orinoco_cs_config(struct pcmcia_device *link)
291 return -ENODEV; 189 return -ENODEV;
292} /* orinoco_cs_config */ 190} /* orinoco_cs_config */
293 191
294/*
295 * After a card is removed, orinoco_cs_release() will unregister the
296 * device, and release the PCMCIA configuration. If the device is
297 * still open, this will be postponed until it is closed.
298 */
299static void 192static void
300orinoco_cs_release(struct pcmcia_device *link) 193orinoco_cs_release(struct pcmcia_device *link)
301{ 194{
@@ -344,12 +237,6 @@ static int orinoco_cs_resume(struct pcmcia_device *link)
344/* Module initialization */ 237/* Module initialization */
345/********************************************************************/ 238/********************************************************************/
346 239
347/* Can't be declared "const" or the whole __initdata section will
348 * become const */
349static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
350 " (David Gibson <hermes@gibson.dropbear.id.au>, "
351 "Pavel Roskin <proski@gnu.org>, et al)";
352
353static struct pcmcia_device_id orinoco_cs_ids[] = { 240static struct pcmcia_device_id orinoco_cs_ids[] = {
354 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), /* 3Com AirConnect PCI 777A */ 241 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), /* 3Com AirConnect PCI 777A */
355 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), /* Lucent Orinoco and old Intersil */ 242 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), /* Lucent Orinoco and old Intersil */
@@ -441,9 +328,7 @@ MODULE_DEVICE_TABLE(pcmcia, orinoco_cs_ids);
441 328
442static struct pcmcia_driver orinoco_driver = { 329static struct pcmcia_driver orinoco_driver = {
443 .owner = THIS_MODULE, 330 .owner = THIS_MODULE,
444 .drv = { 331 .name = DRIVER_NAME,
445 .name = DRIVER_NAME,
446 },
447 .probe = orinoco_cs_probe, 332 .probe = orinoco_cs_probe,
448 .remove = orinoco_cs_detach, 333 .remove = orinoco_cs_detach,
449 .id_table = orinoco_cs_ids, 334 .id_table = orinoco_cs_ids,
@@ -454,8 +339,6 @@ static struct pcmcia_driver orinoco_driver = {
454static int __init 339static int __init
455init_orinoco_cs(void) 340init_orinoco_cs(void)
456{ 341{
457 printk(KERN_DEBUG "%s\n", version);
458
459 return pcmcia_register_driver(&orinoco_driver); 342 return pcmcia_register_driver(&orinoco_driver);
460} 343}
461 344
diff --git a/drivers/net/wireless/orinoco/spectrum_cs.c b/drivers/net/wireless/orinoco/spectrum_cs.c
index 873877e17e1b..fb859a5ad2eb 100644
--- a/drivers/net/wireless/orinoco/spectrum_cs.c
+++ b/drivers/net/wireless/orinoco/spectrum_cs.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <pcmcia/cs.h>
29#include <pcmcia/cistpl.h> 28#include <pcmcia/cistpl.h>
30#include <pcmcia/cisreg.h> 29#include <pcmcia/cisreg.h>
31#include <pcmcia/ds.h> 30#include <pcmcia/ds.h>
@@ -154,14 +153,6 @@ spectrum_cs_stop_firmware(struct orinoco_private *priv, int idle)
154/* PCMCIA stuff */ 153/* PCMCIA stuff */
155/********************************************************************/ 154/********************************************************************/
156 155
157/*
158 * This creates an "instance" of the driver, allocating local data
159 * structures for one device. The device is registered with Card
160 * Services.
161 *
162 * The dev_link structure is initialized, but we don't actually
163 * configure the card at this point -- we wait until we receive a card
164 * insertion event. */
165static int 156static int
166spectrum_cs_probe(struct pcmcia_device *link) 157spectrum_cs_probe(struct pcmcia_device *link)
167{ 158{
@@ -179,23 +170,9 @@ spectrum_cs_probe(struct pcmcia_device *link)
179 card->p_dev = link; 170 card->p_dev = link;
180 link->priv = priv; 171 link->priv = priv;
181 172
182 /* General socket configuration defaults can go here. In this
183 * client, we assume very little, and rely on the CIS for
184 * almost everything. In most clients, many details (i.e.,
185 * number, sizes, and attributes of IO windows) are fixed by
186 * the nature of the device, and can be hard-wired here. */
187 link->conf.Attributes = 0;
188 link->conf.IntType = INT_MEMORY_AND_IO;
189
190 return spectrum_cs_config(link); 173 return spectrum_cs_config(link);
191} /* spectrum_cs_attach */ 174} /* spectrum_cs_attach */
192 175
193/*
194 * This deletes a driver "instance". The device is de-registered with
195 * Card Services. If it has been released, all local data structures
196 * are freed. Otherwise, the structures will be freed when the device
197 * is released.
198 */
199static void spectrum_cs_detach(struct pcmcia_device *link) 176static void spectrum_cs_detach(struct pcmcia_device *link)
200{ 177{
201 struct orinoco_private *priv = link->priv; 178 struct orinoco_private *priv = link->priv;
@@ -207,76 +184,13 @@ static void spectrum_cs_detach(struct pcmcia_device *link)
207 free_orinocodev(priv); 184 free_orinocodev(priv);
208} /* spectrum_cs_detach */ 185} /* spectrum_cs_detach */
209 186
210/*
211 * spectrum_cs_config() is scheduled to run after a CARD_INSERTION
212 * event is received, to configure the PCMCIA socket, and to make the
213 * device available to the system.
214 */
215
216static int spectrum_cs_config_check(struct pcmcia_device *p_dev, 187static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
217 cistpl_cftable_entry_t *cfg,
218 cistpl_cftable_entry_t *dflt,
219 unsigned int vcc,
220 void *priv_data) 188 void *priv_data)
221{ 189{
222 if (cfg->index == 0) 190 if (p_dev->config_index == 0)
223 goto next_entry; 191 return -EINVAL;
224
225 /* Use power settings for Vcc and Vpp if present */
226 /* Note that the CIS values need to be rescaled */
227 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
228 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
229 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
230 __func__, vcc,
231 cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
232 if (!ignore_cis_vcc)
233 goto next_entry;
234 }
235 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
236 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
237 DEBUG(2, "%s: Vcc mismatch (vcc = %d, CIS = %d)\n",
238 __func__, vcc,
239 dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
240 if (!ignore_cis_vcc)
241 goto next_entry;
242 }
243 }
244 192
245 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 193 return pcmcia_request_io(p_dev);
246 p_dev->conf.Vpp =
247 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
248 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
249 p_dev->conf.Vpp =
250 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
251
252 /* Do we need to allocate an interrupt? */
253 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
254
255 /* IO window settings */
256 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
257 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
258 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
259 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
260 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
261 p_dev->resource[0]->flags |=
262 pcmcia_io_cfg_data_width(io->flags);
263 p_dev->resource[0]->start = io->win[0].base;
264 p_dev->resource[0]->end = io->win[0].len;
265 if (io->nwin > 1) {
266 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
267 p_dev->resource[1]->start = io->win[1].base;
268 p_dev->resource[1]->end = io->win[1].len;
269 }
270
271 /* This reserves IO space but doesn't actually enable it */
272 if (pcmcia_request_io(p_dev) != 0)
273 goto next_entry;
274 }
275 return 0;
276
277next_entry:
278 pcmcia_disable_device(p_dev);
279 return -ENODEV;
280}; 194};
281 195
282static int 196static int
@@ -287,20 +201,10 @@ spectrum_cs_config(struct pcmcia_device *link)
287 int ret; 201 int ret;
288 void __iomem *mem; 202 void __iomem *mem;
289 203
290 /* 204 link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC |
291 * In this loop, we scan the CIS for configuration table 205 CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
292 * entries, each of which describes a valid card 206 if (ignore_cis_vcc)
293 * configuration, including voltage, IO window, memory window, 207 link->config_flags &= ~CONF_AUTO_CHECK_VCC;
294 * and interrupt settings.
295 *
296 * We make no assumptions about the card to be configured: we
297 * use just the information available in the CIS. In an ideal
298 * world, this would work for any PCMCIA card, but it requires
299 * a complete and accurate CIS. In practice, a driver usually
300 * "knows" most of these things without consulting the CIS,
301 * and most client drivers will only use the CIS to fill in
302 * implementation-defined details.
303 */
304 ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL); 208 ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
305 if (ret) { 209 if (ret) {
306 if (!ignore_cis_vcc) 210 if (!ignore_cis_vcc)
@@ -325,12 +229,7 @@ spectrum_cs_config(struct pcmcia_device *link)
325 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING); 229 hermes_struct_init(hw, mem, HERMES_16BIT_REGSPACING);
326 hw->eeprom_pda = true; 230 hw->eeprom_pda = true;
327 231
328 /* 232 ret = pcmcia_enable_device(link);
329 * This actually configures the PCMCIA socket -- setting up
330 * the I/O windows and the interrupt mapping, and putting the
331 * card and host interface into "Memory and IO" mode.
332 */
333 ret = pcmcia_request_configuration(link, &link->conf);
334 if (ret) 233 if (ret)
335 goto failed; 234 goto failed;
336 235
@@ -358,11 +257,6 @@ spectrum_cs_config(struct pcmcia_device *link)
358 return -ENODEV; 257 return -ENODEV;
359} /* spectrum_cs_config */ 258} /* spectrum_cs_config */
360 259
361/*
362 * After a card is removed, spectrum_cs_release() will unregister the
363 * device, and release the PCMCIA configuration. If the device is
364 * still open, this will be postponed until it is closed.
365 */
366static void 260static void
367spectrum_cs_release(struct pcmcia_device *link) 261spectrum_cs_release(struct pcmcia_device *link)
368{ 262{
@@ -407,12 +301,6 @@ spectrum_cs_resume(struct pcmcia_device *link)
407/* Module initialization */ 301/* Module initialization */
408/********************************************************************/ 302/********************************************************************/
409 303
410/* Can't be declared "const" or the whole __initdata section will
411 * become const */
412static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
413 " (Pavel Roskin <proski@gnu.org>,"
414 " David Gibson <hermes@gibson.dropbear.id.au>, et al)";
415
416static struct pcmcia_device_id spectrum_cs_ids[] = { 304static struct pcmcia_device_id spectrum_cs_ids[] = {
417 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */ 305 PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), /* Symbol Spectrum24 LA4137 */
418 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */ 306 PCMCIA_DEVICE_MANF_CARD(0x0104, 0x0001), /* Socket Communications CF */
@@ -423,9 +311,7 @@ MODULE_DEVICE_TABLE(pcmcia, spectrum_cs_ids);
423 311
424static struct pcmcia_driver orinoco_driver = { 312static struct pcmcia_driver orinoco_driver = {
425 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
426 .drv = { 314 .name = DRIVER_NAME,
427 .name = DRIVER_NAME,
428 },
429 .probe = spectrum_cs_probe, 315 .probe = spectrum_cs_probe,
430 .remove = spectrum_cs_detach, 316 .remove = spectrum_cs_detach,
431 .suspend = spectrum_cs_suspend, 317 .suspend = spectrum_cs_suspend,
@@ -436,8 +322,6 @@ static struct pcmcia_driver orinoco_driver = {
436static int __init 322static int __init
437init_spectrum_cs(void) 323init_spectrum_cs(void)
438{ 324{
439 printk(KERN_DEBUG "%s\n", version);
440
441 return pcmcia_register_driver(&orinoco_driver); 325 return pcmcia_register_driver(&orinoco_driver);
442} 326}
443 327
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index dab30a8c7470..46da03753fd5 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -46,7 +46,6 @@
46#include <linux/ethtool.h> 46#include <linux/ethtool.h>
47#include <linux/ieee80211.h> 47#include <linux/ieee80211.h>
48 48
49#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h> 49#include <pcmcia/cistpl.h>
51#include <pcmcia/cisreg.h> 50#include <pcmcia/cisreg.h>
52#include <pcmcia/ds.h> 51#include <pcmcia/ds.h>
@@ -169,13 +168,6 @@ static int bc;
169 */ 168 */
170static char *phy_addr = NULL; 169static char *phy_addr = NULL;
171 170
172
173/* A struct pcmcia_device structure has fields for most things that are needed
174 to keep track of a socket, but there will usually be some device
175 specific information that also needs to be kept track of. The
176 'priv' pointer in a struct pcmcia_device structure can be used to point to
177 a device-specific private data structure, like this.
178*/
179static unsigned int ray_mem_speed = 500; 171static unsigned int ray_mem_speed = 500;
180 172
181/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */ 173/* WARNING: THIS DRIVER IS NOT CAPABLE OF HANDLING MULTIPLE DEVICES! */
@@ -290,14 +282,6 @@ static const struct net_device_ops ray_netdev_ops = {
290 .ndo_validate_addr = eth_validate_addr, 282 .ndo_validate_addr = eth_validate_addr,
291}; 283};
292 284
293/*=============================================================================
294 ray_attach() creates an "instance" of the driver, allocating
295 local data structures for one device. The device is registered
296 with Card Services.
297 The dev_link structure is initialized, but we don't actually
298 configure the card at this point -- we wait until we receive a
299 card insertion event.
300=============================================================================*/
301static int ray_probe(struct pcmcia_device *p_dev) 285static int ray_probe(struct pcmcia_device *p_dev)
302{ 286{
303 ray_dev_t *local; 287 ray_dev_t *local;
@@ -318,9 +302,8 @@ static int ray_probe(struct pcmcia_device *p_dev)
318 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 302 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
319 303
320 /* General socket configuration */ 304 /* General socket configuration */
321 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 305 p_dev->config_flags |= CONF_ENABLE_IRQ;
322 p_dev->conf.IntType = INT_MEMORY_AND_IO; 306 p_dev->config_index = 1;
323 p_dev->conf.ConfigIndex = 1;
324 307
325 p_dev->priv = dev; 308 p_dev->priv = dev;
326 309
@@ -353,12 +336,6 @@ fail_alloc_dev:
353 return -ENOMEM; 336 return -ENOMEM;
354} /* ray_attach */ 337} /* ray_attach */
355 338
356/*=============================================================================
357 This deletes a driver "instance". The device is de-registered
358 with Card Services. If it has been released, all local data
359 structures are freed. Otherwise, the structures will be freed
360 when the device is released.
361=============================================================================*/
362static void ray_detach(struct pcmcia_device *link) 339static void ray_detach(struct pcmcia_device *link)
363{ 340{
364 struct net_device *dev; 341 struct net_device *dev;
@@ -381,17 +358,11 @@ static void ray_detach(struct pcmcia_device *link)
381 dev_dbg(&link->dev, "ray_cs ray_detach ending\n"); 358 dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
382} /* ray_detach */ 359} /* ray_detach */
383 360
384/*=============================================================================
385 ray_config() is run after a CARD_INSERTION event
386 is received, to configure the PCMCIA socket, and to make the
387 ethernet device available to the system.
388=============================================================================*/
389#define MAX_TUPLE_SIZE 128 361#define MAX_TUPLE_SIZE 128
390static int ray_config(struct pcmcia_device *link) 362static int ray_config(struct pcmcia_device *link)
391{ 363{
392 int ret = 0; 364 int ret = 0;
393 int i; 365 int i;
394 win_req_t req;
395 struct net_device *dev = (struct net_device *)link->priv; 366 struct net_device *dev = (struct net_device *)link->priv;
396 ray_dev_t *local = netdev_priv(dev); 367 ray_dev_t *local = netdev_priv(dev);
397 368
@@ -412,54 +383,50 @@ static int ray_config(struct pcmcia_device *link)
412 goto failed; 383 goto failed;
413 dev->irq = link->irq; 384 dev->irq = link->irq;
414 385
415 /* This actually configures the PCMCIA socket -- setting up 386 ret = pcmcia_enable_device(link);
416 the I/O windows and the interrupt mapping.
417 */
418 ret = pcmcia_request_configuration(link, &link->conf);
419 if (ret) 387 if (ret)
420 goto failed; 388 goto failed;
421 389
422/*** Set up 32k window for shared memory (transmit and control) ************/ 390/*** Set up 32k window for shared memory (transmit and control) ************/
423 req.Attributes = 391 link->resource[2]->flags |= WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
424 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 392 link->resource[2]->start = 0;
425 req.Base = 0; 393 link->resource[2]->end = 0x8000;
426 req.Size = 0x8000; 394 ret = pcmcia_request_window(link, link->resource[2], ray_mem_speed);
427 req.AccessSpeed = ray_mem_speed;
428 ret = pcmcia_request_window(link, &req, &link->win);
429 if (ret) 395 if (ret)
430 goto failed; 396 goto failed;
431 ret = pcmcia_map_mem_page(link, link->win, 0); 397 ret = pcmcia_map_mem_page(link, link->resource[2], 0);
432 if (ret) 398 if (ret)
433 goto failed; 399 goto failed;
434 local->sram = ioremap(req.Base, req.Size); 400 local->sram = ioremap(link->resource[2]->start,
401 resource_size(link->resource[2]));
435 402
436/*** Set up 16k window for shared memory (receive buffer) ***************/ 403/*** Set up 16k window for shared memory (receive buffer) ***************/
437 req.Attributes = 404 link->resource[3]->flags |=
438 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT; 405 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
439 req.Base = 0; 406 link->resource[3]->start = 0;
440 req.Size = 0x4000; 407 link->resource[3]->end = 0x4000;
441 req.AccessSpeed = ray_mem_speed; 408 ret = pcmcia_request_window(link, link->resource[3], ray_mem_speed);
442 ret = pcmcia_request_window(link, &req, &local->rmem_handle);
443 if (ret) 409 if (ret)
444 goto failed; 410 goto failed;
445 ret = pcmcia_map_mem_page(link, local->rmem_handle, 0x8000); 411 ret = pcmcia_map_mem_page(link, link->resource[3], 0x8000);
446 if (ret) 412 if (ret)
447 goto failed; 413 goto failed;
448 local->rmem = ioremap(req.Base, req.Size); 414 local->rmem = ioremap(link->resource[3]->start,
415 resource_size(link->resource[3]));
449 416
450/*** Set up window for attribute memory ***********************************/ 417/*** Set up window for attribute memory ***********************************/
451 req.Attributes = 418 link->resource[4]->flags |=
452 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT; 419 WIN_DATA_WIDTH_8 | WIN_MEMORY_TYPE_AM | WIN_ENABLE | WIN_USE_WAIT;
453 req.Base = 0; 420 link->resource[4]->start = 0;
454 req.Size = 0x1000; 421 link->resource[4]->end = 0x1000;
455 req.AccessSpeed = ray_mem_speed; 422 ret = pcmcia_request_window(link, link->resource[4], ray_mem_speed);
456 ret = pcmcia_request_window(link, &req, &local->amem_handle);
457 if (ret) 423 if (ret)
458 goto failed; 424 goto failed;
459 ret = pcmcia_map_mem_page(link, local->amem_handle, 0); 425 ret = pcmcia_map_mem_page(link, link->resource[4], 0);
460 if (ret) 426 if (ret)
461 goto failed; 427 goto failed;
462 local->amem = ioremap(req.Base, req.Size); 428 local->amem = ioremap(link->resource[4]->start,
429 resource_size(link->resource[4]));
463 430
464 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram); 431 dev_dbg(&link->dev, "ray_config sram=%p\n", local->sram);
465 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem); 432 dev_dbg(&link->dev, "ray_config rmem=%p\n", local->rmem);
@@ -775,11 +742,7 @@ static void join_net(u_long data)
775 local->card_status = CARD_DOING_ACQ; 742 local->card_status = CARD_DOING_ACQ;
776} 743}
777 744
778/*============================================================================ 745
779 After a card is removed, ray_release() will unregister the net
780 device, and release the PCMCIA configuration. If the device is
781 still open, this will be postponed until it is closed.
782=============================================================================*/
783static void ray_release(struct pcmcia_device *link) 746static void ray_release(struct pcmcia_device *link)
784{ 747{
785 struct net_device *dev = link->priv; 748 struct net_device *dev = link->priv;
@@ -2849,9 +2812,7 @@ MODULE_DEVICE_TABLE(pcmcia, ray_ids);
2849 2812
2850static struct pcmcia_driver ray_driver = { 2813static struct pcmcia_driver ray_driver = {
2851 .owner = THIS_MODULE, 2814 .owner = THIS_MODULE,
2852 .drv = { 2815 .name = "ray_cs",
2853 .name = "ray_cs",
2854 },
2855 .probe = ray_probe, 2816 .probe = ray_probe,
2856 .remove = ray_detach, 2817 .remove = ray_detach,
2857 .id_table = ray_ids, 2818 .id_table = ray_ids,
diff --git a/drivers/net/wireless/ray_cs.h b/drivers/net/wireless/ray_cs.h
index 9f01ddb19748..e79848fbcca1 100644
--- a/drivers/net/wireless/ray_cs.h
+++ b/drivers/net/wireless/ray_cs.h
@@ -25,8 +25,6 @@ struct beacon_rx {
25typedef struct ray_dev_t { 25typedef struct ray_dev_t {
26 int card_status; 26 int card_status;
27 int authentication_state; 27 int authentication_state;
28 window_handle_t amem_handle; /* handle to window for attribute memory */
29 window_handle_t rmem_handle; /* handle to window for rx buffer on card */
30 void __iomem *sram; /* pointer to beginning of shared RAM */ 28 void __iomem *sram; /* pointer to beginning of shared RAM */
31 void __iomem *amem; /* pointer to attribute mem window */ 29 void __iomem *amem; /* pointer to attribute mem window */
32 void __iomem *rmem; /* pointer to receive buffer window */ 30 void __iomem *rmem; /* pointer to receive buffer window */
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index a1cc2d498a1c..ca3f8961fa27 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -48,7 +48,6 @@
48 48
49#include <net/iw_handler.h> 49#include <net/iw_handler.h>
50 50
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/cisreg.h> 52#include <pcmcia/cisreg.h>
54#include <pcmcia/ds.h> 53#include <pcmcia/ds.h>
@@ -78,13 +77,6 @@
78#define WL3501_RESUME 0 77#define WL3501_RESUME 0
79#define WL3501_SUSPEND 1 78#define WL3501_SUSPEND 1
80 79
81/*
82 * The event() function is this driver's Card Services event handler. It will
83 * be called by Card Services when an appropriate card status event is
84 * received. The config() and release() entry points are used to configure or
85 * release a socket, in response to card insertion and ejection events. They
86 * are invoked from the wl24 event handler.
87 */
88static int wl3501_config(struct pcmcia_device *link); 80static int wl3501_config(struct pcmcia_device *link);
89static void wl3501_release(struct pcmcia_device *link); 81static void wl3501_release(struct pcmcia_device *link);
90 82
@@ -1869,15 +1861,6 @@ static const struct net_device_ops wl3501_netdev_ops = {
1869 .ndo_validate_addr = eth_validate_addr, 1861 .ndo_validate_addr = eth_validate_addr,
1870}; 1862};
1871 1863
1872/**
1873 * wl3501_attach - creates an "instance" of the driver
1874 *
1875 * Creates an "instance" of the driver, allocating local data structures for
1876 * one device. The device is registered with Card Services.
1877 *
1878 * The dev_link structure is initialized, but we don't actually configure the
1879 * card at this point -- we wait until we receive a card insertion event.
1880 */
1881static int wl3501_probe(struct pcmcia_device *p_dev) 1864static int wl3501_probe(struct pcmcia_device *p_dev)
1882{ 1865{
1883 struct net_device *dev; 1866 struct net_device *dev;
@@ -1888,9 +1871,8 @@ static int wl3501_probe(struct pcmcia_device *p_dev)
1888 p_dev->resource[0]->flags = IO_DATA_PATH_WIDTH_8; 1871 p_dev->resource[0]->flags = IO_DATA_PATH_WIDTH_8;
1889 1872
1890 /* General socket configuration */ 1873 /* General socket configuration */
1891 p_dev->conf.Attributes = CONF_ENABLE_IRQ; 1874 p_dev->config_flags = CONF_ENABLE_IRQ;
1892 p_dev->conf.IntType = INT_MEMORY_AND_IO; 1875 p_dev->config_index = 1;
1893 p_dev->conf.ConfigIndex = 1;
1894 1876
1895 dev = alloc_etherdev(sizeof(struct wl3501_card)); 1877 dev = alloc_etherdev(sizeof(struct wl3501_card));
1896 if (!dev) 1878 if (!dev)
@@ -1914,14 +1896,6 @@ out_link:
1914 return -ENOMEM; 1896 return -ENOMEM;
1915} 1897}
1916 1898
1917/**
1918 * wl3501_config - configure the PCMCIA socket and make eth device available
1919 * @link - FILL_IN
1920 *
1921 * wl3501_config() is scheduled to run after a CARD_INSERTION event is
1922 * received, to configure the PCMCIA socket, and to make the ethernet device
1923 * available to the system.
1924 */
1925static int wl3501_config(struct pcmcia_device *link) 1899static int wl3501_config(struct pcmcia_device *link)
1926{ 1900{
1927 struct net_device *dev = link->priv; 1901 struct net_device *dev = link->priv;
@@ -1952,10 +1926,7 @@ static int wl3501_config(struct pcmcia_device *link)
1952 if (ret) 1926 if (ret)
1953 goto failed; 1927 goto failed;
1954 1928
1955 /* This actually configures the PCMCIA socket -- setting up the I/O 1929 ret = pcmcia_enable_device(link);
1956 * windows and the interrupt mapping. */
1957
1958 ret = pcmcia_request_configuration(link, &link->conf);
1959 if (ret) 1930 if (ret)
1960 goto failed; 1931 goto failed;
1961 1932
@@ -2010,14 +1981,6 @@ failed:
2010 return -ENODEV; 1981 return -ENODEV;
2011} 1982}
2012 1983
2013/**
2014 * wl3501_release - unregister the net, release PCMCIA configuration
2015 * @arg - link
2016 *
2017 * After a card is removed, wl3501_release() will unregister the net device,
2018 * and release the PCMCIA configuration. If the device is still open, this
2019 * will be postponed until it is closed.
2020 */
2021static void wl3501_release(struct pcmcia_device *link) 1984static void wl3501_release(struct pcmcia_device *link)
2022{ 1985{
2023 pcmcia_disable_device(link); 1986 pcmcia_disable_device(link);
@@ -2056,9 +2019,7 @@ MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
2056 2019
2057static struct pcmcia_driver wl3501_driver = { 2020static struct pcmcia_driver wl3501_driver = {
2058 .owner = THIS_MODULE, 2021 .owner = THIS_MODULE,
2059 .drv = { 2022 .name = "wl3501_cs",
2060 .name = "wl3501_cs",
2061 },
2062 .probe = wl3501_probe, 2023 .probe = wl3501_probe,
2063 .remove = wl3501_detach, 2024 .remove = wl3501_detach,
2064 .id_table = wl3501_ids, 2025 .id_table = wl3501_ids,
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
index b336cd9ee7a1..f9bda64fcd1b 100644
--- a/drivers/oprofile/oprof.c
+++ b/drivers/oprofile/oprof.c
@@ -225,26 +225,17 @@ post_sync:
225 mutex_unlock(&start_mutex); 225 mutex_unlock(&start_mutex);
226} 226}
227 227
228int oprofile_set_backtrace(unsigned long val) 228int oprofile_set_ulong(unsigned long *addr, unsigned long val)
229{ 229{
230 int err = 0; 230 int err = -EBUSY;
231 231
232 mutex_lock(&start_mutex); 232 mutex_lock(&start_mutex);
233 233 if (!oprofile_started) {
234 if (oprofile_started) { 234 *addr = val;
235 err = -EBUSY; 235 err = 0;
236 goto out;
237 }
238
239 if (!oprofile_ops.backtrace) {
240 err = -EINVAL;
241 goto out;
242 } 236 }
243
244 oprofile_backtrace_depth = val;
245
246out:
247 mutex_unlock(&start_mutex); 237 mutex_unlock(&start_mutex);
238
248 return err; 239 return err;
249} 240}
250 241
@@ -257,16 +248,9 @@ static int __init oprofile_init(void)
257 printk(KERN_INFO "oprofile: using timer interrupt.\n"); 248 printk(KERN_INFO "oprofile: using timer interrupt.\n");
258 err = oprofile_timer_init(&oprofile_ops); 249 err = oprofile_timer_init(&oprofile_ops);
259 if (err) 250 if (err)
260 goto out_arch; 251 return err;
261 } 252 }
262 err = oprofilefs_register(); 253 return oprofilefs_register();
263 if (err)
264 goto out_arch;
265 return 0;
266
267out_arch:
268 oprofile_arch_exit();
269 return err;
270} 254}
271 255
272 256
diff --git a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h
index 47e12cb4ee8b..177b73de5e5f 100644
--- a/drivers/oprofile/oprof.h
+++ b/drivers/oprofile/oprof.h
@@ -37,7 +37,7 @@ void oprofile_create_files(struct super_block *sb, struct dentry *root);
37int oprofile_timer_init(struct oprofile_operations *ops); 37int oprofile_timer_init(struct oprofile_operations *ops);
38void oprofile_timer_exit(void); 38void oprofile_timer_exit(void);
39 39
40int oprofile_set_backtrace(unsigned long depth); 40int oprofile_set_ulong(unsigned long *addr, unsigned long val);
41int oprofile_set_timeout(unsigned long time); 41int oprofile_set_timeout(unsigned long time);
42 42
43#endif /* OPROF_H */ 43#endif /* OPROF_H */
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
index 9bb4d4bdc237..89f63456646f 100644
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -80,14 +80,17 @@ static ssize_t depth_write(struct file *file, char const __user *buf, size_t cou
80 if (*offset) 80 if (*offset)
81 return -EINVAL; 81 return -EINVAL;
82 82
83 if (!oprofile_ops.backtrace)
84 return -EINVAL;
85
83 retval = oprofilefs_ulong_from_user(&val, buf, count); 86 retval = oprofilefs_ulong_from_user(&val, buf, count);
84 if (retval) 87 if (retval)
85 return retval; 88 return retval;
86 89
87 retval = oprofile_set_backtrace(val); 90 retval = oprofile_set_ulong(&oprofile_backtrace_depth, val);
88
89 if (retval) 91 if (retval)
90 return retval; 92 return retval;
93
91 return count; 94 return count;
92} 95}
93 96
diff --git a/drivers/oprofile/oprofile_perf.c b/drivers/oprofile/oprofile_perf.c
new file mode 100644
index 000000000000..9046f7b2ed79
--- /dev/null
+++ b/drivers/oprofile/oprofile_perf.c
@@ -0,0 +1,328 @@
1/*
2 * Copyright 2010 ARM Ltd.
3 *
4 * Perf-events backend for OProfile.
5 */
6#include <linux/perf_event.h>
7#include <linux/platform_device.h>
8#include <linux/oprofile.h>
9#include <linux/slab.h>
10
11/*
12 * Per performance monitor configuration as set via oprofilefs.
13 */
14struct op_counter_config {
15 unsigned long count;
16 unsigned long enabled;
17 unsigned long event;
18 unsigned long unit_mask;
19 unsigned long kernel;
20 unsigned long user;
21 struct perf_event_attr attr;
22};
23
24static int oprofile_perf_enabled;
25static DEFINE_MUTEX(oprofile_perf_mutex);
26
27static struct op_counter_config *counter_config;
28static struct perf_event **perf_events[nr_cpumask_bits];
29static int num_counters;
30
31/*
32 * Overflow callback for oprofile.
33 */
34static void op_overflow_handler(struct perf_event *event, int unused,
35 struct perf_sample_data *data, struct pt_regs *regs)
36{
37 int id;
38 u32 cpu = smp_processor_id();
39
40 for (id = 0; id < num_counters; ++id)
41 if (perf_events[cpu][id] == event)
42 break;
43
44 if (id != num_counters)
45 oprofile_add_sample(regs, id);
46 else
47 pr_warning("oprofile: ignoring spurious overflow "
48 "on cpu %u\n", cpu);
49}
50
51/*
52 * Called by oprofile_perf_setup to create perf attributes to mirror the oprofile
53 * settings in counter_config. Attributes are created as `pinned' events and
54 * so are permanently scheduled on the PMU.
55 */
56static void op_perf_setup(void)
57{
58 int i;
59 u32 size = sizeof(struct perf_event_attr);
60 struct perf_event_attr *attr;
61
62 for (i = 0; i < num_counters; ++i) {
63 attr = &counter_config[i].attr;
64 memset(attr, 0, size);
65 attr->type = PERF_TYPE_RAW;
66 attr->size = size;
67 attr->config = counter_config[i].event;
68 attr->sample_period = counter_config[i].count;
69 attr->pinned = 1;
70 }
71}
72
73static int op_create_counter(int cpu, int event)
74{
75 struct perf_event *pevent;
76
77 if (!counter_config[event].enabled || perf_events[cpu][event])
78 return 0;
79
80 pevent = perf_event_create_kernel_counter(&counter_config[event].attr,
81 cpu, NULL,
82 op_overflow_handler);
83
84 if (IS_ERR(pevent))
85 return PTR_ERR(pevent);
86
87 if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
88 perf_event_release_kernel(pevent);
89 pr_warning("oprofile: failed to enable event %d "
90 "on CPU %d\n", event, cpu);
91 return -EBUSY;
92 }
93
94 perf_events[cpu][event] = pevent;
95
96 return 0;
97}
98
99static void op_destroy_counter(int cpu, int event)
100{
101 struct perf_event *pevent = perf_events[cpu][event];
102
103 if (pevent) {
104 perf_event_release_kernel(pevent);
105 perf_events[cpu][event] = NULL;
106 }
107}
108
109/*
110 * Called by oprofile_perf_start to create active perf events based on the
111 * perviously configured attributes.
112 */
113static int op_perf_start(void)
114{
115 int cpu, event, ret = 0;
116
117 for_each_online_cpu(cpu) {
118 for (event = 0; event < num_counters; ++event) {
119 ret = op_create_counter(cpu, event);
120 if (ret)
121 return ret;
122 }
123 }
124
125 return ret;
126}
127
128/*
129 * Called by oprofile_perf_stop at the end of a profiling run.
130 */
131static void op_perf_stop(void)
132{
133 int cpu, event;
134
135 for_each_online_cpu(cpu)
136 for (event = 0; event < num_counters; ++event)
137 op_destroy_counter(cpu, event);
138}
139
140static int oprofile_perf_create_files(struct super_block *sb, struct dentry *root)
141{
142 unsigned int i;
143
144 for (i = 0; i < num_counters; i++) {
145 struct dentry *dir;
146 char buf[4];
147
148 snprintf(buf, sizeof buf, "%d", i);
149 dir = oprofilefs_mkdir(sb, root, buf);
150 oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);
151 oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);
152 oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);
153 oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);
154 oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);
155 oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);
156 }
157
158 return 0;
159}
160
161static int oprofile_perf_setup(void)
162{
163 spin_lock(&oprofilefs_lock);
164 op_perf_setup();
165 spin_unlock(&oprofilefs_lock);
166 return 0;
167}
168
169static int oprofile_perf_start(void)
170{
171 int ret = -EBUSY;
172
173 mutex_lock(&oprofile_perf_mutex);
174 if (!oprofile_perf_enabled) {
175 ret = 0;
176 op_perf_start();
177 oprofile_perf_enabled = 1;
178 }
179 mutex_unlock(&oprofile_perf_mutex);
180 return ret;
181}
182
183static void oprofile_perf_stop(void)
184{
185 mutex_lock(&oprofile_perf_mutex);
186 if (oprofile_perf_enabled)
187 op_perf_stop();
188 oprofile_perf_enabled = 0;
189 mutex_unlock(&oprofile_perf_mutex);
190}
191
192#ifdef CONFIG_PM
193
194static int oprofile_perf_suspend(struct platform_device *dev, pm_message_t state)
195{
196 mutex_lock(&oprofile_perf_mutex);
197 if (oprofile_perf_enabled)
198 op_perf_stop();
199 mutex_unlock(&oprofile_perf_mutex);
200 return 0;
201}
202
203static int oprofile_perf_resume(struct platform_device *dev)
204{
205 mutex_lock(&oprofile_perf_mutex);
206 if (oprofile_perf_enabled && op_perf_start())
207 oprofile_perf_enabled = 0;
208 mutex_unlock(&oprofile_perf_mutex);
209 return 0;
210}
211
212static struct platform_driver oprofile_driver = {
213 .driver = {
214 .name = "oprofile-perf",
215 },
216 .resume = oprofile_perf_resume,
217 .suspend = oprofile_perf_suspend,
218};
219
220static struct platform_device *oprofile_pdev;
221
222static int __init init_driverfs(void)
223{
224 int ret;
225
226 ret = platform_driver_register(&oprofile_driver);
227 if (ret)
228 return ret;
229
230 oprofile_pdev = platform_device_register_simple(
231 oprofile_driver.driver.name, 0, NULL, 0);
232 if (IS_ERR(oprofile_pdev)) {
233 ret = PTR_ERR(oprofile_pdev);
234 platform_driver_unregister(&oprofile_driver);
235 }
236
237 return ret;
238}
239
240static void exit_driverfs(void)
241{
242 platform_device_unregister(oprofile_pdev);
243 platform_driver_unregister(&oprofile_driver);
244}
245
246#else
247
248static inline int init_driverfs(void) { return 0; }
249static inline void exit_driverfs(void) { }
250
251#endif /* CONFIG_PM */
252
253void oprofile_perf_exit(void)
254{
255 int cpu, id;
256 struct perf_event *event;
257
258 for_each_possible_cpu(cpu) {
259 for (id = 0; id < num_counters; ++id) {
260 event = perf_events[cpu][id];
261 if (event)
262 perf_event_release_kernel(event);
263 }
264
265 kfree(perf_events[cpu]);
266 }
267
268 kfree(counter_config);
269 exit_driverfs();
270}
271
272int __init oprofile_perf_init(struct oprofile_operations *ops)
273{
274 int cpu, ret = 0;
275
276 ret = init_driverfs();
277 if (ret)
278 return ret;
279
280 memset(&perf_events, 0, sizeof(perf_events));
281
282 num_counters = perf_num_counters();
283 if (num_counters <= 0) {
284 pr_info("oprofile: no performance counters\n");
285 ret = -ENODEV;
286 goto out;
287 }
288
289 counter_config = kcalloc(num_counters,
290 sizeof(struct op_counter_config), GFP_KERNEL);
291
292 if (!counter_config) {
293 pr_info("oprofile: failed to allocate %d "
294 "counters\n", num_counters);
295 ret = -ENOMEM;
296 num_counters = 0;
297 goto out;
298 }
299
300 for_each_possible_cpu(cpu) {
301 perf_events[cpu] = kcalloc(num_counters,
302 sizeof(struct perf_event *), GFP_KERNEL);
303 if (!perf_events[cpu]) {
304 pr_info("oprofile: failed to allocate %d perf events "
305 "for cpu %d\n", num_counters, cpu);
306 ret = -ENOMEM;
307 goto out;
308 }
309 }
310
311 ops->create_files = oprofile_perf_create_files;
312 ops->setup = oprofile_perf_setup;
313 ops->start = oprofile_perf_start;
314 ops->stop = oprofile_perf_stop;
315 ops->shutdown = oprofile_perf_stop;
316 ops->cpu_type = op_name_from_perf_id();
317
318 if (!ops->cpu_type)
319 ret = -ENODEV;
320 else
321 pr_info("oprofile: using %s\n", ops->cpu_type);
322
323out:
324 if (ret)
325 oprofile_perf_exit();
326
327 return ret;
328}
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 6b6a1f71957d..95f711b251ad 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -91,16 +91,20 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count
91 91
92static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) 92static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset)
93{ 93{
94 unsigned long *value = file->private_data; 94 unsigned long value;
95 int retval; 95 int retval;
96 96
97 if (*offset) 97 if (*offset)
98 return -EINVAL; 98 return -EINVAL;
99 99
100 retval = oprofilefs_ulong_from_user(value, buf, count); 100 retval = oprofilefs_ulong_from_user(&value, buf, count);
101 if (retval)
102 return retval;
101 103
104 retval = oprofile_set_ulong(file->private_data, value);
102 if (retval) 105 if (retval)
103 return retval; 106 return retval;
107
104 return count; 108 return count;
105} 109}
106 110
@@ -128,50 +132,41 @@ static const struct file_operations ulong_ro_fops = {
128}; 132};
129 133
130 134
131static struct dentry *__oprofilefs_create_file(struct super_block *sb, 135static int __oprofilefs_create_file(struct super_block *sb,
132 struct dentry *root, char const *name, const struct file_operations *fops, 136 struct dentry *root, char const *name, const struct file_operations *fops,
133 int perm) 137 int perm, void *priv)
134{ 138{
135 struct dentry *dentry; 139 struct dentry *dentry;
136 struct inode *inode; 140 struct inode *inode;
137 141
138 dentry = d_alloc_name(root, name); 142 dentry = d_alloc_name(root, name);
139 if (!dentry) 143 if (!dentry)
140 return NULL; 144 return -ENOMEM;
141 inode = oprofilefs_get_inode(sb, S_IFREG | perm); 145 inode = oprofilefs_get_inode(sb, S_IFREG | perm);
142 if (!inode) { 146 if (!inode) {
143 dput(dentry); 147 dput(dentry);
144 return NULL; 148 return -ENOMEM;
145 } 149 }
146 inode->i_fop = fops; 150 inode->i_fop = fops;
147 d_add(dentry, inode); 151 d_add(dentry, inode);
148 return dentry; 152 dentry->d_inode->i_private = priv;
153 return 0;
149} 154}
150 155
151 156
152int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, 157int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root,
153 char const *name, unsigned long *val) 158 char const *name, unsigned long *val)
154{ 159{
155 struct dentry *d = __oprofilefs_create_file(sb, root, name, 160 return __oprofilefs_create_file(sb, root, name,
156 &ulong_fops, 0644); 161 &ulong_fops, 0644, val);
157 if (!d)
158 return -EFAULT;
159
160 d->d_inode->i_private = val;
161 return 0;
162} 162}
163 163
164 164
165int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, 165int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root,
166 char const *name, unsigned long *val) 166 char const *name, unsigned long *val)
167{ 167{
168 struct dentry *d = __oprofilefs_create_file(sb, root, name, 168 return __oprofilefs_create_file(sb, root, name,
169 &ulong_ro_fops, 0444); 169 &ulong_ro_fops, 0444, val);
170 if (!d)
171 return -EFAULT;
172
173 d->d_inode->i_private = val;
174 return 0;
175} 170}
176 171
177 172
@@ -192,31 +187,22 @@ static const struct file_operations atomic_ro_fops = {
192int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, 187int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
193 char const *name, atomic_t *val) 188 char const *name, atomic_t *val)
194{ 189{
195 struct dentry *d = __oprofilefs_create_file(sb, root, name, 190 return __oprofilefs_create_file(sb, root, name,
196 &atomic_ro_fops, 0444); 191 &atomic_ro_fops, 0444, val);
197 if (!d)
198 return -EFAULT;
199
200 d->d_inode->i_private = val;
201 return 0;
202} 192}
203 193
204 194
205int oprofilefs_create_file(struct super_block *sb, struct dentry *root, 195int oprofilefs_create_file(struct super_block *sb, struct dentry *root,
206 char const *name, const struct file_operations *fops) 196 char const *name, const struct file_operations *fops)
207{ 197{
208 if (!__oprofilefs_create_file(sb, root, name, fops, 0644)) 198 return __oprofilefs_create_file(sb, root, name, fops, 0644, NULL);
209 return -EFAULT;
210 return 0;
211} 199}
212 200
213 201
214int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, 202int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root,
215 char const *name, const struct file_operations *fops, int perm) 203 char const *name, const struct file_operations *fops, int perm)
216{ 204{
217 if (!__oprofilefs_create_file(sb, root, name, fops, perm)) 205 return __oprofilefs_create_file(sb, root, name, fops, perm, NULL);
218 return -EFAULT;
219 return 0;
220} 206}
221 207
222 208
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 23e50f4a27c5..787ebdeae310 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -48,7 +48,6 @@
48#include <linux/parport.h> 48#include <linux/parport.h>
49#include <linux/parport_pc.h> 49#include <linux/parport_pc.h>
50 50
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
54#include <pcmcia/cisreg.h> 53#include <pcmcia/cisreg.h>
@@ -81,14 +80,6 @@ static void parport_detach(struct pcmcia_device *p_dev);
81static int parport_config(struct pcmcia_device *link); 80static int parport_config(struct pcmcia_device *link);
82static void parport_cs_release(struct pcmcia_device *); 81static void parport_cs_release(struct pcmcia_device *);
83 82
84/*======================================================================
85
86 parport_attach() creates an "instance" of the driver, allocating
87 local data structures for one device. The device is registered
88 with Card Services.
89
90======================================================================*/
91
92static int parport_probe(struct pcmcia_device *link) 83static int parport_probe(struct pcmcia_device *link)
93{ 84{
94 parport_info_t *info; 85 parport_info_t *info;
@@ -101,23 +92,11 @@ static int parport_probe(struct pcmcia_device *link)
101 link->priv = info; 92 link->priv = info;
102 info->p_dev = link; 93 info->p_dev = link;
103 94
104 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 95 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
105 link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
106 link->conf.Attributes = CONF_ENABLE_IRQ;
107 link->conf.IntType = INT_MEMORY_AND_IO;
108 96
109 return parport_config(link); 97 return parport_config(link);
110} /* parport_attach */ 98} /* parport_attach */
111 99
112/*======================================================================
113
114 This deletes a driver "instance". The device is de-registered
115 with Card Services. If it has been released, all local data
116 structures are freed. Otherwise, the structures will be freed
117 when the device is released.
118
119======================================================================*/
120
121static void parport_detach(struct pcmcia_device *link) 100static void parport_detach(struct pcmcia_device *link)
122{ 101{
123 dev_dbg(&link->dev, "parport_detach\n"); 102 dev_dbg(&link->dev, "parport_detach\n");
@@ -127,36 +106,14 @@ static void parport_detach(struct pcmcia_device *link)
127 kfree(link->priv); 106 kfree(link->priv);
128} /* parport_detach */ 107} /* parport_detach */
129 108
130/*====================================================================== 109static int parport_config_check(struct pcmcia_device *p_dev, void *priv_data)
131
132 parport_config() is scheduled to run after a CARD_INSERTION event
133 is received, to configure the PCMCIA socket, and to make the
134 parport device available to the system.
135
136======================================================================*/
137
138static int parport_config_check(struct pcmcia_device *p_dev,
139 cistpl_cftable_entry_t *cfg,
140 cistpl_cftable_entry_t *dflt,
141 unsigned int vcc,
142 void *priv_data)
143{ 110{
144 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { 111 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
145 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; 112 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
146 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK; 113 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
147 if (epp_mode) 114 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
148 p_dev->conf.ConfigIndex |= FORCE_EPP_MODE; 115
149 p_dev->resource[0]->start = io->win[0].base; 116 return pcmcia_request_io(p_dev);
150 p_dev->resource[0]->end = io->win[0].len;
151 if (io->nwin == 2) {
152 p_dev->resource[1]->start = io->win[1].base;
153 p_dev->resource[1]->end = io->win[1].len;
154 }
155 if (pcmcia_request_io(p_dev) != 0)
156 return -ENODEV;
157 return 0;
158 }
159 return -ENODEV;
160} 117}
161 118
162static int parport_config(struct pcmcia_device *link) 119static int parport_config(struct pcmcia_device *link)
@@ -167,13 +124,16 @@ static int parport_config(struct pcmcia_device *link)
167 124
168 dev_dbg(&link->dev, "parport_config\n"); 125 dev_dbg(&link->dev, "parport_config\n");
169 126
127 if (epp_mode)
128 link->config_index |= FORCE_EPP_MODE;
129
170 ret = pcmcia_loop_config(link, parport_config_check, NULL); 130 ret = pcmcia_loop_config(link, parport_config_check, NULL);
171 if (ret) 131 if (ret)
172 goto failed; 132 goto failed;
173 133
174 if (!link->irq) 134 if (!link->irq)
175 goto failed; 135 goto failed;
176 ret = pcmcia_request_configuration(link, &link->conf); 136 ret = pcmcia_enable_device(link);
177 if (ret) 137 if (ret)
178 goto failed; 138 goto failed;
179 139
@@ -202,14 +162,6 @@ failed:
202 return -ENODEV; 162 return -ENODEV;
203} /* parport_config */ 163} /* parport_config */
204 164
205/*======================================================================
206
207 After a card is removed, parport_cs_release() will unregister the
208 device, and release the PCMCIA configuration. If the device is
209 still open, this will be postponed until it is closed.
210
211======================================================================*/
212
213static void parport_cs_release(struct pcmcia_device *link) 165static void parport_cs_release(struct pcmcia_device *link)
214{ 166{
215 parport_info_t *info = link->priv; 167 parport_info_t *info = link->priv;
@@ -236,9 +188,7 @@ MODULE_DEVICE_TABLE(pcmcia, parport_ids);
236 188
237static struct pcmcia_driver parport_cs_driver = { 189static struct pcmcia_driver parport_cs_driver = {
238 .owner = THIS_MODULE, 190 .owner = THIS_MODULE,
239 .drv = { 191 .name = "parport_cs",
240 .name = "parport_cs",
241 },
242 .probe = parport_probe, 192 .probe = parport_probe,
243 .remove = parport_detach, 193 .remove = parport_detach,
244 .id_table = parport_ids, 194 .id_table = parport_ids,
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index dffa5d4fb298..a2d9d1e59260 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -306,7 +306,7 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
306 spin_lock_init(&tmp->pardevice_lock); 306 spin_lock_init(&tmp->pardevice_lock);
307 tmp->ieee1284.mode = IEEE1284_MODE_COMPAT; 307 tmp->ieee1284.mode = IEEE1284_MODE_COMPAT;
308 tmp->ieee1284.phase = IEEE1284_PH_FWD_IDLE; 308 tmp->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
309 init_MUTEX_LOCKED (&tmp->ieee1284.irq); /* actually a semaphore at 0 */ 309 sema_init(&tmp->ieee1284.irq, 0);
310 tmp->spintime = parport_default_spintime; 310 tmp->spintime = parport_default_spintime;
311 atomic_set (&tmp->ref_count, 1); 311 atomic_set (&tmp->ref_count, 1);
312 INIT_LIST_HEAD(&tmp->full_list); 312 INIT_LIST_HEAD(&tmp->full_list);
diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index 0a19708074c2..0157708d474d 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -36,6 +36,7 @@
36#include <linux/tboot.h> 36#include <linux/tboot.h>
37#include <linux/dmi.h> 37#include <linux/dmi.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <asm/iommu_table.h>
39 40
40#define PREFIX "DMAR: " 41#define PREFIX "DMAR: "
41 42
@@ -687,7 +688,7 @@ failed:
687 return 0; 688 return 0;
688} 689}
689 690
690void __init detect_intel_iommu(void) 691int __init detect_intel_iommu(void)
691{ 692{
692 int ret; 693 int ret;
693 694
@@ -723,6 +724,8 @@ void __init detect_intel_iommu(void)
723 } 724 }
724 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size); 725 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
725 dmar_tbl = NULL; 726 dmar_tbl = NULL;
727
728 return ret ? 1 : -ENODEV;
726} 729}
727 730
728 731
@@ -1221,9 +1224,9 @@ const char *dmar_get_fault_reason(u8 fault_reason, int *fault_type)
1221 } 1224 }
1222} 1225}
1223 1226
1224void dmar_msi_unmask(unsigned int irq) 1227void dmar_msi_unmask(struct irq_data *data)
1225{ 1228{
1226 struct intel_iommu *iommu = get_irq_data(irq); 1229 struct intel_iommu *iommu = irq_data_get_irq_data(data);
1227 unsigned long flag; 1230 unsigned long flag;
1228 1231
1229 /* unmask it */ 1232 /* unmask it */
@@ -1234,10 +1237,10 @@ void dmar_msi_unmask(unsigned int irq)
1234 spin_unlock_irqrestore(&iommu->register_lock, flag); 1237 spin_unlock_irqrestore(&iommu->register_lock, flag);
1235} 1238}
1236 1239
1237void dmar_msi_mask(unsigned int irq) 1240void dmar_msi_mask(struct irq_data *data)
1238{ 1241{
1239 unsigned long flag; 1242 unsigned long flag;
1240 struct intel_iommu *iommu = get_irq_data(irq); 1243 struct intel_iommu *iommu = irq_data_get_irq_data(data);
1241 1244
1242 /* mask it */ 1245 /* mask it */
1243 spin_lock_irqsave(&iommu->register_lock, flag); 1246 spin_lock_irqsave(&iommu->register_lock, flag);
@@ -1455,3 +1458,4 @@ int __init dmar_ir_support(void)
1455 return 0; 1458 return 0;
1456 return dmar->flags & 0x1; 1459 return dmar->flags & 0x1;
1457} 1460}
1461IOMMU_INIT_POST(detect_intel_iommu);
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index 56215322930a..4cb30447a486 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -34,10 +34,11 @@
34#include <linux/workqueue.h> 34#include <linux/workqueue.h>
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/pci_hotplug.h> 36#include <linux/pci_hotplug.h>
37#include <linux/smp_lock.h> 37#include <linux/mutex.h>
38#include <linux/debugfs.h> 38#include <linux/debugfs.h>
39#include "cpqphp.h" 39#include "cpqphp.h"
40 40
41static DEFINE_MUTEX(cpqphp_mutex);
41static int show_ctrl (struct controller *ctrl, char *buf) 42static int show_ctrl (struct controller *ctrl, char *buf)
42{ 43{
43 char *out = buf; 44 char *out = buf;
@@ -147,7 +148,7 @@ static int open(struct inode *inode, struct file *file)
147 struct ctrl_dbg *dbg; 148 struct ctrl_dbg *dbg;
148 int retval = -ENOMEM; 149 int retval = -ENOMEM;
149 150
150 lock_kernel(); 151 mutex_lock(&cpqphp_mutex);
151 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL); 152 dbg = kmalloc(sizeof(*dbg), GFP_KERNEL);
152 if (!dbg) 153 if (!dbg)
153 goto exit; 154 goto exit;
@@ -160,7 +161,7 @@ static int open(struct inode *inode, struct file *file)
160 file->private_data = dbg; 161 file->private_data = dbg;
161 retval = 0; 162 retval = 0;
162exit: 163exit:
163 unlock_kernel(); 164 mutex_unlock(&cpqphp_mutex);
164 return retval; 165 return retval;
165} 166}
166 167
@@ -169,7 +170,7 @@ static loff_t lseek(struct file *file, loff_t off, int whence)
169 struct ctrl_dbg *dbg; 170 struct ctrl_dbg *dbg;
170 loff_t new = -1; 171 loff_t new = -1;
171 172
172 lock_kernel(); 173 mutex_lock(&cpqphp_mutex);
173 dbg = file->private_data; 174 dbg = file->private_data;
174 175
175 switch (whence) { 176 switch (whence) {
@@ -181,10 +182,10 @@ static loff_t lseek(struct file *file, loff_t off, int whence)
181 break; 182 break;
182 } 183 }
183 if (new < 0 || new > dbg->size) { 184 if (new < 0 || new > dbg->size) {
184 unlock_kernel(); 185 mutex_unlock(&cpqphp_mutex);
185 return -EINVAL; 186 return -EINVAL;
186 } 187 }
187 unlock_kernel(); 188 mutex_unlock(&cpqphp_mutex);
188 return (file->f_pos = new); 189 return (file->f_pos = new);
189} 190}
190 191
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index 98abf8b91294..834842aa5bbf 100644
--- a/drivers/pci/htirq.c
+++ b/drivers/pci/htirq.c
@@ -57,28 +57,22 @@ void fetch_ht_irq_msg(unsigned int irq, struct ht_irq_msg *msg)
57 *msg = cfg->msg; 57 *msg = cfg->msg;
58} 58}
59 59
60void mask_ht_irq(unsigned int irq) 60void mask_ht_irq(struct irq_data *data)
61{ 61{
62 struct ht_irq_cfg *cfg; 62 struct ht_irq_cfg *cfg = irq_data_get_irq_data(data);
63 struct ht_irq_msg msg; 63 struct ht_irq_msg msg = cfg->msg;
64
65 cfg = get_irq_data(irq);
66 64
67 msg = cfg->msg;
68 msg.address_lo |= 1; 65 msg.address_lo |= 1;
69 write_ht_irq_msg(irq, &msg); 66 write_ht_irq_msg(data->irq, &msg);
70} 67}
71 68
72void unmask_ht_irq(unsigned int irq) 69void unmask_ht_irq(struct irq_data *data)
73{ 70{
74 struct ht_irq_cfg *cfg; 71 struct ht_irq_cfg *cfg = irq_data_get_irq_data(data);
75 struct ht_irq_msg msg; 72 struct ht_irq_msg msg = cfg->msg;
76
77 cfg = get_irq_data(irq);
78 73
79 msg = cfg->msg;
80 msg.address_lo &= ~1; 74 msg.address_lo &= ~1;
81 write_ht_irq_msg(irq, &msg); 75 write_ht_irq_msg(data->irq, &msg);
82} 76}
83 77
84/** 78/**
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index c3ceebb5be84..4789f8e8bf7a 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -71,6 +71,49 @@
71#define DMA_32BIT_PFN IOVA_PFN(DMA_BIT_MASK(32)) 71#define DMA_32BIT_PFN IOVA_PFN(DMA_BIT_MASK(32))
72#define DMA_64BIT_PFN IOVA_PFN(DMA_BIT_MASK(64)) 72#define DMA_64BIT_PFN IOVA_PFN(DMA_BIT_MASK(64))
73 73
74/* page table handling */
75#define LEVEL_STRIDE (9)
76#define LEVEL_MASK (((u64)1 << LEVEL_STRIDE) - 1)
77
78static inline int agaw_to_level(int agaw)
79{
80 return agaw + 2;
81}
82
83static inline int agaw_to_width(int agaw)
84{
85 return 30 + agaw * LEVEL_STRIDE;
86}
87
88static inline int width_to_agaw(int width)
89{
90 return (width - 30) / LEVEL_STRIDE;
91}
92
93static inline unsigned int level_to_offset_bits(int level)
94{
95 return (level - 1) * LEVEL_STRIDE;
96}
97
98static inline int pfn_level_offset(unsigned long pfn, int level)
99{
100 return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK;
101}
102
103static inline unsigned long level_mask(int level)
104{
105 return -1UL << level_to_offset_bits(level);
106}
107
108static inline unsigned long level_size(int level)
109{
110 return 1UL << level_to_offset_bits(level);
111}
112
113static inline unsigned long align_to_level(unsigned long pfn, int level)
114{
115 return (pfn + level_size(level) - 1) & level_mask(level);
116}
74 117
75/* VT-d pages must always be _smaller_ than MM pages. Otherwise things 118/* VT-d pages must always be _smaller_ than MM pages. Otherwise things
76 are never going to work. */ 119 are never going to work. */
@@ -434,8 +477,6 @@ void free_iova_mem(struct iova *iova)
434} 477}
435 478
436 479
437static inline int width_to_agaw(int width);
438
439static int __iommu_calculate_agaw(struct intel_iommu *iommu, int max_gaw) 480static int __iommu_calculate_agaw(struct intel_iommu *iommu, int max_gaw)
440{ 481{
441 unsigned long sagaw; 482 unsigned long sagaw;
@@ -646,51 +687,6 @@ out:
646 spin_unlock_irqrestore(&iommu->lock, flags); 687 spin_unlock_irqrestore(&iommu->lock, flags);
647} 688}
648 689
649/* page table handling */
650#define LEVEL_STRIDE (9)
651#define LEVEL_MASK (((u64)1 << LEVEL_STRIDE) - 1)
652
653static inline int agaw_to_level(int agaw)
654{
655 return agaw + 2;
656}
657
658static inline int agaw_to_width(int agaw)
659{
660 return 30 + agaw * LEVEL_STRIDE;
661
662}
663
664static inline int width_to_agaw(int width)
665{
666 return (width - 30) / LEVEL_STRIDE;
667}
668
669static inline unsigned int level_to_offset_bits(int level)
670{
671 return (level - 1) * LEVEL_STRIDE;
672}
673
674static inline int pfn_level_offset(unsigned long pfn, int level)
675{
676 return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK;
677}
678
679static inline unsigned long level_mask(int level)
680{
681 return -1UL << level_to_offset_bits(level);
682}
683
684static inline unsigned long level_size(int level)
685{
686 return 1UL << level_to_offset_bits(level);
687}
688
689static inline unsigned long align_to_level(unsigned long pfn, int level)
690{
691 return (pfn + level_size(level) - 1) & level_mask(level);
692}
693
694static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, 690static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain,
695 unsigned long pfn) 691 unsigned long pfn)
696{ 692{
@@ -3761,6 +3757,33 @@ static void __devinit quirk_iommu_rwbf(struct pci_dev *dev)
3761 3757
3762DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_rwbf); 3758DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2a40, quirk_iommu_rwbf);
3763 3759
3760#define GGC 0x52
3761#define GGC_MEMORY_SIZE_MASK (0xf << 8)
3762#define GGC_MEMORY_SIZE_NONE (0x0 << 8)
3763#define GGC_MEMORY_SIZE_1M (0x1 << 8)
3764#define GGC_MEMORY_SIZE_2M (0x3 << 8)
3765#define GGC_MEMORY_VT_ENABLED (0x8 << 8)
3766#define GGC_MEMORY_SIZE_2M_VT (0x9 << 8)
3767#define GGC_MEMORY_SIZE_3M_VT (0xa << 8)
3768#define GGC_MEMORY_SIZE_4M_VT (0xb << 8)
3769
3770static void __devinit quirk_calpella_no_shadow_gtt(struct pci_dev *dev)
3771{
3772 unsigned short ggc;
3773
3774 if (pci_read_config_word(dev, GGC, &ggc))
3775 return;
3776
3777 if (!(ggc & GGC_MEMORY_VT_ENABLED)) {
3778 printk(KERN_INFO "DMAR: BIOS has allocated no shadow GTT; disabling IOMMU for graphics\n");
3779 dmar_map_gfx = 0;
3780 }
3781}
3782DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0040, quirk_calpella_no_shadow_gtt);
3783DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0044, quirk_calpella_no_shadow_gtt);
3784DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0062, quirk_calpella_no_shadow_gtt);
3785DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x006a, quirk_calpella_no_shadow_gtt);
3786
3764/* On Tylersburg chipsets, some BIOSes have been known to enable the 3787/* On Tylersburg chipsets, some BIOSes have been known to enable the
3765 ISOCH DMAR unit for the Azalia sound device, but not give it any 3788 ISOCH DMAR unit for the Azalia sound device, but not give it any
3766 TLB entries, which causes it to deadlock. Check for that. We do 3789 TLB entries, which causes it to deadlock. Check for that. We do
diff --git a/drivers/pci/intr_remapping.c b/drivers/pci/intr_remapping.c
index fd1d2867cdcc..ec87cd66f3eb 100644
--- a/drivers/pci/intr_remapping.c
+++ b/drivers/pci/intr_remapping.c
@@ -46,109 +46,24 @@ static __init int setup_intremap(char *str)
46} 46}
47early_param("intremap", setup_intremap); 47early_param("intremap", setup_intremap);
48 48
49struct irq_2_iommu {
50 struct intel_iommu *iommu;
51 u16 irte_index;
52 u16 sub_handle;
53 u8 irte_mask;
54};
55
56#ifdef CONFIG_GENERIC_HARDIRQS
57static struct irq_2_iommu *get_one_free_irq_2_iommu(int node)
58{
59 struct irq_2_iommu *iommu;
60
61 iommu = kzalloc_node(sizeof(*iommu), GFP_ATOMIC, node);
62 printk(KERN_DEBUG "alloc irq_2_iommu on node %d\n", node);
63
64 return iommu;
65}
66
67static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
68{
69 struct irq_desc *desc;
70
71 desc = irq_to_desc(irq);
72
73 if (WARN_ON_ONCE(!desc))
74 return NULL;
75
76 return desc->irq_2_iommu;
77}
78
79static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
80{
81 struct irq_desc *desc;
82 struct irq_2_iommu *irq_iommu;
83
84 desc = irq_to_desc(irq);
85 if (!desc) {
86 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
87 return NULL;
88 }
89
90 irq_iommu = desc->irq_2_iommu;
91
92 if (!irq_iommu)
93 desc->irq_2_iommu = get_one_free_irq_2_iommu(irq_node(irq));
94
95 return desc->irq_2_iommu;
96}
97
98#else /* !CONFIG_SPARSE_IRQ */
99
100static struct irq_2_iommu irq_2_iommuX[NR_IRQS];
101
102static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
103{
104 if (irq < nr_irqs)
105 return &irq_2_iommuX[irq];
106
107 return NULL;
108}
109static struct irq_2_iommu *irq_2_iommu_alloc(unsigned int irq)
110{
111 return irq_2_iommu(irq);
112}
113#endif
114
115static DEFINE_SPINLOCK(irq_2_ir_lock); 49static DEFINE_SPINLOCK(irq_2_ir_lock);
116 50
117static struct irq_2_iommu *valid_irq_2_iommu(unsigned int irq) 51static struct irq_2_iommu *irq_2_iommu(unsigned int irq)
118{
119 struct irq_2_iommu *irq_iommu;
120
121 irq_iommu = irq_2_iommu(irq);
122
123 if (!irq_iommu)
124 return NULL;
125
126 if (!irq_iommu->iommu)
127 return NULL;
128
129 return irq_iommu;
130}
131
132int irq_remapped(int irq)
133{ 52{
134 return valid_irq_2_iommu(irq) != NULL; 53 struct irq_cfg *cfg = get_irq_chip_data(irq);
54 return cfg ? &cfg->irq_2_iommu : NULL;
135} 55}
136 56
137int get_irte(int irq, struct irte *entry) 57int get_irte(int irq, struct irte *entry)
138{ 58{
139 int index; 59 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
140 struct irq_2_iommu *irq_iommu;
141 unsigned long flags; 60 unsigned long flags;
61 int index;
142 62
143 if (!entry) 63 if (!entry || !irq_iommu)
144 return -1; 64 return -1;
145 65
146 spin_lock_irqsave(&irq_2_ir_lock, flags); 66 spin_lock_irqsave(&irq_2_ir_lock, flags);
147 irq_iommu = valid_irq_2_iommu(irq);
148 if (!irq_iommu) {
149 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
150 return -1;
151 }
152 67
153 index = irq_iommu->irte_index + irq_iommu->sub_handle; 68 index = irq_iommu->irte_index + irq_iommu->sub_handle;
154 *entry = *(irq_iommu->iommu->ir_table->base + index); 69 *entry = *(irq_iommu->iommu->ir_table->base + index);
@@ -160,20 +75,14 @@ int get_irte(int irq, struct irte *entry)
160int alloc_irte(struct intel_iommu *iommu, int irq, u16 count) 75int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
161{ 76{
162 struct ir_table *table = iommu->ir_table; 77 struct ir_table *table = iommu->ir_table;
163 struct irq_2_iommu *irq_iommu; 78 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
164 u16 index, start_index; 79 u16 index, start_index;
165 unsigned int mask = 0; 80 unsigned int mask = 0;
166 unsigned long flags; 81 unsigned long flags;
167 int i; 82 int i;
168 83
169 if (!count) 84 if (!count || !irq_iommu)
170 return -1;
171
172#ifndef CONFIG_SPARSE_IRQ
173 /* protect irq_2_iommu_alloc later */
174 if (irq >= nr_irqs)
175 return -1; 85 return -1;
176#endif
177 86
178 /* 87 /*
179 * start the IRTE search from index 0. 88 * start the IRTE search from index 0.
@@ -214,13 +123,6 @@ int alloc_irte(struct intel_iommu *iommu, int irq, u16 count)
214 for (i = index; i < index + count; i++) 123 for (i = index; i < index + count; i++)
215 table->base[i].present = 1; 124 table->base[i].present = 1;
216 125
217 irq_iommu = irq_2_iommu_alloc(irq);
218 if (!irq_iommu) {
219 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
220 printk(KERN_ERR "can't allocate irq_2_iommu\n");
221 return -1;
222 }
223
224 irq_iommu->iommu = iommu; 126 irq_iommu->iommu = iommu;
225 irq_iommu->irte_index = index; 127 irq_iommu->irte_index = index;
226 irq_iommu->sub_handle = 0; 128 irq_iommu->sub_handle = 0;
@@ -244,17 +146,14 @@ static int qi_flush_iec(struct intel_iommu *iommu, int index, int mask)
244 146
245int map_irq_to_irte_handle(int irq, u16 *sub_handle) 147int map_irq_to_irte_handle(int irq, u16 *sub_handle)
246{ 148{
247 int index; 149 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
248 struct irq_2_iommu *irq_iommu;
249 unsigned long flags; 150 unsigned long flags;
151 int index;
250 152
251 spin_lock_irqsave(&irq_2_ir_lock, flags); 153 if (!irq_iommu)
252 irq_iommu = valid_irq_2_iommu(irq);
253 if (!irq_iommu) {
254 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
255 return -1; 154 return -1;
256 }
257 155
156 spin_lock_irqsave(&irq_2_ir_lock, flags);
258 *sub_handle = irq_iommu->sub_handle; 157 *sub_handle = irq_iommu->sub_handle;
259 index = irq_iommu->irte_index; 158 index = irq_iommu->irte_index;
260 spin_unlock_irqrestore(&irq_2_ir_lock, flags); 159 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
@@ -263,18 +162,13 @@ int map_irq_to_irte_handle(int irq, u16 *sub_handle)
263 162
264int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle) 163int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
265{ 164{
266 struct irq_2_iommu *irq_iommu; 165 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
267 unsigned long flags; 166 unsigned long flags;
268 167
269 spin_lock_irqsave(&irq_2_ir_lock, flags); 168 if (!irq_iommu)
270
271 irq_iommu = irq_2_iommu_alloc(irq);
272
273 if (!irq_iommu) {
274 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
275 printk(KERN_ERR "can't allocate irq_2_iommu\n");
276 return -1; 169 return -1;
277 } 170
171 spin_lock_irqsave(&irq_2_ir_lock, flags);
278 172
279 irq_iommu->iommu = iommu; 173 irq_iommu->iommu = iommu;
280 irq_iommu->irte_index = index; 174 irq_iommu->irte_index = index;
@@ -286,43 +180,18 @@ int set_irte_irq(int irq, struct intel_iommu *iommu, u16 index, u16 subhandle)
286 return 0; 180 return 0;
287} 181}
288 182
289int clear_irte_irq(int irq, struct intel_iommu *iommu, u16 index)
290{
291 struct irq_2_iommu *irq_iommu;
292 unsigned long flags;
293
294 spin_lock_irqsave(&irq_2_ir_lock, flags);
295 irq_iommu = valid_irq_2_iommu(irq);
296 if (!irq_iommu) {
297 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
298 return -1;
299 }
300
301 irq_iommu->iommu = NULL;
302 irq_iommu->irte_index = 0;
303 irq_iommu->sub_handle = 0;
304 irq_2_iommu(irq)->irte_mask = 0;
305
306 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
307
308 return 0;
309}
310
311int modify_irte(int irq, struct irte *irte_modified) 183int modify_irte(int irq, struct irte *irte_modified)
312{ 184{
313 int rc; 185 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
314 int index;
315 struct irte *irte;
316 struct intel_iommu *iommu; 186 struct intel_iommu *iommu;
317 struct irq_2_iommu *irq_iommu;
318 unsigned long flags; 187 unsigned long flags;
188 struct irte *irte;
189 int rc, index;
319 190
320 spin_lock_irqsave(&irq_2_ir_lock, flags); 191 if (!irq_iommu)
321 irq_iommu = valid_irq_2_iommu(irq);
322 if (!irq_iommu) {
323 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
324 return -1; 192 return -1;
325 } 193
194 spin_lock_irqsave(&irq_2_ir_lock, flags);
326 195
327 iommu = irq_iommu->iommu; 196 iommu = irq_iommu->iommu;
328 197
@@ -339,31 +208,6 @@ int modify_irte(int irq, struct irte *irte_modified)
339 return rc; 208 return rc;
340} 209}
341 210
342int flush_irte(int irq)
343{
344 int rc;
345 int index;
346 struct intel_iommu *iommu;
347 struct irq_2_iommu *irq_iommu;
348 unsigned long flags;
349
350 spin_lock_irqsave(&irq_2_ir_lock, flags);
351 irq_iommu = valid_irq_2_iommu(irq);
352 if (!irq_iommu) {
353 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
354 return -1;
355 }
356
357 iommu = irq_iommu->iommu;
358
359 index = irq_iommu->irte_index + irq_iommu->sub_handle;
360
361 rc = qi_flush_iec(iommu, index, irq_iommu->irte_mask);
362 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
363
364 return rc;
365}
366
367struct intel_iommu *map_hpet_to_ir(u8 hpet_id) 211struct intel_iommu *map_hpet_to_ir(u8 hpet_id)
368{ 212{
369 int i; 213 int i;
@@ -420,16 +264,14 @@ static int clear_entries(struct irq_2_iommu *irq_iommu)
420 264
421int free_irte(int irq) 265int free_irte(int irq)
422{ 266{
423 int rc = 0; 267 struct irq_2_iommu *irq_iommu = irq_2_iommu(irq);
424 struct irq_2_iommu *irq_iommu;
425 unsigned long flags; 268 unsigned long flags;
269 int rc;
426 270
427 spin_lock_irqsave(&irq_2_ir_lock, flags); 271 if (!irq_iommu)
428 irq_iommu = valid_irq_2_iommu(irq);
429 if (!irq_iommu) {
430 spin_unlock_irqrestore(&irq_2_ir_lock, flags);
431 return -1; 272 return -1;
432 } 273
274 spin_lock_irqsave(&irq_2_ir_lock, flags);
433 275
434 rc = clear_entries(irq_iommu); 276 rc = clear_entries(irq_iommu);
435 277
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index ce6a3666b3d9..553d8ee55c1c 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -608,7 +608,7 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno,
608 * the VF BAR size multiplied by the number of VFs. The alignment 608 * the VF BAR size multiplied by the number of VFs. The alignment
609 * is just the VF BAR size. 609 * is just the VF BAR size.
610 */ 610 */
611int pci_sriov_resource_alignment(struct pci_dev *dev, int resno) 611resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno)
612{ 612{
613 struct resource tmp; 613 struct resource tmp;
614 enum pci_bar_type type; 614 enum pci_bar_type type;
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 69b7be33b3a2..5fcf5aec680f 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -170,33 +170,31 @@ static void msix_mask_irq(struct msi_desc *desc, u32 flag)
170 desc->masked = __msix_mask_irq(desc, flag); 170 desc->masked = __msix_mask_irq(desc, flag);
171} 171}
172 172
173static void msi_set_mask_bit(unsigned irq, u32 flag) 173static void msi_set_mask_bit(struct irq_data *data, u32 flag)
174{ 174{
175 struct msi_desc *desc = get_irq_msi(irq); 175 struct msi_desc *desc = irq_data_get_msi(data);
176 176
177 if (desc->msi_attrib.is_msix) { 177 if (desc->msi_attrib.is_msix) {
178 msix_mask_irq(desc, flag); 178 msix_mask_irq(desc, flag);
179 readl(desc->mask_base); /* Flush write to device */ 179 readl(desc->mask_base); /* Flush write to device */
180 } else { 180 } else {
181 unsigned offset = irq - desc->dev->irq; 181 unsigned offset = data->irq - desc->dev->irq;
182 msi_mask_irq(desc, 1 << offset, flag << offset); 182 msi_mask_irq(desc, 1 << offset, flag << offset);
183 } 183 }
184} 184}
185 185
186void mask_msi_irq(unsigned int irq) 186void mask_msi_irq(struct irq_data *data)
187{ 187{
188 msi_set_mask_bit(irq, 1); 188 msi_set_mask_bit(data, 1);
189} 189}
190 190
191void unmask_msi_irq(unsigned int irq) 191void unmask_msi_irq(struct irq_data *data)
192{ 192{
193 msi_set_mask_bit(irq, 0); 193 msi_set_mask_bit(data, 0);
194} 194}
195 195
196void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg) 196void __read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
197{ 197{
198 struct msi_desc *entry = get_irq_desc_msi(desc);
199
200 BUG_ON(entry->dev->current_state != PCI_D0); 198 BUG_ON(entry->dev->current_state != PCI_D0);
201 199
202 if (entry->msi_attrib.is_msix) { 200 if (entry->msi_attrib.is_msix) {
@@ -227,15 +225,13 @@ void read_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
227 225
228void read_msi_msg(unsigned int irq, struct msi_msg *msg) 226void read_msi_msg(unsigned int irq, struct msi_msg *msg)
229{ 227{
230 struct irq_desc *desc = irq_to_desc(irq); 228 struct msi_desc *entry = get_irq_msi(irq);
231 229
232 read_msi_msg_desc(desc, msg); 230 __read_msi_msg(entry, msg);
233} 231}
234 232
235void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg) 233void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
236{ 234{
237 struct msi_desc *entry = get_irq_desc_msi(desc);
238
239 /* Assert that the cache is valid, assuming that 235 /* Assert that the cache is valid, assuming that
240 * valid messages are not all-zeroes. */ 236 * valid messages are not all-zeroes. */
241 BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo | 237 BUG_ON(!(entry->msg.address_hi | entry->msg.address_lo |
@@ -246,15 +242,13 @@ void get_cached_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
246 242
247void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg) 243void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg)
248{ 244{
249 struct irq_desc *desc = irq_to_desc(irq); 245 struct msi_desc *entry = get_irq_msi(irq);
250 246
251 get_cached_msi_msg_desc(desc, msg); 247 __get_cached_msi_msg(entry, msg);
252} 248}
253 249
254void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg) 250void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
255{ 251{
256 struct msi_desc *entry = get_irq_desc_msi(desc);
257
258 if (entry->dev->current_state != PCI_D0) { 252 if (entry->dev->current_state != PCI_D0) {
259 /* Don't touch the hardware now */ 253 /* Don't touch the hardware now */
260 } else if (entry->msi_attrib.is_msix) { 254 } else if (entry->msi_attrib.is_msix) {
@@ -292,9 +286,9 @@ void write_msi_msg_desc(struct irq_desc *desc, struct msi_msg *msg)
292 286
293void write_msi_msg(unsigned int irq, struct msi_msg *msg) 287void write_msi_msg(unsigned int irq, struct msi_msg *msg)
294{ 288{
295 struct irq_desc *desc = irq_to_desc(irq); 289 struct msi_desc *entry = get_irq_msi(irq);
296 290
297 write_msi_msg_desc(desc, msg); 291 __write_msi_msg(entry, msg);
298} 292}
299 293
300static void free_msi_irqs(struct pci_dev *dev) 294static void free_msi_irqs(struct pci_dev *dev)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 7754a678ab15..6beb11b617a9 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -264,7 +264,8 @@ extern int pci_iov_init(struct pci_dev *dev);
264extern void pci_iov_release(struct pci_dev *dev); 264extern void pci_iov_release(struct pci_dev *dev);
265extern int pci_iov_resource_bar(struct pci_dev *dev, int resno, 265extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
266 enum pci_bar_type *type); 266 enum pci_bar_type *type);
267extern int pci_sriov_resource_alignment(struct pci_dev *dev, int resno); 267extern resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev,
268 int resno);
268extern void pci_restore_iov_state(struct pci_dev *dev); 269extern void pci_restore_iov_state(struct pci_dev *dev);
269extern int pci_iov_bus_range(struct pci_bus *bus); 270extern int pci_iov_bus_range(struct pci_bus *bus);
270 271
@@ -320,7 +321,7 @@ static inline int pci_ats_enabled(struct pci_dev *dev)
320} 321}
321#endif /* CONFIG_PCI_IOV */ 322#endif /* CONFIG_PCI_IOV */
322 323
323static inline int pci_resource_alignment(struct pci_dev *dev, 324static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
324 struct resource *res) 325 struct resource *res)
325{ 326{
326#ifdef CONFIG_PCI_IOV 327#ifdef CONFIG_PCI_IOV
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 89ed181cd90c..857ae01734a6 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -163,6 +163,26 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_2, quirk_isa_d
163DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_3, quirk_isa_dma_hangs); 163DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_3, quirk_isa_dma_hangs);
164 164
165/* 165/*
166 * Intel NM10 "TigerPoint" LPC PM1a_STS.BM_STS must be clear
167 * for some HT machines to use C4 w/o hanging.
168 */
169static void __devinit quirk_tigerpoint_bm_sts(struct pci_dev *dev)
170{
171 u32 pmbase;
172 u16 pm1a;
173
174 pci_read_config_dword(dev, 0x40, &pmbase);
175 pmbase = pmbase & 0xff80;
176 pm1a = inw(pmbase);
177
178 if (pm1a & 0x10) {
179 dev_info(&dev->dev, FW_BUG "TigerPoint LPC.BM_STS cleared\n");
180 outw(0x10, pmbase);
181 }
182}
183DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGP_LPC, quirk_tigerpoint_bm_sts);
184
185/*
166 * Chipsets where PCI->PCI transfers vanish or hang 186 * Chipsets where PCI->PCI transfers vanish or hang
167 */ 187 */
168static void __devinit quirk_nopcipci(struct pci_dev *dev) 188static void __devinit quirk_nopcipci(struct pci_dev *dev)
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index 88c4c4098789..95dd7c62741f 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -441,14 +441,12 @@ int au1x00_pcmcia_socket_probe(struct device *dev, struct pcmcia_low_level *ops,
441 441
442 442
443out_err: 443out_err:
444 flush_scheduled_work();
445 ops->hw_shutdown(skt); 444 ops->hw_shutdown(skt);
446 while (i-- > 0) { 445 while (i-- > 0) {
447 skt = PCMCIA_SOCKET(i); 446 skt = PCMCIA_SOCKET(i);
448 447
449 del_timer_sync(&skt->poll_timer); 448 del_timer_sync(&skt->poll_timer);
450 pcmcia_unregister_socket(&skt->socket); 449 pcmcia_unregister_socket(&skt->socket);
451 flush_scheduled_work();
452 if (i == 0) { 450 if (i == 0) {
453 iounmap(skt->virt_io + (u32)mips_io_port_base); 451 iounmap(skt->virt_io + (u32)mips_io_port_base);
454 skt->virt_io = NULL; 452 skt->virt_io = NULL;
@@ -480,7 +478,6 @@ int au1x00_drv_pcmcia_remove(struct platform_device *dev)
480 478
481 del_timer_sync(&skt->poll_timer); 479 del_timer_sync(&skt->poll_timer);
482 pcmcia_unregister_socket(&skt->socket); 480 pcmcia_unregister_socket(&skt->socket);
483 flush_scheduled_work();
484 skt->ops->hw_shutdown(skt); 481 skt->ops->hw_shutdown(skt);
485 au1x00_pcmcia_config_skt(skt, &dead_socket); 482 au1x00_pcmcia_config_skt(skt, &dead_socket);
486 iounmap(skt->virt_io + (u32)mips_io_port_base); 483 iounmap(skt->virt_io + (u32)mips_io_port_base);
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h
index 67530cefcf3c..5c36bda2963b 100644
--- a/drivers/pcmcia/au1000_generic.h
+++ b/drivers/pcmcia/au1000_generic.h
@@ -23,7 +23,6 @@
23 23
24/* include the world */ 24/* include the world */
25 25
26#include <pcmcia/cs.h>
27#include <pcmcia/ss.h> 26#include <pcmcia/ss.h>
28#include <pcmcia/cistpl.h> 27#include <pcmcia/cistpl.h>
29#include "cs_internal.h" 28#include "cs_internal.h"
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c
index 807f2d75dad3..b2396647a165 100644
--- a/drivers/pcmcia/au1000_pb1x00.c
+++ b/drivers/pcmcia/au1000_pb1x00.c
@@ -31,7 +31,6 @@
31#include <linux/proc_fs.h> 31#include <linux/proc_fs.h>
32#include <linux/types.h> 32#include <linux/types.h>
33 33
34#include <pcmcia/cs.h>
35#include <pcmcia/ss.h> 34#include <pcmcia/ss.h>
36#include <pcmcia/cistpl.h> 35#include <pcmcia/cistpl.h>
37 36
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 91414a0ddc44..884a984216fe 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -28,7 +28,6 @@
28#include <asm/unaligned.h> 28#include <asm/unaligned.h>
29 29
30#include <pcmcia/ss.h> 30#include <pcmcia/ss.h>
31#include <pcmcia/cs.h>
32#include <pcmcia/cisreg.h> 31#include <pcmcia/cisreg.h>
33#include <pcmcia/cistpl.h> 32#include <pcmcia/cistpl.h>
34#include "cs_internal.h" 33#include "cs_internal.h"
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index 2ec8ac97445c..d9ea192c4001 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -33,7 +33,6 @@
33#include <asm/irq.h> 33#include <asm/irq.h>
34 34
35#include <pcmcia/ss.h> 35#include <pcmcia/ss.h>
36#include <pcmcia/cs.h>
37#include <pcmcia/cistpl.h> 36#include <pcmcia/cistpl.h>
38#include <pcmcia/cisreg.h> 37#include <pcmcia/cisreg.h>
39#include <pcmcia/ds.h> 38#include <pcmcia/ds.h>
@@ -845,7 +844,7 @@ static int pcmcia_socket_dev_resume_noirq(struct device *dev)
845 return __pcmcia_pm_op(dev, socket_early_resume); 844 return __pcmcia_pm_op(dev, socket_early_resume);
846} 845}
847 846
848static int pcmcia_socket_dev_resume(struct device *dev) 847static int __used pcmcia_socket_dev_resume(struct device *dev)
849{ 848{
850 return __pcmcia_pm_op(dev, socket_late_resume); 849 return __pcmcia_pm_op(dev, socket_late_resume);
851} 850}
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index da055dc14d98..7f1953f78b12 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -33,18 +33,9 @@
33typedef struct config_t { 33typedef struct config_t {
34 struct kref ref; 34 struct kref ref;
35 unsigned int state; 35 unsigned int state;
36 unsigned int Attributes;
37 unsigned int IntType;
38 unsigned int ConfigBase;
39 unsigned char Status, Pin, Copy, Option, ExtStatus;
40 unsigned int CardValues;
41 36
42 struct resource io[MAX_IO_WIN]; /* io ports */ 37 struct resource io[MAX_IO_WIN]; /* io ports */
43 struct resource mem[MAX_WIN]; /* mem areas */ 38 struct resource mem[MAX_WIN]; /* mem areas */
44
45 struct {
46 u_int Attributes;
47 } irq;
48} config_t; 39} config_t;
49 40
50 41
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 55570d9e1e4c..100c4412457d 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -26,7 +26,6 @@
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28 28
29#include <pcmcia/cs.h>
30#include <pcmcia/cistpl.h> 29#include <pcmcia/cistpl.h>
31#include <pcmcia/ds.h> 30#include <pcmcia/ds.h>
32#include <pcmcia/ss.h> 31#include <pcmcia/ss.h>
@@ -52,7 +51,7 @@ static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
52 51
53 if (!p_drv->probe || !p_drv->remove) 52 if (!p_drv->probe || !p_drv->remove)
54 printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback " 53 printk(KERN_DEBUG "pcmcia: %s lacks a requisite callback "
55 "function\n", p_drv->drv.name); 54 "function\n", p_drv->name);
56 55
57 while (did && did->match_flags) { 56 while (did && did->match_flags) {
58 for (i = 0; i < 4; i++) { 57 for (i = 0; i < 4; i++) {
@@ -65,7 +64,7 @@ static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
65 64
66 printk(KERN_DEBUG "pcmcia: %s: invalid hash for " 65 printk(KERN_DEBUG "pcmcia: %s: invalid hash for "
67 "product string \"%s\": is 0x%x, should " 66 "product string \"%s\": is 0x%x, should "
68 "be 0x%x\n", p_drv->drv.name, did->prod_id[i], 67 "be 0x%x\n", p_drv->name, did->prod_id[i],
69 did->prod_id_hash[i], hash); 68 did->prod_id_hash[i], hash);
70 printk(KERN_DEBUG "pcmcia: see " 69 printk(KERN_DEBUG "pcmcia: see "
71 "Documentation/pcmcia/devicetable.txt for " 70 "Documentation/pcmcia/devicetable.txt for "
@@ -180,10 +179,11 @@ int pcmcia_register_driver(struct pcmcia_driver *driver)
180 /* initialize common fields */ 179 /* initialize common fields */
181 driver->drv.bus = &pcmcia_bus_type; 180 driver->drv.bus = &pcmcia_bus_type;
182 driver->drv.owner = driver->owner; 181 driver->drv.owner = driver->owner;
182 driver->drv.name = driver->name;
183 mutex_init(&driver->dynids.lock); 183 mutex_init(&driver->dynids.lock);
184 INIT_LIST_HEAD(&driver->dynids.list); 184 INIT_LIST_HEAD(&driver->dynids.list);
185 185
186 pr_debug("registering driver %s\n", driver->drv.name); 186 pr_debug("registering driver %s\n", driver->name);
187 187
188 error = driver_register(&driver->drv); 188 error = driver_register(&driver->drv);
189 if (error < 0) 189 if (error < 0)
@@ -203,7 +203,7 @@ EXPORT_SYMBOL(pcmcia_register_driver);
203 */ 203 */
204void pcmcia_unregister_driver(struct pcmcia_driver *driver) 204void pcmcia_unregister_driver(struct pcmcia_driver *driver)
205{ 205{
206 pr_debug("unregistering driver %s\n", driver->drv.name); 206 pr_debug("unregistering driver %s\n", driver->name);
207 driver_unregister(&driver->drv); 207 driver_unregister(&driver->drv);
208 pcmcia_free_dynids(driver); 208 pcmcia_free_dynids(driver);
209} 209}
@@ -264,7 +264,7 @@ static int pcmcia_device_probe(struct device *dev)
264 p_drv = to_pcmcia_drv(dev->driver); 264 p_drv = to_pcmcia_drv(dev->driver);
265 s = p_dev->socket; 265 s = p_dev->socket;
266 266
267 dev_dbg(dev, "trying to bind to %s\n", p_drv->drv.name); 267 dev_dbg(dev, "trying to bind to %s\n", p_drv->name);
268 268
269 if ((!p_drv->probe) || (!p_dev->function_config) || 269 if ((!p_drv->probe) || (!p_dev->function_config) ||
270 (!try_module_get(p_drv->owner))) { 270 (!try_module_get(p_drv->owner))) {
@@ -276,21 +276,28 @@ static int pcmcia_device_probe(struct device *dev)
276 ret = pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_CONFIG, 276 ret = pccard_read_tuple(p_dev->socket, p_dev->func, CISTPL_CONFIG,
277 &cis_config); 277 &cis_config);
278 if (!ret) { 278 if (!ret) {
279 p_dev->conf.ConfigBase = cis_config.base; 279 p_dev->config_base = cis_config.base;
280 p_dev->conf.Present = cis_config.rmask[0]; 280 p_dev->config_regs = cis_config.rmask[0];
281 dev_dbg(dev, "base %x, regs %x", p_dev->config_base,
282 p_dev->config_regs);
281 } else { 283 } else {
282 dev_printk(KERN_INFO, dev, 284 dev_printk(KERN_INFO, dev,
283 "pcmcia: could not parse base and rmask0 of CIS\n"); 285 "pcmcia: could not parse base and rmask0 of CIS\n");
284 p_dev->conf.ConfigBase = 0; 286 p_dev->config_base = 0;
285 p_dev->conf.Present = 0; 287 p_dev->config_regs = 0;
286 } 288 }
287 289
288 ret = p_drv->probe(p_dev); 290 ret = p_drv->probe(p_dev);
289 if (ret) { 291 if (ret) {
290 dev_dbg(dev, "binding to %s failed with %d\n", 292 dev_dbg(dev, "binding to %s failed with %d\n",
291 p_drv->drv.name, ret); 293 p_drv->name, ret);
292 goto put_module; 294 goto put_module;
293 } 295 }
296 dev_dbg(dev, "%s bound: Vpp %d.%d, idx %x, IRQ %d", p_drv->name,
297 p_dev->vpp/10, p_dev->vpp%10, p_dev->config_index, p_dev->irq);
298 dev_dbg(dev, "resources: ioport %pR %pR iomem %pR %pR %pR",
299 p_dev->resource[0], p_dev->resource[1], p_dev->resource[2],
300 p_dev->resource[3], p_dev->resource[4]);
294 301
295 mutex_lock(&s->ops_mutex); 302 mutex_lock(&s->ops_mutex);
296 if ((s->pcmcia_pfc) && 303 if ((s->pcmcia_pfc) &&
@@ -374,13 +381,13 @@ static int pcmcia_device_remove(struct device *dev)
374 if (p_dev->_irq || p_dev->_io || p_dev->_locked) 381 if (p_dev->_irq || p_dev->_io || p_dev->_locked)
375 dev_printk(KERN_INFO, dev, 382 dev_printk(KERN_INFO, dev,
376 "pcmcia: driver %s did not release config properly\n", 383 "pcmcia: driver %s did not release config properly\n",
377 p_drv->drv.name); 384 p_drv->name);
378 385
379 for (i = 0; i < MAX_WIN; i++) 386 for (i = 0; i < MAX_WIN; i++)
380 if (p_dev->_win & CLIENT_WIN_REQ(i)) 387 if (p_dev->_win & CLIENT_WIN_REQ(i))
381 dev_printk(KERN_INFO, dev, 388 dev_printk(KERN_INFO, dev,
382 "pcmcia: driver %s did not release window properly\n", 389 "pcmcia: driver %s did not release window properly\n",
383 p_drv->drv.name); 390 p_drv->name);
384 391
385 /* references from pcmcia_probe_device */ 392 /* references from pcmcia_probe_device */
386 pcmcia_put_dev(p_dev); 393 pcmcia_put_dev(p_dev);
@@ -1136,7 +1143,7 @@ static int pcmcia_dev_suspend(struct device *dev, pm_message_t state)
1136 dev_printk(KERN_ERR, dev, 1143 dev_printk(KERN_ERR, dev,
1137 "pcmcia: device %s (driver %s) did " 1144 "pcmcia: device %s (driver %s) did "
1138 "not want to go to sleep (%d)\n", 1145 "not want to go to sleep (%d)\n",
1139 p_dev->devname, p_drv->drv.name, ret); 1146 p_dev->devname, p_drv->name, ret);
1140 mutex_lock(&p_dev->socket->ops_mutex); 1147 mutex_lock(&p_dev->socket->ops_mutex);
1141 p_dev->suspended = 0; 1148 p_dev->suspended = 0;
1142 mutex_unlock(&p_dev->socket->ops_mutex); 1149 mutex_unlock(&p_dev->socket->ops_mutex);
@@ -1178,7 +1185,7 @@ static int pcmcia_dev_resume(struct device *dev)
1178 1185
1179 if (p_dev->device_no == p_dev->func) { 1186 if (p_dev->device_no == p_dev->func) {
1180 dev_dbg(dev, "requesting configuration\n"); 1187 dev_dbg(dev, "requesting configuration\n");
1181 ret = pcmcia_request_configuration(p_dev, &p_dev->conf); 1188 ret = pcmcia_enable_device(p_dev);
1182 if (ret) 1189 if (ret)
1183 goto out; 1190 goto out;
1184 } 1191 }
diff --git a/drivers/pcmcia/i82092.c b/drivers/pcmcia/i82092.c
index 05d0879ce935..fc7906eaf228 100644
--- a/drivers/pcmcia/i82092.c
+++ b/drivers/pcmcia/i82092.c
@@ -16,7 +16,6 @@
16#include <linux/device.h> 16#include <linux/device.h>
17 17
18#include <pcmcia/ss.h> 18#include <pcmcia/ss.h>
19#include <pcmcia/cs.h>
20 19
21#include <asm/system.h> 20#include <asm/system.h>
22#include <asm/io.h> 21#include <asm/io.h>
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 61746bd598b3..72a033a2acdb 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -51,7 +51,6 @@
51#include <asm/system.h> 51#include <asm/system.h>
52 52
53#include <pcmcia/ss.h> 53#include <pcmcia/ss.h>
54#include <pcmcia/cs.h>
55 54
56#include <linux/isapnp.h> 55#include <linux/isapnp.h>
57 56
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index 24de49925863..2adb0106a039 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -27,7 +27,6 @@
27#include <asm/system.h> 27#include <asm/system.h>
28 28
29#include <pcmcia/ss.h> 29#include <pcmcia/ss.h>
30#include <pcmcia/cs.h>
31 30
32#undef MAX_IO_WIN /* FIXME */ 31#undef MAX_IO_WIN /* FIXME */
33#define MAX_IO_WIN 1 32#define MAX_IO_WIN 1
diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
index 8e4723844ad3..1511ff71c87b 100644
--- a/drivers/pcmcia/m32r_pcc.c
+++ b/drivers/pcmcia/m32r_pcc.c
@@ -28,7 +28,6 @@
28#include <asm/addrspace.h> 28#include <asm/addrspace.h>
29 29
30#include <pcmcia/ss.h> 30#include <pcmcia/ss.h>
31#include <pcmcia/cs.h>
32 31
33/* XXX: should be moved into asm/irq.h */ 32/* XXX: should be moved into asm/irq.h */
34#define PCC0_IRQ 24 33#define PCC0_IRQ 24
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index f0ecad99ce81..99d4f23cb435 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -59,7 +59,6 @@
59#include <asm/irq.h> 59#include <asm/irq.h>
60#include <asm/fs_pd.h> 60#include <asm/fs_pd.h>
61 61
62#include <pcmcia/cs.h>
63#include <pcmcia/ss.h> 62#include <pcmcia/ss.h>
64 63
65#define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args) 64#define pcmcia_info(args...) printk(KERN_INFO "m8xx_pcmcia: "args)
diff --git a/drivers/pcmcia/o2micro.h b/drivers/pcmcia/o2micro.h
index e74bebac2695..5096e92c7a4c 100644
--- a/drivers/pcmcia/o2micro.h
+++ b/drivers/pcmcia/o2micro.h
@@ -153,14 +153,14 @@ static int o2micro_override(struct yenta_socket *socket)
153 153
154 if (use_speedup) { 154 if (use_speedup) {
155 dev_info(&socket->dev->dev, 155 dev_info(&socket->dev->dev,
156 "O2: enabling read prefetch/write burst\n"); 156 "O2: enabling read prefetch/write burst. If you experience problems or performance issues, use the yenta_socket parameter 'o2_speedup=off'\n");
157 config_writeb(socket, O2_RESERVED1, 157 config_writeb(socket, O2_RESERVED1,
158 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); 158 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
159 config_writeb(socket, O2_RESERVED2, 159 config_writeb(socket, O2_RESERVED2,
160 b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); 160 b | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
161 } else { 161 } else {
162 dev_info(&socket->dev->dev, 162 dev_info(&socket->dev->dev,
163 "O2: disabling read prefetch/write burst\n"); 163 "O2: disabling read prefetch/write burst. If you experience problems or performance issues, use the yenta_socket parameter 'o2_speedup=on'\n");
164 config_writeb(socket, O2_RESERVED1, 164 config_writeb(socket, O2_RESERVED1,
165 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); 165 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
166 config_writeb(socket, O2_RESERVED2, 166 config_writeb(socket, O2_RESERVED2,
diff --git a/drivers/pcmcia/pcmcia_cis.c b/drivers/pcmcia/pcmcia_cis.c
index 0ac54da15885..e2c92415b892 100644
--- a/drivers/pcmcia/pcmcia_cis.c
+++ b/drivers/pcmcia/pcmcia_cis.c
@@ -6,7 +6,7 @@
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 * 7 *
8 * Copyright (C) 1999 David A. Hinds 8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2009 Dominik Brodowski 9 * Copyright (C) 2004-2010 Dominik Brodowski
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -22,7 +22,6 @@
22#include <pcmcia/cisreg.h> 22#include <pcmcia/cisreg.h>
23#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
24#include <pcmcia/ss.h> 24#include <pcmcia/ss.h>
25#include <pcmcia/cs.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
27#include "cs_internal.h" 26#include "cs_internal.h"
28 27
@@ -126,14 +125,24 @@ next_entry:
126 return ret; 125 return ret;
127} 126}
128 127
128
129/**
130 * pcmcia_io_cfg_data_width() - convert cfgtable to data path width parameter
131 */
132static int pcmcia_io_cfg_data_width(unsigned int flags)
133{
134 if (!(flags & CISTPL_IO_8BIT))
135 return IO_DATA_PATH_WIDTH_16;
136 if (!(flags & CISTPL_IO_16BIT))
137 return IO_DATA_PATH_WIDTH_8;
138 return IO_DATA_PATH_WIDTH_AUTO;
139}
140
141
129struct pcmcia_cfg_mem { 142struct pcmcia_cfg_mem {
130 struct pcmcia_device *p_dev; 143 struct pcmcia_device *p_dev;
144 int (*conf_check) (struct pcmcia_device *p_dev, void *priv_data);
131 void *priv_data; 145 void *priv_data;
132 int (*conf_check) (struct pcmcia_device *p_dev,
133 cistpl_cftable_entry_t *cfg,
134 cistpl_cftable_entry_t *dflt,
135 unsigned int vcc,
136 void *priv_data);
137 cisparse_t parse; 146 cisparse_t parse;
138 cistpl_cftable_entry_t dflt; 147 cistpl_cftable_entry_t dflt;
139}; 148};
@@ -147,25 +156,102 @@ struct pcmcia_cfg_mem {
147 */ 156 */
148static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv) 157static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
149{ 158{
150 cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
151 struct pcmcia_cfg_mem *cfg_mem = priv; 159 struct pcmcia_cfg_mem *cfg_mem = priv;
160 struct pcmcia_device *p_dev = cfg_mem->p_dev;
161 cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
162 cistpl_cftable_entry_t *dflt = &cfg_mem->dflt;
163 unsigned int flags = p_dev->config_flags;
164 unsigned int vcc = p_dev->socket->socket.Vcc;
165
166 dev_dbg(&p_dev->dev, "testing configuration %x, autoconf %x\n",
167 cfg->index, flags);
152 168
153 /* default values */ 169 /* default values */
154 cfg_mem->p_dev->conf.ConfigIndex = cfg->index; 170 cfg_mem->p_dev->config_index = cfg->index;
155 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) 171 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
156 cfg_mem->dflt = *cfg; 172 cfg_mem->dflt = *cfg;
157 173
158 return cfg_mem->conf_check(cfg_mem->p_dev, cfg, &cfg_mem->dflt, 174 /* check for matching Vcc? */
159 cfg_mem->p_dev->socket->socket.Vcc, 175 if (flags & CONF_AUTO_CHECK_VCC) {
160 cfg_mem->priv_data); 176 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
177 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
178 return -ENODEV;
179 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
180 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
181 return -ENODEV;
182 }
183 }
184
185 /* set Vpp? */
186 if (flags & CONF_AUTO_SET_VPP) {
187 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
188 p_dev->vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
189 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
190 p_dev->vpp =
191 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
192 }
193
194 /* enable audio? */
195 if ((flags & CONF_AUTO_AUDIO) && (cfg->flags & CISTPL_CFTABLE_AUDIO))
196 p_dev->config_flags |= CONF_ENABLE_SPKR;
197
198
199 /* IO window settings? */
200 if (flags & CONF_AUTO_SET_IO) {
201 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
202 int i = 0;
203
204 p_dev->resource[0]->start = p_dev->resource[0]->end = 0;
205 p_dev->resource[1]->start = p_dev->resource[1]->end = 0;
206 if (io->nwin == 0)
207 return -ENODEV;
208
209 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
210 p_dev->resource[0]->flags |=
211 pcmcia_io_cfg_data_width(io->flags);
212 if (io->nwin > 1) {
213 /* For multifunction cards, by convention, we
214 * configure the network function with window 0,
215 * and serial with window 1 */
216 i = (io->win[1].len > io->win[0].len);
217 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
218 p_dev->resource[1]->start = io->win[1-i].base;
219 p_dev->resource[1]->end = io->win[1-i].len;
220 }
221 p_dev->resource[0]->start = io->win[i].base;
222 p_dev->resource[0]->end = io->win[i].len;
223 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
224 }
225
226 /* MEM window settings? */
227 if (flags & CONF_AUTO_SET_IOMEM) {
228 /* so far, we only set one memory window */
229 cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
230
231 p_dev->resource[2]->start = p_dev->resource[2]->end = 0;
232 if (mem->nwin == 0)
233 return -ENODEV;
234
235 p_dev->resource[2]->start = mem->win[0].host_addr;
236 p_dev->resource[2]->end = mem->win[0].len;
237 if (p_dev->resource[2]->end < 0x1000)
238 p_dev->resource[2]->end = 0x1000;
239 p_dev->card_addr = mem->win[0].card_addr;
240 }
241
242 dev_dbg(&p_dev->dev,
243 "checking configuration %x: %pr %pr %pr (%d lines)\n",
244 p_dev->config_index, p_dev->resource[0], p_dev->resource[1],
245 p_dev->resource[2], p_dev->io_lines);
246
247 return cfg_mem->conf_check(p_dev, cfg_mem->priv_data);
161} 248}
162 249
163/** 250/**
164 * pcmcia_loop_config() - loop over configuration options 251 * pcmcia_loop_config() - loop over configuration options
165 * @p_dev: the struct pcmcia_device which we need to loop for. 252 * @p_dev: the struct pcmcia_device which we need to loop for.
166 * @conf_check: function to call for each configuration option. 253 * @conf_check: function to call for each configuration option.
167 * It gets passed the struct pcmcia_device, the CIS data 254 * It gets passed the struct pcmcia_device and private data
168 * describing the configuration option, and private data
169 * being passed to pcmcia_loop_config() 255 * being passed to pcmcia_loop_config()
170 * @priv_data: private data to be passed to the conf_check function. 256 * @priv_data: private data to be passed to the conf_check function.
171 * 257 *
@@ -175,9 +261,6 @@ static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
175 */ 261 */
176int pcmcia_loop_config(struct pcmcia_device *p_dev, 262int pcmcia_loop_config(struct pcmcia_device *p_dev,
177 int (*conf_check) (struct pcmcia_device *p_dev, 263 int (*conf_check) (struct pcmcia_device *p_dev,
178 cistpl_cftable_entry_t *cfg,
179 cistpl_cftable_entry_t *dflt,
180 unsigned int vcc,
181 void *priv_data), 264 void *priv_data),
182 void *priv_data) 265 void *priv_data)
183{ 266{
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 54aa1c238cb3..a9af0d784426 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -6,7 +6,7 @@
6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 6 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
7 * 7 *
8 * Copyright (C) 1999 David A. Hinds 8 * Copyright (C) 1999 David A. Hinds
9 * Copyright (C) 2004-2005 Dominik Brodowski 9 * Copyright (C) 2004-2010 Dominik Brodowski
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
@@ -26,7 +26,6 @@
26#include <asm/irq.h> 26#include <asm/irq.h>
27 27
28#include <pcmcia/ss.h> 28#include <pcmcia/ss.h>
29#include <pcmcia/cs.h>
30#include <pcmcia/cistpl.h> 29#include <pcmcia/cistpl.h>
31#include <pcmcia/cisreg.h> 30#include <pcmcia/cisreg.h>
32#include <pcmcia/ds.h> 31#include <pcmcia/ds.h>
@@ -56,6 +55,12 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
56} 55}
57 56
58 57
58/**
59 * release_io_space() - release IO ports allocated with alloc_io_space()
60 * @s: pcmcia socket
61 * @res: resource to release
62 *
63 */
59static void release_io_space(struct pcmcia_socket *s, struct resource *res) 64static void release_io_space(struct pcmcia_socket *s, struct resource *res)
60{ 65{
61 resource_size_t num = resource_size(res); 66 resource_size_t num = resource_size(res);
@@ -81,9 +86,14 @@ static void release_io_space(struct pcmcia_socket *s, struct resource *res)
81 } 86 }
82 } 87 }
83 } 88 }
84} /* release_io_space */ 89}
90
85 91
86/** alloc_io_space 92/**
93 * alloc_io_space() - allocate IO ports for use by a PCMCIA device
94 * @s: pcmcia socket
95 * @res: resource to allocate (begin: begin, end: size)
96 * @lines: number of IO lines decoded by the PCMCIA card
87 * 97 *
88 * Special stuff for managing IO windows, because they are scarce 98 * Special stuff for managing IO windows, because they are scarce
89 */ 99 */
@@ -135,7 +145,7 @@ static int alloc_io_space(struct pcmcia_socket *s, struct resource *res,
135 } 145 }
136 dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res); 146 dev_dbg(&s->dev, "alloc_io_space request result %d: %pR\n", ret, res);
137 return ret; 147 return ret;
138} /* alloc_io_space */ 148}
139 149
140 150
141/** 151/**
@@ -163,19 +173,19 @@ static int pcmcia_access_config(struct pcmcia_device *p_dev,
163 c = p_dev->function_config; 173 c = p_dev->function_config;
164 174
165 if (!(c->state & CONFIG_LOCKED)) { 175 if (!(c->state & CONFIG_LOCKED)) {
166 dev_dbg(&s->dev, "Configuration isnt't locked\n"); 176 dev_dbg(&p_dev->dev, "Configuration isnt't locked\n");
167 mutex_unlock(&s->ops_mutex); 177 mutex_unlock(&s->ops_mutex);
168 return -EACCES; 178 return -EACCES;
169 } 179 }
170 180
171 addr = (c->ConfigBase + where) >> 1; 181 addr = (p_dev->config_base + where) >> 1;
172 182
173 ret = accessf(s, 1, addr, 1, val); 183 ret = accessf(s, 1, addr, 1, val);
174 184
175 mutex_unlock(&s->ops_mutex); 185 mutex_unlock(&s->ops_mutex);
176 186
177 return ret; 187 return ret;
178} /* pcmcia_access_config */ 188}
179 189
180 190
181/** 191/**
@@ -204,11 +214,20 @@ int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val)
204EXPORT_SYMBOL(pcmcia_write_config_byte); 214EXPORT_SYMBOL(pcmcia_write_config_byte);
205 215
206 216
207int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh, 217/**
218 * pcmcia_map_mem_page() - modify iomem window to point to a different offset
219 * @p_dev: pcmcia device
220 * @res: iomem resource already enabled by pcmcia_request_window()
221 * @offset: card_offset to map
222 *
223 * pcmcia_map_mem_page() modifies what can be read and written by accessing
224 * an iomem range previously enabled by pcmcia_request_window(), by setting
225 * the card_offset value to @offset.
226 */
227int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
208 unsigned int offset) 228 unsigned int offset)
209{ 229{
210 struct pcmcia_socket *s = p_dev->socket; 230 struct pcmcia_socket *s = p_dev->socket;
211 struct resource *res = wh;
212 unsigned int w; 231 unsigned int w;
213 int ret; 232 int ret;
214 233
@@ -220,99 +239,114 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, window_handle_t wh,
220 s->win[w].card_start = offset; 239 s->win[w].card_start = offset;
221 ret = s->ops->set_mem_map(s, &s->win[w]); 240 ret = s->ops->set_mem_map(s, &s->win[w]);
222 if (ret) 241 if (ret)
223 dev_warn(&s->dev, "failed to set_mem_map\n"); 242 dev_warn(&p_dev->dev, "failed to set_mem_map\n");
224 mutex_unlock(&s->ops_mutex); 243 mutex_unlock(&s->ops_mutex);
225 return ret; 244 return ret;
226} /* pcmcia_map_mem_page */ 245}
227EXPORT_SYMBOL(pcmcia_map_mem_page); 246EXPORT_SYMBOL(pcmcia_map_mem_page);
228 247
229 248
230/** pcmcia_modify_configuration 249/**
250 * pcmcia_fixup_iowidth() - reduce io width to 8bit
251 * @p_dev: pcmcia device
231 * 252 *
232 * Modify a locked socket configuration 253 * pcmcia_fixup_iowidth() allows a PCMCIA device driver to reduce the
254 * IO width to 8bit after having called pcmcia_enable_device()
255 * previously.
233 */ 256 */
234int pcmcia_modify_configuration(struct pcmcia_device *p_dev, 257int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev)
235 modconf_t *mod)
236{ 258{
237 struct pcmcia_socket *s; 259 struct pcmcia_socket *s = p_dev->socket;
238 config_t *c; 260 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
239 int ret; 261 pccard_io_map io_on;
240 262 int i, ret = 0;
241 s = p_dev->socket;
242 263
243 mutex_lock(&s->ops_mutex); 264 mutex_lock(&s->ops_mutex);
244 c = p_dev->function_config;
245 265
246 if (!(s->state & SOCKET_PRESENT)) { 266 dev_dbg(&p_dev->dev, "fixup iowidth to 8bit\n");
247 dev_dbg(&s->dev, "No card present\n"); 267
248 ret = -ENODEV; 268 if (!(s->state & SOCKET_PRESENT) ||
249 goto unlock; 269 !(p_dev->function_config->state & CONFIG_LOCKED)) {
250 } 270 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
251 if (!(c->state & CONFIG_LOCKED)) {
252 dev_dbg(&s->dev, "Configuration isnt't locked\n");
253 ret = -EACCES; 271 ret = -EACCES;
254 goto unlock; 272 goto unlock;
255 } 273 }
256 274
257 if (mod->Attributes & (CONF_IRQ_CHANGE_VALID | CONF_VCC_CHANGE_VALID)) { 275 io_on.speed = io_speed;
258 dev_dbg(&s->dev, 276 for (i = 0; i < MAX_IO_WIN; i++) {
259 "changing Vcc or IRQ is not allowed at this time\n"); 277 if (!s->io[i].res)
260 ret = -EINVAL; 278 continue;
261 goto unlock; 279 io_off.map = i;
262 } 280 io_on.map = i;
263 281
264 /* We only allow changing Vpp1 and Vpp2 to the same value */ 282 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
265 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && 283 io_on.start = s->io[i].res->start;
266 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 284 io_on.stop = s->io[i].res->end;
267 if (mod->Vpp1 != mod->Vpp2) { 285
268 dev_dbg(&s->dev, "Vpp1 and Vpp2 must be the same\n"); 286 s->ops->set_io_map(s, &io_off);
269 ret = -EINVAL; 287 mdelay(40);
270 goto unlock; 288 s->ops->set_io_map(s, &io_on);
271 }
272 s->socket.Vpp = mod->Vpp1;
273 if (s->ops->set_socket(s, &s->socket)) {
274 dev_printk(KERN_WARNING, &s->dev,
275 "Unable to set VPP\n");
276 ret = -EIO;
277 goto unlock;
278 }
279 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
280 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
281 dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n");
282 ret = -EINVAL;
283 goto unlock;
284 } 289 }
290unlock:
291 mutex_unlock(&s->ops_mutex);
285 292
286 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { 293 return ret;
287 pccard_io_map io_off = { 0, 0, 0, 0, 1 }; 294}
288 pccard_io_map io_on; 295EXPORT_SYMBOL(pcmcia_fixup_iowidth);
289 int i;
290 296
291 io_on.speed = io_speed;
292 for (i = 0; i < MAX_IO_WIN; i++) {
293 if (!s->io[i].res)
294 continue;
295 io_off.map = i;
296 io_on.map = i;
297 297
298 io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8; 298/**
299 io_on.start = s->io[i].res->start; 299 * pcmcia_fixup_vpp() - set Vpp to a new voltage level
300 io_on.stop = s->io[i].res->end; 300 * @p_dev: pcmcia device
301 * @new_vpp: new Vpp voltage
302 *
303 * pcmcia_fixup_vpp() allows a PCMCIA device driver to set Vpp to
304 * a new voltage level between calls to pcmcia_enable_device()
305 * and pcmcia_disable_device().
306 */
307int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp)
308{
309 struct pcmcia_socket *s = p_dev->socket;
310 int ret = 0;
301 311
302 s->ops->set_io_map(s, &io_off); 312 mutex_lock(&s->ops_mutex);
303 mdelay(40); 313
304 s->ops->set_io_map(s, &io_on); 314 dev_dbg(&p_dev->dev, "fixup Vpp to %d\n", new_vpp);
305 } 315
316 if (!(s->state & SOCKET_PRESENT) ||
317 !(p_dev->function_config->state & CONFIG_LOCKED)) {
318 dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
319 ret = -EACCES;
320 goto unlock;
306 } 321 }
307 ret = 0; 322
323 s->socket.Vpp = new_vpp;
324 if (s->ops->set_socket(s, &s->socket)) {
325 dev_warn(&p_dev->dev, "Unable to set VPP\n");
326 ret = -EIO;
327 goto unlock;
328 }
329 p_dev->vpp = new_vpp;
330
308unlock: 331unlock:
309 mutex_unlock(&s->ops_mutex); 332 mutex_unlock(&s->ops_mutex);
310 333
311 return ret; 334 return ret;
312} /* modify_configuration */ 335}
313EXPORT_SYMBOL(pcmcia_modify_configuration); 336EXPORT_SYMBOL(pcmcia_fixup_vpp);
314 337
315 338
339/**
340 * pcmcia_release_configuration() - physically disable a PCMCIA device
341 * @p_dev: pcmcia device
342 *
343 * pcmcia_release_configuration() is the 1:1 counterpart to
344 * pcmcia_enable_device(): If a PCMCIA device is no longer used by any
345 * driver, the Vpp voltage is set to 0, IRQs will no longer be generated,
346 * and I/O ranges will be disabled. As pcmcia_release_io() and
347 * pcmcia_release_window() still need to be called, device drivers are
348 * expected to call pcmcia_disable_device() instead.
349 */
316int pcmcia_release_configuration(struct pcmcia_device *p_dev) 350int pcmcia_release_configuration(struct pcmcia_device *p_dev)
317{ 351{
318 pccard_io_map io = { 0, 0, 0, 0, 1 }; 352 pccard_io_map io = { 0, 0, 0, 0, 1 };
@@ -325,7 +359,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
325 if (p_dev->_locked) { 359 if (p_dev->_locked) {
326 p_dev->_locked = 0; 360 p_dev->_locked = 0;
327 if (--(s->lock_count) == 0) { 361 if (--(s->lock_count) == 0) {
328 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */ 362 s->socket.flags = SS_OUTPUT_ENA; /* Is this correct? */
329 s->socket.Vpp = 0; 363 s->socket.Vpp = 0;
330 s->socket.io_irq = 0; 364 s->socket.io_irq = 0;
331 s->ops->set_socket(s, &s->socket); 365 s->ops->set_socket(s, &s->socket);
@@ -347,16 +381,18 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
347 mutex_unlock(&s->ops_mutex); 381 mutex_unlock(&s->ops_mutex);
348 382
349 return 0; 383 return 0;
350} /* pcmcia_release_configuration */ 384}
351 385
352 386
353/** pcmcia_release_io 387/**
388 * pcmcia_release_io() - release I/O allocated by a PCMCIA device
389 * @p_dev: pcmcia device
354 * 390 *
355 * Release_io() releases the I/O ranges allocated by a client. This 391 * pcmcia_release_io() releases the I/O ranges allocated by a PCMCIA
356 * may be invoked some time after a card ejection has already dumped 392 * device. This may be invoked some time after a card ejection has
357 * the actual socket configuration, so if the client is "stale", we 393 * already dumped the actual socket configuration, so if the client is
358 * don't bother checking the port ranges against the current socket 394 * "stale", we don't bother checking the port ranges against the
359 * values. 395 * current socket values.
360 */ 396 */
361static int pcmcia_release_io(struct pcmcia_device *p_dev) 397static int pcmcia_release_io(struct pcmcia_device *p_dev)
362{ 398{
@@ -385,6 +421,14 @@ out:
385} /* pcmcia_release_io */ 421} /* pcmcia_release_io */
386 422
387 423
424/**
425 * pcmcia_release_window() - release reserved iomem for PCMCIA devices
426 * @p_dev: pcmcia device
427 * @res: iomem resource to release
428 *
429 * pcmcia_release_window() releases &struct resource *res which was
430 * previously reserved by calling pcmcia_request_window().
431 */
388int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res) 432int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
389{ 433{
390 struct pcmcia_socket *s = p_dev->socket; 434 struct pcmcia_socket *s = p_dev->socket;
@@ -401,7 +445,7 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
401 win = &s->win[w]; 445 win = &s->win[w];
402 446
403 if (!(p_dev->_win & CLIENT_WIN_REQ(w))) { 447 if (!(p_dev->_win & CLIENT_WIN_REQ(w))) {
404 dev_dbg(&s->dev, "not releasing unknown window\n"); 448 dev_dbg(&p_dev->dev, "not releasing unknown window\n");
405 mutex_unlock(&s->ops_mutex); 449 mutex_unlock(&s->ops_mutex);
406 return -EINVAL; 450 return -EINVAL;
407 } 451 }
@@ -418,6 +462,8 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
418 kfree(win->res); 462 kfree(win->res);
419 win->res = NULL; 463 win->res = NULL;
420 } 464 }
465 res->start = res->end = 0;
466 res->flags = IORESOURCE_MEM;
421 p_dev->_win &= ~CLIENT_WIN_REQ(w); 467 p_dev->_win &= ~CLIENT_WIN_REQ(w);
422 mutex_unlock(&s->ops_mutex); 468 mutex_unlock(&s->ops_mutex);
423 469
@@ -426,99 +472,114 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res)
426EXPORT_SYMBOL(pcmcia_release_window); 472EXPORT_SYMBOL(pcmcia_release_window);
427 473
428 474
429int pcmcia_request_configuration(struct pcmcia_device *p_dev, 475/**
430 config_req_t *req) 476 * pcmcia_enable_device() - set up and activate a PCMCIA device
477 * @p_dev: the associated PCMCIA device
478 *
479 * pcmcia_enable_device() physically enables a PCMCIA device. It parses
480 * the flags passed to in @flags and stored in @p_dev->flags and sets up
481 * the Vpp voltage, enables the speaker line, I/O ports and store proper
482 * values to configuration registers.
483 */
484int pcmcia_enable_device(struct pcmcia_device *p_dev)
431{ 485{
432 int i; 486 int i;
433 u_int base; 487 unsigned int base;
434 struct pcmcia_socket *s = p_dev->socket; 488 struct pcmcia_socket *s = p_dev->socket;
435 config_t *c; 489 config_t *c;
436 pccard_io_map iomap; 490 pccard_io_map iomap;
491 unsigned char status = 0;
492 unsigned char ext_status = 0;
493 unsigned char option = 0;
494 unsigned int flags = p_dev->config_flags;
437 495
438 if (!(s->state & SOCKET_PRESENT)) 496 if (!(s->state & SOCKET_PRESENT))
439 return -ENODEV; 497 return -ENODEV;
440 498
441 if (req->IntType & INT_CARDBUS) {
442 dev_dbg(&s->dev, "IntType may not be INT_CARDBUS\n");
443 return -EINVAL;
444 }
445
446 mutex_lock(&s->ops_mutex); 499 mutex_lock(&s->ops_mutex);
447 c = p_dev->function_config; 500 c = p_dev->function_config;
448 if (c->state & CONFIG_LOCKED) { 501 if (c->state & CONFIG_LOCKED) {
449 mutex_unlock(&s->ops_mutex); 502 mutex_unlock(&s->ops_mutex);
450 dev_dbg(&s->dev, "Configuration is locked\n"); 503 dev_dbg(&p_dev->dev, "Configuration is locked\n");
451 return -EACCES; 504 return -EACCES;
452 } 505 }
453 506
454 /* Do power control. We don't allow changes in Vcc. */ 507 /* Do power control. We don't allow changes in Vcc. */
455 s->socket.Vpp = req->Vpp; 508 s->socket.Vpp = p_dev->vpp;
456 if (s->ops->set_socket(s, &s->socket)) { 509 if (s->ops->set_socket(s, &s->socket)) {
457 mutex_unlock(&s->ops_mutex); 510 mutex_unlock(&s->ops_mutex);
458 dev_printk(KERN_WARNING, &s->dev, 511 dev_printk(KERN_WARNING, &p_dev->dev,
459 "Unable to set socket state\n"); 512 "Unable to set socket state\n");
460 return -EINVAL; 513 return -EINVAL;
461 } 514 }
462 515
463 /* Pick memory or I/O card, DMA mode, interrupt */ 516 /* Pick memory or I/O card, DMA mode, interrupt */
464 c->IntType = req->IntType; 517 if (p_dev->_io)
465 c->Attributes = req->Attributes;
466 if (req->IntType & INT_MEMORY_AND_IO)
467 s->socket.flags |= SS_IOCARD; 518 s->socket.flags |= SS_IOCARD;
468 if (req->IntType & INT_ZOOMED_VIDEO) 519 if (flags & CONF_ENABLE_SPKR) {
469 s->socket.flags |= SS_ZVCARD | SS_IOCARD;
470 if (req->Attributes & CONF_ENABLE_DMA)
471 s->socket.flags |= SS_DMA_MODE;
472 if (req->Attributes & CONF_ENABLE_SPKR)
473 s->socket.flags |= SS_SPKR_ENA; 520 s->socket.flags |= SS_SPKR_ENA;
474 if (req->Attributes & CONF_ENABLE_IRQ) 521 status = CCSR_AUDIO_ENA;
522 if (!(p_dev->config_regs & PRESENT_STATUS))
523 dev_warn(&p_dev->dev, "speaker requested, but "
524 "PRESENT_STATUS not set!\n");
525 }
526 if (flags & CONF_ENABLE_IRQ)
475 s->socket.io_irq = s->pcmcia_irq; 527 s->socket.io_irq = s->pcmcia_irq;
476 else 528 else
477 s->socket.io_irq = 0; 529 s->socket.io_irq = 0;
530 if (flags & CONF_ENABLE_ESR) {
531 p_dev->config_regs |= PRESENT_EXT_STATUS;
532 ext_status = ESR_REQ_ATTN_ENA;
533 }
478 s->ops->set_socket(s, &s->socket); 534 s->ops->set_socket(s, &s->socket);
479 s->lock_count++; 535 s->lock_count++;
480 536
537 dev_dbg(&p_dev->dev,
538 "enable_device: V %d, flags %x, base %x, regs %x, idx %x\n",
539 p_dev->vpp, flags, p_dev->config_base, p_dev->config_regs,
540 p_dev->config_index);
541
481 /* Set up CIS configuration registers */ 542 /* Set up CIS configuration registers */
482 base = c->ConfigBase = req->ConfigBase; 543 base = p_dev->config_base;
483 c->CardValues = req->Present; 544 if (p_dev->config_regs & PRESENT_COPY) {
484 if (req->Present & PRESENT_COPY) { 545 u16 tmp = 0;
485 c->Copy = req->Copy; 546 dev_dbg(&p_dev->dev, "clearing CISREG_SCR\n");
486 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &c->Copy); 547 pcmcia_write_cis_mem(s, 1, (base + CISREG_SCR)>>1, 1, &tmp);
487 } 548 }
488 if (req->Present & PRESENT_OPTION) { 549 if (p_dev->config_regs & PRESENT_PIN_REPLACE) {
550 u16 tmp = 0;
551 dev_dbg(&p_dev->dev, "clearing CISREG_PRR\n");
552 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &tmp);
553 }
554 if (p_dev->config_regs & PRESENT_OPTION) {
489 if (s->functions == 1) { 555 if (s->functions == 1) {
490 c->Option = req->ConfigIndex & COR_CONFIG_MASK; 556 option = p_dev->config_index & COR_CONFIG_MASK;
491 } else { 557 } else {
492 c->Option = req->ConfigIndex & COR_MFC_CONFIG_MASK; 558 option = p_dev->config_index & COR_MFC_CONFIG_MASK;
493 c->Option |= COR_FUNC_ENA|COR_IREQ_ENA; 559 option |= COR_FUNC_ENA|COR_IREQ_ENA;
494 if (req->Present & PRESENT_IOBASE_0) 560 if (p_dev->config_regs & PRESENT_IOBASE_0)
495 c->Option |= COR_ADDR_DECODE; 561 option |= COR_ADDR_DECODE;
496 } 562 }
497 if ((req->Attributes & CONF_ENABLE_IRQ) && 563 if ((flags & CONF_ENABLE_IRQ) &&
498 !(req->Attributes & CONF_ENABLE_PULSE_IRQ)) 564 !(flags & CONF_ENABLE_PULSE_IRQ))
499 c->Option |= COR_LEVEL_REQ; 565 option |= COR_LEVEL_REQ;
500 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option); 566 pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &option);
501 mdelay(40); 567 mdelay(40);
502 } 568 }
503 if (req->Present & PRESENT_STATUS) { 569 if (p_dev->config_regs & PRESENT_STATUS)
504 c->Status = req->Status; 570 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &status);
505 pcmcia_write_cis_mem(s, 1, (base + CISREG_CCSR)>>1, 1, &c->Status); 571
506 } 572 if (p_dev->config_regs & PRESENT_EXT_STATUS)
507 if (req->Present & PRESENT_PIN_REPLACE) { 573 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1,
508 c->Pin = req->Pin; 574 &ext_status);
509 pcmcia_write_cis_mem(s, 1, (base + CISREG_PRR)>>1, 1, &c->Pin); 575
510 } 576 if (p_dev->config_regs & PRESENT_IOBASE_0) {
511 if (req->Present & PRESENT_EXT_STATUS) {
512 c->ExtStatus = req->ExtStatus;
513 pcmcia_write_cis_mem(s, 1, (base + CISREG_ESR)>>1, 1, &c->ExtStatus);
514 }
515 if (req->Present & PRESENT_IOBASE_0) {
516 u8 b = c->io[0].start & 0xff; 577 u8 b = c->io[0].start & 0xff;
517 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b); 578 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_0)>>1, 1, &b);
518 b = (c->io[0].start >> 8) & 0xff; 579 b = (c->io[0].start >> 8) & 0xff;
519 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b); 580 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOBASE_1)>>1, 1, &b);
520 } 581 }
521 if (req->Present & PRESENT_IOSIZE) { 582 if (p_dev->config_regs & PRESENT_IOSIZE) {
522 u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1; 583 u8 b = resource_size(&c->io[0]) + resource_size(&c->io[1]) - 1;
523 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b); 584 pcmcia_write_cis_mem(s, 1, (base + CISREG_IOSIZE)>>1, 1, &b);
524 } 585 }
@@ -549,14 +610,15 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
549 p_dev->_locked = 1; 610 p_dev->_locked = 1;
550 mutex_unlock(&s->ops_mutex); 611 mutex_unlock(&s->ops_mutex);
551 return 0; 612 return 0;
552} /* pcmcia_request_configuration */ 613} /* pcmcia_enable_device */
553EXPORT_SYMBOL(pcmcia_request_configuration); 614EXPORT_SYMBOL(pcmcia_enable_device);
554 615
555 616
556/** 617/**
557 * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices 618 * pcmcia_request_io() - attempt to reserve port ranges for PCMCIA devices
619 * @p_dev: the associated PCMCIA device
558 * 620 *
559 * pcmcia_request_io() attepts to reserve the IO port ranges specified in 621 * pcmcia_request_io() attempts to reserve the IO port ranges specified in
560 * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The 622 * &struct pcmcia_device @p_dev->resource[0] and @p_dev->resource[1]. The
561 * "start" value is the requested start of the IO port resource; "end" 623 * "start" value is the requested start of the IO port resource; "end"
562 * reflects the number of ports requested. The number of IO lines requested 624 * reflects the number of ports requested. The number of IO lines requested
@@ -569,19 +631,20 @@ int pcmcia_request_io(struct pcmcia_device *p_dev)
569 int ret = -EINVAL; 631 int ret = -EINVAL;
570 632
571 mutex_lock(&s->ops_mutex); 633 mutex_lock(&s->ops_mutex);
572 dev_dbg(&s->dev, "pcmcia_request_io: %pR , %pR", &c->io[0], &c->io[1]); 634 dev_dbg(&p_dev->dev, "pcmcia_request_io: %pR , %pR",
635 &c->io[0], &c->io[1]);
573 636
574 if (!(s->state & SOCKET_PRESENT)) { 637 if (!(s->state & SOCKET_PRESENT)) {
575 dev_dbg(&s->dev, "pcmcia_request_io: No card present\n"); 638 dev_dbg(&p_dev->dev, "pcmcia_request_io: No card present\n");
576 goto out; 639 goto out;
577 } 640 }
578 641
579 if (c->state & CONFIG_LOCKED) { 642 if (c->state & CONFIG_LOCKED) {
580 dev_dbg(&s->dev, "Configuration is locked\n"); 643 dev_dbg(&p_dev->dev, "Configuration is locked\n");
581 goto out; 644 goto out;
582 } 645 }
583 if (c->state & CONFIG_IO_REQ) { 646 if (c->state & CONFIG_IO_REQ) {
584 dev_dbg(&s->dev, "IO already configured\n"); 647 dev_dbg(&p_dev->dev, "IO already configured\n");
585 goto out; 648 goto out;
586 } 649 }
587 650
@@ -592,7 +655,13 @@ int pcmcia_request_io(struct pcmcia_device *p_dev)
592 if (c->io[1].end) { 655 if (c->io[1].end) {
593 ret = alloc_io_space(s, &c->io[1], p_dev->io_lines); 656 ret = alloc_io_space(s, &c->io[1], p_dev->io_lines);
594 if (ret) { 657 if (ret) {
658 struct resource tmp = c->io[0];
659 /* release the previously allocated resource */
595 release_io_space(s, &c->io[0]); 660 release_io_space(s, &c->io[0]);
661 /* but preserve the settings, for they worked... */
662 c->io[0].end = resource_size(&tmp);
663 c->io[0].start = tmp.start;
664 c->io[0].flags = tmp.flags;
596 goto out; 665 goto out;
597 } 666 }
598 } else 667 } else
@@ -601,7 +670,7 @@ int pcmcia_request_io(struct pcmcia_device *p_dev)
601 c->state |= CONFIG_IO_REQ; 670 c->state |= CONFIG_IO_REQ;
602 p_dev->_io = 1; 671 p_dev->_io = 1;
603 672
604 dev_dbg(&s->dev, "pcmcia_request_io succeeded: %pR , %pR", 673 dev_dbg(&p_dev->dev, "pcmcia_request_io succeeded: %pR , %pR",
605 &c->io[0], &c->io[1]); 674 &c->io[0], &c->io[1]);
606out: 675out:
607 mutex_unlock(&s->ops_mutex); 676 mutex_unlock(&s->ops_mutex);
@@ -613,11 +682,13 @@ EXPORT_SYMBOL(pcmcia_request_io);
613 682
614/** 683/**
615 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device 684 * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
685 * @p_dev: the associated PCMCIA device
686 * @handler: IRQ handler to register
616 * 687 *
617 * pcmcia_request_irq() is a wrapper around request_irq which will allow 688 * pcmcia_request_irq() is a wrapper around request_irq() which allows
618 * the PCMCIA core to clean up the registration in pcmcia_disable_device(). 689 * the PCMCIA core to clean up the registration in pcmcia_disable_device().
619 * Drivers are free to use request_irq() directly, but then they need to 690 * Drivers are free to use request_irq() directly, but then they need to
620 * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ 691 * call free_irq() themselfves, too. Also, only %IRQF_SHARED capable IRQ
621 * handlers are allowed. 692 * handlers are allowed.
622 */ 693 */
623int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev, 694int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
@@ -640,12 +711,14 @@ EXPORT_SYMBOL(pcmcia_request_irq);
640 711
641/** 712/**
642 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first 713 * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
714 * @p_dev: the associated PCMCIA device
715 * @handler: IRQ handler to register
643 * 716 *
644 * pcmcia_request_exclusive_irq() is a wrapper around request_irq which 717 * pcmcia_request_exclusive_irq() is a wrapper around request_irq() which
645 * attempts first to request an exclusive IRQ. If it fails, it also accepts 718 * attempts first to request an exclusive IRQ. If it fails, it also accepts
646 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for 719 * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
647 * IRQ sharing and either use request_irq directly (then they need to call 720 * IRQ sharing and either use request_irq directly (then they need to call
648 * free_irq themselves, too), or the pcmcia_request_irq() function. 721 * free_irq() themselves, too), or the pcmcia_request_irq() function.
649 */ 722 */
650int __must_check 723int __must_check
651__pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev, 724__pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
@@ -786,38 +859,47 @@ int pcmcia_setup_irq(struct pcmcia_device *p_dev)
786} 859}
787 860
788 861
789/** pcmcia_request_window 862/**
863 * pcmcia_request_window() - attempt to reserve iomem for PCMCIA devices
864 * @p_dev: the associated PCMCIA device
865 * @res: &struct resource pointing to p_dev->resource[2..5]
866 * @speed: access speed
790 * 867 *
791 * Request_window() establishes a mapping between card memory space 868 * pcmcia_request_window() attepts to reserve an iomem ranges specified in
792 * and system memory space. 869 * &struct resource @res pointing to one of the entries in
870 * &struct pcmcia_device @p_dev->resource[2..5]. The "start" value is the
871 * requested start of the IO mem resource; "end" reflects the size
872 * requested.
793 */ 873 */
794int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_handle_t *wh) 874int pcmcia_request_window(struct pcmcia_device *p_dev, struct resource *res,
875 unsigned int speed)
795{ 876{
796 struct pcmcia_socket *s = p_dev->socket; 877 struct pcmcia_socket *s = p_dev->socket;
797 pccard_mem_map *win; 878 pccard_mem_map *win;
798 u_long align; 879 u_long align;
799 struct resource *res;
800 int w; 880 int w;
801 881
882 dev_dbg(&p_dev->dev, "request_window %pR %d\n", res, speed);
883
802 if (!(s->state & SOCKET_PRESENT)) { 884 if (!(s->state & SOCKET_PRESENT)) {
803 dev_dbg(&s->dev, "No card present\n"); 885 dev_dbg(&p_dev->dev, "No card present\n");
804 return -ENODEV; 886 return -ENODEV;
805 } 887 }
806 888
807 /* Window size defaults to smallest available */ 889 /* Window size defaults to smallest available */
808 if (req->Size == 0) 890 if (res->end == 0)
809 req->Size = s->map_size; 891 res->end = s->map_size;
810 align = (s->features & SS_CAP_MEM_ALIGN) ? req->Size : s->map_size; 892 align = (s->features & SS_CAP_MEM_ALIGN) ? res->end : s->map_size;
811 if (req->Size & (s->map_size-1)) { 893 if (res->end & (s->map_size-1)) {
812 dev_dbg(&s->dev, "invalid map size\n"); 894 dev_dbg(&p_dev->dev, "invalid map size\n");
813 return -EINVAL; 895 return -EINVAL;
814 } 896 }
815 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || 897 if ((res->start && (s->features & SS_CAP_STATIC_MAP)) ||
816 (req->Base & (align-1))) { 898 (res->start & (align-1))) {
817 dev_dbg(&s->dev, "invalid base address\n"); 899 dev_dbg(&p_dev->dev, "invalid base address\n");
818 return -EINVAL; 900 return -EINVAL;
819 } 901 }
820 if (req->Base) 902 if (res->start)
821 align = 0; 903 align = 0;
822 904
823 /* Allocate system memory window */ 905 /* Allocate system memory window */
@@ -826,7 +908,7 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
826 if (!(s->state & SOCKET_WIN_REQ(w))) 908 if (!(s->state & SOCKET_WIN_REQ(w)))
827 break; 909 break;
828 if (w == MAX_WIN) { 910 if (w == MAX_WIN) {
829 dev_dbg(&s->dev, "all windows are used already\n"); 911 dev_dbg(&p_dev->dev, "all windows are used already\n");
830 mutex_unlock(&s->ops_mutex); 912 mutex_unlock(&s->ops_mutex);
831 return -EINVAL; 913 return -EINVAL;
832 } 914 }
@@ -834,10 +916,10 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
834 win = &s->win[w]; 916 win = &s->win[w];
835 917
836 if (!(s->features & SS_CAP_STATIC_MAP)) { 918 if (!(s->features & SS_CAP_STATIC_MAP)) {
837 win->res = pcmcia_find_mem_region(req->Base, req->Size, align, 919 win->res = pcmcia_find_mem_region(res->start, res->end, align,
838 0, s); 920 0, s);
839 if (!win->res) { 921 if (!win->res) {
840 dev_dbg(&s->dev, "allocating mem region failed\n"); 922 dev_dbg(&p_dev->dev, "allocating mem region failed\n");
841 mutex_unlock(&s->ops_mutex); 923 mutex_unlock(&s->ops_mutex);
842 return -EINVAL; 924 return -EINVAL;
843 } 925 }
@@ -846,12 +928,12 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
846 928
847 /* Configure the socket controller */ 929 /* Configure the socket controller */
848 win->map = w+1; 930 win->map = w+1;
849 win->flags = req->Attributes; 931 win->flags = res->flags & WIN_FLAGS_MAP;
850 win->speed = req->AccessSpeed; 932 win->speed = speed;
851 win->card_start = 0; 933 win->card_start = 0;
852 934
853 if (s->ops->set_mem_map(s, win) != 0) { 935 if (s->ops->set_mem_map(s, win) != 0) {
854 dev_dbg(&s->dev, "failed to set memory mapping\n"); 936 dev_dbg(&p_dev->dev, "failed to set memory mapping\n");
855 mutex_unlock(&s->ops_mutex); 937 mutex_unlock(&s->ops_mutex);
856 return -EIO; 938 return -EIO;
857 } 939 }
@@ -859,33 +941,45 @@ int pcmcia_request_window(struct pcmcia_device *p_dev, win_req_t *req, window_ha
859 941
860 /* Return window handle */ 942 /* Return window handle */
861 if (s->features & SS_CAP_STATIC_MAP) 943 if (s->features & SS_CAP_STATIC_MAP)
862 req->Base = win->static_start; 944 res->start = win->static_start;
863 else 945 else
864 req->Base = win->res->start; 946 res->start = win->res->start;
865 947
866 /* convert to new-style resources */ 948 /* convert to new-style resources */
867 res = p_dev->resource[w + MAX_IO_WIN]; 949 res->end += res->start - 1;
868 res->start = req->Base; 950 res->flags &= ~WIN_FLAGS_REQ;
869 res->end = req->Base + req->Size - 1; 951 res->flags |= (win->map << 2) | IORESOURCE_MEM;
870 res->flags &= ~IORESOURCE_BITS;
871 res->flags |= (req->Attributes & WIN_FLAGS_MAP) | (win->map << 2);
872 res->flags |= IORESOURCE_MEM;
873 res->parent = win->res; 952 res->parent = win->res;
874 if (win->res) 953 if (win->res)
875 request_resource(&iomem_resource, res); 954 request_resource(&iomem_resource, res);
876 955
877 dev_dbg(&s->dev, "request_window results in %pR\n", res); 956 dev_dbg(&p_dev->dev, "request_window results in %pR\n", res);
878 957
879 mutex_unlock(&s->ops_mutex); 958 mutex_unlock(&s->ops_mutex);
880 *wh = res;
881 959
882 return 0; 960 return 0;
883} /* pcmcia_request_window */ 961} /* pcmcia_request_window */
884EXPORT_SYMBOL(pcmcia_request_window); 962EXPORT_SYMBOL(pcmcia_request_window);
885 963
964
965/**
966 * pcmcia_disable_device() - disable and clean up a PCMCIA device
967 * @p_dev: the associated PCMCIA device
968 *
969 * pcmcia_disable_device() is the driver-callable counterpart to
970 * pcmcia_enable_device(): If a PCMCIA device is no longer used,
971 * drivers are expected to clean up and disable the device by calling
972 * this function. Any I/O ranges (iomem and ioports) will be released,
973 * the Vpp voltage will be set to 0, and IRQs will no longer be
974 * generated -- at least if there is no other card function (of
975 * multifunction devices) being used.
976 */
886void pcmcia_disable_device(struct pcmcia_device *p_dev) 977void pcmcia_disable_device(struct pcmcia_device *p_dev)
887{ 978{
888 int i; 979 int i;
980
981 dev_dbg(&p_dev->dev, "disabling device\n");
982
889 for (i = 0; i < MAX_WIN; i++) { 983 for (i = 0; i < MAX_WIN; i++) {
890 struct resource *res = p_dev->resource[MAX_IO_WIN + i]; 984 struct resource *res = p_dev->resource[MAX_IO_WIN + i];
891 if (res->flags & WIN_FLAGS_REQ) 985 if (res->flags & WIN_FLAGS_REQ)
diff --git a/drivers/pcmcia/pd6729.c b/drivers/pcmcia/pd6729.c
index b8a869af0f44..8cbfa067171f 100644
--- a/drivers/pcmcia/pd6729.c
+++ b/drivers/pcmcia/pd6729.c
@@ -18,7 +18,6 @@
18#include <linux/io.h> 18#include <linux/io.h>
19 19
20#include <pcmcia/ss.h> 20#include <pcmcia/ss.h>
21#include <pcmcia/cs.h>
22 21
23#include <asm/system.h> 22#include <asm/system.h>
24 23
@@ -646,7 +645,7 @@ static int __devinit pd6729_pci_probe(struct pci_dev *dev,
646 if (!pci_resource_start(dev, 0)) { 645 if (!pci_resource_start(dev, 0)) {
647 dev_warn(&dev->dev, "refusing to load the driver as the " 646 dev_warn(&dev->dev, "refusing to load the driver as the "
648 "io_base is NULL.\n"); 647 "io_base is NULL.\n");
649 goto err_out_free_mem; 648 goto err_out_disable;
650 } 649 }
651 650
652 dev_info(&dev->dev, "Cirrus PD6729 PCI to PCMCIA Bridge at 0x%llx " 651 dev_info(&dev->dev, "Cirrus PD6729 PCI to PCMCIA Bridge at 0x%llx "
diff --git a/drivers/pcmcia/rsrc_iodyn.c b/drivers/pcmcia/rsrc_iodyn.c
index 8510c35d2952..523eb691c30b 100644
--- a/drivers/pcmcia/rsrc_iodyn.c
+++ b/drivers/pcmcia/rsrc_iodyn.c
@@ -17,7 +17,6 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18 18
19#include <pcmcia/ss.h> 19#include <pcmcia/ss.h>
20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h> 20#include <pcmcia/cistpl.h>
22#include "cs_internal.h" 21#include "cs_internal.h"
23 22
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index 4e80421fd908..aa628ed0e9f4 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -17,7 +17,6 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18 18
19#include <pcmcia/ss.h> 19#include <pcmcia/ss.h>
20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h> 20#include <pcmcia/cistpl.h>
22#include "cs_internal.h" 21#include "cs_internal.h"
23 22
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 96f348b35fde..b187555d4388 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -29,7 +29,6 @@
29#include <asm/irq.h> 29#include <asm/irq.h>
30 30
31#include <pcmcia/ss.h> 31#include <pcmcia/ss.h>
32#include <pcmcia/cs.h>
33#include <pcmcia/cistpl.h> 32#include <pcmcia/cistpl.h>
34#include "cs_internal.h" 33#include "cs_internal.h"
35 34
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index e09851480295..945857f8c284 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -35,7 +35,6 @@
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37 37
38#include <pcmcia/cs.h>
39#include <pcmcia/ss.h> 38#include <pcmcia/ss.h>
40 39
41#include <asm/hardware/scoop.h> 40#include <asm/hardware/scoop.h>
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index 6f1a86b43c60..689e3c02edb8 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -627,8 +627,6 @@ void soc_pcmcia_remove_one(struct soc_pcmcia_socket *skt)
627 627
628 pcmcia_unregister_socket(&skt->socket); 628 pcmcia_unregister_socket(&skt->socket);
629 629
630 flush_scheduled_work();
631
632 skt->ops->hw_shutdown(skt); 630 skt->ops->hw_shutdown(skt);
633 631
634 soc_common_pcmcia_config_skt(skt, &dead_socket); 632 soc_common_pcmcia_config_skt(skt, &dead_socket);
@@ -720,8 +718,6 @@ int soc_pcmcia_add_one(struct soc_pcmcia_socket *skt)
720 pcmcia_unregister_socket(&skt->socket); 718 pcmcia_unregister_socket(&skt->socket);
721 719
722 out_err_7: 720 out_err_7:
723 flush_scheduled_work();
724
725 skt->ops->hw_shutdown(skt); 721 skt->ops->hw_shutdown(skt);
726 out_err_6: 722 out_err_6:
727 list_del(&skt->node); 723 list_del(&skt->node);
diff --git a/drivers/pcmcia/soc_common.h b/drivers/pcmcia/soc_common.h
index 3fba3a679128..bbcd5385a221 100644
--- a/drivers/pcmcia/soc_common.h
+++ b/drivers/pcmcia/soc_common.h
@@ -11,7 +11,6 @@
11 11
12/* include the world */ 12/* include the world */
13#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
14#include <pcmcia/cs.h>
15#include <pcmcia/ss.h> 14#include <pcmcia/ss.h>
16#include <pcmcia/cistpl.h> 15#include <pcmcia/cistpl.h>
17 16
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index cb0d3ace18bd..71aeed93037c 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -27,7 +27,6 @@
27#include <asm/irq.h> 27#include <asm/irq.h>
28 28
29#include <pcmcia/ss.h> 29#include <pcmcia/ss.h>
30#include <pcmcia/cs.h>
31#include <pcmcia/cistpl.h> 30#include <pcmcia/cistpl.h>
32#include <pcmcia/cisreg.h> 31#include <pcmcia/cisreg.h>
33#include <pcmcia/ds.h> 32#include <pcmcia/ds.h>
diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
index be0d841c7ebd..310160bffe38 100644
--- a/drivers/pcmcia/tcic.c
+++ b/drivers/pcmcia/tcic.c
@@ -49,7 +49,6 @@
49#include <asm/io.h> 49#include <asm/io.h>
50#include <asm/system.h> 50#include <asm/system.h>
51 51
52#include <pcmcia/cs.h>
53#include <pcmcia/ss.h> 52#include <pcmcia/ss.h>
54#include "tcic.h" 53#include "tcic.h"
55 54
diff --git a/drivers/pcmcia/vrc4173_cardu.c b/drivers/pcmcia/vrc4173_cardu.c
index 9b3c15827e5c..c6d36b3a6ce8 100644
--- a/drivers/pcmcia/vrc4173_cardu.c
+++ b/drivers/pcmcia/vrc4173_cardu.c
@@ -461,7 +461,7 @@ static int __devinit vrc4173_cardu_probe(struct pci_dev *dev,
461{ 461{
462 vrc4173_socket_t *socket; 462 vrc4173_socket_t *socket;
463 unsigned long start, len, flags; 463 unsigned long start, len, flags;
464 int slot, err; 464 int slot, err, ret;
465 465
466 slot = vrc4173_cardu_slots++; 466 slot = vrc4173_cardu_slots++;
467 socket = &cardu_sockets[slot]; 467 socket = &cardu_sockets[slot];
@@ -474,43 +474,63 @@ static int __devinit vrc4173_cardu_probe(struct pci_dev *dev,
474 return err; 474 return err;
475 475
476 start = pci_resource_start(dev, 0); 476 start = pci_resource_start(dev, 0);
477 if (start == 0) 477 if (start == 0) {
478 return -ENODEV; 478 ret = -ENODEV;
479 goto disable;
480 }
479 481
480 len = pci_resource_len(dev, 0); 482 len = pci_resource_len(dev, 0);
481 if (len == 0) 483 if (len == 0) {
482 return -ENODEV; 484 ret = -ENODEV;
485 goto disable;
486 }
483 487
484 if (((flags = pci_resource_flags(dev, 0)) & IORESOURCE_MEM) == 0) 488 flags = pci_resource_flags(dev, 0);
485 return -EBUSY; 489 if ((flags & IORESOURCE_MEM) == 0) {
490 ret = -EBUSY;
491 goto disable;
492 }
486 493
487 if ((err = pci_request_regions(dev, socket->name)) < 0) 494 err = pci_request_regions(dev, socket->name);
488 return err; 495 if (err < 0) {
496 ret = err;
497 goto disable;
498 }
489 499
490 socket->base = ioremap(start, len); 500 socket->base = ioremap(start, len);
491 if (socket->base == NULL) 501 if (socket->base == NULL) {
492 return -ENODEV; 502 ret = -ENODEV;
503 goto release;
504 }
493 505
494 socket->dev = dev; 506 socket->dev = dev;
495 507
496 socket->pcmcia_socket = pcmcia_register_socket(slot, &cardu_operations, 1); 508 socket->pcmcia_socket = pcmcia_register_socket(slot, &cardu_operations, 1);
497 if (socket->pcmcia_socket == NULL) { 509 if (socket->pcmcia_socket == NULL) {
498 iounmap(socket->base); 510 ret = -ENOMEM;
499 socket->base = NULL; 511 goto unmap;
500 return -ENOMEM;
501 } 512 }
502 513
503 if (request_irq(dev->irq, cardu_interrupt, IRQF_SHARED, socket->name, socket) < 0) { 514 if (request_irq(dev->irq, cardu_interrupt, IRQF_SHARED, socket->name, socket) < 0) {
504 pcmcia_unregister_socket(socket->pcmcia_socket); 515 ret = -EBUSY;
505 socket->pcmcia_socket = NULL; 516 goto unregister;
506 iounmap(socket->base);
507 socket->base = NULL;
508 return -EBUSY;
509 } 517 }
510 518
511 printk(KERN_INFO "%s at %#08lx, IRQ %d\n", socket->name, start, dev->irq); 519 printk(KERN_INFO "%s at %#08lx, IRQ %d\n", socket->name, start, dev->irq);
512 520
513 return 0; 521 return 0;
522
523unregister:
524 pcmcia_unregister_socket(socket->pcmcia_socket);
525 socket->pcmcia_socket = NULL;
526unmap:
527 iounmap(socket->base);
528 socket->base = NULL;
529release:
530 pci_release_regions(dev);
531disable:
532 pci_disable_device(dev);
533 return ret;
514} 534}
515 535
516static int __devinit vrc4173_cardu_setup(char *options) 536static int __devinit vrc4173_cardu_setup(char *options)
diff --git a/drivers/pcmcia/xxs1500_ss.c b/drivers/pcmcia/xxs1500_ss.c
index fa88c360c37a..3b67a1b6a197 100644
--- a/drivers/pcmcia/xxs1500_ss.c
+++ b/drivers/pcmcia/xxs1500_ss.c
@@ -17,7 +17,6 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19 19
20#include <pcmcia/cs.h>
21#include <pcmcia/ss.h> 20#include <pcmcia/ss.h>
22#include <pcmcia/cistpl.h> 21#include <pcmcia/cistpl.h>
23 22
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 414d9a6f9a32..408dbaa080a1 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -20,7 +20,6 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21 21
22#include <pcmcia/ss.h> 22#include <pcmcia/ss.h>
23#include <pcmcia/cs.h>
24 23
25#include "yenta_socket.h" 24#include "yenta_socket.h"
26#include "i82365.h" 25#include "i82365.h"
diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
index 9024480a8228..c44a5e8b8b82 100644
--- a/drivers/platform/x86/intel_ips.c
+++ b/drivers/platform/x86/intel_ips.c
@@ -51,7 +51,6 @@
51 * TODO: 51 * TODO:
52 * - handle CPU hotplug 52 * - handle CPU hotplug
53 * - provide turbo enable/disable api 53 * - provide turbo enable/disable api
54 * - make sure we can write turbo enable/disable reg based on MISC_EN
55 * 54 *
56 * Related documents: 55 * Related documents:
57 * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2 56 * - CDI 403777, 403778 - Auburndale EDS vol 1 & 2
@@ -230,7 +229,7 @@
230#define THM_TC2 0xac 229#define THM_TC2 0xac
231#define THM_DTV 0xb0 230#define THM_DTV 0xb0
232#define THM_ITV 0xd8 231#define THM_ITV 0xd8
233#define ITV_ME_SEQNO_MASK 0x000f0000 /* ME should update every ~200ms */ 232#define ITV_ME_SEQNO_MASK 0x00ff0000 /* ME should update every ~200ms */
234#define ITV_ME_SEQNO_SHIFT (16) 233#define ITV_ME_SEQNO_SHIFT (16)
235#define ITV_MCH_TEMP_MASK 0x0000ff00 234#define ITV_MCH_TEMP_MASK 0x0000ff00
236#define ITV_MCH_TEMP_SHIFT (8) 235#define ITV_MCH_TEMP_SHIFT (8)
@@ -325,6 +324,7 @@ struct ips_driver {
325 bool gpu_preferred; 324 bool gpu_preferred;
326 bool poll_turbo_status; 325 bool poll_turbo_status;
327 bool second_cpu; 326 bool second_cpu;
327 bool turbo_toggle_allowed;
328 struct ips_mcp_limits *limits; 328 struct ips_mcp_limits *limits;
329 329
330 /* Optional MCH interfaces for if i915 is in use */ 330 /* Optional MCH interfaces for if i915 is in use */
@@ -415,7 +415,7 @@ static void ips_cpu_lower(struct ips_driver *ips)
415 new_limit = cur_limit - 8; /* 1W decrease */ 415 new_limit = cur_limit - 8; /* 1W decrease */
416 416
417 /* Clamp to SKU TDP limit */ 417 /* Clamp to SKU TDP limit */
418 if (((new_limit * 10) / 8) < (ips->orig_turbo_limit & TURBO_TDP_MASK)) 418 if (new_limit < (ips->orig_turbo_limit & TURBO_TDP_MASK))
419 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK; 419 new_limit = ips->orig_turbo_limit & TURBO_TDP_MASK;
420 420
421 thm_writew(THM_MPCPC, (new_limit * 10) / 8); 421 thm_writew(THM_MPCPC, (new_limit * 10) / 8);
@@ -461,7 +461,8 @@ static void ips_enable_cpu_turbo(struct ips_driver *ips)
461 if (ips->__cpu_turbo_on) 461 if (ips->__cpu_turbo_on)
462 return; 462 return;
463 463
464 on_each_cpu(do_enable_cpu_turbo, ips, 1); 464 if (ips->turbo_toggle_allowed)
465 on_each_cpu(do_enable_cpu_turbo, ips, 1);
465 466
466 ips->__cpu_turbo_on = true; 467 ips->__cpu_turbo_on = true;
467} 468}
@@ -498,7 +499,8 @@ static void ips_disable_cpu_turbo(struct ips_driver *ips)
498 if (!ips->__cpu_turbo_on) 499 if (!ips->__cpu_turbo_on)
499 return; 500 return;
500 501
501 on_each_cpu(do_disable_cpu_turbo, ips, 1); 502 if (ips->turbo_toggle_allowed)
503 on_each_cpu(do_disable_cpu_turbo, ips, 1);
502 504
503 ips->__cpu_turbo_on = false; 505 ips->__cpu_turbo_on = false;
504} 506}
@@ -598,17 +600,29 @@ static bool mcp_exceeded(struct ips_driver *ips)
598{ 600{
599 unsigned long flags; 601 unsigned long flags;
600 bool ret = false; 602 bool ret = false;
603 u32 temp_limit;
604 u32 avg_power;
605 const char *msg = "MCP limit exceeded: ";
601 606
602 spin_lock_irqsave(&ips->turbo_status_lock, flags); 607 spin_lock_irqsave(&ips->turbo_status_lock, flags);
603 if (ips->mcp_avg_temp > (ips->mcp_temp_limit * 100)) 608
604 ret = true; 609 temp_limit = ips->mcp_temp_limit * 100;
605 if (ips->cpu_avg_power + ips->mch_avg_power > ips->mcp_power_limit) 610 if (ips->mcp_avg_temp > temp_limit) {
611 dev_info(&ips->dev->dev,
612 "%sAvg temp %u, limit %u\n", msg, ips->mcp_avg_temp,
613 temp_limit);
606 ret = true; 614 ret = true;
607 spin_unlock_irqrestore(&ips->turbo_status_lock, flags); 615 }
608 616
609 if (ret) 617 avg_power = ips->cpu_avg_power + ips->mch_avg_power;
618 if (avg_power > ips->mcp_power_limit) {
610 dev_info(&ips->dev->dev, 619 dev_info(&ips->dev->dev,
611 "MCP power or thermal limit exceeded\n"); 620 "%sAvg power %u, limit %u\n", msg, avg_power,
621 ips->mcp_power_limit);
622 ret = true;
623 }
624
625 spin_unlock_irqrestore(&ips->turbo_status_lock, flags);
612 626
613 return ret; 627 return ret;
614} 628}
@@ -663,6 +677,27 @@ static bool mch_exceeded(struct ips_driver *ips)
663} 677}
664 678
665/** 679/**
680 * verify_limits - verify BIOS provided limits
681 * @ips: IPS structure
682 *
683 * BIOS can optionally provide non-default limits for power and temp. Check
684 * them here and use the defaults if the BIOS values are not provided or
685 * are otherwise unusable.
686 */
687static void verify_limits(struct ips_driver *ips)
688{
689 if (ips->mcp_power_limit < ips->limits->mcp_power_limit ||
690 ips->mcp_power_limit > 35000)
691 ips->mcp_power_limit = ips->limits->mcp_power_limit;
692
693 if (ips->mcp_temp_limit < ips->limits->core_temp_limit ||
694 ips->mcp_temp_limit < ips->limits->mch_temp_limit ||
695 ips->mcp_temp_limit > 150)
696 ips->mcp_temp_limit = min(ips->limits->core_temp_limit,
697 ips->limits->mch_temp_limit);
698}
699
700/**
666 * update_turbo_limits - get various limits & settings from regs 701 * update_turbo_limits - get various limits & settings from regs
667 * @ips: IPS driver struct 702 * @ips: IPS driver struct
668 * 703 *
@@ -680,12 +715,21 @@ static void update_turbo_limits(struct ips_driver *ips)
680 u32 hts = thm_readl(THM_HTS); 715 u32 hts = thm_readl(THM_HTS);
681 716
682 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS); 717 ips->cpu_turbo_enabled = !(hts & HTS_PCTD_DIS);
683 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS); 718 /*
719 * Disable turbo for now, until we can figure out why the power figures
720 * are wrong
721 */
722 ips->cpu_turbo_enabled = false;
723
724 if (ips->gpu_busy)
725 ips->gpu_turbo_enabled = !(hts & HTS_GTD_DIS);
726
684 ips->core_power_limit = thm_readw(THM_MPCPC); 727 ips->core_power_limit = thm_readw(THM_MPCPC);
685 ips->mch_power_limit = thm_readw(THM_MMGPC); 728 ips->mch_power_limit = thm_readw(THM_MMGPC);
686 ips->mcp_temp_limit = thm_readw(THM_PTL); 729 ips->mcp_temp_limit = thm_readw(THM_PTL);
687 ips->mcp_power_limit = thm_readw(THM_MPPC); 730 ips->mcp_power_limit = thm_readw(THM_MPPC);
688 731
732 verify_limits(ips);
689 /* Ignore BIOS CPU vs GPU pref */ 733 /* Ignore BIOS CPU vs GPU pref */
690} 734}
691 735
@@ -858,7 +902,7 @@ static u32 get_cpu_power(struct ips_driver *ips, u32 *last, int period)
858 ret = (ret * 1000) / 65535; 902 ret = (ret * 1000) / 65535;
859 *last = val; 903 *last = val;
860 904
861 return ret; 905 return 0;
862} 906}
863 907
864static const u16 temp_decay_factor = 2; 908static const u16 temp_decay_factor = 2;
@@ -940,7 +984,6 @@ static int ips_monitor(void *data)
940 kfree(mch_samples); 984 kfree(mch_samples);
941 kfree(cpu_samples); 985 kfree(cpu_samples);
942 kfree(mchp_samples); 986 kfree(mchp_samples);
943 kthread_stop(ips->adjust);
944 return -ENOMEM; 987 return -ENOMEM;
945 } 988 }
946 989
@@ -948,7 +991,7 @@ static int ips_monitor(void *data)
948 ITV_ME_SEQNO_SHIFT; 991 ITV_ME_SEQNO_SHIFT;
949 seqno_timestamp = get_jiffies_64(); 992 seqno_timestamp = get_jiffies_64();
950 993
951 old_cpu_power = thm_readl(THM_CEC) / 65535; 994 old_cpu_power = thm_readl(THM_CEC);
952 schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD)); 995 schedule_timeout_interruptible(msecs_to_jiffies(IPS_SAMPLE_PERIOD));
953 996
954 /* Collect an initial average */ 997 /* Collect an initial average */
@@ -1150,11 +1193,18 @@ static irqreturn_t ips_irq_handler(int irq, void *arg)
1150 STS_GPL_SHIFT; 1193 STS_GPL_SHIFT;
1151 /* ignore EC CPU vs GPU pref */ 1194 /* ignore EC CPU vs GPU pref */
1152 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS); 1195 ips->cpu_turbo_enabled = !(sts & STS_PCTD_DIS);
1153 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS); 1196 /*
1197 * Disable turbo for now, until we can figure
1198 * out why the power figures are wrong
1199 */
1200 ips->cpu_turbo_enabled = false;
1201 if (ips->gpu_busy)
1202 ips->gpu_turbo_enabled = !(sts & STS_GTD_DIS);
1154 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >> 1203 ips->mcp_temp_limit = (sts & STS_PTL_MASK) >>
1155 STS_PTL_SHIFT; 1204 STS_PTL_SHIFT;
1156 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >> 1205 ips->mcp_power_limit = (tc1 & STS_PPL_MASK) >>
1157 STS_PPL_SHIFT; 1206 STS_PPL_SHIFT;
1207 verify_limits(ips);
1158 spin_unlock(&ips->turbo_status_lock); 1208 spin_unlock(&ips->turbo_status_lock);
1159 1209
1160 thm_writeb(THM_SEC, SEC_ACK); 1210 thm_writeb(THM_SEC, SEC_ACK);
@@ -1333,8 +1383,10 @@ static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips)
1333 * turbo manually or we'll get an illegal MSR access, even though 1383 * turbo manually or we'll get an illegal MSR access, even though
1334 * turbo will still be available. 1384 * turbo will still be available.
1335 */ 1385 */
1336 if (!(misc_en & IA32_MISC_TURBO_EN)) 1386 if (misc_en & IA32_MISC_TURBO_EN)
1337 ; /* add turbo MSR write allowed flag if necessary */ 1387 ips->turbo_toggle_allowed = true;
1388 else
1389 ips->turbo_toggle_allowed = false;
1338 1390
1339 if (strstr(boot_cpu_data.x86_model_id, "CPU M")) 1391 if (strstr(boot_cpu_data.x86_model_id, "CPU M"))
1340 limits = &ips_sv_limits; 1392 limits = &ips_sv_limits;
@@ -1351,9 +1403,10 @@ static struct ips_mcp_limits *ips_detect_cpu(struct ips_driver *ips)
1351 tdp = turbo_power & TURBO_TDP_MASK; 1403 tdp = turbo_power & TURBO_TDP_MASK;
1352 1404
1353 /* Sanity check TDP against CPU */ 1405 /* Sanity check TDP against CPU */
1354 if (limits->mcp_power_limit != (tdp / 8) * 1000) { 1406 if (limits->core_power_limit != (tdp / 8) * 1000) {
1355 dev_warn(&ips->dev->dev, "Warning: CPU TDP doesn't match expected value (found %d, expected %d)\n", 1407 dev_info(&ips->dev->dev, "CPU TDP doesn't match expected value (found %d, expected %d)\n",
1356 tdp / 8, limits->mcp_power_limit / 1000); 1408 tdp / 8, limits->core_power_limit / 1000);
1409 limits->core_power_limit = (tdp / 8) * 1000;
1357 } 1410 }
1358 1411
1359out: 1412out:
@@ -1390,7 +1443,7 @@ static bool ips_get_i915_syms(struct ips_driver *ips)
1390 return true; 1443 return true;
1391 1444
1392out_put_busy: 1445out_put_busy:
1393 symbol_put(i915_gpu_turbo_disable); 1446 symbol_put(i915_gpu_busy);
1394out_put_lower: 1447out_put_lower:
1395 symbol_put(i915_gpu_lower); 1448 symbol_put(i915_gpu_lower);
1396out_put_raise: 1449out_put_raise:
@@ -1532,22 +1585,27 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
1532 /* Save turbo limits & ratios */ 1585 /* Save turbo limits & ratios */
1533 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit); 1586 rdmsrl(TURBO_POWER_CURRENT_LIMIT, ips->orig_turbo_limit);
1534 1587
1535 ips_enable_cpu_turbo(ips); 1588 ips_disable_cpu_turbo(ips);
1536 ips->cpu_turbo_enabled = true; 1589 ips->cpu_turbo_enabled = false;
1537 1590
1538 /* Set up the work queue and monitor/adjust threads */ 1591 /* Create thermal adjust thread */
1539 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor"); 1592 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust");
1540 if (IS_ERR(ips->monitor)) { 1593 if (IS_ERR(ips->adjust)) {
1541 dev_err(&dev->dev, 1594 dev_err(&dev->dev,
1542 "failed to create thermal monitor thread, aborting\n"); 1595 "failed to create thermal adjust thread, aborting\n");
1543 ret = -ENOMEM; 1596 ret = -ENOMEM;
1544 goto error_free_irq; 1597 goto error_free_irq;
1598
1545 } 1599 }
1546 1600
1547 ips->adjust = kthread_create(ips_adjust, ips, "ips-adjust"); 1601 /*
1548 if (IS_ERR(ips->adjust)) { 1602 * Set up the work queue and monitor thread. The monitor thread
1603 * will wake up ips_adjust thread.
1604 */
1605 ips->monitor = kthread_run(ips_monitor, ips, "ips-monitor");
1606 if (IS_ERR(ips->monitor)) {
1549 dev_err(&dev->dev, 1607 dev_err(&dev->dev,
1550 "failed to create thermal adjust thread, aborting\n"); 1608 "failed to create thermal monitor thread, aborting\n");
1551 ret = -ENOMEM; 1609 ret = -ENOMEM;
1552 goto error_thread_cleanup; 1610 goto error_thread_cleanup;
1553 } 1611 }
@@ -1566,7 +1624,7 @@ static int ips_probe(struct pci_dev *dev, const struct pci_device_id *id)
1566 return ret; 1624 return ret;
1567 1625
1568error_thread_cleanup: 1626error_thread_cleanup:
1569 kthread_stop(ips->monitor); 1627 kthread_stop(ips->adjust);
1570error_free_irq: 1628error_free_irq:
1571 free_irq(ips->dev->irq, ips); 1629 free_irq(ips->dev->irq, ips);
1572error_unmap: 1630error_unmap:
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index e35ed128bdef..2d61186ad5a2 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -3093,7 +3093,8 @@ static const struct tpacpi_quirk tpacpi_hotkey_qtable[] __initconst = {
3093 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */ 3093 TPACPI_Q_IBM('1', 'D', TPACPI_HK_Q_INIMASK), /* X22, X23, X24 */
3094}; 3094};
3095 3095
3096typedef u16 tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN]; 3096typedef u16 tpacpi_keymap_entry_t;
3097typedef tpacpi_keymap_entry_t tpacpi_keymap_t[TPACPI_HOTKEY_MAP_LEN];
3097 3098
3098static int __init hotkey_init(struct ibm_init_struct *iibm) 3099static int __init hotkey_init(struct ibm_init_struct *iibm)
3099{ 3100{
@@ -3230,7 +3231,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
3230 }; 3231 };
3231 3232
3232#define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t) 3233#define TPACPI_HOTKEY_MAP_SIZE sizeof(tpacpi_keymap_t)
3233#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_t[0]) 3234#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(tpacpi_keymap_entry_t)
3234 3235
3235 int res, i; 3236 int res, i;
3236 int status; 3237 int status;
diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c
index 3f94edab25fa..e73ebefdf3e0 100644
--- a/drivers/pnp/isapnp/proc.c
+++ b/drivers/pnp/isapnp/proc.c
@@ -31,8 +31,9 @@ static struct proc_dir_entry *isapnp_proc_bus_dir = NULL;
31static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence) 31static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
32{ 32{
33 loff_t new = -1; 33 loff_t new = -1;
34 struct inode *inode = file->f_path.dentry->d_inode;
34 35
35 lock_kernel(); 36 mutex_lock(&inode->i_mutex);
36 switch (whence) { 37 switch (whence) {
37 case 0: 38 case 0:
38 new = off; 39 new = off;
@@ -44,12 +45,12 @@ static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
44 new = 256 + off; 45 new = 256 + off;
45 break; 46 break;
46 } 47 }
47 if (new < 0 || new > 256) { 48 if (new < 0 || new > 256)
48 unlock_kernel(); 49 new = -EINVAL;
49 return -EINVAL; 50 else
50 } 51 file->f_pos = new;
51 unlock_kernel(); 52 mutex_unlock(&inode->i_mutex);
52 return (file->f_pos = new); 53 return new;
53} 54}
54 55
55static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf, 56static ssize_t isapnp_proc_bus_read(struct file *file, char __user * buf,
diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index 936bae560fa1..dc628cb2e762 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -233,6 +233,7 @@ static int calculate_capacity(enum apm_source source)
233 empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN; 233 empty_design_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN;
234 now_prop = POWER_SUPPLY_PROP_ENERGY_NOW; 234 now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
235 avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG; 235 avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
236 break;
236 case SOURCE_VOLTAGE: 237 case SOURCE_VOLTAGE:
237 full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX; 238 full_prop = POWER_SUPPLY_PROP_VOLTAGE_MAX;
238 empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN; 239 empty_prop = POWER_SUPPLY_PROP_VOLTAGE_MIN;
diff --git a/drivers/power/intel_mid_battery.c b/drivers/power/intel_mid_battery.c
index c61ffec2ff10..2a10cd361181 100644
--- a/drivers/power/intel_mid_battery.c
+++ b/drivers/power/intel_mid_battery.c
@@ -185,8 +185,8 @@ static int pmic_scu_ipc_battery_property_get(struct battery_property *prop)
185{ 185{
186 u32 data[3]; 186 u32 data[3];
187 u8 *p = (u8 *)&data[1]; 187 u8 *p = (u8 *)&data[1];
188 int err = intel_scu_ipc_command(IPC_CMD_BATTERY_PROPERTY, 188 int err = intel_scu_ipc_command(IPCMSG_BATTERY,
189 IPCMSG_BATTERY, NULL, 0, data, 3); 189 IPC_CMD_BATTERY_PROPERTY, NULL, 0, data, 3);
190 190
191 prop->capacity = data[0]; 191 prop->capacity = data[0];
192 prop->crnt = *p++; 192 prop->crnt = *p++;
@@ -207,7 +207,7 @@ static int pmic_scu_ipc_battery_property_get(struct battery_property *prop)
207 207
208static int pmic_scu_ipc_set_charger(int charger) 208static int pmic_scu_ipc_set_charger(int charger)
209{ 209{
210 return intel_scu_ipc_simple_command(charger, IPCMSG_BATTERY); 210 return intel_scu_ipc_simple_command(IPCMSG_BATTERY, charger);
211} 211}
212 212
213/** 213/**
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 7d149a8d8d9b..2ce2eb71d0f5 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -215,7 +215,7 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index)
215 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); 215 struct pm8607_regulator_info *info = rdev_get_drvdata(rdev);
216 int ret = -EINVAL; 216 int ret = -EINVAL;
217 217
218 if (info->vol_table && (index < (2 << info->vol_nbits))) { 218 if (info->vol_table && (index < (1 << info->vol_nbits))) {
219 ret = info->vol_table[index]; 219 ret = info->vol_table[index];
220 if (info->slope_double) 220 if (info->slope_double)
221 ret <<= 1; 221 ret <<= 1;
@@ -233,7 +233,7 @@ static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV)
233 max_uV = max_uV >> 1; 233 max_uV = max_uV >> 1;
234 } 234 }
235 if (info->vol_table) { 235 if (info->vol_table) {
236 for (i = 0; i < (2 << info->vol_nbits); i++) { 236 for (i = 0; i < (1 << info->vol_nbits); i++) {
237 if (!info->vol_table[i]) 237 if (!info->vol_table[i])
238 break; 238 break;
239 if ((min_uV <= info->vol_table[i]) 239 if ((min_uV <= info->vol_table[i])
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c
index 11790990277a..b349266a43de 100644
--- a/drivers/regulator/ab3100.c
+++ b/drivers/regulator/ab3100.c
@@ -634,12 +634,9 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev)
634 "%s: failed to register regulator %s err %d\n", 634 "%s: failed to register regulator %s err %d\n",
635 __func__, ab3100_regulator_desc[i].name, 635 __func__, ab3100_regulator_desc[i].name,
636 err); 636 err);
637 i--;
638 /* remove the already registered regulators */ 637 /* remove the already registered regulators */
639 while (i > 0) { 638 while (--i >= 0)
640 regulator_unregister(ab3100_regulators[i].rdev); 639 regulator_unregister(ab3100_regulators[i].rdev);
641 i--;
642 }
643 return err; 640 return err;
644 } 641 }
645 642
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index dc3f1a491675..28c7ae67cec9 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -157,7 +157,7 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
157 if (info->fixed_uV) 157 if (info->fixed_uV)
158 return info->fixed_uV; 158 return info->fixed_uV;
159 159
160 if (selector > info->voltages_len) 160 if (selector >= info->voltages_len)
161 return -EINVAL; 161 return -EINVAL;
162 162
163 return info->supported_voltages[selector]; 163 return info->supported_voltages[selector];
@@ -344,13 +344,14 @@ static inline struct ab8500_regulator_info *find_regulator_info(int id)
344static __devinit int ab8500_regulator_probe(struct platform_device *pdev) 344static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
345{ 345{
346 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); 346 struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
347 struct ab8500_platform_data *pdata = dev_get_platdata(ab8500->dev); 347 struct ab8500_platform_data *pdata;
348 int i, err; 348 int i, err;
349 349
350 if (!ab8500) { 350 if (!ab8500) {
351 dev_err(&pdev->dev, "null mfd parent\n"); 351 dev_err(&pdev->dev, "null mfd parent\n");
352 return -EINVAL; 352 return -EINVAL;
353 } 353 }
354 pdata = dev_get_platdata(ab8500->dev);
354 355
355 /* register all regulators */ 356 /* register all regulators */
356 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { 357 for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
@@ -368,11 +369,9 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
368 dev_err(&pdev->dev, "failed to register regulator %s\n", 369 dev_err(&pdev->dev, "failed to register regulator %s\n",
369 info->desc.name); 370 info->desc.name);
370 /* when we fail, un-register all earlier regulators */ 371 /* when we fail, un-register all earlier regulators */
371 i--; 372 while (--i >= 0) {
372 while (i > 0) {
373 info = &ab8500_regulator_info[i]; 373 info = &ab8500_regulator_info[i];
374 regulator_unregister(info->regulator); 374 regulator_unregister(info->regulator);
375 i--;
376 } 375 }
377 return err; 376 return err;
378 } 377 }
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c
index d59d2f2314af..a4be41614eeb 100644
--- a/drivers/regulator/ad5398.c
+++ b/drivers/regulator/ad5398.c
@@ -25,7 +25,7 @@ struct ad5398_chip_info {
25 unsigned int current_level; 25 unsigned int current_level;
26 unsigned int current_mask; 26 unsigned int current_mask;
27 unsigned int current_offset; 27 unsigned int current_offset;
28 struct regulator_dev rdev; 28 struct regulator_dev *rdev;
29}; 29};
30 30
31static int ad5398_calc_current(struct ad5398_chip_info *chip, 31static int ad5398_calc_current(struct ad5398_chip_info *chip,
@@ -211,7 +211,6 @@ MODULE_DEVICE_TABLE(i2c, ad5398_id);
211static int __devinit ad5398_probe(struct i2c_client *client, 211static int __devinit ad5398_probe(struct i2c_client *client,
212 const struct i2c_device_id *id) 212 const struct i2c_device_id *id)
213{ 213{
214 struct regulator_dev *rdev;
215 struct regulator_init_data *init_data = client->dev.platform_data; 214 struct regulator_init_data *init_data = client->dev.platform_data;
216 struct ad5398_chip_info *chip; 215 struct ad5398_chip_info *chip;
217 const struct ad5398_current_data_format *df = 216 const struct ad5398_current_data_format *df =
@@ -233,9 +232,10 @@ static int __devinit ad5398_probe(struct i2c_client *client,
233 chip->current_offset = df->current_offset; 232 chip->current_offset = df->current_offset;
234 chip->current_mask = (chip->current_level - 1) << chip->current_offset; 233 chip->current_mask = (chip->current_level - 1) << chip->current_offset;
235 234
236 rdev = regulator_register(&ad5398_reg, &client->dev, init_data, chip); 235 chip->rdev = regulator_register(&ad5398_reg, &client->dev,
237 if (IS_ERR(rdev)) { 236 init_data, chip);
238 ret = PTR_ERR(rdev); 237 if (IS_ERR(chip->rdev)) {
238 ret = PTR_ERR(chip->rdev);
239 dev_err(&client->dev, "failed to register %s %s\n", 239 dev_err(&client->dev, "failed to register %s %s\n",
240 id->name, ad5398_reg.name); 240 id->name, ad5398_reg.name);
241 goto err; 241 goto err;
@@ -254,9 +254,8 @@ static int __devexit ad5398_remove(struct i2c_client *client)
254{ 254{
255 struct ad5398_chip_info *chip = i2c_get_clientdata(client); 255 struct ad5398_chip_info *chip = i2c_get_clientdata(client);
256 256
257 regulator_unregister(&chip->rdev); 257 regulator_unregister(chip->rdev);
258 kfree(chip); 258 kfree(chip);
259 i2c_set_clientdata(client, NULL);
260 259
261 return 0; 260 return 0;
262} 261}
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 422a709d271d..cc8b337b9119 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -700,7 +700,7 @@ static void print_constraints(struct regulator_dev *rdev)
700 constraints->min_uA != constraints->max_uA) { 700 constraints->min_uA != constraints->max_uA) {
701 ret = _regulator_get_current_limit(rdev); 701 ret = _regulator_get_current_limit(rdev);
702 if (ret > 0) 702 if (ret > 0)
703 count += sprintf(buf + count, "at %d uA ", ret / 1000); 703 count += sprintf(buf + count, "at %d mA ", ret / 1000);
704 } 704 }
705 705
706 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST) 706 if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
@@ -2302,8 +2302,10 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2302 dev_set_name(&rdev->dev, "regulator.%d", 2302 dev_set_name(&rdev->dev, "regulator.%d",
2303 atomic_inc_return(&regulator_no) - 1); 2303 atomic_inc_return(&regulator_no) - 1);
2304 ret = device_register(&rdev->dev); 2304 ret = device_register(&rdev->dev);
2305 if (ret != 0) 2305 if (ret != 0) {
2306 put_device(&rdev->dev);
2306 goto clean; 2307 goto clean;
2308 }
2307 2309
2308 dev_set_drvdata(&rdev->dev, rdev); 2310 dev_set_drvdata(&rdev->dev, rdev);
2309 2311
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c
index e49d2bd393f2..b8cc6389a541 100644
--- a/drivers/regulator/isl6271a-regulator.c
+++ b/drivers/regulator/isl6271a-regulator.c
@@ -165,7 +165,7 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c,
165 mutex_init(&pmic->mtx); 165 mutex_init(&pmic->mtx);
166 166
167 for (i = 0; i < 3; i++) { 167 for (i = 0; i < 3; i++) {
168 pmic->rdev[i] = regulator_register(&isl_rd[0], &i2c->dev, 168 pmic->rdev[i] = regulator_register(&isl_rd[i], &i2c->dev,
169 init_data, pmic); 169 init_data, pmic);
170 if (IS_ERR(pmic->rdev[i])) { 170 if (IS_ERR(pmic->rdev[i])) {
171 dev_err(&i2c->dev, "failed to register %s\n", id->name); 171 dev_err(&i2c->dev, "failed to register %s\n", id->name);
@@ -191,8 +191,6 @@ static int __devexit isl6271a_remove(struct i2c_client *i2c)
191 struct isl_pmic *pmic = i2c_get_clientdata(i2c); 191 struct isl_pmic *pmic = i2c_get_clientdata(i2c);
192 int i; 192 int i;
193 193
194 i2c_set_clientdata(i2c, NULL);
195
196 for (i = 0; i < 3; i++) 194 for (i = 0; i < 3; i++)
197 regulator_unregister(pmic->rdev[i]); 195 regulator_unregister(pmic->rdev[i]);
198 196
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 8867c2710a6d..559cfa271a44 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -121,14 +121,14 @@ static int max1586_v6_set(struct regulator_dev *rdev, int min_uV, int max_uV)
121 if (max_uV < MAX1586_V6_MIN_UV || max_uV > MAX1586_V6_MAX_UV) 121 if (max_uV < MAX1586_V6_MIN_UV || max_uV > MAX1586_V6_MAX_UV)
122 return -EINVAL; 122 return -EINVAL;
123 123
124 if (min_uV >= 3000000)
125 selector = 3;
126 if (min_uV < 3000000)
127 selector = 2;
128 if (min_uV < 2500000)
129 selector = 1;
130 if (min_uV < 1800000) 124 if (min_uV < 1800000)
131 selector = 0; 125 selector = 0;
126 else if (min_uV < 2500000)
127 selector = 1;
128 else if (min_uV < 3000000)
129 selector = 2;
130 else if (min_uV >= 3000000)
131 selector = 3;
132 132
133 if (max1586_v6_calc_voltage(selector) > max_uV) 133 if (max1586_v6_calc_voltage(selector) > max_uV)
134 return -EINVAL; 134 return -EINVAL;
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c
index 4520ace3f7e7..6b60a9c0366b 100644
--- a/drivers/regulator/max8649.c
+++ b/drivers/regulator/max8649.c
@@ -330,7 +330,7 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client,
330 /* set external clock frequency */ 330 /* set external clock frequency */
331 info->extclk_freq = pdata->extclk_freq; 331 info->extclk_freq = pdata->extclk_freq;
332 max8649_set_bits(info->i2c, MAX8649_SYNC, MAX8649_EXT_MASK, 332 max8649_set_bits(info->i2c, MAX8649_SYNC, MAX8649_EXT_MASK,
333 info->extclk_freq); 333 info->extclk_freq << 6);
334 } 334 }
335 335
336 if (pdata->ramp_timing) { 336 if (pdata->ramp_timing) {
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index ab67298799f9..a1baf1fbe004 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -549,7 +549,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
549 if (!max8998) 549 if (!max8998)
550 return -ENOMEM; 550 return -ENOMEM;
551 551
552 size = sizeof(struct regulator_dev *) * (pdata->num_regulators + 1); 552 size = sizeof(struct regulator_dev *) * pdata->num_regulators;
553 max8998->rdev = kzalloc(size, GFP_KERNEL); 553 max8998->rdev = kzalloc(size, GFP_KERNEL);
554 if (!max8998->rdev) { 554 if (!max8998->rdev) {
555 kfree(max8998); 555 kfree(max8998);
@@ -557,7 +557,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
557 } 557 }
558 558
559 rdev = max8998->rdev; 559 rdev = max8998->rdev;
560 max8998->dev = &pdev->dev;
560 max8998->iodev = iodev; 561 max8998->iodev = iodev;
562 max8998->num_regulators = pdata->num_regulators;
561 platform_set_drvdata(pdev, max8998); 563 platform_set_drvdata(pdev, max8998);
562 564
563 for (i = 0; i < pdata->num_regulators; i++) { 565 for (i = 0; i < pdata->num_regulators; i++) {
@@ -583,7 +585,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev)
583 585
584 return 0; 586 return 0;
585err: 587err:
586 for (i = 0; i <= max8998->num_regulators; i++) 588 for (i = 0; i < max8998->num_regulators; i++)
587 if (rdev[i]) 589 if (rdev[i])
588 regulator_unregister(rdev[i]); 590 regulator_unregister(rdev[i]);
589 591
@@ -599,7 +601,7 @@ static int __devexit max8998_pmic_remove(struct platform_device *pdev)
599 struct regulator_dev **rdev = max8998->rdev; 601 struct regulator_dev **rdev = max8998->rdev;
600 int i; 602 int i;
601 603
602 for (i = 0; i <= max8998->num_regulators; i++) 604 for (i = 0; i < max8998->num_regulators; i++)
603 if (rdev[i]) 605 if (rdev[i])
604 regulator_unregister(rdev[i]); 606 regulator_unregister(rdev[i]);
605 607
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c
index c239f42aa4a3..020f5878d7ff 100644
--- a/drivers/regulator/tps6507x-regulator.c
+++ b/drivers/regulator/tps6507x-regulator.c
@@ -626,12 +626,6 @@ fail:
626 return error; 626 return error;
627} 627}
628 628
629/**
630 * tps6507x_remove - TPS6507x driver i2c remove handler
631 * @client: i2c driver client device structure
632 *
633 * Unregister TPS driver as an i2c client device driver
634 */
635static int __devexit tps6507x_pmic_remove(struct platform_device *pdev) 629static int __devexit tps6507x_pmic_remove(struct platform_device *pdev)
636{ 630{
637 struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev); 631 struct tps6507x_dev *tps6507x_dev = platform_get_drvdata(pdev);
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index 8cff1413a147..51237fbb1bbb 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -133,7 +133,7 @@ static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev)
133 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; 133 mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift;
134 val = (val & mask) >> ri->volt_shift; 134 val = (val & mask) >> ri->volt_shift;
135 135
136 if (val > ri->desc.n_voltages) 136 if (val >= ri->desc.n_voltages)
137 BUG(); 137 BUG();
138 138
139 return ri->voltages[val] * 1000; 139 return ri->voltages[val] * 1000;
@@ -150,7 +150,7 @@ static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev,
150 if (ret) 150 if (ret)
151 return ret; 151 return ret;
152 152
153 return tps6586x_set_bits(parent, ri->go_reg, ri->go_bit); 153 return tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit);
154} 154}
155 155
156static int tps6586x_regulator_enable(struct regulator_dev *rdev) 156static int tps6586x_regulator_enable(struct regulator_dev *rdev)
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c
index e686cdb61b97..9edf8f692341 100644
--- a/drivers/regulator/wm831x-ldo.c
+++ b/drivers/regulator/wm831x-ldo.c
@@ -215,8 +215,7 @@ static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
215 215
216 case REGULATOR_MODE_IDLE: 216 case REGULATOR_MODE_IDLE:
217 ret = wm831x_set_bits(wm831x, ctrl_reg, 217 ret = wm831x_set_bits(wm831x, ctrl_reg,
218 WM831X_LDO1_LP_MODE, 218 WM831X_LDO1_LP_MODE, 0);
219 WM831X_LDO1_LP_MODE);
220 if (ret < 0) 219 if (ret < 0)
221 return ret; 220 return ret;
222 221
@@ -225,10 +224,12 @@ static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev,
225 WM831X_LDO1_ON_MODE); 224 WM831X_LDO1_ON_MODE);
226 if (ret < 0) 225 if (ret < 0)
227 return ret; 226 return ret;
227 break;
228 228
229 case REGULATOR_MODE_STANDBY: 229 case REGULATOR_MODE_STANDBY:
230 ret = wm831x_set_bits(wm831x, ctrl_reg, 230 ret = wm831x_set_bits(wm831x, ctrl_reg,
231 WM831X_LDO1_LP_MODE, 0); 231 WM831X_LDO1_LP_MODE,
232 WM831X_LDO1_LP_MODE);
232 if (ret < 0) 233 if (ret < 0)
233 return ret; 234 return ret;
234 235
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index 0e6ed7db9364..fe4b8a8a9dfd 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -1129,7 +1129,7 @@ static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev)
1129 mode = REGULATOR_MODE_NORMAL; 1129 mode = REGULATOR_MODE_NORMAL;
1130 } else if (!active && !sleep) 1130 } else if (!active && !sleep)
1131 mode = REGULATOR_MODE_IDLE; 1131 mode = REGULATOR_MODE_IDLE;
1132 else if (!sleep) 1132 else if (sleep)
1133 mode = REGULATOR_MODE_STANDBY; 1133 mode = REGULATOR_MODE_STANDBY;
1134 1134
1135 return mode; 1135 return mode;
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index d26780ea254b..261a07e0fb24 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -235,6 +235,7 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
235 err = PTR_ERR(rtc); 235 err = PTR_ERR(rtc);
236 return err; 236 return err;
237 } 237 }
238 platform_set_drvdata(pdev, rtc);
238 239
239 return 0; 240 return 0;
240} 241}
@@ -244,6 +245,7 @@ static int __exit ab3100_rtc_remove(struct platform_device *pdev)
244 struct rtc_device *rtc = platform_get_drvdata(pdev); 245 struct rtc_device *rtc = platform_get_drvdata(pdev);
245 246
246 rtc_device_unregister(rtc); 247 rtc_device_unregister(rtc);
248 platform_set_drvdata(pdev, NULL);
247 return 0; 249 return 0;
248} 250}
249 251
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index 9daed8db83d3..9de8516e3531 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -268,7 +268,6 @@ out_irq:
268 free_irq(client->irq, client); 268 free_irq(client->irq, client);
269 269
270out_free: 270out_free:
271 i2c_set_clientdata(client, NULL);
272 kfree(ds3232); 271 kfree(ds3232);
273 return ret; 272 return ret;
274} 273}
@@ -287,7 +286,6 @@ static int __devexit ds3232_remove(struct i2c_client *client)
287 } 286 }
288 287
289 rtc_device_unregister(ds3232->rtc); 288 rtc_device_unregister(ds3232->rtc);
290 i2c_set_clientdata(client, NULL);
291 kfree(ds3232); 289 kfree(ds3232);
292 return 0; 290 return 0;
293} 291}
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index ef151ce04430..5a8daa358066 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -20,7 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/rtc.h> 21#include <linux/rtc.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/smp_lock.h> 23#include <linux/mutex.h>
24#include <linux/string.h> 24#include <linux/string.h>
25#ifdef CONFIG_RTC_DRV_M41T80_WDT 25#ifdef CONFIG_RTC_DRV_M41T80_WDT
26#include <linux/fs.h> 26#include <linux/fs.h>
@@ -68,6 +68,7 @@
68 68
69#define DRV_VERSION "0.05" 69#define DRV_VERSION "0.05"
70 70
71static DEFINE_MUTEX(m41t80_rtc_mutex);
71static const struct i2c_device_id m41t80_id[] = { 72static const struct i2c_device_id m41t80_id[] = {
72 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, 73 { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT },
73 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, 74 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD },
@@ -677,9 +678,9 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,
677{ 678{
678 int ret; 679 int ret;
679 680
680 lock_kernel(); 681 mutex_lock(&m41t80_rtc_mutex);
681 ret = wdt_ioctl(file, cmd, arg); 682 ret = wdt_ioctl(file, cmd, arg);
682 unlock_kernel(); 683 mutex_unlock(&m41t80_rtc_mutex);
683 684
684 return ret; 685 return ret;
685} 686}
@@ -693,16 +694,16 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd,
693static int wdt_open(struct inode *inode, struct file *file) 694static int wdt_open(struct inode *inode, struct file *file)
694{ 695{
695 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { 696 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
696 lock_kernel(); 697 mutex_lock(&m41t80_rtc_mutex);
697 if (test_and_set_bit(0, &wdt_is_open)) { 698 if (test_and_set_bit(0, &wdt_is_open)) {
698 unlock_kernel(); 699 mutex_unlock(&m41t80_rtc_mutex);
699 return -EBUSY; 700 return -EBUSY;
700 } 701 }
701 /* 702 /*
702 * Activate 703 * Activate
703 */ 704 */
704 wdt_is_open = 1; 705 wdt_is_open = 1;
705 unlock_kernel(); 706 mutex_unlock(&m41t80_rtc_mutex);
706 return nonseekable_open(inode, file); 707 return nonseekable_open(inode, file);
707 } 708 }
708 return -ENODEV; 709 return -ENODEV;
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index a0d3ec89d412..f57a87f4ae96 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -310,11 +310,6 @@ static int s3c_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
310 310
311 s3c_rtc_setaie(alrm->enabled); 311 s3c_rtc_setaie(alrm->enabled);
312 312
313 if (alrm->enabled)
314 enable_irq_wake(s3c_rtc_alarmno);
315 else
316 disable_irq_wake(s3c_rtc_alarmno);
317
318 return 0; 313 return 0;
319} 314}
320 315
@@ -587,6 +582,10 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
587 ticnt_en_save &= S3C64XX_RTCCON_TICEN; 582 ticnt_en_save &= S3C64XX_RTCCON_TICEN;
588 } 583 }
589 s3c_rtc_enable(pdev, 0); 584 s3c_rtc_enable(pdev, 0);
585
586 if (device_may_wakeup(&pdev->dev))
587 enable_irq_wake(s3c_rtc_alarmno);
588
590 return 0; 589 return 0;
591} 590}
592 591
@@ -600,6 +599,10 @@ static int s3c_rtc_resume(struct platform_device *pdev)
600 tmp = readb(s3c_rtc_base + S3C2410_RTCCON); 599 tmp = readb(s3c_rtc_base + S3C2410_RTCCON);
601 writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 600 writeb(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
602 } 601 }
602
603 if (device_may_wakeup(&pdev->dev))
604 disable_irq_wake(s3c_rtc_alarmno);
605
603 return 0; 606 return 0;
604} 607}
605#else 608#else
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 8373ca0de8e0..38e6fa9a2012 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -21,7 +21,6 @@
21#include <linux/hdreg.h> 21#include <linux/hdreg.h>
22#include <linux/async.h> 22#include <linux/async.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/smp_lock.h>
25 24
26#include <asm/ccwdev.h> 25#include <asm/ccwdev.h>
27#include <asm/ebcdic.h> 26#include <asm/ebcdic.h>
@@ -2236,7 +2235,6 @@ static int dasd_open(struct block_device *bdev, fmode_t mode)
2236 if (!block) 2235 if (!block)
2237 return -ENODEV; 2236 return -ENODEV;
2238 2237
2239 lock_kernel();
2240 base = block->base; 2238 base = block->base;
2241 atomic_inc(&block->open_count); 2239 atomic_inc(&block->open_count);
2242 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) { 2240 if (test_bit(DASD_FLAG_OFFLINE, &base->flags)) {
@@ -2271,14 +2269,12 @@ static int dasd_open(struct block_device *bdev, fmode_t mode)
2271 goto out; 2269 goto out;
2272 } 2270 }
2273 2271
2274 unlock_kernel();
2275 return 0; 2272 return 0;
2276 2273
2277out: 2274out:
2278 module_put(base->discipline->owner); 2275 module_put(base->discipline->owner);
2279unlock: 2276unlock:
2280 atomic_dec(&block->open_count); 2277 atomic_dec(&block->open_count);
2281 unlock_kernel();
2282 return rc; 2278 return rc;
2283} 2279}
2284 2280
@@ -2286,10 +2282,8 @@ static int dasd_release(struct gendisk *disk, fmode_t mode)
2286{ 2282{
2287 struct dasd_block *block = disk->private_data; 2283 struct dasd_block *block = disk->private_data;
2288 2284
2289 lock_kernel();
2290 atomic_dec(&block->open_count); 2285 atomic_dec(&block->open_count);
2291 module_put(block->base->discipline->owner); 2286 module_put(block->base->discipline->owner);
2292 unlock_kernel();
2293 return 0; 2287 return 0;
2294} 2288}
2295 2289
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 1557214944f7..26075e95b1ba 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -16,7 +16,6 @@
16#include <linux/major.h> 16#include <linux/major.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/blkpg.h> 18#include <linux/blkpg.h>
19#include <linux/smp_lock.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <asm/compat.h> 20#include <asm/compat.h>
22#include <asm/ccwdev.h> 21#include <asm/ccwdev.h>
@@ -370,9 +369,8 @@ static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
370 return ret; 369 return ret;
371} 370}
372 371
373static int 372int dasd_ioctl(struct block_device *bdev, fmode_t mode,
374dasd_do_ioctl(struct block_device *bdev, fmode_t mode, 373 unsigned int cmd, unsigned long arg)
375 unsigned int cmd, unsigned long arg)
376{ 374{
377 struct dasd_block *block = bdev->bd_disk->private_data; 375 struct dasd_block *block = bdev->bd_disk->private_data;
378 void __user *argp; 376 void __user *argp;
@@ -430,14 +428,3 @@ dasd_do_ioctl(struct block_device *bdev, fmode_t mode,
430 return -EINVAL; 428 return -EINVAL;
431 } 429 }
432} 430}
433
434int dasd_ioctl(struct block_device *bdev, fmode_t mode,
435 unsigned int cmd, unsigned long arg)
436{
437 int rc;
438
439 lock_kernel();
440 rc = dasd_do_ioctl(bdev, mode, cmd, arg);
441 unlock_kernel();
442 return rc;
443}
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 2bd72aa34c59..9b43ae94beba 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -14,7 +14,6 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/smp_lock.h>
18#include <linux/completion.h> 17#include <linux/completion.h>
19#include <linux/interrupt.h> 18#include <linux/interrupt.h>
20#include <linux/platform_device.h> 19#include <linux/platform_device.h>
@@ -776,7 +775,6 @@ dcssblk_open(struct block_device *bdev, fmode_t mode)
776 struct dcssblk_dev_info *dev_info; 775 struct dcssblk_dev_info *dev_info;
777 int rc; 776 int rc;
778 777
779 lock_kernel();
780 dev_info = bdev->bd_disk->private_data; 778 dev_info = bdev->bd_disk->private_data;
781 if (NULL == dev_info) { 779 if (NULL == dev_info) {
782 rc = -ENODEV; 780 rc = -ENODEV;
@@ -786,7 +784,6 @@ dcssblk_open(struct block_device *bdev, fmode_t mode)
786 bdev->bd_block_size = 4096; 784 bdev->bd_block_size = 4096;
787 rc = 0; 785 rc = 0;
788out: 786out:
789 unlock_kernel();
790 return rc; 787 return rc;
791} 788}
792 789
@@ -797,7 +794,6 @@ dcssblk_release(struct gendisk *disk, fmode_t mode)
797 struct segment_info *entry; 794 struct segment_info *entry;
798 int rc; 795 int rc;
799 796
800 lock_kernel();
801 if (!dev_info) { 797 if (!dev_info) {
802 rc = -ENODEV; 798 rc = -ENODEV;
803 goto out; 799 goto out;
@@ -815,7 +811,6 @@ dcssblk_release(struct gendisk *disk, fmode_t mode)
815 up_write(&dcssblk_devices_sem); 811 up_write(&dcssblk_devices_sem);
816 rc = 0; 812 rc = 0;
817out: 813out:
818 unlock_kernel();
819 return rc; 814 return rc;
820} 815}
821 816
diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index f6d72e1f2a38..5707a80b96b6 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -468,7 +468,7 @@ sclp_sync_wait(void)
468 cr0_sync &= 0xffff00a0; 468 cr0_sync &= 0xffff00a0;
469 cr0_sync |= 0x00000200; 469 cr0_sync |= 0x00000200;
470 __ctl_load(cr0_sync, 0, 0); 470 __ctl_load(cr0_sync, 0, 0);
471 __raw_local_irq_stosm(0x01); 471 __arch_local_irq_stosm(0x01);
472 /* Loop until driver state indicates finished request */ 472 /* Loop until driver state indicates finished request */
473 while (sclp_running_state != sclp_running_state_idle) { 473 while (sclp_running_state != sclp_running_state_idle) {
474 /* Check for expired request timer */ 474 /* Check for expired request timer */
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index 85cf607fc78f..f0fa9ca5cb2c 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -16,7 +16,7 @@
16#include <linux/fs.h> 16#include <linux/fs.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/blkdev.h> 18#include <linux/blkdev.h>
19#include <linux/smp_lock.h> 19#include <linux/mutex.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/buffer_head.h> 21#include <linux/buffer_head.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
@@ -45,6 +45,7 @@
45/* 45/*
46 * file operation structure for tape block frontend 46 * file operation structure for tape block frontend
47 */ 47 */
48static DEFINE_MUTEX(tape_block_mutex);
48static int tapeblock_open(struct block_device *, fmode_t); 49static int tapeblock_open(struct block_device *, fmode_t);
49static int tapeblock_release(struct gendisk *, fmode_t); 50static int tapeblock_release(struct gendisk *, fmode_t);
50static int tapeblock_medium_changed(struct gendisk *); 51static int tapeblock_medium_changed(struct gendisk *);
@@ -361,7 +362,7 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
361 struct tape_device * device; 362 struct tape_device * device;
362 int rc; 363 int rc;
363 364
364 lock_kernel(); 365 mutex_lock(&tape_block_mutex);
365 device = tape_get_device(disk->private_data); 366 device = tape_get_device(disk->private_data);
366 367
367 if (device->required_tapemarks) { 368 if (device->required_tapemarks) {
@@ -385,14 +386,14 @@ tapeblock_open(struct block_device *bdev, fmode_t mode)
385 * is called. 386 * is called.
386 */ 387 */
387 tape_state_set(device, TS_BLKUSE); 388 tape_state_set(device, TS_BLKUSE);
388 unlock_kernel(); 389 mutex_unlock(&tape_block_mutex);
389 return 0; 390 return 0;
390 391
391release: 392release:
392 tape_release(device); 393 tape_release(device);
393 put_device: 394 put_device:
394 tape_put_device(device); 395 tape_put_device(device);
395 unlock_kernel(); 396 mutex_unlock(&tape_block_mutex);
396 return rc; 397 return rc;
397} 398}
398 399
@@ -407,11 +408,11 @@ tapeblock_release(struct gendisk *disk, fmode_t mode)
407{ 408{
408 struct tape_device *device = disk->private_data; 409 struct tape_device *device = disk->private_data;
409 410
410 lock_kernel(); 411 mutex_lock(&tape_block_mutex);
411 tape_state_set(device, TS_IN_USE); 412 tape_state_set(device, TS_IN_USE);
412 tape_release(device); 413 tape_release(device);
413 tape_put_device(device); 414 tape_put_device(device);
414 unlock_kernel(); 415 mutex_unlock(&tape_block_mutex);
415 416
416 return 0; 417 return 0;
417} 418}
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
index 6edf20b62de5..2c7d2d9be4d0 100644
--- a/drivers/s390/net/ctcm_main.c
+++ b/drivers/s390/net/ctcm_main.c
@@ -1154,7 +1154,7 @@ static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1154 dev_fsm, dev_fsm_len, GFP_KERNEL); 1154 dev_fsm, dev_fsm_len, GFP_KERNEL);
1155 if (priv->fsm == NULL) { 1155 if (priv->fsm == NULL) {
1156 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error"); 1156 CTCMY_DBF_DEV(SETUP, dev, "init_fsm error");
1157 kfree(dev); 1157 free_netdev(dev);
1158 return NULL; 1158 return NULL;
1159 } 1159 }
1160 fsm_newstate(priv->fsm, DEV_STATE_STOPPED); 1160 fsm_newstate(priv->fsm, DEV_STATE_STOPPED);
@@ -1165,7 +1165,7 @@ static struct net_device *ctcm_init_netdevice(struct ctcm_priv *priv)
1165 grp = ctcmpc_init_mpc_group(priv); 1165 grp = ctcmpc_init_mpc_group(priv);
1166 if (grp == NULL) { 1166 if (grp == NULL) {
1167 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error"); 1167 MPC_DBF_DEV(SETUP, dev, "init_mpc_group error");
1168 kfree(dev); 1168 free_netdev(dev);
1169 return NULL; 1169 return NULL;
1170 } 1170 }
1171 tasklet_init(&grp->mpc_tasklet2, 1171 tasklet_init(&grp->mpc_tasklet2,
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 4942050dc5b6..13f48e28a1e1 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -27,7 +27,7 @@
27 */ 27 */
28 28
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/smp_lock.h> 30#include <linux/mutex.h>
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/miscdevice.h> 33#include <linux/miscdevice.h>
@@ -68,6 +68,8 @@
68#define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */ 68#define JSF_PART_BITS 2 /* 2 bits of minors to cover JSF_NPART */
69#define JSF_PART_MASK 0x3 /* 2 bits mask */ 69#define JSF_PART_MASK 0x3 /* 2 bits mask */
70 70
71static DEFINE_MUTEX(jsf_mutex);
72
71/* 73/*
72 * Access functions. 74 * Access functions.
73 * We could ioremap(), but it's easier this way. 75 * We could ioremap(), but it's easier this way.
@@ -225,7 +227,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)
225{ 227{
226 loff_t ret; 228 loff_t ret;
227 229
228 lock_kernel(); 230 mutex_lock(&jsf_mutex);
229 switch (orig) { 231 switch (orig) {
230 case 0: 232 case 0:
231 file->f_pos = offset; 233 file->f_pos = offset;
@@ -238,7 +240,7 @@ static loff_t jsf_lseek(struct file * file, loff_t offset, int orig)
238 default: 240 default:
239 ret = -EINVAL; 241 ret = -EINVAL;
240 } 242 }
241 unlock_kernel(); 243 mutex_unlock(&jsf_mutex);
242 return ret; 244 return ret;
243} 245}
244 246
@@ -384,18 +386,18 @@ static int jsf_ioctl_program(void __user *arg)
384 386
385static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg) 387static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
386{ 388{
387 lock_kernel(); 389 mutex_lock(&jsf_mutex);
388 int error = -ENOTTY; 390 int error = -ENOTTY;
389 void __user *argp = (void __user *)arg; 391 void __user *argp = (void __user *)arg;
390 392
391 if (!capable(CAP_SYS_ADMIN)) { 393 if (!capable(CAP_SYS_ADMIN)) {
392 unlock_kernel(); 394 mutex_unlock(&jsf_mutex);
393 return -EPERM; 395 return -EPERM;
394 } 396 }
395 switch (cmd) { 397 switch (cmd) {
396 case JSFLASH_IDENT: 398 case JSFLASH_IDENT:
397 if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) { 399 if (copy_to_user(argp, &jsf0.id, JSFIDSZ)) {
398 unlock_kernel(); 400 mutex_unlock(&jsf_mutex);
399 return -EFAULT; 401 return -EFAULT;
400 } 402 }
401 break; 403 break;
@@ -407,7 +409,7 @@ static long jsf_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
407 break; 409 break;
408 } 410 }
409 411
410 unlock_kernel(); 412 mutex_unlock(&jsf_mutex);
411 return error; 413 return error;
412} 414}
413 415
@@ -418,17 +420,17 @@ static int jsf_mmap(struct file * file, struct vm_area_struct * vma)
418 420
419static int jsf_open(struct inode * inode, struct file * filp) 421static int jsf_open(struct inode * inode, struct file * filp)
420{ 422{
421 lock_kernel(); 423 mutex_lock(&jsf_mutex);
422 if (jsf0.base == 0) { 424 if (jsf0.base == 0) {
423 unlock_kernel(); 425 mutex_unlock(&jsf_mutex);
424 return -ENXIO; 426 return -ENXIO;
425 } 427 }
426 if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) { 428 if (test_and_set_bit(0, (void *)&jsf0.busy) != 0) {
427 unlock_kernel(); 429 mutex_unlock(&jsf_mutex);
428 return -EBUSY; 430 return -EBUSY;
429 } 431 }
430 432
431 unlock_kernel(); 433 mutex_unlock(&jsf_mutex);
432 return 0; /* XXX What security? */ 434 return 0; /* XXX What security? */
433} 435}
434 436
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 67aad69cfbc2..fcf08b3f52c1 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -92,7 +92,6 @@
92#include <linux/pci.h> 92#include <linux/pci.h>
93#include <linux/time.h> 93#include <linux/time.h>
94#include <linux/mutex.h> 94#include <linux/mutex.h>
95#include <linux/smp_lock.h>
96#include <linux/slab.h> 95#include <linux/slab.h>
97#include <asm/io.h> 96#include <asm/io.h>
98#include <asm/irq.h> 97#include <asm/irq.h>
@@ -105,6 +104,7 @@
105 104
106/* Globals */ 105/* Globals */
107#define TW_DRIVER_VERSION "2.26.02.014" 106#define TW_DRIVER_VERSION "2.26.02.014"
107static DEFINE_MUTEX(twa_chrdev_mutex);
108static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT]; 108static TW_Device_Extension *twa_device_extension_list[TW_MAX_SLOT];
109static unsigned int twa_device_extension_count; 109static unsigned int twa_device_extension_count;
110static int twa_major = -1; 110static int twa_major = -1;
@@ -659,7 +659,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
659 int retval = TW_IOCTL_ERROR_OS_EFAULT; 659 int retval = TW_IOCTL_ERROR_OS_EFAULT;
660 void __user *argp = (void __user *)arg; 660 void __user *argp = (void __user *)arg;
661 661
662 lock_kernel(); 662 mutex_lock(&twa_chrdev_mutex);
663 663
664 /* Only let one of these through at a time */ 664 /* Only let one of these through at a time */
665 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 665 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
@@ -880,7 +880,7 @@ out3:
880out2: 880out2:
881 mutex_unlock(&tw_dev->ioctl_lock); 881 mutex_unlock(&tw_dev->ioctl_lock);
882out: 882out:
883 unlock_kernel(); 883 mutex_unlock(&twa_chrdev_mutex);
884 return retval; 884 return retval;
885} /* End twa_chrdev_ioctl() */ 885} /* End twa_chrdev_ioctl() */
886 886
@@ -891,7 +891,6 @@ static int twa_chrdev_open(struct inode *inode, struct file *file)
891 unsigned int minor_number; 891 unsigned int minor_number;
892 int retval = TW_IOCTL_ERROR_OS_ENODEV; 892 int retval = TW_IOCTL_ERROR_OS_ENODEV;
893 893
894 cycle_kernel_lock();
895 minor_number = iminor(inode); 894 minor_number = iminor(inode);
896 if (minor_number >= twa_device_extension_count) 895 if (minor_number >= twa_device_extension_count)
897 goto out; 896 goto out;
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 7afac93d889f..6a95d111d207 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -64,7 +64,6 @@
64#include <linux/pci.h> 64#include <linux/pci.h>
65#include <linux/time.h> 65#include <linux/time.h>
66#include <linux/mutex.h> 66#include <linux/mutex.h>
67#include <linux/smp_lock.h>
68#include <linux/slab.h> 67#include <linux/slab.h>
69#include <asm/io.h> 68#include <asm/io.h>
70#include <asm/irq.h> 69#include <asm/irq.h>
@@ -77,6 +76,7 @@
77 76
78/* Globals */ 77/* Globals */
79#define TW_DRIVER_VERSION "3.26.02.000" 78#define TW_DRIVER_VERSION "3.26.02.000"
79static DEFINE_MUTEX(twl_chrdev_mutex);
80static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT]; 80static TW_Device_Extension *twl_device_extension_list[TW_MAX_SLOT];
81static unsigned int twl_device_extension_count; 81static unsigned int twl_device_extension_count;
82static int twl_major = -1; 82static int twl_major = -1;
@@ -764,7 +764,7 @@ static long twl_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long
764 int retval = -EFAULT; 764 int retval = -EFAULT;
765 void __user *argp = (void __user *)arg; 765 void __user *argp = (void __user *)arg;
766 766
767 lock_kernel(); 767 mutex_lock(&twl_chrdev_mutex);
768 768
769 /* Only let one of these through at a time */ 769 /* Only let one of these through at a time */
770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 770 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
@@ -861,7 +861,7 @@ out3:
861out2: 861out2:
862 mutex_unlock(&tw_dev->ioctl_lock); 862 mutex_unlock(&tw_dev->ioctl_lock);
863out: 863out:
864 unlock_kernel(); 864 mutex_unlock(&twl_chrdev_mutex);
865 return retval; 865 return retval;
866} /* End twl_chrdev_ioctl() */ 866} /* End twl_chrdev_ioctl() */
867 867
@@ -876,7 +876,6 @@ static int twl_chrdev_open(struct inode *inode, struct file *file)
876 goto out; 876 goto out;
877 } 877 }
878 878
879 cycle_kernel_lock();
880 minor_number = iminor(inode); 879 minor_number = iminor(inode);
881 if (minor_number >= twl_device_extension_count) 880 if (minor_number >= twl_device_extension_count)
882 goto out; 881 goto out;
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 5a2337306037..b1125341f4c8 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -199,7 +199,6 @@
199 199
200#include <linux/module.h> 200#include <linux/module.h>
201#include <linux/reboot.h> 201#include <linux/reboot.h>
202#include <linux/smp_lock.h>
203#include <linux/spinlock.h> 202#include <linux/spinlock.h>
204#include <linux/interrupt.h> 203#include <linux/interrupt.h>
205#include <linux/moduleparam.h> 204#include <linux/moduleparam.h>
@@ -221,6 +220,7 @@
221 220
222/* Globals */ 221/* Globals */
223#define TW_DRIVER_VERSION "1.26.02.003" 222#define TW_DRIVER_VERSION "1.26.02.003"
223static DEFINE_MUTEX(tw_mutex);
224static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT]; 224static TW_Device_Extension *tw_device_extension_list[TW_MAX_SLOT];
225static int tw_device_extension_count = 0; 225static int tw_device_extension_count = 0;
226static int twe_major = -1; 226static int twe_major = -1;
@@ -900,10 +900,10 @@ static long tw_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long a
900 900
901 dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n"); 901 dprintk(KERN_WARNING "3w-xxxx: tw_chrdev_ioctl()\n");
902 902
903 lock_kernel(); 903 mutex_lock(&tw_mutex);
904 /* Only let one of these through at a time */ 904 /* Only let one of these through at a time */
905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) { 905 if (mutex_lock_interruptible(&tw_dev->ioctl_lock)) {
906 unlock_kernel(); 906 mutex_unlock(&tw_mutex);
907 return -EINTR; 907 return -EINTR;
908 } 908 }
909 909
@@ -1034,7 +1034,7 @@ out2:
1034 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle); 1034 dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_New_Ioctl) - 1, cpu_addr, dma_handle);
1035out: 1035out:
1036 mutex_unlock(&tw_dev->ioctl_lock); 1036 mutex_unlock(&tw_dev->ioctl_lock);
1037 unlock_kernel(); 1037 mutex_unlock(&tw_mutex);
1038 return retval; 1038 return retval;
1039} /* End tw_chrdev_ioctl() */ 1039} /* End tw_chrdev_ioctl() */
1040 1040
@@ -1044,7 +1044,6 @@ static int tw_chrdev_open(struct inode *inode, struct file *file)
1044{ 1044{
1045 unsigned int minor_number; 1045 unsigned int minor_number;
1046 1046
1047 cycle_kernel_lock();
1048 dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n"); 1047 dprintk(KERN_WARNING "3w-xxxx: tw_ioctl_open()\n");
1049 1048
1050 minor_number = iminor(inode); 1049 minor_number = iminor(inode);
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 13af86eec96e..dae46d779c7b 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -38,7 +38,7 @@
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/smp_lock.h> 41#include <linux/mutex.h>
42#include <linux/spinlock.h> 42#include <linux/spinlock.h>
43#include <linux/syscalls.h> 43#include <linux/syscalls.h>
44#include <linux/delay.h> 44#include <linux/delay.h>
@@ -76,6 +76,7 @@ MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
76MODULE_LICENSE("GPL"); 76MODULE_LICENSE("GPL");
77MODULE_VERSION(AAC_DRIVER_FULL_VERSION); 77MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
78 78
79static DEFINE_MUTEX(aac_mutex);
79static LIST_HEAD(aac_devices); 80static LIST_HEAD(aac_devices);
80static int aac_cfg_major = -1; 81static int aac_cfg_major = -1;
81char aac_driver_version[] = AAC_DRIVER_FULL_VERSION; 82char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
@@ -678,7 +679,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
678 unsigned minor_number = iminor(inode); 679 unsigned minor_number = iminor(inode);
679 int err = -ENODEV; 680 int err = -ENODEV;
680 681
681 lock_kernel(); /* BKL pushdown: nothing else protects this list */ 682 mutex_lock(&aac_mutex); /* BKL pushdown: nothing else protects this list */
682 list_for_each_entry(aac, &aac_devices, entry) { 683 list_for_each_entry(aac, &aac_devices, entry) {
683 if (aac->id == minor_number) { 684 if (aac->id == minor_number) {
684 file->private_data = aac; 685 file->private_data = aac;
@@ -686,7 +687,7 @@ static int aac_cfg_open(struct inode *inode, struct file *file)
686 break; 687 break;
687 } 688 }
688 } 689 }
689 unlock_kernel(); 690 mutex_unlock(&aac_mutex);
690 691
691 return err; 692 return err;
692} 693}
@@ -711,9 +712,9 @@ static long aac_cfg_ioctl(struct file *file,
711 int ret; 712 int ret;
712 if (!capable(CAP_SYS_RAWIO)) 713 if (!capable(CAP_SYS_RAWIO))
713 return -EPERM; 714 return -EPERM;
714 lock_kernel(); 715 mutex_lock(&aac_mutex);
715 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg); 716 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
716 unlock_kernel(); 717 mutex_unlock(&aac_mutex);
717 718
718 return ret; 719 return ret;
719} 720}
@@ -722,7 +723,7 @@ static long aac_cfg_ioctl(struct file *file,
722static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg) 723static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg)
723{ 724{
724 long ret; 725 long ret;
725 lock_kernel(); 726 mutex_lock(&aac_mutex);
726 switch (cmd) { 727 switch (cmd) {
727 case FSACTL_MINIPORT_REV_CHECK: 728 case FSACTL_MINIPORT_REV_CHECK:
728 case FSACTL_SENDFIB: 729 case FSACTL_SENDFIB:
@@ -756,7 +757,7 @@ static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long
756 ret = -ENOIOCTLCMD; 757 ret = -ENOIOCTLCMD;
757 break; 758 break;
758 } 759 }
759 unlock_kernel(); 760 mutex_unlock(&aac_mutex);
760 return ret; 761 return ret;
761} 762}
762 763
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index e40c9f7a002a..a15474eef5f7 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -22,7 +22,6 @@
22#include <linux/chio.h> /* here are all the ioctls */ 22#include <linux/chio.h> /* here are all the ioctls */
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/idr.h> 24#include <linux/idr.h>
25#include <linux/smp_lock.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
27 26
28#include <scsi/scsi.h> 27#include <scsi/scsi.h>
@@ -44,6 +43,7 @@ MODULE_LICENSE("GPL");
44MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR); 43MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR);
45MODULE_ALIAS_SCSI_DEVICE(TYPE_MEDIUM_CHANGER); 44MODULE_ALIAS_SCSI_DEVICE(TYPE_MEDIUM_CHANGER);
46 45
46static DEFINE_MUTEX(ch_mutex);
47static int init = 1; 47static int init = 1;
48module_param(init, int, 0444); 48module_param(init, int, 0444);
49MODULE_PARM_DESC(init, \ 49MODULE_PARM_DESC(init, \
@@ -581,19 +581,19 @@ ch_open(struct inode *inode, struct file *file)
581 scsi_changer *ch; 581 scsi_changer *ch;
582 int minor = iminor(inode); 582 int minor = iminor(inode);
583 583
584 lock_kernel(); 584 mutex_lock(&ch_mutex);
585 spin_lock(&ch_index_lock); 585 spin_lock(&ch_index_lock);
586 ch = idr_find(&ch_index_idr, minor); 586 ch = idr_find(&ch_index_idr, minor);
587 587
588 if (NULL == ch || scsi_device_get(ch->device)) { 588 if (NULL == ch || scsi_device_get(ch->device)) {
589 spin_unlock(&ch_index_lock); 589 spin_unlock(&ch_index_lock);
590 unlock_kernel(); 590 mutex_unlock(&ch_mutex);
591 return -ENXIO; 591 return -ENXIO;
592 } 592 }
593 spin_unlock(&ch_index_lock); 593 spin_unlock(&ch_index_lock);
594 594
595 file->private_data = ch; 595 file->private_data = ch;
596 unlock_kernel(); 596 mutex_unlock(&ch_mutex);
597 return 0; 597 return 0;
598} 598}
599 599
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 7a61206ed1c0..23dec0063385 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -49,7 +49,6 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
49#include <linux/kernel.h> /* for printk */ 49#include <linux/kernel.h> /* for printk */
50#include <linux/sched.h> 50#include <linux/sched.h>
51#include <linux/reboot.h> 51#include <linux/reboot.h>
52#include <linux/smp_lock.h>
53#include <linux/spinlock.h> 52#include <linux/spinlock.h>
54#include <linux/dma-mapping.h> 53#include <linux/dma-mapping.h>
55 54
@@ -76,6 +75,7 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
76 * Needed for our management apps 75 * Needed for our management apps
77 *============================================================================ 76 *============================================================================
78 */ 77 */
78static DEFINE_MUTEX(adpt_mutex);
79static dpt_sig_S DPTI_sig = { 79static dpt_sig_S DPTI_sig = {
80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, 80 {'d', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION,
81#ifdef __i386__ 81#ifdef __i386__
@@ -1733,12 +1733,12 @@ static int adpt_open(struct inode *inode, struct file *file)
1733 int minor; 1733 int minor;
1734 adpt_hba* pHba; 1734 adpt_hba* pHba;
1735 1735
1736 lock_kernel(); 1736 mutex_lock(&adpt_mutex);
1737 //TODO check for root access 1737 //TODO check for root access
1738 // 1738 //
1739 minor = iminor(inode); 1739 minor = iminor(inode);
1740 if (minor >= hba_count) { 1740 if (minor >= hba_count) {
1741 unlock_kernel(); 1741 mutex_unlock(&adpt_mutex);
1742 return -ENXIO; 1742 return -ENXIO;
1743 } 1743 }
1744 mutex_lock(&adpt_configuration_lock); 1744 mutex_lock(&adpt_configuration_lock);
@@ -1749,7 +1749,7 @@ static int adpt_open(struct inode *inode, struct file *file)
1749 } 1749 }
1750 if (pHba == NULL) { 1750 if (pHba == NULL) {
1751 mutex_unlock(&adpt_configuration_lock); 1751 mutex_unlock(&adpt_configuration_lock);
1752 unlock_kernel(); 1752 mutex_unlock(&adpt_mutex);
1753 return -ENXIO; 1753 return -ENXIO;
1754 } 1754 }
1755 1755
@@ -1760,7 +1760,7 @@ static int adpt_open(struct inode *inode, struct file *file)
1760 1760
1761 pHba->in_use = 1; 1761 pHba->in_use = 1;
1762 mutex_unlock(&adpt_configuration_lock); 1762 mutex_unlock(&adpt_configuration_lock);
1763 unlock_kernel(); 1763 mutex_unlock(&adpt_mutex);
1764 1764
1765 return 0; 1765 return 0;
1766} 1766}
@@ -2161,9 +2161,9 @@ static long adpt_unlocked_ioctl(struct file *file, uint cmd, ulong arg)
2161 2161
2162 inode = file->f_dentry->d_inode; 2162 inode = file->f_dentry->d_inode;
2163 2163
2164 lock_kernel(); 2164 mutex_lock(&adpt_mutex);
2165 ret = adpt_ioctl(inode, file, cmd, arg); 2165 ret = adpt_ioctl(inode, file, cmd, arg);
2166 unlock_kernel(); 2166 mutex_unlock(&adpt_mutex);
2167 2167
2168 return ret; 2168 return ret;
2169} 2169}
@@ -2177,7 +2177,7 @@ static long compat_adpt_ioctl(struct file *file,
2177 2177
2178 inode = file->f_dentry->d_inode; 2178 inode = file->f_dentry->d_inode;
2179 2179
2180 lock_kernel(); 2180 mutex_lock(&adpt_mutex);
2181 2181
2182 switch(cmd) { 2182 switch(cmd) {
2183 case DPT_SIGNATURE: 2183 case DPT_SIGNATURE:
@@ -2195,7 +2195,7 @@ static long compat_adpt_ioctl(struct file *file,
2195 ret = -ENOIOCTLCMD; 2195 ret = -ENOIOCTLCMD;
2196 } 2196 }
2197 2197
2198 unlock_kernel(); 2198 mutex_unlock(&adpt_mutex);
2199 2199
2200 return ret; 2200 return ret;
2201} 2201}
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 9886586df01f..5a3f93101017 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -120,7 +120,7 @@
120#include <linux/timer.h> 120#include <linux/timer.h>
121#include <linux/dma-mapping.h> 121#include <linux/dma-mapping.h>
122#include <linux/list.h> 122#include <linux/list.h>
123#include <linux/smp_lock.h> 123#include <linux/mutex.h>
124#include <linux/slab.h> 124#include <linux/slab.h>
125 125
126#ifdef GDTH_RTC 126#ifdef GDTH_RTC
@@ -140,6 +140,7 @@
140#include <scsi/scsi_host.h> 140#include <scsi/scsi_host.h>
141#include "gdth.h" 141#include "gdth.h"
142 142
143static DEFINE_MUTEX(gdth_mutex);
143static void gdth_delay(int milliseconds); 144static void gdth_delay(int milliseconds);
144static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs); 145static void gdth_eval_mapping(u32 size, u32 *cyls, int *heads, int *secs);
145static irqreturn_t gdth_interrupt(int irq, void *dev_id); 146static irqreturn_t gdth_interrupt(int irq, void *dev_id);
@@ -4043,12 +4044,12 @@ static int gdth_open(struct inode *inode, struct file *filep)
4043{ 4044{
4044 gdth_ha_str *ha; 4045 gdth_ha_str *ha;
4045 4046
4046 lock_kernel(); 4047 mutex_lock(&gdth_mutex);
4047 list_for_each_entry(ha, &gdth_instances, list) { 4048 list_for_each_entry(ha, &gdth_instances, list) {
4048 if (!ha->sdev) 4049 if (!ha->sdev)
4049 ha->sdev = scsi_get_host_dev(ha->shost); 4050 ha->sdev = scsi_get_host_dev(ha->shost);
4050 } 4051 }
4051 unlock_kernel(); 4052 mutex_unlock(&gdth_mutex);
4052 4053
4053 TRACE(("gdth_open()\n")); 4054 TRACE(("gdth_open()\n"));
4054 return 0; 4055 return 0;
@@ -4616,9 +4617,9 @@ static long gdth_unlocked_ioctl(struct file *file, unsigned int cmd,
4616{ 4617{
4617 int ret; 4618 int ret;
4618 4619
4619 lock_kernel(); 4620 mutex_lock(&gdth_mutex);
4620 ret = gdth_ioctl(file, cmd, arg); 4621 ret = gdth_ioctl(file, cmd, arg);
4621 unlock_kernel(); 4622 mutex_unlock(&gdth_mutex);
4622 4623
4623 return ret; 4624 return ret;
4624} 4625}
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index aac80f7bb999..7ceb5cf12c6b 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -46,7 +46,7 @@
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/init.h> 47#include <linux/init.h>
48#include <linux/dma-mapping.h> 48#include <linux/dma-mapping.h>
49#include <linux/smp_lock.h> 49#include <linux/mutex.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <scsi/scsicam.h> 51#include <scsi/scsicam.h>
52 52
@@ -62,6 +62,7 @@ MODULE_DESCRIPTION ("LSI Logic MegaRAID legacy driver");
62MODULE_LICENSE ("GPL"); 62MODULE_LICENSE ("GPL");
63MODULE_VERSION(MEGARAID_MODULE_VERSION); 63MODULE_VERSION(MEGARAID_MODULE_VERSION);
64 64
65static DEFINE_MUTEX(megadev_mutex);
65static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN; 66static unsigned int max_cmd_per_lun = DEF_CMD_PER_LUN;
66module_param(max_cmd_per_lun, uint, 0); 67module_param(max_cmd_per_lun, uint, 0);
67MODULE_PARM_DESC(max_cmd_per_lun, "Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)"); 68MODULE_PARM_DESC(max_cmd_per_lun, "Maximum number of commands which can be issued to a single LUN (default=DEF_CMD_PER_LUN=63)");
@@ -3283,7 +3284,6 @@ mega_init_scb(adapter_t *adapter)
3283static int 3284static int
3284megadev_open (struct inode *inode, struct file *filep) 3285megadev_open (struct inode *inode, struct file *filep)
3285{ 3286{
3286 cycle_kernel_lock();
3287 /* 3287 /*
3288 * Only allow superuser to access private ioctl interface 3288 * Only allow superuser to access private ioctl interface
3289 */ 3289 */
@@ -3702,9 +3702,9 @@ megadev_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
3702{ 3702{
3703 int ret; 3703 int ret;
3704 3704
3705 lock_kernel(); 3705 mutex_lock(&megadev_mutex);
3706 ret = megadev_ioctl(filep, cmd, arg); 3706 ret = megadev_ioctl(filep, cmd, arg);
3707 unlock_kernel(); 3707 mutex_unlock(&megadev_mutex);
3708 3708
3709 return ret; 3709 return ret;
3710} 3710}
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index ab801232d777..a7008c0c24f9 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -16,11 +16,12 @@
16 */ 16 */
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/smp_lock.h> 19#include <linux/mutex.h>
20#include "megaraid_mm.h" 20#include "megaraid_mm.h"
21 21
22 22
23// Entry points for char node driver 23// Entry points for char node driver
24static DEFINE_MUTEX(mraid_mm_mutex);
24static int mraid_mm_open(struct inode *, struct file *); 25static int mraid_mm_open(struct inode *, struct file *);
25static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long); 26static long mraid_mm_unlocked_ioctl(struct file *, uint, unsigned long);
26 27
@@ -99,7 +100,6 @@ mraid_mm_open(struct inode *inode, struct file *filep)
99 */ 100 */
100 if (!capable(CAP_SYS_ADMIN)) return (-EACCES); 101 if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
101 102
102 cycle_kernel_lock();
103 return 0; 103 return 0;
104} 104}
105 105
@@ -225,9 +225,9 @@ mraid_mm_unlocked_ioctl(struct file *filep, unsigned int cmd,
225 int err; 225 int err;
226 226
227 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */ 227 /* inconsistant: mraid_mm_compat_ioctl doesn't take the BKL */
228 lock_kernel(); 228 mutex_lock(&mraid_mm_mutex);
229 err = mraid_mm_ioctl(filep, cmd, arg); 229 err = mraid_mm_ioctl(filep, cmd, arg);
230 unlock_kernel(); 230 mutex_unlock(&mraid_mm_mutex);
231 231
232 return err; 232 return err;
233} 233}
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index 209cc87b9a32..51e2579a743a 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -33,7 +33,6 @@
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/smp_lock.h>
37#include <linux/uio.h> 36#include <linux/uio.h>
38#include <linux/slab.h> 37#include <linux/slab.h>
39#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -3557,7 +3556,6 @@ static void megasas_shutdown(struct pci_dev *pdev)
3557 */ 3556 */
3558static int megasas_mgmt_open(struct inode *inode, struct file *filep) 3557static int megasas_mgmt_open(struct inode *inode, struct file *filep)
3559{ 3558{
3560 cycle_kernel_lock();
3561 /* 3559 /*
3562 * Allow only those users with admin rights 3560 * Allow only those users with admin rights
3563 */ 3561 */
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 9a4e584ae3cc..40cb8aeb21b1 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -51,7 +51,7 @@
51#include <linux/types.h> 51#include <linux/types.h>
52#include <linux/pci.h> 52#include <linux/pci.h>
53#include <linux/delay.h> 53#include <linux/delay.h>
54#include <linux/smp_lock.h> 54#include <linux/mutex.h>
55#include <linux/compat.h> 55#include <linux/compat.h>
56#include <linux/poll.h> 56#include <linux/poll.h>
57 57
@@ -61,6 +61,7 @@
61#include "mpt2sas_base.h" 61#include "mpt2sas_base.h"
62#include "mpt2sas_ctl.h" 62#include "mpt2sas_ctl.h"
63 63
64static DEFINE_MUTEX(_ctl_mutex);
64static struct fasync_struct *async_queue; 65static struct fasync_struct *async_queue;
65static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait); 66static DECLARE_WAIT_QUEUE_HEAD(ctl_poll_wait);
66 67
@@ -2238,9 +2239,9 @@ _ctl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2238{ 2239{
2239 long ret; 2240 long ret;
2240 2241
2241 lock_kernel(); 2242 mutex_lock(&_ctl_mutex);
2242 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2243 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2243 unlock_kernel(); 2244 mutex_unlock(&_ctl_mutex);
2244 return ret; 2245 return ret;
2245} 2246}
2246 2247
@@ -2309,12 +2310,12 @@ _ctl_ioctl_compat(struct file *file, unsigned cmd, unsigned long arg)
2309{ 2310{
2310 long ret; 2311 long ret;
2311 2312
2312 lock_kernel(); 2313 mutex_lock(&_ctl_mutex);
2313 if (cmd == MPT2COMMAND32) 2314 if (cmd == MPT2COMMAND32)
2314 ret = _ctl_compat_mpt_command(file, cmd, arg); 2315 ret = _ctl_compat_mpt_command(file, cmd, arg);
2315 else 2316 else
2316 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg); 2317 ret = _ctl_ioctl_main(file, cmd, (void __user *)arg);
2317 unlock_kernel(); 2318 mutex_unlock(&_ctl_mutex);
2318 return ret; 2319 return ret;
2319} 2320}
2320#endif 2321#endif
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 278b352ae78d..54de1d1af1a7 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -51,7 +51,7 @@ static const char * osst_version = "0.99.4";
51#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/jiffies.h> 53#include <linux/jiffies.h>
54#include <linux/smp_lock.h> 54#include <linux/mutex.h>
55#include <asm/uaccess.h> 55#include <asm/uaccess.h>
56#include <asm/dma.h> 56#include <asm/dma.h>
57#include <asm/system.h> 57#include <asm/system.h>
@@ -80,6 +80,7 @@ static const char * osst_version = "0.99.4";
80#include "osst_options.h" 80#include "osst_options.h"
81#include "osst_detect.h" 81#include "osst_detect.h"
82 82
83static DEFINE_MUTEX(osst_int_mutex);
83static int max_dev = 0; 84static int max_dev = 0;
84static int write_threshold_kbs = 0; 85static int write_threshold_kbs = 0;
85static int max_sg_segs = 0; 86static int max_sg_segs = 0;
@@ -4807,9 +4808,9 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
4807{ 4808{
4808 int ret; 4809 int ret;
4809 4810
4810 lock_kernel(); 4811 mutex_lock(&osst_int_mutex);
4811 ret = __os_scsi_tape_open(inode, filp); 4812 ret = __os_scsi_tape_open(inode, filp);
4812 unlock_kernel(); 4813 mutex_unlock(&osst_int_mutex);
4813 return ret; 4814 return ret;
4814} 4815}
4815 4816
@@ -4943,9 +4944,9 @@ static long osst_ioctl(struct file * file,
4943 char * name = tape_name(STp); 4944 char * name = tape_name(STp);
4944 void __user * p = (void __user *)arg; 4945 void __user * p = (void __user *)arg;
4945 4946
4946 lock_kernel(); 4947 mutex_lock(&osst_int_mutex);
4947 if (mutex_lock_interruptible(&STp->lock)) { 4948 if (mutex_lock_interruptible(&STp->lock)) {
4948 unlock_kernel(); 4949 mutex_unlock(&osst_int_mutex);
4949 return -ERESTARTSYS; 4950 return -ERESTARTSYS;
4950 } 4951 }
4951 4952
@@ -5260,14 +5261,14 @@ static long osst_ioctl(struct file * file,
5260 mutex_unlock(&STp->lock); 5261 mutex_unlock(&STp->lock);
5261 5262
5262 retval = scsi_ioctl(STp->device, cmd_in, p); 5263 retval = scsi_ioctl(STp->device, cmd_in, p);
5263 unlock_kernel(); 5264 mutex_unlock(&osst_int_mutex);
5264 return retval; 5265 return retval;
5265 5266
5266out: 5267out:
5267 if (SRpnt) osst_release_request(SRpnt); 5268 if (SRpnt) osst_release_request(SRpnt);
5268 5269
5269 mutex_unlock(&STp->lock); 5270 mutex_unlock(&STp->lock);
5270 unlock_kernel(); 5271 mutex_unlock(&osst_int_mutex);
5271 5272
5272 return retval; 5273 return retval;
5273} 5274}
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 61f49bdcc0c2..e77dd02eccdd 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -49,7 +49,6 @@
49#include <scsi/scsi_host.h> 49#include <scsi/scsi_host.h>
50#include "aha152x.h" 50#include "aha152x.h"
51 51
52#include <pcmcia/cs.h>
53#include <pcmcia/cistpl.h> 52#include <pcmcia/cistpl.h>
54#include <pcmcia/ds.h> 53#include <pcmcia/ds.h>
55 54
@@ -86,8 +85,6 @@ static void aha152x_release_cs(struct pcmcia_device *link);
86static void aha152x_detach(struct pcmcia_device *p_dev); 85static void aha152x_detach(struct pcmcia_device *p_dev);
87static int aha152x_config_cs(struct pcmcia_device *link); 86static int aha152x_config_cs(struct pcmcia_device *link);
88 87
89static struct pcmcia_device *dev_list;
90
91static int aha152x_probe(struct pcmcia_device *link) 88static int aha152x_probe(struct pcmcia_device *link)
92{ 89{
93 scsi_info_t *info; 90 scsi_info_t *info;
@@ -100,11 +97,8 @@ static int aha152x_probe(struct pcmcia_device *link)
100 info->p_dev = link; 97 info->p_dev = link;
101 link->priv = info; 98 link->priv = info;
102 99
103 link->resource[0]->end = 0x20; 100 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
104 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 101 link->config_regs = PRESENT_OPTION;
105 link->conf.Attributes = CONF_ENABLE_IRQ;
106 link->conf.IntType = INT_MEMORY_AND_IO;
107 link->conf.Present = PRESENT_OPTION;
108 102
109 return aha152x_config_cs(link); 103 return aha152x_config_cs(link);
110} /* aha152x_attach */ 104} /* aha152x_attach */
@@ -123,25 +117,24 @@ static void aha152x_detach(struct pcmcia_device *link)
123 117
124/*====================================================================*/ 118/*====================================================================*/
125 119
126static int aha152x_config_check(struct pcmcia_device *p_dev, 120static int aha152x_config_check(struct pcmcia_device *p_dev, void *priv_data)
127 cistpl_cftable_entry_t *cfg,
128 cistpl_cftable_entry_t *dflt,
129 unsigned int vcc,
130 void *priv_data)
131{ 121{
132 p_dev->io_lines = 10; 122 p_dev->io_lines = 10;
123
133 /* For New Media T&J, look for a SCSI window */ 124 /* For New Media T&J, look for a SCSI window */
134 if (cfg->io.win[0].len >= 0x20) 125 if ((p_dev->resource[0]->end < 0x20) &&
135 p_dev->resource[0]->start = cfg->io.win[0].base; 126 (p_dev->resource[1]->end >= 0x20))
136 else if ((cfg->io.nwin > 1) && 127 p_dev->resource[0]->start = p_dev->resource[1]->start;
137 (cfg->io.win[1].len >= 0x20)) 128
138 p_dev->resource[0]->start = cfg->io.win[1].base; 129 if (p_dev->resource[0]->start >= 0xffff)
139 if ((cfg->io.nwin > 0) && 130 return -EINVAL;
140 (p_dev->resource[0]->start < 0xffff)) { 131
141 if (!pcmcia_request_io(p_dev)) 132 p_dev->resource[1]->start = p_dev->resource[1]->end = 0;
142 return 0; 133 p_dev->resource[0]->end = 0x20;
143 } 134 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
144 return -EINVAL; 135 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
136
137 return pcmcia_request_io(p_dev);
145} 138}
146 139
147static int aha152x_config_cs(struct pcmcia_device *link) 140static int aha152x_config_cs(struct pcmcia_device *link)
@@ -160,7 +153,7 @@ static int aha152x_config_cs(struct pcmcia_device *link)
160 if (!link->irq) 153 if (!link->irq)
161 goto failed; 154 goto failed;
162 155
163 ret = pcmcia_request_configuration(link, &link->conf); 156 ret = pcmcia_enable_device(link);
164 if (ret) 157 if (ret)
165 goto failed; 158 goto failed;
166 159
@@ -221,9 +214,7 @@ MODULE_DEVICE_TABLE(pcmcia, aha152x_ids);
221 214
222static struct pcmcia_driver aha152x_cs_driver = { 215static struct pcmcia_driver aha152x_cs_driver = {
223 .owner = THIS_MODULE, 216 .owner = THIS_MODULE,
224 .drv = { 217 .name = "aha152x_cs",
225 .name = "aha152x_cs",
226 },
227 .probe = aha152x_probe, 218 .probe = aha152x_probe,
228 .remove = aha152x_detach, 219 .remove = aha152x_detach,
229 .id_table = aha152x_ids, 220 .id_table = aha152x_ids,
@@ -238,7 +229,6 @@ static int __init init_aha152x_cs(void)
238static void __exit exit_aha152x_cs(void) 229static void __exit exit_aha152x_cs(void)
239{ 230{
240 pcmcia_unregister_driver(&aha152x_cs_driver); 231 pcmcia_unregister_driver(&aha152x_cs_driver);
241 BUG_ON(dev_list != NULL);
242} 232}
243 233
244module_init(init_aha152x_cs); 234module_init(init_aha152x_cs);
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index 13dbe5c48492..cd69c2670f81 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -46,7 +46,6 @@
46#include <scsi/scsi_host.h> 46#include <scsi/scsi_host.h>
47#include "fdomain.h" 47#include "fdomain.h"
48 48
49#include <pcmcia/cs.h>
50#include <pcmcia/cistpl.h> 49#include <pcmcia/cistpl.h>
51#include <pcmcia/ds.h> 50#include <pcmcia/ds.h>
52 51
@@ -83,11 +82,8 @@ static int fdomain_probe(struct pcmcia_device *link)
83 82
84 info->p_dev = link; 83 info->p_dev = link;
85 link->priv = info; 84 link->priv = info;
86 link->resource[0]->end = 0x10; 85 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
87 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 86 link->config_regs = PRESENT_OPTION;
88 link->conf.Attributes = CONF_ENABLE_IRQ;
89 link->conf.IntType = INT_MEMORY_AND_IO;
90 link->conf.Present = PRESENT_OPTION;
91 87
92 return fdomain_config(link); 88 return fdomain_config(link);
93} /* fdomain_attach */ 89} /* fdomain_attach */
@@ -105,14 +101,12 @@ static void fdomain_detach(struct pcmcia_device *link)
105 101
106/*====================================================================*/ 102/*====================================================================*/
107 103
108static int fdomain_config_check(struct pcmcia_device *p_dev, 104static int fdomain_config_check(struct pcmcia_device *p_dev, void *priv_data)
109 cistpl_cftable_entry_t *cfg,
110 cistpl_cftable_entry_t *dflt,
111 unsigned int vcc,
112 void *priv_data)
113{ 105{
114 p_dev->io_lines = 10; 106 p_dev->io_lines = 10;
115 p_dev->resource[0]->start = cfg->io.win[0].base; 107 p_dev->resource[0]->end = 0x10;
108 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
109 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
116 return pcmcia_request_io(p_dev); 110 return pcmcia_request_io(p_dev);
117} 111}
118 112
@@ -132,7 +126,7 @@ static int fdomain_config(struct pcmcia_device *link)
132 126
133 if (!link->irq) 127 if (!link->irq)
134 goto failed; 128 goto failed;
135 ret = pcmcia_request_configuration(link, &link->conf); 129 ret = pcmcia_enable_device(link);
136 if (ret) 130 if (ret)
137 goto failed; 131 goto failed;
138 132
@@ -194,9 +188,7 @@ MODULE_DEVICE_TABLE(pcmcia, fdomain_ids);
194 188
195static struct pcmcia_driver fdomain_cs_driver = { 189static struct pcmcia_driver fdomain_cs_driver = {
196 .owner = THIS_MODULE, 190 .owner = THIS_MODULE,
197 .drv = { 191 .name = "fdomain_cs",
198 .name = "fdomain_cs",
199 },
200 .probe = fdomain_probe, 192 .probe = fdomain_probe,
201 .remove = fdomain_detach, 193 .remove = fdomain_detach,
202 .id_table = fdomain_ids, 194 .id_table = fdomain_ids,
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index dd9b40306f3d..9326c2c14880 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -47,7 +47,6 @@
47#include <scsi/scsi.h> 47#include <scsi/scsi.h>
48#include <scsi/scsi_ioctl.h> 48#include <scsi/scsi_ioctl.h>
49 49
50#include <pcmcia/cs.h>
51#include <pcmcia/cistpl.h> 50#include <pcmcia/cistpl.h>
52#include <pcmcia/cisreg.h> 51#include <pcmcia/cisreg.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
@@ -1531,15 +1530,6 @@ static int nsp_eh_host_reset(struct scsi_cmnd *SCpnt)
1531 PCMCIA functions 1530 PCMCIA functions
1532**********************************************************************/ 1531**********************************************************************/
1533 1532
1534/*======================================================================
1535 nsp_cs_attach() creates an "instance" of the driver, allocating
1536 local data structures for one device. The device is registered
1537 with Card Services.
1538
1539 The dev_link structure is initialized, but we don't actually
1540 configure the card at this point -- we wait until we receive a
1541 card insertion event.
1542======================================================================*/
1543static int nsp_cs_probe(struct pcmcia_device *link) 1533static int nsp_cs_probe(struct pcmcia_device *link)
1544{ 1534{
1545 scsi_info_t *info; 1535 scsi_info_t *info;
@@ -1557,14 +1547,6 @@ static int nsp_cs_probe(struct pcmcia_device *link)
1557 1547
1558 nsp_dbg(NSP_DEBUG_INIT, "info=0x%p", info); 1548 nsp_dbg(NSP_DEBUG_INIT, "info=0x%p", info);
1559 1549
1560 /* The io structure describes IO port mapping */
1561 link->resource[0]->end = 0x10;
1562 link->resource[0]->flags = IO_DATA_PATH_WIDTH_AUTO;
1563
1564 /* General socket configuration */
1565 link->conf.Attributes = CONF_ENABLE_IRQ;
1566 link->conf.IntType = INT_MEMORY_AND_IO;
1567
1568 ret = nsp_cs_config(link); 1550 ret = nsp_cs_config(link);
1569 1551
1570 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link); 1552 nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
@@ -1572,12 +1554,6 @@ static int nsp_cs_probe(struct pcmcia_device *link)
1572} /* nsp_cs_attach */ 1554} /* nsp_cs_attach */
1573 1555
1574 1556
1575/*======================================================================
1576 This deletes a driver "instance". The device is de-registered
1577 with Card Services. If it has been released, all local data
1578 structures are freed. Otherwise, the structures will be freed
1579 when the device is released.
1580======================================================================*/
1581static void nsp_cs_detach(struct pcmcia_device *link) 1557static void nsp_cs_detach(struct pcmcia_device *link)
1582{ 1558{
1583 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link); 1559 nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
@@ -1590,98 +1566,36 @@ static void nsp_cs_detach(struct pcmcia_device *link)
1590} /* nsp_cs_detach */ 1566} /* nsp_cs_detach */
1591 1567
1592 1568
1593/*====================================================================== 1569static int nsp_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
1594 nsp_cs_config() is scheduled to run after a CARD_INSERTION event
1595 is received, to configure the PCMCIA socket, and to make the
1596 ethernet device available to the system.
1597======================================================================*/
1598
1599struct nsp_cs_configdata {
1600 nsp_hw_data *data;
1601 win_req_t req;
1602};
1603
1604static int nsp_cs_config_check(struct pcmcia_device *p_dev,
1605 cistpl_cftable_entry_t *cfg,
1606 cistpl_cftable_entry_t *dflt,
1607 unsigned int vcc,
1608 void *priv_data)
1609{ 1570{
1610 struct nsp_cs_configdata *cfg_mem = priv_data; 1571 nsp_hw_data *data = priv_data;
1611 1572
1612 if (cfg->index == 0) 1573 if (p_dev->config_index == 0)
1613 return -ENODEV; 1574 return -ENODEV;
1614 1575
1615 /* Does this card need audio output? */ 1576 /* This reserves IO space but doesn't actually enable it */
1616 if (cfg->flags & CISTPL_CFTABLE_AUDIO) { 1577 if (pcmcia_request_io(p_dev) != 0)
1617 p_dev->conf.Attributes |= CONF_ENABLE_SPKR; 1578 goto next_entry;
1618 p_dev->conf.Status = CCSR_AUDIO_ENA; 1579
1619 } 1580 if (resource_size(p_dev->resource[2])) {
1620 1581 p_dev->resource[2]->flags |= (WIN_DATA_WIDTH_16 |
1621 /* Use power settings for Vcc and Vpp if present */ 1582 WIN_MEMORY_TYPE_CM |
1622 /* Note that the CIS values need to be rescaled */ 1583 WIN_ENABLE);
1623 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { 1584 if (p_dev->resource[2]->end < 0x1000)
1624 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) 1585 p_dev->resource[2]->end = 0x1000;
1625 return -ENODEV; 1586 if (pcmcia_request_window(p_dev, p_dev->resource[2], 0) != 0)
1626 else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) { 1587 goto next_entry;
1627 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000) 1588 if (pcmcia_map_mem_page(p_dev, p_dev->resource[2],
1628 return -ENODEV; 1589 p_dev->card_addr) != 0)
1629 } 1590 goto next_entry;
1630 1591
1631 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1592 data->MmioAddress = (unsigned long)
1632 p_dev->conf.Vpp = 1593 ioremap_nocache(p_dev->resource[2]->start,
1633 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 1594 resource_size(p_dev->resource[2]));
1634 } else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1595 data->MmioLength = resource_size(p_dev->resource[2]);
1635 p_dev->conf.Vpp =
1636 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1637 }
1638
1639 /* Do we need to allocate an interrupt? */
1640 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
1641
1642 /* IO window settings */
1643 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
1644 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
1645 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
1646 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
1647 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
1648 p_dev->resource[0]->flags |=
1649 pcmcia_io_cfg_data_width(io->flags);
1650 p_dev->resource[0]->start = io->win[0].base;
1651 p_dev->resource[0]->end = io->win[0].len;
1652 if (io->nwin > 1) {
1653 p_dev->resource[1]->flags =
1654 p_dev->resource[0]->flags;
1655 p_dev->resource[1]->start = io->win[1].base;
1656 p_dev->resource[1]->end = io->win[1].len;
1657 }
1658 /* This reserves IO space but doesn't actually enable it */
1659 if (pcmcia_request_io(p_dev) != 0)
1660 goto next_entry;
1661 }
1662
1663 if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
1664 cistpl_mem_t *mem =
1665 (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
1666 cfg_mem->req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
1667 cfg_mem->req.Attributes |= WIN_ENABLE;
1668 cfg_mem->req.Base = mem->win[0].host_addr;
1669 cfg_mem->req.Size = mem->win[0].len;
1670 if (cfg_mem->req.Size < 0x1000)
1671 cfg_mem->req.Size = 0x1000;
1672 cfg_mem->req.AccessSpeed = 0;
1673 if (pcmcia_request_window(p_dev, &cfg_mem->req, &p_dev->win) != 0)
1674 goto next_entry;
1675 if (pcmcia_map_mem_page(p_dev, p_dev->win,
1676 mem->win[0].card_addr) != 0)
1677 goto next_entry;
1678
1679 cfg_mem->data->MmioAddress = (unsigned long) ioremap_nocache(cfg_mem->req.Base, cfg_mem->req.Size);
1680 cfg_mem->data->MmioLength = cfg_mem->req.Size;
1681 }
1682 /* If we got this far, we're cool! */
1683 return 0;
1684 } 1596 }
1597 /* If we got this far, we're cool! */
1598 return 0;
1685 1599
1686next_entry: 1600next_entry:
1687 nsp_dbg(NSP_DEBUG_INIT, "next"); 1601 nsp_dbg(NSP_DEBUG_INIT, "next");
@@ -1693,25 +1607,23 @@ static int nsp_cs_config(struct pcmcia_device *link)
1693{ 1607{
1694 int ret; 1608 int ret;
1695 scsi_info_t *info = link->priv; 1609 scsi_info_t *info = link->priv;
1696 struct nsp_cs_configdata *cfg_mem;
1697 struct Scsi_Host *host; 1610 struct Scsi_Host *host;
1698 nsp_hw_data *data = &nsp_data_base; 1611 nsp_hw_data *data = &nsp_data_base;
1699 1612
1700 nsp_dbg(NSP_DEBUG_INIT, "in"); 1613 nsp_dbg(NSP_DEBUG_INIT, "in");
1701 1614
1702 cfg_mem = kzalloc(sizeof(*cfg_mem), GFP_KERNEL); 1615 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_CHECK_VCC |
1703 if (!cfg_mem) 1616 CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO | CONF_AUTO_SET_IOMEM |
1704 return -ENOMEM; 1617 CONF_AUTO_SET_IO;
1705 cfg_mem->data = data;
1706 1618
1707 ret = pcmcia_loop_config(link, nsp_cs_config_check, cfg_mem); 1619 ret = pcmcia_loop_config(link, nsp_cs_config_check, data);
1708 if (ret) 1620 if (ret)
1709 goto cs_failed; 1621 goto cs_failed;
1710 1622
1711 if (pcmcia_request_irq(link, nspintr)) 1623 if (pcmcia_request_irq(link, nspintr))
1712 goto cs_failed; 1624 goto cs_failed;
1713 1625
1714 ret = pcmcia_request_configuration(link, &link->conf); 1626 ret = pcmcia_enable_device(link);
1715 if (ret) 1627 if (ret)
1716 goto cs_failed; 1628 goto cs_failed;
1717 1629
@@ -1754,41 +1666,16 @@ static int nsp_cs_config(struct pcmcia_device *link)
1754 1666
1755 info->host = host; 1667 info->host = host;
1756 1668
1757 /* Finally, report what we've done */
1758 printk(KERN_INFO "nsp_cs: index 0x%02x: ",
1759 link->conf.ConfigIndex);
1760 if (link->conf.Vpp) {
1761 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
1762 }
1763 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1764 printk(", irq %d", link->irq);
1765 }
1766 if (link->resource[0])
1767 printk(", io %pR", link->resource[0]);
1768 if (link->resource[1])
1769 printk(" & %pR", link->resource[1]);
1770 if (link->win)
1771 printk(", mem 0x%06lx-0x%06lx", cfg_mem->req.Base,
1772 cfg_mem->req.Base+cfg_mem->req.Size-1);
1773 printk("\n");
1774
1775 kfree(cfg_mem);
1776 return 0; 1669 return 0;
1777 1670
1778 cs_failed: 1671 cs_failed:
1779 nsp_dbg(NSP_DEBUG_INIT, "config fail"); 1672 nsp_dbg(NSP_DEBUG_INIT, "config fail");
1780 nsp_cs_release(link); 1673 nsp_cs_release(link);
1781 kfree(cfg_mem);
1782 1674
1783 return -ENODEV; 1675 return -ENODEV;
1784} /* nsp_cs_config */ 1676} /* nsp_cs_config */
1785 1677
1786 1678
1787/*======================================================================
1788 After a card is removed, nsp_cs_release() will unregister the net
1789 device, and release the PCMCIA configuration. If the device is
1790 still open, this will be postponed until it is closed.
1791======================================================================*/
1792static void nsp_cs_release(struct pcmcia_device *link) 1679static void nsp_cs_release(struct pcmcia_device *link)
1793{ 1680{
1794 scsi_info_t *info = link->priv; 1681 scsi_info_t *info = link->priv;
@@ -1807,7 +1694,7 @@ static void nsp_cs_release(struct pcmcia_device *link)
1807 scsi_remove_host(info->host); 1694 scsi_remove_host(info->host);
1808 } 1695 }
1809 1696
1810 if (link->win) { 1697 if (resource_size(link->resource[2])) {
1811 if (data != NULL) { 1698 if (data != NULL) {
1812 iounmap((void *)(data->MmioAddress)); 1699 iounmap((void *)(data->MmioAddress));
1813 } 1700 }
@@ -1877,9 +1764,7 @@ MODULE_DEVICE_TABLE(pcmcia, nsp_cs_ids);
1877 1764
1878static struct pcmcia_driver nsp_driver = { 1765static struct pcmcia_driver nsp_driver = {
1879 .owner = THIS_MODULE, 1766 .owner = THIS_MODULE,
1880 .drv = { 1767 .name = "nsp_cs",
1881 .name = "nsp_cs",
1882 },
1883 .probe = nsp_cs_probe, 1768 .probe = nsp_cs_probe,
1884 .remove = nsp_cs_detach, 1769 .remove = nsp_cs_detach,
1885 .id_table = nsp_cs_ids, 1770 .id_table = nsp_cs_ids,
@@ -1889,14 +1774,11 @@ static struct pcmcia_driver nsp_driver = {
1889 1774
1890static int __init nsp_cs_init(void) 1775static int __init nsp_cs_init(void)
1891{ 1776{
1892 nsp_msg(KERN_INFO, "loading...");
1893
1894 return pcmcia_register_driver(&nsp_driver); 1777 return pcmcia_register_driver(&nsp_driver);
1895} 1778}
1896 1779
1897static void __exit nsp_cs_exit(void) 1780static void __exit nsp_cs_exit(void)
1898{ 1781{
1899 nsp_msg(KERN_INFO, "unloading...");
1900 pcmcia_unregister_driver(&nsp_driver); 1782 pcmcia_unregister_driver(&nsp_driver);
1901} 1783}
1902 1784
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index eb775f1a523c..9c96ca889ec9 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -48,7 +48,6 @@
48#include <scsi/scsi_host.h> 48#include <scsi/scsi_host.h>
49#include "../qlogicfas408.h" 49#include "../qlogicfas408.h"
50 50
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
54#include <pcmcia/ciscode.h> 53#include <pcmcia/ciscode.h>
@@ -156,11 +155,8 @@ static int qlogic_probe(struct pcmcia_device *link)
156 return -ENOMEM; 155 return -ENOMEM;
157 info->p_dev = link; 156 info->p_dev = link;
158 link->priv = info; 157 link->priv = info;
159 link->resource[0]->end = 16; 158 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
160 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; 159 link->config_regs = PRESENT_OPTION;
161 link->conf.Attributes = CONF_ENABLE_IRQ;
162 link->conf.IntType = INT_MEMORY_AND_IO;
163 link->conf.Present = PRESENT_OPTION;
164 160
165 return qlogic_config(link); 161 return qlogic_config(link);
166} /* qlogic_attach */ 162} /* qlogic_attach */
@@ -178,15 +174,11 @@ static void qlogic_detach(struct pcmcia_device *link)
178 174
179/*====================================================================*/ 175/*====================================================================*/
180 176
181static int qlogic_config_check(struct pcmcia_device *p_dev, 177static int qlogic_config_check(struct pcmcia_device *p_dev, void *priv_data)
182 cistpl_cftable_entry_t *cfg,
183 cistpl_cftable_entry_t *dflt,
184 unsigned int vcc,
185 void *priv_data)
186{ 178{
187 p_dev->io_lines = 10; 179 p_dev->io_lines = 10;
188 p_dev->resource[0]->start = cfg->io.win[0].base; 180 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
189 p_dev->resource[0]->end = cfg->io.win[0].len; 181 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
190 182
191 if (p_dev->resource[0]->start == 0) 183 if (p_dev->resource[0]->start == 0)
192 return -ENODEV; 184 return -ENODEV;
@@ -209,7 +201,7 @@ static int qlogic_config(struct pcmcia_device * link)
209 if (!link->irq) 201 if (!link->irq)
210 goto failed; 202 goto failed;
211 203
212 ret = pcmcia_request_configuration(link, &link->conf); 204 ret = pcmcia_enable_device(link);
213 if (ret) 205 if (ret)
214 goto failed; 206 goto failed;
215 207
@@ -264,7 +256,7 @@ static int qlogic_resume(struct pcmcia_device *link)
264{ 256{
265 scsi_info_t *info = link->priv; 257 scsi_info_t *info = link->priv;
266 258
267 pcmcia_request_configuration(link, &link->conf); 259 pcmcia_enable_device(link);
268 if ((info->manf_id == MANFID_MACNICA) || 260 if ((info->manf_id == MANFID_MACNICA) ||
269 (info->manf_id == MANFID_PIONEER) || 261 (info->manf_id == MANFID_PIONEER) ||
270 (info->manf_id == 0x0098)) { 262 (info->manf_id == 0x0098)) {
@@ -302,9 +294,7 @@ MODULE_DEVICE_TABLE(pcmcia, qlogic_ids);
302 294
303static struct pcmcia_driver qlogic_cs_driver = { 295static struct pcmcia_driver qlogic_cs_driver = {
304 .owner = THIS_MODULE, 296 .owner = THIS_MODULE,
305 .drv = {
306 .name = "qlogic_cs", 297 .name = "qlogic_cs",
307 },
308 .probe = qlogic_probe, 298 .probe = qlogic_probe,
309 .remove = qlogic_detach, 299 .remove = qlogic_detach,
310 .id_table = qlogic_ids, 300 .id_table = qlogic_ids,
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 321e390c9120..0ae27cb5cd6f 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -71,7 +71,6 @@
71#include <scsi/scsi.h> 71#include <scsi/scsi.h>
72#include <scsi/scsi_host.h> 72#include <scsi/scsi_host.h>
73 73
74#include <pcmcia/cs.h>
75#include <pcmcia/cistpl.h> 74#include <pcmcia/cistpl.h>
76#include <pcmcia/ds.h> 75#include <pcmcia/ds.h>
77#include <pcmcia/ciscode.h> 76#include <pcmcia/ciscode.h>
@@ -684,15 +683,11 @@ static struct scsi_host_template sym53c500_driver_template = {
684 .shost_attrs = SYM53C500_shost_attrs 683 .shost_attrs = SYM53C500_shost_attrs
685}; 684};
686 685
687static int SYM53C500_config_check(struct pcmcia_device *p_dev, 686static int SYM53C500_config_check(struct pcmcia_device *p_dev, void *priv_data)
688 cistpl_cftable_entry_t *cfg,
689 cistpl_cftable_entry_t *dflt,
690 unsigned int vcc,
691 void *priv_data)
692{ 687{
693 p_dev->io_lines = 10; 688 p_dev->io_lines = 10;
694 p_dev->resource[0]->start = cfg->io.win[0].base; 689 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
695 p_dev->resource[0]->end = cfg->io.win[0].len; 690 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
696 691
697 if (p_dev->resource[0]->start == 0) 692 if (p_dev->resource[0]->start == 0)
698 return -ENODEV; 693 return -ENODEV;
@@ -721,7 +716,7 @@ SYM53C500_config(struct pcmcia_device *link)
721 if (!link->irq) 716 if (!link->irq)
722 goto failed; 717 goto failed;
723 718
724 ret = pcmcia_request_configuration(link, &link->conf); 719 ret = pcmcia_enable_device(link);
725 if (ret) 720 if (ret)
726 goto failed; 721 goto failed;
727 722
@@ -859,10 +854,7 @@ SYM53C500_probe(struct pcmcia_device *link)
859 return -ENOMEM; 854 return -ENOMEM;
860 info->p_dev = link; 855 info->p_dev = link;
861 link->priv = info; 856 link->priv = info;
862 link->resource[0]->end = 16; 857 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
863 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
864 link->conf.Attributes = CONF_ENABLE_IRQ;
865 link->conf.IntType = INT_MEMORY_AND_IO;
866 858
867 return SYM53C500_config(link); 859 return SYM53C500_config(link);
868} /* SYM53C500_attach */ 860} /* SYM53C500_attach */
@@ -881,9 +873,7 @@ MODULE_DEVICE_TABLE(pcmcia, sym53c500_ids);
881 873
882static struct pcmcia_driver sym53c500_cs_driver = { 874static struct pcmcia_driver sym53c500_cs_driver = {
883 .owner = THIS_MODULE, 875 .owner = THIS_MODULE,
884 .drv = { 876 .name = "sym53c500_cs",
885 .name = "sym53c500_cs",
886 },
887 .probe = SYM53C500_probe, 877 .probe = SYM53C500_probe,
888 .remove = SYM53C500_detach, 878 .remove = SYM53C500_detach,
889 .id_table = sym53c500_ids, 879 .id_table = sym53c500_ids,
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index ad0ed212db4a..348fba0a8976 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -1046,13 +1046,13 @@ int scsi_get_vpd_page(struct scsi_device *sdev, u8 page, unsigned char *buf,
1046 1046
1047 /* If the user actually wanted this page, we can skip the rest */ 1047 /* If the user actually wanted this page, we can skip the rest */
1048 if (page == 0) 1048 if (page == 0)
1049 return -EINVAL; 1049 return 0;
1050 1050
1051 for (i = 0; i < min((int)buf[3], buf_len - 4); i++) 1051 for (i = 0; i < min((int)buf[3], buf_len - 4); i++)
1052 if (buf[i + 4] == page) 1052 if (buf[i + 4] == page)
1053 goto found; 1053 goto found;
1054 1054
1055 if (i < buf[3] && i > buf_len) 1055 if (i < buf[3] && i >= buf_len - 4)
1056 /* ran off the end of the buffer, give us benefit of doubt */ 1056 /* ran off the end of the buffer, give us benefit of doubt */
1057 goto found; 1057 goto found;
1058 /* The device claims it doesn't support the requested page */ 1058 /* The device claims it doesn't support the requested page */
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index bbb02f6e917c..0172de197008 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -22,7 +22,6 @@
22#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
23#include <linux/gfp.h> 23#include <linux/gfp.h>
24#include <linux/file.h> 24#include <linux/file.h>
25#include <linux/smp_lock.h>
26#include <net/tcp.h> 25#include <net/tcp.h>
27#include <scsi/scsi.h> 26#include <scsi/scsi.h>
28#include <scsi/scsi_cmnd.h> 27#include <scsi/scsi_cmnd.h>
@@ -323,7 +322,6 @@ static int tgt_open(struct inode *inode, struct file *file)
323{ 322{
324 tx_ring.tr_idx = rx_ring.tr_idx = 0; 323 tx_ring.tr_idx = rx_ring.tr_idx = 0;
325 324
326 cycle_kernel_lock();
327 return 0; 325 return 0;
328} 326}
329 327
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 00baea1e2dbf..58ec8f4efcc2 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -49,7 +49,7 @@ static int sg_version_num = 30534; /* 2 digits for each component */
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/delay.h> 50#include <linux/delay.h>
51#include <linux/blktrace_api.h> 51#include <linux/blktrace_api.h>
52#include <linux/smp_lock.h> 52#include <linux/mutex.h>
53 53
54#include "scsi.h" 54#include "scsi.h"
55#include <scsi/scsi_dbg.h> 55#include <scsi/scsi_dbg.h>
@@ -103,6 +103,8 @@ static int scatter_elem_sz_prev = SG_SCATTER_SZ;
103static int sg_add(struct device *, struct class_interface *); 103static int sg_add(struct device *, struct class_interface *);
104static void sg_remove(struct device *, struct class_interface *); 104static void sg_remove(struct device *, struct class_interface *);
105 105
106static DEFINE_MUTEX(sg_mutex);
107
106static DEFINE_IDR(sg_index_idr); 108static DEFINE_IDR(sg_index_idr);
107static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock 109static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock
108 file descriptor list for device */ 110 file descriptor list for device */
@@ -229,7 +231,7 @@ sg_open(struct inode *inode, struct file *filp)
229 int res; 231 int res;
230 int retval; 232 int retval;
231 233
232 lock_kernel(); 234 mutex_lock(&sg_mutex);
233 nonseekable_open(inode, filp); 235 nonseekable_open(inode, filp);
234 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags)); 236 SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags));
235 sdp = sg_get_dev(dev); 237 sdp = sg_get_dev(dev);
@@ -314,7 +316,7 @@ sdp_put:
314sg_put: 316sg_put:
315 if (sdp) 317 if (sdp)
316 sg_put_dev(sdp); 318 sg_put_dev(sdp);
317 unlock_kernel(); 319 mutex_unlock(&sg_mutex);
318 return retval; 320 return retval;
319} 321}
320 322
@@ -1092,9 +1094,9 @@ sg_unlocked_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1092{ 1094{
1093 int ret; 1095 int ret;
1094 1096
1095 lock_kernel(); 1097 mutex_lock(&sg_mutex);
1096 ret = sg_ioctl(filp, cmd_in, arg); 1098 ret = sg_ioctl(filp, cmd_in, arg);
1097 unlock_kernel(); 1099 mutex_unlock(&sg_mutex);
1098 1100
1099 return ret; 1101 return ret;
1100} 1102}
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index ba9c3e0387ce..e148341079b5 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -44,7 +44,6 @@
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/smp_lock.h>
48#include <linux/slab.h> 47#include <linux/slab.h>
49#include <asm/uaccess.h> 48#include <asm/uaccess.h>
50 49
@@ -76,6 +75,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
76 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ 75 CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \
77 CDC_MRW|CDC_MRW_W|CDC_RAM) 76 CDC_MRW|CDC_MRW_W|CDC_RAM)
78 77
78static DEFINE_MUTEX(sr_mutex);
79static int sr_probe(struct device *); 79static int sr_probe(struct device *);
80static int sr_remove(struct device *); 80static int sr_remove(struct device *);
81static int sr_done(struct scsi_cmnd *); 81static int sr_done(struct scsi_cmnd *);
@@ -470,24 +470,24 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode)
470 struct scsi_cd *cd; 470 struct scsi_cd *cd;
471 int ret = -ENXIO; 471 int ret = -ENXIO;
472 472
473 lock_kernel(); 473 mutex_lock(&sr_mutex);
474 cd = scsi_cd_get(bdev->bd_disk); 474 cd = scsi_cd_get(bdev->bd_disk);
475 if (cd) { 475 if (cd) {
476 ret = cdrom_open(&cd->cdi, bdev, mode); 476 ret = cdrom_open(&cd->cdi, bdev, mode);
477 if (ret) 477 if (ret)
478 scsi_cd_put(cd); 478 scsi_cd_put(cd);
479 } 479 }
480 unlock_kernel(); 480 mutex_unlock(&sr_mutex);
481 return ret; 481 return ret;
482} 482}
483 483
484static int sr_block_release(struct gendisk *disk, fmode_t mode) 484static int sr_block_release(struct gendisk *disk, fmode_t mode)
485{ 485{
486 struct scsi_cd *cd = scsi_cd(disk); 486 struct scsi_cd *cd = scsi_cd(disk);
487 lock_kernel(); 487 mutex_lock(&sr_mutex);
488 cdrom_release(&cd->cdi, mode); 488 cdrom_release(&cd->cdi, mode);
489 scsi_cd_put(cd); 489 scsi_cd_put(cd);
490 unlock_kernel(); 490 mutex_unlock(&sr_mutex);
491 return 0; 491 return 0;
492} 492}
493 493
@@ -499,7 +499,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
499 void __user *argp = (void __user *)arg; 499 void __user *argp = (void __user *)arg;
500 int ret; 500 int ret;
501 501
502 lock_kernel(); 502 mutex_lock(&sr_mutex);
503 503
504 /* 504 /*
505 * Send SCSI addressing ioctls directly to mid level, send other 505 * Send SCSI addressing ioctls directly to mid level, send other
@@ -529,7 +529,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
529 ret = scsi_ioctl(sdev, cmd, argp); 529 ret = scsi_ioctl(sdev, cmd, argp);
530 530
531out: 531out:
532 unlock_kernel(); 532 mutex_unlock(&sr_mutex);
533 return ret; 533 return ret;
534} 534}
535 535
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 24211d0efa6d..afdc3f5d915c 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -39,7 +39,6 @@ static const char *verstr = "20081215";
39#include <linux/cdev.h> 39#include <linux/cdev.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/smp_lock.h>
43 42
44#include <asm/uaccess.h> 43#include <asm/uaccess.h>
45#include <asm/dma.h> 44#include <asm/dma.h>
@@ -76,6 +75,7 @@ static const char *verstr = "20081215";
76#include "st_options.h" 75#include "st_options.h"
77#include "st.h" 76#include "st.h"
78 77
78static DEFINE_MUTEX(st_mutex);
79static int buffer_kbs; 79static int buffer_kbs;
80static int max_sg_segs; 80static int max_sg_segs;
81static int try_direct_io = TRY_DIRECT_IO; 81static int try_direct_io = TRY_DIRECT_IO;
@@ -1180,7 +1180,7 @@ static int st_open(struct inode *inode, struct file *filp)
1180 int dev = TAPE_NR(inode); 1180 int dev = TAPE_NR(inode);
1181 char *name; 1181 char *name;
1182 1182
1183 lock_kernel(); 1183 mutex_lock(&st_mutex);
1184 /* 1184 /*
1185 * We really want to do nonseekable_open(inode, filp); here, but some 1185 * We really want to do nonseekable_open(inode, filp); here, but some
1186 * versions of tar incorrectly call lseek on tapes and bail out if that 1186 * versions of tar incorrectly call lseek on tapes and bail out if that
@@ -1189,7 +1189,7 @@ static int st_open(struct inode *inode, struct file *filp)
1189 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE); 1189 filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
1190 1190
1191 if (!(STp = scsi_tape_get(dev))) { 1191 if (!(STp = scsi_tape_get(dev))) {
1192 unlock_kernel(); 1192 mutex_unlock(&st_mutex);
1193 return -ENXIO; 1193 return -ENXIO;
1194 } 1194 }
1195 1195
@@ -1200,7 +1200,7 @@ static int st_open(struct inode *inode, struct file *filp)
1200 if (STp->in_use) { 1200 if (STp->in_use) {
1201 write_unlock(&st_dev_arr_lock); 1201 write_unlock(&st_dev_arr_lock);
1202 scsi_tape_put(STp); 1202 scsi_tape_put(STp);
1203 unlock_kernel(); 1203 mutex_unlock(&st_mutex);
1204 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); ) 1204 DEB( printk(ST_DEB_MSG "%s: Device already in use.\n", name); )
1205 return (-EBUSY); 1205 return (-EBUSY);
1206 } 1206 }
@@ -1249,14 +1249,14 @@ static int st_open(struct inode *inode, struct file *filp)
1249 retval = (-EIO); 1249 retval = (-EIO);
1250 goto err_out; 1250 goto err_out;
1251 } 1251 }
1252 unlock_kernel(); 1252 mutex_unlock(&st_mutex);
1253 return 0; 1253 return 0;
1254 1254
1255 err_out: 1255 err_out:
1256 normalize_buffer(STp->buffer); 1256 normalize_buffer(STp->buffer);
1257 STp->in_use = 0; 1257 STp->in_use = 0;
1258 scsi_tape_put(STp); 1258 scsi_tape_put(STp);
1259 unlock_kernel(); 1259 mutex_unlock(&st_mutex);
1260 return retval; 1260 return retval;
1261 1261
1262} 1262}
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 12900f7083b0..3198c5335f0b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -458,6 +458,7 @@ config SERIAL_SAMSUNG_UARTS
458 int 458 int
459 depends on ARM && PLAT_SAMSUNG 459 depends on ARM && PLAT_SAMSUNG
460 default 2 if ARCH_S3C2400 460 default 2 if ARCH_S3C2400
461 default 6 if ARCH_S5P6450
461 default 4 if SERIAL_SAMSUNG_UARTS_4 462 default 4 if SERIAL_SAMSUNG_UARTS_4
462 default 3 463 default 3
463 help 464 help
@@ -526,12 +527,12 @@ config SERIAL_S3C24A0
526 Serial port support for the Samsung S3C24A0 SoC 527 Serial port support for the Samsung S3C24A0 SoC
527 528
528config SERIAL_S3C6400 529config SERIAL_S3C6400
529 tristate "Samsung S3C6400/S3C6410/S5P6440/S5PC100 Serial port support" 530 tristate "Samsung S3C6400/S3C6410/S5P6440/S5P6450/S5PC100 Serial port support"
530 depends on SERIAL_SAMSUNG && (CPU_S3C6400 || CPU_S3C6410 || CPU_S5P6440 || CPU_S5PC100) 531 depends on SERIAL_SAMSUNG && (CPU_S3C6400 || CPU_S3C6410 || CPU_S5P6440 || CPU_S5P6450 || CPU_S5PC100)
531 select SERIAL_SAMSUNG_UARTS_4 532 select SERIAL_SAMSUNG_UARTS_4
532 default y 533 default y
533 help 534 help
534 Serial port support for the Samsung S3C6400, S3C6410, S5P6440 535 Serial port support for the Samsung S3C6400, S3C6410, S5P6440, S5P6450
535 and S5PC100 SoCs 536 and S5PC100 SoCs
536 537
537config SERIAL_S5PV210 538config SERIAL_S5PV210
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 50441ffe8e38..2904aa044126 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -472,14 +472,9 @@ pl010_set_termios(struct uart_port *port, struct ktermios *termios,
472 spin_unlock_irqrestore(&uap->port.lock, flags); 472 spin_unlock_irqrestore(&uap->port.lock, flags);
473} 473}
474 474
475static void pl010_set_ldisc(struct uart_port *port) 475static void pl010_set_ldisc(struct uart_port *port, int new)
476{ 476{
477 int line = port->line; 477 if (new == N_PPS) {
478
479 if (line >= port->state->port.tty->driver->num)
480 return;
481
482 if (port->state->port.tty->ldisc->ops->num == N_PPS) {
483 port->flags |= UPF_HARDPPS_CD; 478 port->flags |= UPF_HARDPPS_CD;
484 pl010_enable_ms(port); 479 pl010_enable_ms(port);
485 } else 480 } else
diff --git a/drivers/serial/ioc3_serial.c b/drivers/serial/ioc3_serial.c
index 93de907b1208..ee43efc7bdcc 100644
--- a/drivers/serial/ioc3_serial.c
+++ b/drivers/serial/ioc3_serial.c
@@ -2017,6 +2017,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2017 struct ioc3_port *port; 2017 struct ioc3_port *port;
2018 struct ioc3_port *ports[PORTS_PER_CARD]; 2018 struct ioc3_port *ports[PORTS_PER_CARD];
2019 int phys_port; 2019 int phys_port;
2020 int cnt;
2020 2021
2021 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, is, idd)); 2022 DPRINT_CONFIG(("%s (0x%p, 0x%p)\n", __func__, is, idd));
2022 2023
@@ -2044,6 +2045,7 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2044 if (!port) { 2045 if (!port) {
2045 printk(KERN_WARNING 2046 printk(KERN_WARNING
2046 "IOC3 serial memory not available for port\n"); 2047 "IOC3 serial memory not available for port\n");
2048 ret = -ENOMEM;
2047 goto out4; 2049 goto out4;
2048 } 2050 }
2049 spin_lock_init(&port->ip_lock); 2051 spin_lock_init(&port->ip_lock);
@@ -2146,6 +2148,9 @@ ioc3uart_probe(struct ioc3_submodule *is, struct ioc3_driver_data *idd)
2146 2148
2147 /* error exits that give back resources */ 2149 /* error exits that give back resources */
2148out4: 2150out4:
2151 for (cnt = 0; cnt < phys_port; cnt++)
2152 kfree(ports[cnt]);
2153
2149 kfree(card_ptr); 2154 kfree(card_ptr);
2150 return ret; 2155 return ret;
2151} 2156}
diff --git a/drivers/serial/mfd.c b/drivers/serial/mfd.c
index 6703f3e802a2..dc0967fb9ea6 100644
--- a/drivers/serial/mfd.c
+++ b/drivers/serial/mfd.c
@@ -27,6 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/console.h> 28#include <linux/console.h>
29#include <linux/sysrq.h> 29#include <linux/sysrq.h>
30#include <linux/slab.h>
30#include <linux/serial_reg.h> 31#include <linux/serial_reg.h>
31#include <linux/circ_buf.h> 32#include <linux/circ_buf.h>
32#include <linux/delay.h> 33#include <linux/delay.h>
@@ -1425,7 +1426,6 @@ static void hsu_global_init(void)
1425 } 1426 }
1426 1427
1427 phsu = hsu; 1428 phsu = hsu;
1428
1429 hsu_debugfs_init(hsu); 1429 hsu_debugfs_init(hsu);
1430 return; 1430 return;
1431 1431
@@ -1437,18 +1437,20 @@ err_free_region:
1437 1437
1438static void serial_hsu_remove(struct pci_dev *pdev) 1438static void serial_hsu_remove(struct pci_dev *pdev)
1439{ 1439{
1440 struct hsu_port *hsu; 1440 void *priv = pci_get_drvdata(pdev);
1441 int i; 1441 struct uart_hsu_port *up;
1442 1442
1443 hsu = pci_get_drvdata(pdev); 1443 if (!priv)
1444 if (!hsu)
1445 return; 1444 return;
1446 1445
1447 for (i = 0; i < 3; i++) 1446 /* For port 0/1/2, priv is the address of uart_hsu_port */
1448 uart_remove_one_port(&serial_hsu_reg, &hsu->port[i].port); 1447 if (pdev->device != 0x081E) {
1448 up = priv;
1449 uart_remove_one_port(&serial_hsu_reg, &up->port);
1450 }
1449 1451
1450 pci_set_drvdata(pdev, NULL); 1452 pci_set_drvdata(pdev, NULL);
1451 free_irq(hsu->irq, hsu); 1453 free_irq(pdev->irq, priv);
1452 pci_disable_device(pdev); 1454 pci_disable_device(pdev);
1453} 1455}
1454 1456
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 8dedb266f143..c4399e23565a 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -500,6 +500,7 @@ static int __init mpc512x_psc_fifoc_init(void)
500 psc_fifoc = of_iomap(np, 0); 500 psc_fifoc = of_iomap(np, 0);
501 if (!psc_fifoc) { 501 if (!psc_fifoc) {
502 pr_err("%s: Can't map FIFOC\n", __func__); 502 pr_err("%s: Can't map FIFOC\n", __func__);
503 of_node_put(np);
503 return -ENODEV; 504 return -ENODEV;
504 } 505 }
505 506
diff --git a/drivers/serial/mrst_max3110.c b/drivers/serial/mrst_max3110.c
index f6ad1ecbff79..51c15f58e01e 100644
--- a/drivers/serial/mrst_max3110.c
+++ b/drivers/serial/mrst_max3110.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/irq.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/console.h> 34#include <linux/console.h>
34#include <linux/sysrq.h> 35#include <linux/sysrq.h>
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index b1156ba8ad14..7ac2bf5167cd 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -1101,7 +1101,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
1101 dbg("resource %p (%lx..%lx)\n", res, res->start, res->end); 1101 dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
1102 1102
1103 port->mapbase = res->start; 1103 port->mapbase = res->start;
1104 port->membase = S3C_VA_UART + res->start - (S3C_PA_UART & 0xfff00000); 1104 port->membase = S3C_VA_UART + (res->start & 0xfffff);
1105 ret = platform_get_irq(platdev, 0); 1105 ret = platform_get_irq(platdev, 0);
1106 if (ret < 0) 1106 if (ret < 0)
1107 port->irq = 0; 1107 port->irq = 0;
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 141c69554bd4..93760b2ea172 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -45,7 +45,6 @@
45#include <asm/io.h> 45#include <asm/io.h>
46#include <asm/system.h> 46#include <asm/system.h>
47 47
48#include <pcmcia/cs.h>
49#include <pcmcia/cistpl.h> 48#include <pcmcia/cistpl.h>
50#include <pcmcia/ciscode.h> 49#include <pcmcia/ciscode.h>
51#include <pcmcia/ds.h> 50#include <pcmcia/ds.h>
@@ -183,10 +182,8 @@ static void quirk_config_socket(struct pcmcia_device *link)
183{ 182{
184 struct serial_info *info = link->priv; 183 struct serial_info *info = link->priv;
185 184
186 if (info->multi) { 185 if (info->multi)
187 link->conf.Present |= PRESENT_EXT_STATUS; 186 link->config_flags |= CONF_ENABLE_ESR;
188 link->conf.ExtStatus = ESR_REQ_ATTN_ENA;
189 }
190} 187}
191 188
192static const struct serial_quirk quirks[] = { 189static const struct serial_quirk quirks[] = {
@@ -265,13 +262,6 @@ static const struct serial_quirk quirks[] = {
265static int serial_config(struct pcmcia_device * link); 262static int serial_config(struct pcmcia_device * link);
266 263
267 264
268/*======================================================================
269
270 After a card is removed, serial_remove() will unregister
271 the serial device(s), and release the PCMCIA configuration.
272
273======================================================================*/
274
275static void serial_remove(struct pcmcia_device *link) 265static void serial_remove(struct pcmcia_device *link)
276{ 266{
277 struct serial_info *info = link->priv; 267 struct serial_info *info = link->priv;
@@ -314,14 +304,6 @@ static int serial_resume(struct pcmcia_device *link)
314 return 0; 304 return 0;
315} 305}
316 306
317/*======================================================================
318
319 serial_attach() creates an "instance" of the driver, allocating
320 local data structures for one device. The device is registered
321 with Card Services.
322
323======================================================================*/
324
325static int serial_probe(struct pcmcia_device *link) 307static int serial_probe(struct pcmcia_device *link)
326{ 308{
327 struct serial_info *info; 309 struct serial_info *info;
@@ -335,27 +317,13 @@ static int serial_probe(struct pcmcia_device *link)
335 info->p_dev = link; 317 info->p_dev = link;
336 link->priv = info; 318 link->priv = info;
337 319
338 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8; 320 link->config_flags |= CONF_ENABLE_IRQ;
339 link->resource[0]->end = 8; 321 if (do_sound)
340 link->conf.Attributes = CONF_ENABLE_IRQ; 322 link->config_flags |= CONF_ENABLE_SPKR;
341 if (do_sound) {
342 link->conf.Attributes |= CONF_ENABLE_SPKR;
343 link->conf.Status = CCSR_AUDIO_ENA;
344 }
345 link->conf.IntType = INT_MEMORY_AND_IO;
346 323
347 return serial_config(link); 324 return serial_config(link);
348} 325}
349 326
350/*======================================================================
351
352 This deletes a driver "instance". The device is de-registered
353 with Card Services. If it has been released, all local data
354 structures are freed. Otherwise, the structures will be freed
355 when the device is released.
356
357======================================================================*/
358
359static void serial_detach(struct pcmcia_device *link) 327static void serial_detach(struct pcmcia_device *link)
360{ 328{
361 struct serial_info *info = link->priv; 329 struct serial_info *info = link->priv;
@@ -363,11 +331,6 @@ static void serial_detach(struct pcmcia_device *link)
363 dev_dbg(&link->dev, "serial_detach\n"); 331 dev_dbg(&link->dev, "serial_detach\n");
364 332
365 /* 333 /*
366 * Ensure any outstanding scheduled tasks are completed.
367 */
368 flush_scheduled_work();
369
370 /*
371 * Ensure that the ports have been released. 334 * Ensure that the ports have been released.
372 */ 335 */
373 serial_remove(link); 336 serial_remove(link);
@@ -411,47 +374,66 @@ static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
411 374
412/*====================================================================*/ 375/*====================================================================*/
413 376
414static int simple_config_check(struct pcmcia_device *p_dev, 377static int pfc_config(struct pcmcia_device *p_dev)
415 cistpl_cftable_entry_t *cf, 378{
416 cistpl_cftable_entry_t *dflt, 379 unsigned int port = 0;
417 unsigned int vcc, 380 struct serial_info *info = p_dev->priv;
418 void *priv_data) 381
382 if ((p_dev->resource[1]->end != 0) &&
383 (resource_size(p_dev->resource[1]) == 8)) {
384 port = p_dev->resource[1]->start;
385 info->slave = 1;
386 } else if ((info->manfid == MANFID_OSITECH) &&
387 (resource_size(p_dev->resource[0]) == 0x40)) {
388 port = p_dev->resource[0]->start + 0x28;
389 info->slave = 1;
390 }
391 if (info->slave)
392 return setup_serial(p_dev, info, port, p_dev->irq);
393
394 dev_warn(&p_dev->dev, "no usable port range found, giving up\n");
395 return -ENODEV;
396}
397
398static int simple_config_check(struct pcmcia_device *p_dev, void *priv_data)
419{ 399{
420 static const int size_table[2] = { 8, 16 }; 400 static const int size_table[2] = { 8, 16 };
421 int *try = priv_data; 401 int *try = priv_data;
422 402
423 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM)) 403 if (p_dev->resource[0]->start == 0)
424 p_dev->conf.Vpp = 404 return -ENODEV;
425 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
426 405
427 p_dev->io_lines = ((*try & 0x1) == 0) ? 406 if ((*try & 0x1) == 0)
428 16 : cf->io.flags & CISTPL_IO_LINES_MASK; 407 p_dev->io_lines = 16;
429 408
430 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[(*try >> 1)]) 409 if (p_dev->resource[0]->end != size_table[(*try >> 1)])
431 && (cf->io.win[0].base != 0)) { 410 return -ENODEV;
432 p_dev->resource[0]->start = cf->io.win[0].base; 411
433 if (!pcmcia_request_io(p_dev)) 412 p_dev->resource[0]->end = 8;
434 return 0; 413 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
435 } 414 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
436 return -EINVAL; 415
416 return pcmcia_request_io(p_dev);
437} 417}
438 418
439static int simple_config_check_notpicky(struct pcmcia_device *p_dev, 419static int simple_config_check_notpicky(struct pcmcia_device *p_dev,
440 cistpl_cftable_entry_t *cf,
441 cistpl_cftable_entry_t *dflt,
442 unsigned int vcc,
443 void *priv_data) 420 void *priv_data)
444{ 421{
445 static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; 422 static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
446 int j; 423 int j;
447 424
448 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) { 425 if (p_dev->io_lines > 3)
449 for (j = 0; j < 5; j++) { 426 return -ENODEV;
450 p_dev->resource[0]->start = base[j]; 427
451 p_dev->io_lines = base[j] ? 16 : 3; 428 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
452 if (!pcmcia_request_io(p_dev)) 429 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
453 return 0; 430 p_dev->resource[0]->end = 8;
454 } 431
432 for (j = 0; j < 5; j++) {
433 p_dev->resource[0]->start = base[j];
434 p_dev->io_lines = base[j] ? 16 : 3;
435 if (!pcmcia_request_io(p_dev))
436 return 0;
455 } 437 }
456 return -ENODEV; 438 return -ENODEV;
457} 439}
@@ -461,26 +443,9 @@ static int simple_config(struct pcmcia_device *link)
461 struct serial_info *info = link->priv; 443 struct serial_info *info = link->priv;
462 int i = -ENODEV, try; 444 int i = -ENODEV, try;
463 445
464 /* If the card is already configured, look up the port and irq */
465 if (link->function_config) {
466 unsigned int port = 0;
467 if ((link->resource[1]->end != 0) &&
468 (resource_size(link->resource[1]) == 8)) {
469 port = link->resource[1]->end;
470 info->slave = 1;
471 } else if ((info->manfid == MANFID_OSITECH) &&
472 (resource_size(link->resource[0]) == 0x40)) {
473 port = link->resource[0]->start + 0x28;
474 info->slave = 1;
475 }
476 if (info->slave) {
477 return setup_serial(link, info, port,
478 link->irq);
479 }
480 }
481
482 /* First pass: look for a config entry that looks normal. 446 /* First pass: look for a config entry that looks normal.
483 * Two tries: without IO aliases, then with aliases */ 447 * Two tries: without IO aliases, then with aliases */
448 link->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_SET_IO;
484 for (try = 0; try < 4; try++) 449 for (try = 0; try < 4; try++)
485 if (!pcmcia_loop_config(link, simple_config_check, &try)) 450 if (!pcmcia_loop_config(link, simple_config_check, &try))
486 goto found_port; 451 goto found_port;
@@ -491,13 +456,12 @@ static int simple_config(struct pcmcia_device *link)
491 if (!pcmcia_loop_config(link, simple_config_check_notpicky, NULL)) 456 if (!pcmcia_loop_config(link, simple_config_check_notpicky, NULL))
492 goto found_port; 457 goto found_port;
493 458
494 printk(KERN_NOTICE 459 dev_warn(&link->dev, "no usable port range found, giving up\n");
495 "serial_cs: no usable port range found, giving up\n");
496 return -1; 460 return -1;
497 461
498found_port: 462found_port:
499 if (info->multi && (info->manfid == MANFID_3COM)) 463 if (info->multi && (info->manfid == MANFID_3COM))
500 link->conf.ConfigIndex &= ~(0x08); 464 link->config_index &= ~(0x08);
501 465
502 /* 466 /*
503 * Apply any configuration quirks. 467 * Apply any configuration quirks.
@@ -505,51 +469,50 @@ found_port:
505 if (info->quirk && info->quirk->config) 469 if (info->quirk && info->quirk->config)
506 info->quirk->config(link); 470 info->quirk->config(link);
507 471
508 i = pcmcia_request_configuration(link, &link->conf); 472 i = pcmcia_enable_device(link);
509 if (i != 0) 473 if (i != 0)
510 return -1; 474 return -1;
511 return setup_serial(link, info, link->resource[0]->start, link->irq); 475 return setup_serial(link, info, link->resource[0]->start, link->irq);
512} 476}
513 477
514static int multi_config_check(struct pcmcia_device *p_dev, 478static int multi_config_check(struct pcmcia_device *p_dev, void *priv_data)
515 cistpl_cftable_entry_t *cf,
516 cistpl_cftable_entry_t *dflt,
517 unsigned int vcc,
518 void *priv_data)
519{ 479{
520 int *base2 = priv_data; 480 int *multi = priv_data;
481
482 if (p_dev->resource[1]->end)
483 return -EINVAL;
521 484
522 /* The quad port cards have bad CIS's, so just look for a 485 /* The quad port cards have bad CIS's, so just look for a
523 window larger than 8 ports and assume it will be right */ 486 window larger than 8 ports and assume it will be right */
524 if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) { 487 if (p_dev->resource[0]->end <= 8)
525 p_dev->resource[0]->start = cf->io.win[0].base; 488 return -EINVAL;
526 p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK; 489
527 if (!pcmcia_request_io(p_dev)) { 490 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
528 *base2 = p_dev->resource[0]->start + 8; 491 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
529 return 0; 492 p_dev->resource[0]->end = *multi * 8;
530 } 493
531 } 494 if (pcmcia_request_io(p_dev))
532 return -ENODEV; 495 return -ENODEV;
496 return 0;
533} 497}
534 498
535static int multi_config_check_notpicky(struct pcmcia_device *p_dev, 499static int multi_config_check_notpicky(struct pcmcia_device *p_dev,
536 cistpl_cftable_entry_t *cf,
537 cistpl_cftable_entry_t *dflt,
538 unsigned int vcc,
539 void *priv_data) 500 void *priv_data)
540{ 501{
541 int *base2 = priv_data; 502 int *base2 = priv_data;
542 503
543 if (cf->io.nwin == 2) { 504 if (!p_dev->resource[0]->end || !p_dev->resource[1]->end)
544 p_dev->resource[0]->start = cf->io.win[0].base; 505 return -ENODEV;
545 p_dev->resource[1]->start = cf->io.win[1].base; 506
546 p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK; 507 p_dev->resource[0]->end = p_dev->resource[1]->end = 8;
547 if (!pcmcia_request_io(p_dev)) { 508 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
548 *base2 = p_dev->resource[1]->start; 509 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
549 return 0; 510
550 } 511 if (pcmcia_request_io(p_dev))
551 } 512 return -ENODEV;
552 return -ENODEV; 513
514 *base2 = p_dev->resource[0]->start + 8;
515 return 0;
553} 516}
554 517
555static int multi_config(struct pcmcia_device *link) 518static int multi_config(struct pcmcia_device *link)
@@ -557,23 +520,23 @@ static int multi_config(struct pcmcia_device *link)
557 struct serial_info *info = link->priv; 520 struct serial_info *info = link->priv;
558 int i, base2 = 0; 521 int i, base2 = 0;
559 522
523 link->config_flags |= CONF_AUTO_SET_IO;
560 /* First, look for a generic full-sized window */ 524 /* First, look for a generic full-sized window */
561 link->resource[0]->end = info->multi * 8; 525 if (!pcmcia_loop_config(link, multi_config_check, &info->multi))
562 if (pcmcia_loop_config(link, multi_config_check, &base2)) { 526 base2 = link->resource[0]->start + 8;
527 else {
563 /* If that didn't work, look for two windows */ 528 /* If that didn't work, look for two windows */
564 link->resource[0]->end = link->resource[1]->end = 8;
565 info->multi = 2; 529 info->multi = 2;
566 if (pcmcia_loop_config(link, multi_config_check_notpicky, 530 if (pcmcia_loop_config(link, multi_config_check_notpicky,
567 &base2)) { 531 &base2)) {
568 printk(KERN_NOTICE "serial_cs: no usable port range" 532 dev_warn(&link->dev, "no usable port range "
569 "found, giving up\n"); 533 "found, giving up\n");
570 return -ENODEV; 534 return -ENODEV;
571 } 535 }
572 } 536 }
573 537
574 if (!link->irq) 538 if (!link->irq)
575 dev_warn(&link->dev, 539 dev_warn(&link->dev, "no usable IRQ found, continuing...\n");
576 "serial_cs: no usable IRQ found, continuing...\n");
577 540
578 /* 541 /*
579 * Apply any configuration quirks. 542 * Apply any configuration quirks.
@@ -581,7 +544,7 @@ static int multi_config(struct pcmcia_device *link)
581 if (info->quirk && info->quirk->config) 544 if (info->quirk && info->quirk->config)
582 info->quirk->config(link); 545 info->quirk->config(link);
583 546
584 i = pcmcia_request_configuration(link, &link->conf); 547 i = pcmcia_enable_device(link);
585 if (i != 0) 548 if (i != 0)
586 return -ENODEV; 549 return -ENODEV;
587 550
@@ -593,11 +556,11 @@ static int multi_config(struct pcmcia_device *link)
593 info->prodid == PRODID_POSSIO_GCC)) { 556 info->prodid == PRODID_POSSIO_GCC)) {
594 int err; 557 int err;
595 558
596 if (link->conf.ConfigIndex == 1 || 559 if (link->config_index == 1 ||
597 link->conf.ConfigIndex == 3) { 560 link->config_index == 3) {
598 err = setup_serial(link, info, base2, 561 err = setup_serial(link, info, base2,
599 link->irq); 562 link->irq);
600 base2 = link->resource[0]->start;; 563 base2 = link->resource[0]->start;
601 } else { 564 } else {
602 err = setup_serial(link, info, link->resource[0]->start, 565 err = setup_serial(link, info, link->resource[0]->start,
603 link->irq); 566 link->irq);
@@ -621,33 +584,24 @@ static int multi_config(struct pcmcia_device *link)
621 return 0; 584 return 0;
622} 585}
623 586
624static int serial_check_for_multi(struct pcmcia_device *p_dev, 587static int serial_check_for_multi(struct pcmcia_device *p_dev, void *priv_data)
625 cistpl_cftable_entry_t *cf,
626 cistpl_cftable_entry_t *dflt,
627 unsigned int vcc,
628 void *priv_data)
629{ 588{
630 struct serial_info *info = p_dev->priv; 589 struct serial_info *info = p_dev->priv;
631 590
632 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0)) 591 if (!p_dev->resource[0]->end)
633 info->multi = cf->io.win[0].len >> 3; 592 return -EINVAL;
593
594 if ((!p_dev->resource[1]->end) && (p_dev->resource[0]->end % 8 == 0))
595 info->multi = p_dev->resource[0]->end >> 3;
634 596
635 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) && 597 if ((p_dev->resource[1]->end) && (p_dev->resource[0]->end == 8)
636 (cf->io.win[1].len == 8)) 598 && (p_dev->resource[1]->end == 8))
637 info->multi = 2; 599 info->multi = 2;
638 600
639 return 0; /* break */ 601 return 0; /* break */
640} 602}
641 603
642 604
643/*======================================================================
644
645 serial_config() is scheduled to run after a CARD_INSERTION event
646 is received, to configure the PCMCIA socket, and to make the
647 serial device available to the system.
648
649======================================================================*/
650
651static int serial_config(struct pcmcia_device * link) 605static int serial_config(struct pcmcia_device * link)
652{ 606{
653 struct serial_info *info = link->priv; 607 struct serial_info *info = link->priv;
@@ -675,6 +629,7 @@ static int serial_config(struct pcmcia_device * link)
675 multifunction cards that ask for appropriate IO port ranges */ 629 multifunction cards that ask for appropriate IO port ranges */
676 if ((info->multi == 0) && 630 if ((info->multi == 0) &&
677 (link->has_func_id) && 631 (link->has_func_id) &&
632 (link->socket->pcmcia_pfc == 0) &&
678 ((link->func_id == CISTPL_FUNCID_MULTI) || 633 ((link->func_id == CISTPL_FUNCID_MULTI) ||
679 (link->func_id == CISTPL_FUNCID_SERIAL))) 634 (link->func_id == CISTPL_FUNCID_SERIAL)))
680 pcmcia_loop_config(link, serial_check_for_multi, info); 635 pcmcia_loop_config(link, serial_check_for_multi, info);
@@ -685,7 +640,13 @@ static int serial_config(struct pcmcia_device * link)
685 if (info->quirk && info->quirk->multi != -1) 640 if (info->quirk && info->quirk->multi != -1)
686 info->multi = info->quirk->multi; 641 info->multi = info->quirk->multi;
687 642
688 if (info->multi > 1) 643 dev_info(&link->dev,
644 "trying to set up [0x%04x:0x%04x] (pfc: %d, multi: %d, quirk: %p)\n",
645 link->manf_id, link->card_id,
646 link->socket->pcmcia_pfc, info->multi, info->quirk);
647 if (link->socket->pcmcia_pfc)
648 i = pfc_config(link);
649 else if (info->multi > 1)
689 i = multi_config(link); 650 i = multi_config(link);
690 else 651 else
691 i = simple_config(link); 652 i = simple_config(link);
@@ -704,7 +665,7 @@ static int serial_config(struct pcmcia_device * link)
704 return 0; 665 return 0;
705 666
706failed: 667failed:
707 dev_warn(&link->dev, "serial_cs: failed to initialize\n"); 668 dev_warn(&link->dev, "failed to initialize\n");
708 serial_remove(link); 669 serial_remove(link);
709 return -ENODEV; 670 return -ENODEV;
710} 671}
@@ -884,9 +845,7 @@ MODULE_FIRMWARE("cis/RS-COM-2P.cis");
884 845
885static struct pcmcia_driver serial_cs_driver = { 846static struct pcmcia_driver serial_cs_driver = {
886 .owner = THIS_MODULE, 847 .owner = THIS_MODULE,
887 .drv = { 848 .name = "serial_cs",
888 .name = "serial_cs",
889 },
890 .probe = serial_probe, 849 .probe = serial_probe,
891 .remove = serial_detach, 850 .remove = serial_detach,
892 .id_table = serial_ids, 851 .id_table = serial_ids,
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 91c2f4f3af10..4b9eec68fad6 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -143,10 +143,26 @@ config SPI_GPIO
143 GPIO operations, you should be able to leverage that for better 143 GPIO operations, you should be able to leverage that for better
144 speed with a custom version of this driver; see the source code. 144 speed with a custom version of this driver; see the source code.
145 145
146config SPI_IMX_VER_IMX1
147 def_bool y if SOC_IMX1
148
149config SPI_IMX_VER_0_0
150 def_bool y if SOC_IMX21 || SOC_IMX27
151
152config SPI_IMX_VER_0_4
153 def_bool y if ARCH_MX31
154
155config SPI_IMX_VER_0_7
156 def_bool y if ARCH_MX25 || ARCH_MX35 || ARCH_MX51
157
158config SPI_IMX_VER_2_3
159 def_bool y if ARCH_MX51
160
146config SPI_IMX 161config SPI_IMX
147 tristate "Freescale i.MX SPI controllers" 162 tristate "Freescale i.MX SPI controllers"
148 depends on ARCH_MXC 163 depends on ARCH_MXC
149 select SPI_BITBANG 164 select SPI_BITBANG
165 default m if IMX_HAVE_PLATFORM_SPI_IMX
150 help 166 help
151 This enables using the Freescale i.MX SPI controllers in master 167 This enables using the Freescale i.MX SPI controllers in master
152 mode. 168 mode.
@@ -182,12 +198,27 @@ config SPI_MPC512x_PSC
182 This enables using the Freescale MPC5121 Programmable Serial 198 This enables using the Freescale MPC5121 Programmable Serial
183 Controller in SPI master mode. 199 Controller in SPI master mode.
184 200
185config SPI_MPC8xxx 201config SPI_FSL_LIB
186 tristate "Freescale MPC8xxx SPI controller" 202 tristate
203 depends on FSL_SOC
204
205config SPI_FSL_SPI
206 tristate "Freescale SPI controller"
187 depends on FSL_SOC 207 depends on FSL_SOC
208 select SPI_FSL_LIB
188 help 209 help
189 This enables using the Freescale MPC8xxx SPI controllers in master 210 This enables using the Freescale SPI controllers in master mode.
190 mode. 211 MPC83xx platform uses the controller in cpu mode or CPM/QE mode.
212 MPC8569 uses the controller in QE mode, MPC8610 in cpu mode.
213
214config SPI_FSL_ESPI
215 tristate "Freescale eSPI controller"
216 depends on FSL_SOC
217 select SPI_FSL_LIB
218 help
219 This enables using the Freescale eSPI controllers in master mode.
220 From MPC8536, 85xx platform uses the controller, and all P10xx,
221 P20xx, P30xx,P40xx, P50xx uses this controller.
191 222
192config SPI_OMAP_UWIRE 223config SPI_OMAP_UWIRE
193 tristate "OMAP1 MicroWire" 224 tristate "OMAP1 MicroWire"
@@ -298,6 +329,13 @@ config SPI_STMP3XXX
298 help 329 help
299 SPI driver for Freescale STMP37xx/378x SoC SSP interface 330 SPI driver for Freescale STMP37xx/378x SoC SSP interface
300 331
332config SPI_TOPCLIFF_PCH
333 tristate "Topcliff PCH SPI Controller"
334 depends on PCI
335 help
336 SPI driver for the Topcliff PCH (Platform Controller Hub) SPI bus
337 used in some x86 embedded processors.
338
301config SPI_TXX9 339config SPI_TXX9
302 tristate "Toshiba TXx9 SPI controller" 340 tristate "Toshiba TXx9 SPI controller"
303 depends on GENERIC_GPIO && CPU_TX49XX 341 depends on GENERIC_GPIO && CPU_TX49XX
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index e9cbd18217a0..557aaadf56b2 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -2,9 +2,7 @@
2# Makefile for kernel SPI drivers. 2# Makefile for kernel SPI drivers.
3# 3#
4 4
5ifeq ($(CONFIG_SPI_DEBUG),y) 5ccflags-$(CONFIG_SPI_DEBUG) := -DDEBUG
6EXTRA_CFLAGS += -DDEBUG
7endif
8 6
9# small core, mostly translating board-specific 7# small core, mostly translating board-specific
10# config declarations into driver model code 8# config declarations into driver model code
@@ -34,11 +32,14 @@ obj-$(CONFIG_SPI_PL022) += amba-pl022.o
34obj-$(CONFIG_SPI_MPC512x_PSC) += mpc512x_psc_spi.o 32obj-$(CONFIG_SPI_MPC512x_PSC) += mpc512x_psc_spi.o
35obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o 33obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
36obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o 34obj-$(CONFIG_SPI_MPC52xx) += mpc52xx_spi.o
37obj-$(CONFIG_SPI_MPC8xxx) += spi_mpc8xxx.o 35obj-$(CONFIG_SPI_FSL_LIB) += spi_fsl_lib.o
36obj-$(CONFIG_SPI_FSL_ESPI) += spi_fsl_espi.o
37obj-$(CONFIG_SPI_FSL_SPI) += spi_fsl_spi.o
38obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o 38obj-$(CONFIG_SPI_PPC4xx) += spi_ppc4xx.o
39obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o 39obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
40obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx_hw.o 40obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx_hw.o
41obj-$(CONFIG_SPI_S3C64XX) += spi_s3c64xx.o 41obj-$(CONFIG_SPI_S3C64XX) += spi_s3c64xx.o
42obj-$(CONFIG_SPI_TOPCLIFF_PCH) += spi_topcliff_pch.o
42obj-$(CONFIG_SPI_TXX9) += spi_txx9.o 43obj-$(CONFIG_SPI_TXX9) += spi_txx9.o
43obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o 44obj-$(CONFIG_SPI_XILINX) += xilinx_spi.o
44obj-$(CONFIG_SPI_XILINX_OF) += xilinx_spi_of.o 45obj-$(CONFIG_SPI_XILINX_OF) += xilinx_spi_of.o
diff --git a/drivers/spi/amba-pl022.c b/drivers/spi/amba-pl022.c
index acd35d1ebd12..fb3d1b31772d 100644
--- a/drivers/spi/amba-pl022.c
+++ b/drivers/spi/amba-pl022.c
@@ -27,7 +27,6 @@
27/* 27/*
28 * TODO: 28 * TODO:
29 * - add timeout on polled transfers 29 * - add timeout on polled transfers
30 * - add generic DMA framework support
31 */ 30 */
32 31
33#include <linux/init.h> 32#include <linux/init.h>
@@ -45,6 +44,9 @@
45#include <linux/amba/pl022.h> 44#include <linux/amba/pl022.h>
46#include <linux/io.h> 45#include <linux/io.h>
47#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/dmaengine.h>
48#include <linux/dma-mapping.h>
49#include <linux/scatterlist.h>
48 50
49/* 51/*
50 * This macro is used to define some register default values. 52 * This macro is used to define some register default values.
@@ -381,6 +383,14 @@ struct pl022 {
381 enum ssp_reading read; 383 enum ssp_reading read;
382 enum ssp_writing write; 384 enum ssp_writing write;
383 u32 exp_fifo_level; 385 u32 exp_fifo_level;
386 /* DMA settings */
387#ifdef CONFIG_DMA_ENGINE
388 struct dma_chan *dma_rx_channel;
389 struct dma_chan *dma_tx_channel;
390 struct sg_table sgt_rx;
391 struct sg_table sgt_tx;
392 char *dummypage;
393#endif
384}; 394};
385 395
386/** 396/**
@@ -406,7 +416,7 @@ struct chip_data {
406 u16 dmacr; 416 u16 dmacr;
407 u16 cpsr; 417 u16 cpsr;
408 u8 n_bytes; 418 u8 n_bytes;
409 u8 enable_dma:1; 419 bool enable_dma;
410 enum ssp_reading read; 420 enum ssp_reading read;
411 enum ssp_writing write; 421 enum ssp_writing write;
412 void (*cs_control) (u32 command); 422 void (*cs_control) (u32 command);
@@ -503,8 +513,9 @@ static void giveback(struct pl022 *pl022)
503 msg->state = NULL; 513 msg->state = NULL;
504 if (msg->complete) 514 if (msg->complete)
505 msg->complete(msg->context); 515 msg->complete(msg->context);
506 /* This message is completed, so let's turn off the clock! */ 516 /* This message is completed, so let's turn off the clocks! */
507 clk_disable(pl022->clk); 517 clk_disable(pl022->clk);
518 amba_pclk_disable(pl022->adev);
508} 519}
509 520
510/** 521/**
@@ -762,6 +773,371 @@ static void *next_transfer(struct pl022 *pl022)
762 } 773 }
763 return STATE_DONE; 774 return STATE_DONE;
764} 775}
776
777/*
778 * This DMA functionality is only compiled in if we have
779 * access to the generic DMA devices/DMA engine.
780 */
781#ifdef CONFIG_DMA_ENGINE
782static void unmap_free_dma_scatter(struct pl022 *pl022)
783{
784 /* Unmap and free the SG tables */
785 dma_unmap_sg(&pl022->adev->dev, pl022->sgt_tx.sgl,
786 pl022->sgt_tx.nents, DMA_TO_DEVICE);
787 dma_unmap_sg(&pl022->adev->dev, pl022->sgt_rx.sgl,
788 pl022->sgt_rx.nents, DMA_FROM_DEVICE);
789 sg_free_table(&pl022->sgt_rx);
790 sg_free_table(&pl022->sgt_tx);
791}
792
793static void dma_callback(void *data)
794{
795 struct pl022 *pl022 = data;
796 struct spi_message *msg = pl022->cur_msg;
797
798 BUG_ON(!pl022->sgt_rx.sgl);
799
800#ifdef VERBOSE_DEBUG
801 /*
802 * Optionally dump out buffers to inspect contents, this is
803 * good if you want to convince yourself that the loopback
804 * read/write contents are the same, when adopting to a new
805 * DMA engine.
806 */
807 {
808 struct scatterlist *sg;
809 unsigned int i;
810
811 dma_sync_sg_for_cpu(&pl022->adev->dev,
812 pl022->sgt_rx.sgl,
813 pl022->sgt_rx.nents,
814 DMA_FROM_DEVICE);
815
816 for_each_sg(pl022->sgt_rx.sgl, sg, pl022->sgt_rx.nents, i) {
817 dev_dbg(&pl022->adev->dev, "SPI RX SG ENTRY: %d", i);
818 print_hex_dump(KERN_ERR, "SPI RX: ",
819 DUMP_PREFIX_OFFSET,
820 16,
821 1,
822 sg_virt(sg),
823 sg_dma_len(sg),
824 1);
825 }
826 for_each_sg(pl022->sgt_tx.sgl, sg, pl022->sgt_tx.nents, i) {
827 dev_dbg(&pl022->adev->dev, "SPI TX SG ENTRY: %d", i);
828 print_hex_dump(KERN_ERR, "SPI TX: ",
829 DUMP_PREFIX_OFFSET,
830 16,
831 1,
832 sg_virt(sg),
833 sg_dma_len(sg),
834 1);
835 }
836 }
837#endif
838
839 unmap_free_dma_scatter(pl022);
840
841 /* Update total bytes transfered */
842 msg->actual_length += pl022->cur_transfer->len;
843 if (pl022->cur_transfer->cs_change)
844 pl022->cur_chip->
845 cs_control(SSP_CHIP_DESELECT);
846
847 /* Move to next transfer */
848 msg->state = next_transfer(pl022);
849 tasklet_schedule(&pl022->pump_transfers);
850}
851
852static void setup_dma_scatter(struct pl022 *pl022,
853 void *buffer,
854 unsigned int length,
855 struct sg_table *sgtab)
856{
857 struct scatterlist *sg;
858 int bytesleft = length;
859 void *bufp = buffer;
860 int mapbytes;
861 int i;
862
863 if (buffer) {
864 for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
865 /*
866 * If there are less bytes left than what fits
867 * in the current page (plus page alignment offset)
868 * we just feed in this, else we stuff in as much
869 * as we can.
870 */
871 if (bytesleft < (PAGE_SIZE - offset_in_page(bufp)))
872 mapbytes = bytesleft;
873 else
874 mapbytes = PAGE_SIZE - offset_in_page(bufp);
875 sg_set_page(sg, virt_to_page(bufp),
876 mapbytes, offset_in_page(bufp));
877 bufp += mapbytes;
878 bytesleft -= mapbytes;
879 dev_dbg(&pl022->adev->dev,
880 "set RX/TX target page @ %p, %d bytes, %d left\n",
881 bufp, mapbytes, bytesleft);
882 }
883 } else {
884 /* Map the dummy buffer on every page */
885 for_each_sg(sgtab->sgl, sg, sgtab->nents, i) {
886 if (bytesleft < PAGE_SIZE)
887 mapbytes = bytesleft;
888 else
889 mapbytes = PAGE_SIZE;
890 sg_set_page(sg, virt_to_page(pl022->dummypage),
891 mapbytes, 0);
892 bytesleft -= mapbytes;
893 dev_dbg(&pl022->adev->dev,
894 "set RX/TX to dummy page %d bytes, %d left\n",
895 mapbytes, bytesleft);
896
897 }
898 }
899 BUG_ON(bytesleft);
900}
901
902/**
903 * configure_dma - configures the channels for the next transfer
904 * @pl022: SSP driver's private data structure
905 */
906static int configure_dma(struct pl022 *pl022)
907{
908 struct dma_slave_config rx_conf = {
909 .src_addr = SSP_DR(pl022->phybase),
910 .direction = DMA_FROM_DEVICE,
911 .src_maxburst = pl022->vendor->fifodepth >> 1,
912 };
913 struct dma_slave_config tx_conf = {
914 .dst_addr = SSP_DR(pl022->phybase),
915 .direction = DMA_TO_DEVICE,
916 .dst_maxburst = pl022->vendor->fifodepth >> 1,
917 };
918 unsigned int pages;
919 int ret;
920 int sglen;
921 struct dma_chan *rxchan = pl022->dma_rx_channel;
922 struct dma_chan *txchan = pl022->dma_tx_channel;
923 struct dma_async_tx_descriptor *rxdesc;
924 struct dma_async_tx_descriptor *txdesc;
925 dma_cookie_t cookie;
926
927 /* Check that the channels are available */
928 if (!rxchan || !txchan)
929 return -ENODEV;
930
931 switch (pl022->read) {
932 case READING_NULL:
933 /* Use the same as for writing */
934 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
935 break;
936 case READING_U8:
937 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
938 break;
939 case READING_U16:
940 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
941 break;
942 case READING_U32:
943 rx_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
944 break;
945 }
946
947 switch (pl022->write) {
948 case WRITING_NULL:
949 /* Use the same as for reading */
950 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED;
951 break;
952 case WRITING_U8:
953 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
954 break;
955 case WRITING_U16:
956 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
957 break;
958 case WRITING_U32:
959 tx_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;;
960 break;
961 }
962
963 /* SPI pecularity: we need to read and write the same width */
964 if (rx_conf.src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
965 rx_conf.src_addr_width = tx_conf.dst_addr_width;
966 if (tx_conf.dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
967 tx_conf.dst_addr_width = rx_conf.src_addr_width;
968 BUG_ON(rx_conf.src_addr_width != tx_conf.dst_addr_width);
969
970 rxchan->device->device_control(rxchan, DMA_SLAVE_CONFIG,
971 (unsigned long) &rx_conf);
972 txchan->device->device_control(txchan, DMA_SLAVE_CONFIG,
973 (unsigned long) &tx_conf);
974
975 /* Create sglists for the transfers */
976 pages = (pl022->cur_transfer->len >> PAGE_SHIFT) + 1;
977 dev_dbg(&pl022->adev->dev, "using %d pages for transfer\n", pages);
978
979 ret = sg_alloc_table(&pl022->sgt_rx, pages, GFP_KERNEL);
980 if (ret)
981 goto err_alloc_rx_sg;
982
983 ret = sg_alloc_table(&pl022->sgt_tx, pages, GFP_KERNEL);
984 if (ret)
985 goto err_alloc_tx_sg;
986
987 /* Fill in the scatterlists for the RX+TX buffers */
988 setup_dma_scatter(pl022, pl022->rx,
989 pl022->cur_transfer->len, &pl022->sgt_rx);
990 setup_dma_scatter(pl022, pl022->tx,
991 pl022->cur_transfer->len, &pl022->sgt_tx);
992
993 /* Map DMA buffers */
994 sglen = dma_map_sg(&pl022->adev->dev, pl022->sgt_rx.sgl,
995 pl022->sgt_rx.nents, DMA_FROM_DEVICE);
996 if (!sglen)
997 goto err_rx_sgmap;
998
999 sglen = dma_map_sg(&pl022->adev->dev, pl022->sgt_tx.sgl,
1000 pl022->sgt_tx.nents, DMA_TO_DEVICE);
1001 if (!sglen)
1002 goto err_tx_sgmap;
1003
1004 /* Send both scatterlists */
1005 rxdesc = rxchan->device->device_prep_slave_sg(rxchan,
1006 pl022->sgt_rx.sgl,
1007 pl022->sgt_rx.nents,
1008 DMA_FROM_DEVICE,
1009 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1010 if (!rxdesc)
1011 goto err_rxdesc;
1012
1013 txdesc = txchan->device->device_prep_slave_sg(txchan,
1014 pl022->sgt_tx.sgl,
1015 pl022->sgt_tx.nents,
1016 DMA_TO_DEVICE,
1017 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1018 if (!txdesc)
1019 goto err_txdesc;
1020
1021 /* Put the callback on the RX transfer only, that should finish last */
1022 rxdesc->callback = dma_callback;
1023 rxdesc->callback_param = pl022;
1024
1025 /* Submit and fire RX and TX with TX last so we're ready to read! */
1026 cookie = rxdesc->tx_submit(rxdesc);
1027 if (dma_submit_error(cookie))
1028 goto err_submit_rx;
1029 cookie = txdesc->tx_submit(txdesc);
1030 if (dma_submit_error(cookie))
1031 goto err_submit_tx;
1032 rxchan->device->device_issue_pending(rxchan);
1033 txchan->device->device_issue_pending(txchan);
1034
1035 return 0;
1036
1037err_submit_tx:
1038err_submit_rx:
1039err_txdesc:
1040 txchan->device->device_control(txchan, DMA_TERMINATE_ALL, 0);
1041err_rxdesc:
1042 rxchan->device->device_control(rxchan, DMA_TERMINATE_ALL, 0);
1043 dma_unmap_sg(&pl022->adev->dev, pl022->sgt_tx.sgl,
1044 pl022->sgt_tx.nents, DMA_TO_DEVICE);
1045err_tx_sgmap:
1046 dma_unmap_sg(&pl022->adev->dev, pl022->sgt_rx.sgl,
1047 pl022->sgt_tx.nents, DMA_FROM_DEVICE);
1048err_rx_sgmap:
1049 sg_free_table(&pl022->sgt_tx);
1050err_alloc_tx_sg:
1051 sg_free_table(&pl022->sgt_rx);
1052err_alloc_rx_sg:
1053 return -ENOMEM;
1054}
1055
1056static int __init pl022_dma_probe(struct pl022 *pl022)
1057{
1058 dma_cap_mask_t mask;
1059
1060 /* Try to acquire a generic DMA engine slave channel */
1061 dma_cap_zero(mask);
1062 dma_cap_set(DMA_SLAVE, mask);
1063 /*
1064 * We need both RX and TX channels to do DMA, else do none
1065 * of them.
1066 */
1067 pl022->dma_rx_channel = dma_request_channel(mask,
1068 pl022->master_info->dma_filter,
1069 pl022->master_info->dma_rx_param);
1070 if (!pl022->dma_rx_channel) {
1071 dev_err(&pl022->adev->dev, "no RX DMA channel!\n");
1072 goto err_no_rxchan;
1073 }
1074
1075 pl022->dma_tx_channel = dma_request_channel(mask,
1076 pl022->master_info->dma_filter,
1077 pl022->master_info->dma_tx_param);
1078 if (!pl022->dma_tx_channel) {
1079 dev_err(&pl022->adev->dev, "no TX DMA channel!\n");
1080 goto err_no_txchan;
1081 }
1082
1083 pl022->dummypage = kmalloc(PAGE_SIZE, GFP_KERNEL);
1084 if (!pl022->dummypage) {
1085 dev_err(&pl022->adev->dev, "no DMA dummypage!\n");
1086 goto err_no_dummypage;
1087 }
1088
1089 dev_info(&pl022->adev->dev, "setup for DMA on RX %s, TX %s\n",
1090 dma_chan_name(pl022->dma_rx_channel),
1091 dma_chan_name(pl022->dma_tx_channel));
1092
1093 return 0;
1094
1095err_no_dummypage:
1096 dma_release_channel(pl022->dma_tx_channel);
1097err_no_txchan:
1098 dma_release_channel(pl022->dma_rx_channel);
1099 pl022->dma_rx_channel = NULL;
1100err_no_rxchan:
1101 return -ENODEV;
1102}
1103
1104static void terminate_dma(struct pl022 *pl022)
1105{
1106 struct dma_chan *rxchan = pl022->dma_rx_channel;
1107 struct dma_chan *txchan = pl022->dma_tx_channel;
1108
1109 rxchan->device->device_control(rxchan, DMA_TERMINATE_ALL, 0);
1110 txchan->device->device_control(txchan, DMA_TERMINATE_ALL, 0);
1111 unmap_free_dma_scatter(pl022);
1112}
1113
1114static void pl022_dma_remove(struct pl022 *pl022)
1115{
1116 if (pl022->busy)
1117 terminate_dma(pl022);
1118 if (pl022->dma_tx_channel)
1119 dma_release_channel(pl022->dma_tx_channel);
1120 if (pl022->dma_rx_channel)
1121 dma_release_channel(pl022->dma_rx_channel);
1122 kfree(pl022->dummypage);
1123}
1124
1125#else
1126static inline int configure_dma(struct pl022 *pl022)
1127{
1128 return -ENODEV;
1129}
1130
1131static inline int pl022_dma_probe(struct pl022 *pl022)
1132{
1133 return 0;
1134}
1135
1136static inline void pl022_dma_remove(struct pl022 *pl022)
1137{
1138}
1139#endif
1140
765/** 1141/**
766 * pl022_interrupt_handler - Interrupt handler for SSP controller 1142 * pl022_interrupt_handler - Interrupt handler for SSP controller
767 * 1143 *
@@ -793,14 +1169,17 @@ static irqreturn_t pl022_interrupt_handler(int irq, void *dev_id)
793 if (unlikely(!irq_status)) 1169 if (unlikely(!irq_status))
794 return IRQ_NONE; 1170 return IRQ_NONE;
795 1171
796 /* This handles the error code interrupts */ 1172 /*
1173 * This handles the FIFO interrupts, the timeout
1174 * interrupts are flatly ignored, they cannot be
1175 * trusted.
1176 */
797 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) { 1177 if (unlikely(irq_status & SSP_MIS_MASK_RORMIS)) {
798 /* 1178 /*
799 * Overrun interrupt - bail out since our Data has been 1179 * Overrun interrupt - bail out since our Data has been
800 * corrupted 1180 * corrupted
801 */ 1181 */
802 dev_err(&pl022->adev->dev, 1182 dev_err(&pl022->adev->dev, "FIFO overrun\n");
803 "FIFO overrun\n");
804 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF) 1183 if (readw(SSP_SR(pl022->virtbase)) & SSP_SR_MASK_RFF)
805 dev_err(&pl022->adev->dev, 1184 dev_err(&pl022->adev->dev,
806 "RXFIFO is full\n"); 1185 "RXFIFO is full\n");
@@ -895,8 +1274,8 @@ static int set_up_next_transfer(struct pl022 *pl022,
895} 1274}
896 1275
897/** 1276/**
898 * pump_transfers - Tasklet function which schedules next interrupt transfer 1277 * pump_transfers - Tasklet function which schedules next transfer
899 * when running in interrupt transfer mode. 1278 * when running in interrupt or DMA transfer mode.
900 * @data: SSP driver private data structure 1279 * @data: SSP driver private data structure
901 * 1280 *
902 */ 1281 */
@@ -953,65 +1332,23 @@ static void pump_transfers(unsigned long data)
953 } 1332 }
954 /* Flush the FIFOs and let's go! */ 1333 /* Flush the FIFOs and let's go! */
955 flush(pl022); 1334 flush(pl022);
956 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
957}
958 1335
959/** 1336 if (pl022->cur_chip->enable_dma) {
960 * NOT IMPLEMENTED 1337 if (configure_dma(pl022)) {
961 * configure_dma - It configures the DMA pipes for DMA transfers 1338 dev_dbg(&pl022->adev->dev,
962 * @data: SSP driver's private data structure 1339 "configuration of DMA failed, fall back to interrupt mode\n");
963 * 1340 goto err_config_dma;
964 */ 1341 }
965static int configure_dma(void *data)
966{
967 struct pl022 *pl022 = data;
968 dev_dbg(&pl022->adev->dev, "configure DMA\n");
969 return -ENOTSUPP;
970}
971
972/**
973 * do_dma_transfer - It handles transfers of the current message
974 * if it is DMA xfer.
975 * NOT FULLY IMPLEMENTED
976 * @data: SSP driver's private data structure
977 */
978static void do_dma_transfer(void *data)
979{
980 struct pl022 *pl022 = data;
981
982 if (configure_dma(data)) {
983 dev_dbg(&pl022->adev->dev, "configuration of DMA Failed!\n");
984 goto err_config_dma;
985 }
986
987 /* TODO: Implememt DMA setup of pipes here */
988
989 /* Enable target chip, set up transfer */
990 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
991 if (set_up_next_transfer(pl022, pl022->cur_transfer)) {
992 /* Error path */
993 pl022->cur_msg->state = STATE_ERROR;
994 pl022->cur_msg->status = -EIO;
995 giveback(pl022);
996 return; 1342 return;
997 } 1343 }
998 /* Enable SSP */
999 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
1000 SSP_CR1(pl022->virtbase));
1001
1002 /* TODO: Enable the DMA transfer here */
1003 return;
1004 1344
1005 err_config_dma: 1345err_config_dma:
1006 pl022->cur_msg->state = STATE_ERROR; 1346 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase));
1007 pl022->cur_msg->status = -EIO;
1008 giveback(pl022);
1009 return;
1010} 1347}
1011 1348
1012static void do_interrupt_transfer(void *data) 1349static void do_interrupt_dma_transfer(struct pl022 *pl022)
1013{ 1350{
1014 struct pl022 *pl022 = data; 1351 u32 irqflags = ENABLE_ALL_INTERRUPTS;
1015 1352
1016 /* Enable target chip */ 1353 /* Enable target chip */
1017 pl022->cur_chip->cs_control(SSP_CHIP_SELECT); 1354 pl022->cur_chip->cs_control(SSP_CHIP_SELECT);
@@ -1022,15 +1359,26 @@ static void do_interrupt_transfer(void *data)
1022 giveback(pl022); 1359 giveback(pl022);
1023 return; 1360 return;
1024 } 1361 }
1362 /* If we're using DMA, set up DMA here */
1363 if (pl022->cur_chip->enable_dma) {
1364 /* Configure DMA transfer */
1365 if (configure_dma(pl022)) {
1366 dev_dbg(&pl022->adev->dev,
1367 "configuration of DMA failed, fall back to interrupt mode\n");
1368 goto err_config_dma;
1369 }
1370 /* Disable interrupts in DMA mode, IRQ from DMA controller */
1371 irqflags = DISABLE_ALL_INTERRUPTS;
1372 }
1373err_config_dma:
1025 /* Enable SSP, turn on interrupts */ 1374 /* Enable SSP, turn on interrupts */
1026 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE), 1375 writew((readw(SSP_CR1(pl022->virtbase)) | SSP_CR1_MASK_SSE),
1027 SSP_CR1(pl022->virtbase)); 1376 SSP_CR1(pl022->virtbase));
1028 writew(ENABLE_ALL_INTERRUPTS, SSP_IMSC(pl022->virtbase)); 1377 writew(irqflags, SSP_IMSC(pl022->virtbase));
1029} 1378}
1030 1379
1031static void do_polling_transfer(void *data) 1380static void do_polling_transfer(struct pl022 *pl022)
1032{ 1381{
1033 struct pl022 *pl022 = data;
1034 struct spi_message *message = NULL; 1382 struct spi_message *message = NULL;
1035 struct spi_transfer *transfer = NULL; 1383 struct spi_transfer *transfer = NULL;
1036 struct spi_transfer *previous = NULL; 1384 struct spi_transfer *previous = NULL;
@@ -1100,7 +1448,7 @@ static void do_polling_transfer(void *data)
1100 * 1448 *
1101 * This function checks if there is any spi message in the queue that 1449 * This function checks if there is any spi message in the queue that
1102 * needs processing and delegate control to appropriate function 1450 * needs processing and delegate control to appropriate function
1103 * do_polling_transfer()/do_interrupt_transfer()/do_dma_transfer() 1451 * do_polling_transfer()/do_interrupt_dma_transfer()
1104 * based on the kind of the transfer 1452 * based on the kind of the transfer
1105 * 1453 *
1106 */ 1454 */
@@ -1139,19 +1487,18 @@ static void pump_messages(struct work_struct *work)
1139 /* Setup the SPI using the per chip configuration */ 1487 /* Setup the SPI using the per chip configuration */
1140 pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi); 1488 pl022->cur_chip = spi_get_ctldata(pl022->cur_msg->spi);
1141 /* 1489 /*
1142 * We enable the clock here, then the clock will be disabled when 1490 * We enable the clocks here, then the clocks will be disabled when
1143 * giveback() is called in each method (poll/interrupt/DMA) 1491 * giveback() is called in each method (poll/interrupt/DMA)
1144 */ 1492 */
1493 amba_pclk_enable(pl022->adev);
1145 clk_enable(pl022->clk); 1494 clk_enable(pl022->clk);
1146 restore_state(pl022); 1495 restore_state(pl022);
1147 flush(pl022); 1496 flush(pl022);
1148 1497
1149 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER) 1498 if (pl022->cur_chip->xfer_type == POLLING_TRANSFER)
1150 do_polling_transfer(pl022); 1499 do_polling_transfer(pl022);
1151 else if (pl022->cur_chip->xfer_type == INTERRUPT_TRANSFER)
1152 do_interrupt_transfer(pl022);
1153 else 1500 else
1154 do_dma_transfer(pl022); 1501 do_interrupt_dma_transfer(pl022);
1155} 1502}
1156 1503
1157 1504
@@ -1246,100 +1593,56 @@ static int destroy_queue(struct pl022 *pl022)
1246} 1593}
1247 1594
1248static int verify_controller_parameters(struct pl022 *pl022, 1595static int verify_controller_parameters(struct pl022 *pl022,
1249 struct pl022_config_chip *chip_info) 1596 struct pl022_config_chip const *chip_info)
1250{ 1597{
1251 if ((chip_info->lbm != LOOPBACK_ENABLED)
1252 && (chip_info->lbm != LOOPBACK_DISABLED)) {
1253 dev_err(chip_info->dev,
1254 "loopback Mode is configured incorrectly\n");
1255 return -EINVAL;
1256 }
1257 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI) 1598 if ((chip_info->iface < SSP_INTERFACE_MOTOROLA_SPI)
1258 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) { 1599 || (chip_info->iface > SSP_INTERFACE_UNIDIRECTIONAL)) {
1259 dev_err(chip_info->dev, 1600 dev_err(&pl022->adev->dev,
1260 "interface is configured incorrectly\n"); 1601 "interface is configured incorrectly\n");
1261 return -EINVAL; 1602 return -EINVAL;
1262 } 1603 }
1263 if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) && 1604 if ((chip_info->iface == SSP_INTERFACE_UNIDIRECTIONAL) &&
1264 (!pl022->vendor->unidir)) { 1605 (!pl022->vendor->unidir)) {
1265 dev_err(chip_info->dev, 1606 dev_err(&pl022->adev->dev,
1266 "unidirectional mode not supported in this " 1607 "unidirectional mode not supported in this "
1267 "hardware version\n"); 1608 "hardware version\n");
1268 return -EINVAL; 1609 return -EINVAL;
1269 } 1610 }
1270 if ((chip_info->hierarchy != SSP_MASTER) 1611 if ((chip_info->hierarchy != SSP_MASTER)
1271 && (chip_info->hierarchy != SSP_SLAVE)) { 1612 && (chip_info->hierarchy != SSP_SLAVE)) {
1272 dev_err(chip_info->dev, 1613 dev_err(&pl022->adev->dev,
1273 "hierarchy is configured incorrectly\n"); 1614 "hierarchy is configured incorrectly\n");
1274 return -EINVAL; 1615 return -EINVAL;
1275 } 1616 }
1276 if (((chip_info->clk_freq).cpsdvsr < CPSDVR_MIN)
1277 || ((chip_info->clk_freq).cpsdvsr > CPSDVR_MAX)) {
1278 dev_err(chip_info->dev,
1279 "cpsdvsr is configured incorrectly\n");
1280 return -EINVAL;
1281 }
1282 if ((chip_info->endian_rx != SSP_RX_MSB)
1283 && (chip_info->endian_rx != SSP_RX_LSB)) {
1284 dev_err(chip_info->dev,
1285 "RX FIFO endianess is configured incorrectly\n");
1286 return -EINVAL;
1287 }
1288 if ((chip_info->endian_tx != SSP_TX_MSB)
1289 && (chip_info->endian_tx != SSP_TX_LSB)) {
1290 dev_err(chip_info->dev,
1291 "TX FIFO endianess is configured incorrectly\n");
1292 return -EINVAL;
1293 }
1294 if ((chip_info->data_size < SSP_DATA_BITS_4)
1295 || (chip_info->data_size > SSP_DATA_BITS_32)) {
1296 dev_err(chip_info->dev,
1297 "DATA Size is configured incorrectly\n");
1298 return -EINVAL;
1299 }
1300 if ((chip_info->com_mode != INTERRUPT_TRANSFER) 1617 if ((chip_info->com_mode != INTERRUPT_TRANSFER)
1301 && (chip_info->com_mode != DMA_TRANSFER) 1618 && (chip_info->com_mode != DMA_TRANSFER)
1302 && (chip_info->com_mode != POLLING_TRANSFER)) { 1619 && (chip_info->com_mode != POLLING_TRANSFER)) {
1303 dev_err(chip_info->dev, 1620 dev_err(&pl022->adev->dev,
1304 "Communication mode is configured incorrectly\n"); 1621 "Communication mode is configured incorrectly\n");
1305 return -EINVAL; 1622 return -EINVAL;
1306 } 1623 }
1307 if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM) 1624 if ((chip_info->rx_lev_trig < SSP_RX_1_OR_MORE_ELEM)
1308 || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) { 1625 || (chip_info->rx_lev_trig > SSP_RX_32_OR_MORE_ELEM)) {
1309 dev_err(chip_info->dev, 1626 dev_err(&pl022->adev->dev,
1310 "RX FIFO Trigger Level is configured incorrectly\n"); 1627 "RX FIFO Trigger Level is configured incorrectly\n");
1311 return -EINVAL; 1628 return -EINVAL;
1312 } 1629 }
1313 if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC) 1630 if ((chip_info->tx_lev_trig < SSP_TX_1_OR_MORE_EMPTY_LOC)
1314 || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) { 1631 || (chip_info->tx_lev_trig > SSP_TX_32_OR_MORE_EMPTY_LOC)) {
1315 dev_err(chip_info->dev, 1632 dev_err(&pl022->adev->dev,
1316 "TX FIFO Trigger Level is configured incorrectly\n"); 1633 "TX FIFO Trigger Level is configured incorrectly\n");
1317 return -EINVAL; 1634 return -EINVAL;
1318 } 1635 }
1319 if (chip_info->iface == SSP_INTERFACE_MOTOROLA_SPI) {
1320 if ((chip_info->clk_phase != SSP_CLK_FIRST_EDGE)
1321 && (chip_info->clk_phase != SSP_CLK_SECOND_EDGE)) {
1322 dev_err(chip_info->dev,
1323 "Clock Phase is configured incorrectly\n");
1324 return -EINVAL;
1325 }
1326 if ((chip_info->clk_pol != SSP_CLK_POL_IDLE_LOW)
1327 && (chip_info->clk_pol != SSP_CLK_POL_IDLE_HIGH)) {
1328 dev_err(chip_info->dev,
1329 "Clock Polarity is configured incorrectly\n");
1330 return -EINVAL;
1331 }
1332 }
1333 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) { 1636 if (chip_info->iface == SSP_INTERFACE_NATIONAL_MICROWIRE) {
1334 if ((chip_info->ctrl_len < SSP_BITS_4) 1637 if ((chip_info->ctrl_len < SSP_BITS_4)
1335 || (chip_info->ctrl_len > SSP_BITS_32)) { 1638 || (chip_info->ctrl_len > SSP_BITS_32)) {
1336 dev_err(chip_info->dev, 1639 dev_err(&pl022->adev->dev,
1337 "CTRL LEN is configured incorrectly\n"); 1640 "CTRL LEN is configured incorrectly\n");
1338 return -EINVAL; 1641 return -EINVAL;
1339 } 1642 }
1340 if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO) 1643 if ((chip_info->wait_state != SSP_MWIRE_WAIT_ZERO)
1341 && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) { 1644 && (chip_info->wait_state != SSP_MWIRE_WAIT_ONE)) {
1342 dev_err(chip_info->dev, 1645 dev_err(&pl022->adev->dev,
1343 "Wait State is configured incorrectly\n"); 1646 "Wait State is configured incorrectly\n");
1344 return -EINVAL; 1647 return -EINVAL;
1345 } 1648 }
@@ -1348,24 +1651,20 @@ static int verify_controller_parameters(struct pl022 *pl022,
1348 if ((chip_info->duplex != 1651 if ((chip_info->duplex !=
1349 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) 1652 SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
1350 && (chip_info->duplex != 1653 && (chip_info->duplex !=
1351 SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) 1654 SSP_MICROWIRE_CHANNEL_HALF_DUPLEX)) {
1352 dev_err(chip_info->dev, 1655 dev_err(&pl022->adev->dev,
1353 "Microwire duplex mode is configured incorrectly\n"); 1656 "Microwire duplex mode is configured incorrectly\n");
1354 return -EINVAL; 1657 return -EINVAL;
1658 }
1355 } else { 1659 } else {
1356 if (chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX) 1660 if (chip_info->duplex != SSP_MICROWIRE_CHANNEL_FULL_DUPLEX)
1357 dev_err(chip_info->dev, 1661 dev_err(&pl022->adev->dev,
1358 "Microwire half duplex mode requested," 1662 "Microwire half duplex mode requested,"
1359 " but this is only available in the" 1663 " but this is only available in the"
1360 " ST version of PL022\n"); 1664 " ST version of PL022\n");
1361 return -EINVAL; 1665 return -EINVAL;
1362 } 1666 }
1363 } 1667 }
1364 if (chip_info->cs_control == NULL) {
1365 dev_warn(chip_info->dev,
1366 "Chip Select Function is NULL for this chip\n");
1367 chip_info->cs_control = null_cs_control;
1368 }
1369 return 0; 1668 return 0;
1370} 1669}
1371 1670
@@ -1465,22 +1764,24 @@ static int calculate_effective_freq(struct pl022 *pl022,
1465 return 0; 1764 return 0;
1466} 1765}
1467 1766
1468/** 1767
1469 * NOT IMPLEMENTED 1768/*
1470 * process_dma_info - Processes the DMA info provided by client drivers 1769 * A piece of default chip info unless the platform
1471 * @chip_info: chip info provided by client device 1770 * supplies it.
1472 * @chip: Runtime state maintained by the SSP controller for each spi device
1473 *
1474 * This function processes and stores DMA config provided by client driver
1475 * into the runtime state maintained by the SSP controller driver
1476 */ 1771 */
1477static int process_dma_info(struct pl022_config_chip *chip_info, 1772static const struct pl022_config_chip pl022_default_chip_info = {
1478 struct chip_data *chip) 1773 .com_mode = POLLING_TRANSFER,
1479{ 1774 .iface = SSP_INTERFACE_MOTOROLA_SPI,
1480 dev_err(chip_info->dev, 1775 .hierarchy = SSP_SLAVE,
1481 "cannot process DMA info, DMA not implemented!\n"); 1776 .slave_tx_disable = DO_NOT_DRIVE_TX,
1482 return -ENOTSUPP; 1777 .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM,
1483} 1778 .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC,
1779 .ctrl_len = SSP_BITS_8,
1780 .wait_state = SSP_MWIRE_WAIT_ZERO,
1781 .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
1782 .cs_control = null_cs_control,
1783};
1784
1484 1785
1485/** 1786/**
1486 * pl022_setup - setup function registered to SPI master framework 1787 * pl022_setup - setup function registered to SPI master framework
@@ -1494,23 +1795,15 @@ static int process_dma_info(struct pl022_config_chip *chip_info,
1494 * controller hardware here, that is not done until the actual transfer 1795 * controller hardware here, that is not done until the actual transfer
1495 * commence. 1796 * commence.
1496 */ 1797 */
1497
1498/* FIXME: JUST GUESSING the spi->mode bits understood by this driver */
1499#define MODEBITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
1500 | SPI_LSB_FIRST | SPI_LOOP)
1501
1502static int pl022_setup(struct spi_device *spi) 1798static int pl022_setup(struct spi_device *spi)
1503{ 1799{
1504 struct pl022_config_chip *chip_info; 1800 struct pl022_config_chip const *chip_info;
1505 struct chip_data *chip; 1801 struct chip_data *chip;
1802 struct ssp_clock_params clk_freq;
1506 int status = 0; 1803 int status = 0;
1507 struct pl022 *pl022 = spi_master_get_devdata(spi->master); 1804 struct pl022 *pl022 = spi_master_get_devdata(spi->master);
1508 1805 unsigned int bits = spi->bits_per_word;
1509 if (spi->mode & ~MODEBITS) { 1806 u32 tmp;
1510 dev_dbg(&spi->dev, "unsupported mode bits %x\n",
1511 spi->mode & ~MODEBITS);
1512 return -EINVAL;
1513 }
1514 1807
1515 if (!spi->max_speed_hz) 1808 if (!spi->max_speed_hz)
1516 return -EINVAL; 1809 return -EINVAL;
@@ -1533,48 +1826,13 @@ static int pl022_setup(struct spi_device *spi)
1533 chip_info = spi->controller_data; 1826 chip_info = spi->controller_data;
1534 1827
1535 if (chip_info == NULL) { 1828 if (chip_info == NULL) {
1829 chip_info = &pl022_default_chip_info;
1536 /* spi_board_info.controller_data not is supplied */ 1830 /* spi_board_info.controller_data not is supplied */
1537 dev_dbg(&spi->dev, 1831 dev_dbg(&spi->dev,
1538 "using default controller_data settings\n"); 1832 "using default controller_data settings\n");
1539 1833 } else
1540 chip_info =
1541 kzalloc(sizeof(struct pl022_config_chip), GFP_KERNEL);
1542
1543 if (!chip_info) {
1544 dev_err(&spi->dev,
1545 "cannot allocate controller data\n");
1546 status = -ENOMEM;
1547 goto err_first_setup;
1548 }
1549
1550 dev_dbg(&spi->dev, "allocated memory for controller data\n");
1551
1552 /* Pointer back to the SPI device */
1553 chip_info->dev = &spi->dev;
1554 /*
1555 * Set controller data default values:
1556 * Polling is supported by default
1557 */
1558 chip_info->lbm = LOOPBACK_DISABLED;
1559 chip_info->com_mode = POLLING_TRANSFER;
1560 chip_info->iface = SSP_INTERFACE_MOTOROLA_SPI;
1561 chip_info->hierarchy = SSP_SLAVE;
1562 chip_info->slave_tx_disable = DO_NOT_DRIVE_TX;
1563 chip_info->endian_tx = SSP_TX_LSB;
1564 chip_info->endian_rx = SSP_RX_LSB;
1565 chip_info->data_size = SSP_DATA_BITS_12;
1566 chip_info->rx_lev_trig = SSP_RX_1_OR_MORE_ELEM;
1567 chip_info->tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC;
1568 chip_info->clk_phase = SSP_CLK_SECOND_EDGE;
1569 chip_info->clk_pol = SSP_CLK_POL_IDLE_LOW;
1570 chip_info->ctrl_len = SSP_BITS_8;
1571 chip_info->wait_state = SSP_MWIRE_WAIT_ZERO;
1572 chip_info->duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX;
1573 chip_info->cs_control = null_cs_control;
1574 } else {
1575 dev_dbg(&spi->dev, 1834 dev_dbg(&spi->dev,
1576 "using user supplied controller_data settings\n"); 1835 "using user supplied controller_data settings\n");
1577 }
1578 1836
1579 /* 1837 /*
1580 * We can override with custom divisors, else we use the board 1838 * We can override with custom divisors, else we use the board
@@ -1584,29 +1842,48 @@ static int pl022_setup(struct spi_device *spi)
1584 && (0 == chip_info->clk_freq.scr)) { 1842 && (0 == chip_info->clk_freq.scr)) {
1585 status = calculate_effective_freq(pl022, 1843 status = calculate_effective_freq(pl022,
1586 spi->max_speed_hz, 1844 spi->max_speed_hz,
1587 &chip_info->clk_freq); 1845 &clk_freq);
1588 if (status < 0) 1846 if (status < 0)
1589 goto err_config_params; 1847 goto err_config_params;
1590 } else { 1848 } else {
1591 if ((chip_info->clk_freq.cpsdvsr % 2) != 0) 1849 memcpy(&clk_freq, &chip_info->clk_freq, sizeof(clk_freq));
1592 chip_info->clk_freq.cpsdvsr = 1850 if ((clk_freq.cpsdvsr % 2) != 0)
1593 chip_info->clk_freq.cpsdvsr - 1; 1851 clk_freq.cpsdvsr =
1852 clk_freq.cpsdvsr - 1;
1594 } 1853 }
1854 if ((clk_freq.cpsdvsr < CPSDVR_MIN)
1855 || (clk_freq.cpsdvsr > CPSDVR_MAX)) {
1856 dev_err(&spi->dev,
1857 "cpsdvsr is configured incorrectly\n");
1858 goto err_config_params;
1859 }
1860
1861
1595 status = verify_controller_parameters(pl022, chip_info); 1862 status = verify_controller_parameters(pl022, chip_info);
1596 if (status) { 1863 if (status) {
1597 dev_err(&spi->dev, "controller data is incorrect"); 1864 dev_err(&spi->dev, "controller data is incorrect");
1598 goto err_config_params; 1865 goto err_config_params;
1599 } 1866 }
1867
1600 /* Now set controller state based on controller data */ 1868 /* Now set controller state based on controller data */
1601 chip->xfer_type = chip_info->com_mode; 1869 chip->xfer_type = chip_info->com_mode;
1602 chip->cs_control = chip_info->cs_control; 1870 if (!chip_info->cs_control) {
1603 1871 chip->cs_control = null_cs_control;
1604 if (chip_info->data_size <= 8) { 1872 dev_warn(&spi->dev,
1605 dev_dbg(&spi->dev, "1 <= n <=8 bits per word\n"); 1873 "chip select function is NULL for this chip\n");
1874 } else
1875 chip->cs_control = chip_info->cs_control;
1876
1877 if (bits <= 3) {
1878 /* PL022 doesn't support less than 4-bits */
1879 status = -ENOTSUPP;
1880 goto err_config_params;
1881 } else if (bits <= 8) {
1882 dev_dbg(&spi->dev, "4 <= n <=8 bits per word\n");
1606 chip->n_bytes = 1; 1883 chip->n_bytes = 1;
1607 chip->read = READING_U8; 1884 chip->read = READING_U8;
1608 chip->write = WRITING_U8; 1885 chip->write = WRITING_U8;
1609 } else if (chip_info->data_size <= 16) { 1886 } else if (bits <= 16) {
1610 dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n"); 1887 dev_dbg(&spi->dev, "9 <= n <= 16 bits per word\n");
1611 chip->n_bytes = 2; 1888 chip->n_bytes = 2;
1612 chip->read = READING_U16; 1889 chip->read = READING_U16;
@@ -1623,6 +1900,7 @@ static int pl022_setup(struct spi_device *spi)
1623 dev_err(&spi->dev, 1900 dev_err(&spi->dev,
1624 "a standard pl022 can only handle " 1901 "a standard pl022 can only handle "
1625 "1 <= n <= 16 bit words\n"); 1902 "1 <= n <= 16 bit words\n");
1903 status = -ENOTSUPP;
1626 goto err_config_params; 1904 goto err_config_params;
1627 } 1905 }
1628 } 1906 }
@@ -1634,9 +1912,8 @@ static int pl022_setup(struct spi_device *spi)
1634 chip->cpsr = 0; 1912 chip->cpsr = 0;
1635 if ((chip_info->com_mode == DMA_TRANSFER) 1913 if ((chip_info->com_mode == DMA_TRANSFER)
1636 && ((pl022->master_info)->enable_dma)) { 1914 && ((pl022->master_info)->enable_dma)) {
1637 chip->enable_dma = 1; 1915 chip->enable_dma = true;
1638 dev_dbg(&spi->dev, "DMA mode set in controller state\n"); 1916 dev_dbg(&spi->dev, "DMA mode set in controller state\n");
1639 status = process_dma_info(chip_info, chip);
1640 if (status < 0) 1917 if (status < 0)
1641 goto err_config_params; 1918 goto err_config_params;
1642 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, 1919 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
@@ -1644,7 +1921,7 @@ static int pl022_setup(struct spi_device *spi)
1644 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED, 1921 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_ENABLED,
1645 SSP_DMACR_MASK_TXDMAE, 1); 1922 SSP_DMACR_MASK_TXDMAE, 1);
1646 } else { 1923 } else {
1647 chip->enable_dma = 0; 1924 chip->enable_dma = false;
1648 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n"); 1925 dev_dbg(&spi->dev, "DMA mode NOT set in controller state\n");
1649 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED, 1926 SSP_WRITE_BITS(chip->dmacr, SSP_DMA_DISABLED,
1650 SSP_DMACR_MASK_RXDMAE, 0); 1927 SSP_DMACR_MASK_RXDMAE, 0);
@@ -1652,10 +1929,12 @@ static int pl022_setup(struct spi_device *spi)
1652 SSP_DMACR_MASK_TXDMAE, 1); 1929 SSP_DMACR_MASK_TXDMAE, 1);
1653 } 1930 }
1654 1931
1655 chip->cpsr = chip_info->clk_freq.cpsdvsr; 1932 chip->cpsr = clk_freq.cpsdvsr;
1656 1933
1657 /* Special setup for the ST micro extended control registers */ 1934 /* Special setup for the ST micro extended control registers */
1658 if (pl022->vendor->extended_cr) { 1935 if (pl022->vendor->extended_cr) {
1936 u32 etx;
1937
1659 if (pl022->vendor->pl023) { 1938 if (pl022->vendor->pl023) {
1660 /* These bits are only in the PL023 */ 1939 /* These bits are only in the PL023 */
1661 SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay, 1940 SSP_WRITE_BITS(chip->cr1, chip_info->clkdelay,
@@ -1671,29 +1950,51 @@ static int pl022_setup(struct spi_device *spi)
1671 SSP_WRITE_BITS(chip->cr1, chip_info->wait_state, 1950 SSP_WRITE_BITS(chip->cr1, chip_info->wait_state,
1672 SSP_CR1_MASK_MWAIT_ST, 6); 1951 SSP_CR1_MASK_MWAIT_ST, 6);
1673 } 1952 }
1674 SSP_WRITE_BITS(chip->cr0, chip_info->data_size, 1953 SSP_WRITE_BITS(chip->cr0, bits - 1,
1675 SSP_CR0_MASK_DSS_ST, 0); 1954 SSP_CR0_MASK_DSS_ST, 0);
1676 SSP_WRITE_BITS(chip->cr1, chip_info->endian_rx, 1955
1677 SSP_CR1_MASK_RENDN_ST, 4); 1956 if (spi->mode & SPI_LSB_FIRST) {
1678 SSP_WRITE_BITS(chip->cr1, chip_info->endian_tx, 1957 tmp = SSP_RX_LSB;
1679 SSP_CR1_MASK_TENDN_ST, 5); 1958 etx = SSP_TX_LSB;
1959 } else {
1960 tmp = SSP_RX_MSB;
1961 etx = SSP_TX_MSB;
1962 }
1963 SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_RENDN_ST, 4);
1964 SSP_WRITE_BITS(chip->cr1, etx, SSP_CR1_MASK_TENDN_ST, 5);
1680 SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig, 1965 SSP_WRITE_BITS(chip->cr1, chip_info->rx_lev_trig,
1681 SSP_CR1_MASK_RXIFLSEL_ST, 7); 1966 SSP_CR1_MASK_RXIFLSEL_ST, 7);
1682 SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig, 1967 SSP_WRITE_BITS(chip->cr1, chip_info->tx_lev_trig,
1683 SSP_CR1_MASK_TXIFLSEL_ST, 10); 1968 SSP_CR1_MASK_TXIFLSEL_ST, 10);
1684 } else { 1969 } else {
1685 SSP_WRITE_BITS(chip->cr0, chip_info->data_size, 1970 SSP_WRITE_BITS(chip->cr0, bits - 1,
1686 SSP_CR0_MASK_DSS, 0); 1971 SSP_CR0_MASK_DSS, 0);
1687 SSP_WRITE_BITS(chip->cr0, chip_info->iface, 1972 SSP_WRITE_BITS(chip->cr0, chip_info->iface,
1688 SSP_CR0_MASK_FRF, 4); 1973 SSP_CR0_MASK_FRF, 4);
1689 } 1974 }
1975
1690 /* Stuff that is common for all versions */ 1976 /* Stuff that is common for all versions */
1691 SSP_WRITE_BITS(chip->cr0, chip_info->clk_pol, SSP_CR0_MASK_SPO, 6); 1977 if (spi->mode & SPI_CPOL)
1692 SSP_WRITE_BITS(chip->cr0, chip_info->clk_phase, SSP_CR0_MASK_SPH, 7); 1978 tmp = SSP_CLK_POL_IDLE_HIGH;
1693 SSP_WRITE_BITS(chip->cr0, chip_info->clk_freq.scr, SSP_CR0_MASK_SCR, 8); 1979 else
1980 tmp = SSP_CLK_POL_IDLE_LOW;
1981 SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPO, 6);
1982
1983 if (spi->mode & SPI_CPHA)
1984 tmp = SSP_CLK_SECOND_EDGE;
1985 else
1986 tmp = SSP_CLK_FIRST_EDGE;
1987 SSP_WRITE_BITS(chip->cr0, tmp, SSP_CR0_MASK_SPH, 7);
1988
1989 SSP_WRITE_BITS(chip->cr0, clk_freq.scr, SSP_CR0_MASK_SCR, 8);
1694 /* Loopback is available on all versions except PL023 */ 1990 /* Loopback is available on all versions except PL023 */
1695 if (!pl022->vendor->pl023) 1991 if (!pl022->vendor->pl023) {
1696 SSP_WRITE_BITS(chip->cr1, chip_info->lbm, SSP_CR1_MASK_LBM, 0); 1992 if (spi->mode & SPI_LOOP)
1993 tmp = LOOPBACK_ENABLED;
1994 else
1995 tmp = LOOPBACK_DISABLED;
1996 SSP_WRITE_BITS(chip->cr1, tmp, SSP_CR1_MASK_LBM, 0);
1997 }
1697 SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1); 1998 SSP_WRITE_BITS(chip->cr1, SSP_DISABLED, SSP_CR1_MASK_SSE, 1);
1698 SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2); 1999 SSP_WRITE_BITS(chip->cr1, chip_info->hierarchy, SSP_CR1_MASK_MS, 2);
1699 SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3); 2000 SSP_WRITE_BITS(chip->cr1, chip_info->slave_tx_disable, SSP_CR1_MASK_SOD, 3);
@@ -1702,7 +2003,7 @@ static int pl022_setup(struct spi_device *spi)
1702 spi_set_ctldata(spi, chip); 2003 spi_set_ctldata(spi, chip);
1703 return status; 2004 return status;
1704 err_config_params: 2005 err_config_params:
1705 err_first_setup: 2006 spi_set_ctldata(spi, NULL);
1706 kfree(chip); 2007 kfree(chip);
1707 return status; 2008 return status;
1708} 2009}
@@ -1764,12 +2065,21 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1764 master->setup = pl022_setup; 2065 master->setup = pl022_setup;
1765 master->transfer = pl022_transfer; 2066 master->transfer = pl022_transfer;
1766 2067
2068 /*
2069 * Supports mode 0-3, loopback, and active low CS. Transfers are
2070 * always MS bit first on the original pl022.
2071 */
2072 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
2073 if (pl022->vendor->extended_cr)
2074 master->mode_bits |= SPI_LSB_FIRST;
2075
1767 dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num); 2076 dev_dbg(&adev->dev, "BUSNO: %d\n", master->bus_num);
1768 2077
1769 status = amba_request_regions(adev, NULL); 2078 status = amba_request_regions(adev, NULL);
1770 if (status) 2079 if (status)
1771 goto err_no_ioregion; 2080 goto err_no_ioregion;
1772 2081
2082 pl022->phybase = adev->res.start;
1773 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res)); 2083 pl022->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
1774 if (pl022->virtbase == NULL) { 2084 if (pl022->virtbase == NULL) {
1775 status = -ENOMEM; 2085 status = -ENOMEM;
@@ -1786,11 +2096,9 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1786 } 2096 }
1787 2097
1788 /* Disable SSP */ 2098 /* Disable SSP */
1789 clk_enable(pl022->clk);
1790 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)), 2099 writew((readw(SSP_CR1(pl022->virtbase)) & (~SSP_CR1_MASK_SSE)),
1791 SSP_CR1(pl022->virtbase)); 2100 SSP_CR1(pl022->virtbase));
1792 load_ssp_default_config(pl022); 2101 load_ssp_default_config(pl022);
1793 clk_disable(pl022->clk);
1794 2102
1795 status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022", 2103 status = request_irq(adev->irq[0], pl022_interrupt_handler, 0, "pl022",
1796 pl022); 2104 pl022);
@@ -1798,6 +2106,14 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1798 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status); 2106 dev_err(&adev->dev, "probe - cannot get IRQ (%d)\n", status);
1799 goto err_no_irq; 2107 goto err_no_irq;
1800 } 2108 }
2109
2110 /* Get DMA channels */
2111 if (platform_info->enable_dma) {
2112 status = pl022_dma_probe(pl022);
2113 if (status != 0)
2114 goto err_no_dma;
2115 }
2116
1801 /* Initialize and start queue */ 2117 /* Initialize and start queue */
1802 status = init_queue(pl022); 2118 status = init_queue(pl022);
1803 if (status != 0) { 2119 if (status != 0) {
@@ -1818,12 +2134,16 @@ pl022_probe(struct amba_device *adev, struct amba_id *id)
1818 goto err_spi_register; 2134 goto err_spi_register;
1819 } 2135 }
1820 dev_dbg(dev, "probe succeded\n"); 2136 dev_dbg(dev, "probe succeded\n");
2137 /* Disable the silicon block pclk and clock it when needed */
2138 amba_pclk_disable(adev);
1821 return 0; 2139 return 0;
1822 2140
1823 err_spi_register: 2141 err_spi_register:
1824 err_start_queue: 2142 err_start_queue:
1825 err_init_queue: 2143 err_init_queue:
1826 destroy_queue(pl022); 2144 destroy_queue(pl022);
2145 pl022_dma_remove(pl022);
2146 err_no_dma:
1827 free_irq(adev->irq[0], pl022); 2147 free_irq(adev->irq[0], pl022);
1828 err_no_irq: 2148 err_no_irq:
1829 clk_put(pl022->clk); 2149 clk_put(pl022->clk);
@@ -1854,6 +2174,7 @@ pl022_remove(struct amba_device *adev)
1854 return status; 2174 return status;
1855 } 2175 }
1856 load_ssp_default_config(pl022); 2176 load_ssp_default_config(pl022);
2177 pl022_dma_remove(pl022);
1857 free_irq(adev->irq[0], pl022); 2178 free_irq(adev->irq[0], pl022);
1858 clk_disable(pl022->clk); 2179 clk_disable(pl022->clk);
1859 clk_put(pl022->clk); 2180 clk_put(pl022->clk);
@@ -1879,9 +2200,9 @@ static int pl022_suspend(struct amba_device *adev, pm_message_t state)
1879 return status; 2200 return status;
1880 } 2201 }
1881 2202
1882 clk_enable(pl022->clk); 2203 amba_pclk_enable(adev);
1883 load_ssp_default_config(pl022); 2204 load_ssp_default_config(pl022);
1884 clk_disable(pl022->clk); 2205 amba_pclk_disable(adev);
1885 dev_dbg(&adev->dev, "suspended\n"); 2206 dev_dbg(&adev->dev, "suspended\n");
1886 return 0; 2207 return 0;
1887} 2208}
@@ -1981,7 +2302,7 @@ static int __init pl022_init(void)
1981 return amba_driver_register(&pl022_driver); 2302 return amba_driver_register(&pl022_driver);
1982} 2303}
1983 2304
1984module_init(pl022_init); 2305subsys_initcall(pl022_init);
1985 2306
1986static void __exit pl022_exit(void) 2307static void __exit pl022_exit(void)
1987{ 2308{
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index c4e04428992d..154529aacc03 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -654,6 +654,8 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
654 struct spi_transfer *xfer; 654 struct spi_transfer *xfer;
655 unsigned long flags; 655 unsigned long flags;
656 struct device *controller = spi->master->dev.parent; 656 struct device *controller = spi->master->dev.parent;
657 u8 bits;
658 struct atmel_spi_device *asd;
657 659
658 as = spi_master_get_devdata(spi->master); 660 as = spi_master_get_devdata(spi->master);
659 661
@@ -672,8 +674,18 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
672 return -EINVAL; 674 return -EINVAL;
673 } 675 }
674 676
677 if (xfer->bits_per_word) {
678 asd = spi->controller_state;
679 bits = (asd->csr >> 4) & 0xf;
680 if (bits != xfer->bits_per_word - 8) {
681 dev_dbg(&spi->dev, "you can't yet change "
682 "bits_per_word in transfers\n");
683 return -ENOPROTOOPT;
684 }
685 }
686
675 /* FIXME implement these protocol options!! */ 687 /* FIXME implement these protocol options!! */
676 if (xfer->bits_per_word || xfer->speed_hz) { 688 if (xfer->speed_hz) {
677 dev_dbg(&spi->dev, "no protocol options yet\n"); 689 dev_dbg(&spi->dev, "no protocol options yet\n");
678 return -ENOPROTOOPT; 690 return -ENOPROTOOPT;
679 } 691 }
diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index a32aa66d66bf..90439314cf67 100644
--- a/drivers/spi/dw_spi.c
+++ b/drivers/spi/dw_spi.c
@@ -182,10 +182,6 @@ static void flush(struct dw_spi *dws)
182 wait_till_not_busy(dws); 182 wait_till_not_busy(dws);
183} 183}
184 184
185static void null_cs_control(u32 command)
186{
187}
188
189static int null_writer(struct dw_spi *dws) 185static int null_writer(struct dw_spi *dws)
190{ 186{
191 u8 n_bytes = dws->n_bytes; 187 u8 n_bytes = dws->n_bytes;
@@ -323,7 +319,7 @@ static void giveback(struct dw_spi *dws)
323 struct spi_transfer, 319 struct spi_transfer,
324 transfer_list); 320 transfer_list);
325 321
326 if (!last_transfer->cs_change) 322 if (!last_transfer->cs_change && dws->cs_control)
327 dws->cs_control(MRST_SPI_DEASSERT); 323 dws->cs_control(MRST_SPI_DEASSERT);
328 324
329 msg->state = NULL; 325 msg->state = NULL;
@@ -397,6 +393,11 @@ static irqreturn_t interrupt_transfer(struct dw_spi *dws)
397static irqreturn_t dw_spi_irq(int irq, void *dev_id) 393static irqreturn_t dw_spi_irq(int irq, void *dev_id)
398{ 394{
399 struct dw_spi *dws = dev_id; 395 struct dw_spi *dws = dev_id;
396 u16 irq_status, irq_mask = 0x3f;
397
398 irq_status = dw_readw(dws, isr) & irq_mask;
399 if (!irq_status)
400 return IRQ_NONE;
400 401
401 if (!dws->cur_msg) { 402 if (!dws->cur_msg) {
402 spi_mask_intr(dws, SPI_INT_TXEI); 403 spi_mask_intr(dws, SPI_INT_TXEI);
@@ -545,13 +546,13 @@ static void pump_transfers(unsigned long data)
545 */ 546 */
546 if (dws->cs_control) { 547 if (dws->cs_control) {
547 if (dws->rx && dws->tx) 548 if (dws->rx && dws->tx)
548 chip->tmode = 0x00; 549 chip->tmode = SPI_TMOD_TR;
549 else if (dws->rx) 550 else if (dws->rx)
550 chip->tmode = 0x02; 551 chip->tmode = SPI_TMOD_RO;
551 else 552 else
552 chip->tmode = 0x01; 553 chip->tmode = SPI_TMOD_TO;
553 554
554 cr0 &= ~(0x3 << SPI_MODE_OFFSET); 555 cr0 &= ~SPI_TMOD_MASK;
555 cr0 |= (chip->tmode << SPI_TMOD_OFFSET); 556 cr0 |= (chip->tmode << SPI_TMOD_OFFSET);
556 } 557 }
557 558
@@ -700,9 +701,6 @@ static int dw_spi_setup(struct spi_device *spi)
700 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); 701 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
701 if (!chip) 702 if (!chip)
702 return -ENOMEM; 703 return -ENOMEM;
703
704 chip->cs_control = null_cs_control;
705 chip->enable_dma = 0;
706 } 704 }
707 705
708 /* 706 /*
@@ -884,7 +882,7 @@ int __devinit dw_spi_add_host(struct dw_spi *dws)
884 dws->dma_inited = 0; 882 dws->dma_inited = 0;
885 dws->dma_addr = (dma_addr_t)(dws->paddr + 0x60); 883 dws->dma_addr = (dma_addr_t)(dws->paddr + 0x60);
886 884
887 ret = request_irq(dws->irq, dw_spi_irq, 0, 885 ret = request_irq(dws->irq, dw_spi_irq, IRQF_SHARED,
888 "dw_spi", dws); 886 "dw_spi", dws);
889 if (ret < 0) { 887 if (ret < 0) {
890 dev_err(&master->dev, "can not get IRQ\n"); 888 dev_err(&master->dev, "can not get IRQ\n");
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index b3a94ca0a75a..2a651e61bfbf 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -296,6 +296,19 @@ static int omap2_mcspi_enable_clocks(struct omap2_mcspi *mcspi)
296 return 0; 296 return 0;
297} 297}
298 298
299static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
300{
301 unsigned long timeout;
302
303 timeout = jiffies + msecs_to_jiffies(1000);
304 while (!(__raw_readl(reg) & bit)) {
305 if (time_after(jiffies, timeout))
306 return -1;
307 cpu_relax();
308 }
309 return 0;
310}
311
299static unsigned 312static unsigned
300omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) 313omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
301{ 314{
@@ -309,11 +322,14 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
309 u32 l; 322 u32 l;
310 u8 * rx; 323 u8 * rx;
311 const u8 * tx; 324 const u8 * tx;
325 void __iomem *chstat_reg;
312 326
313 mcspi = spi_master_get_devdata(spi->master); 327 mcspi = spi_master_get_devdata(spi->master);
314 mcspi_dma = &mcspi->dma_channels[spi->chip_select]; 328 mcspi_dma = &mcspi->dma_channels[spi->chip_select];
315 l = mcspi_cached_chconf0(spi); 329 l = mcspi_cached_chconf0(spi);
316 330
331 chstat_reg = cs->base + OMAP2_MCSPI_CHSTAT0;
332
317 count = xfer->len; 333 count = xfer->len;
318 c = count; 334 c = count;
319 word_len = cs->word_len; 335 word_len = cs->word_len;
@@ -382,6 +398,16 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
382 if (tx != NULL) { 398 if (tx != NULL) {
383 wait_for_completion(&mcspi_dma->dma_tx_completion); 399 wait_for_completion(&mcspi_dma->dma_tx_completion);
384 dma_unmap_single(NULL, xfer->tx_dma, count, DMA_TO_DEVICE); 400 dma_unmap_single(NULL, xfer->tx_dma, count, DMA_TO_DEVICE);
401
402 /* for TX_ONLY mode, be sure all words have shifted out */
403 if (rx == NULL) {
404 if (mcspi_wait_for_reg_bit(chstat_reg,
405 OMAP2_MCSPI_CHSTAT_TXS) < 0)
406 dev_err(&spi->dev, "TXS timed out\n");
407 else if (mcspi_wait_for_reg_bit(chstat_reg,
408 OMAP2_MCSPI_CHSTAT_EOT) < 0)
409 dev_err(&spi->dev, "EOT timed out\n");
410 }
385 } 411 }
386 412
387 if (rx != NULL) { 413 if (rx != NULL) {
@@ -435,19 +461,6 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
435 return count; 461 return count;
436} 462}
437 463
438static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit)
439{
440 unsigned long timeout;
441
442 timeout = jiffies + msecs_to_jiffies(1000);
443 while (!(__raw_readl(reg) & bit)) {
444 if (time_after(jiffies, timeout))
445 return -1;
446 cpu_relax();
447 }
448 return 0;
449}
450
451static unsigned 464static unsigned
452omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer) 465omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
453{ 466{
@@ -489,10 +502,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
489 dev_err(&spi->dev, "TXS timed out\n"); 502 dev_err(&spi->dev, "TXS timed out\n");
490 goto out; 503 goto out;
491 } 504 }
492#ifdef VERBOSE 505 dev_vdbg(&spi->dev, "write-%d %02x\n",
493 dev_dbg(&spi->dev, "write-%d %02x\n",
494 word_len, *tx); 506 word_len, *tx);
495#endif
496 __raw_writel(*tx++, tx_reg); 507 __raw_writel(*tx++, tx_reg);
497 } 508 }
498 if (rx != NULL) { 509 if (rx != NULL) {
@@ -506,10 +517,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
506 (l & OMAP2_MCSPI_CHCONF_TURBO)) { 517 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
507 omap2_mcspi_set_enable(spi, 0); 518 omap2_mcspi_set_enable(spi, 0);
508 *rx++ = __raw_readl(rx_reg); 519 *rx++ = __raw_readl(rx_reg);
509#ifdef VERBOSE 520 dev_vdbg(&spi->dev, "read-%d %02x\n",
510 dev_dbg(&spi->dev, "read-%d %02x\n",
511 word_len, *(rx - 1)); 521 word_len, *(rx - 1));
512#endif
513 if (mcspi_wait_for_reg_bit(chstat_reg, 522 if (mcspi_wait_for_reg_bit(chstat_reg,
514 OMAP2_MCSPI_CHSTAT_RXS) < 0) { 523 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
515 dev_err(&spi->dev, 524 dev_err(&spi->dev,
@@ -522,10 +531,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
522 } 531 }
523 532
524 *rx++ = __raw_readl(rx_reg); 533 *rx++ = __raw_readl(rx_reg);
525#ifdef VERBOSE 534 dev_vdbg(&spi->dev, "read-%d %02x\n",
526 dev_dbg(&spi->dev, "read-%d %02x\n",
527 word_len, *(rx - 1)); 535 word_len, *(rx - 1));
528#endif
529 } 536 }
530 } while (c); 537 } while (c);
531 } else if (word_len <= 16) { 538 } else if (word_len <= 16) {
@@ -542,10 +549,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
542 dev_err(&spi->dev, "TXS timed out\n"); 549 dev_err(&spi->dev, "TXS timed out\n");
543 goto out; 550 goto out;
544 } 551 }
545#ifdef VERBOSE 552 dev_vdbg(&spi->dev, "write-%d %04x\n",
546 dev_dbg(&spi->dev, "write-%d %04x\n",
547 word_len, *tx); 553 word_len, *tx);
548#endif
549 __raw_writel(*tx++, tx_reg); 554 __raw_writel(*tx++, tx_reg);
550 } 555 }
551 if (rx != NULL) { 556 if (rx != NULL) {
@@ -559,10 +564,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
559 (l & OMAP2_MCSPI_CHCONF_TURBO)) { 564 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
560 omap2_mcspi_set_enable(spi, 0); 565 omap2_mcspi_set_enable(spi, 0);
561 *rx++ = __raw_readl(rx_reg); 566 *rx++ = __raw_readl(rx_reg);
562#ifdef VERBOSE 567 dev_vdbg(&spi->dev, "read-%d %04x\n",
563 dev_dbg(&spi->dev, "read-%d %04x\n",
564 word_len, *(rx - 1)); 568 word_len, *(rx - 1));
565#endif
566 if (mcspi_wait_for_reg_bit(chstat_reg, 569 if (mcspi_wait_for_reg_bit(chstat_reg,
567 OMAP2_MCSPI_CHSTAT_RXS) < 0) { 570 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
568 dev_err(&spi->dev, 571 dev_err(&spi->dev,
@@ -575,10 +578,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
575 } 578 }
576 579
577 *rx++ = __raw_readl(rx_reg); 580 *rx++ = __raw_readl(rx_reg);
578#ifdef VERBOSE 581 dev_vdbg(&spi->dev, "read-%d %04x\n",
579 dev_dbg(&spi->dev, "read-%d %04x\n",
580 word_len, *(rx - 1)); 582 word_len, *(rx - 1));
581#endif
582 } 583 }
583 } while (c); 584 } while (c);
584 } else if (word_len <= 32) { 585 } else if (word_len <= 32) {
@@ -595,10 +596,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
595 dev_err(&spi->dev, "TXS timed out\n"); 596 dev_err(&spi->dev, "TXS timed out\n");
596 goto out; 597 goto out;
597 } 598 }
598#ifdef VERBOSE 599 dev_vdbg(&spi->dev, "write-%d %08x\n",
599 dev_dbg(&spi->dev, "write-%d %08x\n",
600 word_len, *tx); 600 word_len, *tx);
601#endif
602 __raw_writel(*tx++, tx_reg); 601 __raw_writel(*tx++, tx_reg);
603 } 602 }
604 if (rx != NULL) { 603 if (rx != NULL) {
@@ -612,10 +611,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
612 (l & OMAP2_MCSPI_CHCONF_TURBO)) { 611 (l & OMAP2_MCSPI_CHCONF_TURBO)) {
613 omap2_mcspi_set_enable(spi, 0); 612 omap2_mcspi_set_enable(spi, 0);
614 *rx++ = __raw_readl(rx_reg); 613 *rx++ = __raw_readl(rx_reg);
615#ifdef VERBOSE 614 dev_vdbg(&spi->dev, "read-%d %08x\n",
616 dev_dbg(&spi->dev, "read-%d %08x\n",
617 word_len, *(rx - 1)); 615 word_len, *(rx - 1));
618#endif
619 if (mcspi_wait_for_reg_bit(chstat_reg, 616 if (mcspi_wait_for_reg_bit(chstat_reg,
620 OMAP2_MCSPI_CHSTAT_RXS) < 0) { 617 OMAP2_MCSPI_CHSTAT_RXS) < 0) {
621 dev_err(&spi->dev, 618 dev_err(&spi->dev,
@@ -628,10 +625,8 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
628 } 625 }
629 626
630 *rx++ = __raw_readl(rx_reg); 627 *rx++ = __raw_readl(rx_reg);
631#ifdef VERBOSE 628 dev_vdbg(&spi->dev, "read-%d %08x\n",
632 dev_dbg(&spi->dev, "read-%d %08x\n",
633 word_len, *(rx - 1)); 629 word_len, *(rx - 1));
634#endif
635 } 630 }
636 } while (c); 631 } while (c);
637 } 632 }
@@ -644,6 +639,12 @@ omap2_mcspi_txrx_pio(struct spi_device *spi, struct spi_transfer *xfer)
644 } else if (mcspi_wait_for_reg_bit(chstat_reg, 639 } else if (mcspi_wait_for_reg_bit(chstat_reg,
645 OMAP2_MCSPI_CHSTAT_EOT) < 0) 640 OMAP2_MCSPI_CHSTAT_EOT) < 0)
646 dev_err(&spi->dev, "EOT timed out\n"); 641 dev_err(&spi->dev, "EOT timed out\n");
642
643 /* disable chan to purge rx datas received in TX_ONLY transfer,
644 * otherwise these rx datas will affect the direct following
645 * RX_ONLY transfer.
646 */
647 omap2_mcspi_set_enable(spi, 0);
647 } 648 }
648out: 649out:
649 omap2_mcspi_set_enable(spi, 1); 650 omap2_mcspi_set_enable(spi, 1);
diff --git a/drivers/spi/orion_spi.c b/drivers/spi/orion_spi.c
index 3aea50da7b29..0b677dc041ad 100644
--- a/drivers/spi/orion_spi.c
+++ b/drivers/spi/orion_spi.c
@@ -404,7 +404,7 @@ static int orion_spi_transfer(struct spi_device *spi, struct spi_message *m)
404 goto msg_rejected; 404 goto msg_rejected;
405 } 405 }
406 406
407 if ((t != NULL) && t->bits_per_word) 407 if (t->bits_per_word)
408 bits_per_word = t->bits_per_word; 408 bits_per_word = t->bits_per_word;
409 409
410 if ((bits_per_word != 8) && (bits_per_word != 16)) { 410 if ((bits_per_word != 8) && (bits_per_word != 16)) {
@@ -415,7 +415,7 @@ static int orion_spi_transfer(struct spi_device *spi, struct spi_message *m)
415 goto msg_rejected; 415 goto msg_rejected;
416 } 416 }
417 /*make sure buffer length is even when working in 16 bit mode*/ 417 /*make sure buffer length is even when working in 16 bit mode*/
418 if ((t != NULL) && (t->bits_per_word == 16) && (t->len & 1)) { 418 if ((t->bits_per_word == 16) && (t->len & 1)) {
419 dev_err(&spi->dev, 419 dev_err(&spi->dev,
420 "message rejected : " 420 "message rejected : "
421 "odd data length (%d) while in 16 bit mode\n", 421 "odd data length (%d) while in 16 bit mode\n",
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a9e5c79ae52a..b5a78a1f4421 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -23,6 +23,7 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/cache.h> 24#include <linux/cache.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26#include <linux/of_device.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27#include <linux/mod_devicetable.h> 28#include <linux/mod_devicetable.h>
28#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
@@ -86,6 +87,10 @@ static int spi_match_device(struct device *dev, struct device_driver *drv)
86 const struct spi_device *spi = to_spi_device(dev); 87 const struct spi_device *spi = to_spi_device(dev);
87 const struct spi_driver *sdrv = to_spi_driver(drv); 88 const struct spi_driver *sdrv = to_spi_driver(drv);
88 89
90 /* Attempt an OF style match */
91 if (of_driver_match_device(dev, drv))
92 return 1;
93
89 if (sdrv->id_table) 94 if (sdrv->id_table)
90 return !!spi_match_id(sdrv->id_table, spi); 95 return !!spi_match_id(sdrv->id_table, spi);
91 96
@@ -554,11 +559,9 @@ done:
554EXPORT_SYMBOL_GPL(spi_register_master); 559EXPORT_SYMBOL_GPL(spi_register_master);
555 560
556 561
557static int __unregister(struct device *dev, void *master_dev) 562static int __unregister(struct device *dev, void *null)
558{ 563{
559 /* note: before about 2.6.14-rc1 this would corrupt memory: */ 564 spi_unregister_device(to_spi_device(dev));
560 if (dev != master_dev)
561 spi_unregister_device(to_spi_device(dev));
562 return 0; 565 return 0;
563} 566}
564 567
@@ -576,8 +579,7 @@ void spi_unregister_master(struct spi_master *master)
576{ 579{
577 int dummy; 580 int dummy;
578 581
579 dummy = device_for_each_child(master->dev.parent, &master->dev, 582 dummy = device_for_each_child(&master->dev, NULL, __unregister);
580 __unregister);
581 device_unregister(&master->dev); 583 device_unregister(&master->dev);
582} 584}
583EXPORT_SYMBOL_GPL(spi_unregister_master); 585EXPORT_SYMBOL_GPL(spi_unregister_master);
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index 10a6dc3d37ac..ab483a0ec6d0 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Blackfin On-Chip SPI Driver 2 * Blackfin On-Chip SPI Driver
3 * 3 *
4 * Copyright 2004-2007 Analog Devices Inc. 4 * Copyright 2004-2010 Analog Devices Inc.
5 * 5 *
6 * Enter bugs at http://blackfin.uclinux.org/ 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
@@ -41,13 +41,16 @@ MODULE_LICENSE("GPL");
41#define RUNNING_STATE ((void *)1) 41#define RUNNING_STATE ((void *)1)
42#define DONE_STATE ((void *)2) 42#define DONE_STATE ((void *)2)
43#define ERROR_STATE ((void *)-1) 43#define ERROR_STATE ((void *)-1)
44#define QUEUE_RUNNING 0
45#define QUEUE_STOPPED 1
46 44
47/* Value to send if no TX value is supplied */ 45struct bfin_spi_master_data;
48#define SPI_IDLE_TXVAL 0x0000
49 46
50struct driver_data { 47struct bfin_spi_transfer_ops {
48 void (*write) (struct bfin_spi_master_data *);
49 void (*read) (struct bfin_spi_master_data *);
50 void (*duplex) (struct bfin_spi_master_data *);
51};
52
53struct bfin_spi_master_data {
51 /* Driver model hookup */ 54 /* Driver model hookup */
52 struct platform_device *pdev; 55 struct platform_device *pdev;
53 56
@@ -69,7 +72,7 @@ struct driver_data {
69 spinlock_t lock; 72 spinlock_t lock;
70 struct list_head queue; 73 struct list_head queue;
71 int busy; 74 int busy;
72 int run; 75 bool running;
73 76
74 /* Message Transfer pump */ 77 /* Message Transfer pump */
75 struct tasklet_struct pump_transfers; 78 struct tasklet_struct pump_transfers;
@@ -77,7 +80,7 @@ struct driver_data {
77 /* Current message transfer state info */ 80 /* Current message transfer state info */
78 struct spi_message *cur_msg; 81 struct spi_message *cur_msg;
79 struct spi_transfer *cur_transfer; 82 struct spi_transfer *cur_transfer;
80 struct chip_data *cur_chip; 83 struct bfin_spi_slave_data *cur_chip;
81 size_t len_in_bytes; 84 size_t len_in_bytes;
82 size_t len; 85 size_t len;
83 void *tx; 86 void *tx;
@@ -92,38 +95,37 @@ struct driver_data {
92 dma_addr_t rx_dma; 95 dma_addr_t rx_dma;
93 dma_addr_t tx_dma; 96 dma_addr_t tx_dma;
94 97
98 int irq_requested;
99 int spi_irq;
100
95 size_t rx_map_len; 101 size_t rx_map_len;
96 size_t tx_map_len; 102 size_t tx_map_len;
97 u8 n_bytes; 103 u8 n_bytes;
104 u16 ctrl_reg;
105 u16 flag_reg;
106
98 int cs_change; 107 int cs_change;
99 void (*write) (struct driver_data *); 108 const struct bfin_spi_transfer_ops *ops;
100 void (*read) (struct driver_data *);
101 void (*duplex) (struct driver_data *);
102}; 109};
103 110
104struct chip_data { 111struct bfin_spi_slave_data {
105 u16 ctl_reg; 112 u16 ctl_reg;
106 u16 baud; 113 u16 baud;
107 u16 flag; 114 u16 flag;
108 115
109 u8 chip_select_num; 116 u8 chip_select_num;
110 u8 n_bytes;
111 u8 width; /* 0 or 1 */
112 u8 enable_dma; 117 u8 enable_dma;
113 u8 bits_per_word; /* 8 or 16 */
114 u8 cs_change_per_word;
115 u16 cs_chg_udelay; /* Some devices require > 255usec delay */ 118 u16 cs_chg_udelay; /* Some devices require > 255usec delay */
116 u32 cs_gpio; 119 u32 cs_gpio;
117 u16 idle_tx_val; 120 u16 idle_tx_val;
118 void (*write) (struct driver_data *); 121 u8 pio_interrupt; /* use spi data irq */
119 void (*read) (struct driver_data *); 122 const struct bfin_spi_transfer_ops *ops;
120 void (*duplex) (struct driver_data *);
121}; 123};
122 124
123#define DEFINE_SPI_REG(reg, off) \ 125#define DEFINE_SPI_REG(reg, off) \
124static inline u16 read_##reg(struct driver_data *drv_data) \ 126static inline u16 read_##reg(struct bfin_spi_master_data *drv_data) \
125 { return bfin_read16(drv_data->regs_base + off); } \ 127 { return bfin_read16(drv_data->regs_base + off); } \
126static inline void write_##reg(struct driver_data *drv_data, u16 v) \ 128static inline void write_##reg(struct bfin_spi_master_data *drv_data, u16 v) \
127 { bfin_write16(drv_data->regs_base + off, v); } 129 { bfin_write16(drv_data->regs_base + off, v); }
128 130
129DEFINE_SPI_REG(CTRL, 0x00) 131DEFINE_SPI_REG(CTRL, 0x00)
@@ -134,7 +136,7 @@ DEFINE_SPI_REG(RDBR, 0x10)
134DEFINE_SPI_REG(BAUD, 0x14) 136DEFINE_SPI_REG(BAUD, 0x14)
135DEFINE_SPI_REG(SHAW, 0x18) 137DEFINE_SPI_REG(SHAW, 0x18)
136 138
137static void bfin_spi_enable(struct driver_data *drv_data) 139static void bfin_spi_enable(struct bfin_spi_master_data *drv_data)
138{ 140{
139 u16 cr; 141 u16 cr;
140 142
@@ -142,7 +144,7 @@ static void bfin_spi_enable(struct driver_data *drv_data)
142 write_CTRL(drv_data, (cr | BIT_CTL_ENABLE)); 144 write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
143} 145}
144 146
145static void bfin_spi_disable(struct driver_data *drv_data) 147static void bfin_spi_disable(struct bfin_spi_master_data *drv_data)
146{ 148{
147 u16 cr; 149 u16 cr;
148 150
@@ -165,7 +167,7 @@ static u16 hz_to_spi_baud(u32 speed_hz)
165 return spi_baud; 167 return spi_baud;
166} 168}
167 169
168static int bfin_spi_flush(struct driver_data *drv_data) 170static int bfin_spi_flush(struct bfin_spi_master_data *drv_data)
169{ 171{
170 unsigned long limit = loops_per_jiffy << 1; 172 unsigned long limit = loops_per_jiffy << 1;
171 173
@@ -179,13 +181,12 @@ static int bfin_spi_flush(struct driver_data *drv_data)
179} 181}
180 182
181/* Chip select operation functions for cs_change flag */ 183/* Chip select operation functions for cs_change flag */
182static void bfin_spi_cs_active(struct driver_data *drv_data, struct chip_data *chip) 184static void bfin_spi_cs_active(struct bfin_spi_master_data *drv_data, struct bfin_spi_slave_data *chip)
183{ 185{
184 if (likely(chip->chip_select_num)) { 186 if (likely(chip->chip_select_num < MAX_CTRL_CS)) {
185 u16 flag = read_FLAG(drv_data); 187 u16 flag = read_FLAG(drv_data);
186 188
187 flag |= chip->flag; 189 flag &= ~chip->flag;
188 flag &= ~(chip->flag << 8);
189 190
190 write_FLAG(drv_data, flag); 191 write_FLAG(drv_data, flag);
191 } else { 192 } else {
@@ -193,13 +194,13 @@ static void bfin_spi_cs_active(struct driver_data *drv_data, struct chip_data *c
193 } 194 }
194} 195}
195 196
196static void bfin_spi_cs_deactive(struct driver_data *drv_data, struct chip_data *chip) 197static void bfin_spi_cs_deactive(struct bfin_spi_master_data *drv_data,
198 struct bfin_spi_slave_data *chip)
197{ 199{
198 if (likely(chip->chip_select_num)) { 200 if (likely(chip->chip_select_num < MAX_CTRL_CS)) {
199 u16 flag = read_FLAG(drv_data); 201 u16 flag = read_FLAG(drv_data);
200 202
201 flag &= ~chip->flag; 203 flag |= chip->flag;
202 flag |= (chip->flag << 8);
203 204
204 write_FLAG(drv_data, flag); 205 write_FLAG(drv_data, flag);
205 } else { 206 } else {
@@ -211,16 +212,43 @@ static void bfin_spi_cs_deactive(struct driver_data *drv_data, struct chip_data
211 udelay(chip->cs_chg_udelay); 212 udelay(chip->cs_chg_udelay);
212} 213}
213 214
215/* enable or disable the pin muxed by GPIO and SPI CS to work as SPI CS */
216static inline void bfin_spi_cs_enable(struct bfin_spi_master_data *drv_data,
217 struct bfin_spi_slave_data *chip)
218{
219 if (chip->chip_select_num < MAX_CTRL_CS) {
220 u16 flag = read_FLAG(drv_data);
221
222 flag |= (chip->flag >> 8);
223
224 write_FLAG(drv_data, flag);
225 }
226}
227
228static inline void bfin_spi_cs_disable(struct bfin_spi_master_data *drv_data,
229 struct bfin_spi_slave_data *chip)
230{
231 if (chip->chip_select_num < MAX_CTRL_CS) {
232 u16 flag = read_FLAG(drv_data);
233
234 flag &= ~(chip->flag >> 8);
235
236 write_FLAG(drv_data, flag);
237 }
238}
239
214/* stop controller and re-config current chip*/ 240/* stop controller and re-config current chip*/
215static void bfin_spi_restore_state(struct driver_data *drv_data) 241static void bfin_spi_restore_state(struct bfin_spi_master_data *drv_data)
216{ 242{
217 struct chip_data *chip = drv_data->cur_chip; 243 struct bfin_spi_slave_data *chip = drv_data->cur_chip;
218 244
219 /* Clear status and disable clock */ 245 /* Clear status and disable clock */
220 write_STAT(drv_data, BIT_STAT_CLR); 246 write_STAT(drv_data, BIT_STAT_CLR);
221 bfin_spi_disable(drv_data); 247 bfin_spi_disable(drv_data);
222 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n"); 248 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n");
223 249
250 SSYNC();
251
224 /* Load the registers */ 252 /* Load the registers */
225 write_CTRL(drv_data, chip->ctl_reg); 253 write_CTRL(drv_data, chip->ctl_reg);
226 write_BAUD(drv_data, chip->baud); 254 write_BAUD(drv_data, chip->baud);
@@ -230,49 +258,12 @@ static void bfin_spi_restore_state(struct driver_data *drv_data)
230} 258}
231 259
232/* used to kick off transfer in rx mode and read unwanted RX data */ 260/* used to kick off transfer in rx mode and read unwanted RX data */
233static inline void bfin_spi_dummy_read(struct driver_data *drv_data) 261static inline void bfin_spi_dummy_read(struct bfin_spi_master_data *drv_data)
234{ 262{
235 (void) read_RDBR(drv_data); 263 (void) read_RDBR(drv_data);
236} 264}
237 265
238static void bfin_spi_null_writer(struct driver_data *drv_data) 266static void bfin_spi_u8_writer(struct bfin_spi_master_data *drv_data)
239{
240 u8 n_bytes = drv_data->n_bytes;
241 u16 tx_val = drv_data->cur_chip->idle_tx_val;
242
243 /* clear RXS (we check for RXS inside the loop) */
244 bfin_spi_dummy_read(drv_data);
245
246 while (drv_data->tx < drv_data->tx_end) {
247 write_TDBR(drv_data, tx_val);
248 drv_data->tx += n_bytes;
249 /* wait until transfer finished.
250 checking SPIF or TXS may not guarantee transfer completion */
251 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
252 cpu_relax();
253 /* discard RX data and clear RXS */
254 bfin_spi_dummy_read(drv_data);
255 }
256}
257
258static void bfin_spi_null_reader(struct driver_data *drv_data)
259{
260 u8 n_bytes = drv_data->n_bytes;
261 u16 tx_val = drv_data->cur_chip->idle_tx_val;
262
263 /* discard old RX data and clear RXS */
264 bfin_spi_dummy_read(drv_data);
265
266 while (drv_data->rx < drv_data->rx_end) {
267 write_TDBR(drv_data, tx_val);
268 drv_data->rx += n_bytes;
269 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
270 cpu_relax();
271 bfin_spi_dummy_read(drv_data);
272 }
273}
274
275static void bfin_spi_u8_writer(struct driver_data *drv_data)
276{ 267{
277 /* clear RXS (we check for RXS inside the loop) */ 268 /* clear RXS (we check for RXS inside the loop) */
278 bfin_spi_dummy_read(drv_data); 269 bfin_spi_dummy_read(drv_data);
@@ -288,25 +279,7 @@ static void bfin_spi_u8_writer(struct driver_data *drv_data)
288 } 279 }
289} 280}
290 281
291static void bfin_spi_u8_cs_chg_writer(struct driver_data *drv_data) 282static void bfin_spi_u8_reader(struct bfin_spi_master_data *drv_data)
292{
293 struct chip_data *chip = drv_data->cur_chip;
294
295 /* clear RXS (we check for RXS inside the loop) */
296 bfin_spi_dummy_read(drv_data);
297
298 while (drv_data->tx < drv_data->tx_end) {
299 bfin_spi_cs_active(drv_data, chip);
300 write_TDBR(drv_data, (*(u8 *) (drv_data->tx++)));
301 /* make sure transfer finished before deactiving CS */
302 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
303 cpu_relax();
304 bfin_spi_dummy_read(drv_data);
305 bfin_spi_cs_deactive(drv_data, chip);
306 }
307}
308
309static void bfin_spi_u8_reader(struct driver_data *drv_data)
310{ 283{
311 u16 tx_val = drv_data->cur_chip->idle_tx_val; 284 u16 tx_val = drv_data->cur_chip->idle_tx_val;
312 285
@@ -321,25 +294,7 @@ static void bfin_spi_u8_reader(struct driver_data *drv_data)
321 } 294 }
322} 295}
323 296
324static void bfin_spi_u8_cs_chg_reader(struct driver_data *drv_data) 297static void bfin_spi_u8_duplex(struct bfin_spi_master_data *drv_data)
325{
326 struct chip_data *chip = drv_data->cur_chip;
327 u16 tx_val = chip->idle_tx_val;
328
329 /* discard old RX data and clear RXS */
330 bfin_spi_dummy_read(drv_data);
331
332 while (drv_data->rx < drv_data->rx_end) {
333 bfin_spi_cs_active(drv_data, chip);
334 write_TDBR(drv_data, tx_val);
335 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
336 cpu_relax();
337 *(u8 *) (drv_data->rx++) = read_RDBR(drv_data);
338 bfin_spi_cs_deactive(drv_data, chip);
339 }
340}
341
342static void bfin_spi_u8_duplex(struct driver_data *drv_data)
343{ 298{
344 /* discard old RX data and clear RXS */ 299 /* discard old RX data and clear RXS */
345 bfin_spi_dummy_read(drv_data); 300 bfin_spi_dummy_read(drv_data);
@@ -352,24 +307,13 @@ static void bfin_spi_u8_duplex(struct driver_data *drv_data)
352 } 307 }
353} 308}
354 309
355static void bfin_spi_u8_cs_chg_duplex(struct driver_data *drv_data) 310static const struct bfin_spi_transfer_ops bfin_bfin_spi_transfer_ops_u8 = {
356{ 311 .write = bfin_spi_u8_writer,
357 struct chip_data *chip = drv_data->cur_chip; 312 .read = bfin_spi_u8_reader,
358 313 .duplex = bfin_spi_u8_duplex,
359 /* discard old RX data and clear RXS */ 314};
360 bfin_spi_dummy_read(drv_data);
361
362 while (drv_data->rx < drv_data->rx_end) {
363 bfin_spi_cs_active(drv_data, chip);
364 write_TDBR(drv_data, (*(u8 *) (drv_data->tx++)));
365 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
366 cpu_relax();
367 *(u8 *) (drv_data->rx++) = read_RDBR(drv_data);
368 bfin_spi_cs_deactive(drv_data, chip);
369 }
370}
371 315
372static void bfin_spi_u16_writer(struct driver_data *drv_data) 316static void bfin_spi_u16_writer(struct bfin_spi_master_data *drv_data)
373{ 317{
374 /* clear RXS (we check for RXS inside the loop) */ 318 /* clear RXS (we check for RXS inside the loop) */
375 bfin_spi_dummy_read(drv_data); 319 bfin_spi_dummy_read(drv_data);
@@ -386,26 +330,7 @@ static void bfin_spi_u16_writer(struct driver_data *drv_data)
386 } 330 }
387} 331}
388 332
389static void bfin_spi_u16_cs_chg_writer(struct driver_data *drv_data) 333static void bfin_spi_u16_reader(struct bfin_spi_master_data *drv_data)
390{
391 struct chip_data *chip = drv_data->cur_chip;
392
393 /* clear RXS (we check for RXS inside the loop) */
394 bfin_spi_dummy_read(drv_data);
395
396 while (drv_data->tx < drv_data->tx_end) {
397 bfin_spi_cs_active(drv_data, chip);
398 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
399 drv_data->tx += 2;
400 /* make sure transfer finished before deactiving CS */
401 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
402 cpu_relax();
403 bfin_spi_dummy_read(drv_data);
404 bfin_spi_cs_deactive(drv_data, chip);
405 }
406}
407
408static void bfin_spi_u16_reader(struct driver_data *drv_data)
409{ 334{
410 u16 tx_val = drv_data->cur_chip->idle_tx_val; 335 u16 tx_val = drv_data->cur_chip->idle_tx_val;
411 336
@@ -421,26 +346,7 @@ static void bfin_spi_u16_reader(struct driver_data *drv_data)
421 } 346 }
422} 347}
423 348
424static void bfin_spi_u16_cs_chg_reader(struct driver_data *drv_data) 349static void bfin_spi_u16_duplex(struct bfin_spi_master_data *drv_data)
425{
426 struct chip_data *chip = drv_data->cur_chip;
427 u16 tx_val = chip->idle_tx_val;
428
429 /* discard old RX data and clear RXS */
430 bfin_spi_dummy_read(drv_data);
431
432 while (drv_data->rx < drv_data->rx_end) {
433 bfin_spi_cs_active(drv_data, chip);
434 write_TDBR(drv_data, tx_val);
435 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
436 cpu_relax();
437 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
438 drv_data->rx += 2;
439 bfin_spi_cs_deactive(drv_data, chip);
440 }
441}
442
443static void bfin_spi_u16_duplex(struct driver_data *drv_data)
444{ 350{
445 /* discard old RX data and clear RXS */ 351 /* discard old RX data and clear RXS */
446 bfin_spi_dummy_read(drv_data); 352 bfin_spi_dummy_read(drv_data);
@@ -455,27 +361,14 @@ static void bfin_spi_u16_duplex(struct driver_data *drv_data)
455 } 361 }
456} 362}
457 363
458static void bfin_spi_u16_cs_chg_duplex(struct driver_data *drv_data) 364static const struct bfin_spi_transfer_ops bfin_bfin_spi_transfer_ops_u16 = {
459{ 365 .write = bfin_spi_u16_writer,
460 struct chip_data *chip = drv_data->cur_chip; 366 .read = bfin_spi_u16_reader,
461 367 .duplex = bfin_spi_u16_duplex,
462 /* discard old RX data and clear RXS */ 368};
463 bfin_spi_dummy_read(drv_data);
464
465 while (drv_data->rx < drv_data->rx_end) {
466 bfin_spi_cs_active(drv_data, chip);
467 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
468 drv_data->tx += 2;
469 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
470 cpu_relax();
471 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
472 drv_data->rx += 2;
473 bfin_spi_cs_deactive(drv_data, chip);
474 }
475}
476 369
477/* test if ther is more transfer to be done */ 370/* test if there is more transfer to be done */
478static void *bfin_spi_next_transfer(struct driver_data *drv_data) 371static void *bfin_spi_next_transfer(struct bfin_spi_master_data *drv_data)
479{ 372{
480 struct spi_message *msg = drv_data->cur_msg; 373 struct spi_message *msg = drv_data->cur_msg;
481 struct spi_transfer *trans = drv_data->cur_transfer; 374 struct spi_transfer *trans = drv_data->cur_transfer;
@@ -494,9 +387,9 @@ static void *bfin_spi_next_transfer(struct driver_data *drv_data)
494 * caller already set message->status; 387 * caller already set message->status;
495 * dma and pio irqs are blocked give finished message back 388 * dma and pio irqs are blocked give finished message back
496 */ 389 */
497static void bfin_spi_giveback(struct driver_data *drv_data) 390static void bfin_spi_giveback(struct bfin_spi_master_data *drv_data)
498{ 391{
499 struct chip_data *chip = drv_data->cur_chip; 392 struct bfin_spi_slave_data *chip = drv_data->cur_chip;
500 struct spi_transfer *last_transfer; 393 struct spi_transfer *last_transfer;
501 unsigned long flags; 394 unsigned long flags;
502 struct spi_message *msg; 395 struct spi_message *msg;
@@ -525,10 +418,83 @@ static void bfin_spi_giveback(struct driver_data *drv_data)
525 msg->complete(msg->context); 418 msg->complete(msg->context);
526} 419}
527 420
421/* spi data irq handler */
422static irqreturn_t bfin_spi_pio_irq_handler(int irq, void *dev_id)
423{
424 struct bfin_spi_master_data *drv_data = dev_id;
425 struct bfin_spi_slave_data *chip = drv_data->cur_chip;
426 struct spi_message *msg = drv_data->cur_msg;
427 int n_bytes = drv_data->n_bytes;
428
429 /* wait until transfer finished. */
430 while (!(read_STAT(drv_data) & BIT_STAT_RXS))
431 cpu_relax();
432
433 if ((drv_data->tx && drv_data->tx >= drv_data->tx_end) ||
434 (drv_data->rx && drv_data->rx >= (drv_data->rx_end - n_bytes))) {
435 /* last read */
436 if (drv_data->rx) {
437 dev_dbg(&drv_data->pdev->dev, "last read\n");
438 if (n_bytes == 2)
439 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
440 else if (n_bytes == 1)
441 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
442 drv_data->rx += n_bytes;
443 }
444
445 msg->actual_length += drv_data->len_in_bytes;
446 if (drv_data->cs_change)
447 bfin_spi_cs_deactive(drv_data, chip);
448 /* Move to next transfer */
449 msg->state = bfin_spi_next_transfer(drv_data);
450
451 disable_irq_nosync(drv_data->spi_irq);
452
453 /* Schedule transfer tasklet */
454 tasklet_schedule(&drv_data->pump_transfers);
455 return IRQ_HANDLED;
456 }
457
458 if (drv_data->rx && drv_data->tx) {
459 /* duplex */
460 dev_dbg(&drv_data->pdev->dev, "duplex: write_TDBR\n");
461 if (drv_data->n_bytes == 2) {
462 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
463 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
464 } else if (drv_data->n_bytes == 1) {
465 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
466 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
467 }
468 } else if (drv_data->rx) {
469 /* read */
470 dev_dbg(&drv_data->pdev->dev, "read: write_TDBR\n");
471 if (drv_data->n_bytes == 2)
472 *(u16 *) (drv_data->rx) = read_RDBR(drv_data);
473 else if (drv_data->n_bytes == 1)
474 *(u8 *) (drv_data->rx) = read_RDBR(drv_data);
475 write_TDBR(drv_data, chip->idle_tx_val);
476 } else if (drv_data->tx) {
477 /* write */
478 dev_dbg(&drv_data->pdev->dev, "write: write_TDBR\n");
479 bfin_spi_dummy_read(drv_data);
480 if (drv_data->n_bytes == 2)
481 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
482 else if (drv_data->n_bytes == 1)
483 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
484 }
485
486 if (drv_data->tx)
487 drv_data->tx += n_bytes;
488 if (drv_data->rx)
489 drv_data->rx += n_bytes;
490
491 return IRQ_HANDLED;
492}
493
528static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id) 494static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
529{ 495{
530 struct driver_data *drv_data = dev_id; 496 struct bfin_spi_master_data *drv_data = dev_id;
531 struct chip_data *chip = drv_data->cur_chip; 497 struct bfin_spi_slave_data *chip = drv_data->cur_chip;
532 struct spi_message *msg = drv_data->cur_msg; 498 struct spi_message *msg = drv_data->cur_msg;
533 unsigned long timeout; 499 unsigned long timeout;
534 unsigned short dmastat = get_dma_curr_irqstat(drv_data->dma_channel); 500 unsigned short dmastat = get_dma_curr_irqstat(drv_data->dma_channel);
@@ -540,10 +506,6 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
540 506
541 clear_dma_irqstat(drv_data->dma_channel); 507 clear_dma_irqstat(drv_data->dma_channel);
542 508
543 /* Wait for DMA to complete */
544 while (get_dma_curr_irqstat(drv_data->dma_channel) & DMA_RUN)
545 cpu_relax();
546
547 /* 509 /*
548 * wait for the last transaction shifted out. HRM states: 510 * wait for the last transaction shifted out. HRM states:
549 * at this point there may still be data in the SPI DMA FIFO waiting 511 * at this point there may still be data in the SPI DMA FIFO waiting
@@ -551,8 +513,8 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
551 * register until it goes low for 2 successive reads 513 * register until it goes low for 2 successive reads
552 */ 514 */
553 if (drv_data->tx != NULL) { 515 if (drv_data->tx != NULL) {
554 while ((read_STAT(drv_data) & TXS) || 516 while ((read_STAT(drv_data) & BIT_STAT_TXS) ||
555 (read_STAT(drv_data) & TXS)) 517 (read_STAT(drv_data) & BIT_STAT_TXS))
556 cpu_relax(); 518 cpu_relax();
557 } 519 }
558 520
@@ -561,14 +523,14 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
561 dmastat, read_STAT(drv_data)); 523 dmastat, read_STAT(drv_data));
562 524
563 timeout = jiffies + HZ; 525 timeout = jiffies + HZ;
564 while (!(read_STAT(drv_data) & SPIF)) 526 while (!(read_STAT(drv_data) & BIT_STAT_SPIF))
565 if (!time_before(jiffies, timeout)) { 527 if (!time_before(jiffies, timeout)) {
566 dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF"); 528 dev_warn(&drv_data->pdev->dev, "timeout waiting for SPIF");
567 break; 529 break;
568 } else 530 } else
569 cpu_relax(); 531 cpu_relax();
570 532
571 if ((dmastat & DMA_ERR) && (spistat & RBSY)) { 533 if ((dmastat & DMA_ERR) && (spistat & BIT_STAT_RBSY)) {
572 msg->state = ERROR_STATE; 534 msg->state = ERROR_STATE;
573 dev_err(&drv_data->pdev->dev, "dma receive: fifo/buffer overflow\n"); 535 dev_err(&drv_data->pdev->dev, "dma receive: fifo/buffer overflow\n");
574 } else { 536 } else {
@@ -588,20 +550,20 @@ static irqreturn_t bfin_spi_dma_irq_handler(int irq, void *dev_id)
588 dev_dbg(&drv_data->pdev->dev, 550 dev_dbg(&drv_data->pdev->dev,
589 "disable dma channel irq%d\n", 551 "disable dma channel irq%d\n",
590 drv_data->dma_channel); 552 drv_data->dma_channel);
591 dma_disable_irq(drv_data->dma_channel); 553 dma_disable_irq_nosync(drv_data->dma_channel);
592 554
593 return IRQ_HANDLED; 555 return IRQ_HANDLED;
594} 556}
595 557
596static void bfin_spi_pump_transfers(unsigned long data) 558static void bfin_spi_pump_transfers(unsigned long data)
597{ 559{
598 struct driver_data *drv_data = (struct driver_data *)data; 560 struct bfin_spi_master_data *drv_data = (struct bfin_spi_master_data *)data;
599 struct spi_message *message = NULL; 561 struct spi_message *message = NULL;
600 struct spi_transfer *transfer = NULL; 562 struct spi_transfer *transfer = NULL;
601 struct spi_transfer *previous = NULL; 563 struct spi_transfer *previous = NULL;
602 struct chip_data *chip = NULL; 564 struct bfin_spi_slave_data *chip = NULL;
603 u8 width; 565 unsigned int bits_per_word;
604 u16 cr, dma_width, dma_config; 566 u16 cr, cr_width, dma_width, dma_config;
605 u32 tranf_success = 1; 567 u32 tranf_success = 1;
606 u8 full_duplex = 0; 568 u8 full_duplex = 0;
607 569
@@ -639,7 +601,7 @@ static void bfin_spi_pump_transfers(unsigned long data)
639 udelay(previous->delay_usecs); 601 udelay(previous->delay_usecs);
640 } 602 }
641 603
642 /* Setup the transfer state based on the type of transfer */ 604 /* Flush any existing transfers that may be sitting in the hardware */
643 if (bfin_spi_flush(drv_data) == 0) { 605 if (bfin_spi_flush(drv_data) == 0) {
644 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n"); 606 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
645 message->status = -EIO; 607 message->status = -EIO;
@@ -679,52 +641,31 @@ static void bfin_spi_pump_transfers(unsigned long data)
679 drv_data->cs_change = transfer->cs_change; 641 drv_data->cs_change = transfer->cs_change;
680 642
681 /* Bits per word setup */ 643 /* Bits per word setup */
682 switch (transfer->bits_per_word) { 644 bits_per_word = transfer->bits_per_word ? : message->spi->bits_per_word;
683 case 8: 645 if (bits_per_word == 8) {
684 drv_data->n_bytes = 1; 646 drv_data->n_bytes = 1;
685 width = CFG_SPI_WORDSIZE8; 647 drv_data->len = transfer->len;
686 drv_data->read = chip->cs_change_per_word ? 648 cr_width = 0;
687 bfin_spi_u8_cs_chg_reader : bfin_spi_u8_reader; 649 drv_data->ops = &bfin_bfin_spi_transfer_ops_u8;
688 drv_data->write = chip->cs_change_per_word ? 650 } else if (bits_per_word == 16) {
689 bfin_spi_u8_cs_chg_writer : bfin_spi_u8_writer;
690 drv_data->duplex = chip->cs_change_per_word ?
691 bfin_spi_u8_cs_chg_duplex : bfin_spi_u8_duplex;
692 break;
693
694 case 16:
695 drv_data->n_bytes = 2; 651 drv_data->n_bytes = 2;
696 width = CFG_SPI_WORDSIZE16;
697 drv_data->read = chip->cs_change_per_word ?
698 bfin_spi_u16_cs_chg_reader : bfin_spi_u16_reader;
699 drv_data->write = chip->cs_change_per_word ?
700 bfin_spi_u16_cs_chg_writer : bfin_spi_u16_writer;
701 drv_data->duplex = chip->cs_change_per_word ?
702 bfin_spi_u16_cs_chg_duplex : bfin_spi_u16_duplex;
703 break;
704
705 default:
706 /* No change, the same as default setting */
707 drv_data->n_bytes = chip->n_bytes;
708 width = chip->width;
709 drv_data->write = drv_data->tx ? chip->write : bfin_spi_null_writer;
710 drv_data->read = drv_data->rx ? chip->read : bfin_spi_null_reader;
711 drv_data->duplex = chip->duplex ? chip->duplex : bfin_spi_null_writer;
712 break;
713 }
714 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD));
715 cr |= (width << 8);
716 write_CTRL(drv_data, cr);
717
718 if (width == CFG_SPI_WORDSIZE16) {
719 drv_data->len = (transfer->len) >> 1; 652 drv_data->len = (transfer->len) >> 1;
653 cr_width = BIT_CTL_WORDSIZE;
654 drv_data->ops = &bfin_bfin_spi_transfer_ops_u16;
720 } else { 655 } else {
721 drv_data->len = transfer->len; 656 dev_err(&drv_data->pdev->dev, "transfer: unsupported bits_per_word\n");
657 message->status = -EINVAL;
658 bfin_spi_giveback(drv_data);
659 return;
722 } 660 }
661 cr = read_CTRL(drv_data) & ~(BIT_CTL_TIMOD | BIT_CTL_WORDSIZE);
662 cr |= cr_width;
663 write_CTRL(drv_data, cr);
664
723 dev_dbg(&drv_data->pdev->dev, 665 dev_dbg(&drv_data->pdev->dev,
724 "transfer: drv_data->write is %p, chip->write is %p, null_wr is %p\n", 666 "transfer: drv_data->ops is %p, chip->ops is %p, u8_ops is %p\n",
725 drv_data->write, chip->write, bfin_spi_null_writer); 667 drv_data->ops, chip->ops, &bfin_bfin_spi_transfer_ops_u8);
726 668
727 /* speed and width has been set on per message */
728 message->state = RUNNING_STATE; 669 message->state = RUNNING_STATE;
729 dma_config = 0; 670 dma_config = 0;
730 671
@@ -735,13 +676,11 @@ static void bfin_spi_pump_transfers(unsigned long data)
735 write_BAUD(drv_data, chip->baud); 676 write_BAUD(drv_data, chip->baud);
736 677
737 write_STAT(drv_data, BIT_STAT_CLR); 678 write_STAT(drv_data, BIT_STAT_CLR);
738 cr = (read_CTRL(drv_data) & (~BIT_CTL_TIMOD)); 679 bfin_spi_cs_active(drv_data, chip);
739 if (drv_data->cs_change)
740 bfin_spi_cs_active(drv_data, chip);
741 680
742 dev_dbg(&drv_data->pdev->dev, 681 dev_dbg(&drv_data->pdev->dev,
743 "now pumping a transfer: width is %d, len is %d\n", 682 "now pumping a transfer: width is %d, len is %d\n",
744 width, transfer->len); 683 cr_width, transfer->len);
745 684
746 /* 685 /*
747 * Try to map dma buffer and do a dma transfer. If successful use, 686 * Try to map dma buffer and do a dma transfer. If successful use,
@@ -760,7 +699,7 @@ static void bfin_spi_pump_transfers(unsigned long data)
760 /* config dma channel */ 699 /* config dma channel */
761 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n"); 700 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
762 set_dma_x_count(drv_data->dma_channel, drv_data->len); 701 set_dma_x_count(drv_data->dma_channel, drv_data->len);
763 if (width == CFG_SPI_WORDSIZE16) { 702 if (cr_width == BIT_CTL_WORDSIZE) {
764 set_dma_x_modify(drv_data->dma_channel, 2); 703 set_dma_x_modify(drv_data->dma_channel, 2);
765 dma_width = WDSIZE_16; 704 dma_width = WDSIZE_16;
766 } else { 705 } else {
@@ -846,73 +785,100 @@ static void bfin_spi_pump_transfers(unsigned long data)
846 dma_enable_irq(drv_data->dma_channel); 785 dma_enable_irq(drv_data->dma_channel);
847 local_irq_restore(flags); 786 local_irq_restore(flags);
848 787
849 } else { 788 return;
850 /* IO mode write then read */ 789 }
851 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
852
853 /* we always use SPI_WRITE mode. SPI_READ mode
854 seems to have problems with setting up the
855 output value in TDBR prior to the transfer. */
856 write_CTRL(drv_data, (cr | CFG_SPI_WRITE));
857
858 if (full_duplex) {
859 /* full duplex mode */
860 BUG_ON((drv_data->tx_end - drv_data->tx) !=
861 (drv_data->rx_end - drv_data->rx));
862 dev_dbg(&drv_data->pdev->dev,
863 "IO duplex: cr is 0x%x\n", cr);
864
865 drv_data->duplex(drv_data);
866 790
867 if (drv_data->tx != drv_data->tx_end) 791 /*
868 tranf_success = 0; 792 * We always use SPI_WRITE mode (transfer starts with TDBR write).
869 } else if (drv_data->tx != NULL) { 793 * SPI_READ mode (transfer starts with RDBR read) seems to have
870 /* write only half duplex */ 794 * problems with setting up the output value in TDBR prior to the
871 dev_dbg(&drv_data->pdev->dev, 795 * start of the transfer.
872 "IO write: cr is 0x%x\n", cr); 796 */
797 write_CTRL(drv_data, cr | BIT_CTL_TXMOD);
873 798
874 drv_data->write(drv_data); 799 if (chip->pio_interrupt) {
800 /* SPI irq should have been disabled by now */
875 801
876 if (drv_data->tx != drv_data->tx_end) 802 /* discard old RX data and clear RXS */
877 tranf_success = 0; 803 bfin_spi_dummy_read(drv_data);
878 } else if (drv_data->rx != NULL) {
879 /* read only half duplex */
880 dev_dbg(&drv_data->pdev->dev,
881 "IO read: cr is 0x%x\n", cr);
882 804
883 drv_data->read(drv_data); 805 /* start transfer */
884 if (drv_data->rx != drv_data->rx_end) 806 if (drv_data->tx == NULL)
885 tranf_success = 0; 807 write_TDBR(drv_data, chip->idle_tx_val);
808 else {
809 if (bits_per_word == 8)
810 write_TDBR(drv_data, (*(u8 *) (drv_data->tx)));
811 else
812 write_TDBR(drv_data, (*(u16 *) (drv_data->tx)));
813 drv_data->tx += drv_data->n_bytes;
886 } 814 }
887 815
888 if (!tranf_success) { 816 /* once TDBR is empty, interrupt is triggered */
889 dev_dbg(&drv_data->pdev->dev, 817 enable_irq(drv_data->spi_irq);
890 "IO write error!\n"); 818 return;
891 message->state = ERROR_STATE; 819 }
892 } else { 820
893 /* Update total byte transfered */ 821 /* IO mode */
894 message->actual_length += drv_data->len_in_bytes; 822 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
895 /* Move to next transfer of this msg */ 823
896 message->state = bfin_spi_next_transfer(drv_data); 824 if (full_duplex) {
897 if (drv_data->cs_change) 825 /* full duplex mode */
898 bfin_spi_cs_deactive(drv_data, chip); 826 BUG_ON((drv_data->tx_end - drv_data->tx) !=
899 } 827 (drv_data->rx_end - drv_data->rx));
900 /* Schedule next transfer tasklet */ 828 dev_dbg(&drv_data->pdev->dev,
901 tasklet_schedule(&drv_data->pump_transfers); 829 "IO duplex: cr is 0x%x\n", cr);
830
831 drv_data->ops->duplex(drv_data);
832
833 if (drv_data->tx != drv_data->tx_end)
834 tranf_success = 0;
835 } else if (drv_data->tx != NULL) {
836 /* write only half duplex */
837 dev_dbg(&drv_data->pdev->dev,
838 "IO write: cr is 0x%x\n", cr);
839
840 drv_data->ops->write(drv_data);
841
842 if (drv_data->tx != drv_data->tx_end)
843 tranf_success = 0;
844 } else if (drv_data->rx != NULL) {
845 /* read only half duplex */
846 dev_dbg(&drv_data->pdev->dev,
847 "IO read: cr is 0x%x\n", cr);
848
849 drv_data->ops->read(drv_data);
850 if (drv_data->rx != drv_data->rx_end)
851 tranf_success = 0;
852 }
853
854 if (!tranf_success) {
855 dev_dbg(&drv_data->pdev->dev,
856 "IO write error!\n");
857 message->state = ERROR_STATE;
858 } else {
859 /* Update total byte transfered */
860 message->actual_length += drv_data->len_in_bytes;
861 /* Move to next transfer of this msg */
862 message->state = bfin_spi_next_transfer(drv_data);
863 if (drv_data->cs_change)
864 bfin_spi_cs_deactive(drv_data, chip);
902 } 865 }
866
867 /* Schedule next transfer tasklet */
868 tasklet_schedule(&drv_data->pump_transfers);
903} 869}
904 870
905/* pop a msg from queue and kick off real transfer */ 871/* pop a msg from queue and kick off real transfer */
906static void bfin_spi_pump_messages(struct work_struct *work) 872static void bfin_spi_pump_messages(struct work_struct *work)
907{ 873{
908 struct driver_data *drv_data; 874 struct bfin_spi_master_data *drv_data;
909 unsigned long flags; 875 unsigned long flags;
910 876
911 drv_data = container_of(work, struct driver_data, pump_messages); 877 drv_data = container_of(work, struct bfin_spi_master_data, pump_messages);
912 878
913 /* Lock queue and check for queue work */ 879 /* Lock queue and check for queue work */
914 spin_lock_irqsave(&drv_data->lock, flags); 880 spin_lock_irqsave(&drv_data->lock, flags);
915 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) { 881 if (list_empty(&drv_data->queue) || !drv_data->running) {
916 /* pumper kicked off but no work to do */ 882 /* pumper kicked off but no work to do */
917 drv_data->busy = 0; 883 drv_data->busy = 0;
918 spin_unlock_irqrestore(&drv_data->lock, flags); 884 spin_unlock_irqrestore(&drv_data->lock, flags);
@@ -962,12 +928,12 @@ static void bfin_spi_pump_messages(struct work_struct *work)
962 */ 928 */
963static int bfin_spi_transfer(struct spi_device *spi, struct spi_message *msg) 929static int bfin_spi_transfer(struct spi_device *spi, struct spi_message *msg)
964{ 930{
965 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 931 struct bfin_spi_master_data *drv_data = spi_master_get_devdata(spi->master);
966 unsigned long flags; 932 unsigned long flags;
967 933
968 spin_lock_irqsave(&drv_data->lock, flags); 934 spin_lock_irqsave(&drv_data->lock, flags);
969 935
970 if (drv_data->run == QUEUE_STOPPED) { 936 if (!drv_data->running) {
971 spin_unlock_irqrestore(&drv_data->lock, flags); 937 spin_unlock_irqrestore(&drv_data->lock, flags);
972 return -ESHUTDOWN; 938 return -ESHUTDOWN;
973 } 939 }
@@ -979,7 +945,7 @@ static int bfin_spi_transfer(struct spi_device *spi, struct spi_message *msg)
979 dev_dbg(&spi->dev, "adding an msg in transfer() \n"); 945 dev_dbg(&spi->dev, "adding an msg in transfer() \n");
980 list_add_tail(&msg->queue, &drv_data->queue); 946 list_add_tail(&msg->queue, &drv_data->queue);
981 947
982 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy) 948 if (drv_data->running && !drv_data->busy)
983 queue_work(drv_data->workqueue, &drv_data->pump_messages); 949 queue_work(drv_data->workqueue, &drv_data->pump_messages);
984 950
985 spin_unlock_irqrestore(&drv_data->lock, flags); 951 spin_unlock_irqrestore(&drv_data->lock, flags);
@@ -1003,147 +969,184 @@ static u16 ssel[][MAX_SPI_SSEL] = {
1003 P_SPI2_SSEL6, P_SPI2_SSEL7}, 969 P_SPI2_SSEL6, P_SPI2_SSEL7},
1004}; 970};
1005 971
1006/* first setup for new devices */ 972/* setup for devices (may be called multiple times -- not just first setup) */
1007static int bfin_spi_setup(struct spi_device *spi) 973static int bfin_spi_setup(struct spi_device *spi)
1008{ 974{
1009 struct bfin5xx_spi_chip *chip_info = NULL; 975 struct bfin5xx_spi_chip *chip_info;
1010 struct chip_data *chip; 976 struct bfin_spi_slave_data *chip = NULL;
1011 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 977 struct bfin_spi_master_data *drv_data = spi_master_get_devdata(spi->master);
1012 int ret; 978 u16 bfin_ctl_reg;
1013 979 int ret = -EINVAL;
1014 if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
1015 return -EINVAL;
1016 980
1017 /* Only alloc (or use chip_info) on first setup */ 981 /* Only alloc (or use chip_info) on first setup */
982 chip_info = NULL;
1018 chip = spi_get_ctldata(spi); 983 chip = spi_get_ctldata(spi);
1019 if (chip == NULL) { 984 if (chip == NULL) {
1020 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); 985 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1021 if (!chip) 986 if (!chip) {
1022 return -ENOMEM; 987 dev_err(&spi->dev, "cannot allocate chip data\n");
988 ret = -ENOMEM;
989 goto error;
990 }
1023 991
1024 chip->enable_dma = 0; 992 chip->enable_dma = 0;
1025 chip_info = spi->controller_data; 993 chip_info = spi->controller_data;
1026 } 994 }
1027 995
996 /* Let people set non-standard bits directly */
997 bfin_ctl_reg = BIT_CTL_OPENDRAIN | BIT_CTL_EMISO |
998 BIT_CTL_PSSE | BIT_CTL_GM | BIT_CTL_SZ;
999
1028 /* chip_info isn't always needed */ 1000 /* chip_info isn't always needed */
1029 if (chip_info) { 1001 if (chip_info) {
1030 /* Make sure people stop trying to set fields via ctl_reg 1002 /* Make sure people stop trying to set fields via ctl_reg
1031 * when they should actually be using common SPI framework. 1003 * when they should actually be using common SPI framework.
1032 * Currently we let through: WOM EMISO PSSE GM SZ TIMOD. 1004 * Currently we let through: WOM EMISO PSSE GM SZ.
1033 * Not sure if a user actually needs/uses any of these, 1005 * Not sure if a user actually needs/uses any of these,
1034 * but let's assume (for now) they do. 1006 * but let's assume (for now) they do.
1035 */ 1007 */
1036 if (chip_info->ctl_reg & (SPE|MSTR|CPOL|CPHA|LSBF|SIZE)) { 1008 if (chip_info->ctl_reg & ~bfin_ctl_reg) {
1037 dev_err(&spi->dev, "do not set bits in ctl_reg " 1009 dev_err(&spi->dev, "do not set bits in ctl_reg "
1038 "that the SPI framework manages\n"); 1010 "that the SPI framework manages\n");
1039 return -EINVAL; 1011 goto error;
1040 } 1012 }
1041
1042 chip->enable_dma = chip_info->enable_dma != 0 1013 chip->enable_dma = chip_info->enable_dma != 0
1043 && drv_data->master_info->enable_dma; 1014 && drv_data->master_info->enable_dma;
1044 chip->ctl_reg = chip_info->ctl_reg; 1015 chip->ctl_reg = chip_info->ctl_reg;
1045 chip->bits_per_word = chip_info->bits_per_word;
1046 chip->cs_change_per_word = chip_info->cs_change_per_word;
1047 chip->cs_chg_udelay = chip_info->cs_chg_udelay; 1016 chip->cs_chg_udelay = chip_info->cs_chg_udelay;
1048 chip->cs_gpio = chip_info->cs_gpio;
1049 chip->idle_tx_val = chip_info->idle_tx_val; 1017 chip->idle_tx_val = chip_info->idle_tx_val;
1018 chip->pio_interrupt = chip_info->pio_interrupt;
1019 spi->bits_per_word = chip_info->bits_per_word;
1020 } else {
1021 /* force a default base state */
1022 chip->ctl_reg &= bfin_ctl_reg;
1023 }
1024
1025 if (spi->bits_per_word != 8 && spi->bits_per_word != 16) {
1026 dev_err(&spi->dev, "%d bits_per_word is not supported\n",
1027 spi->bits_per_word);
1028 goto error;
1050 } 1029 }
1051 1030
1052 /* translate common spi framework into our register */ 1031 /* translate common spi framework into our register */
1032 if (spi->mode & ~(SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST)) {
1033 dev_err(&spi->dev, "unsupported spi modes detected\n");
1034 goto error;
1035 }
1053 if (spi->mode & SPI_CPOL) 1036 if (spi->mode & SPI_CPOL)
1054 chip->ctl_reg |= CPOL; 1037 chip->ctl_reg |= BIT_CTL_CPOL;
1055 if (spi->mode & SPI_CPHA) 1038 if (spi->mode & SPI_CPHA)
1056 chip->ctl_reg |= CPHA; 1039 chip->ctl_reg |= BIT_CTL_CPHA;
1057 if (spi->mode & SPI_LSB_FIRST) 1040 if (spi->mode & SPI_LSB_FIRST)
1058 chip->ctl_reg |= LSBF; 1041 chip->ctl_reg |= BIT_CTL_LSBF;
1059 /* we dont support running in slave mode (yet?) */ 1042 /* we dont support running in slave mode (yet?) */
1060 chip->ctl_reg |= MSTR; 1043 chip->ctl_reg |= BIT_CTL_MASTER;
1061 1044
1062 /* 1045 /*
1046 * Notice: for blackfin, the speed_hz is the value of register
1047 * SPI_BAUD, not the real baudrate
1048 */
1049 chip->baud = hz_to_spi_baud(spi->max_speed_hz);
1050 chip->chip_select_num = spi->chip_select;
1051 if (chip->chip_select_num < MAX_CTRL_CS) {
1052 if (!(spi->mode & SPI_CPHA))
1053 dev_warn(&spi->dev, "Warning: SPI CPHA not set:"
1054 " Slave Select not under software control!\n"
1055 " See Documentation/blackfin/bfin-spi-notes.txt");
1056
1057 chip->flag = (1 << spi->chip_select) << 8;
1058 } else
1059 chip->cs_gpio = chip->chip_select_num - MAX_CTRL_CS;
1060
1061 if (chip->enable_dma && chip->pio_interrupt) {
1062 dev_err(&spi->dev, "enable_dma is set, "
1063 "do not set pio_interrupt\n");
1064 goto error;
1065 }
1066 /*
1063 * if any one SPI chip is registered and wants DMA, request the 1067 * if any one SPI chip is registered and wants DMA, request the
1064 * DMA channel for it 1068 * DMA channel for it
1065 */ 1069 */
1066 if (chip->enable_dma && !drv_data->dma_requested) { 1070 if (chip->enable_dma && !drv_data->dma_requested) {
1067 /* register dma irq handler */ 1071 /* register dma irq handler */
1068 if (request_dma(drv_data->dma_channel, "BFIN_SPI_DMA") < 0) { 1072 ret = request_dma(drv_data->dma_channel, "BFIN_SPI_DMA");
1069 dev_dbg(&spi->dev, 1073 if (ret) {
1074 dev_err(&spi->dev,
1070 "Unable to request BlackFin SPI DMA channel\n"); 1075 "Unable to request BlackFin SPI DMA channel\n");
1071 return -ENODEV; 1076 goto error;
1072 } 1077 }
1073 if (set_dma_callback(drv_data->dma_channel, 1078 drv_data->dma_requested = 1;
1074 bfin_spi_dma_irq_handler, drv_data) < 0) { 1079
1075 dev_dbg(&spi->dev, "Unable to set dma callback\n"); 1080 ret = set_dma_callback(drv_data->dma_channel,
1076 return -EPERM; 1081 bfin_spi_dma_irq_handler, drv_data);
1082 if (ret) {
1083 dev_err(&spi->dev, "Unable to set dma callback\n");
1084 goto error;
1077 } 1085 }
1078 dma_disable_irq(drv_data->dma_channel); 1086 dma_disable_irq(drv_data->dma_channel);
1079 drv_data->dma_requested = 1;
1080 } 1087 }
1081 1088
1082 /* 1089 if (chip->pio_interrupt && !drv_data->irq_requested) {
1083 * Notice: for blackfin, the speed_hz is the value of register 1090 ret = request_irq(drv_data->spi_irq, bfin_spi_pio_irq_handler,
1084 * SPI_BAUD, not the real baudrate 1091 IRQF_DISABLED, "BFIN_SPI", drv_data);
1085 */ 1092 if (ret) {
1086 chip->baud = hz_to_spi_baud(spi->max_speed_hz); 1093 dev_err(&spi->dev, "Unable to register spi IRQ\n");
1087 chip->flag = 1 << (spi->chip_select); 1094 goto error;
1088 chip->chip_select_num = spi->chip_select; 1095 }
1096 drv_data->irq_requested = 1;
1097 /* we use write mode, spi irq has to be disabled here */
1098 disable_irq(drv_data->spi_irq);
1099 }
1089 1100
1090 if (chip->chip_select_num == 0) { 1101 if (chip->chip_select_num >= MAX_CTRL_CS) {
1091 ret = gpio_request(chip->cs_gpio, spi->modalias); 1102 ret = gpio_request(chip->cs_gpio, spi->modalias);
1092 if (ret) { 1103 if (ret) {
1093 if (drv_data->dma_requested) 1104 dev_err(&spi->dev, "gpio_request() error\n");
1094 free_dma(drv_data->dma_channel); 1105 goto pin_error;
1095 return ret;
1096 } 1106 }
1097 gpio_direction_output(chip->cs_gpio, 1); 1107 gpio_direction_output(chip->cs_gpio, 1);
1098 } 1108 }
1099 1109
1100 switch (chip->bits_per_word) {
1101 case 8:
1102 chip->n_bytes = 1;
1103 chip->width = CFG_SPI_WORDSIZE8;
1104 chip->read = chip->cs_change_per_word ?
1105 bfin_spi_u8_cs_chg_reader : bfin_spi_u8_reader;
1106 chip->write = chip->cs_change_per_word ?
1107 bfin_spi_u8_cs_chg_writer : bfin_spi_u8_writer;
1108 chip->duplex = chip->cs_change_per_word ?
1109 bfin_spi_u8_cs_chg_duplex : bfin_spi_u8_duplex;
1110 break;
1111
1112 case 16:
1113 chip->n_bytes = 2;
1114 chip->width = CFG_SPI_WORDSIZE16;
1115 chip->read = chip->cs_change_per_word ?
1116 bfin_spi_u16_cs_chg_reader : bfin_spi_u16_reader;
1117 chip->write = chip->cs_change_per_word ?
1118 bfin_spi_u16_cs_chg_writer : bfin_spi_u16_writer;
1119 chip->duplex = chip->cs_change_per_word ?
1120 bfin_spi_u16_cs_chg_duplex : bfin_spi_u16_duplex;
1121 break;
1122
1123 default:
1124 dev_err(&spi->dev, "%d bits_per_word is not supported\n",
1125 chip->bits_per_word);
1126 if (chip_info)
1127 kfree(chip);
1128 return -ENODEV;
1129 }
1130
1131 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n", 1110 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d\n",
1132 spi->modalias, chip->width, chip->enable_dma); 1111 spi->modalias, spi->bits_per_word, chip->enable_dma);
1133 dev_dbg(&spi->dev, "ctl_reg is 0x%x, flag_reg is 0x%x\n", 1112 dev_dbg(&spi->dev, "ctl_reg is 0x%x, flag_reg is 0x%x\n",
1134 chip->ctl_reg, chip->flag); 1113 chip->ctl_reg, chip->flag);
1135 1114
1136 spi_set_ctldata(spi, chip); 1115 spi_set_ctldata(spi, chip);
1137 1116
1138 dev_dbg(&spi->dev, "chip select number is %d\n", chip->chip_select_num); 1117 dev_dbg(&spi->dev, "chip select number is %d\n", chip->chip_select_num);
1139 if ((chip->chip_select_num > 0) 1118 if (chip->chip_select_num < MAX_CTRL_CS) {
1140 && (chip->chip_select_num <= spi->master->num_chipselect)) 1119 ret = peripheral_request(ssel[spi->master->bus_num]
1141 peripheral_request(ssel[spi->master->bus_num] 1120 [chip->chip_select_num-1], spi->modalias);
1142 [chip->chip_select_num-1], spi->modalias); 1121 if (ret) {
1122 dev_err(&spi->dev, "peripheral_request() error\n");
1123 goto pin_error;
1124 }
1125 }
1143 1126
1127 bfin_spi_cs_enable(drv_data, chip);
1144 bfin_spi_cs_deactive(drv_data, chip); 1128 bfin_spi_cs_deactive(drv_data, chip);
1145 1129
1146 return 0; 1130 return 0;
1131
1132 pin_error:
1133 if (chip->chip_select_num >= MAX_CTRL_CS)
1134 gpio_free(chip->cs_gpio);
1135 else
1136 peripheral_free(ssel[spi->master->bus_num]
1137 [chip->chip_select_num - 1]);
1138 error:
1139 if (chip) {
1140 if (drv_data->dma_requested)
1141 free_dma(drv_data->dma_channel);
1142 drv_data->dma_requested = 0;
1143
1144 kfree(chip);
1145 /* prevent free 'chip' twice */
1146 spi_set_ctldata(spi, NULL);
1147 }
1148
1149 return ret;
1147} 1150}
1148 1151
1149/* 1152/*
@@ -1152,28 +1155,30 @@ static int bfin_spi_setup(struct spi_device *spi)
1152 */ 1155 */
1153static void bfin_spi_cleanup(struct spi_device *spi) 1156static void bfin_spi_cleanup(struct spi_device *spi)
1154{ 1157{
1155 struct chip_data *chip = spi_get_ctldata(spi); 1158 struct bfin_spi_slave_data *chip = spi_get_ctldata(spi);
1159 struct bfin_spi_master_data *drv_data = spi_master_get_devdata(spi->master);
1156 1160
1157 if (!chip) 1161 if (!chip)
1158 return; 1162 return;
1159 1163
1160 if ((chip->chip_select_num > 0) 1164 if (chip->chip_select_num < MAX_CTRL_CS) {
1161 && (chip->chip_select_num <= spi->master->num_chipselect))
1162 peripheral_free(ssel[spi->master->bus_num] 1165 peripheral_free(ssel[spi->master->bus_num]
1163 [chip->chip_select_num-1]); 1166 [chip->chip_select_num-1]);
1164 1167 bfin_spi_cs_disable(drv_data, chip);
1165 if (chip->chip_select_num == 0) 1168 } else
1166 gpio_free(chip->cs_gpio); 1169 gpio_free(chip->cs_gpio);
1167 1170
1168 kfree(chip); 1171 kfree(chip);
1172 /* prevent free 'chip' twice */
1173 spi_set_ctldata(spi, NULL);
1169} 1174}
1170 1175
1171static inline int bfin_spi_init_queue(struct driver_data *drv_data) 1176static inline int bfin_spi_init_queue(struct bfin_spi_master_data *drv_data)
1172{ 1177{
1173 INIT_LIST_HEAD(&drv_data->queue); 1178 INIT_LIST_HEAD(&drv_data->queue);
1174 spin_lock_init(&drv_data->lock); 1179 spin_lock_init(&drv_data->lock);
1175 1180
1176 drv_data->run = QUEUE_STOPPED; 1181 drv_data->running = false;
1177 drv_data->busy = 0; 1182 drv_data->busy = 0;
1178 1183
1179 /* init transfer tasklet */ 1184 /* init transfer tasklet */
@@ -1190,18 +1195,18 @@ static inline int bfin_spi_init_queue(struct driver_data *drv_data)
1190 return 0; 1195 return 0;
1191} 1196}
1192 1197
1193static inline int bfin_spi_start_queue(struct driver_data *drv_data) 1198static inline int bfin_spi_start_queue(struct bfin_spi_master_data *drv_data)
1194{ 1199{
1195 unsigned long flags; 1200 unsigned long flags;
1196 1201
1197 spin_lock_irqsave(&drv_data->lock, flags); 1202 spin_lock_irqsave(&drv_data->lock, flags);
1198 1203
1199 if (drv_data->run == QUEUE_RUNNING || drv_data->busy) { 1204 if (drv_data->running || drv_data->busy) {
1200 spin_unlock_irqrestore(&drv_data->lock, flags); 1205 spin_unlock_irqrestore(&drv_data->lock, flags);
1201 return -EBUSY; 1206 return -EBUSY;
1202 } 1207 }
1203 1208
1204 drv_data->run = QUEUE_RUNNING; 1209 drv_data->running = true;
1205 drv_data->cur_msg = NULL; 1210 drv_data->cur_msg = NULL;
1206 drv_data->cur_transfer = NULL; 1211 drv_data->cur_transfer = NULL;
1207 drv_data->cur_chip = NULL; 1212 drv_data->cur_chip = NULL;
@@ -1212,7 +1217,7 @@ static inline int bfin_spi_start_queue(struct driver_data *drv_data)
1212 return 0; 1217 return 0;
1213} 1218}
1214 1219
1215static inline int bfin_spi_stop_queue(struct driver_data *drv_data) 1220static inline int bfin_spi_stop_queue(struct bfin_spi_master_data *drv_data)
1216{ 1221{
1217 unsigned long flags; 1222 unsigned long flags;
1218 unsigned limit = 500; 1223 unsigned limit = 500;
@@ -1226,7 +1231,7 @@ static inline int bfin_spi_stop_queue(struct driver_data *drv_data)
1226 * execution path (pump_messages) would be required to call wake_up or 1231 * execution path (pump_messages) would be required to call wake_up or
1227 * friends on every SPI message. Do this instead 1232 * friends on every SPI message. Do this instead
1228 */ 1233 */
1229 drv_data->run = QUEUE_STOPPED; 1234 drv_data->running = false;
1230 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) { 1235 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1231 spin_unlock_irqrestore(&drv_data->lock, flags); 1236 spin_unlock_irqrestore(&drv_data->lock, flags);
1232 msleep(10); 1237 msleep(10);
@@ -1241,7 +1246,7 @@ static inline int bfin_spi_stop_queue(struct driver_data *drv_data)
1241 return status; 1246 return status;
1242} 1247}
1243 1248
1244static inline int bfin_spi_destroy_queue(struct driver_data *drv_data) 1249static inline int bfin_spi_destroy_queue(struct bfin_spi_master_data *drv_data)
1245{ 1250{
1246 int status; 1251 int status;
1247 1252
@@ -1259,14 +1264,14 @@ static int __init bfin_spi_probe(struct platform_device *pdev)
1259 struct device *dev = &pdev->dev; 1264 struct device *dev = &pdev->dev;
1260 struct bfin5xx_spi_master *platform_info; 1265 struct bfin5xx_spi_master *platform_info;
1261 struct spi_master *master; 1266 struct spi_master *master;
1262 struct driver_data *drv_data = 0; 1267 struct bfin_spi_master_data *drv_data;
1263 struct resource *res; 1268 struct resource *res;
1264 int status = 0; 1269 int status = 0;
1265 1270
1266 platform_info = dev->platform_data; 1271 platform_info = dev->platform_data;
1267 1272
1268 /* Allocate master with space for drv_data */ 1273 /* Allocate master with space for drv_data */
1269 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16); 1274 master = spi_alloc_master(dev, sizeof(*drv_data));
1270 if (!master) { 1275 if (!master) {
1271 dev_err(&pdev->dev, "can not alloc spi_master\n"); 1276 dev_err(&pdev->dev, "can not alloc spi_master\n");
1272 return -ENOMEM; 1277 return -ENOMEM;
@@ -1302,11 +1307,19 @@ static int __init bfin_spi_probe(struct platform_device *pdev)
1302 goto out_error_ioremap; 1307 goto out_error_ioremap;
1303 } 1308 }
1304 1309
1305 drv_data->dma_channel = platform_get_irq(pdev, 0); 1310 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1306 if (drv_data->dma_channel < 0) { 1311 if (res == NULL) {
1307 dev_err(dev, "No DMA channel specified\n"); 1312 dev_err(dev, "No DMA channel specified\n");
1308 status = -ENOENT; 1313 status = -ENOENT;
1309 goto out_error_no_dma_ch; 1314 goto out_error_free_io;
1315 }
1316 drv_data->dma_channel = res->start;
1317
1318 drv_data->spi_irq = platform_get_irq(pdev, 0);
1319 if (drv_data->spi_irq < 0) {
1320 dev_err(dev, "No spi pio irq specified\n");
1321 status = -ENOENT;
1322 goto out_error_free_io;
1310 } 1323 }
1311 1324
1312 /* Initial and start queue */ 1325 /* Initial and start queue */
@@ -1328,6 +1341,12 @@ static int __init bfin_spi_probe(struct platform_device *pdev)
1328 goto out_error_queue_alloc; 1341 goto out_error_queue_alloc;
1329 } 1342 }
1330 1343
1344 /* Reset SPI registers. If these registers were used by the boot loader,
1345 * the sky may fall on your head if you enable the dma controller.
1346 */
1347 write_CTRL(drv_data, BIT_CTL_CPHA | BIT_CTL_MASTER);
1348 write_FLAG(drv_data, 0xFF00);
1349
1331 /* Register with the SPI framework */ 1350 /* Register with the SPI framework */
1332 platform_set_drvdata(pdev, drv_data); 1351 platform_set_drvdata(pdev, drv_data);
1333 status = spi_register_master(master); 1352 status = spi_register_master(master);
@@ -1343,7 +1362,7 @@ static int __init bfin_spi_probe(struct platform_device *pdev)
1343 1362
1344out_error_queue_alloc: 1363out_error_queue_alloc:
1345 bfin_spi_destroy_queue(drv_data); 1364 bfin_spi_destroy_queue(drv_data);
1346out_error_no_dma_ch: 1365out_error_free_io:
1347 iounmap((void *) drv_data->regs_base); 1366 iounmap((void *) drv_data->regs_base);
1348out_error_ioremap: 1367out_error_ioremap:
1349out_error_get_res: 1368out_error_get_res:
@@ -1355,7 +1374,7 @@ out_error_get_res:
1355/* stop hardware and remove the driver */ 1374/* stop hardware and remove the driver */
1356static int __devexit bfin_spi_remove(struct platform_device *pdev) 1375static int __devexit bfin_spi_remove(struct platform_device *pdev)
1357{ 1376{
1358 struct driver_data *drv_data = platform_get_drvdata(pdev); 1377 struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
1359 int status = 0; 1378 int status = 0;
1360 1379
1361 if (!drv_data) 1380 if (!drv_data)
@@ -1375,6 +1394,11 @@ static int __devexit bfin_spi_remove(struct platform_device *pdev)
1375 free_dma(drv_data->dma_channel); 1394 free_dma(drv_data->dma_channel);
1376 } 1395 }
1377 1396
1397 if (drv_data->irq_requested) {
1398 free_irq(drv_data->spi_irq, drv_data);
1399 drv_data->irq_requested = 0;
1400 }
1401
1378 /* Disconnect from the SPI framework */ 1402 /* Disconnect from the SPI framework */
1379 spi_unregister_master(drv_data->master); 1403 spi_unregister_master(drv_data->master);
1380 1404
@@ -1389,26 +1413,32 @@ static int __devexit bfin_spi_remove(struct platform_device *pdev)
1389#ifdef CONFIG_PM 1413#ifdef CONFIG_PM
1390static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state) 1414static int bfin_spi_suspend(struct platform_device *pdev, pm_message_t state)
1391{ 1415{
1392 struct driver_data *drv_data = platform_get_drvdata(pdev); 1416 struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
1393 int status = 0; 1417 int status = 0;
1394 1418
1395 status = bfin_spi_stop_queue(drv_data); 1419 status = bfin_spi_stop_queue(drv_data);
1396 if (status != 0) 1420 if (status != 0)
1397 return status; 1421 return status;
1398 1422
1399 /* stop hardware */ 1423 drv_data->ctrl_reg = read_CTRL(drv_data);
1400 bfin_spi_disable(drv_data); 1424 drv_data->flag_reg = read_FLAG(drv_data);
1425
1426 /*
1427 * reset SPI_CTL and SPI_FLG registers
1428 */
1429 write_CTRL(drv_data, BIT_CTL_CPHA | BIT_CTL_MASTER);
1430 write_FLAG(drv_data, 0xFF00);
1401 1431
1402 return 0; 1432 return 0;
1403} 1433}
1404 1434
1405static int bfin_spi_resume(struct platform_device *pdev) 1435static int bfin_spi_resume(struct platform_device *pdev)
1406{ 1436{
1407 struct driver_data *drv_data = platform_get_drvdata(pdev); 1437 struct bfin_spi_master_data *drv_data = platform_get_drvdata(pdev);
1408 int status = 0; 1438 int status = 0;
1409 1439
1410 /* Enable the SPI interface */ 1440 write_CTRL(drv_data, drv_data->ctrl_reg);
1411 bfin_spi_enable(drv_data); 1441 write_FLAG(drv_data, drv_data->flag_reg);
1412 1442
1413 /* Start the queue running */ 1443 /* Start the queue running */
1414 status = bfin_spi_start_queue(drv_data); 1444 status = bfin_spi_start_queue(drv_data);
@@ -1439,7 +1469,7 @@ static int __init bfin_spi_init(void)
1439{ 1469{
1440 return platform_driver_probe(&bfin_spi_driver, bfin_spi_probe); 1470 return platform_driver_probe(&bfin_spi_driver, bfin_spi_probe);
1441} 1471}
1442module_init(bfin_spi_init); 1472subsys_initcall(bfin_spi_init);
1443 1473
1444static void __exit bfin_spi_exit(void) 1474static void __exit bfin_spi_exit(void)
1445{ 1475{
diff --git a/drivers/spi/spi_fsl_espi.c b/drivers/spi/spi_fsl_espi.c
new file mode 100644
index 000000000000..e3b4f6451966
--- /dev/null
+++ b/drivers/spi/spi_fsl_espi.c
@@ -0,0 +1,748 @@
1/*
2 * Freescale eSPI controller driver.
3 *
4 * Copyright 2010 Freescale Semiconductor, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11#include <linux/module.h>
12#include <linux/delay.h>
13#include <linux/irq.h>
14#include <linux/spi/spi.h>
15#include <linux/platform_device.h>
16#include <linux/fsl_devices.h>
17#include <linux/mm.h>
18#include <linux/of.h>
19#include <linux/of_platform.h>
20#include <linux/of_spi.h>
21#include <linux/interrupt.h>
22#include <linux/err.h>
23#include <sysdev/fsl_soc.h>
24
25#include "spi_fsl_lib.h"
26
27/* eSPI Controller registers */
28struct fsl_espi_reg {
29 __be32 mode; /* 0x000 - eSPI mode register */
30 __be32 event; /* 0x004 - eSPI event register */
31 __be32 mask; /* 0x008 - eSPI mask register */
32 __be32 command; /* 0x00c - eSPI command register */
33 __be32 transmit; /* 0x010 - eSPI transmit FIFO access register*/
34 __be32 receive; /* 0x014 - eSPI receive FIFO access register*/
35 u8 res[8]; /* 0x018 - 0x01c reserved */
36 __be32 csmode[4]; /* 0x020 - 0x02c eSPI cs mode register */
37};
38
39struct fsl_espi_transfer {
40 const void *tx_buf;
41 void *rx_buf;
42 unsigned len;
43 unsigned n_tx;
44 unsigned n_rx;
45 unsigned actual_length;
46 int status;
47};
48
49/* eSPI Controller mode register definitions */
50#define SPMODE_ENABLE (1 << 31)
51#define SPMODE_LOOP (1 << 30)
52#define SPMODE_TXTHR(x) ((x) << 8)
53#define SPMODE_RXTHR(x) ((x) << 0)
54
55/* eSPI Controller CS mode register definitions */
56#define CSMODE_CI_INACTIVEHIGH (1 << 31)
57#define CSMODE_CP_BEGIN_EDGECLK (1 << 30)
58#define CSMODE_REV (1 << 29)
59#define CSMODE_DIV16 (1 << 28)
60#define CSMODE_PM(x) ((x) << 24)
61#define CSMODE_POL_1 (1 << 20)
62#define CSMODE_LEN(x) ((x) << 16)
63#define CSMODE_BEF(x) ((x) << 12)
64#define CSMODE_AFT(x) ((x) << 8)
65#define CSMODE_CG(x) ((x) << 3)
66
67/* Default mode/csmode for eSPI controller */
68#define SPMODE_INIT_VAL (SPMODE_TXTHR(4) | SPMODE_RXTHR(3))
69#define CSMODE_INIT_VAL (CSMODE_POL_1 | CSMODE_BEF(0) \
70 | CSMODE_AFT(0) | CSMODE_CG(1))
71
72/* SPIE register values */
73#define SPIE_NE 0x00000200 /* Not empty */
74#define SPIE_NF 0x00000100 /* Not full */
75
76/* SPIM register values */
77#define SPIM_NE 0x00000200 /* Not empty */
78#define SPIM_NF 0x00000100 /* Not full */
79#define SPIE_RXCNT(reg) ((reg >> 24) & 0x3F)
80#define SPIE_TXCNT(reg) ((reg >> 16) & 0x3F)
81
82/* SPCOM register values */
83#define SPCOM_CS(x) ((x) << 30)
84#define SPCOM_TRANLEN(x) ((x) << 0)
85#define SPCOM_TRANLEN_MAX 0xFFFF /* Max transaction length */
86
87static void fsl_espi_change_mode(struct spi_device *spi)
88{
89 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
90 struct spi_mpc8xxx_cs *cs = spi->controller_state;
91 struct fsl_espi_reg *reg_base = mspi->reg_base;
92 __be32 __iomem *mode = &reg_base->csmode[spi->chip_select];
93 __be32 __iomem *espi_mode = &reg_base->mode;
94 u32 tmp;
95 unsigned long flags;
96
97 /* Turn off IRQs locally to minimize time that SPI is disabled. */
98 local_irq_save(flags);
99
100 /* Turn off SPI unit prior changing mode */
101 tmp = mpc8xxx_spi_read_reg(espi_mode);
102 mpc8xxx_spi_write_reg(espi_mode, tmp & ~SPMODE_ENABLE);
103 mpc8xxx_spi_write_reg(mode, cs->hw_mode);
104 mpc8xxx_spi_write_reg(espi_mode, tmp);
105
106 local_irq_restore(flags);
107}
108
109static u32 fsl_espi_tx_buf_lsb(struct mpc8xxx_spi *mpc8xxx_spi)
110{
111 u32 data;
112 u16 data_h;
113 u16 data_l;
114 const u32 *tx = mpc8xxx_spi->tx;
115
116 if (!tx)
117 return 0;
118
119 data = *tx++ << mpc8xxx_spi->tx_shift;
120 data_l = data & 0xffff;
121 data_h = (data >> 16) & 0xffff;
122 swab16s(&data_l);
123 swab16s(&data_h);
124 data = data_h | data_l;
125
126 mpc8xxx_spi->tx = tx;
127 return data;
128}
129
130static int fsl_espi_setup_transfer(struct spi_device *spi,
131 struct spi_transfer *t)
132{
133 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
134 int bits_per_word = 0;
135 u8 pm;
136 u32 hz = 0;
137 struct spi_mpc8xxx_cs *cs = spi->controller_state;
138
139 if (t) {
140 bits_per_word = t->bits_per_word;
141 hz = t->speed_hz;
142 }
143
144 /* spi_transfer level calls that work per-word */
145 if (!bits_per_word)
146 bits_per_word = spi->bits_per_word;
147
148 /* Make sure its a bit width we support [4..16] */
149 if ((bits_per_word < 4) || (bits_per_word > 16))
150 return -EINVAL;
151
152 if (!hz)
153 hz = spi->max_speed_hz;
154
155 cs->rx_shift = 0;
156 cs->tx_shift = 0;
157 cs->get_rx = mpc8xxx_spi_rx_buf_u32;
158 cs->get_tx = mpc8xxx_spi_tx_buf_u32;
159 if (bits_per_word <= 8) {
160 cs->rx_shift = 8 - bits_per_word;
161 } else if (bits_per_word <= 16) {
162 cs->rx_shift = 16 - bits_per_word;
163 if (spi->mode & SPI_LSB_FIRST)
164 cs->get_tx = fsl_espi_tx_buf_lsb;
165 } else {
166 return -EINVAL;
167 }
168
169 mpc8xxx_spi->rx_shift = cs->rx_shift;
170 mpc8xxx_spi->tx_shift = cs->tx_shift;
171 mpc8xxx_spi->get_rx = cs->get_rx;
172 mpc8xxx_spi->get_tx = cs->get_tx;
173
174 bits_per_word = bits_per_word - 1;
175
176 /* mask out bits we are going to set */
177 cs->hw_mode &= ~(CSMODE_LEN(0xF) | CSMODE_DIV16 | CSMODE_PM(0xF));
178
179 cs->hw_mode |= CSMODE_LEN(bits_per_word);
180
181 if ((mpc8xxx_spi->spibrg / hz) > 64) {
182 cs->hw_mode |= CSMODE_DIV16;
183 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 64) + 1;
184
185 WARN_ONCE(pm > 16, "%s: Requested speed is too low: %d Hz. "
186 "Will use %d Hz instead.\n", dev_name(&spi->dev),
187 hz, mpc8xxx_spi->spibrg / 1024);
188 if (pm > 16)
189 pm = 16;
190 } else {
191 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 4) + 1;
192 }
193 if (pm)
194 pm--;
195
196 cs->hw_mode |= CSMODE_PM(pm);
197
198 fsl_espi_change_mode(spi);
199 return 0;
200}
201
202static int fsl_espi_cpu_bufs(struct mpc8xxx_spi *mspi, struct spi_transfer *t,
203 unsigned int len)
204{
205 u32 word;
206 struct fsl_espi_reg *reg_base = mspi->reg_base;
207
208 mspi->count = len;
209
210 /* enable rx ints */
211 mpc8xxx_spi_write_reg(&reg_base->mask, SPIM_NE);
212
213 /* transmit word */
214 word = mspi->get_tx(mspi);
215 mpc8xxx_spi_write_reg(&reg_base->transmit, word);
216
217 return 0;
218}
219
220static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
221{
222 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
223 struct fsl_espi_reg *reg_base = mpc8xxx_spi->reg_base;
224 unsigned int len = t->len;
225 u8 bits_per_word;
226 int ret;
227
228 bits_per_word = spi->bits_per_word;
229 if (t->bits_per_word)
230 bits_per_word = t->bits_per_word;
231
232 mpc8xxx_spi->len = t->len;
233 len = roundup(len, 4) / 4;
234
235 mpc8xxx_spi->tx = t->tx_buf;
236 mpc8xxx_spi->rx = t->rx_buf;
237
238 INIT_COMPLETION(mpc8xxx_spi->done);
239
240 /* Set SPCOM[CS] and SPCOM[TRANLEN] field */
241 if ((t->len - 1) > SPCOM_TRANLEN_MAX) {
242 dev_err(mpc8xxx_spi->dev, "Transaction length (%d)"
243 " beyond the SPCOM[TRANLEN] field\n", t->len);
244 return -EINVAL;
245 }
246 mpc8xxx_spi_write_reg(&reg_base->command,
247 (SPCOM_CS(spi->chip_select) | SPCOM_TRANLEN(t->len - 1)));
248
249 ret = fsl_espi_cpu_bufs(mpc8xxx_spi, t, len);
250 if (ret)
251 return ret;
252
253 wait_for_completion(&mpc8xxx_spi->done);
254
255 /* disable rx ints */
256 mpc8xxx_spi_write_reg(&reg_base->mask, 0);
257
258 return mpc8xxx_spi->count;
259}
260
261static void fsl_espi_addr2cmd(unsigned int addr, u8 *cmd)
262{
263 if (cmd[1] && cmd[2] && cmd[3]) {
264 cmd[1] = (u8)(addr >> 16);
265 cmd[2] = (u8)(addr >> 8);
266 cmd[3] = (u8)(addr >> 0);
267 }
268}
269
270static unsigned int fsl_espi_cmd2addr(u8 *cmd)
271{
272 if (cmd[1] && cmd[2] && cmd[3])
273 return cmd[1] << 16 | cmd[2] << 8 | cmd[3] << 0;
274
275 return 0;
276}
277
278static void fsl_espi_do_trans(struct spi_message *m,
279 struct fsl_espi_transfer *tr)
280{
281 struct spi_device *spi = m->spi;
282 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
283 struct fsl_espi_transfer *espi_trans = tr;
284 struct spi_message message;
285 struct spi_transfer *t, *first, trans;
286 int status = 0;
287
288 spi_message_init(&message);
289 memset(&trans, 0, sizeof(trans));
290
291 first = list_first_entry(&m->transfers, struct spi_transfer,
292 transfer_list);
293 list_for_each_entry(t, &m->transfers, transfer_list) {
294 if ((first->bits_per_word != t->bits_per_word) ||
295 (first->speed_hz != t->speed_hz)) {
296 espi_trans->status = -EINVAL;
297 dev_err(mspi->dev, "bits_per_word/speed_hz should be"
298 " same for the same SPI transfer\n");
299 return;
300 }
301
302 trans.speed_hz = t->speed_hz;
303 trans.bits_per_word = t->bits_per_word;
304 trans.delay_usecs = max(first->delay_usecs, t->delay_usecs);
305 }
306
307 trans.len = espi_trans->len;
308 trans.tx_buf = espi_trans->tx_buf;
309 trans.rx_buf = espi_trans->rx_buf;
310 spi_message_add_tail(&trans, &message);
311
312 list_for_each_entry(t, &message.transfers, transfer_list) {
313 if (t->bits_per_word || t->speed_hz) {
314 status = -EINVAL;
315
316 status = fsl_espi_setup_transfer(spi, t);
317 if (status < 0)
318 break;
319 }
320
321 if (t->len)
322 status = fsl_espi_bufs(spi, t);
323
324 if (status) {
325 status = -EMSGSIZE;
326 break;
327 }
328
329 if (t->delay_usecs)
330 udelay(t->delay_usecs);
331 }
332
333 espi_trans->status = status;
334 fsl_espi_setup_transfer(spi, NULL);
335}
336
337static void fsl_espi_cmd_trans(struct spi_message *m,
338 struct fsl_espi_transfer *trans, u8 *rx_buff)
339{
340 struct spi_transfer *t;
341 u8 *local_buf;
342 int i = 0;
343 struct fsl_espi_transfer *espi_trans = trans;
344
345 local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
346 if (!local_buf) {
347 espi_trans->status = -ENOMEM;
348 return;
349 }
350
351 list_for_each_entry(t, &m->transfers, transfer_list) {
352 if (t->tx_buf) {
353 memcpy(local_buf + i, t->tx_buf, t->len);
354 i += t->len;
355 }
356 }
357
358 espi_trans->tx_buf = local_buf;
359 espi_trans->rx_buf = local_buf + espi_trans->n_tx;
360 fsl_espi_do_trans(m, espi_trans);
361
362 espi_trans->actual_length = espi_trans->len;
363 kfree(local_buf);
364}
365
366static void fsl_espi_rw_trans(struct spi_message *m,
367 struct fsl_espi_transfer *trans, u8 *rx_buff)
368{
369 struct fsl_espi_transfer *espi_trans = trans;
370 unsigned int n_tx = espi_trans->n_tx;
371 unsigned int n_rx = espi_trans->n_rx;
372 struct spi_transfer *t;
373 u8 *local_buf;
374 u8 *rx_buf = rx_buff;
375 unsigned int trans_len;
376 unsigned int addr;
377 int i, pos, loop;
378
379 local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
380 if (!local_buf) {
381 espi_trans->status = -ENOMEM;
382 return;
383 }
384
385 for (pos = 0, loop = 0; pos < n_rx; pos += trans_len, loop++) {
386 trans_len = n_rx - pos;
387 if (trans_len > SPCOM_TRANLEN_MAX - n_tx)
388 trans_len = SPCOM_TRANLEN_MAX - n_tx;
389
390 i = 0;
391 list_for_each_entry(t, &m->transfers, transfer_list) {
392 if (t->tx_buf) {
393 memcpy(local_buf + i, t->tx_buf, t->len);
394 i += t->len;
395 }
396 }
397
398 addr = fsl_espi_cmd2addr(local_buf);
399 addr += pos;
400 fsl_espi_addr2cmd(addr, local_buf);
401
402 espi_trans->n_tx = n_tx;
403 espi_trans->n_rx = trans_len;
404 espi_trans->len = trans_len + n_tx;
405 espi_trans->tx_buf = local_buf;
406 espi_trans->rx_buf = local_buf + n_tx;
407 fsl_espi_do_trans(m, espi_trans);
408
409 memcpy(rx_buf + pos, espi_trans->rx_buf + n_tx, trans_len);
410
411 if (loop > 0)
412 espi_trans->actual_length += espi_trans->len - n_tx;
413 else
414 espi_trans->actual_length += espi_trans->len;
415 }
416
417 kfree(local_buf);
418}
419
420static void fsl_espi_do_one_msg(struct spi_message *m)
421{
422 struct spi_transfer *t;
423 u8 *rx_buf = NULL;
424 unsigned int n_tx = 0;
425 unsigned int n_rx = 0;
426 struct fsl_espi_transfer espi_trans;
427
428 list_for_each_entry(t, &m->transfers, transfer_list) {
429 if (t->tx_buf)
430 n_tx += t->len;
431 if (t->rx_buf) {
432 n_rx += t->len;
433 rx_buf = t->rx_buf;
434 }
435 }
436
437 espi_trans.n_tx = n_tx;
438 espi_trans.n_rx = n_rx;
439 espi_trans.len = n_tx + n_rx;
440 espi_trans.actual_length = 0;
441 espi_trans.status = 0;
442
443 if (!rx_buf)
444 fsl_espi_cmd_trans(m, &espi_trans, NULL);
445 else
446 fsl_espi_rw_trans(m, &espi_trans, rx_buf);
447
448 m->actual_length = espi_trans.actual_length;
449 m->status = espi_trans.status;
450 m->complete(m->context);
451}
452
453static int fsl_espi_setup(struct spi_device *spi)
454{
455 struct mpc8xxx_spi *mpc8xxx_spi;
456 struct fsl_espi_reg *reg_base;
457 int retval;
458 u32 hw_mode;
459 u32 loop_mode;
460 struct spi_mpc8xxx_cs *cs = spi->controller_state;
461
462 if (!spi->max_speed_hz)
463 return -EINVAL;
464
465 if (!cs) {
466 cs = kzalloc(sizeof *cs, GFP_KERNEL);
467 if (!cs)
468 return -ENOMEM;
469 spi->controller_state = cs;
470 }
471
472 mpc8xxx_spi = spi_master_get_devdata(spi->master);
473 reg_base = mpc8xxx_spi->reg_base;
474
475 hw_mode = cs->hw_mode; /* Save orginal settings */
476 cs->hw_mode = mpc8xxx_spi_read_reg(
477 &reg_base->csmode[spi->chip_select]);
478 /* mask out bits we are going to set */
479 cs->hw_mode &= ~(CSMODE_CP_BEGIN_EDGECLK | CSMODE_CI_INACTIVEHIGH
480 | CSMODE_REV);
481
482 if (spi->mode & SPI_CPHA)
483 cs->hw_mode |= CSMODE_CP_BEGIN_EDGECLK;
484 if (spi->mode & SPI_CPOL)
485 cs->hw_mode |= CSMODE_CI_INACTIVEHIGH;
486 if (!(spi->mode & SPI_LSB_FIRST))
487 cs->hw_mode |= CSMODE_REV;
488
489 /* Handle the loop mode */
490 loop_mode = mpc8xxx_spi_read_reg(&reg_base->mode);
491 loop_mode &= ~SPMODE_LOOP;
492 if (spi->mode & SPI_LOOP)
493 loop_mode |= SPMODE_LOOP;
494 mpc8xxx_spi_write_reg(&reg_base->mode, loop_mode);
495
496 retval = fsl_espi_setup_transfer(spi, NULL);
497 if (retval < 0) {
498 cs->hw_mode = hw_mode; /* Restore settings */
499 return retval;
500 }
501 return 0;
502}
503
504void fsl_espi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
505{
506 struct fsl_espi_reg *reg_base = mspi->reg_base;
507
508 /* We need handle RX first */
509 if (events & SPIE_NE) {
510 u32 rx_data;
511
512 /* Spin until RX is done */
513 while (SPIE_RXCNT(events) < min(4, mspi->len)) {
514 cpu_relax();
515 events = mpc8xxx_spi_read_reg(&reg_base->event);
516 }
517 mspi->len -= 4;
518
519 rx_data = mpc8xxx_spi_read_reg(&reg_base->receive);
520
521 if (mspi->rx)
522 mspi->get_rx(rx_data, mspi);
523 }
524
525 if (!(events & SPIE_NF)) {
526 int ret;
527
528 /* spin until TX is done */
529 ret = spin_event_timeout(((events = mpc8xxx_spi_read_reg(
530 &reg_base->event)) & SPIE_NF) == 0, 1000, 0);
531 if (!ret) {
532 dev_err(mspi->dev, "tired waiting for SPIE_NF\n");
533 return;
534 }
535 }
536
537 /* Clear the events */
538 mpc8xxx_spi_write_reg(&reg_base->event, events);
539
540 mspi->count -= 1;
541 if (mspi->count) {
542 u32 word = mspi->get_tx(mspi);
543
544 mpc8xxx_spi_write_reg(&reg_base->transmit, word);
545 } else {
546 complete(&mspi->done);
547 }
548}
549
550static irqreturn_t fsl_espi_irq(s32 irq, void *context_data)
551{
552 struct mpc8xxx_spi *mspi = context_data;
553 struct fsl_espi_reg *reg_base = mspi->reg_base;
554 irqreturn_t ret = IRQ_NONE;
555 u32 events;
556
557 /* Get interrupt events(tx/rx) */
558 events = mpc8xxx_spi_read_reg(&reg_base->event);
559 if (events)
560 ret = IRQ_HANDLED;
561
562 dev_vdbg(mspi->dev, "%s: events %x\n", __func__, events);
563
564 fsl_espi_cpu_irq(mspi, events);
565
566 return ret;
567}
568
569static void fsl_espi_remove(struct mpc8xxx_spi *mspi)
570{
571 iounmap(mspi->reg_base);
572}
573
574static struct spi_master * __devinit fsl_espi_probe(struct device *dev,
575 struct resource *mem, unsigned int irq)
576{
577 struct fsl_spi_platform_data *pdata = dev->platform_data;
578 struct spi_master *master;
579 struct mpc8xxx_spi *mpc8xxx_spi;
580 struct fsl_espi_reg *reg_base;
581 u32 regval;
582 int i, ret = 0;
583
584 master = spi_alloc_master(dev, sizeof(struct mpc8xxx_spi));
585 if (!master) {
586 ret = -ENOMEM;
587 goto err;
588 }
589
590 dev_set_drvdata(dev, master);
591
592 ret = mpc8xxx_spi_probe(dev, mem, irq);
593 if (ret)
594 goto err_probe;
595
596 master->setup = fsl_espi_setup;
597
598 mpc8xxx_spi = spi_master_get_devdata(master);
599 mpc8xxx_spi->spi_do_one_msg = fsl_espi_do_one_msg;
600 mpc8xxx_spi->spi_remove = fsl_espi_remove;
601
602 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
603 if (!mpc8xxx_spi->reg_base) {
604 ret = -ENOMEM;
605 goto err_probe;
606 }
607
608 reg_base = mpc8xxx_spi->reg_base;
609
610 /* Register for SPI Interrupt */
611 ret = request_irq(mpc8xxx_spi->irq, fsl_espi_irq,
612 0, "fsl_espi", mpc8xxx_spi);
613 if (ret)
614 goto free_irq;
615
616 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
617 mpc8xxx_spi->rx_shift = 16;
618 mpc8xxx_spi->tx_shift = 24;
619 }
620
621 /* SPI controller initializations */
622 mpc8xxx_spi_write_reg(&reg_base->mode, 0);
623 mpc8xxx_spi_write_reg(&reg_base->mask, 0);
624 mpc8xxx_spi_write_reg(&reg_base->command, 0);
625 mpc8xxx_spi_write_reg(&reg_base->event, 0xffffffff);
626
627 /* Init eSPI CS mode register */
628 for (i = 0; i < pdata->max_chipselect; i++)
629 mpc8xxx_spi_write_reg(&reg_base->csmode[i], CSMODE_INIT_VAL);
630
631 /* Enable SPI interface */
632 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
633
634 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
635
636 ret = spi_register_master(master);
637 if (ret < 0)
638 goto unreg_master;
639
640 dev_info(dev, "at 0x%p (irq = %d)\n", reg_base, mpc8xxx_spi->irq);
641
642 return master;
643
644unreg_master:
645 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
646free_irq:
647 iounmap(mpc8xxx_spi->reg_base);
648err_probe:
649 spi_master_put(master);
650err:
651 return ERR_PTR(ret);
652}
653
654static int of_fsl_espi_get_chipselects(struct device *dev)
655{
656 struct device_node *np = dev->of_node;
657 struct fsl_spi_platform_data *pdata = dev->platform_data;
658 const u32 *prop;
659 int len;
660
661 prop = of_get_property(np, "fsl,espi-num-chipselects", &len);
662 if (!prop || len < sizeof(*prop)) {
663 dev_err(dev, "No 'fsl,espi-num-chipselects' property\n");
664 return -EINVAL;
665 }
666
667 pdata->max_chipselect = *prop;
668 pdata->cs_control = NULL;
669
670 return 0;
671}
672
673static int __devinit of_fsl_espi_probe(struct platform_device *ofdev,
674 const struct of_device_id *ofid)
675{
676 struct device *dev = &ofdev->dev;
677 struct device_node *np = ofdev->dev.of_node;
678 struct spi_master *master;
679 struct resource mem;
680 struct resource irq;
681 int ret = -ENOMEM;
682
683 ret = of_mpc8xxx_spi_probe(ofdev, ofid);
684 if (ret)
685 return ret;
686
687 ret = of_fsl_espi_get_chipselects(dev);
688 if (ret)
689 goto err;
690
691 ret = of_address_to_resource(np, 0, &mem);
692 if (ret)
693 goto err;
694
695 ret = of_irq_to_resource(np, 0, &irq);
696 if (!ret) {
697 ret = -EINVAL;
698 goto err;
699 }
700
701 master = fsl_espi_probe(dev, &mem, irq.start);
702 if (IS_ERR(master)) {
703 ret = PTR_ERR(master);
704 goto err;
705 }
706
707 return 0;
708
709err:
710 return ret;
711}
712
713static int __devexit of_fsl_espi_remove(struct platform_device *dev)
714{
715 return mpc8xxx_spi_remove(&dev->dev);
716}
717
718static const struct of_device_id of_fsl_espi_match[] = {
719 { .compatible = "fsl,mpc8536-espi" },
720 {}
721};
722MODULE_DEVICE_TABLE(of, of_fsl_espi_match);
723
724static struct of_platform_driver fsl_espi_driver = {
725 .driver = {
726 .name = "fsl_espi",
727 .owner = THIS_MODULE,
728 .of_match_table = of_fsl_espi_match,
729 },
730 .probe = of_fsl_espi_probe,
731 .remove = __devexit_p(of_fsl_espi_remove),
732};
733
734static int __init fsl_espi_init(void)
735{
736 return of_register_platform_driver(&fsl_espi_driver);
737}
738module_init(fsl_espi_init);
739
740static void __exit fsl_espi_exit(void)
741{
742 of_unregister_platform_driver(&fsl_espi_driver);
743}
744module_exit(fsl_espi_exit);
745
746MODULE_AUTHOR("Mingkai Hu");
747MODULE_DESCRIPTION("Enhanced Freescale SPI Driver");
748MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi_fsl_lib.c b/drivers/spi/spi_fsl_lib.c
new file mode 100644
index 000000000000..5cd741fdb5c3
--- /dev/null
+++ b/drivers/spi/spi_fsl_lib.c
@@ -0,0 +1,237 @@
1/*
2 * Freescale SPI/eSPI controller driver library.
3 *
4 * Maintainer: Kumar Gala
5 *
6 * Copyright (C) 2006 Polycom, Inc.
7 *
8 * CPM SPI and QE buffer descriptors mode support:
9 * Copyright (c) 2009 MontaVista Software, Inc.
10 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
11 *
12 * Copyright 2010 Freescale Semiconductor, Inc.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 */
19#include <linux/kernel.h>
20#include <linux/interrupt.h>
21#include <linux/fsl_devices.h>
22#include <linux/dma-mapping.h>
23#include <linux/mm.h>
24#include <linux/of_platform.h>
25#include <linux/of_spi.h>
26#include <sysdev/fsl_soc.h>
27
28#include "spi_fsl_lib.h"
29
30#define MPC8XXX_SPI_RX_BUF(type) \
31void mpc8xxx_spi_rx_buf_##type(u32 data, struct mpc8xxx_spi *mpc8xxx_spi) \
32{ \
33 type *rx = mpc8xxx_spi->rx; \
34 *rx++ = (type)(data >> mpc8xxx_spi->rx_shift); \
35 mpc8xxx_spi->rx = rx; \
36}
37
38#define MPC8XXX_SPI_TX_BUF(type) \
39u32 mpc8xxx_spi_tx_buf_##type(struct mpc8xxx_spi *mpc8xxx_spi) \
40{ \
41 u32 data; \
42 const type *tx = mpc8xxx_spi->tx; \
43 if (!tx) \
44 return 0; \
45 data = *tx++ << mpc8xxx_spi->tx_shift; \
46 mpc8xxx_spi->tx = tx; \
47 return data; \
48}
49
50MPC8XXX_SPI_RX_BUF(u8)
51MPC8XXX_SPI_RX_BUF(u16)
52MPC8XXX_SPI_RX_BUF(u32)
53MPC8XXX_SPI_TX_BUF(u8)
54MPC8XXX_SPI_TX_BUF(u16)
55MPC8XXX_SPI_TX_BUF(u32)
56
57struct mpc8xxx_spi_probe_info *to_of_pinfo(struct fsl_spi_platform_data *pdata)
58{
59 return container_of(pdata, struct mpc8xxx_spi_probe_info, pdata);
60}
61
62void mpc8xxx_spi_work(struct work_struct *work)
63{
64 struct mpc8xxx_spi *mpc8xxx_spi = container_of(work, struct mpc8xxx_spi,
65 work);
66
67 spin_lock_irq(&mpc8xxx_spi->lock);
68 while (!list_empty(&mpc8xxx_spi->queue)) {
69 struct spi_message *m = container_of(mpc8xxx_spi->queue.next,
70 struct spi_message, queue);
71
72 list_del_init(&m->queue);
73 spin_unlock_irq(&mpc8xxx_spi->lock);
74
75 if (mpc8xxx_spi->spi_do_one_msg)
76 mpc8xxx_spi->spi_do_one_msg(m);
77
78 spin_lock_irq(&mpc8xxx_spi->lock);
79 }
80 spin_unlock_irq(&mpc8xxx_spi->lock);
81}
82
83int mpc8xxx_spi_transfer(struct spi_device *spi,
84 struct spi_message *m)
85{
86 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
87 unsigned long flags;
88
89 m->actual_length = 0;
90 m->status = -EINPROGRESS;
91
92 spin_lock_irqsave(&mpc8xxx_spi->lock, flags);
93 list_add_tail(&m->queue, &mpc8xxx_spi->queue);
94 queue_work(mpc8xxx_spi->workqueue, &mpc8xxx_spi->work);
95 spin_unlock_irqrestore(&mpc8xxx_spi->lock, flags);
96
97 return 0;
98}
99
100void mpc8xxx_spi_cleanup(struct spi_device *spi)
101{
102 kfree(spi->controller_state);
103}
104
105const char *mpc8xxx_spi_strmode(unsigned int flags)
106{
107 if (flags & SPI_QE_CPU_MODE) {
108 return "QE CPU";
109 } else if (flags & SPI_CPM_MODE) {
110 if (flags & SPI_QE)
111 return "QE";
112 else if (flags & SPI_CPM2)
113 return "CPM2";
114 else
115 return "CPM1";
116 }
117 return "CPU";
118}
119
120int mpc8xxx_spi_probe(struct device *dev, struct resource *mem,
121 unsigned int irq)
122{
123 struct fsl_spi_platform_data *pdata = dev->platform_data;
124 struct spi_master *master;
125 struct mpc8xxx_spi *mpc8xxx_spi;
126 int ret = 0;
127
128 master = dev_get_drvdata(dev);
129
130 /* the spi->mode bits understood by this driver: */
131 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH
132 | SPI_LSB_FIRST | SPI_LOOP;
133
134 master->transfer = mpc8xxx_spi_transfer;
135 master->cleanup = mpc8xxx_spi_cleanup;
136 master->dev.of_node = dev->of_node;
137
138 mpc8xxx_spi = spi_master_get_devdata(master);
139 mpc8xxx_spi->dev = dev;
140 mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8;
141 mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8;
142 mpc8xxx_spi->flags = pdata->flags;
143 mpc8xxx_spi->spibrg = pdata->sysclk;
144 mpc8xxx_spi->irq = irq;
145
146 mpc8xxx_spi->rx_shift = 0;
147 mpc8xxx_spi->tx_shift = 0;
148
149 init_completion(&mpc8xxx_spi->done);
150
151 master->bus_num = pdata->bus_num;
152 master->num_chipselect = pdata->max_chipselect;
153
154 spin_lock_init(&mpc8xxx_spi->lock);
155 init_completion(&mpc8xxx_spi->done);
156 INIT_WORK(&mpc8xxx_spi->work, mpc8xxx_spi_work);
157 INIT_LIST_HEAD(&mpc8xxx_spi->queue);
158
159 mpc8xxx_spi->workqueue = create_singlethread_workqueue(
160 dev_name(master->dev.parent));
161 if (mpc8xxx_spi->workqueue == NULL) {
162 ret = -EBUSY;
163 goto err;
164 }
165
166 return 0;
167
168err:
169 return ret;
170}
171
172int __devexit mpc8xxx_spi_remove(struct device *dev)
173{
174 struct mpc8xxx_spi *mpc8xxx_spi;
175 struct spi_master *master;
176
177 master = dev_get_drvdata(dev);
178 mpc8xxx_spi = spi_master_get_devdata(master);
179
180 flush_workqueue(mpc8xxx_spi->workqueue);
181 destroy_workqueue(mpc8xxx_spi->workqueue);
182 spi_unregister_master(master);
183
184 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
185
186 if (mpc8xxx_spi->spi_remove)
187 mpc8xxx_spi->spi_remove(mpc8xxx_spi);
188
189 return 0;
190}
191
192int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev,
193 const struct of_device_id *ofid)
194{
195 struct device *dev = &ofdev->dev;
196 struct device_node *np = ofdev->dev.of_node;
197 struct mpc8xxx_spi_probe_info *pinfo;
198 struct fsl_spi_platform_data *pdata;
199 const void *prop;
200 int ret = -ENOMEM;
201
202 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL);
203 if (!pinfo)
204 return -ENOMEM;
205
206 pdata = &pinfo->pdata;
207 dev->platform_data = pdata;
208
209 /* Allocate bus num dynamically. */
210 pdata->bus_num = -1;
211
212 /* SPI controller is either clocked from QE or SoC clock. */
213 pdata->sysclk = get_brgfreq();
214 if (pdata->sysclk == -1) {
215 pdata->sysclk = fsl_get_sys_freq();
216 if (pdata->sysclk == -1) {
217 ret = -ENODEV;
218 goto err;
219 }
220 }
221
222 prop = of_get_property(np, "mode", NULL);
223 if (prop && !strcmp(prop, "cpu-qe"))
224 pdata->flags = SPI_QE_CPU_MODE;
225 else if (prop && !strcmp(prop, "qe"))
226 pdata->flags = SPI_CPM_MODE | SPI_QE;
227 else if (of_device_is_compatible(np, "fsl,cpm2-spi"))
228 pdata->flags = SPI_CPM_MODE | SPI_CPM2;
229 else if (of_device_is_compatible(np, "fsl,cpm1-spi"))
230 pdata->flags = SPI_CPM_MODE | SPI_CPM1;
231
232 return 0;
233
234err:
235 kfree(pinfo);
236 return ret;
237}
diff --git a/drivers/spi/spi_fsl_lib.h b/drivers/spi/spi_fsl_lib.h
new file mode 100644
index 000000000000..281e060977cd
--- /dev/null
+++ b/drivers/spi/spi_fsl_lib.h
@@ -0,0 +1,124 @@
1/*
2 * Freescale SPI/eSPI controller driver library.
3 *
4 * Maintainer: Kumar Gala
5 *
6 * Copyright 2010 Freescale Semiconductor, Inc.
7 * Copyright (C) 2006 Polycom, Inc.
8 *
9 * CPM SPI and QE buffer descriptors mode support:
10 * Copyright (c) 2009 MontaVista Software, Inc.
11 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18#ifndef __SPI_FSL_LIB_H__
19#define __SPI_FSL_LIB_H__
20
21#include <asm/io.h>
22
23/* SPI/eSPI Controller driver's private data. */
24struct mpc8xxx_spi {
25 struct device *dev;
26 void *reg_base;
27
28 /* rx & tx bufs from the spi_transfer */
29 const void *tx;
30 void *rx;
31#ifdef CONFIG_SPI_FSL_ESPI
32 int len;
33#endif
34
35 int subblock;
36 struct spi_pram __iomem *pram;
37 struct cpm_buf_desc __iomem *tx_bd;
38 struct cpm_buf_desc __iomem *rx_bd;
39
40 struct spi_transfer *xfer_in_progress;
41
42 /* dma addresses for CPM transfers */
43 dma_addr_t tx_dma;
44 dma_addr_t rx_dma;
45 bool map_tx_dma;
46 bool map_rx_dma;
47
48 dma_addr_t dma_dummy_tx;
49 dma_addr_t dma_dummy_rx;
50
51 /* functions to deal with different sized buffers */
52 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
53 u32(*get_tx) (struct mpc8xxx_spi *);
54
55 /* hooks for different controller driver */
56 void (*spi_do_one_msg) (struct spi_message *m);
57 void (*spi_remove) (struct mpc8xxx_spi *mspi);
58
59 unsigned int count;
60 unsigned int irq;
61
62 unsigned nsecs; /* (clock cycle time)/2 */
63
64 u32 spibrg; /* SPIBRG input clock */
65 u32 rx_shift; /* RX data reg shift when in qe mode */
66 u32 tx_shift; /* TX data reg shift when in qe mode */
67
68 unsigned int flags;
69
70 struct workqueue_struct *workqueue;
71 struct work_struct work;
72
73 struct list_head queue;
74 spinlock_t lock;
75
76 struct completion done;
77};
78
79struct spi_mpc8xxx_cs {
80 /* functions to deal with different sized buffers */
81 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
82 u32 (*get_tx) (struct mpc8xxx_spi *);
83 u32 rx_shift; /* RX data reg shift when in qe mode */
84 u32 tx_shift; /* TX data reg shift when in qe mode */
85 u32 hw_mode; /* Holds HW mode register settings */
86};
87
88static inline void mpc8xxx_spi_write_reg(__be32 __iomem *reg, u32 val)
89{
90 out_be32(reg, val);
91}
92
93static inline u32 mpc8xxx_spi_read_reg(__be32 __iomem *reg)
94{
95 return in_be32(reg);
96}
97
98struct mpc8xxx_spi_probe_info {
99 struct fsl_spi_platform_data pdata;
100 int *gpios;
101 bool *alow_flags;
102};
103
104extern u32 mpc8xxx_spi_tx_buf_u8(struct mpc8xxx_spi *mpc8xxx_spi);
105extern u32 mpc8xxx_spi_tx_buf_u16(struct mpc8xxx_spi *mpc8xxx_spi);
106extern u32 mpc8xxx_spi_tx_buf_u32(struct mpc8xxx_spi *mpc8xxx_spi);
107extern void mpc8xxx_spi_rx_buf_u8(u32 data, struct mpc8xxx_spi *mpc8xxx_spi);
108extern void mpc8xxx_spi_rx_buf_u16(u32 data, struct mpc8xxx_spi *mpc8xxx_spi);
109extern void mpc8xxx_spi_rx_buf_u32(u32 data, struct mpc8xxx_spi *mpc8xxx_spi);
110
111extern struct mpc8xxx_spi_probe_info *to_of_pinfo(
112 struct fsl_spi_platform_data *pdata);
113extern int mpc8xxx_spi_bufs(struct mpc8xxx_spi *mspi,
114 struct spi_transfer *t, unsigned int len);
115extern int mpc8xxx_spi_transfer(struct spi_device *spi, struct spi_message *m);
116extern void mpc8xxx_spi_cleanup(struct spi_device *spi);
117extern const char *mpc8xxx_spi_strmode(unsigned int flags);
118extern int mpc8xxx_spi_probe(struct device *dev, struct resource *mem,
119 unsigned int irq);
120extern int mpc8xxx_spi_remove(struct device *dev);
121extern int of_mpc8xxx_spi_probe(struct platform_device *ofdev,
122 const struct of_device_id *ofid);
123
124#endif /* __SPI_FSL_LIB_H__ */
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_fsl_spi.c
index d31b57f7baaf..7ca52d3ae8f8 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_fsl_spi.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * MPC8xxx SPI controller driver. 2 * Freescale SPI controller driver.
3 * 3 *
4 * Maintainer: Kumar Gala 4 * Maintainer: Kumar Gala
5 * 5 *
6 * Copyright (C) 2006 Polycom, Inc. 6 * Copyright (C) 2006 Polycom, Inc.
7 * Copyright 2010 Freescale Semiconductor, Inc.
7 * 8 *
8 * CPM SPI and QE buffer descriptors mode support: 9 * CPM SPI and QE buffer descriptors mode support:
9 * Copyright (c) 2009 MontaVista Software, Inc. 10 * Copyright (c) 2009 MontaVista Software, Inc.
@@ -15,18 +16,11 @@
15 * option) any later version. 16 * option) any later version.
16 */ 17 */
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/bug.h>
22#include <linux/errno.h>
23#include <linux/err.h>
24#include <linux/io.h>
25#include <linux/completion.h>
26#include <linux/interrupt.h> 21#include <linux/interrupt.h>
27#include <linux/delay.h> 22#include <linux/delay.h>
28#include <linux/irq.h> 23#include <linux/irq.h>
29#include <linux/device.h>
30#include <linux/spi/spi.h> 24#include <linux/spi/spi.h>
31#include <linux/spi/spi_bitbang.h> 25#include <linux/spi/spi_bitbang.h>
32#include <linux/platform_device.h> 26#include <linux/platform_device.h>
@@ -38,12 +32,12 @@
38#include <linux/of_platform.h> 32#include <linux/of_platform.h>
39#include <linux/gpio.h> 33#include <linux/gpio.h>
40#include <linux/of_gpio.h> 34#include <linux/of_gpio.h>
41#include <linux/slab.h>
42 35
43#include <sysdev/fsl_soc.h> 36#include <sysdev/fsl_soc.h>
44#include <asm/cpm.h> 37#include <asm/cpm.h>
45#include <asm/qe.h> 38#include <asm/qe.h>
46#include <asm/irq.h> 39
40#include "spi_fsl_lib.h"
47 41
48/* CPM1 and CPM2 are mutually exclusive. */ 42/* CPM1 and CPM2 are mutually exclusive. */
49#ifdef CONFIG_CPM1 43#ifdef CONFIG_CPM1
@@ -55,7 +49,7 @@
55#endif 49#endif
56 50
57/* SPI Controller registers */ 51/* SPI Controller registers */
58struct mpc8xxx_spi_reg { 52struct fsl_spi_reg {
59 u8 res1[0x20]; 53 u8 res1[0x20];
60 __be32 mode; 54 __be32 mode;
61 __be32 event; 55 __be32 event;
@@ -80,7 +74,7 @@ struct mpc8xxx_spi_reg {
80 74
81/* 75/*
82 * Default for SPI Mode: 76 * Default for SPI Mode:
83 * SPI MODE 0 (inactive low, phase middle, MSB, 8-bit length, slow clk 77 * SPI MODE 0 (inactive low, phase middle, MSB, 8-bit length, slow clk
84 */ 78 */
85#define SPMODE_INIT_VAL (SPMODE_CI_INACTIVEHIGH | SPMODE_DIV16 | SPMODE_REV | \ 79#define SPMODE_INIT_VAL (SPMODE_CI_INACTIVEHIGH | SPMODE_DIV16 | SPMODE_REV | \
86 SPMODE_MS | SPMODE_LEN(7) | SPMODE_PM(0xf)) 80 SPMODE_MS | SPMODE_LEN(7) | SPMODE_PM(0xf))
@@ -102,112 +96,16 @@ struct mpc8xxx_spi_reg {
102#define SPI_PRAM_SIZE 0x100 96#define SPI_PRAM_SIZE 0x100
103#define SPI_MRBLR ((unsigned int)PAGE_SIZE) 97#define SPI_MRBLR ((unsigned int)PAGE_SIZE)
104 98
105/* SPI Controller driver's private data. */ 99static void *fsl_dummy_rx;
106struct mpc8xxx_spi { 100static DEFINE_MUTEX(fsl_dummy_rx_lock);
107 struct device *dev; 101static int fsl_dummy_rx_refcnt;
108 struct mpc8xxx_spi_reg __iomem *base;
109
110 /* rx & tx bufs from the spi_transfer */
111 const void *tx;
112 void *rx;
113
114 int subblock;
115 struct spi_pram __iomem *pram;
116 struct cpm_buf_desc __iomem *tx_bd;
117 struct cpm_buf_desc __iomem *rx_bd;
118
119 struct spi_transfer *xfer_in_progress;
120
121 /* dma addresses for CPM transfers */
122 dma_addr_t tx_dma;
123 dma_addr_t rx_dma;
124 bool map_tx_dma;
125 bool map_rx_dma;
126
127 dma_addr_t dma_dummy_tx;
128 dma_addr_t dma_dummy_rx;
129
130 /* functions to deal with different sized buffers */
131 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
132 u32(*get_tx) (struct mpc8xxx_spi *);
133
134 unsigned int count;
135 unsigned int irq;
136
137 unsigned nsecs; /* (clock cycle time)/2 */
138
139 u32 spibrg; /* SPIBRG input clock */
140 u32 rx_shift; /* RX data reg shift when in qe mode */
141 u32 tx_shift; /* TX data reg shift when in qe mode */
142
143 unsigned int flags;
144
145 struct workqueue_struct *workqueue;
146 struct work_struct work;
147
148 struct list_head queue;
149 spinlock_t lock;
150 102
151 struct completion done; 103static void fsl_spi_change_mode(struct spi_device *spi)
152};
153
154static void *mpc8xxx_dummy_rx;
155static DEFINE_MUTEX(mpc8xxx_dummy_rx_lock);
156static int mpc8xxx_dummy_rx_refcnt;
157
158struct spi_mpc8xxx_cs {
159 /* functions to deal with different sized buffers */
160 void (*get_rx) (u32 rx_data, struct mpc8xxx_spi *);
161 u32 (*get_tx) (struct mpc8xxx_spi *);
162 u32 rx_shift; /* RX data reg shift when in qe mode */
163 u32 tx_shift; /* TX data reg shift when in qe mode */
164 u32 hw_mode; /* Holds HW mode register settings */
165};
166
167static inline void mpc8xxx_spi_write_reg(__be32 __iomem *reg, u32 val)
168{
169 out_be32(reg, val);
170}
171
172static inline u32 mpc8xxx_spi_read_reg(__be32 __iomem *reg)
173{
174 return in_be32(reg);
175}
176
177#define MPC83XX_SPI_RX_BUF(type) \
178static \
179void mpc8xxx_spi_rx_buf_##type(u32 data, struct mpc8xxx_spi *mpc8xxx_spi) \
180{ \
181 type *rx = mpc8xxx_spi->rx; \
182 *rx++ = (type)(data >> mpc8xxx_spi->rx_shift); \
183 mpc8xxx_spi->rx = rx; \
184}
185
186#define MPC83XX_SPI_TX_BUF(type) \
187static \
188u32 mpc8xxx_spi_tx_buf_##type(struct mpc8xxx_spi *mpc8xxx_spi) \
189{ \
190 u32 data; \
191 const type *tx = mpc8xxx_spi->tx; \
192 if (!tx) \
193 return 0; \
194 data = *tx++ << mpc8xxx_spi->tx_shift; \
195 mpc8xxx_spi->tx = tx; \
196 return data; \
197}
198
199MPC83XX_SPI_RX_BUF(u8)
200MPC83XX_SPI_RX_BUF(u16)
201MPC83XX_SPI_RX_BUF(u32)
202MPC83XX_SPI_TX_BUF(u8)
203MPC83XX_SPI_TX_BUF(u16)
204MPC83XX_SPI_TX_BUF(u32)
205
206static void mpc8xxx_spi_change_mode(struct spi_device *spi)
207{ 104{
208 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master); 105 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
209 struct spi_mpc8xxx_cs *cs = spi->controller_state; 106 struct spi_mpc8xxx_cs *cs = spi->controller_state;
210 __be32 __iomem *mode = &mspi->base->mode; 107 struct fsl_spi_reg *reg_base = mspi->reg_base;
108 __be32 __iomem *mode = &reg_base->mode;
211 unsigned long flags; 109 unsigned long flags;
212 110
213 if (cs->hw_mode == mpc8xxx_spi_read_reg(mode)) 111 if (cs->hw_mode == mpc8xxx_spi_read_reg(mode))
@@ -238,7 +136,7 @@ static void mpc8xxx_spi_change_mode(struct spi_device *spi)
238 local_irq_restore(flags); 136 local_irq_restore(flags);
239} 137}
240 138
241static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value) 139static void fsl_spi_chipselect(struct spi_device *spi, int value)
242{ 140{
243 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 141 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
244 struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data; 142 struct fsl_spi_platform_data *pdata = spi->dev.parent->platform_data;
@@ -256,18 +154,17 @@ static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
256 mpc8xxx_spi->get_rx = cs->get_rx; 154 mpc8xxx_spi->get_rx = cs->get_rx;
257 mpc8xxx_spi->get_tx = cs->get_tx; 155 mpc8xxx_spi->get_tx = cs->get_tx;
258 156
259 mpc8xxx_spi_change_mode(spi); 157 fsl_spi_change_mode(spi);
260 158
261 if (pdata->cs_control) 159 if (pdata->cs_control)
262 pdata->cs_control(spi, pol); 160 pdata->cs_control(spi, pol);
263 } 161 }
264} 162}
265 163
266static int 164static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
267mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs, 165 struct spi_device *spi,
268 struct spi_device *spi, 166 struct mpc8xxx_spi *mpc8xxx_spi,
269 struct mpc8xxx_spi *mpc8xxx_spi, 167 int bits_per_word)
270 int bits_per_word)
271{ 168{
272 cs->rx_shift = 0; 169 cs->rx_shift = 0;
273 cs->tx_shift = 0; 170 cs->tx_shift = 0;
@@ -307,10 +204,9 @@ mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
307 return bits_per_word; 204 return bits_per_word;
308} 205}
309 206
310static int 207static int mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs,
311mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs, 208 struct spi_device *spi,
312 struct spi_device *spi, 209 int bits_per_word)
313 int bits_per_word)
314{ 210{
315 /* QE uses Little Endian for words > 8 211 /* QE uses Little Endian for words > 8
316 * so transform all words > 8 into 8 bits 212 * so transform all words > 8 into 8 bits
@@ -326,13 +222,13 @@ mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs,
326 return bits_per_word; 222 return bits_per_word;
327} 223}
328 224
329static 225static int fsl_spi_setup_transfer(struct spi_device *spi,
330int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 226 struct spi_transfer *t)
331{ 227{
332 struct mpc8xxx_spi *mpc8xxx_spi; 228 struct mpc8xxx_spi *mpc8xxx_spi;
333 int bits_per_word; 229 int bits_per_word = 0;
334 u8 pm; 230 u8 pm;
335 u32 hz; 231 u32 hz = 0;
336 struct spi_mpc8xxx_cs *cs = spi->controller_state; 232 struct spi_mpc8xxx_cs *cs = spi->controller_state;
337 233
338 mpc8xxx_spi = spi_master_get_devdata(spi->master); 234 mpc8xxx_spi = spi_master_get_devdata(spi->master);
@@ -340,9 +236,6 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
340 if (t) { 236 if (t) {
341 bits_per_word = t->bits_per_word; 237 bits_per_word = t->bits_per_word;
342 hz = t->speed_hz; 238 hz = t->speed_hz;
343 } else {
344 bits_per_word = 0;
345 hz = 0;
346 } 239 }
347 240
348 /* spi_transfer level calls that work per-word */ 241 /* spi_transfer level calls that work per-word */
@@ -388,43 +281,52 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
388 hz, mpc8xxx_spi->spibrg / 1024); 281 hz, mpc8xxx_spi->spibrg / 1024);
389 if (pm > 16) 282 if (pm > 16)
390 pm = 16; 283 pm = 16;
391 } else 284 } else {
392 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 4) + 1; 285 pm = (mpc8xxx_spi->spibrg - 1) / (hz * 4) + 1;
286 }
393 if (pm) 287 if (pm)
394 pm--; 288 pm--;
395 289
396 cs->hw_mode |= SPMODE_PM(pm); 290 cs->hw_mode |= SPMODE_PM(pm);
397 291
398 mpc8xxx_spi_change_mode(spi); 292 fsl_spi_change_mode(spi);
399 return 0; 293 return 0;
400} 294}
401 295
402static void mpc8xxx_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi) 296static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi)
403{ 297{
404 struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd; 298 struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd;
405 struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd; 299 struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd;
406 unsigned int xfer_len = min(mspi->count, SPI_MRBLR); 300 unsigned int xfer_len = min(mspi->count, SPI_MRBLR);
407 unsigned int xfer_ofs; 301 unsigned int xfer_ofs;
302 struct fsl_spi_reg *reg_base = mspi->reg_base;
408 303
409 xfer_ofs = mspi->xfer_in_progress->len - mspi->count; 304 xfer_ofs = mspi->xfer_in_progress->len - mspi->count;
410 305
411 out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs); 306 if (mspi->rx_dma == mspi->dma_dummy_rx)
307 out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma);
308 else
309 out_be32(&rx_bd->cbd_bufaddr, mspi->rx_dma + xfer_ofs);
412 out_be16(&rx_bd->cbd_datlen, 0); 310 out_be16(&rx_bd->cbd_datlen, 0);
413 out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP); 311 out_be16(&rx_bd->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP);
414 312
415 out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs); 313 if (mspi->tx_dma == mspi->dma_dummy_tx)
314 out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma);
315 else
316 out_be32(&tx_bd->cbd_bufaddr, mspi->tx_dma + xfer_ofs);
416 out_be16(&tx_bd->cbd_datlen, xfer_len); 317 out_be16(&tx_bd->cbd_datlen, xfer_len);
417 out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP | 318 out_be16(&tx_bd->cbd_sc, BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP |
418 BD_SC_LAST); 319 BD_SC_LAST);
419 320
420 /* start transfer */ 321 /* start transfer */
421 mpc8xxx_spi_write_reg(&mspi->base->command, SPCOM_STR); 322 mpc8xxx_spi_write_reg(&reg_base->command, SPCOM_STR);
422} 323}
423 324
424static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi, 325static int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
425 struct spi_transfer *t, bool is_dma_mapped) 326 struct spi_transfer *t, bool is_dma_mapped)
426{ 327{
427 struct device *dev = mspi->dev; 328 struct device *dev = mspi->dev;
329 struct fsl_spi_reg *reg_base = mspi->reg_base;
428 330
429 if (is_dma_mapped) { 331 if (is_dma_mapped) {
430 mspi->map_tx_dma = 0; 332 mspi->map_tx_dma = 0;
@@ -469,13 +371,13 @@ static int mpc8xxx_spi_cpm_bufs(struct mpc8xxx_spi *mspi,
469 } 371 }
470 372
471 /* enable rx ints */ 373 /* enable rx ints */
472 mpc8xxx_spi_write_reg(&mspi->base->mask, SPIE_RXB); 374 mpc8xxx_spi_write_reg(&reg_base->mask, SPIE_RXB);
473 375
474 mspi->xfer_in_progress = t; 376 mspi->xfer_in_progress = t;
475 mspi->count = t->len; 377 mspi->count = t->len;
476 378
477 /* start CPM transfers */ 379 /* start CPM transfers */
478 mpc8xxx_spi_cpm_bufs_start(mspi); 380 fsl_spi_cpm_bufs_start(mspi);
479 381
480 return 0; 382 return 0;
481 383
@@ -485,7 +387,7 @@ err_rx_dma:
485 return -ENOMEM; 387 return -ENOMEM;
486} 388}
487 389
488static void mpc8xxx_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) 390static void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi)
489{ 391{
490 struct device *dev = mspi->dev; 392 struct device *dev = mspi->dev;
491 struct spi_transfer *t = mspi->xfer_in_progress; 393 struct spi_transfer *t = mspi->xfer_in_progress;
@@ -497,31 +399,34 @@ static void mpc8xxx_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi)
497 mspi->xfer_in_progress = NULL; 399 mspi->xfer_in_progress = NULL;
498} 400}
499 401
500static int mpc8xxx_spi_cpu_bufs(struct mpc8xxx_spi *mspi, 402static int fsl_spi_cpu_bufs(struct mpc8xxx_spi *mspi,
501 struct spi_transfer *t, unsigned int len) 403 struct spi_transfer *t, unsigned int len)
502{ 404{
503 u32 word; 405 u32 word;
406 struct fsl_spi_reg *reg_base = mspi->reg_base;
504 407
505 mspi->count = len; 408 mspi->count = len;
506 409
507 /* enable rx ints */ 410 /* enable rx ints */
508 mpc8xxx_spi_write_reg(&mspi->base->mask, SPIM_NE); 411 mpc8xxx_spi_write_reg(&reg_base->mask, SPIM_NE);
509 412
510 /* transmit word */ 413 /* transmit word */
511 word = mspi->get_tx(mspi); 414 word = mspi->get_tx(mspi);
512 mpc8xxx_spi_write_reg(&mspi->base->transmit, word); 415 mpc8xxx_spi_write_reg(&reg_base->transmit, word);
513 416
514 return 0; 417 return 0;
515} 418}
516 419
517static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t, 420static int fsl_spi_bufs(struct spi_device *spi, struct spi_transfer *t,
518 bool is_dma_mapped) 421 bool is_dma_mapped)
519{ 422{
520 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 423 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
424 struct fsl_spi_reg *reg_base;
521 unsigned int len = t->len; 425 unsigned int len = t->len;
522 u8 bits_per_word; 426 u8 bits_per_word;
523 int ret; 427 int ret;
524 428
429 reg_base = mpc8xxx_spi->reg_base;
525 bits_per_word = spi->bits_per_word; 430 bits_per_word = spi->bits_per_word;
526 if (t->bits_per_word) 431 if (t->bits_per_word)
527 bits_per_word = t->bits_per_word; 432 bits_per_word = t->bits_per_word;
@@ -545,24 +450,24 @@ static int mpc8xxx_spi_bufs(struct spi_device *spi, struct spi_transfer *t,
545 INIT_COMPLETION(mpc8xxx_spi->done); 450 INIT_COMPLETION(mpc8xxx_spi->done);
546 451
547 if (mpc8xxx_spi->flags & SPI_CPM_MODE) 452 if (mpc8xxx_spi->flags & SPI_CPM_MODE)
548 ret = mpc8xxx_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped); 453 ret = fsl_spi_cpm_bufs(mpc8xxx_spi, t, is_dma_mapped);
549 else 454 else
550 ret = mpc8xxx_spi_cpu_bufs(mpc8xxx_spi, t, len); 455 ret = fsl_spi_cpu_bufs(mpc8xxx_spi, t, len);
551 if (ret) 456 if (ret)
552 return ret; 457 return ret;
553 458
554 wait_for_completion(&mpc8xxx_spi->done); 459 wait_for_completion(&mpc8xxx_spi->done);
555 460
556 /* disable rx ints */ 461 /* disable rx ints */
557 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0); 462 mpc8xxx_spi_write_reg(&reg_base->mask, 0);
558 463
559 if (mpc8xxx_spi->flags & SPI_CPM_MODE) 464 if (mpc8xxx_spi->flags & SPI_CPM_MODE)
560 mpc8xxx_spi_cpm_bufs_complete(mpc8xxx_spi); 465 fsl_spi_cpm_bufs_complete(mpc8xxx_spi);
561 466
562 return mpc8xxx_spi->count; 467 return mpc8xxx_spi->count;
563} 468}
564 469
565static void mpc8xxx_spi_do_one_msg(struct spi_message *m) 470static void fsl_spi_do_one_msg(struct spi_message *m)
566{ 471{
567 struct spi_device *spi = m->spi; 472 struct spi_device *spi = m->spi;
568 struct spi_transfer *t; 473 struct spi_transfer *t;
@@ -578,18 +483,18 @@ static void mpc8xxx_spi_do_one_msg(struct spi_message *m)
578 status = -EINVAL; 483 status = -EINVAL;
579 484
580 if (cs_change) 485 if (cs_change)
581 status = mpc8xxx_spi_setup_transfer(spi, t); 486 status = fsl_spi_setup_transfer(spi, t);
582 if (status < 0) 487 if (status < 0)
583 break; 488 break;
584 } 489 }
585 490
586 if (cs_change) { 491 if (cs_change) {
587 mpc8xxx_spi_chipselect(spi, BITBANG_CS_ACTIVE); 492 fsl_spi_chipselect(spi, BITBANG_CS_ACTIVE);
588 ndelay(nsecs); 493 ndelay(nsecs);
589 } 494 }
590 cs_change = t->cs_change; 495 cs_change = t->cs_change;
591 if (t->len) 496 if (t->len)
592 status = mpc8xxx_spi_bufs(spi, t, m->is_dma_mapped); 497 status = fsl_spi_bufs(spi, t, m->is_dma_mapped);
593 if (status) { 498 if (status) {
594 status = -EMSGSIZE; 499 status = -EMSGSIZE;
595 break; 500 break;
@@ -601,7 +506,7 @@ static void mpc8xxx_spi_do_one_msg(struct spi_message *m)
601 506
602 if (cs_change) { 507 if (cs_change) {
603 ndelay(nsecs); 508 ndelay(nsecs);
604 mpc8xxx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 509 fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE);
605 ndelay(nsecs); 510 ndelay(nsecs);
606 } 511 }
607 } 512 }
@@ -611,35 +516,16 @@ static void mpc8xxx_spi_do_one_msg(struct spi_message *m)
611 516
612 if (status || !cs_change) { 517 if (status || !cs_change) {
613 ndelay(nsecs); 518 ndelay(nsecs);
614 mpc8xxx_spi_chipselect(spi, BITBANG_CS_INACTIVE); 519 fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE);
615 } 520 }
616 521
617 mpc8xxx_spi_setup_transfer(spi, NULL); 522 fsl_spi_setup_transfer(spi, NULL);
618}
619
620static void mpc8xxx_spi_work(struct work_struct *work)
621{
622 struct mpc8xxx_spi *mpc8xxx_spi = container_of(work, struct mpc8xxx_spi,
623 work);
624
625 spin_lock_irq(&mpc8xxx_spi->lock);
626 while (!list_empty(&mpc8xxx_spi->queue)) {
627 struct spi_message *m = container_of(mpc8xxx_spi->queue.next,
628 struct spi_message, queue);
629
630 list_del_init(&m->queue);
631 spin_unlock_irq(&mpc8xxx_spi->lock);
632
633 mpc8xxx_spi_do_one_msg(m);
634
635 spin_lock_irq(&mpc8xxx_spi->lock);
636 }
637 spin_unlock_irq(&mpc8xxx_spi->lock);
638} 523}
639 524
640static int mpc8xxx_spi_setup(struct spi_device *spi) 525static int fsl_spi_setup(struct spi_device *spi)
641{ 526{
642 struct mpc8xxx_spi *mpc8xxx_spi; 527 struct mpc8xxx_spi *mpc8xxx_spi;
528 struct fsl_spi_reg *reg_base;
643 int retval; 529 int retval;
644 u32 hw_mode; 530 u32 hw_mode;
645 struct spi_mpc8xxx_cs *cs = spi->controller_state; 531 struct spi_mpc8xxx_cs *cs = spi->controller_state;
@@ -655,8 +541,10 @@ static int mpc8xxx_spi_setup(struct spi_device *spi)
655 } 541 }
656 mpc8xxx_spi = spi_master_get_devdata(spi->master); 542 mpc8xxx_spi = spi_master_get_devdata(spi->master);
657 543
544 reg_base = mpc8xxx_spi->reg_base;
545
658 hw_mode = cs->hw_mode; /* Save original settings */ 546 hw_mode = cs->hw_mode; /* Save original settings */
659 cs->hw_mode = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode); 547 cs->hw_mode = mpc8xxx_spi_read_reg(&reg_base->mode);
660 /* mask out bits we are going to set */ 548 /* mask out bits we are going to set */
661 cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH 549 cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH
662 | SPMODE_REV | SPMODE_LOOP); 550 | SPMODE_REV | SPMODE_LOOP);
@@ -670,7 +558,7 @@ static int mpc8xxx_spi_setup(struct spi_device *spi)
670 if (spi->mode & SPI_LOOP) 558 if (spi->mode & SPI_LOOP)
671 cs->hw_mode |= SPMODE_LOOP; 559 cs->hw_mode |= SPMODE_LOOP;
672 560
673 retval = mpc8xxx_spi_setup_transfer(spi, NULL); 561 retval = fsl_spi_setup_transfer(spi, NULL);
674 if (retval < 0) { 562 if (retval < 0) {
675 cs->hw_mode = hw_mode; /* Restore settings */ 563 cs->hw_mode = hw_mode; /* Restore settings */
676 return retval; 564 return retval;
@@ -678,9 +566,10 @@ static int mpc8xxx_spi_setup(struct spi_device *spi)
678 return 0; 566 return 0;
679} 567}
680 568
681static void mpc8xxx_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) 569static void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events)
682{ 570{
683 u16 len; 571 u16 len;
572 struct fsl_spi_reg *reg_base = mspi->reg_base;
684 573
685 dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__, 574 dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__,
686 in_be16(&mspi->rx_bd->cbd_datlen), mspi->count); 575 in_be16(&mspi->rx_bd->cbd_datlen), mspi->count);
@@ -692,20 +581,22 @@ static void mpc8xxx_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events)
692 } 581 }
693 582
694 /* Clear the events */ 583 /* Clear the events */
695 mpc8xxx_spi_write_reg(&mspi->base->event, events); 584 mpc8xxx_spi_write_reg(&reg_base->event, events);
696 585
697 mspi->count -= len; 586 mspi->count -= len;
698 if (mspi->count) 587 if (mspi->count)
699 mpc8xxx_spi_cpm_bufs_start(mspi); 588 fsl_spi_cpm_bufs_start(mspi);
700 else 589 else
701 complete(&mspi->done); 590 complete(&mspi->done);
702} 591}
703 592
704static void mpc8xxx_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events) 593static void fsl_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
705{ 594{
595 struct fsl_spi_reg *reg_base = mspi->reg_base;
596
706 /* We need handle RX first */ 597 /* We need handle RX first */
707 if (events & SPIE_NE) { 598 if (events & SPIE_NE) {
708 u32 rx_data = mpc8xxx_spi_read_reg(&mspi->base->receive); 599 u32 rx_data = mpc8xxx_spi_read_reg(&reg_base->receive);
709 600
710 if (mspi->rx) 601 if (mspi->rx)
711 mspi->get_rx(rx_data, mspi); 602 mspi->get_rx(rx_data, mspi);
@@ -714,102 +605,80 @@ static void mpc8xxx_spi_cpu_irq(struct mpc8xxx_spi *mspi, u32 events)
714 if ((events & SPIE_NF) == 0) 605 if ((events & SPIE_NF) == 0)
715 /* spin until TX is done */ 606 /* spin until TX is done */
716 while (((events = 607 while (((events =
717 mpc8xxx_spi_read_reg(&mspi->base->event)) & 608 mpc8xxx_spi_read_reg(&reg_base->event)) &
718 SPIE_NF) == 0) 609 SPIE_NF) == 0)
719 cpu_relax(); 610 cpu_relax();
720 611
721 /* Clear the events */ 612 /* Clear the events */
722 mpc8xxx_spi_write_reg(&mspi->base->event, events); 613 mpc8xxx_spi_write_reg(&reg_base->event, events);
723 614
724 mspi->count -= 1; 615 mspi->count -= 1;
725 if (mspi->count) { 616 if (mspi->count) {
726 u32 word = mspi->get_tx(mspi); 617 u32 word = mspi->get_tx(mspi);
727 618
728 mpc8xxx_spi_write_reg(&mspi->base->transmit, word); 619 mpc8xxx_spi_write_reg(&reg_base->transmit, word);
729 } else { 620 } else {
730 complete(&mspi->done); 621 complete(&mspi->done);
731 } 622 }
732} 623}
733 624
734static irqreturn_t mpc8xxx_spi_irq(s32 irq, void *context_data) 625static irqreturn_t fsl_spi_irq(s32 irq, void *context_data)
735{ 626{
736 struct mpc8xxx_spi *mspi = context_data; 627 struct mpc8xxx_spi *mspi = context_data;
737 irqreturn_t ret = IRQ_NONE; 628 irqreturn_t ret = IRQ_NONE;
738 u32 events; 629 u32 events;
630 struct fsl_spi_reg *reg_base = mspi->reg_base;
739 631
740 /* Get interrupt events(tx/rx) */ 632 /* Get interrupt events(tx/rx) */
741 events = mpc8xxx_spi_read_reg(&mspi->base->event); 633 events = mpc8xxx_spi_read_reg(&reg_base->event);
742 if (events) 634 if (events)
743 ret = IRQ_HANDLED; 635 ret = IRQ_HANDLED;
744 636
745 dev_dbg(mspi->dev, "%s: events %x\n", __func__, events); 637 dev_dbg(mspi->dev, "%s: events %x\n", __func__, events);
746 638
747 if (mspi->flags & SPI_CPM_MODE) 639 if (mspi->flags & SPI_CPM_MODE)
748 mpc8xxx_spi_cpm_irq(mspi, events); 640 fsl_spi_cpm_irq(mspi, events);
749 else 641 else
750 mpc8xxx_spi_cpu_irq(mspi, events); 642 fsl_spi_cpu_irq(mspi, events);
751 643
752 return ret; 644 return ret;
753} 645}
754 646
755static int mpc8xxx_spi_transfer(struct spi_device *spi, 647static void *fsl_spi_alloc_dummy_rx(void)
756 struct spi_message *m)
757{ 648{
758 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 649 mutex_lock(&fsl_dummy_rx_lock);
759 unsigned long flags;
760 650
761 m->actual_length = 0; 651 if (!fsl_dummy_rx)
762 m->status = -EINPROGRESS; 652 fsl_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL);
653 if (fsl_dummy_rx)
654 fsl_dummy_rx_refcnt++;
763 655
764 spin_lock_irqsave(&mpc8xxx_spi->lock, flags); 656 mutex_unlock(&fsl_dummy_rx_lock);
765 list_add_tail(&m->queue, &mpc8xxx_spi->queue);
766 queue_work(mpc8xxx_spi->workqueue, &mpc8xxx_spi->work);
767 spin_unlock_irqrestore(&mpc8xxx_spi->lock, flags);
768 657
769 return 0; 658 return fsl_dummy_rx;
770} 659}
771 660
772 661static void fsl_spi_free_dummy_rx(void)
773static void mpc8xxx_spi_cleanup(struct spi_device *spi)
774{ 662{
775 kfree(spi->controller_state); 663 mutex_lock(&fsl_dummy_rx_lock);
776}
777
778static void *mpc8xxx_spi_alloc_dummy_rx(void)
779{
780 mutex_lock(&mpc8xxx_dummy_rx_lock);
781
782 if (!mpc8xxx_dummy_rx)
783 mpc8xxx_dummy_rx = kmalloc(SPI_MRBLR, GFP_KERNEL);
784 if (mpc8xxx_dummy_rx)
785 mpc8xxx_dummy_rx_refcnt++;
786
787 mutex_unlock(&mpc8xxx_dummy_rx_lock);
788
789 return mpc8xxx_dummy_rx;
790}
791
792static void mpc8xxx_spi_free_dummy_rx(void)
793{
794 mutex_lock(&mpc8xxx_dummy_rx_lock);
795 664
796 switch (mpc8xxx_dummy_rx_refcnt) { 665 switch (fsl_dummy_rx_refcnt) {
797 case 0: 666 case 0:
798 WARN_ON(1); 667 WARN_ON(1);
799 break; 668 break;
800 case 1: 669 case 1:
801 kfree(mpc8xxx_dummy_rx); 670 kfree(fsl_dummy_rx);
802 mpc8xxx_dummy_rx = NULL; 671 fsl_dummy_rx = NULL;
803 /* fall through */ 672 /* fall through */
804 default: 673 default:
805 mpc8xxx_dummy_rx_refcnt--; 674 fsl_dummy_rx_refcnt--;
806 break; 675 break;
807 } 676 }
808 677
809 mutex_unlock(&mpc8xxx_dummy_rx_lock); 678 mutex_unlock(&fsl_dummy_rx_lock);
810} 679}
811 680
812static unsigned long mpc8xxx_spi_cpm_get_pram(struct mpc8xxx_spi *mspi) 681static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
813{ 682{
814 struct device *dev = mspi->dev; 683 struct device *dev = mspi->dev;
815 struct device_node *np = dev->of_node; 684 struct device_node *np = dev->of_node;
@@ -863,7 +732,7 @@ static unsigned long mpc8xxx_spi_cpm_get_pram(struct mpc8xxx_spi *mspi)
863 return pram_ofs; 732 return pram_ofs;
864} 733}
865 734
866static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi) 735static int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi)
867{ 736{
868 struct device *dev = mspi->dev; 737 struct device *dev = mspi->dev;
869 struct device_node *np = dev->of_node; 738 struct device_node *np = dev->of_node;
@@ -875,7 +744,7 @@ static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi)
875 if (!(mspi->flags & SPI_CPM_MODE)) 744 if (!(mspi->flags & SPI_CPM_MODE))
876 return 0; 745 return 0;
877 746
878 if (!mpc8xxx_spi_alloc_dummy_rx()) 747 if (!fsl_spi_alloc_dummy_rx())
879 return -ENOMEM; 748 return -ENOMEM;
880 749
881 if (mspi->flags & SPI_QE) { 750 if (mspi->flags & SPI_QE) {
@@ -896,7 +765,7 @@ static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi)
896 } 765 }
897 } 766 }
898 767
899 pram_ofs = mpc8xxx_spi_cpm_get_pram(mspi); 768 pram_ofs = fsl_spi_cpm_get_pram(mspi);
900 if (IS_ERR_VALUE(pram_ofs)) { 769 if (IS_ERR_VALUE(pram_ofs)) {
901 dev_err(dev, "can't allocate spi parameter ram\n"); 770 dev_err(dev, "can't allocate spi parameter ram\n");
902 goto err_pram; 771 goto err_pram;
@@ -916,7 +785,7 @@ static int mpc8xxx_spi_cpm_init(struct mpc8xxx_spi *mspi)
916 goto err_dummy_tx; 785 goto err_dummy_tx;
917 } 786 }
918 787
919 mspi->dma_dummy_rx = dma_map_single(dev, mpc8xxx_dummy_rx, SPI_MRBLR, 788 mspi->dma_dummy_rx = dma_map_single(dev, fsl_dummy_rx, SPI_MRBLR,
920 DMA_FROM_DEVICE); 789 DMA_FROM_DEVICE);
921 if (dma_mapping_error(dev, mspi->dma_dummy_rx)) { 790 if (dma_mapping_error(dev, mspi->dma_dummy_rx)) {
922 dev_err(dev, "unable to map dummy rx buffer\n"); 791 dev_err(dev, "unable to map dummy rx buffer\n");
@@ -954,11 +823,11 @@ err_dummy_tx:
954err_bds: 823err_bds:
955 cpm_muram_free(pram_ofs); 824 cpm_muram_free(pram_ofs);
956err_pram: 825err_pram:
957 mpc8xxx_spi_free_dummy_rx(); 826 fsl_spi_free_dummy_rx();
958 return -ENOMEM; 827 return -ENOMEM;
959} 828}
960 829
961static void mpc8xxx_spi_cpm_free(struct mpc8xxx_spi *mspi) 830static void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi)
962{ 831{
963 struct device *dev = mspi->dev; 832 struct device *dev = mspi->dev;
964 833
@@ -966,30 +835,22 @@ static void mpc8xxx_spi_cpm_free(struct mpc8xxx_spi *mspi)
966 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); 835 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
967 cpm_muram_free(cpm_muram_offset(mspi->tx_bd)); 836 cpm_muram_free(cpm_muram_offset(mspi->tx_bd));
968 cpm_muram_free(cpm_muram_offset(mspi->pram)); 837 cpm_muram_free(cpm_muram_offset(mspi->pram));
969 mpc8xxx_spi_free_dummy_rx(); 838 fsl_spi_free_dummy_rx();
970} 839}
971 840
972static const char *mpc8xxx_spi_strmode(unsigned int flags) 841static void fsl_spi_remove(struct mpc8xxx_spi *mspi)
973{ 842{
974 if (flags & SPI_QE_CPU_MODE) { 843 iounmap(mspi->reg_base);
975 return "QE CPU"; 844 fsl_spi_cpm_free(mspi);
976 } else if (flags & SPI_CPM_MODE) {
977 if (flags & SPI_QE)
978 return "QE";
979 else if (flags & SPI_CPM2)
980 return "CPM2";
981 else
982 return "CPM1";
983 }
984 return "CPU";
985} 845}
986 846
987static struct spi_master * __devinit 847static struct spi_master * __devinit fsl_spi_probe(struct device *dev,
988mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq) 848 struct resource *mem, unsigned int irq)
989{ 849{
990 struct fsl_spi_platform_data *pdata = dev->platform_data; 850 struct fsl_spi_platform_data *pdata = dev->platform_data;
991 struct spi_master *master; 851 struct spi_master *master;
992 struct mpc8xxx_spi *mpc8xxx_spi; 852 struct mpc8xxx_spi *mpc8xxx_spi;
853 struct fsl_spi_reg *reg_base;
993 u32 regval; 854 u32 regval;
994 int ret = 0; 855 int ret = 0;
995 856
@@ -1001,132 +862,77 @@ mpc8xxx_spi_probe(struct device *dev, struct resource *mem, unsigned int irq)
1001 862
1002 dev_set_drvdata(dev, master); 863 dev_set_drvdata(dev, master);
1003 864
1004 /* the spi->mode bits understood by this driver: */ 865 ret = mpc8xxx_spi_probe(dev, mem, irq);
1005 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH 866 if (ret)
1006 | SPI_LSB_FIRST | SPI_LOOP; 867 goto err_probe;
1007 868
1008 master->setup = mpc8xxx_spi_setup; 869 master->setup = fsl_spi_setup;
1009 master->transfer = mpc8xxx_spi_transfer;
1010 master->cleanup = mpc8xxx_spi_cleanup;
1011 master->dev.of_node = dev->of_node;
1012 870
1013 mpc8xxx_spi = spi_master_get_devdata(master); 871 mpc8xxx_spi = spi_master_get_devdata(master);
1014 mpc8xxx_spi->dev = dev; 872 mpc8xxx_spi->spi_do_one_msg = fsl_spi_do_one_msg;
1015 mpc8xxx_spi->get_rx = mpc8xxx_spi_rx_buf_u8; 873 mpc8xxx_spi->spi_remove = fsl_spi_remove;
1016 mpc8xxx_spi->get_tx = mpc8xxx_spi_tx_buf_u8;
1017 mpc8xxx_spi->flags = pdata->flags;
1018 mpc8xxx_spi->spibrg = pdata->sysclk;
1019 874
1020 ret = mpc8xxx_spi_cpm_init(mpc8xxx_spi); 875
876 ret = fsl_spi_cpm_init(mpc8xxx_spi);
1021 if (ret) 877 if (ret)
1022 goto err_cpm_init; 878 goto err_cpm_init;
1023 879
1024 mpc8xxx_spi->rx_shift = 0;
1025 mpc8xxx_spi->tx_shift = 0;
1026 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 880 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
1027 mpc8xxx_spi->rx_shift = 16; 881 mpc8xxx_spi->rx_shift = 16;
1028 mpc8xxx_spi->tx_shift = 24; 882 mpc8xxx_spi->tx_shift = 24;
1029 } 883 }
1030 884
1031 init_completion(&mpc8xxx_spi->done); 885 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
1032 886 if (mpc8xxx_spi->reg_base == NULL) {
1033 mpc8xxx_spi->base = ioremap(mem->start, resource_size(mem));
1034 if (mpc8xxx_spi->base == NULL) {
1035 ret = -ENOMEM; 887 ret = -ENOMEM;
1036 goto err_ioremap; 888 goto err_ioremap;
1037 } 889 }
1038 890
1039 mpc8xxx_spi->irq = irq;
1040
1041 /* Register for SPI Interrupt */ 891 /* Register for SPI Interrupt */
1042 ret = request_irq(mpc8xxx_spi->irq, mpc8xxx_spi_irq, 892 ret = request_irq(mpc8xxx_spi->irq, fsl_spi_irq,
1043 0, "mpc8xxx_spi", mpc8xxx_spi); 893 0, "fsl_spi", mpc8xxx_spi);
1044 894
1045 if (ret != 0) 895 if (ret != 0)
1046 goto unmap_io; 896 goto free_irq;
1047 897
1048 master->bus_num = pdata->bus_num; 898 reg_base = mpc8xxx_spi->reg_base;
1049 master->num_chipselect = pdata->max_chipselect;
1050 899
1051 /* SPI controller initializations */ 900 /* SPI controller initializations */
1052 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, 0); 901 mpc8xxx_spi_write_reg(&reg_base->mode, 0);
1053 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mask, 0); 902 mpc8xxx_spi_write_reg(&reg_base->mask, 0);
1054 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->command, 0); 903 mpc8xxx_spi_write_reg(&reg_base->command, 0);
1055 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->event, 0xffffffff); 904 mpc8xxx_spi_write_reg(&reg_base->event, 0xffffffff);
1056 905
1057 /* Enable SPI interface */ 906 /* Enable SPI interface */
1058 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE; 907 regval = pdata->initial_spmode | SPMODE_INIT_VAL | SPMODE_ENABLE;
1059 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) 908 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
1060 regval |= SPMODE_OP; 909 regval |= SPMODE_OP;
1061 910
1062 mpc8xxx_spi_write_reg(&mpc8xxx_spi->base->mode, regval); 911 mpc8xxx_spi_write_reg(&reg_base->mode, regval);
1063 spin_lock_init(&mpc8xxx_spi->lock);
1064 init_completion(&mpc8xxx_spi->done);
1065 INIT_WORK(&mpc8xxx_spi->work, mpc8xxx_spi_work);
1066 INIT_LIST_HEAD(&mpc8xxx_spi->queue);
1067
1068 mpc8xxx_spi->workqueue = create_singlethread_workqueue(
1069 dev_name(master->dev.parent));
1070 if (mpc8xxx_spi->workqueue == NULL) {
1071 ret = -EBUSY;
1072 goto free_irq;
1073 }
1074 912
1075 ret = spi_register_master(master); 913 ret = spi_register_master(master);
1076 if (ret < 0) 914 if (ret < 0)
1077 goto unreg_master; 915 goto unreg_master;
1078 916
1079 dev_info(dev, "at 0x%p (irq = %d), %s mode\n", mpc8xxx_spi->base, 917 dev_info(dev, "at 0x%p (irq = %d), %s mode\n", reg_base,
1080 mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags)); 918 mpc8xxx_spi->irq, mpc8xxx_spi_strmode(mpc8xxx_spi->flags));
1081 919
1082 return master; 920 return master;
1083 921
1084unreg_master: 922unreg_master:
1085 destroy_workqueue(mpc8xxx_spi->workqueue);
1086free_irq:
1087 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi); 923 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
1088unmap_io: 924free_irq:
1089 iounmap(mpc8xxx_spi->base); 925 iounmap(mpc8xxx_spi->reg_base);
1090err_ioremap: 926err_ioremap:
1091 mpc8xxx_spi_cpm_free(mpc8xxx_spi); 927 fsl_spi_cpm_free(mpc8xxx_spi);
1092err_cpm_init: 928err_cpm_init:
929err_probe:
1093 spi_master_put(master); 930 spi_master_put(master);
1094err: 931err:
1095 return ERR_PTR(ret); 932 return ERR_PTR(ret);
1096} 933}
1097 934
1098static int __devexit mpc8xxx_spi_remove(struct device *dev) 935static void fsl_spi_cs_control(struct spi_device *spi, bool on)
1099{
1100 struct mpc8xxx_spi *mpc8xxx_spi;
1101 struct spi_master *master;
1102
1103 master = dev_get_drvdata(dev);
1104 mpc8xxx_spi = spi_master_get_devdata(master);
1105
1106 flush_workqueue(mpc8xxx_spi->workqueue);
1107 destroy_workqueue(mpc8xxx_spi->workqueue);
1108 spi_unregister_master(master);
1109
1110 free_irq(mpc8xxx_spi->irq, mpc8xxx_spi);
1111 iounmap(mpc8xxx_spi->base);
1112 mpc8xxx_spi_cpm_free(mpc8xxx_spi);
1113
1114 return 0;
1115}
1116
1117struct mpc8xxx_spi_probe_info {
1118 struct fsl_spi_platform_data pdata;
1119 int *gpios;
1120 bool *alow_flags;
1121};
1122
1123static struct mpc8xxx_spi_probe_info *
1124to_of_pinfo(struct fsl_spi_platform_data *pdata)
1125{
1126 return container_of(pdata, struct mpc8xxx_spi_probe_info, pdata);
1127}
1128
1129static void mpc8xxx_spi_cs_control(struct spi_device *spi, bool on)
1130{ 936{
1131 struct device *dev = spi->dev.parent; 937 struct device *dev = spi->dev.parent;
1132 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data); 938 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(dev->platform_data);
@@ -1137,7 +943,7 @@ static void mpc8xxx_spi_cs_control(struct spi_device *spi, bool on)
1137 gpio_set_value(gpio, on ^ alow); 943 gpio_set_value(gpio, on ^ alow);
1138} 944}
1139 945
1140static int of_mpc8xxx_spi_get_chipselects(struct device *dev) 946static int of_fsl_spi_get_chipselects(struct device *dev)
1141{ 947{
1142 struct device_node *np = dev->of_node; 948 struct device_node *np = dev->of_node;
1143 struct fsl_spi_platform_data *pdata = dev->platform_data; 949 struct fsl_spi_platform_data *pdata = dev->platform_data;
@@ -1198,7 +1004,7 @@ static int of_mpc8xxx_spi_get_chipselects(struct device *dev)
1198 } 1004 }
1199 1005
1200 pdata->max_chipselect = ngpios; 1006 pdata->max_chipselect = ngpios;
1201 pdata->cs_control = mpc8xxx_spi_cs_control; 1007 pdata->cs_control = fsl_spi_cs_control;
1202 1008
1203 return 0; 1009 return 0;
1204 1010
@@ -1217,7 +1023,7 @@ err_alloc_flags:
1217 return ret; 1023 return ret;
1218} 1024}
1219 1025
1220static int of_mpc8xxx_spi_free_chipselects(struct device *dev) 1026static int of_fsl_spi_free_chipselects(struct device *dev)
1221{ 1027{
1222 struct fsl_spi_platform_data *pdata = dev->platform_data; 1028 struct fsl_spi_platform_data *pdata = dev->platform_data;
1223 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata); 1029 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata);
@@ -1236,50 +1042,21 @@ static int of_mpc8xxx_spi_free_chipselects(struct device *dev)
1236 return 0; 1042 return 0;
1237} 1043}
1238 1044
1239static int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev, 1045static int __devinit of_fsl_spi_probe(struct platform_device *ofdev,
1240 const struct of_device_id *ofid) 1046 const struct of_device_id *ofid)
1241{ 1047{
1242 struct device *dev = &ofdev->dev; 1048 struct device *dev = &ofdev->dev;
1243 struct device_node *np = ofdev->dev.of_node; 1049 struct device_node *np = ofdev->dev.of_node;
1244 struct mpc8xxx_spi_probe_info *pinfo;
1245 struct fsl_spi_platform_data *pdata;
1246 struct spi_master *master; 1050 struct spi_master *master;
1247 struct resource mem; 1051 struct resource mem;
1248 struct resource irq; 1052 struct resource irq;
1249 const void *prop;
1250 int ret = -ENOMEM; 1053 int ret = -ENOMEM;
1251 1054
1252 pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL); 1055 ret = of_mpc8xxx_spi_probe(ofdev, ofid);
1253 if (!pinfo) 1056 if (ret)
1254 return -ENOMEM; 1057 return ret;
1255
1256 pdata = &pinfo->pdata;
1257 dev->platform_data = pdata;
1258
1259 /* Allocate bus num dynamically. */
1260 pdata->bus_num = -1;
1261
1262 /* SPI controller is either clocked from QE or SoC clock. */
1263 pdata->sysclk = get_brgfreq();
1264 if (pdata->sysclk == -1) {
1265 pdata->sysclk = fsl_get_sys_freq();
1266 if (pdata->sysclk == -1) {
1267 ret = -ENODEV;
1268 goto err_clk;
1269 }
1270 }
1271 1058
1272 prop = of_get_property(np, "mode", NULL); 1059 ret = of_fsl_spi_get_chipselects(dev);
1273 if (prop && !strcmp(prop, "cpu-qe"))
1274 pdata->flags = SPI_QE_CPU_MODE;
1275 else if (prop && !strcmp(prop, "qe"))
1276 pdata->flags = SPI_CPM_MODE | SPI_QE;
1277 else if (of_device_is_compatible(np, "fsl,cpm2-spi"))
1278 pdata->flags = SPI_CPM_MODE | SPI_CPM2;
1279 else if (of_device_is_compatible(np, "fsl,cpm1-spi"))
1280 pdata->flags = SPI_CPM_MODE | SPI_CPM1;
1281
1282 ret = of_mpc8xxx_spi_get_chipselects(dev);
1283 if (ret) 1060 if (ret)
1284 goto err; 1061 goto err;
1285 1062
@@ -1293,7 +1070,7 @@ static int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev,
1293 goto err; 1070 goto err;
1294 } 1071 }
1295 1072
1296 master = mpc8xxx_spi_probe(dev, &mem, irq.start); 1073 master = fsl_spi_probe(dev, &mem, irq.start);
1297 if (IS_ERR(master)) { 1074 if (IS_ERR(master)) {
1298 ret = PTR_ERR(master); 1075 ret = PTR_ERR(master);
1299 goto err; 1076 goto err;
@@ -1302,42 +1079,40 @@ static int __devinit of_mpc8xxx_spi_probe(struct platform_device *ofdev,
1302 return 0; 1079 return 0;
1303 1080
1304err: 1081err:
1305 of_mpc8xxx_spi_free_chipselects(dev); 1082 of_fsl_spi_free_chipselects(dev);
1306err_clk:
1307 kfree(pinfo);
1308 return ret; 1083 return ret;
1309} 1084}
1310 1085
1311static int __devexit of_mpc8xxx_spi_remove(struct platform_device *ofdev) 1086static int __devexit of_fsl_spi_remove(struct platform_device *ofdev)
1312{ 1087{
1313 int ret; 1088 int ret;
1314 1089
1315 ret = mpc8xxx_spi_remove(&ofdev->dev); 1090 ret = mpc8xxx_spi_remove(&ofdev->dev);
1316 if (ret) 1091 if (ret)
1317 return ret; 1092 return ret;
1318 of_mpc8xxx_spi_free_chipselects(&ofdev->dev); 1093 of_fsl_spi_free_chipselects(&ofdev->dev);
1319 return 0; 1094 return 0;
1320} 1095}
1321 1096
1322static const struct of_device_id of_mpc8xxx_spi_match[] = { 1097static const struct of_device_id of_fsl_spi_match[] = {
1323 { .compatible = "fsl,spi" }, 1098 { .compatible = "fsl,spi" },
1324 {}, 1099 {}
1325}; 1100};
1326MODULE_DEVICE_TABLE(of, of_mpc8xxx_spi_match); 1101MODULE_DEVICE_TABLE(of, of_fsl_spi_match);
1327 1102
1328static struct of_platform_driver of_mpc8xxx_spi_driver = { 1103static struct of_platform_driver of_fsl_spi_driver = {
1329 .driver = { 1104 .driver = {
1330 .name = "mpc8xxx_spi", 1105 .name = "fsl_spi",
1331 .owner = THIS_MODULE, 1106 .owner = THIS_MODULE,
1332 .of_match_table = of_mpc8xxx_spi_match, 1107 .of_match_table = of_fsl_spi_match,
1333 }, 1108 },
1334 .probe = of_mpc8xxx_spi_probe, 1109 .probe = of_fsl_spi_probe,
1335 .remove = __devexit_p(of_mpc8xxx_spi_remove), 1110 .remove = __devexit_p(of_fsl_spi_remove),
1336}; 1111};
1337 1112
1338#ifdef CONFIG_MPC832x_RDB 1113#ifdef CONFIG_MPC832x_RDB
1339/* 1114/*
1340 * XXX XXX XXX 1115 * XXX XXX XXX
1341 * This is "legacy" platform driver, was used by the MPC8323E-RDB boards 1116 * This is "legacy" platform driver, was used by the MPC8323E-RDB boards
1342 * only. The driver should go away soon, since newer MPC8323E-RDB's device 1117 * only. The driver should go away soon, since newer MPC8323E-RDB's device
1343 * tree can work with OpenFirmware driver. But for now we support old trees 1118 * tree can work with OpenFirmware driver. But for now we support old trees
@@ -1360,7 +1135,7 @@ static int __devinit plat_mpc8xxx_spi_probe(struct platform_device *pdev)
1360 if (irq <= 0) 1135 if (irq <= 0)
1361 return -EINVAL; 1136 return -EINVAL;
1362 1137
1363 master = mpc8xxx_spi_probe(&pdev->dev, mem, irq); 1138 master = fsl_spi_probe(&pdev->dev, mem, irq);
1364 if (IS_ERR(master)) 1139 if (IS_ERR(master))
1365 return PTR_ERR(master); 1140 return PTR_ERR(master);
1366 return 0; 1141 return 0;
@@ -1399,21 +1174,20 @@ static void __init legacy_driver_register(void) {}
1399static void __exit legacy_driver_unregister(void) {} 1174static void __exit legacy_driver_unregister(void) {}
1400#endif /* CONFIG_MPC832x_RDB */ 1175#endif /* CONFIG_MPC832x_RDB */
1401 1176
1402static int __init mpc8xxx_spi_init(void) 1177static int __init fsl_spi_init(void)
1403{ 1178{
1404 legacy_driver_register(); 1179 legacy_driver_register();
1405 return of_register_platform_driver(&of_mpc8xxx_spi_driver); 1180 return of_register_platform_driver(&of_fsl_spi_driver);
1406} 1181}
1182module_init(fsl_spi_init);
1407 1183
1408static void __exit mpc8xxx_spi_exit(void) 1184static void __exit fsl_spi_exit(void)
1409{ 1185{
1410 of_unregister_platform_driver(&of_mpc8xxx_spi_driver); 1186 of_unregister_platform_driver(&of_fsl_spi_driver);
1411 legacy_driver_unregister(); 1187 legacy_driver_unregister();
1412} 1188}
1413 1189module_exit(fsl_spi_exit);
1414module_init(mpc8xxx_spi_init);
1415module_exit(mpc8xxx_spi_exit);
1416 1190
1417MODULE_AUTHOR("Kumar Gala"); 1191MODULE_AUTHOR("Kumar Gala");
1418MODULE_DESCRIPTION("Simple MPC8xxx SPI Driver"); 1192MODULE_DESCRIPTION("Simple Freescale SPI Driver");
1419MODULE_LICENSE("GPL"); 1193MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index e24a63498acb..63e51b011d50 100644
--- a/drivers/spi/spi_gpio.c
+++ b/drivers/spi/spi_gpio.c
@@ -350,7 +350,7 @@ static int __init spi_gpio_probe(struct platform_device *pdev)
350 spi_gpio->bitbang.master = spi_master_get(master); 350 spi_gpio->bitbang.master = spi_master_get(master);
351 spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 351 spi_gpio->bitbang.chipselect = spi_gpio_chipselect;
352 352
353 if ((master_flags & (SPI_MASTER_NO_RX | SPI_MASTER_NO_RX)) == 0) { 353 if ((master_flags & (SPI_MASTER_NO_TX | SPI_MASTER_NO_RX)) == 0) {
354 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 354 spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0;
355 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; 355 spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1;
356 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; 356 spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2;
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 7972e9077473..55a38e2c6c13 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -56,7 +56,28 @@ struct spi_imx_config {
56 unsigned int speed_hz; 56 unsigned int speed_hz;
57 unsigned int bpw; 57 unsigned int bpw;
58 unsigned int mode; 58 unsigned int mode;
59 int cs; 59 u8 cs;
60};
61
62enum spi_imx_devtype {
63 SPI_IMX_VER_IMX1,
64 SPI_IMX_VER_0_0,
65 SPI_IMX_VER_0_4,
66 SPI_IMX_VER_0_5,
67 SPI_IMX_VER_0_7,
68 SPI_IMX_VER_2_3,
69 SPI_IMX_VER_AUTODETECT,
70};
71
72struct spi_imx_data;
73
74struct spi_imx_devtype_data {
75 void (*intctrl)(struct spi_imx_data *, int);
76 int (*config)(struct spi_imx_data *, struct spi_imx_config *);
77 void (*trigger)(struct spi_imx_data *);
78 int (*rx_available)(struct spi_imx_data *);
79 void (*reset)(struct spi_imx_data *);
80 unsigned int fifosize;
60}; 81};
61 82
62struct spi_imx_data { 83struct spi_imx_data {
@@ -76,11 +97,7 @@ struct spi_imx_data {
76 const void *tx_buf; 97 const void *tx_buf;
77 unsigned int txfifo; /* number of words pushed in tx FIFO */ 98 unsigned int txfifo; /* number of words pushed in tx FIFO */
78 99
79 /* SoC specific functions */ 100 struct spi_imx_devtype_data devtype_data;
80 void (*intctrl)(struct spi_imx_data *, int);
81 int (*config)(struct spi_imx_data *, struct spi_imx_config *);
82 void (*trigger)(struct spi_imx_data *);
83 int (*rx_available)(struct spi_imx_data *);
84}; 101};
85 102
86#define MXC_SPI_BUF_RX(type) \ 103#define MXC_SPI_BUF_RX(type) \
@@ -140,7 +157,7 @@ static unsigned int spi_imx_clkdiv_1(unsigned int fin,
140 return max; 157 return max;
141} 158}
142 159
143/* MX1, MX31, MX35 */ 160/* MX1, MX31, MX35, MX51 CSPI */
144static unsigned int spi_imx_clkdiv_2(unsigned int fin, 161static unsigned int spi_imx_clkdiv_2(unsigned int fin,
145 unsigned int fspi) 162 unsigned int fspi)
146{ 163{
@@ -155,6 +172,128 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
155 return 7; 172 return 7;
156} 173}
157 174
175#define SPI_IMX2_3_CTRL 0x08
176#define SPI_IMX2_3_CTRL_ENABLE (1 << 0)
177#define SPI_IMX2_3_CTRL_XCH (1 << 2)
178#define SPI_IMX2_3_CTRL_MODE(cs) (1 << ((cs) + 4))
179#define SPI_IMX2_3_CTRL_POSTDIV_OFFSET 8
180#define SPI_IMX2_3_CTRL_PREDIV_OFFSET 12
181#define SPI_IMX2_3_CTRL_CS(cs) ((cs) << 18)
182#define SPI_IMX2_3_CTRL_BL_OFFSET 20
183
184#define SPI_IMX2_3_CONFIG 0x0c
185#define SPI_IMX2_3_CONFIG_SCLKPHA(cs) (1 << ((cs) + 0))
186#define SPI_IMX2_3_CONFIG_SCLKPOL(cs) (1 << ((cs) + 4))
187#define SPI_IMX2_3_CONFIG_SBBCTRL(cs) (1 << ((cs) + 8))
188#define SPI_IMX2_3_CONFIG_SSBPOL(cs) (1 << ((cs) + 12))
189
190#define SPI_IMX2_3_INT 0x10
191#define SPI_IMX2_3_INT_TEEN (1 << 0)
192#define SPI_IMX2_3_INT_RREN (1 << 3)
193
194#define SPI_IMX2_3_STAT 0x18
195#define SPI_IMX2_3_STAT_RR (1 << 3)
196
197/* MX51 eCSPI */
198static unsigned int spi_imx2_3_clkdiv(unsigned int fin, unsigned int fspi)
199{
200 /*
201 * there are two 4-bit dividers, the pre-divider divides by
202 * $pre, the post-divider by 2^$post
203 */
204 unsigned int pre, post;
205
206 if (unlikely(fspi > fin))
207 return 0;
208
209 post = fls(fin) - fls(fspi);
210 if (fin > fspi << post)
211 post++;
212
213 /* now we have: (fin <= fspi << post) with post being minimal */
214
215 post = max(4U, post) - 4;
216 if (unlikely(post > 0xf)) {
217 pr_err("%s: cannot set clock freq: %u (base freq: %u)\n",
218 __func__, fspi, fin);
219 return 0xff;
220 }
221
222 pre = DIV_ROUND_UP(fin, fspi << post) - 1;
223
224 pr_debug("%s: fin: %u, fspi: %u, post: %u, pre: %u\n",
225 __func__, fin, fspi, post, pre);
226 return (pre << SPI_IMX2_3_CTRL_PREDIV_OFFSET) |
227 (post << SPI_IMX2_3_CTRL_POSTDIV_OFFSET);
228}
229
230static void __maybe_unused spi_imx2_3_intctrl(struct spi_imx_data *spi_imx, int enable)
231{
232 unsigned val = 0;
233
234 if (enable & MXC_INT_TE)
235 val |= SPI_IMX2_3_INT_TEEN;
236
237 if (enable & MXC_INT_RR)
238 val |= SPI_IMX2_3_INT_RREN;
239
240 writel(val, spi_imx->base + SPI_IMX2_3_INT);
241}
242
243static void __maybe_unused spi_imx2_3_trigger(struct spi_imx_data *spi_imx)
244{
245 u32 reg;
246
247 reg = readl(spi_imx->base + SPI_IMX2_3_CTRL);
248 reg |= SPI_IMX2_3_CTRL_XCH;
249 writel(reg, spi_imx->base + SPI_IMX2_3_CTRL);
250}
251
252static int __maybe_unused spi_imx2_3_config(struct spi_imx_data *spi_imx,
253 struct spi_imx_config *config)
254{
255 u32 ctrl = SPI_IMX2_3_CTRL_ENABLE, cfg = 0;
256
257 /* set master mode */
258 ctrl |= SPI_IMX2_3_CTRL_MODE(config->cs);
259
260 /* set clock speed */
261 ctrl |= spi_imx2_3_clkdiv(spi_imx->spi_clk, config->speed_hz);
262
263 /* set chip select to use */
264 ctrl |= SPI_IMX2_3_CTRL_CS(config->cs);
265
266 ctrl |= (config->bpw - 1) << SPI_IMX2_3_CTRL_BL_OFFSET;
267
268 cfg |= SPI_IMX2_3_CONFIG_SBBCTRL(config->cs);
269
270 if (config->mode & SPI_CPHA)
271 cfg |= SPI_IMX2_3_CONFIG_SCLKPHA(config->cs);
272
273 if (config->mode & SPI_CPOL)
274 cfg |= SPI_IMX2_3_CONFIG_SCLKPOL(config->cs);
275
276 if (config->mode & SPI_CS_HIGH)
277 cfg |= SPI_IMX2_3_CONFIG_SSBPOL(config->cs);
278
279 writel(ctrl, spi_imx->base + SPI_IMX2_3_CTRL);
280 writel(cfg, spi_imx->base + SPI_IMX2_3_CONFIG);
281
282 return 0;
283}
284
285static int __maybe_unused spi_imx2_3_rx_available(struct spi_imx_data *spi_imx)
286{
287 return readl(spi_imx->base + SPI_IMX2_3_STAT) & SPI_IMX2_3_STAT_RR;
288}
289
290static void __maybe_unused spi_imx2_3_reset(struct spi_imx_data *spi_imx)
291{
292 /* drain receive buffer */
293 while (spi_imx2_3_rx_available(spi_imx))
294 readl(spi_imx->base + MXC_CSPIRXDATA);
295}
296
158#define MX31_INTREG_TEEN (1 << 0) 297#define MX31_INTREG_TEEN (1 << 0)
159#define MX31_INTREG_RREN (1 << 3) 298#define MX31_INTREG_RREN (1 << 3)
160 299
@@ -178,7 +317,7 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin,
178 * the i.MX35 has a slightly different register layout for bits 317 * the i.MX35 has a slightly different register layout for bits
179 * we do not use here. 318 * we do not use here.
180 */ 319 */
181static void mx31_intctrl(struct spi_imx_data *spi_imx, int enable) 320static void __maybe_unused mx31_intctrl(struct spi_imx_data *spi_imx, int enable)
182{ 321{
183 unsigned int val = 0; 322 unsigned int val = 0;
184 323
@@ -190,7 +329,7 @@ static void mx31_intctrl(struct spi_imx_data *spi_imx, int enable)
190 writel(val, spi_imx->base + MXC_CSPIINT); 329 writel(val, spi_imx->base + MXC_CSPIINT);
191} 330}
192 331
193static void mx31_trigger(struct spi_imx_data *spi_imx) 332static void __maybe_unused mx31_trigger(struct spi_imx_data *spi_imx)
194{ 333{
195 unsigned int reg; 334 unsigned int reg;
196 335
@@ -199,20 +338,16 @@ static void mx31_trigger(struct spi_imx_data *spi_imx)
199 writel(reg, spi_imx->base + MXC_CSPICTRL); 338 writel(reg, spi_imx->base + MXC_CSPICTRL);
200} 339}
201 340
202static int mx31_config(struct spi_imx_data *spi_imx, 341static int __maybe_unused spi_imx0_4_config(struct spi_imx_data *spi_imx,
203 struct spi_imx_config *config) 342 struct spi_imx_config *config)
204{ 343{
205 unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER; 344 unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER;
345 int cs = spi_imx->chipselect[config->cs];
206 346
207 reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) << 347 reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
208 MX31_CSPICTRL_DR_SHIFT; 348 MX31_CSPICTRL_DR_SHIFT;
209 349
210 if (cpu_is_mx31()) 350 reg |= (config->bpw - 1) << MX31_CSPICTRL_BC_SHIFT;
211 reg |= (config->bpw - 1) << MX31_CSPICTRL_BC_SHIFT;
212 else if (cpu_is_mx25() || cpu_is_mx35()) {
213 reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
214 reg |= MX31_CSPICTRL_SSCTL;
215 }
216 351
217 if (config->mode & SPI_CPHA) 352 if (config->mode & SPI_CPHA)
218 reg |= MX31_CSPICTRL_PHA; 353 reg |= MX31_CSPICTRL_PHA;
@@ -220,23 +355,52 @@ static int mx31_config(struct spi_imx_data *spi_imx,
220 reg |= MX31_CSPICTRL_POL; 355 reg |= MX31_CSPICTRL_POL;
221 if (config->mode & SPI_CS_HIGH) 356 if (config->mode & SPI_CS_HIGH)
222 reg |= MX31_CSPICTRL_SSPOL; 357 reg |= MX31_CSPICTRL_SSPOL;
223 if (config->cs < 0) { 358 if (cs < 0)
224 if (cpu_is_mx31()) 359 reg |= (cs + 32) << MX31_CSPICTRL_CS_SHIFT;
225 reg |= (config->cs + 32) << MX31_CSPICTRL_CS_SHIFT; 360
226 else if (cpu_is_mx25() || cpu_is_mx35()) 361 writel(reg, spi_imx->base + MXC_CSPICTRL);
227 reg |= (config->cs + 32) << MX35_CSPICTRL_CS_SHIFT; 362
228 } 363 return 0;
364}
365
366static int __maybe_unused spi_imx0_7_config(struct spi_imx_data *spi_imx,
367 struct spi_imx_config *config)
368{
369 unsigned int reg = MX31_CSPICTRL_ENABLE | MX31_CSPICTRL_MASTER;
370 int cs = spi_imx->chipselect[config->cs];
371
372 reg |= spi_imx_clkdiv_2(spi_imx->spi_clk, config->speed_hz) <<
373 MX31_CSPICTRL_DR_SHIFT;
374
375 reg |= (config->bpw - 1) << MX35_CSPICTRL_BL_SHIFT;
376 reg |= MX31_CSPICTRL_SSCTL;
377
378 if (config->mode & SPI_CPHA)
379 reg |= MX31_CSPICTRL_PHA;
380 if (config->mode & SPI_CPOL)
381 reg |= MX31_CSPICTRL_POL;
382 if (config->mode & SPI_CS_HIGH)
383 reg |= MX31_CSPICTRL_SSPOL;
384 if (cs < 0)
385 reg |= (cs + 32) << MX35_CSPICTRL_CS_SHIFT;
229 386
230 writel(reg, spi_imx->base + MXC_CSPICTRL); 387 writel(reg, spi_imx->base + MXC_CSPICTRL);
231 388
232 return 0; 389 return 0;
233} 390}
234 391
235static int mx31_rx_available(struct spi_imx_data *spi_imx) 392static int __maybe_unused mx31_rx_available(struct spi_imx_data *spi_imx)
236{ 393{
237 return readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR; 394 return readl(spi_imx->base + MX31_CSPISTATUS) & MX31_STATUS_RR;
238} 395}
239 396
397static void __maybe_unused spi_imx0_4_reset(struct spi_imx_data *spi_imx)
398{
399 /* drain receive buffer */
400 while (readl(spi_imx->base + MX3_CSPISTAT) & MX3_CSPISTAT_RR)
401 readl(spi_imx->base + MXC_CSPIRXDATA);
402}
403
240#define MX27_INTREG_RR (1 << 4) 404#define MX27_INTREG_RR (1 << 4)
241#define MX27_INTREG_TEEN (1 << 9) 405#define MX27_INTREG_TEEN (1 << 9)
242#define MX27_INTREG_RREN (1 << 13) 406#define MX27_INTREG_RREN (1 << 13)
@@ -250,7 +414,7 @@ static int mx31_rx_available(struct spi_imx_data *spi_imx)
250#define MX27_CSPICTRL_DR_SHIFT 14 414#define MX27_CSPICTRL_DR_SHIFT 14
251#define MX27_CSPICTRL_CS_SHIFT 19 415#define MX27_CSPICTRL_CS_SHIFT 19
252 416
253static void mx27_intctrl(struct spi_imx_data *spi_imx, int enable) 417static void __maybe_unused mx27_intctrl(struct spi_imx_data *spi_imx, int enable)
254{ 418{
255 unsigned int val = 0; 419 unsigned int val = 0;
256 420
@@ -262,7 +426,7 @@ static void mx27_intctrl(struct spi_imx_data *spi_imx, int enable)
262 writel(val, spi_imx->base + MXC_CSPIINT); 426 writel(val, spi_imx->base + MXC_CSPIINT);
263} 427}
264 428
265static void mx27_trigger(struct spi_imx_data *spi_imx) 429static void __maybe_unused mx27_trigger(struct spi_imx_data *spi_imx)
266{ 430{
267 unsigned int reg; 431 unsigned int reg;
268 432
@@ -271,10 +435,11 @@ static void mx27_trigger(struct spi_imx_data *spi_imx)
271 writel(reg, spi_imx->base + MXC_CSPICTRL); 435 writel(reg, spi_imx->base + MXC_CSPICTRL);
272} 436}
273 437
274static int mx27_config(struct spi_imx_data *spi_imx, 438static int __maybe_unused mx27_config(struct spi_imx_data *spi_imx,
275 struct spi_imx_config *config) 439 struct spi_imx_config *config)
276{ 440{
277 unsigned int reg = MX27_CSPICTRL_ENABLE | MX27_CSPICTRL_MASTER; 441 unsigned int reg = MX27_CSPICTRL_ENABLE | MX27_CSPICTRL_MASTER;
442 int cs = spi_imx->chipselect[config->cs];
278 443
279 reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) << 444 reg |= spi_imx_clkdiv_1(spi_imx->spi_clk, config->speed_hz) <<
280 MX27_CSPICTRL_DR_SHIFT; 445 MX27_CSPICTRL_DR_SHIFT;
@@ -286,19 +451,24 @@ static int mx27_config(struct spi_imx_data *spi_imx,
286 reg |= MX27_CSPICTRL_POL; 451 reg |= MX27_CSPICTRL_POL;
287 if (config->mode & SPI_CS_HIGH) 452 if (config->mode & SPI_CS_HIGH)
288 reg |= MX27_CSPICTRL_SSPOL; 453 reg |= MX27_CSPICTRL_SSPOL;
289 if (config->cs < 0) 454 if (cs < 0)
290 reg |= (config->cs + 32) << MX27_CSPICTRL_CS_SHIFT; 455 reg |= (cs + 32) << MX27_CSPICTRL_CS_SHIFT;
291 456
292 writel(reg, spi_imx->base + MXC_CSPICTRL); 457 writel(reg, spi_imx->base + MXC_CSPICTRL);
293 458
294 return 0; 459 return 0;
295} 460}
296 461
297static int mx27_rx_available(struct spi_imx_data *spi_imx) 462static int __maybe_unused mx27_rx_available(struct spi_imx_data *spi_imx)
298{ 463{
299 return readl(spi_imx->base + MXC_CSPIINT) & MX27_INTREG_RR; 464 return readl(spi_imx->base + MXC_CSPIINT) & MX27_INTREG_RR;
300} 465}
301 466
467static void __maybe_unused spi_imx0_0_reset(struct spi_imx_data *spi_imx)
468{
469 writel(1, spi_imx->base + MXC_RESET);
470}
471
302#define MX1_INTREG_RR (1 << 3) 472#define MX1_INTREG_RR (1 << 3)
303#define MX1_INTREG_TEEN (1 << 8) 473#define MX1_INTREG_TEEN (1 << 8)
304#define MX1_INTREG_RREN (1 << 11) 474#define MX1_INTREG_RREN (1 << 11)
@@ -310,7 +480,7 @@ static int mx27_rx_available(struct spi_imx_data *spi_imx)
310#define MX1_CSPICTRL_MASTER (1 << 10) 480#define MX1_CSPICTRL_MASTER (1 << 10)
311#define MX1_CSPICTRL_DR_SHIFT 13 481#define MX1_CSPICTRL_DR_SHIFT 13
312 482
313static void mx1_intctrl(struct spi_imx_data *spi_imx, int enable) 483static void __maybe_unused mx1_intctrl(struct spi_imx_data *spi_imx, int enable)
314{ 484{
315 unsigned int val = 0; 485 unsigned int val = 0;
316 486
@@ -322,7 +492,7 @@ static void mx1_intctrl(struct spi_imx_data *spi_imx, int enable)
322 writel(val, spi_imx->base + MXC_CSPIINT); 492 writel(val, spi_imx->base + MXC_CSPIINT);
323} 493}
324 494
325static void mx1_trigger(struct spi_imx_data *spi_imx) 495static void __maybe_unused mx1_trigger(struct spi_imx_data *spi_imx)
326{ 496{
327 unsigned int reg; 497 unsigned int reg;
328 498
@@ -331,7 +501,7 @@ static void mx1_trigger(struct spi_imx_data *spi_imx)
331 writel(reg, spi_imx->base + MXC_CSPICTRL); 501 writel(reg, spi_imx->base + MXC_CSPICTRL);
332} 502}
333 503
334static int mx1_config(struct spi_imx_data *spi_imx, 504static int __maybe_unused mx1_config(struct spi_imx_data *spi_imx,
335 struct spi_imx_config *config) 505 struct spi_imx_config *config)
336{ 506{
337 unsigned int reg = MX1_CSPICTRL_ENABLE | MX1_CSPICTRL_MASTER; 507 unsigned int reg = MX1_CSPICTRL_ENABLE | MX1_CSPICTRL_MASTER;
@@ -350,11 +520,73 @@ static int mx1_config(struct spi_imx_data *spi_imx,
350 return 0; 520 return 0;
351} 521}
352 522
353static int mx1_rx_available(struct spi_imx_data *spi_imx) 523static int __maybe_unused mx1_rx_available(struct spi_imx_data *spi_imx)
354{ 524{
355 return readl(spi_imx->base + MXC_CSPIINT) & MX1_INTREG_RR; 525 return readl(spi_imx->base + MXC_CSPIINT) & MX1_INTREG_RR;
356} 526}
357 527
528static void __maybe_unused mx1_reset(struct spi_imx_data *spi_imx)
529{
530 writel(1, spi_imx->base + MXC_RESET);
531}
532
533/*
534 * These version numbers are taken from the Freescale driver. Unfortunately it
535 * doesn't support i.MX1, so this entry doesn't match the scheme. :-(
536 */
537static struct spi_imx_devtype_data spi_imx_devtype_data[] __devinitdata = {
538#ifdef CONFIG_SPI_IMX_VER_IMX1
539 [SPI_IMX_VER_IMX1] = {
540 .intctrl = mx1_intctrl,
541 .config = mx1_config,
542 .trigger = mx1_trigger,
543 .rx_available = mx1_rx_available,
544 .reset = mx1_reset,
545 .fifosize = 8,
546 },
547#endif
548#ifdef CONFIG_SPI_IMX_VER_0_0
549 [SPI_IMX_VER_0_0] = {
550 .intctrl = mx27_intctrl,
551 .config = mx27_config,
552 .trigger = mx27_trigger,
553 .rx_available = mx27_rx_available,
554 .reset = spi_imx0_0_reset,
555 .fifosize = 8,
556 },
557#endif
558#ifdef CONFIG_SPI_IMX_VER_0_4
559 [SPI_IMX_VER_0_4] = {
560 .intctrl = mx31_intctrl,
561 .config = spi_imx0_4_config,
562 .trigger = mx31_trigger,
563 .rx_available = mx31_rx_available,
564 .reset = spi_imx0_4_reset,
565 .fifosize = 8,
566 },
567#endif
568#ifdef CONFIG_SPI_IMX_VER_0_7
569 [SPI_IMX_VER_0_7] = {
570 .intctrl = mx31_intctrl,
571 .config = spi_imx0_7_config,
572 .trigger = mx31_trigger,
573 .rx_available = mx31_rx_available,
574 .reset = spi_imx0_4_reset,
575 .fifosize = 8,
576 },
577#endif
578#ifdef CONFIG_SPI_IMX_VER_2_3
579 [SPI_IMX_VER_2_3] = {
580 .intctrl = spi_imx2_3_intctrl,
581 .config = spi_imx2_3_config,
582 .trigger = spi_imx2_3_trigger,
583 .rx_available = spi_imx2_3_rx_available,
584 .reset = spi_imx2_3_reset,
585 .fifosize = 64,
586 },
587#endif
588};
589
358static void spi_imx_chipselect(struct spi_device *spi, int is_active) 590static void spi_imx_chipselect(struct spi_device *spi, int is_active)
359{ 591{
360 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master); 592 struct spi_imx_data *spi_imx = spi_master_get_devdata(spi->master);
@@ -370,21 +602,21 @@ static void spi_imx_chipselect(struct spi_device *spi, int is_active)
370 602
371static void spi_imx_push(struct spi_imx_data *spi_imx) 603static void spi_imx_push(struct spi_imx_data *spi_imx)
372{ 604{
373 while (spi_imx->txfifo < 8) { 605 while (spi_imx->txfifo < spi_imx->devtype_data.fifosize) {
374 if (!spi_imx->count) 606 if (!spi_imx->count)
375 break; 607 break;
376 spi_imx->tx(spi_imx); 608 spi_imx->tx(spi_imx);
377 spi_imx->txfifo++; 609 spi_imx->txfifo++;
378 } 610 }
379 611
380 spi_imx->trigger(spi_imx); 612 spi_imx->devtype_data.trigger(spi_imx);
381} 613}
382 614
383static irqreturn_t spi_imx_isr(int irq, void *dev_id) 615static irqreturn_t spi_imx_isr(int irq, void *dev_id)
384{ 616{
385 struct spi_imx_data *spi_imx = dev_id; 617 struct spi_imx_data *spi_imx = dev_id;
386 618
387 while (spi_imx->rx_available(spi_imx)) { 619 while (spi_imx->devtype_data.rx_available(spi_imx)) {
388 spi_imx->rx(spi_imx); 620 spi_imx->rx(spi_imx);
389 spi_imx->txfifo--; 621 spi_imx->txfifo--;
390 } 622 }
@@ -398,11 +630,12 @@ static irqreturn_t spi_imx_isr(int irq, void *dev_id)
398 /* No data left to push, but still waiting for rx data, 630 /* No data left to push, but still waiting for rx data,
399 * enable receive data available interrupt. 631 * enable receive data available interrupt.
400 */ 632 */
401 spi_imx->intctrl(spi_imx, MXC_INT_RR); 633 spi_imx->devtype_data.intctrl(
634 spi_imx, MXC_INT_RR);
402 return IRQ_HANDLED; 635 return IRQ_HANDLED;
403 } 636 }
404 637
405 spi_imx->intctrl(spi_imx, 0); 638 spi_imx->devtype_data.intctrl(spi_imx, 0);
406 complete(&spi_imx->xfer_done); 639 complete(&spi_imx->xfer_done);
407 640
408 return IRQ_HANDLED; 641 return IRQ_HANDLED;
@@ -417,7 +650,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
417 config.bpw = t ? t->bits_per_word : spi->bits_per_word; 650 config.bpw = t ? t->bits_per_word : spi->bits_per_word;
418 config.speed_hz = t ? t->speed_hz : spi->max_speed_hz; 651 config.speed_hz = t ? t->speed_hz : spi->max_speed_hz;
419 config.mode = spi->mode; 652 config.mode = spi->mode;
420 config.cs = spi_imx->chipselect[spi->chip_select]; 653 config.cs = spi->chip_select;
421 654
422 if (!config.speed_hz) 655 if (!config.speed_hz)
423 config.speed_hz = spi->max_speed_hz; 656 config.speed_hz = spi->max_speed_hz;
@@ -439,7 +672,7 @@ static int spi_imx_setupxfer(struct spi_device *spi,
439 } else 672 } else
440 BUG(); 673 BUG();
441 674
442 spi_imx->config(spi_imx, &config); 675 spi_imx->devtype_data.config(spi_imx, &config);
443 676
444 return 0; 677 return 0;
445} 678}
@@ -458,7 +691,7 @@ static int spi_imx_transfer(struct spi_device *spi,
458 691
459 spi_imx_push(spi_imx); 692 spi_imx_push(spi_imx);
460 693
461 spi_imx->intctrl(spi_imx, MXC_INT_TE); 694 spi_imx->devtype_data.intctrl(spi_imx, MXC_INT_TE);
462 695
463 wait_for_completion(&spi_imx->xfer_done); 696 wait_for_completion(&spi_imx->xfer_done);
464 697
@@ -485,6 +718,39 @@ static void spi_imx_cleanup(struct spi_device *spi)
485{ 718{
486} 719}
487 720
721static struct platform_device_id spi_imx_devtype[] = {
722 {
723 .name = DRIVER_NAME,
724 .driver_data = SPI_IMX_VER_AUTODETECT,
725 }, {
726 .name = "imx1-cspi",
727 .driver_data = SPI_IMX_VER_IMX1,
728 }, {
729 .name = "imx21-cspi",
730 .driver_data = SPI_IMX_VER_0_0,
731 }, {
732 .name = "imx25-cspi",
733 .driver_data = SPI_IMX_VER_0_7,
734 }, {
735 .name = "imx27-cspi",
736 .driver_data = SPI_IMX_VER_0_0,
737 }, {
738 .name = "imx31-cspi",
739 .driver_data = SPI_IMX_VER_0_4,
740 }, {
741 .name = "imx35-cspi",
742 .driver_data = SPI_IMX_VER_0_7,
743 }, {
744 .name = "imx51-cspi",
745 .driver_data = SPI_IMX_VER_0_7,
746 }, {
747 .name = "imx51-ecspi",
748 .driver_data = SPI_IMX_VER_2_3,
749 }, {
750 /* sentinel */
751 }
752};
753
488static int __devinit spi_imx_probe(struct platform_device *pdev) 754static int __devinit spi_imx_probe(struct platform_device *pdev)
489{ 755{
490 struct spi_imx_master *mxc_platform_info; 756 struct spi_imx_master *mxc_platform_info;
@@ -536,6 +802,31 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
536 802
537 init_completion(&spi_imx->xfer_done); 803 init_completion(&spi_imx->xfer_done);
538 804
805 if (pdev->id_entry->driver_data == SPI_IMX_VER_AUTODETECT) {
806 if (cpu_is_mx25() || cpu_is_mx35())
807 spi_imx->devtype_data =
808 spi_imx_devtype_data[SPI_IMX_VER_0_7];
809 else if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35())
810 spi_imx->devtype_data =
811 spi_imx_devtype_data[SPI_IMX_VER_0_4];
812 else if (cpu_is_mx27() || cpu_is_mx21())
813 spi_imx->devtype_data =
814 spi_imx_devtype_data[SPI_IMX_VER_0_0];
815 else if (cpu_is_mx1())
816 spi_imx->devtype_data =
817 spi_imx_devtype_data[SPI_IMX_VER_IMX1];
818 else
819 BUG();
820 } else
821 spi_imx->devtype_data =
822 spi_imx_devtype_data[pdev->id_entry->driver_data];
823
824 if (!spi_imx->devtype_data.intctrl) {
825 dev_err(&pdev->dev, "no support for this device compiled in\n");
826 ret = -ENODEV;
827 goto out_gpio_free;
828 }
829
539 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 830 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
540 if (!res) { 831 if (!res) {
541 dev_err(&pdev->dev, "can't get platform resource\n"); 832 dev_err(&pdev->dev, "can't get platform resource\n");
@@ -567,24 +858,6 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
567 goto out_iounmap; 858 goto out_iounmap;
568 } 859 }
569 860
570 if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35()) {
571 spi_imx->intctrl = mx31_intctrl;
572 spi_imx->config = mx31_config;
573 spi_imx->trigger = mx31_trigger;
574 spi_imx->rx_available = mx31_rx_available;
575 } else if (cpu_is_mx27() || cpu_is_mx21()) {
576 spi_imx->intctrl = mx27_intctrl;
577 spi_imx->config = mx27_config;
578 spi_imx->trigger = mx27_trigger;
579 spi_imx->rx_available = mx27_rx_available;
580 } else if (cpu_is_mx1()) {
581 spi_imx->intctrl = mx1_intctrl;
582 spi_imx->config = mx1_config;
583 spi_imx->trigger = mx1_trigger;
584 spi_imx->rx_available = mx1_rx_available;
585 } else
586 BUG();
587
588 spi_imx->clk = clk_get(&pdev->dev, NULL); 861 spi_imx->clk = clk_get(&pdev->dev, NULL);
589 if (IS_ERR(spi_imx->clk)) { 862 if (IS_ERR(spi_imx->clk)) {
590 dev_err(&pdev->dev, "unable to get clock\n"); 863 dev_err(&pdev->dev, "unable to get clock\n");
@@ -595,15 +868,9 @@ static int __devinit spi_imx_probe(struct platform_device *pdev)
595 clk_enable(spi_imx->clk); 868 clk_enable(spi_imx->clk);
596 spi_imx->spi_clk = clk_get_rate(spi_imx->clk); 869 spi_imx->spi_clk = clk_get_rate(spi_imx->clk);
597 870
598 if (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27()) 871 spi_imx->devtype_data.reset(spi_imx);
599 writel(1, spi_imx->base + MXC_RESET);
600
601 /* drain receive buffer */
602 if (cpu_is_mx25() || cpu_is_mx31() || cpu_is_mx35())
603 while (readl(spi_imx->base + MX3_CSPISTAT) & MX3_CSPISTAT_RR)
604 readl(spi_imx->base + MXC_CSPIRXDATA);
605 872
606 spi_imx->intctrl(spi_imx, 0); 873 spi_imx->devtype_data.intctrl(spi_imx, 0);
607 874
608 ret = spi_bitbang_start(&spi_imx->bitbang); 875 ret = spi_bitbang_start(&spi_imx->bitbang);
609 if (ret) { 876 if (ret) {
@@ -668,6 +935,7 @@ static struct platform_driver spi_imx_driver = {
668 .name = DRIVER_NAME, 935 .name = DRIVER_NAME,
669 .owner = THIS_MODULE, 936 .owner = THIS_MODULE,
670 }, 937 },
938 .id_table = spi_imx_devtype,
671 .probe = spi_imx_probe, 939 .probe = spi_imx_probe,
672 .remove = __devexit_p(spi_imx_remove), 940 .remove = __devexit_p(spi_imx_remove),
673}; 941};
diff --git a/drivers/spi/spi_s3c64xx.c b/drivers/spi/spi_s3c64xx.c
index 97365815a729..795828b90f45 100644
--- a/drivers/spi/spi_s3c64xx.c
+++ b/drivers/spi/spi_s3c64xx.c
@@ -200,6 +200,9 @@ static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
200 val = readl(regs + S3C64XX_SPI_STATUS); 200 val = readl(regs + S3C64XX_SPI_STATUS);
201 } while (TX_FIFO_LVL(val, sci) && loops--); 201 } while (TX_FIFO_LVL(val, sci) && loops--);
202 202
203 if (loops == 0)
204 dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO\n");
205
203 /* Flush RxFIFO*/ 206 /* Flush RxFIFO*/
204 loops = msecs_to_loops(1); 207 loops = msecs_to_loops(1);
205 do { 208 do {
@@ -210,6 +213,9 @@ static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
210 break; 213 break;
211 } while (loops--); 214 } while (loops--);
212 215
216 if (loops == 0)
217 dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO\n");
218
213 val = readl(regs + S3C64XX_SPI_CH_CFG); 219 val = readl(regs + S3C64XX_SPI_CH_CFG);
214 val &= ~S3C64XX_SPI_CH_SW_RST; 220 val &= ~S3C64XX_SPI_CH_SW_RST;
215 writel(val, regs + S3C64XX_SPI_CH_CFG); 221 writel(val, regs + S3C64XX_SPI_CH_CFG);
@@ -255,15 +261,25 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
255 chcfg |= S3C64XX_SPI_CH_TXCH_ON; 261 chcfg |= S3C64XX_SPI_CH_TXCH_ON;
256 if (dma_mode) { 262 if (dma_mode) {
257 modecfg |= S3C64XX_SPI_MODE_TXDMA_ON; 263 modecfg |= S3C64XX_SPI_MODE_TXDMA_ON;
258 s3c2410_dma_config(sdd->tx_dmach, 1); 264 s3c2410_dma_config(sdd->tx_dmach, sdd->cur_bpw / 8);
259 s3c2410_dma_enqueue(sdd->tx_dmach, (void *)sdd, 265 s3c2410_dma_enqueue(sdd->tx_dmach, (void *)sdd,
260 xfer->tx_dma, xfer->len); 266 xfer->tx_dma, xfer->len);
261 s3c2410_dma_ctrl(sdd->tx_dmach, S3C2410_DMAOP_START); 267 s3c2410_dma_ctrl(sdd->tx_dmach, S3C2410_DMAOP_START);
262 } else { 268 } else {
263 unsigned char *buf = (unsigned char *) xfer->tx_buf; 269 switch (sdd->cur_bpw) {
264 int i = 0; 270 case 32:
265 while (i < xfer->len) 271 iowrite32_rep(regs + S3C64XX_SPI_TX_DATA,
266 writeb(buf[i++], regs + S3C64XX_SPI_TX_DATA); 272 xfer->tx_buf, xfer->len / 4);
273 break;
274 case 16:
275 iowrite16_rep(regs + S3C64XX_SPI_TX_DATA,
276 xfer->tx_buf, xfer->len / 2);
277 break;
278 default:
279 iowrite8_rep(regs + S3C64XX_SPI_TX_DATA,
280 xfer->tx_buf, xfer->len);
281 break;
282 }
267 } 283 }
268 } 284 }
269 285
@@ -280,7 +296,7 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
280 writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff) 296 writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
281 | S3C64XX_SPI_PACKET_CNT_EN, 297 | S3C64XX_SPI_PACKET_CNT_EN,
282 regs + S3C64XX_SPI_PACKET_CNT); 298 regs + S3C64XX_SPI_PACKET_CNT);
283 s3c2410_dma_config(sdd->rx_dmach, 1); 299 s3c2410_dma_config(sdd->rx_dmach, sdd->cur_bpw / 8);
284 s3c2410_dma_enqueue(sdd->rx_dmach, (void *)sdd, 300 s3c2410_dma_enqueue(sdd->rx_dmach, (void *)sdd,
285 xfer->rx_dma, xfer->len); 301 xfer->rx_dma, xfer->len);
286 s3c2410_dma_ctrl(sdd->rx_dmach, S3C2410_DMAOP_START); 302 s3c2410_dma_ctrl(sdd->rx_dmach, S3C2410_DMAOP_START);
@@ -320,16 +336,17 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd,
320 336
321 /* millisecs to xfer 'len' bytes @ 'cur_speed' */ 337 /* millisecs to xfer 'len' bytes @ 'cur_speed' */
322 ms = xfer->len * 8 * 1000 / sdd->cur_speed; 338 ms = xfer->len * 8 * 1000 / sdd->cur_speed;
323 ms += 5; /* some tolerance */ 339 ms += 10; /* some tolerance */
324 340
325 if (dma_mode) { 341 if (dma_mode) {
326 val = msecs_to_jiffies(ms) + 10; 342 val = msecs_to_jiffies(ms) + 10;
327 val = wait_for_completion_timeout(&sdd->xfer_completion, val); 343 val = wait_for_completion_timeout(&sdd->xfer_completion, val);
328 } else { 344 } else {
345 u32 status;
329 val = msecs_to_loops(ms); 346 val = msecs_to_loops(ms);
330 do { 347 do {
331 val = readl(regs + S3C64XX_SPI_STATUS); 348 status = readl(regs + S3C64XX_SPI_STATUS);
332 } while (RX_FIFO_LVL(val, sci) < xfer->len && --val); 349 } while (RX_FIFO_LVL(status, sci) < xfer->len && --val);
333 } 350 }
334 351
335 if (!val) 352 if (!val)
@@ -359,20 +376,26 @@ static int wait_for_xfer(struct s3c64xx_spi_driver_data *sdd,
359 return -EIO; 376 return -EIO;
360 } 377 }
361 } else { 378 } else {
362 unsigned char *buf;
363 int i;
364
365 /* If it was only Tx */ 379 /* If it was only Tx */
366 if (xfer->rx_buf == NULL) { 380 if (xfer->rx_buf == NULL) {
367 sdd->state &= ~TXBUSY; 381 sdd->state &= ~TXBUSY;
368 return 0; 382 return 0;
369 } 383 }
370 384
371 i = 0; 385 switch (sdd->cur_bpw) {
372 buf = xfer->rx_buf; 386 case 32:
373 while (i < xfer->len) 387 ioread32_rep(regs + S3C64XX_SPI_RX_DATA,
374 buf[i++] = readb(regs + S3C64XX_SPI_RX_DATA); 388 xfer->rx_buf, xfer->len / 4);
375 389 break;
390 case 16:
391 ioread16_rep(regs + S3C64XX_SPI_RX_DATA,
392 xfer->rx_buf, xfer->len / 2);
393 break;
394 default:
395 ioread8_rep(regs + S3C64XX_SPI_RX_DATA,
396 xfer->rx_buf, xfer->len);
397 break;
398 }
376 sdd->state &= ~RXBUSY; 399 sdd->state &= ~RXBUSY;
377 } 400 }
378 401
@@ -392,13 +415,18 @@ static inline void disable_cs(struct s3c64xx_spi_driver_data *sdd,
392 415
393static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) 416static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
394{ 417{
418 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
395 void __iomem *regs = sdd->regs; 419 void __iomem *regs = sdd->regs;
396 u32 val; 420 u32 val;
397 421
398 /* Disable Clock */ 422 /* Disable Clock */
399 val = readl(regs + S3C64XX_SPI_CLK_CFG); 423 if (sci->clk_from_cmu) {
400 val &= ~S3C64XX_SPI_ENCLK_ENABLE; 424 clk_disable(sdd->src_clk);
401 writel(val, regs + S3C64XX_SPI_CLK_CFG); 425 } else {
426 val = readl(regs + S3C64XX_SPI_CLK_CFG);
427 val &= ~S3C64XX_SPI_ENCLK_ENABLE;
428 writel(val, regs + S3C64XX_SPI_CLK_CFG);
429 }
402 430
403 /* Set Polarity and Phase */ 431 /* Set Polarity and Phase */
404 val = readl(regs + S3C64XX_SPI_CH_CFG); 432 val = readl(regs + S3C64XX_SPI_CH_CFG);
@@ -422,33 +450,43 @@ static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
422 switch (sdd->cur_bpw) { 450 switch (sdd->cur_bpw) {
423 case 32: 451 case 32:
424 val |= S3C64XX_SPI_MODE_BUS_TSZ_WORD; 452 val |= S3C64XX_SPI_MODE_BUS_TSZ_WORD;
453 val |= S3C64XX_SPI_MODE_CH_TSZ_WORD;
425 break; 454 break;
426 case 16: 455 case 16:
427 val |= S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD; 456 val |= S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD;
457 val |= S3C64XX_SPI_MODE_CH_TSZ_HALFWORD;
428 break; 458 break;
429 default: 459 default:
430 val |= S3C64XX_SPI_MODE_BUS_TSZ_BYTE; 460 val |= S3C64XX_SPI_MODE_BUS_TSZ_BYTE;
461 val |= S3C64XX_SPI_MODE_CH_TSZ_BYTE;
431 break; 462 break;
432 } 463 }
433 val |= S3C64XX_SPI_MODE_CH_TSZ_BYTE; /* Always 8bits wide */
434 464
435 writel(val, regs + S3C64XX_SPI_MODE_CFG); 465 writel(val, regs + S3C64XX_SPI_MODE_CFG);
436 466
437 /* Configure Clock */ 467 if (sci->clk_from_cmu) {
438 val = readl(regs + S3C64XX_SPI_CLK_CFG); 468 /* Configure Clock */
439 val &= ~S3C64XX_SPI_PSR_MASK; 469 /* There is half-multiplier before the SPI */
440 val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / 2 - 1) 470 clk_set_rate(sdd->src_clk, sdd->cur_speed * 2);
441 & S3C64XX_SPI_PSR_MASK); 471 /* Enable Clock */
442 writel(val, regs + S3C64XX_SPI_CLK_CFG); 472 clk_enable(sdd->src_clk);
443 473 } else {
444 /* Enable Clock */ 474 /* Configure Clock */
445 val = readl(regs + S3C64XX_SPI_CLK_CFG); 475 val = readl(regs + S3C64XX_SPI_CLK_CFG);
446 val |= S3C64XX_SPI_ENCLK_ENABLE; 476 val &= ~S3C64XX_SPI_PSR_MASK;
447 writel(val, regs + S3C64XX_SPI_CLK_CFG); 477 val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / 2 - 1)
478 & S3C64XX_SPI_PSR_MASK);
479 writel(val, regs + S3C64XX_SPI_CLK_CFG);
480
481 /* Enable Clock */
482 val = readl(regs + S3C64XX_SPI_CLK_CFG);
483 val |= S3C64XX_SPI_ENCLK_ENABLE;
484 writel(val, regs + S3C64XX_SPI_CLK_CFG);
485 }
448} 486}
449 487
450void s3c64xx_spi_dma_rxcb(struct s3c2410_dma_chan *chan, void *buf_id, 488static void s3c64xx_spi_dma_rxcb(struct s3c2410_dma_chan *chan, void *buf_id,
451 int size, enum s3c2410_dma_buffresult res) 489 int size, enum s3c2410_dma_buffresult res)
452{ 490{
453 struct s3c64xx_spi_driver_data *sdd = buf_id; 491 struct s3c64xx_spi_driver_data *sdd = buf_id;
454 unsigned long flags; 492 unsigned long flags;
@@ -467,8 +505,8 @@ void s3c64xx_spi_dma_rxcb(struct s3c2410_dma_chan *chan, void *buf_id,
467 spin_unlock_irqrestore(&sdd->lock, flags); 505 spin_unlock_irqrestore(&sdd->lock, flags);
468} 506}
469 507
470void s3c64xx_spi_dma_txcb(struct s3c2410_dma_chan *chan, void *buf_id, 508static void s3c64xx_spi_dma_txcb(struct s3c2410_dma_chan *chan, void *buf_id,
471 int size, enum s3c2410_dma_buffresult res) 509 int size, enum s3c2410_dma_buffresult res)
472{ 510{
473 struct s3c64xx_spi_driver_data *sdd = buf_id; 511 struct s3c64xx_spi_driver_data *sdd = buf_id;
474 unsigned long flags; 512 unsigned long flags;
@@ -492,6 +530,7 @@ void s3c64xx_spi_dma_txcb(struct s3c2410_dma_chan *chan, void *buf_id,
492static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd, 530static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
493 struct spi_message *msg) 531 struct spi_message *msg)
494{ 532{
533 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
495 struct device *dev = &sdd->pdev->dev; 534 struct device *dev = &sdd->pdev->dev;
496 struct spi_transfer *xfer; 535 struct spi_transfer *xfer;
497 536
@@ -507,9 +546,13 @@ static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
507 /* Map until end or first fail */ 546 /* Map until end or first fail */
508 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 547 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
509 548
549 if (xfer->len <= ((sci->fifo_lvl_mask >> 1) + 1))
550 continue;
551
510 if (xfer->tx_buf != NULL) { 552 if (xfer->tx_buf != NULL) {
511 xfer->tx_dma = dma_map_single(dev, xfer->tx_buf, 553 xfer->tx_dma = dma_map_single(dev,
512 xfer->len, DMA_TO_DEVICE); 554 (void *)xfer->tx_buf, xfer->len,
555 DMA_TO_DEVICE);
513 if (dma_mapping_error(dev, xfer->tx_dma)) { 556 if (dma_mapping_error(dev, xfer->tx_dma)) {
514 dev_err(dev, "dma_map_single Tx failed\n"); 557 dev_err(dev, "dma_map_single Tx failed\n");
515 xfer->tx_dma = XFER_DMAADDR_INVALID; 558 xfer->tx_dma = XFER_DMAADDR_INVALID;
@@ -537,6 +580,7 @@ static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
537static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd, 580static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd,
538 struct spi_message *msg) 581 struct spi_message *msg)
539{ 582{
583 struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
540 struct device *dev = &sdd->pdev->dev; 584 struct device *dev = &sdd->pdev->dev;
541 struct spi_transfer *xfer; 585 struct spi_transfer *xfer;
542 586
@@ -545,6 +589,9 @@ static void s3c64xx_spi_unmap_mssg(struct s3c64xx_spi_driver_data *sdd,
545 589
546 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 590 list_for_each_entry(xfer, &msg->transfers, transfer_list) {
547 591
592 if (xfer->len <= ((sci->fifo_lvl_mask >> 1) + 1))
593 continue;
594
548 if (xfer->rx_buf != NULL 595 if (xfer->rx_buf != NULL
549 && xfer->rx_dma != XFER_DMAADDR_INVALID) 596 && xfer->rx_dma != XFER_DMAADDR_INVALID)
550 dma_unmap_single(dev, xfer->rx_dma, 597 dma_unmap_single(dev, xfer->rx_dma,
@@ -600,6 +647,14 @@ static void handle_msg(struct s3c64xx_spi_driver_data *sdd,
600 bpw = xfer->bits_per_word ? : spi->bits_per_word; 647 bpw = xfer->bits_per_word ? : spi->bits_per_word;
601 speed = xfer->speed_hz ? : spi->max_speed_hz; 648 speed = xfer->speed_hz ? : spi->max_speed_hz;
602 649
650 if (xfer->len % (bpw / 8)) {
651 dev_err(&spi->dev,
652 "Xfer length(%u) not a multiple of word size(%u)\n",
653 xfer->len, bpw / 8);
654 status = -EIO;
655 goto out;
656 }
657
603 if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) { 658 if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
604 sdd->cur_bpw = bpw; 659 sdd->cur_bpw = bpw;
605 sdd->cur_speed = speed; 660 sdd->cur_speed = speed;
@@ -790,7 +845,6 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
790 struct s3c64xx_spi_driver_data *sdd; 845 struct s3c64xx_spi_driver_data *sdd;
791 struct s3c64xx_spi_info *sci; 846 struct s3c64xx_spi_info *sci;
792 struct spi_message *msg; 847 struct spi_message *msg;
793 u32 psr, speed;
794 unsigned long flags; 848 unsigned long flags;
795 int err = 0; 849 int err = 0;
796 850
@@ -833,32 +887,37 @@ static int s3c64xx_spi_setup(struct spi_device *spi)
833 } 887 }
834 888
835 /* Check if we can provide the requested rate */ 889 /* Check if we can provide the requested rate */
836 speed = clk_get_rate(sdd->src_clk) / 2 / (0 + 1); /* Max possible */ 890 if (!sci->clk_from_cmu) {
837 891 u32 psr, speed;
838 if (spi->max_speed_hz > speed) 892
839 spi->max_speed_hz = speed; 893 /* Max possible */
840 894 speed = clk_get_rate(sdd->src_clk) / 2 / (0 + 1);
841 psr = clk_get_rate(sdd->src_clk) / 2 / spi->max_speed_hz - 1; 895
842 psr &= S3C64XX_SPI_PSR_MASK; 896 if (spi->max_speed_hz > speed)
843 if (psr == S3C64XX_SPI_PSR_MASK) 897 spi->max_speed_hz = speed;
844 psr--; 898
899 psr = clk_get_rate(sdd->src_clk) / 2 / spi->max_speed_hz - 1;
900 psr &= S3C64XX_SPI_PSR_MASK;
901 if (psr == S3C64XX_SPI_PSR_MASK)
902 psr--;
903
904 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
905 if (spi->max_speed_hz < speed) {
906 if (psr+1 < S3C64XX_SPI_PSR_MASK) {
907 psr++;
908 } else {
909 err = -EINVAL;
910 goto setup_exit;
911 }
912 }
845 913
846 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1); 914 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
847 if (spi->max_speed_hz < speed) { 915 if (spi->max_speed_hz >= speed)
848 if (psr+1 < S3C64XX_SPI_PSR_MASK) { 916 spi->max_speed_hz = speed;
849 psr++; 917 else
850 } else {
851 err = -EINVAL; 918 err = -EINVAL;
852 goto setup_exit;
853 }
854 } 919 }
855 920
856 speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1);
857 if (spi->max_speed_hz >= speed)
858 spi->max_speed_hz = speed;
859 else
860 err = -EINVAL;
861
862setup_exit: 921setup_exit:
863 922
864 /* setup() returns with device de-selected */ 923 /* setup() returns with device de-selected */
@@ -880,7 +939,8 @@ static void s3c64xx_spi_hwinit(struct s3c64xx_spi_driver_data *sdd, int channel)
880 /* Disable Interrupts - we use Polling if not DMA mode */ 939 /* Disable Interrupts - we use Polling if not DMA mode */
881 writel(0, regs + S3C64XX_SPI_INT_EN); 940 writel(0, regs + S3C64XX_SPI_INT_EN);
882 941
883 writel(sci->src_clk_nr << S3C64XX_SPI_CLKSEL_SRCSHFT, 942 if (!sci->clk_from_cmu)
943 writel(sci->src_clk_nr << S3C64XX_SPI_CLKSEL_SRCSHFT,
884 regs + S3C64XX_SPI_CLK_CFG); 944 regs + S3C64XX_SPI_CLK_CFG);
885 writel(0, regs + S3C64XX_SPI_MODE_CFG); 945 writel(0, regs + S3C64XX_SPI_MODE_CFG);
886 writel(0, regs + S3C64XX_SPI_PACKET_CNT); 946 writel(0, regs + S3C64XX_SPI_PACKET_CNT);
@@ -919,6 +979,13 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
919 return -ENODEV; 979 return -ENODEV;
920 } 980 }
921 981
982 sci = pdev->dev.platform_data;
983 if (!sci->src_clk_name) {
984 dev_err(&pdev->dev,
985 "Board init must call s3c64xx_spi_set_info()\n");
986 return -EINVAL;
987 }
988
922 /* Check for availability of necessary resource */ 989 /* Check for availability of necessary resource */
923 990
924 dmatx_res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 991 dmatx_res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
@@ -946,8 +1013,6 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
946 return -ENOMEM; 1013 return -ENOMEM;
947 } 1014 }
948 1015
949 sci = pdev->dev.platform_data;
950
951 platform_set_drvdata(pdev, master); 1016 platform_set_drvdata(pdev, master);
952 1017
953 sdd = spi_master_get_devdata(master); 1018 sdd = spi_master_get_devdata(master);
@@ -1170,7 +1235,7 @@ static int __init s3c64xx_spi_init(void)
1170{ 1235{
1171 return platform_driver_probe(&s3c64xx_spi_driver, s3c64xx_spi_probe); 1236 return platform_driver_probe(&s3c64xx_spi_driver, s3c64xx_spi_probe);
1172} 1237}
1173module_init(s3c64xx_spi_init); 1238subsys_initcall(s3c64xx_spi_init);
1174 1239
1175static void __exit s3c64xx_spi_exit(void) 1240static void __exit s3c64xx_spi_exit(void)
1176{ 1241{
diff --git a/drivers/spi/spi_topcliff_pch.c b/drivers/spi/spi_topcliff_pch.c
new file mode 100644
index 000000000000..58e187f45ec7
--- /dev/null
+++ b/drivers/spi/spi_topcliff_pch.c
@@ -0,0 +1,1303 @@
1/*
2 * SPI bus driver for the Topcliff PCH used by Intel SoCs
3 *
4 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/delay.h>
21#include <linux/pci.h>
22#include <linux/wait.h>
23#include <linux/spi/spi.h>
24#include <linux/interrupt.h>
25#include <linux/sched.h>
26#include <linux/spi/spidev.h>
27#include <linux/module.h>
28#include <linux/device.h>
29
30/* Register offsets */
31#define PCH_SPCR 0x00 /* SPI control register */
32#define PCH_SPBRR 0x04 /* SPI baud rate register */
33#define PCH_SPSR 0x08 /* SPI status register */
34#define PCH_SPDWR 0x0C /* SPI write data register */
35#define PCH_SPDRR 0x10 /* SPI read data register */
36#define PCH_SSNXCR 0x18 /* SSN Expand Control Register */
37#define PCH_SRST 0x1C /* SPI reset register */
38
39#define PCH_SPSR_TFD 0x000007C0
40#define PCH_SPSR_RFD 0x0000F800
41
42#define PCH_READABLE(x) (((x) & PCH_SPSR_RFD)>>11)
43#define PCH_WRITABLE(x) (((x) & PCH_SPSR_TFD)>>6)
44
45#define PCH_RX_THOLD 7
46#define PCH_RX_THOLD_MAX 15
47
48#define PCH_MAX_BAUDRATE 5000000
49#define PCH_MAX_FIFO_DEPTH 16
50
51#define STATUS_RUNNING 1
52#define STATUS_EXITING 2
53#define PCH_SLEEP_TIME 10
54
55#define PCH_ADDRESS_SIZE 0x20
56
57#define SSN_LOW 0x02U
58#define SSN_NO_CONTROL 0x00U
59#define PCH_MAX_CS 0xFF
60#define PCI_DEVICE_ID_GE_SPI 0x8816
61
62#define SPCR_SPE_BIT (1 << 0)
63#define SPCR_MSTR_BIT (1 << 1)
64#define SPCR_LSBF_BIT (1 << 4)
65#define SPCR_CPHA_BIT (1 << 5)
66#define SPCR_CPOL_BIT (1 << 6)
67#define SPCR_TFIE_BIT (1 << 8)
68#define SPCR_RFIE_BIT (1 << 9)
69#define SPCR_FIE_BIT (1 << 10)
70#define SPCR_ORIE_BIT (1 << 11)
71#define SPCR_MDFIE_BIT (1 << 12)
72#define SPCR_FICLR_BIT (1 << 24)
73#define SPSR_TFI_BIT (1 << 0)
74#define SPSR_RFI_BIT (1 << 1)
75#define SPSR_FI_BIT (1 << 2)
76#define SPBRR_SIZE_BIT (1 << 10)
77
78#define PCH_ALL (SPCR_TFIE_BIT|SPCR_RFIE_BIT|SPCR_FIE_BIT|SPCR_ORIE_BIT|SPCR_MDFIE_BIT)
79
80#define SPCR_RFIC_FIELD 20
81#define SPCR_TFIC_FIELD 16
82
83#define SPSR_INT_BITS 0x1F
84#define MASK_SPBRR_SPBR_BITS (~((1 << 10) - 1))
85#define MASK_RFIC_SPCR_BITS (~(0xf << 20))
86#define MASK_TFIC_SPCR_BITS (~(0xf000f << 12))
87
88#define PCH_CLOCK_HZ 50000000
89#define PCH_MAX_SPBR 1023
90
91
92/**
93 * struct pch_spi_data - Holds the SPI channel specific details
94 * @io_remap_addr: The remapped PCI base address
95 * @master: Pointer to the SPI master structure
96 * @work: Reference to work queue handler
97 * @wk: Workqueue for carrying out execution of the
98 * requests
99 * @wait: Wait queue for waking up upon receiving an
100 * interrupt.
101 * @transfer_complete: Status of SPI Transfer
102 * @bcurrent_msg_processing: Status flag for message processing
103 * @lock: Lock for protecting this structure
104 * @queue: SPI Message queue
105 * @status: Status of the SPI driver
106 * @bpw_len: Length of data to be transferred in bits per
107 * word
108 * @transfer_active: Flag showing active transfer
109 * @tx_index: Transmit data count; for bookkeeping during
110 * transfer
111 * @rx_index: Receive data count; for bookkeeping during
112 * transfer
113 * @tx_buff: Buffer for data to be transmitted
114 * @rx_index: Buffer for Received data
115 * @n_curnt_chip: The chip number that this SPI driver currently
116 * operates on
117 * @current_chip: Reference to the current chip that this SPI
118 * driver currently operates on
119 * @current_msg: The current message that this SPI driver is
120 * handling
121 * @cur_trans: The current transfer that this SPI driver is
122 * handling
123 * @board_dat: Reference to the SPI device data structure
124 */
125struct pch_spi_data {
126 void __iomem *io_remap_addr;
127 struct spi_master *master;
128 struct work_struct work;
129 struct workqueue_struct *wk;
130 wait_queue_head_t wait;
131 u8 transfer_complete;
132 u8 bcurrent_msg_processing;
133 spinlock_t lock;
134 struct list_head queue;
135 u8 status;
136 u32 bpw_len;
137 u8 transfer_active;
138 u32 tx_index;
139 u32 rx_index;
140 u16 *pkt_tx_buff;
141 u16 *pkt_rx_buff;
142 u8 n_curnt_chip;
143 struct spi_device *current_chip;
144 struct spi_message *current_msg;
145 struct spi_transfer *cur_trans;
146 struct pch_spi_board_data *board_dat;
147};
148
149/**
150 * struct pch_spi_board_data - Holds the SPI device specific details
151 * @pdev: Pointer to the PCI device
152 * @irq_reg_sts: Status of IRQ registration
153 * @pci_req_sts: Status of pci_request_regions
154 * @suspend_sts: Status of suspend
155 * @data: Pointer to SPI channel data structure
156 */
157struct pch_spi_board_data {
158 struct pci_dev *pdev;
159 u8 irq_reg_sts;
160 u8 pci_req_sts;
161 u8 suspend_sts;
162 struct pch_spi_data *data;
163};
164
165static struct pci_device_id pch_spi_pcidev_id[] = {
166 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_GE_SPI)},
167 {0,}
168};
169
170/**
171 * pch_spi_writereg() - Performs register writes
172 * @master: Pointer to struct spi_master.
173 * @idx: Register offset.
174 * @val: Value to be written to register.
175 */
176static inline void pch_spi_writereg(struct spi_master *master, int idx, u32 val)
177{
178 struct pch_spi_data *data = spi_master_get_devdata(master);
179 iowrite32(val, (data->io_remap_addr + idx));
180}
181
182/**
183 * pch_spi_readreg() - Performs register reads
184 * @master: Pointer to struct spi_master.
185 * @idx: Register offset.
186 */
187static inline u32 pch_spi_readreg(struct spi_master *master, int idx)
188{
189 struct pch_spi_data *data = spi_master_get_devdata(master);
190 return ioread32(data->io_remap_addr + idx);
191}
192
193static inline void pch_spi_setclr_reg(struct spi_master *master, int idx,
194 u32 set, u32 clr)
195{
196 u32 tmp = pch_spi_readreg(master, idx);
197 tmp = (tmp & ~clr) | set;
198 pch_spi_writereg(master, idx, tmp);
199}
200
201static void pch_spi_set_master_mode(struct spi_master *master)
202{
203 pch_spi_setclr_reg(master, PCH_SPCR, SPCR_MSTR_BIT, 0);
204}
205
206/**
207 * pch_spi_clear_fifo() - Clears the Transmit and Receive FIFOs
208 * @master: Pointer to struct spi_master.
209 */
210static void pch_spi_clear_fifo(struct spi_master *master)
211{
212 pch_spi_setclr_reg(master, PCH_SPCR, SPCR_FICLR_BIT, 0);
213 pch_spi_setclr_reg(master, PCH_SPCR, 0, SPCR_FICLR_BIT);
214}
215
216static void pch_spi_handler_sub(struct pch_spi_data *data, u32 reg_spsr_val,
217 void __iomem *io_remap_addr)
218{
219 u32 n_read, tx_index, rx_index, bpw_len;
220 u16 *pkt_rx_buffer, *pkt_tx_buff;
221 int read_cnt;
222 u32 reg_spcr_val;
223 void __iomem *spsr;
224 void __iomem *spdrr;
225 void __iomem *spdwr;
226
227 spsr = io_remap_addr + PCH_SPSR;
228 iowrite32(reg_spsr_val, spsr);
229
230 if (data->transfer_active) {
231 rx_index = data->rx_index;
232 tx_index = data->tx_index;
233 bpw_len = data->bpw_len;
234 pkt_rx_buffer = data->pkt_rx_buff;
235 pkt_tx_buff = data->pkt_tx_buff;
236
237 spdrr = io_remap_addr + PCH_SPDRR;
238 spdwr = io_remap_addr + PCH_SPDWR;
239
240 n_read = PCH_READABLE(reg_spsr_val);
241
242 for (read_cnt = 0; (read_cnt < n_read); read_cnt++) {
243 pkt_rx_buffer[rx_index++] = ioread32(spdrr);
244 if (tx_index < bpw_len)
245 iowrite32(pkt_tx_buff[tx_index++], spdwr);
246 }
247
248 /* disable RFI if not needed */
249 if ((bpw_len - rx_index) <= PCH_MAX_FIFO_DEPTH) {
250 reg_spcr_val = ioread32(io_remap_addr + PCH_SPCR);
251 reg_spcr_val &= ~SPCR_RFIE_BIT; /* disable RFI */
252
253 /* reset rx threshold */
254 reg_spcr_val &= MASK_RFIC_SPCR_BITS;
255 reg_spcr_val |= (PCH_RX_THOLD_MAX << SPCR_RFIC_FIELD);
256 iowrite32(((reg_spcr_val) &= (~(SPCR_RFIE_BIT))),
257 (io_remap_addr + PCH_SPCR));
258 }
259
260 /* update counts */
261 data->tx_index = tx_index;
262 data->rx_index = rx_index;
263
264 }
265
266 /* if transfer complete interrupt */
267 if (reg_spsr_val & SPSR_FI_BIT) {
268 /* disable FI & RFI interrupts */
269 pch_spi_setclr_reg(data->master, PCH_SPCR, 0,
270 SPCR_FIE_BIT | SPCR_TFIE_BIT);
271
272 /* transfer is completed;inform pch_spi_process_messages */
273 data->transfer_complete = true;
274 wake_up(&data->wait);
275 }
276}
277
278/**
279 * pch_spi_handler() - Interrupt handler
280 * @irq: The interrupt number.
281 * @dev_id: Pointer to struct pch_spi_board_data.
282 */
283static irqreturn_t pch_spi_handler(int irq, void *dev_id)
284{
285 u32 reg_spsr_val;
286 struct pch_spi_data *data;
287 void __iomem *spsr;
288 void __iomem *io_remap_addr;
289 irqreturn_t ret = IRQ_NONE;
290 struct pch_spi_board_data *board_dat = dev_id;
291
292 if (board_dat->suspend_sts) {
293 dev_dbg(&board_dat->pdev->dev,
294 "%s returning due to suspend\n", __func__);
295 return IRQ_NONE;
296 }
297
298 data = board_dat->data;
299 io_remap_addr = data->io_remap_addr;
300 spsr = io_remap_addr + PCH_SPSR;
301
302 reg_spsr_val = ioread32(spsr);
303
304 /* Check if the interrupt is for SPI device */
305 if (reg_spsr_val & (SPSR_FI_BIT | SPSR_RFI_BIT)) {
306 pch_spi_handler_sub(data, reg_spsr_val, io_remap_addr);
307 ret = IRQ_HANDLED;
308 }
309
310 dev_dbg(&board_dat->pdev->dev, "%s EXIT return value=%d\n",
311 __func__, ret);
312
313 return ret;
314}
315
316/**
317 * pch_spi_set_baud_rate() - Sets SPBR field in SPBRR
318 * @master: Pointer to struct spi_master.
319 * @speed_hz: Baud rate.
320 */
321static void pch_spi_set_baud_rate(struct spi_master *master, u32 speed_hz)
322{
323 u32 n_spbr = PCH_CLOCK_HZ / (speed_hz * 2);
324
325 /* if baud rate is less than we can support limit it */
326 if (n_spbr > PCH_MAX_SPBR)
327 n_spbr = PCH_MAX_SPBR;
328
329 pch_spi_setclr_reg(master, PCH_SPBRR, n_spbr, ~MASK_SPBRR_SPBR_BITS);
330}
331
332/**
333 * pch_spi_set_bits_per_word() - Sets SIZE field in SPBRR
334 * @master: Pointer to struct spi_master.
335 * @bits_per_word: Bits per word for SPI transfer.
336 */
337static void pch_spi_set_bits_per_word(struct spi_master *master,
338 u8 bits_per_word)
339{
340 if (bits_per_word == 8)
341 pch_spi_setclr_reg(master, PCH_SPBRR, 0, SPBRR_SIZE_BIT);
342 else
343 pch_spi_setclr_reg(master, PCH_SPBRR, SPBRR_SIZE_BIT, 0);
344}
345
346/**
347 * pch_spi_setup_transfer() - Configures the PCH SPI hardware for transfer
348 * @spi: Pointer to struct spi_device.
349 */
350static void pch_spi_setup_transfer(struct spi_device *spi)
351{
352 u32 flags = 0;
353
354 dev_dbg(&spi->dev, "%s SPBRR content =%x setting baud rate=%d\n",
355 __func__, pch_spi_readreg(spi->master, PCH_SPBRR),
356 spi->max_speed_hz);
357 pch_spi_set_baud_rate(spi->master, spi->max_speed_hz);
358
359 /* set bits per word */
360 pch_spi_set_bits_per_word(spi->master, spi->bits_per_word);
361
362 if (!(spi->mode & SPI_LSB_FIRST))
363 flags |= SPCR_LSBF_BIT;
364 if (spi->mode & SPI_CPOL)
365 flags |= SPCR_CPOL_BIT;
366 if (spi->mode & SPI_CPHA)
367 flags |= SPCR_CPHA_BIT;
368 pch_spi_setclr_reg(spi->master, PCH_SPCR, flags,
369 (SPCR_LSBF_BIT | SPCR_CPOL_BIT | SPCR_CPHA_BIT));
370
371 /* Clear the FIFO by toggling FICLR to 1 and back to 0 */
372 pch_spi_clear_fifo(spi->master);
373}
374
375/**
376 * pch_spi_reset() - Clears SPI registers
377 * @master: Pointer to struct spi_master.
378 */
379static void pch_spi_reset(struct spi_master *master)
380{
381 /* write 1 to reset SPI */
382 pch_spi_writereg(master, PCH_SRST, 0x1);
383
384 /* clear reset */
385 pch_spi_writereg(master, PCH_SRST, 0x0);
386}
387
388static int pch_spi_setup(struct spi_device *pspi)
389{
390 /* check bits per word */
391 if (pspi->bits_per_word == 0) {
392 pspi->bits_per_word = 8;
393 dev_dbg(&pspi->dev, "%s 8 bits per word\n", __func__);
394 }
395
396 if ((pspi->bits_per_word != 8) && (pspi->bits_per_word != 16)) {
397 dev_err(&pspi->dev, "%s Invalid bits per word\n", __func__);
398 return -EINVAL;
399 }
400
401 /* Check baud rate setting */
402 /* if baud rate of chip is greater than
403 max we can support,return error */
404 if ((pspi->max_speed_hz) > PCH_MAX_BAUDRATE)
405 pspi->max_speed_hz = PCH_MAX_BAUDRATE;
406
407 dev_dbg(&pspi->dev, "%s MODE = %x\n", __func__,
408 (pspi->mode) & (SPI_CPOL | SPI_CPHA));
409
410 return 0;
411}
412
413static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg)
414{
415
416 struct spi_transfer *transfer;
417 struct pch_spi_data *data = spi_master_get_devdata(pspi->master);
418 int retval;
419 unsigned long flags;
420
421 /* validate spi message and baud rate */
422 if (unlikely(list_empty(&pmsg->transfers) == 1)) {
423 dev_err(&pspi->dev, "%s list empty\n", __func__);
424 retval = -EINVAL;
425 goto err_out;
426 }
427
428 if (unlikely(pspi->max_speed_hz == 0)) {
429 dev_err(&pspi->dev, "%s pch_spi_tranfer maxspeed=%d\n",
430 __func__, pspi->max_speed_hz);
431 retval = -EINVAL;
432 goto err_out;
433 }
434
435 dev_dbg(&pspi->dev, "%s Transfer List not empty. "
436 "Transfer Speed is set.\n", __func__);
437
438 /* validate Tx/Rx buffers and Transfer length */
439 list_for_each_entry(transfer, &pmsg->transfers, transfer_list) {
440 if (!transfer->tx_buf && !transfer->rx_buf) {
441 dev_err(&pspi->dev,
442 "%s Tx and Rx buffer NULL\n", __func__);
443 retval = -EINVAL;
444 goto err_out;
445 }
446
447 if (!transfer->len) {
448 dev_err(&pspi->dev, "%s Transfer length invalid\n",
449 __func__);
450 retval = -EINVAL;
451 goto err_out;
452 }
453
454 dev_dbg(&pspi->dev, "%s Tx/Rx buffer valid. Transfer length"
455 " valid\n", __func__);
456
457 /* if baud rate hs been specified validate the same */
458 if (transfer->speed_hz > PCH_MAX_BAUDRATE)
459 transfer->speed_hz = PCH_MAX_BAUDRATE;
460
461 /* if bits per word has been specified validate the same */
462 if (transfer->bits_per_word) {
463 if ((transfer->bits_per_word != 8)
464 && (transfer->bits_per_word != 16)) {
465 retval = -EINVAL;
466 dev_err(&pspi->dev,
467 "%s Invalid bits per word\n", __func__);
468 goto err_out;
469 }
470 }
471 }
472
473 spin_lock_irqsave(&data->lock, flags);
474
475 /* We won't process any messages if we have been asked to terminate */
476 if (data->status == STATUS_EXITING) {
477 dev_err(&pspi->dev, "%s status = STATUS_EXITING.\n", __func__);
478 retval = -ESHUTDOWN;
479 goto err_return_spinlock;
480 }
481
482 /* If suspended ,return -EINVAL */
483 if (data->board_dat->suspend_sts) {
484 dev_err(&pspi->dev, "%s suspend; returning EINVAL\n", __func__);
485 retval = -EINVAL;
486 goto err_return_spinlock;
487 }
488
489 /* set status of message */
490 pmsg->actual_length = 0;
491 dev_dbg(&pspi->dev, "%s - pmsg->status =%d\n", __func__, pmsg->status);
492
493 pmsg->status = -EINPROGRESS;
494
495 /* add message to queue */
496 list_add_tail(&pmsg->queue, &data->queue);
497 dev_dbg(&pspi->dev, "%s - Invoked list_add_tail\n", __func__);
498
499 /* schedule work queue to run */
500 queue_work(data->wk, &data->work);
501 dev_dbg(&pspi->dev, "%s - Invoked queue work\n", __func__);
502
503 retval = 0;
504
505err_return_spinlock:
506 spin_unlock_irqrestore(&data->lock, flags);
507err_out:
508 dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval);
509 return retval;
510}
511
512static inline void pch_spi_select_chip(struct pch_spi_data *data,
513 struct spi_device *pspi)
514{
515 if (data->current_chip != NULL) {
516 if (pspi->chip_select != data->n_curnt_chip) {
517 dev_dbg(&pspi->dev, "%s : different slave\n", __func__);
518 data->current_chip = NULL;
519 }
520 }
521
522 data->current_chip = pspi;
523
524 data->n_curnt_chip = data->current_chip->chip_select;
525
526 dev_dbg(&pspi->dev, "%s :Invoking pch_spi_setup_transfer\n", __func__);
527 pch_spi_setup_transfer(pspi);
528}
529
530static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw,
531 struct spi_message **ppmsg)
532{
533 int size;
534 u32 n_writes;
535 int j;
536 struct spi_message *pmsg;
537 const u8 *tx_buf;
538 const u16 *tx_sbuf;
539
540 pmsg = *ppmsg;
541
542 /* set baud rate if needed */
543 if (data->cur_trans->speed_hz) {
544 dev_dbg(&data->master->dev, "%s:setting baud rate\n", __func__);
545 pch_spi_set_baud_rate(data->master, data->cur_trans->speed_hz);
546 }
547
548 /* set bits per word if needed */
549 if (data->cur_trans->bits_per_word &&
550 (data->current_msg->spi->bits_per_word != data->cur_trans->bits_per_word)) {
551 dev_dbg(&data->master->dev, "%s:set bits per word\n", __func__);
552 pch_spi_set_bits_per_word(data->master,
553 data->cur_trans->bits_per_word);
554 *bpw = data->cur_trans->bits_per_word;
555 } else {
556 *bpw = data->current_msg->spi->bits_per_word;
557 }
558
559 /* reset Tx/Rx index */
560 data->tx_index = 0;
561 data->rx_index = 0;
562
563 data->bpw_len = data->cur_trans->len / (*bpw / 8);
564
565 /* find alloc size */
566 size = data->cur_trans->len * sizeof(*data->pkt_tx_buff);
567
568 /* allocate memory for pkt_tx_buff & pkt_rx_buffer */
569 data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);
570 if (data->pkt_tx_buff != NULL) {
571 data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);
572 if (!data->pkt_rx_buff)
573 kfree(data->pkt_tx_buff);
574 }
575
576 if (!data->pkt_rx_buff) {
577 /* flush queue and set status of all transfers to -ENOMEM */
578 dev_err(&data->master->dev, "%s :kzalloc failed\n", __func__);
579 list_for_each_entry(pmsg, data->queue.next, queue) {
580 pmsg->status = -ENOMEM;
581
582 if (pmsg->complete != 0)
583 pmsg->complete(pmsg->context);
584
585 /* delete from queue */
586 list_del_init(&pmsg->queue);
587 }
588 return;
589 }
590
591 /* copy Tx Data */
592 if (data->cur_trans->tx_buf != NULL) {
593 if (*bpw == 8) {
594 tx_buf = data->cur_trans->tx_buf;
595 for (j = 0; j < data->bpw_len; j++)
596 data->pkt_tx_buff[j] = *tx_buf++;
597 } else {
598 tx_sbuf = data->cur_trans->tx_buf;
599 for (j = 0; j < data->bpw_len; j++)
600 data->pkt_tx_buff[j] = *tx_sbuf++;
601 }
602 }
603
604 /* if len greater than PCH_MAX_FIFO_DEPTH, write 16,else len bytes */
605 n_writes = data->bpw_len;
606 if (n_writes > PCH_MAX_FIFO_DEPTH)
607 n_writes = PCH_MAX_FIFO_DEPTH;
608
609 dev_dbg(&data->master->dev, "\n%s:Pulling down SSN low - writing "
610 "0x2 to SSNXCR\n", __func__);
611 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_LOW);
612
613 for (j = 0; j < n_writes; j++)
614 pch_spi_writereg(data->master, PCH_SPDWR, data->pkt_tx_buff[j]);
615
616 /* update tx_index */
617 data->tx_index = j;
618
619 /* reset transfer complete flag */
620 data->transfer_complete = false;
621 data->transfer_active = true;
622}
623
624
625static void pch_spi_nomore_transfer(struct pch_spi_data *data,
626 struct spi_message *pmsg)
627{
628 dev_dbg(&data->master->dev, "%s called\n", __func__);
629 /* Invoke complete callback
630 * [To the spi core..indicating end of transfer] */
631 data->current_msg->status = 0;
632
633 if (data->current_msg->complete != 0) {
634 dev_dbg(&data->master->dev,
635 "%s:Invoking callback of SPI core\n", __func__);
636 data->current_msg->complete(data->current_msg->context);
637 }
638
639 /* update status in global variable */
640 data->bcurrent_msg_processing = false;
641
642 dev_dbg(&data->master->dev,
643 "%s:data->bcurrent_msg_processing = false\n", __func__);
644
645 data->current_msg = NULL;
646 data->cur_trans = NULL;
647
648 /* check if we have items in list and not suspending
649 * return 1 if list empty */
650 if ((list_empty(&data->queue) == 0) &&
651 (!data->board_dat->suspend_sts) &&
652 (data->status != STATUS_EXITING)) {
653 /* We have some more work to do (either there is more tranint
654 * bpw;sfer requests in the current message or there are
655 *more messages)
656 */
657 dev_dbg(&data->master->dev, "%s:Invoke queue_work\n", __func__);
658 queue_work(data->wk, &data->work);
659 } else if (data->board_dat->suspend_sts ||
660 data->status == STATUS_EXITING) {
661 dev_dbg(&data->master->dev,
662 "%s suspend/remove initiated, flushing queue\n",
663 __func__);
664 list_for_each_entry(pmsg, data->queue.next, queue) {
665 pmsg->status = -EIO;
666
667 if (pmsg->complete)
668 pmsg->complete(pmsg->context);
669
670 /* delete from queue */
671 list_del_init(&pmsg->queue);
672 }
673 }
674}
675
676static void pch_spi_set_ir(struct pch_spi_data *data)
677{
678 /* enable interrupts */
679 if ((data->bpw_len) > PCH_MAX_FIFO_DEPTH) {
680 /* set receive threhold to PCH_RX_THOLD */
681 pch_spi_setclr_reg(data->master, PCH_SPCR,
682 PCH_RX_THOLD << SPCR_TFIC_FIELD,
683 ~MASK_TFIC_SPCR_BITS);
684 /* enable FI and RFI interrupts */
685 pch_spi_setclr_reg(data->master, PCH_SPCR,
686 SPCR_RFIE_BIT | SPCR_TFIE_BIT, 0);
687 } else {
688 /* set receive threhold to maximum */
689 pch_spi_setclr_reg(data->master, PCH_SPCR,
690 PCH_RX_THOLD_MAX << SPCR_TFIC_FIELD,
691 ~MASK_TFIC_SPCR_BITS);
692 /* enable FI interrupt */
693 pch_spi_setclr_reg(data->master, PCH_SPCR, SPCR_FIE_BIT, 0);
694 }
695
696 dev_dbg(&data->master->dev,
697 "%s:invoking pch_spi_set_enable to enable SPI\n", __func__);
698
699 /* SPI set enable */
700 pch_spi_setclr_reg(data->current_chip->master, PCH_SPCR, SPCR_SPE_BIT, 0);
701
702 /* Wait until the transfer completes; go to sleep after
703 initiating the transfer. */
704 dev_dbg(&data->master->dev,
705 "%s:waiting for transfer to get over\n", __func__);
706
707 wait_event_interruptible(data->wait, data->transfer_complete);
708
709 pch_spi_writereg(data->master, PCH_SSNXCR, SSN_NO_CONTROL);
710 dev_dbg(&data->master->dev,
711 "%s:no more control over SSN-writing 0 to SSNXCR.", __func__);
712
713 data->transfer_active = false;
714 dev_dbg(&data->master->dev,
715 "%s set data->transfer_active = false\n", __func__);
716
717 /* clear all interrupts */
718 pch_spi_writereg(data->master, PCH_SPSR,
719 pch_spi_readreg(data->master, PCH_SPSR));
720 /* disable interrupts */
721 pch_spi_setclr_reg(data->master, PCH_SPCR, 0, PCH_ALL);
722}
723
724static void pch_spi_copy_rx_data(struct pch_spi_data *data, int bpw)
725{
726 int j;
727 u8 *rx_buf;
728 u16 *rx_sbuf;
729
730 /* copy Rx Data */
731 if (!data->cur_trans->rx_buf)
732 return;
733
734 if (bpw == 8) {
735 rx_buf = data->cur_trans->rx_buf;
736 for (j = 0; j < data->bpw_len; j++)
737 *rx_buf++ = data->pkt_rx_buff[j] & 0xFF;
738 } else {
739 rx_sbuf = data->cur_trans->rx_buf;
740 for (j = 0; j < data->bpw_len; j++)
741 *rx_sbuf++ = data->pkt_rx_buff[j];
742 }
743}
744
745
746static void pch_spi_process_messages(struct work_struct *pwork)
747{
748 struct spi_message *pmsg;
749 struct pch_spi_data *data;
750 int bpw;
751
752 data = container_of(pwork, struct pch_spi_data, work);
753 dev_dbg(&data->master->dev, "%s data initialized\n", __func__);
754
755 spin_lock(&data->lock);
756
757 /* check if suspend has been initiated;if yes flush queue */
758 if (data->board_dat->suspend_sts || (data->status == STATUS_EXITING)) {
759 dev_dbg(&data->master->dev,
760 "%s suspend/remove initiated,flushing queue\n",
761 __func__);
762
763 list_for_each_entry(pmsg, data->queue.next, queue) {
764 pmsg->status = -EIO;
765
766 if (pmsg->complete != 0) {
767 spin_unlock(&data->lock);
768 pmsg->complete(pmsg->context);
769 spin_lock(&data->lock);
770 }
771
772 /* delete from queue */
773 list_del_init(&pmsg->queue);
774 }
775
776 spin_unlock(&data->lock);
777 return;
778 }
779
780 data->bcurrent_msg_processing = true;
781 dev_dbg(&data->master->dev,
782 "%s Set data->bcurrent_msg_processing= true\n", __func__);
783
784 /* Get the message from the queue and delete it from there. */
785 data->current_msg = list_entry(data->queue.next, struct spi_message,
786 queue);
787
788 list_del_init(&data->current_msg->queue);
789
790 data->current_msg->status = 0;
791
792 pch_spi_select_chip(data, data->current_msg->spi);
793
794 spin_unlock(&data->lock);
795
796 do {
797 /* If we are already processing a message get the next
798 transfer structure from the message otherwise retrieve
799 the 1st transfer request from the message. */
800 spin_lock(&data->lock);
801
802 if (data->cur_trans == NULL) {
803 data->cur_trans =
804 list_entry(data->current_msg->transfers.
805 next, struct spi_transfer,
806 transfer_list);
807 dev_dbg(&data->master->dev,
808 "%s :Getting 1st transfer message\n", __func__);
809 } else {
810 data->cur_trans =
811 list_entry(data->cur_trans->transfer_list.next,
812 struct spi_transfer,
813 transfer_list);
814 dev_dbg(&data->master->dev,
815 "%s :Getting next transfer message\n",
816 __func__);
817 }
818
819 spin_unlock(&data->lock);
820
821 pch_spi_set_tx(data, &bpw, &pmsg);
822
823 /* Control interrupt*/
824 pch_spi_set_ir(data);
825
826 /* Disable SPI transfer */
827 pch_spi_setclr_reg(data->current_chip->master, PCH_SPCR, 0,
828 SPCR_SPE_BIT);
829
830 /* clear FIFO */
831 pch_spi_clear_fifo(data->master);
832
833 /* copy Rx Data */
834 pch_spi_copy_rx_data(data, bpw);
835
836 /* free memory */
837 kfree(data->pkt_rx_buff);
838 data->pkt_rx_buff = NULL;
839
840 kfree(data->pkt_tx_buff);
841 data->pkt_tx_buff = NULL;
842
843 /* increment message count */
844 data->current_msg->actual_length += data->cur_trans->len;
845
846 dev_dbg(&data->master->dev,
847 "%s:data->current_msg->actual_length=%d\n",
848 __func__, data->current_msg->actual_length);
849
850 /* check for delay */
851 if (data->cur_trans->delay_usecs) {
852 dev_dbg(&data->master->dev, "%s:"
853 "delay in usec=%d\n", __func__,
854 data->cur_trans->delay_usecs);
855 udelay(data->cur_trans->delay_usecs);
856 }
857
858 spin_lock(&data->lock);
859
860 /* No more transfer in this message. */
861 if ((data->cur_trans->transfer_list.next) ==
862 &(data->current_msg->transfers)) {
863 pch_spi_nomore_transfer(data, pmsg);
864 }
865
866 spin_unlock(&data->lock);
867
868 } while (data->cur_trans != NULL);
869}
870
871static void pch_spi_free_resources(struct pch_spi_board_data *board_dat)
872{
873 dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
874
875 /* free workqueue */
876 if (board_dat->data->wk != NULL) {
877 destroy_workqueue(board_dat->data->wk);
878 board_dat->data->wk = NULL;
879 dev_dbg(&board_dat->pdev->dev,
880 "%s destroy_workqueue invoked successfully\n",
881 __func__);
882 }
883
884 /* disable interrupts & free IRQ */
885 if (board_dat->irq_reg_sts) {
886 /* disable interrupts */
887 pch_spi_setclr_reg(board_dat->data->master, PCH_SPCR, 0,
888 PCH_ALL);
889
890 /* free IRQ */
891 free_irq(board_dat->pdev->irq, board_dat);
892
893 dev_dbg(&board_dat->pdev->dev,
894 "%s free_irq invoked successfully\n", __func__);
895
896 board_dat->irq_reg_sts = false;
897 }
898
899 /* unmap PCI base address */
900 if (board_dat->data->io_remap_addr != 0) {
901 pci_iounmap(board_dat->pdev, board_dat->data->io_remap_addr);
902
903 board_dat->data->io_remap_addr = 0;
904
905 dev_dbg(&board_dat->pdev->dev,
906 "%s pci_iounmap invoked successfully\n", __func__);
907 }
908
909 /* release PCI region */
910 if (board_dat->pci_req_sts) {
911 pci_release_regions(board_dat->pdev);
912 dev_dbg(&board_dat->pdev->dev,
913 "%s pci_release_regions invoked successfully\n",
914 __func__);
915 board_dat->pci_req_sts = false;
916 }
917}
918
919static int pch_spi_get_resources(struct pch_spi_board_data *board_dat)
920{
921 void __iomem *io_remap_addr;
922 int retval;
923 dev_dbg(&board_dat->pdev->dev, "%s ENTRY\n", __func__);
924
925 /* create workqueue */
926 board_dat->data->wk = create_singlethread_workqueue(KBUILD_MODNAME);
927 if (!board_dat->data->wk) {
928 dev_err(&board_dat->pdev->dev,
929 "%s create_singlet hread_workqueue failed\n", __func__);
930 retval = -EBUSY;
931 goto err_return;
932 }
933
934 dev_dbg(&board_dat->pdev->dev,
935 "%s create_singlethread_workqueue success\n", __func__);
936
937 retval = pci_request_regions(board_dat->pdev, KBUILD_MODNAME);
938 if (retval != 0) {
939 dev_err(&board_dat->pdev->dev,
940 "%s request_region failed\n", __func__);
941 goto err_return;
942 }
943
944 board_dat->pci_req_sts = true;
945
946 io_remap_addr = pci_iomap(board_dat->pdev, 1, 0);
947 if (io_remap_addr == 0) {
948 dev_err(&board_dat->pdev->dev,
949 "%s pci_iomap failed\n", __func__);
950 retval = -ENOMEM;
951 goto err_return;
952 }
953
954 /* calculate base address for all channels */
955 board_dat->data->io_remap_addr = io_remap_addr;
956
957 /* reset PCH SPI h/w */
958 pch_spi_reset(board_dat->data->master);
959 dev_dbg(&board_dat->pdev->dev,
960 "%s pch_spi_reset invoked successfully\n", __func__);
961
962 /* register IRQ */
963 retval = request_irq(board_dat->pdev->irq, pch_spi_handler,
964 IRQF_SHARED, KBUILD_MODNAME, board_dat);
965 if (retval != 0) {
966 dev_err(&board_dat->pdev->dev,
967 "%s request_irq failed\n", __func__);
968 goto err_return;
969 }
970
971 dev_dbg(&board_dat->pdev->dev, "%s request_irq returned=%d\n",
972 __func__, retval);
973
974 board_dat->irq_reg_sts = true;
975 dev_dbg(&board_dat->pdev->dev, "%s data->irq_reg_sts=true\n", __func__);
976
977err_return:
978 if (retval != 0) {
979 dev_err(&board_dat->pdev->dev,
980 "%s FAIL:invoking pch_spi_free_resources\n", __func__);
981 pch_spi_free_resources(board_dat);
982 }
983
984 dev_dbg(&board_dat->pdev->dev, "%s Return=%d\n", __func__, retval);
985
986 return retval;
987}
988
989static int pch_spi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
990{
991
992 struct spi_master *master;
993
994 struct pch_spi_board_data *board_dat;
995 int retval;
996
997 dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
998
999 /* allocate memory for private data */
1000 board_dat = kzalloc(sizeof(struct pch_spi_board_data), GFP_KERNEL);
1001 if (board_dat == NULL) {
1002 dev_err(&pdev->dev,
1003 " %s memory allocation for private data failed\n",
1004 __func__);
1005 retval = -ENOMEM;
1006 goto err_kmalloc;
1007 }
1008
1009 dev_dbg(&pdev->dev,
1010 "%s memory allocation for private data success\n", __func__);
1011
1012 /* enable PCI device */
1013 retval = pci_enable_device(pdev);
1014 if (retval != 0) {
1015 dev_err(&pdev->dev, "%s pci_enable_device FAILED\n", __func__);
1016
1017 goto err_pci_en_device;
1018 }
1019
1020 dev_dbg(&pdev->dev, "%s pci_enable_device returned=%d\n",
1021 __func__, retval);
1022
1023 board_dat->pdev = pdev;
1024
1025 /* alllocate memory for SPI master */
1026 master = spi_alloc_master(&pdev->dev, sizeof(struct pch_spi_data));
1027 if (master == NULL) {
1028 retval = -ENOMEM;
1029 dev_err(&pdev->dev, "%s Fail.\n", __func__);
1030 goto err_spi_alloc_master;
1031 }
1032
1033 dev_dbg(&pdev->dev,
1034 "%s spi_alloc_master returned non NULL\n", __func__);
1035
1036 /* initialize members of SPI master */
1037 master->bus_num = -1;
1038 master->num_chipselect = PCH_MAX_CS;
1039 master->setup = pch_spi_setup;
1040 master->transfer = pch_spi_transfer;
1041 dev_dbg(&pdev->dev,
1042 "%s transfer member of SPI master initialized\n", __func__);
1043
1044 board_dat->data = spi_master_get_devdata(master);
1045
1046 board_dat->data->master = master;
1047 board_dat->data->n_curnt_chip = 255;
1048 board_dat->data->board_dat = board_dat;
1049 board_dat->data->status = STATUS_RUNNING;
1050
1051 INIT_LIST_HEAD(&board_dat->data->queue);
1052 spin_lock_init(&board_dat->data->lock);
1053 INIT_WORK(&board_dat->data->work, pch_spi_process_messages);
1054 init_waitqueue_head(&board_dat->data->wait);
1055
1056 /* allocate resources for PCH SPI */
1057 retval = pch_spi_get_resources(board_dat);
1058 if (retval) {
1059 dev_err(&pdev->dev, "%s fail(retval=%d)\n", __func__, retval);
1060 goto err_spi_get_resources;
1061 }
1062
1063 dev_dbg(&pdev->dev, "%s pch_spi_get_resources returned=%d\n",
1064 __func__, retval);
1065
1066 /* save private data in dev */
1067 pci_set_drvdata(pdev, board_dat);
1068 dev_dbg(&pdev->dev, "%s invoked pci_set_drvdata\n", __func__);
1069
1070 /* set master mode */
1071 pch_spi_set_master_mode(master);
1072 dev_dbg(&pdev->dev,
1073 "%s invoked pch_spi_set_master_mode\n", __func__);
1074
1075 /* Register the controller with the SPI core. */
1076 retval = spi_register_master(master);
1077 if (retval != 0) {
1078 dev_err(&pdev->dev,
1079 "%s spi_register_master FAILED\n", __func__);
1080 goto err_spi_reg_master;
1081 }
1082
1083 dev_dbg(&pdev->dev, "%s spi_register_master returned=%d\n",
1084 __func__, retval);
1085
1086
1087 return 0;
1088
1089err_spi_reg_master:
1090 spi_unregister_master(master);
1091err_spi_get_resources:
1092err_spi_alloc_master:
1093 spi_master_put(master);
1094 pci_disable_device(pdev);
1095err_pci_en_device:
1096 kfree(board_dat);
1097err_kmalloc:
1098 return retval;
1099}
1100
1101static void pch_spi_remove(struct pci_dev *pdev)
1102{
1103 struct pch_spi_board_data *board_dat = pci_get_drvdata(pdev);
1104 int count;
1105
1106 dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
1107
1108 if (!board_dat) {
1109 dev_err(&pdev->dev,
1110 "%s pci_get_drvdata returned NULL\n", __func__);
1111 return;
1112 }
1113
1114 /* check for any pending messages; no action is taken if the queue
1115 * is still full; but at least we tried. Unload anyway */
1116 count = 500;
1117 spin_lock(&board_dat->data->lock);
1118 board_dat->data->status = STATUS_EXITING;
1119 while ((list_empty(&board_dat->data->queue) == 0) && --count) {
1120 dev_dbg(&board_dat->pdev->dev, "%s :queue not empty\n",
1121 __func__);
1122 spin_unlock(&board_dat->data->lock);
1123 msleep(PCH_SLEEP_TIME);
1124 spin_lock(&board_dat->data->lock);
1125 }
1126 spin_unlock(&board_dat->data->lock);
1127
1128 /* Free resources allocated for PCH SPI */
1129 pch_spi_free_resources(board_dat);
1130
1131 spi_unregister_master(board_dat->data->master);
1132
1133 /* free memory for private data */
1134 kfree(board_dat);
1135
1136 pci_set_drvdata(pdev, NULL);
1137
1138 /* disable PCI device */
1139 pci_disable_device(pdev);
1140
1141 dev_dbg(&pdev->dev, "%s invoked pci_disable_device\n", __func__);
1142}
1143
1144#ifdef CONFIG_PM
1145static int pch_spi_suspend(struct pci_dev *pdev, pm_message_t state)
1146{
1147 u8 count;
1148 int retval;
1149
1150 struct pch_spi_board_data *board_dat = pci_get_drvdata(pdev);
1151
1152 dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
1153
1154 if (!board_dat) {
1155 dev_err(&pdev->dev,
1156 "%s pci_get_drvdata returned NULL\n", __func__);
1157 return -EFAULT;
1158 }
1159
1160 retval = 0;
1161 board_dat->suspend_sts = true;
1162
1163 /* check if the current message is processed:
1164 Only after thats done the transfer will be suspended */
1165 count = 255;
1166 while ((--count) > 0) {
1167 if (!(board_dat->data->bcurrent_msg_processing)) {
1168 dev_dbg(&pdev->dev, "%s board_dat->data->bCurrent_"
1169 "msg_processing = false\n", __func__);
1170 break;
1171 } else {
1172 dev_dbg(&pdev->dev, "%s board_dat->data->bCurrent_msg_"
1173 "processing = true\n", __func__);
1174 }
1175 msleep(PCH_SLEEP_TIME);
1176 }
1177
1178 /* Free IRQ */
1179 if (board_dat->irq_reg_sts) {
1180 /* disable all interrupts */
1181 pch_spi_setclr_reg(board_dat->data->master, PCH_SPCR, 0,
1182 PCH_ALL);
1183 pch_spi_reset(board_dat->data->master);
1184
1185 free_irq(board_dat->pdev->irq, board_dat);
1186
1187 board_dat->irq_reg_sts = false;
1188 dev_dbg(&pdev->dev,
1189 "%s free_irq invoked successfully.\n", __func__);
1190 }
1191
1192 /* save config space */
1193 retval = pci_save_state(pdev);
1194
1195 if (retval == 0) {
1196 dev_dbg(&pdev->dev, "%s pci_save_state returned=%d\n",
1197 __func__, retval);
1198 /* disable PM notifications */
1199 pci_enable_wake(pdev, PCI_D3hot, 0);
1200 dev_dbg(&pdev->dev,
1201 "%s pci_enable_wake invoked successfully\n", __func__);
1202 /* disable PCI device */
1203 pci_disable_device(pdev);
1204 dev_dbg(&pdev->dev,
1205 "%s pci_disable_device invoked successfully\n",
1206 __func__);
1207 /* move device to D3hot state */
1208 pci_set_power_state(pdev, PCI_D3hot);
1209 dev_dbg(&pdev->dev,
1210 "%s pci_set_power_state invoked successfully\n",
1211 __func__);
1212 } else {
1213 dev_err(&pdev->dev, "%s pci_save_state failed\n", __func__);
1214 }
1215
1216 dev_dbg(&pdev->dev, "%s return=%d\n", __func__, retval);
1217
1218 return retval;
1219}
1220
1221static int pch_spi_resume(struct pci_dev *pdev)
1222{
1223 int retval;
1224
1225 struct pch_spi_board_data *board = pci_get_drvdata(pdev);
1226 dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
1227
1228 if (!board) {
1229 dev_err(&pdev->dev,
1230 "%s pci_get_drvdata returned NULL\n", __func__);
1231 return -EFAULT;
1232 }
1233
1234 /* move device to DO power state */
1235 pci_set_power_state(pdev, PCI_D0);
1236
1237 /* restore state */
1238 pci_restore_state(pdev);
1239
1240 retval = pci_enable_device(pdev);
1241 if (retval < 0) {
1242 dev_err(&pdev->dev,
1243 "%s pci_enable_device failed\n", __func__);
1244 } else {
1245 /* disable PM notifications */
1246 pci_enable_wake(pdev, PCI_D3hot, 0);
1247
1248 /* register IRQ handler */
1249 if (!board->irq_reg_sts) {
1250 /* register IRQ */
1251 retval = request_irq(board->pdev->irq, pch_spi_handler,
1252 IRQF_SHARED, KBUILD_MODNAME,
1253 board);
1254 if (retval < 0) {
1255 dev_err(&pdev->dev,
1256 "%s request_irq failed\n", __func__);
1257 return retval;
1258 }
1259 board->irq_reg_sts = true;
1260
1261 /* reset PCH SPI h/w */
1262 pch_spi_reset(board->data->master);
1263 pch_spi_set_master_mode(board->data->master);
1264
1265 /* set suspend status to false */
1266 board->suspend_sts = false;
1267
1268 }
1269 }
1270
1271 dev_dbg(&pdev->dev, "%s returning=%d\n", __func__, retval);
1272
1273 return retval;
1274}
1275#else
1276#define pch_spi_suspend NULL
1277#define pch_spi_resume NULL
1278
1279#endif
1280
1281static struct pci_driver pch_spi_pcidev = {
1282 .name = "pch_spi",
1283 .id_table = pch_spi_pcidev_id,
1284 .probe = pch_spi_probe,
1285 .remove = pch_spi_remove,
1286 .suspend = pch_spi_suspend,
1287 .resume = pch_spi_resume,
1288};
1289
1290static int __init pch_spi_init(void)
1291{
1292 return pci_register_driver(&pch_spi_pcidev);
1293}
1294module_init(pch_spi_init);
1295
1296static void __exit pch_spi_exit(void)
1297{
1298 pci_unregister_driver(&pch_spi_pcidev);
1299}
1300module_exit(pch_spi_exit);
1301
1302MODULE_LICENSE("GPL");
1303MODULE_DESCRIPTION("Topcliff PCH SPI PCI Driver");
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index 7892ac163522..c68b3dc19e11 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -20,7 +20,6 @@
20#include <linux/mmc/sdio_func.h> 20#include <linux/mmc/sdio_func.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/ds.h> 24#include <pcmcia/ds.h>
26 25
diff --git a/drivers/ssb/pcmcia.c b/drivers/ssb/pcmcia.c
index 526682d68de8..c7345dbf43fa 100644
--- a/drivers/ssb/pcmcia.c
+++ b/drivers/ssb/pcmcia.c
@@ -13,7 +13,6 @@
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/etherdevice.h> 14#include <linux/etherdevice.h>
15 15
16#include <pcmcia/cs.h>
17#include <pcmcia/cistpl.h> 16#include <pcmcia/cistpl.h>
18#include <pcmcia/ciscode.h> 17#include <pcmcia/ciscode.h>
19#include <pcmcia/ds.h> 18#include <pcmcia/ds.h>
diff --git a/drivers/ssb/scan.c b/drivers/ssb/scan.c
index 9738cad4ba13..ee079ab9fb28 100644
--- a/drivers/ssb/scan.c
+++ b/drivers/ssb/scan.c
@@ -17,7 +17,6 @@
17#include <linux/pci.h> 17#include <linux/pci.h>
18#include <linux/io.h> 18#include <linux/io.h>
19 19
20#include <pcmcia/cs.h>
21#include <pcmcia/cistpl.h> 20#include <pcmcia/cistpl.h>
22#include <pcmcia/ds.h> 21#include <pcmcia/ds.h>
23 22
diff --git a/drivers/staging/batman-adv/hard-interface.c b/drivers/staging/batman-adv/hard-interface.c
index baa8b05b9e8d..6e973a79aa25 100644
--- a/drivers/staging/batman-adv/hard-interface.c
+++ b/drivers/staging/batman-adv/hard-interface.c
@@ -30,7 +30,6 @@
30#include "hash.h" 30#include "hash.h"
31 31
32#include <linux/if_arp.h> 32#include <linux/if_arp.h>
33#include <linux/netfilter_bridge.h>
34 33
35#define MIN(x, y) ((x) < (y) ? (x) : (y)) 34#define MIN(x, y) ((x) < (y) ? (x) : (y))
36 35
@@ -431,11 +430,6 @@ out:
431 return NOTIFY_DONE; 430 return NOTIFY_DONE;
432} 431}
433 432
434static int batman_skb_recv_finish(struct sk_buff *skb)
435{
436 return NF_ACCEPT;
437}
438
439/* receive a packet with the batman ethertype coming on a hard 433/* receive a packet with the batman ethertype coming on a hard
440 * interface */ 434 * interface */
441int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, 435int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
@@ -456,13 +450,6 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
456 if (atomic_read(&module_state) != MODULE_ACTIVE) 450 if (atomic_read(&module_state) != MODULE_ACTIVE)
457 goto err_free; 451 goto err_free;
458 452
459 /* if netfilter/ebtables wants to block incoming batman
460 * packets then give them a chance to do so here */
461 ret = NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, dev, NULL,
462 batman_skb_recv_finish);
463 if (ret != 1)
464 goto err_out;
465
466 /* packet should hold at least type and version */ 453 /* packet should hold at least type and version */
467 if (unlikely(skb_headlen(skb) < 2)) 454 if (unlikely(skb_headlen(skb) < 2))
468 goto err_free; 455 goto err_free;
diff --git a/drivers/staging/batman-adv/send.c b/drivers/staging/batman-adv/send.c
index 055edee7b4e4..da3c82e47bbd 100644
--- a/drivers/staging/batman-adv/send.c
+++ b/drivers/staging/batman-adv/send.c
@@ -29,7 +29,6 @@
29#include "vis.h" 29#include "vis.h"
30#include "aggregation.h" 30#include "aggregation.h"
31 31
32#include <linux/netfilter_bridge.h>
33 32
34static void send_outstanding_bcast_packet(struct work_struct *work); 33static void send_outstanding_bcast_packet(struct work_struct *work);
35 34
@@ -92,12 +91,9 @@ int send_skb_packet(struct sk_buff *skb,
92 91
93 /* dev_queue_xmit() returns a negative result on error. However on 92 /* dev_queue_xmit() returns a negative result on error. However on
94 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP 93 * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
95 * (which is > 0). This will not be treated as an error. 94 * (which is > 0). This will not be treated as an error. */
96 * Also, if netfilter/ebtables wants to block outgoing batman
97 * packets then giving them a chance to do so here */
98 95
99 return NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev, 96 return dev_queue_xmit(skb);
100 dev_queue_xmit);
101send_skb_err: 97send_skb_err:
102 kfree_skb(skb); 98 kfree_skb(skb);
103 return NET_XMIT_DROP; 99 return NET_XMIT_DROP;
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index f8ede1182ccc..0345b4caba73 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -37,7 +37,6 @@ Status: experimental
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39 39
40#include <pcmcia/cs.h>
41#include <pcmcia/cistpl.h> 40#include <pcmcia/cistpl.h>
42#include <pcmcia/ds.h> 41#include <pcmcia/ds.h>
43 42
@@ -692,10 +691,6 @@ static int das16cs_pcmcia_attach(struct pcmcia_device *link)
692 local->link = link; 691 local->link = link;
693 link->priv = local; 692 link->priv = local;
694 693
695 /* Initialize the pcmcia_device structure */
696 link->conf.Attributes = 0;
697 link->conf.IntType = INT_MEMORY_AND_IO;
698
699 cur_dev = link; 694 cur_dev = link;
700 695
701 das16cs_pcmcia_config(link); 696 das16cs_pcmcia_config(link);
@@ -715,37 +710,12 @@ static void das16cs_pcmcia_detach(struct pcmcia_device *link)
715 710
716 711
717static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev, 712static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev,
718 cistpl_cftable_entry_t *cfg,
719 cistpl_cftable_entry_t *dflt,
720 unsigned int vcc,
721 void *priv_data) 713 void *priv_data)
722{ 714{
723 if (cfg->index == 0) 715 if (p_dev->config_index == 0)
724 return -EINVAL; 716 return -EINVAL;
725 717
726 /* Do we need to allocate an interrupt? */ 718 return pcmcia_request_io(p_dev);
727 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
728
729 /* IO window settings */
730 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
731 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
732 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
733 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
734 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
735 p_dev->resource[0]->flags |=
736 pcmcia_io_cfg_data_width(io->flags);
737 p_dev->resource[0]->start = io->win[0].base;
738 p_dev->resource[0]->end = io->win[0].len;
739 if (io->nwin > 1) {
740 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
741 p_dev->resource[1]->start = io->win[1].base;
742 p_dev->resource[1]->end = io->win[1].len;
743 }
744 /* This reserves IO space but doesn't actually enable it */
745 return pcmcia_request_io(p_dev);
746 }
747
748 return 0;
749} 719}
750 720
751static void das16cs_pcmcia_config(struct pcmcia_device *link) 721static void das16cs_pcmcia_config(struct pcmcia_device *link)
@@ -754,6 +724,9 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link)
754 724
755 dev_dbg(&link->dev, "das16cs_pcmcia_config\n"); 725 dev_dbg(&link->dev, "das16cs_pcmcia_config\n");
756 726
727 /* Do we need to allocate an interrupt? */
728 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
729
757 ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL); 730 ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL);
758 if (ret) { 731 if (ret) {
759 dev_warn(&link->dev, "no configuration found\n"); 732 dev_warn(&link->dev, "no configuration found\n");
@@ -763,25 +736,10 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link)
763 if (!link->irq) 736 if (!link->irq)
764 goto failed; 737 goto failed;
765 738
766 /* 739 ret = pcmcia_enable_device(link);
767 This actually configures the PCMCIA socket -- setting up
768 the I/O windows and the interrupt mapping, and putting the
769 card and host interface into "Memory and IO" mode.
770 */
771 ret = pcmcia_request_configuration(link, &link->conf);
772 if (ret) 740 if (ret)
773 goto failed; 741 goto failed;
774 742
775 /* Finally, report what we've done */
776 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
777 if (link->conf.Attributes & CONF_ENABLE_IRQ)
778 printk(", irq %u", link->irq);
779 if (link->resource[0])
780 printk(", io %pR", link->resource[0]);
781 if (link->resource[1])
782 printk(", io %pR", link->resource[1]);
783 printk("\n");
784
785 return; 743 return;
786 744
787failed: 745failed:
@@ -832,9 +790,7 @@ struct pcmcia_driver das16cs_driver = {
832 .resume = das16cs_pcmcia_resume, 790 .resume = das16cs_pcmcia_resume,
833 .id_table = das16cs_id_table, 791 .id_table = das16cs_id_table,
834 .owner = THIS_MODULE, 792 .owner = THIS_MODULE,
835 .drv = { 793 .name = "cb_das16_cs",
836 .name = "cb_das16_cs",
837 },
838}; 794};
839 795
840static int __init init_das16cs_pcmcia_cs(void) 796static int __init init_das16cs_pcmcia_cs(void)
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c
index 48d9fb1227df..0b32a2df7768 100644
--- a/drivers/staging/comedi/drivers/das08_cs.c
+++ b/drivers/staging/comedi/drivers/das08_cs.c
@@ -48,7 +48,6 @@ Command support does not exist, but could be added for this board.
48#include "das08.h" 48#include "das08.h"
49 49
50/* pcmcia includes */ 50/* pcmcia includes */
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
54 53
@@ -115,40 +114,15 @@ static void das08_pcmcia_release(struct pcmcia_device *link);
115static int das08_pcmcia_suspend(struct pcmcia_device *p_dev); 114static int das08_pcmcia_suspend(struct pcmcia_device *p_dev);
116static int das08_pcmcia_resume(struct pcmcia_device *p_dev); 115static int das08_pcmcia_resume(struct pcmcia_device *p_dev);
117 116
118/*
119 The attach() and detach() entry points are used to create and destroy
120 "instances" of the driver, where each instance represents everything
121 needed to manage one actual PCMCIA card.
122*/
123
124static int das08_pcmcia_attach(struct pcmcia_device *); 117static int das08_pcmcia_attach(struct pcmcia_device *);
125static void das08_pcmcia_detach(struct pcmcia_device *); 118static void das08_pcmcia_detach(struct pcmcia_device *);
126 119
127/*
128 You'll also need to prototype all the functions that will actually
129 be used to talk to your device. See 'memory_cs' for a good example
130 of a fully self-sufficient driver; the other drivers rely more or
131 less on other parts of the kernel.
132*/
133
134struct local_info_t { 120struct local_info_t {
135 struct pcmcia_device *link; 121 struct pcmcia_device *link;
136 int stop; 122 int stop;
137 struct bus_operations *bus; 123 struct bus_operations *bus;
138}; 124};
139 125
140/*======================================================================
141
142 das08_pcmcia_attach() creates an "instance" of the driver, allocating
143 local data structures for one device. The device is registered
144 with Card Services.
145
146 The dev_link structure is initialized, but we don't actually
147 configure the card at this point -- we wait until we receive a
148 card insertion event.
149
150======================================================================*/
151
152static int das08_pcmcia_attach(struct pcmcia_device *link) 126static int das08_pcmcia_attach(struct pcmcia_device *link)
153{ 127{
154 struct local_info_t *local; 128 struct local_info_t *local;
@@ -162,16 +136,6 @@ static int das08_pcmcia_attach(struct pcmcia_device *link)
162 local->link = link; 136 local->link = link;
163 link->priv = local; 137 link->priv = local;
164 138
165 /*
166 General socket configuration defaults can go here. In this
167 client, we assume very little, and rely on the CIS for almost
168 everything. In most clients, many details (i.e., number, sizes,
169 and attributes of IO windows) are fixed by the nature of the
170 device, and can be hard-wired here.
171 */
172 link->conf.Attributes = 0;
173 link->conf.IntType = INT_MEMORY_AND_IO;
174
175 cur_dev = link; 139 cur_dev = link;
176 140
177 das08_pcmcia_config(link); 141 das08_pcmcia_config(link);
@@ -179,15 +143,6 @@ static int das08_pcmcia_attach(struct pcmcia_device *link)
179 return 0; 143 return 0;
180} /* das08_pcmcia_attach */ 144} /* das08_pcmcia_attach */
181 145
182/*======================================================================
183
184 This deletes a driver "instance". The device is de-registered
185 with Card Services. If it has been released, all local data
186 structures are freed. Otherwise, the structures will be freed
187 when the device is released.
188
189======================================================================*/
190
191static void das08_pcmcia_detach(struct pcmcia_device *link) 146static void das08_pcmcia_detach(struct pcmcia_device *link)
192{ 147{
193 148
@@ -203,46 +158,13 @@ static void das08_pcmcia_detach(struct pcmcia_device *link)
203 158
204 159
205static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev, 160static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
206 cistpl_cftable_entry_t *cfg,
207 cistpl_cftable_entry_t *dflt,
208 unsigned int vcc,
209 void *priv_data) 161 void *priv_data)
210{ 162{
211 if (cfg->index == 0) 163 if (p_dev->config_index == 0)
212 return -ENODEV; 164 return -EINVAL;
213
214 /* Do we need to allocate an interrupt? */
215 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
216
217 /* IO window settings */
218 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
219 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
220 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
221 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
222 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
223 p_dev->resource[0]->flags |=
224 pcmcia_io_cfg_data_width(io->flags);
225 p_dev->resource[0]->start = io->win[0].base;
226 p_dev->resource[0]->end = io->win[0].len;
227 if (io->nwin > 1) {
228 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
229 p_dev->resource[1]->start = io->win[1].base;
230 p_dev->resource[1]->end = io->win[1].len;
231 }
232 /* This reserves IO space but doesn't actually enable it */
233 return pcmcia_request_io(p_dev);
234 }
235 return 0;
236}
237
238
239/*======================================================================
240
241 das08_pcmcia_config() is scheduled to run after a CARD_INSERTION event
242 is received, to configure the PCMCIA socket, and to make the
243 device available to the system.
244 165
245======================================================================*/ 166 return pcmcia_request_io(p_dev);
167}
246 168
247static void das08_pcmcia_config(struct pcmcia_device *link) 169static void das08_pcmcia_config(struct pcmcia_device *link)
248{ 170{
@@ -250,6 +172,8 @@ static void das08_pcmcia_config(struct pcmcia_device *link)
250 172
251 dev_dbg(&link->dev, "das08_pcmcia_config\n"); 173 dev_dbg(&link->dev, "das08_pcmcia_config\n");
252 174
175 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
176
253 ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL); 177 ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL);
254 if (ret) { 178 if (ret) {
255 dev_warn(&link->dev, "no configuration found\n"); 179 dev_warn(&link->dev, "no configuration found\n");
@@ -259,25 +183,10 @@ static void das08_pcmcia_config(struct pcmcia_device *link)
259 if (!link->irq) 183 if (!link->irq)
260 goto failed; 184 goto failed;
261 185
262 /* 186 ret = pcmcia_enable_device(link);
263 This actually configures the PCMCIA socket -- setting up
264 the I/O windows and the interrupt mapping, and putting the
265 card and host interface into "Memory and IO" mode.
266 */
267 ret = pcmcia_request_configuration(link, &link->conf);
268 if (ret) 187 if (ret)
269 goto failed; 188 goto failed;
270 189
271 /* Finally, report what we've done */
272 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
273 if (link->conf.Attributes & CONF_ENABLE_IRQ)
274 printk(", irq %u", link->irq);
275 if (link->resource[0])
276 printk(", io %pR", link->resource[0]);
277 if (link->resource[1])
278 printk(" & %pR", link->resource[1]);
279 printk("\n");
280
281 return; 190 return;
282 191
283failed: 192failed:
@@ -285,32 +194,12 @@ failed:
285 194
286} /* das08_pcmcia_config */ 195} /* das08_pcmcia_config */
287 196
288/*======================================================================
289
290 After a card is removed, das08_pcmcia_release() will unregister the
291 device, and release the PCMCIA configuration. If the device is
292 still open, this will be postponed until it is closed.
293
294======================================================================*/
295
296static void das08_pcmcia_release(struct pcmcia_device *link) 197static void das08_pcmcia_release(struct pcmcia_device *link)
297{ 198{
298 dev_dbg(&link->dev, "das08_pcmcia_release\n"); 199 dev_dbg(&link->dev, "das08_pcmcia_release\n");
299 pcmcia_disable_device(link); 200 pcmcia_disable_device(link);
300} /* das08_pcmcia_release */ 201} /* das08_pcmcia_release */
301 202
302/*======================================================================
303
304 The card status event handler. Mostly, this schedules other
305 stuff to run after an event is received.
306
307 When a CARD_REMOVAL event is received, we immediately set a
308 private flag to block future accesses to this device. All the
309 functions that actually access the device should check this flag
310 to make sure the card is still present.
311
312======================================================================*/
313
314static int das08_pcmcia_suspend(struct pcmcia_device *link) 203static int das08_pcmcia_suspend(struct pcmcia_device *link)
315{ 204{
316 struct local_info_t *local = link->priv; 205 struct local_info_t *local = link->priv;
@@ -348,9 +237,7 @@ struct pcmcia_driver das08_cs_driver = {
348 .resume = das08_pcmcia_resume, 237 .resume = das08_pcmcia_resume,
349 .id_table = das08_cs_id_table, 238 .id_table = das08_cs_id_table,
350 .owner = THIS_MODULE, 239 .owner = THIS_MODULE,
351 .drv = { 240 .name = "pcm-das08",
352 .name = "pcm-das08",
353 },
354}; 241};
355 242
356static int __init init_das08_pcmcia_cs(void) 243static int __init init_das08_pcmcia_cs(void)
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index cc15666e5cc1..fc772a8a55c6 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -47,7 +47,6 @@ IRQ is assigned but not used.
47 47
48#include <linux/ioport.h> 48#include <linux/ioport.h>
49 49
50#include <pcmcia/cs.h>
51#include <pcmcia/cistpl.h> 50#include <pcmcia/cistpl.h>
52#include <pcmcia/cisreg.h> 51#include <pcmcia/cisreg.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
@@ -435,47 +434,20 @@ static int dio700_detach(struct comedi_device *dev)
435 return 0; 434 return 0;
436}; 435};
437 436
438/* PCMCIA crap -- watch your words, please! */
439
440static void dio700_config(struct pcmcia_device *link); 437static void dio700_config(struct pcmcia_device *link);
441static void dio700_release(struct pcmcia_device *link); 438static void dio700_release(struct pcmcia_device *link);
442static int dio700_cs_suspend(struct pcmcia_device *p_dev); 439static int dio700_cs_suspend(struct pcmcia_device *p_dev);
443static int dio700_cs_resume(struct pcmcia_device *p_dev); 440static int dio700_cs_resume(struct pcmcia_device *p_dev);
444 441
445/*
446 The attach() and detach() entry points are used to create and destroy
447 "instances" of the driver, where each instance represents everything
448 needed to manage one actual PCMCIA card.
449*/
450
451static int dio700_cs_attach(struct pcmcia_device *); 442static int dio700_cs_attach(struct pcmcia_device *);
452static void dio700_cs_detach(struct pcmcia_device *); 443static void dio700_cs_detach(struct pcmcia_device *);
453 444
454/*
455 You'll also need to prototype all the functions that will actually
456 be used to talk to your device. See 'memory_cs' for a good example
457 of a fully self-sufficient driver; the other drivers rely more or
458 less on other parts of the kernel.
459*/
460
461struct local_info_t { 445struct local_info_t {
462 struct pcmcia_device *link; 446 struct pcmcia_device *link;
463 int stop; 447 int stop;
464 struct bus_operations *bus; 448 struct bus_operations *bus;
465}; 449};
466 450
467/*======================================================================
468
469 dio700_cs_attach() creates an "instance" of the driver, allocating
470 local data structures for one device. The device is registered
471 with Card Services.
472
473 The dev_link structure is initialized, but we don't actually
474 configure the card at this point -- we wait until we receive a
475 card insertion event.
476
477======================================================================*/
478
479static int dio700_cs_attach(struct pcmcia_device *link) 451static int dio700_cs_attach(struct pcmcia_device *link)
480{ 452{
481 struct local_info_t *local; 453 struct local_info_t *local;
@@ -491,16 +463,6 @@ static int dio700_cs_attach(struct pcmcia_device *link)
491 local->link = link; 463 local->link = link;
492 link->priv = local; 464 link->priv = local;
493 465
494 /*
495 General socket configuration defaults can go here. In this
496 client, we assume very little, and rely on the CIS for almost
497 everything. In most clients, many details (i.e., number, sizes,
498 and attributes of IO windows) are fixed by the nature of the
499 device, and can be hard-wired here.
500 */
501 link->conf.Attributes = 0;
502 link->conf.IntType = INT_MEMORY_AND_IO;
503
504 pcmcia_cur_dev = link; 466 pcmcia_cur_dev = link;
505 467
506 dio700_config(link); 468 dio700_config(link);
@@ -508,15 +470,6 @@ static int dio700_cs_attach(struct pcmcia_device *link)
508 return 0; 470 return 0;
509} /* dio700_cs_attach */ 471} /* dio700_cs_attach */
510 472
511/*======================================================================
512
513 This deletes a driver "instance". The device is de-registered
514 with Card Services. If it has been released, all local data
515 structures are freed. Otherwise, the structures will be freed
516 when the device is released.
517
518======================================================================*/
519
520static void dio700_cs_detach(struct pcmcia_device *link) 473static void dio700_cs_detach(struct pcmcia_device *link)
521{ 474{
522 475
@@ -532,54 +485,13 @@ static void dio700_cs_detach(struct pcmcia_device *link)
532 485
533} /* dio700_cs_detach */ 486} /* dio700_cs_detach */
534 487
535/*======================================================================
536
537 dio700_config() is scheduled to run after a CARD_INSERTION event
538 is received, to configure the PCMCIA socket, and to make the
539 device available to the system.
540
541======================================================================*/
542
543static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev, 488static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev,
544 cistpl_cftable_entry_t *cfg,
545 cistpl_cftable_entry_t *dflt,
546 unsigned int vcc,
547 void *priv_data) 489 void *priv_data)
548{ 490{
549 if (cfg->index == 0) 491 if (p_dev->config_index == 0)
550 return -ENODEV; 492 return -EINVAL;
551
552 /* Does this card need audio output? */
553 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
554 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
555 p_dev->conf.Status = CCSR_AUDIO_ENA;
556 }
557
558 /* Do we need to allocate an interrupt? */
559 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
560
561 /* IO window settings */
562 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
563 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
564 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
565 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
566 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
567 p_dev->resource[0]->flags |=
568 pcmcia_io_cfg_data_width(io->flags);
569 p_dev->resource[0]->start = io->win[0].base;
570 p_dev->resource[0]->end = io->win[0].len;
571 if (io->nwin > 1) {
572 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
573 p_dev->resource[1]->start = io->win[1].base;
574 p_dev->resource[1]->end = io->win[1].len;
575 }
576 /* This reserves IO space but doesn't actually enable it */
577 if (pcmcia_request_io(p_dev) != 0)
578 return -ENODEV;
579 }
580 493
581 /* If we got this far, we're cool! */ 494 return pcmcia_request_io(p_dev);
582 return 0;
583} 495}
584 496
585static void dio700_config(struct pcmcia_device *link) 497static void dio700_config(struct pcmcia_device *link)
@@ -591,6 +503,9 @@ static void dio700_config(struct pcmcia_device *link)
591 503
592 dev_dbg(&link->dev, "dio700_config\n"); 504 dev_dbg(&link->dev, "dio700_config\n");
593 505
506 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
507 CONF_AUTO_SET_IO;
508
594 ret = pcmcia_loop_config(link, dio700_pcmcia_config_loop, NULL); 509 ret = pcmcia_loop_config(link, dio700_pcmcia_config_loop, NULL);
595 if (ret) { 510 if (ret) {
596 dev_warn(&link->dev, "no configuration found\n"); 511 dev_warn(&link->dev, "no configuration found\n");
@@ -600,25 +515,10 @@ static void dio700_config(struct pcmcia_device *link)
600 if (!link->irq) 515 if (!link->irq)
601 goto failed; 516 goto failed;
602 517
603 /* 518 ret = pcmcia_enable_device(link);
604 This actually configures the PCMCIA socket -- setting up
605 the I/O windows and the interrupt mapping, and putting the
606 card and host interface into "Memory and IO" mode.
607 */
608 ret = pcmcia_request_configuration(link, &link->conf);
609 if (ret != 0) 519 if (ret != 0)
610 goto failed; 520 goto failed;
611 521
612 /* Finally, report what we've done */
613 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
614 if (link->conf.Attributes & CONF_ENABLE_IRQ)
615 printk(", irq %d", link->irq);
616 if (link->resource[0])
617 printk(", io %pR", link->resource[0]);
618 if (link->resource[1])
619 printk(" & %pR", link->resource[1]);
620 printk("\n");
621
622 return; 522 return;
623 523
624failed: 524failed:
@@ -634,18 +534,6 @@ static void dio700_release(struct pcmcia_device *link)
634 pcmcia_disable_device(link); 534 pcmcia_disable_device(link);
635} /* dio700_release */ 535} /* dio700_release */
636 536
637/*======================================================================
638
639 The card status event handler. Mostly, this schedules other
640 stuff to run after an event is received.
641
642 When a CARD_REMOVAL event is received, we immediately set a
643 private flag to block future accesses to this device. All the
644 functions that actually access the device should check this flag
645 to make sure the card is still present.
646
647======================================================================*/
648
649static int dio700_cs_suspend(struct pcmcia_device *link) 537static int dio700_cs_suspend(struct pcmcia_device *link)
650{ 538{
651 struct local_info_t *local = link->priv; 539 struct local_info_t *local = link->priv;
@@ -685,9 +573,7 @@ struct pcmcia_driver dio700_cs_driver = {
685 .resume = dio700_cs_resume, 573 .resume = dio700_cs_resume,
686 .id_table = dio700_cs_ids, 574 .id_table = dio700_cs_ids,
687 .owner = THIS_MODULE, 575 .owner = THIS_MODULE,
688 .drv = { 576 .name = "ni_daq_700",
689 .name = "ni_daq_700",
690 },
691}; 577};
692 578
693static int __init init_dio700_cs(void) 579static int __init init_dio700_cs(void)
diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c
index 773ae2044e0e..c9c28584db67 100644
--- a/drivers/staging/comedi/drivers/ni_daq_dio24.c
+++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c
@@ -48,7 +48,6 @@ the PCMCIA interface.
48 48
49#include "8255.h" 49#include "8255.h"
50 50
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/cisreg.h> 52#include <pcmcia/cisreg.h>
54#include <pcmcia/ds.h> 53#include <pcmcia/ds.h>
@@ -187,47 +186,20 @@ static int dio24_detach(struct comedi_device *dev)
187 return 0; 186 return 0;
188}; 187};
189 188
190/* PCMCIA crap -- watch your words! */
191
192static void dio24_config(struct pcmcia_device *link); 189static void dio24_config(struct pcmcia_device *link);
193static void dio24_release(struct pcmcia_device *link); 190static void dio24_release(struct pcmcia_device *link);
194static int dio24_cs_suspend(struct pcmcia_device *p_dev); 191static int dio24_cs_suspend(struct pcmcia_device *p_dev);
195static int dio24_cs_resume(struct pcmcia_device *p_dev); 192static int dio24_cs_resume(struct pcmcia_device *p_dev);
196 193
197/*
198 The attach() and detach() entry points are used to create and destroy
199 "instances" of the driver, where each instance represents everything
200 needed to manage one actual PCMCIA card.
201*/
202
203static int dio24_cs_attach(struct pcmcia_device *); 194static int dio24_cs_attach(struct pcmcia_device *);
204static void dio24_cs_detach(struct pcmcia_device *); 195static void dio24_cs_detach(struct pcmcia_device *);
205 196
206/*
207 You'll also need to prototype all the functions that will actually
208 be used to talk to your device. See 'memory_cs' for a good example
209 of a fully self-sufficient driver; the other drivers rely more or
210 less on other parts of the kernel.
211*/
212
213struct local_info_t { 197struct local_info_t {
214 struct pcmcia_device *link; 198 struct pcmcia_device *link;
215 int stop; 199 int stop;
216 struct bus_operations *bus; 200 struct bus_operations *bus;
217}; 201};
218 202
219/*======================================================================
220
221 dio24_cs_attach() creates an "instance" of the driver, allocating
222 local data structures for one device. The device is registered
223 with Card Services.
224
225 The dev_link structure is initialized, but we don't actually
226 configure the card at this point -- we wait until we receive a
227 card insertion event.
228
229======================================================================*/
230
231static int dio24_cs_attach(struct pcmcia_device *link) 203static int dio24_cs_attach(struct pcmcia_device *link)
232{ 204{
233 struct local_info_t *local; 205 struct local_info_t *local;
@@ -243,16 +215,6 @@ static int dio24_cs_attach(struct pcmcia_device *link)
243 local->link = link; 215 local->link = link;
244 link->priv = local; 216 link->priv = local;
245 217
246 /*
247 General socket configuration defaults can go here. In this
248 client, we assume very little, and rely on the CIS for almost
249 everything. In most clients, many details (i.e., number, sizes,
250 and attributes of IO windows) are fixed by the nature of the
251 device, and can be hard-wired here.
252 */
253 link->conf.Attributes = 0;
254 link->conf.IntType = INT_MEMORY_AND_IO;
255
256 pcmcia_cur_dev = link; 218 pcmcia_cur_dev = link;
257 219
258 dio24_config(link); 220 dio24_config(link);
@@ -260,15 +222,6 @@ static int dio24_cs_attach(struct pcmcia_device *link)
260 return 0; 222 return 0;
261} /* dio24_cs_attach */ 223} /* dio24_cs_attach */
262 224
263/*======================================================================
264
265 This deletes a driver "instance". The device is de-registered
266 with Card Services. If it has been released, all local data
267 structures are freed. Otherwise, the structures will be freed
268 when the device is released.
269
270======================================================================*/
271
272static void dio24_cs_detach(struct pcmcia_device *link) 225static void dio24_cs_detach(struct pcmcia_device *link)
273{ 226{
274 227
@@ -284,54 +237,13 @@ static void dio24_cs_detach(struct pcmcia_device *link)
284 237
285} /* dio24_cs_detach */ 238} /* dio24_cs_detach */
286 239
287/*======================================================================
288
289 dio24_config() is scheduled to run after a CARD_INSERTION event
290 is received, to configure the PCMCIA socket, and to make the
291 device available to the system.
292
293======================================================================*/
294
295static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev, 240static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
296 cistpl_cftable_entry_t *cfg,
297 cistpl_cftable_entry_t *dflt,
298 unsigned int vcc,
299 void *priv_data) 241 void *priv_data)
300{ 242{
301 if (cfg->index == 0) 243 if (p_dev->config_index == 0)
302 return -ENODEV; 244 return -EINVAL;
303
304 /* Does this card need audio output? */
305 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
306 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
307 p_dev->conf.Status = CCSR_AUDIO_ENA;
308 }
309
310 /* Do we need to allocate an interrupt? */
311 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
312
313 /* IO window settings */
314 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
315 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
316 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
317 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
318 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
319 p_dev->resource[0]->flags |=
320 pcmcia_io_cfg_data_width(io->flags);
321 p_dev->resource[0]->start = io->win[0].base;
322 p_dev->resource[0]->end = io->win[0].len;
323 if (io->nwin > 1) {
324 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
325 p_dev->resource[1]->start = io->win[1].base;
326 p_dev->resource[1]->end = io->win[1].len;
327 }
328 /* This reserves IO space but doesn't actually enable it */
329 if (pcmcia_request_io(p_dev) != 0)
330 return -ENODEV;
331 }
332 245
333 /* If we got this far, we're cool! */ 246 return pcmcia_request_io(p_dev);
334 return 0;
335} 247}
336 248
337static void dio24_config(struct pcmcia_device *link) 249static void dio24_config(struct pcmcia_device *link)
@@ -342,6 +254,9 @@ static void dio24_config(struct pcmcia_device *link)
342 254
343 dev_dbg(&link->dev, "dio24_config\n"); 255 dev_dbg(&link->dev, "dio24_config\n");
344 256
257 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
258 CONF_AUTO_SET_IO;
259
345 ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL); 260 ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL);
346 if (ret) { 261 if (ret) {
347 dev_warn(&link->dev, "no configuration found\n"); 262 dev_warn(&link->dev, "no configuration found\n");
@@ -351,25 +266,10 @@ static void dio24_config(struct pcmcia_device *link)
351 if (!link->irq) 266 if (!link->irq)
352 goto failed; 267 goto failed;
353 268
354 /* 269 ret = pcmcia_enable_device(link);
355 This actually configures the PCMCIA socket -- setting up
356 the I/O windows and the interrupt mapping, and putting the
357 card and host interface into "Memory and IO" mode.
358 */
359 ret = pcmcia_request_configuration(link, &link->conf);
360 if (ret) 270 if (ret)
361 goto failed; 271 goto failed;
362 272
363 /* Finally, report what we've done */
364 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
365 if (link->conf.Attributes & CONF_ENABLE_IRQ)
366 printk(", irq %d", link->irq);
367 if (link->resource[0])
368 printk(" & %pR", link->resource[0]);
369 if (link->resource[1])
370 printk(" & %pR", link->resource[1]);
371 printk("\n");
372
373 return; 273 return;
374 274
375failed: 275failed:
@@ -385,18 +285,6 @@ static void dio24_release(struct pcmcia_device *link)
385 pcmcia_disable_device(link); 285 pcmcia_disable_device(link);
386} /* dio24_release */ 286} /* dio24_release */
387 287
388/*======================================================================
389
390 The card status event handler. Mostly, this schedules other
391 stuff to run after an event is received.
392
393 When a CARD_REMOVAL event is received, we immediately set a
394 private flag to block future accesses to this device. All the
395 functions that actually access the device should check this flag
396 to make sure the card is still present.
397
398======================================================================*/
399
400static int dio24_cs_suspend(struct pcmcia_device *link) 288static int dio24_cs_suspend(struct pcmcia_device *link)
401{ 289{
402 struct local_info_t *local = link->priv; 290 struct local_info_t *local = link->priv;
@@ -435,9 +323,7 @@ struct pcmcia_driver dio24_cs_driver = {
435 .resume = dio24_cs_resume, 323 .resume = dio24_cs_resume,
436 .id_table = dio24_cs_ids, 324 .id_table = dio24_cs_ids,
437 .owner = THIS_MODULE, 325 .owner = THIS_MODULE,
438 .drv = { 326 .name = "ni_daq_dio24",
439 .name = "ni_daq_dio24",
440 },
441}; 327};
442 328
443static int __init init_dio24_cs(void) 329static int __init init_dio24_cs(void)
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index 68c4ecbd93ae..6facbc8bf776 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -71,7 +71,6 @@ NI manuals:
71#include "comedi_fc.h" 71#include "comedi_fc.h"
72#include "ni_labpc.h" 72#include "ni_labpc.h"
73 73
74#include <pcmcia/cs.h>
75#include <pcmcia/cistpl.h> 74#include <pcmcia/cistpl.h>
76#include <pcmcia/cisreg.h> 75#include <pcmcia/cisreg.h>
77#include <pcmcia/ds.h> 76#include <pcmcia/ds.h>
@@ -153,59 +152,20 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
153 return labpc_common_attach(dev, iobase, irq, 0); 152 return labpc_common_attach(dev, iobase, irq, 0);
154} 153}
155 154
156/*====================================================================*/
157
158/*
159 The event() function is this driver's Card Services event handler.
160 It will be called by Card Services when an appropriate card status
161 event is received. The config() and release() entry points are
162 used to configure or release a socket, in response to card
163 insertion and ejection events. They are invoked from the dummy
164 event handler.
165
166 Kernel version 2.6.16 upwards uses suspend() and resume() functions
167 instead of an event() function.
168*/
169
170static void labpc_config(struct pcmcia_device *link); 155static void labpc_config(struct pcmcia_device *link);
171static void labpc_release(struct pcmcia_device *link); 156static void labpc_release(struct pcmcia_device *link);
172static int labpc_cs_suspend(struct pcmcia_device *p_dev); 157static int labpc_cs_suspend(struct pcmcia_device *p_dev);
173static int labpc_cs_resume(struct pcmcia_device *p_dev); 158static int labpc_cs_resume(struct pcmcia_device *p_dev);
174 159
175/*
176 The attach() and detach() entry points are used to create and destroy
177 "instances" of the driver, where each instance represents everything
178 needed to manage one actual PCMCIA card.
179*/
180
181static int labpc_cs_attach(struct pcmcia_device *); 160static int labpc_cs_attach(struct pcmcia_device *);
182static void labpc_cs_detach(struct pcmcia_device *); 161static void labpc_cs_detach(struct pcmcia_device *);
183 162
184/*
185 You'll also need to prototype all the functions that will actually
186 be used to talk to your device. See 'memory_cs' for a good example
187 of a fully self-sufficient driver; the other drivers rely more or
188 less on other parts of the kernel.
189*/
190
191struct local_info_t { 163struct local_info_t {
192 struct pcmcia_device *link; 164 struct pcmcia_device *link;
193 int stop; 165 int stop;
194 struct bus_operations *bus; 166 struct bus_operations *bus;
195}; 167};
196 168
197/*======================================================================
198
199 labpc_cs_attach() creates an "instance" of the driver, allocating
200 local data structures for one device. The device is registered
201 with Card Services.
202
203 The dev_link structure is initialized, but we don't actually
204 configure the card at this point -- we wait until we receive a
205 card insertion event.
206
207======================================================================*/
208
209static int labpc_cs_attach(struct pcmcia_device *link) 169static int labpc_cs_attach(struct pcmcia_device *link)
210{ 170{
211 struct local_info_t *local; 171 struct local_info_t *local;
@@ -219,16 +179,6 @@ static int labpc_cs_attach(struct pcmcia_device *link)
219 local->link = link; 179 local->link = link;
220 link->priv = local; 180 link->priv = local;
221 181
222 /*
223 General socket configuration defaults can go here. In this
224 client, we assume very little, and rely on the CIS for almost
225 everything. In most clients, many details (i.e., number, sizes,
226 and attributes of IO windows) are fixed by the nature of the
227 device, and can be hard-wired here.
228 */
229 link->conf.Attributes = 0;
230 link->conf.IntType = INT_MEMORY_AND_IO;
231
232 pcmcia_cur_dev = link; 182 pcmcia_cur_dev = link;
233 183
234 labpc_config(link); 184 labpc_config(link);
@@ -236,15 +186,6 @@ static int labpc_cs_attach(struct pcmcia_device *link)
236 return 0; 186 return 0;
237} /* labpc_cs_attach */ 187} /* labpc_cs_attach */
238 188
239/*======================================================================
240
241 This deletes a driver "instance". The device is de-registered
242 with Card Services. If it has been released, all local data
243 structures are freed. Otherwise, the structures will be freed
244 when the device is released.
245
246======================================================================*/
247
248static void labpc_cs_detach(struct pcmcia_device *link) 189static void labpc_cs_detach(struct pcmcia_device *link)
249{ 190{
250 dev_dbg(&link->dev, "labpc_cs_detach\n"); 191 dev_dbg(&link->dev, "labpc_cs_detach\n");
@@ -263,54 +204,13 @@ static void labpc_cs_detach(struct pcmcia_device *link)
263 204
264} /* labpc_cs_detach */ 205} /* labpc_cs_detach */
265 206
266/*======================================================================
267
268 labpc_config() is scheduled to run after a CARD_INSERTION event
269 is received, to configure the PCMCIA socket, and to make the
270 device available to the system.
271
272======================================================================*/
273
274static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev, 207static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
275 cistpl_cftable_entry_t *cfg,
276 cistpl_cftable_entry_t *dflt,
277 unsigned int vcc,
278 void *priv_data) 208 void *priv_data)
279{ 209{
280 if (cfg->index == 0) 210 if (p_dev->config_index == 0)
281 return -ENODEV; 211 return -EINVAL;
282
283 /* Does this card need audio output? */
284 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
285 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
286 p_dev->conf.Status = CCSR_AUDIO_ENA;
287 }
288
289 /* Do we need to allocate an interrupt? */
290 p_dev->conf.Attributes |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
291
292 /* IO window settings */
293 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
294 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
295 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
296 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
297 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
298 p_dev->resource[0]->flags |=
299 pcmcia_io_cfg_data_width(io->flags);
300 p_dev->resource[0]->start = io->win[0].base;
301 p_dev->resource[0]->end = io->win[0].len;
302 if (io->nwin > 1) {
303 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
304 p_dev->resource[1]->start = io->win[1].base;
305 p_dev->resource[1]->end = io->win[1].len;
306 }
307 /* This reserves IO space but doesn't actually enable it */
308 if (pcmcia_request_io(p_dev) != 0)
309 return -ENODEV;
310 }
311 212
312 /* If we got this far, we're cool! */ 213 return pcmcia_request_io(p_dev);
313 return 0;
314} 214}
315 215
316 216
@@ -320,6 +220,9 @@ static void labpc_config(struct pcmcia_device *link)
320 220
321 dev_dbg(&link->dev, "labpc_config\n"); 221 dev_dbg(&link->dev, "labpc_config\n");
322 222
223 link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ |
224 CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
225
323 ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL); 226 ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL);
324 if (ret) { 227 if (ret) {
325 dev_warn(&link->dev, "no configuration found\n"); 228 dev_warn(&link->dev, "no configuration found\n");
@@ -329,25 +232,10 @@ static void labpc_config(struct pcmcia_device *link)
329 if (!link->irq) 232 if (!link->irq)
330 goto failed; 233 goto failed;
331 234
332 /* 235 ret = pcmcia_enable_device(link);
333 This actually configures the PCMCIA socket -- setting up
334 the I/O windows and the interrupt mapping, and putting the
335 card and host interface into "Memory and IO" mode.
336 */
337 ret = pcmcia_request_configuration(link, &link->conf);
338 if (ret) 236 if (ret)
339 goto failed; 237 goto failed;
340 238
341 /* Finally, report what we've done */
342 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
343 if (link->conf.Attributes & CONF_ENABLE_IRQ)
344 printk(", irq %d", link->irq);
345 if (link->resource[0])
346 printk(" & %pR", link->resource[0]);
347 if (link->resource[1])
348 printk(" & %pR", link->resource[1]);
349 printk("\n");
350
351 return; 239 return;
352 240
353failed: 241failed:
@@ -362,18 +250,6 @@ static void labpc_release(struct pcmcia_device *link)
362 pcmcia_disable_device(link); 250 pcmcia_disable_device(link);
363} /* labpc_release */ 251} /* labpc_release */
364 252
365/*======================================================================
366
367 The card status event handler. Mostly, this schedules other
368 stuff to run after an event is received.
369
370 When a CARD_REMOVAL event is received, we immediately set a
371 private flag to block future accesses to this device. All the
372 functions that actually access the device should check this flag
373 to make sure the card is still present.
374
375======================================================================*/
376
377static int labpc_cs_suspend(struct pcmcia_device *link) 253static int labpc_cs_suspend(struct pcmcia_device *link)
378{ 254{
379 struct local_info_t *local = link->priv; 255 struct local_info_t *local = link->priv;
@@ -391,8 +267,6 @@ static int labpc_cs_resume(struct pcmcia_device *link)
391 return 0; 267 return 0;
392} /* labpc_cs_resume */ 268} /* labpc_cs_resume */
393 269
394/*====================================================================*/
395
396static struct pcmcia_device_id labpc_cs_ids[] = { 270static struct pcmcia_device_id labpc_cs_ids[] = {
397 /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */ 271 /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */
398 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ 272 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */
@@ -411,9 +285,7 @@ struct pcmcia_driver labpc_cs_driver = {
411 .resume = labpc_cs_resume, 285 .resume = labpc_cs_resume,
412 .id_table = labpc_cs_ids, 286 .id_table = labpc_cs_ids,
413 .owner = THIS_MODULE, 287 .owner = THIS_MODULE,
414 .drv = { 288 .name = "daqcard-1200",
415 .name = "daqcard-1200",
416 },
417}; 289};
418 290
419static int __init init_labpc_cs(void) 291static int __init init_labpc_cs(void)
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c
index 1f2426352eb5..49563273f605 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -48,7 +48,6 @@ See the notes in the ni_atmio.o driver.
48#include "ni_stc.h" 48#include "ni_stc.h"
49#include "8255.h" 49#include "8255.h"
50 50
51#include <pcmcia/cs.h>
52#include <pcmcia/cistpl.h> 51#include <pcmcia/cistpl.h>
53#include <pcmcia/ds.h> 52#include <pcmcia/ds.h>
54 53
@@ -263,11 +262,6 @@ static struct pcmcia_device *cur_dev = NULL;
263 262
264static int cs_attach(struct pcmcia_device *link) 263static int cs_attach(struct pcmcia_device *link)
265{ 264{
266 link->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
267 link->resource[0]->end = 16;
268 link->conf.Attributes = CONF_ENABLE_IRQ;
269 link->conf.IntType = INT_MEMORY_AND_IO;
270
271 cur_dev = link; 265 cur_dev = link;
272 266
273 mio_cs_config(link); 267 mio_cs_config(link);
@@ -301,16 +295,12 @@ static int mio_cs_resume(struct pcmcia_device *link)
301} 295}
302 296
303 297
304static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, 298static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
305 cistpl_cftable_entry_t *cfg,
306 cistpl_cftable_entry_t *dflt,
307 unsigned int vcc,
308 void *priv_data)
309{ 299{
310 int base, ret; 300 int base, ret;
311 301
312 p_dev->resource[0]->end = cfg->io.win[0].len; 302 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
313 p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK; 303 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_16;
314 304
315 for (base = 0x000; base < 0x400; base += 0x20) { 305 for (base = 0x000; base < 0x400; base += 0x20) {
316 p_dev->resource[0]->start = base; 306 p_dev->resource[0]->start = base;
@@ -327,6 +317,7 @@ static void mio_cs_config(struct pcmcia_device *link)
327 int ret; 317 int ret;
328 318
329 DPRINTK("mio_cs_config(link=%p)\n", link); 319 DPRINTK("mio_cs_config(link=%p)\n", link);
320 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
330 321
331 ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL); 322 ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL);
332 if (ret) { 323 if (ret) {
@@ -337,7 +328,7 @@ static void mio_cs_config(struct pcmcia_device *link)
337 if (!link->irq) 328 if (!link->irq)
338 dev_info(&link->dev, "no IRQ available\n"); 329 dev_info(&link->dev, "no IRQ available\n");
339 330
340 ret = pcmcia_request_configuration(link, &link->conf); 331 ret = pcmcia_enable_device(link);
341} 332}
342 333
343static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it) 334static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -446,9 +437,7 @@ struct pcmcia_driver ni_mio_cs_driver = {
446 .resume = &mio_cs_resume, 437 .resume = &mio_cs_resume,
447 .id_table = ni_mio_cs_ids, 438 .id_table = ni_mio_cs_ids,
448 .owner = THIS_MODULE, 439 .owner = THIS_MODULE,
449 .drv = { 440 .name = "ni_mio_cs",
450 .name = "ni_mio_cs",
451 },
452}; 441};
453 442
454int init_module(void) 443int init_module(void)
diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index bf489d7f4990..ebba9bb47777 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -50,7 +50,6 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308
50#include "../comedidev.h" 50#include "../comedidev.h"
51#include <linux/semaphore.h> 51#include <linux/semaphore.h>
52 52
53#include <pcmcia/cs.h>
54#include <pcmcia/cistpl.h> 53#include <pcmcia/cistpl.h>
55#include <pcmcia/cisreg.h> 54#include <pcmcia/cisreg.h>
56#include <pcmcia/ds.h> 55#include <pcmcia/ds.h>
@@ -969,43 +968,14 @@ static int daqp_detach(struct comedi_device *dev)
969 968
970======================================================================*/ 969======================================================================*/
971 970
972/*
973 The event() function is this driver's Card Services event handler.
974 It will be called by Card Services when an appropriate card status
975 event is received. The config() and release() entry points are
976 used to configure or release a socket, in response to card
977 insertion and ejection events.
978
979 Kernel version 2.6.16 upwards uses suspend() and resume() functions
980 instead of an event() function.
981*/
982
983static void daqp_cs_config(struct pcmcia_device *link); 971static void daqp_cs_config(struct pcmcia_device *link);
984static void daqp_cs_release(struct pcmcia_device *link); 972static void daqp_cs_release(struct pcmcia_device *link);
985static int daqp_cs_suspend(struct pcmcia_device *p_dev); 973static int daqp_cs_suspend(struct pcmcia_device *p_dev);
986static int daqp_cs_resume(struct pcmcia_device *p_dev); 974static int daqp_cs_resume(struct pcmcia_device *p_dev);
987 975
988/*
989 The attach() and detach() entry points are used to create and destroy
990 "instances" of the driver, where each instance represents everything
991 needed to manage one actual PCMCIA card.
992*/
993
994static int daqp_cs_attach(struct pcmcia_device *); 976static int daqp_cs_attach(struct pcmcia_device *);
995static void daqp_cs_detach(struct pcmcia_device *); 977static void daqp_cs_detach(struct pcmcia_device *);
996 978
997/*======================================================================
998
999 daqp_cs_attach() creates an "instance" of the driver, allocating
1000 local data structures for one device. The device is registered
1001 with Card Services.
1002
1003 The dev_link structure is initialized, but we don't actually
1004 configure the card at this point -- we wait until we receive a
1005 card insertion event.
1006
1007======================================================================*/
1008
1009static int daqp_cs_attach(struct pcmcia_device *link) 979static int daqp_cs_attach(struct pcmcia_device *link)
1010{ 980{
1011 struct local_info_t *local; 981 struct local_info_t *local;
@@ -1031,30 +1001,11 @@ static int daqp_cs_attach(struct pcmcia_device *link)
1031 local->link = link; 1001 local->link = link;
1032 link->priv = local; 1002 link->priv = local;
1033 1003
1034 /*
1035 General socket configuration defaults can go here. In this
1036 client, we assume very little, and rely on the CIS for almost
1037 everything. In most clients, many details (i.e., number, sizes,
1038 and attributes of IO windows) are fixed by the nature of the
1039 device, and can be hard-wired here.
1040 */
1041 link->conf.Attributes = 0;
1042 link->conf.IntType = INT_MEMORY_AND_IO;
1043
1044 daqp_cs_config(link); 1004 daqp_cs_config(link);
1045 1005
1046 return 0; 1006 return 0;
1047} /* daqp_cs_attach */ 1007} /* daqp_cs_attach */
1048 1008
1049/*======================================================================
1050
1051 This deletes a driver "instance". The device is de-registered
1052 with Card Services. If it has been released, all local data
1053 structures are freed. Otherwise, the structures will be freed
1054 when the device is released.
1055
1056======================================================================*/
1057
1058static void daqp_cs_detach(struct pcmcia_device *link) 1009static void daqp_cs_detach(struct pcmcia_device *link)
1059{ 1010{
1060 struct local_info_t *dev = link->priv; 1011 struct local_info_t *dev = link->priv;
@@ -1070,45 +1021,11 @@ static void daqp_cs_detach(struct pcmcia_device *link)
1070 1021
1071} /* daqp_cs_detach */ 1022} /* daqp_cs_detach */
1072 1023
1073/*====================================================================== 1024static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
1074
1075 daqp_cs_config() is scheduled to run after a CARD_INSERTION event
1076 is received, to configure the PCMCIA socket, and to make the
1077 device available to the system.
1078
1079======================================================================*/
1080
1081
1082static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev,
1083 cistpl_cftable_entry_t *cfg,
1084 cistpl_cftable_entry_t *dflt,
1085 unsigned int vcc,
1086 void *priv_data)
1087{ 1025{
1088 if (cfg->index == 0) 1026 if (p_dev->config_index == 0)
1089 return -ENODEV; 1027 return -EINVAL;
1090 1028
1091 /* Do we need to allocate an interrupt? */
1092 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
1093
1094 /* IO window settings */
1095 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
1096 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
1097 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
1098 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
1099 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
1100 p_dev->resource[0]->flags |=
1101 pcmcia_io_cfg_data_width(io->flags);
1102 p_dev->resource[0]->start = io->win[0].base;
1103 p_dev->resource[0]->end = io->win[0].len;
1104 if (io->nwin > 1) {
1105 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
1106 p_dev->resource[1]->start = io->win[1].base;
1107 p_dev->resource[1]->end = io->win[1].len;
1108 }
1109 }
1110
1111 /* This reserves IO space but doesn't actually enable it */
1112 return pcmcia_request_io(p_dev); 1029 return pcmcia_request_io(p_dev);
1113} 1030}
1114 1031
@@ -1118,6 +1035,8 @@ static void daqp_cs_config(struct pcmcia_device *link)
1118 1035
1119 dev_dbg(&link->dev, "daqp_cs_config\n"); 1036 dev_dbg(&link->dev, "daqp_cs_config\n");
1120 1037
1038 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
1039
1121 ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL); 1040 ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL);
1122 if (ret) { 1041 if (ret) {
1123 dev_warn(&link->dev, "no configuration found\n"); 1042 dev_warn(&link->dev, "no configuration found\n");
@@ -1128,25 +1047,10 @@ static void daqp_cs_config(struct pcmcia_device *link)
1128 if (ret) 1047 if (ret)
1129 goto failed; 1048 goto failed;
1130 1049
1131 /* 1050 ret = pcmcia_enable_device(link);
1132 This actually configures the PCMCIA socket -- setting up
1133 the I/O windows and the interrupt mapping, and putting the
1134 card and host interface into "Memory and IO" mode.
1135 */
1136 ret = pcmcia_request_configuration(link, &link->conf);
1137 if (ret) 1051 if (ret)
1138 goto failed; 1052 goto failed;
1139 1053
1140 /* Finally, report what we've done */
1141 dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
1142 if (link->conf.Attributes & CONF_ENABLE_IRQ)
1143 printk(", irq %u", link->irq);
1144 if (link->resource[0])
1145 printk(" & %pR", link->resource[0]);
1146 if (link->resource[1])
1147 printk(" & %pR", link->resource[1]);
1148 printk("\n");
1149
1150 return; 1054 return;
1151 1055
1152failed: 1056failed:
@@ -1161,18 +1065,6 @@ static void daqp_cs_release(struct pcmcia_device *link)
1161 pcmcia_disable_device(link); 1065 pcmcia_disable_device(link);
1162} /* daqp_cs_release */ 1066} /* daqp_cs_release */
1163 1067
1164/*======================================================================
1165
1166 The card status event handler. Mostly, this schedules other
1167 stuff to run after an event is received.
1168
1169 When a CARD_REMOVAL event is received, we immediately set a
1170 private flag to block future accesses to this device. All the
1171 functions that actually access the device should check this flag
1172 to make sure the card is still present.
1173
1174======================================================================*/
1175
1176static int daqp_cs_suspend(struct pcmcia_device *link) 1068static int daqp_cs_suspend(struct pcmcia_device *link)
1177{ 1069{
1178 struct local_info_t *local = link->priv; 1070 struct local_info_t *local = link->priv;
@@ -1212,9 +1104,7 @@ static struct pcmcia_driver daqp_cs_driver = {
1212 .resume = daqp_cs_resume, 1104 .resume = daqp_cs_resume,
1213 .id_table = daqp_cs_id_table, 1105 .id_table = daqp_cs_id_table,
1214 .owner = THIS_MODULE, 1106 .owner = THIS_MODULE,
1215 .drv = { 1107 .name = "quatech_daqp_cs",
1216 .name = "quatech_daqp_cs",
1217 },
1218}; 1108};
1219 1109
1220int __init init_module(void) 1110int __init init_module(void)
diff --git a/drivers/staging/cx25821/Kconfig b/drivers/staging/cx25821/Kconfig
index df7756a95fad..813cb355ac01 100644
--- a/drivers/staging/cx25821/Kconfig
+++ b/drivers/staging/cx25821/Kconfig
@@ -1,6 +1,7 @@
1config VIDEO_CX25821 1config VIDEO_CX25821
2 tristate "Conexant cx25821 support" 2 tristate "Conexant cx25821 support"
3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C && INPUT 3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C && INPUT
4 depends on BKL # please fix
4 select I2C_ALGOBIT 5 select I2C_ALGOBIT
5 select VIDEO_BTCX 6 select VIDEO_BTCX
6 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
diff --git a/drivers/staging/easycap/Kconfig b/drivers/staging/easycap/Kconfig
index bd96f39f2735..9d5fe4ddc30a 100644
--- a/drivers/staging/easycap/Kconfig
+++ b/drivers/staging/easycap/Kconfig
@@ -1,6 +1,7 @@
1config EASYCAP 1config EASYCAP
2 tristate "EasyCAP USB ID 05e1:0408 support" 2 tristate "EasyCAP USB ID 05e1:0408 support"
3 depends on USB && VIDEO_DEV 3 depends on USB && VIDEO_DEV
4 depends on BKL # please fix
4 5
5 ---help--- 6 ---help---
6 This is an integrated audio/video driver for EasyCAP cards with 7 This is an integrated audio/video driver for EasyCAP cards with
diff --git a/drivers/staging/go7007/Kconfig b/drivers/staging/go7007/Kconfig
index e47f683a323e..75fa46805527 100644
--- a/drivers/staging/go7007/Kconfig
+++ b/drivers/staging/go7007/Kconfig
@@ -1,6 +1,7 @@
1config VIDEO_GO7007 1config VIDEO_GO7007
2 tristate "WIS GO7007 MPEG encoder support" 2 tristate "WIS GO7007 MPEG encoder support"
3 depends on VIDEO_DEV && PCI && I2C && INPUT 3 depends on VIDEO_DEV && PCI && I2C && INPUT
4 depends on BKL # please fix
4 depends on SND 5 depends on SND
5 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
6 select VIDEO_IR 7 select VIDEO_IR
diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
index ff1d24720f11..8284297b30e9 100644
--- a/drivers/staging/hv/blkvsc_drv.c
+++ b/drivers/staging/hv/blkvsc_drv.c
@@ -25,7 +25,7 @@
25#include <linux/major.h> 25#include <linux/major.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/hdreg.h> 27#include <linux/hdreg.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <scsi/scsi.h> 30#include <scsi/scsi.h>
31#include <scsi/scsi_cmnd.h> 31#include <scsi/scsi_cmnd.h>
@@ -124,6 +124,7 @@ struct blkvsc_driver_context {
124}; 124};
125 125
126/* Static decl */ 126/* Static decl */
127static DEFINE_MUTEX(blkvsc_mutex);
127static int blkvsc_probe(struct device *dev); 128static int blkvsc_probe(struct device *dev);
128static int blkvsc_remove(struct device *device); 129static int blkvsc_remove(struct device *device);
129static void blkvsc_shutdown(struct device *device); 130static void blkvsc_shutdown(struct device *device);
@@ -1309,7 +1310,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1309 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1310 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1310 blkdev->gd->disk_name); 1311 blkdev->gd->disk_name);
1311 1312
1312 lock_kernel(); 1313 mutex_lock(&blkvsc_mutex);
1313 spin_lock(&blkdev->lock); 1314 spin_lock(&blkdev->lock);
1314 1315
1315 if (!blkdev->users && blkdev->device_type == DVD_TYPE) { 1316 if (!blkdev->users && blkdev->device_type == DVD_TYPE) {
@@ -1321,7 +1322,7 @@ static int blkvsc_open(struct block_device *bdev, fmode_t mode)
1321 blkdev->users++; 1322 blkdev->users++;
1322 1323
1323 spin_unlock(&blkdev->lock); 1324 spin_unlock(&blkdev->lock);
1324 unlock_kernel(); 1325 mutex_unlock(&blkvsc_mutex);
1325 return 0; 1326 return 0;
1326} 1327}
1327 1328
@@ -1332,7 +1333,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1332 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, 1333 DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users,
1333 blkdev->gd->disk_name); 1334 blkdev->gd->disk_name);
1334 1335
1335 lock_kernel(); 1336 mutex_lock(&blkvsc_mutex);
1336 spin_lock(&blkdev->lock); 1337 spin_lock(&blkdev->lock);
1337 if (blkdev->users == 1) { 1338 if (blkdev->users == 1) {
1338 spin_unlock(&blkdev->lock); 1339 spin_unlock(&blkdev->lock);
@@ -1343,7 +1344,7 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode)
1343 blkdev->users--; 1344 blkdev->users--;
1344 1345
1345 spin_unlock(&blkdev->lock); 1346 spin_unlock(&blkdev->lock);
1346 unlock_kernel(); 1347 mutex_unlock(&blkvsc_mutex);
1347 return 0; 1348 return 0;
1348} 1349}
1349 1350
diff --git a/drivers/staging/spectra/ffsport.c b/drivers/staging/spectra/ffsport.c
index fa21a0fd8e84..c7932da03c56 100644
--- a/drivers/staging/spectra/ffsport.c
+++ b/drivers/staging/spectra/ffsport.c
@@ -27,7 +27,6 @@
27#include <linux/kthread.h> 27#include <linux/kthread.h>
28#include <linux/log2.h> 28#include <linux/log2.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/smp_lock.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32 31
33/**** Helper functions used for Div, Remainder operation on u64 ****/ 32/**** Helper functions used for Div, Remainder operation on u64 ****/
@@ -590,14 +589,16 @@ int GLOB_SBD_ioctl(struct block_device *bdev, fmode_t mode,
590 return -ENOTTY; 589 return -ENOTTY;
591} 590}
592 591
592static DEFINE_MUTEX(ffsport_mutex);
593
593int GLOB_SBD_unlocked_ioctl(struct block_device *bdev, fmode_t mode, 594int GLOB_SBD_unlocked_ioctl(struct block_device *bdev, fmode_t mode,
594 unsigned int cmd, unsigned long arg) 595 unsigned int cmd, unsigned long arg)
595{ 596{
596 int ret; 597 int ret;
597 598
598 lock_kernel(); 599 mutex_lock(&ffsport_mutex);
599 ret = GLOB_SBD_ioctl(bdev, mode, cmd, arg); 600 ret = GLOB_SBD_ioctl(bdev, mode, cmd, arg);
600 unlock_kernel(); 601 mutex_unlock(&ffsport_mutex);
601 602
602 return ret; 603 return ret;
603} 604}
diff --git a/drivers/staging/ti-st/st.h b/drivers/staging/ti-st/st.h
index 9952579425b9..1b3060eb2921 100644
--- a/drivers/staging/ti-st/st.h
+++ b/drivers/staging/ti-st/st.h
@@ -80,5 +80,4 @@ struct st_proto_s {
80extern long st_register(struct st_proto_s *); 80extern long st_register(struct st_proto_s *);
81extern long st_unregister(enum proto_type); 81extern long st_unregister(enum proto_type);
82 82
83extern struct platform_device *st_get_plat_device(void);
84#endif /* ST_H */ 83#endif /* ST_H */
diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
index 063c9b1db1ab..b85d8bfdf600 100644
--- a/drivers/staging/ti-st/st_core.c
+++ b/drivers/staging/ti-st/st_core.c
@@ -38,7 +38,6 @@
38#include "st_ll.h" 38#include "st_ll.h"
39#include "st.h" 39#include "st.h"
40 40
41#define VERBOSE
42/* strings to be used for rfkill entries and by 41/* strings to be used for rfkill entries and by
43 * ST Core to be used for sysfs debug entry 42 * ST Core to be used for sysfs debug entry
44 */ 43 */
@@ -581,7 +580,7 @@ long st_register(struct st_proto_s *new_proto)
581 long err = 0; 580 long err = 0;
582 unsigned long flags = 0; 581 unsigned long flags = 0;
583 582
584 st_kim_ref(&st_gdata); 583 st_kim_ref(&st_gdata, 0);
585 pr_info("%s(%d) ", __func__, new_proto->type); 584 pr_info("%s(%d) ", __func__, new_proto->type);
586 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL 585 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
587 || new_proto->reg_complete_cb == NULL) { 586 || new_proto->reg_complete_cb == NULL) {
@@ -713,7 +712,7 @@ long st_unregister(enum proto_type type)
713 712
714 pr_debug("%s: %d ", __func__, type); 713 pr_debug("%s: %d ", __func__, type);
715 714
716 st_kim_ref(&st_gdata); 715 st_kim_ref(&st_gdata, 0);
717 if (type < ST_BT || type >= ST_MAX) { 716 if (type < ST_BT || type >= ST_MAX) {
718 pr_err(" protocol %d not supported", type); 717 pr_err(" protocol %d not supported", type);
719 return -EPROTONOSUPPORT; 718 return -EPROTONOSUPPORT;
@@ -767,7 +766,7 @@ long st_write(struct sk_buff *skb)
767#endif 766#endif
768 long len; 767 long len;
769 768
770 st_kim_ref(&st_gdata); 769 st_kim_ref(&st_gdata, 0);
771 if (unlikely(skb == NULL || st_gdata == NULL 770 if (unlikely(skb == NULL || st_gdata == NULL
772 || st_gdata->tty == NULL)) { 771 || st_gdata->tty == NULL)) {
773 pr_err("data/tty unavailable to perform write"); 772 pr_err("data/tty unavailable to perform write");
@@ -818,7 +817,7 @@ static int st_tty_open(struct tty_struct *tty)
818 struct st_data_s *st_gdata; 817 struct st_data_s *st_gdata;
819 pr_info("%s ", __func__); 818 pr_info("%s ", __func__);
820 819
821 st_kim_ref(&st_gdata); 820 st_kim_ref(&st_gdata, 0);
822 st_gdata->tty = tty; 821 st_gdata->tty = tty;
823 tty->disc_data = st_gdata; 822 tty->disc_data = st_gdata;
824 823
diff --git a/drivers/staging/ti-st/st_core.h b/drivers/staging/ti-st/st_core.h
index e0c32d149f5f..8601320a679e 100644
--- a/drivers/staging/ti-st/st_core.h
+++ b/drivers/staging/ti-st/st_core.h
@@ -117,7 +117,7 @@ int st_core_init(struct st_data_s **);
117void st_core_exit(struct st_data_s *); 117void st_core_exit(struct st_data_s *);
118 118
119/* ask for reference from KIM */ 119/* ask for reference from KIM */
120void st_kim_ref(struct st_data_s **); 120void st_kim_ref(struct st_data_s **, int);
121 121
122#define GPS_STUB_TEST 122#define GPS_STUB_TEST
123#ifdef GPS_STUB_TEST 123#ifdef GPS_STUB_TEST
diff --git a/drivers/staging/ti-st/st_kim.c b/drivers/staging/ti-st/st_kim.c
index b4a6c7fdc4e6..9e99463f76e8 100644
--- a/drivers/staging/ti-st/st_kim.c
+++ b/drivers/staging/ti-st/st_kim.c
@@ -72,11 +72,26 @@ const unsigned char *protocol_names[] = {
72 PROTO_ENTRY(ST_GPS, "GPS"), 72 PROTO_ENTRY(ST_GPS, "GPS"),
73}; 73};
74 74
75#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
76struct platform_device *st_kim_devices[MAX_ST_DEVICES];
75 77
76/**********************************************************************/ 78/**********************************************************************/
77/* internal functions */ 79/* internal functions */
78 80
79/** 81/**
82 * st_get_plat_device -
83 * function which returns the reference to the platform device
84 * requested by id. As of now only 1 such device exists (id=0)
85 * the context requesting for reference can get the id to be
86 * requested by a. The protocol driver which is registering or
87 * b. the tty device which is opened.
88 */
89static struct platform_device *st_get_plat_device(int id)
90{
91 return st_kim_devices[id];
92}
93
94/**
80 * validate_firmware_response - 95 * validate_firmware_response -
81 * function to return whether the firmware response was proper 96 * function to return whether the firmware response was proper
82 * in case of error don't complete so that waiting for proper 97 * in case of error don't complete so that waiting for proper
@@ -353,7 +368,7 @@ void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
353 struct kim_data_s *kim_gdata; 368 struct kim_data_s *kim_gdata;
354 pr_info(" %s ", __func__); 369 pr_info(" %s ", __func__);
355 370
356 kim_pdev = st_get_plat_device(); 371 kim_pdev = st_get_plat_device(0);
357 kim_gdata = dev_get_drvdata(&kim_pdev->dev); 372 kim_gdata = dev_get_drvdata(&kim_pdev->dev);
358 373
359 if (kim_gdata->gpios[type] == -1) { 374 if (kim_gdata->gpios[type] == -1) {
@@ -574,12 +589,12 @@ static int kim_toggle_radio(void *data, bool blocked)
574 * This would enable multiple such platform devices to exist 589 * This would enable multiple such platform devices to exist
575 * on a given platform 590 * on a given platform
576 */ 591 */
577void st_kim_ref(struct st_data_s **core_data) 592void st_kim_ref(struct st_data_s **core_data, int id)
578{ 593{
579 struct platform_device *pdev; 594 struct platform_device *pdev;
580 struct kim_data_s *kim_gdata; 595 struct kim_data_s *kim_gdata;
581 /* get kim_gdata reference from platform device */ 596 /* get kim_gdata reference from platform device */
582 pdev = st_get_plat_device(); 597 pdev = st_get_plat_device(id);
583 kim_gdata = dev_get_drvdata(&pdev->dev); 598 kim_gdata = dev_get_drvdata(&pdev->dev);
584 *core_data = kim_gdata->core_data; 599 *core_data = kim_gdata->core_data;
585} 600}
@@ -623,6 +638,7 @@ static int kim_probe(struct platform_device *pdev)
623 long *gpios = pdev->dev.platform_data; 638 long *gpios = pdev->dev.platform_data;
624 struct kim_data_s *kim_gdata; 639 struct kim_data_s *kim_gdata;
625 640
641 st_kim_devices[pdev->id] = pdev;
626 kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC); 642 kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC);
627 if (!kim_gdata) { 643 if (!kim_gdata) {
628 pr_err("no mem to allocate"); 644 pr_err("no mem to allocate");
diff --git a/drivers/staging/tm6000/Kconfig b/drivers/staging/tm6000/Kconfig
index c725356cc346..de7ebb99d8f6 100644
--- a/drivers/staging/tm6000/Kconfig
+++ b/drivers/staging/tm6000/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_TM6000 1config VIDEO_TM6000
2 tristate "TV Master TM5600/6000/6010 driver" 2 tristate "TV Master TM5600/6000/6010 driver"
3 depends on VIDEO_DEV && I2C && INPUT && USB && EXPERIMENTAL 3 depends on VIDEO_DEV && I2C && INPUT && IR_CORE && USB && EXPERIMENTAL
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select MEDIA_TUNER_XC2028 5 select MEDIA_TUNER_XC2028
6 select MEDIA_TUNER_XC5000 6 select MEDIA_TUNER_XC5000
diff --git a/drivers/staging/tm6000/tm6000-input.c b/drivers/staging/tm6000/tm6000-input.c
index 32f7a0af6938..54f7667cc706 100644
--- a/drivers/staging/tm6000/tm6000-input.c
+++ b/drivers/staging/tm6000/tm6000-input.c
@@ -46,7 +46,7 @@ MODULE_PARM_DESC(enable_ir, "enable ir (default is enable");
46 } 46 }
47 47
48struct tm6000_ir_poll_result { 48struct tm6000_ir_poll_result {
49 u8 rc_data[4]; 49 u16 rc_data;
50}; 50};
51 51
52struct tm6000_IR { 52struct tm6000_IR {
@@ -60,9 +60,9 @@ struct tm6000_IR {
60 int polling; 60 int polling;
61 struct delayed_work work; 61 struct delayed_work work;
62 u8 wait:1; 62 u8 wait:1;
63 u8 key:1;
63 struct urb *int_urb; 64 struct urb *int_urb;
64 u8 *urb_data; 65 u8 *urb_data;
65 u8 key:1;
66 66
67 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *); 67 int (*get_key) (struct tm6000_IR *, struct tm6000_ir_poll_result *);
68 68
@@ -122,13 +122,14 @@ static void tm6000_ir_urb_received(struct urb *urb)
122 122
123 if (urb->status != 0) 123 if (urb->status != 0)
124 printk(KERN_INFO "not ready\n"); 124 printk(KERN_INFO "not ready\n");
125 else if (urb->actual_length > 0) 125 else if (urb->actual_length > 0) {
126 memcpy(ir->urb_data, urb->transfer_buffer, urb->actual_length); 126 memcpy(ir->urb_data, urb->transfer_buffer, urb->actual_length);
127 127
128 dprintk("data %02x %02x %02x %02x\n", ir->urb_data[0], 128 dprintk("data %02x %02x %02x %02x\n", ir->urb_data[0],
129 ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]); 129 ir->urb_data[1], ir->urb_data[2], ir->urb_data[3]);
130 130
131 ir->key = 1; 131 ir->key = 1;
132 }
132 133
133 rc = usb_submit_urb(urb, GFP_ATOMIC); 134 rc = usb_submit_urb(urb, GFP_ATOMIC);
134} 135}
@@ -140,30 +141,47 @@ static int default_polling_getkey(struct tm6000_IR *ir,
140 int rc; 141 int rc;
141 u8 buf[2]; 142 u8 buf[2];
142 143
143 if (ir->wait && !&dev->int_in) { 144 if (ir->wait && !&dev->int_in)
144 poll_result->rc_data[0] = 0xff;
145 return 0; 145 return 0;
146 }
147 146
148 if (&dev->int_in) { 147 if (&dev->int_in) {
149 poll_result->rc_data[0] = ir->urb_data[0]; 148 if (ir->ir.ir_type == IR_TYPE_RC5)
150 poll_result->rc_data[1] = ir->urb_data[1]; 149 poll_result->rc_data = ir->urb_data[0];
150 else
151 poll_result->rc_data = ir->urb_data[0] | ir->urb_data[1] << 8;
151 } else { 152 } else {
152 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0); 153 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 0);
153 msleep(10); 154 msleep(10);
154 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1); 155 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT, 2, 1);
155 msleep(10); 156 msleep(10);
156 157
157 rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | 158 if (ir->ir.ir_type == IR_TYPE_RC5) {
158 USB_RECIP_DEVICE, REQ_02_GET_IR_CODE, 0, 0, buf, 1); 159 rc = tm6000_read_write_usb(dev, USB_DIR_IN |
160 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
161 REQ_02_GET_IR_CODE, 0, 0, buf, 1);
159 162
160 msleep(10); 163 msleep(10);
161 164
162 dprintk("read data=%02x\n", buf[0]); 165 dprintk("read data=%02x\n", buf[0]);
163 if (rc < 0) 166 if (rc < 0)
164 return rc; 167 return rc;
165 168
166 poll_result->rc_data[0] = buf[0]; 169 poll_result->rc_data = buf[0];
170 } else {
171 rc = tm6000_read_write_usb(dev, USB_DIR_IN |
172 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
173 REQ_02_GET_IR_CODE, 0, 0, buf, 2);
174
175 msleep(10);
176
177 dprintk("read data=%04x\n", buf[0] | buf[1] << 8);
178 if (rc < 0)
179 return rc;
180
181 poll_result->rc_data = buf[0] | buf[1] << 8;
182 }
183 if ((poll_result->rc_data & 0x00ff) != 0xff)
184 ir->key = 1;
167 } 185 }
168 return 0; 186 return 0;
169} 187}
@@ -180,12 +198,11 @@ static void tm6000_ir_handle_key(struct tm6000_IR *ir)
180 return; 198 return;
181 } 199 }
182 200
183 dprintk("ir->get_key result data=%02x %02x\n", 201 dprintk("ir->get_key result data=%04x\n", poll_result.rc_data);
184 poll_result.rc_data[0], poll_result.rc_data[1]);
185 202
186 if (poll_result.rc_data[0] != 0xff && ir->key == 1) { 203 if (ir->key) {
187 ir_input_keydown(ir->input->input_dev, &ir->ir, 204 ir_input_keydown(ir->input->input_dev, &ir->ir,
188 poll_result.rc_data[0] | poll_result.rc_data[1] << 8); 205 (u32)poll_result.rc_data);
189 206
190 ir_input_nokey(ir->input->input_dev, &ir->ir); 207 ir_input_nokey(ir->input->input_dev, &ir->ir);
191 ir->key = 0; 208 ir->key = 0;
diff --git a/drivers/staging/usbip/Kconfig b/drivers/staging/usbip/Kconfig
index 2c1d10acb8b5..b11ec379b5c2 100644
--- a/drivers/staging/usbip/Kconfig
+++ b/drivers/staging/usbip/Kconfig
@@ -1,6 +1,6 @@
1config USB_IP_COMMON 1config USB_IP_COMMON
2 tristate "USB IP support (EXPERIMENTAL)" 2 tristate "USB IP support (EXPERIMENTAL)"
3 depends on USB && NET && EXPERIMENTAL 3 depends on USB && NET && EXPERIMENTAL && BKL
4 default N 4 default N
5 ---help--- 5 ---help---
6 This enables pushing USB packets over IP to allow remote 6 This enables pushing USB packets over IP to allow remote
diff --git a/drivers/staging/vt6655/wpactl.c b/drivers/staging/vt6655/wpactl.c
index 0142338bcafe..4bdb8362de82 100644
--- a/drivers/staging/vt6655/wpactl.c
+++ b/drivers/staging/vt6655/wpactl.c
@@ -766,9 +766,14 @@ static int wpa_set_associate(PSDevice pDevice,
766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len); 766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
767 767
768 768
769 if (param->u.wpa_associate.wpa_ie && 769 if (param->u.wpa_associate.wpa_ie_len) {
770 copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len)) 770 if (!param->u.wpa_associate.wpa_ie)
771 return -EINVAL; 771 return -EINVAL;
772 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
773 return -EINVAL;
774 if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
775 return -EFAULT;
776 }
772 777
773 if (param->u.wpa_associate.mode == 1) 778 if (param->u.wpa_associate.mode == 1)
774 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; 779 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
diff --git a/drivers/staging/wlags49_h2/wl_cs.c b/drivers/staging/wlags49_h2/wl_cs.c
index 19c335458653..6555891e149c 100644
--- a/drivers/staging/wlags49_h2/wl_cs.c
+++ b/drivers/staging/wlags49_h2/wl_cs.c
@@ -83,7 +83,6 @@
83#include <linux/if_arp.h> 83#include <linux/if_arp.h>
84#include <linux/ioport.h> 84#include <linux/ioport.h>
85 85
86#include <pcmcia/cs.h>
87#include <pcmcia/cistpl.h> 86#include <pcmcia/cistpl.h>
88#include <pcmcia/cisreg.h> 87#include <pcmcia/cisreg.h>
89#include <pcmcia/ciscode.h> 88#include <pcmcia/ciscode.h>
@@ -147,10 +146,9 @@ static int wl_adapter_attach(struct pcmcia_device *link)
147 146
148 link->resource[0]->end = HCF_NUM_IO_PORTS; 147 link->resource[0]->end = HCF_NUM_IO_PORTS;
149 link->resource[0]->flags= IO_DATA_PATH_WIDTH_16; 148 link->resource[0]->flags= IO_DATA_PATH_WIDTH_16;
150 link->conf.Attributes = CONF_ENABLE_IRQ; 149 link->config_flags |= CONF_ENABLE_IRQ;
151 link->conf.IntType = INT_MEMORY_AND_IO; 150 link->config_index = 5;
152 link->conf.ConfigIndex = 5; 151 link->config_regs = PRESENT_OPTION;
153 link->conf.Present = PRESENT_OPTION;
154 152
155 link->priv = dev; 153 link->priv = dev;
156 lp = wl_priv(dev); 154 lp = wl_priv(dev);
@@ -165,27 +163,6 @@ static int wl_adapter_attach(struct pcmcia_device *link)
165 163
166 164
167 165
168/*******************************************************************************
169 * wl_adapter_detach()
170 *******************************************************************************
171 *
172 * DESCRIPTION:
173 *
174 * This deletes a driver "instance". The device is de-registered with Card
175 * Services. If it has been released, then the net device is unregistered, and
176 * all local data structures are freed. Otherwise, the structures will be
177 * freed when the device is released.
178 *
179 * PARAMETERS:
180 *
181 * link - pointer to the dev_link_t structure representing the device to
182 * detach
183 *
184 * RETURNS:
185 *
186 * N/A
187 *
188 ******************************************************************************/
189static void wl_adapter_detach(struct pcmcia_device *link) 166static void wl_adapter_detach(struct pcmcia_device *link)
190{ 167{
191 struct net_device *dev = link->priv; 168 struct net_device *dev = link->priv;
@@ -209,26 +186,6 @@ static void wl_adapter_detach(struct pcmcia_device *link)
209/*============================================================================*/ 186/*============================================================================*/
210 187
211 188
212/*******************************************************************************
213 * wl_adapter_release()
214 *******************************************************************************
215 *
216 * DESCRIPTION:
217 *
218 * After a card is removed, this routine will release the PCMCIA
219 * configuration. If the device is still open, this will be postponed until it
220 * is closed.
221 *
222 * PARAMETERS:
223 *
224 * arg - a u_long representing a pointer to a dev_link_t structure for the
225 * device to be released.
226 *
227 * RETURNS:
228 *
229 * N/A
230 *
231 ******************************************************************************/
232void wl_adapter_release(struct pcmcia_device *link) 189void wl_adapter_release(struct pcmcia_device *link)
233{ 190{
234 DBG_FUNC("wl_adapter_release"); 191 DBG_FUNC("wl_adapter_release");
@@ -268,26 +225,6 @@ static int wl_adapter_resume(struct pcmcia_device *link)
268 return 0; 225 return 0;
269} /* wl_adapter_resume */ 226} /* wl_adapter_resume */
270 227
271/*******************************************************************************
272 * wl_adapter_insert()
273 *******************************************************************************
274 *
275 * DESCRIPTION:
276 *
277 * wl_adapter_insert() is scheduled to run after a CARD_INSERTION event is
278 * received, to configure the PCMCIA socket, and to make the ethernet device
279 * available to the system.
280 *
281 * PARAMETERS:
282 *
283 * link - pointer to the dev_link_t structure representing the device to
284 * insert
285 *
286 * RETURNS:
287 *
288 * N/A
289 *
290 ******************************************************************************/
291void wl_adapter_insert(struct pcmcia_device *link) 228void wl_adapter_insert(struct pcmcia_device *link)
292{ 229{
293 struct net_device *dev; 230 struct net_device *dev;
@@ -302,7 +239,7 @@ void wl_adapter_insert(struct pcmcia_device *link)
302 dev = link->priv; 239 dev = link->priv;
303 240
304 /* Do we need to allocate an interrupt? */ 241 /* Do we need to allocate an interrupt? */
305 link->conf.Attributes |= CONF_ENABLE_IRQ; 242 link->config_flags |= CONF_ENABLE_IRQ;
306 link->io_lines = 6; 243 link->io_lines = 6;
307 244
308 ret = pcmcia_request_io(link); 245 ret = pcmcia_request_io(link);
@@ -313,7 +250,7 @@ void wl_adapter_insert(struct pcmcia_device *link)
313 if (ret != 0) 250 if (ret != 0)
314 goto failed; 251 goto failed;
315 252
316 ret = pcmcia_request_configuration(link, &link->conf); 253 ret = pcmcia_enable_device(link);
317 if (ret != 0) 254 if (ret != 0)
318 goto failed; 255 goto failed;
319 256
@@ -457,9 +394,7 @@ MODULE_DEVICE_TABLE(pcmcia, wl_adapter_ids);
457 394
458static struct pcmcia_driver wlags49_driver = { 395static struct pcmcia_driver wlags49_driver = {
459 .owner = THIS_MODULE, 396 .owner = THIS_MODULE,
460 .drv = { 397 .name = DRIVER_NAME,
461 .name = DRIVER_NAME,
462 },
463 .probe = wl_adapter_attach, 398 .probe = wl_adapter_attach,
464 .remove = wl_adapter_detach, 399 .remove = wl_adapter_detach,
465 .id_table = wl_adapter_ids, 400 .id_table = wl_adapter_ids,
diff --git a/drivers/staging/wlags49_h2/wl_internal.h b/drivers/staging/wlags49_h2/wl_internal.h
index 02f0a20e178a..cd129b3ee6c0 100644
--- a/drivers/staging/wlags49_h2/wl_internal.h
+++ b/drivers/staging/wlags49_h2/wl_internal.h
@@ -69,7 +69,6 @@
69 ******************************************************************************/ 69 ******************************************************************************/
70#include <linux/version.h> 70#include <linux/version.h>
71#ifdef BUS_PCMCIA 71#ifdef BUS_PCMCIA
72#include <pcmcia/cs.h>
73#include <pcmcia/cistpl.h> 72#include <pcmcia/cistpl.h>
74#include <pcmcia/cisreg.h> 73#include <pcmcia/cisreg.h>
75#include <pcmcia/ciscode.h> 74#include <pcmcia/ciscode.h>
diff --git a/drivers/staging/wlags49_h2/wl_main.c b/drivers/staging/wlags49_h2/wl_main.c
index 88d0d472142f..8e3536acbf46 100644
--- a/drivers/staging/wlags49_h2/wl_main.c
+++ b/drivers/staging/wlags49_h2/wl_main.c
@@ -414,25 +414,6 @@ extern memimage fw_image; // firmware image to be downloaded
414#endif /* HCF_STA */ 414#endif /* HCF_STA */
415 415
416 416
417/*******************************************************************************
418 * wl_insert()
419 *******************************************************************************
420 *
421 * DESCRIPTION:
422 *
423 * wl_insert() is scheduled to run after a CARD_INSERTION event is
424 * received, to configure the PCMCIA socket, and to make the ethernet device
425 * available to the system.
426 *
427 * PARAMETERS:
428 *
429 * dev - a pointer to the net_device struct of the wireless device
430 *
431 * RETURNS:
432 *
433 * TRUE or FALSE
434 *
435 ******************************************************************************/
436int wl_insert( struct net_device *dev ) 417int wl_insert( struct net_device *dev )
437{ 418{
438 int result = 0; 419 int result = 0;
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index 5c6239e5aa21..0d236f4bb8c2 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -257,7 +257,7 @@
257#include <linux/fs.h> /* everything... */ 257#include <linux/fs.h> /* everything... */
258#include <linux/errno.h> /* error codes */ 258#include <linux/errno.h> /* error codes */
259#include <linux/slab.h> 259#include <linux/slab.h>
260#include <linux/smp_lock.h> 260#include <linux/mutex.h>
261#include <linux/mm.h> 261#include <linux/mm.h>
262#include <linux/ioport.h> 262#include <linux/ioport.h>
263#include <linux/interrupt.h> 263#include <linux/interrupt.h>
@@ -277,6 +277,7 @@
277#define TYPE(inode) (iminor(inode) >> 4) 277#define TYPE(inode) (iminor(inode) >> 4)
278#define NUM(inode) (iminor(inode) & 0xf) 278#define NUM(inode) (iminor(inode) & 0xf)
279 279
280static DEFINE_MUTEX(ixj_mutex);
280static int ixjdebug; 281static int ixjdebug;
281static int hertz = HZ; 282static int hertz = HZ;
282static int samplerate = 100; 283static int samplerate = 100;
@@ -6655,9 +6656,9 @@ static long do_ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long ar
6655static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg) 6656static long ixj_ioctl(struct file *file_p, unsigned int cmd, unsigned long arg)
6656{ 6657{
6657 long ret; 6658 long ret;
6658 lock_kernel(); 6659 mutex_lock(&ixj_mutex);
6659 ret = do_ixj_ioctl(file_p, cmd, arg); 6660 ret = do_ixj_ioctl(file_p, cmd, arg);
6660 unlock_kernel(); 6661 mutex_unlock(&ixj_mutex);
6661 return ret; 6662 return ret;
6662} 6663}
6663 6664
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index a1900e502518..d005b9eeebbc 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -8,7 +8,6 @@
8#include <linux/errno.h> /* error codes */ 8#include <linux/errno.h> /* error codes */
9#include <linux/slab.h> 9#include <linux/slab.h>
10 10
11#include <pcmcia/cs.h>
12#include <pcmcia/cistpl.h> 11#include <pcmcia/cistpl.h>
13#include <pcmcia/ds.h> 12#include <pcmcia/ds.h>
14 13
@@ -32,9 +31,6 @@ static int ixj_probe(struct pcmcia_device *p_dev)
32{ 31{
33 dev_dbg(&p_dev->dev, "ixj_attach()\n"); 32 dev_dbg(&p_dev->dev, "ixj_attach()\n");
34 /* Create new ixj device */ 33 /* Create new ixj device */
35 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
36 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
37 p_dev->conf.IntType = INT_MEMORY_AND_IO;
38 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL); 34 p_dev->priv = kzalloc(sizeof(struct ixj_info_t), GFP_KERNEL);
39 if (!p_dev->priv) { 35 if (!p_dev->priv) {
40 return -ENOMEM; 36 return -ENOMEM;
@@ -111,40 +107,31 @@ failed:
111 return; 107 return;
112} 108}
113 109
114static int ixj_config_check(struct pcmcia_device *p_dev, 110static int ixj_config_check(struct pcmcia_device *p_dev, void *priv_data)
115 cistpl_cftable_entry_t *cfg,
116 cistpl_cftable_entry_t *dflt,
117 unsigned int vcc,
118 void *priv_data)
119{ 111{
120 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) { 112 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
121 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io; 113 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
122 p_dev->resource[0]->start = io->win[0].base; 114 p_dev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
123 p_dev->resource[0]->end = io->win[0].len; 115 p_dev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
124 p_dev->io_lines = 3; 116 p_dev->io_lines = 3;
125 if (io->nwin == 2) { 117
126 p_dev->resource[1]->start = io->win[1].base; 118 return pcmcia_request_io(p_dev);
127 p_dev->resource[1]->end = io->win[1].len;
128 }
129 if (!pcmcia_request_io(p_dev))
130 return 0;
131 }
132 return -ENODEV;
133} 119}
134 120
135static int ixj_config(struct pcmcia_device * link) 121static int ixj_config(struct pcmcia_device * link)
136{ 122{
137 IXJ *j; 123 IXJ *j;
138 ixj_info_t *info; 124 ixj_info_t *info;
139 cistpl_cftable_entry_t dflt = { 0 };
140 125
141 info = link->priv; 126 info = link->priv;
142 dev_dbg(&link->dev, "ixj_config\n"); 127 dev_dbg(&link->dev, "ixj_config\n");
143 128
144 if (pcmcia_loop_config(link, ixj_config_check, &dflt)) 129 link->config_flags = CONF_AUTO_SET_IO;
130
131 if (pcmcia_loop_config(link, ixj_config_check, NULL))
145 goto failed; 132 goto failed;
146 133
147 if (pcmcia_request_configuration(link, &link->conf)) 134 if (pcmcia_enable_device(link))
148 goto failed; 135 goto failed;
149 136
150 /* 137 /*
@@ -178,9 +165,7 @@ MODULE_DEVICE_TABLE(pcmcia, ixj_ids);
178 165
179static struct pcmcia_driver ixj_driver = { 166static struct pcmcia_driver ixj_driver = {
180 .owner = THIS_MODULE, 167 .owner = THIS_MODULE,
181 .drv = { 168 .name = "ixj_cs",
182 .name = "ixj_cs",
183 },
184 .probe = ixj_probe, 169 .probe = ixj_probe,
185 .remove = ixj_detach, 170 .remove = ixj_detach,
186 .id_table = ixj_ids, 171 .id_table = ixj_ids,
diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
index 7e594449600e..9eed5b52d9de 100644
--- a/drivers/usb/core/Kconfig
+++ b/drivers/usb/core/Kconfig
@@ -91,12 +91,12 @@ config USB_DYNAMIC_MINORS
91 If you are unsure about this, say N here. 91 If you are unsure about this, say N here.
92 92
93config USB_SUSPEND 93config USB_SUSPEND
94 bool "USB runtime power management (suspend/resume and wakeup)" 94 bool "USB runtime power management (autosuspend) and wakeup"
95 depends on USB && PM_RUNTIME 95 depends on USB && PM_RUNTIME
96 help 96 help
97 If you say Y here, you can use driver calls or the sysfs 97 If you say Y here, you can use driver calls or the sysfs
98 "power/level" file to suspend or resume individual USB 98 "power/control" file to enable or disable autosuspend for
99 peripherals and to enable or disable autosuspend (see 99 individual USB peripherals (see
100 Documentation/usb/power-management.txt for more details). 100 Documentation/usb/power-management.txt for more details).
101 101
102 Also, USB "remote wakeup" signaling is supported, whereby some 102 Also, USB "remote wakeup" signaling is supported, whereby some
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 580bcd396839..9fe34fb78ef1 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -160,9 +160,9 @@ void usb_major_cleanup(void)
160int usb_register_dev(struct usb_interface *intf, 160int usb_register_dev(struct usb_interface *intf,
161 struct usb_class_driver *class_driver) 161 struct usb_class_driver *class_driver)
162{ 162{
163 int retval = -EINVAL; 163 int retval;
164 int minor_base = class_driver->minor_base; 164 int minor_base = class_driver->minor_base;
165 int minor = 0; 165 int minor;
166 char name[20]; 166 char name[20];
167 char *temp; 167 char *temp;
168 168
@@ -174,12 +174,17 @@ int usb_register_dev(struct usb_interface *intf,
174 */ 174 */
175 minor_base = 0; 175 minor_base = 0;
176#endif 176#endif
177 intf->minor = -1;
178
179 dbg ("looking for a minor, starting at %d", minor_base);
180 177
181 if (class_driver->fops == NULL) 178 if (class_driver->fops == NULL)
182 goto exit; 179 return -EINVAL;
180 if (intf->minor >= 0)
181 return -EADDRINUSE;
182
183 retval = init_usb_class();
184 if (retval)
185 return retval;
186
187 dev_dbg(&intf->dev, "looking for a minor, starting at %d", minor_base);
183 188
184 down_write(&minor_rwsem); 189 down_write(&minor_rwsem);
185 for (minor = minor_base; minor < MAX_USB_MINORS; ++minor) { 190 for (minor = minor_base; minor < MAX_USB_MINORS; ++minor) {
@@ -187,20 +192,12 @@ int usb_register_dev(struct usb_interface *intf,
187 continue; 192 continue;
188 193
189 usb_minors[minor] = class_driver->fops; 194 usb_minors[minor] = class_driver->fops;
190 195 intf->minor = minor;
191 retval = 0;
192 break; 196 break;
193 } 197 }
194 up_write(&minor_rwsem); 198 up_write(&minor_rwsem);
195 199 if (intf->minor < 0)
196 if (retval) 200 return -EXFULL;
197 goto exit;
198
199 retval = init_usb_class();
200 if (retval)
201 goto exit;
202
203 intf->minor = minor;
204 201
205 /* create a usb class device for this usb interface */ 202 /* create a usb class device for this usb interface */
206 snprintf(name, sizeof(name), class_driver->name, minor - minor_base); 203 snprintf(name, sizeof(name), class_driver->name, minor - minor_base);
@@ -214,11 +211,11 @@ int usb_register_dev(struct usb_interface *intf,
214 "%s", temp); 211 "%s", temp);
215 if (IS_ERR(intf->usb_dev)) { 212 if (IS_ERR(intf->usb_dev)) {
216 down_write(&minor_rwsem); 213 down_write(&minor_rwsem);
217 usb_minors[intf->minor] = NULL; 214 usb_minors[minor] = NULL;
215 intf->minor = -1;
218 up_write(&minor_rwsem); 216 up_write(&minor_rwsem);
219 retval = PTR_ERR(intf->usb_dev); 217 retval = PTR_ERR(intf->usb_dev);
220 } 218 }
221exit:
222 return retval; 219 return retval;
223} 220}
224EXPORT_SYMBOL_GPL(usb_register_dev); 221EXPORT_SYMBOL_GPL(usb_register_dev);
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 844683e50383..9f0ce7de0e36 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1802,6 +1802,7 @@ free_interfaces:
1802 intf->dev.groups = usb_interface_groups; 1802 intf->dev.groups = usb_interface_groups;
1803 intf->dev.dma_mask = dev->dev.dma_mask; 1803 intf->dev.dma_mask = dev->dev.dma_mask;
1804 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device); 1804 INIT_WORK(&intf->reset_ws, __usb_queue_reset_device);
1805 intf->minor = -1;
1805 device_initialize(&intf->dev); 1806 device_initialize(&intf->dev);
1806 dev_set_name(&intf->dev, "%d-%s:%d.%d", 1807 dev_set_name(&intf->dev, "%d-%s:%d.%d",
1807 dev->bus->busnum, dev->devpath, 1808 dev->bus->busnum, dev->devpath,
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index fc35406fc80c..3f1d771c8be5 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -33,7 +33,6 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/poll.h> 35#include <linux/poll.h>
36#include <linux/smp_lock.h>
37 36
38#include <linux/device.h> 37#include <linux/device.h>
39#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 58b72d741d93..a1e8d273103f 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -119,6 +119,11 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
119 ehci->broken_periodic = 1; 119 ehci->broken_periodic = 1;
120 ehci_info(ehci, "using broken periodic workaround\n"); 120 ehci_info(ehci, "using broken periodic workaround\n");
121 } 121 }
122 if (pdev->device == 0x0806 || pdev->device == 0x0811
123 || pdev->device == 0x0829) {
124 ehci_info(ehci, "disable lpm for langwell/penwell\n");
125 ehci->has_lpm = 0;
126 }
122 break; 127 break;
123 case PCI_VENDOR_ID_TDI: 128 case PCI_VENDOR_ID_TDI:
124 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 129 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index 418163894775..afef7b0a4195 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -24,6 +24,7 @@
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <mach/ohci.h> 26#include <mach/ohci.h>
27#include <mach/pxa3xx-u2d.h>
27 28
28/* 29/*
29 * UHC: USB Host Controller (OHCI-like) register definitions 30 * UHC: USB Host Controller (OHCI-like) register definitions
@@ -235,6 +236,9 @@ static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
235 if (retval < 0) 236 if (retval < 0)
236 return retval; 237 return retval;
237 238
239 if (cpu_is_pxa3xx())
240 pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self);
241
238 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE; 242 uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE;
239 __raw_writel(uhchr, ohci->mmio_base + UHCHR); 243 __raw_writel(uhchr, ohci->mmio_base + UHCHR);
240 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE); 244 __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE);
@@ -251,6 +255,9 @@ static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev)
251 255
252 inf = dev->platform_data; 256 inf = dev->platform_data;
253 257
258 if (cpu_is_pxa3xx())
259 pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self);
260
254 if (inf->exit) 261 if (inf->exit)
255 inf->exit(dev); 262 inf->exit(dev);
256 263
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 0e13a00eb2ed..3775c035a6c5 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -20,7 +20,6 @@
20#include <linux/ioport.h> 20#include <linux/ioport.h>
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22 22
23#include <pcmcia/cs.h>
24#include <pcmcia/cistpl.h> 23#include <pcmcia/cistpl.h>
25#include <pcmcia/cisreg.h> 24#include <pcmcia/cisreg.h>
26#include <pcmcia/ds.h> 25#include <pcmcia/ds.h>
@@ -132,49 +131,12 @@ static void sl811_cs_release(struct pcmcia_device * link)
132 platform_device_unregister(&platform_dev); 131 platform_device_unregister(&platform_dev);
133} 132}
134 133
135static int sl811_cs_config_check(struct pcmcia_device *p_dev, 134static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
136 cistpl_cftable_entry_t *cfg,
137 cistpl_cftable_entry_t *dflt,
138 unsigned int vcc,
139 void *priv_data)
140{ 135{
141 if (cfg->index == 0) 136 if (p_dev->config_index == 0)
142 return -ENODEV; 137 return -EINVAL;
143 138
144 /* Use power settings for Vcc and Vpp if present */ 139 return pcmcia_request_io(p_dev);
145 /* Note that the CIS values need to be rescaled */
146 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
147 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
148 return -ENODEV;
149 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
150 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
151 return -ENODEV;
152 }
153
154 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
155 p_dev->conf.Vpp =
156 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
157 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
158 p_dev->conf.Vpp =
159 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
160
161 /* we need an interrupt */
162 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
163
164 /* IO window settings */
165 p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
166 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
167 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
168 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
169
170 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
171 p_dev->resource[0]->start = io->win[0].base;
172 p_dev->resource[0]->end = io->win[0].len;
173
174 return pcmcia_request_io(p_dev);
175 }
176 pcmcia_disable_device(p_dev);
177 return -ENODEV;
178} 140}
179 141
180 142
@@ -185,6 +147,9 @@ static int sl811_cs_config(struct pcmcia_device *link)
185 147
186 dev_dbg(&link->dev, "sl811_cs_config\n"); 148 dev_dbg(&link->dev, "sl811_cs_config\n");
187 149
150 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
151 CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
152
188 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL)) 153 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
189 goto failed; 154 goto failed;
190 155
@@ -195,18 +160,10 @@ static int sl811_cs_config(struct pcmcia_device *link)
195 if (!link->irq) 160 if (!link->irq)
196 goto failed; 161 goto failed;
197 162
198 ret = pcmcia_request_configuration(link, &link->conf); 163 ret = pcmcia_enable_device(link);
199 if (ret) 164 if (ret)
200 goto failed; 165 goto failed;
201 166
202 dev_info(&link->dev, "index 0x%02x: ",
203 link->conf.ConfigIndex);
204 if (link->conf.Vpp)
205 printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
206 printk(", irq %d", link->irq);
207 printk(", io %pR", link->resource[0]);
208 printk("\n");
209
210 if (sl811_hc_init(parent, link->resource[0]->start, link->irq) 167 if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
211 < 0) { 168 < 0) {
212failed: 169failed:
@@ -227,9 +184,6 @@ static int sl811_cs_probe(struct pcmcia_device *link)
227 local->p_dev = link; 184 local->p_dev = link;
228 link->priv = local; 185 link->priv = local;
229 186
230 link->conf.Attributes = 0;
231 link->conf.IntType = INT_MEMORY_AND_IO;
232
233 return sl811_cs_config(link); 187 return sl811_cs_config(link);
234} 188}
235 189
@@ -241,9 +195,7 @@ MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
241 195
242static struct pcmcia_driver sl811_cs_driver = { 196static struct pcmcia_driver sl811_cs_driver = {
243 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
244 .drv = { 198 .name = "sl811_cs",
245 .name = "sl811_cs",
246 },
247 .probe = sl811_cs_probe, 199 .probe = sl811_cs_probe,
248 .remove = sl811_cs_detach, 200 .remove = sl811_cs_detach,
249 .id_table = sl811_ids, 201 .id_table = sl811_ids,
diff --git a/drivers/usb/musb/cppi_dma.c b/drivers/usb/musb/cppi_dma.c
index 59dc3d351b60..5ab5bb89bae3 100644
--- a/drivers/usb/musb/cppi_dma.c
+++ b/drivers/usb/musb/cppi_dma.c
@@ -322,6 +322,7 @@ cppi_channel_allocate(struct dma_controller *c,
322 index, transmit ? 'T' : 'R', cppi_ch); 322 index, transmit ? 'T' : 'R', cppi_ch);
323 cppi_ch->hw_ep = ep; 323 cppi_ch->hw_ep = ep;
324 cppi_ch->channel.status = MUSB_DMA_STATUS_FREE; 324 cppi_ch->channel.status = MUSB_DMA_STATUS_FREE;
325 cppi_ch->channel.max_len = 0x7fffffff;
325 326
326 DBG(4, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R'); 327 DBG(4, "Allocate CPPI%d %cX\n", index, transmit ? 'T' : 'R');
327 return &cppi_ch->channel; 328 return &cppi_ch->channel;
diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index c79a5e30d437..9e8639d4e862 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -195,15 +195,14 @@ static const struct file_operations musb_regdump_fops = {
195 195
196static int musb_test_mode_open(struct inode *inode, struct file *file) 196static int musb_test_mode_open(struct inode *inode, struct file *file)
197{ 197{
198 file->private_data = inode->i_private;
199
200 return single_open(file, musb_test_mode_show, inode->i_private); 198 return single_open(file, musb_test_mode_show, inode->i_private);
201} 199}
202 200
203static ssize_t musb_test_mode_write(struct file *file, 201static ssize_t musb_test_mode_write(struct file *file,
204 const char __user *ubuf, size_t count, loff_t *ppos) 202 const char __user *ubuf, size_t count, loff_t *ppos)
205{ 203{
206 struct musb *musb = file->private_data; 204 struct seq_file *s = file->private_data;
205 struct musb *musb = s->private;
207 u8 test = 0; 206 u8 test = 0;
208 char buf[18]; 207 char buf[18];
209 208
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 6fca870e957e..d065e23f123e 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -300,6 +300,11 @@ static void txstate(struct musb *musb, struct musb_request *req)
300#ifndef CONFIG_MUSB_PIO_ONLY 300#ifndef CONFIG_MUSB_PIO_ONLY
301 if (is_dma_capable() && musb_ep->dma) { 301 if (is_dma_capable() && musb_ep->dma) {
302 struct dma_controller *c = musb->dma_controller; 302 struct dma_controller *c = musb->dma_controller;
303 size_t request_size;
304
305 /* setup DMA, then program endpoint CSR */
306 request_size = min_t(size_t, request->length - request->actual,
307 musb_ep->dma->max_len);
303 308
304 use_dma = (request->dma != DMA_ADDR_INVALID); 309 use_dma = (request->dma != DMA_ADDR_INVALID);
305 310
@@ -307,11 +312,6 @@ static void txstate(struct musb *musb, struct musb_request *req)
307 312
308#ifdef CONFIG_USB_INVENTRA_DMA 313#ifdef CONFIG_USB_INVENTRA_DMA
309 { 314 {
310 size_t request_size;
311
312 /* setup DMA, then program endpoint CSR */
313 request_size = min_t(size_t, request->length,
314 musb_ep->dma->max_len);
315 if (request_size < musb_ep->packet_sz) 315 if (request_size < musb_ep->packet_sz)
316 musb_ep->dma->desired_mode = 0; 316 musb_ep->dma->desired_mode = 0;
317 else 317 else
@@ -373,8 +373,8 @@ static void txstate(struct musb *musb, struct musb_request *req)
373 use_dma = use_dma && c->channel_program( 373 use_dma = use_dma && c->channel_program(
374 musb_ep->dma, musb_ep->packet_sz, 374 musb_ep->dma, musb_ep->packet_sz,
375 0, 375 0,
376 request->dma, 376 request->dma + request->actual,
377 request->length); 377 request_size);
378 if (!use_dma) { 378 if (!use_dma) {
379 c->channel_release(musb_ep->dma); 379 c->channel_release(musb_ep->dma);
380 musb_ep->dma = NULL; 380 musb_ep->dma = NULL;
@@ -386,8 +386,8 @@ static void txstate(struct musb *musb, struct musb_request *req)
386 use_dma = use_dma && c->channel_program( 386 use_dma = use_dma && c->channel_program(
387 musb_ep->dma, musb_ep->packet_sz, 387 musb_ep->dma, musb_ep->packet_sz,
388 request->zero, 388 request->zero,
389 request->dma, 389 request->dma + request->actual,
390 request->length); 390 request_size);
391#endif 391#endif
392 } 392 }
393#endif 393#endif
@@ -501,26 +501,14 @@ void musb_g_tx(struct musb *musb, u8 epnum)
501 request->zero = 0; 501 request->zero = 0;
502 } 502 }
503 503
504 /* ... or if not, then complete it. */ 504 if (request->actual == request->length) {
505 musb_g_giveback(musb_ep, request, 0); 505 musb_g_giveback(musb_ep, request, 0);
506 506 request = musb_ep->desc ? next_request(musb_ep) : NULL;
507 /* 507 if (!request) {
508 * Kickstart next transfer if appropriate; 508 DBG(4, "%s idle now\n",
509 * the packet that just completed might not 509 musb_ep->end_point.name);
510 * be transmitted for hours or days. 510 return;
511 * REVISIT for double buffering... 511 }
512 * FIXME revisit for stalls too...
513 */
514 musb_ep_select(mbase, epnum);
515 csr = musb_readw(epio, MUSB_TXCSR);
516 if (csr & MUSB_TXCSR_FIFONOTEMPTY)
517 return;
518
519 request = musb_ep->desc ? next_request(musb_ep) : NULL;
520 if (!request) {
521 DBG(4, "%s idle now\n",
522 musb_ep->end_point.name);
523 return;
524 } 512 }
525 } 513 }
526 514
@@ -568,11 +556,19 @@ static void rxstate(struct musb *musb, struct musb_request *req)
568{ 556{
569 const u8 epnum = req->epnum; 557 const u8 epnum = req->epnum;
570 struct usb_request *request = &req->request; 558 struct usb_request *request = &req->request;
571 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_out; 559 struct musb_ep *musb_ep;
572 void __iomem *epio = musb->endpoints[epnum].regs; 560 void __iomem *epio = musb->endpoints[epnum].regs;
573 unsigned fifo_count = 0; 561 unsigned fifo_count = 0;
574 u16 len = musb_ep->packet_sz; 562 u16 len;
575 u16 csr = musb_readw(epio, MUSB_RXCSR); 563 u16 csr = musb_readw(epio, MUSB_RXCSR);
564 struct musb_hw_ep *hw_ep = &musb->endpoints[epnum];
565
566 if (hw_ep->is_shared_fifo)
567 musb_ep = &hw_ep->ep_in;
568 else
569 musb_ep = &hw_ep->ep_out;
570
571 len = musb_ep->packet_sz;
576 572
577 /* We shouldn't get here while DMA is active, but we do... */ 573 /* We shouldn't get here while DMA is active, but we do... */
578 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) { 574 if (dma_channel_status(musb_ep->dma) == MUSB_DMA_STATUS_BUSY) {
@@ -647,8 +643,8 @@ static void rxstate(struct musb *musb, struct musb_request *req)
647 */ 643 */
648 644
649 csr |= MUSB_RXCSR_DMAENAB; 645 csr |= MUSB_RXCSR_DMAENAB;
650#ifdef USE_MODE1
651 csr |= MUSB_RXCSR_AUTOCLEAR; 646 csr |= MUSB_RXCSR_AUTOCLEAR;
647#ifdef USE_MODE1
652 /* csr |= MUSB_RXCSR_DMAMODE; */ 648 /* csr |= MUSB_RXCSR_DMAMODE; */
653 649
654 /* this special sequence (enabling and then 650 /* this special sequence (enabling and then
@@ -663,10 +659,11 @@ static void rxstate(struct musb *musb, struct musb_request *req)
663 if (request->actual < request->length) { 659 if (request->actual < request->length) {
664 int transfer_size = 0; 660 int transfer_size = 0;
665#ifdef USE_MODE1 661#ifdef USE_MODE1
666 transfer_size = min(request->length, 662 transfer_size = min(request->length - request->actual,
667 channel->max_len); 663 channel->max_len);
668#else 664#else
669 transfer_size = len; 665 transfer_size = min(request->length - request->actual,
666 (unsigned)len);
670#endif 667#endif
671 if (transfer_size <= musb_ep->packet_sz) 668 if (transfer_size <= musb_ep->packet_sz)
672 musb_ep->dma->desired_mode = 0; 669 musb_ep->dma->desired_mode = 0;
@@ -740,9 +737,15 @@ void musb_g_rx(struct musb *musb, u8 epnum)
740 u16 csr; 737 u16 csr;
741 struct usb_request *request; 738 struct usb_request *request;
742 void __iomem *mbase = musb->mregs; 739 void __iomem *mbase = musb->mregs;
743 struct musb_ep *musb_ep = &musb->endpoints[epnum].ep_out; 740 struct musb_ep *musb_ep;
744 void __iomem *epio = musb->endpoints[epnum].regs; 741 void __iomem *epio = musb->endpoints[epnum].regs;
745 struct dma_channel *dma; 742 struct dma_channel *dma;
743 struct musb_hw_ep *hw_ep = &musb->endpoints[epnum];
744
745 if (hw_ep->is_shared_fifo)
746 musb_ep = &hw_ep->ep_in;
747 else
748 musb_ep = &hw_ep->ep_out;
746 749
747 musb_ep_select(mbase, epnum); 750 musb_ep_select(mbase, epnum);
748 751
@@ -1081,7 +1084,7 @@ struct free_record {
1081/* 1084/*
1082 * Context: controller locked, IRQs blocked. 1085 * Context: controller locked, IRQs blocked.
1083 */ 1086 */
1084static void musb_ep_restart(struct musb *musb, struct musb_request *req) 1087void musb_ep_restart(struct musb *musb, struct musb_request *req)
1085{ 1088{
1086 DBG(3, "<== %s request %p len %u on hw_ep%d\n", 1089 DBG(3, "<== %s request %p len %u on hw_ep%d\n",
1087 req->tx ? "TX/IN" : "RX/OUT", 1090 req->tx ? "TX/IN" : "RX/OUT",
diff --git a/drivers/usb/musb/musb_gadget.h b/drivers/usb/musb/musb_gadget.h
index c8b140325d82..572b1da7f2dc 100644
--- a/drivers/usb/musb/musb_gadget.h
+++ b/drivers/usb/musb/musb_gadget.h
@@ -105,4 +105,6 @@ extern void musb_gadget_cleanup(struct musb *);
105 105
106extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int); 106extern void musb_g_giveback(struct musb_ep *, struct usb_request *, int);
107 107
108extern void musb_ep_restart(struct musb *, struct musb_request *);
109
108#endif /* __MUSB_GADGET_H */ 110#endif /* __MUSB_GADGET_H */
diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 59bef8f3a358..6dd03f4c5f49 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -261,6 +261,7 @@ __acquires(musb->lock)
261 ctrlrequest->wIndex & 0x0f; 261 ctrlrequest->wIndex & 0x0f;
262 struct musb_ep *musb_ep; 262 struct musb_ep *musb_ep;
263 struct musb_hw_ep *ep; 263 struct musb_hw_ep *ep;
264 struct musb_request *request;
264 void __iomem *regs; 265 void __iomem *regs;
265 int is_in; 266 int is_in;
266 u16 csr; 267 u16 csr;
@@ -302,6 +303,14 @@ __acquires(musb->lock)
302 musb_writew(regs, MUSB_RXCSR, csr); 303 musb_writew(regs, MUSB_RXCSR, csr);
303 } 304 }
304 305
306 /* Maybe start the first request in the queue */
307 request = to_musb_request(
308 next_request(musb_ep));
309 if (!musb_ep->busy && request) {
310 DBG(3, "restarting the request\n");
311 musb_ep_restart(musb, request);
312 }
313
305 /* select ep0 again */ 314 /* select ep0 again */
306 musb_ep_select(mbase, 0); 315 musb_ep_select(mbase, 0);
307 } break; 316 } break;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 877d20b1dff9..9e65c47cc98b 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -660,6 +660,12 @@ static bool musb_tx_dma_program(struct dma_controller *dma,
660 660
661 qh->segsize = length; 661 qh->segsize = length;
662 662
663 /*
664 * Ensure the data reaches to main memory before starting
665 * DMA transfer
666 */
667 wmb();
668
663 if (!dma->channel_program(channel, pkt_size, mode, 669 if (!dma->channel_program(channel, pkt_size, mode,
664 urb->transfer_dma + offset, length)) { 670 urb->transfer_dma + offset, length)) {
665 dma->channel_release(channel); 671 dma->channel_release(channel);
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 05aaac1c3861..0bc97698af15 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -347,11 +347,20 @@ static void twl4030_i2c_access(struct twl4030_usb *twl, int on)
347 } 347 }
348} 348}
349 349
350static void twl4030_phy_power(struct twl4030_usb *twl, int on) 350static void __twl4030_phy_power(struct twl4030_usb *twl, int on)
351{ 351{
352 u8 pwr; 352 u8 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL);
353
354 if (on)
355 pwr &= ~PHY_PWR_PHYPWD;
356 else
357 pwr |= PHY_PWR_PHYPWD;
353 358
354 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); 359 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
360}
361
362static void twl4030_phy_power(struct twl4030_usb *twl, int on)
363{
355 if (on) { 364 if (on) {
356 regulator_enable(twl->usb3v1); 365 regulator_enable(twl->usb3v1);
357 regulator_enable(twl->usb1v8); 366 regulator_enable(twl->usb1v8);
@@ -365,15 +374,13 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
365 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, 374 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0,
366 VUSB_DEDICATED2); 375 VUSB_DEDICATED2);
367 regulator_enable(twl->usb1v5); 376 regulator_enable(twl->usb1v5);
368 pwr &= ~PHY_PWR_PHYPWD; 377 __twl4030_phy_power(twl, 1);
369 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
370 twl4030_usb_write(twl, PHY_CLK_CTRL, 378 twl4030_usb_write(twl, PHY_CLK_CTRL,
371 twl4030_usb_read(twl, PHY_CLK_CTRL) | 379 twl4030_usb_read(twl, PHY_CLK_CTRL) |
372 (PHY_CLK_CTRL_CLOCKGATING_EN | 380 (PHY_CLK_CTRL_CLOCKGATING_EN |
373 PHY_CLK_CTRL_CLK32K_EN)); 381 PHY_CLK_CTRL_CLK32K_EN));
374 } else { 382 } else {
375 pwr |= PHY_PWR_PHYPWD; 383 __twl4030_phy_power(twl, 0);
376 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
377 regulator_disable(twl->usb1v5); 384 regulator_disable(twl->usb1v5);
378 regulator_disable(twl->usb1v8); 385 regulator_disable(twl->usb1v8);
379 regulator_disable(twl->usb3v1); 386 regulator_disable(twl->usb3v1);
@@ -387,19 +394,25 @@ static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
387 394
388 twl4030_phy_power(twl, 0); 395 twl4030_phy_power(twl, 0);
389 twl->asleep = 1; 396 twl->asleep = 1;
397 dev_dbg(twl->dev, "%s\n", __func__);
390} 398}
391 399
392static void twl4030_phy_resume(struct twl4030_usb *twl) 400static void __twl4030_phy_resume(struct twl4030_usb *twl)
393{ 401{
394 if (!twl->asleep)
395 return;
396
397 twl4030_phy_power(twl, 1); 402 twl4030_phy_power(twl, 1);
398 twl4030_i2c_access(twl, 1); 403 twl4030_i2c_access(twl, 1);
399 twl4030_usb_set_mode(twl, twl->usb_mode); 404 twl4030_usb_set_mode(twl, twl->usb_mode);
400 if (twl->usb_mode == T2_USB_MODE_ULPI) 405 if (twl->usb_mode == T2_USB_MODE_ULPI)
401 twl4030_i2c_access(twl, 0); 406 twl4030_i2c_access(twl, 0);
407}
408
409static void twl4030_phy_resume(struct twl4030_usb *twl)
410{
411 if (!twl->asleep)
412 return;
413 __twl4030_phy_resume(twl);
402 twl->asleep = 0; 414 twl->asleep = 0;
415 dev_dbg(twl->dev, "%s\n", __func__);
403} 416}
404 417
405static int twl4030_usb_ldo_init(struct twl4030_usb *twl) 418static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
@@ -408,8 +421,8 @@ static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
408 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY); 421 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY);
409 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY); 422 twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0x0C, PROTECT_KEY);
410 423
411 /* put VUSB3V1 LDO in active state */ 424 /* Keep VUSB3V1 LDO in sleep state until VBUS/ID change detected*/
412 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2); 425 /*twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB_DEDICATED2);*/
413 426
414 /* input to VUSB3V1 LDO is from VBAT, not VBUS */ 427 /* input to VUSB3V1 LDO is from VBAT, not VBUS */
415 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1); 428 twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1);
@@ -502,6 +515,26 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
502 return IRQ_HANDLED; 515 return IRQ_HANDLED;
503} 516}
504 517
518static void twl4030_usb_phy_init(struct twl4030_usb *twl)
519{
520 int status;
521
522 status = twl4030_usb_linkstat(twl);
523 if (status >= 0) {
524 if (status == USB_EVENT_NONE) {
525 __twl4030_phy_power(twl, 0);
526 twl->asleep = 1;
527 } else {
528 __twl4030_phy_resume(twl);
529 twl->asleep = 0;
530 }
531
532 blocking_notifier_call_chain(&twl->otg.notifier, status,
533 twl->otg.gadget);
534 }
535 sysfs_notify(&twl->dev->kobj, NULL, "vbus");
536}
537
505static int twl4030_set_suspend(struct otg_transceiver *x, int suspend) 538static int twl4030_set_suspend(struct otg_transceiver *x, int suspend)
506{ 539{
507 struct twl4030_usb *twl = xceiv_to_twl(x); 540 struct twl4030_usb *twl = xceiv_to_twl(x);
@@ -550,7 +583,6 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
550 struct twl4030_usb_data *pdata = pdev->dev.platform_data; 583 struct twl4030_usb_data *pdata = pdev->dev.platform_data;
551 struct twl4030_usb *twl; 584 struct twl4030_usb *twl;
552 int status, err; 585 int status, err;
553 u8 pwr;
554 586
555 if (!pdata) { 587 if (!pdata) {
556 dev_dbg(&pdev->dev, "platform_data not available\n"); 588 dev_dbg(&pdev->dev, "platform_data not available\n");
@@ -569,10 +601,7 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
569 twl->otg.set_peripheral = twl4030_set_peripheral; 601 twl->otg.set_peripheral = twl4030_set_peripheral;
570 twl->otg.set_suspend = twl4030_set_suspend; 602 twl->otg.set_suspend = twl4030_set_suspend;
571 twl->usb_mode = pdata->usb_mode; 603 twl->usb_mode = pdata->usb_mode;
572 604 twl->asleep = 1;
573 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL);
574
575 twl->asleep = (pwr & PHY_PWR_PHYPWD);
576 605
577 /* init spinlock for workqueue */ 606 /* init spinlock for workqueue */
578 spin_lock_init(&twl->lock); 607 spin_lock_init(&twl->lock);
@@ -610,15 +639,10 @@ static int __devinit twl4030_usb_probe(struct platform_device *pdev)
610 return status; 639 return status;
611 } 640 }
612 641
613 /* The IRQ handler just handles changes from the previous states 642 /* Power down phy or make it work according to
614 * of the ID and VBUS pins ... in probe() we must initialize that 643 * current link state.
615 * previous state. The easy way: fake an IRQ.
616 *
617 * REVISIT: a real IRQ might have happened already, if PREEMPT is
618 * enabled. Else the IRQ may not yet be configured or enabled,
619 * because of scheduling delays.
620 */ 644 */
621 twl4030_usb_irq(twl->irq, twl); 645 twl4030_usb_phy_init(twl);
622 646
623 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n"); 647 dev_info(&pdev->dev, "Initialized TWL4030 USB module\n");
624 return 0; 648 return 0;
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 30922a7e3347..aa665817a272 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -2024,6 +2024,9 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
2024 2024
2025 case TIOCGICOUNT: 2025 case TIOCGICOUNT:
2026 cnow = mos7720_port->icount; 2026 cnow = mos7720_port->icount;
2027
2028 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2029
2027 icount.cts = cnow.cts; 2030 icount.cts = cnow.cts;
2028 icount.dsr = cnow.dsr; 2031 icount.dsr = cnow.dsr;
2029 icount.rng = cnow.rng; 2032 icount.rng = cnow.rng;
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 1c9b6e9b2386..1a42bc213799 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -2285,6 +2285,9 @@ static int mos7840_ioctl(struct tty_struct *tty, struct file *file,
2285 case TIOCGICOUNT: 2285 case TIOCGICOUNT:
2286 cnow = mos7840_port->icount; 2286 cnow = mos7840_port->icount;
2287 smp_rmb(); 2287 smp_rmb();
2288
2289 memset(&icount, 0, sizeof(struct serial_icounter_struct));
2290
2288 icount.cts = cnow.cts; 2291 icount.cts = cnow.cts;
2289 icount.dsr = cnow.dsr; 2292 icount.dsr = cnow.dsr;
2290 icount.rng = cnow.rng; 2293 icount.rng = cnow.rng;
diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index c8523ce2e4c6..861af4a8b79c 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -127,7 +127,10 @@ static void handle_tx(struct vhost_net *net)
127 size_t len, total_len = 0; 127 size_t len, total_len = 0;
128 int err, wmem; 128 int err, wmem;
129 size_t hdr_size; 129 size_t hdr_size;
130 struct socket *sock = rcu_dereference(vq->private_data); 130 struct socket *sock;
131
132 sock = rcu_dereference_check(vq->private_data,
133 lockdep_is_held(&vq->mutex));
131 if (!sock) 134 if (!sock)
132 return; 135 return;
133 136
@@ -243,7 +246,7 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
243 int r, nlogs = 0; 246 int r, nlogs = 0;
244 247
245 while (datalen > 0) { 248 while (datalen > 0) {
246 if (unlikely(headcount >= VHOST_NET_MAX_SG)) { 249 if (unlikely(seg >= VHOST_NET_MAX_SG)) {
247 r = -ENOBUFS; 250 r = -ENOBUFS;
248 goto err; 251 goto err;
249 } 252 }
@@ -582,7 +585,10 @@ static void vhost_net_disable_vq(struct vhost_net *n,
582static void vhost_net_enable_vq(struct vhost_net *n, 585static void vhost_net_enable_vq(struct vhost_net *n,
583 struct vhost_virtqueue *vq) 586 struct vhost_virtqueue *vq)
584{ 587{
585 struct socket *sock = vq->private_data; 588 struct socket *sock;
589
590 sock = rcu_dereference_protected(vq->private_data,
591 lockdep_is_held(&vq->mutex));
586 if (!sock) 592 if (!sock)
587 return; 593 return;
588 if (vq == n->vqs + VHOST_NET_VQ_TX) { 594 if (vq == n->vqs + VHOST_NET_VQ_TX) {
@@ -598,7 +604,8 @@ static struct socket *vhost_net_stop_vq(struct vhost_net *n,
598 struct socket *sock; 604 struct socket *sock;
599 605
600 mutex_lock(&vq->mutex); 606 mutex_lock(&vq->mutex);
601 sock = vq->private_data; 607 sock = rcu_dereference_protected(vq->private_data,
608 lockdep_is_held(&vq->mutex));
602 vhost_net_disable_vq(n, vq); 609 vhost_net_disable_vq(n, vq);
603 rcu_assign_pointer(vq->private_data, NULL); 610 rcu_assign_pointer(vq->private_data, NULL);
604 mutex_unlock(&vq->mutex); 611 mutex_unlock(&vq->mutex);
@@ -736,7 +743,8 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
736 } 743 }
737 744
738 /* start polling new socket */ 745 /* start polling new socket */
739 oldsock = vq->private_data; 746 oldsock = rcu_dereference_protected(vq->private_data,
747 lockdep_is_held(&vq->mutex));
740 if (sock != oldsock) { 748 if (sock != oldsock) {
741 vhost_net_disable_vq(n, vq); 749 vhost_net_disable_vq(n, vq);
742 rcu_assign_pointer(vq->private_data, sock); 750 rcu_assign_pointer(vq->private_data, sock);
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index c579dcc9200c..8b5a1b33d0fe 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -320,7 +320,7 @@ long vhost_dev_reset_owner(struct vhost_dev *dev)
320 vhost_dev_cleanup(dev); 320 vhost_dev_cleanup(dev);
321 321
322 memory->nregions = 0; 322 memory->nregions = 0;
323 dev->memory = memory; 323 RCU_INIT_POINTER(dev->memory, memory);
324 return 0; 324 return 0;
325} 325}
326 326
@@ -352,8 +352,9 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
352 fput(dev->log_file); 352 fput(dev->log_file);
353 dev->log_file = NULL; 353 dev->log_file = NULL;
354 /* No one will access memory at this point */ 354 /* No one will access memory at this point */
355 kfree(dev->memory); 355 kfree(rcu_dereference_protected(dev->memory,
356 dev->memory = NULL; 356 lockdep_is_held(&dev->mutex)));
357 RCU_INIT_POINTER(dev->memory, NULL);
357 if (dev->mm) 358 if (dev->mm)
358 mmput(dev->mm); 359 mmput(dev->mm);
359 dev->mm = NULL; 360 dev->mm = NULL;
@@ -440,14 +441,22 @@ static int vq_access_ok(unsigned int num,
440/* Caller should have device mutex but not vq mutex */ 441/* Caller should have device mutex but not vq mutex */
441int vhost_log_access_ok(struct vhost_dev *dev) 442int vhost_log_access_ok(struct vhost_dev *dev)
442{ 443{
443 return memory_access_ok(dev, dev->memory, 1); 444 struct vhost_memory *mp;
445
446 mp = rcu_dereference_protected(dev->memory,
447 lockdep_is_held(&dev->mutex));
448 return memory_access_ok(dev, mp, 1);
444} 449}
445 450
446/* Verify access for write logging. */ 451/* Verify access for write logging. */
447/* Caller should have vq mutex and device mutex */ 452/* Caller should have vq mutex and device mutex */
448static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base) 453static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base)
449{ 454{
450 return vq_memory_access_ok(log_base, vq->dev->memory, 455 struct vhost_memory *mp;
456
457 mp = rcu_dereference_protected(vq->dev->memory,
458 lockdep_is_held(&vq->mutex));
459 return vq_memory_access_ok(log_base, mp,
451 vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) && 460 vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) &&
452 (!vq->log_used || log_access_ok(log_base, vq->log_addr, 461 (!vq->log_used || log_access_ok(log_base, vq->log_addr,
453 sizeof *vq->used + 462 sizeof *vq->used +
@@ -487,7 +496,8 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
487 kfree(newmem); 496 kfree(newmem);
488 return -EFAULT; 497 return -EFAULT;
489 } 498 }
490 oldmem = d->memory; 499 oldmem = rcu_dereference_protected(d->memory,
500 lockdep_is_held(&d->mutex));
491 rcu_assign_pointer(d->memory, newmem); 501 rcu_assign_pointer(d->memory, newmem);
492 synchronize_rcu(); 502 synchronize_rcu();
493 kfree(oldmem); 503 kfree(oldmem);
@@ -858,11 +868,12 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
858 if (r < 0) 868 if (r < 0)
859 return r; 869 return r;
860 len -= l; 870 len -= l;
861 if (!len) 871 if (!len) {
872 if (vq->log_ctx)
873 eventfd_signal(vq->log_ctx, 1);
862 return 0; 874 return 0;
875 }
863 } 876 }
864 if (vq->log_ctx)
865 eventfd_signal(vq->log_ctx, 1);
866 /* Length written exceeds what we have stored. This is a bug. */ 877 /* Length written exceeds what we have stored. This is a bug. */
867 BUG(); 878 BUG();
868 return 0; 879 return 0;
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index afd77295971c..af3c11ded5fd 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -106,7 +106,7 @@ struct vhost_virtqueue {
106 * vhost_work execution acts instead of rcu_read_lock() and the end of 106 * vhost_work execution acts instead of rcu_read_lock() and the end of
107 * vhost_work execution acts instead of rcu_read_lock(). 107 * vhost_work execution acts instead of rcu_read_lock().
108 * Writers use virtqueue mutex. */ 108 * Writers use virtqueue mutex. */
109 void *private_data; 109 void __rcu *private_data;
110 /* Log write descriptors */ 110 /* Log write descriptors */
111 void __user *log_base; 111 void __user *log_base;
112 struct vhost_log log[VHOST_NET_MAX_SG]; 112 struct vhost_log log[VHOST_NET_MAX_SG];
@@ -116,7 +116,7 @@ struct vhost_dev {
116 /* Readers use RCU to access memory table pointer 116 /* Readers use RCU to access memory table pointer
117 * log base pointer and features. 117 * log base pointer and features.
118 * Writers use mutex below.*/ 118 * Writers use mutex below.*/
119 struct vhost_memory *memory; 119 struct vhost_memory __rcu *memory;
120 struct mm_struct *mm; 120 struct mm_struct *mm;
121 struct mutex mutex; 121 struct mutex mutex;
122 unsigned acked_features; 122 unsigned acked_features;
@@ -173,7 +173,11 @@ enum {
173 173
174static inline int vhost_has_feature(struct vhost_dev *dev, int bit) 174static inline int vhost_has_feature(struct vhost_dev *dev, int bit)
175{ 175{
176 unsigned acked_features = rcu_dereference(dev->acked_features); 176 unsigned acked_features;
177
178 acked_features =
179 rcu_dereference_index_check(dev->acked_features,
180 lockdep_is_held(&dev->mutex));
177 return acked_features & (1 << bit); 181 return acked_features & (1 << bit);
178} 182}
179 183
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 84f842331dfa..7ccc967831f0 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -3508,7 +3508,7 @@ static void fbcon_exit(void)
3508 softback_buf = 0UL; 3508 softback_buf = 0UL;
3509 3509
3510 for (i = 0; i < FB_MAX; i++) { 3510 for (i = 0; i < FB_MAX; i++) {
3511 int pending; 3511 int pending = 0;
3512 3512
3513 mapped = 0; 3513 mapped = 0;
3514 info = registered_fb[i]; 3514 info = registered_fb[i];
@@ -3516,7 +3516,8 @@ static void fbcon_exit(void)
3516 if (info == NULL) 3516 if (info == NULL)
3517 continue; 3517 continue;
3518 3518
3519 pending = cancel_work_sync(&info->queue); 3519 if (info->queue.func)
3520 pending = cancel_work_sync(&info->queue);
3520 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" : 3521 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3521 "no")); 3522 "no"));
3522 3523
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index 815f84b07933..70477c2e4b61 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -13,7 +13,7 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/screen_info.h> 14#include <linux/screen_info.h>
15#include <linux/dmi.h> 15#include <linux/dmi.h>
16 16#include <linux/pci.h>
17#include <video/vga.h> 17#include <video/vga.h>
18 18
19static struct fb_var_screeninfo efifb_defined __devinitdata = { 19static struct fb_var_screeninfo efifb_defined __devinitdata = {
@@ -39,17 +39,31 @@ enum {
39 M_I20, /* 20-Inch iMac */ 39 M_I20, /* 20-Inch iMac */
40 M_I20_SR, /* 20-Inch iMac (Santa Rosa) */ 40 M_I20_SR, /* 20-Inch iMac (Santa Rosa) */
41 M_I24, /* 24-Inch iMac */ 41 M_I24, /* 24-Inch iMac */
42 M_I24_8_1, /* 24-Inch iMac, 8,1th gen */
43 M_I24_10_1, /* 24-Inch iMac, 10,1th gen */
44 M_I27_11_1, /* 27-Inch iMac, 11,1th gen */
42 M_MINI, /* Mac Mini */ 45 M_MINI, /* Mac Mini */
46 M_MINI_3_1, /* Mac Mini, 3,1th gen */
47 M_MINI_4_1, /* Mac Mini, 4,1th gen */
43 M_MB, /* MacBook */ 48 M_MB, /* MacBook */
44 M_MB_2, /* MacBook, 2nd rev. */ 49 M_MB_2, /* MacBook, 2nd rev. */
45 M_MB_3, /* MacBook, 3rd rev. */ 50 M_MB_3, /* MacBook, 3rd rev. */
51 M_MB_5_1, /* MacBook, 5th rev. */
52 M_MB_6_1, /* MacBook, 6th rev. */
53 M_MB_7_1, /* MacBook, 7th rev. */
46 M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */ 54 M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */
47 M_MBA, /* MacBook Air */ 55 M_MBA, /* MacBook Air */
48 M_MBP, /* MacBook Pro */ 56 M_MBP, /* MacBook Pro */
49 M_MBP_2, /* MacBook Pro 2nd gen */ 57 M_MBP_2, /* MacBook Pro 2nd gen */
58 M_MBP_2_2, /* MacBook Pro 2,2nd gen */
50 M_MBP_SR, /* MacBook Pro (Santa Rosa) */ 59 M_MBP_SR, /* MacBook Pro (Santa Rosa) */
51 M_MBP_4, /* MacBook Pro, 4th gen */ 60 M_MBP_4, /* MacBook Pro, 4th gen */
52 M_MBP_5_1, /* MacBook Pro, 5,1th gen */ 61 M_MBP_5_1, /* MacBook Pro, 5,1th gen */
62 M_MBP_5_2, /* MacBook Pro, 5,2th gen */
63 M_MBP_5_3, /* MacBook Pro, 5,3rd gen */
64 M_MBP_6_1, /* MacBook Pro, 6,1th gen */
65 M_MBP_6_2, /* MacBook Pro, 6,2th gen */
66 M_MBP_7_1, /* MacBook Pro, 7,1th gen */
53 M_UNKNOWN /* placeholder */ 67 M_UNKNOWN /* placeholder */
54}; 68};
55 69
@@ -64,14 +78,28 @@ static struct efifb_dmi_info {
64 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */ 78 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */
65 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 }, 79 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 },
66 [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200 }, /* guess */ 80 [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200 }, /* guess */
81 [M_I24_8_1] = { "imac8", 0xc0060000, 2048 * 4, 1920, 1200 },
82 [M_I24_10_1] = { "imac10", 0xc0010000, 2048 * 4, 1920, 1080 },
83 [M_I27_11_1] = { "imac11", 0xc0010000, 2560 * 4, 2560, 1440 },
67 [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768 }, 84 [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768 },
85 [M_MINI_3_1] = { "mini31", 0x40010000, 1024 * 4, 1024, 768 },
86 [M_MINI_4_1] = { "mini41", 0xc0010000, 2048 * 4, 1920, 1200 },
68 [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800 }, 87 [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800 },
88 [M_MB_5_1] = { "macbook51", 0x80010000, 2048 * 4, 1280, 800 },
89 [M_MB_6_1] = { "macbook61", 0x80010000, 2048 * 4, 1280, 800 },
90 [M_MB_7_1] = { "macbook71", 0x80010000, 2048 * 4, 1280, 800 },
69 [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800 }, 91 [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800 },
70 [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900 }, 92 [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900 },
71 [M_MBP_2] = { "mbp2", 0, 0, 0, 0 }, /* placeholder */ 93 [M_MBP_2] = { "mbp2", 0, 0, 0, 0 }, /* placeholder */
94 [M_MBP_2_2] = { "mbp22", 0x80010000, 1472 * 4, 1440, 900 },
72 [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900 }, 95 [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900 },
73 [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200 }, 96 [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200 },
74 [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900 }, 97 [M_MBP_5_1] = { "mbp51", 0xc0010000, 2048 * 4, 1440, 900 },
98 [M_MBP_5_2] = { "mbp52", 0xc0010000, 2048 * 4, 1920, 1200 },
99 [M_MBP_5_3] = { "mbp53", 0xd0010000, 2048 * 4, 1440, 900 },
100 [M_MBP_6_1] = { "mbp61", 0x90030000, 2048 * 4, 1920, 1200 },
101 [M_MBP_6_2] = { "mbp62", 0x90030000, 2048 * 4, 1680, 1050 },
102 [M_MBP_7_1] = { "mbp71", 0xc0010000, 2048 * 4, 1280, 800 },
75 [M_UNKNOWN] = { NULL, 0, 0, 0, 0 } 103 [M_UNKNOWN] = { NULL, 0, 0, 0, 0 }
76}; 104};
77 105
@@ -92,7 +120,12 @@ static const struct dmi_system_id dmi_system_table[] __initconst = {
92 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24), 120 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
93 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24), 121 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
94 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR), 122 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
123 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac8,1", M_I24_8_1),
124 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac10,1", M_I24_10_1),
125 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac11,1", M_I27_11_1),
95 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI), 126 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
127 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini3,1", M_MINI_3_1),
128 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "Macmini4,1", M_MINI_4_1),
96 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB), 129 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
97 /* At least one of these two will be right; maybe both? */ 130 /* At least one of these two will be right; maybe both? */
98 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB), 131 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
@@ -101,14 +134,23 @@ static const struct dmi_system_id dmi_system_table[] __initconst = {
101 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB), 134 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
102 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB), 135 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
103 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB), 136 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
137 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook5,1", M_MB_5_1),
138 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook6,1", M_MB_6_1),
139 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook7,1", M_MB_7_1),
104 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA), 140 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
105 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP), 141 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
106 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2), 142 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
143 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,2", M_MBP_2_2),
107 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2), 144 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
108 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR), 145 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
109 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR), 146 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
110 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4), 147 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
111 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1), 148 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,1", M_MBP_5_1),
149 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,2", M_MBP_5_2),
150 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro5,3", M_MBP_5_3),
151 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,1", M_MBP_6_1),
152 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro6,2", M_MBP_6_2),
153 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro7,1", M_MBP_7_1),
112 {}, 154 {},
113}; 155};
114 156
@@ -116,7 +158,7 @@ static int set_system(const struct dmi_system_id *id)
116{ 158{
117 struct efifb_dmi_info *info = id->driver_data; 159 struct efifb_dmi_info *info = id->driver_data;
118 if (info->base == 0) 160 if (info->base == 0)
119 return -ENODEV; 161 return 0;
120 162
121 printk(KERN_INFO "efifb: dmi detected %s - framebuffer at %p " 163 printk(KERN_INFO "efifb: dmi detected %s - framebuffer at %p "
122 "(%dx%d, stride %d)\n", id->ident, 164 "(%dx%d, stride %d)\n", id->ident,
@@ -124,18 +166,55 @@ static int set_system(const struct dmi_system_id *id)
124 info->stride); 166 info->stride);
125 167
126 /* Trust the bootloader over the DMI tables */ 168 /* Trust the bootloader over the DMI tables */
127 if (screen_info.lfb_base == 0) 169 if (screen_info.lfb_base == 0) {
170#if defined(CONFIG_PCI)
171 struct pci_dev *dev = NULL;
172 int found_bar = 0;
173#endif
128 screen_info.lfb_base = info->base; 174 screen_info.lfb_base = info->base;
129 if (screen_info.lfb_linelength == 0)
130 screen_info.lfb_linelength = info->stride;
131 if (screen_info.lfb_width == 0)
132 screen_info.lfb_width = info->width;
133 if (screen_info.lfb_height == 0)
134 screen_info.lfb_height = info->height;
135 if (screen_info.orig_video_isVGA == 0)
136 screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
137 175
138 return 0; 176#if defined(CONFIG_PCI)
177 /* make sure that the address in the table is actually on a
178 * VGA device's PCI BAR */
179
180 for_each_pci_dev(dev) {
181 int i;
182 if ((dev->class >> 8) != PCI_CLASS_DISPLAY_VGA)
183 continue;
184 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
185 resource_size_t start, end;
186
187 start = pci_resource_start(dev, i);
188 if (start == 0)
189 break;
190 end = pci_resource_end(dev, i);
191 if (screen_info.lfb_base >= start &&
192 screen_info.lfb_base < end) {
193 found_bar = 1;
194 }
195 }
196 }
197 if (!found_bar)
198 screen_info.lfb_base = 0;
199#endif
200 }
201 if (screen_info.lfb_base) {
202 if (screen_info.lfb_linelength == 0)
203 screen_info.lfb_linelength = info->stride;
204 if (screen_info.lfb_width == 0)
205 screen_info.lfb_width = info->width;
206 if (screen_info.lfb_height == 0)
207 screen_info.lfb_height = info->height;
208 if (screen_info.orig_video_isVGA == 0)
209 screen_info.orig_video_isVGA = VIDEO_TYPE_EFI;
210 } else {
211 screen_info.lfb_linelength = 0;
212 screen_info.lfb_width = 0;
213 screen_info.lfb_height = 0;
214 screen_info.orig_video_isVGA = 0;
215 return 0;
216 }
217 return 1;
139} 218}
140 219
141static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, 220static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
diff --git a/drivers/video/omap2/vram.c b/drivers/video/omap2/vram.c
index f6fdc2085f3e..fed2a72bc6b6 100644
--- a/drivers/video/omap2/vram.c
+++ b/drivers/video/omap2/vram.c
@@ -554,12 +554,8 @@ void __init omap_vram_reserve_sdram_memblock(void)
554 size = PAGE_ALIGN(size); 554 size = PAGE_ALIGN(size);
555 555
556 if (paddr) { 556 if (paddr) {
557 struct memblock_property res; 557 if ((paddr & ~PAGE_MASK) ||
558 558 !memblock_is_region_memory(paddr, size)) {
559 res.base = paddr;
560 res.size = size;
561 if ((paddr & ~PAGE_MASK) || memblock_find(&res) ||
562 res.base != paddr || res.size != size) {
563 pr_err("Illegal SDRAM region for VRAM\n"); 559 pr_err("Illegal SDRAM region for VRAM\n");
564 return; 560 return;
565 } 561 }
diff --git a/drivers/video/pxa168fb.c b/drivers/video/pxa168fb.c
index 5d786bd3e304..cea6403ae71c 100644
--- a/drivers/video/pxa168fb.c
+++ b/drivers/video/pxa168fb.c
@@ -298,8 +298,8 @@ static void set_dma_control0(struct pxa168fb_info *fbi)
298 * Set bit to enable graphics DMA. 298 * Set bit to enable graphics DMA.
299 */ 299 */
300 x = readl(fbi->reg_base + LCD_SPU_DMA_CTRL0); 300 x = readl(fbi->reg_base + LCD_SPU_DMA_CTRL0);
301 x |= fbi->active ? 0x00000100 : 0; 301 x &= ~CFG_GRA_ENA_MASK;
302 fbi->active = 0; 302 x |= fbi->active ? CFG_GRA_ENA(1) : CFG_GRA_ENA(0);
303 303
304 /* 304 /*
305 * If we are in a pseudo-color mode, we need to enable 305 * If we are in a pseudo-color mode, we need to enable
@@ -784,12 +784,53 @@ failed:
784 return ret; 784 return ret;
785} 785}
786 786
787static int __devexit pxa168fb_remove(struct platform_device *pdev)
788{
789 struct pxa168fb_info *fbi = platform_get_drvdata(pdev);
790 struct fb_info *info;
791 int irq;
792 unsigned int data;
793
794 if (!fbi)
795 return 0;
796
797 /* disable DMA transfer */
798 data = readl(fbi->reg_base + LCD_SPU_DMA_CTRL0);
799 data &= ~CFG_GRA_ENA_MASK;
800 writel(data, fbi->reg_base + LCD_SPU_DMA_CTRL0);
801
802 info = fbi->info;
803
804 unregister_framebuffer(info);
805
806 writel(GRA_FRAME_IRQ0_ENA(0x0), fbi->reg_base + SPU_IRQ_ENA);
807
808 if (info->cmap.len)
809 fb_dealloc_cmap(&info->cmap);
810
811 irq = platform_get_irq(pdev, 0);
812 free_irq(irq, fbi);
813
814 dma_free_writecombine(fbi->dev, PAGE_ALIGN(info->fix.smem_len),
815 info->screen_base, info->fix.smem_start);
816
817 iounmap(fbi->reg_base);
818
819 clk_disable(fbi->clk);
820 clk_put(fbi->clk);
821
822 framebuffer_release(info);
823
824 return 0;
825}
826
787static struct platform_driver pxa168fb_driver = { 827static struct platform_driver pxa168fb_driver = {
788 .driver = { 828 .driver = {
789 .name = "pxa168-fb", 829 .name = "pxa168-fb",
790 .owner = THIS_MODULE, 830 .owner = THIS_MODULE,
791 }, 831 },
792 .probe = pxa168fb_probe, 832 .probe = pxa168fb_probe,
833 .remove = __devexit_p(pxa168fb_remove),
793}; 834};
794 835
795static int __init pxa168fb_init(void) 836static int __init pxa168fb_init(void)
@@ -798,6 +839,12 @@ static int __init pxa168fb_init(void)
798} 839}
799module_init(pxa168fb_init); 840module_init(pxa168fb_init);
800 841
842static void __exit pxa168fb_exit(void)
843{
844 platform_driver_unregister(&pxa168fb_driver);
845}
846module_exit(pxa168fb_exit);
847
801MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com> " 848MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com> "
802 "Green Wan <gwan@marvell.com>"); 849 "Green Wan <gwan@marvell.com>");
803MODULE_DESCRIPTION("Framebuffer driver for PXA168/910"); 850MODULE_DESCRIPTION("Framebuffer driver for PXA168/910");
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 559bf1727a2b..b52f8e4ef1fd 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -1701,6 +1701,9 @@ static int sisfb_ioctl(struct fb_info *info, unsigned int cmd,
1701 break; 1701 break;
1702 1702
1703 case FBIOGET_VBLANK: 1703 case FBIOGET_VBLANK:
1704
1705 memset(&sisvbblank, 0, sizeof(struct fb_vblank));
1706
1704 sisvbblank.count = 0; 1707 sisvbblank.count = 0;
1705 sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount); 1708 sisvbblank.flags = sisfb_setupvbblankflags(ivideo, &sisvbblank.vcount, &sisvbblank.hcount);
1706 1709
diff --git a/drivers/video/via/ioctl.c b/drivers/video/via/ioctl.c
index da03c074e32a..4d553d0b8d7a 100644
--- a/drivers/video/via/ioctl.c
+++ b/drivers/video/via/ioctl.c
@@ -25,6 +25,8 @@ int viafb_ioctl_get_viafb_info(u_long arg)
25{ 25{
26 struct viafb_ioctl_info viainfo; 26 struct viafb_ioctl_info viainfo;
27 27
28 memset(&viainfo, 0, sizeof(struct viafb_ioctl_info));
29
28 viainfo.viafb_id = VIAID; 30 viainfo.viafb_id = VIAID;
29 viainfo.vendor_id = PCI_VIA_VENDOR_ID; 31 viainfo.vendor_id = PCI_VIA_VENDOR_ID;
30 32
diff --git a/drivers/vlynq/vlynq.c b/drivers/vlynq/vlynq.c
index f2d9e667972d..f885c868a04d 100644
--- a/drivers/vlynq/vlynq.c
+++ b/drivers/vlynq/vlynq.c
@@ -31,6 +31,7 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/irq.h>
34 35
35#include <linux/vlynq.h> 36#include <linux/vlynq.h>
36 37
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b036677df8c4..c356146bd712 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -213,11 +213,11 @@ config OMAP_WATCHDOG
213 here to enable the OMAP1610/OMAP1710/OMAP2420/OMAP3430/OMAP4430 watchdog timer. 213 here to enable the OMAP1610/OMAP1710/OMAP2420/OMAP3430/OMAP4430 watchdog timer.
214 214
215config PNX4008_WATCHDOG 215config PNX4008_WATCHDOG
216 tristate "PNX4008 Watchdog" 216 tristate "PNX4008 and LPC32XX Watchdog"
217 depends on ARCH_PNX4008 217 depends on ARCH_PNX4008 || ARCH_LPC32XX
218 help 218 help
219 Say Y here if to include support for the watchdog timer 219 Say Y here if to include support for the watchdog timer
220 in the PNX4008 processor. 220 in the PNX4008 or LPC32XX processor.
221 This driver can be built as a module by choosing M. The module 221 This driver can be built as a module by choosing M. The module
222 will be called pnx4008_wdt. 222 will be called pnx4008_wdt.
223 223
@@ -957,12 +957,32 @@ config PIKA_WDT
957 the Warp platform. 957 the Warp platform.
958 958
959config BOOKE_WDT 959config BOOKE_WDT
960 bool "PowerPC Book-E Watchdog Timer" 960 tristate "PowerPC Book-E Watchdog Timer"
961 depends on BOOKE || 4xx 961 depends on BOOKE || 4xx
962 ---help--- 962 ---help---
963 Watchdog driver for PowerPC Book-E chips, such as the Freescale
964 MPC85xx SOCs and the IBM PowerPC 440.
965
963 Please see Documentation/watchdog/watchdog-api.txt for 966 Please see Documentation/watchdog/watchdog-api.txt for
964 more information. 967 more information.
965 968
969config BOOKE_WDT_DEFAULT_TIMEOUT
970 int "PowerPC Book-E Watchdog Timer Default Timeout"
971 depends on BOOKE_WDT
972 default 38 if FSL_BOOKE
973 range 0 63 if FSL_BOOKE
974 default 3 if !FSL_BOOKE
975 range 0 3 if !FSL_BOOKE
976 help
977 Select the default watchdog timer period to be used by the PowerPC
978 Book-E watchdog driver. A watchdog "event" occurs when the bit
979 position represented by this number transitions from zero to one.
980
981 For Freescale Book-E processors, this is a number between 0 and 63.
982 For other Book-E processors, this is a number between 0 and 3.
983
984 The value can be overidden by the wdt_period command-line parameter.
985
966# PPC64 Architecture 986# PPC64 Architecture
967 987
968config WATCHDOG_RTAS 988config WATCHDOG_RTAS
diff --git a/drivers/watchdog/booke_wdt.c b/drivers/watchdog/booke_wdt.c
index 3d49671cdf5a..d11ffb091b0d 100644
--- a/drivers/watchdog/booke_wdt.c
+++ b/drivers/watchdog/booke_wdt.c
@@ -4,7 +4,7 @@
4 * Author: Matthew McClintock 4 * Author: Matthew McClintock
5 * Maintainer: Kumar Gala <galak@kernel.crashing.org> 5 * Maintainer: Kumar Gala <galak@kernel.crashing.org>
6 * 6 *
7 * Copyright 2005, 2008 Freescale Semiconductor Inc. 7 * Copyright 2005, 2008, 2010 Freescale Semiconductor Inc.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the 10 * under the terms of the GNU General Public License as published by the
@@ -33,14 +33,8 @@
33 * occur, and the final time the board will reset. 33 * occur, and the final time the board will reset.
34 */ 34 */
35 35
36#ifdef CONFIG_FSL_BOOKE
37#define WDT_PERIOD_DEFAULT 38 /* Ex. wdt_period=28 bus=333Mhz,reset=~40sec */
38#else
39#define WDT_PERIOD_DEFAULT 3 /* Refer to the PPC40x and PPC4xx manuals */
40#endif /* for timing information */
41
42u32 booke_wdt_enabled; 36u32 booke_wdt_enabled;
43u32 booke_wdt_period = WDT_PERIOD_DEFAULT; 37u32 booke_wdt_period = CONFIG_BOOKE_WDT_DEFAULT_TIMEOUT;
44 38
45#ifdef CONFIG_FSL_BOOKE 39#ifdef CONFIG_FSL_BOOKE
46#define WDTP(x) ((((x)&0x3)<<30)|(((x)&0x3c)<<15)) 40#define WDTP(x) ((((x)&0x3)<<30)|(((x)&0x3c)<<15))
@@ -114,6 +108,27 @@ static void __booke_wdt_enable(void *data)
114 mtspr(SPRN_TCR, val); 108 mtspr(SPRN_TCR, val);
115} 109}
116 110
111/**
112 * booke_wdt_disable - disable the watchdog on the given CPU
113 *
114 * This function is called on each CPU. It disables the watchdog on that CPU.
115 *
116 * TCR[WRC] cannot be changed once it has been set to non-zero, but we can
117 * effectively disable the watchdog by setting its period to the maximum value.
118 */
119static void __booke_wdt_disable(void *data)
120{
121 u32 val;
122
123 val = mfspr(SPRN_TCR);
124 val &= ~(TCR_WIE | WDTP_MASK);
125 mtspr(SPRN_TCR, val);
126
127 /* clear status to make sure nothing is pending */
128 __booke_wdt_ping(NULL);
129
130}
131
117static ssize_t booke_wdt_write(struct file *file, const char __user *buf, 132static ssize_t booke_wdt_write(struct file *file, const char __user *buf,
118 size_t count, loff_t *ppos) 133 size_t count, loff_t *ppos)
119{ 134{
@@ -193,12 +208,21 @@ static int booke_wdt_open(struct inode *inode, struct file *file)
193 return nonseekable_open(inode, file); 208 return nonseekable_open(inode, file);
194} 209}
195 210
211static int booke_wdt_release(struct inode *inode, struct file *file)
212{
213 on_each_cpu(__booke_wdt_disable, NULL, 0);
214 booke_wdt_enabled = 0;
215
216 return 0;
217}
218
196static const struct file_operations booke_wdt_fops = { 219static const struct file_operations booke_wdt_fops = {
197 .owner = THIS_MODULE, 220 .owner = THIS_MODULE,
198 .llseek = no_llseek, 221 .llseek = no_llseek,
199 .write = booke_wdt_write, 222 .write = booke_wdt_write,
200 .unlocked_ioctl = booke_wdt_ioctl, 223 .unlocked_ioctl = booke_wdt_ioctl,
201 .open = booke_wdt_open, 224 .open = booke_wdt_open,
225 .release = booke_wdt_release,
202}; 226};
203 227
204static struct miscdevice booke_wdt_miscdev = { 228static struct miscdevice booke_wdt_miscdev = {
@@ -237,4 +261,9 @@ static int __init booke_wdt_init(void)
237 261
238 return ret; 262 return ret;
239} 263}
240device_initcall(booke_wdt_init); 264
265module_init(booke_wdt_init);
266module_exit(booke_wdt_exit);
267
268MODULE_DESCRIPTION("PowerPC Book-E watchdog driver");
269MODULE_LICENSE("GPL");
diff --git a/drivers/watchdog/cpwd.c b/drivers/watchdog/cpwd.c
index 51ae4e84f4f9..eca855a55c0d 100644
--- a/drivers/watchdog/cpwd.c
+++ b/drivers/watchdog/cpwd.c
@@ -25,7 +25,7 @@
25#include <linux/ioport.h> 25#include <linux/ioport.h>
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/smp_lock.h> 28#include <linux/mutex.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/of_device.h> 31#include <linux/of_device.h>
@@ -89,6 +89,7 @@ struct cpwd {
89 } devs[WD_NUMDEVS]; 89 } devs[WD_NUMDEVS];
90}; 90};
91 91
92static DEFINE_MUTEX(cpwd_mutex);
92static struct cpwd *cpwd_device; 93static struct cpwd *cpwd_device;
93 94
94/* Sun uses Altera PLD EPF8820ATC144-4 95/* Sun uses Altera PLD EPF8820ATC144-4
@@ -368,7 +369,7 @@ static int cpwd_open(struct inode *inode, struct file *f)
368{ 369{
369 struct cpwd *p = cpwd_device; 370 struct cpwd *p = cpwd_device;
370 371
371 lock_kernel(); 372 mutex_lock(&cpwd_mutex);
372 switch (iminor(inode)) { 373 switch (iminor(inode)) {
373 case WD0_MINOR: 374 case WD0_MINOR:
374 case WD1_MINOR: 375 case WD1_MINOR:
@@ -376,7 +377,7 @@ static int cpwd_open(struct inode *inode, struct file *f)
376 break; 377 break;
377 378
378 default: 379 default:
379 unlock_kernel(); 380 mutex_unlock(&cpwd_mutex);
380 return -ENODEV; 381 return -ENODEV;
381 } 382 }
382 383
@@ -386,13 +387,13 @@ static int cpwd_open(struct inode *inode, struct file *f)
386 IRQF_SHARED, DRIVER_NAME, p)) { 387 IRQF_SHARED, DRIVER_NAME, p)) {
387 printk(KERN_ERR PFX "Cannot register IRQ %d\n", 388 printk(KERN_ERR PFX "Cannot register IRQ %d\n",
388 p->irq); 389 p->irq);
389 unlock_kernel(); 390 mutex_unlock(&cpwd_mutex);
390 return -EBUSY; 391 return -EBUSY;
391 } 392 }
392 p->initialized = true; 393 p->initialized = true;
393 } 394 }
394 395
395 unlock_kernel(); 396 mutex_unlock(&cpwd_mutex);
396 397
397 return nonseekable_open(inode, f); 398 return nonseekable_open(inode, f);
398} 399}
@@ -482,9 +483,9 @@ static long cpwd_compat_ioctl(struct file *file, unsigned int cmd,
482 case WIOCSTART: 483 case WIOCSTART:
483 case WIOCSTOP: 484 case WIOCSTOP:
484 case WIOCGSTAT: 485 case WIOCGSTAT:
485 lock_kernel(); 486 mutex_lock(&cpwd_mutex);
486 rval = cpwd_ioctl(file, cmd, arg); 487 rval = cpwd_ioctl(file, cmd, arg);
487 unlock_kernel(); 488 mutex_unlock(&cpwd_mutex);
488 break; 489 break;
489 490
490 /* everything else is handled by the generic compat layer */ 491 /* everything else is handled by the generic compat layer */
diff --git a/drivers/watchdog/octeon-wdt-main.c b/drivers/watchdog/octeon-wdt-main.c
index 2a410170eca6..909923800a02 100644
--- a/drivers/watchdog/octeon-wdt-main.c
+++ b/drivers/watchdog/octeon-wdt-main.c
@@ -64,6 +64,7 @@
64#include <linux/cpu.h> 64#include <linux/cpu.h>
65#include <linux/smp.h> 65#include <linux/smp.h>
66#include <linux/fs.h> 66#include <linux/fs.h>
67#include <linux/irq.h>
67 68
68#include <asm/mipsregs.h> 69#include <asm/mipsregs.h>
69#include <asm/uasm.h> 70#include <asm/uasm.h>
diff --git a/drivers/watchdog/sb_wdog.c b/drivers/watchdog/sb_wdog.c
index 88c83aa57303..f31493e65b38 100644
--- a/drivers/watchdog/sb_wdog.c
+++ b/drivers/watchdog/sb_wdog.c
@@ -305,7 +305,7 @@ static int __init sbwdog_init(void)
305 if (ret) { 305 if (ret) {
306 printk(KERN_ERR "%s: failed to request irq 1 - %d\n", 306 printk(KERN_ERR "%s: failed to request irq 1 - %d\n",
307 ident.identity, ret); 307 ident.identity, ret);
308 return ret; 308 goto out;
309 } 309 }
310 310
311 ret = misc_register(&sbwdog_miscdev); 311 ret = misc_register(&sbwdog_miscdev);
@@ -313,14 +313,20 @@ static int __init sbwdog_init(void)
313 printk(KERN_INFO "%s: timeout is %ld.%ld secs\n", 313 printk(KERN_INFO "%s: timeout is %ld.%ld secs\n",
314 ident.identity, 314 ident.identity,
315 timeout / 1000000, (timeout / 100000) % 10); 315 timeout / 1000000, (timeout / 100000) % 10);
316 } else 316 return 0;
317 free_irq(1, (void *)user_dog); 317 }
318 free_irq(1, (void *)user_dog);
319out:
320 unregister_reboot_notifier(&sbwdog_notifier);
321
318 return ret; 322 return ret;
319} 323}
320 324
321static void __exit sbwdog_exit(void) 325static void __exit sbwdog_exit(void)
322{ 326{
323 misc_deregister(&sbwdog_miscdev); 327 misc_deregister(&sbwdog_miscdev);
328 free_irq(1, (void *)user_dog);
329 unregister_reboot_notifier(&sbwdog_notifier);
324} 330}
325 331
326module_init(sbwdog_init); 332module_init(sbwdog_init);
diff --git a/drivers/watchdog/ts72xx_wdt.c b/drivers/watchdog/ts72xx_wdt.c
index 458c499c1223..18cdeb4c4258 100644
--- a/drivers/watchdog/ts72xx_wdt.c
+++ b/drivers/watchdog/ts72xx_wdt.c
@@ -449,6 +449,9 @@ static __devinit int ts72xx_wdt_probe(struct platform_device *pdev)
449 wdt->pdev = pdev; 449 wdt->pdev = pdev;
450 mutex_init(&wdt->lock); 450 mutex_init(&wdt->lock);
451 451
452 /* make sure that the watchdog is disabled */
453 ts72xx_wdt_stop(wdt);
454
452 error = misc_register(&ts72xx_wdt_miscdev); 455 error = misc_register(&ts72xx_wdt_miscdev);
453 if (error) { 456 if (error) {
454 dev_err(&pdev->dev, "failed to register miscdev\n"); 457 dev_err(&pdev->dev, "failed to register miscdev\n");
diff --git a/drivers/xen/events.c b/drivers/xen/events.c
index 13365ba35218..7d24b0d94ed4 100644
--- a/drivers/xen/events.c
+++ b/drivers/xen/events.c
@@ -338,30 +338,29 @@ static void unmask_evtchn(int port)
338 338
339static int find_unbound_irq(void) 339static int find_unbound_irq(void)
340{ 340{
341 int irq; 341 struct irq_data *data;
342 struct irq_desc *desc; 342 int irq, res;
343 343
344 for (irq = 0; irq < nr_irqs; irq++) { 344 for (irq = 0; irq < nr_irqs; irq++) {
345 desc = irq_to_desc(irq); 345 data = irq_get_irq_data(irq);
346 /* only 0->15 have init'd desc; handle irq > 16 */ 346 /* only 0->15 have init'd desc; handle irq > 16 */
347 if (desc == NULL) 347 if (!data)
348 break; 348 break;
349 if (desc->chip == &no_irq_chip) 349 if (data->chip == &no_irq_chip)
350 break; 350 break;
351 if (desc->chip != &xen_dynamic_chip) 351 if (data->chip != &xen_dynamic_chip)
352 continue; 352 continue;
353 if (irq_info[irq].type == IRQT_UNBOUND) 353 if (irq_info[irq].type == IRQT_UNBOUND)
354 break; 354 return irq;
355 } 355 }
356 356
357 if (irq == nr_irqs) 357 if (irq == nr_irqs)
358 panic("No available IRQ to bind to: increase nr_irqs!\n"); 358 panic("No available IRQ to bind to: increase nr_irqs!\n");
359 359
360 desc = irq_to_desc_alloc_node(irq, 0); 360 res = irq_alloc_desc_at(irq, 0);
361 if (WARN_ON(desc == NULL))
362 return -1;
363 361
364 dynamic_irq_init_keep_chip_data(irq); 362 if (WARN_ON(res != irq))
363 return -1;
365 364
366 return irq; 365 return irq;
367} 366}
@@ -495,7 +494,7 @@ static void unbind_from_irq(unsigned int irq)
495 if (irq_info[irq].type != IRQT_UNBOUND) { 494 if (irq_info[irq].type != IRQT_UNBOUND) {
496 irq_info[irq] = mk_unbound_info(); 495 irq_info[irq] = mk_unbound_info();
497 496
498 dynamic_irq_cleanup(irq); 497 irq_free_desc(irq);
499 } 498 }
500 499
501 spin_unlock(&irq_mapping_update_lock); 500 spin_unlock(&irq_mapping_update_lock);
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 29bac5118877..d409495876f1 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -755,7 +755,10 @@ int register_xenstore_notifier(struct notifier_block *nb)
755{ 755{
756 int ret = 0; 756 int ret = 0;
757 757
758 blocking_notifier_chain_register(&xenstore_chain, nb); 758 if (xenstored_ready > 0)
759 ret = nb->notifier_call(nb, 0, NULL);
760 else
761 blocking_notifier_chain_register(&xenstore_chain, nb);
759 762
760 return ret; 763 return ret;
761} 764}
@@ -769,7 +772,7 @@ EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
769 772
770void xenbus_probe(struct work_struct *unused) 773void xenbus_probe(struct work_struct *unused)
771{ 774{
772 BUG_ON((xenstored_ready <= 0)); 775 xenstored_ready = 1;
773 776
774 /* Enumerate devices in xenstore and watch for changes. */ 777 /* Enumerate devices in xenstore and watch for changes. */
775 xenbus_probe_devices(&xenbus_frontend); 778 xenbus_probe_devices(&xenbus_frontend);
@@ -835,8 +838,8 @@ static int __init xenbus_init(void)
835 xen_store_evtchn = xen_start_info->store_evtchn; 838 xen_store_evtchn = xen_start_info->store_evtchn;
836 xen_store_mfn = xen_start_info->store_mfn; 839 xen_store_mfn = xen_start_info->store_mfn;
837 xen_store_interface = mfn_to_virt(xen_store_mfn); 840 xen_store_interface = mfn_to_virt(xen_store_mfn);
841 xenstored_ready = 1;
838 } 842 }
839 xenstored_ready = 1;
840 } 843 }
841 844
842 /* Initialize the interface to xenstore. */ 845 /* Initialize the interface to xenstore. */