aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig17
-rw-r--r--drivers/acpi/ac.c9
-rw-r--r--drivers/acpi/acpi_memhotplug.c5
-rw-r--r--drivers/acpi/asus_acpi.c70
-rw-r--r--drivers/acpi/battery.c31
-rw-r--r--drivers/acpi/button.c223
-rw-r--r--drivers/acpi/container.c5
-rw-r--r--drivers/acpi/dock.c153
-rw-r--r--drivers/acpi/ec.c356
-rw-r--r--drivers/acpi/events/evmisc.c1
-rw-r--r--drivers/acpi/executer/exmutex.c6
-rw-r--r--drivers/acpi/fan.c9
-rw-r--r--drivers/acpi/glue.c10
-rw-r--r--drivers/acpi/hotkey.c5
-rw-r--r--drivers/acpi/i2c_ec.c8
-rw-r--r--drivers/acpi/ibm_acpi.c1053
-rw-r--r--drivers/acpi/namespace/nsxfobj.c44
-rw-r--r--drivers/acpi/numa.c2
-rw-r--r--drivers/acpi/osl.c5
-rw-r--r--drivers/acpi/pci_bind.c16
-rw-r--r--drivers/acpi/pci_irq.c9
-rw-r--r--drivers/acpi/pci_link.c14
-rw-r--r--drivers/acpi/pci_root.c16
-rw-r--r--drivers/acpi/power.c9
-rw-r--r--drivers/acpi/processor_core.c17
-rw-r--r--drivers/acpi/processor_idle.c26
-rw-r--r--drivers/acpi/processor_perflib.c10
-rw-r--r--drivers/acpi/processor_thermal.c6
-rw-r--r--drivers/acpi/processor_throttling.c6
-rw-r--r--drivers/acpi/sbs.c27
-rw-r--r--drivers/acpi/scan.c3
-rw-r--r--drivers/acpi/sleep/wakeup.c6
-rw-r--r--drivers/acpi/tables.c2
-rw-r--r--drivers/acpi/tables/tbxface.c54
-rw-r--r--drivers/acpi/thermal.c37
-rw-r--r--drivers/acpi/toshiba_acpi.c89
-rw-r--r--drivers/acpi/utilities/utdebug.c5
-rw-r--r--drivers/acpi/utilities/utmutex.c16
-rw-r--r--drivers/acpi/utils.c10
-rw-r--r--drivers/acpi/video.c110
-rw-r--r--drivers/ata/Kconfig6
-rw-r--r--drivers/ata/ahci.c10
-rw-r--r--drivers/ata/ata_piix.c22
-rw-r--r--drivers/ata/libata-core.c14
-rw-r--r--drivers/ata/libata-scsi.c242
-rw-r--r--drivers/ata/pata_cs5530.c3
-rw-r--r--drivers/ata/pata_legacy.c4
-rw-r--r--drivers/ata/pata_qdi.c4
-rw-r--r--drivers/ata/pata_rz1000.c2
-rw-r--r--drivers/ata/pata_via.c11
-rw-r--r--drivers/ata/pata_winbond.c4
-rw-r--r--drivers/ata/sata_nv.c8
-rw-r--r--drivers/ata/sata_svw.c82
-rw-r--r--drivers/ata/sata_vsc.c43
-rw-r--r--drivers/atm/Kconfig4
-rw-r--r--drivers/atm/fore200e.c166
-rw-r--r--drivers/base/firmware_class.c1
-rw-r--r--drivers/block/aoe/aoecmd.c13
-rw-r--r--drivers/block/cciss.c6
-rw-r--r--drivers/block/viodasd.c6
-rw-r--r--drivers/bluetooth/hci_usb.c1
-rw-r--r--drivers/cdrom/cdrom.c3
-rw-r--r--drivers/cdrom/viocd.c4
-rw-r--r--drivers/char/drm/drmP.h7
-rw-r--r--drivers/char/drm/drm_lock.c2
-rw-r--r--drivers/char/drm/drm_stub.c12
-rw-r--r--drivers/char/drm/drm_sysfs.c8
-rw-r--r--drivers/char/drm/i915_irq.c199
-rw-r--r--drivers/char/drm/r128_drm.h3
-rw-r--r--drivers/char/drm/r128_drv.h3
-rw-r--r--drivers/char/drm/r128_state.c3
-rw-r--r--drivers/char/drm/r300_cmdbuf.c32
-rw-r--r--drivers/char/drm/radeon_drv.h15
-rw-r--r--drivers/char/drm/radeon_irq.c4
-rw-r--r--drivers/char/drm/radeon_mem.c4
-rw-r--r--drivers/char/drm/radeon_state.c13
-rw-r--r--drivers/char/drm/savage_bci.c4
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c11
-rw-r--r--drivers/char/isicom.c103
-rw-r--r--drivers/char/mxser.c1
-rw-r--r--drivers/char/mxser_new.c1
-rw-r--r--drivers/char/rtc.c7
-rw-r--r--drivers/char/tlclk.c2
-rw-r--r--drivers/char/viocons.c7
-rw-r--r--drivers/char/viotape.c5
-rw-r--r--drivers/connector/cn_queue.c5
-rw-r--r--drivers/connector/connector.c17
-rw-r--r--drivers/cpufreq/cpufreq.c2
-rw-r--r--drivers/hid/hid-input.c44
-rw-r--r--drivers/ide/pci/atiixp.c1
-rw-r--r--drivers/ide/pci/piix.c66
-rw-r--r--drivers/ide/pci/slc90e66.c20
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c113
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c3
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c2
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h2
-rw-r--r--drivers/input/keyboard/amikbd.c2
-rw-r--r--drivers/input/keyboard/sunkbd.c2
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c1
-rw-r--r--drivers/kvm/kvm.h18
-rw-r--r--drivers/kvm/kvm_main.c151
-rw-r--r--drivers/kvm/mmu.c22
-rw-r--r--drivers/kvm/paging_tmpl.h4
-rw-r--r--drivers/kvm/svm.c69
-rw-r--r--drivers/kvm/vmx.c74
-rw-r--r--drivers/kvm/vmx.h10
-rw-r--r--drivers/macintosh/via-pmu-backlight.c2
-rw-r--r--drivers/md/md.c13
-rw-r--r--drivers/media/common/ir-functions.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c4
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c4
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c2
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c4
-rw-r--r--drivers/media/video/cafe_ccic.c2
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c4
-rw-r--r--drivers/media/video/cx2341x.c21
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c9
-rw-r--r--drivers/media/video/cx88/cx88-cards.c2
-rw-r--r--drivers/media/video/cx88/cx88-core.c35
-rw-r--r--drivers/media/video/cx88/cx88.h2
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c4
-rw-r--r--drivers/media/video/meye.c4
-rw-r--r--drivers/media/video/msp3400-driver.c8
-rw-r--r--drivers/media/video/msp3400-kthreads.c11
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c8
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c11
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c83
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c35
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c150
-rw-r--r--drivers/media/video/usbvision/usbvision.h27
-rw-r--r--drivers/media/video/vivi.c8
-rw-r--r--drivers/media/video/w9966.c2
-rw-r--r--drivers/media/video/w9968cf.c24
-rw-r--r--drivers/media/video/zoran_device.c3
-rw-r--r--drivers/message/i2o/exec-osm.c2
-rw-r--r--drivers/misc/msi-laptop.c3
-rw-r--r--drivers/mtd/devices/m25p80.c4
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c2
-rw-r--r--drivers/net/8139cp.c6
-rw-r--r--drivers/net/arm/ep93xx_eth.c4
-rw-r--r--drivers/net/b44.c6
-rw-r--r--drivers/net/bnx2.c23
-rw-r--r--drivers/net/e1000/e1000_ethtool.c3
-rw-r--r--drivers/net/e1000/e1000_hw.c296
-rw-r--r--drivers/net/e1000/e1000_hw.h310
-rw-r--r--drivers/net/e1000/e1000_main.c345
-rw-r--r--drivers/net/e1000/e1000_param.c4
-rw-r--r--drivers/net/forcedeth.c16
-rw-r--r--drivers/net/ibm_emac/ibm_emac_phy.c4
-rw-r--r--drivers/net/iseries_veth.c9
-rw-r--r--drivers/net/myri10ge/myri10ge.c163
-rw-r--r--drivers/net/netxen/netxen_nic.h25
-rw-r--r--drivers/net/netxen/netxen_nic_ethtool.c5
-rw-r--r--drivers/net/netxen/netxen_nic_hw.c296
-rw-r--r--drivers/net/netxen/netxen_nic_init.c251
-rw-r--r--drivers/net/netxen/netxen_nic_ioctl.h77
-rw-r--r--drivers/net/netxen/netxen_nic_isr.c3
-rw-r--r--drivers/net/netxen/netxen_nic_main.c85
-rw-r--r--drivers/net/r8169.c6
-rw-r--r--drivers/net/skge.c5
-rw-r--r--drivers/net/sky2.c35
-rw-r--r--drivers/net/smc911x.c23
-rw-r--r--drivers/net/tg3.c42
-rw-r--r--drivers/net/tg3.h1
-rw-r--r--drivers/net/via-velocity.c18
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c96
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.h5
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c4
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c2
-rw-r--r--drivers/pci/hotplug/acpiphp_ibm.c3
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c47
-rw-r--r--drivers/pci/hotplug/shpchp.h238
-rw-r--r--drivers/pci/hotplug/shpchp_core.c116
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c21
-rw-r--r--drivers/pci/hotplug/shpchp_hpc.c223
-rw-r--r--drivers/pci/htirq.c9
-rw-r--r--drivers/pci/pci-driver.c12
-rw-r--r--drivers/pci/pci.c112
-rw-r--r--drivers/pci/pcie/portdrv_pci.c2
-rw-r--r--drivers/pci/probe.c10
-rw-r--r--drivers/pci/quirks.c217
-rw-r--r--drivers/pci/search.c38
-rw-r--r--drivers/pci/setup-bus.c2
-rw-r--r--drivers/pci/setup-res.c19
-rw-r--r--drivers/s390/char/monwriter.c2
-rw-r--r--drivers/s390/char/sclp_cpi.c2
-rw-r--r--drivers/s390/cio/cio.c36
-rw-r--r--drivers/s390/cio/css.c3
-rw-r--r--drivers/s390/cio/qdio.c13
-rw-r--r--drivers/s390/crypto/ap_bus.c14
-rw-r--r--drivers/scsi/ibmvscsi/Makefile2
-rw-r--r--drivers/scsi/scsi_lib.c4
-rw-r--r--drivers/scsi/sun3_NCR5380.c6
-rw-r--r--drivers/serial/uartlite.c4
-rw-r--r--drivers/spi/spi_mpc83xx.c2
-rw-r--r--drivers/spi/spi_s3c24xx.c2
-rw-r--r--drivers/spi/spi_s3c24xx_gpio.c3
-rw-r--r--drivers/usb/class/usblp.c54
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/gadget/at91_udc.c236
-rw-r--r--drivers/usb/gadget/at91_udc.h7
-rw-r--r--drivers/usb/gadget/dummy_hcd.c7
-rw-r--r--drivers/usb/gadget/file_storage.c2
-rw-r--r--drivers/usb/gadget/gmidi.c12
-rw-r--r--drivers/usb/gadget/goku_udc.c12
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c13
-rw-r--r--drivers/usb/gadget/net2280.c11
-rw-r--r--drivers/usb/gadget/omap_udc.c13
-rw-r--r--drivers/usb/gadget/pxa2xx_udc.c7
-rw-r--r--drivers/usb/gadget/serial.c2
-rw-r--r--drivers/usb/host/ohci-at91.c3
-rw-r--r--drivers/usb/host/ohci-au1xxx.c4
-rw-r--r--drivers/usb/host/ohci-dbg.c8
-rw-r--r--drivers/usb/host/ohci-ep93xx.c2
-rw-r--r--drivers/usb/host/ohci-hcd.c110
-rw-r--r--drivers/usb/host/ohci-hub.c21
-rw-r--r--drivers/usb/host/ohci-lh7a404.c8
-rw-r--r--drivers/usb/host/ohci-mem.c10
-rw-r--r--drivers/usb/host/ohci-omap.c4
-rw-r--r--drivers/usb/host/ohci-pci.c16
-rw-r--r--drivers/usb/host/ohci-pnx4008.c4
-rw-r--r--drivers/usb/host/ohci-pnx8550.c258
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c8
-rw-r--r--drivers/usb/host/ohci-pxa27x.c10
-rw-r--r--drivers/usb/host/ohci-q.c103
-rw-r--r--drivers/usb/host/ohci-s3c2410.c4
-rw-r--r--drivers/usb/host/ohci-sa1111.c8
-rw-r--r--drivers/usb/host/ohci.h92
-rw-r--r--drivers/usb/host/u132-hcd.c92
-rw-r--r--drivers/usb/host/uhci-hcd.c13
-rw-r--r--drivers/usb/host/uhci-hub.c14
-rw-r--r--drivers/usb/input/Kconfig5
-rw-r--r--drivers/usb/input/wacom_sys.c4
-rw-r--r--drivers/usb/input/wacom_wac.c26
-rw-r--r--drivers/usb/misc/appledisplay.c2
-rw-r--r--drivers/usb/misc/auerswald.c6
-rw-r--r--drivers/usb/misc/ftdi-elan.c592
-rw-r--r--drivers/usb/misc/phidgetservo.c1
-rw-r--r--drivers/usb/misc/trancevibrator.c2
-rw-r--r--drivers/usb/net/gl620a.c154
-rw-r--r--drivers/usb/net/rtl8150.c6
-rw-r--r--drivers/usb/serial/airprime.c3
-rw-r--r--drivers/usb/serial/cp2101.c1
-rw-r--r--drivers/usb/serial/cypress_m8.c15
-rw-r--r--drivers/usb/serial/ftdi_sio.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.h5
-rw-r--r--drivers/usb/serial/funsoft.c27
-rw-r--r--drivers/usb/serial/kl5kusb105.c68
-rw-r--r--drivers/usb/serial/mos7840.c6
-rw-r--r--drivers/usb/serial/option.c3
-rw-r--r--drivers/usb/storage/unusual_devs.h16
-rw-r--r--drivers/video/aty/aty128fb.c2
-rw-r--r--drivers/video/aty/atyfb_base.c2
-rw-r--r--drivers/video/aty/radeon_backlight.c2
-rw-r--r--drivers/video/backlight/backlight.c7
-rw-r--r--drivers/video/gxt4500.c95
-rw-r--r--drivers/video/nvidia/nv_backlight.c2
-rw-r--r--drivers/video/pxafb.c40
-rw-r--r--drivers/video/riva/fbdev.c2
-rw-r--r--drivers/video/sa1100fb.c6
262 files changed, 5731 insertions, 4607 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 0f9d4be7ed75..1639998e4d27 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -11,7 +11,7 @@ config ACPI
11 bool "ACPI Support" 11 bool "ACPI Support"
12 depends on IA64 || X86 12 depends on IA64 || X86
13 depends on PCI 13 depends on PCI
14 select PM 14 depends on PM
15 default y 15 default y
16 ---help--- 16 ---help---
17 Advanced Configuration and Power Interface (ACPI) support for 17 Advanced Configuration and Power Interface (ACPI) support for
@@ -97,6 +97,7 @@ config ACPI_BATTERY
97 97
98config ACPI_BUTTON 98config ACPI_BUTTON
99 tristate "Button" 99 tristate "Button"
100 depends on INPUT
100 default y 101 default y
101 help 102 help
102 This driver handles events on the power, sleep and lid buttons. 103 This driver handles events on the power, sleep and lid buttons.
@@ -172,6 +173,7 @@ config ACPI_NUMA
172config ACPI_ASUS 173config ACPI_ASUS
173 tristate "ASUS/Medion Laptop Extras" 174 tristate "ASUS/Medion Laptop Extras"
174 depends on X86 175 depends on X86
176 select BACKLIGHT_CLASS_DEVICE
175 ---help--- 177 ---help---
176 This driver provides support for extra features of ACPI-compatible 178 This driver provides support for extra features of ACPI-compatible
177 ASUS laptops. As some of Medion laptops are made by ASUS, it may also 179 ASUS laptops. As some of Medion laptops are made by ASUS, it may also
@@ -200,6 +202,7 @@ config ACPI_ASUS
200config ACPI_IBM 202config ACPI_IBM
201 tristate "IBM ThinkPad Laptop Extras" 203 tristate "IBM ThinkPad Laptop Extras"
202 depends on X86 204 depends on X86
205 select BACKLIGHT_CLASS_DEVICE
203 ---help--- 206 ---help---
204 This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds 207 This is a Linux ACPI driver for the IBM ThinkPad laptops. It adds
205 support for Fn-Fx key combinations, Bluetooth control, video 208 support for Fn-Fx key combinations, Bluetooth control, video
@@ -222,9 +225,21 @@ config ACPI_IBM_DOCK
222 225
223 If you are not sure, say N here. 226 If you are not sure, say N here.
224 227
228config ACPI_IBM_BAY
229 bool "Legacy Removable Bay Support"
230 depends on ACPI_IBM
231 depends on ACPI_BAY=n
232 default n
233 ---help---
234 Allows the ibm_acpi driver to handle removable bays.
235 This support is obsoleted by CONFIG_ACPI_BAY.
236
237 If you are not sure, say N here.
238
225config ACPI_TOSHIBA 239config ACPI_TOSHIBA
226 tristate "Toshiba Laptop Extras" 240 tristate "Toshiba Laptop Extras"
227 depends on X86 241 depends on X86
242 select BACKLIGHT_CLASS_DEVICE
228 ---help--- 243 ---help---
229 This driver adds support for access to certain system settings 244 This driver adds support for access to certain system settings
230 on "legacy free" Toshiba laptops. These laptops can be recognized by 245 on "legacy free" Toshiba laptops. These laptops can be recognized by
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 11abc7bf777e..6daeace796a8 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -109,7 +109,7 @@ static struct proc_dir_entry *acpi_ac_dir;
109 109
110static int acpi_ac_seq_show(struct seq_file *seq, void *offset) 110static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
111{ 111{
112 struct acpi_ac *ac = (struct acpi_ac *)seq->private; 112 struct acpi_ac *ac = seq->private;
113 113
114 114
115 if (!ac) 115 if (!ac)
@@ -187,7 +187,7 @@ static int acpi_ac_remove_fs(struct acpi_device *device)
187 187
188static void acpi_ac_notify(acpi_handle handle, u32 event, void *data) 188static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
189{ 189{
190 struct acpi_ac *ac = (struct acpi_ac *)data; 190 struct acpi_ac *ac = data;
191 struct acpi_device *device = NULL; 191 struct acpi_device *device = NULL;
192 192
193 193
@@ -221,10 +221,9 @@ static int acpi_ac_add(struct acpi_device *device)
221 if (!device) 221 if (!device)
222 return -EINVAL; 222 return -EINVAL;
223 223
224 ac = kmalloc(sizeof(struct acpi_ac), GFP_KERNEL); 224 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
225 if (!ac) 225 if (!ac)
226 return -ENOMEM; 226 return -ENOMEM;
227 memset(ac, 0, sizeof(struct acpi_ac));
228 227
229 ac->device = device; 228 ac->device = device;
230 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME); 229 strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
@@ -269,7 +268,7 @@ static int acpi_ac_remove(struct acpi_device *device, int type)
269 if (!device || !acpi_driver_data(device)) 268 if (!device || !acpi_driver_data(device))
270 return -EINVAL; 269 return -EINVAL;
271 270
272 ac = (struct acpi_ac *)acpi_driver_data(device); 271 ac = acpi_driver_data(device);
273 272
274 status = acpi_remove_notify_handler(device->handle, 273 status = acpi_remove_notify_handler(device->handle,
275 ACPI_ALL_NOTIFY, acpi_ac_notify); 274 ACPI_ALL_NOTIFY, acpi_ac_notify);
diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
index 6bcd9e8e7bcb..cd946ed192d3 100644
--- a/drivers/acpi/acpi_memhotplug.c
+++ b/drivers/acpi/acpi_memhotplug.c
@@ -395,10 +395,9 @@ static int acpi_memory_device_add(struct acpi_device *device)
395 if (!device) 395 if (!device)
396 return -EINVAL; 396 return -EINVAL;
397 397
398 mem_device = kmalloc(sizeof(struct acpi_memory_device), GFP_KERNEL); 398 mem_device = kzalloc(sizeof(struct acpi_memory_device), GFP_KERNEL);
399 if (!mem_device) 399 if (!mem_device)
400 return -ENOMEM; 400 return -ENOMEM;
401 memset(mem_device, 0, sizeof(struct acpi_memory_device));
402 401
403 INIT_LIST_HEAD(&mem_device->res_list); 402 INIT_LIST_HEAD(&mem_device->res_list);
404 mem_device->device = device; 403 mem_device->device = device;
@@ -429,7 +428,7 @@ static int acpi_memory_device_remove(struct acpi_device *device, int type)
429 if (!device || !acpi_driver_data(device)) 428 if (!device || !acpi_driver_data(device))
430 return -EINVAL; 429 return -EINVAL;
431 430
432 mem_device = (struct acpi_memory_device *)acpi_driver_data(device); 431 mem_device = acpi_driver_data(device);
433 kfree(mem_device); 432 kfree(mem_device);
434 433
435 return 0; 434 return 0;
diff --git a/drivers/acpi/asus_acpi.c b/drivers/acpi/asus_acpi.c
index c7ac9297a204..396140bbbe57 100644
--- a/drivers/acpi/asus_acpi.c
+++ b/drivers/acpi/asus_acpi.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/backlight.h>
38#include <acpi/acpi_drivers.h> 39#include <acpi/acpi_drivers.h>
39#include <acpi/acpi_bus.h> 40#include <acpi/acpi_bus.h>
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
@@ -402,6 +403,8 @@ static struct model_data model_conf[END_MODEL] = {
402/* procdir we use */ 403/* procdir we use */
403static struct proc_dir_entry *asus_proc_dir; 404static struct proc_dir_entry *asus_proc_dir;
404 405
406static struct backlight_device *asus_backlight_device;
407
405/* 408/*
406 * This header is made available to allow proper configuration given model, 409 * This header is made available to allow proper configuration given model,
407 * revision number , ... this info cannot go in struct asus_hotk because it is 410 * revision number , ... this info cannot go in struct asus_hotk because it is
@@ -779,7 +782,7 @@ proc_write_lcd(struct file *file, const char __user * buffer,
779 return rv; 782 return rv;
780} 783}
781 784
782static int read_brightness(void) 785static int read_brightness(struct backlight_device *bd)
783{ 786{
784 int value; 787 int value;
785 788
@@ -801,9 +804,10 @@ static int read_brightness(void)
801/* 804/*
802 * Change the brightness level 805 * Change the brightness level
803 */ 806 */
804static void set_brightness(int value) 807static int set_brightness(int value)
805{ 808{
806 acpi_status status = 0; 809 acpi_status status = 0;
810 int ret = 0;
807 811
808 /* SPLV laptop */ 812 /* SPLV laptop */
809 if (hotk->methods->brightness_set) { 813 if (hotk->methods->brightness_set) {
@@ -811,11 +815,12 @@ static void set_brightness(int value)
811 value, NULL)) 815 value, NULL))
812 printk(KERN_WARNING 816 printk(KERN_WARNING
813 "Asus ACPI: Error changing brightness\n"); 817 "Asus ACPI: Error changing brightness\n");
814 return; 818 ret = -EIO;
819 goto out;
815 } 820 }
816 821
817 /* No SPLV method if we are here, act as appropriate */ 822 /* No SPLV method if we are here, act as appropriate */
818 value -= read_brightness(); 823 value -= read_brightness(NULL);
819 while (value != 0) { 824 while (value != 0) {
820 status = acpi_evaluate_object(NULL, (value > 0) ? 825 status = acpi_evaluate_object(NULL, (value > 0) ?
821 hotk->methods->brightness_up : 826 hotk->methods->brightness_up :
@@ -825,15 +830,22 @@ static void set_brightness(int value)
825 if (ACPI_FAILURE(status)) 830 if (ACPI_FAILURE(status))
826 printk(KERN_WARNING 831 printk(KERN_WARNING
827 "Asus ACPI: Error changing brightness\n"); 832 "Asus ACPI: Error changing brightness\n");
833 ret = -EIO;
828 } 834 }
829 return; 835out:
836 return ret;
837}
838
839static int set_brightness_status(struct backlight_device *bd)
840{
841 return set_brightness(bd->props->brightness);
830} 842}
831 843
832static int 844static int
833proc_read_brn(char *page, char **start, off_t off, int count, int *eof, 845proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
834 void *data) 846 void *data)
835{ 847{
836 return sprintf(page, "%d\n", read_brightness()); 848 return sprintf(page, "%d\n", read_brightness(NULL));
837} 849}
838 850
839static int 851static int
@@ -1134,7 +1146,7 @@ static int asus_hotk_get_info(void)
1134 if (ACPI_FAILURE(status)) 1146 if (ACPI_FAILURE(status))
1135 printk(KERN_WARNING " Couldn't get the DSDT table header\n"); 1147 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
1136 else 1148 else
1137 asus_info = (struct acpi_table_header *)dsdt.pointer; 1149 asus_info = dsdt.pointer;
1138 1150
1139 /* We have to write 0 on init this far for all ASUS models */ 1151 /* We have to write 0 on init this far for all ASUS models */
1140 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { 1152 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
@@ -1156,7 +1168,7 @@ static int asus_hotk_get_info(void)
1156 * asus_model_match() and try something completely different. 1168 * asus_model_match() and try something completely different.
1157 */ 1169 */
1158 if (buffer.pointer) { 1170 if (buffer.pointer) {
1159 model = (union acpi_object *)buffer.pointer; 1171 model = buffer.pointer;
1160 switch (model->type) { 1172 switch (model->type) {
1161 case ACPI_TYPE_STRING: 1173 case ACPI_TYPE_STRING:
1162 string = model->string.pointer; 1174 string = model->string.pointer;
@@ -1252,11 +1264,9 @@ static int asus_hotk_add(struct acpi_device *device)
1252 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n", 1264 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1253 ASUS_ACPI_VERSION); 1265 ASUS_ACPI_VERSION);
1254 1266
1255 hotk = 1267 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1256 (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
1257 if (!hotk) 1268 if (!hotk)
1258 return -ENOMEM; 1269 return -ENOMEM;
1259 memset(hotk, 0, sizeof(struct asus_hotk));
1260 1270
1261 hotk->handle = device->handle; 1271 hotk->handle = device->handle;
1262 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME); 1272 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
@@ -1333,6 +1343,26 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
1333 return 0; 1343 return 0;
1334} 1344}
1335 1345
1346static struct backlight_properties asus_backlight_data = {
1347 .owner = THIS_MODULE,
1348 .get_brightness = read_brightness,
1349 .update_status = set_brightness_status,
1350 .max_brightness = 15,
1351};
1352
1353static void __exit asus_acpi_exit(void)
1354{
1355 if (asus_backlight_device)
1356 backlight_device_unregister(asus_backlight_device);
1357
1358 acpi_bus_unregister_driver(&asus_hotk_driver);
1359 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1360
1361 kfree(asus_info);
1362
1363 return;
1364}
1365
1336static int __init asus_acpi_init(void) 1366static int __init asus_acpi_init(void)
1337{ 1367{
1338 int result; 1368 int result;
@@ -1370,17 +1400,15 @@ static int __init asus_acpi_init(void)
1370 return result; 1400 return result;
1371 } 1401 }
1372 1402
1373 return 0; 1403 asus_backlight_device = backlight_device_register("asus",NULL,NULL,
1374} 1404 &asus_backlight_data);
1375 1405 if (IS_ERR(asus_backlight_device)) {
1376static void __exit asus_acpi_exit(void) 1406 printk(KERN_ERR "Could not register asus backlight device\n");
1377{ 1407 asus_backlight_device = NULL;
1378 acpi_bus_unregister_driver(&asus_hotk_driver); 1408 asus_acpi_exit();
1379 remove_proc_entry(PROC_ASUS, acpi_root_dir); 1409 }
1380
1381 kfree(asus_info);
1382 1410
1383 return; 1411 return 0;
1384} 1412}
1385 1413
1386module_init(asus_acpi_init); 1414module_init(asus_acpi_init);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 026e40755cdd..5f43e0d14899 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -149,7 +149,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
149 return -ENODEV; 149 return -ENODEV;
150 } 150 }
151 151
152 package = (union acpi_object *)buffer.pointer; 152 package = buffer.pointer;
153 153
154 /* Extract Package Data */ 154 /* Extract Package Data */
155 155
@@ -160,12 +160,11 @@ acpi_battery_get_info(struct acpi_battery *battery,
160 goto end; 160 goto end;
161 } 161 }
162 162
163 data.pointer = kmalloc(data.length, GFP_KERNEL); 163 data.pointer = kzalloc(data.length, GFP_KERNEL);
164 if (!data.pointer) { 164 if (!data.pointer) {
165 result = -ENOMEM; 165 result = -ENOMEM;
166 goto end; 166 goto end;
167 } 167 }
168 memset(data.pointer, 0, data.length);
169 168
170 status = acpi_extract_package(package, &format, &data); 169 status = acpi_extract_package(package, &format, &data);
171 if (ACPI_FAILURE(status)) { 170 if (ACPI_FAILURE(status)) {
@@ -179,7 +178,7 @@ acpi_battery_get_info(struct acpi_battery *battery,
179 kfree(buffer.pointer); 178 kfree(buffer.pointer);
180 179
181 if (!result) 180 if (!result)
182 (*bif) = (struct acpi_battery_info *)data.pointer; 181 (*bif) = data.pointer;
183 182
184 return result; 183 return result;
185} 184}
@@ -209,7 +208,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
209 return -ENODEV; 208 return -ENODEV;
210 } 209 }
211 210
212 package = (union acpi_object *)buffer.pointer; 211 package = buffer.pointer;
213 212
214 /* Extract Package Data */ 213 /* Extract Package Data */
215 214
@@ -220,12 +219,11 @@ acpi_battery_get_status(struct acpi_battery *battery,
220 goto end; 219 goto end;
221 } 220 }
222 221
223 data.pointer = kmalloc(data.length, GFP_KERNEL); 222 data.pointer = kzalloc(data.length, GFP_KERNEL);
224 if (!data.pointer) { 223 if (!data.pointer) {
225 result = -ENOMEM; 224 result = -ENOMEM;
226 goto end; 225 goto end;
227 } 226 }
228 memset(data.pointer, 0, data.length);
229 227
230 status = acpi_extract_package(package, &format, &data); 228 status = acpi_extract_package(package, &format, &data);
231 if (ACPI_FAILURE(status)) { 229 if (ACPI_FAILURE(status)) {
@@ -239,7 +237,7 @@ acpi_battery_get_status(struct acpi_battery *battery,
239 kfree(buffer.pointer); 237 kfree(buffer.pointer);
240 238
241 if (!result) 239 if (!result)
242 (*bst) = (struct acpi_battery_status *)data.pointer; 240 (*bst) = data.pointer;
243 241
244 return result; 242 return result;
245} 243}
@@ -334,7 +332,7 @@ static struct proc_dir_entry *acpi_battery_dir;
334static int acpi_battery_read_info(struct seq_file *seq, void *offset) 332static int acpi_battery_read_info(struct seq_file *seq, void *offset)
335{ 333{
336 int result = 0; 334 int result = 0;
337 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 335 struct acpi_battery *battery = seq->private;
338 struct acpi_battery_info *bif = NULL; 336 struct acpi_battery_info *bif = NULL;
339 char *units = "?"; 337 char *units = "?";
340 338
@@ -418,7 +416,7 @@ static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
418static int acpi_battery_read_state(struct seq_file *seq, void *offset) 416static int acpi_battery_read_state(struct seq_file *seq, void *offset)
419{ 417{
420 int result = 0; 418 int result = 0;
421 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 419 struct acpi_battery *battery = seq->private;
422 struct acpi_battery_status *bst = NULL; 420 struct acpi_battery_status *bst = NULL;
423 char *units = "?"; 421 char *units = "?";
424 422
@@ -494,7 +492,7 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
494 492
495static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 493static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
496{ 494{
497 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 495 struct acpi_battery *battery = seq->private;
498 char *units = "?"; 496 char *units = "?";
499 497
500 498
@@ -531,8 +529,8 @@ acpi_battery_write_alarm(struct file *file,
531{ 529{
532 int result = 0; 530 int result = 0;
533 char alarm_string[12] = { '\0' }; 531 char alarm_string[12] = { '\0' };
534 struct seq_file *m = (struct seq_file *)file->private_data; 532 struct seq_file *m = file->private_data;
535 struct acpi_battery *battery = (struct acpi_battery *)m->private; 533 struct acpi_battery *battery = m->private;
536 534
537 535
538 if (!battery || (count > sizeof(alarm_string) - 1)) 536 if (!battery || (count > sizeof(alarm_string) - 1))
@@ -658,7 +656,7 @@ static int acpi_battery_remove_fs(struct acpi_device *device)
658 656
659static void acpi_battery_notify(acpi_handle handle, u32 event, void *data) 657static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
660{ 658{
661 struct acpi_battery *battery = (struct acpi_battery *)data; 659 struct acpi_battery *battery = data;
662 struct acpi_device *device = NULL; 660 struct acpi_device *device = NULL;
663 661
664 662
@@ -694,10 +692,9 @@ static int acpi_battery_add(struct acpi_device *device)
694 if (!device) 692 if (!device)
695 return -EINVAL; 693 return -EINVAL;
696 694
697 battery = kmalloc(sizeof(struct acpi_battery), GFP_KERNEL); 695 battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
698 if (!battery) 696 if (!battery)
699 return -ENOMEM; 697 return -ENOMEM;
700 memset(battery, 0, sizeof(struct acpi_battery));
701 698
702 battery->device = device; 699 battery->device = device;
703 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 700 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
@@ -742,7 +739,7 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
742 if (!device || !acpi_driver_data(device)) 739 if (!device || !acpi_driver_data(device))
743 return -EINVAL; 740 return -EINVAL;
744 741
745 battery = (struct acpi_battery *)acpi_driver_data(device); 742 battery = acpi_driver_data(device);
746 743
747 status = acpi_remove_notify_handler(device->handle, 744 status = acpi_remove_notify_handler(device->handle,
748 ACPI_ALL_NOTIFY, 745 ACPI_ALL_NOTIFY,
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 5ef885e82c78..ac860583c203 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -29,6 +29,7 @@
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/input.h>
32#include <acpi/acpi_bus.h> 33#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h> 34#include <acpi/acpi_drivers.h>
34 35
@@ -62,7 +63,7 @@
62#define _COMPONENT ACPI_BUTTON_COMPONENT 63#define _COMPONENT ACPI_BUTTON_COMPONENT
63ACPI_MODULE_NAME("acpi_button") 64ACPI_MODULE_NAME("acpi_button")
64 65
65 MODULE_AUTHOR("Paul Diefenbaugh"); 66MODULE_AUTHOR("Paul Diefenbaugh");
66MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME); 67MODULE_DESCRIPTION(ACPI_BUTTON_DRIVER_NAME);
67MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
68 69
@@ -78,12 +79,14 @@ static struct acpi_driver acpi_button_driver = {
78 .ops = { 79 .ops = {
79 .add = acpi_button_add, 80 .add = acpi_button_add,
80 .remove = acpi_button_remove, 81 .remove = acpi_button_remove,
81 }, 82 },
82}; 83};
83 84
84struct acpi_button { 85struct acpi_button {
85 struct acpi_device *device; /* Fixed button kludge */ 86 struct acpi_device *device; /* Fixed button kludge */
86 u8 type; 87 unsigned int type;
88 struct input_dev *input;
89 char phys[32]; /* for input device */
87 unsigned long pushed; 90 unsigned long pushed;
88}; 91};
89 92
@@ -109,8 +112,7 @@ static struct proc_dir_entry *acpi_button_dir;
109 112
110static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) 113static int acpi_button_info_seq_show(struct seq_file *seq, void *offset)
111{ 114{
112 struct acpi_button *button = (struct acpi_button *)seq->private; 115 struct acpi_button *button = seq->private;
113
114 116
115 if (!button || !button->device) 117 if (!button || !button->device)
116 return 0; 118 return 0;
@@ -128,22 +130,17 @@ static int acpi_button_info_open_fs(struct inode *inode, struct file *file)
128 130
129static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) 131static int acpi_button_state_seq_show(struct seq_file *seq, void *offset)
130{ 132{
131 struct acpi_button *button = (struct acpi_button *)seq->private; 133 struct acpi_button *button = seq->private;
132 acpi_status status; 134 acpi_status status;
133 unsigned long state; 135 unsigned long state;
134 136
135
136 if (!button || !button->device) 137 if (!button || !button->device)
137 return 0; 138 return 0;
138 139
139 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); 140 status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state);
140 if (ACPI_FAILURE(status)) { 141 seq_printf(seq, "state: %s\n",
141 seq_printf(seq, "state: unsupported\n"); 142 ACPI_FAILURE(status) ? "unsupported" :
142 } else { 143 (state ? "open" : "closed"));
143 seq_printf(seq, "state: %s\n",
144 (state ? "open" : "closed"));
145 }
146
147 return 0; 144 return 0;
148} 145}
149 146
@@ -159,8 +156,7 @@ static struct proc_dir_entry *acpi_lid_dir;
159static int acpi_button_add_fs(struct acpi_device *device) 156static int acpi_button_add_fs(struct acpi_device *device)
160{ 157{
161 struct proc_dir_entry *entry = NULL; 158 struct proc_dir_entry *entry = NULL;
162 struct acpi_button *button = NULL; 159 struct acpi_button *button;
163
164 160
165 if (!device || !acpi_driver_data(device)) 161 if (!device || !acpi_driver_data(device))
166 return -EINVAL; 162 return -EINVAL;
@@ -228,10 +224,8 @@ static int acpi_button_add_fs(struct acpi_device *device)
228 224
229static int acpi_button_remove_fs(struct acpi_device *device) 225static int acpi_button_remove_fs(struct acpi_device *device)
230{ 226{
231 struct acpi_button *button = NULL; 227 struct acpi_button *button = acpi_driver_data(device);
232
233 228
234 button = acpi_driver_data(device);
235 if (acpi_device_dir(device)) { 229 if (acpi_device_dir(device)) {
236 if (button->type == ACPI_BUTTON_TYPE_LID) 230 if (button->type == ACPI_BUTTON_TYPE_LID)
237 remove_proc_entry(ACPI_BUTTON_FILE_STATE, 231 remove_proc_entry(ACPI_BUTTON_FILE_STATE,
@@ -253,14 +247,34 @@ static int acpi_button_remove_fs(struct acpi_device *device)
253 247
254static void acpi_button_notify(acpi_handle handle, u32 event, void *data) 248static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
255{ 249{
256 struct acpi_button *button = (struct acpi_button *)data; 250 struct acpi_button *button = data;
257 251 struct input_dev *input;
258 252
259 if (!button || !button->device) 253 if (!button || !button->device)
260 return; 254 return;
261 255
262 switch (event) { 256 switch (event) {
263 case ACPI_BUTTON_NOTIFY_STATUS: 257 case ACPI_BUTTON_NOTIFY_STATUS:
258 input = button->input;
259
260 if (button->type == ACPI_BUTTON_TYPE_LID) {
261 struct acpi_handle *handle = button->device->handle;
262 unsigned long state;
263
264 if (!ACPI_FAILURE(acpi_evaluate_integer(handle, "_LID",
265 NULL, &state)))
266 input_report_switch(input, SW_LID, !state);
267
268 } else {
269 int keycode = test_bit(KEY_SLEEP, input->keybit) ?
270 KEY_SLEEP : KEY_POWER;
271
272 input_report_key(input, keycode, 1);
273 input_sync(input);
274 input_report_key(input, keycode, 0);
275 }
276 input_sync(input);
277
264 acpi_bus_generate_event(button->device, event, 278 acpi_bus_generate_event(button->device, event,
265 ++button->pushed); 279 ++button->pushed);
266 break; 280 break;
@@ -275,8 +289,7 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
275 289
276static acpi_status acpi_button_notify_fixed(void *data) 290static acpi_status acpi_button_notify_fixed(void *data)
277{ 291{
278 struct acpi_button *button = (struct acpi_button *)data; 292 struct acpi_button *button = data;
279
280 293
281 if (!button) 294 if (!button)
282 return AE_BAD_PARAMETER; 295 return AE_BAD_PARAMETER;
@@ -286,24 +299,75 @@ static acpi_status acpi_button_notify_fixed(void *data)
286 return AE_OK; 299 return AE_OK;
287} 300}
288 301
289static int acpi_button_add(struct acpi_device *device) 302static int acpi_button_install_notify_handlers(struct acpi_button *button)
290{ 303{
291 int result = 0; 304 acpi_status status;
292 acpi_status status = AE_OK;
293 struct acpi_button *button = NULL;
294 305
306 switch (button->type) {
307 case ACPI_BUTTON_TYPE_POWERF:
308 status =
309 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
310 acpi_button_notify_fixed,
311 button);
312 break;
313 case ACPI_BUTTON_TYPE_SLEEPF:
314 status =
315 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
316 acpi_button_notify_fixed,
317 button);
318 break;
319 default:
320 status = acpi_install_notify_handler(button->device->handle,
321 ACPI_DEVICE_NOTIFY,
322 acpi_button_notify,
323 button);
324 break;
325 }
326
327 return ACPI_FAILURE(status) ? -ENODEV : 0;
328}
329
330static void acpi_button_remove_notify_handlers(struct acpi_button *button)
331{
332 switch (button->type) {
333 case ACPI_BUTTON_TYPE_POWERF:
334 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
335 acpi_button_notify_fixed);
336 break;
337 case ACPI_BUTTON_TYPE_SLEEPF:
338 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
339 acpi_button_notify_fixed);
340 break;
341 default:
342 acpi_remove_notify_handler(button->device->handle,
343 ACPI_DEVICE_NOTIFY,
344 acpi_button_notify);
345 break;
346 }
347}
348
349static int acpi_button_add(struct acpi_device *device)
350{
351 int error;
352 struct acpi_button *button;
353 struct input_dev *input;
295 354
296 if (!device) 355 if (!device)
297 return -EINVAL; 356 return -EINVAL;
298 357
299 button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); 358 button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL);
300 if (!button) 359 if (!button)
301 return -ENOMEM; 360 return -ENOMEM;
302 memset(button, 0, sizeof(struct acpi_button));
303 361
304 button->device = device; 362 button->device = device;
305 acpi_driver_data(device) = button; 363 acpi_driver_data(device) = button;
306 364
365 button->input = input = input_allocate_device();
366 if (!input) {
367 error = -ENOMEM;
368 goto err_free_button;
369 }
370
307 /* 371 /*
308 * Determine the button type (via hid), as fixed-feature buttons 372 * Determine the button type (via hid), as fixed-feature buttons
309 * need to be handled a bit differently than generic-space. 373 * need to be handled a bit differently than generic-space.
@@ -338,39 +402,48 @@ static int acpi_button_add(struct acpi_device *device)
338 } else { 402 } else {
339 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", 403 printk(KERN_ERR PREFIX "Unsupported hid [%s]\n",
340 acpi_device_hid(device)); 404 acpi_device_hid(device));
341 result = -ENODEV; 405 error = -ENODEV;
342 goto end; 406 goto err_free_input;
343 } 407 }
344 408
345 result = acpi_button_add_fs(device); 409 error = acpi_button_add_fs(device);
346 if (result) 410 if (error)
347 goto end; 411 goto err_free_input;
412
413 error = acpi_button_install_notify_handlers(button);
414 if (error)
415 goto err_remove_fs;
416
417 snprintf(button->phys, sizeof(button->phys),
418 "%s/button/input0", acpi_device_hid(device));
419
420 input->name = acpi_device_name(device);
421 input->phys = button->phys;
422 input->id.bustype = BUS_HOST;
423 input->id.product = button->type;
348 424
349 switch (button->type) { 425 switch (button->type) {
426 case ACPI_BUTTON_TYPE_POWER:
350 case ACPI_BUTTON_TYPE_POWERF: 427 case ACPI_BUTTON_TYPE_POWERF:
351 status = 428 input->evbit[0] = BIT(EV_KEY);
352 acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, 429 set_bit(KEY_POWER, input->keybit);
353 acpi_button_notify_fixed,
354 button);
355 break; 430 break;
431
432 case ACPI_BUTTON_TYPE_SLEEP:
356 case ACPI_BUTTON_TYPE_SLEEPF: 433 case ACPI_BUTTON_TYPE_SLEEPF:
357 status = 434 input->evbit[0] = BIT(EV_KEY);
358 acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, 435 set_bit(KEY_SLEEP, input->keybit);
359 acpi_button_notify_fixed,
360 button);
361 break; 436 break;
362 default: 437
363 status = acpi_install_notify_handler(device->handle, 438 case ACPI_BUTTON_TYPE_LID:
364 ACPI_DEVICE_NOTIFY, 439 input->evbit[0] = BIT(EV_SW);
365 acpi_button_notify, 440 set_bit(SW_LID, input->swbit);
366 button);
367 break; 441 break;
368 } 442 }
369 443
370 if (ACPI_FAILURE(status)) { 444 error = input_register_device(input);
371 result = -ENODEV; 445 if (error)
372 goto end; 446 goto err_remove_handlers;
373 }
374 447
375 if (device->wakeup.flags.valid) { 448 if (device->wakeup.flags.valid) {
376 /* Button's GPE is run-wake GPE */ 449 /* Button's GPE is run-wake GPE */
@@ -385,47 +458,31 @@ static int acpi_button_add(struct acpi_device *device)
385 printk(KERN_INFO PREFIX "%s [%s]\n", 458 printk(KERN_INFO PREFIX "%s [%s]\n",
386 acpi_device_name(device), acpi_device_bid(device)); 459 acpi_device_name(device), acpi_device_bid(device));
387 460
388 end: 461 return 0;
389 if (result) {
390 acpi_button_remove_fs(device);
391 kfree(button);
392 }
393 462
394 return result; 463 err_remove_handlers:
464 acpi_button_remove_notify_handlers(button);
465 err_remove_fs:
466 acpi_button_remove_fs(device);
467 err_free_input:
468 input_free_device(input);
469 err_free_button:
470 kfree(button);
471 return error;
395} 472}
396 473
397static int acpi_button_remove(struct acpi_device *device, int type) 474static int acpi_button_remove(struct acpi_device *device, int type)
398{ 475{
399 acpi_status status = 0; 476 struct acpi_button *button;
400 struct acpi_button *button = NULL;
401
402 477
403 if (!device || !acpi_driver_data(device)) 478 if (!device || !acpi_driver_data(device))
404 return -EINVAL; 479 return -EINVAL;
405 480
406 button = acpi_driver_data(device); 481 button = acpi_driver_data(device);
407 482
408 /* Unregister for device notifications. */ 483 acpi_button_remove_notify_handlers(button);
409 switch (button->type) {
410 case ACPI_BUTTON_TYPE_POWERF:
411 status =
412 acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
413 acpi_button_notify_fixed);
414 break;
415 case ACPI_BUTTON_TYPE_SLEEPF:
416 status =
417 acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
418 acpi_button_notify_fixed);
419 break;
420 default:
421 status = acpi_remove_notify_handler(device->handle,
422 ACPI_DEVICE_NOTIFY,
423 acpi_button_notify);
424 break;
425 }
426
427 acpi_button_remove_fs(device); 484 acpi_button_remove_fs(device);
428 485 input_unregister_device(button->input);
429 kfree(button); 486 kfree(button);
430 487
431 return 0; 488 return 0;
@@ -433,8 +490,7 @@ static int acpi_button_remove(struct acpi_device *device, int type)
433 490
434static int __init acpi_button_init(void) 491static int __init acpi_button_init(void)
435{ 492{
436 int result = 0; 493 int result;
437
438 494
439 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); 495 acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir);
440 if (!acpi_button_dir) 496 if (!acpi_button_dir)
@@ -451,7 +507,6 @@ static int __init acpi_button_init(void)
451 507
452static void __exit acpi_button_exit(void) 508static void __exit acpi_button_exit(void)
453{ 509{
454
455 acpi_bus_unregister_driver(&acpi_button_driver); 510 acpi_bus_unregister_driver(&acpi_button_driver);
456 511
457 if (acpi_power_dir) 512 if (acpi_power_dir)
@@ -461,8 +516,6 @@ static void __exit acpi_button_exit(void)
461 if (acpi_lid_dir) 516 if (acpi_lid_dir)
462 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); 517 remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir);
463 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); 518 remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir);
464
465 return;
466} 519}
467 520
468module_init(acpi_button_init); 521module_init(acpi_button_init);
diff --git a/drivers/acpi/container.c b/drivers/acpi/container.c
index 871aa520ece7..0a1863ec91f3 100644
--- a/drivers/acpi/container.c
+++ b/drivers/acpi/container.c
@@ -96,11 +96,10 @@ static int acpi_container_add(struct acpi_device *device)
96 return -EINVAL; 96 return -EINVAL;
97 } 97 }
98 98
99 container = kmalloc(sizeof(struct acpi_container), GFP_KERNEL); 99 container = kzalloc(sizeof(struct acpi_container), GFP_KERNEL);
100 if (!container) 100 if (!container)
101 return -ENOMEM; 101 return -ENOMEM;
102 102
103 memset(container, 0, sizeof(struct acpi_container));
104 container->handle = device->handle; 103 container->handle = device->handle;
105 strcpy(acpi_device_name(device), ACPI_CONTAINER_DEVICE_NAME); 104 strcpy(acpi_device_name(device), ACPI_CONTAINER_DEVICE_NAME);
106 strcpy(acpi_device_class(device), ACPI_CONTAINER_CLASS); 105 strcpy(acpi_device_class(device), ACPI_CONTAINER_CLASS);
@@ -117,7 +116,7 @@ static int acpi_container_remove(struct acpi_device *device, int type)
117 acpi_status status = AE_OK; 116 acpi_status status = AE_OK;
118 struct acpi_container *pc = NULL; 117 struct acpi_container *pc = NULL;
119 118
120 pc = (struct acpi_container *)acpi_driver_data(device); 119 pc = acpi_driver_data(device);
121 kfree(pc); 120 kfree(pc);
122 return status; 121 return status;
123} 122}
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index bf5b79ed3613..90990a4b6526 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -27,6 +27,7 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/notifier.h> 29#include <linux/notifier.h>
30#include <linux/platform_device.h>
30#include <linux/jiffies.h> 31#include <linux/jiffies.h>
31#include <acpi/acpi_bus.h> 32#include <acpi/acpi_bus.h>
32#include <acpi/acpi_drivers.h> 33#include <acpi/acpi_drivers.h>
@@ -39,13 +40,15 @@ MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_NAME);
39MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
40 41
41static struct atomic_notifier_head dock_notifier_list; 42static struct atomic_notifier_head dock_notifier_list;
43static struct platform_device dock_device;
44static char dock_device_name[] = "dock";
42 45
43struct dock_station { 46struct dock_station {
44 acpi_handle handle; 47 acpi_handle handle;
45 unsigned long last_dock_time; 48 unsigned long last_dock_time;
46 u32 flags; 49 u32 flags;
47 spinlock_t dd_lock; 50 spinlock_t dd_lock;
48 spinlock_t hp_lock; 51 struct mutex hp_lock;
49 struct list_head dependent_devices; 52 struct list_head dependent_devices;
50 struct list_head hotplug_devices; 53 struct list_head hotplug_devices;
51}; 54};
@@ -115,9 +118,9 @@ static void
115dock_add_hotplug_device(struct dock_station *ds, 118dock_add_hotplug_device(struct dock_station *ds,
116 struct dock_dependent_device *dd) 119 struct dock_dependent_device *dd)
117{ 120{
118 spin_lock(&ds->hp_lock); 121 mutex_lock(&ds->hp_lock);
119 list_add_tail(&dd->hotplug_list, &ds->hotplug_devices); 122 list_add_tail(&dd->hotplug_list, &ds->hotplug_devices);
120 spin_unlock(&ds->hp_lock); 123 mutex_unlock(&ds->hp_lock);
121} 124}
122 125
123/** 126/**
@@ -131,9 +134,9 @@ static void
131dock_del_hotplug_device(struct dock_station *ds, 134dock_del_hotplug_device(struct dock_station *ds,
132 struct dock_dependent_device *dd) 135 struct dock_dependent_device *dd)
133{ 136{
134 spin_lock(&ds->hp_lock); 137 mutex_lock(&ds->hp_lock);
135 list_del(&dd->hotplug_list); 138 list_del(&dd->hotplug_list);
136 spin_unlock(&ds->hp_lock); 139 mutex_unlock(&ds->hp_lock);
137} 140}
138 141
139/** 142/**
@@ -296,7 +299,7 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
296{ 299{
297 struct dock_dependent_device *dd; 300 struct dock_dependent_device *dd;
298 301
299 spin_lock(&ds->hp_lock); 302 mutex_lock(&ds->hp_lock);
300 303
301 /* 304 /*
302 * First call driver specific hotplug functions 305 * First call driver specific hotplug functions
@@ -318,15 +321,17 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
318 else 321 else
319 dock_create_acpi_device(dd->handle); 322 dock_create_acpi_device(dd->handle);
320 } 323 }
321 spin_unlock(&ds->hp_lock); 324 mutex_unlock(&ds->hp_lock);
322} 325}
323 326
324static void dock_event(struct dock_station *ds, u32 event, int num) 327static void dock_event(struct dock_station *ds, u32 event, int num)
325{ 328{
329 struct device *dev = &dock_device.dev;
326 /* 330 /*
327 * we don't do events until someone tells me that 331 * Indicate that the status of the dock station has
328 * they would like to have them. 332 * changed.
329 */ 333 */
334 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
330} 335}
331 336
332/** 337/**
@@ -441,6 +446,9 @@ static int dock_in_progress(struct dock_station *ds)
441 */ 446 */
442int register_dock_notifier(struct notifier_block *nb) 447int register_dock_notifier(struct notifier_block *nb)
443{ 448{
449 if (!dock_station)
450 return -ENODEV;
451
444 return atomic_notifier_chain_register(&dock_notifier_list, nb); 452 return atomic_notifier_chain_register(&dock_notifier_list, nb);
445} 453}
446 454
@@ -452,6 +460,9 @@ EXPORT_SYMBOL_GPL(register_dock_notifier);
452 */ 460 */
453void unregister_dock_notifier(struct notifier_block *nb) 461void unregister_dock_notifier(struct notifier_block *nb)
454{ 462{
463 if (!dock_station)
464 return;
465
455 atomic_notifier_chain_unregister(&dock_notifier_list, nb); 466 atomic_notifier_chain_unregister(&dock_notifier_list, nb);
456} 467}
457 468
@@ -512,6 +523,37 @@ void unregister_hotplug_dock_device(acpi_handle handle)
512EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device); 523EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
513 524
514/** 525/**
526 * handle_eject_request - handle an undock request checking for error conditions
527 *
528 * Check to make sure the dock device is still present, then undock and
529 * hotremove all the devices that may need removing.
530 */
531static int handle_eject_request(struct dock_station *ds, u32 event)
532{
533 if (!dock_present(ds))
534 return -ENODEV;
535
536 if (dock_in_progress(ds))
537 return -EBUSY;
538
539 /*
540 * here we need to generate the undock
541 * event prior to actually doing the undock
542 * so that the device struct still exists.
543 */
544 dock_event(ds, event, UNDOCK_EVENT);
545 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
546 undock(ds);
547 eject_dock(ds);
548 if (dock_present(ds)) {
549 printk(KERN_ERR PREFIX "Unable to undock!\n");
550 return -EBUSY;
551 }
552
553 return 0;
554}
555
556/**
515 * dock_notify - act upon an acpi dock notification 557 * dock_notify - act upon an acpi dock notification
516 * @handle: the dock station handle 558 * @handle: the dock station handle
517 * @event: the acpi event 559 * @event: the acpi event
@@ -519,13 +561,11 @@ EXPORT_SYMBOL_GPL(unregister_hotplug_dock_device);
519 * 561 *
520 * If we are notified to dock, then check to see if the dock is 562 * If we are notified to dock, then check to see if the dock is
521 * present and then dock. Notify all drivers of the dock event, 563 * present and then dock. Notify all drivers of the dock event,
522 * and then hotplug and devices that may need hotplugging. For undock 564 * and then hotplug and devices that may need hotplugging.
523 * check to make sure the dock device is still present, then undock
524 * and hotremove all the devices that may need removing.
525 */ 565 */
526static void dock_notify(acpi_handle handle, u32 event, void *data) 566static void dock_notify(acpi_handle handle, u32 event, void *data)
527{ 567{
528 struct dock_station *ds = (struct dock_station *)data; 568 struct dock_station *ds = data;
529 569
530 switch (event) { 570 switch (event) {
531 case ACPI_NOTIFY_BUS_CHECK: 571 case ACPI_NOTIFY_BUS_CHECK:
@@ -553,19 +593,7 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
553 * to the driver who wish to hotplug. 593 * to the driver who wish to hotplug.
554 */ 594 */
555 case ACPI_NOTIFY_EJECT_REQUEST: 595 case ACPI_NOTIFY_EJECT_REQUEST:
556 if (!dock_in_progress(ds) && dock_present(ds)) { 596 handle_eject_request(ds, event);
557 /*
558 * here we need to generate the undock
559 * event prior to actually doing the undock
560 * so that the device struct still exists.
561 */
562 dock_event(ds, event, UNDOCK_EVENT);
563 hotplug_dock_devices(ds, ACPI_NOTIFY_EJECT_REQUEST);
564 undock(ds);
565 eject_dock(ds);
566 if (dock_present(ds))
567 printk(KERN_ERR PREFIX "Unable to undock!\n");
568 }
569 break; 597 break;
570 default: 598 default:
571 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); 599 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event);
@@ -588,7 +616,7 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
588{ 616{
589 acpi_status status; 617 acpi_status status;
590 acpi_handle tmp; 618 acpi_handle tmp;
591 struct dock_station *ds = (struct dock_station *)context; 619 struct dock_station *ds = context;
592 struct dock_dependent_device *dd; 620 struct dock_dependent_device *dd;
593 621
594 status = acpi_bus_get_ejd(handle, &tmp); 622 status = acpi_bus_get_ejd(handle, &tmp);
@@ -604,6 +632,33 @@ find_dock_devices(acpi_handle handle, u32 lvl, void *context, void **rv)
604 return AE_OK; 632 return AE_OK;
605} 633}
606 634
635/*
636 * show_docked - read method for "docked" file in sysfs
637 */
638static ssize_t show_docked(struct device *dev,
639 struct device_attribute *attr, char *buf)
640{
641 return snprintf(buf, PAGE_SIZE, "%d\n", dock_present(dock_station));
642
643}
644DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
645
646/*
647 * write_undock - write method for "undock" file in sysfs
648 */
649static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
650 const char *buf, size_t count)
651{
652 int ret;
653
654 if (!count)
655 return -EINVAL;
656
657 ret = handle_eject_request(dock_station, ACPI_NOTIFY_EJECT_REQUEST);
658 return ret ? ret: count;
659}
660DEVICE_ATTR(undock, S_IWUSR, NULL, write_undock);
661
607/** 662/**
608 * dock_add - add a new dock station 663 * dock_add - add a new dock station
609 * @handle: the dock station handle 664 * @handle: the dock station handle
@@ -626,9 +681,33 @@ static int dock_add(acpi_handle handle)
626 INIT_LIST_HEAD(&dock_station->dependent_devices); 681 INIT_LIST_HEAD(&dock_station->dependent_devices);
627 INIT_LIST_HEAD(&dock_station->hotplug_devices); 682 INIT_LIST_HEAD(&dock_station->hotplug_devices);
628 spin_lock_init(&dock_station->dd_lock); 683 spin_lock_init(&dock_station->dd_lock);
629 spin_lock_init(&dock_station->hp_lock); 684 mutex_init(&dock_station->hp_lock);
630 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); 685 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
631 686
687 /* initialize platform device stuff */
688 dock_device.name = dock_device_name;
689 ret = platform_device_register(&dock_device);
690 if (ret) {
691 printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret);
692 kfree(dock_station);
693 return ret;
694 }
695 ret = device_create_file(&dock_device.dev, &dev_attr_docked);
696 if (ret) {
697 printk("Error %d adding sysfs file\n", ret);
698 platform_device_unregister(&dock_device);
699 kfree(dock_station);
700 return ret;
701 }
702 ret = device_create_file(&dock_device.dev, &dev_attr_undock);
703 if (ret) {
704 printk("Error %d adding sysfs file\n", ret);
705 device_remove_file(&dock_device.dev, &dev_attr_docked);
706 platform_device_unregister(&dock_device);
707 kfree(dock_station);
708 return ret;
709 }
710
632 /* Find dependent devices */ 711 /* Find dependent devices */
633 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, 712 acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
634 ACPI_UINT32_MAX, find_dock_devices, dock_station, 713 ACPI_UINT32_MAX, find_dock_devices, dock_station,
@@ -638,7 +717,8 @@ static int dock_add(acpi_handle handle)
638 dd = alloc_dock_dependent_device(handle); 717 dd = alloc_dock_dependent_device(handle);
639 if (!dd) { 718 if (!dd) {
640 kfree(dock_station); 719 kfree(dock_station);
641 return -ENOMEM; 720 ret = -ENOMEM;
721 goto dock_add_err_unregister;
642 } 722 }
643 add_dock_dependent_device(dock_station, dd); 723 add_dock_dependent_device(dock_station, dd);
644 724
@@ -658,8 +738,12 @@ static int dock_add(acpi_handle handle)
658 return 0; 738 return 0;
659 739
660dock_add_err: 740dock_add_err:
661 kfree(dock_station);
662 kfree(dd); 741 kfree(dd);
742dock_add_err_unregister:
743 device_remove_file(&dock_device.dev, &dev_attr_docked);
744 device_remove_file(&dock_device.dev, &dev_attr_undock);
745 platform_device_unregister(&dock_device);
746 kfree(dock_station);
663 return ret; 747 return ret;
664} 748}
665 749
@@ -686,6 +770,11 @@ static int dock_remove(void)
686 if (ACPI_FAILURE(status)) 770 if (ACPI_FAILURE(status))
687 printk(KERN_ERR "Error removing notify handler\n"); 771 printk(KERN_ERR "Error removing notify handler\n");
688 772
773 /* cleanup sysfs */
774 device_remove_file(&dock_device.dev, &dev_attr_docked);
775 device_remove_file(&dock_device.dev, &dev_attr_undock);
776 platform_device_unregister(&dock_device);
777
689 /* free dock station memory */ 778 /* free dock station memory */
690 kfree(dock_station); 779 kfree(dock_station);
691 return 0; 780 return 0;
@@ -703,7 +792,7 @@ static int dock_remove(void)
703static acpi_status 792static acpi_status
704find_dock(acpi_handle handle, u32 lvl, void *context, void **rv) 793find_dock(acpi_handle handle, u32 lvl, void *context, void **rv)
705{ 794{
706 int *count = (int *)context; 795 int *count = context;
707 acpi_status status = AE_OK; 796 acpi_status status = AE_OK;
708 797
709 if (is_dock(handle)) { 798 if (is_dock(handle)) {
@@ -726,7 +815,7 @@ static int __init dock_init(void)
726 ACPI_UINT32_MAX, find_dock, &num, NULL); 815 ACPI_UINT32_MAX, find_dock, &num, NULL);
727 816
728 if (!num) 817 if (!num)
729 return -ENODEV; 818 printk(KERN_INFO "No dock devices found.\n");
730 819
731 return 0; 820 return 0;
732} 821}
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index e6d4b084dca2..9c52d87d6f04 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -45,35 +45,34 @@ ACPI_MODULE_NAME("acpi_ec")
45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver" 45#define ACPI_EC_DRIVER_NAME "ACPI Embedded Controller Driver"
46#define ACPI_EC_DEVICE_NAME "Embedded Controller" 46#define ACPI_EC_DEVICE_NAME "Embedded Controller"
47#define ACPI_EC_FILE_INFO "info" 47#define ACPI_EC_FILE_INFO "info"
48 48#undef PREFIX
49#define PREFIX "ACPI: EC: "
49/* EC status register */ 50/* EC status register */
50#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 51#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
51#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 52#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
52#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ 53#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
53#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ 54#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
54
55/* EC commands */ 55/* EC commands */
56#define ACPI_EC_COMMAND_READ 0x80 56enum ec_command {
57#define ACPI_EC_COMMAND_WRITE 0x81 57 ACPI_EC_COMMAND_READ = 0x80,
58#define ACPI_EC_BURST_ENABLE 0x82 58 ACPI_EC_COMMAND_WRITE = 0x81,
59#define ACPI_EC_BURST_DISABLE 0x83 59 ACPI_EC_BURST_ENABLE = 0x82,
60#define ACPI_EC_COMMAND_QUERY 0x84 60 ACPI_EC_BURST_DISABLE = 0x83,
61 61 ACPI_EC_COMMAND_QUERY = 0x84,
62};
62/* EC events */ 63/* EC events */
63enum { 64enum ec_event {
64 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ 65 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
65 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */ 66 ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
66}; 67};
67 68
68#define ACPI_EC_DELAY 50 /* Wait 50ms max. during EC ops */ 69#define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
69#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */ 70#define ACPI_EC_UDELAY_GLK 1000 /* Wait 1ms max. to get global lock */
70#define ACPI_EC_UDELAY 100 /* Poll @ 100us increments */
71#define ACPI_EC_UDELAY_COUNT 1000 /* Wait 10ms max. during EC ops */
72 71
73enum { 72static enum ec_mode {
74 EC_INTR = 1, /* Output buffer full */ 73 EC_INTR = 1, /* Output buffer full */
75 EC_POLL, /* Input buffer empty */ 74 EC_POLL, /* Input buffer empty */
76}; 75} acpi_ec_mode = EC_INTR;
77 76
78static int acpi_ec_remove(struct acpi_device *device, int type); 77static int acpi_ec_remove(struct acpi_device *device, int type);
79static int acpi_ec_start(struct acpi_device *device); 78static int acpi_ec_start(struct acpi_device *device);
@@ -93,22 +92,21 @@ static struct acpi_driver acpi_ec_driver = {
93}; 92};
94 93
95/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 94/* If we find an EC via the ECDT, we need to keep a ptr to its context */
96struct acpi_ec { 95static struct acpi_ec {
97 acpi_handle handle; 96 acpi_handle handle;
98 unsigned long uid; 97 unsigned long uid;
99 unsigned long gpe_bit; 98 unsigned long gpe;
100 unsigned long command_addr; 99 unsigned long command_addr;
101 unsigned long data_addr; 100 unsigned long data_addr;
102 unsigned long global_lock; 101 unsigned long global_lock;
103 struct semaphore sem; 102 struct mutex lock;
104 unsigned int expect_event; 103 atomic_t query_pending;
105 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */ 104 atomic_t leaving_burst; /* 0 : No, 1 : Yes, 2: abort */
106 wait_queue_head_t wait; 105 wait_queue_head_t wait;
107} *ec_ecdt; 106} *ec_ecdt;
108 107
109/* External interfaces use first EC only, so remember */ 108/* External interfaces use first EC only, so remember */
110static struct acpi_device *first_ec; 109static struct acpi_device *first_ec;
111static int acpi_ec_mode = EC_INTR;
112 110
113/* -------------------------------------------------------------------------- 111/* --------------------------------------------------------------------------
114 Transaction Management 112 Transaction Management
@@ -134,54 +132,41 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
134 outb(data, ec->data_addr); 132 outb(data, ec->data_addr);
135} 133}
136 134
137static int acpi_ec_check_status(u8 status, u8 event) 135static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
138{ 136{
139 switch (event) { 137 u8 status = acpi_ec_read_status(ec);
140 case ACPI_EC_EVENT_OBF_1: 138
139 if (event == ACPI_EC_EVENT_OBF_1) {
141 if (status & ACPI_EC_FLAG_OBF) 140 if (status & ACPI_EC_FLAG_OBF)
142 return 1; 141 return 1;
143 break; 142 } else if (event == ACPI_EC_EVENT_IBF_0) {
144 case ACPI_EC_EVENT_IBF_0:
145 if (!(status & ACPI_EC_FLAG_IBF)) 143 if (!(status & ACPI_EC_FLAG_IBF))
146 return 1; 144 return 1;
147 break;
148 default:
149 break;
150 } 145 }
151 146
152 return 0; 147 return 0;
153} 148}
154 149
155static int acpi_ec_wait(struct acpi_ec *ec, u8 event) 150static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event)
156{ 151{
157 int i = (acpi_ec_mode == EC_POLL) ? ACPI_EC_UDELAY_COUNT : 0; 152 if (acpi_ec_mode == EC_POLL) {
158 long time_left; 153 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
159 154 while (time_before(jiffies, delay)) {
160 ec->expect_event = event; 155 if (acpi_ec_check_status(ec, event))
161 if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) {
162 ec->expect_event = 0;
163 return 0;
164 }
165
166 do {
167 if (acpi_ec_mode == EC_POLL) {
168 udelay(ACPI_EC_UDELAY);
169 } else {
170 time_left = wait_event_timeout(ec->wait,
171 !ec->expect_event,
172 msecs_to_jiffies(ACPI_EC_DELAY));
173 if (time_left > 0) {
174 ec->expect_event = 0;
175 return 0; 156 return 0;
176 }
177 } 157 }
178 if (acpi_ec_check_status(acpi_ec_read_status(ec), event)) { 158 } else {
179 ec->expect_event = 0; 159 if (wait_event_timeout(ec->wait,
160 acpi_ec_check_status(ec, event),
161 msecs_to_jiffies(ACPI_EC_DELAY)) ||
162 acpi_ec_check_status(ec, event)) {
180 return 0; 163 return 0;
164 } else {
165 printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
166 " status = %d, expect_event = %d\n",
167 acpi_ec_read_status(ec), event);
181 } 168 }
182 } while (--i > 0); 169 }
183
184 ec->expect_event = 0;
185 170
186 return -ETIME; 171 return -ETIME;
187} 172}
@@ -196,7 +181,6 @@ int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
196 u8 tmp = 0; 181 u8 tmp = 0;
197 u8 status = 0; 182 u8 status = 0;
198 183
199
200 status = acpi_ec_read_status(ec); 184 status = acpi_ec_read_status(ec);
201 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) { 185 if (status != -EINVAL && !(status & ACPI_EC_FLAG_BURST)) {
202 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 186 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
@@ -212,7 +196,7 @@ int acpi_ec_enter_burst_mode(struct acpi_ec *ec)
212 196
213 atomic_set(&ec->leaving_burst, 0); 197 atomic_set(&ec->leaving_burst, 0);
214 return 0; 198 return 0;
215 end: 199 end:
216 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode")); 200 ACPI_EXCEPTION((AE_INFO, status, "EC wait, burst mode"));
217 return -1; 201 return -1;
218} 202}
@@ -221,58 +205,68 @@ int acpi_ec_leave_burst_mode(struct acpi_ec *ec)
221{ 205{
222 u8 status = 0; 206 u8 status = 0;
223 207
224
225 status = acpi_ec_read_status(ec); 208 status = acpi_ec_read_status(ec);
226 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)){ 209 if (status != -EINVAL && (status & ACPI_EC_FLAG_BURST)) {
227 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 210 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
228 if(status) 211 if (status)
229 goto end; 212 goto end;
230 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE); 213 acpi_ec_write_cmd(ec, ACPI_EC_BURST_DISABLE);
231 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 214 acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
232 } 215 }
233 atomic_set(&ec->leaving_burst, 1); 216 atomic_set(&ec->leaving_burst, 1);
234 return 0; 217 return 0;
235 end: 218 end:
236 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode")); 219 ACPI_EXCEPTION((AE_INFO, status, "EC leave burst mode"));
237 return -1; 220 return -1;
238} 221}
239#endif /* ACPI_FUTURE_USAGE */ 222#endif /* ACPI_FUTURE_USAGE */
240 223
241static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 224static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
242 const u8 *wdata, unsigned wdata_len, 225 const u8 * wdata, unsigned wdata_len,
243 u8 *rdata, unsigned rdata_len) 226 u8 * rdata, unsigned rdata_len)
244{ 227{
245 int result; 228 int result = 0;
246 229
247 acpi_ec_write_cmd(ec, command); 230 acpi_ec_write_cmd(ec, command);
248 231
249 for (; wdata_len > 0; wdata_len --) { 232 for (; wdata_len > 0; --wdata_len) {
250 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 233 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
251 if (result) 234 if (result) {
252 return result; 235 printk(KERN_ERR PREFIX
236 "write_cmd timeout, command = %d\n", command);
237 goto end;
238 }
253 acpi_ec_write_data(ec, *(wdata++)); 239 acpi_ec_write_data(ec, *(wdata++));
254 } 240 }
255 241
256 if (command == ACPI_EC_COMMAND_WRITE) { 242 if (!rdata_len) {
257 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 243 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
258 if (result) 244 if (result) {
259 return result; 245 printk(KERN_ERR PREFIX
246 "finish-write timeout, command = %d\n", command);
247 goto end;
248 }
249 } else if (command == ACPI_EC_COMMAND_QUERY) {
250 atomic_set(&ec->query_pending, 0);
260 } 251 }
261 252
262 for (; rdata_len > 0; rdata_len --) { 253 for (; rdata_len > 0; --rdata_len) {
263 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1); 254 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1);
264 if (result) 255 if (result) {
265 return result; 256 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
257 command);
258 goto end;
259 }
266 260
267 *(rdata++) = acpi_ec_read_data(ec); 261 *(rdata++) = acpi_ec_read_data(ec);
268 } 262 }
269 263 end:
270 return 0; 264 return result;
271} 265}
272 266
273static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, 267static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
274 const u8 *wdata, unsigned wdata_len, 268 const u8 * wdata, unsigned wdata_len,
275 u8 *rdata, unsigned rdata_len) 269 u8 * rdata, unsigned rdata_len)
276{ 270{
277 int status; 271 int status;
278 u32 glk; 272 u32 glk;
@@ -280,36 +274,40 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
280 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata)) 274 if (!ec || (wdata_len && !wdata) || (rdata_len && !rdata))
281 return -EINVAL; 275 return -EINVAL;
282 276
283 if (rdata) 277 if (rdata)
284 memset(rdata, 0, rdata_len); 278 memset(rdata, 0, rdata_len);
285 279
280 mutex_lock(&ec->lock);
286 if (ec->global_lock) { 281 if (ec->global_lock) {
287 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk); 282 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
288 if (ACPI_FAILURE(status)) 283 if (ACPI_FAILURE(status))
289 return -ENODEV; 284 return -ENODEV;
290 } 285 }
291 down(&ec->sem); 286
287 /* Make sure GPE is enabled before doing transaction */
288 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
292 289
293 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0); 290 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0);
294 if (status) { 291 if (status) {
295 printk(KERN_DEBUG PREFIX "read EC, IB not empty\n"); 292 printk(KERN_DEBUG PREFIX
293 "input buffer is not empty, aborting transaction\n");
296 goto end; 294 goto end;
297 } 295 }
298 296
299 status = acpi_ec_transaction_unlocked(ec, command, 297 status = acpi_ec_transaction_unlocked(ec, command,
300 wdata, wdata_len, 298 wdata, wdata_len,
301 rdata, rdata_len); 299 rdata, rdata_len);
302 300
303end: 301 end:
304 up(&ec->sem);
305 302
306 if (ec->global_lock) 303 if (ec->global_lock)
307 acpi_release_global_lock(glk); 304 acpi_release_global_lock(glk);
305 mutex_unlock(&ec->lock);
308 306
309 return status; 307 return status;
310} 308}
311 309
312static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data) 310static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
313{ 311{
314 int result; 312 int result;
315 u8 d; 313 u8 d;
@@ -322,15 +320,15 @@ static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 *data)
322 320
323static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data) 321static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
324{ 322{
325 u8 wdata[2] = { address, data }; 323 u8 wdata[2] = { address, data };
326 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, 324 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
327 wdata, 2, NULL, 0); 325 wdata, 2, NULL, 0);
328} 326}
329 327
330/* 328/*
331 * Externally callable EC access functions. For now, assume 1 EC only 329 * Externally callable EC access functions. For now, assume 1 EC only
332 */ 330 */
333int ec_read(u8 addr, u8 *val) 331int ec_read(u8 addr, u8 * val)
334{ 332{
335 struct acpi_ec *ec; 333 struct acpi_ec *ec;
336 int err; 334 int err;
@@ -369,9 +367,9 @@ int ec_write(u8 addr, u8 val)
369 367
370EXPORT_SYMBOL(ec_write); 368EXPORT_SYMBOL(ec_write);
371 369
372extern int ec_transaction(u8 command, 370int ec_transaction(u8 command,
373 const u8 *wdata, unsigned wdata_len, 371 const u8 * wdata, unsigned wdata_len,
374 u8 *rdata, unsigned rdata_len) 372 u8 * rdata, unsigned rdata_len)
375{ 373{
376 struct acpi_ec *ec; 374 struct acpi_ec *ec;
377 375
@@ -386,65 +384,49 @@ extern int ec_transaction(u8 command,
386 384
387EXPORT_SYMBOL(ec_transaction); 385EXPORT_SYMBOL(ec_transaction);
388 386
389static int acpi_ec_query(struct acpi_ec *ec, u8 *data) 387static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
390{ 388{
391 int result; 389 int result;
392 u8 d; 390 u8 d;
393 391
394 if (!ec || !data) 392 if (!ec || !data)
395 return -EINVAL; 393 return -EINVAL;
396 394
397 /* 395 /*
398 * Query the EC to find out which _Qxx method we need to evaluate. 396 * Query the EC to find out which _Qxx method we need to evaluate.
399 * Note that successful completion of the query causes the ACPI_EC_SCI 397 * Note that successful completion of the query causes the ACPI_EC_SCI
400 * bit to be cleared (and thus clearing the interrupt source). 398 * bit to be cleared (and thus clearing the interrupt source).
401 */ 399 */
402 400
403 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); 401 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1);
404 if (result) 402 if (result)
405 return result; 403 return result;
406 404
407 if (!d) 405 if (!d)
408 return -ENODATA; 406 return -ENODATA;
409 407
410 *data = d; 408 *data = d;
411 return 0; 409 return 0;
412} 410}
413 411
414/* -------------------------------------------------------------------------- 412/* --------------------------------------------------------------------------
415 Event Management 413 Event Management
416 -------------------------------------------------------------------------- */ 414 -------------------------------------------------------------------------- */
417 415
418struct acpi_ec_query_data {
419 acpi_handle handle;
420 u8 data;
421};
422
423static void acpi_ec_gpe_query(void *ec_cxt) 416static void acpi_ec_gpe_query(void *ec_cxt)
424{ 417{
425 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt; 418 struct acpi_ec *ec = (struct acpi_ec *)ec_cxt;
426 u8 value = 0; 419 u8 value = 0;
427 static char object_name[8]; 420 char object_name[8];
428 421
429 if (!ec) 422 if (!ec || acpi_ec_query(ec, &value))
430 goto end; 423 return;
431
432 value = acpi_ec_read_status(ec);
433
434 if (!(value & ACPI_EC_FLAG_SCI))
435 goto end;
436
437 if (acpi_ec_query(ec, &value))
438 goto end;
439 424
440 snprintf(object_name, 8, "_Q%2.2X", value); 425 snprintf(object_name, 8, "_Q%2.2X", value);
441 426
442 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name)); 427 printk(KERN_INFO PREFIX "evaluating %s\n", object_name);
443 428
444 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 429 acpi_evaluate_object(ec->handle, object_name, NULL, NULL);
445
446 end:
447 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR);
448} 430}
449 431
450static u32 acpi_ec_gpe_handler(void *data) 432static u32 acpi_ec_gpe_handler(void *data)
@@ -453,22 +435,18 @@ static u32 acpi_ec_gpe_handler(void *data)
453 u8 value; 435 u8 value;
454 struct acpi_ec *ec = (struct acpi_ec *)data; 436 struct acpi_ec *ec = (struct acpi_ec *)data;
455 437
456 acpi_clear_gpe(NULL, ec->gpe_bit, ACPI_ISR);
457 value = acpi_ec_read_status(ec);
458
459 if (acpi_ec_mode == EC_INTR) { 438 if (acpi_ec_mode == EC_INTR) {
460 if (acpi_ec_check_status(value, ec->expect_event)) { 439 wake_up(&ec->wait);
461 ec->expect_event = 0;
462 wake_up(&ec->wait);
463 }
464 } 440 }
465 441
466 if (value & ACPI_EC_FLAG_SCI) { 442 value = acpi_ec_read_status(ec);
467 status = acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec); 443 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
468 return status == AE_OK ? 444 atomic_set(&ec->query_pending, 1);
469 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 445 status =
446 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query,
447 ec);
470 } 448 }
471 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_ISR); 449
472 return status == AE_OK ? 450 return status == AE_OK ?
473 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED; 451 ACPI_INTERRUPT_HANDLED : ACPI_INTERRUPT_NOT_HANDLED;
474} 452}
@@ -504,7 +482,6 @@ acpi_ec_space_handler(u32 function,
504 acpi_integer f_v = 0; 482 acpi_integer f_v = 0;
505 int i = 0; 483 int i = 0;
506 484
507
508 if ((address > 0xFF) || !value || !handler_context) 485 if ((address > 0xFF) || !value || !handler_context)
509 return AE_BAD_PARAMETER; 486 return AE_BAD_PARAMETER;
510 487
@@ -518,7 +495,7 @@ acpi_ec_space_handler(u32 function,
518 switch (function) { 495 switch (function) {
519 case ACPI_READ: 496 case ACPI_READ:
520 temp = 0; 497 temp = 0;
521 result = acpi_ec_read(ec, (u8) address, (u8 *) &temp); 498 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
522 break; 499 break;
523 case ACPI_WRITE: 500 case ACPI_WRITE:
524 result = acpi_ec_write(ec, (u8) address, (u8) temp); 501 result = acpi_ec_write(ec, (u8) address, (u8) temp);
@@ -571,18 +548,15 @@ static int acpi_ec_read_info(struct seq_file *seq, void *offset)
571{ 548{
572 struct acpi_ec *ec = (struct acpi_ec *)seq->private; 549 struct acpi_ec *ec = (struct acpi_ec *)seq->private;
573 550
574
575 if (!ec) 551 if (!ec)
576 goto end; 552 goto end;
577 553
578 seq_printf(seq, "gpe bit: 0x%02x\n", 554 seq_printf(seq, "gpe: 0x%02x\n", (u32) ec->gpe);
579 (u32) ec->gpe_bit);
580 seq_printf(seq, "ports: 0x%02x, 0x%02x\n", 555 seq_printf(seq, "ports: 0x%02x, 0x%02x\n",
581 (u32) ec->command_addr, 556 (u32) ec->command_addr, (u32) ec->data_addr);
582 (u32) ec->data_addr);
583 seq_printf(seq, "use global lock: %s\n", 557 seq_printf(seq, "use global lock: %s\n",
584 ec->global_lock ? "yes" : "no"); 558 ec->global_lock ? "yes" : "no");
585 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 559 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
586 560
587 end: 561 end:
588 return 0; 562 return 0;
@@ -605,7 +579,6 @@ static int acpi_ec_add_fs(struct acpi_device *device)
605{ 579{
606 struct proc_dir_entry *entry = NULL; 580 struct proc_dir_entry *entry = NULL;
607 581
608
609 if (!acpi_device_dir(device)) { 582 if (!acpi_device_dir(device)) {
610 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 583 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
611 acpi_ec_dir); 584 acpi_ec_dir);
@@ -648,18 +621,17 @@ static int acpi_ec_add(struct acpi_device *device)
648 acpi_status status = AE_OK; 621 acpi_status status = AE_OK;
649 struct acpi_ec *ec = NULL; 622 struct acpi_ec *ec = NULL;
650 623
651
652 if (!device) 624 if (!device)
653 return -EINVAL; 625 return -EINVAL;
654 626
655 ec = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 627 ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
656 if (!ec) 628 if (!ec)
657 return -ENOMEM; 629 return -ENOMEM;
658 memset(ec, 0, sizeof(struct acpi_ec));
659 630
660 ec->handle = device->handle; 631 ec->handle = device->handle;
661 ec->uid = -1; 632 ec->uid = -1;
662 init_MUTEX(&ec->sem); 633 mutex_init(&ec->lock);
634 atomic_set(&ec->query_pending, 0);
663 if (acpi_ec_mode == EC_INTR) { 635 if (acpi_ec_mode == EC_INTR) {
664 atomic_set(&ec->leaving_burst, 1); 636 atomic_set(&ec->leaving_burst, 1);
665 init_waitqueue_head(&ec->wait); 637 init_waitqueue_head(&ec->wait);
@@ -669,8 +641,7 @@ static int acpi_ec_add(struct acpi_device *device)
669 acpi_driver_data(device) = ec; 641 acpi_driver_data(device) = ec;
670 642
671 /* Use the global lock for all EC transactions? */ 643 /* Use the global lock for all EC transactions? */
672 acpi_evaluate_integer(ec->handle, "_GLK", NULL, 644 acpi_evaluate_integer(ec->handle, "_GLK", NULL, &ec->global_lock);
673 &ec->global_lock);
674 645
675 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see: 646 /* XXX we don't test uids, because on some boxes ecdt uid = 0, see:
676 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */ 647 http://bugzilla.kernel.org/show_bug.cgi?id=6111 */
@@ -679,7 +650,7 @@ static int acpi_ec_add(struct acpi_device *device)
679 ACPI_ADR_SPACE_EC, 650 ACPI_ADR_SPACE_EC,
680 &acpi_ec_space_handler); 651 &acpi_ec_space_handler);
681 652
682 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 653 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
683 &acpi_ec_gpe_handler); 654 &acpi_ec_gpe_handler);
684 655
685 kfree(ec_ecdt); 656 kfree(ec_ecdt);
@@ -687,11 +658,10 @@ static int acpi_ec_add(struct acpi_device *device)
687 658
688 /* Get GPE bit assignment (EC events). */ 659 /* Get GPE bit assignment (EC events). */
689 /* TODO: Add support for _GPE returning a package */ 660 /* TODO: Add support for _GPE returning a package */
690 status = 661 status = acpi_evaluate_integer(ec->handle, "_GPE", NULL, &ec->gpe);
691 acpi_evaluate_integer(ec->handle, "_GPE", NULL,
692 &ec->gpe_bit);
693 if (ACPI_FAILURE(status)) { 662 if (ACPI_FAILURE(status)) {
694 ACPI_EXCEPTION((AE_INFO, status, "Obtaining GPE bit assignment")); 663 ACPI_EXCEPTION((AE_INFO, status,
664 "Obtaining GPE bit assignment"));
695 result = -ENODEV; 665 result = -ENODEV;
696 goto end; 666 goto end;
697 } 667 }
@@ -701,13 +671,13 @@ static int acpi_ec_add(struct acpi_device *device)
701 goto end; 671 goto end;
702 672
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.", 673 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
704 acpi_device_name(device), acpi_device_bid(device), 674 acpi_device_name(device), acpi_device_bid(device),
705 (u32) ec->gpe_bit)); 675 (u32) ec->gpe));
706 676
707 if (!first_ec) 677 if (!first_ec)
708 first_ec = device; 678 first_ec = device;
709 679
710 end: 680 end:
711 if (result) 681 if (result)
712 kfree(ec); 682 kfree(ec);
713 683
@@ -718,7 +688,6 @@ static int acpi_ec_remove(struct acpi_device *device, int type)
718{ 688{
719 struct acpi_ec *ec = NULL; 689 struct acpi_ec *ec = NULL;
720 690
721
722 if (!device) 691 if (!device)
723 return -EINVAL; 692 return -EINVAL;
724 693
@@ -761,7 +730,6 @@ static int acpi_ec_start(struct acpi_device *device)
761 acpi_status status = AE_OK; 730 acpi_status status = AE_OK;
762 struct acpi_ec *ec = NULL; 731 struct acpi_ec *ec = NULL;
763 732
764
765 if (!device) 733 if (!device)
766 return -EINVAL; 734 return -EINVAL;
767 735
@@ -782,27 +750,26 @@ static int acpi_ec_start(struct acpi_device *device)
782 } 750 }
783 751
784 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx", 752 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
785 ec->gpe_bit, ec->command_addr, ec->data_addr)); 753 ec->gpe, ec->command_addr, ec->data_addr));
786 754
787 /* 755 /*
788 * Install GPE handler 756 * Install GPE handler
789 */ 757 */
790 status = acpi_install_gpe_handler(NULL, ec->gpe_bit, 758 status = acpi_install_gpe_handler(NULL, ec->gpe,
791 ACPI_GPE_EDGE_TRIGGERED, 759 ACPI_GPE_EDGE_TRIGGERED,
792 &acpi_ec_gpe_handler, ec); 760 &acpi_ec_gpe_handler, ec);
793 if (ACPI_FAILURE(status)) { 761 if (ACPI_FAILURE(status)) {
794 return -ENODEV; 762 return -ENODEV;
795 } 763 }
796 acpi_set_gpe_type(NULL, ec->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 764 acpi_set_gpe_type(NULL, ec->gpe, ACPI_GPE_TYPE_RUNTIME);
797 acpi_enable_gpe(NULL, ec->gpe_bit, ACPI_NOT_ISR); 765 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
798 766
799 status = acpi_install_address_space_handler(ec->handle, 767 status = acpi_install_address_space_handler(ec->handle,
800 ACPI_ADR_SPACE_EC, 768 ACPI_ADR_SPACE_EC,
801 &acpi_ec_space_handler, 769 &acpi_ec_space_handler,
802 &acpi_ec_space_setup, ec); 770 &acpi_ec_space_setup, ec);
803 if (ACPI_FAILURE(status)) { 771 if (ACPI_FAILURE(status)) {
804 acpi_remove_gpe_handler(NULL, ec->gpe_bit, 772 acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
805 &acpi_ec_gpe_handler);
806 return -ENODEV; 773 return -ENODEV;
807 } 774 }
808 775
@@ -814,7 +781,6 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
814 acpi_status status = AE_OK; 781 acpi_status status = AE_OK;
815 struct acpi_ec *ec = NULL; 782 struct acpi_ec *ec = NULL;
816 783
817
818 if (!device) 784 if (!device)
819 return -EINVAL; 785 return -EINVAL;
820 786
@@ -826,9 +792,7 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
826 if (ACPI_FAILURE(status)) 792 if (ACPI_FAILURE(status))
827 return -ENODEV; 793 return -ENODEV;
828 794
829 status = 795 status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler);
830 acpi_remove_gpe_handler(NULL, ec->gpe_bit,
831 &acpi_ec_gpe_handler);
832 if (ACPI_FAILURE(status)) 796 if (ACPI_FAILURE(status))
833 return -ENODEV; 797 return -ENODEV;
834 798
@@ -841,7 +805,7 @@ acpi_fake_ecdt_callback(acpi_handle handle,
841{ 805{
842 acpi_status status; 806 acpi_status status;
843 807
844 init_MUTEX(&ec_ecdt->sem); 808 mutex_init(&ec_ecdt->lock);
845 if (acpi_ec_mode == EC_INTR) { 809 if (acpi_ec_mode == EC_INTR) {
846 init_waitqueue_head(&ec_ecdt->wait); 810 init_waitqueue_head(&ec_ecdt->wait);
847 } 811 }
@@ -853,16 +817,15 @@ acpi_fake_ecdt_callback(acpi_handle handle,
853 ec_ecdt->uid = -1; 817 ec_ecdt->uid = -1;
854 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid); 818 acpi_evaluate_integer(handle, "_UID", NULL, &ec_ecdt->uid);
855 819
856 status = 820 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec_ecdt->gpe);
857 acpi_evaluate_integer(handle, "_GPE", NULL,
858 &ec_ecdt->gpe_bit);
859 if (ACPI_FAILURE(status)) 821 if (ACPI_FAILURE(status))
860 return status; 822 return status;
861 ec_ecdt->global_lock = TRUE; 823 ec_ecdt->global_lock = TRUE;
862 ec_ecdt->handle = handle; 824 ec_ecdt->handle = handle;
863 825
864 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx", 826 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
865 ec_ecdt->gpe_bit, ec_ecdt->command_addr, ec_ecdt->data_addr)); 827 ec_ecdt->gpe, ec_ecdt->command_addr,
828 ec_ecdt->data_addr));
866 829
867 return AE_CTRL_TERMINATE; 830 return AE_CTRL_TERMINATE;
868} 831}
@@ -884,12 +847,11 @@ static int __init acpi_ec_fake_ecdt(void)
884 847
885 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT")); 848 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Try to make an fake ECDT"));
886 849
887 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 850 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
888 if (!ec_ecdt) { 851 if (!ec_ecdt) {
889 ret = -ENOMEM; 852 ret = -ENOMEM;
890 goto error; 853 goto error;
891 } 854 }
892 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
893 855
894 status = acpi_get_devices(ACPI_EC_HID, 856 status = acpi_get_devices(ACPI_EC_HID,
895 acpi_fake_ecdt_callback, NULL, NULL); 857 acpi_fake_ecdt_callback, NULL, NULL);
@@ -901,7 +863,7 @@ static int __init acpi_ec_fake_ecdt(void)
901 goto error; 863 goto error;
902 } 864 }
903 return 0; 865 return 0;
904 error: 866 error:
905 return ret; 867 return ret;
906} 868}
907 869
@@ -921,30 +883,28 @@ static int __init acpi_ec_get_real_ecdt(void)
921 /* 883 /*
922 * Generate a temporary ec context to use until the namespace is scanned 884 * Generate a temporary ec context to use until the namespace is scanned
923 */ 885 */
924 ec_ecdt = kmalloc(sizeof(struct acpi_ec), GFP_KERNEL); 886 ec_ecdt = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
925 if (!ec_ecdt) 887 if (!ec_ecdt)
926 return -ENOMEM; 888 return -ENOMEM;
927 memset(ec_ecdt, 0, sizeof(struct acpi_ec));
928 889
929 init_MUTEX(&ec_ecdt->sem); 890 mutex_init(&ec_ecdt->lock);
930 if (acpi_ec_mode == EC_INTR) { 891 if (acpi_ec_mode == EC_INTR) {
931 init_waitqueue_head(&ec_ecdt->wait); 892 init_waitqueue_head(&ec_ecdt->wait);
932 } 893 }
933 ec_ecdt->command_addr = ecdt_ptr->ec_control.address; 894 ec_ecdt->command_addr = ecdt_ptr->ec_control.address;
934 ec_ecdt->data_addr = ecdt_ptr->ec_data.address; 895 ec_ecdt->data_addr = ecdt_ptr->ec_data.address;
935 ec_ecdt->gpe_bit = ecdt_ptr->gpe_bit; 896 ec_ecdt->gpe = ecdt_ptr->gpe_bit;
936 /* use the GL just to be safe */ 897 /* use the GL just to be safe */
937 ec_ecdt->global_lock = TRUE; 898 ec_ecdt->global_lock = TRUE;
938 ec_ecdt->uid = ecdt_ptr->uid; 899 ec_ecdt->uid = ecdt_ptr->uid;
939 900
940 status = 901 status = acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
941 acpi_get_handle(NULL, ecdt_ptr->ec_id, &ec_ecdt->handle);
942 if (ACPI_FAILURE(status)) { 902 if (ACPI_FAILURE(status)) {
943 goto error; 903 goto error;
944 } 904 }
945 905
946 return 0; 906 return 0;
947 error: 907 error:
948 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT")); 908 ACPI_EXCEPTION((AE_INFO, status, "Could not use ECDT"));
949 kfree(ec_ecdt); 909 kfree(ec_ecdt);
950 ec_ecdt = NULL; 910 ec_ecdt = NULL;
@@ -970,14 +930,14 @@ int __init acpi_ec_ecdt_probe(void)
970 /* 930 /*
971 * Install GPE handler 931 * Install GPE handler
972 */ 932 */
973 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe_bit, 933 status = acpi_install_gpe_handler(NULL, ec_ecdt->gpe,
974 ACPI_GPE_EDGE_TRIGGERED, 934 ACPI_GPE_EDGE_TRIGGERED,
975 &acpi_ec_gpe_handler, ec_ecdt); 935 &acpi_ec_gpe_handler, ec_ecdt);
976 if (ACPI_FAILURE(status)) { 936 if (ACPI_FAILURE(status)) {
977 goto error; 937 goto error;
978 } 938 }
979 acpi_set_gpe_type(NULL, ec_ecdt->gpe_bit, ACPI_GPE_TYPE_RUNTIME); 939 acpi_set_gpe_type(NULL, ec_ecdt->gpe, ACPI_GPE_TYPE_RUNTIME);
980 acpi_enable_gpe(NULL, ec_ecdt->gpe_bit, ACPI_NOT_ISR); 940 acpi_enable_gpe(NULL, ec_ecdt->gpe, ACPI_NOT_ISR);
981 941
982 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT, 942 status = acpi_install_address_space_handler(ACPI_ROOT_OBJECT,
983 ACPI_ADR_SPACE_EC, 943 ACPI_ADR_SPACE_EC,
@@ -985,7 +945,7 @@ int __init acpi_ec_ecdt_probe(void)
985 &acpi_ec_space_setup, 945 &acpi_ec_space_setup,
986 ec_ecdt); 946 ec_ecdt);
987 if (ACPI_FAILURE(status)) { 947 if (ACPI_FAILURE(status)) {
988 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe_bit, 948 acpi_remove_gpe_handler(NULL, ec_ecdt->gpe,
989 &acpi_ec_gpe_handler); 949 &acpi_ec_gpe_handler);
990 goto error; 950 goto error;
991 } 951 }
@@ -1004,7 +964,6 @@ static int __init acpi_ec_init(void)
1004{ 964{
1005 int result = 0; 965 int result = 0;
1006 966
1007
1008 if (acpi_disabled) 967 if (acpi_disabled)
1009 return 0; 968 return 0;
1010 969
@@ -1057,7 +1016,8 @@ static int __init acpi_ec_set_intr_mode(char *str)
1057 acpi_ec_mode = EC_POLL; 1016 acpi_ec_mode = EC_POLL;
1058 } 1017 }
1059 acpi_ec_driver.ops.add = acpi_ec_add; 1018 acpi_ec_driver.ops.add = acpi_ec_add;
1060 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n", intr ? "interrupt" : "polling")); 1019 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "EC %s mode.\n",
1020 intr ? "interrupt" : "polling"));
1061 1021
1062 return 1; 1022 return 1;
1063} 1023}
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index ee2a10bf9077..bf63edc6608d 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -331,7 +331,6 @@ static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context)
331static u32 acpi_ev_global_lock_handler(void *context) 331static u32 acpi_ev_global_lock_handler(void *context)
332{ 332{
333 u8 acquired = FALSE; 333 u8 acquired = FALSE;
334 acpi_status status;
335 334
336 /* 335 /*
337 * Attempt to get the lock 336 * Attempt to get the lock
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 3a39c2e8e104..bf90f04f2c60 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -266,10 +266,10 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
266 walk_state->thread->thread_id) 266 walk_state->thread->thread_id)
267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) { 267 && (obj_desc->mutex.os_mutex != ACPI_GLOBAL_LOCK)) {
268 ACPI_ERROR((AE_INFO, 268 ACPI_ERROR((AE_INFO,
269 "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", 269 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
270 (u32) walk_state->thread->thread_id, 270 (unsigned long)walk_state->thread->thread_id,
271 acpi_ut_get_node_name(obj_desc->mutex.node), 271 acpi_ut_get_node_name(obj_desc->mutex.node),
272 (u32) obj_desc->mutex.owner_thread->thread_id)); 272 (unsigned long)obj_desc->mutex.owner_thread->thread_id));
273 return_ACPI_STATUS(AE_AML_NOT_OWNER); 273 return_ACPI_STATUS(AE_AML_NOT_OWNER);
274 } 274 }
275 275
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 045c89477e59..f305a826ca2d 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -99,8 +99,8 @@ acpi_fan_write_state(struct file *file, const char __user * buffer,
99 size_t count, loff_t * ppos) 99 size_t count, loff_t * ppos)
100{ 100{
101 int result = 0; 101 int result = 0;
102 struct seq_file *m = (struct seq_file *)file->private_data; 102 struct seq_file *m = file->private_data;
103 struct acpi_fan *fan = (struct acpi_fan *)m->private; 103 struct acpi_fan *fan = m->private;
104 char state_string[12] = { '\0' }; 104 char state_string[12] = { '\0' };
105 105
106 106
@@ -186,10 +186,9 @@ static int acpi_fan_add(struct acpi_device *device)
186 if (!device) 186 if (!device)
187 return -EINVAL; 187 return -EINVAL;
188 188
189 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL); 189 fan = kzalloc(sizeof(struct acpi_fan), GFP_KERNEL);
190 if (!fan) 190 if (!fan)
191 return -ENOMEM; 191 return -ENOMEM;
192 memset(fan, 0, sizeof(struct acpi_fan));
193 192
194 fan->device = device; 193 fan->device = device;
195 strcpy(acpi_device_name(device), "Fan"); 194 strcpy(acpi_device_name(device), "Fan");
@@ -229,7 +228,7 @@ static int acpi_fan_remove(struct acpi_device *device, int type)
229 if (!device || !acpi_driver_data(device)) 228 if (!device || !acpi_driver_data(device))
230 return -EINVAL; 229 return -EINVAL;
231 230
232 fan = (struct acpi_fan *)acpi_driver_data(device); 231 fan = acpi_driver_data(device);
233 232
234 acpi_fan_remove_fs(device); 233 acpi_fan_remove_fs(device);
235 234
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index a2f46d587d55..8a0324b43e53 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -96,7 +96,7 @@ struct acpi_find_pci_root {
96static acpi_status 96static acpi_status
97do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) 97do_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
98{ 98{
99 unsigned long *busnr = (unsigned long *)data; 99 unsigned long *busnr = data;
100 struct acpi_resource_address64 address; 100 struct acpi_resource_address64 address;
101 101
102 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && 102 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
@@ -189,8 +189,12 @@ find_pci_rootbridge(acpi_handle handle, u32 lvl, void *context, void **rv)
189 bus = tmp; 189 bus = tmp;
190 190
191 if (seg == find->seg && bus == find->bus) 191 if (seg == find->seg && bus == find->bus)
192 {
192 find->handle = handle; 193 find->handle = handle;
193 status = AE_OK; 194 status = AE_CTRL_TERMINATE;
195 }
196 else
197 status = AE_OK;
194 exit: 198 exit:
195 kfree(buffer.pointer); 199 kfree(buffer.pointer);
196 return status; 200 return status;
@@ -217,7 +221,7 @@ do_acpi_find_child(acpi_handle handle, u32 lvl, void *context, void **rv)
217 acpi_status status; 221 acpi_status status;
218 struct acpi_device_info *info; 222 struct acpi_device_info *info;
219 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 223 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
220 struct acpi_find_child *find = (struct acpi_find_child *)context; 224 struct acpi_find_child *find = context;
221 225
222 status = acpi_get_object_info(handle, &buffer); 226 status = acpi_get_object_info(handle, &buffer);
223 if (ACPI_SUCCESS(status)) { 227 if (ACPI_SUCCESS(status)) {
diff --git a/drivers/acpi/hotkey.c b/drivers/acpi/hotkey.c
index 1ba2db671865..8edfb92f7ede 100644
--- a/drivers/acpi/hotkey.c
+++ b/drivers/acpi/hotkey.c
@@ -265,8 +265,7 @@ static char *format_result(union acpi_object *object)
265 265
266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) 266static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
267{ 267{
268 struct acpi_polling_hotkey *poll_hotkey = 268 struct acpi_polling_hotkey *poll_hotkey = seq->private;
269 (struct acpi_polling_hotkey *)seq->private;
270 char *buf; 269 char *buf;
271 270
272 271
@@ -577,7 +576,7 @@ init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry,
577 if (ACPI_FAILURE(status)) 576 if (ACPI_FAILURE(status))
578 goto do_fail_zero; 577 goto do_fail_zero;
579 key->poll_hotkey.poll_result = 578 key->poll_hotkey.poll_result =
580 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL); 579 kmalloc(sizeof(union acpi_object), GFP_KERNEL);
581 if (!key->poll_hotkey.poll_result) 580 if (!key->poll_hotkey.poll_result)
582 goto do_fail_zero; 581 goto do_fail_zero;
583 return AE_OK; 582 return AE_OK;
diff --git a/drivers/acpi/i2c_ec.c b/drivers/acpi/i2c_ec.c
index 6342e612c203..8338be0990bc 100644
--- a/drivers/acpi/i2c_ec.c
+++ b/drivers/acpi/i2c_ec.c
@@ -309,18 +309,16 @@ static int acpi_ec_hc_add(struct acpi_device *device)
309 return -EINVAL; 309 return -EINVAL;
310 } 310 }
311 311
312 ec_hc = kmalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL); 312 ec_hc = kzalloc(sizeof(struct acpi_ec_hc), GFP_KERNEL);
313 if (!ec_hc) { 313 if (!ec_hc) {
314 return -ENOMEM; 314 return -ENOMEM;
315 } 315 }
316 memset(ec_hc, 0, sizeof(struct acpi_ec_hc));
317 316
318 smbus = kmalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL); 317 smbus = kzalloc(sizeof(struct acpi_ec_smbus), GFP_KERNEL);
319 if (!smbus) { 318 if (!smbus) {
320 kfree(ec_hc); 319 kfree(ec_hc);
321 return -ENOMEM; 320 return -ENOMEM;
322 } 321 }
323 memset(smbus, 0, sizeof(struct acpi_ec_smbus));
324 322
325 ec_hc->handle = device->handle; 323 ec_hc->handle = device->handle;
326 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME); 324 strcpy(acpi_device_name(device), ACPI_EC_HC_DEVICE_NAME);
@@ -393,7 +391,7 @@ static void __exit acpi_ec_hc_exit(void)
393 391
394struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device) 392struct acpi_ec_hc *acpi_get_ec_hc(struct acpi_device *device)
395{ 393{
396 return ((struct acpi_ec_hc *)acpi_driver_data(device->parent)); 394 return acpi_driver_data(device->parent);
397} 395}
398 396
399EXPORT_SYMBOL(acpi_get_ec_hc); 397EXPORT_SYMBOL(acpi_get_ec_hc);
diff --git a/drivers/acpi/ibm_acpi.c b/drivers/acpi/ibm_acpi.c
index 003a9876c968..b72d13d11a27 100644
--- a/drivers/acpi/ibm_acpi.c
+++ b/drivers/acpi/ibm_acpi.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * 4 *
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> 5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -19,10 +20,14 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 21 */
21 22
22#define IBM_VERSION "0.12a" 23#define IBM_VERSION "0.13"
23 24
24/* 25/*
25 * Changelog: 26 * Changelog:
27 *
28 * 2006-11-22 0.13 new maintainer
29 * changelog now lives in git commit history, and will
30 * not be updated further in-file.
26 * 31 *
27 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels 32 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
28 * 2005-03-17 0.11 support for 600e, 770x 33 * 2005-03-17 0.11 support for 600e, 770x
@@ -77,9 +82,16 @@
77#include <linux/module.h> 82#include <linux/module.h>
78#include <linux/init.h> 83#include <linux/init.h>
79#include <linux/types.h> 84#include <linux/types.h>
85#include <linux/string.h>
86
80#include <linux/proc_fs.h> 87#include <linux/proc_fs.h>
88#include <linux/backlight.h>
81#include <asm/uaccess.h> 89#include <asm/uaccess.h>
82 90
91#include <linux/dmi.h>
92#include <linux/jiffies.h>
93#include <linux/workqueue.h>
94
83#include <acpi/acpi_drivers.h> 95#include <acpi/acpi_drivers.h>
84#include <acpi/acnamesp.h> 96#include <acpi/acnamesp.h>
85 97
@@ -88,7 +100,7 @@
88#define IBM_FILE "ibm_acpi" 100#define IBM_FILE "ibm_acpi"
89#define IBM_URL "http://ibm-acpi.sf.net/" 101#define IBM_URL "http://ibm-acpi.sf.net/"
90 102
91MODULE_AUTHOR("Borislav Deianov"); 103MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
92MODULE_DESCRIPTION(IBM_DESC); 104MODULE_DESCRIPTION(IBM_DESC);
93MODULE_VERSION(IBM_VERSION); 105MODULE_VERSION(IBM_VERSION);
94MODULE_LICENSE("GPL"); 106MODULE_LICENSE("GPL");
@@ -116,28 +128,6 @@ static acpi_handle root_handle = NULL;
116 static char *object##_path; \ 128 static char *object##_path; \
117 static char *object##_paths[] = { paths } 129 static char *object##_paths[] = { paths }
118 130
119/*
120 * The following models are supported to various degrees:
121 *
122 * 570, 600e, 600x, 770e, 770x
123 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
124 * G40, G41
125 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
126 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
127 * X20, X21, X22, X23, X24, X30, X31, X40
128 *
129 * The following models have no supported features:
130 *
131 * 240, 240x, i1400
132 *
133 * Still missing DSDTs for the following models:
134 *
135 * A20p, A22e, A22m
136 * R52
137 * S31
138 * T43p
139 */
140
141IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ 131IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
142 "\\_SB.PCI.ISA.EC", /* 570 */ 132 "\\_SB.PCI.ISA.EC", /* 570 */
143 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ 133 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
@@ -167,8 +157,10 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
167 "\\_SB.PCI.ISA.SLCE", /* 570 */ 157 "\\_SB.PCI.ISA.SLCE", /* 570 */
168 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ 158 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
169#endif 159#endif
160#ifdef CONFIG_ACPI_IBM_BAY
170IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ 161IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
171 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ 162 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
163 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
172 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ 164 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
173 ); /* A21e, R30, R31 */ 165 ); /* A21e, R30, R31 */
174 166
@@ -183,6 +175,7 @@ IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
183IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ 175IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
184 "_EJ0", /* 770x */ 176 "_EJ0", /* 770x */
185 ); /* all others */ 177 ); /* all others */
178#endif
186 179
187/* don't list other alternatives as we install a notify handler on the 570 */ 180/* don't list other alternatives as we install a notify handler on the 570 */
188IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ 181IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
@@ -203,7 +196,7 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */
203IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ 196IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
204IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ 197IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
205IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ 198IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
206IBM_HANDLE(fans, ec, "FANS"); /* X31, X40 */ 199IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
207 200
208IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ 201IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
209 "\\FSPD", /* 600e/x, 770e, 770x */ 202 "\\FSPD", /* 600e/x, 770e, 770x */
@@ -216,6 +209,152 @@ IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
216#define IBM_HKEY_HID "IBM0068" 209#define IBM_HKEY_HID "IBM0068"
217#define IBM_PCI_HID "PNP0A03" 210#define IBM_PCI_HID "PNP0A03"
218 211
212enum thermal_access_mode {
213 IBMACPI_THERMAL_NONE = 0, /* No thermal support */
214 IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
215 IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
216 IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
217 IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
218};
219
220#define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
221struct ibm_thermal_sensors_struct {
222 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
223};
224
225/*
226 * FAN ACCESS MODES
227 *
228 * IBMACPI_FAN_RD_ACPI_GFAN:
229 * ACPI GFAN method: returns fan level
230 *
231 * see IBMACPI_FAN_WR_ACPI_SFAN
232 * EC 0x2f not available if GFAN exists
233 *
234 * IBMACPI_FAN_WR_ACPI_SFAN:
235 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
236 *
237 * EC 0x2f might be available *for reading*, but never for writing.
238 *
239 * IBMACPI_FAN_WR_TPEC:
240 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
241 * on almost all ThinkPads
242 *
243 * Fan speed changes of any sort (including those caused by the
244 * disengaged mode) are usually done slowly by the firmware as the
245 * maximum ammount of fan duty cycle change per second seems to be
246 * limited.
247 *
248 * Reading is not available if GFAN exists.
249 * Writing is not available if SFAN exists.
250 *
251 * Bits
252 * 7 automatic mode engaged;
253 * (default operation mode of the ThinkPad)
254 * fan level is ignored in this mode.
255 * 6 disengage mode (takes precedence over bit 7);
256 * not available on all thinkpads. May disable
257 * the tachometer, and speeds up fan to 100% duty-cycle,
258 * which speeds it up far above the standard RPM
259 * levels. It is not impossible that it could cause
260 * hardware damage.
261 * 5-3 unused in some models. Extra bits for fan level
262 * in others, but still useless as all values above
263 * 7 map to the same speed as level 7 in these models.
264 * 2-0 fan level (0..7 usually)
265 * 0x00 = stop
266 * 0x07 = max (set when temperatures critical)
267 * Some ThinkPads may have other levels, see
268 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
269 *
270 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
271 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
272 * does so, its initial value is meaningless (0x07).
273 *
274 * For firmware bugs, refer to:
275 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
276 *
277 * ----
278 *
279 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
280 * Main fan tachometer reading (in RPM)
281 *
282 * This register is present on all ThinkPads with a new-style EC, and
283 * it is known not to be present on the A21m/e, and T22, as there is
284 * something else in offset 0x84 according to the ACPI DSDT. Other
285 * ThinkPads from this same time period (and earlier) probably lack the
286 * tachometer as well.
287 *
288 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
289 * was never fixed by IBM to report the EC firmware version string
290 * probably support the tachometer (like the early X models), so
291 * detecting it is quite hard. We need more data to know for sure.
292 *
293 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
294 * might result.
295 *
296 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
297 * register is not invalidated in ThinkPads that disable tachometer
298 * readings. Thus, the tachometer readings go stale.
299 *
300 * For firmware bugs, refer to:
301 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
302 *
303 * IBMACPI_FAN_WR_ACPI_FANS:
304 * ThinkPad X31, X40, X41. Not available in the X60.
305 *
306 * FANS ACPI handle: takes three arguments: low speed, medium speed,
307 * high speed. ACPI DSDT seems to map these three speeds to levels
308 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
309 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
310 *
311 * The speeds are stored on handles
312 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
313 *
314 * There are three default speed sets, acessible as handles:
315 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
316 *
317 * ACPI DSDT switches which set is in use depending on various
318 * factors.
319 *
320 * IBMACPI_FAN_WR_TPEC is also available and should be used to
321 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
322 * but the ACPI tables just mention level 7.
323 */
324
325enum fan_status_access_mode {
326 IBMACPI_FAN_NONE = 0, /* No fan status or control */
327 IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
328 IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
329};
330
331enum fan_control_access_mode {
332 IBMACPI_FAN_WR_NONE = 0, /* No fan control */
333 IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
334 IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
335 IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
336};
337
338enum fan_control_commands {
339 IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
340 IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
341 IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
342 * and also watchdog cmd */
343};
344
345enum { /* Fan control constants */
346 fan_status_offset = 0x2f, /* EC register 0x2f */
347 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
348 * 0x84 must be read before 0x85 */
349
350 IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
351 * disengaged */
352 IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
353 * control */
354};
355
356static char *ibm_thinkpad_ec_found = NULL;
357
219struct ibm_struct { 358struct ibm_struct {
220 char *name; 359 char *name;
221 char param[32]; 360 char param[32];
@@ -243,6 +382,8 @@ struct ibm_struct {
243 382
244static struct proc_dir_entry *proc_dir = NULL; 383static struct proc_dir_entry *proc_dir = NULL;
245 384
385static struct backlight_device *ibm_backlight_device = NULL;
386
246#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") 387#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
247#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") 388#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
248#define strlencmp(a,b) (strncmp((a), (b), strlen(b))) 389#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
@@ -352,7 +493,7 @@ static char *next_cmd(char **cmds)
352 return start; 493 return start;
353} 494}
354 495
355static int driver_init(void) 496static int ibm_acpi_driver_init(void)
356{ 497{
357 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); 498 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
358 printk(IBM_INFO "%s\n", IBM_URL); 499 printk(IBM_INFO "%s\n", IBM_URL);
@@ -581,8 +722,7 @@ static int wan_status(void)
581{ 722{
582 int status; 723 int status;
583 724
584 if (!wan_supported || 725 if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
585 !acpi_evalf(hkey_handle, &status, "GWAN", "d"))
586 status = 0; 726 status = 0;
587 727
588 return status; 728 return status;
@@ -630,12 +770,15 @@ static int wan_write(char *buf)
630 return 0; 770 return 0;
631} 771}
632 772
633static int video_supported; 773enum video_access_mode {
634static int video_orig_autosw; 774 IBMACPI_VIDEO_NONE = 0,
775 IBMACPI_VIDEO_570, /* 570 */
776 IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */
777 IBMACPI_VIDEO_NEW, /* all others */
778};
635 779
636#define VIDEO_570 1 780static enum video_access_mode video_supported;
637#define VIDEO_770 2 781static int video_orig_autosw;
638#define VIDEO_NEW 3
639 782
640static int video_init(void) 783static int video_init(void)
641{ 784{
@@ -647,16 +790,16 @@ static int video_init(void)
647 790
648 if (!vid_handle) 791 if (!vid_handle)
649 /* video switching not supported on R30, R31 */ 792 /* video switching not supported on R30, R31 */
650 video_supported = 0; 793 video_supported = IBMACPI_VIDEO_NONE;
651 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) 794 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
652 /* 570 */ 795 /* 570 */
653 video_supported = VIDEO_570; 796 video_supported = IBMACPI_VIDEO_570;
654 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) 797 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
655 /* 600e/x, 770e, 770x */ 798 /* 600e/x, 770e, 770x */
656 video_supported = VIDEO_770; 799 video_supported = IBMACPI_VIDEO_770;
657 else 800 else
658 /* all others */ 801 /* all others */
659 video_supported = VIDEO_NEW; 802 video_supported = IBMACPI_VIDEO_NEW;
660 803
661 return 0; 804 return 0;
662} 805}
@@ -666,15 +809,15 @@ static int video_status(void)
666 int status = 0; 809 int status = 0;
667 int i; 810 int i;
668 811
669 if (video_supported == VIDEO_570) { 812 if (video_supported == IBMACPI_VIDEO_570) {
670 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) 813 if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87))
671 status = i & 3; 814 status = i & 3;
672 } else if (video_supported == VIDEO_770) { 815 } else if (video_supported == IBMACPI_VIDEO_770) {
673 if (acpi_evalf(NULL, &i, "\\VCDL", "d")) 816 if (acpi_evalf(NULL, &i, "\\VCDL", "d"))
674 status |= 0x01 * i; 817 status |= 0x01 * i;
675 if (acpi_evalf(NULL, &i, "\\VCDC", "d")) 818 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
676 status |= 0x02 * i; 819 status |= 0x02 * i;
677 } else if (video_supported == VIDEO_NEW) { 820 } else if (video_supported == IBMACPI_VIDEO_NEW) {
678 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); 821 acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1);
679 if (acpi_evalf(NULL, &i, "\\VCDC", "d")) 822 if (acpi_evalf(NULL, &i, "\\VCDC", "d"))
680 status |= 0x02 * i; 823 status |= 0x02 * i;
@@ -693,9 +836,10 @@ static int video_autosw(void)
693{ 836{
694 int autosw = 0; 837 int autosw = 0;
695 838
696 if (video_supported == VIDEO_570) 839 if (video_supported == IBMACPI_VIDEO_570)
697 acpi_evalf(vid_handle, &autosw, "SWIT", "d"); 840 acpi_evalf(vid_handle, &autosw, "SWIT", "d");
698 else if (video_supported == VIDEO_770 || video_supported == VIDEO_NEW) 841 else if (video_supported == IBMACPI_VIDEO_770 ||
842 video_supported == IBMACPI_VIDEO_NEW)
699 acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); 843 acpi_evalf(vid_handle, &autosw, "^VDEE", "d");
700 844
701 return autosw & 1; 845 return autosw & 1;
@@ -715,12 +859,12 @@ static int video_read(char *p)
715 len += sprintf(p + len, "status:\t\tsupported\n"); 859 len += sprintf(p + len, "status:\t\tsupported\n");
716 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); 860 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
717 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); 861 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
718 if (video_supported == VIDEO_NEW) 862 if (video_supported == IBMACPI_VIDEO_NEW)
719 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); 863 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
720 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); 864 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
721 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); 865 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
722 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); 866 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
723 if (video_supported == VIDEO_NEW) 867 if (video_supported == IBMACPI_VIDEO_NEW)
724 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); 868 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
725 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); 869 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
726 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); 870 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
@@ -735,7 +879,7 @@ static int video_switch(void)
735 879
736 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) 880 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
737 return -EIO; 881 return -EIO;
738 ret = video_supported == VIDEO_570 ? 882 ret = video_supported == IBMACPI_VIDEO_570 ?
739 acpi_evalf(ec_handle, NULL, "_Q16", "v") : 883 acpi_evalf(ec_handle, NULL, "_Q16", "v") :
740 acpi_evalf(vid_handle, NULL, "VSWT", "v"); 884 acpi_evalf(vid_handle, NULL, "VSWT", "v");
741 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); 885 acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw);
@@ -745,9 +889,9 @@ static int video_switch(void)
745 889
746static int video_expand(void) 890static int video_expand(void)
747{ 891{
748 if (video_supported == VIDEO_570) 892 if (video_supported == IBMACPI_VIDEO_570)
749 return acpi_evalf(ec_handle, NULL, "_Q17", "v"); 893 return acpi_evalf(ec_handle, NULL, "_Q17", "v");
750 else if (video_supported == VIDEO_770) 894 else if (video_supported == IBMACPI_VIDEO_770)
751 return acpi_evalf(vid_handle, NULL, "VEXP", "v"); 895 return acpi_evalf(vid_handle, NULL, "VEXP", "v");
752 else 896 else
753 return acpi_evalf(NULL, NULL, "\\VEXP", "v"); 897 return acpi_evalf(NULL, NULL, "\\VEXP", "v");
@@ -757,10 +901,10 @@ static int video_switch2(int status)
757{ 901{
758 int ret; 902 int ret;
759 903
760 if (video_supported == VIDEO_570) { 904 if (video_supported == IBMACPI_VIDEO_570) {
761 ret = acpi_evalf(NULL, NULL, 905 ret = acpi_evalf(NULL, NULL,
762 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); 906 "\\_SB.PHS2", "vdd", 0x8b, status | 0x80);
763 } else if (video_supported == VIDEO_770) { 907 } else if (video_supported == IBMACPI_VIDEO_770) {
764 int autosw = video_autosw(); 908 int autosw = video_autosw();
765 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) 909 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1))
766 return -EIO; 910 return -EIO;
@@ -796,10 +940,10 @@ static int video_write(char *buf)
796 enable |= 0x02; 940 enable |= 0x02;
797 } else if (strlencmp(cmd, "crt_disable") == 0) { 941 } else if (strlencmp(cmd, "crt_disable") == 0) {
798 disable |= 0x02; 942 disable |= 0x02;
799 } else if (video_supported == VIDEO_NEW && 943 } else if (video_supported == IBMACPI_VIDEO_NEW &&
800 strlencmp(cmd, "dvi_enable") == 0) { 944 strlencmp(cmd, "dvi_enable") == 0) {
801 enable |= 0x08; 945 enable |= 0x08;
802 } else if (video_supported == VIDEO_NEW && 946 } else if (video_supported == IBMACPI_VIDEO_NEW &&
803 strlencmp(cmd, "dvi_disable") == 0) { 947 strlencmp(cmd, "dvi_disable") == 0) {
804 disable |= 0x08; 948 disable |= 0x08;
805 } else if (strlencmp(cmd, "auto_enable") == 0) { 949 } else if (strlencmp(cmd, "auto_enable") == 0) {
@@ -898,6 +1042,7 @@ static int light_write(char *buf)
898 return 0; 1042 return 0;
899} 1043}
900 1044
1045#if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
901static int _sta(acpi_handle handle) 1046static int _sta(acpi_handle handle)
902{ 1047{
903 int status; 1048 int status;
@@ -907,6 +1052,7 @@ static int _sta(acpi_handle handle)
907 1052
908 return status; 1053 return status;
909} 1054}
1055#endif
910#ifdef CONFIG_ACPI_IBM_DOCK 1056#ifdef CONFIG_ACPI_IBM_DOCK
911#define dock_docked() (_sta(dock_handle) & 1) 1057#define dock_docked() (_sta(dock_handle) & 1)
912 1058
@@ -972,6 +1118,7 @@ static void dock_notify(struct ibm_struct *ibm, u32 event)
972} 1118}
973#endif 1119#endif
974 1120
1121#ifdef CONFIG_ACPI_IBM_BAY
975static int bay_status_supported; 1122static int bay_status_supported;
976static int bay_status2_supported; 1123static int bay_status2_supported;
977static int bay_eject_supported; 1124static int bay_eject_supported;
@@ -1047,6 +1194,7 @@ static void bay_notify(struct ibm_struct *ibm, u32 event)
1047{ 1194{
1048 acpi_bus_generate_event(ibm->device, event, 0); 1195 acpi_bus_generate_event(ibm->device, event, 0);
1049} 1196}
1197#endif
1050 1198
1051static int cmos_read(char *p) 1199static int cmos_read(char *p)
1052{ 1200{
@@ -1094,26 +1242,28 @@ static int cmos_write(char *buf)
1094 return 0; 1242 return 0;
1095} 1243}
1096 1244
1097static int led_supported; 1245enum led_access_mode {
1098 1246 IBMACPI_LED_NONE = 0,
1099#define LED_570 1 1247 IBMACPI_LED_570, /* 570 */
1100#define LED_OLD 2 1248 IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1101#define LED_NEW 3 1249 IBMACPI_LED_NEW, /* all others */
1250};
1251static enum led_access_mode led_supported;
1102 1252
1103static int led_init(void) 1253static int led_init(void)
1104{ 1254{
1105 if (!led_handle) 1255 if (!led_handle)
1106 /* led not supported on R30, R31 */ 1256 /* led not supported on R30, R31 */
1107 led_supported = 0; 1257 led_supported = IBMACPI_LED_NONE;
1108 else if (strlencmp(led_path, "SLED") == 0) 1258 else if (strlencmp(led_path, "SLED") == 0)
1109 /* 570 */ 1259 /* 570 */
1110 led_supported = LED_570; 1260 led_supported = IBMACPI_LED_570;
1111 else if (strlencmp(led_path, "SYSL") == 0) 1261 else if (strlencmp(led_path, "SYSL") == 0)
1112 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ 1262 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1113 led_supported = LED_OLD; 1263 led_supported = IBMACPI_LED_OLD;
1114 else 1264 else
1115 /* all others */ 1265 /* all others */
1116 led_supported = LED_NEW; 1266 led_supported = IBMACPI_LED_NEW;
1117 1267
1118 return 0; 1268 return 0;
1119} 1269}
@@ -1130,7 +1280,7 @@ static int led_read(char *p)
1130 } 1280 }
1131 len += sprintf(p + len, "status:\t\tsupported\n"); 1281 len += sprintf(p + len, "status:\t\tsupported\n");
1132 1282
1133 if (led_supported == LED_570) { 1283 if (led_supported == IBMACPI_LED_570) {
1134 /* 570 */ 1284 /* 570 */
1135 int i, status; 1285 int i, status;
1136 for (i = 0; i < 8; i++) { 1286 for (i = 0; i < 8; i++) {
@@ -1179,13 +1329,13 @@ static int led_write(char *buf)
1179 } else 1329 } else
1180 return -EINVAL; 1330 return -EINVAL;
1181 1331
1182 if (led_supported == LED_570) { 1332 if (led_supported == IBMACPI_LED_570) {
1183 /* 570 */ 1333 /* 570 */
1184 led = 1 << led; 1334 led = 1 << led;
1185 if (!acpi_evalf(led_handle, NULL, NULL, "vdd", 1335 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1186 led, led_sled_arg1[ind])) 1336 led, led_sled_arg1[ind]))
1187 return -EIO; 1337 return -EIO;
1188 } else if (led_supported == LED_OLD) { 1338 } else if (led_supported == IBMACPI_LED_OLD) {
1189 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ 1339 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1190 led = 1 << led; 1340 led = 1 << led;
1191 ret = ec_write(EC_HLMS, led); 1341 ret = ec_write(EC_HLMS, led);
@@ -1272,50 +1422,142 @@ static int acpi_ec_write(int i, u8 v)
1272 return 1; 1422 return 1;
1273} 1423}
1274 1424
1275static int thermal_tmp_supported; 1425static enum thermal_access_mode thermal_read_mode;
1276static int thermal_updt_supported;
1277 1426
1278static int thermal_init(void) 1427static int thermal_init(void)
1279{ 1428{
1280 /* temperatures not supported on 570, G4x, R30, R31, R32 */ 1429 u8 t, ta1, ta2;
1281 thermal_tmp_supported = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); 1430 int i;
1431 int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
1432
1433 if (ibm_thinkpad_ec_found && experimental) {
1434 /*
1435 * Direct EC access mode: sensors at registers
1436 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1437 * non-implemented, thermal sensors return 0x80 when
1438 * not available
1439 */
1282 1440
1283 /* 600e/x, 770e, 770x */ 1441 ta1 = ta2 = 0;
1284 thermal_updt_supported = acpi_evalf(ec_handle, NULL, "UPDT", "qv"); 1442 for (i = 0; i < 8; i++) {
1443 if (likely(acpi_ec_read(0x78 + i, &t))) {
1444 ta1 |= t;
1445 } else {
1446 ta1 = 0;
1447 break;
1448 }
1449 if (likely(acpi_ec_read(0xC0 + i, &t))) {
1450 ta2 |= t;
1451 } else {
1452 ta1 = 0;
1453 break;
1454 }
1455 }
1456 if (ta1 == 0) {
1457 /* This is sheer paranoia, but we handle it anyway */
1458 if (acpi_tmp7) {
1459 printk(IBM_ERR
1460 "ThinkPad ACPI EC access misbehaving, "
1461 "falling back to ACPI TMPx access mode\n");
1462 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1463 } else {
1464 printk(IBM_ERR
1465 "ThinkPad ACPI EC access misbehaving, "
1466 "disabling thermal sensors access\n");
1467 thermal_read_mode = IBMACPI_THERMAL_NONE;
1468 }
1469 } else {
1470 thermal_read_mode =
1471 (ta2 != 0) ?
1472 IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8;
1473 }
1474 } else if (acpi_tmp7) {
1475 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1476 /* 600e/x, 770e, 770x */
1477 thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT;
1478 } else {
1479 /* Standard ACPI TMPx access, max 8 sensors */
1480 thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07;
1481 }
1482 } else {
1483 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1484 thermal_read_mode = IBMACPI_THERMAL_NONE;
1485 }
1285 1486
1286 return 0; 1487 return 0;
1287} 1488}
1288 1489
1289static int thermal_read(char *p) 1490static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1290{ 1491{
1291 int len = 0; 1492 int i, t;
1493 s8 tmp;
1494 char tmpi[] = "TMPi";
1292 1495
1293 if (!thermal_tmp_supported) 1496 if (!s)
1294 len += sprintf(p + len, "temperatures:\tnot supported\n"); 1497 return -EINVAL;
1295 else {
1296 int i, t;
1297 char tmpi[] = "TMPi";
1298 s8 tmp[8];
1299 1498
1300 if (thermal_updt_supported) 1499 switch (thermal_read_mode) {
1301 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) 1500#if IBMACPI_MAX_THERMAL_SENSORS >= 16
1501 case IBMACPI_THERMAL_TPEC_16:
1502 for (i = 0; i < 8; i++) {
1503 if (!acpi_ec_read(0xC0 + i, &tmp))
1504 return -EIO;
1505 s->temp[i + 8] = tmp * 1000;
1506 }
1507 /* fallthrough */
1508#endif
1509 case IBMACPI_THERMAL_TPEC_8:
1510 for (i = 0; i < 8; i++) {
1511 if (!acpi_ec_read(0x78 + i, &tmp))
1302 return -EIO; 1512 return -EIO;
1513 s->temp[i] = tmp * 1000;
1514 }
1515 return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8;
1303 1516
1517 case IBMACPI_THERMAL_ACPI_UPDT:
1518 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1519 return -EIO;
1304 for (i = 0; i < 8; i++) { 1520 for (i = 0; i < 8; i++) {
1305 tmpi[3] = '0' + i; 1521 tmpi[3] = '0' + i;
1306 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 1522 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1307 return -EIO; 1523 return -EIO;
1308 if (thermal_updt_supported) 1524 s->temp[i] = (t - 2732) * 100;
1309 tmp[i] = (t - 2732 + 5) / 10;
1310 else
1311 tmp[i] = t;
1312 } 1525 }
1526 return 8;
1313 1527
1314 len += sprintf(p + len, 1528 case IBMACPI_THERMAL_ACPI_TMP07:
1315 "temperatures:\t%d %d %d %d %d %d %d %d\n", 1529 for (i = 0; i < 8; i++) {
1316 tmp[0], tmp[1], tmp[2], tmp[3], 1530 tmpi[3] = '0' + i;
1317 tmp[4], tmp[5], tmp[6], tmp[7]); 1531 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1532 return -EIO;
1533 s->temp[i] = t * 1000;
1534 }
1535 return 8;
1536
1537 case IBMACPI_THERMAL_NONE:
1538 default:
1539 return 0;
1318 } 1540 }
1541}
1542
1543static int thermal_read(char *p)
1544{
1545 int len = 0;
1546 int n, i;
1547 struct ibm_thermal_sensors_struct t;
1548
1549 n = thermal_get_sensors(&t);
1550 if (unlikely(n < 0))
1551 return n;
1552
1553 len += sprintf(p + len, "temperatures:\t");
1554
1555 if (n > 0) {
1556 for (i = 0; i < (n - 1); i++)
1557 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1558 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1559 } else
1560 len += sprintf(p + len, "not supported\n");
1319 1561
1320 return len; 1562 return len;
1321} 1563}
@@ -1381,12 +1623,23 @@ static int ecdump_write(char *buf)
1381 1623
1382static int brightness_offset = 0x31; 1624static int brightness_offset = 0x31;
1383 1625
1626static int brightness_get(struct backlight_device *bd)
1627{
1628 u8 level;
1629 if (!acpi_ec_read(brightness_offset, &level))
1630 return -EIO;
1631
1632 level &= 0x7;
1633
1634 return level;
1635}
1636
1384static int brightness_read(char *p) 1637static int brightness_read(char *p)
1385{ 1638{
1386 int len = 0; 1639 int len = 0;
1387 u8 level; 1640 int level;
1388 1641
1389 if (!acpi_ec_read(brightness_offset, &level)) { 1642 if ((level = brightness_get(NULL)) < 0) {
1390 len += sprintf(p + len, "level:\t\tunreadable\n"); 1643 len += sprintf(p + len, "level:\t\tunreadable\n");
1391 } else { 1644 } else {
1392 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); 1645 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
@@ -1401,16 +1654,34 @@ static int brightness_read(char *p)
1401#define BRIGHTNESS_UP 4 1654#define BRIGHTNESS_UP 4
1402#define BRIGHTNESS_DOWN 5 1655#define BRIGHTNESS_DOWN 5
1403 1656
1404static int brightness_write(char *buf) 1657static int brightness_set(int value)
1405{ 1658{
1406 int cmos_cmd, inc, i; 1659 int cmos_cmd, inc, i;
1407 u8 level; 1660 int current_value = brightness_get(NULL);
1661
1662 value &= 7;
1663
1664 cmos_cmd = value > current_value ? BRIGHTNESS_UP : BRIGHTNESS_DOWN;
1665 inc = value > current_value ? 1 : -1;
1666 for (i = current_value; i != value; i += inc) {
1667 if (!cmos_eval(cmos_cmd))
1668 return -EIO;
1669 if (!acpi_ec_write(brightness_offset, i + inc))
1670 return -EIO;
1671 }
1672
1673 return 0;
1674}
1675
1676static int brightness_write(char *buf)
1677{
1678 int level;
1408 int new_level; 1679 int new_level;
1409 char *cmd; 1680 char *cmd;
1410 1681
1411 while ((cmd = next_cmd(&buf))) { 1682 while ((cmd = next_cmd(&buf))) {
1412 if (!acpi_ec_read(brightness_offset, &level)) 1683 if ((level = brightness_get(NULL)) < 0)
1413 return -EIO; 1684 return level;
1414 level &= 7; 1685 level &= 7;
1415 1686
1416 if (strlencmp(cmd, "up") == 0) { 1687 if (strlencmp(cmd, "up") == 0) {
@@ -1423,19 +1694,44 @@ static int brightness_write(char *buf)
1423 } else 1694 } else
1424 return -EINVAL; 1695 return -EINVAL;
1425 1696
1426 cmos_cmd = new_level > level ? BRIGHTNESS_UP : BRIGHTNESS_DOWN; 1697 brightness_set(new_level);
1427 inc = new_level > level ? 1 : -1;
1428 for (i = level; i != new_level; i += inc) {
1429 if (!cmos_eval(cmos_cmd))
1430 return -EIO;
1431 if (!acpi_ec_write(brightness_offset, i + inc))
1432 return -EIO;
1433 }
1434 } 1698 }
1435 1699
1436 return 0; 1700 return 0;
1437} 1701}
1438 1702
1703static int brightness_update_status(struct backlight_device *bd)
1704{
1705 return brightness_set(bd->props->brightness);
1706}
1707
1708static struct backlight_properties ibm_backlight_data = {
1709 .owner = THIS_MODULE,
1710 .get_brightness = brightness_get,
1711 .update_status = brightness_update_status,
1712 .max_brightness = 7,
1713};
1714
1715static int brightness_init(void)
1716{
1717 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
1718 &ibm_backlight_data);
1719 if (IS_ERR(ibm_backlight_device)) {
1720 printk(IBM_ERR "Could not register backlight device\n");
1721 return PTR_ERR(ibm_backlight_device);
1722 }
1723
1724 return 0;
1725}
1726
1727static void brightness_exit(void)
1728{
1729 if (ibm_backlight_device) {
1730 backlight_device_unregister(ibm_backlight_device);
1731 ibm_backlight_device = NULL;
1732 }
1733}
1734
1439static int volume_offset = 0x30; 1735static int volume_offset = 0x30;
1440 1736
1441static int volume_read(char *p) 1737static int volume_read(char *p)
@@ -1522,90 +1818,486 @@ static int volume_write(char *buf)
1522 return 0; 1818 return 0;
1523} 1819}
1524 1820
1525static int fan_status_offset = 0x2f; 1821static enum fan_status_access_mode fan_status_access_mode;
1526static int fan_rpm_offset = 0x84; 1822static enum fan_control_access_mode fan_control_access_mode;
1823static enum fan_control_commands fan_control_commands;
1527 1824
1528static int fan_read(char *p) 1825static int fan_control_status_known;
1826static u8 fan_control_initial_status;
1827
1828static void fan_watchdog_fire(struct work_struct *ignored);
1829static int fan_watchdog_maxinterval;
1830static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
1831
1832static int fan_init(void)
1529{ 1833{
1530 int len = 0; 1834 fan_status_access_mode = IBMACPI_FAN_NONE;
1531 int s; 1835 fan_control_access_mode = IBMACPI_FAN_WR_NONE;
1532 u8 lo, hi, status; 1836 fan_control_commands = 0;
1837 fan_control_status_known = 1;
1838 fan_watchdog_maxinterval = 0;
1533 1839
1534 if (gfan_handle) { 1840 if (gfan_handle) {
1535 /* 570, 600e/x, 770e, 770x */ 1841 /* 570, 600e/x, 770e, 770x */
1536 if (!acpi_evalf(gfan_handle, &s, NULL, "d")) 1842 fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN;
1537 return -EIO; 1843 } else {
1844 /* all other ThinkPads: note that even old-style
1845 * ThinkPad ECs supports the fan control register */
1846 if (likely(acpi_ec_read(fan_status_offset,
1847 &fan_control_initial_status))) {
1848 fan_status_access_mode = IBMACPI_FAN_RD_TPEC;
1849
1850 /* In some ThinkPads, neither the EC nor the ACPI
1851 * DSDT initialize the fan status, and it ends up
1852 * being set to 0x07 when it *could* be either
1853 * 0x07 or 0x80.
1854 *
1855 * Enable for TP-1Y (T43), TP-78 (R51e),
1856 * TP-76 (R52), TP-70 (T43, R52), which are known
1857 * to be buggy. */
1858 if (fan_control_initial_status == 0x07 &&
1859 ibm_thinkpad_ec_found &&
1860 ((ibm_thinkpad_ec_found[0] == '1' &&
1861 ibm_thinkpad_ec_found[1] == 'Y') ||
1862 (ibm_thinkpad_ec_found[0] == '7' &&
1863 (ibm_thinkpad_ec_found[1] == '6' ||
1864 ibm_thinkpad_ec_found[1] == '8' ||
1865 ibm_thinkpad_ec_found[1] == '0'))
1866 )) {
1867 printk(IBM_NOTICE
1868 "fan_init: initial fan status is "
1869 "unknown, assuming it is in auto "
1870 "mode\n");
1871 fan_control_status_known = 0;
1872 }
1873 } else {
1874 printk(IBM_ERR
1875 "ThinkPad ACPI EC access misbehaving, "
1876 "fan status and control unavailable\n");
1877 return 0;
1878 }
1879 }
1538 1880
1539 len += sprintf(p + len, "level:\t\t%d\n", s); 1881 if (sfan_handle) {
1882 /* 570, 770x-JL */
1883 fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN;
1884 fan_control_commands |=
1885 IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE;
1540 } else { 1886 } else {
1887 if (!gfan_handle) {
1888 /* gfan without sfan means no fan control */
1889 /* all other models implement TP EC 0x2f control */
1890
1891 if (fans_handle) {
1892 /* X31, X40, X41 */
1893 fan_control_access_mode =
1894 IBMACPI_FAN_WR_ACPI_FANS;
1895 fan_control_commands |=
1896 IBMACPI_FAN_CMD_SPEED |
1897 IBMACPI_FAN_CMD_LEVEL |
1898 IBMACPI_FAN_CMD_ENABLE;
1899 } else {
1900 fan_control_access_mode = IBMACPI_FAN_WR_TPEC;
1901 fan_control_commands |=
1902 IBMACPI_FAN_CMD_LEVEL |
1903 IBMACPI_FAN_CMD_ENABLE;
1904 }
1905 }
1906 }
1907
1908 return 0;
1909}
1910
1911static int fan_get_status(u8 *status)
1912{
1913 u8 s;
1914
1915 /* TODO:
1916 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1917
1918 switch (fan_status_access_mode) {
1919 case IBMACPI_FAN_RD_ACPI_GFAN:
1920 /* 570, 600e/x, 770e, 770x */
1921
1922 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
1923 return -EIO;
1924
1925 if (likely(status))
1926 *status = s & 0x07;
1927
1928 break;
1929
1930 case IBMACPI_FAN_RD_TPEC:
1541 /* all except 570, 600e/x, 770e, 770x */ 1931 /* all except 570, 600e/x, 770e, 770x */
1542 if (!acpi_ec_read(fan_status_offset, &status)) 1932 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
1543 len += sprintf(p + len, "status:\t\tunreadable\n"); 1933 return -EIO;
1544 else
1545 len += sprintf(p + len, "status:\t\t%s\n",
1546 enabled(status, 7));
1547 1934
1548 if (!acpi_ec_read(fan_rpm_offset, &lo) || 1935 if (likely(status))
1549 !acpi_ec_read(fan_rpm_offset + 1, &hi)) 1936 *status = s;
1550 len += sprintf(p + len, "speed:\t\tunreadable\n"); 1937
1551 else 1938 break;
1552 len += sprintf(p + len, "speed:\t\t%d\n", 1939
1553 (hi << 8) + lo); 1940 default:
1941 return -ENXIO;
1554 } 1942 }
1555 1943
1556 if (sfan_handle) 1944 return 0;
1557 /* 570, 770x-JL */ 1945}
1558 len += sprintf(p + len, "commands:\tlevel <level>" 1946
1559 " (<level> is 0-7)\n"); 1947static int fan_get_speed(unsigned int *speed)
1560 if (!gfan_handle) 1948{
1949 u8 hi, lo;
1950
1951 switch (fan_status_access_mode) {
1952 case IBMACPI_FAN_RD_TPEC:
1561 /* all except 570, 600e/x, 770e, 770x */ 1953 /* all except 570, 600e/x, 770e, 770x */
1562 len += sprintf(p + len, "commands:\tenable, disable\n"); 1954 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
1563 if (fans_handle) 1955 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
1564 /* X31, X40 */ 1956 return -EIO;
1957
1958 if (likely(speed))
1959 *speed = (hi << 8) | lo;
1960
1961 break;
1962
1963 default:
1964 return -ENXIO;
1965 }
1966
1967 return 0;
1968}
1969
1970static void fan_exit(void)
1971{
1972 cancel_delayed_work(&fan_watchdog_task);
1973 flush_scheduled_work();
1974}
1975
1976static void fan_watchdog_reset(void)
1977{
1978 static int fan_watchdog_active = 0;
1979
1980 if (fan_watchdog_active)
1981 cancel_delayed_work(&fan_watchdog_task);
1982
1983 if (fan_watchdog_maxinterval > 0) {
1984 fan_watchdog_active = 1;
1985 if (!schedule_delayed_work(&fan_watchdog_task,
1986 msecs_to_jiffies(fan_watchdog_maxinterval
1987 * 1000))) {
1988 printk(IBM_ERR "failed to schedule the fan watchdog, "
1989 "watchdog will not trigger\n");
1990 }
1991 } else
1992 fan_watchdog_active = 0;
1993}
1994
1995static int fan_read(char *p)
1996{
1997 int len = 0;
1998 int rc;
1999 u8 status;
2000 unsigned int speed = 0;
2001
2002 switch (fan_status_access_mode) {
2003 case IBMACPI_FAN_RD_ACPI_GFAN:
2004 /* 570, 600e/x, 770e, 770x */
2005 if ((rc = fan_get_status(&status)) < 0)
2006 return rc;
2007
2008 len += sprintf(p + len, "status:\t\t%s\n"
2009 "level:\t\t%d\n",
2010 (status != 0) ? "enabled" : "disabled", status);
2011 break;
2012
2013 case IBMACPI_FAN_RD_TPEC:
2014 /* all except 570, 600e/x, 770e, 770x */
2015 if ((rc = fan_get_status(&status)) < 0)
2016 return rc;
2017
2018 if (unlikely(!fan_control_status_known)) {
2019 if (status != fan_control_initial_status)
2020 fan_control_status_known = 1;
2021 else
2022 /* Return most likely status. In fact, it
2023 * might be the only possible status */
2024 status = IBMACPI_FAN_EC_AUTO;
2025 }
2026
2027 len += sprintf(p + len, "status:\t\t%s\n",
2028 (status != 0) ? "enabled" : "disabled");
2029
2030 /* No ThinkPad boots on disengaged mode, we can safely
2031 * assume the tachometer is online if fan control status
2032 * was unknown */
2033 if ((rc = fan_get_speed(&speed)) < 0)
2034 return rc;
2035
2036 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2037
2038 if (status & IBMACPI_FAN_EC_DISENGAGED)
2039 /* Disengaged mode takes precedence */
2040 len += sprintf(p + len, "level:\t\tdisengaged\n");
2041 else if (status & IBMACPI_FAN_EC_AUTO)
2042 len += sprintf(p + len, "level:\t\tauto\n");
2043 else
2044 len += sprintf(p + len, "level:\t\t%d\n", status);
2045 break;
2046
2047 case IBMACPI_FAN_NONE:
2048 default:
2049 len += sprintf(p + len, "status:\t\tnot supported\n");
2050 }
2051
2052 if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) {
2053 len += sprintf(p + len, "commands:\tlevel <level>");
2054
2055 switch (fan_control_access_mode) {
2056 case IBMACPI_FAN_WR_ACPI_SFAN:
2057 len += sprintf(p + len, " (<level> is 0-7)\n");
2058 break;
2059
2060 default:
2061 len += sprintf(p + len, " (<level> is 0-7, "
2062 "auto, disengaged)\n");
2063 break;
2064 }
2065 }
2066
2067 if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE)
2068 len += sprintf(p + len, "commands:\tenable, disable\n"
2069 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2070 "1-120 (seconds))\n");
2071
2072 if (fan_control_commands & IBMACPI_FAN_CMD_SPEED)
1565 len += sprintf(p + len, "commands:\tspeed <speed>" 2073 len += sprintf(p + len, "commands:\tspeed <speed>"
1566 " (<speed> is 0-65535)\n"); 2074 " (<speed> is 0-65535)\n");
1567 2075
1568 return len; 2076 return len;
1569} 2077}
1570 2078
1571static int fan_write(char *buf) 2079static int fan_set_level(int level)
1572{ 2080{
1573 char *cmd; 2081 switch (fan_control_access_mode) {
1574 int level, speed; 2082 case IBMACPI_FAN_WR_ACPI_SFAN:
1575 2083 if (level >= 0 && level <= 7) {
1576 while ((cmd = next_cmd(&buf))) {
1577 if (sfan_handle &&
1578 sscanf(cmd, "level %d", &level) == 1 &&
1579 level >= 0 && level <= 7) {
1580 /* 570, 770x-JL */
1581 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) 2084 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
1582 return -EIO; 2085 return -EIO;
1583 } else if (!gfan_handle && strlencmp(cmd, "enable") == 0) { 2086 } else
1584 /* all except 570, 600e/x, 770e, 770x */ 2087 return -EINVAL;
1585 if (!acpi_ec_write(fan_status_offset, 0x80)) 2088 break;
1586 return -EIO; 2089
1587 } else if (!gfan_handle && strlencmp(cmd, "disable") == 0) { 2090 case IBMACPI_FAN_WR_ACPI_FANS:
1588 /* all except 570, 600e/x, 770e, 770x */ 2091 case IBMACPI_FAN_WR_TPEC:
1589 if (!acpi_ec_write(fan_status_offset, 0x00)) 2092 if ((level != IBMACPI_FAN_EC_AUTO) &&
1590 return -EIO; 2093 (level != IBMACPI_FAN_EC_DISENGAGED) &&
1591 } else if (fans_handle && 2094 ((level < 0) || (level > 7)))
1592 sscanf(cmd, "speed %d", &speed) == 1 && 2095 return -EINVAL;
1593 speed >= 0 && speed <= 65535) { 2096
1594 /* X31, X40 */ 2097 if (!acpi_ec_write(fan_status_offset, level))
2098 return -EIO;
2099 else
2100 fan_control_status_known = 1;
2101 break;
2102
2103 default:
2104 return -ENXIO;
2105 }
2106 return 0;
2107}
2108
2109static int fan_set_enable(void)
2110{
2111 u8 s;
2112 int rc;
2113
2114 switch (fan_control_access_mode) {
2115 case IBMACPI_FAN_WR_ACPI_FANS:
2116 case IBMACPI_FAN_WR_TPEC:
2117 if ((rc = fan_get_status(&s)) < 0)
2118 return rc;
2119
2120 /* Don't go out of emergency fan mode */
2121 if (s != 7)
2122 s = IBMACPI_FAN_EC_AUTO;
2123
2124 if (!acpi_ec_write(fan_status_offset, s))
2125 return -EIO;
2126 else
2127 fan_control_status_known = 1;
2128 break;
2129
2130 case IBMACPI_FAN_WR_ACPI_SFAN:
2131 if ((rc = fan_get_status(&s)) < 0)
2132 return rc;
2133
2134 s &= 0x07;
2135
2136 /* Set fan to at least level 4 */
2137 if (s < 4)
2138 s = 4;
2139
2140 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
2141 return -EIO;
2142 break;
2143
2144 default:
2145 return -ENXIO;
2146 }
2147 return 0;
2148}
2149
2150static int fan_set_disable(void)
2151{
2152 switch (fan_control_access_mode) {
2153 case IBMACPI_FAN_WR_ACPI_FANS:
2154 case IBMACPI_FAN_WR_TPEC:
2155 if (!acpi_ec_write(fan_status_offset, 0x00))
2156 return -EIO;
2157 else
2158 fan_control_status_known = 1;
2159 break;
2160
2161 case IBMACPI_FAN_WR_ACPI_SFAN:
2162 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2163 return -EIO;
2164 break;
2165
2166 default:
2167 return -ENXIO;
2168 }
2169 return 0;
2170}
2171
2172static int fan_set_speed(int speed)
2173{
2174 switch (fan_control_access_mode) {
2175 case IBMACPI_FAN_WR_ACPI_FANS:
2176 if (speed >= 0 && speed <= 65535) {
1595 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", 2177 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
1596 speed, speed, speed)) 2178 speed, speed, speed))
1597 return -EIO; 2179 return -EIO;
1598 } else 2180 } else
1599 return -EINVAL; 2181 return -EINVAL;
1600 } 2182 break;
1601 2183
2184 default:
2185 return -ENXIO;
2186 }
1602 return 0; 2187 return 0;
1603} 2188}
1604 2189
2190static int fan_write_cmd_level(const char *cmd, int *rc)
2191{
2192 int level;
2193
2194 if (strlencmp(cmd, "level auto") == 0)
2195 level = IBMACPI_FAN_EC_AUTO;
2196 else if (strlencmp(cmd, "level disengaged") == 0)
2197 level = IBMACPI_FAN_EC_DISENGAGED;
2198 else if (sscanf(cmd, "level %d", &level) != 1)
2199 return 0;
2200
2201 if ((*rc = fan_set_level(level)) == -ENXIO)
2202 printk(IBM_ERR "level command accepted for unsupported "
2203 "access mode %d", fan_control_access_mode);
2204
2205 return 1;
2206}
2207
2208static int fan_write_cmd_enable(const char *cmd, int *rc)
2209{
2210 if (strlencmp(cmd, "enable") != 0)
2211 return 0;
2212
2213 if ((*rc = fan_set_enable()) == -ENXIO)
2214 printk(IBM_ERR "enable command accepted for unsupported "
2215 "access mode %d", fan_control_access_mode);
2216
2217 return 1;
2218}
2219
2220static int fan_write_cmd_disable(const char *cmd, int *rc)
2221{
2222 if (strlencmp(cmd, "disable") != 0)
2223 return 0;
2224
2225 if ((*rc = fan_set_disable()) == -ENXIO)
2226 printk(IBM_ERR "disable command accepted for unsupported "
2227 "access mode %d", fan_control_access_mode);
2228
2229 return 1;
2230}
2231
2232static int fan_write_cmd_speed(const char *cmd, int *rc)
2233{
2234 int speed;
2235
2236 /* TODO:
2237 * Support speed <low> <medium> <high> ? */
2238
2239 if (sscanf(cmd, "speed %d", &speed) != 1)
2240 return 0;
2241
2242 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2243 printk(IBM_ERR "speed command accepted for unsupported "
2244 "access mode %d", fan_control_access_mode);
2245
2246 return 1;
2247}
2248
2249static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2250{
2251 int interval;
2252
2253 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2254 return 0;
2255
2256 if (interval < 0 || interval > 120)
2257 *rc = -EINVAL;
2258 else
2259 fan_watchdog_maxinterval = interval;
2260
2261 return 1;
2262}
2263
2264static int fan_write(char *buf)
2265{
2266 char *cmd;
2267 int rc = 0;
2268
2269 while (!rc && (cmd = next_cmd(&buf))) {
2270 if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) &&
2271 fan_write_cmd_level(cmd, &rc)) &&
2272 !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) &&
2273 (fan_write_cmd_enable(cmd, &rc) ||
2274 fan_write_cmd_disable(cmd, &rc) ||
2275 fan_write_cmd_watchdog(cmd, &rc))) &&
2276 !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) &&
2277 fan_write_cmd_speed(cmd, &rc))
2278 )
2279 rc = -EINVAL;
2280 else if (!rc)
2281 fan_watchdog_reset();
2282 }
2283
2284 return rc;
2285}
2286
2287static void fan_watchdog_fire(struct work_struct *ignored)
2288{
2289 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
2290 if (fan_set_enable()) {
2291 printk(IBM_ERR "fan watchdog: error while enabling fan\n");
2292 /* reschedule for later */
2293 fan_watchdog_reset();
2294 }
2295}
2296
1605static struct ibm_struct ibms[] = { 2297static struct ibm_struct ibms[] = {
1606 { 2298 {
1607 .name = "driver", 2299 .name = "driver",
1608 .init = driver_init, 2300 .init = ibm_acpi_driver_init,
1609 .read = driver_read, 2301 .read = driver_read,
1610 }, 2302 },
1611 { 2303 {
@@ -1662,6 +2354,7 @@ static struct ibm_struct ibms[] = {
1662 .type = ACPI_SYSTEM_NOTIFY, 2354 .type = ACPI_SYSTEM_NOTIFY,
1663 }, 2355 },
1664#endif 2356#endif
2357#ifdef CONFIG_ACPI_IBM_BAY
1665 { 2358 {
1666 .name = "bay", 2359 .name = "bay",
1667 .init = bay_init, 2360 .init = bay_init,
@@ -1671,6 +2364,7 @@ static struct ibm_struct ibms[] = {
1671 .handle = &bay_handle, 2364 .handle = &bay_handle,
1672 .type = ACPI_SYSTEM_NOTIFY, 2365 .type = ACPI_SYSTEM_NOTIFY,
1673 }, 2366 },
2367#endif
1674 { 2368 {
1675 .name = "cmos", 2369 .name = "cmos",
1676 .read = cmos_read, 2370 .read = cmos_read,
@@ -1702,6 +2396,8 @@ static struct ibm_struct ibms[] = {
1702 .name = "brightness", 2396 .name = "brightness",
1703 .read = brightness_read, 2397 .read = brightness_read,
1704 .write = brightness_write, 2398 .write = brightness_write,
2399 .init = brightness_init,
2400 .exit = brightness_exit,
1705 }, 2401 },
1706 { 2402 {
1707 .name = "volume", 2403 .name = "volume",
@@ -1712,6 +2408,8 @@ static struct ibm_struct ibms[] = {
1712 .name = "fan", 2408 .name = "fan",
1713 .read = fan_read, 2409 .read = fan_read,
1714 .write = fan_write, 2410 .write = fan_write,
2411 .init = fan_init,
2412 .exit = fan_exit,
1715 .experimental = 1, 2413 .experimental = 1,
1716 }, 2414 },
1717}; 2415};
@@ -1719,7 +2417,7 @@ static struct ibm_struct ibms[] = {
1719static int dispatch_read(char *page, char **start, off_t off, int count, 2417static int dispatch_read(char *page, char **start, off_t off, int count,
1720 int *eof, void *data) 2418 int *eof, void *data)
1721{ 2419{
1722 struct ibm_struct *ibm = (struct ibm_struct *)data; 2420 struct ibm_struct *ibm = data;
1723 int len; 2421 int len;
1724 2422
1725 if (!ibm || !ibm->read) 2423 if (!ibm || !ibm->read)
@@ -1744,7 +2442,7 @@ static int dispatch_read(char *page, char **start, off_t off, int count,
1744static int dispatch_write(struct file *file, const char __user * userbuf, 2442static int dispatch_write(struct file *file, const char __user * userbuf,
1745 unsigned long count, void *data) 2443 unsigned long count, void *data)
1746{ 2444{
1747 struct ibm_struct *ibm = (struct ibm_struct *)data; 2445 struct ibm_struct *ibm = data;
1748 char *kernbuf; 2446 char *kernbuf;
1749 int ret; 2447 int ret;
1750 2448
@@ -1773,7 +2471,7 @@ static int dispatch_write(struct file *file, const char __user * userbuf,
1773 2471
1774static void dispatch_notify(acpi_handle handle, u32 event, void *data) 2472static void dispatch_notify(acpi_handle handle, u32 event, void *data)
1775{ 2473{
1776 struct ibm_struct *ibm = (struct ibm_struct *)data; 2474 struct ibm_struct *ibm = data;
1777 2475
1778 if (!ibm || !ibm->notify) 2476 if (!ibm || !ibm->notify)
1779 return; 2477 return;
@@ -1805,7 +2503,7 @@ static int __init setup_notify(struct ibm_struct *ibm)
1805 ibm->name, status); 2503 ibm->name, status);
1806 return -ENODEV; 2504 return -ENODEV;
1807 } 2505 }
1808 2506 ibm->notify_installed = 1;
1809 return 0; 2507 return 0;
1810} 2508}
1811 2509
@@ -1818,14 +2516,13 @@ static int __init register_driver(struct ibm_struct *ibm)
1818{ 2516{
1819 int ret; 2517 int ret;
1820 2518
1821 ibm->driver = kmalloc(sizeof(struct acpi_driver), GFP_KERNEL); 2519 ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
1822 if (!ibm->driver) { 2520 if (!ibm->driver) {
1823 printk(IBM_ERR "kmalloc(ibm->driver) failed\n"); 2521 printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
1824 return -1; 2522 return -1;
1825 } 2523 }
1826 2524
1827 memset(ibm->driver, 0, sizeof(struct acpi_driver)); 2525 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
1828 sprintf(ibm->driver->name, "%s/%s", IBM_NAME, ibm->name);
1829 ibm->driver->ids = ibm->hid; 2526 ibm->driver->ids = ibm->hid;
1830 ibm->driver->ops.add = &ibm_device_add; 2527 ibm->driver->ops.add = &ibm_device_add;
1831 2528
@@ -1882,7 +2579,6 @@ static int __init ibm_init(struct ibm_struct *ibm)
1882 ret = setup_notify(ibm); 2579 ret = setup_notify(ibm);
1883 if (ret < 0) 2580 if (ret < 0)
1884 return ret; 2581 return ret;
1885 ibm->notify_installed = 1;
1886 } 2582 }
1887 2583
1888 return 0; 2584 return 0;
@@ -1954,7 +2650,9 @@ IBM_PARAM(light);
1954#ifdef CONFIG_ACPI_IBM_DOCK 2650#ifdef CONFIG_ACPI_IBM_DOCK
1955IBM_PARAM(dock); 2651IBM_PARAM(dock);
1956#endif 2652#endif
2653#ifdef CONFIG_ACPI_IBM_BAY
1957IBM_PARAM(bay); 2654IBM_PARAM(bay);
2655#endif
1958IBM_PARAM(cmos); 2656IBM_PARAM(cmos);
1959IBM_PARAM(led); 2657IBM_PARAM(led);
1960IBM_PARAM(beep); 2658IBM_PARAM(beep);
@@ -1971,6 +2669,33 @@ static void acpi_ibm_exit(void)
1971 ibm_exit(&ibms[i]); 2669 ibm_exit(&ibms[i]);
1972 2670
1973 remove_proc_entry(IBM_DIR, acpi_root_dir); 2671 remove_proc_entry(IBM_DIR, acpi_root_dir);
2672
2673 if (ibm_thinkpad_ec_found)
2674 kfree(ibm_thinkpad_ec_found);
2675}
2676
2677static char* __init check_dmi_for_ec(void)
2678{
2679 struct dmi_device *dev = NULL;
2680 char ec_fw_string[18];
2681
2682 /*
2683 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2684 * X32 or newer, all Z series; Some models must have an
2685 * up-to-date BIOS or they will not be detected.
2686 *
2687 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2688 */
2689 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
2690 if (sscanf(dev->name,
2691 "IBM ThinkPad Embedded Controller -[%17c",
2692 ec_fw_string) == 1) {
2693 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
2694 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
2695 return kstrdup(ec_fw_string, GFP_KERNEL);
2696 }
2697 }
2698 return NULL;
1974} 2699}
1975 2700
1976static int __init acpi_ibm_init(void) 2701static int __init acpi_ibm_init(void)
@@ -1992,6 +2717,12 @@ static int __init acpi_ibm_init(void)
1992 return -ENODEV; 2717 return -ENODEV;
1993 } 2718 }
1994 2719
2720 /* Models with newer firmware report the EC in DMI */
2721 ibm_thinkpad_ec_found = check_dmi_for_ec();
2722 if (ibm_thinkpad_ec_found)
2723 printk(IBM_INFO "ThinkPad EC firmware %s\n",
2724 ibm_thinkpad_ec_found);
2725
1995 /* these handles are not required */ 2726 /* these handles are not required */
1996 IBM_HANDLE_INIT(vid); 2727 IBM_HANDLE_INIT(vid);
1997 IBM_HANDLE_INIT(vid2); 2728 IBM_HANDLE_INIT(vid2);
@@ -2004,12 +2735,14 @@ static int __init acpi_ibm_init(void)
2004 IBM_HANDLE_INIT(dock); 2735 IBM_HANDLE_INIT(dock);
2005#endif 2736#endif
2006 IBM_HANDLE_INIT(pci); 2737 IBM_HANDLE_INIT(pci);
2738#ifdef CONFIG_ACPI_IBM_BAY
2007 IBM_HANDLE_INIT(bay); 2739 IBM_HANDLE_INIT(bay);
2008 if (bay_handle) 2740 if (bay_handle)
2009 IBM_HANDLE_INIT(bay_ej); 2741 IBM_HANDLE_INIT(bay_ej);
2010 IBM_HANDLE_INIT(bay2); 2742 IBM_HANDLE_INIT(bay2);
2011 if (bay2_handle) 2743 if (bay2_handle)
2012 IBM_HANDLE_INIT(bay2_ej); 2744 IBM_HANDLE_INIT(bay2_ej);
2745#endif
2013 IBM_HANDLE_INIT(beep); 2746 IBM_HANDLE_INIT(beep);
2014 IBM_HANDLE_INIT(ecrd); 2747 IBM_HANDLE_INIT(ecrd);
2015 IBM_HANDLE_INIT(ecwr); 2748 IBM_HANDLE_INIT(ecwr);
diff --git a/drivers/acpi/namespace/nsxfobj.c b/drivers/acpi/namespace/nsxfobj.c
index a163e1d3708d..a18b1c223129 100644
--- a/drivers/acpi/namespace/nsxfobj.c
+++ b/drivers/acpi/namespace/nsxfobj.c
@@ -50,6 +50,50 @@ ACPI_MODULE_NAME("nsxfobj")
50 50
51/******************************************************************************* 51/*******************************************************************************
52 * 52 *
53 * FUNCTION: acpi_get_id
54 *
55 * PARAMETERS: Handle - Handle of object whose id is desired
56 * ret_id - Where the id will be placed
57 *
58 * RETURN: Status
59 *
60 * DESCRIPTION: This routine returns the owner id associated with a handle
61 *
62 ******************************************************************************/
63acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
64{
65 struct acpi_namespace_node *node;
66 acpi_status status;
67
68 /* Parameter Validation */
69
70 if (!ret_id) {
71 return (AE_BAD_PARAMETER);
72 }
73
74 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
75 if (ACPI_FAILURE(status)) {
76 return (status);
77 }
78
79 /* Convert and validate the handle */
80
81 node = acpi_ns_map_handle_to_node(handle);
82 if (!node) {
83 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
84 return (AE_BAD_PARAMETER);
85 }
86
87 *ret_id = node->owner_id;
88
89 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
90 return (status);
91}
92
93ACPI_EXPORT_SYMBOL(acpi_get_id)
94
95/*******************************************************************************
96 *
53 * FUNCTION: acpi_get_type 97 * FUNCTION: acpi_get_type
54 * 98 *
55 * PARAMETERS: Handle - Handle of object whose type is desired 99 * PARAMETERS: Handle - Handle of object whose type is desired
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index e5e448edca41..bd96a7045925 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -248,7 +248,7 @@ int acpi_get_pxm(acpi_handle h)
248 handle = phandle; 248 handle = phandle;
249 status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm); 249 status = acpi_evaluate_integer(handle, "_PXM", NULL, &pxm);
250 if (ACPI_SUCCESS(status)) 250 if (ACPI_SUCCESS(status))
251 return (int)pxm; 251 return pxm;
252 status = acpi_get_parent(handle, &phandle); 252 status = acpi_get_parent(handle, &phandle);
253 } while (ACPI_SUCCESS(status)); 253 } while (ACPI_SUCCESS(status));
254 return -1; 254 return -1;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 02b30ae6a68e..57ae1e5cde0a 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -568,6 +568,7 @@ void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
568static void acpi_os_execute_deferred(struct work_struct *work) 568static void acpi_os_execute_deferred(struct work_struct *work)
569{ 569{
570 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); 570 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
571
571 if (!dpc) { 572 if (!dpc) {
572 printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); 573 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
573 return; 574 return;
@@ -1031,7 +1032,7 @@ acpi_status
1031acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache) 1032acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1032{ 1033{
1033 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL); 1034 *cache = kmem_cache_create(name, size, 0, 0, NULL, NULL);
1034 if (cache == NULL) 1035 if (*cache == NULL)
1035 return AE_ERROR; 1036 return AE_ERROR;
1036 else 1037 else
1037 return AE_OK; 1038 return AE_OK;
@@ -1051,7 +1052,7 @@ acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
1051 1052
1052acpi_status acpi_os_purge_cache(acpi_cache_t * cache) 1053acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
1053{ 1054{
1054 (void)kmem_cache_shrink(cache); 1055 kmem_cache_shrink(cache);
1055 return (AE_OK); 1056 return (AE_OK);
1056} 1057}
1057 1058
diff --git a/drivers/acpi/pci_bind.c b/drivers/acpi/pci_bind.c
index 1e2ae6e7a7e4..55f57a61c55e 100644
--- a/drivers/acpi/pci_bind.c
+++ b/drivers/acpi/pci_bind.c
@@ -122,19 +122,17 @@ int acpi_pci_bind(struct acpi_device *device)
122 if (!device || !device->parent) 122 if (!device || !device->parent)
123 return -EINVAL; 123 return -EINVAL;
124 124
125 pathname = kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 125 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
126 if (!pathname) 126 if (!pathname)
127 return -ENOMEM; 127 return -ENOMEM;
128 memset(pathname, 0, ACPI_PATHNAME_MAX);
129 buffer.length = ACPI_PATHNAME_MAX; 128 buffer.length = ACPI_PATHNAME_MAX;
130 buffer.pointer = pathname; 129 buffer.pointer = pathname;
131 130
132 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 131 data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
133 if (!data) { 132 if (!data) {
134 kfree(pathname); 133 kfree(pathname);
135 return -ENOMEM; 134 return -ENOMEM;
136 } 135 }
137 memset(data, 0, sizeof(struct acpi_pci_data));
138 136
139 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); 137 acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
140 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n", 138 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n",
@@ -281,10 +279,9 @@ int acpi_pci_unbind(struct acpi_device *device)
281 if (!device || !device->parent) 279 if (!device || !device->parent)
282 return -EINVAL; 280 return -EINVAL;
283 281
284 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 282 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
285 if (!pathname) 283 if (!pathname)
286 return -ENOMEM; 284 return -ENOMEM;
287 memset(pathname, 0, ACPI_PATHNAME_MAX);
288 285
289 buffer.length = ACPI_PATHNAME_MAX; 286 buffer.length = ACPI_PATHNAME_MAX;
290 buffer.pointer = pathname; 287 buffer.pointer = pathname;
@@ -331,11 +328,9 @@ acpi_pci_bind_root(struct acpi_device *device,
331 char *pathname = NULL; 328 char *pathname = NULL;
332 struct acpi_buffer buffer = { 0, NULL }; 329 struct acpi_buffer buffer = { 0, NULL };
333 330
334 331 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
335 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
336 if (!pathname) 332 if (!pathname)
337 return -ENOMEM; 333 return -ENOMEM;
338 memset(pathname, 0, ACPI_PATHNAME_MAX);
339 334
340 buffer.length = ACPI_PATHNAME_MAX; 335 buffer.length = ACPI_PATHNAME_MAX;
341 buffer.pointer = pathname; 336 buffer.pointer = pathname;
@@ -345,12 +340,11 @@ acpi_pci_bind_root(struct acpi_device *device,
345 return -EINVAL; 340 return -EINVAL;
346 } 341 }
347 342
348 data = kmalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); 343 data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
349 if (!data) { 344 if (!data) {
350 kfree(pathname); 345 kfree(pathname);
351 return -ENOMEM; 346 return -ENOMEM;
352 } 347 }
353 memset(data, 0, sizeof(struct acpi_pci_data));
354 348
355 data->id = *id; 349 data->id = *id;
356 data->bus = bus; 350 data->bus = bus;
diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
index feda0341f5a7..fe7d007833ad 100644
--- a/drivers/acpi/pci_irq.c
+++ b/drivers/acpi/pci_irq.c
@@ -89,10 +89,9 @@ acpi_pci_irq_add_entry(acpi_handle handle,
89 if (!prt) 89 if (!prt)
90 return -EINVAL; 90 return -EINVAL;
91 91
92 entry = kmalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL); 92 entry = kzalloc(sizeof(struct acpi_prt_entry), GFP_KERNEL);
93 if (!entry) 93 if (!entry)
94 return -ENOMEM; 94 return -ENOMEM;
95 memset(entry, 0, sizeof(struct acpi_prt_entry));
96 95
97 entry->id.segment = segment; 96 entry->id.segment = segment;
98 entry->id.bus = bus; 97 entry->id.bus = bus;
@@ -161,10 +160,9 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
161 static int first_time = 1; 160 static int first_time = 1;
162 161
163 162
164 pathname = (char *)kmalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); 163 pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
165 if (!pathname) 164 if (!pathname)
166 return -ENOMEM; 165 return -ENOMEM;
167 memset(pathname, 0, ACPI_PATHNAME_MAX);
168 166
169 if (first_time) { 167 if (first_time) {
170 acpi_prt.count = 0; 168 acpi_prt.count = 0;
@@ -198,11 +196,10 @@ int acpi_pci_irq_add_prt(acpi_handle handle, int segment, int bus)
198 return -ENODEV; 196 return -ENODEV;
199 } 197 }
200 198
201 prt = kmalloc(buffer.length, GFP_KERNEL); 199 prt = kzalloc(buffer.length, GFP_KERNEL);
202 if (!prt) { 200 if (!prt) {
203 return -ENOMEM; 201 return -ENOMEM;
204 } 202 }
205 memset(prt, 0, buffer.length);
206 buffer.pointer = prt; 203 buffer.pointer = prt;
207 204
208 status = acpi_get_irq_routing_table(handle, &buffer); 205 status = acpi_get_irq_routing_table(handle, &buffer);
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index d53bd9878ca2..481e633bbf41 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -103,7 +103,7 @@ DEFINE_MUTEX(acpi_link_lock);
103static acpi_status 103static acpi_status
104acpi_pci_link_check_possible(struct acpi_resource *resource, void *context) 104acpi_pci_link_check_possible(struct acpi_resource *resource, void *context)
105{ 105{
106 struct acpi_pci_link *link = (struct acpi_pci_link *)context; 106 struct acpi_pci_link *link = context;
107 u32 i = 0; 107 u32 i = 0;
108 108
109 109
@@ -307,11 +307,10 @@ static int acpi_pci_link_set(struct acpi_pci_link *link, int irq)
307 if (!link || !irq) 307 if (!link || !irq)
308 return -EINVAL; 308 return -EINVAL;
309 309
310 resource = kmalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); 310 resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
311 if (!resource) 311 if (!resource)
312 return -ENOMEM; 312 return -ENOMEM;
313 313
314 memset(resource, 0, sizeof(*resource) + 1);
315 buffer.length = sizeof(*resource) + 1; 314 buffer.length = sizeof(*resource) + 1;
316 buffer.pointer = resource; 315 buffer.pointer = resource;
317 316
@@ -613,7 +612,7 @@ acpi_pci_link_allocate_irq(acpi_handle handle,
613 return -1; 612 return -1;
614 } 613 }
615 614
616 link = (struct acpi_pci_link *)acpi_driver_data(device); 615 link = acpi_driver_data(device);
617 if (!link) { 616 if (!link) {
618 printk(KERN_ERR PREFIX "Invalid link context\n"); 617 printk(KERN_ERR PREFIX "Invalid link context\n");
619 return -1; 618 return -1;
@@ -668,7 +667,7 @@ int acpi_pci_link_free_irq(acpi_handle handle)
668 return -1; 667 return -1;
669 } 668 }
670 669
671 link = (struct acpi_pci_link *)acpi_driver_data(device); 670 link = acpi_driver_data(device);
672 if (!link) { 671 if (!link) {
673 printk(KERN_ERR PREFIX "Invalid link context\n"); 672 printk(KERN_ERR PREFIX "Invalid link context\n");
674 return -1; 673 return -1;
@@ -718,10 +717,9 @@ static int acpi_pci_link_add(struct acpi_device *device)
718 if (!device) 717 if (!device)
719 return -EINVAL; 718 return -EINVAL;
720 719
721 link = kmalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); 720 link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL);
722 if (!link) 721 if (!link)
723 return -ENOMEM; 722 return -ENOMEM;
724 memset(link, 0, sizeof(struct acpi_pci_link));
725 723
726 link->device = device; 724 link->device = device;
727 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); 725 strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME);
@@ -808,7 +806,7 @@ static int acpi_pci_link_remove(struct acpi_device *device, int type)
808 if (!device || !acpi_driver_data(device)) 806 if (!device || !acpi_driver_data(device))
809 return -EINVAL; 807 return -EINVAL;
810 808
811 link = (struct acpi_pci_link *)acpi_driver_data(device); 809 link = acpi_driver_data(device);
812 810
813 mutex_lock(&acpi_link_lock); 811 mutex_lock(&acpi_link_lock);
814 list_del(&link->node); 812 list_del(&link->node);
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 0984a1ee24ed..a860efa2c562 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -98,11 +98,12 @@ void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
98 98
99 struct acpi_pci_driver **pptr = &sub_driver; 99 struct acpi_pci_driver **pptr = &sub_driver;
100 while (*pptr) { 100 while (*pptr) {
101 if (*pptr != driver) 101 if (*pptr == driver)
102 continue; 102 break;
103 *pptr = (*pptr)->next; 103 pptr = &(*pptr)->next;
104 break;
105 } 104 }
105 BUG_ON(!*pptr);
106 *pptr = (*pptr)->next;
106 107
107 if (!driver->remove) 108 if (!driver->remove)
108 return; 109 return;
@@ -119,7 +120,7 @@ EXPORT_SYMBOL(acpi_pci_unregister_driver);
119static acpi_status 120static acpi_status
120get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data) 121get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
121{ 122{
122 int *busnr = (int *)data; 123 int *busnr = data;
123 struct acpi_resource_address64 address; 124 struct acpi_resource_address64 address;
124 125
125 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 && 126 if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
@@ -164,10 +165,9 @@ static int acpi_pci_root_add(struct acpi_device *device)
164 if (!device) 165 if (!device)
165 return -EINVAL; 166 return -EINVAL;
166 167
167 root = kmalloc(sizeof(struct acpi_pci_root), GFP_KERNEL); 168 root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
168 if (!root) 169 if (!root)
169 return -ENOMEM; 170 return -ENOMEM;
170 memset(root, 0, sizeof(struct acpi_pci_root));
171 INIT_LIST_HEAD(&root->node); 171 INIT_LIST_HEAD(&root->node);
172 172
173 root->device = device; 173 root->device = device;
@@ -331,7 +331,7 @@ static int acpi_pci_root_remove(struct acpi_device *device, int type)
331 if (!device || !acpi_driver_data(device)) 331 if (!device || !acpi_driver_data(device))
332 return -EINVAL; 332 return -EINVAL;
333 333
334 root = (struct acpi_pci_root *)acpi_driver_data(device); 334 root = acpi_driver_data(device);
335 335
336 kfree(root); 336 kfree(root);
337 337
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index fe67a8af520e..0ba7dfbbb2ee 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -108,7 +108,7 @@ acpi_power_get_context(acpi_handle handle,
108 return result; 108 return result;
109 } 109 }
110 110
111 *resource = (struct acpi_power_resource *)acpi_driver_data(device); 111 *resource = acpi_driver_data(device);
112 if (!resource) 112 if (!resource)
113 return -ENODEV; 113 return -ENODEV;
114 114
@@ -442,7 +442,7 @@ static int acpi_power_seq_show(struct seq_file *seq, void *offset)
442 struct acpi_power_resource *resource = NULL; 442 struct acpi_power_resource *resource = NULL;
443 443
444 444
445 resource = (struct acpi_power_resource *)seq->private; 445 resource = seq->private;
446 446
447 if (!resource) 447 if (!resource)
448 goto end; 448 goto end;
@@ -532,10 +532,9 @@ static int acpi_power_add(struct acpi_device *device)
532 if (!device) 532 if (!device)
533 return -EINVAL; 533 return -EINVAL;
534 534
535 resource = kmalloc(sizeof(struct acpi_power_resource), GFP_KERNEL); 535 resource = kzalloc(sizeof(struct acpi_power_resource), GFP_KERNEL);
536 if (!resource) 536 if (!resource)
537 return -ENOMEM; 537 return -ENOMEM;
538 memset(resource, 0, sizeof(struct acpi_power_resource));
539 538
540 resource->device = device; 539 resource->device = device;
541 strcpy(resource->name, device->pnp.bus_id); 540 strcpy(resource->name, device->pnp.bus_id);
@@ -590,7 +589,7 @@ static int acpi_power_remove(struct acpi_device *device, int type)
590 if (!device || !acpi_driver_data(device)) 589 if (!device || !acpi_driver_data(device))
591 return -EINVAL; 590 return -EINVAL;
592 591
593 resource = (struct acpi_power_resource *)acpi_driver_data(device); 592 resource = acpi_driver_data(device);
594 593
595 acpi_power_remove_fs(device); 594 acpi_power_remove_fs(device);
596 595
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 1908e0d20222..25718fed39f1 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -277,7 +277,7 @@ static struct proc_dir_entry *acpi_processor_dir = NULL;
277 277
278static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset) 278static int acpi_processor_info_seq_show(struct seq_file *seq, void *offset)
279{ 279{
280 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 280 struct acpi_processor *pr = seq->private;
281 281
282 282
283 if (!pr) 283 if (!pr)
@@ -542,12 +542,12 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
542 * Don't trust it blindly 542 * Don't trust it blindly
543 */ 543 */
544 if (processor_device_array[pr->id] != NULL && 544 if (processor_device_array[pr->id] != NULL &&
545 processor_device_array[pr->id] != (void *)device) { 545 processor_device_array[pr->id] != device) {
546 printk(KERN_WARNING "BIOS reported wrong ACPI id" 546 printk(KERN_WARNING "BIOS reported wrong ACPI id"
547 "for the processor\n"); 547 "for the processor\n");
548 return -ENODEV; 548 return -ENODEV;
549 } 549 }
550 processor_device_array[pr->id] = (void *)device; 550 processor_device_array[pr->id] = device;
551 551
552 processors[pr->id] = pr; 552 processors[pr->id] = pr;
553 553
@@ -578,7 +578,7 @@ static int __cpuinit acpi_processor_start(struct acpi_device *device)
578 578
579static void acpi_processor_notify(acpi_handle handle, u32 event, void *data) 579static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
580{ 580{
581 struct acpi_processor *pr = (struct acpi_processor *)data; 581 struct acpi_processor *pr = data;
582 struct acpi_device *device = NULL; 582 struct acpi_device *device = NULL;
583 583
584 584
@@ -615,10 +615,9 @@ static int acpi_processor_add(struct acpi_device *device)
615 if (!device) 615 if (!device)
616 return -EINVAL; 616 return -EINVAL;
617 617
618 pr = kmalloc(sizeof(struct acpi_processor), GFP_KERNEL); 618 pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
619 if (!pr) 619 if (!pr)
620 return -ENOMEM; 620 return -ENOMEM;
621 memset(pr, 0, sizeof(struct acpi_processor));
622 621
623 pr->handle = device->handle; 622 pr->handle = device->handle;
624 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME); 623 strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
@@ -637,7 +636,7 @@ static int acpi_processor_remove(struct acpi_device *device, int type)
637 if (!device || !acpi_driver_data(device)) 636 if (!device || !acpi_driver_data(device))
638 return -EINVAL; 637 return -EINVAL;
639 638
640 pr = (struct acpi_processor *)acpi_driver_data(device); 639 pr = acpi_driver_data(device);
641 640
642 if (pr->id >= NR_CPUS) { 641 if (pr->id >= NR_CPUS) {
643 kfree(pr); 642 kfree(pr);
@@ -901,13 +900,13 @@ static int __init acpi_processor_init(void)
901 900
902 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir); 901 acpi_processor_dir = proc_mkdir(ACPI_PROCESSOR_CLASS, acpi_root_dir);
903 if (!acpi_processor_dir) 902 if (!acpi_processor_dir)
904 return 0; 903 return -ENOMEM;
905 acpi_processor_dir->owner = THIS_MODULE; 904 acpi_processor_dir->owner = THIS_MODULE;
906 905
907 result = acpi_bus_register_driver(&acpi_processor_driver); 906 result = acpi_bus_register_driver(&acpi_processor_driver);
908 if (result < 0) { 907 if (result < 0) {
909 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir); 908 remove_proc_entry(ACPI_PROCESSOR_CLASS, acpi_root_dir);
910 return 0; 909 return result;
911 } 910 }
912 911
913 acpi_processor_install_hotplug_notify(); 912 acpi_processor_install_hotplug_notify();
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 65b3f056ad89..3f30af21574e 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -211,7 +211,11 @@ acpi_processor_power_activate(struct acpi_processor *pr,
211static void acpi_safe_halt(void) 211static void acpi_safe_halt(void)
212{ 212{
213 current_thread_info()->status &= ~TS_POLLING; 213 current_thread_info()->status &= ~TS_POLLING;
214 smp_mb__after_clear_bit(); 214 /*
215 * TS_POLLING-cleared state must be visible before we
216 * test NEED_RESCHED:
217 */
218 smp_mb();
215 if (!need_resched()) 219 if (!need_resched())
216 safe_halt(); 220 safe_halt();
217 current_thread_info()->status |= TS_POLLING; 221 current_thread_info()->status |= TS_POLLING;
@@ -345,7 +349,11 @@ static void acpi_processor_idle(void)
345 */ 349 */
346 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) { 350 if (cx->type == ACPI_STATE_C2 || cx->type == ACPI_STATE_C3) {
347 current_thread_info()->status &= ~TS_POLLING; 351 current_thread_info()->status &= ~TS_POLLING;
348 smp_mb__after_clear_bit(); 352 /*
353 * TS_POLLING-cleared state must be visible before we
354 * test NEED_RESCHED:
355 */
356 smp_mb();
349 if (need_resched()) { 357 if (need_resched()) {
350 current_thread_info()->status |= TS_POLLING; 358 current_thread_info()->status |= TS_POLLING;
351 local_irq_enable(); 359 local_irq_enable();
@@ -673,7 +681,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
673 return -ENODEV; 681 return -ENODEV;
674 } 682 }
675 683
676 cst = (union acpi_object *)buffer.pointer; 684 cst = buffer.pointer;
677 685
678 /* There must be at least 2 elements */ 686 /* There must be at least 2 elements */
679 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) { 687 if (!cst || (cst->type != ACPI_TYPE_PACKAGE) || cst->package.count < 2) {
@@ -702,14 +710,14 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
702 710
703 memset(&cx, 0, sizeof(cx)); 711 memset(&cx, 0, sizeof(cx));
704 712
705 element = (union acpi_object *)&(cst->package.elements[i]); 713 element = &(cst->package.elements[i]);
706 if (element->type != ACPI_TYPE_PACKAGE) 714 if (element->type != ACPI_TYPE_PACKAGE)
707 continue; 715 continue;
708 716
709 if (element->package.count != 4) 717 if (element->package.count != 4)
710 continue; 718 continue;
711 719
712 obj = (union acpi_object *)&(element->package.elements[0]); 720 obj = &(element->package.elements[0]);
713 721
714 if (obj->type != ACPI_TYPE_BUFFER) 722 if (obj->type != ACPI_TYPE_BUFFER)
715 continue; 723 continue;
@@ -721,7 +729,7 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
721 continue; 729 continue;
722 730
723 /* There should be an easy way to extract an integer... */ 731 /* There should be an easy way to extract an integer... */
724 obj = (union acpi_object *)&(element->package.elements[1]); 732 obj = &(element->package.elements[1]);
725 if (obj->type != ACPI_TYPE_INTEGER) 733 if (obj->type != ACPI_TYPE_INTEGER)
726 continue; 734 continue;
727 735
@@ -754,13 +762,13 @@ static int acpi_processor_get_power_info_cst(struct acpi_processor *pr)
754 } 762 }
755 } 763 }
756 764
757 obj = (union acpi_object *)&(element->package.elements[2]); 765 obj = &(element->package.elements[2]);
758 if (obj->type != ACPI_TYPE_INTEGER) 766 if (obj->type != ACPI_TYPE_INTEGER)
759 continue; 767 continue;
760 768
761 cx.latency = obj->integer.value; 769 cx.latency = obj->integer.value;
762 770
763 obj = (union acpi_object *)&(element->package.elements[3]); 771 obj = &(element->package.elements[3]);
764 if (obj->type != ACPI_TYPE_INTEGER) 772 if (obj->type != ACPI_TYPE_INTEGER)
765 continue; 773 continue;
766 774
@@ -1029,7 +1037,7 @@ int acpi_processor_cst_has_changed(struct acpi_processor *pr)
1029 1037
1030static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset) 1038static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
1031{ 1039{
1032 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 1040 struct acpi_processor *pr = seq->private;
1033 unsigned int i; 1041 unsigned int i;
1034 1042
1035 1043
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index 6fd174a37149..0e60382714bb 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -236,7 +236,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
236 return -ENODEV; 236 return -ENODEV;
237 } 237 }
238 238
239 pss = (union acpi_object *)buffer.pointer; 239 pss = buffer.pointer;
240 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { 240 if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
241 printk(KERN_ERR PREFIX "Invalid _PSS data\n"); 241 printk(KERN_ERR PREFIX "Invalid _PSS data\n");
242 result = -EFAULT; 242 result = -EFAULT;
@@ -410,7 +410,7 @@ static struct file_operations acpi_processor_perf_fops = {
410 410
411static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) 411static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
412{ 412{
413 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 413 struct acpi_processor *pr = seq->private;
414 int i; 414 int i;
415 415
416 416
@@ -451,8 +451,8 @@ acpi_processor_write_performance(struct file *file,
451 size_t count, loff_t * data) 451 size_t count, loff_t * data)
452{ 452{
453 int result = 0; 453 int result = 0;
454 struct seq_file *m = (struct seq_file *)file->private_data; 454 struct seq_file *m = file->private_data;
455 struct acpi_processor *pr = (struct acpi_processor *)m->private; 455 struct acpi_processor *pr = m->private;
456 struct acpi_processor_performance *perf; 456 struct acpi_processor_performance *perf;
457 char state_string[12] = { '\0' }; 457 char state_string[12] = { '\0' };
458 unsigned int new_state = 0; 458 unsigned int new_state = 0;
@@ -551,7 +551,7 @@ static int acpi_processor_get_psd(struct acpi_processor *pr)
551 return -ENODEV; 551 return -ENODEV;
552 } 552 }
553 553
554 psd = (union acpi_object *) buffer.pointer; 554 psd = buffer.pointer;
555 if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { 555 if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
556 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); 556 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
557 result = -EFAULT; 557 result = -EFAULT;
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index ef5e0f6efdba..40fecd67ad83 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -208,7 +208,7 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type)
208 if (result) 208 if (result)
209 return result; 209 return result;
210 210
211 pr = (struct acpi_processor *)acpi_driver_data(device); 211 pr = acpi_driver_data(device);
212 if (!pr) 212 if (!pr)
213 return -ENODEV; 213 return -ENODEV;
214 214
@@ -348,8 +348,8 @@ static ssize_t acpi_processor_write_limit(struct file * file,
348 size_t count, loff_t * data) 348 size_t count, loff_t * data)
349{ 349{
350 int result = 0; 350 int result = 0;
351 struct seq_file *m = (struct seq_file *)file->private_data; 351 struct seq_file *m = file->private_data;
352 struct acpi_processor *pr = (struct acpi_processor *)m->private; 352 struct acpi_processor *pr = m->private;
353 char limit_string[25] = { '\0' }; 353 char limit_string[25] = { '\0' };
354 int px = 0; 354 int px = 0;
355 int tx = 0; 355 int tx = 0;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index d044ec519db0..0ec7dcde0063 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -259,7 +259,7 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
259static int acpi_processor_throttling_seq_show(struct seq_file *seq, 259static int acpi_processor_throttling_seq_show(struct seq_file *seq,
260 void *offset) 260 void *offset)
261{ 261{
262 struct acpi_processor *pr = (struct acpi_processor *)seq->private; 262 struct acpi_processor *pr = seq->private;
263 int i = 0; 263 int i = 0;
264 int result = 0; 264 int result = 0;
265 265
@@ -307,8 +307,8 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
307 size_t count, loff_t * data) 307 size_t count, loff_t * data)
308{ 308{
309 int result = 0; 309 int result = 0;
310 struct seq_file *m = (struct seq_file *)file->private_data; 310 struct seq_file *m = file->private_data;
311 struct acpi_processor *pr = (struct acpi_processor *)m->private; 311 struct acpi_processor *pr = m->private;
312 char state_string[12] = { '\0' }; 312 char state_string[12] = { '\0' };
313 313
314 314
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 8908a975e575..f58fc7447ab4 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -923,7 +923,7 @@ static struct proc_dir_entry *acpi_battery_dir = NULL;
923 923
924static int acpi_battery_read_info(struct seq_file *seq, void *offset) 924static int acpi_battery_read_info(struct seq_file *seq, void *offset)
925{ 925{
926 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 926 struct acpi_battery *battery = seq->private;
927 int cscale; 927 int cscale;
928 int result = 0; 928 int result = 0;
929 929
@@ -1076,7 +1076,7 @@ static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
1076 1076
1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 1077static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
1078{ 1078{
1079 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1079 struct acpi_battery *battery = seq->private;
1080 int result = 0; 1080 int result = 0;
1081 int cscale; 1081 int cscale;
1082 1082
@@ -1125,8 +1125,8 @@ static ssize_t
1125acpi_battery_write_alarm(struct file *file, const char __user * buffer, 1125acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1126 size_t count, loff_t * ppos) 1126 size_t count, loff_t * ppos)
1127{ 1127{
1128 struct seq_file *seq = (struct seq_file *)file->private_data; 1128 struct seq_file *seq = file->private_data;
1129 struct acpi_battery *battery = (struct acpi_battery *)seq->private; 1129 struct acpi_battery *battery = seq->private;
1130 char alarm_string[12] = { '\0' }; 1130 char alarm_string[12] = { '\0' };
1131 int result, old_alarm, new_alarm; 1131 int result, old_alarm, new_alarm;
1132 1132
@@ -1160,14 +1160,14 @@ acpi_battery_write_alarm(struct file *file, const char __user * buffer,
1160 if (result) { 1160 if (result) {
1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1161 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1162 "acpi_battery_set_alarm() failed\n")); 1162 "acpi_battery_set_alarm() failed\n"));
1163 (void)acpi_battery_set_alarm(battery, old_alarm); 1163 acpi_battery_set_alarm(battery, old_alarm);
1164 goto end; 1164 goto end;
1165 } 1165 }
1166 result = acpi_battery_get_alarm(battery); 1166 result = acpi_battery_get_alarm(battery);
1167 if (result) { 1167 if (result) {
1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1168 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1169 "acpi_battery_get_alarm() failed\n")); 1169 "acpi_battery_get_alarm() failed\n"));
1170 (void)acpi_battery_set_alarm(battery, old_alarm); 1170 acpi_battery_set_alarm(battery, old_alarm);
1171 goto end; 1171 goto end;
1172 } 1172 }
1173 1173
@@ -1217,7 +1217,7 @@ static struct proc_dir_entry *acpi_ac_dir = NULL;
1217 1217
1218static int acpi_ac_read_state(struct seq_file *seq, void *offset) 1218static int acpi_ac_read_state(struct seq_file *seq, void *offset)
1219{ 1219{
1220 struct acpi_sbs *sbs = (struct acpi_sbs *)seq->private; 1220 struct acpi_sbs *sbs = seq->private;
1221 int result; 1221 int result;
1222 1222
1223 if (sbs->zombie) { 1223 if (sbs->zombie) {
@@ -1302,7 +1302,7 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
1302 battery->init_state = 1; 1302 battery->init_state = 1;
1303 } 1303 }
1304 1304
1305 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1305 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1306 1306
1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry, 1307 result = acpi_sbs_generic_add_fs(&battery->battery_entry,
1308 acpi_battery_dir, 1308 acpi_battery_dir,
@@ -1485,7 +1485,7 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1485 } 1485 }
1486 1486
1487 if (old_battery_present != new_battery_present) { 1487 if (old_battery_present != new_battery_present) {
1488 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1488 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1489 result = acpi_sbs_generate_event(sbs->device, 1489 result = acpi_sbs_generate_event(sbs->device,
1490 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1490 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1491 new_battery_present, 1491 new_battery_present,
@@ -1498,7 +1498,7 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, int data_type)
1498 } 1498 }
1499 } 1499 }
1500 if (old_remaining_capacity != battery->state.remaining_capacity) { 1500 if (old_remaining_capacity != battery->state.remaining_capacity) {
1501 (void)sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id); 1501 sprintf(dir_name, ACPI_BATTERY_DIR_NAME, id);
1502 result = acpi_sbs_generate_event(sbs->device, 1502 result = acpi_sbs_generate_event(sbs->device,
1503 ACPI_SBS_BATTERY_NOTIFY_STATUS, 1503 ACPI_SBS_BATTERY_NOTIFY_STATUS,
1504 new_battery_present, 1504 new_battery_present,
@@ -1576,12 +1576,11 @@ static int acpi_sbs_add(struct acpi_device *device)
1576 int id, cnt; 1576 int id, cnt;
1577 acpi_status status = AE_OK; 1577 acpi_status status = AE_OK;
1578 1578
1579 sbs = kmalloc(sizeof(struct acpi_sbs), GFP_KERNEL); 1579 sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL);
1580 if (!sbs) { 1580 if (!sbs) {
1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n")); 1581 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "kmalloc() failed\n"));
1582 return -ENOMEM; 1582 return -ENOMEM;
1583 } 1583 }
1584 memset(sbs, 0, sizeof(struct acpi_sbs));
1585 1584
1586 cnt = 0; 1585 cnt = 0;
1587 while (cnt < 10) { 1586 while (cnt < 10) {
@@ -1659,7 +1658,7 @@ static int acpi_sbs_add(struct acpi_device *device)
1659 init_timer(&sbs->update_timer); 1658 init_timer(&sbs->update_timer);
1660 if (update_mode == QUEUE_UPDATE_MODE) { 1659 if (update_mode == QUEUE_UPDATE_MODE) {
1661 status = acpi_os_execute(OSL_GPE_HANDLER, 1660 status = acpi_os_execute(OSL_GPE_HANDLER,
1662 acpi_sbs_update_queue, (void *)sbs); 1661 acpi_sbs_update_queue, sbs);
1663 if (status != AE_OK) { 1662 if (status != AE_OK) {
1664 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 1663 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1665 "acpi_os_execute() failed\n")); 1664 "acpi_os_execute() failed\n"));
@@ -1685,7 +1684,7 @@ static int acpi_sbs_add(struct acpi_device *device)
1685 1684
1686int acpi_sbs_remove(struct acpi_device *device, int type) 1685int acpi_sbs_remove(struct acpi_device *device, int type)
1687{ 1686{
1688 struct acpi_sbs *sbs = NULL; 1687 struct acpi_sbs *sbs;
1689 int id; 1688 int id;
1690 1689
1691 if (!device) { 1690 if (!device) {
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 698a1540e303..283d87522c5d 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -984,12 +984,11 @@ acpi_add_single_object(struct acpi_device **child,
984 if (!child) 984 if (!child)
985 return -EINVAL; 985 return -EINVAL;
986 986
987 device = kmalloc(sizeof(struct acpi_device), GFP_KERNEL); 987 device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
988 if (!device) { 988 if (!device) {
989 printk(KERN_ERR PREFIX "Memory allocation error\n"); 989 printk(KERN_ERR PREFIX "Memory allocation error\n");
990 return -ENOMEM; 990 return -ENOMEM;
991 } 991 }
992 memset(device, 0, sizeof(struct acpi_device));
993 992
994 device->handle = handle; 993 device->handle = handle;
995 device->parent = parent; 994 device->parent = parent;
diff --git a/drivers/acpi/sleep/wakeup.c b/drivers/acpi/sleep/wakeup.c
index af1dbabaf0b1..fab8f2694f03 100644
--- a/drivers/acpi/sleep/wakeup.c
+++ b/drivers/acpi/sleep/wakeup.c
@@ -183,11 +183,11 @@ late_initcall(acpi_wakeup_device_init);
183#endif 183#endif
184 184
185/* 185/*
186 * Disable all wakeup GPEs before power off. 186 * Disable all wakeup GPEs before entering requested sleep state.
187 * 187 * @sleep_state: ACPI state
188 * Since acpi_enter_sleep_state() will disable all 188 * Since acpi_enter_sleep_state() will disable all
189 * RUNTIME GPEs, we simply mark all GPES that 189 * RUNTIME GPEs, we simply mark all GPES that
190 * are not enabled for wakeup from S5 as RUNTIME. 190 * are not enabled for wakeup from requested state as RUNTIME.
191 */ 191 */
192void acpi_gpe_sleep_prepare(u32 sleep_state) 192void acpi_gpe_sleep_prepare(u32 sleep_state)
193{ 193{
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index bfb3bfcf9e91..ffa30c9fccbf 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -228,7 +228,7 @@ void acpi_table_print_madt_entry(acpi_table_entry_header * header)
228static int 228static int
229acpi_table_compute_checksum(void *table_pointer, unsigned long length) 229acpi_table_compute_checksum(void *table_pointer, unsigned long length)
230{ 230{
231 u8 *p = (u8 *) table_pointer; 231 u8 *p = table_pointer;
232 unsigned long remains = length; 232 unsigned long remains = length;
233 unsigned long sum = 0; 233 unsigned long sum = 0;
234 234
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 7767987be15a..5ba9303293ad 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -123,7 +123,6 @@ acpi_status acpi_load_tables(void)
123 123
124ACPI_EXPORT_SYMBOL(acpi_load_tables) 124ACPI_EXPORT_SYMBOL(acpi_load_tables)
125 125
126#ifdef ACPI_FUTURE_USAGE
127/******************************************************************************* 126/*******************************************************************************
128 * 127 *
129 * FUNCTION: acpi_load_table 128 * FUNCTION: acpi_load_table
@@ -221,6 +220,59 @@ ACPI_EXPORT_SYMBOL(acpi_load_table)
221 220
222/******************************************************************************* 221/*******************************************************************************
223 * 222 *
223 * FUNCTION: acpi_unload_table_id
224 *
225 * PARAMETERS: table_type - Type of table to be unloaded
226 * id - Owner ID of the table to be removed.
227 *
228 * RETURN: Status
229 *
230 * DESCRIPTION: This routine is used to force the unload of a table (by id)
231 *
232 ******************************************************************************/
233acpi_status acpi_unload_table_id(acpi_table_type table_type, acpi_owner_id id)
234{
235 struct acpi_table_desc *table_desc;
236 acpi_status status;
237
238 ACPI_FUNCTION_TRACE(acpi_unload_table);
239
240 /* Parameter validation */
241 if (table_type > ACPI_TABLE_ID_MAX)
242 return_ACPI_STATUS(AE_BAD_PARAMETER);
243
244 /* Find table from the requested type list */
245 table_desc = acpi_gbl_table_lists[table_type].next;
246 while (table_desc && table_desc->owner_id != id)
247 table_desc = table_desc->next;
248
249 if (!table_desc)
250 return_ACPI_STATUS(AE_NOT_EXIST);
251
252 /*
253 * Delete all namespace objects owned by this table. Note that these
254 * objects can appear anywhere in the namespace by virtue of the AML
255 * "Scope" operator. Thus, we need to track ownership by an ID, not
256 * simply a position within the hierarchy
257 */
258 acpi_ns_delete_namespace_by_owner(table_desc->owner_id);
259
260 status = acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
261 if (ACPI_FAILURE(status))
262 return_ACPI_STATUS(status);
263
264 (void)acpi_tb_uninstall_table(table_desc);
265
266 (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
267
268 return_ACPI_STATUS(AE_OK);
269}
270
271ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
272
273#ifdef ACPI_FUTURE_USAGE
274/*******************************************************************************
275 *
224 * FUNCTION: acpi_unload_table 276 * FUNCTION: acpi_unload_table
225 * 277 *
226 * PARAMETERS: table_type - Type of table to be unloaded 278 * PARAMETERS: table_type - Type of table to be unloaded
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 5753d06b7860..40ddb4dd9631 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -663,7 +663,7 @@ static void acpi_thermal_run(unsigned long data)
663static void acpi_thermal_check(void *data) 663static void acpi_thermal_check(void *data)
664{ 664{
665 int result = 0; 665 int result = 0;
666 struct acpi_thermal *tz = (struct acpi_thermal *)data; 666 struct acpi_thermal *tz = data;
667 unsigned long sleep_time = 0; 667 unsigned long sleep_time = 0;
668 int i = 0; 668 int i = 0;
669 struct acpi_thermal_state state; 669 struct acpi_thermal_state state;
@@ -778,7 +778,7 @@ static struct proc_dir_entry *acpi_thermal_dir;
778 778
779static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset) 779static int acpi_thermal_state_seq_show(struct seq_file *seq, void *offset)
780{ 780{
781 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 781 struct acpi_thermal *tz = seq->private;
782 782
783 783
784 if (!tz) 784 if (!tz)
@@ -813,7 +813,7 @@ static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file)
813static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset) 813static int acpi_thermal_temp_seq_show(struct seq_file *seq, void *offset)
814{ 814{
815 int result = 0; 815 int result = 0;
816 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 816 struct acpi_thermal *tz = seq->private;
817 817
818 818
819 if (!tz) 819 if (!tz)
@@ -837,7 +837,7 @@ static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file)
837 837
838static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset) 838static int acpi_thermal_trip_seq_show(struct seq_file *seq, void *offset)
839{ 839{
840 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 840 struct acpi_thermal *tz = seq->private;
841 int i = 0; 841 int i = 0;
842 int j = 0; 842 int j = 0;
843 843
@@ -893,8 +893,8 @@ acpi_thermal_write_trip_points(struct file *file,
893 const char __user * buffer, 893 const char __user * buffer,
894 size_t count, loff_t * ppos) 894 size_t count, loff_t * ppos)
895{ 895{
896 struct seq_file *m = (struct seq_file *)file->private_data; 896 struct seq_file *m = file->private_data;
897 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 897 struct acpi_thermal *tz = m->private;
898 898
899 char *limit_string; 899 char *limit_string;
900 int num, critical, hot, passive; 900 int num, critical, hot, passive;
@@ -902,12 +902,10 @@ acpi_thermal_write_trip_points(struct file *file,
902 int i = 0; 902 int i = 0;
903 903
904 904
905 limit_string = kmalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL); 905 limit_string = kzalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
906 if (!limit_string) 906 if (!limit_string)
907 return -ENOMEM; 907 return -ENOMEM;
908 908
909 memset(limit_string, 0, ACPI_THERMAL_MAX_LIMIT_STR_LEN);
910
911 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL); 909 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL);
912 if (!active) { 910 if (!active) {
913 kfree(limit_string); 911 kfree(limit_string);
@@ -953,7 +951,7 @@ acpi_thermal_write_trip_points(struct file *file,
953 951
954static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) 952static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
955{ 953{
956 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 954 struct acpi_thermal *tz = seq->private;
957 955
958 956
959 if (!tz) 957 if (!tz)
@@ -984,8 +982,8 @@ acpi_thermal_write_cooling_mode(struct file *file,
984 const char __user * buffer, 982 const char __user * buffer,
985 size_t count, loff_t * ppos) 983 size_t count, loff_t * ppos)
986{ 984{
987 struct seq_file *m = (struct seq_file *)file->private_data; 985 struct seq_file *m = file->private_data;
988 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 986 struct acpi_thermal *tz = m->private;
989 int result = 0; 987 int result = 0;
990 char mode_string[12] = { '\0' }; 988 char mode_string[12] = { '\0' };
991 989
@@ -1014,7 +1012,7 @@ acpi_thermal_write_cooling_mode(struct file *file,
1014 1012
1015static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset) 1013static int acpi_thermal_polling_seq_show(struct seq_file *seq, void *offset)
1016{ 1014{
1017 struct acpi_thermal *tz = (struct acpi_thermal *)seq->private; 1015 struct acpi_thermal *tz = seq->private;
1018 1016
1019 1017
1020 if (!tz) 1018 if (!tz)
@@ -1043,8 +1041,8 @@ acpi_thermal_write_polling(struct file *file,
1043 const char __user * buffer, 1041 const char __user * buffer,
1044 size_t count, loff_t * ppos) 1042 size_t count, loff_t * ppos)
1045{ 1043{
1046 struct seq_file *m = (struct seq_file *)file->private_data; 1044 struct seq_file *m = file->private_data;
1047 struct acpi_thermal *tz = (struct acpi_thermal *)m->private; 1045 struct acpi_thermal *tz = m->private;
1048 int result = 0; 1046 int result = 0;
1049 char polling_string[12] = { '\0' }; 1047 char polling_string[12] = { '\0' };
1050 int seconds = 0; 1048 int seconds = 0;
@@ -1170,7 +1168,7 @@ static int acpi_thermal_remove_fs(struct acpi_device *device)
1170 1168
1171static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data) 1169static void acpi_thermal_notify(acpi_handle handle, u32 event, void *data)
1172{ 1170{
1173 struct acpi_thermal *tz = (struct acpi_thermal *)data; 1171 struct acpi_thermal *tz = data;
1174 struct acpi_device *device = NULL; 1172 struct acpi_device *device = NULL;
1175 1173
1176 1174
@@ -1271,10 +1269,9 @@ static int acpi_thermal_add(struct acpi_device *device)
1271 if (!device) 1269 if (!device)
1272 return -EINVAL; 1270 return -EINVAL;
1273 1271
1274 tz = kmalloc(sizeof(struct acpi_thermal), GFP_KERNEL); 1272 tz = kzalloc(sizeof(struct acpi_thermal), GFP_KERNEL);
1275 if (!tz) 1273 if (!tz)
1276 return -ENOMEM; 1274 return -ENOMEM;
1277 memset(tz, 0, sizeof(struct acpi_thermal));
1278 1275
1279 tz->device = device; 1276 tz->device = device;
1280 strcpy(tz->name, device->pnp.bus_id); 1277 strcpy(tz->name, device->pnp.bus_id);
@@ -1324,7 +1321,7 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1324 if (!device || !acpi_driver_data(device)) 1321 if (!device || !acpi_driver_data(device))
1325 return -EINVAL; 1322 return -EINVAL;
1326 1323
1327 tz = (struct acpi_thermal *)acpi_driver_data(device); 1324 tz = acpi_driver_data(device);
1328 1325
1329 /* avoid timer adding new defer task */ 1326 /* avoid timer adding new defer task */
1330 tz->zombie = 1; 1327 tz->zombie = 1;
@@ -1364,7 +1361,7 @@ static int acpi_thermal_resume(struct acpi_device *device, int state)
1364 if (!device || !acpi_driver_data(device)) 1361 if (!device || !acpi_driver_data(device))
1365 return -EINVAL; 1362 return -EINVAL;
1366 1363
1367 tz = (struct acpi_thermal *)acpi_driver_data(device); 1364 tz = acpi_driver_data(device);
1368 1365
1369 acpi_thermal_get_temperature(tz); 1366 acpi_thermal_get_temperature(tz);
1370 1367
diff --git a/drivers/acpi/toshiba_acpi.c b/drivers/acpi/toshiba_acpi.c
index 7fe0b7ae9733..88aeccbafaaf 100644
--- a/drivers/acpi/toshiba_acpi.c
+++ b/drivers/acpi/toshiba_acpi.c
@@ -41,6 +41,8 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/types.h> 42#include <linux/types.h>
43#include <linux/proc_fs.h> 43#include <linux/proc_fs.h>
44#include <linux/backlight.h>
45
44#include <asm/uaccess.h> 46#include <asm/uaccess.h>
45 47
46#include <acpi/acpi_drivers.h> 48#include <acpi/acpi_drivers.h>
@@ -210,6 +212,7 @@ static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
210} 212}
211 213
212static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ; 214static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
215static struct backlight_device *toshiba_backlight_device;
213static int force_fan; 216static int force_fan;
214static int last_key_event; 217static int last_key_event;
215static int key_event_valid; 218static int key_event_valid;
@@ -271,14 +274,23 @@ dispatch_write(struct file *file, const char __user * buffer,
271 return result; 274 return result;
272} 275}
273 276
274static char *read_lcd(char *p) 277static int get_lcd(struct backlight_device *bd)
275{ 278{
276 u32 hci_result; 279 u32 hci_result;
277 u32 value; 280 u32 value;
278 281
279 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result); 282 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
280 if (hci_result == HCI_SUCCESS) { 283 if (hci_result == HCI_SUCCESS) {
281 value = value >> HCI_LCD_BRIGHTNESS_SHIFT; 284 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
285 } else
286 return -EFAULT;
287}
288
289static char *read_lcd(char *p)
290{
291 int value = get_lcd(NULL);
292
293 if (value >= 0) {
282 p += sprintf(p, "brightness: %d\n", value); 294 p += sprintf(p, "brightness: %d\n", value);
283 p += sprintf(p, "brightness_levels: %d\n", 295 p += sprintf(p, "brightness_levels: %d\n",
284 HCI_LCD_BRIGHTNESS_LEVELS); 296 HCI_LCD_BRIGHTNESS_LEVELS);
@@ -289,22 +301,34 @@ static char *read_lcd(char *p)
289 return p; 301 return p;
290} 302}
291 303
304static int set_lcd(int value)
305{
306 u32 hci_result;
307
308 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
309 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
310 if (hci_result != HCI_SUCCESS)
311 return -EFAULT;
312
313 return 0;
314}
315
316static int set_lcd_status(struct backlight_device *bd)
317{
318 return set_lcd(bd->props->brightness);
319}
320
292static unsigned long write_lcd(const char *buffer, unsigned long count) 321static unsigned long write_lcd(const char *buffer, unsigned long count)
293{ 322{
294 int value; 323 int value;
295 u32 hci_result; 324 int ret = count;
296 325
297 if (sscanf(buffer, " brightness : %i", &value) == 1 && 326 if (sscanf(buffer, " brightness : %i", &value) == 1 &&
298 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) { 327 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS)
299 value = value << HCI_LCD_BRIGHTNESS_SHIFT; 328 ret = set_lcd(value);
300 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result); 329 else
301 if (hci_result != HCI_SUCCESS) 330 ret = -EINVAL;
302 return -EFAULT; 331 return ret;
303 } else {
304 return -EINVAL;
305 }
306
307 return count;
308} 332}
309 333
310static char *read_video(char *p) 334static char *read_video(char *p)
@@ -506,6 +530,26 @@ static acpi_status __exit remove_device(void)
506 return AE_OK; 530 return AE_OK;
507} 531}
508 532
533static struct backlight_properties toshiba_backlight_data = {
534 .owner = THIS_MODULE,
535 .get_brightness = get_lcd,
536 .update_status = set_lcd_status,
537 .max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1,
538};
539
540static void __exit toshiba_acpi_exit(void)
541{
542 if (toshiba_backlight_device)
543 backlight_device_unregister(toshiba_backlight_device);
544
545 remove_device();
546
547 if (toshiba_proc_dir)
548 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
549
550 return;
551}
552
509static int __init toshiba_acpi_init(void) 553static int __init toshiba_acpi_init(void)
510{ 554{
511 acpi_status status = AE_OK; 555 acpi_status status = AE_OK;
@@ -546,17 +590,16 @@ static int __init toshiba_acpi_init(void)
546 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); 590 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
547 } 591 }
548 592
549 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV; 593 toshiba_backlight_device = backlight_device_register("toshiba",NULL,
550} 594 NULL,
551 595 &toshiba_backlight_data);
552static void __exit toshiba_acpi_exit(void) 596 if (IS_ERR(toshiba_backlight_device)) {
553{ 597 printk(KERN_ERR "Could not register toshiba backlight device\n");
554 remove_device(); 598 toshiba_backlight_device = NULL;
555 599 toshiba_acpi_exit();
556 if (toshiba_proc_dir) 600 }
557 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
558 601
559 return; 602 return (ACPI_SUCCESS(status)) ? 0 : -ENODEV;
560} 603}
561 604
562module_init(toshiba_acpi_init); 605module_init(toshiba_acpi_init);
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index bb1eaf9aa653..9e9054e155c1 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -180,8 +180,9 @@ acpi_ut_debug_print(u32 requested_debug_level,
180 if (thread_id != acpi_gbl_prev_thread_id) { 180 if (thread_id != acpi_gbl_prev_thread_id) {
181 if (ACPI_LV_THREADS & acpi_dbg_level) { 181 if (ACPI_LV_THREADS & acpi_dbg_level) {
182 acpi_os_printf 182 acpi_os_printf
183 ("\n**** Context Switch from TID %X to TID %X ****\n\n", 183 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
184 (u32) acpi_gbl_prev_thread_id, (u32) thread_id); 184 (unsigned long) acpi_gbl_prev_thread_id,
185 (unsigned long) thread_id);
185 } 186 }
186 187
187 acpi_gbl_prev_thread_id = thread_id; 188 acpi_gbl_prev_thread_id = thread_id;
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index c39062a047cd..180e73ceb6e2 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -243,23 +243,24 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
243#endif 243#endif
244 244
245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
246 "Thread %X attempting to acquire Mutex [%s]\n", 246 "Thread %lX attempting to acquire Mutex [%s]\n",
247 (u32) this_thread_id, acpi_ut_get_mutex_name(mutex_id))); 247 (unsigned long) this_thread_id,
248 acpi_ut_get_mutex_name(mutex_id)));
248 249
249 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, 250 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
250 ACPI_WAIT_FOREVER); 251 ACPI_WAIT_FOREVER);
251 if (ACPI_SUCCESS(status)) { 252 if (ACPI_SUCCESS(status)) {
252 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 253 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
253 "Thread %X acquired Mutex [%s]\n", 254 "Thread %lX acquired Mutex [%s]\n",
254 (u32) this_thread_id, 255 (unsigned long) this_thread_id,
255 acpi_ut_get_mutex_name(mutex_id))); 256 acpi_ut_get_mutex_name(mutex_id)));
256 257
257 acpi_gbl_mutex_info[mutex_id].use_count++; 258 acpi_gbl_mutex_info[mutex_id].use_count++;
258 acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id; 259 acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id;
259 } else { 260 } else {
260 ACPI_EXCEPTION((AE_INFO, status, 261 ACPI_EXCEPTION((AE_INFO, status,
261 "Thread %X could not acquire Mutex [%X]", 262 "Thread %lX could not acquire Mutex [%X]",
262 (u32) this_thread_id, mutex_id)); 263 (unsigned long) this_thread_id, mutex_id));
263 } 264 }
264 265
265 return (status); 266 return (status);
@@ -285,7 +286,8 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
285 286
286 this_thread_id = acpi_os_get_thread_id(); 287 this_thread_id = acpi_os_get_thread_id();
287 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 288 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
288 "Thread %X releasing Mutex [%s]\n", (u32) this_thread_id, 289 "Thread %lX releasing Mutex [%s]\n",
290 (unsigned long) this_thread_id,
289 acpi_ut_get_mutex_name(mutex_id))); 291 acpi_ut_get_mutex_name(mutex_id)));
290 292
291 if (mutex_id > ACPI_MAX_MUTEX) { 293 if (mutex_id > ACPI_MAX_MUTEX) {
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index d0d84c43a9d4..68a809fa7b19 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -83,7 +83,7 @@ acpi_extract_package(union acpi_object *package,
83 return AE_BAD_DATA; 83 return AE_BAD_DATA;
84 } 84 }
85 85
86 format_string = (char *)format->pointer; 86 format_string = format->pointer;
87 87
88 /* 88 /*
89 * Calculate size_required. 89 * Calculate size_required.
@@ -262,11 +262,10 @@ acpi_evaluate_integer(acpi_handle handle,
262 if (!data) 262 if (!data)
263 return AE_BAD_PARAMETER; 263 return AE_BAD_PARAMETER;
264 264
265 element = kmalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); 265 element = kzalloc(sizeof(union acpi_object), irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL);
266 if (!element) 266 if (!element)
267 return AE_NO_MEMORY; 267 return AE_NO_MEMORY;
268 268
269 memset(element, 0, sizeof(union acpi_object));
270 buffer.length = sizeof(union acpi_object); 269 buffer.length = sizeof(union acpi_object);
271 buffer.pointer = element; 270 buffer.pointer = element;
272 status = acpi_evaluate_object(handle, pathname, arguments, &buffer); 271 status = acpi_evaluate_object(handle, pathname, arguments, &buffer);
@@ -321,12 +320,11 @@ acpi_evaluate_string(acpi_handle handle,
321 return AE_BAD_DATA; 320 return AE_BAD_DATA;
322 } 321 }
323 322
324 *data = kmalloc(element->string.length + 1, GFP_KERNEL); 323 *data = kzalloc(element->string.length + 1, GFP_KERNEL);
325 if (!data) { 324 if (!data) {
326 printk(KERN_ERR PREFIX "Memory allocation\n"); 325 printk(KERN_ERR PREFIX "Memory allocation\n");
327 return -ENOMEM; 326 return -ENOMEM;
328 } 327 }
329 memset(*data, 0, element->string.length + 1);
330 328
331 memcpy(*data, element->string.pointer, element->string.length); 329 memcpy(*data, element->string.pointer, element->string.length);
332 330
@@ -361,7 +359,7 @@ acpi_evaluate_reference(acpi_handle handle,
361 if (ACPI_FAILURE(status)) 359 if (ACPI_FAILURE(status))
362 goto end; 360 goto end;
363 361
364 package = (union acpi_object *)buffer.pointer; 362 package = buffer.pointer;
365 363
366 if ((buffer.length == 0) || !package) { 364 if ((buffer.length == 0) || !package) {
367 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n", 365 printk(KERN_ERR PREFIX "No return object (len %X ptr %p)\n",
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 56666a982476..36b37d755dbc 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com> 4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org> 5 * Copyright (C) 2004 Bruno Ducrot <ducrot@poupinou.org>
6 * Copyright (C) 2006 Thomas Tuttle <linux-kernel@ttuttle.net>
6 * 7 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * 9 *
@@ -47,11 +48,11 @@
47#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83 48#define ACPI_VIDEO_NOTIFY_NEXT_OUTPUT 0x83
48#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84 49#define ACPI_VIDEO_NOTIFY_PREV_OUTPUT 0x84
49 50
50#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x82 51#define ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS 0x85
51#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x83 52#define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
52#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x84 53#define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
53#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x85 54#define ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS 0x88
54#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x86 55#define ACPI_VIDEO_NOTIFY_DISPLAY_OFF 0x89
55 56
56#define ACPI_VIDEO_HEAD_INVALID (~0u - 1) 57#define ACPI_VIDEO_HEAD_INVALID (~0u - 1)
57#define ACPI_VIDEO_HEAD_END (~0u) 58#define ACPI_VIDEO_HEAD_END (~0u)
@@ -386,7 +387,7 @@ acpi_video_device_EDID(struct acpi_video_device *device,
386 if (ACPI_FAILURE(status)) 387 if (ACPI_FAILURE(status))
387 return -ENODEV; 388 return -ENODEV;
388 389
389 obj = (union acpi_object *)buffer.pointer; 390 obj = buffer.pointer;
390 391
391 if (obj && obj->type == ACPI_TYPE_BUFFER) 392 if (obj && obj->type == ACPI_TYPE_BUFFER)
392 *edid = obj; 393 *edid = obj;
@@ -532,11 +533,10 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
532 int count = 0; 533 int count = 0;
533 union acpi_object *o; 534 union acpi_object *o;
534 535
535 br = kmalloc(sizeof(*br), GFP_KERNEL); 536 br = kzalloc(sizeof(*br), GFP_KERNEL);
536 if (!br) { 537 if (!br) {
537 printk(KERN_ERR "can't allocate memory\n"); 538 printk(KERN_ERR "can't allocate memory\n");
538 } else { 539 } else {
539 memset(br, 0, sizeof(*br));
540 br->levels = kmalloc(obj->package.count * 540 br->levels = kmalloc(obj->package.count *
541 sizeof *(br->levels), GFP_KERNEL); 541 sizeof *(br->levels), GFP_KERNEL);
542 if (!br->levels) 542 if (!br->levels)
@@ -654,8 +654,7 @@ static struct proc_dir_entry *acpi_video_dir;
654 654
655static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset) 655static int acpi_video_device_info_seq_show(struct seq_file *seq, void *offset)
656{ 656{
657 struct acpi_video_device *dev = 657 struct acpi_video_device *dev = seq->private;
658 (struct acpi_video_device *)seq->private;
659 658
660 659
661 if (!dev) 660 if (!dev)
@@ -688,8 +687,7 @@ acpi_video_device_info_open_fs(struct inode *inode, struct file *file)
688static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset) 687static int acpi_video_device_state_seq_show(struct seq_file *seq, void *offset)
689{ 688{
690 int status; 689 int status;
691 struct acpi_video_device *dev = 690 struct acpi_video_device *dev = seq->private;
692 (struct acpi_video_device *)seq->private;
693 unsigned long state; 691 unsigned long state;
694 692
695 693
@@ -727,8 +725,8 @@ acpi_video_device_write_state(struct file *file,
727 size_t count, loff_t * data) 725 size_t count, loff_t * data)
728{ 726{
729 int status; 727 int status;
730 struct seq_file *m = (struct seq_file *)file->private_data; 728 struct seq_file *m = file->private_data;
731 struct acpi_video_device *dev = (struct acpi_video_device *)m->private; 729 struct acpi_video_device *dev = m->private;
732 char str[12] = { 0 }; 730 char str[12] = { 0 };
733 u32 state = 0; 731 u32 state = 0;
734 732
@@ -754,8 +752,7 @@ acpi_video_device_write_state(struct file *file,
754static int 752static int
755acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset) 753acpi_video_device_brightness_seq_show(struct seq_file *seq, void *offset)
756{ 754{
757 struct acpi_video_device *dev = 755 struct acpi_video_device *dev = seq->private;
758 (struct acpi_video_device *)seq->private;
759 int i; 756 int i;
760 757
761 758
@@ -784,8 +781,8 @@ acpi_video_device_write_brightness(struct file *file,
784 const char __user * buffer, 781 const char __user * buffer,
785 size_t count, loff_t * data) 782 size_t count, loff_t * data)
786{ 783{
787 struct seq_file *m = (struct seq_file *)file->private_data; 784 struct seq_file *m = file->private_data;
788 struct acpi_video_device *dev = (struct acpi_video_device *)m->private; 785 struct acpi_video_device *dev = m->private;
789 char str[4] = { 0 }; 786 char str[4] = { 0 };
790 unsigned int level = 0; 787 unsigned int level = 0;
791 int i; 788 int i;
@@ -817,8 +814,7 @@ acpi_video_device_write_brightness(struct file *file,
817 814
818static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset) 815static int acpi_video_device_EDID_seq_show(struct seq_file *seq, void *offset)
819{ 816{
820 struct acpi_video_device *dev = 817 struct acpi_video_device *dev = seq->private;
821 (struct acpi_video_device *)seq->private;
822 int status; 818 int status;
823 int i; 819 int i;
824 union acpi_object *edid = NULL; 820 union acpi_object *edid = NULL;
@@ -866,7 +862,7 @@ static int acpi_video_device_add_fs(struct acpi_device *device)
866 if (!device) 862 if (!device)
867 return -ENODEV; 863 return -ENODEV;
868 864
869 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 865 vid_dev = acpi_driver_data(device);
870 if (!vid_dev) 866 if (!vid_dev)
871 return -ENODEV; 867 return -ENODEV;
872 868
@@ -931,7 +927,7 @@ static int acpi_video_device_remove_fs(struct acpi_device *device)
931{ 927{
932 struct acpi_video_device *vid_dev; 928 struct acpi_video_device *vid_dev;
933 929
934 vid_dev = (struct acpi_video_device *)acpi_driver_data(device); 930 vid_dev = acpi_driver_data(device);
935 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir) 931 if (!vid_dev || !vid_dev->video || !vid_dev->video->dir)
936 return -ENODEV; 932 return -ENODEV;
937 933
@@ -950,7 +946,7 @@ static int acpi_video_device_remove_fs(struct acpi_device *device)
950/* video bus */ 946/* video bus */
951static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset) 947static int acpi_video_bus_info_seq_show(struct seq_file *seq, void *offset)
952{ 948{
953 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 949 struct acpi_video_bus *video = seq->private;
954 950
955 951
956 if (!video) 952 if (!video)
@@ -975,7 +971,7 @@ static int acpi_video_bus_info_open_fs(struct inode *inode, struct file *file)
975 971
976static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset) 972static int acpi_video_bus_ROM_seq_show(struct seq_file *seq, void *offset)
977{ 973{
978 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 974 struct acpi_video_bus *video = seq->private;
979 975
980 976
981 if (!video) 977 if (!video)
@@ -995,7 +991,7 @@ static int acpi_video_bus_ROM_open_fs(struct inode *inode, struct file *file)
995 991
996static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset) 992static int acpi_video_bus_POST_info_seq_show(struct seq_file *seq, void *offset)
997{ 993{
998 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 994 struct acpi_video_bus *video = seq->private;
999 unsigned long options; 995 unsigned long options;
1000 int status; 996 int status;
1001 997
@@ -1033,7 +1029,7 @@ acpi_video_bus_POST_info_open_fs(struct inode *inode, struct file *file)
1033 1029
1034static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset) 1030static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1035{ 1031{
1036 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1032 struct acpi_video_bus *video = seq->private;
1037 int status; 1033 int status;
1038 unsigned long id; 1034 unsigned long id;
1039 1035
@@ -1054,7 +1050,7 @@ static int acpi_video_bus_POST_seq_show(struct seq_file *seq, void *offset)
1054 1050
1055static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset) 1051static int acpi_video_bus_DOS_seq_show(struct seq_file *seq, void *offset)
1056{ 1052{
1057 struct acpi_video_bus *video = (struct acpi_video_bus *)seq->private; 1053 struct acpi_video_bus *video = seq->private;
1058 1054
1059 1055
1060 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting); 1056 seq_printf(seq, "DOS setting: <%d>\n", video->dos_setting);
@@ -1079,8 +1075,8 @@ acpi_video_bus_write_POST(struct file *file,
1079 size_t count, loff_t * data) 1075 size_t count, loff_t * data)
1080{ 1076{
1081 int status; 1077 int status;
1082 struct seq_file *m = (struct seq_file *)file->private_data; 1078 struct seq_file *m = file->private_data;
1083 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; 1079 struct acpi_video_bus *video = m->private;
1084 char str[12] = { 0 }; 1080 char str[12] = { 0 };
1085 unsigned long opt, options; 1081 unsigned long opt, options;
1086 1082
@@ -1119,8 +1115,8 @@ acpi_video_bus_write_DOS(struct file *file,
1119 size_t count, loff_t * data) 1115 size_t count, loff_t * data)
1120{ 1116{
1121 int status; 1117 int status;
1122 struct seq_file *m = (struct seq_file *)file->private_data; 1118 struct seq_file *m = file->private_data;
1123 struct acpi_video_bus *video = (struct acpi_video_bus *)m->private; 1119 struct acpi_video_bus *video = m->private;
1124 char str[12] = { 0 }; 1120 char str[12] = { 0 };
1125 unsigned long opt; 1121 unsigned long opt;
1126 1122
@@ -1150,7 +1146,7 @@ static int acpi_video_bus_add_fs(struct acpi_device *device)
1150 struct acpi_video_bus *video; 1146 struct acpi_video_bus *video;
1151 1147
1152 1148
1153 video = (struct acpi_video_bus *)acpi_driver_data(device); 1149 video = acpi_driver_data(device);
1154 1150
1155 if (!acpi_device_dir(device)) { 1151 if (!acpi_device_dir(device)) {
1156 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 1152 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
@@ -1226,7 +1222,7 @@ static int acpi_video_bus_remove_fs(struct acpi_device *device)
1226 struct acpi_video_bus *video; 1222 struct acpi_video_bus *video;
1227 1223
1228 1224
1229 video = (struct acpi_video_bus *)acpi_driver_data(device); 1225 video = acpi_driver_data(device);
1230 1226
1231 if (acpi_device_dir(device)) { 1227 if (acpi_device_dir(device)) {
1232 remove_proc_entry("info", acpi_device_dir(device)); 1228 remove_proc_entry("info", acpi_device_dir(device));
@@ -1263,12 +1259,10 @@ acpi_video_bus_get_one_device(struct acpi_device *device,
1263 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id); 1259 acpi_evaluate_integer(device->handle, "_ADR", NULL, &device_id);
1264 if (ACPI_SUCCESS(status)) { 1260 if (ACPI_SUCCESS(status)) {
1265 1261
1266 data = kmalloc(sizeof(struct acpi_video_device), GFP_KERNEL); 1262 data = kzalloc(sizeof(struct acpi_video_device), GFP_KERNEL);
1267 if (!data) 1263 if (!data)
1268 return -ENOMEM; 1264 return -ENOMEM;
1269 1265
1270 memset(data, 0, sizeof(struct acpi_video_device));
1271
1272 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME); 1266 strcpy(acpi_device_name(device), ACPI_VIDEO_DEVICE_NAME);
1273 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS); 1267 strcpy(acpi_device_class(device), ACPI_VIDEO_CLASS);
1274 acpi_driver_data(device) = data; 1268 acpi_driver_data(device) = data;
@@ -1403,7 +1397,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1403 return status; 1397 return status;
1404 } 1398 }
1405 1399
1406 dod = (union acpi_object *)buffer.pointer; 1400 dod = buffer.pointer;
1407 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) { 1401 if (!dod || (dod->type != ACPI_TYPE_PACKAGE)) {
1408 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data")); 1402 ACPI_EXCEPTION((AE_INFO, status, "Invalid _DOD data"));
1409 status = -EFAULT; 1403 status = -EFAULT;
@@ -1426,7 +1420,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
1426 1420
1427 count = 0; 1421 count = 0;
1428 for (i = 0; i < dod->package.count; i++) { 1422 for (i = 0; i < dod->package.count; i++) {
1429 obj = (union acpi_object *)&dod->package.elements[i]; 1423 obj = &dod->package.elements[i];
1430 1424
1431 if (obj->type != ACPI_TYPE_INTEGER) { 1425 if (obj->type != ACPI_TYPE_INTEGER) {
1432 printk(KERN_ERR PREFIX "Invalid _DOD data\n"); 1426 printk(KERN_ERR PREFIX "Invalid _DOD data\n");
@@ -1509,8 +1503,34 @@ static int
1509acpi_video_get_next_level(struct acpi_video_device *device, 1503acpi_video_get_next_level(struct acpi_video_device *device,
1510 u32 level_current, u32 event) 1504 u32 level_current, u32 event)
1511{ 1505{
1512 /*Fix me */ 1506 int min, max, min_above, max_below, i, l;
1513 return level_current; 1507 max = max_below = 0;
1508 min = min_above = 255;
1509 for (i = 0; i < device->brightness->count; i++) {
1510 l = device->brightness->levels[i];
1511 if (l < min)
1512 min = l;
1513 if (l > max)
1514 max = l;
1515 if (l < min_above && l > level_current)
1516 min_above = l;
1517 if (l > max_below && l < level_current)
1518 max_below = l;
1519 }
1520
1521 switch (event) {
1522 case ACPI_VIDEO_NOTIFY_CYCLE_BRIGHTNESS:
1523 return (level_current < max) ? min_above : min;
1524 case ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS:
1525 return (level_current < max) ? min_above : max;
1526 case ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS:
1527 return (level_current > min) ? max_below : min;
1528 case ACPI_VIDEO_NOTIFY_ZERO_BRIGHTNESS:
1529 case ACPI_VIDEO_NOTIFY_DISPLAY_OFF:
1530 return 0;
1531 default:
1532 return level_current;
1533 }
1514} 1534}
1515 1535
1516static void 1536static void
@@ -1612,7 +1632,7 @@ static int acpi_video_bus_stop_devices(struct acpi_video_bus *video)
1612 1632
1613static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data) 1633static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1614{ 1634{
1615 struct acpi_video_bus *video = (struct acpi_video_bus *)data; 1635 struct acpi_video_bus *video = data;
1616 struct acpi_device *device = NULL; 1636 struct acpi_device *device = NULL;
1617 1637
1618 printk("video bus notify\n"); 1638 printk("video bus notify\n");
@@ -1654,8 +1674,7 @@ static void acpi_video_bus_notify(acpi_handle handle, u32 event, void *data)
1654 1674
1655static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data) 1675static void acpi_video_device_notify(acpi_handle handle, u32 event, void *data)
1656{ 1676{
1657 struct acpi_video_device *video_device = 1677 struct acpi_video_device *video_device = data;
1658 (struct acpi_video_device *)data;
1659 struct acpi_device *device = NULL; 1678 struct acpi_device *device = NULL;
1660 1679
1661 1680
@@ -1696,10 +1715,9 @@ static int acpi_video_bus_add(struct acpi_device *device)
1696 if (!device) 1715 if (!device)
1697 return -EINVAL; 1716 return -EINVAL;
1698 1717
1699 video = kmalloc(sizeof(struct acpi_video_bus), GFP_KERNEL); 1718 video = kzalloc(sizeof(struct acpi_video_bus), GFP_KERNEL);
1700 if (!video) 1719 if (!video)
1701 return -ENOMEM; 1720 return -ENOMEM;
1702 memset(video, 0, sizeof(struct acpi_video_bus));
1703 1721
1704 video->device = device; 1722 video->device = device;
1705 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME); 1723 strcpy(acpi_device_name(device), ACPI_VIDEO_BUS_NAME);
@@ -1757,7 +1775,7 @@ static int acpi_video_bus_remove(struct acpi_device *device, int type)
1757 if (!device || !acpi_driver_data(device)) 1775 if (!device || !acpi_driver_data(device))
1758 return -EINVAL; 1776 return -EINVAL;
1759 1777
1760 video = (struct acpi_video_bus *)acpi_driver_data(device); 1778 video = acpi_driver_data(device);
1761 1779
1762 acpi_video_bus_stop_devices(video); 1780 acpi_video_bus_stop_devices(video);
1763 1781
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 984ab284382a..b34e0a958d0f 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -40,9 +40,9 @@ config ATA_PIIX
40 tristate "Intel PIIX/ICH SATA support" 40 tristate "Intel PIIX/ICH SATA support"
41 depends on PCI 41 depends on PCI
42 help 42 help
43 This option enables support for ICH5/6/7/8 Serial ATA. 43 This option enables support for ICH5/6/7/8 Serial ATA
44 If PATA support was enabled previously, this enables 44 and support for PATA on the Intel PIIX3/PIIX4/ICH series
45 support for select Intel PIIX/ICH PATA host controllers. 45 PATA host controllers.
46 46
47 If unsure, say N. 47 If unsure, say N.
48 48
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index f36da488a2c1..b517d2493551 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -402,6 +402,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
402 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci }, /* MCP65 */ 402 { PCI_VDEVICE(NVIDIA, 0x044d), board_ahci }, /* MCP65 */
403 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci }, /* MCP65 */ 403 { PCI_VDEVICE(NVIDIA, 0x044e), board_ahci }, /* MCP65 */
404 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci }, /* MCP65 */ 404 { PCI_VDEVICE(NVIDIA, 0x044f), board_ahci }, /* MCP65 */
405 { PCI_VDEVICE(NVIDIA, 0x045c), board_ahci }, /* MCP65 */
406 { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci }, /* MCP65 */
407 { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci }, /* MCP65 */
408 { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci }, /* MCP65 */
409 { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci }, /* MCP67 */
410 { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci }, /* MCP67 */
411 { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci }, /* MCP67 */
412 { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci }, /* MCP67 */
405 { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci }, /* MCP67 */ 413 { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci }, /* MCP67 */
406 { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci }, /* MCP67 */ 414 { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci }, /* MCP67 */
407 { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci }, /* MCP67 */ 415 { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci }, /* MCP67 */
@@ -645,8 +653,6 @@ static int ahci_reset_controller(void __iomem *mmio, struct pci_dev *pdev)
645 u32 cap_save, impl_save, tmp; 653 u32 cap_save, impl_save, tmp;
646 654
647 cap_save = readl(mmio + HOST_CAP); 655 cap_save = readl(mmio + HOST_CAP);
648 cap_save &= ( (1<<28) | (1<<17) );
649 cap_save |= (1 << 27);
650 impl_save = readl(mmio + HOST_PORTS_IMPL); 656 impl_save = readl(mmio + HOST_PORTS_IMPL);
651 657
652 /* global controller reset */ 658 /* global controller reset */
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index c7de0bb1591f..47701b286f8b 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -226,14 +226,26 @@ static const struct pci_device_id piix_pci_tbl[] = {
226 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 226 { 0x8086, 0x27c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
227 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */ 227 /* 2801GBM/GHM (ICH7M, identical to ICH6M) */
228 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci }, 228 { 0x8086, 0x27c4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6m_sata_ahci },
229 /* Enterprise Southbridge 2 (where's the datasheet?) */ 229 /* Enterprise Southbridge 2 (631xESB/632xESB) */
230 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci }, 230 { 0x8086, 0x2680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich6_sata_ahci },
231 /* SATA Controller 1 IDE (ICH8, no datasheet yet) */ 231 /* SATA Controller 1 IDE (ICH8) */
232 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 232 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
233 /* SATA Controller 2 IDE (ICH8, ditto) */ 233 /* SATA Controller 2 IDE (ICH8) */
234 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 234 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
235 /* Mobile SATA Controller IDE (ICH8M, ditto) */ 235 /* Mobile SATA Controller IDE (ICH8M) */
236 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 236 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
237 /* SATA Controller IDE (ICH9) */
238 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
239 /* SATA Controller IDE (ICH9) */
240 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
241 /* SATA Controller IDE (ICH9) */
242 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
243 /* SATA Controller IDE (ICH9M) */
244 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
245 /* SATA Controller IDE (ICH9M) */
246 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
247 /* SATA Controller IDE (ICH9M) */
248 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
237 249
238 { } /* terminate list */ 250 { } /* terminate list */
239}; 251};
@@ -330,7 +342,7 @@ static const struct ata_port_operations ich_pata_ops = {
330 342
331 .port_start = ata_port_start, 343 .port_start = ata_port_start,
332 .port_stop = ata_port_stop, 344 .port_stop = ata_port_stop,
333 .host_stop = ata_host_stop, 345 .host_stop = piix_host_stop,
334}; 346};
335 347
336static const struct ata_port_operations piix_sata_ops = { 348static const struct ata_port_operations piix_sata_ops = {
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 011c0a8a2dcc..0d51d13b16bf 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -1332,7 +1332,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1332} 1332}
1333 1333
1334/** 1334/**
1335 * ata_exec_internal_sg - execute libata internal command 1335 * ata_exec_internal - execute libata internal command
1336 * @dev: Device to which the command is sent 1336 * @dev: Device to which the command is sent
1337 * @tf: Taskfile registers for the command and the result 1337 * @tf: Taskfile registers for the command and the result
1338 * @cdb: CDB for packet command 1338 * @cdb: CDB for packet command
@@ -1353,11 +1353,17 @@ unsigned ata_exec_internal(struct ata_device *dev,
1353 struct ata_taskfile *tf, const u8 *cdb, 1353 struct ata_taskfile *tf, const u8 *cdb,
1354 int dma_dir, void *buf, unsigned int buflen) 1354 int dma_dir, void *buf, unsigned int buflen)
1355{ 1355{
1356 struct scatterlist sg; 1356 struct scatterlist *psg = NULL, sg;
1357 unsigned int n_elem = 0;
1357 1358
1358 sg_init_one(&sg, buf, buflen); 1359 if (dma_dir != DMA_NONE) {
1360 WARN_ON(!buf);
1361 sg_init_one(&sg, buf, buflen);
1362 psg = &sg;
1363 n_elem++;
1364 }
1359 1365
1360 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, &sg, 1); 1366 return ata_exec_internal_sg(dev, tf, cdb, dma_dir, psg, n_elem);
1361} 1367}
1362 1368
1363/** 1369/**
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 664e1377b54c..836947da5b14 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -51,7 +51,7 @@
51 51
52#define SECTOR_SIZE 512 52#define SECTOR_SIZE 512
53 53
54typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc, const u8 *scsicmd); 54typedef unsigned int (*ata_xlat_func_t)(struct ata_queued_cmd *qc);
55 55
56static struct ata_device * __ata_scsi_find_dev(struct ata_port *ap, 56static struct ata_device * __ata_scsi_find_dev(struct ata_port *ap,
57 const struct scsi_device *scsidev); 57 const struct scsi_device *scsidev);
@@ -935,7 +935,6 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
935/** 935/**
936 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 936 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
937 * @qc: Storage for translated ATA taskfile 937 * @qc: Storage for translated ATA taskfile
938 * @scsicmd: SCSI command to translate
939 * 938 *
940 * Sets up an ATA taskfile to issue STANDBY (to stop) or READ VERIFY 939 * Sets up an ATA taskfile to issue STANDBY (to stop) or READ VERIFY
941 * (to start). Perhaps these commands should be preceded by 940 * (to start). Perhaps these commands should be preceded by
@@ -948,22 +947,25 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
948 * RETURNS: 947 * RETURNS:
949 * Zero on success, non-zero on error. 948 * Zero on success, non-zero on error.
950 */ 949 */
951 950static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
952static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
953 const u8 *scsicmd)
954{ 951{
952 struct scsi_cmnd *scmd = qc->scsicmd;
955 struct ata_taskfile *tf = &qc->tf; 953 struct ata_taskfile *tf = &qc->tf;
954 const u8 *cdb = scmd->cmnd;
955
956 if (scmd->cmd_len < 5)
957 goto invalid_fld;
956 958
957 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR; 959 tf->flags |= ATA_TFLAG_DEVICE | ATA_TFLAG_ISADDR;
958 tf->protocol = ATA_PROT_NODATA; 960 tf->protocol = ATA_PROT_NODATA;
959 if (scsicmd[1] & 0x1) { 961 if (cdb[1] & 0x1) {
960 ; /* ignore IMMED bit, violates sat-r05 */ 962 ; /* ignore IMMED bit, violates sat-r05 */
961 } 963 }
962 if (scsicmd[4] & 0x2) 964 if (cdb[4] & 0x2)
963 goto invalid_fld; /* LOEJ bit set not supported */ 965 goto invalid_fld; /* LOEJ bit set not supported */
964 if (((scsicmd[4] >> 4) & 0xf) != 0) 966 if (((cdb[4] >> 4) & 0xf) != 0)
965 goto invalid_fld; /* power conditions not supported */ 967 goto invalid_fld; /* power conditions not supported */
966 if (scsicmd[4] & 0x1) { 968 if (cdb[4] & 0x1) {
967 tf->nsect = 1; /* 1 sector, lba=0 */ 969 tf->nsect = 1; /* 1 sector, lba=0 */
968 970
969 if (qc->dev->flags & ATA_DFLAG_LBA) { 971 if (qc->dev->flags & ATA_DFLAG_LBA) {
@@ -996,7 +998,7 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc,
996 return 0; 998 return 0;
997 999
998invalid_fld: 1000invalid_fld:
999 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1001 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1000 /* "Invalid field in cbd" */ 1002 /* "Invalid field in cbd" */
1001 return 1; 1003 return 1;
1002} 1004}
@@ -1005,7 +1007,6 @@ invalid_fld:
1005/** 1007/**
1006 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command 1008 * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command
1007 * @qc: Storage for translated ATA taskfile 1009 * @qc: Storage for translated ATA taskfile
1008 * @scsicmd: SCSI command to translate (ignored)
1009 * 1010 *
1010 * Sets up an ATA taskfile to issue FLUSH CACHE or 1011 * Sets up an ATA taskfile to issue FLUSH CACHE or
1011 * FLUSH CACHE EXT. 1012 * FLUSH CACHE EXT.
@@ -1016,8 +1017,7 @@ invalid_fld:
1016 * RETURNS: 1017 * RETURNS:
1017 * Zero on success, non-zero on error. 1018 * Zero on success, non-zero on error.
1018 */ 1019 */
1019 1020static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc)
1020static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1021{ 1021{
1022 struct ata_taskfile *tf = &qc->tf; 1022 struct ata_taskfile *tf = &qc->tf;
1023 1023
@@ -1034,7 +1034,7 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scs
1034 1034
1035/** 1035/**
1036 * scsi_6_lba_len - Get LBA and transfer length 1036 * scsi_6_lba_len - Get LBA and transfer length
1037 * @scsicmd: SCSI command to translate 1037 * @cdb: SCSI command to translate
1038 * 1038 *
1039 * Calculate LBA and transfer length for 6-byte commands. 1039 * Calculate LBA and transfer length for 6-byte commands.
1040 * 1040 *
@@ -1042,18 +1042,17 @@ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc, const u8 *scs
1042 * @plba: the LBA 1042 * @plba: the LBA
1043 * @plen: the transfer length 1043 * @plen: the transfer length
1044 */ 1044 */
1045 1045static void scsi_6_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1046static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1047{ 1046{
1048 u64 lba = 0; 1047 u64 lba = 0;
1049 u32 len = 0; 1048 u32 len = 0;
1050 1049
1051 VPRINTK("six-byte command\n"); 1050 VPRINTK("six-byte command\n");
1052 1051
1053 lba |= ((u64)scsicmd[2]) << 8; 1052 lba |= ((u64)cdb[2]) << 8;
1054 lba |= ((u64)scsicmd[3]); 1053 lba |= ((u64)cdb[3]);
1055 1054
1056 len |= ((u32)scsicmd[4]); 1055 len |= ((u32)cdb[4]);
1057 1056
1058 *plba = lba; 1057 *plba = lba;
1059 *plen = len; 1058 *plen = len;
@@ -1061,7 +1060,7 @@ static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1061 1060
1062/** 1061/**
1063 * scsi_10_lba_len - Get LBA and transfer length 1062 * scsi_10_lba_len - Get LBA and transfer length
1064 * @scsicmd: SCSI command to translate 1063 * @cdb: SCSI command to translate
1065 * 1064 *
1066 * Calculate LBA and transfer length for 10-byte commands. 1065 * Calculate LBA and transfer length for 10-byte commands.
1067 * 1066 *
@@ -1069,21 +1068,20 @@ static void scsi_6_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1069 * @plba: the LBA 1068 * @plba: the LBA
1070 * @plen: the transfer length 1069 * @plen: the transfer length
1071 */ 1070 */
1072 1071static void scsi_10_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1073static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1074{ 1072{
1075 u64 lba = 0; 1073 u64 lba = 0;
1076 u32 len = 0; 1074 u32 len = 0;
1077 1075
1078 VPRINTK("ten-byte command\n"); 1076 VPRINTK("ten-byte command\n");
1079 1077
1080 lba |= ((u64)scsicmd[2]) << 24; 1078 lba |= ((u64)cdb[2]) << 24;
1081 lba |= ((u64)scsicmd[3]) << 16; 1079 lba |= ((u64)cdb[3]) << 16;
1082 lba |= ((u64)scsicmd[4]) << 8; 1080 lba |= ((u64)cdb[4]) << 8;
1083 lba |= ((u64)scsicmd[5]); 1081 lba |= ((u64)cdb[5]);
1084 1082
1085 len |= ((u32)scsicmd[7]) << 8; 1083 len |= ((u32)cdb[7]) << 8;
1086 len |= ((u32)scsicmd[8]); 1084 len |= ((u32)cdb[8]);
1087 1085
1088 *plba = lba; 1086 *plba = lba;
1089 *plen = len; 1087 *plen = len;
@@ -1091,7 +1089,7 @@ static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1091 1089
1092/** 1090/**
1093 * scsi_16_lba_len - Get LBA and transfer length 1091 * scsi_16_lba_len - Get LBA and transfer length
1094 * @scsicmd: SCSI command to translate 1092 * @cdb: SCSI command to translate
1095 * 1093 *
1096 * Calculate LBA and transfer length for 16-byte commands. 1094 * Calculate LBA and transfer length for 16-byte commands.
1097 * 1095 *
@@ -1099,27 +1097,26 @@ static void scsi_10_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1099 * @plba: the LBA 1097 * @plba: the LBA
1100 * @plen: the transfer length 1098 * @plen: the transfer length
1101 */ 1099 */
1102 1100static void scsi_16_lba_len(const u8 *cdb, u64 *plba, u32 *plen)
1103static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1104{ 1101{
1105 u64 lba = 0; 1102 u64 lba = 0;
1106 u32 len = 0; 1103 u32 len = 0;
1107 1104
1108 VPRINTK("sixteen-byte command\n"); 1105 VPRINTK("sixteen-byte command\n");
1109 1106
1110 lba |= ((u64)scsicmd[2]) << 56; 1107 lba |= ((u64)cdb[2]) << 56;
1111 lba |= ((u64)scsicmd[3]) << 48; 1108 lba |= ((u64)cdb[3]) << 48;
1112 lba |= ((u64)scsicmd[4]) << 40; 1109 lba |= ((u64)cdb[4]) << 40;
1113 lba |= ((u64)scsicmd[5]) << 32; 1110 lba |= ((u64)cdb[5]) << 32;
1114 lba |= ((u64)scsicmd[6]) << 24; 1111 lba |= ((u64)cdb[6]) << 24;
1115 lba |= ((u64)scsicmd[7]) << 16; 1112 lba |= ((u64)cdb[7]) << 16;
1116 lba |= ((u64)scsicmd[8]) << 8; 1113 lba |= ((u64)cdb[8]) << 8;
1117 lba |= ((u64)scsicmd[9]); 1114 lba |= ((u64)cdb[9]);
1118 1115
1119 len |= ((u32)scsicmd[10]) << 24; 1116 len |= ((u32)cdb[10]) << 24;
1120 len |= ((u32)scsicmd[11]) << 16; 1117 len |= ((u32)cdb[11]) << 16;
1121 len |= ((u32)scsicmd[12]) << 8; 1118 len |= ((u32)cdb[12]) << 8;
1122 len |= ((u32)scsicmd[13]); 1119 len |= ((u32)cdb[13]);
1123 1120
1124 *plba = lba; 1121 *plba = lba;
1125 *plen = len; 1122 *plen = len;
@@ -1128,7 +1125,6 @@ static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1128/** 1125/**
1129 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one 1126 * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one
1130 * @qc: Storage for translated ATA taskfile 1127 * @qc: Storage for translated ATA taskfile
1131 * @scsicmd: SCSI command to translate
1132 * 1128 *
1133 * Converts SCSI VERIFY command to an ATA READ VERIFY command. 1129 * Converts SCSI VERIFY command to an ATA READ VERIFY command.
1134 * 1130 *
@@ -1138,23 +1134,28 @@ static void scsi_16_lba_len(const u8 *scsicmd, u64 *plba, u32 *plen)
1138 * RETURNS: 1134 * RETURNS:
1139 * Zero on success, non-zero on error. 1135 * Zero on success, non-zero on error.
1140 */ 1136 */
1141 1137static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc)
1142static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1143{ 1138{
1139 struct scsi_cmnd *scmd = qc->scsicmd;
1144 struct ata_taskfile *tf = &qc->tf; 1140 struct ata_taskfile *tf = &qc->tf;
1145 struct ata_device *dev = qc->dev; 1141 struct ata_device *dev = qc->dev;
1146 u64 dev_sectors = qc->dev->n_sectors; 1142 u64 dev_sectors = qc->dev->n_sectors;
1143 const u8 *cdb = scmd->cmnd;
1147 u64 block; 1144 u64 block;
1148 u32 n_block; 1145 u32 n_block;
1149 1146
1150 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 1147 tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1151 tf->protocol = ATA_PROT_NODATA; 1148 tf->protocol = ATA_PROT_NODATA;
1152 1149
1153 if (scsicmd[0] == VERIFY) 1150 if (cdb[0] == VERIFY) {
1154 scsi_10_lba_len(scsicmd, &block, &n_block); 1151 if (scmd->cmd_len < 10)
1155 else if (scsicmd[0] == VERIFY_16) 1152 goto invalid_fld;
1156 scsi_16_lba_len(scsicmd, &block, &n_block); 1153 scsi_10_lba_len(cdb, &block, &n_block);
1157 else 1154 } else if (cdb[0] == VERIFY_16) {
1155 if (scmd->cmd_len < 16)
1156 goto invalid_fld;
1157 scsi_16_lba_len(cdb, &block, &n_block);
1158 } else
1158 goto invalid_fld; 1159 goto invalid_fld;
1159 1160
1160 if (!n_block) 1161 if (!n_block)
@@ -1229,24 +1230,23 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc
1229 return 0; 1230 return 0;
1230 1231
1231invalid_fld: 1232invalid_fld:
1232 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1233 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1233 /* "Invalid field in cbd" */ 1234 /* "Invalid field in cbd" */
1234 return 1; 1235 return 1;
1235 1236
1236out_of_range: 1237out_of_range:
1237 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); 1238 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x21, 0x0);
1238 /* "Logical Block Address out of range" */ 1239 /* "Logical Block Address out of range" */
1239 return 1; 1240 return 1;
1240 1241
1241nothing_to_do: 1242nothing_to_do:
1242 qc->scsicmd->result = SAM_STAT_GOOD; 1243 scmd->result = SAM_STAT_GOOD;
1243 return 1; 1244 return 1;
1244} 1245}
1245 1246
1246/** 1247/**
1247 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one 1248 * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one
1248 * @qc: Storage for translated ATA taskfile 1249 * @qc: Storage for translated ATA taskfile
1249 * @scsicmd: SCSI command to translate
1250 * 1250 *
1251 * Converts any of six SCSI read/write commands into the 1251 * Converts any of six SCSI read/write commands into the
1252 * ATA counterpart, including starting sector (LBA), 1252 * ATA counterpart, including starting sector (LBA),
@@ -1262,29 +1262,33 @@ nothing_to_do:
1262 * RETURNS: 1262 * RETURNS:
1263 * Zero on success, non-zero on error. 1263 * Zero on success, non-zero on error.
1264 */ 1264 */
1265 1265static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
1266static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
1267{ 1266{
1267 struct scsi_cmnd *scmd = qc->scsicmd;
1268 const u8 *cdb = scmd->cmnd;
1268 unsigned int tf_flags = 0; 1269 unsigned int tf_flags = 0;
1269 u64 block; 1270 u64 block;
1270 u32 n_block; 1271 u32 n_block;
1271 int rc; 1272 int rc;
1272 1273
1273 if (scsicmd[0] == WRITE_10 || scsicmd[0] == WRITE_6 || 1274 if (cdb[0] == WRITE_10 || cdb[0] == WRITE_6 || cdb[0] == WRITE_16)
1274 scsicmd[0] == WRITE_16)
1275 tf_flags |= ATA_TFLAG_WRITE; 1275 tf_flags |= ATA_TFLAG_WRITE;
1276 1276
1277 /* Calculate the SCSI LBA, transfer length and FUA. */ 1277 /* Calculate the SCSI LBA, transfer length and FUA. */
1278 switch (scsicmd[0]) { 1278 switch (cdb[0]) {
1279 case READ_10: 1279 case READ_10:
1280 case WRITE_10: 1280 case WRITE_10:
1281 scsi_10_lba_len(scsicmd, &block, &n_block); 1281 if (unlikely(scmd->cmd_len < 10))
1282 if (unlikely(scsicmd[1] & (1 << 3))) 1282 goto invalid_fld;
1283 scsi_10_lba_len(cdb, &block, &n_block);
1284 if (unlikely(cdb[1] & (1 << 3)))
1283 tf_flags |= ATA_TFLAG_FUA; 1285 tf_flags |= ATA_TFLAG_FUA;
1284 break; 1286 break;
1285 case READ_6: 1287 case READ_6:
1286 case WRITE_6: 1288 case WRITE_6:
1287 scsi_6_lba_len(scsicmd, &block, &n_block); 1289 if (unlikely(scmd->cmd_len < 6))
1290 goto invalid_fld;
1291 scsi_6_lba_len(cdb, &block, &n_block);
1288 1292
1289 /* for 6-byte r/w commands, transfer length 0 1293 /* for 6-byte r/w commands, transfer length 0
1290 * means 256 blocks of data, not 0 block. 1294 * means 256 blocks of data, not 0 block.
@@ -1294,8 +1298,10 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1294 break; 1298 break;
1295 case READ_16: 1299 case READ_16:
1296 case WRITE_16: 1300 case WRITE_16:
1297 scsi_16_lba_len(scsicmd, &block, &n_block); 1301 if (unlikely(scmd->cmd_len < 16))
1298 if (unlikely(scsicmd[1] & (1 << 3))) 1302 goto invalid_fld;
1303 scsi_16_lba_len(cdb, &block, &n_block);
1304 if (unlikely(cdb[1] & (1 << 3)))
1299 tf_flags |= ATA_TFLAG_FUA; 1305 tf_flags |= ATA_TFLAG_FUA;
1300 break; 1306 break;
1301 default: 1307 default:
@@ -1326,17 +1332,17 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm
1326 goto out_of_range; 1332 goto out_of_range;
1327 /* treat all other errors as -EINVAL, fall through */ 1333 /* treat all other errors as -EINVAL, fall through */
1328invalid_fld: 1334invalid_fld:
1329 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x0); 1335 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x0);
1330 /* "Invalid field in cbd" */ 1336 /* "Invalid field in cbd" */
1331 return 1; 1337 return 1;
1332 1338
1333out_of_range: 1339out_of_range:
1334 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x21, 0x0); 1340 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x21, 0x0);
1335 /* "Logical Block Address out of range" */ 1341 /* "Logical Block Address out of range" */
1336 return 1; 1342 return 1;
1337 1343
1338nothing_to_do: 1344nothing_to_do:
1339 qc->scsicmd->result = SAM_STAT_GOOD; 1345 scmd->result = SAM_STAT_GOOD;
1340 return 1; 1346 return 1;
1341} 1347}
1342 1348
@@ -1456,7 +1462,6 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1456 ata_xlat_func_t xlat_func) 1462 ata_xlat_func_t xlat_func)
1457{ 1463{
1458 struct ata_queued_cmd *qc; 1464 struct ata_queued_cmd *qc;
1459 u8 *scsicmd = cmd->cmnd;
1460 int is_io = xlat_func == ata_scsi_rw_xlat; 1465 int is_io = xlat_func == ata_scsi_rw_xlat;
1461 1466
1462 VPRINTK("ENTER\n"); 1467 VPRINTK("ENTER\n");
@@ -1488,7 +1493,7 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1488 1493
1489 qc->complete_fn = ata_scsi_qc_complete; 1494 qc->complete_fn = ata_scsi_qc_complete;
1490 1495
1491 if (xlat_func(qc, scsicmd)) 1496 if (xlat_func(qc))
1492 goto early_finish; 1497 goto early_finish;
1493 1498
1494 /* select device, send command to hardware */ 1499 /* select device, send command to hardware */
@@ -1539,7 +1544,7 @@ static unsigned int ata_scsi_rbuf_get(struct scsi_cmnd *cmd, u8 **buf_out)
1539 struct scatterlist *sg; 1544 struct scatterlist *sg;
1540 1545
1541 sg = (struct scatterlist *) cmd->request_buffer; 1546 sg = (struct scatterlist *) cmd->request_buffer;
1542 buf = kmap_atomic(sg->page, KM_USER0) + sg->offset; 1547 buf = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1543 buflen = sg->length; 1548 buflen = sg->length;
1544 } else { 1549 } else {
1545 buf = cmd->request_buffer; 1550 buf = cmd->request_buffer;
@@ -1567,7 +1572,7 @@ static inline void ata_scsi_rbuf_put(struct scsi_cmnd *cmd, u8 *buf)
1567 struct scatterlist *sg; 1572 struct scatterlist *sg;
1568 1573
1569 sg = (struct scatterlist *) cmd->request_buffer; 1574 sg = (struct scatterlist *) cmd->request_buffer;
1570 kunmap_atomic(buf - sg->offset, KM_USER0); 1575 kunmap_atomic(buf - sg->offset, KM_IRQ0);
1571 } 1576 }
1572} 1577}
1573 1578
@@ -2344,7 +2349,6 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2344/** 2349/**
2345 * atapi_xlat - Initialize PACKET taskfile 2350 * atapi_xlat - Initialize PACKET taskfile
2346 * @qc: command structure to be initialized 2351 * @qc: command structure to be initialized
2347 * @scsicmd: SCSI CDB associated with this PACKET command
2348 * 2352 *
2349 * LOCKING: 2353 * LOCKING:
2350 * spin_lock_irqsave(host lock) 2354 * spin_lock_irqsave(host lock)
@@ -2352,25 +2356,25 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
2352 * RETURNS: 2356 * RETURNS:
2353 * Zero on success, non-zero on failure. 2357 * Zero on success, non-zero on failure.
2354 */ 2358 */
2355 2359static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
2356static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2357{ 2360{
2358 struct scsi_cmnd *cmd = qc->scsicmd; 2361 struct scsi_cmnd *scmd = qc->scsicmd;
2359 struct ata_device *dev = qc->dev; 2362 struct ata_device *dev = qc->dev;
2360 int using_pio = (dev->flags & ATA_DFLAG_PIO); 2363 int using_pio = (dev->flags & ATA_DFLAG_PIO);
2361 int nodata = (cmd->sc_data_direction == DMA_NONE); 2364 int nodata = (scmd->sc_data_direction == DMA_NONE);
2362 2365
2363 if (!using_pio) 2366 if (!using_pio)
2364 /* Check whether ATAPI DMA is safe */ 2367 /* Check whether ATAPI DMA is safe */
2365 if (ata_check_atapi_dma(qc)) 2368 if (ata_check_atapi_dma(qc))
2366 using_pio = 1; 2369 using_pio = 1;
2367 2370
2368 memcpy(&qc->cdb, scsicmd, dev->cdb_len); 2371 memset(qc->cdb, 0, dev->cdb_len);
2372 memcpy(qc->cdb, scmd->cmnd, scmd->cmd_len);
2369 2373
2370 qc->complete_fn = atapi_qc_complete; 2374 qc->complete_fn = atapi_qc_complete;
2371 2375
2372 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 2376 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
2373 if (cmd->sc_data_direction == DMA_TO_DEVICE) { 2377 if (scmd->sc_data_direction == DMA_TO_DEVICE) {
2374 qc->tf.flags |= ATA_TFLAG_WRITE; 2378 qc->tf.flags |= ATA_TFLAG_WRITE;
2375 DPRINTK("direction: write\n"); 2379 DPRINTK("direction: write\n");
2376 } 2380 }
@@ -2392,12 +2396,12 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc, const u8 *scsicmd)
2392 qc->tf.protocol = ATA_PROT_ATAPI_DMA; 2396 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
2393 qc->tf.feature |= ATAPI_PKT_DMA; 2397 qc->tf.feature |= ATAPI_PKT_DMA;
2394 2398
2395 if (atapi_dmadir && (cmd->sc_data_direction != DMA_TO_DEVICE)) 2399 if (atapi_dmadir && (scmd->sc_data_direction != DMA_TO_DEVICE))
2396 /* some SATA bridges need us to indicate data xfer direction */ 2400 /* some SATA bridges need us to indicate data xfer direction */
2397 qc->tf.feature |= ATAPI_DMADIR; 2401 qc->tf.feature |= ATAPI_DMADIR;
2398 } 2402 }
2399 2403
2400 qc->nbytes = cmd->request_bufflen; 2404 qc->nbytes = scmd->request_bufflen;
2401 2405
2402 return 0; 2406 return 0;
2403} 2407}
@@ -2517,28 +2521,27 @@ ata_scsi_map_proto(u8 byte1)
2517/** 2521/**
2518 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile 2522 * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile
2519 * @qc: command structure to be initialized 2523 * @qc: command structure to be initialized
2520 * @scsicmd: SCSI command to convert
2521 * 2524 *
2522 * Handles either 12 or 16-byte versions of the CDB. 2525 * Handles either 12 or 16-byte versions of the CDB.
2523 * 2526 *
2524 * RETURNS: 2527 * RETURNS:
2525 * Zero on success, non-zero on failure. 2528 * Zero on success, non-zero on failure.
2526 */ 2529 */
2527static unsigned int 2530static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2528ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2529{ 2531{
2530 struct ata_taskfile *tf = &(qc->tf); 2532 struct ata_taskfile *tf = &(qc->tf);
2531 struct scsi_cmnd *cmd = qc->scsicmd; 2533 struct scsi_cmnd *scmd = qc->scsicmd;
2532 struct ata_device *dev = qc->dev; 2534 struct ata_device *dev = qc->dev;
2535 const u8 *cdb = scmd->cmnd;
2533 2536
2534 if ((tf->protocol = ata_scsi_map_proto(scsicmd[1])) == ATA_PROT_UNKNOWN) 2537 if ((tf->protocol = ata_scsi_map_proto(cdb[1])) == ATA_PROT_UNKNOWN)
2535 goto invalid_fld; 2538 goto invalid_fld;
2536 2539
2537 /* We may not issue DMA commands if no DMA mode is set */ 2540 /* We may not issue DMA commands if no DMA mode is set */
2538 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0) 2541 if (tf->protocol == ATA_PROT_DMA && dev->dma_mode == 0)
2539 goto invalid_fld; 2542 goto invalid_fld;
2540 2543
2541 if (scsicmd[1] & 0xe0) 2544 if (cdb[1] & 0xe0)
2542 /* PIO multi not supported yet */ 2545 /* PIO multi not supported yet */
2543 goto invalid_fld; 2546 goto invalid_fld;
2544 2547
@@ -2546,18 +2549,18 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2546 * 12 and 16 byte CDBs use different offsets to 2549 * 12 and 16 byte CDBs use different offsets to
2547 * provide the various register values. 2550 * provide the various register values.
2548 */ 2551 */
2549 if (scsicmd[0] == ATA_16) { 2552 if (cdb[0] == ATA_16) {
2550 /* 2553 /*
2551 * 16-byte CDB - may contain extended commands. 2554 * 16-byte CDB - may contain extended commands.
2552 * 2555 *
2553 * If that is the case, copy the upper byte register values. 2556 * If that is the case, copy the upper byte register values.
2554 */ 2557 */
2555 if (scsicmd[1] & 0x01) { 2558 if (cdb[1] & 0x01) {
2556 tf->hob_feature = scsicmd[3]; 2559 tf->hob_feature = cdb[3];
2557 tf->hob_nsect = scsicmd[5]; 2560 tf->hob_nsect = cdb[5];
2558 tf->hob_lbal = scsicmd[7]; 2561 tf->hob_lbal = cdb[7];
2559 tf->hob_lbam = scsicmd[9]; 2562 tf->hob_lbam = cdb[9];
2560 tf->hob_lbah = scsicmd[11]; 2563 tf->hob_lbah = cdb[11];
2561 tf->flags |= ATA_TFLAG_LBA48; 2564 tf->flags |= ATA_TFLAG_LBA48;
2562 } else 2565 } else
2563 tf->flags &= ~ATA_TFLAG_LBA48; 2566 tf->flags &= ~ATA_TFLAG_LBA48;
@@ -2565,26 +2568,26 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2565 /* 2568 /*
2566 * Always copy low byte, device and command registers. 2569 * Always copy low byte, device and command registers.
2567 */ 2570 */
2568 tf->feature = scsicmd[4]; 2571 tf->feature = cdb[4];
2569 tf->nsect = scsicmd[6]; 2572 tf->nsect = cdb[6];
2570 tf->lbal = scsicmd[8]; 2573 tf->lbal = cdb[8];
2571 tf->lbam = scsicmd[10]; 2574 tf->lbam = cdb[10];
2572 tf->lbah = scsicmd[12]; 2575 tf->lbah = cdb[12];
2573 tf->device = scsicmd[13]; 2576 tf->device = cdb[13];
2574 tf->command = scsicmd[14]; 2577 tf->command = cdb[14];
2575 } else { 2578 } else {
2576 /* 2579 /*
2577 * 12-byte CDB - incapable of extended commands. 2580 * 12-byte CDB - incapable of extended commands.
2578 */ 2581 */
2579 tf->flags &= ~ATA_TFLAG_LBA48; 2582 tf->flags &= ~ATA_TFLAG_LBA48;
2580 2583
2581 tf->feature = scsicmd[3]; 2584 tf->feature = cdb[3];
2582 tf->nsect = scsicmd[4]; 2585 tf->nsect = cdb[4];
2583 tf->lbal = scsicmd[5]; 2586 tf->lbal = cdb[5];
2584 tf->lbam = scsicmd[6]; 2587 tf->lbam = cdb[6];
2585 tf->lbah = scsicmd[7]; 2588 tf->lbah = cdb[7];
2586 tf->device = scsicmd[8]; 2589 tf->device = cdb[8];
2587 tf->command = scsicmd[9]; 2590 tf->command = cdb[9];
2588 } 2591 }
2589 /* 2592 /*
2590 * If slave is possible, enforce correct master/slave bit 2593 * If slave is possible, enforce correct master/slave bit
@@ -2611,7 +2614,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2611 */ 2614 */
2612 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE); 2615 tf->flags |= (ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE);
2613 2616
2614 if (cmd->sc_data_direction == DMA_TO_DEVICE) 2617 if (scmd->sc_data_direction == DMA_TO_DEVICE)
2615 tf->flags |= ATA_TFLAG_WRITE; 2618 tf->flags |= ATA_TFLAG_WRITE;
2616 2619
2617 /* 2620 /*
@@ -2620,7 +2623,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2620 * TODO: find out if we need to do more here to 2623 * TODO: find out if we need to do more here to
2621 * cover scatter/gather case. 2624 * cover scatter/gather case.
2622 */ 2625 */
2623 qc->nsect = cmd->request_bufflen / ATA_SECT_SIZE; 2626 qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE;
2624 2627
2625 /* request result TF */ 2628 /* request result TF */
2626 qc->flags |= ATA_QCFLAG_RESULT_TF; 2629 qc->flags |= ATA_QCFLAG_RESULT_TF;
@@ -2628,7 +2631,7 @@ ata_scsi_pass_thru(struct ata_queued_cmd *qc, const u8 *scsicmd)
2628 return 0; 2631 return 0;
2629 2632
2630 invalid_fld: 2633 invalid_fld:
2631 ata_scsi_set_sense(qc->scsicmd, ILLEGAL_REQUEST, 0x24, 0x00); 2634 ata_scsi_set_sense(scmd, ILLEGAL_REQUEST, 0x24, 0x00);
2632 /* "Invalid field in cdb" */ 2635 /* "Invalid field in cdb" */
2633 return 1; 2636 return 1;
2634} 2637}
@@ -2701,22 +2704,29 @@ static inline void ata_scsi_dump_cdb(struct ata_port *ap,
2701#endif 2704#endif
2702} 2705}
2703 2706
2704static inline int __ata_scsi_queuecmd(struct scsi_cmnd *cmd, 2707static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
2705 void (*done)(struct scsi_cmnd *), 2708 void (*done)(struct scsi_cmnd *),
2706 struct ata_device *dev) 2709 struct ata_device *dev)
2707{ 2710{
2708 int rc = 0; 2711 int rc = 0;
2709 2712
2713 if (unlikely(!scmd->cmd_len)) {
2714 ata_dev_printk(dev, KERN_WARNING, "WARNING: zero len CDB\n");
2715 scmd->result = DID_ERROR << 16;
2716 done(scmd);
2717 return 0;
2718 }
2719
2710 if (dev->class == ATA_DEV_ATA) { 2720 if (dev->class == ATA_DEV_ATA) {
2711 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev, 2721 ata_xlat_func_t xlat_func = ata_get_xlat_func(dev,
2712 cmd->cmnd[0]); 2722 scmd->cmnd[0]);
2713 2723
2714 if (xlat_func) 2724 if (xlat_func)
2715 rc = ata_scsi_translate(dev, cmd, done, xlat_func); 2725 rc = ata_scsi_translate(dev, scmd, done, xlat_func);
2716 else 2726 else
2717 ata_scsi_simulate(dev, cmd, done); 2727 ata_scsi_simulate(dev, scmd, done);
2718 } else 2728 } else
2719 rc = ata_scsi_translate(dev, cmd, done, atapi_xlat); 2729 rc = ata_scsi_translate(dev, scmd, done, atapi_xlat);
2720 2730
2721 return rc; 2731 return rc;
2722} 2732}
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index 1c628014dae6..b1ca207e3545 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -372,7 +372,8 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
372static int cs5530_reinit_one(struct pci_dev *pdev) 372static int cs5530_reinit_one(struct pci_dev *pdev)
373{ 373{
374 /* If we fail on resume we are doomed */ 374 /* If we fail on resume we are doomed */
375 BUG_ON(cs5530_init_chip()); 375 if (cs5530_init_chip())
376 BUG();
376 return ata_pci_device_resume(pdev); 377 return ata_pci_device_resume(pdev);
377} 378}
378 379
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index c7d1738e4e69..e7bf9d89c8ee 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -698,8 +698,10 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
698 goto fail_io; 698 goto fail_io;
699 699
700 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0); 700 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0);
701 if (pdev == NULL) 701 if (IS_ERR(pdev)) {
702 ret = PTR_ERR(pdev);
702 goto fail_dev; 703 goto fail_dev;
704 }
703 705
704 if (ht6560a & mask) { 706 if (ht6560a & mask) {
705 ops = &ht6560a_port_ops; 707 ops = &ht6560a_port_ops;
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index 36f621abc390..afc0d990e7d6 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -247,8 +247,8 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
247 */ 247 */
248 248
249 pdev = platform_device_register_simple(DRV_NAME, nr_qdi_host, NULL, 0); 249 pdev = platform_device_register_simple(DRV_NAME, nr_qdi_host, NULL, 0);
250 if (pdev == NULL) 250 if (IS_ERR(pdev))
251 return -ENOMEM; 251 return PTR_ERR(pdev);
252 252
253 memset(&ae, 0, sizeof(struct ata_probe_ent)); 253 memset(&ae, 0, sizeof(struct ata_probe_ent));
254 INIT_LIST_HEAD(&ae.node); 254 INIT_LIST_HEAD(&ae.node);
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 3677c642c9f9..adf4cc134f25 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -105,8 +105,6 @@ static struct ata_port_operations rz1000_port_ops = {
105 .exec_command = ata_exec_command, 105 .exec_command = ata_exec_command,
106 .dev_select = ata_std_dev_select, 106 .dev_select = ata_std_dev_select,
107 107
108 .error_handler = rz1000_error_handler,
109
110 .bmdma_setup = ata_bmdma_setup, 108 .bmdma_setup = ata_bmdma_setup,
111 .bmdma_start = ata_bmdma_start, 109 .bmdma_start = ata_bmdma_start,
112 .bmdma_stop = ata_bmdma_stop, 110 .bmdma_stop = ata_bmdma_stop,
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index cc09d47fb927..f0d4f7e9ed31 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -161,10 +161,15 @@ static int via_pre_reset(struct ata_port *ap)
161 return -ENOENT; 161 return -ENOENT;
162 } 162 }
163 163
164 if ((config->flags & VIA_UDMA) >= VIA_UDMA_66) 164 if ((config->flags & VIA_UDMA) >= VIA_UDMA_100)
165 ap->cbl = via_cable_detect(ap); 165 ap->cbl = via_cable_detect(ap);
166 else 166 /* The UDMA66 series has no cable detect so do drive side detect */
167 else if ((config->flags & VIA_UDMA) < VIA_UDMA_66)
167 ap->cbl = ATA_CBL_PATA40; 168 ap->cbl = ATA_CBL_PATA40;
169 else
170 ap->cbl = ATA_CBL_PATA_UNK;
171
172
168 return ata_std_prereset(ap); 173 return ata_std_prereset(ap);
169} 174}
170 175
@@ -390,7 +395,7 @@ static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
390 enable &= 3; 395 enable &= 3;
391 396
392 if (flags & VIA_SET_FIFO) { 397 if (flags & VIA_SET_FIFO) {
393 u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20}; 398 static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
394 u8 fifo; 399 u8 fifo;
395 400
396 pci_read_config_byte(pdev, 0x43, &fifo); 401 pci_read_config_byte(pdev, 0x43, &fifo);
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 3ea345cde52e..5d1f518e1cc7 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -206,8 +206,8 @@ static __init int winbond_init_one(unsigned long port)
206 */ 206 */
207 207
208 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0); 208 pdev = platform_device_register_simple(DRV_NAME, nr_winbond_host, NULL, 0);
209 if (pdev == NULL) 209 if (IS_ERR(pdev))
210 return -ENOMEM; 210 return PTR_ERR(pdev);
211 211
212 memset(&ae, 0, sizeof(struct ata_probe_ent)); 212 memset(&ae, 0, sizeof(struct ata_probe_ent));
213 INIT_LIST_HEAD(&ae.node); 213 INIT_LIST_HEAD(&ae.node);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 0d316eb3c214..f6d498e1cf80 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -270,14 +270,6 @@ static const struct pci_device_id nv_pci_tbl[] = {
270 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC }, 270 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC },
271 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC }, 271 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC },
272 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC }, 272 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC },
273 { PCI_VDEVICE(NVIDIA, 0x045c), GENERIC }, /* MCP65 */
274 { PCI_VDEVICE(NVIDIA, 0x045d), GENERIC }, /* MCP65 */
275 { PCI_VDEVICE(NVIDIA, 0x045e), GENERIC }, /* MCP65 */
276 { PCI_VDEVICE(NVIDIA, 0x045f), GENERIC }, /* MCP65 */
277 { PCI_VDEVICE(NVIDIA, 0x0550), GENERIC }, /* MCP67 */
278 { PCI_VDEVICE(NVIDIA, 0x0551), GENERIC }, /* MCP67 */
279 { PCI_VDEVICE(NVIDIA, 0x0552), GENERIC }, /* MCP67 */
280 { PCI_VDEVICE(NVIDIA, 0x0553), GENERIC }, /* MCP67 */
281 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, 273 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
282 PCI_ANY_ID, PCI_ANY_ID, 274 PCI_ANY_ID, PCI_ANY_ID,
283 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC }, 275 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index db32d15b7fa1..46d8a94669b4 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -56,6 +56,8 @@
56#define DRV_VERSION "2.0" 56#define DRV_VERSION "2.0"
57 57
58enum { 58enum {
59 K2_FLAG_NO_ATAPI_DMA = (1 << 29),
60
59 /* Taskfile registers offsets */ 61 /* Taskfile registers offsets */
60 K2_SATA_TF_CMD_OFFSET = 0x00, 62 K2_SATA_TF_CMD_OFFSET = 0x00,
61 K2_SATA_TF_DATA_OFFSET = 0x00, 63 K2_SATA_TF_DATA_OFFSET = 0x00,
@@ -83,11 +85,33 @@ enum {
83 85
84 /* Port stride */ 86 /* Port stride */
85 K2_SATA_PORT_OFFSET = 0x100, 87 K2_SATA_PORT_OFFSET = 0x100,
88
89 board_svw4 = 0,
90 board_svw8 = 1,
91};
92
93static const struct k2_board_info {
94 unsigned int n_ports;
95 unsigned long port_flags;
96} k2_board_info[] = {
97 /* board_svw4 */
98 { 4, K2_FLAG_NO_ATAPI_DMA },
99
100 /* board_svw8 */
101 { 8, K2_FLAG_NO_ATAPI_DMA },
86}; 102};
87 103
88static u8 k2_stat_check_status(struct ata_port *ap); 104static u8 k2_stat_check_status(struct ata_port *ap);
89 105
90 106
107static int k2_sata_check_atapi_dma(struct ata_queued_cmd *qc)
108{
109 if (qc->ap->flags & K2_FLAG_NO_ATAPI_DMA)
110 return -1; /* ATAPI DMA not supported */
111
112 return 0;
113}
114
91static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 115static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
92{ 116{
93 if (sc_reg > SCR_CONTROL) 117 if (sc_reg > SCR_CONTROL)
@@ -111,26 +135,31 @@ static void k2_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
111 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 135 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
112 136
113 if (tf->ctl != ap->last_ctl) { 137 if (tf->ctl != ap->last_ctl) {
114 writeb(tf->ctl, ioaddr->ctl_addr); 138 writeb(tf->ctl, (void __iomem *) ioaddr->ctl_addr);
115 ap->last_ctl = tf->ctl; 139 ap->last_ctl = tf->ctl;
116 ata_wait_idle(ap); 140 ata_wait_idle(ap);
117 } 141 }
118 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 142 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
119 writew(tf->feature | (((u16)tf->hob_feature) << 8), ioaddr->feature_addr); 143 writew(tf->feature | (((u16)tf->hob_feature) << 8),
120 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), ioaddr->nsect_addr); 144 (void __iomem *) ioaddr->feature_addr);
121 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), ioaddr->lbal_addr); 145 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
122 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), ioaddr->lbam_addr); 146 (void __iomem *) ioaddr->nsect_addr);
123 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), ioaddr->lbah_addr); 147 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
148 (void __iomem *) ioaddr->lbal_addr);
149 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
150 (void __iomem *) ioaddr->lbam_addr);
151 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
152 (void __iomem *) ioaddr->lbah_addr);
124 } else if (is_addr) { 153 } else if (is_addr) {
125 writew(tf->feature, ioaddr->feature_addr); 154 writew(tf->feature, (void __iomem *) ioaddr->feature_addr);
126 writew(tf->nsect, ioaddr->nsect_addr); 155 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
127 writew(tf->lbal, ioaddr->lbal_addr); 156 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
128 writew(tf->lbam, ioaddr->lbam_addr); 157 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
129 writew(tf->lbah, ioaddr->lbah_addr); 158 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
130 } 159 }
131 160
132 if (tf->flags & ATA_TFLAG_DEVICE) 161 if (tf->flags & ATA_TFLAG_DEVICE)
133 writeb(tf->device, ioaddr->device_addr); 162 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
134 163
135 ata_wait_idle(ap); 164 ata_wait_idle(ap);
136} 165}
@@ -142,12 +171,12 @@ static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
142 u16 nsect, lbal, lbam, lbah, feature; 171 u16 nsect, lbal, lbam, lbah, feature;
143 172
144 tf->command = k2_stat_check_status(ap); 173 tf->command = k2_stat_check_status(ap);
145 tf->device = readw(ioaddr->device_addr); 174 tf->device = readw((void __iomem *)ioaddr->device_addr);
146 feature = readw(ioaddr->error_addr); 175 feature = readw((void __iomem *)ioaddr->error_addr);
147 nsect = readw(ioaddr->nsect_addr); 176 nsect = readw((void __iomem *)ioaddr->nsect_addr);
148 lbal = readw(ioaddr->lbal_addr); 177 lbal = readw((void __iomem *)ioaddr->lbal_addr);
149 lbam = readw(ioaddr->lbam_addr); 178 lbam = readw((void __iomem *)ioaddr->lbam_addr);
150 lbah = readw(ioaddr->lbah_addr); 179 lbah = readw((void __iomem *)ioaddr->lbah_addr);
151 180
152 tf->feature = feature; 181 tf->feature = feature;
153 tf->nsect = nsect; 182 tf->nsect = nsect;
@@ -313,6 +342,7 @@ static const struct ata_port_operations k2_sata_ops = {
313 .check_status = k2_stat_check_status, 342 .check_status = k2_stat_check_status,
314 .exec_command = ata_exec_command, 343 .exec_command = ata_exec_command,
315 .dev_select = ata_std_dev_select, 344 .dev_select = ata_std_dev_select,
345 .check_atapi_dma = k2_sata_check_atapi_dma,
316 .bmdma_setup = k2_bmdma_setup_mmio, 346 .bmdma_setup = k2_bmdma_setup_mmio,
317 .bmdma_start = k2_bmdma_start_mmio, 347 .bmdma_start = k2_bmdma_start_mmio,
318 .bmdma_stop = ata_bmdma_stop, 348 .bmdma_stop = ata_bmdma_stop,
@@ -359,6 +389,8 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
359 struct ata_probe_ent *probe_ent = NULL; 389 struct ata_probe_ent *probe_ent = NULL;
360 unsigned long base; 390 unsigned long base;
361 void __iomem *mmio_base; 391 void __iomem *mmio_base;
392 const struct k2_board_info *board_info =
393 &k2_board_info[ent->driver_data];
362 int pci_dev_busy = 0; 394 int pci_dev_busy = 0;
363 int rc; 395 int rc;
364 int i; 396 int i;
@@ -424,7 +456,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
424 456
425 probe_ent->sht = &k2_sata_sht; 457 probe_ent->sht = &k2_sata_sht;
426 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 458 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
427 ATA_FLAG_MMIO; 459 ATA_FLAG_MMIO | board_info->port_flags;
428 probe_ent->port_ops = &k2_sata_ops; 460 probe_ent->port_ops = &k2_sata_ops;
429 probe_ent->n_ports = 4; 461 probe_ent->n_ports = 4;
430 probe_ent->irq = pdev->irq; 462 probe_ent->irq = pdev->irq;
@@ -441,7 +473,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
441 /* different controllers have different number of ports - currently 4 or 8 */ 473 /* different controllers have different number of ports - currently 4 or 8 */
442 /* All ports are on the same function. Multi-function device is no 474 /* All ports are on the same function. Multi-function device is no
443 * longer available. This should not be seen in any system. */ 475 * longer available. This should not be seen in any system. */
444 for (i = 0; i < ent->driver_data; i++) 476 for (i = 0; i < board_info->n_ports; i++)
445 k2_sata_setup_port(&probe_ent->port[i], base + i * K2_SATA_PORT_OFFSET); 477 k2_sata_setup_port(&probe_ent->port[i], base + i * K2_SATA_PORT_OFFSET);
446 478
447 pci_set_master(pdev); 479 pci_set_master(pdev);
@@ -469,11 +501,11 @@ err_out:
469 * controller 501 * controller
470 * */ 502 * */
471static const struct pci_device_id k2_sata_pci_tbl[] = { 503static const struct pci_device_id k2_sata_pci_tbl[] = {
472 { PCI_VDEVICE(SERVERWORKS, 0x0240), 4 }, 504 { PCI_VDEVICE(SERVERWORKS, 0x0240), board_svw4 },
473 { PCI_VDEVICE(SERVERWORKS, 0x0241), 4 }, 505 { PCI_VDEVICE(SERVERWORKS, 0x0241), board_svw4 },
474 { PCI_VDEVICE(SERVERWORKS, 0x0242), 8 }, 506 { PCI_VDEVICE(SERVERWORKS, 0x0242), board_svw8 },
475 { PCI_VDEVICE(SERVERWORKS, 0x024a), 4 }, 507 { PCI_VDEVICE(SERVERWORKS, 0x024a), board_svw4 },
476 { PCI_VDEVICE(SERVERWORKS, 0x024b), 4 }, 508 { PCI_VDEVICE(SERVERWORKS, 0x024b), board_svw4 },
477 509
478 { } 510 { }
479}; 511};
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index e654b990b905..0fa1b89f76d5 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -149,21 +149,26 @@ static void vsc_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
149 vsc_intr_mask_update(ap, tf->ctl & ATA_NIEN); 149 vsc_intr_mask_update(ap, tf->ctl & ATA_NIEN);
150 } 150 }
151 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 151 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
152 writew(tf->feature | (((u16)tf->hob_feature) << 8), ioaddr->feature_addr); 152 writew(tf->feature | (((u16)tf->hob_feature) << 8),
153 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), ioaddr->nsect_addr); 153 (void __iomem *) ioaddr->feature_addr);
154 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), ioaddr->lbal_addr); 154 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
155 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), ioaddr->lbam_addr); 155 (void __iomem *) ioaddr->nsect_addr);
156 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), ioaddr->lbah_addr); 156 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
157 (void __iomem *) ioaddr->lbal_addr);
158 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
159 (void __iomem *) ioaddr->lbam_addr);
160 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
161 (void __iomem *) ioaddr->lbah_addr);
157 } else if (is_addr) { 162 } else if (is_addr) {
158 writew(tf->feature, ioaddr->feature_addr); 163 writew(tf->feature, (void __iomem *) ioaddr->feature_addr);
159 writew(tf->nsect, ioaddr->nsect_addr); 164 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr);
160 writew(tf->lbal, ioaddr->lbal_addr); 165 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr);
161 writew(tf->lbam, ioaddr->lbam_addr); 166 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr);
162 writew(tf->lbah, ioaddr->lbah_addr); 167 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr);
163 } 168 }
164 169
165 if (tf->flags & ATA_TFLAG_DEVICE) 170 if (tf->flags & ATA_TFLAG_DEVICE)
166 writeb(tf->device, ioaddr->device_addr); 171 writeb(tf->device, (void __iomem *) ioaddr->device_addr);
167 172
168 ata_wait_idle(ap); 173 ata_wait_idle(ap);
169} 174}
@@ -175,12 +180,12 @@ static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
175 u16 nsect, lbal, lbam, lbah, feature; 180 u16 nsect, lbal, lbam, lbah, feature;
176 181
177 tf->command = ata_check_status(ap); 182 tf->command = ata_check_status(ap);
178 tf->device = readw(ioaddr->device_addr); 183 tf->device = readw((void __iomem *) ioaddr->device_addr);
179 feature = readw(ioaddr->error_addr); 184 feature = readw((void __iomem *) ioaddr->error_addr);
180 nsect = readw(ioaddr->nsect_addr); 185 nsect = readw((void __iomem *) ioaddr->nsect_addr);
181 lbal = readw(ioaddr->lbal_addr); 186 lbal = readw((void __iomem *) ioaddr->lbal_addr);
182 lbam = readw(ioaddr->lbam_addr); 187 lbam = readw((void __iomem *) ioaddr->lbam_addr);
183 lbah = readw(ioaddr->lbah_addr); 188 lbah = readw((void __iomem *) ioaddr->lbah_addr);
184 189
185 tf->feature = feature; 190 tf->feature = feature;
186 tf->nsect = nsect; 191 tf->nsect = nsect;
@@ -327,8 +332,8 @@ static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned lon
327 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET; 332 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET;
328 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET; 333 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET;
329 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET; 334 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET;
330 writel(0, base + VSC_SATA_UP_DESCRIPTOR_OFFSET); 335 writel(0, (void __iomem *) base + VSC_SATA_UP_DESCRIPTOR_OFFSET);
331 writel(0, base + VSC_SATA_UP_DATA_BUFFER_OFFSET); 336 writel(0, (void __iomem *) base + VSC_SATA_UP_DATA_BUFFER_OFFSET);
332} 337}
333 338
334 339
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index 2ddd76fdbc43..33687454eb32 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -167,10 +167,6 @@ config ATM_ZATM_DEBUG
167 Note that extended debugging may create certain race conditions 167 Note that extended debugging may create certain race conditions
168 itself. Enable this ONLY if you suspect problems with the driver. 168 itself. Enable this ONLY if you suspect problems with the driver.
169 169
170# bool 'Rolfs TI TNETA1570' CONFIG_ATM_TNETA1570 y
171# if [ "$CONFIG_ATM_TNETA1570" = "y" ]; then
172# bool ' Enable extended debugging' CONFIG_ATM_TNETA1570_DEBUG n
173# fi
174config ATM_NICSTAR 170config ATM_NICSTAR
175 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)" 171 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)"
176 depends on PCI && ATM && !64BIT 172 depends on PCI && ATM && !64BIT
diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
index 3a7b21ff30a5..4aeb3d062ff6 100644
--- a/drivers/atm/fore200e.c
+++ b/drivers/atm/fore200e.c
@@ -172,25 +172,6 @@ fore200e_irq_itoa(int irq)
172} 172}
173 173
174 174
175static void*
176fore200e_kmalloc(int size, gfp_t flags)
177{
178 void *chunk = kzalloc(size, flags);
179
180 if (!chunk)
181 printk(FORE200E "kmalloc() failed, requested size = %d, flags = 0x%x\n", size, flags);
182
183 return chunk;
184}
185
186
187static void
188fore200e_kfree(void* chunk)
189{
190 kfree(chunk);
191}
192
193
194/* allocate and align a chunk of memory intended to hold the data behing exchanged 175/* allocate and align a chunk of memory intended to hold the data behing exchanged
195 between the driver and the adapter (using streaming DVMA) */ 176 between the driver and the adapter (using streaming DVMA) */
196 177
@@ -206,7 +187,7 @@ fore200e_chunk_alloc(struct fore200e* fore200e, struct chunk* chunk, int size, i
206 chunk->align_size = size; 187 chunk->align_size = size;
207 chunk->direction = direction; 188 chunk->direction = direction;
208 189
209 chunk->alloc_addr = fore200e_kmalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA); 190 chunk->alloc_addr = kzalloc(chunk->alloc_size, GFP_KERNEL | GFP_DMA);
210 if (chunk->alloc_addr == NULL) 191 if (chunk->alloc_addr == NULL)
211 return -ENOMEM; 192 return -ENOMEM;
212 193
@@ -228,7 +209,7 @@ fore200e_chunk_free(struct fore200e* fore200e, struct chunk* chunk)
228{ 209{
229 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction); 210 fore200e->bus->dma_unmap(fore200e, chunk->dma_addr, chunk->dma_size, chunk->direction);
230 211
231 fore200e_kfree(chunk->alloc_addr); 212 kfree(chunk->alloc_addr);
232} 213}
233 214
234 215
@@ -882,7 +863,7 @@ fore200e_sba_detect(const struct fore200e_bus* bus, int index)
882 return NULL; 863 return NULL;
883 } 864 }
884 865
885 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL); 866 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
886 if (fore200e == NULL) 867 if (fore200e == NULL)
887 return NULL; 868 return NULL;
888 869
@@ -1505,7 +1486,7 @@ fore200e_open(struct atm_vcc *vcc)
1505 1486
1506 spin_unlock_irqrestore(&fore200e->q_lock, flags); 1487 spin_unlock_irqrestore(&fore200e->q_lock, flags);
1507 1488
1508 fore200e_vcc = fore200e_kmalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC); 1489 fore200e_vcc = kzalloc(sizeof(struct fore200e_vcc), GFP_ATOMIC);
1509 if (fore200e_vcc == NULL) { 1490 if (fore200e_vcc == NULL) {
1510 vc_map->vcc = NULL; 1491 vc_map->vcc = NULL;
1511 return -ENOMEM; 1492 return -ENOMEM;
@@ -1526,7 +1507,7 @@ fore200e_open(struct atm_vcc *vcc)
1526 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) { 1507 if (fore200e->available_cell_rate < vcc->qos.txtp.max_pcr) {
1527 up(&fore200e->rate_sf); 1508 up(&fore200e->rate_sf);
1528 1509
1529 fore200e_kfree(fore200e_vcc); 1510 kfree(fore200e_vcc);
1530 vc_map->vcc = NULL; 1511 vc_map->vcc = NULL;
1531 return -EAGAIN; 1512 return -EAGAIN;
1532 } 1513 }
@@ -1554,7 +1535,7 @@ fore200e_open(struct atm_vcc *vcc)
1554 1535
1555 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr; 1536 fore200e->available_cell_rate += vcc->qos.txtp.max_pcr;
1556 1537
1557 fore200e_kfree(fore200e_vcc); 1538 kfree(fore200e_vcc);
1558 return -EINVAL; 1539 return -EINVAL;
1559 } 1540 }
1560 1541
@@ -1630,7 +1611,7 @@ fore200e_close(struct atm_vcc* vcc)
1630 clear_bit(ATM_VF_PARTIAL,&vcc->flags); 1611 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
1631 1612
1632 ASSERT(fore200e_vcc); 1613 ASSERT(fore200e_vcc);
1633 fore200e_kfree(fore200e_vcc); 1614 kfree(fore200e_vcc);
1634} 1615}
1635 1616
1636 1617
@@ -1831,7 +1812,7 @@ fore200e_getstats(struct fore200e* fore200e)
1831 u32 stats_dma_addr; 1812 u32 stats_dma_addr;
1832 1813
1833 if (fore200e->stats == NULL) { 1814 if (fore200e->stats == NULL) {
1834 fore200e->stats = fore200e_kmalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA); 1815 fore200e->stats = kzalloc(sizeof(struct stats), GFP_KERNEL | GFP_DMA);
1835 if (fore200e->stats == NULL) 1816 if (fore200e->stats == NULL)
1836 return -ENOMEM; 1817 return -ENOMEM;
1837 } 1818 }
@@ -2002,17 +1983,6 @@ fore200e_setloop(struct fore200e* fore200e, int loop_mode)
2002} 1983}
2003 1984
2004 1985
2005static inline unsigned int
2006fore200e_swap(unsigned int in)
2007{
2008#if defined(__LITTLE_ENDIAN)
2009 return swab32(in);
2010#else
2011 return in;
2012#endif
2013}
2014
2015
2016static int 1986static int
2017fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg) 1987fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
2018{ 1988{
@@ -2021,19 +1991,19 @@ fore200e_fetch_stats(struct fore200e* fore200e, struct sonet_stats __user *arg)
2021 if (fore200e_getstats(fore200e) < 0) 1991 if (fore200e_getstats(fore200e) < 0)
2022 return -EIO; 1992 return -EIO;
2023 1993
2024 tmp.section_bip = fore200e_swap(fore200e->stats->oc3.section_bip8_errors); 1994 tmp.section_bip = cpu_to_be32(fore200e->stats->oc3.section_bip8_errors);
2025 tmp.line_bip = fore200e_swap(fore200e->stats->oc3.line_bip24_errors); 1995 tmp.line_bip = cpu_to_be32(fore200e->stats->oc3.line_bip24_errors);
2026 tmp.path_bip = fore200e_swap(fore200e->stats->oc3.path_bip8_errors); 1996 tmp.path_bip = cpu_to_be32(fore200e->stats->oc3.path_bip8_errors);
2027 tmp.line_febe = fore200e_swap(fore200e->stats->oc3.line_febe_errors); 1997 tmp.line_febe = cpu_to_be32(fore200e->stats->oc3.line_febe_errors);
2028 tmp.path_febe = fore200e_swap(fore200e->stats->oc3.path_febe_errors); 1998 tmp.path_febe = cpu_to_be32(fore200e->stats->oc3.path_febe_errors);
2029 tmp.corr_hcs = fore200e_swap(fore200e->stats->oc3.corr_hcs_errors); 1999 tmp.corr_hcs = cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors);
2030 tmp.uncorr_hcs = fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors); 2000 tmp.uncorr_hcs = cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors);
2031 tmp.tx_cells = fore200e_swap(fore200e->stats->aal0.cells_transmitted) + 2001 tmp.tx_cells = cpu_to_be32(fore200e->stats->aal0.cells_transmitted) +
2032 fore200e_swap(fore200e->stats->aal34.cells_transmitted) + 2002 cpu_to_be32(fore200e->stats->aal34.cells_transmitted) +
2033 fore200e_swap(fore200e->stats->aal5.cells_transmitted); 2003 cpu_to_be32(fore200e->stats->aal5.cells_transmitted);
2034 tmp.rx_cells = fore200e_swap(fore200e->stats->aal0.cells_received) + 2004 tmp.rx_cells = cpu_to_be32(fore200e->stats->aal0.cells_received) +
2035 fore200e_swap(fore200e->stats->aal34.cells_received) + 2005 cpu_to_be32(fore200e->stats->aal34.cells_received) +
2036 fore200e_swap(fore200e->stats->aal5.cells_received); 2006 cpu_to_be32(fore200e->stats->aal5.cells_received);
2037 2007
2038 if (arg) 2008 if (arg)
2039 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0; 2009 return copy_to_user(arg, &tmp, sizeof(struct sonet_stats)) ? -EFAULT : 0;
@@ -2146,7 +2116,7 @@ fore200e_irq_request(struct fore200e* fore200e)
2146static int __devinit 2116static int __devinit
2147fore200e_get_esi(struct fore200e* fore200e) 2117fore200e_get_esi(struct fore200e* fore200e)
2148{ 2118{
2149 struct prom_data* prom = fore200e_kmalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA); 2119 struct prom_data* prom = kzalloc(sizeof(struct prom_data), GFP_KERNEL | GFP_DMA);
2150 int ok, i; 2120 int ok, i;
2151 2121
2152 if (!prom) 2122 if (!prom)
@@ -2154,7 +2124,7 @@ fore200e_get_esi(struct fore200e* fore200e)
2154 2124
2155 ok = fore200e->bus->prom_read(fore200e, prom); 2125 ok = fore200e->bus->prom_read(fore200e, prom);
2156 if (ok < 0) { 2126 if (ok < 0) {
2157 fore200e_kfree(prom); 2127 kfree(prom);
2158 return -EBUSY; 2128 return -EBUSY;
2159 } 2129 }
2160 2130
@@ -2169,7 +2139,7 @@ fore200e_get_esi(struct fore200e* fore200e)
2169 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ]; 2139 fore200e->esi[ i ] = fore200e->atm_dev->esi[ i ] = prom->mac_addr[ i + 2 ];
2170 } 2140 }
2171 2141
2172 fore200e_kfree(prom); 2142 kfree(prom);
2173 2143
2174 return 0; 2144 return 0;
2175} 2145}
@@ -2194,7 +2164,7 @@ fore200e_alloc_rx_buf(struct fore200e* fore200e)
2194 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn); 2164 DPRINTK(2, "rx buffers %d / %d are being allocated\n", scheme, magn);
2195 2165
2196 /* allocate the array of receive buffers */ 2166 /* allocate the array of receive buffers */
2197 buffer = bsq->buffer = fore200e_kmalloc(nbr * sizeof(struct buffer), GFP_KERNEL); 2167 buffer = bsq->buffer = kzalloc(nbr * sizeof(struct buffer), GFP_KERNEL);
2198 2168
2199 if (buffer == NULL) 2169 if (buffer == NULL)
2200 return -ENOMEM; 2170 return -ENOMEM;
@@ -2217,7 +2187,7 @@ fore200e_alloc_rx_buf(struct fore200e* fore200e)
2217 2187
2218 while (i > 0) 2188 while (i > 0)
2219 fore200e_chunk_free(fore200e, &buffer[ --i ].data); 2189 fore200e_chunk_free(fore200e, &buffer[ --i ].data);
2220 fore200e_kfree(buffer); 2190 kfree(buffer);
2221 2191
2222 return -ENOMEM; 2192 return -ENOMEM;
2223 } 2193 }
@@ -2736,7 +2706,7 @@ fore200e_pca_detect(struct pci_dev *pci_dev, const struct pci_device_id *pci_ent
2736 goto out; 2706 goto out;
2737 } 2707 }
2738 2708
2739 fore200e = fore200e_kmalloc(sizeof(struct fore200e), GFP_KERNEL); 2709 fore200e = kzalloc(sizeof(struct fore200e), GFP_KERNEL);
2740 if (fore200e == NULL) { 2710 if (fore200e == NULL) {
2741 err = -ENOMEM; 2711 err = -ENOMEM;
2742 goto out_disable; 2712 goto out_disable;
@@ -2999,8 +2969,8 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
2999 " 4b5b:\n" 2969 " 4b5b:\n"
3000 " crc_header_errors:\t\t%10u\n" 2970 " crc_header_errors:\t\t%10u\n"
3001 " framing_errors:\t\t%10u\n", 2971 " framing_errors:\t\t%10u\n",
3002 fore200e_swap(fore200e->stats->phy.crc_header_errors), 2972 cpu_to_be32(fore200e->stats->phy.crc_header_errors),
3003 fore200e_swap(fore200e->stats->phy.framing_errors)); 2973 cpu_to_be32(fore200e->stats->phy.framing_errors));
3004 2974
3005 if (!left--) 2975 if (!left--)
3006 return sprintf(page, "\n" 2976 return sprintf(page, "\n"
@@ -3012,13 +2982,13 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3012 " path_febe_errors:\t\t%10u\n" 2982 " path_febe_errors:\t\t%10u\n"
3013 " corr_hcs_errors:\t\t%10u\n" 2983 " corr_hcs_errors:\t\t%10u\n"
3014 " ucorr_hcs_errors:\t\t%10u\n", 2984 " ucorr_hcs_errors:\t\t%10u\n",
3015 fore200e_swap(fore200e->stats->oc3.section_bip8_errors), 2985 cpu_to_be32(fore200e->stats->oc3.section_bip8_errors),
3016 fore200e_swap(fore200e->stats->oc3.path_bip8_errors), 2986 cpu_to_be32(fore200e->stats->oc3.path_bip8_errors),
3017 fore200e_swap(fore200e->stats->oc3.line_bip24_errors), 2987 cpu_to_be32(fore200e->stats->oc3.line_bip24_errors),
3018 fore200e_swap(fore200e->stats->oc3.line_febe_errors), 2988 cpu_to_be32(fore200e->stats->oc3.line_febe_errors),
3019 fore200e_swap(fore200e->stats->oc3.path_febe_errors), 2989 cpu_to_be32(fore200e->stats->oc3.path_febe_errors),
3020 fore200e_swap(fore200e->stats->oc3.corr_hcs_errors), 2990 cpu_to_be32(fore200e->stats->oc3.corr_hcs_errors),
3021 fore200e_swap(fore200e->stats->oc3.ucorr_hcs_errors)); 2991 cpu_to_be32(fore200e->stats->oc3.ucorr_hcs_errors));
3022 2992
3023 if (!left--) 2993 if (!left--)
3024 return sprintf(page,"\n" 2994 return sprintf(page,"\n"
@@ -3029,12 +2999,12 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3029 " vpi no conn:\t\t%10u\n" 2999 " vpi no conn:\t\t%10u\n"
3030 " vci out of range:\t\t%10u\n" 3000 " vci out of range:\t\t%10u\n"
3031 " vci no conn:\t\t%10u\n", 3001 " vci no conn:\t\t%10u\n",
3032 fore200e_swap(fore200e->stats->atm.cells_transmitted), 3002 cpu_to_be32(fore200e->stats->atm.cells_transmitted),
3033 fore200e_swap(fore200e->stats->atm.cells_received), 3003 cpu_to_be32(fore200e->stats->atm.cells_received),
3034 fore200e_swap(fore200e->stats->atm.vpi_bad_range), 3004 cpu_to_be32(fore200e->stats->atm.vpi_bad_range),
3035 fore200e_swap(fore200e->stats->atm.vpi_no_conn), 3005 cpu_to_be32(fore200e->stats->atm.vpi_no_conn),
3036 fore200e_swap(fore200e->stats->atm.vci_bad_range), 3006 cpu_to_be32(fore200e->stats->atm.vci_bad_range),
3037 fore200e_swap(fore200e->stats->atm.vci_no_conn)); 3007 cpu_to_be32(fore200e->stats->atm.vci_no_conn));
3038 3008
3039 if (!left--) 3009 if (!left--)
3040 return sprintf(page,"\n" 3010 return sprintf(page,"\n"
@@ -3042,9 +3012,9 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3042 " TX:\t\t\t%10u\n" 3012 " TX:\t\t\t%10u\n"
3043 " RX:\t\t\t%10u\n" 3013 " RX:\t\t\t%10u\n"
3044 " dropped:\t\t\t%10u\n", 3014 " dropped:\t\t\t%10u\n",
3045 fore200e_swap(fore200e->stats->aal0.cells_transmitted), 3015 cpu_to_be32(fore200e->stats->aal0.cells_transmitted),
3046 fore200e_swap(fore200e->stats->aal0.cells_received), 3016 cpu_to_be32(fore200e->stats->aal0.cells_received),
3047 fore200e_swap(fore200e->stats->aal0.cells_dropped)); 3017 cpu_to_be32(fore200e->stats->aal0.cells_dropped));
3048 3018
3049 if (!left--) 3019 if (!left--)
3050 return sprintf(page,"\n" 3020 return sprintf(page,"\n"
@@ -3060,15 +3030,15 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3060 " RX:\t\t\t%10u\n" 3030 " RX:\t\t\t%10u\n"
3061 " dropped:\t\t\t%10u\n" 3031 " dropped:\t\t\t%10u\n"
3062 " protocol errors:\t\t%10u\n", 3032 " protocol errors:\t\t%10u\n",
3063 fore200e_swap(fore200e->stats->aal34.cells_transmitted), 3033 cpu_to_be32(fore200e->stats->aal34.cells_transmitted),
3064 fore200e_swap(fore200e->stats->aal34.cells_received), 3034 cpu_to_be32(fore200e->stats->aal34.cells_received),
3065 fore200e_swap(fore200e->stats->aal34.cells_dropped), 3035 cpu_to_be32(fore200e->stats->aal34.cells_dropped),
3066 fore200e_swap(fore200e->stats->aal34.cells_crc_errors), 3036 cpu_to_be32(fore200e->stats->aal34.cells_crc_errors),
3067 fore200e_swap(fore200e->stats->aal34.cells_protocol_errors), 3037 cpu_to_be32(fore200e->stats->aal34.cells_protocol_errors),
3068 fore200e_swap(fore200e->stats->aal34.cspdus_transmitted), 3038 cpu_to_be32(fore200e->stats->aal34.cspdus_transmitted),
3069 fore200e_swap(fore200e->stats->aal34.cspdus_received), 3039 cpu_to_be32(fore200e->stats->aal34.cspdus_received),
3070 fore200e_swap(fore200e->stats->aal34.cspdus_dropped), 3040 cpu_to_be32(fore200e->stats->aal34.cspdus_dropped),
3071 fore200e_swap(fore200e->stats->aal34.cspdus_protocol_errors)); 3041 cpu_to_be32(fore200e->stats->aal34.cspdus_protocol_errors));
3072 3042
3073 if (!left--) 3043 if (!left--)
3074 return sprintf(page,"\n" 3044 return sprintf(page,"\n"
@@ -3084,15 +3054,15 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3084 " dropped:\t\t\t%10u\n" 3054 " dropped:\t\t\t%10u\n"
3085 " CRC errors:\t\t%10u\n" 3055 " CRC errors:\t\t%10u\n"
3086 " protocol errors:\t\t%10u\n", 3056 " protocol errors:\t\t%10u\n",
3087 fore200e_swap(fore200e->stats->aal5.cells_transmitted), 3057 cpu_to_be32(fore200e->stats->aal5.cells_transmitted),
3088 fore200e_swap(fore200e->stats->aal5.cells_received), 3058 cpu_to_be32(fore200e->stats->aal5.cells_received),
3089 fore200e_swap(fore200e->stats->aal5.cells_dropped), 3059 cpu_to_be32(fore200e->stats->aal5.cells_dropped),
3090 fore200e_swap(fore200e->stats->aal5.congestion_experienced), 3060 cpu_to_be32(fore200e->stats->aal5.congestion_experienced),
3091 fore200e_swap(fore200e->stats->aal5.cspdus_transmitted), 3061 cpu_to_be32(fore200e->stats->aal5.cspdus_transmitted),
3092 fore200e_swap(fore200e->stats->aal5.cspdus_received), 3062 cpu_to_be32(fore200e->stats->aal5.cspdus_received),
3093 fore200e_swap(fore200e->stats->aal5.cspdus_dropped), 3063 cpu_to_be32(fore200e->stats->aal5.cspdus_dropped),
3094 fore200e_swap(fore200e->stats->aal5.cspdus_crc_errors), 3064 cpu_to_be32(fore200e->stats->aal5.cspdus_crc_errors),
3095 fore200e_swap(fore200e->stats->aal5.cspdus_protocol_errors)); 3065 cpu_to_be32(fore200e->stats->aal5.cspdus_protocol_errors));
3096 3066
3097 if (!left--) 3067 if (!left--)
3098 return sprintf(page,"\n" 3068 return sprintf(page,"\n"
@@ -3103,11 +3073,11 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
3103 " large b2:\t\t\t%10u\n" 3073 " large b2:\t\t\t%10u\n"
3104 " RX PDUs:\t\t\t%10u\n" 3074 " RX PDUs:\t\t\t%10u\n"
3105 " TX PDUs:\t\t\t%10lu\n", 3075 " TX PDUs:\t\t\t%10lu\n",
3106 fore200e_swap(fore200e->stats->aux.small_b1_failed), 3076 cpu_to_be32(fore200e->stats->aux.small_b1_failed),
3107 fore200e_swap(fore200e->stats->aux.large_b1_failed), 3077 cpu_to_be32(fore200e->stats->aux.large_b1_failed),
3108 fore200e_swap(fore200e->stats->aux.small_b2_failed), 3078 cpu_to_be32(fore200e->stats->aux.small_b2_failed),
3109 fore200e_swap(fore200e->stats->aux.large_b2_failed), 3079 cpu_to_be32(fore200e->stats->aux.large_b2_failed),
3110 fore200e_swap(fore200e->stats->aux.rpd_alloc_failed), 3080 cpu_to_be32(fore200e->stats->aux.rpd_alloc_failed),
3111 fore200e->tx_sat); 3081 fore200e->tx_sat);
3112 3082
3113 if (!left--) 3083 if (!left--)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4bad2870c485..64558f45e6bc 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -127,6 +127,7 @@ static ssize_t firmware_loading_show(struct device *dev,
127/** 127/**
128 * firmware_loading_store - set value in the 'loading' control file 128 * firmware_loading_store - set value in the 'loading' control file
129 * @dev: device pointer 129 * @dev: device pointer
130 * @attr: device attribute pointer
130 * @buf: buffer to scan for loading control value 131 * @buf: buffer to scan for loading control value
131 * @count: number of bytes in @buf 132 * @count: number of bytes in @buf
132 * 133 *
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 97f7f535f412..bb022ed4a866 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -30,8 +30,6 @@ new_skb(ulong len)
30 skb->nh.raw = skb->mac.raw = skb->data; 30 skb->nh.raw = skb->mac.raw = skb->data;
31 skb->protocol = __constant_htons(ETH_P_AOE); 31 skb->protocol = __constant_htons(ETH_P_AOE);
32 skb->priority = 0; 32 skb->priority = 0;
33 skb_put(skb, len);
34 memset(skb->head, 0, len);
35 skb->next = skb->prev = NULL; 33 skb->next = skb->prev = NULL;
36 34
37 /* tell the network layer not to perform IP checksums 35 /* tell the network layer not to perform IP checksums
@@ -122,8 +120,8 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
122 skb = f->skb; 120 skb = f->skb;
123 h = (struct aoe_hdr *) skb->mac.raw; 121 h = (struct aoe_hdr *) skb->mac.raw;
124 ah = (struct aoe_atahdr *) (h+1); 122 ah = (struct aoe_atahdr *) (h+1);
125 skb->len = sizeof *h + sizeof *ah; 123 skb_put(skb, sizeof *h + sizeof *ah);
126 memset(h, 0, ETH_ZLEN); 124 memset(h, 0, skb->len);
127 f->tag = aoehdr_atainit(d, h); 125 f->tag = aoehdr_atainit(d, h);
128 f->waited = 0; 126 f->waited = 0;
129 f->buf = buf; 127 f->buf = buf;
@@ -149,7 +147,6 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
149 skb->len += bcnt; 147 skb->len += bcnt;
150 skb->data_len = bcnt; 148 skb->data_len = bcnt;
151 } else { 149 } else {
152 skb->len = ETH_ZLEN;
153 writebit = 0; 150 writebit = 0;
154 } 151 }
155 152
@@ -206,6 +203,7 @@ aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
206 printk(KERN_INFO "aoe: skb alloc failure\n"); 203 printk(KERN_INFO "aoe: skb alloc failure\n");
207 continue; 204 continue;
208 } 205 }
206 skb_put(skb, sizeof *h + sizeof *ch);
209 skb->dev = ifp; 207 skb->dev = ifp;
210 if (sl_tail == NULL) 208 if (sl_tail == NULL)
211 sl_tail = skb; 209 sl_tail = skb;
@@ -243,6 +241,7 @@ freeframe(struct aoedev *d)
243 continue; 241 continue;
244 if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) { 242 if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) {
245 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0; 243 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
244 skb_trim(f->skb, 0);
246 return f; 245 return f;
247 } 246 }
248 n++; 247 n++;
@@ -698,8 +697,8 @@ aoecmd_ata_id(struct aoedev *d)
698 skb = f->skb; 697 skb = f->skb;
699 h = (struct aoe_hdr *) skb->mac.raw; 698 h = (struct aoe_hdr *) skb->mac.raw;
700 ah = (struct aoe_atahdr *) (h+1); 699 ah = (struct aoe_atahdr *) (h+1);
701 skb->len = ETH_ZLEN; 700 skb_put(skb, sizeof *h + sizeof *ah);
702 memset(h, 0, ETH_ZLEN); 701 memset(h, 0, skb->len);
703 f->tag = aoehdr_atainit(d, h); 702 f->tag = aoehdr_atainit(d, h);
704 f->waited = 0; 703 f->waited = 0;
705 704
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index d719a5d8f435..05dfe357527c 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -225,6 +225,8 @@ static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
225 225
226#include "cciss_scsi.c" /* For SCSI tape support */ 226#include "cciss_scsi.c" /* For SCSI tape support */
227 227
228#define RAID_UNKNOWN 6
229
228#ifdef CONFIG_PROC_FS 230#ifdef CONFIG_PROC_FS
229 231
230/* 232/*
@@ -232,7 +234,6 @@ static inline CommandList_struct *removeQ(CommandList_struct **Qptr,
232 */ 234 */
233#define ENG_GIG 1000000000 235#define ENG_GIG 1000000000
234#define ENG_GIG_FACTOR (ENG_GIG/512) 236#define ENG_GIG_FACTOR (ENG_GIG/512)
235#define RAID_UNKNOWN 6
236static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG", 237static const char *raid_label[] = { "0", "4", "1(1+0)", "5", "5+1", "ADG",
237 "UNKNOWN" 238 "UNKNOWN"
238}; 239};
@@ -1907,6 +1908,7 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
1907 "does not support reading geometry\n"); 1908 "does not support reading geometry\n");
1908 drv->heads = 255; 1909 drv->heads = 255;
1909 drv->sectors = 32; // Sectors per track 1910 drv->sectors = 32; // Sectors per track
1911 drv->raid_level = RAID_UNKNOWN;
1910 } else { 1912 } else {
1911 drv->heads = inq_buff->data_byte[6]; 1913 drv->heads = inq_buff->data_byte[6];
1912 drv->sectors = inq_buff->data_byte[7]; 1914 drv->sectors = inq_buff->data_byte[7];
@@ -2491,7 +2493,7 @@ static void do_cciss_request(request_queue_t *q)
2491 c->Request.Type.Type = TYPE_CMD; // It is a command. 2493 c->Request.Type.Type = TYPE_CMD; // It is a command.
2492 c->Request.Type.Attribute = ATTR_SIMPLE; 2494 c->Request.Type.Attribute = ATTR_SIMPLE;
2493 c->Request.Type.Direction = 2495 c->Request.Type.Direction =
2494 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 2496 (rq_data_dir(creq) == READ) ? XFER_READ : XFER_WRITE;
2495 c->Request.Timeout = 0; // Don't time out 2497 c->Request.Timeout = 0; // Don't time out
2496 c->Request.CDB[0] = 2498 c->Request.CDB[0] =
2497 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 2499 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index e19ba4ebcd4e..68592c336011 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -49,6 +49,7 @@
49#include <asm/iseries/hv_lp_event.h> 49#include <asm/iseries/hv_lp_event.h>
50#include <asm/iseries/hv_lp_config.h> 50#include <asm/iseries/hv_lp_config.h>
51#include <asm/iseries/vio.h> 51#include <asm/iseries/vio.h>
52#include <asm/firmware.h>
52 53
53MODULE_DESCRIPTION("iSeries Virtual DASD"); 54MODULE_DESCRIPTION("iSeries Virtual DASD");
54MODULE_AUTHOR("Dave Boutcher"); 55MODULE_AUTHOR("Dave Boutcher");
@@ -769,6 +770,11 @@ static int __init viodasd_init(void)
769{ 770{
770 int rc; 771 int rc;
771 772
773 if (!firmware_has_feature(FW_FEATURE_ISERIES)) {
774 rc = -ENODEV;
775 goto early_fail;
776 }
777
772 /* Try to open to our host lp */ 778 /* Try to open to our host lp */
773 if (viopath_hostLp == HvLpIndexInvalid) 779 if (viopath_hostLp == HvLpIndexInvalid)
774 vio_set_hostlp(); 780 vio_set_hostlp();
diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c
index fdea58ae16b2..aeefec97fdee 100644
--- a/drivers/bluetooth/hci_usb.c
+++ b/drivers/bluetooth/hci_usb.c
@@ -126,6 +126,7 @@ static struct usb_device_id blacklist_ids[] = {
126 126
127 /* Kensington Bluetooth USB adapter */ 127 /* Kensington Bluetooth USB adapter */
128 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET }, 128 { USB_DEVICE(0x047d, 0x105d), .driver_info = HCI_RESET },
129 { USB_DEVICE(0x047d, 0x105e), .driver_info = HCI_WRONG_SCO_MTU },
129 130
130 /* ISSC Bluetooth Adapter v3.1 */ 131 /* ISSC Bluetooth Adapter v3.1 */
131 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET }, 132 { USB_DEVICE(0x1131, 0x1001), .driver_info = HCI_RESET },
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index e4a2f8f3a1d7..66d028d30439 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2139,8 +2139,7 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2139 cdi->last_sense = s->sense_key; 2139 cdi->last_sense = s->sense_key;
2140 } 2140 }
2141 2141
2142 rq->bio = bio; 2142 if (blk_rq_unmap_user(bio))
2143 if (blk_rq_unmap_user(rq))
2144 ret = -EFAULT; 2143 ret = -EFAULT;
2145 2144
2146 if (ret) 2145 if (ret)
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 54ca931e19ea..93fbf84dcc4a 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -47,6 +47,7 @@
47#include <asm/iseries/hv_types.h> 47#include <asm/iseries/hv_types.h>
48#include <asm/iseries/hv_lp_event.h> 48#include <asm/iseries/hv_lp_event.h>
49#include <asm/iseries/vio.h> 49#include <asm/iseries/vio.h>
50#include <asm/firmware.h>
50 51
51#define VIOCD_DEVICE "iseries/vcd" 52#define VIOCD_DEVICE "iseries/vcd"
52 53
@@ -748,6 +749,9 @@ static int __init viocd_init(void)
748 struct proc_dir_entry *e; 749 struct proc_dir_entry *e;
749 int ret = 0; 750 int ret = 0;
750 751
752 if (!firmware_has_feature(FW_FEATURE_ISERIES))
753 return -ENODEV;
754
751 if (viopath_hostLp == HvLpIndexInvalid) { 755 if (viopath_hostLp == HvLpIndexInvalid) {
752 vio_set_hostlp(); 756 vio_set_hostlp();
753 /* If we don't have a host, bail out */ 757 /* If we don't have a host, bail out */
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 0bbb04f2390f..6dcdceb81203 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -561,8 +561,7 @@ struct drm_driver {
561 int (*context_dtor) (struct drm_device * dev, int context); 561 int (*context_dtor) (struct drm_device * dev, int context);
562 int (*kernel_context_switch) (struct drm_device * dev, int old, 562 int (*kernel_context_switch) (struct drm_device * dev, int old,
563 int new); 563 int new);
564 void (*kernel_context_switch_unlock) (struct drm_device * dev, 564 void (*kernel_context_switch_unlock) (struct drm_device * dev);
565 drm_lock_t *lock);
566 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); 565 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
567 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence); 566 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
568 int (*dri_library_name) (struct drm_device *dev, char *buf); 567 int (*dri_library_name) (struct drm_device *dev, char *buf);
@@ -1143,9 +1142,5 @@ extern void *drm_calloc(size_t nmemb, size_t size, int area);
1143extern unsigned long drm_core_get_map_ofs(drm_map_t * map); 1142extern unsigned long drm_core_get_map_ofs(drm_map_t * map);
1144extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev); 1143extern unsigned long drm_core_get_reg_ofs(struct drm_device *dev);
1145 1144
1146#ifndef pci_pretty_name
1147#define pci_pretty_name(dev) ""
1148#endif
1149
1150#endif /* __KERNEL__ */ 1145#endif /* __KERNEL__ */
1151#endif 1146#endif
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index 116ed0f2ac09..e9993ba461a2 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -182,7 +182,7 @@ int drm_unlock(struct inode *inode, struct file *filp,
182 * modules but is required by the Sparc driver. 182 * modules but is required by the Sparc driver.
183 */ 183 */
184 if (dev->driver->kernel_context_switch_unlock) 184 if (dev->driver->kernel_context_switch_unlock)
185 dev->driver->kernel_context_switch_unlock(dev, &lock); 185 dev->driver->kernel_context_switch_unlock(dev);
186 else { 186 else {
187 drm_lock_transfer(dev, &dev->lock.hw_lock->lock, 187 drm_lock_transfer(dev, &dev->lock.hw_lock->lock,
188 DRM_KERNEL_CONTEXT); 188 DRM_KERNEL_CONTEXT);
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 5fd6dc0870cf..120d10256feb 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -211,14 +211,16 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
211 if (!dev) 211 if (!dev)
212 return -ENOMEM; 212 return -ENOMEM;
213 213
214 pci_enable_device(pdev); 214 ret = pci_enable_device(pdev);
215 if (ret)
216 goto err_g1;
215 217
216 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) { 218 if ((ret = drm_fill_in_dev(dev, pdev, ent, driver))) {
217 printk(KERN_ERR "DRM: Fill_in_dev failed.\n"); 219 printk(KERN_ERR "DRM: Fill_in_dev failed.\n");
218 goto err_g1; 220 goto err_g2;
219 } 221 }
220 if ((ret = drm_get_head(dev, &dev->primary))) 222 if ((ret = drm_get_head(dev, &dev->primary)))
221 goto err_g1; 223 goto err_g2;
222 224
223 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n", 225 DRM_INFO("Initialized %s %d.%d.%d %s on minor %d\n",
224 driver->name, driver->major, driver->minor, driver->patchlevel, 226 driver->name, driver->major, driver->minor, driver->patchlevel,
@@ -226,7 +228,9 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
226 228
227 return 0; 229 return 0;
228 230
229 err_g1: 231err_g2:
232 pci_disable_device(pdev);
233err_g1:
230 drm_free(dev, sizeof(*dev), DRM_MEM_STUB); 234 drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
231 return ret; 235 return ret;
232} 236}
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index ba4b8de83cf0..cc8e2ebe128c 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -45,8 +45,8 @@ struct class *drm_sysfs_create(struct module *owner, char *name)
45 int err; 45 int err;
46 46
47 class = class_create(owner, name); 47 class = class_create(owner, name);
48 if (!class) { 48 if (IS_ERR(class)) {
49 err = -ENOMEM; 49 err = PTR_ERR(class);
50 goto err_out; 50 goto err_out;
51 } 51 }
52 52
@@ -113,8 +113,8 @@ struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head)
113 MKDEV(DRM_MAJOR, head->minor), 113 MKDEV(DRM_MAJOR, head->minor),
114 &(head->dev->pdev)->dev, 114 &(head->dev->pdev)->dev,
115 "card%d", head->minor); 115 "card%d", head->minor);
116 if (!class_dev) { 116 if (IS_ERR(class_dev)) {
117 err = -ENOMEM; 117 err = PTR_ERR(class_dev);
118 goto err_out; 118 goto err_out;
119 } 119 }
120 120
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index e5463b111fc0..e2c4b3a41b1e 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -46,88 +46,167 @@ static void i915_vblank_tasklet(drm_device_t *dev)
46{ 46{
47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
48 unsigned long irqflags; 48 unsigned long irqflags;
49 struct list_head *list, *tmp; 49 struct list_head *list, *tmp, hits, *hit;
50 int nhits, nrects, slice[2], upper[2], lower[2], i;
51 unsigned counter[2] = { atomic_read(&dev->vbl_received),
52 atomic_read(&dev->vbl_received2) };
53 drm_drawable_info_t *drw;
54 drm_i915_sarea_t *sarea_priv = dev_priv->sarea_priv;
55 u32 cpp = dev_priv->cpp;
56 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
57 XY_SRC_COPY_BLT_WRITE_ALPHA |
58 XY_SRC_COPY_BLT_WRITE_RGB)
59 : XY_SRC_COPY_BLT_CMD;
60 u32 pitchropcpp = (sarea_priv->pitch * cpp) | (0xcc << 16) |
61 (cpp << 23) | (1 << 24);
62 RING_LOCALS;
50 63
51 DRM_DEBUG("\n"); 64 DRM_DEBUG("\n");
52 65
66 INIT_LIST_HEAD(&hits);
67
68 nhits = nrects = 0;
69
53 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags); 70 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
54 71
72 /* Find buffer swaps scheduled for this vertical blank */
55 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) { 73 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
56 drm_i915_vbl_swap_t *vbl_swap = 74 drm_i915_vbl_swap_t *vbl_swap =
57 list_entry(list, drm_i915_vbl_swap_t, head); 75 list_entry(list, drm_i915_vbl_swap_t, head);
58 atomic_t *counter = vbl_swap->pipe ? &dev->vbl_received2 :
59 &dev->vbl_received;
60
61 if ((atomic_read(counter) - vbl_swap->sequence) <= (1<<23)) {
62 drm_drawable_info_t *drw;
63
64 spin_unlock(&dev_priv->swaps_lock);
65
66 spin_lock(&dev->drw_lock);
67
68 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
69
70 if (drw) {
71 int i, num_rects = drw->num_rects;
72 drm_clip_rect_t *rect = drw->rects;
73 drm_i915_sarea_t *sarea_priv =
74 dev_priv->sarea_priv;
75 u32 cpp = dev_priv->cpp;
76 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
77 XY_SRC_COPY_BLT_WRITE_ALPHA |
78 XY_SRC_COPY_BLT_WRITE_RGB)
79 : XY_SRC_COPY_BLT_CMD;
80 u32 pitchropcpp = (sarea_priv->pitch * cpp) |
81 (0xcc << 16) | (cpp << 23) |
82 (1 << 24);
83 RING_LOCALS;
84
85 i915_kernel_lost_context(dev);
86
87 BEGIN_LP_RING(6);
88
89 OUT_RING(GFX_OP_DRAWRECT_INFO);
90 OUT_RING(0);
91 OUT_RING(0);
92 OUT_RING(sarea_priv->width |
93 sarea_priv->height << 16);
94 OUT_RING(sarea_priv->width |
95 sarea_priv->height << 16);
96 OUT_RING(0);
97 76
98 ADVANCE_LP_RING(); 77 if ((counter[vbl_swap->pipe] - vbl_swap->sequence) > (1<<23))
78 continue;
79
80 list_del(list);
81 dev_priv->swaps_pending--;
99 82
100 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT; 83 spin_unlock(&dev_priv->swaps_lock);
84 spin_lock(&dev->drw_lock);
101 85
102 for (i = 0; i < num_rects; i++, rect++) { 86 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
103 BEGIN_LP_RING(8); 87
88 if (!drw) {
89 spin_unlock(&dev->drw_lock);
90 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
91 spin_lock(&dev_priv->swaps_lock);
92 continue;
93 }
104 94
105 OUT_RING(cmd); 95 list_for_each(hit, &hits) {
106 OUT_RING(pitchropcpp); 96 drm_i915_vbl_swap_t *swap_cmp =
107 OUT_RING((rect->y1 << 16) | rect->x1); 97 list_entry(hit, drm_i915_vbl_swap_t, head);
108 OUT_RING((rect->y2 << 16) | rect->x2); 98 drm_drawable_info_t *drw_cmp =
109 OUT_RING(sarea_priv->front_offset); 99 drm_get_drawable_info(dev, swap_cmp->drw_id);
110 OUT_RING((rect->y1 << 16) | rect->x1);
111 OUT_RING(pitchropcpp & 0xffff);
112 OUT_RING(sarea_priv->back_offset);
113 100
114 ADVANCE_LP_RING(); 101 if (drw_cmp &&
115 } 102 drw_cmp->rects[0].y1 > drw->rects[0].y1) {
103 list_add_tail(list, hit);
104 break;
116 } 105 }
106 }
117 107
118 spin_unlock(&dev->drw_lock); 108 spin_unlock(&dev->drw_lock);
119 109
120 spin_lock(&dev_priv->swaps_lock); 110 /* List of hits was empty, or we reached the end of it */
111 if (hit == &hits)
112 list_add_tail(list, hits.prev);
121 113
122 list_del(list); 114 nhits++;
123 115
124 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER); 116 spin_lock(&dev_priv->swaps_lock);
117 }
118
119 if (nhits == 0) {
120 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
121 return;
122 }
123
124 spin_unlock(&dev_priv->swaps_lock);
125 125
126 dev_priv->swaps_pending--; 126 i915_kernel_lost_context(dev);
127
128 BEGIN_LP_RING(6);
129
130 OUT_RING(GFX_OP_DRAWRECT_INFO);
131 OUT_RING(0);
132 OUT_RING(0);
133 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
134 OUT_RING(sarea_priv->width | sarea_priv->height << 16);
135 OUT_RING(0);
136
137 ADVANCE_LP_RING();
138
139 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
140
141 upper[0] = upper[1] = 0;
142 slice[0] = max(sarea_priv->pipeA_h / nhits, 1);
143 slice[1] = max(sarea_priv->pipeB_h / nhits, 1);
144 lower[0] = sarea_priv->pipeA_y + slice[0];
145 lower[1] = sarea_priv->pipeB_y + slice[0];
146
147 spin_lock(&dev->drw_lock);
148
149 /* Emit blits for buffer swaps, partitioning both outputs into as many
150 * slices as there are buffer swaps scheduled in order to avoid tearing
151 * (based on the assumption that a single buffer swap would always
152 * complete before scanout starts).
153 */
154 for (i = 0; i++ < nhits;
155 upper[0] = lower[0], lower[0] += slice[0],
156 upper[1] = lower[1], lower[1] += slice[1]) {
157 if (i == nhits)
158 lower[0] = lower[1] = sarea_priv->height;
159
160 list_for_each(hit, &hits) {
161 drm_i915_vbl_swap_t *swap_hit =
162 list_entry(hit, drm_i915_vbl_swap_t, head);
163 drm_clip_rect_t *rect;
164 int num_rects, pipe;
165 unsigned short top, bottom;
166
167 drw = drm_get_drawable_info(dev, swap_hit->drw_id);
168
169 if (!drw)
170 continue;
171
172 rect = drw->rects;
173 pipe = swap_hit->pipe;
174 top = upper[pipe];
175 bottom = lower[pipe];
176
177 for (num_rects = drw->num_rects; num_rects--; rect++) {
178 int y1 = max(rect->y1, top);
179 int y2 = min(rect->y2, bottom);
180
181 if (y1 >= y2)
182 continue;
183
184 BEGIN_LP_RING(8);
185
186 OUT_RING(cmd);
187 OUT_RING(pitchropcpp);
188 OUT_RING((y1 << 16) | rect->x1);
189 OUT_RING((y2 << 16) | rect->x2);
190 OUT_RING(sarea_priv->front_offset);
191 OUT_RING((y1 << 16) | rect->x1);
192 OUT_RING(pitchropcpp & 0xffff);
193 OUT_RING(sarea_priv->back_offset);
194
195 ADVANCE_LP_RING();
196 }
127 } 197 }
128 } 198 }
129 199
130 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags); 200 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
201
202 list_for_each_safe(hit, tmp, &hits) {
203 drm_i915_vbl_swap_t *swap_hit =
204 list_entry(hit, drm_i915_vbl_swap_t, head);
205
206 list_del(hit);
207
208 drm_free(swap_hit, sizeof(*swap_hit), DRM_MEM_DRIVER);
209 }
131} 210}
132 211
133irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 212irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
diff --git a/drivers/char/drm/r128_drm.h b/drivers/char/drm/r128_drm.h
index 5d835b006f55..6e8af313f2b4 100644
--- a/drivers/char/drm/r128_drm.h
+++ b/drivers/char/drm/r128_drm.h
@@ -1,7 +1,8 @@
1/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*- 1/* r128_drm.h -- Public header for the r128 driver -*- linux-c -*-
2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com 2 * Created: Wed Apr 5 19:24:19 2000 by kevin@precisioninsight.com
3 */ 3 */
4/* Copyright 2000 Precision Insight, Inc., Cedar Park, Texas. 4/*
5 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved. 7 * All rights reserved.
7 * 8 *
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h
index 94abffb2cca5..f1efb49de8df 100644
--- a/drivers/char/drm/r128_drv.h
+++ b/drivers/char/drm/r128_drv.h
@@ -1,7 +1,8 @@
1/* r128_drv.h -- Private header for r128 driver -*- linux-c -*- 1/* r128_drv.h -- Private header for r128 driver -*- linux-c -*-
2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com 2 * Created: Mon Dec 13 09:51:11 1999 by faith@precisioninsight.com
3 */ 3 */
4/* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 4/*
5 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 6 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved. 7 * All rights reserved.
7 * 8 *
diff --git a/drivers/char/drm/r128_state.c b/drivers/char/drm/r128_state.c
index a080cdd6081e..17b11e7d8f32 100644
--- a/drivers/char/drm/r128_state.c
+++ b/drivers/char/drm/r128_state.c
@@ -1,7 +1,8 @@
1/* r128_state.c -- State support for r128 -*- linux-c -*- 1/* r128_state.c -- State support for r128 -*- linux-c -*-
2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com 2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
3 */ 3 */
4/* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 4/*
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
5 * All Rights Reserved. 6 * All Rights Reserved.
6 * 7 *
7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * Permission is hereby granted, free of charge, to any person obtaining a
diff --git a/drivers/char/drm/r300_cmdbuf.c b/drivers/char/drm/r300_cmdbuf.c
index d14477ba3679..032a022ec6a8 100644
--- a/drivers/char/drm/r300_cmdbuf.c
+++ b/drivers/char/drm/r300_cmdbuf.c
@@ -242,26 +242,6 @@ static __inline__ int r300_check_range(unsigned reg, int count)
242 return 0; 242 return 0;
243} 243}
244 244
245/*
246 * we expect offsets passed to the framebuffer to be either within video
247 * memory or within AGP space
248 */
249static __inline__ int r300_check_offset(drm_radeon_private_t *dev_priv,
250 u32 offset)
251{
252 /* we realy want to check against end of video aperture
253 but this value is not being kept.
254 This code is correct for now (does the same thing as the
255 code that sets MC_FB_LOCATION) in radeon_cp.c */
256 if (offset >= dev_priv->fb_location &&
257 offset < (dev_priv->fb_location + dev_priv->fb_size))
258 return 0;
259 if (offset >= dev_priv->gart_vm_start &&
260 offset < (dev_priv->gart_vm_start + dev_priv->gart_size))
261 return 0;
262 return 1;
263}
264
265static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t * 245static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
266 dev_priv, 246 dev_priv,
267 drm_radeon_kcmd_buffer_t 247 drm_radeon_kcmd_buffer_t
@@ -290,7 +270,7 @@ static __inline__ int r300_emit_carefully_checked_packet0(drm_radeon_private_t *
290 case MARK_SAFE: 270 case MARK_SAFE:
291 break; 271 break;
292 case MARK_CHECK_OFFSET: 272 case MARK_CHECK_OFFSET:
293 if (r300_check_offset(dev_priv, (u32) values[i])) { 273 if (!radeon_check_offset(dev_priv, (u32) values[i])) {
294 DRM_ERROR 274 DRM_ERROR
295 ("Offset failed range check (reg=%04x sz=%d)\n", 275 ("Offset failed range check (reg=%04x sz=%d)\n",
296 reg, sz); 276 reg, sz);
@@ -452,7 +432,7 @@ static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
452 i = 1; 432 i = 1;
453 while ((k < narrays) && (i < (count + 1))) { 433 while ((k < narrays) && (i < (count + 1))) {
454 i++; /* skip attribute field */ 434 i++; /* skip attribute field */
455 if (r300_check_offset(dev_priv, payload[i])) { 435 if (!radeon_check_offset(dev_priv, payload[i])) {
456 DRM_ERROR 436 DRM_ERROR
457 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n", 437 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
458 k, i); 438 k, i);
@@ -463,7 +443,7 @@ static __inline__ int r300_emit_3d_load_vbpntr(drm_radeon_private_t *dev_priv,
463 if (k == narrays) 443 if (k == narrays)
464 break; 444 break;
465 /* have one more to process, they come in pairs */ 445 /* have one more to process, they come in pairs */
466 if (r300_check_offset(dev_priv, payload[i])) { 446 if (!radeon_check_offset(dev_priv, payload[i])) {
467 DRM_ERROR 447 DRM_ERROR
468 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n", 448 ("Offset failed range check (k=%d i=%d) while processing 3D_LOAD_VBPNTR packet.\n",
469 k, i); 449 k, i);
@@ -508,7 +488,7 @@ static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
508 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL 488 if (cmd[1] & (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
509 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) { 489 | RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
510 offset = cmd[2] << 10; 490 offset = cmd[2] << 10;
511 ret = r300_check_offset(dev_priv, offset); 491 ret = !radeon_check_offset(dev_priv, offset);
512 if (ret) { 492 if (ret) {
513 DRM_ERROR("Invalid bitblt first offset is %08X\n", offset); 493 DRM_ERROR("Invalid bitblt first offset is %08X\n", offset);
514 return DRM_ERR(EINVAL); 494 return DRM_ERR(EINVAL);
@@ -518,7 +498,7 @@ static __inline__ int r300_emit_bitblt_multi(drm_radeon_private_t *dev_priv,
518 if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) && 498 if ((cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL) &&
519 (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) { 499 (cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL)) {
520 offset = cmd[3] << 10; 500 offset = cmd[3] << 10;
521 ret = r300_check_offset(dev_priv, offset); 501 ret = !radeon_check_offset(dev_priv, offset);
522 if (ret) { 502 if (ret) {
523 DRM_ERROR("Invalid bitblt second offset is %08X\n", offset); 503 DRM_ERROR("Invalid bitblt second offset is %08X\n", offset);
524 return DRM_ERR(EINVAL); 504 return DRM_ERR(EINVAL);
@@ -551,7 +531,7 @@ static __inline__ int r300_emit_indx_buffer(drm_radeon_private_t *dev_priv,
551 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]); 531 DRM_ERROR("Invalid indx_buffer reg address %08X\n", cmd[1]);
552 return DRM_ERR(EINVAL); 532 return DRM_ERR(EINVAL);
553 } 533 }
554 ret = r300_check_offset(dev_priv, cmd[2]); 534 ret = !radeon_check_offset(dev_priv, cmd[2]);
555 if (ret) { 535 if (ret) {
556 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]); 536 DRM_ERROR("Invalid indx_buffer offset is %08X\n", cmd[2]);
557 return DRM_ERR(EINVAL); 537 return DRM_ERR(EINVAL);
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index f45cd7f147a5..8b105f1460a7 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -303,6 +303,21 @@ extern int radeon_no_wb;
303extern drm_ioctl_desc_t radeon_ioctls[]; 303extern drm_ioctl_desc_t radeon_ioctls[];
304extern int radeon_max_ioctl; 304extern int radeon_max_ioctl;
305 305
306/* Check whether the given hardware address is inside the framebuffer or the
307 * GART area.
308 */
309static __inline__ int radeon_check_offset(drm_radeon_private_t *dev_priv,
310 u64 off)
311{
312 u32 fb_start = dev_priv->fb_location;
313 u32 fb_end = fb_start + dev_priv->fb_size - 1;
314 u32 gart_start = dev_priv->gart_vm_start;
315 u32 gart_end = gart_start + dev_priv->gart_size - 1;
316
317 return ((off >= fb_start && off <= fb_end) ||
318 (off >= gart_start && off <= gart_end));
319}
320
306 /* radeon_cp.c */ 321 /* radeon_cp.c */
307extern int radeon_cp_init(DRM_IOCTL_ARGS); 322extern int radeon_cp_init(DRM_IOCTL_ARGS);
308extern int radeon_cp_start(DRM_IOCTL_ARGS); 323extern int radeon_cp_start(DRM_IOCTL_ARGS);
diff --git a/drivers/char/drm/radeon_irq.c b/drivers/char/drm/radeon_irq.c
index d60519de887b..3ff0baa2fbfa 100644
--- a/drivers/char/drm/radeon_irq.c
+++ b/drivers/char/drm/radeon_irq.c
@@ -1,5 +1,5 @@
1/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- 1/* radeon_irq.c -- IRQ handling for radeon -*- linux-c -*- */
2 * 2/*
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 * 4 *
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
diff --git a/drivers/char/drm/radeon_mem.c b/drivers/char/drm/radeon_mem.c
index 030a6fad0d86..517cad8b6e3a 100644
--- a/drivers/char/drm/radeon_mem.c
+++ b/drivers/char/drm/radeon_mem.c
@@ -1,5 +1,5 @@
1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- 1/* radeon_mem.c -- Simple GART/fb memory manager for radeon -*- linux-c -*- */
2 * 2/*
3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. 3 * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4 * 4 *
5 * The Weather Channel (TM) funded Tungsten Graphics to develop the 5 * The Weather Channel (TM) funded Tungsten Graphics to develop the
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 6e04fdd732ac..938eccb78cc0 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -43,10 +43,7 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
43 u32 *offset) 43 u32 *offset)
44{ 44{
45 u64 off = *offset; 45 u64 off = *offset;
46 u32 fb_start = dev_priv->fb_location; 46 u32 fb_end = dev_priv->fb_location + dev_priv->fb_size - 1;
47 u32 fb_end = fb_start + dev_priv->fb_size - 1;
48 u32 gart_start = dev_priv->gart_vm_start;
49 u32 gart_end = gart_start + dev_priv->gart_size - 1;
50 struct drm_radeon_driver_file_fields *radeon_priv; 47 struct drm_radeon_driver_file_fields *radeon_priv;
51 48
52 /* Hrm ... the story of the offset ... So this function converts 49 /* Hrm ... the story of the offset ... So this function converts
@@ -66,8 +63,7 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
66 /* First, the best case, the offset already lands in either the 63 /* First, the best case, the offset already lands in either the
67 * framebuffer or the GART mapped space 64 * framebuffer or the GART mapped space
68 */ 65 */
69 if ((off >= fb_start && off <= fb_end) || 66 if (radeon_check_offset(dev_priv, off))
70 (off >= gart_start && off <= gart_end))
71 return 0; 67 return 0;
72 68
73 /* Ok, that didn't happen... now check if we have a zero based 69 /* Ok, that didn't happen... now check if we have a zero based
@@ -81,11 +77,10 @@ static __inline__ int radeon_check_and_fixup_offset(drm_radeon_private_t *
81 77
82 /* Finally, assume we aimed at a GART offset if beyond the fb */ 78 /* Finally, assume we aimed at a GART offset if beyond the fb */
83 if (off > fb_end) 79 if (off > fb_end)
84 off = off - fb_end - 1 + gart_start; 80 off = off - fb_end - 1 + dev_priv->gart_vm_start;
85 81
86 /* Now recheck and fail if out of bounds */ 82 /* Now recheck and fail if out of bounds */
87 if ((off >= fb_start && off <= fb_end) || 83 if (radeon_check_offset(dev_priv, off)) {
88 (off >= gart_start && off <= gart_end)) {
89 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off); 84 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off);
90 *offset = off; 85 *offset = off;
91 return 0; 86 return 0;
diff --git a/drivers/char/drm/savage_bci.c b/drivers/char/drm/savage_bci.c
index a9a84f88df5e..b94fab556809 100644
--- a/drivers/char/drm/savage_bci.c
+++ b/drivers/char/drm/savage_bci.c
@@ -963,8 +963,8 @@ static int savage_bci_event_emit(DRM_IOCTL_ARGS)
963 963
964 event.count = savage_bci_emit_event(dev_priv, event.flags); 964 event.count = savage_bci_emit_event(dev_priv, event.flags);
965 event.count |= dev_priv->event_wrap << 16; 965 event.count |= dev_priv->event_wrap << 16;
966 DRM_COPY_TO_USER_IOCTL(&((drm_savage_event_emit_t __user *) data)-> 966 DRM_COPY_TO_USER_IOCTL((drm_savage_event_emit_t __user *) data,
967 count, event.count, sizeof(event.count)); 967 event, sizeof(event));
968 return 0; 968 return 0;
969} 969}
970 970
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 78280380a905..6b634e8d9519 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -216,13 +216,13 @@ static int set_param_str(const char *val, struct kernel_param *kp)
216{ 216{
217 action_fn fn = (action_fn) kp->arg; 217 action_fn fn = (action_fn) kp->arg;
218 int rv = 0; 218 int rv = 0;
219 char *dup, *s; 219 char valcp[16];
220 char *s;
220 221
221 dup = kstrdup(val, GFP_KERNEL); 222 strncpy(valcp, val, 16);
222 if (!dup) 223 valcp[15] = '\0';
223 return -ENOMEM;
224 224
225 s = strstrip(dup); 225 s = strstrip(valcp);
226 226
227 down_read(&register_sem); 227 down_read(&register_sem);
228 rv = fn(s, NULL); 228 rv = fn(s, NULL);
@@ -235,7 +235,6 @@ static int set_param_str(const char *val, struct kernel_param *kp)
235 235
236 out_unlock: 236 out_unlock:
237 up_read(&register_sem); 237 up_read(&register_sem);
238 kfree(dup);
239 return rv; 238 return rv;
240} 239}
241 240
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 5a747e685993..01084abffddf 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -230,6 +230,20 @@ static struct isi_port isi_ports[PORT_COUNT];
230 * it wants to talk. 230 * it wants to talk.
231 */ 231 */
232 232
233static inline int WaitTillCardIsFree(u16 base)
234{
235 unsigned int count = 0;
236 unsigned int a = in_atomic(); /* do we run under spinlock? */
237
238 while (!(inw(base + 0xe) & 0x1) && count++ < 100)
239 if (a)
240 mdelay(1);
241 else
242 msleep(1);
243
244 return !(inw(base + 0xe) & 0x1);
245}
246
233static int lock_card(struct isi_board *card) 247static int lock_card(struct isi_board *card)
234{ 248{
235 char retries; 249 char retries;
@@ -276,69 +290,71 @@ static void unlock_card(struct isi_board *card)
276 * ISI Card specific ops ... 290 * ISI Card specific ops ...
277 */ 291 */
278 292
293/* card->lock HAS to be held */
279static void raise_dtr(struct isi_port *port) 294static void raise_dtr(struct isi_port *port)
280{ 295{
281 struct isi_board *card = port->card; 296 struct isi_board *card = port->card;
282 unsigned long base = card->base; 297 unsigned long base = card->base;
283 u16 channel = port->channel; 298 u16 channel = port->channel;
284 299
285 if (!lock_card(card)) 300 if (WaitTillCardIsFree(base))
286 return; 301 return;
287 302
288 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 303 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
289 outw(0x0504, base); 304 outw(0x0504, base);
290 InterruptTheCard(base); 305 InterruptTheCard(base);
291 port->status |= ISI_DTR; 306 port->status |= ISI_DTR;
292 unlock_card(card);
293} 307}
294 308
309/* card->lock HAS to be held */
295static inline void drop_dtr(struct isi_port *port) 310static inline void drop_dtr(struct isi_port *port)
296{ 311{
297 struct isi_board *card = port->card; 312 struct isi_board *card = port->card;
298 unsigned long base = card->base; 313 unsigned long base = card->base;
299 u16 channel = port->channel; 314 u16 channel = port->channel;
300 315
301 if (!lock_card(card)) 316 if (WaitTillCardIsFree(base))
302 return; 317 return;
303 318
304 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 319 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
305 outw(0x0404, base); 320 outw(0x0404, base);
306 InterruptTheCard(base); 321 InterruptTheCard(base);
307 port->status &= ~ISI_DTR; 322 port->status &= ~ISI_DTR;
308 unlock_card(card);
309} 323}
310 324
325/* card->lock HAS to be held */
311static inline void raise_rts(struct isi_port *port) 326static inline void raise_rts(struct isi_port *port)
312{ 327{
313 struct isi_board *card = port->card; 328 struct isi_board *card = port->card;
314 unsigned long base = card->base; 329 unsigned long base = card->base;
315 u16 channel = port->channel; 330 u16 channel = port->channel;
316 331
317 if (!lock_card(card)) 332 if (WaitTillCardIsFree(base))
318 return; 333 return;
319 334
320 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 335 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
321 outw(0x0a04, base); 336 outw(0x0a04, base);
322 InterruptTheCard(base); 337 InterruptTheCard(base);
323 port->status |= ISI_RTS; 338 port->status |= ISI_RTS;
324 unlock_card(card);
325} 339}
340
341/* card->lock HAS to be held */
326static inline void drop_rts(struct isi_port *port) 342static inline void drop_rts(struct isi_port *port)
327{ 343{
328 struct isi_board *card = port->card; 344 struct isi_board *card = port->card;
329 unsigned long base = card->base; 345 unsigned long base = card->base;
330 u16 channel = port->channel; 346 u16 channel = port->channel;
331 347
332 if (!lock_card(card)) 348 if (WaitTillCardIsFree(base))
333 return; 349 return;
334 350
335 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 351 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
336 outw(0x0804, base); 352 outw(0x0804, base);
337 InterruptTheCard(base); 353 InterruptTheCard(base);
338 port->status &= ~ISI_RTS; 354 port->status &= ~ISI_RTS;
339 unlock_card(card);
340} 355}
341 356
357/* card->lock MUST NOT be held */
342static inline void raise_dtr_rts(struct isi_port *port) 358static inline void raise_dtr_rts(struct isi_port *port)
343{ 359{
344 struct isi_board *card = port->card; 360 struct isi_board *card = port->card;
@@ -355,35 +371,20 @@ static inline void raise_dtr_rts(struct isi_port *port)
355 unlock_card(card); 371 unlock_card(card);
356} 372}
357 373
374/* card->lock HAS to be held */
358static void drop_dtr_rts(struct isi_port *port) 375static void drop_dtr_rts(struct isi_port *port)
359{ 376{
360 struct isi_board *card = port->card; 377 struct isi_board *card = port->card;
361 unsigned long base = card->base; 378 unsigned long base = card->base;
362 u16 channel = port->channel; 379 u16 channel = port->channel;
363 380
364 if (!lock_card(card)) 381 if (WaitTillCardIsFree(base))
365 return; 382 return;
366 383
367 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 384 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
368 outw(0x0c04, base); 385 outw(0x0c04, base);
369 InterruptTheCard(base); 386 InterruptTheCard(base);
370 port->status &= ~(ISI_RTS | ISI_DTR); 387 port->status &= ~(ISI_RTS | ISI_DTR);
371 unlock_card(card);
372}
373
374static inline void kill_queue(struct isi_port *port, short queue)
375{
376 struct isi_board *card = port->card;
377 unsigned long base = card->base;
378 u16 channel = port->channel;
379
380 if (!lock_card(card))
381 return;
382
383 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
384 outw((queue << 8) | 0x06, base);
385 InterruptTheCard(base);
386 unlock_card(card);
387} 388}
388 389
389/* 390/*
@@ -744,7 +745,7 @@ static void isicom_config_port(struct isi_port *port)
744 else 745 else
745 raise_dtr(port); 746 raise_dtr(port);
746 747
747 if (lock_card(card)) { 748 if (WaitTillCardIsFree(base) == 0) {
748 outw(0x8000 | (channel << shift_count) |0x03, base); 749 outw(0x8000 | (channel << shift_count) |0x03, base);
749 outw(linuxb_to_isib[baud] << 8 | 0x03, base); 750 outw(linuxb_to_isib[baud] << 8 | 0x03, base);
750 channel_setup = 0; 751 channel_setup = 0;
@@ -772,7 +773,6 @@ static void isicom_config_port(struct isi_port *port)
772 } 773 }
773 outw(channel_setup, base); 774 outw(channel_setup, base);
774 InterruptTheCard(base); 775 InterruptTheCard(base);
775 unlock_card(card);
776 } 776 }
777 if (C_CLOCAL(tty)) 777 if (C_CLOCAL(tty))
778 port->flags &= ~ASYNC_CHECK_CD; 778 port->flags &= ~ASYNC_CHECK_CD;
@@ -791,12 +791,11 @@ static void isicom_config_port(struct isi_port *port)
791 if (I_IXOFF(tty)) 791 if (I_IXOFF(tty))
792 flow_ctrl |= ISICOM_INITIATE_XONXOFF; 792 flow_ctrl |= ISICOM_INITIATE_XONXOFF;
793 793
794 if (lock_card(card)) { 794 if (WaitTillCardIsFree(base) == 0) {
795 outw(0x8000 | (channel << shift_count) |0x04, base); 795 outw(0x8000 | (channel << shift_count) |0x04, base);
796 outw(flow_ctrl << 8 | 0x05, base); 796 outw(flow_ctrl << 8 | 0x05, base);
797 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base); 797 outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base);
798 InterruptTheCard(base); 798 InterruptTheCard(base);
799 unlock_card(card);
800 } 799 }
801 800
802 /* rx enabled -> enable port for rx on the card */ 801 /* rx enabled -> enable port for rx on the card */
@@ -821,10 +820,9 @@ static inline void isicom_setup_board(struct isi_board *bp)
821 } 820 }
822 port = bp->ports; 821 port = bp->ports;
823 bp->status |= BOARD_ACTIVE; 822 bp->status |= BOARD_ACTIVE;
824 spin_unlock_irqrestore(&bp->card_lock, flags);
825 for (channel = 0; channel < bp->port_count; channel++, port++) 823 for (channel = 0; channel < bp->port_count; channel++, port++)
826 drop_dtr_rts(port); 824 drop_dtr_rts(port);
827 return; 825 spin_unlock_irqrestore(&bp->card_lock, flags);
828} 826}
829 827
830static int isicom_setup_port(struct isi_port *port) 828static int isicom_setup_port(struct isi_port *port)
@@ -857,7 +855,12 @@ static int isicom_setup_port(struct isi_port *port)
857 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 855 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
858 856
859 /* discard any residual data */ 857 /* discard any residual data */
860 kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX); 858 if (WaitTillCardIsFree(card->base) == 0) {
859 outw(0x8000 | (port->channel << card->shift_count) | 0x02,
860 card->base);
861 outw(((ISICOM_KILLTX | ISICOM_KILLRX) << 8) | 0x06, card->base);
862 InterruptTheCard(card->base);
863 }
861 864
862 isicom_config_port(port); 865 isicom_config_port(port);
863 port->flags |= ASYNC_INITIALIZED; 866 port->flags |= ASYNC_INITIALIZED;
@@ -983,28 +986,22 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
983 986
984static inline void isicom_shutdown_board(struct isi_board *bp) 987static inline void isicom_shutdown_board(struct isi_board *bp)
985{ 988{
986 unsigned long flags;
987
988 spin_lock_irqsave(&bp->card_lock, flags);
989 if (bp->status & BOARD_ACTIVE) { 989 if (bp->status & BOARD_ACTIVE) {
990 bp->status &= ~BOARD_ACTIVE; 990 bp->status &= ~BOARD_ACTIVE;
991 } 991 }
992 spin_unlock_irqrestore(&bp->card_lock, flags);
993} 992}
994 993
994/* card->lock HAS to be held */
995static void isicom_shutdown_port(struct isi_port *port) 995static void isicom_shutdown_port(struct isi_port *port)
996{ 996{
997 struct isi_board *card = port->card; 997 struct isi_board *card = port->card;
998 struct tty_struct *tty; 998 struct tty_struct *tty;
999 unsigned long flags;
1000 999
1001 tty = port->tty; 1000 tty = port->tty;
1002 1001
1003 spin_lock_irqsave(&card->card_lock, flags); 1002 if (!(port->flags & ASYNC_INITIALIZED))
1004 if (!(port->flags & ASYNC_INITIALIZED)) {
1005 spin_unlock_irqrestore(&card->card_lock, flags);
1006 return; 1003 return;
1007 } 1004
1008 if (port->xmit_buf) { 1005 if (port->xmit_buf) {
1009 free_page((unsigned long) port->xmit_buf); 1006 free_page((unsigned long) port->xmit_buf);
1010 port->xmit_buf = NULL; 1007 port->xmit_buf = NULL;
@@ -1012,7 +1009,6 @@ static void isicom_shutdown_port(struct isi_port *port)
1012 port->flags &= ~ASYNC_INITIALIZED; 1009 port->flags &= ~ASYNC_INITIALIZED;
1013 /* 3rd October 2000 : Vinayak P Risbud */ 1010 /* 3rd October 2000 : Vinayak P Risbud */
1014 port->tty = NULL; 1011 port->tty = NULL;
1015 spin_unlock_irqrestore(&card->card_lock, flags);
1016 1012
1017 /*Fix done by Anil .S on 30-04-2001 1013 /*Fix done by Anil .S on 30-04-2001
1018 remote login through isi port has dtr toggle problem 1014 remote login through isi port has dtr toggle problem
@@ -1258,10 +1254,12 @@ static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1258 unsigned int set, unsigned int clear) 1254 unsigned int set, unsigned int clear)
1259{ 1255{
1260 struct isi_port *port = tty->driver_data; 1256 struct isi_port *port = tty->driver_data;
1257 unsigned long flags;
1261 1258
1262 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl")) 1259 if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
1263 return -ENODEV; 1260 return -ENODEV;
1264 1261
1262 spin_lock_irqsave(&port->card->card_lock, flags);
1265 if (set & TIOCM_RTS) 1263 if (set & TIOCM_RTS)
1266 raise_rts(port); 1264 raise_rts(port);
1267 if (set & TIOCM_DTR) 1265 if (set & TIOCM_DTR)
@@ -1271,6 +1269,7 @@ static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1271 drop_rts(port); 1269 drop_rts(port);
1272 if (clear & TIOCM_DTR) 1270 if (clear & TIOCM_DTR)
1273 drop_dtr(port); 1271 drop_dtr(port);
1272 spin_unlock_irqrestore(&port->card->card_lock, flags);
1274 1273
1275 return 0; 1274 return 0;
1276} 1275}
@@ -1303,7 +1302,10 @@ static int isicom_set_serial_info(struct isi_port *port,
1303 (newinfo.flags & ASYNC_FLAGS)); 1302 (newinfo.flags & ASYNC_FLAGS));
1304 } 1303 }
1305 if (reconfig_port) { 1304 if (reconfig_port) {
1305 unsigned long flags;
1306 spin_lock_irqsave(&port->card->card_lock, flags);
1306 isicom_config_port(port); 1307 isicom_config_port(port);
1308 spin_unlock_irqrestore(&port->card->card_lock, flags);
1307 } 1309 }
1308 return 0; 1310 return 0;
1309} 1311}
@@ -1384,6 +1386,7 @@ static void isicom_set_termios(struct tty_struct *tty,
1384 struct ktermios *old_termios) 1386 struct ktermios *old_termios)
1385{ 1387{
1386 struct isi_port *port = tty->driver_data; 1388 struct isi_port *port = tty->driver_data;
1389 unsigned long flags;
1387 1390
1388 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios")) 1391 if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
1389 return; 1392 return;
@@ -1392,7 +1395,9 @@ static void isicom_set_termios(struct tty_struct *tty,
1392 tty->termios->c_iflag == old_termios->c_iflag) 1395 tty->termios->c_iflag == old_termios->c_iflag)
1393 return; 1396 return;
1394 1397
1398 spin_lock_irqsave(&port->card->card_lock, flags);
1395 isicom_config_port(port); 1399 isicom_config_port(port);
1400 spin_unlock_irqrestore(&port->card->card_lock, flags);
1396 1401
1397 if ((old_termios->c_cflag & CRTSCTS) && 1402 if ((old_termios->c_cflag & CRTSCTS) &&
1398 !(tty->termios->c_cflag & CRTSCTS)) { 1403 !(tty->termios->c_cflag & CRTSCTS)) {
@@ -1469,11 +1474,15 @@ static void do_isicom_hangup(struct work_struct *work)
1469static void isicom_hangup(struct tty_struct *tty) 1474static void isicom_hangup(struct tty_struct *tty)
1470{ 1475{
1471 struct isi_port *port = tty->driver_data; 1476 struct isi_port *port = tty->driver_data;
1477 unsigned long flags;
1472 1478
1473 if (isicom_paranoia_check(port, tty->name, "isicom_hangup")) 1479 if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
1474 return; 1480 return;
1475 1481
1482 spin_lock_irqsave(&port->card->card_lock, flags);
1476 isicom_shutdown_port(port); 1483 isicom_shutdown_port(port);
1484 spin_unlock_irqrestore(&port->card->card_lock, flags);
1485
1477 port->count = 0; 1486 port->count = 0;
1478 port->flags &= ~ASYNC_NORMAL_ACTIVE; 1487 port->flags &= ~ASYNC_NORMAL_ACTIVE;
1479 port->tty = NULL; 1488 port->tty = NULL;
@@ -1578,16 +1587,6 @@ end:
1578 return retval; 1587 return retval;
1579} 1588}
1580 1589
1581static inline int WaitTillCardIsFree(u16 base)
1582{
1583 unsigned long count = 0;
1584
1585 while (!(inw(base + 0xe) & 0x1) && count++ < 100)
1586 msleep(5);
1587
1588 return !(inw(base + 0xe) & 0x1);
1589}
1590
1591static int __devinit load_firmware(struct pci_dev *pdev, 1590static int __devinit load_firmware(struct pci_dev *pdev,
1592 const unsigned int index, const unsigned int signature) 1591 const unsigned int index, const unsigned int signature)
1593{ 1592{
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index c063359baf78..83f604b19290 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -717,6 +717,7 @@ static int mxser_init(void)
717 717
718 /* Initialize the tty_driver structure */ 718 /* Initialize the tty_driver structure */
719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver)); 719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
720 mxvar_sdriver->owner = THIS_MODULE;
720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 721 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
721 mxvar_sdriver->name = "ttyMI"; 722 mxvar_sdriver->name = "ttyMI";
722 mxvar_sdriver->major = ttymajor; 723 mxvar_sdriver->major = ttymajor;
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index cd989dce7c53..1bb030b3a51a 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -2690,6 +2690,7 @@ static int __init mxser_module_init(void)
2690 MXSER_VERSION); 2690 MXSER_VERSION);
2691 2691
2692 /* Initialize the tty_driver structure */ 2692 /* Initialize the tty_driver structure */
2693 mxvar_sdriver->owner = THIS_MODULE;
2693 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 2694 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2694 mxvar_sdriver->name = "ttyMI"; 2695 mxvar_sdriver->name = "ttyMI";
2695 mxvar_sdriver->major = ttymajor; 2696 mxvar_sdriver->major = ttymajor;
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index e1d70e8b6268..664f36c98e6a 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -113,7 +113,12 @@ static int rtc_has_irq = 1;
113#define hpet_set_rtc_irq_bit(arg) 0 113#define hpet_set_rtc_irq_bit(arg) 0
114#define hpet_rtc_timer_init() do { } while (0) 114#define hpet_rtc_timer_init() do { } while (0)
115#define hpet_rtc_dropped_irq() 0 115#define hpet_rtc_dropped_irq() 0
116static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id) {return 0;} 116#ifdef RTC_IRQ
117static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
118{
119 return 0;
120}
121#endif
117#else 122#else
118extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id); 123extern irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id);
119#endif 124#endif
diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c
index 244d30a03fef..448d5083c381 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -807,8 +807,6 @@ static int __init tlclk_init(void)
807 &tlclk_attribute_group); 807 &tlclk_attribute_group);
808 if (ret) { 808 if (ret) {
809 printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n"); 809 printk(KERN_ERR "tlclk: failed to create sysfs device attributes.\n");
810 sysfs_remove_group(&tlclk_device->dev.kobj,
811 &tlclk_attribute_group);
812 goto out5; 810 goto out5;
813 } 811 }
814 812
diff --git a/drivers/char/viocons.c b/drivers/char/viocons.c
index 0e0da443cbd5..8de6b95aeb84 100644
--- a/drivers/char/viocons.c
+++ b/drivers/char/viocons.c
@@ -42,6 +42,7 @@
42#include <linux/tty_flip.h> 42#include <linux/tty_flip.h>
43#include <linux/sysrq.h> 43#include <linux/sysrq.h>
44 44
45#include <asm/firmware.h>
45#include <asm/iseries/vio.h> 46#include <asm/iseries/vio.h>
46#include <asm/iseries/hv_lp_event.h> 47#include <asm/iseries/hv_lp_event.h>
47#include <asm/iseries/hv_call_event.h> 48#include <asm/iseries/hv_call_event.h>
@@ -1060,6 +1061,9 @@ static int __init viocons_init2(void)
1060 atomic_t wait_flag; 1061 atomic_t wait_flag;
1061 int rc; 1062 int rc;
1062 1063
1064 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1065 return -ENODEV;
1066
1063 /* +2 for fudge */ 1067 /* +2 for fudge */
1064 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(), 1068 rc = viopath_open(HvLpConfig_getPrimaryLpIndex(),
1065 viomajorsubtype_chario, VIOCHAR_WINDOW + 2); 1069 viomajorsubtype_chario, VIOCHAR_WINDOW + 2);
@@ -1145,6 +1149,9 @@ static int __init viocons_init(void)
1145{ 1149{
1146 int i; 1150 int i;
1147 1151
1152 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1153 return -ENODEV;
1154
1148 printk(VIOCONS_KERN_INFO "registering console\n"); 1155 printk(VIOCONS_KERN_INFO "registering console\n");
1149 for (i = 0; i < VTTY_PORTS; i++) { 1156 for (i = 0; i < VTTY_PORTS; i++) {
1150 port_info[i].lp = HvLpIndexInvalid; 1157 port_info[i].lp = HvLpIndexInvalid;
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 94d79cb8ce8d..9438512b17f1 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -49,7 +49,7 @@
49 49
50#include <asm/uaccess.h> 50#include <asm/uaccess.h>
51#include <asm/ioctls.h> 51#include <asm/ioctls.h>
52 52#include <asm/firmware.h>
53#include <asm/vio.h> 53#include <asm/vio.h>
54#include <asm/iseries/vio.h> 54#include <asm/iseries/vio.h>
55#include <asm/iseries/hv_lp_event.h> 55#include <asm/iseries/hv_lp_event.h>
@@ -997,6 +997,9 @@ int __init viotap_init(void)
997 int ret; 997 int ret;
998 struct proc_dir_entry *e; 998 struct proc_dir_entry *e;
999 999
1000 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1001 return -ENODEV;
1002
1000 op_struct_list = NULL; 1003 op_struct_list = NULL;
1001 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) { 1004 if ((ret = add_op_structs(VIOTAPE_MAXREQ)) < 0) {
1002 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n"); 1005 printk(VIOTAPE_KERN_WARN "couldn't allocate op structs\n");
diff --git a/drivers/connector/cn_queue.c b/drivers/connector/cn_queue.c
index b418b16e910e..296f51002b55 100644
--- a/drivers/connector/cn_queue.c
+++ b/drivers/connector/cn_queue.c
@@ -34,7 +34,7 @@
34void cn_queue_wrapper(struct work_struct *work) 34void cn_queue_wrapper(struct work_struct *work)
35{ 35{
36 struct cn_callback_entry *cbq = 36 struct cn_callback_entry *cbq =
37 container_of(work, struct cn_callback_entry, work.work); 37 container_of(work, struct cn_callback_entry, work);
38 struct cn_callback_data *d = &cbq->data; 38 struct cn_callback_data *d = &cbq->data;
39 39
40 d->callback(d->callback_priv); 40 d->callback(d->callback_priv);
@@ -59,13 +59,12 @@ static struct cn_callback_entry *cn_queue_alloc_callback_entry(char *name, struc
59 memcpy(&cbq->id.id, id, sizeof(struct cb_id)); 59 memcpy(&cbq->id.id, id, sizeof(struct cb_id));
60 cbq->data.callback = callback; 60 cbq->data.callback = callback;
61 61
62 INIT_DELAYED_WORK(&cbq->work, &cn_queue_wrapper); 62 INIT_WORK(&cbq->work, &cn_queue_wrapper);
63 return cbq; 63 return cbq;
64} 64}
65 65
66static void cn_queue_free_callback(struct cn_callback_entry *cbq) 66static void cn_queue_free_callback(struct cn_callback_entry *cbq)
67{ 67{
68 cancel_delayed_work(&cbq->work);
69 flush_workqueue(cbq->pdev->cn_queue); 68 flush_workqueue(cbq->pdev->cn_queue);
70 69
71 kfree(cbq); 70 kfree(cbq);
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index 5e7cd45d10ee..a44db75bc25b 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -135,17 +135,15 @@ static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), v
135 spin_lock_bh(&dev->cbdev->queue_lock); 135 spin_lock_bh(&dev->cbdev->queue_lock);
136 list_for_each_entry(__cbq, &dev->cbdev->queue_list, callback_entry) { 136 list_for_each_entry(__cbq, &dev->cbdev->queue_list, callback_entry) {
137 if (cn_cb_equal(&__cbq->id.id, &msg->id)) { 137 if (cn_cb_equal(&__cbq->id.id, &msg->id)) {
138 if (likely(!test_bit(WORK_STRUCT_PENDING, 138 if (likely(!work_pending(&__cbq->work) &&
139 &__cbq->work.work.management) &&
140 __cbq->data.ddata == NULL)) { 139 __cbq->data.ddata == NULL)) {
141 __cbq->data.callback_priv = msg; 140 __cbq->data.callback_priv = msg;
142 141
143 __cbq->data.ddata = data; 142 __cbq->data.ddata = data;
144 __cbq->data.destruct_data = destruct_data; 143 __cbq->data.destruct_data = destruct_data;
145 144
146 if (queue_delayed_work( 145 if (queue_work(dev->cbdev->cn_queue,
147 dev->cbdev->cn_queue, 146 &__cbq->work))
148 &__cbq->work, 0))
149 err = 0; 147 err = 0;
150 } else { 148 } else {
151 struct cn_callback_data *d; 149 struct cn_callback_data *d;
@@ -159,12 +157,11 @@ static int cn_call_callback(struct cn_msg *msg, void (*destruct_data)(void *), v
159 d->destruct_data = destruct_data; 157 d->destruct_data = destruct_data;
160 d->free = __cbq; 158 d->free = __cbq;
161 159
162 INIT_DELAYED_WORK(&__cbq->work, 160 INIT_WORK(&__cbq->work,
163 &cn_queue_wrapper); 161 &cn_queue_wrapper);
164 162
165 if (queue_delayed_work( 163 if (queue_work(dev->cbdev->cn_queue,
166 dev->cbdev->cn_queue, 164 &__cbq->work))
167 &__cbq->work, 0))
168 err = 0; 165 err = 0;
169 else { 166 else {
170 kfree(__cbq); 167 kfree(__cbq);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 9fb2edf36611..d91330432ba2 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -959,7 +959,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
959 959
960 960
961/** 961/**
962 * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur 962 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
963 * @cpu: CPU number 963 * @cpu: CPU number
964 * 964 *
965 * This is the last known freq, without actually getting it from the driver. 965 * This is the last known freq, without actually getting it from the driver.
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 14cdf09316ce..998638020ea0 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -415,12 +415,31 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
415 case 0x000: goto ignore; 415 case 0x000: goto ignore;
416 case 0x034: map_key_clear(KEY_SLEEP); break; 416 case 0x034: map_key_clear(KEY_SLEEP); break;
417 case 0x036: map_key_clear(BTN_MISC); break; 417 case 0x036: map_key_clear(BTN_MISC); break;
418 case 0x040: map_key_clear(KEY_MENU); break;
418 case 0x045: map_key_clear(KEY_RADIO); break; 419 case 0x045: map_key_clear(KEY_RADIO); break;
420
421 case 0x088: map_key_clear(KEY_PC); break;
422 case 0x089: map_key_clear(KEY_TV); break;
419 case 0x08a: map_key_clear(KEY_WWW); break; 423 case 0x08a: map_key_clear(KEY_WWW); break;
424 case 0x08b: map_key_clear(KEY_DVD); break;
425 case 0x08c: map_key_clear(KEY_PHONE); break;
420 case 0x08d: map_key_clear(KEY_PROGRAM); break; 426 case 0x08d: map_key_clear(KEY_PROGRAM); break;
427 case 0x08e: map_key_clear(KEY_VIDEOPHONE); break;
428 case 0x08f: map_key_clear(KEY_GAMES); break;
429 case 0x090: map_key_clear(KEY_MEMO); break;
430 case 0x091: map_key_clear(KEY_CD); break;
431 case 0x092: map_key_clear(KEY_VCR); break;
432 case 0x093: map_key_clear(KEY_TUNER); break;
433 case 0x094: map_key_clear(KEY_EXIT); break;
421 case 0x095: map_key_clear(KEY_HELP); break; 434 case 0x095: map_key_clear(KEY_HELP); break;
435 case 0x096: map_key_clear(KEY_TAPE); break;
436 case 0x097: map_key_clear(KEY_TV2); break;
437 case 0x098: map_key_clear(KEY_SAT); break;
438
422 case 0x09c: map_key_clear(KEY_CHANNELUP); break; 439 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
423 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break; 440 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
441 case 0x0a0: map_key_clear(KEY_VCR2); break;
442
424 case 0x0b0: map_key_clear(KEY_PLAY); break; 443 case 0x0b0: map_key_clear(KEY_PLAY); break;
425 case 0x0b1: map_key_clear(KEY_PAUSE); break; 444 case 0x0b1: map_key_clear(KEY_PAUSE); break;
426 case 0x0b2: map_key_clear(KEY_RECORD); break; 445 case 0x0b2: map_key_clear(KEY_RECORD); break;
@@ -430,6 +449,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
430 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break; 449 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break;
431 case 0x0b7: map_key_clear(KEY_STOPCD); break; 450 case 0x0b7: map_key_clear(KEY_STOPCD); break;
432 case 0x0b8: map_key_clear(KEY_EJECTCD); break; 451 case 0x0b8: map_key_clear(KEY_EJECTCD); break;
452
433 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break; 453 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
434 case 0x0e0: map_abs_clear(ABS_VOLUME); break; 454 case 0x0e0: map_abs_clear(ABS_VOLUME); break;
435 case 0x0e2: map_key_clear(KEY_MUTE); break; 455 case 0x0e2: map_key_clear(KEY_MUTE); break;
@@ -437,11 +457,30 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
437 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break; 457 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break;
438 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break; 458 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break;
439 case 0x183: map_key_clear(KEY_CONFIG); break; 459 case 0x183: map_key_clear(KEY_CONFIG); break;
460 case 0x184: map_key_clear(KEY_WORDPROCESSOR); break;
461 case 0x185: map_key_clear(KEY_EDITOR); break;
462 case 0x186: map_key_clear(KEY_SPREADSHEET); break;
463 case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break;
464 case 0x188: map_key_clear(KEY_PRESENTATION); break;
465 case 0x189: map_key_clear(KEY_DATABASE); break;
440 case 0x18a: map_key_clear(KEY_MAIL); break; 466 case 0x18a: map_key_clear(KEY_MAIL); break;
467 case 0x18b: map_key_clear(KEY_NEWS); break;
468 case 0x18c: map_key_clear(KEY_VOICEMAIL); break;
469 case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break;
470 case 0x18e: map_key_clear(KEY_CALENDAR); break;
471 case 0x191: map_key_clear(KEY_FINANCE); break;
441 case 0x192: map_key_clear(KEY_CALC); break; 472 case 0x192: map_key_clear(KEY_CALC); break;
442 case 0x194: map_key_clear(KEY_FILE); break; 473 case 0x194: map_key_clear(KEY_FILE); break;
474 case 0x196: map_key_clear(KEY_WWW); break;
475 case 0x19e: map_key_clear(KEY_COFFEE); break;
476 case 0x1a6: map_key_clear(KEY_HELP); break;
443 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break; 477 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
478 case 0x1bc: map_key_clear(KEY_MESSENGER); break;
479 case 0x1bd: map_key_clear(KEY_INFO); break;
444 case 0x201: map_key_clear(KEY_NEW); break; 480 case 0x201: map_key_clear(KEY_NEW); break;
481 case 0x202: map_key_clear(KEY_OPEN); break;
482 case 0x203: map_key_clear(KEY_CLOSE); break;
483 case 0x204: map_key_clear(KEY_EXIT); break;
445 case 0x207: map_key_clear(KEY_SAVE); break; 484 case 0x207: map_key_clear(KEY_SAVE); break;
446 case 0x208: map_key_clear(KEY_PRINT); break; 485 case 0x208: map_key_clear(KEY_PRINT); break;
447 case 0x209: map_key_clear(KEY_PROPS); break; 486 case 0x209: map_key_clear(KEY_PROPS); break;
@@ -456,10 +495,15 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
456 case 0x226: map_key_clear(KEY_STOP); break; 495 case 0x226: map_key_clear(KEY_STOP); break;
457 case 0x227: map_key_clear(KEY_REFRESH); break; 496 case 0x227: map_key_clear(KEY_REFRESH); break;
458 case 0x22a: map_key_clear(KEY_BOOKMARKS); break; 497 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
498 case 0x22d: map_key_clear(KEY_ZOOMIN); break;
499 case 0x22e: map_key_clear(KEY_ZOOMOUT); break;
500 case 0x22f: map_key_clear(KEY_ZOOMRESET); break;
459 case 0x233: map_key_clear(KEY_SCROLLUP); break; 501 case 0x233: map_key_clear(KEY_SCROLLUP); break;
460 case 0x234: map_key_clear(KEY_SCROLLDOWN); break; 502 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
461 case 0x238: map_rel(REL_HWHEEL); break; 503 case 0x238: map_rel(REL_HWHEEL); break;
504 case 0x25f: map_key_clear(KEY_CANCEL); break;
462 case 0x279: map_key_clear(KEY_REDO); break; 505 case 0x279: map_key_clear(KEY_REDO); break;
506
463 case 0x289: map_key_clear(KEY_REPLY); break; 507 case 0x289: map_key_clear(KEY_REPLY); break;
464 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break; 508 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
465 case 0x28c: map_key_clear(KEY_SEND); break; 509 case 0x28c: map_key_clear(KEY_SEND); break;
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index d55b938b1aeb..ffdffb6379ef 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -368,7 +368,6 @@ static struct pci_device_id atiixp_pci_tbl[] = {
368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 368 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
369 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 369 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
370 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 370 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
371 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, PCI_ANY_ID, PCI_ANY_ID, (PCI_CLASS_STORAGE_IDE<<8)|0x8a, 0xffff05, 1},
372 { 0, }, 371 { 0, },
373}; 372};
374MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 373MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index b1e9a8eba6b6..edb37f3d558d 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -1,13 +1,14 @@
1/* 1/*
2 * linux/drivers/ide/pci/piix.c Version 0.44 March 20, 2003 2 * linux/drivers/ide/pci/piix.c Version 0.45 May 12, 2006
3 * 3 *
4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer 4 * Copyright (C) 1998-1999 Andrzej Krzysztofowicz, Author and Maintainer
5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 5 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com> 6 * Copyright (C) 2003 Red Hat Inc <alan@redhat.com>
7 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com>
7 * 8 *
8 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
9 * 10 *
10 * PIO mode setting function for Intel chipsets. 11 * PIO mode setting function for Intel chipsets.
11 * For use instead of BIOS settings. 12 * For use instead of BIOS settings.
12 * 13 *
13 * 40-41 14 * 40-41
@@ -25,7 +26,7 @@
25 * sitre = word42 & 0x4000; secondary 26 * sitre = word42 & 0x4000; secondary
26 * 27 *
27 * 44 8421|8421 hdd|hdb 28 * 44 8421|8421 hdd|hdb
28 * 29 *
29 * 48 8421 hdd|hdc|hdb|hda udma enabled 30 * 48 8421 hdd|hdc|hdb|hda udma enabled
30 * 31 *
31 * 0001 hda 32 * 0001 hda
@@ -353,56 +354,24 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
353} 354}
354 355
355/** 356/**
356 * piix_faulty_dma0 - check for DMA0 errata
357 * @hwif: IDE interface to check
358 *
359 * If an ICH/ICH0/ICH2 interface is is operating in multi-word
360 * DMA mode with 600nS cycle time the IDE PIO prefetch buffer will
361 * inadvertently provide an extra piece of secondary data to the primary
362 * device resulting in data corruption.
363 *
364 * With such a device this test function returns true. This allows
365 * our tuning code to follow Intel recommendations and use PIO on
366 * such devices.
367 */
368
369static int piix_faulty_dma0(ide_hwif_t *hwif)
370{
371 switch(hwif->pci_dev->device)
372 {
373 case PCI_DEVICE_ID_INTEL_82801AA_1: /* ICH */
374 case PCI_DEVICE_ID_INTEL_82801AB_1: /* ICH0 */
375 case PCI_DEVICE_ID_INTEL_82801BA_8: /* ICH2 */
376 case PCI_DEVICE_ID_INTEL_82801BA_9: /* ICH2 */
377 return 1;
378 }
379 return 0;
380}
381
382/**
383 * piix_config_drive_for_dma - configure drive for DMA 357 * piix_config_drive_for_dma - configure drive for DMA
384 * @drive: IDE drive to configure 358 * @drive: IDE drive to configure
385 * 359 *
386 * Set up a PIIX interface channel for the best available speed. 360 * Set up a PIIX interface channel for the best available speed.
387 * We prefer UDMA if it is available and then MWDMA. If DMA is 361 * We prefer UDMA if it is available and then MWDMA. If DMA is
388 * not available we switch to PIO and return 0. 362 * not available we switch to PIO and return 0.
389 */ 363 */
390 364
391static int piix_config_drive_for_dma (ide_drive_t *drive) 365static int piix_config_drive_for_dma (ide_drive_t *drive)
392{ 366{
393 u8 speed = ide_dma_speed(drive, piix_ratemask(drive)); 367 u8 speed = ide_dma_speed(drive, piix_ratemask(drive));
394 368
395 /* Some ICH devices cannot support DMA mode 0 */ 369 /*
396 if(speed == XFER_MW_DMA_0 && piix_faulty_dma0(HWIF(drive))) 370 * If no DMA speed was available or the chipset has DMA bugs
397 speed = 0; 371 * then disable DMA and use PIO
398 372 */
399 /* If no DMA speed was available or the chipset has DMA bugs 373 if (!speed || no_piix_dma)
400 then disable DMA and use PIO */ 374 return 0;
401
402 if (!speed || no_piix_dma) {
403 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL);
404 speed = piix_dma_2_pio(XFER_PIO_0 + tspeed);
405 }
406 375
407 (void) piix_tune_chipset(drive, speed); 376 (void) piix_tune_chipset(drive, speed);
408 return ide_dma_enable(drive); 377 return ide_dma_enable(drive);
@@ -425,17 +394,16 @@ static int piix_config_drive_xfer_rate (ide_drive_t *drive)
425 394
426 if ((id->capability & 1) && drive->autodma) { 395 if ((id->capability & 1) && drive->autodma) {
427 396
428 if (ide_use_dma(drive)) { 397 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
429 if (piix_config_drive_for_dma(drive)) 398 return hwif->ide_dma_on(drive);
430 return hwif->ide_dma_on(drive);
431 }
432 399
433 goto fast_ata_pio; 400 goto fast_ata_pio;
434 401
435 } else if ((id->capability & 8) || (id->field_valid & 2)) { 402 } else if ((id->capability & 8) || (id->field_valid & 2)) {
436fast_ata_pio: 403fast_ata_pio:
437 /* Find best PIO mode. */ 404 /* Find best PIO mode. */
438 hwif->tuneproc(drive, 255); 405 (void) hwif->speedproc(drive, XFER_PIO_0 +
406 ide_get_best_pio_mode(drive, 255, 4, NULL));
439 return hwif->ide_dma_off_quietly(drive); 407 return hwif->ide_dma_off_quietly(drive);
440 } 408 }
441 /* IORDY not supported */ 409 /* IORDY not supported */
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 4a1853af3bbb..9be7e49cba0e 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/slc90e66.c Version 0.11 September 11, 2002 2 * linux/drivers/ide/pci/slc90e66.c Version 0.12 May 12, 2006
3 * 3 *
4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006 MontaVista Software, Inc. <source@mvista.com>
5 * 6 *
6 * This a look-a-like variation of the ICH0 PIIX4 Ultra-66, 7 * This is a look-alike variation of the ICH0 PIIX4 Ultra-66,
7 * but this keeps the ISA-Bridge and slots alive. 8 * but this keeps the ISA-Bridge and slots alive.
8 * 9 *
9 */ 10 */
@@ -158,10 +159,8 @@ static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
158{ 159{
159 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive)); 160 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive));
160 161
161 if (!(speed)) { 162 if (!speed)
162 u8 tspeed = ide_get_best_pio_mode(drive, 255, 5, NULL); 163 return 0;
163 speed = slc90e66_dma_2_pio(XFER_PIO_0 + tspeed);
164 }
165 164
166 (void) slc90e66_tune_chipset(drive, speed); 165 (void) slc90e66_tune_chipset(drive, speed);
167 return ide_dma_enable(drive); 166 return ide_dma_enable(drive);
@@ -176,16 +175,15 @@ static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
176 175
177 if (id && (id->capability & 1) && drive->autodma) { 176 if (id && (id->capability & 1) && drive->autodma) {
178 177
179 if (ide_use_dma(drive)) { 178 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
180 if (slc90e66_config_drive_for_dma(drive)) 179 return hwif->ide_dma_on(drive);
181 return hwif->ide_dma_on(drive);
182 }
183 180
184 goto fast_ata_pio; 181 goto fast_ata_pio;
185 182
186 } else if ((id->capability & 8) || (id->field_valid & 2)) { 183 } else if ((id->capability & 8) || (id->field_valid & 2)) {
187fast_ata_pio: 184fast_ata_pio:
188 hwif->tuneproc(drive, 5); 185 (void) hwif->speedproc(drive, XFER_PIO_0 +
186 ide_get_best_pio_mode(drive, 255, 4, NULL));
189 return hwif->ide_dma_off_quietly(drive); 187 return hwif->ide_dma_off_quietly(drive);
190 } 188 }
191 /* IORDY not supported */ 189 /* IORDY not supported */
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 0491ec7a7c0a..44bc6cc734ab 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -80,24 +80,61 @@ static int tune_pci = 0;
80module_param(tune_pci, int, 0444); 80module_param(tune_pci, int, 0444);
81MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero"); 81MODULE_PARM_DESC(tune_pci, "increase PCI burst from the default set by BIOS if nonzero");
82 82
83struct mutex mthca_device_mutex; 83DEFINE_MUTEX(mthca_device_mutex);
84
85#define MTHCA_DEFAULT_NUM_QP (1 << 16)
86#define MTHCA_DEFAULT_RDB_PER_QP (1 << 2)
87#define MTHCA_DEFAULT_NUM_CQ (1 << 16)
88#define MTHCA_DEFAULT_NUM_MCG (1 << 13)
89#define MTHCA_DEFAULT_NUM_MPT (1 << 17)
90#define MTHCA_DEFAULT_NUM_MTT (1 << 20)
91#define MTHCA_DEFAULT_NUM_UDAV (1 << 15)
92#define MTHCA_DEFAULT_NUM_RESERVED_MTTS (1 << 18)
93#define MTHCA_DEFAULT_NUM_UARC_SIZE (1 << 18)
94
95static struct mthca_profile hca_profile = {
96 .num_qp = MTHCA_DEFAULT_NUM_QP,
97 .rdb_per_qp = MTHCA_DEFAULT_RDB_PER_QP,
98 .num_cq = MTHCA_DEFAULT_NUM_CQ,
99 .num_mcg = MTHCA_DEFAULT_NUM_MCG,
100 .num_mpt = MTHCA_DEFAULT_NUM_MPT,
101 .num_mtt = MTHCA_DEFAULT_NUM_MTT,
102 .num_udav = MTHCA_DEFAULT_NUM_UDAV, /* Tavor only */
103 .fmr_reserved_mtts = MTHCA_DEFAULT_NUM_RESERVED_MTTS, /* Tavor only */
104 .uarc_size = MTHCA_DEFAULT_NUM_UARC_SIZE, /* Arbel only */
105};
106
107module_param_named(num_qp, hca_profile.num_qp, int, 0444);
108MODULE_PARM_DESC(num_qp, "maximum number of QPs per HCA");
109
110module_param_named(rdb_per_qp, hca_profile.rdb_per_qp, int, 0444);
111MODULE_PARM_DESC(rdb_per_qp, "number of RDB buffers per QP");
112
113module_param_named(num_cq, hca_profile.num_cq, int, 0444);
114MODULE_PARM_DESC(num_cq, "maximum number of CQs per HCA");
115
116module_param_named(num_mcg, hca_profile.num_mcg, int, 0444);
117MODULE_PARM_DESC(num_mcg, "maximum number of multicast groups per HCA");
118
119module_param_named(num_mpt, hca_profile.num_mpt, int, 0444);
120MODULE_PARM_DESC(num_mpt,
121 "maximum number of memory protection table entries per HCA");
122
123module_param_named(num_mtt, hca_profile.num_mtt, int, 0444);
124MODULE_PARM_DESC(num_mtt,
125 "maximum number of memory translation table segments per HCA");
126
127module_param_named(num_udav, hca_profile.num_udav, int, 0444);
128MODULE_PARM_DESC(num_udav, "maximum number of UD address vectors per HCA");
129
130module_param_named(fmr_reserved_mtts, hca_profile.fmr_reserved_mtts, int, 0444);
131MODULE_PARM_DESC(fmr_reserved_mtts,
132 "number of memory translation table segments reserved for FMR");
84 133
85static const char mthca_version[] __devinitdata = 134static const char mthca_version[] __devinitdata =
86 DRV_NAME ": Mellanox InfiniBand HCA driver v" 135 DRV_NAME ": Mellanox InfiniBand HCA driver v"
87 DRV_VERSION " (" DRV_RELDATE ")\n"; 136 DRV_VERSION " (" DRV_RELDATE ")\n";
88 137
89static struct mthca_profile default_profile = {
90 .num_qp = 1 << 16,
91 .rdb_per_qp = 4,
92 .num_cq = 1 << 16,
93 .num_mcg = 1 << 13,
94 .num_mpt = 1 << 17,
95 .num_mtt = 1 << 20,
96 .num_udav = 1 << 15, /* Tavor only */
97 .fmr_reserved_mtts = 1 << 18, /* Tavor only */
98 .uarc_size = 1 << 18, /* Arbel only */
99};
100
101static int mthca_tune_pci(struct mthca_dev *mdev) 138static int mthca_tune_pci(struct mthca_dev *mdev)
102{ 139{
103 int cap; 140 int cap;
@@ -303,7 +340,7 @@ static int mthca_init_tavor(struct mthca_dev *mdev)
303 goto err_disable; 340 goto err_disable;
304 } 341 }
305 342
306 profile = default_profile; 343 profile = hca_profile;
307 profile.num_uar = dev_lim.uar_size / PAGE_SIZE; 344 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
308 profile.uarc_size = 0; 345 profile.uarc_size = 0;
309 if (mdev->mthca_flags & MTHCA_FLAG_SRQ) 346 if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -621,7 +658,7 @@ static int mthca_init_arbel(struct mthca_dev *mdev)
621 goto err_stop_fw; 658 goto err_stop_fw;
622 } 659 }
623 660
624 profile = default_profile; 661 profile = hca_profile;
625 profile.num_uar = dev_lim.uar_size / PAGE_SIZE; 662 profile.num_uar = dev_lim.uar_size / PAGE_SIZE;
626 profile.num_udav = 0; 663 profile.num_udav = 0;
627 if (mdev->mthca_flags & MTHCA_FLAG_SRQ) 664 if (mdev->mthca_flags & MTHCA_FLAG_SRQ)
@@ -1278,11 +1315,55 @@ static struct pci_driver mthca_driver = {
1278 .remove = __devexit_p(mthca_remove_one) 1315 .remove = __devexit_p(mthca_remove_one)
1279}; 1316};
1280 1317
1318static void __init __mthca_check_profile_val(const char *name, int *pval,
1319 int pval_default)
1320{
1321 /* value must be positive and power of 2 */
1322 int old_pval = *pval;
1323
1324 if (old_pval <= 0)
1325 *pval = pval_default;
1326 else
1327 *pval = roundup_pow_of_two(old_pval);
1328
1329 if (old_pval != *pval) {
1330 printk(KERN_WARNING PFX "Invalid value %d for %s in module parameter.\n",
1331 old_pval, name);
1332 printk(KERN_WARNING PFX "Corrected %s to %d.\n", name, *pval);
1333 }
1334}
1335
1336#define mthca_check_profile_val(name, default) \
1337 __mthca_check_profile_val(#name, &hca_profile.name, default)
1338
1339static void __init mthca_validate_profile(void)
1340{
1341 mthca_check_profile_val(num_qp, MTHCA_DEFAULT_NUM_QP);
1342 mthca_check_profile_val(rdb_per_qp, MTHCA_DEFAULT_RDB_PER_QP);
1343 mthca_check_profile_val(num_cq, MTHCA_DEFAULT_NUM_CQ);
1344 mthca_check_profile_val(num_mcg, MTHCA_DEFAULT_NUM_MCG);
1345 mthca_check_profile_val(num_mpt, MTHCA_DEFAULT_NUM_MPT);
1346 mthca_check_profile_val(num_mtt, MTHCA_DEFAULT_NUM_MTT);
1347 mthca_check_profile_val(num_udav, MTHCA_DEFAULT_NUM_UDAV);
1348 mthca_check_profile_val(fmr_reserved_mtts, MTHCA_DEFAULT_NUM_RESERVED_MTTS);
1349
1350 if (hca_profile.fmr_reserved_mtts >= hca_profile.num_mtt) {
1351 printk(KERN_WARNING PFX "Invalid fmr_reserved_mtts module parameter %d.\n",
1352 hca_profile.fmr_reserved_mtts);
1353 printk(KERN_WARNING PFX "(Must be smaller than num_mtt %d)\n",
1354 hca_profile.num_mtt);
1355 hca_profile.fmr_reserved_mtts = hca_profile.num_mtt / 2;
1356 printk(KERN_WARNING PFX "Corrected fmr_reserved_mtts to %d.\n",
1357 hca_profile.fmr_reserved_mtts);
1358 }
1359}
1360
1281static int __init mthca_init(void) 1361static int __init mthca_init(void)
1282{ 1362{
1283 int ret; 1363 int ret;
1284 1364
1285 mutex_init(&mthca_device_mutex); 1365 mthca_validate_profile();
1366
1286 ret = mthca_catas_init(); 1367 ret = mthca_catas_init();
1287 if (ret) 1368 if (ret)
1288 return ret; 1369 return ret;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 7ec7c4b937f9..7b96751695ea 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -1100,10 +1100,11 @@ static struct ib_fmr *mthca_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
1100 struct mthca_fmr *fmr; 1100 struct mthca_fmr *fmr;
1101 int err; 1101 int err;
1102 1102
1103 fmr = kmemdup(fmr_attr, sizeof *fmr, GFP_KERNEL); 1103 fmr = kmalloc(sizeof *fmr, GFP_KERNEL);
1104 if (!fmr) 1104 if (!fmr)
1105 return ERR_PTR(-ENOMEM); 1105 return ERR_PTR(-ENOMEM);
1106 1106
1107 memcpy(&fmr->attr, fmr_attr, sizeof *fmr_attr);
1107 err = mthca_fmr_alloc(to_mdev(pd->device), to_mpd(pd)->pd_num, 1108 err = mthca_fmr_alloc(to_mdev(pd->device), to_mpd(pd)->pd_num,
1108 convert_access(mr_access_flags), fmr); 1109 convert_access(mr_access_flags), fmr);
1109 1110
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index e9b6a6f07dd7..cdecbf5911c8 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1898,7 +1898,7 @@ static void srp_add_one(struct ib_device *device)
1898 */ 1898 */
1899 srp_dev->fmr_page_shift = max(9, ffs(dev_attr->page_size_cap) - 1); 1899 srp_dev->fmr_page_shift = max(9, ffs(dev_attr->page_size_cap) - 1);
1900 srp_dev->fmr_page_size = 1 << srp_dev->fmr_page_shift; 1900 srp_dev->fmr_page_size = 1 << srp_dev->fmr_page_shift;
1901 srp_dev->fmr_page_mask = ~((unsigned long) srp_dev->fmr_page_size - 1); 1901 srp_dev->fmr_page_mask = ~((u64) srp_dev->fmr_page_size - 1);
1902 1902
1903 INIT_LIST_HEAD(&srp_dev->dev_list); 1903 INIT_LIST_HEAD(&srp_dev->dev_list);
1904 1904
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index 868a540ef7cd..c21772317b86 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -87,7 +87,7 @@ struct srp_device {
87 struct ib_fmr_pool *fmr_pool; 87 struct ib_fmr_pool *fmr_pool;
88 int fmr_page_shift; 88 int fmr_page_shift;
89 int fmr_page_size; 89 int fmr_page_size;
90 unsigned long fmr_page_mask; 90 u64 fmr_page_mask;
91}; 91};
92 92
93struct srp_host { 93struct srp_host {
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 16583d71753b..c67e84ec2d6a 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -187,7 +187,7 @@ static irqreturn_t amikbd_interrupt(int irq, void *dummy)
187 187
188static int __init amikbd_init(void) 188static int __init amikbd_init(void)
189{ 189{
190 int i, j; 190 int i, j, err;
191 191
192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD)) 192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
193 return -ENODEV; 193 return -ENODEV;
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 3826db9403e6..cc0238366414 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -225,7 +225,7 @@ static void sunkbd_reinit(struct work_struct *work)
225static void sunkbd_enable(struct sunkbd *sunkbd, int enable) 225static void sunkbd_enable(struct sunkbd *sunkbd, int enable)
226{ 226{
227 serio_pause_rx(sunkbd->serio); 227 serio_pause_rx(sunkbd->serio);
228 sunkbd->enabled = 1; 228 sunkbd->enabled = enable;
229 serio_continue_rx(sunkbd->serio); 229 serio_continue_rx(sunkbd->serio);
230} 230}
231 231
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 1726131b20be..4e3f127e4003 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -2339,6 +2339,7 @@ static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_s
2339 rs->state = CCPResetIdle; 2339 rs->state = CCPResetIdle;
2340 rs->is = is; 2340 rs->is = is;
2341 rs->id = id; 2341 rs->id = id;
2342 init_timer(&rs->timer);
2342 rs->timer.data = (unsigned long)rs; 2343 rs->timer.data = (unsigned long)rs;
2343 rs->timer.function = isdn_ppp_ccp_timer_callback; 2344 rs->timer.function = isdn_ppp_ccp_timer_callback;
2344 is->reset->rs[id] = rs; 2345 is->reset->rs[id] = rs;
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 930e04ce1af6..100df6f38d92 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -278,7 +278,6 @@ struct kvm_arch_ops {
278 struct kvm_segment *var, int seg); 278 struct kvm_segment *var, int seg);
279 void (*set_segment)(struct kvm_vcpu *vcpu, 279 void (*set_segment)(struct kvm_vcpu *vcpu,
280 struct kvm_segment *var, int seg); 280 struct kvm_segment *var, int seg);
281 int (*is_long_mode)(struct kvm_vcpu *vcpu);
282 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l); 281 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
283 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0); 282 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
284 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu, 283 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu,
@@ -320,7 +319,8 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
320void kvm_exit_arch(void); 319void kvm_exit_arch(void);
321 320
322void kvm_mmu_destroy(struct kvm_vcpu *vcpu); 321void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
323int kvm_mmu_init(struct kvm_vcpu *vcpu); 322int kvm_mmu_create(struct kvm_vcpu *vcpu);
323int kvm_mmu_setup(struct kvm_vcpu *vcpu);
324 324
325int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 325int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
326void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); 326void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
@@ -375,9 +375,8 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
375void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0); 375void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
376void lmsw(struct kvm_vcpu *vcpu, unsigned long msw); 376void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
377 377
378#ifdef CONFIG_X86_64 378int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
379void set_efer(struct kvm_vcpu *vcpu, u64 efer); 379int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data);
380#endif
381 380
382void fx_init(struct kvm_vcpu *vcpu); 381void fx_init(struct kvm_vcpu *vcpu);
383 382
@@ -403,6 +402,15 @@ static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn)
403 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL; 402 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL;
404} 403}
405 404
405static inline int is_long_mode(struct kvm_vcpu *vcpu)
406{
407#ifdef CONFIG_X86_64
408 return vcpu->shadow_efer & EFER_LME;
409#else
410 return 0;
411#endif
412}
413
406static inline int is_pae(struct kvm_vcpu *vcpu) 414static inline int is_pae(struct kvm_vcpu *vcpu)
407{ 415{
408 return vcpu->cr4 & CR4_PAE_MASK; 416 return vcpu->cr4 & CR4_PAE_MASK;
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index fd1bb870545c..ce7fe640f18d 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -113,6 +113,11 @@ unsigned long segment_base(u16 selector)
113} 113}
114EXPORT_SYMBOL_GPL(segment_base); 114EXPORT_SYMBOL_GPL(segment_base);
115 115
116static inline int valid_vcpu(int n)
117{
118 return likely(n >= 0 && n < KVM_MAX_VCPUS);
119}
120
116int kvm_read_guest(struct kvm_vcpu *vcpu, 121int kvm_read_guest(struct kvm_vcpu *vcpu,
117 gva_t addr, 122 gva_t addr,
118 unsigned long size, 123 unsigned long size,
@@ -240,7 +245,8 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
240 if (!dont || free->phys_mem != dont->phys_mem) 245 if (!dont || free->phys_mem != dont->phys_mem)
241 if (free->phys_mem) { 246 if (free->phys_mem) {
242 for (i = 0; i < free->npages; ++i) 247 for (i = 0; i < free->npages; ++i)
243 __free_page(free->phys_mem[i]); 248 if (free->phys_mem[i])
249 __free_page(free->phys_mem[i]);
244 vfree(free->phys_mem); 250 vfree(free->phys_mem);
245 } 251 }
246 252
@@ -393,7 +399,7 @@ void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
393 return; 399 return;
394 } 400 }
395 401
396 if (kvm_arch_ops->is_long_mode(vcpu)) { 402 if (is_long_mode(vcpu)) {
397 if (!(cr4 & CR4_PAE_MASK)) { 403 if (!(cr4 & CR4_PAE_MASK)) {
398 printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while " 404 printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while "
399 "in long mode\n"); 405 "in long mode\n");
@@ -420,7 +426,7 @@ EXPORT_SYMBOL_GPL(set_cr4);
420 426
421void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) 427void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
422{ 428{
423 if (kvm_arch_ops->is_long_mode(vcpu)) { 429 if (is_long_mode(vcpu)) {
424 if ( cr3 & CR3_L_MODE_RESEVED_BITS) { 430 if ( cr3 & CR3_L_MODE_RESEVED_BITS) {
425 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n"); 431 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
426 inject_gp(vcpu); 432 inject_gp(vcpu);
@@ -494,7 +500,7 @@ static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
494 struct kvm_vcpu *vcpu; 500 struct kvm_vcpu *vcpu;
495 501
496 r = -EINVAL; 502 r = -EINVAL;
497 if (n < 0 || n >= KVM_MAX_VCPUS) 503 if (!valid_vcpu(n))
498 goto out; 504 goto out;
499 505
500 vcpu = &kvm->vcpus[n]; 506 vcpu = &kvm->vcpus[n];
@@ -516,12 +522,14 @@ static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
516 if (r < 0) 522 if (r < 0)
517 goto out_free_vcpus; 523 goto out_free_vcpus;
518 524
519 kvm_arch_ops->vcpu_load(vcpu); 525 r = kvm_mmu_create(vcpu);
526 if (r < 0)
527 goto out_free_vcpus;
520 528
521 r = kvm_arch_ops->vcpu_setup(vcpu); 529 kvm_arch_ops->vcpu_load(vcpu);
530 r = kvm_mmu_setup(vcpu);
522 if (r >= 0) 531 if (r >= 0)
523 r = kvm_mmu_init(vcpu); 532 r = kvm_arch_ops->vcpu_setup(vcpu);
524
525 vcpu_put(vcpu); 533 vcpu_put(vcpu);
526 534
527 if (r < 0) 535 if (r < 0)
@@ -1098,6 +1106,51 @@ void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
1098 } 1106 }
1099} 1107}
1100 1108
1109int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
1110{
1111 u64 data;
1112
1113 switch (msr) {
1114 case 0xc0010010: /* SYSCFG */
1115 case 0xc0010015: /* HWCR */
1116 case MSR_IA32_PLATFORM_ID:
1117 case MSR_IA32_P5_MC_ADDR:
1118 case MSR_IA32_P5_MC_TYPE:
1119 case MSR_IA32_MC0_CTL:
1120 case MSR_IA32_MCG_STATUS:
1121 case MSR_IA32_MCG_CAP:
1122 case MSR_IA32_MC0_MISC:
1123 case MSR_IA32_MC0_MISC+4:
1124 case MSR_IA32_MC0_MISC+8:
1125 case MSR_IA32_MC0_MISC+12:
1126 case MSR_IA32_MC0_MISC+16:
1127 case MSR_IA32_UCODE_REV:
1128 case MSR_IA32_PERF_STATUS:
1129 /* MTRR registers */
1130 case 0xfe:
1131 case 0x200 ... 0x2ff:
1132 data = 0;
1133 break;
1134 case 0xcd: /* fsb frequency */
1135 data = 3;
1136 break;
1137 case MSR_IA32_APICBASE:
1138 data = vcpu->apic_base;
1139 break;
1140#ifdef CONFIG_X86_64
1141 case MSR_EFER:
1142 data = vcpu->shadow_efer;
1143 break;
1144#endif
1145 default:
1146 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", msr);
1147 return 1;
1148 }
1149 *pdata = data;
1150 return 0;
1151}
1152EXPORT_SYMBOL_GPL(kvm_get_msr_common);
1153
1101/* 1154/*
1102 * Reads an msr value (of 'msr_index') into 'pdata'. 1155 * Reads an msr value (of 'msr_index') into 'pdata'.
1103 * Returns 0 on success, non-0 otherwise. 1156 * Returns 0 on success, non-0 otherwise.
@@ -1110,7 +1163,7 @@ static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
1110 1163
1111#ifdef CONFIG_X86_64 1164#ifdef CONFIG_X86_64
1112 1165
1113void set_efer(struct kvm_vcpu *vcpu, u64 efer) 1166static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1114{ 1167{
1115 if (efer & EFER_RESERVED_BITS) { 1168 if (efer & EFER_RESERVED_BITS) {
1116 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n", 1169 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n",
@@ -1133,10 +1186,36 @@ void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1133 1186
1134 vcpu->shadow_efer = efer; 1187 vcpu->shadow_efer = efer;
1135} 1188}
1136EXPORT_SYMBOL_GPL(set_efer);
1137 1189
1138#endif 1190#endif
1139 1191
1192int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1193{
1194 switch (msr) {
1195#ifdef CONFIG_X86_64
1196 case MSR_EFER:
1197 set_efer(vcpu, data);
1198 break;
1199#endif
1200 case MSR_IA32_MC0_STATUS:
1201 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n",
1202 __FUNCTION__, data);
1203 break;
1204 case MSR_IA32_UCODE_REV:
1205 case MSR_IA32_UCODE_WRITE:
1206 case 0x200 ... 0x2ff: /* MTRRs */
1207 break;
1208 case MSR_IA32_APICBASE:
1209 vcpu->apic_base = data;
1210 break;
1211 default:
1212 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr);
1213 return 1;
1214 }
1215 return 0;
1216}
1217EXPORT_SYMBOL_GPL(kvm_set_msr_common);
1218
1140/* 1219/*
1141 * Writes msr value into into the appropriate "register". 1220 * Writes msr value into into the appropriate "register".
1142 * Returns 0 on success, non-0 otherwise. 1221 * Returns 0 on success, non-0 otherwise.
@@ -1179,7 +1258,7 @@ static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run)
1179 struct kvm_vcpu *vcpu; 1258 struct kvm_vcpu *vcpu;
1180 int r; 1259 int r;
1181 1260
1182 if (kvm_run->vcpu < 0 || kvm_run->vcpu >= KVM_MAX_VCPUS) 1261 if (!valid_vcpu(kvm_run->vcpu))
1183 return -EINVAL; 1262 return -EINVAL;
1184 1263
1185 vcpu = vcpu_load(kvm, kvm_run->vcpu); 1264 vcpu = vcpu_load(kvm, kvm_run->vcpu);
@@ -1208,7 +1287,7 @@ static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs)
1208{ 1287{
1209 struct kvm_vcpu *vcpu; 1288 struct kvm_vcpu *vcpu;
1210 1289
1211 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS) 1290 if (!valid_vcpu(regs->vcpu))
1212 return -EINVAL; 1291 return -EINVAL;
1213 1292
1214 vcpu = vcpu_load(kvm, regs->vcpu); 1293 vcpu = vcpu_load(kvm, regs->vcpu);
@@ -1254,7 +1333,7 @@ static int kvm_dev_ioctl_set_regs(struct kvm *kvm, struct kvm_regs *regs)
1254{ 1333{
1255 struct kvm_vcpu *vcpu; 1334 struct kvm_vcpu *vcpu;
1256 1335
1257 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS) 1336 if (!valid_vcpu(regs->vcpu))
1258 return -EINVAL; 1337 return -EINVAL;
1259 1338
1260 vcpu = vcpu_load(kvm, regs->vcpu); 1339 vcpu = vcpu_load(kvm, regs->vcpu);
@@ -1301,7 +1380,7 @@ static int kvm_dev_ioctl_get_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1301 struct kvm_vcpu *vcpu; 1380 struct kvm_vcpu *vcpu;
1302 struct descriptor_table dt; 1381 struct descriptor_table dt;
1303 1382
1304 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS) 1383 if (!valid_vcpu(sregs->vcpu))
1305 return -EINVAL; 1384 return -EINVAL;
1306 vcpu = vcpu_load(kvm, sregs->vcpu); 1385 vcpu = vcpu_load(kvm, sregs->vcpu);
1307 if (!vcpu) 1386 if (!vcpu)
@@ -1353,7 +1432,7 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1353 int i; 1432 int i;
1354 struct descriptor_table dt; 1433 struct descriptor_table dt;
1355 1434
1356 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS) 1435 if (!valid_vcpu(sregs->vcpu))
1357 return -EINVAL; 1436 return -EINVAL;
1358 vcpu = vcpu_load(kvm, sregs->vcpu); 1437 vcpu = vcpu_load(kvm, sregs->vcpu);
1359 if (!vcpu) 1438 if (!vcpu)
@@ -1412,6 +1491,9 @@ static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1412/* 1491/*
1413 * List of msr numbers which we expose to userspace through KVM_GET_MSRS 1492 * List of msr numbers which we expose to userspace through KVM_GET_MSRS
1414 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. 1493 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
1494 *
1495 * This list is modified at module load time to reflect the
1496 * capabilities of the host cpu.
1415 */ 1497 */
1416static u32 msrs_to_save[] = { 1498static u32 msrs_to_save[] = {
1417 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP, 1499 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
@@ -1422,6 +1504,22 @@ static u32 msrs_to_save[] = {
1422 MSR_IA32_TIME_STAMP_COUNTER, 1504 MSR_IA32_TIME_STAMP_COUNTER,
1423}; 1505};
1424 1506
1507static unsigned num_msrs_to_save;
1508
1509static __init void kvm_init_msr_list(void)
1510{
1511 u32 dummy[2];
1512 unsigned i, j;
1513
1514 for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
1515 if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
1516 continue;
1517 if (j < i)
1518 msrs_to_save[j] = msrs_to_save[i];
1519 j++;
1520 }
1521 num_msrs_to_save = j;
1522}
1425 1523
1426/* 1524/*
1427 * Adapt set_msr() to msr_io()'s calling convention 1525 * Adapt set_msr() to msr_io()'s calling convention
@@ -1444,7 +1542,7 @@ static int __msr_io(struct kvm *kvm, struct kvm_msrs *msrs,
1444 struct kvm_vcpu *vcpu; 1542 struct kvm_vcpu *vcpu;
1445 int i; 1543 int i;
1446 1544
1447 if (msrs->vcpu < 0 || msrs->vcpu >= KVM_MAX_VCPUS) 1545 if (!valid_vcpu(msrs->vcpu))
1448 return -EINVAL; 1546 return -EINVAL;
1449 1547
1450 vcpu = vcpu_load(kvm, msrs->vcpu); 1548 vcpu = vcpu_load(kvm, msrs->vcpu);
@@ -1537,7 +1635,7 @@ static int kvm_dev_ioctl_interrupt(struct kvm *kvm, struct kvm_interrupt *irq)
1537{ 1635{
1538 struct kvm_vcpu *vcpu; 1636 struct kvm_vcpu *vcpu;
1539 1637
1540 if (irq->vcpu < 0 || irq->vcpu >= KVM_MAX_VCPUS) 1638 if (!valid_vcpu(irq->vcpu))
1541 return -EINVAL; 1639 return -EINVAL;
1542 if (irq->irq < 0 || irq->irq >= 256) 1640 if (irq->irq < 0 || irq->irq >= 256)
1543 return -EINVAL; 1641 return -EINVAL;
@@ -1559,7 +1657,7 @@ static int kvm_dev_ioctl_debug_guest(struct kvm *kvm,
1559 struct kvm_vcpu *vcpu; 1657 struct kvm_vcpu *vcpu;
1560 int r; 1658 int r;
1561 1659
1562 if (dbg->vcpu < 0 || dbg->vcpu >= KVM_MAX_VCPUS) 1660 if (!valid_vcpu(dbg->vcpu))
1563 return -EINVAL; 1661 return -EINVAL;
1564 vcpu = vcpu_load(kvm, dbg->vcpu); 1662 vcpu = vcpu_load(kvm, dbg->vcpu);
1565 if (!vcpu) 1663 if (!vcpu)
@@ -1579,6 +1677,9 @@ static long kvm_dev_ioctl(struct file *filp,
1579 int r = -EINVAL; 1677 int r = -EINVAL;
1580 1678
1581 switch (ioctl) { 1679 switch (ioctl) {
1680 case KVM_GET_API_VERSION:
1681 r = KVM_API_VERSION;
1682 break;
1582 case KVM_CREATE_VCPU: { 1683 case KVM_CREATE_VCPU: {
1583 r = kvm_dev_ioctl_create_vcpu(kvm, arg); 1684 r = kvm_dev_ioctl_create_vcpu(kvm, arg);
1584 if (r) 1685 if (r)
@@ -1730,15 +1831,15 @@ static long kvm_dev_ioctl(struct file *filp,
1730 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list)) 1831 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
1731 goto out; 1832 goto out;
1732 n = msr_list.nmsrs; 1833 n = msr_list.nmsrs;
1733 msr_list.nmsrs = ARRAY_SIZE(msrs_to_save); 1834 msr_list.nmsrs = num_msrs_to_save;
1734 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list)) 1835 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
1735 goto out; 1836 goto out;
1736 r = -E2BIG; 1837 r = -E2BIG;
1737 if (n < ARRAY_SIZE(msrs_to_save)) 1838 if (n < num_msrs_to_save)
1738 goto out; 1839 goto out;
1739 r = -EFAULT; 1840 r = -EFAULT;
1740 if (copy_to_user(user_msr_list->indices, &msrs_to_save, 1841 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
1741 sizeof msrs_to_save)) 1842 num_msrs_to_save * sizeof(u32)))
1742 goto out; 1843 goto out;
1743 r = 0; 1844 r = 0;
1744 } 1845 }
@@ -1838,6 +1939,11 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
1838{ 1939{
1839 int r; 1940 int r;
1840 1941
1942 if (kvm_arch_ops) {
1943 printk(KERN_ERR "kvm: already loaded the other module\n");
1944 return -EEXIST;
1945 }
1946
1841 kvm_arch_ops = ops; 1947 kvm_arch_ops = ops;
1842 1948
1843 if (!kvm_arch_ops->cpu_has_kvm_support()) { 1949 if (!kvm_arch_ops->cpu_has_kvm_support()) {
@@ -1880,6 +1986,7 @@ void kvm_exit_arch(void)
1880 unregister_reboot_notifier(&kvm_reboot_notifier); 1986 unregister_reboot_notifier(&kvm_reboot_notifier);
1881 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1); 1987 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
1882 kvm_arch_ops->hardware_unsetup(); 1988 kvm_arch_ops->hardware_unsetup();
1989 kvm_arch_ops = NULL;
1883} 1990}
1884 1991
1885static __init int kvm_init(void) 1992static __init int kvm_init(void)
@@ -1889,6 +1996,8 @@ static __init int kvm_init(void)
1889 1996
1890 kvm_init_debug(); 1997 kvm_init_debug();
1891 1998
1999 kvm_init_msr_list();
2000
1892 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) { 2001 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) {
1893 r = -ENOMEM; 2002 r = -ENOMEM;
1894 goto out; 2003 goto out;
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 3d367cbfe1f9..790423c5f23d 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -578,7 +578,7 @@ static int init_kvm_mmu(struct kvm_vcpu *vcpu)
578 578
579 if (!is_paging(vcpu)) 579 if (!is_paging(vcpu))
580 return nonpaging_init_context(vcpu); 580 return nonpaging_init_context(vcpu);
581 else if (kvm_arch_ops->is_long_mode(vcpu)) 581 else if (is_long_mode(vcpu))
582 return paging64_init_context(vcpu); 582 return paging64_init_context(vcpu);
583 else if (is_pae(vcpu)) 583 else if (is_pae(vcpu))
584 return paging32E_init_context(vcpu); 584 return paging32E_init_context(vcpu);
@@ -639,22 +639,22 @@ error_1:
639 return -ENOMEM; 639 return -ENOMEM;
640} 640}
641 641
642int kvm_mmu_init(struct kvm_vcpu *vcpu) 642int kvm_mmu_create(struct kvm_vcpu *vcpu)
643{ 643{
644 int r;
645
646 ASSERT(vcpu); 644 ASSERT(vcpu);
647 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa)); 645 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
648 ASSERT(list_empty(&vcpu->free_pages)); 646 ASSERT(list_empty(&vcpu->free_pages));
649 647
650 if ((r = alloc_mmu_pages(vcpu))) 648 return alloc_mmu_pages(vcpu);
651 return r; 649}
652 650
653 if ((r = init_kvm_mmu(vcpu))) { 651int kvm_mmu_setup(struct kvm_vcpu *vcpu)
654 free_mmu_pages(vcpu); 652{
655 return r; 653 ASSERT(vcpu);
656 } 654 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
657 return 0; 655 ASSERT(!list_empty(&vcpu->free_pages));
656
657 return init_kvm_mmu(vcpu);
658} 658}
659 659
660void kvm_mmu_destroy(struct kvm_vcpu *vcpu) 660void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index a9771b4c5bb8..09bb9b4ed12d 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -68,7 +68,7 @@ static void FNAME(init_walker)(struct guest_walker *walker,
68 hpa = safe_gpa_to_hpa(vcpu, vcpu->cr3 & PT64_BASE_ADDR_MASK); 68 hpa = safe_gpa_to_hpa(vcpu, vcpu->cr3 & PT64_BASE_ADDR_MASK);
69 walker->table = kmap_atomic(pfn_to_page(hpa >> PAGE_SHIFT), KM_USER0); 69 walker->table = kmap_atomic(pfn_to_page(hpa >> PAGE_SHIFT), KM_USER0);
70 70
71 ASSERT((!kvm_arch_ops->is_long_mode(vcpu) && is_pae(vcpu)) || 71 ASSERT((!is_long_mode(vcpu) && is_pae(vcpu)) ||
72 (vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) == 0); 72 (vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) == 0);
73 73
74 walker->table = (pt_element_t *)( (unsigned long)walker->table | 74 walker->table = (pt_element_t *)( (unsigned long)walker->table |
@@ -131,7 +131,7 @@ static pt_element_t *FNAME(fetch_guest)(struct kvm_vcpu *vcpu,
131 (walker->table[index] & PT_PAGE_SIZE_MASK) && 131 (walker->table[index] & PT_PAGE_SIZE_MASK) &&
132 (PTTYPE == 64 || is_pse(vcpu)))) 132 (PTTYPE == 64 || is_pse(vcpu))))
133 return &walker->table[index]; 133 return &walker->table[index];
134 if (walker->level != 3 || kvm_arch_ops->is_long_mode(vcpu)) 134 if (walker->level != 3 || is_long_mode(vcpu))
135 walker->inherited_ar &= walker->table[index]; 135 walker->inherited_ar &= walker->table[index];
136 paddr = safe_gpa_to_hpa(vcpu, walker->table[index] & PT_BASE_ADDR_MASK); 136 paddr = safe_gpa_to_hpa(vcpu, walker->table[index] & PT_BASE_ADDR_MASK);
137 kunmap_atomic(walker->table, KM_USER0); 137 kunmap_atomic(walker->table, KM_USER0);
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 0e6bc8c649ce..fa0428735717 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -166,11 +166,6 @@ static inline void write_dr7(unsigned long val)
166 asm volatile ("mov %0, %%dr7" :: "r" (val)); 166 asm volatile ("mov %0, %%dr7" :: "r" (val));
167} 167}
168 168
169static inline int svm_is_long_mode(struct kvm_vcpu *vcpu)
170{
171 return vcpu->svm->vmcb->save.efer & KVM_EFER_LMA;
172}
173
174static inline void force_new_asid(struct kvm_vcpu *vcpu) 169static inline void force_new_asid(struct kvm_vcpu *vcpu)
175{ 170{
176 vcpu->svm->asid_generation--; 171 vcpu->svm->asid_generation--;
@@ -246,7 +241,7 @@ static int has_svm(void)
246{ 241{
247 uint32_t eax, ebx, ecx, edx; 242 uint32_t eax, ebx, ecx, edx;
248 243
249 if (current_cpu_data.x86_vendor != X86_VENDOR_AMD) { 244 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) {
250 printk(KERN_INFO "has_svm: not amd\n"); 245 printk(KERN_INFO "has_svm: not amd\n");
251 return 0; 246 return 0;
252 } 247 }
@@ -402,11 +397,11 @@ static __init int svm_hardware_setup(void)
402 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1); 397 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1);
403 set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1); 398 set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1);
404 set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1); 399 set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1);
405 set_msr_interception(msrpm_va, MSR_STAR, 1, 1);
406 set_msr_interception(msrpm_va, MSR_LSTAR, 1, 1); 400 set_msr_interception(msrpm_va, MSR_LSTAR, 1, 1);
407 set_msr_interception(msrpm_va, MSR_CSTAR, 1, 1); 401 set_msr_interception(msrpm_va, MSR_CSTAR, 1, 1);
408 set_msr_interception(msrpm_va, MSR_SYSCALL_MASK, 1, 1); 402 set_msr_interception(msrpm_va, MSR_SYSCALL_MASK, 1, 1);
409#endif 403#endif
404 set_msr_interception(msrpm_va, MSR_K6_STAR, 1, 1);
410 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_CS, 1, 1); 405 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_CS, 1, 1);
411 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_ESP, 1, 1); 406 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_ESP, 1, 1);
412 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_EIP, 1, 1); 407 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_EIP, 1, 1);
@@ -575,6 +570,8 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
575 memset(vcpu->svm->db_regs, 0, sizeof(vcpu->svm->db_regs)); 570 memset(vcpu->svm->db_regs, 0, sizeof(vcpu->svm->db_regs));
576 init_vmcb(vcpu->svm->vmcb); 571 init_vmcb(vcpu->svm->vmcb);
577 572
573 fx_init(vcpu);
574
578 return 0; 575 return 0;
579 576
580out2: 577out2:
@@ -1071,20 +1068,6 @@ static int emulate_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_ru
1071static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data) 1068static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1072{ 1069{
1073 switch (ecx) { 1070 switch (ecx) {
1074 case MSR_IA32_MC0_CTL:
1075 case MSR_IA32_MCG_STATUS:
1076 case MSR_IA32_MCG_CAP:
1077 case MSR_IA32_MC0_MISC:
1078 case MSR_IA32_MC0_MISC+4:
1079 case MSR_IA32_MC0_MISC+8:
1080 case MSR_IA32_MC0_MISC+12:
1081 case MSR_IA32_MC0_MISC+16:
1082 case MSR_IA32_UCODE_REV:
1083 /* MTRR registers */
1084 case 0xfe:
1085 case 0x200 ... 0x2ff:
1086 *data = 0;
1087 break;
1088 case MSR_IA32_TIME_STAMP_COUNTER: { 1071 case MSR_IA32_TIME_STAMP_COUNTER: {
1089 u64 tsc; 1072 u64 tsc;
1090 1073
@@ -1092,16 +1075,10 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1092 *data = vcpu->svm->vmcb->control.tsc_offset + tsc; 1075 *data = vcpu->svm->vmcb->control.tsc_offset + tsc;
1093 break; 1076 break;
1094 } 1077 }
1095 case MSR_EFER: 1078 case MSR_K6_STAR:
1096 *data = vcpu->shadow_efer;
1097 break;
1098 case MSR_IA32_APICBASE:
1099 *data = vcpu->apic_base;
1100 break;
1101#ifdef CONFIG_X86_64
1102 case MSR_STAR:
1103 *data = vcpu->svm->vmcb->save.star; 1079 *data = vcpu->svm->vmcb->save.star;
1104 break; 1080 break;
1081#ifdef CONFIG_X86_64
1105 case MSR_LSTAR: 1082 case MSR_LSTAR:
1106 *data = vcpu->svm->vmcb->save.lstar; 1083 *data = vcpu->svm->vmcb->save.lstar;
1107 break; 1084 break;
@@ -1125,8 +1102,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1125 *data = vcpu->svm->vmcb->save.sysenter_esp; 1102 *data = vcpu->svm->vmcb->save.sysenter_esp;
1126 break; 1103 break;
1127 default: 1104 default:
1128 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", ecx); 1105 return kvm_get_msr_common(vcpu, ecx, data);
1129 return 1;
1130 } 1106 }
1131 return 0; 1107 return 0;
1132} 1108}
@@ -1150,15 +1126,6 @@ static int rdmsr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1150static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data) 1126static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1151{ 1127{
1152 switch (ecx) { 1128 switch (ecx) {
1153#ifdef CONFIG_X86_64
1154 case MSR_EFER:
1155 set_efer(vcpu, data);
1156 break;
1157#endif
1158 case MSR_IA32_MC0_STATUS:
1159 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
1160 , __FUNCTION__, data);
1161 break;
1162 case MSR_IA32_TIME_STAMP_COUNTER: { 1129 case MSR_IA32_TIME_STAMP_COUNTER: {
1163 u64 tsc; 1130 u64 tsc;
1164 1131
@@ -1166,17 +1133,10 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1166 vcpu->svm->vmcb->control.tsc_offset = data - tsc; 1133 vcpu->svm->vmcb->control.tsc_offset = data - tsc;
1167 break; 1134 break;
1168 } 1135 }
1169 case MSR_IA32_UCODE_REV: 1136 case MSR_K6_STAR:
1170 case MSR_IA32_UCODE_WRITE:
1171 case 0x200 ... 0x2ff: /* MTRRs */
1172 break;
1173 case MSR_IA32_APICBASE:
1174 vcpu->apic_base = data;
1175 break;
1176#ifdef CONFIG_X86_64_
1177 case MSR_STAR:
1178 vcpu->svm->vmcb->save.star = data; 1137 vcpu->svm->vmcb->save.star = data;
1179 break; 1138 break;
1139#ifdef CONFIG_X86_64_
1180 case MSR_LSTAR: 1140 case MSR_LSTAR:
1181 vcpu->svm->vmcb->save.lstar = data; 1141 vcpu->svm->vmcb->save.lstar = data;
1182 break; 1142 break;
@@ -1200,8 +1160,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1200 vcpu->svm->vmcb->save.sysenter_esp = data; 1160 vcpu->svm->vmcb->save.sysenter_esp = data;
1201 break; 1161 break;
1202 default: 1162 default:
1203 printk(KERN_ERR "kvm: unhandled wrmsr: %x\n", ecx); 1163 return kvm_set_msr_common(vcpu, ecx, data);
1204 return 1;
1205 } 1164 }
1206 return 0; 1165 return 0;
1207} 1166}
@@ -1387,6 +1346,10 @@ again:
1387 save_db_regs(vcpu->svm->host_db_regs); 1346 save_db_regs(vcpu->svm->host_db_regs);
1388 load_db_regs(vcpu->svm->db_regs); 1347 load_db_regs(vcpu->svm->db_regs);
1389 } 1348 }
1349
1350 fx_save(vcpu->host_fx_image);
1351 fx_restore(vcpu->guest_fx_image);
1352
1390 asm volatile ( 1353 asm volatile (
1391#ifdef CONFIG_X86_64 1354#ifdef CONFIG_X86_64
1392 "push %%rbx; push %%rcx; push %%rdx;" 1355 "push %%rbx; push %%rcx; push %%rdx;"
@@ -1496,6 +1459,9 @@ again:
1496#endif 1459#endif
1497 : "cc", "memory" ); 1460 : "cc", "memory" );
1498 1461
1462 fx_save(vcpu->guest_fx_image);
1463 fx_restore(vcpu->host_fx_image);
1464
1499 if ((vcpu->svm->vmcb->save.dr7 & 0xff)) 1465 if ((vcpu->svm->vmcb->save.dr7 & 0xff))
1500 load_db_regs(vcpu->svm->host_db_regs); 1466 load_db_regs(vcpu->svm->host_db_regs);
1501 1467
@@ -1598,7 +1564,6 @@ static struct kvm_arch_ops svm_arch_ops = {
1598 .get_segment_base = svm_get_segment_base, 1564 .get_segment_base = svm_get_segment_base,
1599 .get_segment = svm_get_segment, 1565 .get_segment = svm_get_segment,
1600 .set_segment = svm_set_segment, 1566 .set_segment = svm_set_segment,
1601 .is_long_mode = svm_is_long_mode,
1602 .get_cs_db_l_bits = svm_get_cs_db_l_bits, 1567 .get_cs_db_l_bits = svm_get_cs_db_l_bits,
1603 .set_cr0 = svm_set_cr0, 1568 .set_cr0 = svm_set_cr0,
1604 .set_cr0_no_modeswitch = svm_set_cr0, 1569 .set_cr0_no_modeswitch = svm_set_cr0,
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index f0f0b1a781f8..d0a2c2d5342a 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -26,7 +26,6 @@
26 26
27#include "segment_descriptor.h" 27#include "segment_descriptor.h"
28 28
29#define MSR_IA32_FEATURE_CONTROL 0x03a
30 29
31MODULE_AUTHOR("Qumranet"); 30MODULE_AUTHOR("Qumranet");
32MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
@@ -344,8 +343,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
344 data = vmcs_readl(GUEST_GS_BASE); 343 data = vmcs_readl(GUEST_GS_BASE);
345 break; 344 break;
346 case MSR_EFER: 345 case MSR_EFER:
347 data = vcpu->shadow_efer; 346 return kvm_get_msr_common(vcpu, msr_index, pdata);
348 break;
349#endif 347#endif
350 case MSR_IA32_TIME_STAMP_COUNTER: 348 case MSR_IA32_TIME_STAMP_COUNTER:
351 data = guest_read_tsc(); 349 data = guest_read_tsc();
@@ -359,31 +357,13 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
359 case MSR_IA32_SYSENTER_ESP: 357 case MSR_IA32_SYSENTER_ESP:
360 data = vmcs_read32(GUEST_SYSENTER_ESP); 358 data = vmcs_read32(GUEST_SYSENTER_ESP);
361 break; 359 break;
362 case MSR_IA32_MC0_CTL:
363 case MSR_IA32_MCG_STATUS:
364 case MSR_IA32_MCG_CAP:
365 case MSR_IA32_MC0_MISC:
366 case MSR_IA32_MC0_MISC+4:
367 case MSR_IA32_MC0_MISC+8:
368 case MSR_IA32_MC0_MISC+12:
369 case MSR_IA32_MC0_MISC+16:
370 case MSR_IA32_UCODE_REV:
371 /* MTRR registers */
372 case 0xfe:
373 case 0x200 ... 0x2ff:
374 data = 0;
375 break;
376 case MSR_IA32_APICBASE:
377 data = vcpu->apic_base;
378 break;
379 default: 360 default:
380 msr = find_msr_entry(vcpu, msr_index); 361 msr = find_msr_entry(vcpu, msr_index);
381 if (!msr) { 362 if (msr) {
382 printk(KERN_ERR "kvm: unhandled rdmsr: %x\n", msr_index); 363 data = msr->data;
383 return 1; 364 break;
384 } 365 }
385 data = msr->data; 366 return kvm_get_msr_common(vcpu, msr_index, pdata);
386 break;
387 } 367 }
388 368
389 *pdata = data; 369 *pdata = data;
@@ -400,6 +380,8 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
400 struct vmx_msr_entry *msr; 380 struct vmx_msr_entry *msr;
401 switch (msr_index) { 381 switch (msr_index) {
402#ifdef CONFIG_X86_64 382#ifdef CONFIG_X86_64
383 case MSR_EFER:
384 return kvm_set_msr_common(vcpu, msr_index, data);
403 case MSR_FS_BASE: 385 case MSR_FS_BASE:
404 vmcs_writel(GUEST_FS_BASE, data); 386 vmcs_writel(GUEST_FS_BASE, data);
405 break; 387 break;
@@ -416,32 +398,17 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
416 case MSR_IA32_SYSENTER_ESP: 398 case MSR_IA32_SYSENTER_ESP:
417 vmcs_write32(GUEST_SYSENTER_ESP, data); 399 vmcs_write32(GUEST_SYSENTER_ESP, data);
418 break; 400 break;
419#ifdef __x86_64
420 case MSR_EFER:
421 set_efer(vcpu, data);
422 break;
423 case MSR_IA32_MC0_STATUS:
424 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
425 , __FUNCTION__, data);
426 break;
427#endif
428 case MSR_IA32_TIME_STAMP_COUNTER: { 401 case MSR_IA32_TIME_STAMP_COUNTER: {
429 guest_write_tsc(data); 402 guest_write_tsc(data);
430 break; 403 break;
431 } 404 }
432 case MSR_IA32_UCODE_REV:
433 case MSR_IA32_UCODE_WRITE:
434 case 0x200 ... 0x2ff: /* MTRRs */
435 break;
436 case MSR_IA32_APICBASE:
437 vcpu->apic_base = data;
438 break;
439 default: 405 default:
440 msr = find_msr_entry(vcpu, msr_index); 406 msr = find_msr_entry(vcpu, msr_index);
441 if (!msr) { 407 if (msr) {
442 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr_index); 408 msr->data = data;
443 return 1; 409 break;
444 } 410 }
411 return kvm_set_msr_common(vcpu, msr_index, data);
445 msr->data = data; 412 msr->data = data;
446 break; 413 break;
447 } 414 }
@@ -551,11 +518,11 @@ static __init void setup_vmcs_descriptor(void)
551{ 518{
552 u32 vmx_msr_low, vmx_msr_high; 519 u32 vmx_msr_low, vmx_msr_high;
553 520
554 rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high); 521 rdmsr(MSR_IA32_VMX_BASIC, vmx_msr_low, vmx_msr_high);
555 vmcs_descriptor.size = vmx_msr_high & 0x1fff; 522 vmcs_descriptor.size = vmx_msr_high & 0x1fff;
556 vmcs_descriptor.order = get_order(vmcs_descriptor.size); 523 vmcs_descriptor.order = get_order(vmcs_descriptor.size);
557 vmcs_descriptor.revision_id = vmx_msr_low; 524 vmcs_descriptor.revision_id = vmx_msr_low;
558}; 525}
559 526
560static struct vmcs *alloc_vmcs_cpu(int cpu) 527static struct vmcs *alloc_vmcs_cpu(int cpu)
561{ 528{
@@ -726,6 +693,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
726 vmcs_write32(GUEST_SS_AR_BYTES, 0xf3); 693 vmcs_write32(GUEST_SS_AR_BYTES, 0xf3);
727 694
728 vmcs_write32(GUEST_CS_AR_BYTES, 0xf3); 695 vmcs_write32(GUEST_CS_AR_BYTES, 0xf3);
696 vmcs_write32(GUEST_CS_LIMIT, 0xffff);
729 vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4); 697 vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4);
730 698
731 fix_rmode_seg(VCPU_SREG_ES, &vcpu->rmode.es); 699 fix_rmode_seg(VCPU_SREG_ES, &vcpu->rmode.es);
@@ -897,11 +865,6 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
897 vmcs_write32(sf->ar_bytes, ar); 865 vmcs_write32(sf->ar_bytes, ar);
898} 866}
899 867
900static int vmx_is_long_mode(struct kvm_vcpu *vcpu)
901{
902 return vmcs_read32(VM_ENTRY_CONTROLS) & VM_ENTRY_CONTROLS_IA32E_MASK;
903}
904
905static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l) 868static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
906{ 869{
907 u32 ar = vmcs_read32(GUEST_CS_AR_BYTES); 870 u32 ar = vmcs_read32(GUEST_CS_AR_BYTES);
@@ -1075,12 +1038,12 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1075 vmcs_write64(GUEST_IA32_DEBUGCTL, 0); 1038 vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
1076 1039
1077 /* Control */ 1040 /* Control */
1078 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS_MSR, 1041 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS,
1079 PIN_BASED_VM_EXEC_CONTROL, 1042 PIN_BASED_VM_EXEC_CONTROL,
1080 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */ 1043 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */
1081 | PIN_BASED_NMI_EXITING /* 20.6.1 */ 1044 | PIN_BASED_NMI_EXITING /* 20.6.1 */
1082 ); 1045 );
1083 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS_MSR, 1046 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS,
1084 CPU_BASED_VM_EXEC_CONTROL, 1047 CPU_BASED_VM_EXEC_CONTROL,
1085 CPU_BASED_HLT_EXITING /* 20.6.2 */ 1048 CPU_BASED_HLT_EXITING /* 20.6.2 */
1086 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */ 1049 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */
@@ -1163,7 +1126,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1163 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS)); 1126 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS));
1164 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR, 1127 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR,
1165 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS)); 1128 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS));
1166 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS_MSR, VM_EXIT_CONTROLS, 1129 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS, VM_EXIT_CONTROLS,
1167 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */ 1130 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */
1168 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */ 1131 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */
1169 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */ 1132 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */
@@ -1171,7 +1134,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1171 1134
1172 1135
1173 /* 22.2.1, 20.8.1 */ 1136 /* 22.2.1, 20.8.1 */
1174 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS_MSR, 1137 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS,
1175 VM_ENTRY_CONTROLS, 0); 1138 VM_ENTRY_CONTROLS, 0);
1176 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ 1139 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
1177 1140
@@ -1972,7 +1935,6 @@ static struct kvm_arch_ops vmx_arch_ops = {
1972 .get_segment_base = vmx_get_segment_base, 1935 .get_segment_base = vmx_get_segment_base,
1973 .get_segment = vmx_get_segment, 1936 .get_segment = vmx_get_segment,
1974 .set_segment = vmx_set_segment, 1937 .set_segment = vmx_set_segment,
1975 .is_long_mode = vmx_is_long_mode,
1976 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 1938 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
1977 .set_cr0 = vmx_set_cr0, 1939 .set_cr0 = vmx_set_cr0,
1978 .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch, 1940 .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch,
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index 797278341581..4c0ab151836a 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -286,11 +286,11 @@ enum vmcs_field {
286 286
287#define CR4_VMXE 0x2000 287#define CR4_VMXE 0x2000
288 288
289#define MSR_IA32_VMX_BASIC_MSR 0x480 289#define MSR_IA32_VMX_BASIC 0x480
290#define MSR_IA32_FEATURE_CONTROL 0x03a 290#define MSR_IA32_FEATURE_CONTROL 0x03a
291#define MSR_IA32_VMX_PINBASED_CTLS_MSR 0x481 291#define MSR_IA32_VMX_PINBASED_CTLS 0x481
292#define MSR_IA32_VMX_PROCBASED_CTLS_MSR 0x482 292#define MSR_IA32_VMX_PROCBASED_CTLS 0x482
293#define MSR_IA32_VMX_EXIT_CTLS_MSR 0x483 293#define MSR_IA32_VMX_EXIT_CTLS 0x483
294#define MSR_IA32_VMX_ENTRY_CTLS_MSR 0x484 294#define MSR_IA32_VMX_ENTRY_CTLS 0x484
295 295
296#endif 296#endif
diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
index 6c29fe727c0f..801a974342f9 100644
--- a/drivers/macintosh/via-pmu-backlight.c
+++ b/drivers/macintosh/via-pmu-backlight.c
@@ -147,7 +147,7 @@ void __init pmu_backlight_init()
147 147
148 snprintf(name, sizeof(name), "pmubl"); 148 snprintf(name, sizeof(name), "pmubl");
149 149
150 bd = backlight_device_register(name, NULL, &pmu_backlight_data); 150 bd = backlight_device_register(name, NULL, NULL, &pmu_backlight_data);
151 if (IS_ERR(bd)) { 151 if (IS_ERR(bd)) {
152 printk("pmubl: Backlight registration failed\n"); 152 printk("pmubl: Backlight registration failed\n");
153 goto error; 153 goto error;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 21e2a7b08841..d1cb45f6d6a9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1792,7 +1792,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
1792 else { 1792 else {
1793 mddev_t *mddev = rdev->mddev; 1793 mddev_t *mddev = rdev->mddev;
1794 kick_rdev_from_array(rdev); 1794 kick_rdev_from_array(rdev);
1795 md_update_sb(mddev, 1); 1795 if (mddev->pers)
1796 md_update_sb(mddev, 1);
1796 md_new_event(mddev); 1797 md_new_event(mddev);
1797 err = 0; 1798 err = 0;
1798 } 1799 }
@@ -2004,6 +2005,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
2004 2005
2005 rdev->desc_nr = -1; 2006 rdev->desc_nr = -1;
2006 rdev->saved_raid_disk = -1; 2007 rdev->saved_raid_disk = -1;
2008 rdev->raid_disk = -1;
2007 rdev->flags = 0; 2009 rdev->flags = 0;
2008 rdev->data_offset = 0; 2010 rdev->data_offset = 0;
2009 rdev->sb_events = 0; 2011 rdev->sb_events = 0;
@@ -2233,7 +2235,6 @@ static int update_raid_disks(mddev_t *mddev, int raid_disks);
2233static ssize_t 2235static ssize_t
2234raid_disks_store(mddev_t *mddev, const char *buf, size_t len) 2236raid_disks_store(mddev_t *mddev, const char *buf, size_t len)
2235{ 2237{
2236 /* can only set raid_disks if array is not yet active */
2237 char *e; 2238 char *e;
2238 int rv = 0; 2239 int rv = 0;
2239 unsigned long n = simple_strtoul(buf, &e, 10); 2240 unsigned long n = simple_strtoul(buf, &e, 10);
@@ -2631,7 +2632,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
2631 return -EINVAL; 2632 return -EINVAL;
2632 buf = e+1; 2633 buf = e+1;
2633 minor = simple_strtoul(buf, &e, 10); 2634 minor = simple_strtoul(buf, &e, 10);
2634 if (e==buf || *e != '\n') 2635 if (e==buf || (*e && *e != '\n') )
2635 return -EINVAL; 2636 return -EINVAL;
2636 if (major >= sizeof(super_types)/sizeof(super_types[0]) || 2637 if (major >= sizeof(super_types)/sizeof(super_types[0]) ||
2637 super_types[major].name == NULL) 2638 super_types[major].name == NULL)
@@ -3980,6 +3981,7 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
3980 mddev->major_version = info->major_version; 3981 mddev->major_version = info->major_version;
3981 mddev->minor_version = info->minor_version; 3982 mddev->minor_version = info->minor_version;
3982 mddev->patch_version = info->patch_version; 3983 mddev->patch_version = info->patch_version;
3984 mddev->persistent = !info->not_persistent;
3983 return 0; 3985 return 0;
3984 } 3986 }
3985 mddev->major_version = MD_MAJOR_VERSION; 3987 mddev->major_version = MD_MAJOR_VERSION;
@@ -4304,9 +4306,10 @@ static int md_ioctl(struct inode *inode, struct file *file,
4304 * Commands querying/configuring an existing array: 4306 * Commands querying/configuring an existing array:
4305 */ 4307 */
4306 /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY, 4308 /* if we are not initialised yet, only ADD_NEW_DISK, STOP_ARRAY,
4307 * RUN_ARRAY, and SET_BITMAP_FILE are allowed */ 4309 * RUN_ARRAY, and GET_ and SET_BITMAP_FILE are allowed */
4308 if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY 4310 if (!mddev->raid_disks && cmd != ADD_NEW_DISK && cmd != STOP_ARRAY
4309 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE) { 4311 && cmd != RUN_ARRAY && cmd != SET_BITMAP_FILE
4312 && cmd != GET_BITMAP_FILE) {
4310 err = -ENODEV; 4313 err = -ENODEV;
4311 goto abort_unlock; 4314 goto abort_unlock;
4312 } 4315 }
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index 8eaa88fd8b9b..9a8dd8764c99 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/string.h> 25#include <linux/string.h>
26#include <linux/jiffies.h>
26#include <media/ir-common.h> 27#include <media/ir-common.h>
27 28
28/* -------------------------------------------------------------------------- */ 29/* -------------------------------------------------------------------------- */
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index ebf4dc5190f6..76e9c36597eb 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -605,7 +605,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
605 { &utype, sizeof utype }, 605 { &utype, sizeof utype },
606 { priv->ule_skb->data, priv->ule_skb->len - 4 } 606 { priv->ule_skb->data, priv->ule_skb->len - 4 }
607 }; 607 };
608 unsigned long ule_crc = ~0L, expected_crc; 608 u32 ule_crc = ~0L, expected_crc;
609 if (priv->ule_dbit) { 609 if (priv->ule_dbit) {
610 /* Set D-bit for CRC32 verification, 610 /* Set D-bit for CRC32 verification,
611 * if it was set originally. */ 611 * if it was set originally. */
@@ -618,7 +618,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
618 *((u8 *)priv->ule_skb->tail - 2) << 8 | 618 *((u8 *)priv->ule_skb->tail - 2) << 8 |
619 *((u8 *)priv->ule_skb->tail - 1); 619 *((u8 *)priv->ule_skb->tail - 1);
620 if (ule_crc != expected_crc) { 620 if (ule_crc != expected_crc) {
621 printk(KERN_WARNING "%lu: CRC32 check FAILED: %#lx / %#lx, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n", 621 printk(KERN_WARNING "%lu: CRC32 check FAILED: %08x / %08x, SNDU len %d type %#x, ts_remain %d, next 2: %x.\n",
622 priv->ts_count, ule_crc, expected_crc, priv->ule_sndu_len, priv->ule_sndu_type, ts_remain, ts_remain > 2 ? *(unsigned short *)from_where : 0); 622 priv->ts_count, ule_crc, expected_crc, priv->ule_sndu_len, priv->ule_sndu_type, ts_remain, ts_remain > 2 ? *(unsigned short *)from_where : 0);
623 623
624#ifdef ULE_DEBUG 624#ifdef ULE_DEBUG
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index d48622e76b1b..badc468170ea 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -90,9 +90,11 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
90 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle); 90 deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
91 91
92 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) { 92 for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
93 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
94 if (haupp_rc_keys[i].data == data && 93 if (haupp_rc_keys[i].data == data &&
95 haupp_rc_keys[i].custom == custom) { 94 haupp_rc_keys[i].custom == custom) {
95
96 deb_rc("c: %x, d: %x\n",haupp_rc_keys[i].data,haupp_rc_keys[i].custom);
97
96 *event = haupp_rc_keys[i].event; 98 *event = haupp_rc_keys[i].event;
97 *state = REMOTE_KEY_PRESSED; 99 *state = REMOTE_KEY_PRESSED;
98 if (st->old_toggle == toggle) { 100 if (st->old_toggle == toggle) {
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 5da66178006c..23aa75a27c1f 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -515,7 +515,7 @@ static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dibx000
515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2; 515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2;
516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1; 516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1;
517 517
518 dib3000mc_set_channel_cfg(state, &fchan, 7); 518 dib3000mc_set_channel_cfg(state, &fchan, 11);
519 519
520 reg = dib3000mc_read_word(state, 0); 520 reg = dib3000mc_read_word(state, 0);
521 dib3000mc_write_word(state, 0, reg | (1 << 8)); 521 dib3000mc_write_word(state, 0, reg | (1 << 8));
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 29a11c1db1b7..57357db31b8a 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -668,7 +668,7 @@ config VIDEO_M32R_AR_M64278
668 668
669config VIDEO_CAFE_CCIC 669config VIDEO_CAFE_CCIC
670 tristate "Marvell 88ALP01 (Cafe) CMOS Camera Controller support" 670 tristate "Marvell 88ALP01 (Cafe) CMOS Camera Controller support"
671 depends on I2C && VIDEO_V4L2 671 depends on PCI && I2C && VIDEO_V4L2
672 select VIDEO_OV7670 672 select VIDEO_OV7670
673 ---help--- 673 ---help---
674 This is a video4linux2 driver for the Marvell 88ALP01 integrated 674 This is a video4linux2 driver for the Marvell 88ALP01 integrated
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 3c8e4742dccc..ab8f970760f2 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -4050,8 +4050,8 @@ static int __devinit bttv_probe(struct pci_dev *dev,
4050 (unsigned long long)pci_resource_start(dev,0)); 4050 (unsigned long long)pci_resource_start(dev,0));
4051 schedule(); 4051 schedule();
4052 4052
4053 btv->bt848_mmio=ioremap(pci_resource_start(dev,0), 0x1000); 4053 btv->bt848_mmio = ioremap(pci_resource_start(dev, 0), 0x1000);
4054 if (NULL == ioremap(pci_resource_start(dev,0), 0x1000)) { 4054 if (NULL == btv->bt848_mmio) {
4055 printk("bttv%d: ioremap() failed\n", btv->c.nr); 4055 printk("bttv%d: ioremap() failed\n", btv->c.nr);
4056 result = -EIO; 4056 result = -EIO;
4057 goto fail1; 4057 goto fail1;
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index e347c7ebc984..3083c8075d13 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -2166,7 +2166,7 @@ static void cafe_pci_remove(struct pci_dev *pdev)
2166 struct cafe_camera *cam = cafe_find_by_pdev(pdev); 2166 struct cafe_camera *cam = cafe_find_by_pdev(pdev);
2167 2167
2168 if (cam == NULL) { 2168 if (cam == NULL) {
2169 cam_warn(cam, "pci_remove on unknown pdev %p\n", pdev); 2169 printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev);
2170 return; 2170 return;
2171 } 2171 }
2172 mutex_lock(&cam->s_mutex); 2172 mutex_lock(&cam->s_mutex);
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
index 28dc6a1a1e43..d8e929863a88 100644
--- a/drivers/media/video/cpia2/cpia2_usb.c
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -640,6 +640,10 @@ static int submit_urbs(struct camera_data *cam)
640 cam->sbuf[i].data = 640 cam->sbuf[i].data =
641 kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL); 641 kmalloc(FRAMES_PER_DESC * FRAME_SIZE_PER_DESC, GFP_KERNEL);
642 if (!cam->sbuf[i].data) { 642 if (!cam->sbuf[i].data) {
643 while (--i >= 0) {
644 kfree(cam->sbuf[i].data);
645 cam->sbuf[i].data = NULL;
646 }
643 return -ENOMEM; 647 return -ENOMEM;
644 } 648 }
645 } 649 }
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 657e0b969145..2f5ca71e0261 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -742,7 +742,6 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
742 742
743 if (old == NULL || old->width != new->width || old->height != new->height || 743 if (old == NULL || old->width != new->width || old->height != new->height ||
744 old->video_encoding != new->video_encoding) { 744 old->video_encoding != new->video_encoding) {
745 int is_scaling;
746 u16 w = new->width; 745 u16 w = new->width;
747 u16 h = new->height; 746 u16 h = new->height;
748 747
@@ -752,20 +751,18 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
752 } 751 }
753 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w); 752 err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, h, w);
754 if (err) return err; 753 if (err) return err;
754 }
755 755
756 if (new->width != 720 || new->height != (new->is_50hz ? 576 : 480)) {
756 /* Adjust temporal filter if necessary. The problem with the temporal 757 /* Adjust temporal filter if necessary. The problem with the temporal
757 filter is that it works well with full resolution capturing, but 758 filter is that it works well with full resolution capturing, but
758 not when the capture window is scaled (the filter introduces 759 not when the capture window is scaled (the filter introduces
759 a ghosting effect). So if the capture window changed, and there is 760 a ghosting effect). So if the capture window is scaled, then
760 no updated filter value, then the filter is set depending on whether 761 force the filter to 0.
761 the new window is full resolution or not.
762 762
763 For full resolution a setting of 8 really improves the video 763 For full resolution the filter really improves the video
764 quality, especially if the original video quality is suboptimal. */ 764 quality, especially if the original video quality is suboptimal. */
765 is_scaling = new->width != 720 || new->height != (new->is_50hz ? 576 : 480); 765 temporal = 0;
766 if (old && old->video_temporal_filter == temporal) {
767 temporal = is_scaling ? 0 : 8;
768 }
769 } 766 }
770 767
771 if (old == NULL || old->stream_type != new->stream_type) { 768 if (old == NULL || old->stream_type != new->stream_type) {
@@ -866,6 +863,7 @@ invalid:
866void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix) 863void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
867{ 864{
868 int is_mpeg1 = p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1; 865 int is_mpeg1 = p->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1;
866 int temporal = p->video_temporal_filter;
869 867
870 /* Stream */ 868 /* Stream */
871 printk(KERN_INFO "%s: Stream: %s\n", 869 printk(KERN_INFO "%s: Stream: %s\n",
@@ -922,10 +920,13 @@ void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix)
922 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE), 920 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE),
923 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE), 921 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE),
924 p->video_spatial_filter); 922 p->video_spatial_filter);
923 if (p->width != 720 || p->height != (p->is_50hz ? 576 : 480)) {
924 temporal = 0;
925 }
925 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n", 926 printk(KERN_INFO "%s: Temporal Filter: %s, %d\n",
926 prefix, 927 prefix,
927 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE), 928 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE),
928 p->video_temporal_filter); 929 temporal);
929 printk(KERN_INFO "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n", 930 printk(KERN_INFO "%s: Median Filter: %s, Luma [%d, %d], Chroma [%d, %d]\n",
930 prefix, 931 prefix,
931 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE), 932 cx2341x_menu_item(p, V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE),
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index f85f2084324f..ced13febed89 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -128,7 +128,14 @@ void cx25840_vbi_setup(struct i2c_client *client)
128 uv_lpf=1; 128 uv_lpf=1;
129 129
130 src_decimation=0x21f; 130 src_decimation=0x21f;
131 if (std == V4L2_STD_PAL_M) { 131 if (std == V4L2_STD_PAL_60) {
132 vblank=26;
133 vblank656=26;
134 burst=0x5b;
135 luma_lpf=2;
136 comb=0x20;
137 sc=0x0a8263;
138 } else if (std == V4L2_STD_PAL_M) {
132 vblank=20; 139 vblank=20;
133 vblank656=24; 140 vblank656=24;
134 burst=0x61; 141 burst=0x61;
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index c791708b1336..434b78ab37d8 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1632,7 +1632,7 @@ const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
1632/* ----------------------------------------------------------------------- */ 1632/* ----------------------------------------------------------------------- */
1633/* some leadtek specific stuff */ 1633/* some leadtek specific stuff */
1634 1634
1635static void __devinit leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data) 1635static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
1636{ 1636{
1637 /* This is just for the "Winfast 2000XP Expert" board ATM; I don't have data on 1637 /* This is just for the "Winfast 2000XP Expert" board ATM; I don't have data on
1638 * any others. 1638 * any others.
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 453af5e943ff..18997361c75a 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -633,12 +633,12 @@ int cx88_reset(struct cx88_core *core)
633 633
634static unsigned int inline norm_swidth(struct cx88_tvnorm *norm) 634static unsigned int inline norm_swidth(struct cx88_tvnorm *norm)
635{ 635{
636 return (norm->id & V4L2_STD_625_50) ? 922 : 754; 636 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 754 : 922;
637} 637}
638 638
639static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm) 639static unsigned int inline norm_hdelay(struct cx88_tvnorm *norm)
640{ 640{
641 return (norm->id & V4L2_STD_625_50) ? 186 : 135; 641 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 135 : 186;
642} 642}
643 643
644static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm) 644static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm)
@@ -648,24 +648,33 @@ static unsigned int inline norm_vdelay(struct cx88_tvnorm *norm)
648 648
649static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm) 649static unsigned int inline norm_fsc8(struct cx88_tvnorm *norm)
650{ 650{
651 static const unsigned int ntsc = 28636360;
652 static const unsigned int pal = 35468950;
653 static const unsigned int palm = 28604892;
654
655 if (norm->id & V4L2_STD_PAL_M) 651 if (norm->id & V4L2_STD_PAL_M)
656 return palm; 652 return 28604892; // 3.575611 MHz
653
654 if (norm->id & (V4L2_STD_PAL_Nc))
655 return 28656448; // 3.582056 MHz
656
657 if (norm->id & V4L2_STD_NTSC) // All NTSC/M and variants
658 return 28636360; // 3.57954545 MHz +/- 10 Hz
657 659
658 return (norm->id & V4L2_STD_625_50) ? pal : ntsc; 660 /* SECAM have also different sub carrier for chroma,
661 but step_db and step_dr, at cx88_set_tvnorm already handles that.
662
663 The same FSC applies to PAL/BGDKIH, PAL/60, NTSC/4.43 and PAL/N
664 */
665
666 return 35468950; // 4.43361875 MHz +/- 5 Hz
659} 667}
660 668
661static unsigned int inline norm_htotal(struct cx88_tvnorm *norm) 669static unsigned int inline norm_htotal(struct cx88_tvnorm *norm)
662{ 670{
663 /* Should always be Line Draw Time / (4*FSC) */
664 671
665 if (norm->id & V4L2_STD_PAL_M) 672 unsigned int fsc4=norm_fsc8(norm)/2;
666 return 909;
667 673
668 return (norm->id & V4L2_STD_625_50) ? 1135 : 910; 674 /* returns 4*FSC / vtotal / frames per seconds */
675 return (norm->id & V4L2_STD_625_50) ?
676 ((fsc4+312)/625+12)/25 :
677 ((fsc4+262)/525*1001+15000)/30000;
669} 678}
670 679
671static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm) 680static unsigned int inline norm_vbipack(struct cx88_tvnorm *norm)
@@ -692,7 +701,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
692 value &= 0x3fe; 701 value &= 0x3fe;
693 cx_write(MO_HDELAY_EVEN, value); 702 cx_write(MO_HDELAY_EVEN, value);
694 cx_write(MO_HDELAY_ODD, value); 703 cx_write(MO_HDELAY_ODD, value);
695 dprintk(1,"set_scale: hdelay 0x%04x\n", value); 704 dprintk(1,"set_scale: hdelay 0x%04x (width %d)\n", value,swidth);
696 705
697 value = (swidth * 4096 / width) - 4096; 706 value = (swidth * 4096 / width) - 4096;
698 cx_write(MO_HSCALE_EVEN, value); 707 cx_write(MO_HSCALE_EVEN, value);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 7054e941f1d7..a9575ad8ca27 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -91,7 +91,7 @@ struct cx88_tvnorm {
91 91
92static unsigned int inline norm_maxw(struct cx88_tvnorm *norm) 92static unsigned int inline norm_maxw(struct cx88_tvnorm *norm)
93{ 93{
94 return (norm->id & V4L2_STD_625_50) ? 768 : 640; 94 return (norm->id & (V4L2_STD_MN & ~V4L2_STD_PAL_Nc)) ? 720 : 768;
95} 95}
96 96
97 97
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2a461dde480c..36e72c207a8f 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1674,9 +1674,9 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1674 if (dev->has_msp34xx) { 1674 if (dev->has_msp34xx) {
1675 /* Send a reset to other chips via gpio */ 1675 /* Send a reset to other chips via gpio */
1676 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); 1676 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
1677 udelay(2500); 1677 msleep(3);
1678 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1); 1678 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
1679 udelay(2500); 1679 msleep(3);
1680 1680
1681 } 1681 }
1682 video_mux(dev, 0); 1682 video_mux(dev, 0);
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index b083338823df..616a35da191d 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -923,7 +923,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
923 struct video_picture *p = arg; 923 struct video_picture *p = arg;
924 if (p->depth != 16) 924 if (p->depth != 16)
925 return -EINVAL; 925 return -EINVAL;
926 if (p->palette != VIDEO_PALETTE_YUV422) 926 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
927 return -EINVAL; 927 return -EINVAL;
928 mutex_lock(&meye.lock); 928 mutex_lock(&meye.lock);
929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 929 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS,
@@ -978,7 +978,7 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
978 978
979 if (vm->frame >= gbuffers || vm->frame < 0) 979 if (vm->frame >= gbuffers || vm->frame < 0)
980 return -EINVAL; 980 return -EINVAL;
981 if (vm->format != VIDEO_PALETTE_YUV422) 981 if (vm->format != VIDEO_PALETTE_YUV422 && vm->format != VIDEO_PALETTE_YUYV)
982 return -EINVAL; 982 return -EINVAL;
983 if (vm->height * vm->width * 2 > gbufsize) 983 if (vm->height * vm->width * 2 > gbufsize)
984 return -EINVAL; 984 return -EINVAL;
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index e1b56dc13c3f..2fb9fe6a1ae7 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -633,10 +633,8 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
633 if (((rt->input >> (4 + i * 4)) & 0xf) == 0) 633 if (((rt->input >> (4 + i * 4)) & 0xf) == 0)
634 extern_input = 0; 634 extern_input = 0;
635 } 635 }
636 if (extern_input) 636 state->mode = extern_input ? MSP_MODE_EXTERN : MSP_MODE_AM_DETECT;
637 state->mode = MSP_MODE_EXTERN; 637 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
638 else
639 state->mode = MSP_MODE_AM_DETECT;
640 msp_set_scart(client, sc_in, 0); 638 msp_set_scart(client, sc_in, 0);
641 msp_set_scart(client, sc1_out, 1); 639 msp_set_scart(client, sc1_out, 1);
642 msp_set_scart(client, sc2_out, 2); 640 msp_set_scart(client, sc2_out, 2);
@@ -951,7 +949,7 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
951 if (thread_func) { 949 if (thread_func) {
952 state->kthread = kthread_run(thread_func, client, "msp34xx"); 950 state->kthread = kthread_run(thread_func, client, "msp34xx");
953 951
954 if (state->kthread == NULL) 952 if (IS_ERR(state->kthread))
955 v4l_warn(client, "kernel_thread() failed\n"); 953 v4l_warn(client, "kernel_thread() failed\n");
956 msp_wake_thread(client); 954 msp_wake_thread(client);
957 } 955 }
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 4c7f85b566a0..e1821eb82fb5 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -483,7 +483,6 @@ int msp3400c_thread(void *data)
483 /* no carrier scan, just unmute */ 483 /* no carrier scan, just unmute */
484 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n"); 484 v4l_dbg(1, msp_debug, client, "thread: no carrier scan\n");
485 state->scan_in_progress = 0; 485 state->scan_in_progress = 0;
486 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
487 msp_set_audio(client); 486 msp_set_audio(client);
488 continue; 487 continue;
489 } 488 }
@@ -851,12 +850,15 @@ static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
851 source = 1; /* stereo or A|B */ 850 source = 1; /* stereo or A|B */
852 matrix = 0x20; 851 matrix = 0x20;
853 break; 852 break;
854 case V4L2_TUNER_MODE_STEREO:
855 case V4L2_TUNER_MODE_LANG1: 853 case V4L2_TUNER_MODE_LANG1:
856 default:
857 source = 3; /* stereo or A */ 854 source = 3; /* stereo or A */
858 matrix = 0x00; 855 matrix = 0x00;
859 break; 856 break;
857 case V4L2_TUNER_MODE_STEREO:
858 default:
859 source = 3; /* stereo or A */
860 matrix = 0x20;
861 break;
860 } 862 }
861 863
862 if (in == MSP_DSP_IN_TUNER) 864 if (in == MSP_DSP_IN_TUNER)
@@ -1030,6 +1032,9 @@ static int msp34xxg_detect_stereo(struct i2c_client *client)
1030 int is_stereo = status & 0x40; 1032 int is_stereo = status & 0x40;
1031 int oldrx = state->rxsubchans; 1033 int oldrx = state->rxsubchans;
1032 1034
1035 if (state->mode == MSP_MODE_EXTERN)
1036 return 0;
1037
1033 state->rxsubchans = 0; 1038 state->rxsubchans = 0;
1034 if (is_stereo) 1039 if (is_stereo)
1035 state->rxsubchans = V4L2_TUNER_SUB_STEREO; 1040 state->rxsubchans = V4L2_TUNER_SUB_STEREO;
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index fa8339879095..c33f6a69a247 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -50,9 +50,9 @@ static unsigned int antenna_pwr = 0;
50module_param(antenna_pwr, int, 0444); 50module_param(antenna_pwr, int, 0444);
51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
52 52
53static int use_frontent = 0; 53static int use_frontend = 0;
54module_param(use_frontent, int, 0644); 54module_param(use_frontend, int, 0644);
55MODULE_PARM_DESC(use_frontent,"for cards with multiple frontends (0: terrestrial, 1: satellite)"); 55MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
56 56
57/* ------------------------------------------------------------------ */ 57/* ------------------------------------------------------------------ */
58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
@@ -1303,7 +1303,7 @@ static int dvb_init(struct saa7134_dev *dev)
1303 } 1303 }
1304 break; 1304 break;
1305 case SAA7134_BOARD_FLYDVB_TRIO: 1305 case SAA7134_BOARD_FLYDVB_TRIO:
1306 if(! use_frontent) { //terrestrial 1306 if(! use_frontend) { //terrestrial
1307 dev->dvb.frontend = dvb_attach(tda10046_attach, 1307 dev->dvb.frontend = dvb_attach(tda10046_attach,
1308 &lifeview_trio_config, 1308 &lifeview_trio_config,
1309 &dev->i2c_adap); 1309 &dev->i2c_adap);
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 705daaa2a4ff..ee4a493032d6 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -267,6 +267,10 @@ static int tuner_fixup_std(struct tuner *t)
267{ 267{
268 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { 268 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
269 switch (pal[0]) { 269 switch (pal[0]) {
270 case '6':
271 tuner_dbg ("insmod fixup: PAL => PAL-60\n");
272 t->std = V4L2_STD_PAL_60;
273 break;
270 case 'b': 274 case 'b':
271 case 'B': 275 case 'B':
272 case 'g': 276 case 'g':
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 134eb9865df6..a40e5838515b 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -39,8 +39,8 @@ struct usbvision_device_data_st usbvision_device_data[] = {
39 {0x0573, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "D-Link V100"}, 39 {0x0573, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "D-Link V100"},
40 {0x0573, 0x2000, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "X10 USB Camera"}, 40 {0x0573, 0x2000, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "X10 USB Camera"},
41 {0x0573, 0x2d00, -1, CODEC_SAA7111, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, -1, 3, 7, "Osprey 50"}, 41 {0x0573, 0x2d00, -1, CODEC_SAA7111, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, -1, 3, 7, "Osprey 50"},
42 {0x0573, 0x2d01, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Hauppauge USB-Live Model 600"}, 42 {0x0573, 0x2d01, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Hauppauge USB-Live Model 600"},
43 {0x0573, 0x2101, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 2, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Zoran Co. PMD (Nogatech) AV-grabber Manhattan"}, 43 {0x0573, 0x2101, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 2, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Zoran Co. PMD (Nogatech) AV-grabber Manhattan"},
44 {0x0573, 0x4100, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Nogatech USB-TV (NTSC) FM"}, 44 {0x0573, 0x4100, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Nogatech USB-TV (NTSC) FM"},
45 {0x0573, 0x4110, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "PNY USB-TV (NTSC) FM"}, 45 {0x0573, 0x4110, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "PNY USB-TV (NTSC) FM"},
46 {0x0573, 0x4450, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "PixelView PlayTv-USB PRO (PAL) FM"}, 46 {0x0573, 0x4450, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "PixelView PlayTv-USB PRO (PAL) FM"},
@@ -71,10 +71,10 @@ struct usbvision_device_data_st usbvision_device_data[] = {
71 {0x0573, 0x4d37, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTV USB device Model 40219 Rev E189"}, 71 {0x0573, 0x4d37, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTV USB device Model 40219 Rev E189"},
72 {0x0768, 0x0006, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 5, 5, -1, "Camtel Technology USB TV Genie Pro FM Model TVB330"}, 72 {0x0768, 0x0006, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 5, 5, -1, "Camtel Technology USB TV Genie Pro FM Model TVB330"},
73 {0x07d0, 0x0001, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Digital Video Creator I"}, 73 {0x07d0, 0x0001, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Digital Video Creator I"},
74 {0x07d0, 0x0002, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 82, 20, 7, "Global Village GV-007 (NTSC)"}, 74 {0x07d0, 0x0002, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 82, 20, 7, "Global Village GV-007 (NTSC)"},
75 {0x07d0, 0x0003, 0, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)"}, 75 {0x07d0, 0x0003, 0, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)"},
76 {0x07d0, 0x0004, 0, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-80 Rev 1 (PAL)"}, 76 {0x07d0, 0x0004, 0, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-80 Rev 1 (PAL)"},
77 {0x07d0, 0x0005, 0, CODEC_SAA7113, 2, V4L2_STD_SECAM, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)"}, 77 {0x07d0, 0x0005, 0, CODEC_SAA7113, 2, V4L2_STD_SECAM, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)"},
78 {0x2304, 0x010d, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 0, 1, TUNER_TEMIC_4066FY5_PAL_I, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (PAL)"}, 78 {0x2304, 0x010d, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 0, 1, TUNER_TEMIC_4066FY5_PAL_I, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (PAL)"},
79 {0x2304, 0x0109, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (SECAM)"}, 79 {0x2304, 0x0109, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (SECAM)"},
80 {0x2304, 0x0110, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1,128, 23, -1, "Pinnacle Studio PCTV USB (PAL) FM"}, 80 {0x2304, 0x0110, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1,128, 23, -1, "Pinnacle Studio PCTV USB (PAL) FM"},
@@ -86,7 +86,7 @@ struct usbvision_device_data_st usbvision_device_data[] = {
86 {0x2304, 0x0300, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (NTSC)"}, 86 {0x2304, 0x0300, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (NTSC)"},
87 {0x2304, 0x0301, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (PAL)"}, 87 {0x2304, 0x0301, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (PAL)"},
88 {0x2304, 0x0419, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle PCTV Bungee USB (PAL) FM"}, 88 {0x2304, 0x0419, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle PCTV Bungee USB (PAL) FM"},
89 {0x2400, 0x4200, -1, CODEC_SAA7111, 3, VIDEO_MODE_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"}, 89 {0x2400, 0x4200, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"},
90 {} /* Terminating entry */ 90 {} /* Terminating entry */
91}; 91};
92 92
@@ -148,7 +148,6 @@ struct usb_device_id usbvision_table [] = {
148 { USB_DEVICE(0x2304, 0x0300) }, /* Pinnacle Studio Linx Video input cable (NTSC) */ 148 { USB_DEVICE(0x2304, 0x0300) }, /* Pinnacle Studio Linx Video input cable (NTSC) */
149 { USB_DEVICE(0x2304, 0x0301) }, /* Pinnacle Studio Linx Video input cable (PAL) */ 149 { USB_DEVICE(0x2304, 0x0301) }, /* Pinnacle Studio Linx Video input cable (PAL) */
150 { USB_DEVICE(0x2304, 0x0419) }, /* Pinnacle PCTV Bungee USB (PAL) FM */ 150 { USB_DEVICE(0x2304, 0x0419) }, /* Pinnacle PCTV Bungee USB (PAL) FM */
151
152 { USB_DEVICE(0x2400, 0x4200) }, /* Hauppauge WinTv-USB2 Model 42012 */ 151 { USB_DEVICE(0x2400, 0x4200) }, /* Hauppauge WinTv-USB2 Model 42012 */
153 152
154 { } /* Terminating entry */ 153 { } /* Terminating entry */
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 797b97baf9ed..a807d971e273 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -118,7 +118,7 @@ static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision);
118 * This is used when initializing the contents of the area. 118 * This is used when initializing the contents of the area.
119 */ 119 */
120 120
121void *usbvision_rvmalloc(unsigned long size) 121static void *usbvision_rvmalloc(unsigned long size)
122{ 122{
123 void *mem; 123 void *mem;
124 unsigned long adr; 124 unsigned long adr;
@@ -181,7 +181,7 @@ static void usbvision_hexdump(const unsigned char *data, int len)
181/******************************** 181/********************************
182 * scratch ring buffer handling 182 * scratch ring buffer handling
183 ********************************/ 183 ********************************/
184int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */ 184static int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */
185{ 185{
186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr; 186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
187 if (len < 0) { 187 if (len < 0) {
@@ -194,7 +194,7 @@ int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of
194 194
195 195
196/* This returns the free space left in the buffer */ 196/* This returns the free space left in the buffer */
197int scratch_free(struct usb_usbvision *usbvision) 197static int scratch_free(struct usb_usbvision *usbvision)
198{ 198{
199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr; 199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
200 if (free <= 0) { 200 if (free <= 0) {
@@ -211,7 +211,8 @@ int scratch_free(struct usb_usbvision *usbvision)
211 211
212 212
213/* This puts data into the buffer */ 213/* This puts data into the buffer */
214int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len) 214static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
215 int len)
215{ 216{
216 int len_part; 217 int len_part;
217 218
@@ -237,7 +238,7 @@ int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len)
237} 238}
238 239
239/* This marks the write_ptr as position of new frame header */ 240/* This marks the write_ptr as position of new frame header */
240void scratch_mark_header(struct usb_usbvision *usbvision) 241static void scratch_mark_header(struct usb_usbvision *usbvision)
241{ 242{
242 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr); 243 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
243 244
@@ -248,7 +249,8 @@ void scratch_mark_header(struct usb_usbvision *usbvision)
248} 249}
249 250
250/* This gets data from the buffer at the given "ptr" position */ 251/* This gets data from the buffer at the given "ptr" position */
251int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int *ptr, int len) 252static int scratch_get_extra(struct usb_usbvision *usbvision,
253 unsigned char *data, int *ptr, int len)
252{ 254{
253 int len_part; 255 int len_part;
254 if (*ptr + len < scratch_buf_size) { 256 if (*ptr + len < scratch_buf_size) {
@@ -274,7 +276,8 @@ int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int
274 276
275 277
276/* This sets the scratch extra read pointer */ 278/* This sets the scratch extra read pointer */
277void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len) 279static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
280 int len)
278{ 281{
279 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size; 282 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size;
280 283
@@ -283,7 +286,7 @@ void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len)
283 286
284 287
285/*This increments the scratch extra read pointer */ 288/*This increments the scratch extra read pointer */
286void scratch_inc_extra_ptr(int *ptr, int len) 289static void scratch_inc_extra_ptr(int *ptr, int len)
287{ 290{
288 *ptr = (*ptr + len) % scratch_buf_size; 291 *ptr = (*ptr + len) % scratch_buf_size;
289 292
@@ -292,7 +295,8 @@ void scratch_inc_extra_ptr(int *ptr, int len)
292 295
293 296
294/* This gets data from the buffer */ 297/* This gets data from the buffer */
295int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len) 298static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
299 int len)
296{ 300{
297 int len_part; 301 int len_part;
298 if (usbvision->scratch_read_ptr + len < scratch_buf_size) { 302 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
@@ -318,7 +322,8 @@ int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len)
318 322
319 323
320/* This sets read pointer to next header and returns it */ 324/* This sets read pointer to next header and returns it */
321int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_header *header) 325static int scratch_get_header(struct usb_usbvision *usbvision,
326 struct usbvision_frame_header *header)
322{ 327{
323 int errCode = 0; 328 int errCode = 0;
324 329
@@ -346,7 +351,7 @@ int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_he
346 351
347 352
348/*This removes len bytes of old data from the buffer */ 353/*This removes len bytes of old data from the buffer */
349void scratch_rm_old(struct usb_usbvision *usbvision, int len) 354static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
350{ 355{
351 356
352 usbvision->scratch_read_ptr += len; 357 usbvision->scratch_read_ptr += len;
@@ -356,7 +361,7 @@ void scratch_rm_old(struct usb_usbvision *usbvision, int len)
356 361
357 362
358/*This resets the buffer - kills all data in it too */ 363/*This resets the buffer - kills all data in it too */
359void scratch_reset(struct usb_usbvision *usbvision) 364static void scratch_reset(struct usb_usbvision *usbvision)
360{ 365{
361 PDEBUG(DBG_SCRATCH, "\n"); 366 PDEBUG(DBG_SCRATCH, "\n");
362 367
@@ -369,7 +374,7 @@ void scratch_reset(struct usb_usbvision *usbvision)
369 374
370int usbvision_scratch_alloc(struct usb_usbvision *usbvision) 375int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
371{ 376{
372 usbvision->scratch = vmalloc(scratch_buf_size); 377 usbvision->scratch = vmalloc_32(scratch_buf_size);
373 scratch_reset(usbvision); 378 scratch_reset(usbvision);
374 if(usbvision->scratch == NULL) { 379 if(usbvision->scratch == NULL) {
375 err("%s: unable to allocate %d bytes for scratch", 380 err("%s: unable to allocate %d bytes for scratch",
@@ -399,8 +404,8 @@ void usbvision_scratch_free(struct usb_usbvision *usbvision)
399 * 1: Draw a colored grid 404 * 1: Draw a colored grid
400 * 405 *
401 */ 406 */
402void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe, 407static void usbvision_testpattern(struct usb_usbvision *usbvision,
403 int pmode) 408 int fullframe, int pmode)
404{ 409{
405 static const char proc[] = "usbvision_testpattern"; 410 static const char proc[] = "usbvision_testpattern";
406 struct usbvision_frame *frame; 411 struct usbvision_frame *frame;
@@ -480,7 +485,7 @@ void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe,
480int usbvision_decompress_alloc(struct usb_usbvision *usbvision) 485int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
481{ 486{
482 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 487 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
483 usbvision->IntraFrameBuffer = vmalloc(IFB_size); 488 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
484 if (usbvision->IntraFrameBuffer == NULL) { 489 if (usbvision->IntraFrameBuffer == NULL) {
485 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); 490 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size);
486 return -ENOMEM; 491 return -ENOMEM;
@@ -2199,6 +2204,7 @@ int usbvision_power_on(struct usb_usbvision *usbvision)
2199 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN); 2204 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2200 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2205 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2201 USBVISION_SSPND_EN | USBVISION_RES2); 2206 USBVISION_SSPND_EN | USBVISION_RES2);
2207
2202 usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2208 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2203 USBVISION_SSPND_EN | USBVISION_PWR_VID); 2209 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2204 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, 2210 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
@@ -2305,7 +2311,7 @@ int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2305 usbvision->Vin_Reg2_Preset)) < 0) return ret; 2311 usbvision->Vin_Reg2_Preset)) < 0) return ret;
2306 2312
2307 /* TODO: schedule timeout */ 2313 /* TODO: schedule timeout */
2308 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) && 0x01) != 1); 2314 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1);
2309 2315
2310 return 0; 2316 return 0;
2311} 2317}
@@ -2346,40 +2352,6 @@ int usbvision_setup(struct usb_usbvision *usbvision,int format)
2346 return USBVISION_IS_OPERATIONAL(usbvision); 2352 return USBVISION_IS_OPERATIONAL(usbvision);
2347} 2353}
2348 2354
2349
2350int usbvision_sbuf_alloc(struct usb_usbvision *usbvision)
2351{
2352 int i, errCode = 0;
2353 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2354
2355 /* Clean pointers so we know if we allocated something */
2356 for (i = 0; i < USBVISION_NUMSBUF; i++)
2357 usbvision->sbuf[i].data = NULL;
2358
2359 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2360 usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL);
2361 if (usbvision->sbuf[i].data == NULL) {
2362 err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size);
2363 errCode = -ENOMEM;
2364 break;
2365 }
2366 }
2367 return errCode;
2368}
2369
2370
2371void usbvision_sbuf_free(struct usb_usbvision *usbvision)
2372{
2373 int i;
2374
2375 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2376 if (usbvision->sbuf[i].data != NULL) {
2377 kfree(usbvision->sbuf[i].data);
2378 usbvision->sbuf[i].data = NULL;
2379 }
2380 }
2381}
2382
2383/* 2355/*
2384 * usbvision_init_isoc() 2356 * usbvision_init_isoc()
2385 * 2357 *
@@ -2388,6 +2360,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2388{ 2360{
2389 struct usb_device *dev = usbvision->dev; 2361 struct usb_device *dev = usbvision->dev;
2390 int bufIdx, errCode, regValue; 2362 int bufIdx, errCode, regValue;
2363 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2391 2364
2392 if (!USBVISION_IS_OPERATIONAL(usbvision)) 2365 if (!USBVISION_IS_OPERATIONAL(usbvision))
2393 return -EFAULT; 2366 return -EFAULT;
@@ -2423,6 +2396,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2423 return -ENOMEM; 2396 return -ENOMEM;
2424 } 2397 }
2425 usbvision->sbuf[bufIdx].urb = urb; 2398 usbvision->sbuf[bufIdx].urb = urb;
2399 usbvision->sbuf[bufIdx].data = usb_buffer_alloc(usbvision->dev, sb_size, GFP_KERNEL,&urb->transfer_dma);
2426 urb->dev = dev; 2400 urb->dev = dev;
2427 urb->context = usbvision; 2401 urb->context = usbvision;
2428 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); 2402 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
@@ -2464,6 +2438,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2464void usbvision_stop_isoc(struct usb_usbvision *usbvision) 2438void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2465{ 2439{
2466 int bufIdx, errCode, regValue; 2440 int bufIdx, errCode, regValue;
2441 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2467 2442
2468 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL)) 2443 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
2469 return; 2444 return;
@@ -2471,6 +2446,12 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2471 /* Unschedule all of the iso td's */ 2446 /* Unschedule all of the iso td's */
2472 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) { 2447 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2473 usb_kill_urb(usbvision->sbuf[bufIdx].urb); 2448 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2449 if (usbvision->sbuf[bufIdx].data){
2450 usb_buffer_free(usbvision->dev,
2451 sb_size,
2452 usbvision->sbuf[bufIdx].data,
2453 usbvision->sbuf[bufIdx].urb->transfer_dma);
2454 }
2474 usb_free_urb(usbvision->sbuf[bufIdx].urb); 2455 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2475 usbvision->sbuf[bufIdx].urb = NULL; 2456 usbvision->sbuf[bufIdx].urb = NULL;
2476 } 2457 }
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 0f3fba7ea6fe..858252c15084 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -58,7 +58,6 @@ static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
58static inline int try_write_address(struct i2c_adapter *i2c_adap, 58static inline int try_write_address(struct i2c_adapter *i2c_adap,
59 unsigned char addr, int retries) 59 unsigned char addr, int retries)
60{ 60{
61 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
62 void *data; 61 void *data;
63 int i, ret = -1; 62 int i, ret = -1;
64 char buf[4]; 63 char buf[4];
@@ -69,10 +68,10 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
69 ret = (usbvision_i2c_write(data, addr, buf, 1)); 68 ret = (usbvision_i2c_write(data, addr, buf, 1));
70 if (ret == 1) 69 if (ret == 1)
71 break; /* success! */ 70 break; /* success! */
72 udelay(5 /*adap->udelay */ ); 71 udelay(5);
73 if (i == retries) /* no success */ 72 if (i == retries) /* no success */
74 break; 73 break;
75 udelay(adap->udelay); 74 udelay(10);
76 } 75 }
77 if (i) { 76 if (i) {
78 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr); 77 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
@@ -84,7 +83,6 @@ static inline int try_write_address(struct i2c_adapter *i2c_adap,
84static inline int try_read_address(struct i2c_adapter *i2c_adap, 83static inline int try_read_address(struct i2c_adapter *i2c_adap,
85 unsigned char addr, int retries) 84 unsigned char addr, int retries)
86{ 85{
87 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
88 void *data; 86 void *data;
89 int i, ret = -1; 87 int i, ret = -1;
90 char buf[4]; 88 char buf[4];
@@ -94,10 +92,10 @@ static inline int try_read_address(struct i2c_adapter *i2c_adap,
94 ret = (usbvision_i2c_read(data, addr, buf, 1)); 92 ret = (usbvision_i2c_read(data, addr, buf, 1));
95 if (ret == 1) 93 if (ret == 1)
96 break; /* success! */ 94 break; /* success! */
97 udelay(5 /*adap->udelay */ ); 95 udelay(5);
98 if (i == retries) /* no success */ 96 if (i == retries) /* no success */
99 break; 97 break;
100 udelay(adap->udelay); 98 udelay(10);
101 } 99 }
102 if (i) { 100 if (i) {
103 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr); 101 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
@@ -213,7 +211,7 @@ static struct i2c_algorithm i2c_usb_algo = {
213/* 211/*
214 * registering functions to load algorithms at runtime 212 * registering functions to load algorithms at runtime
215 */ 213 */
216int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap) 214static int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
217{ 215{
218 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]"); 216 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
219 PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]"); 217 PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]");
@@ -248,15 +246,12 @@ int usbvision_i2c_usb_del_bus(struct i2c_adapter *adap)
248/* usbvision specific I2C functions */ 246/* usbvision specific I2C functions */
249/* ----------------------------------------------------------------------- */ 247/* ----------------------------------------------------------------------- */
250static struct i2c_adapter i2c_adap_template; 248static struct i2c_adapter i2c_adap_template;
251static struct i2c_algo_usb_data i2c_algo_template;
252static struct i2c_client i2c_client_template; 249static struct i2c_client i2c_client_template;
253 250
254int usbvision_init_i2c(struct usb_usbvision *usbvision) 251int usbvision_init_i2c(struct usb_usbvision *usbvision)
255{ 252{
256 memcpy(&usbvision->i2c_adap, &i2c_adap_template, 253 memcpy(&usbvision->i2c_adap, &i2c_adap_template,
257 sizeof(struct i2c_adapter)); 254 sizeof(struct i2c_adapter));
258 memcpy(&usbvision->i2c_algo, &i2c_algo_template,
259 sizeof(struct i2c_algo_usb_data));
260 memcpy(&usbvision->i2c_client, &i2c_client_template, 255 memcpy(&usbvision->i2c_client, &i2c_client_template,
261 sizeof(struct i2c_client)); 256 sizeof(struct i2c_client));
262 257
@@ -266,9 +261,7 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision)
266 261
267 i2c_set_adapdata(&usbvision->i2c_adap, usbvision); 262 i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
268 i2c_set_clientdata(&usbvision->i2c_client, usbvision); 263 i2c_set_clientdata(&usbvision->i2c_client, usbvision);
269 i2c_set_algo_usb_data(&usbvision->i2c_algo, usbvision);
270 264
271 usbvision->i2c_adap.algo_data = &usbvision->i2c_algo;
272 usbvision->i2c_client.adapter = &usbvision->i2c_adap; 265 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
273 266
274 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) { 267 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
@@ -297,7 +290,6 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision)
297void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd, 290void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
298 void *arg) 291 void *arg)
299{ 292{
300 BUG_ON(NULL == usbvision->i2c_adap.algo_data);
301 i2c_clients_command(&usbvision->i2c_adap, cmd, arg); 293 i2c_clients_command(&usbvision->i2c_adap, cmd, arg);
302} 294}
303 295
@@ -327,6 +319,9 @@ static int attach_inform(struct i2c_client *client)
327 case 0x4a: 319 case 0x4a:
328 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected."); 320 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected.");
329 break; 321 break;
322 case 0x48:
323 PDEBUG(DBG_I2C,"attach_inform: saa7111 detected.");
324 break;
330 case 0xa0: 325 case 0xa0:
331 PDEBUG(DBG_I2C,"attach_inform: eeprom detected."); 326 PDEBUG(DBG_I2C,"attach_inform: eeprom detected.");
332 break; 327 break;
@@ -531,21 +526,10 @@ static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
531 return rdcount; 526 return rdcount;
532} 527}
533 528
534static struct i2c_algo_usb_data i2c_algo_template = {
535 .data = NULL,
536 .inb = usbvision_i2c_read,
537 .outb = usbvision_i2c_write,
538 .udelay = 10,
539 .mdelay = 10,
540 .timeout = 100,
541};
542
543static struct i2c_adapter i2c_adap_template = { 529static struct i2c_adapter i2c_adap_template = {
544 .owner = THIS_MODULE, 530 .owner = THIS_MODULE,
545 .name = "usbvision", 531 .name = "usbvision",
546 .id = I2C_HW_B_BT848, /* FIXME */ 532 .id = I2C_HW_B_BT848, /* FIXME */
547 .algo = NULL,
548 .algo_data = NULL,
549 .client_register = attach_inform, 533 .client_register = attach_inform,
550 .client_unregister = detach_inform, 534 .client_unregister = detach_inform,
551#ifdef I2C_ADAP_CLASS_TV_ANALOG 535#ifdef I2C_ADAP_CLASS_TV_ANALOG
@@ -559,9 +543,6 @@ static struct i2c_client i2c_client_template = {
559 .name = "usbvision internal", 543 .name = "usbvision internal",
560}; 544};
561 545
562EXPORT_SYMBOL(usbvision_i2c_usb_add_bus);
563EXPORT_SYMBOL(usbvision_i2c_usb_del_bus);
564
565/* 546/*
566 * Overrides for Emacs so that we follow Linus's tabbing style. 547 * Overrides for Emacs so that we follow Linus's tabbing style.
567 * --------------------------------------------------------------------------- 548 * ---------------------------------------------------------------------------
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 864446c012eb..8c7eba2a728e 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -204,7 +204,7 @@ MODULE_ALIAS(DRIVER_ALIAS);
204 204
205static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd) 205static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd)
206{ 206{
207 struct video_device *vdev = to_video_device(cd); 207 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
208 return video_get_drvdata(vdev); 208 return video_get_drvdata(vdev);
209} 209}
210 210
@@ -214,81 +214,85 @@ static ssize_t show_version(struct class_device *cd, char *buf)
214} 214}
215static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL); 215static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
216 216
217static ssize_t show_model(struct class_device *class_dev, char *buf) 217static ssize_t show_model(struct class_device *cd, char *buf)
218{ 218{
219 struct video_device *vdev = to_video_device(class_dev); 219 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
220 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 220 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
221 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString); 221 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString);
222} 222}
223static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 223static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
224 224
225static ssize_t show_hue(struct class_device *class_dev, char *buf) 225static ssize_t show_hue(struct class_device *cd, char *buf)
226{ 226{
227 struct video_device *vdev = to_video_device(class_dev); 227 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
228 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 228 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
229 struct v4l2_control ctrl; 229 struct v4l2_control ctrl;
230 ctrl.id = V4L2_CID_HUE; 230 ctrl.id = V4L2_CID_HUE;
231 ctrl.value = 0; 231 ctrl.value = 0;
232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 232 if(usbvision->user)
233 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
233 return sprintf(buf, "%d\n", ctrl.value >> 8); 234 return sprintf(buf, "%d\n", ctrl.value >> 8);
234} 235}
235static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 236static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
236 237
237static ssize_t show_contrast(struct class_device *class_dev, char *buf) 238static ssize_t show_contrast(struct class_device *cd, char *buf)
238{ 239{
239 struct video_device *vdev = to_video_device(class_dev); 240 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
240 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 241 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
241 struct v4l2_control ctrl; 242 struct v4l2_control ctrl;
242 ctrl.id = V4L2_CID_CONTRAST; 243 ctrl.id = V4L2_CID_CONTRAST;
243 ctrl.value = 0; 244 ctrl.value = 0;
244 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 245 if(usbvision->user)
246 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
245 return sprintf(buf, "%d\n", ctrl.value >> 8); 247 return sprintf(buf, "%d\n", ctrl.value >> 8);
246} 248}
247static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 249static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
248 250
249static ssize_t show_brightness(struct class_device *class_dev, char *buf) 251static ssize_t show_brightness(struct class_device *cd, char *buf)
250{ 252{
251 struct video_device *vdev = to_video_device(class_dev); 253 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
252 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 254 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
253 struct v4l2_control ctrl; 255 struct v4l2_control ctrl;
254 ctrl.id = V4L2_CID_BRIGHTNESS; 256 ctrl.id = V4L2_CID_BRIGHTNESS;
255 ctrl.value = 0; 257 ctrl.value = 0;
256 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 258 if(usbvision->user)
259 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
257 return sprintf(buf, "%d\n", ctrl.value >> 8); 260 return sprintf(buf, "%d\n", ctrl.value >> 8);
258} 261}
259static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 262static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
260 263
261static ssize_t show_saturation(struct class_device *class_dev, char *buf) 264static ssize_t show_saturation(struct class_device *cd, char *buf)
262{ 265{
263 struct video_device *vdev = to_video_device(class_dev); 266 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
264 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 267 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
265 struct v4l2_control ctrl; 268 struct v4l2_control ctrl;
266 ctrl.id = V4L2_CID_SATURATION; 269 ctrl.id = V4L2_CID_SATURATION;
267 ctrl.value = 0; 270 ctrl.value = 0;
268 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 271 if(usbvision->user)
272 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
269 return sprintf(buf, "%d\n", ctrl.value >> 8); 273 return sprintf(buf, "%d\n", ctrl.value >> 8);
270} 274}
271static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 275static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
272 276
273static ssize_t show_streaming(struct class_device *class_dev, char *buf) 277static ssize_t show_streaming(struct class_device *cd, char *buf)
274{ 278{
275 struct video_device *vdev = to_video_device(class_dev); 279 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
276 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 280 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
277 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0)); 281 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0));
278} 282}
279static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 283static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
280 284
281static ssize_t show_compression(struct class_device *class_dev, char *buf) 285static ssize_t show_compression(struct class_device *cd, char *buf)
282{ 286{
283 struct video_device *vdev = to_video_device(class_dev); 287 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
284 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 288 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
285 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 289 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
286} 290}
287static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 291static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
288 292
289static ssize_t show_device_bridge(struct class_device *class_dev, char *buf) 293static ssize_t show_device_bridge(struct class_device *cd, char *buf)
290{ 294{
291 struct video_device *vdev = to_video_device(class_dev); 295 struct video_device *vdev = container_of(cd, struct video_device, class_dev);
292 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 296 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
293 return sprintf(buf, "%d\n", usbvision->bridgeType); 297 return sprintf(buf, "%d\n", usbvision->bridgeType);
294} 298}
@@ -297,31 +301,71 @@ static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
297static void usbvision_create_sysfs(struct video_device *vdev) 301static void usbvision_create_sysfs(struct video_device *vdev)
298{ 302{
299 int res; 303 int res;
300 if (vdev) { 304 if (!vdev)
301 res=video_device_create_file(vdev, &class_device_attr_version); 305 return;
302 res=video_device_create_file(vdev, &class_device_attr_model); 306 do {
303 res=video_device_create_file(vdev, &class_device_attr_hue); 307 res=class_device_create_file(&vdev->class_dev,
304 res=video_device_create_file(vdev, &class_device_attr_contrast); 308 &class_device_attr_version);
305 res=video_device_create_file(vdev, &class_device_attr_brightness); 309 if (res<0)
306 res=video_device_create_file(vdev, &class_device_attr_saturation); 310 break;
307 res=video_device_create_file(vdev, &class_device_attr_streaming); 311 res=class_device_create_file(&vdev->class_dev,
308 res=video_device_create_file(vdev, &class_device_attr_compression); 312 &class_device_attr_model);
309 res=video_device_create_file(vdev, &class_device_attr_bridge); 313 if (res<0)
310 } 314 break;
315 res=class_device_create_file(&vdev->class_dev,
316 &class_device_attr_hue);
317 if (res<0)
318 break;
319 res=class_device_create_file(&vdev->class_dev,
320 &class_device_attr_contrast);
321 if (res<0)
322 break;
323 res=class_device_create_file(&vdev->class_dev,
324 &class_device_attr_brightness);
325 if (res<0)
326 break;
327 res=class_device_create_file(&vdev->class_dev,
328 &class_device_attr_saturation);
329 if (res<0)
330 break;
331 res=class_device_create_file(&vdev->class_dev,
332 &class_device_attr_streaming);
333 if (res<0)
334 break;
335 res=class_device_create_file(&vdev->class_dev,
336 &class_device_attr_compression);
337 if (res<0)
338 break;
339 res=class_device_create_file(&vdev->class_dev,
340 &class_device_attr_bridge);
341 if (res>=0)
342 return;
343 } while (0);
344
345 err("%s error: %d\n", __FUNCTION__, res);
311} 346}
312 347
313static void usbvision_remove_sysfs(struct video_device *vdev) 348static void usbvision_remove_sysfs(struct video_device *vdev)
314{ 349{
315 if (vdev) { 350 if (vdev) {
316 video_device_remove_file(vdev, &class_device_attr_version); 351 class_device_remove_file(&vdev->class_dev,
317 video_device_remove_file(vdev, &class_device_attr_model); 352 &class_device_attr_version);
318 video_device_remove_file(vdev, &class_device_attr_hue); 353 class_device_remove_file(&vdev->class_dev,
319 video_device_remove_file(vdev, &class_device_attr_contrast); 354 &class_device_attr_model);
320 video_device_remove_file(vdev, &class_device_attr_brightness); 355 class_device_remove_file(&vdev->class_dev,
321 video_device_remove_file(vdev, &class_device_attr_saturation); 356 &class_device_attr_hue);
322 video_device_remove_file(vdev, &class_device_attr_streaming); 357 class_device_remove_file(&vdev->class_dev,
323 video_device_remove_file(vdev, &class_device_attr_compression); 358 &class_device_attr_contrast);
324 video_device_remove_file(vdev, &class_device_attr_bridge); 359 class_device_remove_file(&vdev->class_dev,
360 &class_device_attr_brightness);
361 class_device_remove_file(&vdev->class_dev,
362 &class_device_attr_saturation);
363 class_device_remove_file(&vdev->class_dev,
364 &class_device_attr_streaming);
365 class_device_remove_file(&vdev->class_dev,
366 &class_device_attr_compression);
367 class_device_remove_file(&vdev->class_dev,
368 &class_device_attr_bridge);
325 } 369 }
326} 370}
327 371
@@ -353,20 +397,15 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
353 if(!errCode) { 397 if(!errCode) {
354 /* Allocate memory for the scratch ring buffer */ 398 /* Allocate memory for the scratch ring buffer */
355 errCode = usbvision_scratch_alloc(usbvision); 399 errCode = usbvision_scratch_alloc(usbvision);
356 if(!errCode) { 400 if ((!errCode) && (isocMode==ISOC_MODE_COMPRESS)) {
357 /* Allocate memory for the USB S buffers */ 401 /* Allocate intermediate decompression buffers only if needed */
358 errCode = usbvision_sbuf_alloc(usbvision); 402 errCode = usbvision_decompress_alloc(usbvision);
359 if ((!errCode) && (usbvision->isocMode==ISOC_MODE_COMPRESS)) {
360 /* Allocate intermediate decompression buffers only if needed */
361 errCode = usbvision_decompress_alloc(usbvision);
362 }
363 } 403 }
364 } 404 }
365 if (errCode) { 405 if (errCode) {
366 /* Deallocate all buffers if trouble */ 406 /* Deallocate all buffers if trouble */
367 usbvision_frames_free(usbvision); 407 usbvision_frames_free(usbvision);
368 usbvision_scratch_free(usbvision); 408 usbvision_scratch_free(usbvision);
369 usbvision_sbuf_free(usbvision);
370 usbvision_decompress_free(usbvision); 409 usbvision_decompress_free(usbvision);
371 } 410 }
372 } 411 }
@@ -437,9 +476,8 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
437 usbvision_stop_isoc(usbvision); 476 usbvision_stop_isoc(usbvision);
438 477
439 usbvision_decompress_free(usbvision); 478 usbvision_decompress_free(usbvision);
440 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size); 479 usbvision_frames_free(usbvision);
441 usbvision_scratch_free(usbvision); 480 usbvision_scratch_free(usbvision);
442 usbvision_sbuf_free(usbvision);
443 481
444 usbvision->user--; 482 usbvision->user--;
445 483
@@ -1884,7 +1922,7 @@ static struct usb_driver usbvision_driver = {
1884 * This procedure preprocesses CustomDevice parameter if any 1922 * This procedure preprocesses CustomDevice parameter if any
1885 * 1923 *
1886 */ 1924 */
1887void customdevice_process(void) 1925static void customdevice_process(void)
1888{ 1926{
1889 usbvision_device_data[0]=usbvision_device_data[1]; 1927 usbvision_device_data[0]=usbvision_device_data[1];
1890 usbvision_table[0]=usbvision_table[1]; 1928 usbvision_table[0]=usbvision_table[1];
@@ -1939,22 +1977,22 @@ void customdevice_process(void)
1939 { 1977 {
1940 case 'P': 1978 case 'P':
1941 PDEBUG(DBG_PROBE, "VideoNorm=PAL"); 1979 PDEBUG(DBG_PROBE, "VideoNorm=PAL");
1942 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL; 1980 usbvision_device_data[0].VideoNorm=V4L2_STD_PAL;
1943 break; 1981 break;
1944 1982
1945 case 'S': 1983 case 'S':
1946 PDEBUG(DBG_PROBE, "VideoNorm=SECAM"); 1984 PDEBUG(DBG_PROBE, "VideoNorm=SECAM");
1947 usbvision_device_data[0].VideoNorm=VIDEO_MODE_SECAM; 1985 usbvision_device_data[0].VideoNorm=V4L2_STD_SECAM;
1948 break; 1986 break;
1949 1987
1950 case 'N': 1988 case 'N':
1951 PDEBUG(DBG_PROBE, "VideoNorm=NTSC"); 1989 PDEBUG(DBG_PROBE, "VideoNorm=NTSC");
1952 usbvision_device_data[0].VideoNorm=VIDEO_MODE_NTSC; 1990 usbvision_device_data[0].VideoNorm=V4L2_STD_NTSC;
1953 break; 1991 break;
1954 1992
1955 default: 1993 default:
1956 PDEBUG(DBG_PROBE, "VideoNorm=PAL (by default)"); 1994 PDEBUG(DBG_PROBE, "VideoNorm=PAL (by default)");
1957 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL; 1995 usbvision_device_data[0].VideoNorm=V4L2_STD_PAL;
1958 break; 1996 break;
1959 } 1997 }
1960 goto2next(parse); 1998 goto2next(parse);
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
index 0e7e3d653cac..e2bcaba93871 100644
--- a/drivers/media/video/usbvision/usbvision.h
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -219,18 +219,6 @@ enum {
219 ((udevice)->last_error == 0) && \ 219 ((udevice)->last_error == 0) && \
220 (!(udevice)->remove_pending)) 220 (!(udevice)->remove_pending))
221 221
222/* I2C structures */
223struct i2c_algo_usb_data {
224 void *data; /* private data for lowlevel routines */
225 int (*inb) (void *data, unsigned char addr, char *buf, short len);
226 int (*outb) (void *data, unsigned char addr, char *buf, short len);
227
228 /* local settings */
229 int udelay;
230 int mdelay;
231 int timeout;
232};
233
234#define I2C_USB_ADAP_MAX 16 222#define I2C_USB_ADAP_MAX 16
235 223
236/* ----------------------------------------------------------------- */ 224/* ----------------------------------------------------------------- */
@@ -383,7 +371,6 @@ struct usb_usbvision {
383 371
384 /* i2c Declaration Section*/ 372 /* i2c Declaration Section*/
385 struct i2c_adapter i2c_adap; 373 struct i2c_adapter i2c_adap;
386 struct i2c_algo_usb_data i2c_algo;
387 struct i2c_client i2c_client; 374 struct i2c_client i2c_client;
388 375
389 struct urb *ctrlUrb; 376 struct urb *ctrlUrb;
@@ -489,19 +476,8 @@ struct usb_usbvision {
489/* i2c-algo-usb declaration */ 476/* i2c-algo-usb declaration */
490/* --------------------------------------------------------------- */ 477/* --------------------------------------------------------------- */
491 478
492int usbvision_i2c_usb_add_bus(struct i2c_adapter *);
493int usbvision_i2c_usb_del_bus(struct i2c_adapter *); 479int usbvision_i2c_usb_del_bus(struct i2c_adapter *);
494 480
495static inline void *i2c_get_algo_usb_data (struct i2c_algo_usb_data *dev)
496{
497 return dev->data;
498}
499
500static inline void i2c_set_algo_usb_data (struct i2c_algo_usb_data *dev, void *data)
501{
502 dev->data = data;
503}
504
505 481
506/* ----------------------------------------------------------------------- */ 482/* ----------------------------------------------------------------------- */
507/* usbvision specific I2C functions */ 483/* usbvision specific I2C functions */
@@ -510,7 +486,6 @@ int usbvision_init_i2c(struct usb_usbvision *usbvision);
510void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg); 486void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
511 487
512/* defined in usbvision-core.c */ 488/* defined in usbvision-core.c */
513void *usbvision_rvmalloc(unsigned long size);
514void usbvision_rvfree(void *mem, unsigned long size); 489void usbvision_rvfree(void *mem, unsigned long size);
515int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg); 490int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg);
516int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg, 491int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
@@ -520,8 +495,6 @@ int usbvision_frames_alloc(struct usb_usbvision *usbvision);
520void usbvision_frames_free(struct usb_usbvision *usbvision); 495void usbvision_frames_free(struct usb_usbvision *usbvision);
521int usbvision_scratch_alloc(struct usb_usbvision *usbvision); 496int usbvision_scratch_alloc(struct usb_usbvision *usbvision);
522void usbvision_scratch_free(struct usb_usbvision *usbvision); 497void usbvision_scratch_free(struct usb_usbvision *usbvision);
523int usbvision_sbuf_alloc(struct usb_usbvision *usbvision);
524void usbvision_sbuf_free(struct usb_usbvision *usbvision);
525int usbvision_decompress_alloc(struct usb_usbvision *usbvision); 498int usbvision_decompress_alloc(struct usb_usbvision *usbvision);
526void usbvision_decompress_free(struct usb_usbvision *usbvision); 499void usbvision_decompress_free(struct usb_usbvision *usbvision);
527 500
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 474ddb779643..bacb311b4f24 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -535,9 +535,9 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
535 535
536 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 536 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi");
537 537
538 if (dma_q->kthread == NULL) { 538 if (IS_ERR(dma_q->kthread)) {
539 printk(KERN_ERR "vivi: kernel_thread() failed\n"); 539 printk(KERN_ERR "vivi: kernel_thread() failed\n");
540 return -EINVAL; 540 return PTR_ERR(dma_q->kthread);
541 } 541 }
542 dprintk(1,"returning from %s\n",__FUNCTION__); 542 dprintk(1,"returning from %s\n",__FUNCTION__);
543 return 0; 543 return 0;
@@ -1363,7 +1363,9 @@ static void __exit vivi_exit(void)
1363 struct vivi_dev *h; 1363 struct vivi_dev *h;
1364 struct list_head *list; 1364 struct list_head *list;
1365 1365
1366 list_for_each(list,&vivi_devlist) { 1366 while (!list_empty(&vivi_devlist)) {
1367 list = vivi_devlist.next;
1368 list_del(list);
1367 h = list_entry(list, struct vivi_dev, vivi_devlist); 1369 h = list_entry(list, struct vivi_dev, vivi_devlist);
1368 kfree (h); 1370 kfree (h);
1369 } 1371 }
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 4bdc886abc4c..8d14f308f171 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -789,7 +789,7 @@ static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
789 case VIDIOCSPICT: 789 case VIDIOCSPICT:
790 { 790 {
791 struct video_picture *vpic = arg; 791 struct video_picture *vpic = arg;
792 if (vpic->depth != 16 || vpic->palette != VIDEO_PALETTE_YUV422) 792 if (vpic->depth != 16 || (vpic->palette != VIDEO_PALETTE_YUV422 && vpic->palette != VIDEO_PALETTE_YUYV))
793 return -EINVAL; 793 return -EINVAL;
794 794
795 cam->brightness = vpic->brightness >> 8; 795 cam->brightness = vpic->brightness >> 8;
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index ddce2fb83424..9f403af7b040 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -1827,8 +1827,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1827 int err = 0; 1827 int err = 0;
1828 1828
1829 /* Work around to avoid FP arithmetics */ 1829 /* Work around to avoid FP arithmetics */
1830 #define __SC(x) ((x) << 10) 1830 #define SC(x) ((x) << 10)
1831 #define __UNSC(x) ((x) >> 10) 1831 #define UNSC(x) ((x) >> 10)
1832 1832
1833 /* Make sure we are using a supported resolution */ 1833 /* Make sure we are using a supported resolution */
1834 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width, 1834 if ((err = w9968cf_adjust_window_size(cam, (u16*)&win.width,
@@ -1836,15 +1836,15 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1836 goto error; 1836 goto error;
1837 1837
1838 /* Scaling factors */ 1838 /* Scaling factors */
1839 fw = __SC(win.width) / cam->maxwidth; 1839 fw = SC(win.width) / cam->maxwidth;
1840 fh = __SC(win.height) / cam->maxheight; 1840 fh = SC(win.height) / cam->maxheight;
1841 1841
1842 /* Set up the width and height values used by the chip */ 1842 /* Set up the width and height values used by the chip */
1843 if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) { 1843 if ((win.width > cam->maxwidth) || (win.height > cam->maxheight)) {
1844 cam->vpp_flag |= VPP_UPSCALE; 1844 cam->vpp_flag |= VPP_UPSCALE;
1845 /* Calculate largest w,h mantaining the same w/h ratio */ 1845 /* Calculate largest w,h mantaining the same w/h ratio */
1846 w = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh; 1846 w = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1847 h = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight; 1847 h = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1848 if (w < cam->minwidth) /* just in case */ 1848 if (w < cam->minwidth) /* just in case */
1849 w = cam->minwidth; 1849 w = cam->minwidth;
1850 if (h < cam->minheight) /* just in case */ 1850 if (h < cam->minheight) /* just in case */
@@ -1861,8 +1861,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1861 1861
1862 /* Calculate cropped area manteining the right w/h ratio */ 1862 /* Calculate cropped area manteining the right w/h ratio */
1863 if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) { 1863 if (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) {
1864 cw = (fw >= fh) ? cam->maxwidth : __SC(win.width)/fh; 1864 cw = (fw >= fh) ? cam->maxwidth : SC(win.width)/fh;
1865 ch = (fw >= fh) ? __SC(win.height)/fw : cam->maxheight; 1865 ch = (fw >= fh) ? SC(win.height)/fw : cam->maxheight;
1866 } else { 1866 } else {
1867 cw = w; 1867 cw = w;
1868 ch = h; 1868 ch = h;
@@ -1901,8 +1901,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1901 /* We have to scale win.x and win.y offsets */ 1901 /* We have to scale win.x and win.y offsets */
1902 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) 1902 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1903 || (cam->vpp_flag & VPP_UPSCALE) ) { 1903 || (cam->vpp_flag & VPP_UPSCALE) ) {
1904 ax = __SC(win.x)/fw; 1904 ax = SC(win.x)/fw;
1905 ay = __SC(win.y)/fh; 1905 ay = SC(win.y)/fh;
1906 } else { 1906 } else {
1907 ax = win.x; 1907 ax = win.x;
1908 ay = win.y; 1908 ay = win.y;
@@ -1917,8 +1917,8 @@ w9968cf_set_window(struct w9968cf_device* cam, struct video_window win)
1917 /* Adjust win.x, win.y */ 1917 /* Adjust win.x, win.y */
1918 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE)) 1918 if ( (cam->largeview && !(cam->vpp_flag & VPP_UPSCALE))
1919 || (cam->vpp_flag & VPP_UPSCALE) ) { 1919 || (cam->vpp_flag & VPP_UPSCALE) ) {
1920 win.x = __UNSC(ax*fw); 1920 win.x = UNSC(ax*fw);
1921 win.y = __UNSC(ay*fh); 1921 win.y = UNSC(ay*fh);
1922 } else { 1922 } else {
1923 win.x = ax; 1923 win.x = ax;
1924 win.y = ay; 1924 win.y = ay;
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
index 168e431d7c71..b0752767ee4f 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran_device.c
@@ -429,7 +429,7 @@ zr36057_set_vfe (struct zoran *zr,
429 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm); 429 reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
430 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm); 430 reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
431 reg |= (DispMode << ZR36057_VFESPFR_DispMode); 431 reg |= (DispMode << ZR36057_VFESPFR_DispMode);
432 if (format->palette != VIDEO_PALETTE_YUV422) 432 if (format->palette != VIDEO_PALETTE_YUV422 && format->palette != VIDEO_PALETTE_YUYV)
433 reg |= ZR36057_VFESPFR_LittleEndian; 433 reg |= ZR36057_VFESPFR_LittleEndian;
434 /* RJ: I don't know, why the following has to be the opposite 434 /* RJ: I don't know, why the following has to be the opposite
435 * of the corresponding ZR36060 setting, but only this way 435 * of the corresponding ZR36060 setting, but only this way
@@ -441,6 +441,7 @@ zr36057_set_vfe (struct zoran *zr,
441 reg |= ZR36057_VFESPFR_TopField; 441 reg |= ZR36057_VFESPFR_TopField;
442 switch (format->palette) { 442 switch (format->palette) {
443 443
444 case VIDEO_PALETTE_YUYV:
444 case VIDEO_PALETTE_YUV422: 445 case VIDEO_PALETTE_YUV422:
445 reg |= ZR36057_VFESPFR_YUV422; 446 reg |= ZR36057_VFESPFR_YUV422;
446 break; 447 break;
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index a539d3b61e76..5278aad92bc4 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -367,7 +367,7 @@ static int i2o_exec_remove(struct device *dev)
367 367
368/** 368/**
369 * i2o_exec_lct_modified - Called on LCT NOTIFY reply 369 * i2o_exec_lct_modified - Called on LCT NOTIFY reply
370 * @work: work struct for a specific controller 370 * @_work: work struct for a specific controller
371 * 371 *
372 * This function handles asynchronus LCT NOTIFY replies. It parses the 372 * This function handles asynchronus LCT NOTIFY replies. It parses the
373 * new LCT and if the buffer for the LCT was to small sends a LCT NOTIFY 373 * new LCT and if the buffer for the LCT was to small sends a LCT NOTIFY
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
index fdb7153f4426..8e5e07e4c1cf 100644
--- a/drivers/misc/msi-laptop.c
+++ b/drivers/misc/msi-laptop.c
@@ -317,7 +317,8 @@ static int __init msi_init(void)
317 317
318 /* Register backlight stuff */ 318 /* Register backlight stuff */
319 319
320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, &msibl_props); 320 msibl_device = backlight_device_register("msi-laptop-bl", NULL, NULL,
321 &msibl_props);
321 if (IS_ERR(msibl_device)) 322 if (IS_ERR(msibl_device))
322 return PTR_ERR(msibl_device); 323 return PTR_ERR(msibl_device);
323 324
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 334e078ffaff..78c2511ae9e0 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -437,7 +437,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
437 * or JEDEC get-id commands. Try them ... 437 * or JEDEC get-id commands. Try them ...
438 */ 438 */
439 DEBUG(MTD_DEBUG_LEVEL1, "%s: no chip id\n", 439 DEBUG(MTD_DEBUG_LEVEL1, "%s: no chip id\n",
440 flash->spi->dev.bus_id); 440 spi->dev.bus_id);
441 return -ENODEV; 441 return -ENODEV;
442 } 442 }
443 443
@@ -447,7 +447,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
447 } 447 }
448 if (i == ARRAY_SIZE(m25p_data)) { 448 if (i == ARRAY_SIZE(m25p_data)) {
449 DEBUG(MTD_DEBUG_LEVEL1, "%s: unrecognized id %s\n", 449 DEBUG(MTD_DEBUG_LEVEL1, "%s: unrecognized id %s\n",
450 flash->spi->dev.bus_id, data->type); 450 spi->dev.bus_id, data->type);
451 return -ENODEV; 451 return -ENODEV;
452 } 452 }
453 453
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 0a7e86859bf1..910e4061dfd2 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -536,7 +536,7 @@ static int __devinit dataflash_probe(struct spi_device *spi)
536 if (status <= 0 || status == 0xff) { 536 if (status <= 0 || status == 0xff) {
537 DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n", 537 DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n",
538 spi->dev.bus_id, status); 538 spi->dev.bus_id, status);
539 if (status == 0xff) 539 if (status == 0 || status == 0xff)
540 status = -ENODEV; 540 status = -ENODEV;
541 return status; 541 return status;
542 } 542 }
diff --git a/drivers/net/8139cp.c b/drivers/net/8139cp.c
index 458dd9f830c4..e2cb19b582a1 100644
--- a/drivers/net/8139cp.c
+++ b/drivers/net/8139cp.c
@@ -617,13 +617,15 @@ rx_next:
617 * this round of polling 617 * this round of polling
618 */ 618 */
619 if (rx_work) { 619 if (rx_work) {
620 unsigned long flags;
621
620 if (cpr16(IntrStatus) & cp_rx_intr_mask) 622 if (cpr16(IntrStatus) & cp_rx_intr_mask)
621 goto rx_status_loop; 623 goto rx_status_loop;
622 624
623 local_irq_disable(); 625 local_irq_save(flags);
624 cpw16_f(IntrMask, cp_intr_mask); 626 cpw16_f(IntrMask, cp_intr_mask);
625 __netif_rx_complete(dev); 627 __netif_rx_complete(dev);
626 local_irq_enable(); 628 local_irq_restore(flags);
627 629
628 return 0; /* done */ 630 return 0; /* done */
629 } 631 }
diff --git a/drivers/net/arm/ep93xx_eth.c b/drivers/net/arm/ep93xx_eth.c
index 8ebd68e2af98..dd698b033a62 100644
--- a/drivers/net/arm/ep93xx_eth.c
+++ b/drivers/net/arm/ep93xx_eth.c
@@ -780,12 +780,10 @@ static struct ethtool_ops ep93xx_ethtool_ops = {
780struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data) 780struct net_device *ep93xx_dev_alloc(struct ep93xx_eth_data *data)
781{ 781{
782 struct net_device *dev; 782 struct net_device *dev;
783 struct ep93xx_priv *ep;
784 783
785 dev = alloc_etherdev(sizeof(struct ep93xx_priv)); 784 dev = alloc_etherdev(sizeof(struct ep93xx_priv));
786 if (dev == NULL) 785 if (dev == NULL)
787 return NULL; 786 return NULL;
788 ep = netdev_priv(dev);
789 787
790 memcpy(dev->dev_addr, data->dev_addr, ETH_ALEN); 788 memcpy(dev->dev_addr, data->dev_addr, ETH_ALEN);
791 789
@@ -840,9 +838,9 @@ static int ep93xx_eth_probe(struct platform_device *pdev)
840 struct ep93xx_priv *ep; 838 struct ep93xx_priv *ep;
841 int err; 839 int err;
842 840
843 data = pdev->dev.platform_data;
844 if (pdev == NULL) 841 if (pdev == NULL)
845 return -ENODEV; 842 return -ENODEV;
843 data = pdev->dev.platform_data;
846 844
847 dev = ep93xx_dev_alloc(data); 845 dev = ep93xx_dev_alloc(data);
848 if (dev == NULL) { 846 if (dev == NULL) {
diff --git a/drivers/net/b44.c b/drivers/net/b44.c
index 474a4e3438db..5eb2ec68393f 100644
--- a/drivers/net/b44.c
+++ b/drivers/net/b44.c
@@ -879,12 +879,14 @@ static int b44_poll(struct net_device *netdev, int *budget)
879 } 879 }
880 880
881 if (bp->istat & ISTAT_ERRORS) { 881 if (bp->istat & ISTAT_ERRORS) {
882 spin_lock_irq(&bp->lock); 882 unsigned long flags;
883
884 spin_lock_irqsave(&bp->lock, flags);
883 b44_halt(bp); 885 b44_halt(bp);
884 b44_init_rings(bp); 886 b44_init_rings(bp);
885 b44_init_hw(bp, 1); 887 b44_init_hw(bp, 1);
886 netif_wake_queue(bp->dev); 888 netif_wake_queue(bp->dev);
887 spin_unlock_irq(&bp->lock); 889 spin_unlock_irqrestore(&bp->lock, flags);
888 done = 1; 890 done = 1;
889 } 891 }
890 892
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 7d824cf8ee2d..ada5e9b9988c 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -57,8 +57,8 @@
57 57
58#define DRV_MODULE_NAME "bnx2" 58#define DRV_MODULE_NAME "bnx2"
59#define PFX DRV_MODULE_NAME ": " 59#define PFX DRV_MODULE_NAME ": "
60#define DRV_MODULE_VERSION "1.5.1" 60#define DRV_MODULE_VERSION "1.5.2"
61#define DRV_MODULE_RELDATE "November 15, 2006" 61#define DRV_MODULE_RELDATE "December 13, 2006"
62 62
63#define RUN_AT(x) (jiffies + (x)) 63#define RUN_AT(x) (jiffies + (x))
64 64
@@ -217,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct bnx2 *bp)
217 u32 diff; 217 u32 diff;
218 218
219 smp_mb(); 219 smp_mb();
220 diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons); 220
221 if (diff > MAX_TX_DESC_CNT) 221 /* The ring uses 256 indices for 255 entries, one of them
222 diff = (diff & MAX_TX_DESC_CNT) - 1; 222 * needs to be skipped.
223 */
224 diff = bp->tx_prod - bp->tx_cons;
225 if (unlikely(diff >= TX_DESC_CNT)) {
226 diff &= 0xffff;
227 if (diff == TX_DESC_CNT)
228 diff = MAX_TX_DESC_CNT;
229 }
223 return (bp->tx_ring_size - diff); 230 return (bp->tx_ring_size - diff);
224} 231}
225 232
@@ -3089,7 +3096,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3089 3096
3090 if ((align_start = (offset32 & 3))) { 3097 if ((align_start = (offset32 & 3))) {
3091 offset32 &= ~3; 3098 offset32 &= ~3;
3092 len32 += align_start; 3099 len32 += (4 - align_start);
3093 if ((rc = bnx2_nvram_read(bp, offset32, start, 4))) 3100 if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
3094 return rc; 3101 return rc;
3095 } 3102 }
@@ -3107,7 +3114,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
3107 3114
3108 if (align_start || align_end) { 3115 if (align_start || align_end) {
3109 buf = kmalloc(len32, GFP_KERNEL); 3116 buf = kmalloc(len32, GFP_KERNEL);
3110 if (buf == 0) 3117 if (buf == NULL)
3111 return -ENOMEM; 3118 return -ENOMEM;
3112 if (align_start) { 3119 if (align_start) {
3113 memcpy(buf, start, 4); 3120 memcpy(buf, start, 4);
@@ -3998,7 +4005,7 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
3998 if (!skb) 4005 if (!skb)
3999 return -ENOMEM; 4006 return -ENOMEM;
4000 packet = skb_put(skb, pkt_size); 4007 packet = skb_put(skb, pkt_size);
4001 memcpy(packet, bp->mac_addr, 6); 4008 memcpy(packet, bp->dev->dev_addr, 6);
4002 memset(packet + 6, 0x0, 8); 4009 memset(packet + 6, 0x0, 8);
4003 for (i = 14; i < pkt_size; i++) 4010 for (i = 14; i < pkt_size; i++)
4004 packet[i] = (unsigned char) (i & 0xff); 4011 packet[i] = (unsigned char) (i & 0xff);
diff --git a/drivers/net/e1000/e1000_ethtool.c b/drivers/net/e1000/e1000_ethtool.c
index da459f7177c6..fb96c87f9e56 100644
--- a/drivers/net/e1000/e1000_ethtool.c
+++ b/drivers/net/e1000/e1000_ethtool.c
@@ -100,6 +100,9 @@ static const struct e1000_stats e1000_gstrings_stats[] = {
100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) }, 100 { "rx_csum_offload_errors", E1000_STAT(hw_csum_err) },
101 { "rx_header_split", E1000_STAT(rx_hdr_split) }, 101 { "rx_header_split", E1000_STAT(rx_hdr_split) },
102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) }, 102 { "alloc_rx_buff_failed", E1000_STAT(alloc_rx_buff_failed) },
103 { "tx_smbus", E1000_STAT(stats.mgptc) },
104 { "rx_smbus", E1000_STAT(stats.mgprc) },
105 { "dropped_smbus", E1000_STAT(stats.mgpdc) },
103}; 106};
104 107
105#define E1000_QUEUE_STATS_LEN 0 108#define E1000_QUEUE_STATS_LEN 0
diff --git a/drivers/net/e1000/e1000_hw.c b/drivers/net/e1000/e1000_hw.c
index 3655d902b0bd..9be44699300b 100644
--- a/drivers/net/e1000/e1000_hw.c
+++ b/drivers/net/e1000/e1000_hw.c
@@ -308,141 +308,160 @@ e1000_phy_init_script(struct e1000_hw *hw)
308int32_t 308int32_t
309e1000_set_mac_type(struct e1000_hw *hw) 309e1000_set_mac_type(struct e1000_hw *hw)
310{ 310{
311 DEBUGFUNC("e1000_set_mac_type"); 311 DEBUGFUNC("e1000_set_mac_type");
312 312
313 switch (hw->device_id) { 313 switch (hw->device_id) {
314 case E1000_DEV_ID_82542: 314 case E1000_DEV_ID_82542:
315 switch (hw->revision_id) { 315 switch (hw->revision_id) {
316 case E1000_82542_2_0_REV_ID: 316 case E1000_82542_2_0_REV_ID:
317 hw->mac_type = e1000_82542_rev2_0; 317 hw->mac_type = e1000_82542_rev2_0;
318 break; 318 break;
319 case E1000_82542_2_1_REV_ID: 319 case E1000_82542_2_1_REV_ID:
320 hw->mac_type = e1000_82542_rev2_1; 320 hw->mac_type = e1000_82542_rev2_1;
321 break; 321 break;
322 default: 322 default:
323 /* Invalid 82542 revision ID */ 323 /* Invalid 82542 revision ID */
324 return -E1000_ERR_MAC_TYPE; 324 return -E1000_ERR_MAC_TYPE;
325 } 325 }
326 break; 326 break;
327 case E1000_DEV_ID_82543GC_FIBER: 327 case E1000_DEV_ID_82543GC_FIBER:
328 case E1000_DEV_ID_82543GC_COPPER: 328 case E1000_DEV_ID_82543GC_COPPER:
329 hw->mac_type = e1000_82543; 329 hw->mac_type = e1000_82543;
330 break; 330 break;
331 case E1000_DEV_ID_82544EI_COPPER: 331 case E1000_DEV_ID_82544EI_COPPER:
332 case E1000_DEV_ID_82544EI_FIBER: 332 case E1000_DEV_ID_82544EI_FIBER:
333 case E1000_DEV_ID_82544GC_COPPER: 333 case E1000_DEV_ID_82544GC_COPPER:
334 case E1000_DEV_ID_82544GC_LOM: 334 case E1000_DEV_ID_82544GC_LOM:
335 hw->mac_type = e1000_82544; 335 hw->mac_type = e1000_82544;
336 break; 336 break;
337 case E1000_DEV_ID_82540EM: 337 case E1000_DEV_ID_82540EM:
338 case E1000_DEV_ID_82540EM_LOM: 338 case E1000_DEV_ID_82540EM_LOM:
339 case E1000_DEV_ID_82540EP: 339 case E1000_DEV_ID_82540EP:
340 case E1000_DEV_ID_82540EP_LOM: 340 case E1000_DEV_ID_82540EP_LOM:
341 case E1000_DEV_ID_82540EP_LP: 341 case E1000_DEV_ID_82540EP_LP:
342 hw->mac_type = e1000_82540; 342 hw->mac_type = e1000_82540;
343 break; 343 break;
344 case E1000_DEV_ID_82545EM_COPPER: 344 case E1000_DEV_ID_82545EM_COPPER:
345 case E1000_DEV_ID_82545EM_FIBER: 345 case E1000_DEV_ID_82545EM_FIBER:
346 hw->mac_type = e1000_82545; 346 hw->mac_type = e1000_82545;
347 break; 347 break;
348 case E1000_DEV_ID_82545GM_COPPER: 348 case E1000_DEV_ID_82545GM_COPPER:
349 case E1000_DEV_ID_82545GM_FIBER: 349 case E1000_DEV_ID_82545GM_FIBER:
350 case E1000_DEV_ID_82545GM_SERDES: 350 case E1000_DEV_ID_82545GM_SERDES:
351 hw->mac_type = e1000_82545_rev_3; 351 hw->mac_type = e1000_82545_rev_3;
352 break; 352 break;
353 case E1000_DEV_ID_82546EB_COPPER: 353 case E1000_DEV_ID_82546EB_COPPER:
354 case E1000_DEV_ID_82546EB_FIBER: 354 case E1000_DEV_ID_82546EB_FIBER:
355 case E1000_DEV_ID_82546EB_QUAD_COPPER: 355 case E1000_DEV_ID_82546EB_QUAD_COPPER:
356 hw->mac_type = e1000_82546; 356 hw->mac_type = e1000_82546;
357 break; 357 break;
358 case E1000_DEV_ID_82546GB_COPPER: 358 case E1000_DEV_ID_82546GB_COPPER:
359 case E1000_DEV_ID_82546GB_FIBER: 359 case E1000_DEV_ID_82546GB_FIBER:
360 case E1000_DEV_ID_82546GB_SERDES: 360 case E1000_DEV_ID_82546GB_SERDES:
361 case E1000_DEV_ID_82546GB_PCIE: 361 case E1000_DEV_ID_82546GB_PCIE:
362 case E1000_DEV_ID_82546GB_QUAD_COPPER: 362 case E1000_DEV_ID_82546GB_QUAD_COPPER:
363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3: 363 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
364 hw->mac_type = e1000_82546_rev_3; 364 hw->mac_type = e1000_82546_rev_3;
365 break; 365 break;
366 case E1000_DEV_ID_82541EI: 366 case E1000_DEV_ID_82541EI:
367 case E1000_DEV_ID_82541EI_MOBILE: 367 case E1000_DEV_ID_82541EI_MOBILE:
368 case E1000_DEV_ID_82541ER_LOM: 368 case E1000_DEV_ID_82541ER_LOM:
369 hw->mac_type = e1000_82541; 369 hw->mac_type = e1000_82541;
370 break; 370 break;
371 case E1000_DEV_ID_82541ER: 371 case E1000_DEV_ID_82541ER:
372 case E1000_DEV_ID_82541GI: 372 case E1000_DEV_ID_82541GI:
373 case E1000_DEV_ID_82541GI_LF: 373 case E1000_DEV_ID_82541GI_LF:
374 case E1000_DEV_ID_82541GI_MOBILE: 374 case E1000_DEV_ID_82541GI_MOBILE:
375 hw->mac_type = e1000_82541_rev_2; 375 hw->mac_type = e1000_82541_rev_2;
376 break; 376 break;
377 case E1000_DEV_ID_82547EI: 377 case E1000_DEV_ID_82547EI:
378 case E1000_DEV_ID_82547EI_MOBILE: 378 case E1000_DEV_ID_82547EI_MOBILE:
379 hw->mac_type = e1000_82547; 379 hw->mac_type = e1000_82547;
380 break; 380 break;
381 case E1000_DEV_ID_82547GI: 381 case E1000_DEV_ID_82547GI:
382 hw->mac_type = e1000_82547_rev_2; 382 hw->mac_type = e1000_82547_rev_2;
383 break; 383 break;
384 case E1000_DEV_ID_82571EB_COPPER: 384 case E1000_DEV_ID_82571EB_COPPER:
385 case E1000_DEV_ID_82571EB_FIBER: 385 case E1000_DEV_ID_82571EB_FIBER:
386 case E1000_DEV_ID_82571EB_SERDES: 386 case E1000_DEV_ID_82571EB_SERDES:
387 case E1000_DEV_ID_82571EB_QUAD_COPPER: 387 case E1000_DEV_ID_82571EB_QUAD_COPPER:
388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE: 388 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
389 hw->mac_type = e1000_82571; 389 hw->mac_type = e1000_82571;
390 break; 390 break;
391 case E1000_DEV_ID_82572EI_COPPER: 391 case E1000_DEV_ID_82572EI_COPPER:
392 case E1000_DEV_ID_82572EI_FIBER: 392 case E1000_DEV_ID_82572EI_FIBER:
393 case E1000_DEV_ID_82572EI_SERDES: 393 case E1000_DEV_ID_82572EI_SERDES:
394 case E1000_DEV_ID_82572EI: 394 case E1000_DEV_ID_82572EI:
395 hw->mac_type = e1000_82572; 395 hw->mac_type = e1000_82572;
396 break; 396 break;
397 case E1000_DEV_ID_82573E: 397 case E1000_DEV_ID_82573E:
398 case E1000_DEV_ID_82573E_IAMT: 398 case E1000_DEV_ID_82573E_IAMT:
399 case E1000_DEV_ID_82573L: 399 case E1000_DEV_ID_82573L:
400 hw->mac_type = e1000_82573; 400 hw->mac_type = e1000_82573;
401 break; 401 break;
402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT: 402 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT: 403 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT: 404 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT: 405 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
406 hw->mac_type = e1000_80003es2lan; 406 hw->mac_type = e1000_80003es2lan;
407 break; 407 break;
408 case E1000_DEV_ID_ICH8_IGP_M_AMT: 408 case E1000_DEV_ID_ICH8_IGP_M_AMT:
409 case E1000_DEV_ID_ICH8_IGP_AMT: 409 case E1000_DEV_ID_ICH8_IGP_AMT:
410 case E1000_DEV_ID_ICH8_IGP_C: 410 case E1000_DEV_ID_ICH8_IGP_C:
411 case E1000_DEV_ID_ICH8_IFE: 411 case E1000_DEV_ID_ICH8_IFE:
412 case E1000_DEV_ID_ICH8_IFE_GT: 412 case E1000_DEV_ID_ICH8_IFE_GT:
413 case E1000_DEV_ID_ICH8_IFE_G: 413 case E1000_DEV_ID_ICH8_IFE_G:
414 case E1000_DEV_ID_ICH8_IGP_M: 414 case E1000_DEV_ID_ICH8_IGP_M:
415 hw->mac_type = e1000_ich8lan; 415 hw->mac_type = e1000_ich8lan;
416 break; 416 break;
417 default: 417 default:
418 /* Should never have loaded on this device */ 418 /* Should never have loaded on this device */
419 return -E1000_ERR_MAC_TYPE; 419 return -E1000_ERR_MAC_TYPE;
420 } 420 }
421 421
422 switch (hw->mac_type) { 422 switch (hw->mac_type) {
423 case e1000_ich8lan: 423 case e1000_ich8lan:
424 hw->swfwhw_semaphore_present = TRUE; 424 hw->swfwhw_semaphore_present = TRUE;
425 hw->asf_firmware_present = TRUE; 425 hw->asf_firmware_present = TRUE;
426 break; 426 break;
427 case e1000_80003es2lan: 427 case e1000_80003es2lan:
428 hw->swfw_sync_present = TRUE; 428 hw->swfw_sync_present = TRUE;
429 /* fall through */ 429 /* fall through */
430 case e1000_82571: 430 case e1000_82571:
431 case e1000_82572: 431 case e1000_82572:
432 case e1000_82573: 432 case e1000_82573:
433 hw->eeprom_semaphore_present = TRUE; 433 hw->eeprom_semaphore_present = TRUE;
434 /* fall through */ 434 /* fall through */
435 case e1000_82541: 435 case e1000_82541:
436 case e1000_82547: 436 case e1000_82547:
437 case e1000_82541_rev_2: 437 case e1000_82541_rev_2:
438 case e1000_82547_rev_2: 438 case e1000_82547_rev_2:
439 hw->asf_firmware_present = TRUE; 439 hw->asf_firmware_present = TRUE;
440 break; 440 break;
441 default: 441 default:
442 break; 442 break;
443 } 443 }
444 444
445 return E1000_SUCCESS; 445 /* The 82543 chip does not count tx_carrier_errors properly in
446 * FD mode
447 */
448 if (hw->mac_type == e1000_82543)
449 hw->bad_tx_carr_stats_fd = TRUE;
450
451 /* capable of receiving management packets to the host */
452 if (hw->mac_type >= e1000_82571)
453 hw->has_manc2h = TRUE;
454
455 /* In rare occasions, ESB2 systems would end up started without
456 * the RX unit being turned on.
457 */
458 if (hw->mac_type == e1000_80003es2lan)
459 hw->rx_needs_kicking = TRUE;
460
461 if (hw->mac_type > e1000_82544)
462 hw->has_smbus = TRUE;
463
464 return E1000_SUCCESS;
446} 465}
447 466
448/***************************************************************************** 467/*****************************************************************************
@@ -6575,7 +6594,7 @@ e1000_get_bus_info(struct e1000_hw *hw)
6575 switch (hw->mac_type) { 6594 switch (hw->mac_type) {
6576 case e1000_82542_rev2_0: 6595 case e1000_82542_rev2_0:
6577 case e1000_82542_rev2_1: 6596 case e1000_82542_rev2_1:
6578 hw->bus_type = e1000_bus_type_unknown; 6597 hw->bus_type = e1000_bus_type_pci;
6579 hw->bus_speed = e1000_bus_speed_unknown; 6598 hw->bus_speed = e1000_bus_speed_unknown;
6580 hw->bus_width = e1000_bus_width_unknown; 6599 hw->bus_width = e1000_bus_width_unknown;
6581 break; 6600 break;
@@ -7817,9 +7836,8 @@ e1000_enable_mng_pass_thru(struct e1000_hw *hw)
7817 fwsm = E1000_READ_REG(hw, FWSM); 7836 fwsm = E1000_READ_REG(hw, FWSM);
7818 factps = E1000_READ_REG(hw, FACTPS); 7837 factps = E1000_READ_REG(hw, FACTPS);
7819 7838
7820 if (((fwsm & E1000_FWSM_MODE_MASK) == 7839 if ((((fwsm & E1000_FWSM_MODE_MASK) >> E1000_FWSM_MODE_SHIFT) ==
7821 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) && 7840 e1000_mng_mode_pt) && !(factps & E1000_FACTPS_MNGCG))
7822 (factps & E1000_FACTPS_MNGCG))
7823 return TRUE; 7841 return TRUE;
7824 } else 7842 } else
7825 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN)) 7843 if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
diff --git a/drivers/net/e1000/e1000_hw.h b/drivers/net/e1000/e1000_hw.h
index 3321fb13bfa9..d67105883341 100644
--- a/drivers/net/e1000/e1000_hw.h
+++ b/drivers/net/e1000/e1000_hw.h
@@ -1301,165 +1301,170 @@ struct e1000_ffvt_entry {
1301#define E1000_82542_RSSIR E1000_RSSIR 1301#define E1000_82542_RSSIR E1000_RSSIR
1302#define E1000_82542_KUMCTRLSTA E1000_KUMCTRLSTA 1302#define E1000_82542_KUMCTRLSTA E1000_KUMCTRLSTA
1303#define E1000_82542_SW_FW_SYNC E1000_SW_FW_SYNC 1303#define E1000_82542_SW_FW_SYNC E1000_SW_FW_SYNC
1304#define E1000_82542_MANC2H E1000_MANC2H
1304 1305
1305/* Statistics counters collected by the MAC */ 1306/* Statistics counters collected by the MAC */
1306struct e1000_hw_stats { 1307struct e1000_hw_stats {
1307 uint64_t crcerrs; 1308 uint64_t crcerrs;
1308 uint64_t algnerrc; 1309 uint64_t algnerrc;
1309 uint64_t symerrs; 1310 uint64_t symerrs;
1310 uint64_t rxerrc; 1311 uint64_t rxerrc;
1311 uint64_t txerrc; 1312 uint64_t txerrc;
1312 uint64_t mpc; 1313 uint64_t mpc;
1313 uint64_t scc; 1314 uint64_t scc;
1314 uint64_t ecol; 1315 uint64_t ecol;
1315 uint64_t mcc; 1316 uint64_t mcc;
1316 uint64_t latecol; 1317 uint64_t latecol;
1317 uint64_t colc; 1318 uint64_t colc;
1318 uint64_t dc; 1319 uint64_t dc;
1319 uint64_t tncrs; 1320 uint64_t tncrs;
1320 uint64_t sec; 1321 uint64_t sec;
1321 uint64_t cexterr; 1322 uint64_t cexterr;
1322 uint64_t rlec; 1323 uint64_t rlec;
1323 uint64_t xonrxc; 1324 uint64_t xonrxc;
1324 uint64_t xontxc; 1325 uint64_t xontxc;
1325 uint64_t xoffrxc; 1326 uint64_t xoffrxc;
1326 uint64_t xofftxc; 1327 uint64_t xofftxc;
1327 uint64_t fcruc; 1328 uint64_t fcruc;
1328 uint64_t prc64; 1329 uint64_t prc64;
1329 uint64_t prc127; 1330 uint64_t prc127;
1330 uint64_t prc255; 1331 uint64_t prc255;
1331 uint64_t prc511; 1332 uint64_t prc511;
1332 uint64_t prc1023; 1333 uint64_t prc1023;
1333 uint64_t prc1522; 1334 uint64_t prc1522;
1334 uint64_t gprc; 1335 uint64_t gprc;
1335 uint64_t bprc; 1336 uint64_t bprc;
1336 uint64_t mprc; 1337 uint64_t mprc;
1337 uint64_t gptc; 1338 uint64_t gptc;
1338 uint64_t gorcl; 1339 uint64_t gorcl;
1339 uint64_t gorch; 1340 uint64_t gorch;
1340 uint64_t gotcl; 1341 uint64_t gotcl;
1341 uint64_t gotch; 1342 uint64_t gotch;
1342 uint64_t rnbc; 1343 uint64_t rnbc;
1343 uint64_t ruc; 1344 uint64_t ruc;
1344 uint64_t rfc; 1345 uint64_t rfc;
1345 uint64_t roc; 1346 uint64_t roc;
1346 uint64_t rlerrc; 1347 uint64_t rlerrc;
1347 uint64_t rjc; 1348 uint64_t rjc;
1348 uint64_t mgprc; 1349 uint64_t mgprc;
1349 uint64_t mgpdc; 1350 uint64_t mgpdc;
1350 uint64_t mgptc; 1351 uint64_t mgptc;
1351 uint64_t torl; 1352 uint64_t torl;
1352 uint64_t torh; 1353 uint64_t torh;
1353 uint64_t totl; 1354 uint64_t totl;
1354 uint64_t toth; 1355 uint64_t toth;
1355 uint64_t tpr; 1356 uint64_t tpr;
1356 uint64_t tpt; 1357 uint64_t tpt;
1357 uint64_t ptc64; 1358 uint64_t ptc64;
1358 uint64_t ptc127; 1359 uint64_t ptc127;
1359 uint64_t ptc255; 1360 uint64_t ptc255;
1360 uint64_t ptc511; 1361 uint64_t ptc511;
1361 uint64_t ptc1023; 1362 uint64_t ptc1023;
1362 uint64_t ptc1522; 1363 uint64_t ptc1522;
1363 uint64_t mptc; 1364 uint64_t mptc;
1364 uint64_t bptc; 1365 uint64_t bptc;
1365 uint64_t tsctc; 1366 uint64_t tsctc;
1366 uint64_t tsctfc; 1367 uint64_t tsctfc;
1367 uint64_t iac; 1368 uint64_t iac;
1368 uint64_t icrxptc; 1369 uint64_t icrxptc;
1369 uint64_t icrxatc; 1370 uint64_t icrxatc;
1370 uint64_t ictxptc; 1371 uint64_t ictxptc;
1371 uint64_t ictxatc; 1372 uint64_t ictxatc;
1372 uint64_t ictxqec; 1373 uint64_t ictxqec;
1373 uint64_t ictxqmtc; 1374 uint64_t ictxqmtc;
1374 uint64_t icrxdmtc; 1375 uint64_t icrxdmtc;
1375 uint64_t icrxoc; 1376 uint64_t icrxoc;
1376}; 1377};
1377 1378
1378/* Structure containing variables used by the shared code (e1000_hw.c) */ 1379/* Structure containing variables used by the shared code (e1000_hw.c) */
1379struct e1000_hw { 1380struct e1000_hw {
1380 uint8_t __iomem *hw_addr; 1381 uint8_t __iomem *hw_addr;
1381 uint8_t __iomem *flash_address; 1382 uint8_t __iomem *flash_address;
1382 e1000_mac_type mac_type; 1383 e1000_mac_type mac_type;
1383 e1000_phy_type phy_type; 1384 e1000_phy_type phy_type;
1384 uint32_t phy_init_script; 1385 uint32_t phy_init_script;
1385 e1000_media_type media_type; 1386 e1000_media_type media_type;
1386 void *back; 1387 void *back;
1387 struct e1000_shadow_ram *eeprom_shadow_ram; 1388 struct e1000_shadow_ram *eeprom_shadow_ram;
1388 uint32_t flash_bank_size; 1389 uint32_t flash_bank_size;
1389 uint32_t flash_base_addr; 1390 uint32_t flash_base_addr;
1390 e1000_fc_type fc; 1391 e1000_fc_type fc;
1391 e1000_bus_speed bus_speed; 1392 e1000_bus_speed bus_speed;
1392 e1000_bus_width bus_width; 1393 e1000_bus_width bus_width;
1393 e1000_bus_type bus_type; 1394 e1000_bus_type bus_type;
1394 struct e1000_eeprom_info eeprom; 1395 struct e1000_eeprom_info eeprom;
1395 e1000_ms_type master_slave; 1396 e1000_ms_type master_slave;
1396 e1000_ms_type original_master_slave; 1397 e1000_ms_type original_master_slave;
1397 e1000_ffe_config ffe_config_state; 1398 e1000_ffe_config ffe_config_state;
1398 uint32_t asf_firmware_present; 1399 uint32_t asf_firmware_present;
1399 uint32_t eeprom_semaphore_present; 1400 uint32_t eeprom_semaphore_present;
1400 uint32_t swfw_sync_present; 1401 uint32_t swfw_sync_present;
1401 uint32_t swfwhw_semaphore_present; 1402 uint32_t swfwhw_semaphore_present;
1402 unsigned long io_base; 1403 unsigned long io_base;
1403 uint32_t phy_id; 1404 uint32_t phy_id;
1404 uint32_t phy_revision; 1405 uint32_t phy_revision;
1405 uint32_t phy_addr; 1406 uint32_t phy_addr;
1406 uint32_t original_fc; 1407 uint32_t original_fc;
1407 uint32_t txcw; 1408 uint32_t txcw;
1408 uint32_t autoneg_failed; 1409 uint32_t autoneg_failed;
1409 uint32_t max_frame_size; 1410 uint32_t max_frame_size;
1410 uint32_t min_frame_size; 1411 uint32_t min_frame_size;
1411 uint32_t mc_filter_type; 1412 uint32_t mc_filter_type;
1412 uint32_t num_mc_addrs; 1413 uint32_t num_mc_addrs;
1413 uint32_t collision_delta; 1414 uint32_t collision_delta;
1414 uint32_t tx_packet_delta; 1415 uint32_t tx_packet_delta;
1415 uint32_t ledctl_default; 1416 uint32_t ledctl_default;
1416 uint32_t ledctl_mode1; 1417 uint32_t ledctl_mode1;
1417 uint32_t ledctl_mode2; 1418 uint32_t ledctl_mode2;
1418 boolean_t tx_pkt_filtering; 1419 boolean_t tx_pkt_filtering;
1419 struct e1000_host_mng_dhcp_cookie mng_cookie; 1420 struct e1000_host_mng_dhcp_cookie mng_cookie;
1420 uint16_t phy_spd_default; 1421 uint16_t phy_spd_default;
1421 uint16_t autoneg_advertised; 1422 uint16_t autoneg_advertised;
1422 uint16_t pci_cmd_word; 1423 uint16_t pci_cmd_word;
1423 uint16_t fc_high_water; 1424 uint16_t fc_high_water;
1424 uint16_t fc_low_water; 1425 uint16_t fc_low_water;
1425 uint16_t fc_pause_time; 1426 uint16_t fc_pause_time;
1426 uint16_t current_ifs_val; 1427 uint16_t current_ifs_val;
1427 uint16_t ifs_min_val; 1428 uint16_t ifs_min_val;
1428 uint16_t ifs_max_val; 1429 uint16_t ifs_max_val;
1429 uint16_t ifs_step_size; 1430 uint16_t ifs_step_size;
1430 uint16_t ifs_ratio; 1431 uint16_t ifs_ratio;
1431 uint16_t device_id; 1432 uint16_t device_id;
1432 uint16_t vendor_id; 1433 uint16_t vendor_id;
1433 uint16_t subsystem_id; 1434 uint16_t subsystem_id;
1434 uint16_t subsystem_vendor_id; 1435 uint16_t subsystem_vendor_id;
1435 uint8_t revision_id; 1436 uint8_t revision_id;
1436 uint8_t autoneg; 1437 uint8_t autoneg;
1437 uint8_t mdix; 1438 uint8_t mdix;
1438 uint8_t forced_speed_duplex; 1439 uint8_t forced_speed_duplex;
1439 uint8_t wait_autoneg_complete; 1440 uint8_t wait_autoneg_complete;
1440 uint8_t dma_fairness; 1441 uint8_t dma_fairness;
1441 uint8_t mac_addr[NODE_ADDRESS_SIZE]; 1442 uint8_t mac_addr[NODE_ADDRESS_SIZE];
1442 uint8_t perm_mac_addr[NODE_ADDRESS_SIZE]; 1443 uint8_t perm_mac_addr[NODE_ADDRESS_SIZE];
1443 boolean_t disable_polarity_correction; 1444 boolean_t disable_polarity_correction;
1444 boolean_t speed_downgraded; 1445 boolean_t speed_downgraded;
1445 e1000_smart_speed smart_speed; 1446 e1000_smart_speed smart_speed;
1446 e1000_dsp_config dsp_config_state; 1447 e1000_dsp_config dsp_config_state;
1447 boolean_t get_link_status; 1448 boolean_t get_link_status;
1448 boolean_t serdes_link_down; 1449 boolean_t serdes_link_down;
1449 boolean_t tbi_compatibility_en; 1450 boolean_t tbi_compatibility_en;
1450 boolean_t tbi_compatibility_on; 1451 boolean_t tbi_compatibility_on;
1451 boolean_t laa_is_present; 1452 boolean_t laa_is_present;
1452 boolean_t phy_reset_disable; 1453 boolean_t phy_reset_disable;
1453 boolean_t initialize_hw_bits_disable; 1454 boolean_t initialize_hw_bits_disable;
1454 boolean_t fc_send_xon; 1455 boolean_t fc_send_xon;
1455 boolean_t fc_strict_ieee; 1456 boolean_t fc_strict_ieee;
1456 boolean_t report_tx_early; 1457 boolean_t report_tx_early;
1457 boolean_t adaptive_ifs; 1458 boolean_t adaptive_ifs;
1458 boolean_t ifs_params_forced; 1459 boolean_t ifs_params_forced;
1459 boolean_t in_ifs_mode; 1460 boolean_t in_ifs_mode;
1460 boolean_t mng_reg_access_disabled; 1461 boolean_t mng_reg_access_disabled;
1461 boolean_t leave_av_bit_off; 1462 boolean_t leave_av_bit_off;
1462 boolean_t kmrn_lock_loss_workaround_disabled; 1463 boolean_t kmrn_lock_loss_workaround_disabled;
1464 boolean_t bad_tx_carr_stats_fd;
1465 boolean_t has_manc2h;
1466 boolean_t rx_needs_kicking;
1467 boolean_t has_smbus;
1463}; 1468};
1464 1469
1465 1470
@@ -2418,6 +2423,7 @@ struct e1000_host_command_info {
2418#define E1000_PBA_8K 0x0008 /* 8KB, default Rx allocation */ 2423#define E1000_PBA_8K 0x0008 /* 8KB, default Rx allocation */
2419#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */ 2424#define E1000_PBA_12K 0x000C /* 12KB, default Rx allocation */
2420#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */ 2425#define E1000_PBA_16K 0x0010 /* 16KB, default TX allocation */
2426#define E1000_PBA_20K 0x0014
2421#define E1000_PBA_22K 0x0016 2427#define E1000_PBA_22K 0x0016
2422#define E1000_PBA_24K 0x0018 2428#define E1000_PBA_24K 0x0018
2423#define E1000_PBA_30K 0x001E 2429#define E1000_PBA_30K 0x001E
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 73f3a85fd238..4c1ff752048c 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -213,6 +213,12 @@ static void e1000_netpoll (struct net_device *netdev);
213 213
214extern void e1000_check_options(struct e1000_adapter *adapter); 214extern void e1000_check_options(struct e1000_adapter *adapter);
215 215
216#define COPYBREAK_DEFAULT 256
217static unsigned int copybreak __read_mostly = COPYBREAK_DEFAULT;
218module_param(copybreak, uint, 0644);
219MODULE_PARM_DESC(copybreak,
220 "Maximum size of packet that is copied to a new buffer on receive");
221
216static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev, 222static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
217 pci_channel_state_t state); 223 pci_channel_state_t state);
218static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev); 224static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev);
@@ -264,7 +270,13 @@ e1000_init_module(void)
264 printk(KERN_INFO "%s\n", e1000_copyright); 270 printk(KERN_INFO "%s\n", e1000_copyright);
265 271
266 ret = pci_register_driver(&e1000_driver); 272 ret = pci_register_driver(&e1000_driver);
267 273 if (copybreak != COPYBREAK_DEFAULT) {
274 if (copybreak == 0)
275 printk(KERN_INFO "e1000: copybreak disabled\n");
276 else
277 printk(KERN_INFO "e1000: copybreak enabled for "
278 "packets <= %u bytes\n", copybreak);
279 }
268 return ret; 280 return ret;
269} 281}
270 282
@@ -464,6 +476,52 @@ e1000_get_hw_control(struct e1000_adapter *adapter)
464 } 476 }
465} 477}
466 478
479static void
480e1000_init_manageability(struct e1000_adapter *adapter)
481{
482 if (adapter->en_mng_pt) {
483 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
484
485 /* disable hardware interception of ARP */
486 manc &= ~(E1000_MANC_ARP_EN);
487
488 /* enable receiving management packets to the host */
489 /* this will probably generate destination unreachable messages
490 * from the host OS, but the packets will be handled on SMBUS */
491 if (adapter->hw.has_manc2h) {
492 uint32_t manc2h = E1000_READ_REG(&adapter->hw, MANC2H);
493
494 manc |= E1000_MANC_EN_MNG2HOST;
495#define E1000_MNG2HOST_PORT_623 (1 << 5)
496#define E1000_MNG2HOST_PORT_664 (1 << 6)
497 manc2h |= E1000_MNG2HOST_PORT_623;
498 manc2h |= E1000_MNG2HOST_PORT_664;
499 E1000_WRITE_REG(&adapter->hw, MANC2H, manc2h);
500 }
501
502 E1000_WRITE_REG(&adapter->hw, MANC, manc);
503 }
504}
505
506static void
507e1000_release_manageability(struct e1000_adapter *adapter)
508{
509 if (adapter->en_mng_pt) {
510 uint32_t manc = E1000_READ_REG(&adapter->hw, MANC);
511
512 /* re-enable hardware interception of ARP */
513 manc |= E1000_MANC_ARP_EN;
514
515 if (adapter->hw.has_manc2h)
516 manc &= ~E1000_MANC_EN_MNG2HOST;
517
518 /* don't explicitly have to mess with MANC2H since
519 * MANC has an enable disable that gates MANC2H */
520
521 E1000_WRITE_REG(&adapter->hw, MANC, manc);
522 }
523}
524
467int 525int
468e1000_up(struct e1000_adapter *adapter) 526e1000_up(struct e1000_adapter *adapter)
469{ 527{
@@ -475,6 +533,7 @@ e1000_up(struct e1000_adapter *adapter)
475 e1000_set_multi(netdev); 533 e1000_set_multi(netdev);
476 534
477 e1000_restore_vlan(adapter); 535 e1000_restore_vlan(adapter);
536 e1000_init_manageability(adapter);
478 537
479 e1000_configure_tx(adapter); 538 e1000_configure_tx(adapter);
480 e1000_setup_rctl(adapter); 539 e1000_setup_rctl(adapter);
@@ -497,7 +556,8 @@ e1000_up(struct e1000_adapter *adapter)
497 556
498 clear_bit(__E1000_DOWN, &adapter->flags); 557 clear_bit(__E1000_DOWN, &adapter->flags);
499 558
500 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); 559 /* fire a link change interrupt to start the watchdog */
560 E1000_WRITE_REG(&adapter->hw, ICS, E1000_ICS_LSC);
501 return 0; 561 return 0;
502} 562}
503 563
@@ -614,16 +674,34 @@ e1000_reinit_locked(struct e1000_adapter *adapter)
614void 674void
615e1000_reset(struct e1000_adapter *adapter) 675e1000_reset(struct e1000_adapter *adapter)
616{ 676{
617 uint32_t pba, manc; 677 uint32_t pba = 0, tx_space, min_tx_space, min_rx_space;
618 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF; 678 uint16_t fc_high_water_mark = E1000_FC_HIGH_DIFF;
679 boolean_t legacy_pba_adjust = FALSE;
619 680
620 /* Repartition Pba for greater than 9k mtu 681 /* Repartition Pba for greater than 9k mtu
621 * To take effect CTRL.RST is required. 682 * To take effect CTRL.RST is required.
622 */ 683 */
623 684
624 switch (adapter->hw.mac_type) { 685 switch (adapter->hw.mac_type) {
686 case e1000_82542_rev2_0:
687 case e1000_82542_rev2_1:
688 case e1000_82543:
689 case e1000_82544:
690 case e1000_82540:
691 case e1000_82541:
692 case e1000_82541_rev_2:
693 legacy_pba_adjust = TRUE;
694 pba = E1000_PBA_48K;
695 break;
696 case e1000_82545:
697 case e1000_82545_rev_3:
698 case e1000_82546:
699 case e1000_82546_rev_3:
700 pba = E1000_PBA_48K;
701 break;
625 case e1000_82547: 702 case e1000_82547:
626 case e1000_82547_rev_2: 703 case e1000_82547_rev_2:
704 legacy_pba_adjust = TRUE;
627 pba = E1000_PBA_30K; 705 pba = E1000_PBA_30K;
628 break; 706 break;
629 case e1000_82571: 707 case e1000_82571:
@@ -632,27 +710,80 @@ e1000_reset(struct e1000_adapter *adapter)
632 pba = E1000_PBA_38K; 710 pba = E1000_PBA_38K;
633 break; 711 break;
634 case e1000_82573: 712 case e1000_82573:
635 pba = E1000_PBA_12K; 713 pba = E1000_PBA_20K;
636 break; 714 break;
637 case e1000_ich8lan: 715 case e1000_ich8lan:
638 pba = E1000_PBA_8K; 716 pba = E1000_PBA_8K;
639 break; 717 case e1000_undefined:
640 default: 718 case e1000_num_macs:
641 pba = E1000_PBA_48K;
642 break; 719 break;
643 } 720 }
644 721
645 if ((adapter->hw.mac_type != e1000_82573) && 722 if (legacy_pba_adjust == TRUE) {
646 (adapter->netdev->mtu > E1000_RXBUFFER_8192)) 723 if (adapter->netdev->mtu > E1000_RXBUFFER_8192)
647 pba -= 8; /* allocate more FIFO for Tx */ 724 pba -= 8; /* allocate more FIFO for Tx */
648 725
726 if (adapter->hw.mac_type == e1000_82547) {
727 adapter->tx_fifo_head = 0;
728 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT;
729 adapter->tx_fifo_size =
730 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT;
731 atomic_set(&adapter->tx_fifo_stall, 0);
732 }
733 } else if (adapter->hw.max_frame_size > MAXIMUM_ETHERNET_FRAME_SIZE) {
734 /* adjust PBA for jumbo frames */
735 E1000_WRITE_REG(&adapter->hw, PBA, pba);
736
737 /* To maintain wire speed transmits, the Tx FIFO should be
738 * large enough to accomodate two full transmit packets,
739 * rounded up to the next 1KB and expressed in KB. Likewise,
740 * the Rx FIFO should be large enough to accomodate at least
741 * one full receive packet and is similarly rounded up and
742 * expressed in KB. */
743 pba = E1000_READ_REG(&adapter->hw, PBA);
744 /* upper 16 bits has Tx packet buffer allocation size in KB */
745 tx_space = pba >> 16;
746 /* lower 16 bits has Rx packet buffer allocation size in KB */
747 pba &= 0xffff;
748 /* don't include ethernet FCS because hardware appends/strips */
749 min_rx_space = adapter->netdev->mtu + ENET_HEADER_SIZE +
750 VLAN_TAG_SIZE;
751 min_tx_space = min_rx_space;
752 min_tx_space *= 2;
753 E1000_ROUNDUP(min_tx_space, 1024);
754 min_tx_space >>= 10;
755 E1000_ROUNDUP(min_rx_space, 1024);
756 min_rx_space >>= 10;
757
758 /* If current Tx allocation is less than the min Tx FIFO size,
759 * and the min Tx FIFO size is less than the current Rx FIFO
760 * allocation, take space away from current Rx allocation */
761 if (tx_space < min_tx_space &&
762 ((min_tx_space - tx_space) < pba)) {
763 pba = pba - (min_tx_space - tx_space);
764
765 /* PCI/PCIx hardware has PBA alignment constraints */
766 switch (adapter->hw.mac_type) {
767 case e1000_82545 ... e1000_82546_rev_3:
768 pba &= ~(E1000_PBA_8K - 1);
769 break;
770 default:
771 break;
772 }
649 773
650 if (adapter->hw.mac_type == e1000_82547) { 774 /* if short on rx space, rx wins and must trump tx
651 adapter->tx_fifo_head = 0; 775 * adjustment or use Early Receive if available */
652 adapter->tx_head_addr = pba << E1000_TX_HEAD_ADDR_SHIFT; 776 if (pba < min_rx_space) {
653 adapter->tx_fifo_size = 777 switch (adapter->hw.mac_type) {
654 (E1000_PBA_40K - pba) << E1000_PBA_BYTES_SHIFT; 778 case e1000_82573:
655 atomic_set(&adapter->tx_fifo_stall, 0); 779 /* ERT enabled in e1000_configure_rx */
780 break;
781 default:
782 pba = min_rx_space;
783 break;
784 }
785 }
786 }
656 } 787 }
657 788
658 E1000_WRITE_REG(&adapter->hw, PBA, pba); 789 E1000_WRITE_REG(&adapter->hw, PBA, pba);
@@ -685,6 +816,20 @@ e1000_reset(struct e1000_adapter *adapter)
685 if (e1000_init_hw(&adapter->hw)) 816 if (e1000_init_hw(&adapter->hw))
686 DPRINTK(PROBE, ERR, "Hardware Error\n"); 817 DPRINTK(PROBE, ERR, "Hardware Error\n");
687 e1000_update_mng_vlan(adapter); 818 e1000_update_mng_vlan(adapter);
819
820 /* if (adapter->hwflags & HWFLAGS_PHY_PWR_BIT) { */
821 if (adapter->hw.mac_type >= e1000_82544 &&
822 adapter->hw.mac_type <= e1000_82547_rev_2 &&
823 adapter->hw.autoneg == 1 &&
824 adapter->hw.autoneg_advertised == ADVERTISE_1000_FULL) {
825 uint32_t ctrl = E1000_READ_REG(&adapter->hw, CTRL);
826 /* clear phy power management bit if we are in gig only mode,
827 * which if enabled will attempt negotiation to 100Mb, which
828 * can cause a loss of link at power off or driver unload */
829 ctrl &= ~E1000_CTRL_SWDPIN3;
830 E1000_WRITE_REG(&adapter->hw, CTRL, ctrl);
831 }
832
688 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */ 833 /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
689 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE); 834 E1000_WRITE_REG(&adapter->hw, VET, ETHERNET_IEEE_VLAN_TYPE);
690 835
@@ -705,14 +850,7 @@ e1000_reset(struct e1000_adapter *adapter)
705 phy_data); 850 phy_data);
706 } 851 }
707 852
708 if ((adapter->en_mng_pt) && 853 e1000_release_manageability(adapter);
709 (adapter->hw.mac_type >= e1000_82540) &&
710 (adapter->hw.mac_type < e1000_82571) &&
711 (adapter->hw.media_type == e1000_media_type_copper)) {
712 manc = E1000_READ_REG(&adapter->hw, MANC);
713 manc |= (E1000_MANC_ARP_EN | E1000_MANC_EN_MNG2HOST);
714 E1000_WRITE_REG(&adapter->hw, MANC, manc);
715 }
716} 854}
717 855
718/** 856/**
@@ -857,6 +995,12 @@ e1000_probe(struct pci_dev *pdev,
857 (adapter->hw.mac_type != e1000_82547)) 995 (adapter->hw.mac_type != e1000_82547))
858 netdev->features |= NETIF_F_TSO; 996 netdev->features |= NETIF_F_TSO;
859 997
998#ifdef CONFIG_DEBUG_SLAB
999 /* 82544's work arounds do not play nicely with DEBUG SLAB */
1000 if (adapter->hw.mac_type == e1000_82544)
1001 netdev->features &= ~NETIF_F_TSO;
1002#endif
1003
860#ifdef NETIF_F_TSO6 1004#ifdef NETIF_F_TSO6
861 if (adapter->hw.mac_type > e1000_82547_rev_2) 1005 if (adapter->hw.mac_type > e1000_82547_rev_2)
862 netdev->features |= NETIF_F_TSO6; 1006 netdev->features |= NETIF_F_TSO6;
@@ -1078,22 +1222,13 @@ e1000_remove(struct pci_dev *pdev)
1078{ 1222{
1079 struct net_device *netdev = pci_get_drvdata(pdev); 1223 struct net_device *netdev = pci_get_drvdata(pdev);
1080 struct e1000_adapter *adapter = netdev_priv(netdev); 1224 struct e1000_adapter *adapter = netdev_priv(netdev);
1081 uint32_t manc;
1082#ifdef CONFIG_E1000_NAPI 1225#ifdef CONFIG_E1000_NAPI
1083 int i; 1226 int i;
1084#endif 1227#endif
1085 1228
1086 flush_scheduled_work(); 1229 flush_scheduled_work();
1087 1230
1088 if (adapter->hw.mac_type >= e1000_82540 && 1231 e1000_release_manageability(adapter);
1089 adapter->hw.mac_type < e1000_82571 &&
1090 adapter->hw.media_type == e1000_media_type_copper) {
1091 manc = E1000_READ_REG(&adapter->hw, MANC);
1092 if (manc & E1000_MANC_SMBUS_EN) {
1093 manc |= E1000_MANC_ARP_EN;
1094 E1000_WRITE_REG(&adapter->hw, MANC, manc);
1095 }
1096 }
1097 1232
1098 /* Release control of h/w to f/w. If f/w is AMT enabled, this 1233 /* Release control of h/w to f/w. If f/w is AMT enabled, this
1099 * would have already happened in close and is redundant. */ 1234 * would have already happened in close and is redundant. */
@@ -1531,9 +1666,9 @@ e1000_configure_tx(struct e1000_adapter *adapter)
1531 } 1666 }
1532 1667
1533 /* Set the default values for the Tx Inter Packet Gap timer */ 1668 /* Set the default values for the Tx Inter Packet Gap timer */
1534 1669 if (adapter->hw.mac_type <= e1000_82547_rev_2 &&
1535 if (hw->media_type == e1000_media_type_fiber || 1670 (hw->media_type == e1000_media_type_fiber ||
1536 hw->media_type == e1000_media_type_internal_serdes) 1671 hw->media_type == e1000_media_type_internal_serdes))
1537 tipg = DEFAULT_82543_TIPG_IPGT_FIBER; 1672 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
1538 else 1673 else
1539 tipg = DEFAULT_82543_TIPG_IPGT_COPPER; 1674 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
@@ -2528,6 +2663,13 @@ e1000_watchdog(unsigned long data)
2528 netif_wake_queue(netdev); 2663 netif_wake_queue(netdev);
2529 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ); 2664 mod_timer(&adapter->phy_info_timer, jiffies + 2 * HZ);
2530 adapter->smartspeed = 0; 2665 adapter->smartspeed = 0;
2666 } else {
2667 /* make sure the receive unit is started */
2668 if (adapter->hw.rx_needs_kicking) {
2669 struct e1000_hw *hw = &adapter->hw;
2670 uint32_t rctl = E1000_READ_REG(hw, RCTL);
2671 E1000_WRITE_REG(hw, RCTL, rctl | E1000_RCTL_EN);
2672 }
2531 } 2673 }
2532 } else { 2674 } else {
2533 if (netif_carrier_ok(netdev)) { 2675 if (netif_carrier_ok(netdev)) {
@@ -2628,29 +2770,34 @@ static unsigned int e1000_update_itr(struct e1000_adapter *adapter,
2628 if (packets == 0) 2770 if (packets == 0)
2629 goto update_itr_done; 2771 goto update_itr_done;
2630 2772
2631
2632 switch (itr_setting) { 2773 switch (itr_setting) {
2633 case lowest_latency: 2774 case lowest_latency:
2634 if ((packets < 5) && (bytes > 512)) 2775 /* jumbo frames get bulk treatment*/
2776 if (bytes/packets > 8000)
2777 retval = bulk_latency;
2778 else if ((packets < 5) && (bytes > 512))
2635 retval = low_latency; 2779 retval = low_latency;
2636 break; 2780 break;
2637 case low_latency: /* 50 usec aka 20000 ints/s */ 2781 case low_latency: /* 50 usec aka 20000 ints/s */
2638 if (bytes > 10000) { 2782 if (bytes > 10000) {
2639 if ((packets < 10) || 2783 /* jumbo frames need bulk latency setting */
2640 ((bytes/packets) > 1200)) 2784 if (bytes/packets > 8000)
2785 retval = bulk_latency;
2786 else if ((packets < 10) || ((bytes/packets) > 1200))
2641 retval = bulk_latency; 2787 retval = bulk_latency;
2642 else if ((packets > 35)) 2788 else if ((packets > 35))
2643 retval = lowest_latency; 2789 retval = lowest_latency;
2644 } else if (packets <= 2 && bytes < 512) 2790 } else if (bytes/packets > 2000)
2791 retval = bulk_latency;
2792 else if (packets <= 2 && bytes < 512)
2645 retval = lowest_latency; 2793 retval = lowest_latency;
2646 break; 2794 break;
2647 case bulk_latency: /* 250 usec aka 4000 ints/s */ 2795 case bulk_latency: /* 250 usec aka 4000 ints/s */
2648 if (bytes > 25000) { 2796 if (bytes > 25000) {
2649 if (packets > 35) 2797 if (packets > 35)
2650 retval = low_latency; 2798 retval = low_latency;
2651 } else { 2799 } else if (bytes < 6000) {
2652 if (bytes < 6000) 2800 retval = low_latency;
2653 retval = low_latency;
2654 } 2801 }
2655 break; 2802 break;
2656 } 2803 }
@@ -2679,17 +2826,20 @@ static void e1000_set_itr(struct e1000_adapter *adapter)
2679 adapter->tx_itr, 2826 adapter->tx_itr,
2680 adapter->total_tx_packets, 2827 adapter->total_tx_packets,
2681 adapter->total_tx_bytes); 2828 adapter->total_tx_bytes);
2829 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2830 if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
2831 adapter->tx_itr = low_latency;
2832
2682 adapter->rx_itr = e1000_update_itr(adapter, 2833 adapter->rx_itr = e1000_update_itr(adapter,
2683 adapter->rx_itr, 2834 adapter->rx_itr,
2684 adapter->total_rx_packets, 2835 adapter->total_rx_packets,
2685 adapter->total_rx_bytes); 2836 adapter->total_rx_bytes);
2837 /* conservative mode (itr 3) eliminates the lowest_latency setting */
2838 if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
2839 adapter->rx_itr = low_latency;
2686 2840
2687 current_itr = max(adapter->rx_itr, adapter->tx_itr); 2841 current_itr = max(adapter->rx_itr, adapter->tx_itr);
2688 2842
2689 /* conservative mode eliminates the lowest_latency setting */
2690 if (current_itr == lowest_latency && (adapter->itr_setting == 3))
2691 current_itr = low_latency;
2692
2693 switch (current_itr) { 2843 switch (current_itr) {
2694 /* counts and packets in update_itr are dependent on these numbers */ 2844 /* counts and packets in update_itr are dependent on these numbers */
2695 case lowest_latency: 2845 case lowest_latency:
@@ -3168,6 +3318,16 @@ e1000_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3168 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) { 3318 if (skb->data_len && (hdr_len == (skb->len - skb->data_len))) {
3169 switch (adapter->hw.mac_type) { 3319 switch (adapter->hw.mac_type) {
3170 unsigned int pull_size; 3320 unsigned int pull_size;
3321 case e1000_82544:
3322 /* Make sure we have room to chop off 4 bytes,
3323 * and that the end alignment will work out to
3324 * this hardware's requirements
3325 * NOTE: this is a TSO only workaround
3326 * if end byte alignment not correct move us
3327 * into the next dword */
3328 if ((unsigned long)(skb->tail - 1) & 4)
3329 break;
3330 /* fall through */
3171 case e1000_82571: 3331 case e1000_82571:
3172 case e1000_82572: 3332 case e1000_82572:
3173 case e1000_82573: 3333 case e1000_82573:
@@ -3419,12 +3579,11 @@ e1000_change_mtu(struct net_device *netdev, int new_mtu)
3419 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE; 3579 adapter->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3420 3580
3421 netdev->mtu = new_mtu; 3581 netdev->mtu = new_mtu;
3582 adapter->hw.max_frame_size = max_frame;
3422 3583
3423 if (netif_running(netdev)) 3584 if (netif_running(netdev))
3424 e1000_reinit_locked(adapter); 3585 e1000_reinit_locked(adapter);
3425 3586
3426 adapter->hw.max_frame_size = max_frame;
3427
3428 return 0; 3587 return 0;
3429} 3588}
3430 3589
@@ -3573,6 +3732,11 @@ e1000_update_stats(struct e1000_adapter *adapter)
3573 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol; 3732 adapter->net_stats.tx_aborted_errors = adapter->stats.ecol;
3574 adapter->net_stats.tx_window_errors = adapter->stats.latecol; 3733 adapter->net_stats.tx_window_errors = adapter->stats.latecol;
3575 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs; 3734 adapter->net_stats.tx_carrier_errors = adapter->stats.tncrs;
3735 if (adapter->hw.bad_tx_carr_stats_fd &&
3736 adapter->link_duplex == FULL_DUPLEX) {
3737 adapter->net_stats.tx_carrier_errors = 0;
3738 adapter->stats.tncrs = 0;
3739 }
3576 3740
3577 /* Tx Dropped needs to be maintained elsewhere */ 3741 /* Tx Dropped needs to be maintained elsewhere */
3578 3742
@@ -3590,6 +3754,13 @@ e1000_update_stats(struct e1000_adapter *adapter)
3590 adapter->phy_stats.receive_errors += phy_tmp; 3754 adapter->phy_stats.receive_errors += phy_tmp;
3591 } 3755 }
3592 3756
3757 /* Management Stats */
3758 if (adapter->hw.has_smbus) {
3759 adapter->stats.mgptc += E1000_READ_REG(hw, MGTPTC);
3760 adapter->stats.mgprc += E1000_READ_REG(hw, MGTPRC);
3761 adapter->stats.mgpdc += E1000_READ_REG(hw, MGTPDC);
3762 }
3763
3593 spin_unlock_irqrestore(&adapter->stats_lock, flags); 3764 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3594} 3765}
3595#ifdef CONFIG_PCI_MSI 3766#ifdef CONFIG_PCI_MSI
@@ -3868,11 +4039,11 @@ e1000_clean_tx_irq(struct e1000_adapter *adapter,
3868 cleaned = (i == eop); 4039 cleaned = (i == eop);
3869 4040
3870 if (cleaned) { 4041 if (cleaned) {
3871 /* this packet count is wrong for TSO but has a 4042 struct sk_buff *skb = buffer_info->skb;
3872 * tendency to make dynamic ITR change more 4043 unsigned int segs = skb_shinfo(skb)->gso_segs;
3873 * towards bulk */ 4044 total_tx_packets += segs;
3874 total_tx_packets++; 4045 total_tx_packets++;
3875 total_tx_bytes += buffer_info->skb->len; 4046 total_tx_bytes += skb->len;
3876 } 4047 }
3877 e1000_unmap_and_free_tx_resource(adapter, buffer_info); 4048 e1000_unmap_and_free_tx_resource(adapter, buffer_info);
3878 tx_desc->upper.data = 0; 4049 tx_desc->upper.data = 0;
@@ -4094,8 +4265,7 @@ e1000_clean_rx_irq(struct e1000_adapter *adapter,
4094 /* code added for copybreak, this should improve 4265 /* code added for copybreak, this should improve
4095 * performance for small packets with large amounts 4266 * performance for small packets with large amounts
4096 * of reassembly being done in the stack */ 4267 * of reassembly being done in the stack */
4097#define E1000_CB_LENGTH 256 4268 if (length < copybreak) {
4098 if (length < E1000_CB_LENGTH) {
4099 struct sk_buff *new_skb = 4269 struct sk_buff *new_skb =
4100 netdev_alloc_skb(netdev, length + NET_IP_ALIGN); 4270 netdev_alloc_skb(netdev, length + NET_IP_ALIGN);
4101 if (new_skb) { 4271 if (new_skb) {
@@ -4253,7 +4423,7 @@ e1000_clean_rx_irq_ps(struct e1000_adapter *adapter,
4253 4423
4254 /* page alloc/put takes too long and effects small packet 4424 /* page alloc/put takes too long and effects small packet
4255 * throughput, so unsplit small packets and save the alloc/put*/ 4425 * throughput, so unsplit small packets and save the alloc/put*/
4256 if (l1 && ((length + l1) <= adapter->rx_ps_bsize0)) { 4426 if (l1 && (l1 <= copybreak) && ((length + l1) <= adapter->rx_ps_bsize0)) {
4257 u8 *vaddr; 4427 u8 *vaddr;
4258 /* there is no documentation about how to call 4428 /* there is no documentation about how to call
4259 * kmap_atomic, so we can't hold the mapping 4429 * kmap_atomic, so we can't hold the mapping
@@ -4998,7 +5168,7 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
4998{ 5168{
4999 struct net_device *netdev = pci_get_drvdata(pdev); 5169 struct net_device *netdev = pci_get_drvdata(pdev);
5000 struct e1000_adapter *adapter = netdev_priv(netdev); 5170 struct e1000_adapter *adapter = netdev_priv(netdev);
5001 uint32_t ctrl, ctrl_ext, rctl, manc, status; 5171 uint32_t ctrl, ctrl_ext, rctl, status;
5002 uint32_t wufc = adapter->wol; 5172 uint32_t wufc = adapter->wol;
5003#ifdef CONFIG_PM 5173#ifdef CONFIG_PM
5004 int retval = 0; 5174 int retval = 0;
@@ -5067,16 +5237,12 @@ e1000_suspend(struct pci_dev *pdev, pm_message_t state)
5067 pci_enable_wake(pdev, PCI_D3cold, 0); 5237 pci_enable_wake(pdev, PCI_D3cold, 0);
5068 } 5238 }
5069 5239
5070 if (adapter->hw.mac_type >= e1000_82540 && 5240 e1000_release_manageability(adapter);
5071 adapter->hw.mac_type < e1000_82571 && 5241
5072 adapter->hw.media_type == e1000_media_type_copper) { 5242 /* make sure adapter isn't asleep if manageability is enabled */
5073 manc = E1000_READ_REG(&adapter->hw, MANC); 5243 if (adapter->en_mng_pt) {
5074 if (manc & E1000_MANC_SMBUS_EN) { 5244 pci_enable_wake(pdev, PCI_D3hot, 1);
5075 manc |= E1000_MANC_ARP_EN; 5245 pci_enable_wake(pdev, PCI_D3cold, 1);
5076 E1000_WRITE_REG(&adapter->hw, MANC, manc);
5077 pci_enable_wake(pdev, PCI_D3hot, 1);
5078 pci_enable_wake(pdev, PCI_D3cold, 1);
5079 }
5080 } 5246 }
5081 5247
5082 if (adapter->hw.phy_type == e1000_phy_igp_3) 5248 if (adapter->hw.phy_type == e1000_phy_igp_3)
@@ -5102,7 +5268,7 @@ e1000_resume(struct pci_dev *pdev)
5102{ 5268{
5103 struct net_device *netdev = pci_get_drvdata(pdev); 5269 struct net_device *netdev = pci_get_drvdata(pdev);
5104 struct e1000_adapter *adapter = netdev_priv(netdev); 5270 struct e1000_adapter *adapter = netdev_priv(netdev);
5105 uint32_t manc, err; 5271 uint32_t err;
5106 5272
5107 pci_set_power_state(pdev, PCI_D0); 5273 pci_set_power_state(pdev, PCI_D0);
5108 e1000_pci_restore_state(adapter); 5274 e1000_pci_restore_state(adapter);
@@ -5122,19 +5288,13 @@ e1000_resume(struct pci_dev *pdev)
5122 e1000_reset(adapter); 5288 e1000_reset(adapter);
5123 E1000_WRITE_REG(&adapter->hw, WUS, ~0); 5289 E1000_WRITE_REG(&adapter->hw, WUS, ~0);
5124 5290
5291 e1000_init_manageability(adapter);
5292
5125 if (netif_running(netdev)) 5293 if (netif_running(netdev))
5126 e1000_up(adapter); 5294 e1000_up(adapter);
5127 5295
5128 netif_device_attach(netdev); 5296 netif_device_attach(netdev);
5129 5297
5130 if (adapter->hw.mac_type >= e1000_82540 &&
5131 adapter->hw.mac_type < e1000_82571 &&
5132 adapter->hw.media_type == e1000_media_type_copper) {
5133 manc = E1000_READ_REG(&adapter->hw, MANC);
5134 manc &= ~(E1000_MANC_ARP_EN);
5135 E1000_WRITE_REG(&adapter->hw, MANC, manc);
5136 }
5137
5138 /* If the controller is 82573 and f/w is AMT, do not set 5298 /* If the controller is 82573 and f/w is AMT, do not set
5139 * DRV_LOAD until the interface is up. For all other cases, 5299 * DRV_LOAD until the interface is up. For all other cases,
5140 * let the f/w know that the h/w is now under the control 5300 * let the f/w know that the h/w is now under the control
@@ -5235,7 +5395,8 @@ static void e1000_io_resume(struct pci_dev *pdev)
5235{ 5395{
5236 struct net_device *netdev = pci_get_drvdata(pdev); 5396 struct net_device *netdev = pci_get_drvdata(pdev);
5237 struct e1000_adapter *adapter = netdev->priv; 5397 struct e1000_adapter *adapter = netdev->priv;
5238 uint32_t manc, swsm; 5398
5399 e1000_init_manageability(adapter);
5239 5400
5240 if (netif_running(netdev)) { 5401 if (netif_running(netdev)) {
5241 if (e1000_up(adapter)) { 5402 if (e1000_up(adapter)) {
@@ -5246,26 +5407,14 @@ static void e1000_io_resume(struct pci_dev *pdev)
5246 5407
5247 netif_device_attach(netdev); 5408 netif_device_attach(netdev);
5248 5409
5249 if (adapter->hw.mac_type >= e1000_82540 && 5410 /* If the controller is 82573 and f/w is AMT, do not set
5250 adapter->hw.mac_type < e1000_82571 && 5411 * DRV_LOAD until the interface is up. For all other cases,
5251 adapter->hw.media_type == e1000_media_type_copper) { 5412 * let the f/w know that the h/w is now under the control
5252 manc = E1000_READ_REG(&adapter->hw, MANC); 5413 * of the driver. */
5253 manc &= ~(E1000_MANC_ARP_EN); 5414 if (adapter->hw.mac_type != e1000_82573 ||
5254 E1000_WRITE_REG(&adapter->hw, MANC, manc); 5415 !e1000_check_mng_mode(&adapter->hw))
5255 } 5416 e1000_get_hw_control(adapter);
5256
5257 switch (adapter->hw.mac_type) {
5258 case e1000_82573:
5259 swsm = E1000_READ_REG(&adapter->hw, SWSM);
5260 E1000_WRITE_REG(&adapter->hw, SWSM,
5261 swsm | E1000_SWSM_DRV_LOAD);
5262 break;
5263 default:
5264 break;
5265 }
5266 5417
5267 if (netif_running(netdev))
5268 mod_timer(&adapter->watchdog_timer, jiffies);
5269} 5418}
5270 5419
5271/* e1000_main.c */ 5420/* e1000_main.c */
diff --git a/drivers/net/e1000/e1000_param.c b/drivers/net/e1000/e1000_param.c
index cbfcd7f2889f..cf2a279307e1 100644
--- a/drivers/net/e1000/e1000_param.c
+++ b/drivers/net/e1000/e1000_param.c
@@ -487,7 +487,9 @@ e1000_check_options(struct e1000_adapter *adapter)
487 e1000_validate_option(&adapter->itr, &opt, 487 e1000_validate_option(&adapter->itr, &opt,
488 adapter); 488 adapter);
489 /* save the setting, because the dynamic bits change itr */ 489 /* save the setting, because the dynamic bits change itr */
490 adapter->itr_setting = adapter->itr; 490 /* clear the lower two bits because they are
491 * used as control */
492 adapter->itr_setting = adapter->itr & ~3;
491 break; 493 break;
492 } 494 }
493 } else { 495 } else {
diff --git a/drivers/net/forcedeth.c b/drivers/net/forcedeth.c
index 439f41338291..2f48fe9a29a7 100644
--- a/drivers/net/forcedeth.c
+++ b/drivers/net/forcedeth.c
@@ -3,8 +3,7 @@
3 * 3 *
4 * Note: This driver is a cleanroom reimplementation based on reverse 4 * Note: This driver is a cleanroom reimplementation based on reverse
5 * engineered documentation written by Carl-Daniel Hailfinger 5 * engineered documentation written by Carl-Daniel Hailfinger
6 * and Andrew de Quincey. It's neither supported nor endorsed 6 * and Andrew de Quincey.
7 * by NVIDIA Corp. Use at your own risk.
8 * 7 *
9 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered 8 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
10 * trademarks of NVIDIA Corporation in the United States and other 9 * trademarks of NVIDIA Corporation in the United States and other
@@ -14,7 +13,7 @@
14 * Copyright (C) 2004 Andrew de Quincey (wol support) 13 * Copyright (C) 2004 Andrew de Quincey (wol support)
15 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane 14 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
16 * IRQ rate fixes, bigendian fixes, cleanups, verification) 15 * IRQ rate fixes, bigendian fixes, cleanups, verification)
17 * Copyright (c) 2004 NVIDIA Corporation 16 * Copyright (c) 2004,5,6 NVIDIA Corporation
18 * 17 *
19 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
@@ -2576,14 +2575,15 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
2576 int pkts, limit = min(*budget, dev->quota); 2575 int pkts, limit = min(*budget, dev->quota);
2577 struct fe_priv *np = netdev_priv(dev); 2576 struct fe_priv *np = netdev_priv(dev);
2578 u8 __iomem *base = get_hwbase(dev); 2577 u8 __iomem *base = get_hwbase(dev);
2578 unsigned long flags;
2579 2579
2580 pkts = nv_rx_process(dev, limit); 2580 pkts = nv_rx_process(dev, limit);
2581 2581
2582 if (nv_alloc_rx(dev)) { 2582 if (nv_alloc_rx(dev)) {
2583 spin_lock_irq(&np->lock); 2583 spin_lock_irqsave(&np->lock, flags);
2584 if (!np->in_shutdown) 2584 if (!np->in_shutdown)
2585 mod_timer(&np->oom_kick, jiffies + OOM_REFILL); 2585 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2586 spin_unlock_irq(&np->lock); 2586 spin_unlock_irqrestore(&np->lock, flags);
2587 } 2587 }
2588 2588
2589 if (pkts < limit) { 2589 if (pkts < limit) {
@@ -2591,13 +2591,15 @@ static int nv_napi_poll(struct net_device *dev, int *budget)
2591 netif_rx_complete(dev); 2591 netif_rx_complete(dev);
2592 2592
2593 /* re-enable receive interrupts */ 2593 /* re-enable receive interrupts */
2594 spin_lock_irq(&np->lock); 2594 spin_lock_irqsave(&np->lock, flags);
2595
2595 np->irqmask |= NVREG_IRQ_RX_ALL; 2596 np->irqmask |= NVREG_IRQ_RX_ALL;
2596 if (np->msi_flags & NV_MSI_X_ENABLED) 2597 if (np->msi_flags & NV_MSI_X_ENABLED)
2597 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); 2598 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2598 else 2599 else
2599 writel(np->irqmask, base + NvRegIrqMask); 2600 writel(np->irqmask, base + NvRegIrqMask);
2600 spin_unlock_irq(&np->lock); 2601
2602 spin_unlock_irqrestore(&np->lock, flags);
2601 return 0; 2603 return 0;
2602 } else { 2604 } else {
2603 /* used up our quantum, so reschedule */ 2605 /* used up our quantum, so reschedule */
diff --git a/drivers/net/ibm_emac/ibm_emac_phy.c b/drivers/net/ibm_emac/ibm_emac_phy.c
index 4a97024061e5..9074f76ee2bf 100644
--- a/drivers/net/ibm_emac/ibm_emac_phy.c
+++ b/drivers/net/ibm_emac/ibm_emac_phy.c
@@ -309,7 +309,7 @@ int mii_phy_probe(struct mii_phy *phy, int address)
309{ 309{
310 struct mii_phy_def *def; 310 struct mii_phy_def *def;
311 int i; 311 int i;
312 u32 id; 312 int id;
313 313
314 phy->autoneg = AUTONEG_DISABLE; 314 phy->autoneg = AUTONEG_DISABLE;
315 phy->advertising = 0; 315 phy->advertising = 0;
@@ -324,6 +324,8 @@ int mii_phy_probe(struct mii_phy *phy, int address)
324 324
325 /* Read ID and find matching entry */ 325 /* Read ID and find matching entry */
326 id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2); 326 id = (phy_read(phy, MII_PHYSID1) << 16) | phy_read(phy, MII_PHYSID2);
327 if (id < 0)
328 return -ENODEV;
327 for (i = 0; (def = mii_phy_table[i]) != NULL; i++) 329 for (i = 0; (def = mii_phy_table[i]) != NULL; i++)
328 if ((id & def->phy_id_mask) == def->phy_id) 330 if ((id & def->phy_id_mask) == def->phy_id)
329 break; 331 break;
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index d6f4f185bf37..2194b567239f 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -73,7 +73,7 @@
73#include <asm/abs_addr.h> 73#include <asm/abs_addr.h>
74#include <asm/iseries/mf.h> 74#include <asm/iseries/mf.h>
75#include <asm/uaccess.h> 75#include <asm/uaccess.h>
76 76#include <asm/firmware.h>
77#include <asm/iseries/hv_lp_config.h> 77#include <asm/iseries/hv_lp_config.h>
78#include <asm/iseries/hv_types.h> 78#include <asm/iseries/hv_types.h>
79#include <asm/iseries/hv_lp_event.h> 79#include <asm/iseries/hv_lp_event.h>
@@ -1668,7 +1668,7 @@ static struct vio_driver veth_driver = {
1668 * Module initialization/cleanup 1668 * Module initialization/cleanup
1669 */ 1669 */
1670 1670
1671void __exit veth_module_cleanup(void) 1671static void __exit veth_module_cleanup(void)
1672{ 1672{
1673 int i; 1673 int i;
1674 struct veth_lpar_connection *cnx; 1674 struct veth_lpar_connection *cnx;
@@ -1697,11 +1697,14 @@ void __exit veth_module_cleanup(void)
1697} 1697}
1698module_exit(veth_module_cleanup); 1698module_exit(veth_module_cleanup);
1699 1699
1700int __init veth_module_init(void) 1700static int __init veth_module_init(void)
1701{ 1701{
1702 int i; 1702 int i;
1703 int rc; 1703 int rc;
1704 1704
1705 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1706 return -ENODEV;
1707
1705 this_lp = HvLpConfig_getLpIndex_outline(); 1708 this_lp = HvLpConfig_getLpIndex_outline();
1706 1709
1707 for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) { 1710 for (i = 0; i < HVMAXARCHITECTEDLPS; ++i) {
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 94ac168be593..07cf574197e5 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -199,8 +199,6 @@ struct myri10ge_priv {
199 unsigned long serial_number; 199 unsigned long serial_number;
200 int vendor_specific_offset; 200 int vendor_specific_offset;
201 int fw_multicast_support; 201 int fw_multicast_support;
202 u32 devctl;
203 u16 msi_flags;
204 u32 read_dma; 202 u32 read_dma;
205 u32 write_dma; 203 u32 write_dma;
206 u32 read_write_dma; 204 u32 read_write_dma;
@@ -228,7 +226,7 @@ module_param(myri10ge_small_bytes, int, S_IRUGO | S_IWUSR);
228MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets\n"); 226MODULE_PARM_DESC(myri10ge_small_bytes, "Threshold of small packets\n");
229 227
230static int myri10ge_msi = 1; /* enable msi by default */ 228static int myri10ge_msi = 1; /* enable msi by default */
231module_param(myri10ge_msi, int, S_IRUGO); 229module_param(myri10ge_msi, int, S_IRUGO | S_IWUSR);
232MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts\n"); 230MODULE_PARM_DESC(myri10ge_msi, "Enable Message Signalled Interrupts\n");
233 231
234static int myri10ge_intr_coal_delay = 25; 232static int myri10ge_intr_coal_delay = 25;
@@ -721,12 +719,10 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
721 status |= 719 status |=
722 myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0); 720 myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_ACK_OFFSET, &cmd, 0);
723 mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0); 721 mgp->irq_claim = (__iomem __be32 *) (mgp->sram + cmd.data0);
724 if (!mgp->msi_enabled) { 722 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET,
725 status |= myri10ge_send_cmd 723 &cmd, 0);
726 (mgp, MXGEFW_CMD_GET_IRQ_DEASSERT_OFFSET, &cmd, 0); 724 mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
727 mgp->irq_deassert = (__iomem __be32 *) (mgp->sram + cmd.data0);
728 725
729 }
730 status |= myri10ge_send_cmd 726 status |= myri10ge_send_cmd
731 (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0); 727 (mgp, MXGEFW_CMD_GET_INTR_COAL_DELAY_OFFSET, &cmd, 0);
732 mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0); 728 mgp->intr_coal_delay_ptr = (__iomem __be32 *) (mgp->sram + cmd.data0);
@@ -1619,6 +1615,41 @@ static void myri10ge_free_rings(struct net_device *dev)
1619 mgp->tx.req_list = NULL; 1615 mgp->tx.req_list = NULL;
1620} 1616}
1621 1617
1618static int myri10ge_request_irq(struct myri10ge_priv *mgp)
1619{
1620 struct pci_dev *pdev = mgp->pdev;
1621 int status;
1622
1623 if (myri10ge_msi) {
1624 status = pci_enable_msi(pdev);
1625 if (status != 0)
1626 dev_err(&pdev->dev,
1627 "Error %d setting up MSI; falling back to xPIC\n",
1628 status);
1629 else
1630 mgp->msi_enabled = 1;
1631 } else {
1632 mgp->msi_enabled = 0;
1633 }
1634 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
1635 mgp->dev->name, mgp);
1636 if (status != 0) {
1637 dev_err(&pdev->dev, "failed to allocate IRQ\n");
1638 if (mgp->msi_enabled)
1639 pci_disable_msi(pdev);
1640 }
1641 return status;
1642}
1643
1644static void myri10ge_free_irq(struct myri10ge_priv *mgp)
1645{
1646 struct pci_dev *pdev = mgp->pdev;
1647
1648 free_irq(pdev->irq, mgp);
1649 if (mgp->msi_enabled)
1650 pci_disable_msi(pdev);
1651}
1652
1622static int myri10ge_open(struct net_device *dev) 1653static int myri10ge_open(struct net_device *dev)
1623{ 1654{
1624 struct myri10ge_priv *mgp; 1655 struct myri10ge_priv *mgp;
@@ -1634,10 +1665,13 @@ static int myri10ge_open(struct net_device *dev)
1634 status = myri10ge_reset(mgp); 1665 status = myri10ge_reset(mgp);
1635 if (status != 0) { 1666 if (status != 0) {
1636 printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name); 1667 printk(KERN_ERR "myri10ge: %s: failed reset\n", dev->name);
1637 mgp->running = MYRI10GE_ETH_STOPPED; 1668 goto abort_with_nothing;
1638 return -ENXIO;
1639 } 1669 }
1640 1670
1671 status = myri10ge_request_irq(mgp);
1672 if (status != 0)
1673 goto abort_with_nothing;
1674
1641 /* decide what small buffer size to use. For good TCP rx 1675 /* decide what small buffer size to use. For good TCP rx
1642 * performance, it is important to not receive 1514 byte 1676 * performance, it is important to not receive 1514 byte
1643 * frames into jumbo buffers, as it confuses the socket buffer 1677 * frames into jumbo buffers, as it confuses the socket buffer
@@ -1677,7 +1711,7 @@ static int myri10ge_open(struct net_device *dev)
1677 "myri10ge: %s: failed to get ring sizes or locations\n", 1711 "myri10ge: %s: failed to get ring sizes or locations\n",
1678 dev->name); 1712 dev->name);
1679 mgp->running = MYRI10GE_ETH_STOPPED; 1713 mgp->running = MYRI10GE_ETH_STOPPED;
1680 return -ENXIO; 1714 goto abort_with_irq;
1681 } 1715 }
1682 1716
1683 if (mgp->mtrr >= 0) { 1717 if (mgp->mtrr >= 0) {
@@ -1708,7 +1742,7 @@ static int myri10ge_open(struct net_device *dev)
1708 1742
1709 status = myri10ge_allocate_rings(dev); 1743 status = myri10ge_allocate_rings(dev);
1710 if (status != 0) 1744 if (status != 0)
1711 goto abort_with_nothing; 1745 goto abort_with_irq;
1712 1746
1713 /* now give firmware buffers sizes, and MTU */ 1747 /* now give firmware buffers sizes, and MTU */
1714 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN; 1748 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
@@ -1771,6 +1805,9 @@ static int myri10ge_open(struct net_device *dev)
1771abort_with_rings: 1805abort_with_rings:
1772 myri10ge_free_rings(dev); 1806 myri10ge_free_rings(dev);
1773 1807
1808abort_with_irq:
1809 myri10ge_free_irq(mgp);
1810
1774abort_with_nothing: 1811abort_with_nothing:
1775 mgp->running = MYRI10GE_ETH_STOPPED; 1812 mgp->running = MYRI10GE_ETH_STOPPED;
1776 return -ENOMEM; 1813 return -ENOMEM;
@@ -1807,7 +1844,7 @@ static int myri10ge_close(struct net_device *dev)
1807 printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name); 1844 printk(KERN_ERR "myri10ge: %s never got down irq\n", dev->name);
1808 1845
1809 netif_tx_disable(dev); 1846 netif_tx_disable(dev);
1810 1847 myri10ge_free_irq(mgp);
1811 myri10ge_free_rings(dev); 1848 myri10ge_free_rings(dev);
1812 1849
1813 mgp->running = MYRI10GE_ETH_STOPPED; 1850 mgp->running = MYRI10GE_ETH_STOPPED;
@@ -2481,34 +2518,6 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2481 } 2518 }
2482} 2519}
2483 2520
2484static void myri10ge_save_state(struct myri10ge_priv *mgp)
2485{
2486 struct pci_dev *pdev = mgp->pdev;
2487 int cap;
2488
2489 pci_save_state(pdev);
2490 /* now save PCIe and MSI state that Linux will not
2491 * save for us */
2492 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2493 pci_read_config_dword(pdev, cap + PCI_EXP_DEVCTL, &mgp->devctl);
2494 cap = pci_find_capability(pdev, PCI_CAP_ID_MSI);
2495 pci_read_config_word(pdev, cap + PCI_MSI_FLAGS, &mgp->msi_flags);
2496}
2497
2498static void myri10ge_restore_state(struct myri10ge_priv *mgp)
2499{
2500 struct pci_dev *pdev = mgp->pdev;
2501 int cap;
2502
2503 /* restore PCIe and MSI state that linux will not */
2504 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2505 pci_write_config_dword(pdev, cap + PCI_CAP_ID_EXP, mgp->devctl);
2506 cap = pci_find_capability(pdev, PCI_CAP_ID_MSI);
2507 pci_write_config_word(pdev, cap + PCI_MSI_FLAGS, mgp->msi_flags);
2508
2509 pci_restore_state(pdev);
2510}
2511
2512#ifdef CONFIG_PM 2521#ifdef CONFIG_PM
2513 2522
2514static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state) 2523static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
@@ -2529,11 +2538,10 @@ static int myri10ge_suspend(struct pci_dev *pdev, pm_message_t state)
2529 rtnl_unlock(); 2538 rtnl_unlock();
2530 } 2539 }
2531 myri10ge_dummy_rdma(mgp, 0); 2540 myri10ge_dummy_rdma(mgp, 0);
2532 free_irq(pdev->irq, mgp); 2541 pci_save_state(pdev);
2533 myri10ge_save_state(mgp);
2534 pci_disable_device(pdev); 2542 pci_disable_device(pdev);
2535 pci_set_power_state(pdev, pci_choose_state(pdev, state)); 2543
2536 return 0; 2544 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
2537} 2545}
2538 2546
2539static int myri10ge_resume(struct pci_dev *pdev) 2547static int myri10ge_resume(struct pci_dev *pdev)
@@ -2555,34 +2563,33 @@ static int myri10ge_resume(struct pci_dev *pdev)
2555 mgp->dev->name); 2563 mgp->dev->name);
2556 return -EIO; 2564 return -EIO;
2557 } 2565 }
2558 myri10ge_restore_state(mgp); 2566
2567 status = pci_restore_state(pdev);
2568 if (status)
2569 return status;
2559 2570
2560 status = pci_enable_device(pdev); 2571 status = pci_enable_device(pdev);
2561 if (status < 0) { 2572 if (status) {
2562 dev_err(&pdev->dev, "failed to enable device\n"); 2573 dev_err(&pdev->dev, "failed to enable device\n");
2563 return -EIO; 2574 return status;
2564 } 2575 }
2565 2576
2566 pci_set_master(pdev); 2577 pci_set_master(pdev);
2567 2578
2568 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
2569 netdev->name, mgp);
2570 if (status != 0) {
2571 dev_err(&pdev->dev, "failed to allocate IRQ\n");
2572 goto abort_with_enabled;
2573 }
2574
2575 myri10ge_reset(mgp); 2579 myri10ge_reset(mgp);
2576 myri10ge_dummy_rdma(mgp, 1); 2580 myri10ge_dummy_rdma(mgp, 1);
2577 2581
2578 /* Save configuration space to be restored if the 2582 /* Save configuration space to be restored if the
2579 * nic resets due to a parity error */ 2583 * nic resets due to a parity error */
2580 myri10ge_save_state(mgp); 2584 pci_save_state(pdev);
2581 2585
2582 if (netif_running(netdev)) { 2586 if (netif_running(netdev)) {
2583 rtnl_lock(); 2587 rtnl_lock();
2584 myri10ge_open(netdev); 2588 status = myri10ge_open(netdev);
2585 rtnl_unlock(); 2589 rtnl_unlock();
2590 if (status != 0)
2591 goto abort_with_enabled;
2592
2586 } 2593 }
2587 netif_device_attach(netdev); 2594 netif_device_attach(netdev);
2588 2595
@@ -2640,7 +2647,11 @@ static void myri10ge_watchdog(struct work_struct *work)
2640 * when the driver was loaded, or the last time the 2647 * when the driver was loaded, or the last time the
2641 * nic was resumed from power saving mode. 2648 * nic was resumed from power saving mode.
2642 */ 2649 */
2643 myri10ge_restore_state(mgp); 2650 pci_restore_state(mgp->pdev);
2651
2652 /* save state again for accounting reasons */
2653 pci_save_state(mgp->pdev);
2654
2644 } else { 2655 } else {
2645 /* if we get back -1's from our slot, perhaps somebody 2656 /* if we get back -1's from our slot, perhaps somebody
2646 * powered off our card. Don't try to reset it in 2657 * powered off our card. Don't try to reset it in
@@ -2856,23 +2867,6 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2856 goto abort_with_firmware; 2867 goto abort_with_firmware;
2857 } 2868 }
2858 2869
2859 if (myri10ge_msi) {
2860 status = pci_enable_msi(pdev);
2861 if (status != 0)
2862 dev_err(&pdev->dev,
2863 "Error %d setting up MSI; falling back to xPIC\n",
2864 status);
2865 else
2866 mgp->msi_enabled = 1;
2867 }
2868
2869 status = request_irq(pdev->irq, myri10ge_intr, IRQF_SHARED,
2870 netdev->name, mgp);
2871 if (status != 0) {
2872 dev_err(&pdev->dev, "failed to allocate IRQ\n");
2873 goto abort_with_firmware;
2874 }
2875
2876 pci_set_drvdata(pdev, mgp); 2870 pci_set_drvdata(pdev, mgp);
2877 if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU) 2871 if ((myri10ge_initial_mtu + ETH_HLEN) > MYRI10GE_MAX_ETHER_MTU)
2878 myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; 2872 myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
@@ -2896,7 +2890,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2896 2890
2897 /* Save configuration space to be restored if the 2891 /* Save configuration space to be restored if the
2898 * nic resets due to a parity error */ 2892 * nic resets due to a parity error */
2899 myri10ge_save_state(mgp); 2893 pci_save_state(pdev);
2900 2894
2901 /* Setup the watchdog timer */ 2895 /* Setup the watchdog timer */
2902 setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer, 2896 setup_timer(&mgp->watchdog_timer, myri10ge_watchdog_timer,
@@ -2907,19 +2901,16 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2907 status = register_netdev(netdev); 2901 status = register_netdev(netdev);
2908 if (status != 0) { 2902 if (status != 0) {
2909 dev_err(&pdev->dev, "register_netdev failed: %d\n", status); 2903 dev_err(&pdev->dev, "register_netdev failed: %d\n", status);
2910 goto abort_with_irq; 2904 goto abort_with_state;
2911 } 2905 }
2912 dev_info(dev, "%s IRQ %d, tx bndry %d, fw %s, WC %s\n", 2906 dev_info(dev, "%d, tx bndry %d, fw %s, WC %s\n",
2913 (mgp->msi_enabled ? "MSI" : "xPIC"),
2914 pdev->irq, mgp->tx.boundary, mgp->fw_name, 2907 pdev->irq, mgp->tx.boundary, mgp->fw_name,
2915 (mgp->mtrr >= 0 ? "Enabled" : "Disabled")); 2908 (mgp->mtrr >= 0 ? "Enabled" : "Disabled"));
2916 2909
2917 return 0; 2910 return 0;
2918 2911
2919abort_with_irq: 2912abort_with_state:
2920 free_irq(pdev->irq, mgp); 2913 pci_restore_state(pdev);
2921 if (mgp->msi_enabled)
2922 pci_disable_msi(pdev);
2923 2914
2924abort_with_firmware: 2915abort_with_firmware:
2925 myri10ge_dummy_rdma(mgp, 0); 2916 myri10ge_dummy_rdma(mgp, 0);
@@ -2970,12 +2961,12 @@ static void myri10ge_remove(struct pci_dev *pdev)
2970 flush_scheduled_work(); 2961 flush_scheduled_work();
2971 netdev = mgp->dev; 2962 netdev = mgp->dev;
2972 unregister_netdev(netdev); 2963 unregister_netdev(netdev);
2973 free_irq(pdev->irq, mgp);
2974 if (mgp->msi_enabled)
2975 pci_disable_msi(pdev);
2976 2964
2977 myri10ge_dummy_rdma(mgp, 0); 2965 myri10ge_dummy_rdma(mgp, 0);
2978 2966
2967 /* avoid a memory leak */
2968 pci_restore_state(pdev);
2969
2979 bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry); 2970 bytes = myri10ge_max_intr_slots * sizeof(*mgp->rx_done.entry);
2980 dma_free_coherent(&pdev->dev, bytes, 2971 dma_free_coherent(&pdev->dev, bytes,
2981 mgp->rx_done.entry, mgp->rx_done.bus); 2972 mgp->rx_done.entry, mgp->rx_done.bus);
diff --git a/drivers/net/netxen/netxen_nic.h b/drivers/net/netxen/netxen_nic.h
index b5410bee5f21..6490acf05305 100644
--- a/drivers/net/netxen/netxen_nic.h
+++ b/drivers/net/netxen/netxen_nic.h
@@ -63,7 +63,7 @@
63 63
64#include "netxen_nic_hw.h" 64#include "netxen_nic_hw.h"
65 65
66#define NETXEN_NIC_BUILD_NO "1" 66#define NETXEN_NIC_BUILD_NO "4"
67#define _NETXEN_NIC_LINUX_MAJOR 3 67#define _NETXEN_NIC_LINUX_MAJOR 3
68#define _NETXEN_NIC_LINUX_MINOR 3 68#define _NETXEN_NIC_LINUX_MINOR 3
69#define _NETXEN_NIC_LINUX_SUBVERSION 2 69#define _NETXEN_NIC_LINUX_SUBVERSION 2
@@ -137,7 +137,7 @@ extern struct workqueue_struct *netxen_workq;
137#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START 137#define THIRD_PAGE_GROUP_SIZE THIRD_PAGE_GROUP_END - THIRD_PAGE_GROUP_START
138 138
139#define MAX_RX_BUFFER_LENGTH 1760 139#define MAX_RX_BUFFER_LENGTH 1760
140#define MAX_RX_JUMBO_BUFFER_LENGTH 9046 140#define MAX_RX_JUMBO_BUFFER_LENGTH 8062
141#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512) 141#define MAX_RX_LRO_BUFFER_LENGTH ((48*1024)-512)
142#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2) 142#define RX_DMA_MAP_LEN (MAX_RX_BUFFER_LENGTH - 2)
143#define RX_JUMBO_DMA_MAP_LEN \ 143#define RX_JUMBO_DMA_MAP_LEN \
@@ -199,9 +199,9 @@ enum {
199 (RCV_DESC_NORMAL))) 199 (RCV_DESC_NORMAL)))
200 200
201#define MAX_CMD_DESCRIPTORS 1024 201#define MAX_CMD_DESCRIPTORS 1024
202#define MAX_RCV_DESCRIPTORS 32768 202#define MAX_RCV_DESCRIPTORS 16384
203#define MAX_JUMBO_RCV_DESCRIPTORS 4096 203#define MAX_JUMBO_RCV_DESCRIPTORS 1024
204#define MAX_LRO_RCV_DESCRIPTORS 2048 204#define MAX_LRO_RCV_DESCRIPTORS 64
205#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS 205#define MAX_RCVSTATUS_DESCRIPTORS MAX_RCV_DESCRIPTORS
206#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS 206#define MAX_JUMBO_RCV_DESC MAX_JUMBO_RCV_DESCRIPTORS
207#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS 207#define MAX_RCV_DESC MAX_RCV_DESCRIPTORS
@@ -852,8 +852,6 @@ struct netxen_adapter {
852 spinlock_t tx_lock; 852 spinlock_t tx_lock;
853 spinlock_t lock; 853 spinlock_t lock;
854 struct work_struct watchdog_task; 854 struct work_struct watchdog_task;
855 struct work_struct tx_timeout_task;
856 struct net_device *netdev;
857 struct timer_list watchdog_timer; 855 struct timer_list watchdog_timer;
858 856
859 u32 curr_window; 857 u32 curr_window;
@@ -887,7 +885,6 @@ struct netxen_adapter {
887 struct netxen_recv_context recv_ctx[MAX_RCV_CTX]; 885 struct netxen_recv_context recv_ctx[MAX_RCV_CTX];
888 886
889 int is_up; 887 int is_up;
890 int number;
891 struct netxen_dummy_dma dummy_dma; 888 struct netxen_dummy_dma dummy_dma;
892 889
893 /* Context interface shared between card and host */ 890 /* Context interface shared between card and host */
@@ -950,6 +947,7 @@ struct netxen_port {
950 struct pci_dev *pdev; 947 struct pci_dev *pdev;
951 struct net_device_stats net_stats; 948 struct net_device_stats net_stats;
952 struct netxen_port_stats stats; 949 struct netxen_port_stats stats;
950 struct work_struct tx_timeout_task;
953}; 951};
954 952
955#define PCI_OFFSET_FIRST_RANGE(adapter, off) \ 953#define PCI_OFFSET_FIRST_RANGE(adapter, off) \
@@ -1027,14 +1025,6 @@ int netxen_nic_hw_read_wx(struct netxen_adapter *adapter, u64 off, void *data,
1027 int len); 1025 int len);
1028int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data, 1026int netxen_nic_hw_write_wx(struct netxen_adapter *adapter, u64 off, void *data,
1029 int len); 1027 int len);
1030int netxen_nic_hw_read_ioctl(struct netxen_adapter *adapter, u64 off,
1031 void *data, int len);
1032int netxen_nic_hw_write_ioctl(struct netxen_adapter *adapter, u64 off,
1033 void *data, int len);
1034int netxen_nic_pci_mem_write_ioctl(struct netxen_adapter *adapter,
1035 u64 off, void *data, int size);
1036int netxen_nic_pci_mem_read_ioctl(struct netxen_adapter *adapter,
1037 u64 off, void *data, int size);
1038void netxen_crb_writelit_adapter(struct netxen_adapter *adapter, 1028void netxen_crb_writelit_adapter(struct netxen_adapter *adapter,
1039 unsigned long off, int data); 1029 unsigned long off, int data);
1040 1030
@@ -1067,9 +1057,6 @@ void netxen_tso_check(struct netxen_adapter *adapter,
1067 struct cmd_desc_type0 *desc, struct sk_buff *skb); 1057 struct cmd_desc_type0 *desc, struct sk_buff *skb);
1068int netxen_nic_hw_resources(struct netxen_adapter *adapter); 1058int netxen_nic_hw_resources(struct netxen_adapter *adapter);
1069void netxen_nic_clear_stats(struct netxen_adapter *adapter); 1059void netxen_nic_clear_stats(struct netxen_adapter *adapter);
1070int
1071netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
1072 struct netxen_port *port);
1073int netxen_nic_rx_has_work(struct netxen_adapter *adapter); 1060int netxen_nic_rx_has_work(struct netxen_adapter *adapter);
1074int netxen_nic_tx_has_work(struct netxen_adapter *adapter); 1061int netxen_nic_tx_has_work(struct netxen_adapter *adapter);
1075void netxen_watchdog_task(struct work_struct *work); 1062void netxen_watchdog_task(struct work_struct *work);
diff --git a/drivers/net/netxen/netxen_nic_ethtool.c b/drivers/net/netxen/netxen_nic_ethtool.c
index 2ab4885cc950..34044616b3c8 100644
--- a/drivers/net/netxen/netxen_nic_ethtool.c
+++ b/drivers/net/netxen/netxen_nic_ethtool.c
@@ -42,7 +42,6 @@
42#include "netxen_nic_hw.h" 42#include "netxen_nic_hw.h"
43#include "netxen_nic.h" 43#include "netxen_nic.h"
44#include "netxen_nic_phan_reg.h" 44#include "netxen_nic_phan_reg.h"
45#include "netxen_nic_ioctl.h"
46 45
47struct netxen_nic_stats { 46struct netxen_nic_stats {
48 char stat_string[ETH_GSTRING_LEN]; 47 char stat_string[ETH_GSTRING_LEN];
@@ -79,8 +78,7 @@ static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
79 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)}, 78 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
80}; 79};
81 80
82#define NETXEN_NIC_STATS_LEN \ 81#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
83 sizeof(netxen_nic_gstrings_stats) / sizeof(struct netxen_nic_stats)
84 82
85static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = { 83static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
86 "Register_Test_offline", "EEPROM_Test_offline", 84 "Register_Test_offline", "EEPROM_Test_offline",
@@ -711,7 +709,6 @@ netxen_nic_get_ethtool_stats(struct net_device *dev,
711 (netxen_nic_gstrings_stats[index].sizeof_stat == 709 (netxen_nic_gstrings_stats[index].sizeof_stat ==
712 sizeof(u64)) ? *(u64 *) p : *(u32 *) p; 710 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
713 } 711 }
714
715} 712}
716 713
717struct ethtool_ops netxen_nic_ethtool_ops = { 714struct ethtool_ops netxen_nic_ethtool_ops = {
diff --git a/drivers/net/netxen/netxen_nic_hw.c b/drivers/net/netxen/netxen_nic_hw.c
index 9147b6048dfb..c0c31d1914a7 100644
--- a/drivers/net/netxen/netxen_nic_hw.c
+++ b/drivers/net/netxen/netxen_nic_hw.c
@@ -376,7 +376,7 @@ void netxen_tso_check(struct netxen_adapter *adapter,
376 ((skb->nh.iph)->ihl * sizeof(u32)) + 376 ((skb->nh.iph)->ihl * sizeof(u32)) +
377 ((skb->h.th)->doff * sizeof(u32)); 377 ((skb->h.th)->doff * sizeof(u32));
378 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO); 378 netxen_set_cmd_desc_opcode(desc, TX_TCP_LSO);
379 } else if (skb->ip_summed == CHECKSUM_COMPLETE) { 379 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
380 if (skb->nh.iph->protocol == IPPROTO_TCP) { 380 if (skb->nh.iph->protocol == IPPROTO_TCP) {
381 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT); 381 netxen_set_cmd_desc_opcode(desc, TX_TCP_PKT);
382 } else if (skb->nh.iph->protocol == IPPROTO_UDP) { 382 } else if (skb->nh.iph->protocol == IPPROTO_UDP) {
@@ -997,297 +997,3 @@ void netxen_nic_flash_print(struct netxen_adapter *adapter)
997 fw_major, fw_minor); 997 fw_major, fw_minor);
998} 998}
999 999
1000int netxen_crb_read_val(struct netxen_adapter *adapter, unsigned long off)
1001{
1002 int data;
1003 netxen_nic_hw_read_wx(adapter, off, &data, 4);
1004 return data;
1005}
1006
1007int netxen_nic_hw_write_ioctl(struct netxen_adapter *adapter, u64 off,
1008 void *data, int len)
1009{
1010 void *addr;
1011 u64 offset = off;
1012 u8 *mem_ptr = NULL;
1013 unsigned long mem_base;
1014 unsigned long mem_page;
1015
1016 if (ADDR_IN_WINDOW1(off)) {
1017 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1018 if (!addr) {
1019 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1020 offset = NETXEN_CRB_NORMAL(off);
1021 mem_page = offset & PAGE_MASK;
1022 if (mem_page != ((offset + len - 1) & PAGE_MASK))
1023 mem_ptr =
1024 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1025 else
1026 mem_ptr =
1027 ioremap(mem_base + mem_page, PAGE_SIZE);
1028 if (mem_ptr == 0UL) {
1029 return 1;
1030 }
1031 addr = mem_ptr;
1032 addr += offset & (PAGE_SIZE - 1);
1033 }
1034 } else {
1035 addr = pci_base_offset(adapter, off);
1036 if (!addr) {
1037 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1038 mem_page = off & PAGE_MASK;
1039 if (mem_page != ((off + len - 1) & PAGE_MASK))
1040 mem_ptr =
1041 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1042 else
1043 mem_ptr =
1044 ioremap(mem_base + mem_page, PAGE_SIZE);
1045 if (mem_ptr == 0UL) {
1046 return 1;
1047 }
1048 addr = mem_ptr;
1049 addr += off & (PAGE_SIZE - 1);
1050 }
1051 netxen_nic_pci_change_crbwindow(adapter, 0);
1052 }
1053 switch (len) {
1054 case 1:
1055 writeb(*(u8 *) data, addr);
1056 break;
1057 case 2:
1058 writew(*(u16 *) data, addr);
1059 break;
1060 case 4:
1061 writel(*(u32 *) data, addr);
1062 break;
1063 case 8:
1064 writeq(*(u64 *) data, addr);
1065 break;
1066 default:
1067 DPRINTK(INFO,
1068 "writing data %lx to offset %llx, num words=%d\n",
1069 *(unsigned long *)data, off, (len >> 3));
1070
1071 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
1072 (len >> 3));
1073 break;
1074 }
1075
1076 if (!ADDR_IN_WINDOW1(off))
1077 netxen_nic_pci_change_crbwindow(adapter, 1);
1078 if (mem_ptr)
1079 iounmap(mem_ptr);
1080 return 0;
1081}
1082
1083int netxen_nic_hw_read_ioctl(struct netxen_adapter *adapter, u64 off,
1084 void *data, int len)
1085{
1086 void *addr;
1087 u64 offset;
1088 u8 *mem_ptr = NULL;
1089 unsigned long mem_base;
1090 unsigned long mem_page;
1091
1092 if (ADDR_IN_WINDOW1(off)) {
1093 addr = NETXEN_CRB_NORMALIZE(adapter, off);
1094 if (!addr) {
1095 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1096 offset = NETXEN_CRB_NORMAL(off);
1097 mem_page = offset & PAGE_MASK;
1098 if (mem_page != ((offset + len - 1) & PAGE_MASK))
1099 mem_ptr =
1100 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1101 else
1102 mem_ptr =
1103 ioremap(mem_base + mem_page, PAGE_SIZE);
1104 if (mem_ptr == 0UL) {
1105 *(u8 *) data = 0;
1106 return 1;
1107 }
1108 addr = mem_ptr;
1109 addr += offset & (PAGE_SIZE - 1);
1110 }
1111 } else {
1112 addr = pci_base_offset(adapter, off);
1113 if (!addr) {
1114 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1115 mem_page = off & PAGE_MASK;
1116 if (mem_page != ((off + len - 1) & PAGE_MASK))
1117 mem_ptr =
1118 ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1119 else
1120 mem_ptr =
1121 ioremap(mem_base + mem_page, PAGE_SIZE);
1122 if (mem_ptr == 0UL)
1123 return 1;
1124 addr = mem_ptr;
1125 addr += off & (PAGE_SIZE - 1);
1126 }
1127 netxen_nic_pci_change_crbwindow(adapter, 0);
1128 }
1129 switch (len) {
1130 case 1:
1131 *(u8 *) data = readb(addr);
1132 break;
1133 case 2:
1134 *(u16 *) data = readw(addr);
1135 break;
1136 case 4:
1137 *(u32 *) data = readl(addr);
1138 break;
1139 case 8:
1140 *(u64 *) data = readq(addr);
1141 break;
1142 default:
1143 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
1144 (len >> 3));
1145 break;
1146 }
1147 if (!ADDR_IN_WINDOW1(off))
1148 netxen_nic_pci_change_crbwindow(adapter, 1);
1149 if (mem_ptr)
1150 iounmap(mem_ptr);
1151 return 0;
1152}
1153
1154int netxen_nic_pci_mem_write_ioctl(struct netxen_adapter *adapter, u64 off,
1155 void *data, int size)
1156{
1157 void *addr;
1158 int ret = 0;
1159 u8 *mem_ptr = NULL;
1160 unsigned long mem_base;
1161 unsigned long mem_page;
1162
1163 if (data == NULL || off > (128 * 1024 * 1024)) {
1164 printk(KERN_ERR "%s: data: %p off:%llx\n",
1165 netxen_nic_driver_name, data, off);
1166 return 1;
1167 }
1168 off = netxen_nic_pci_set_window(adapter, off);
1169 /* Corner case : Malicious user tried to break the driver by reading
1170 last few bytes in ranges and tries to read further addresses.
1171 */
1172 if (!pci_base(adapter, off + size - 1) && pci_base(adapter, off)) {
1173 printk(KERN_ERR "%s: Invalid access to memory address range"
1174 " 0x%llx - 0x%llx\n", netxen_nic_driver_name, off,
1175 off + size);
1176 return 1;
1177 }
1178 addr = pci_base_offset(adapter, off);
1179 DPRINTK(INFO, "writing data %llx to offset %llx\n",
1180 *(unsigned long long *)data, off);
1181 if (!addr) {
1182 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1183 mem_page = off & PAGE_MASK;
1184 /* Map two pages whenever user tries to access addresses in two
1185 consecutive pages.
1186 */
1187 if (mem_page != ((off + size - 1) & PAGE_MASK))
1188 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1189 else
1190 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1191 if (mem_ptr == 0UL) {
1192 return 1;
1193 }
1194 addr = mem_ptr;
1195 addr += off & (PAGE_SIZE - 1);
1196 }
1197 switch (size) {
1198 case 1:
1199 writeb(*(u8 *) data, addr);
1200 break;
1201 case 2:
1202 writew(*(u16 *) data, addr);
1203 break;
1204 case 4:
1205 writel(*(u32 *) data, addr);
1206 break;
1207 case 8:
1208 writeq(*(u64 *) data, addr);
1209 break;
1210 default:
1211 DPRINTK(INFO,
1212 "writing data %lx to offset %llx, num words=%d\n",
1213 *(unsigned long *)data, off, (size >> 3));
1214
1215 netxen_nic_hw_block_write64((u64 __iomem *) data, addr,
1216 (size >> 3));
1217 break;
1218 }
1219
1220 if (mem_ptr)
1221 iounmap(mem_ptr);
1222 DPRINTK(INFO, "wrote %llx\n", *(unsigned long long *)data);
1223
1224 return ret;
1225}
1226
1227int netxen_nic_pci_mem_read_ioctl(struct netxen_adapter *adapter,
1228 u64 off, void *data, int size)
1229{
1230 void *addr;
1231 int ret = 0;
1232 u8 *mem_ptr = NULL;
1233 unsigned long mem_base;
1234 unsigned long mem_page;
1235
1236 if (data == NULL || off > (128 * 1024 * 1024)) {
1237 printk(KERN_ERR "%s: data: %p off:%llx\n",
1238 netxen_nic_driver_name, data, off);
1239 return 1;
1240 }
1241 off = netxen_nic_pci_set_window(adapter, off);
1242 /* Corner case : Malicious user tried to break the driver by reading
1243 last few bytes in ranges and tries to read further addresses.
1244 */
1245 if (!pci_base(adapter, off + size - 1) && pci_base(adapter, off)) {
1246 printk(KERN_ERR "%s: Invalid access to memory address range"
1247 " 0x%llx - 0x%llx\n", netxen_nic_driver_name, off,
1248 off + size);
1249 return 1;
1250 }
1251 addr = pci_base_offset(adapter, off);
1252 if (!addr) {
1253 mem_base = pci_resource_start(adapter->ahw.pdev, 0);
1254 mem_page = off & PAGE_MASK;
1255 /* Map two pages whenever user tries to access addresses in two
1256 consecutive pages.
1257 */
1258 if (mem_page != ((off + size - 1) & PAGE_MASK))
1259 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE * 2);
1260 else
1261 mem_ptr = ioremap(mem_base + mem_page, PAGE_SIZE);
1262 if (mem_ptr == 0UL) {
1263 *(u8 *) data = 0;
1264 return 1;
1265 }
1266 addr = mem_ptr;
1267 addr += off & (PAGE_SIZE - 1);
1268 }
1269 switch (size) {
1270 case 1:
1271 *(u8 *) data = readb(addr);
1272 break;
1273 case 2:
1274 *(u16 *) data = readw(addr);
1275 break;
1276 case 4:
1277 *(u32 *) data = readl(addr);
1278 break;
1279 case 8:
1280 *(u64 *) data = readq(addr);
1281 break;
1282 default:
1283 netxen_nic_hw_block_read64((u64 __iomem *) data, addr,
1284 (size >> 3));
1285 break;
1286 }
1287
1288 if (mem_ptr)
1289 iounmap(mem_ptr);
1290 DPRINTK(INFO, "read %llx\n", *(unsigned long long *)data);
1291
1292 return ret;
1293}
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index 869725f0bb18..c3e41f368554 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -35,7 +35,6 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include "netxen_nic.h" 36#include "netxen_nic.h"
37#include "netxen_nic_hw.h" 37#include "netxen_nic_hw.h"
38#include "netxen_nic_ioctl.h"
39#include "netxen_nic_phan_reg.h" 38#include "netxen_nic_phan_reg.h"
40 39
41struct crb_addr_pair { 40struct crb_addr_pair {
@@ -928,7 +927,7 @@ u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max)
928 } 927 }
929 netxen_process_rcv(adapter, ctxid, desc); 928 netxen_process_rcv(adapter, ctxid, desc);
930 netxen_clear_sts_owner(desc); 929 netxen_clear_sts_owner(desc);
931 netxen_set_sts_owner(desc, STATUS_OWNER_PHANTOM); 930 netxen_set_sts_owner(desc, cpu_to_le16(STATUS_OWNER_PHANTOM));
932 consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1); 931 consumer = (consumer + 1) & (adapter->max_rx_desc_count - 1);
933 count++; 932 count++;
934 } 933 }
@@ -1023,7 +1022,7 @@ int netxen_process_cmd_ring(unsigned long data)
1023 && netif_carrier_ok(port->netdev)) 1022 && netif_carrier_ok(port->netdev))
1024 && ((jiffies - port->netdev->trans_start) > 1023 && ((jiffies - port->netdev->trans_start) >
1025 port->netdev->watchdog_timeo)) { 1024 port->netdev->watchdog_timeo)) {
1026 SCHEDULE_WORK(&port->adapter->tx_timeout_task); 1025 SCHEDULE_WORK(&port->tx_timeout_task);
1027 } 1026 }
1028 1027
1029 last_consumer = get_next_index(last_consumer, 1028 last_consumer = get_next_index(last_consumer,
@@ -1138,13 +1137,13 @@ void netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ctx, u32 ringid)
1138 */ 1137 */
1139 dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size, 1138 dma = pci_map_single(pdev, skb->data, rcv_desc->dma_size,
1140 PCI_DMA_FROMDEVICE); 1139 PCI_DMA_FROMDEVICE);
1141 pdesc->addr_buffer = dma; 1140 pdesc->addr_buffer = cpu_to_le64(dma);
1142 buffer->skb = skb; 1141 buffer->skb = skb;
1143 buffer->state = NETXEN_BUFFER_BUSY; 1142 buffer->state = NETXEN_BUFFER_BUSY;
1144 buffer->dma = dma; 1143 buffer->dma = dma;
1145 /* make a rcv descriptor */ 1144 /* make a rcv descriptor */
1146 pdesc->reference_handle = buffer->ref_handle; 1145 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1147 pdesc->buffer_length = rcv_desc->dma_size; 1146 pdesc->buffer_length = cpu_to_le32(rcv_desc->dma_size);
1148 DPRINTK(INFO, "done writing descripter\n"); 1147 DPRINTK(INFO, "done writing descripter\n");
1149 producer = 1148 producer =
1150 get_next_index(producer, rcv_desc->max_rx_desc_count); 1149 get_next_index(producer, rcv_desc->max_rx_desc_count);
@@ -1232,8 +1231,8 @@ void netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, uint32_t ctx,
1232 PCI_DMA_FROMDEVICE); 1231 PCI_DMA_FROMDEVICE);
1233 1232
1234 /* make a rcv descriptor */ 1233 /* make a rcv descriptor */
1235 pdesc->reference_handle = le16_to_cpu(buffer->ref_handle); 1234 pdesc->reference_handle = cpu_to_le16(buffer->ref_handle);
1236 pdesc->buffer_length = le16_to_cpu(rcv_desc->dma_size); 1235 pdesc->buffer_length = cpu_to_le16(rcv_desc->dma_size);
1237 pdesc->addr_buffer = cpu_to_le64(buffer->dma); 1236 pdesc->addr_buffer = cpu_to_le64(buffer->dma);
1238 DPRINTK(INFO, "done writing descripter\n"); 1237 DPRINTK(INFO, "done writing descripter\n");
1239 producer = 1238 producer =
@@ -1273,52 +1272,6 @@ int netxen_nic_tx_has_work(struct netxen_adapter *adapter)
1273 return 0; 1272 return 0;
1274} 1273}
1275 1274
1276int
1277netxen_nic_fill_statistics(struct netxen_adapter *adapter,
1278 struct netxen_port *port,
1279 struct netxen_statistics *netxen_stats)
1280{
1281 void __iomem *addr;
1282
1283 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
1284 netxen_nic_pci_change_crbwindow(adapter, 0);
1285 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_BYTE_CNT,
1286 &(netxen_stats->tx_bytes));
1287 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_TX_FRAME_CNT,
1288 &(netxen_stats->tx_packets));
1289 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_BYTE_CNT,
1290 &(netxen_stats->rx_bytes));
1291 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_RX_FRAME_CNT,
1292 &(netxen_stats->rx_packets));
1293 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_AGGR_ERROR_CNT,
1294 &(netxen_stats->rx_errors));
1295 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_CRC_ERROR_CNT,
1296 &(netxen_stats->rx_crc_errors));
1297 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
1298 &(netxen_stats->
1299 rx_long_length_error));
1300 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
1301 &(netxen_stats->
1302 rx_short_length_error));
1303
1304 netxen_nic_pci_change_crbwindow(adapter, 1);
1305 } else {
1306 spin_lock_bh(&adapter->tx_lock);
1307 netxen_stats->tx_bytes = port->stats.txbytes;
1308 netxen_stats->tx_packets = port->stats.xmitedframes +
1309 port->stats.xmitfinished;
1310 netxen_stats->rx_bytes = port->stats.rxbytes;
1311 netxen_stats->rx_packets = port->stats.no_rcv;
1312 netxen_stats->rx_errors = port->stats.rcvdbadskb;
1313 netxen_stats->tx_errors = port->stats.nocmddescriptor;
1314 netxen_stats->rx_short_length_error = port->stats.uplcong;
1315 netxen_stats->rx_long_length_error = port->stats.uphcong;
1316 netxen_stats->rx_crc_errors = 0;
1317 netxen_stats->rx_mac_errors = 0;
1318 spin_unlock_bh(&adapter->tx_lock);
1319 }
1320 return 0;
1321}
1322 1275
1323void netxen_nic_clear_stats(struct netxen_adapter *adapter) 1276void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1324{ 1277{
@@ -1332,193 +1285,3 @@ void netxen_nic_clear_stats(struct netxen_adapter *adapter)
1332 } 1285 }
1333} 1286}
1334 1287
1335int
1336netxen_nic_clear_statistics(struct netxen_adapter *adapter,
1337 struct netxen_port *port)
1338{
1339 int data = 0;
1340
1341 netxen_nic_pci_change_crbwindow(adapter, 0);
1342
1343 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_BYTE_CNT, &data);
1344 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_TX_FRAME_CNT,
1345 &data);
1346 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_BYTE_CNT, &data);
1347 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_RX_FRAME_CNT,
1348 &data);
1349 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_AGGR_ERROR_CNT,
1350 &data);
1351 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_CRC_ERROR_CNT,
1352 &data);
1353 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
1354 &data);
1355 netxen_nic_locked_write_reg(adapter, NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
1356 &data);
1357
1358 netxen_nic_pci_change_crbwindow(adapter, 1);
1359 netxen_nic_clear_stats(adapter);
1360 return 0;
1361}
1362
1363int
1364netxen_nic_do_ioctl(struct netxen_adapter *adapter, void *u_data,
1365 struct netxen_port *port)
1366{
1367 struct netxen_nic_ioctl_data data;
1368 struct netxen_nic_ioctl_data *up_data;
1369 int retval = 0;
1370 struct netxen_statistics netxen_stats;
1371
1372 up_data = (void *)u_data;
1373
1374 DPRINTK(INFO, "doing ioctl for %p\n", adapter);
1375 if (copy_from_user(&data, (void __user *)up_data, sizeof(data))) {
1376 /* evil user tried to crash the kernel */
1377 DPRINTK(ERR, "bad copy from userland: %d\n", (int)sizeof(data));
1378 retval = -EFAULT;
1379 goto error_out;
1380 }
1381
1382 /* Shouldn't access beyond legal limits of "char u[64];" member */
1383 if (!data.ptr && (data.size > sizeof(data.u))) {
1384 /* evil user tried to crash the kernel */
1385 DPRINTK(ERR, "bad size: %d\n", data.size);
1386 retval = -EFAULT;
1387 goto error_out;
1388 }
1389
1390 switch (data.cmd) {
1391 case netxen_nic_cmd_pci_read:
1392 if ((retval = netxen_nic_hw_read_ioctl(adapter, data.off,
1393 &(data.u), data.size)))
1394 goto error_out;
1395 if (copy_to_user
1396 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1397 DPRINTK(ERR, "bad copy to userland: %d\n",
1398 (int)sizeof(data));
1399 retval = -EFAULT;
1400 goto error_out;
1401 }
1402 data.rv = 0;
1403 break;
1404
1405 case netxen_nic_cmd_pci_write:
1406 if ((retval = netxen_nic_hw_write_ioctl(adapter, data.off,
1407 &(data.u), data.size)))
1408 goto error_out;
1409 data.rv = 0;
1410 break;
1411
1412 case netxen_nic_cmd_pci_mem_read:
1413 if (netxen_nic_pci_mem_read_ioctl(adapter, data.off, &(data.u),
1414 data.size)) {
1415 DPRINTK(ERR, "Failed to read the data.\n");
1416 retval = -EFAULT;
1417 goto error_out;
1418 }
1419 if (copy_to_user
1420 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1421 DPRINTK(ERR, "bad copy to userland: %d\n",
1422 (int)sizeof(data));
1423 retval = -EFAULT;
1424 goto error_out;
1425 }
1426 data.rv = 0;
1427 break;
1428
1429 case netxen_nic_cmd_pci_mem_write:
1430 if ((retval = netxen_nic_pci_mem_write_ioctl(adapter, data.off,
1431 &(data.u),
1432 data.size)))
1433 goto error_out;
1434 data.rv = 0;
1435 break;
1436
1437 case netxen_nic_cmd_pci_config_read:
1438 switch (data.size) {
1439 case 1:
1440 data.rv = pci_read_config_byte(adapter->ahw.pdev,
1441 data.off,
1442 (char *)&(data.u));
1443 break;
1444 case 2:
1445 data.rv = pci_read_config_word(adapter->ahw.pdev,
1446 data.off,
1447 (short *)&(data.u));
1448 break;
1449 case 4:
1450 data.rv = pci_read_config_dword(adapter->ahw.pdev,
1451 data.off,
1452 (u32 *) & (data.u));
1453 break;
1454 }
1455 if (copy_to_user
1456 ((void __user *)&(up_data->u), &(data.u), data.size)) {
1457 DPRINTK(ERR, "bad copy to userland: %d\n",
1458 (int)sizeof(data));
1459 retval = -EFAULT;
1460 goto error_out;
1461 }
1462 break;
1463
1464 case netxen_nic_cmd_pci_config_write:
1465 switch (data.size) {
1466 case 1:
1467 data.rv = pci_write_config_byte(adapter->ahw.pdev,
1468 data.off,
1469 *(char *)&(data.u));
1470 break;
1471 case 2:
1472 data.rv = pci_write_config_word(adapter->ahw.pdev,
1473 data.off,
1474 *(short *)&(data.u));
1475 break;
1476 case 4:
1477 data.rv = pci_write_config_dword(adapter->ahw.pdev,
1478 data.off,
1479 *(u32 *) & (data.u));
1480 break;
1481 }
1482 break;
1483
1484 case netxen_nic_cmd_get_stats:
1485 data.rv =
1486 netxen_nic_fill_statistics(adapter, port, &netxen_stats);
1487 if (copy_to_user
1488 ((void __user *)(up_data->ptr), (void *)&netxen_stats,
1489 sizeof(struct netxen_statistics))) {
1490 DPRINTK(ERR, "bad copy to userland: %d\n",
1491 (int)sizeof(netxen_stats));
1492 retval = -EFAULT;
1493 goto error_out;
1494 }
1495 up_data->rv = data.rv;
1496 break;
1497
1498 case netxen_nic_cmd_clear_stats:
1499 data.rv = netxen_nic_clear_statistics(adapter, port);
1500 up_data->rv = data.rv;
1501 break;
1502
1503 case netxen_nic_cmd_get_version:
1504 if (copy_to_user
1505 ((void __user *)&(up_data->u), NETXEN_NIC_LINUX_VERSIONID,
1506 sizeof(NETXEN_NIC_LINUX_VERSIONID))) {
1507 DPRINTK(ERR, "bad copy to userland: %d\n",
1508 (int)sizeof(data));
1509 retval = -EFAULT;
1510 goto error_out;
1511 }
1512 break;
1513
1514 default:
1515 DPRINTK(INFO, "bad command %d for %p\n", data.cmd, adapter);
1516 retval = -EOPNOTSUPP;
1517 goto error_out;
1518 }
1519 put_user(data.rv, (&(up_data->rv)));
1520 DPRINTK(INFO, "done ioctl for %p well.\n", adapter);
1521
1522 error_out:
1523 return retval;
1524}
diff --git a/drivers/net/netxen/netxen_nic_ioctl.h b/drivers/net/netxen/netxen_nic_ioctl.h
deleted file mode 100644
index 1221fa527552..000000000000
--- a/drivers/net/netxen/netxen_nic_ioctl.h
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * 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,
18 * MA 02111-1307, USA.
19 *
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
22 *
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 */
29
30#ifndef __NETXEN_NIC_IOCTL_H__
31#define __NETXEN_NIC_IOCTL_H__
32
33#include <linux/sockios.h>
34
35#define NETXEN_CMD_START SIOCDEVPRIVATE
36#define NETXEN_NIC_CMD (NETXEN_CMD_START + 1)
37#define NETXEN_NIC_NAME (NETXEN_CMD_START + 2)
38#define NETXEN_NIC_NAME_LEN 16
39#define NETXEN_NIC_NAME_RSP "NETXEN-UNM"
40
41typedef enum {
42 netxen_nic_cmd_none = 0,
43 netxen_nic_cmd_pci_read,
44 netxen_nic_cmd_pci_write,
45 netxen_nic_cmd_pci_mem_read,
46 netxen_nic_cmd_pci_mem_write,
47 netxen_nic_cmd_pci_config_read,
48 netxen_nic_cmd_pci_config_write,
49 netxen_nic_cmd_get_stats,
50 netxen_nic_cmd_clear_stats,
51 netxen_nic_cmd_get_version
52} netxen_nic_ioctl_cmd_t;
53
54struct netxen_nic_ioctl_data {
55 u32 cmd;
56 u32 unused1;
57 u64 off;
58 u32 size;
59 u32 rv;
60 char u[64];
61 void *ptr;
62};
63
64struct netxen_statistics {
65 u64 rx_packets;
66 u64 tx_packets;
67 u64 rx_bytes;
68 u64 rx_errors;
69 u64 tx_bytes;
70 u64 tx_errors;
71 u64 rx_crc_errors;
72 u64 rx_short_length_error;
73 u64 rx_long_length_error;
74 u64 rx_mac_errors;
75};
76
77#endif /* __NETXEN_NIC_IOCTL_H_ */
diff --git a/drivers/net/netxen/netxen_nic_isr.c b/drivers/net/netxen/netxen_nic_isr.c
index 1b45f50fa6aa..06847d4252c3 100644
--- a/drivers/net/netxen/netxen_nic_isr.c
+++ b/drivers/net/netxen/netxen_nic_isr.c
@@ -157,7 +157,8 @@ void netxen_nic_isr_other(struct netxen_adapter *adapter)
157 for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) { 157 for (portno = 0; portno < NETXEN_NIU_MAX_GBE_PORTS; portno++) {
158 linkup = val & 1; 158 linkup = val & 1;
159 if (linkup != (qg_linksup & 1)) { 159 if (linkup != (qg_linksup & 1)) {
160 printk(KERN_INFO "%s: PORT %d link %s\n", 160 printk(KERN_INFO "%s: %s PORT %d link %s\n",
161 adapter->port[portno]->netdev->name,
161 netxen_nic_driver_name, portno, 162 netxen_nic_driver_name, portno,
162 ((linkup == 0) ? "down" : "up")); 163 ((linkup == 0) ? "down" : "up"));
163 netxen_indicate_link_status(adapter, portno, linkup); 164 netxen_indicate_link_status(adapter, portno, linkup);
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 575b71b67202..8a5792fea774 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -38,7 +38,6 @@
38#include "netxen_nic.h" 38#include "netxen_nic.h"
39#define DEFINE_GLOBAL_RECV_CRB 39#define DEFINE_GLOBAL_RECV_CRB
40#include "netxen_nic_phan_reg.h" 40#include "netxen_nic_phan_reg.h"
41#include "netxen_nic_ioctl.h"
42 41
43#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
44#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
@@ -53,8 +52,6 @@ char netxen_nic_driver_name[] = "netxen-nic";
53static char netxen_nic_driver_string[] = "NetXen Network Driver version " 52static char netxen_nic_driver_string[] = "NetXen Network Driver version "
54 NETXEN_NIC_LINUX_VERSIONID; 53 NETXEN_NIC_LINUX_VERSIONID;
55 54
56struct netxen_adapter *g_adapter = NULL;
57
58#define NETXEN_NETDEV_WEIGHT 120 55#define NETXEN_NETDEV_WEIGHT 120
59#define NETXEN_ADAPTER_UP_MAGIC 777 56#define NETXEN_ADAPTER_UP_MAGIC 777
60#define NETXEN_NIC_PEG_TUNE 0 57#define NETXEN_NIC_PEG_TUNE 0
@@ -75,8 +72,6 @@ static void netxen_tx_timeout(struct net_device *netdev);
75static void netxen_tx_timeout_task(struct work_struct *work); 72static void netxen_tx_timeout_task(struct work_struct *work);
76static void netxen_watchdog(unsigned long); 73static void netxen_watchdog(unsigned long);
77static int netxen_handle_int(struct netxen_adapter *, struct net_device *); 74static int netxen_handle_int(struct netxen_adapter *, struct net_device *);
78static int netxen_nic_ioctl(struct net_device *netdev,
79 struct ifreq *ifr, int cmd);
80static int netxen_nic_poll(struct net_device *dev, int *budget); 75static int netxen_nic_poll(struct net_device *dev, int *budget);
81#ifdef CONFIG_NET_POLL_CONTROLLER 76#ifdef CONFIG_NET_POLL_CONTROLLER
82static void netxen_nic_poll_controller(struct net_device *netdev); 77static void netxen_nic_poll_controller(struct net_device *netdev);
@@ -90,6 +85,8 @@ static struct pci_device_id netxen_pci_tbl[] __devinitdata = {
90 {PCI_DEVICE(0x4040, 0x0003)}, 85 {PCI_DEVICE(0x4040, 0x0003)},
91 {PCI_DEVICE(0x4040, 0x0004)}, 86 {PCI_DEVICE(0x4040, 0x0004)},
92 {PCI_DEVICE(0x4040, 0x0005)}, 87 {PCI_DEVICE(0x4040, 0x0005)},
88 {PCI_DEVICE(0x4040, 0x0024)},
89 {PCI_DEVICE(0x4040, 0x0025)},
93 {0,} 90 {0,}
94}; 91};
95 92
@@ -129,7 +126,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
129 struct netxen_cmd_buffer *cmd_buf_arr = NULL; 126 struct netxen_cmd_buffer *cmd_buf_arr = NULL;
130 u64 mac_addr[FLASH_NUM_PORTS + 1]; 127 u64 mac_addr[FLASH_NUM_PORTS + 1];
131 int valid_mac = 0; 128 int valid_mac = 0;
132 static int netxen_cards_found = 0;
133 129
134 printk(KERN_INFO "%s \n", netxen_nic_driver_string); 130 printk(KERN_INFO "%s \n", netxen_nic_driver_string);
135 /* In current scheme, we use only PCI function 0 */ 131 /* In current scheme, we use only PCI function 0 */
@@ -220,9 +216,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
220 goto err_out_dbunmap; 216 goto err_out_dbunmap;
221 } 217 }
222 218
223 if (netxen_cards_found == 0) {
224 g_adapter = adapter;
225 }
226 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS; 219 adapter->max_tx_desc_count = MAX_CMD_DESCRIPTORS;
227 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS; 220 adapter->max_rx_desc_count = MAX_RCV_DESCRIPTORS;
228 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS; 221 adapter->max_jumbo_rx_desc_count = MAX_JUMBO_RCV_DESCRIPTORS;
@@ -383,7 +376,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
383 netdev->set_multicast_list = netxen_nic_set_multi; 376 netdev->set_multicast_list = netxen_nic_set_multi;
384 netdev->set_mac_address = netxen_nic_set_mac; 377 netdev->set_mac_address = netxen_nic_set_mac;
385 netdev->change_mtu = netxen_nic_change_mtu; 378 netdev->change_mtu = netxen_nic_change_mtu;
386 netdev->do_ioctl = netxen_nic_ioctl;
387 netdev->tx_timeout = netxen_tx_timeout; 379 netdev->tx_timeout = netxen_tx_timeout;
388 netdev->watchdog_timeo = HZ; 380 netdev->watchdog_timeo = HZ;
389 381
@@ -428,8 +420,7 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
428 netdev->dev_addr); 420 netdev->dev_addr);
429 } 421 }
430 } 422 }
431 adapter->netdev = netdev; 423 INIT_WORK(&port->tx_timeout_task, netxen_tx_timeout_task);
432 INIT_WORK(&adapter->tx_timeout_task, netxen_tx_timeout_task);
433 netif_carrier_off(netdev); 424 netif_carrier_off(netdev);
434 netif_stop_queue(netdev); 425 netif_stop_queue(netdev);
435 426
@@ -444,6 +435,11 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
444 adapter->port[i] = port; 435 adapter->port[i] = port;
445 } 436 }
446 437
438 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
439 netxen_pinit_from_rom(adapter, 0);
440 udelay(500);
441 netxen_load_firmware(adapter);
442 netxen_phantom_init(adapter, NETXEN_NIC_PEG_TUNE);
447 /* 443 /*
448 * delay a while to ensure that the Pegs are up & running. 444 * delay a while to ensure that the Pegs are up & running.
449 * Otherwise, we might see some flaky behaviour. 445 * Otherwise, we might see some flaky behaviour.
@@ -461,7 +457,6 @@ netxen_nic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
461 break; 457 break;
462 } 458 }
463 459
464 adapter->number = netxen_cards_found;
465 adapter->driver_mismatch = 0; 460 adapter->driver_mismatch = 0;
466 461
467 return 0; 462 return 0;
@@ -531,6 +526,8 @@ static void __devexit netxen_nic_remove(struct pci_dev *pdev)
531 526
532 netxen_nic_stop_all_ports(adapter); 527 netxen_nic_stop_all_ports(adapter);
533 /* leave the hw in the same state as reboot */ 528 /* leave the hw in the same state as reboot */
529 netxen_pinit_from_rom(adapter, 0);
530 writel(0, NETXEN_CRB_NORMALIZE(adapter, CRB_CMDPEG_STATE));
534 netxen_load_firmware(adapter); 531 netxen_load_firmware(adapter);
535 netxen_free_adapter_offload(adapter); 532 netxen_free_adapter_offload(adapter);
536 533
@@ -821,8 +818,8 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
821 /* Take skb->data itself */ 818 /* Take skb->data itself */
822 pbuf = &adapter->cmd_buf_arr[producer]; 819 pbuf = &adapter->cmd_buf_arr[producer];
823 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) { 820 if ((netdev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size > 0) {
824 pbuf->mss = skb_shinfo(skb)->gso_size; 821 pbuf->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
825 hwdesc->mss = skb_shinfo(skb)->gso_size; 822 hwdesc->mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
826 } else { 823 } else {
827 pbuf->mss = 0; 824 pbuf->mss = 0;
828 hwdesc->mss = 0; 825 hwdesc->mss = 0;
@@ -956,11 +953,6 @@ static int netxen_nic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
956static void netxen_watchdog(unsigned long v) 953static void netxen_watchdog(unsigned long v)
957{ 954{
958 struct netxen_adapter *adapter = (struct netxen_adapter *)v; 955 struct netxen_adapter *adapter = (struct netxen_adapter *)v;
959 if (adapter != g_adapter) {
960 printk("%s: ***BUG*** adapter[%p] != g_adapter[%p]\n",
961 __FUNCTION__, adapter, g_adapter);
962 return;
963 }
964 956
965 SCHEDULE_WORK(&adapter->watchdog_task); 957 SCHEDULE_WORK(&adapter->watchdog_task);
966} 958}
@@ -969,23 +961,23 @@ static void netxen_tx_timeout(struct net_device *netdev)
969{ 961{
970 struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev); 962 struct netxen_port *port = (struct netxen_port *)netdev_priv(netdev);
971 963
972 SCHEDULE_WORK(&port->adapter->tx_timeout_task); 964 SCHEDULE_WORK(&port->tx_timeout_task);
973} 965}
974 966
975static void netxen_tx_timeout_task(struct work_struct *work) 967static void netxen_tx_timeout_task(struct work_struct *work)
976{ 968{
977 struct netxen_adapter *adapter = 969 struct netxen_port *port =
978 container_of(work, struct netxen_adapter, tx_timeout_task); 970 container_of(work, struct netxen_port, tx_timeout_task);
979 struct net_device *netdev = adapter->netdev; 971 struct net_device *netdev = port->netdev;
980 unsigned long flags; 972 unsigned long flags;
981 973
982 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n", 974 printk(KERN_ERR "%s %s: transmit timeout, resetting.\n",
983 netxen_nic_driver_name, netdev->name); 975 netxen_nic_driver_name, netdev->name);
984 976
985 spin_lock_irqsave(&adapter->lock, flags); 977 spin_lock_irqsave(&port->adapter->lock, flags);
986 netxen_nic_close(netdev); 978 netxen_nic_close(netdev);
987 netxen_nic_open(netdev); 979 netxen_nic_open(netdev);
988 spin_unlock_irqrestore(&adapter->lock, flags); 980 spin_unlock_irqrestore(&port->adapter->lock, flags);
989 netdev->trans_start = jiffies; 981 netdev->trans_start = jiffies;
990 netif_wake_queue(netdev); 982 netif_wake_queue(netdev);
991} 983}
@@ -1137,47 +1129,6 @@ static void netxen_nic_poll_controller(struct net_device *netdev)
1137 enable_irq(adapter->irq); 1129 enable_irq(adapter->irq);
1138} 1130}
1139#endif 1131#endif
1140/*
1141 * netxen_nic_ioctl () We provide the tcl/phanmon support through these
1142 * ioctls.
1143 */
1144static int
1145netxen_nic_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
1146{
1147 int err = 0;
1148 unsigned long nr_bytes = 0;
1149 struct netxen_port *port = netdev_priv(netdev);
1150 struct netxen_adapter *adapter = port->adapter;
1151 char dev_name[NETXEN_NIC_NAME_LEN];
1152
1153 DPRINTK(INFO, "doing ioctl for %s\n", netdev->name);
1154 switch (cmd) {
1155 case NETXEN_NIC_CMD:
1156 err = netxen_nic_do_ioctl(adapter, (void *)ifr->ifr_data, port);
1157 break;
1158
1159 case NETXEN_NIC_NAME:
1160 DPRINTK(INFO, "ioctl cmd for NetXen\n");
1161 if (ifr->ifr_data) {
1162 sprintf(dev_name, "%s-%d", NETXEN_NIC_NAME_RSP,
1163 port->portnum);
1164 nr_bytes =
1165 copy_to_user((char __user *)ifr->ifr_data, dev_name,
1166 NETXEN_NIC_NAME_LEN);
1167 if (nr_bytes)
1168 err = -EIO;
1169
1170 }
1171 break;
1172
1173 default:
1174 DPRINTK(INFO, "ioctl cmd %x not supported\n", cmd);
1175 err = -EOPNOTSUPP;
1176 break;
1177 }
1178
1179 return err;
1180}
1181 1132
1182static struct pci_driver netxen_driver = { 1133static struct pci_driver netxen_driver = {
1183 .name = netxen_nic_driver_name, 1134 .name = netxen_nic_driver_name,
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index f83b41d4cb0e..577babd4c938 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -225,7 +225,6 @@ MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl);
225 225
226static int rx_copybreak = 200; 226static int rx_copybreak = 200;
227static int use_dac; 227static int use_dac;
228static int ignore_parity_err;
229static struct { 228static struct {
230 u32 msg_enable; 229 u32 msg_enable;
231} debug = { -1 }; 230} debug = { -1 };
@@ -471,8 +470,6 @@ module_param(use_dac, int, 0);
471MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); 470MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot.");
472module_param_named(debug, debug.msg_enable, int, 0); 471module_param_named(debug, debug.msg_enable, int, 0);
473MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); 472MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)");
474module_param_named(ignore_parity_err, ignore_parity_err, bool, 0);
475MODULE_PARM_DESC(ignore_parity_err, "Ignore PCI parity error as target. Default: false");
476MODULE_LICENSE("GPL"); 473MODULE_LICENSE("GPL");
477MODULE_VERSION(RTL8169_VERSION); 474MODULE_VERSION(RTL8169_VERSION);
478 475
@@ -1885,7 +1882,6 @@ static void rtl8169_hw_start(struct net_device *dev)
1885 (tp->mac_version == RTL_GIGA_MAC_VER_02) || 1882 (tp->mac_version == RTL_GIGA_MAC_VER_02) ||
1886 (tp->mac_version == RTL_GIGA_MAC_VER_03) || 1883 (tp->mac_version == RTL_GIGA_MAC_VER_03) ||
1887 (tp->mac_version == RTL_GIGA_MAC_VER_04)) 1884 (tp->mac_version == RTL_GIGA_MAC_VER_04))
1888 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb);
1889 rtl8169_set_rx_tx_config_registers(tp); 1885 rtl8169_set_rx_tx_config_registers(tp);
1890 1886
1891 cmd = RTL_R16(CPlusCmd); 1887 cmd = RTL_R16(CPlusCmd);
@@ -2388,7 +2384,7 @@ static void rtl8169_pcierr_interrupt(struct net_device *dev)
2388 * 2384 *
2389 * Feel free to adjust to your needs. 2385 * Feel free to adjust to your needs.
2390 */ 2386 */
2391 if (ignore_parity_err) 2387 if (pdev->broken_parity_status)
2392 pci_cmd &= ~PCI_COMMAND_PARITY; 2388 pci_cmd &= ~PCI_COMMAND_PARITY;
2393 else 2389 else
2394 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; 2390 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 8a39376f87dc..deedfd5f8226 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -2920,6 +2920,7 @@ static int skge_poll(struct net_device *dev, int *budget)
2920 struct skge_hw *hw = skge->hw; 2920 struct skge_hw *hw = skge->hw;
2921 struct skge_ring *ring = &skge->rx_ring; 2921 struct skge_ring *ring = &skge->rx_ring;
2922 struct skge_element *e; 2922 struct skge_element *e;
2923 unsigned long flags;
2923 int to_do = min(dev->quota, *budget); 2924 int to_do = min(dev->quota, *budget);
2924 int work_done = 0; 2925 int work_done = 0;
2925 2926
@@ -2957,12 +2958,12 @@ static int skge_poll(struct net_device *dev, int *budget)
2957 if (work_done >= to_do) 2958 if (work_done >= to_do)
2958 return 1; /* not done */ 2959 return 1; /* not done */
2959 2960
2960 spin_lock_irq(&hw->hw_lock); 2961 spin_lock_irqsave(&hw->hw_lock, flags);
2961 __netif_rx_complete(dev); 2962 __netif_rx_complete(dev);
2962 hw->intr_mask |= irqmask[skge->port]; 2963 hw->intr_mask |= irqmask[skge->port];
2963 skge_write32(hw, B0_IMSK, hw->intr_mask); 2964 skge_write32(hw, B0_IMSK, hw->intr_mask);
2964 skge_read32(hw, B0_IMSK); 2965 skge_read32(hw, B0_IMSK);
2965 spin_unlock_irq(&hw->hw_lock); 2966 spin_unlock_irqrestore(&hw->hw_lock, flags);
2966 2967
2967 return 0; 2968 return 0;
2968} 2969}
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index fb1d2c30c1bb..a6601e8d423c 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -569,8 +569,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
569 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1) 569 if (hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
570 onoff = !onoff; 570 onoff = !onoff;
571 571
572 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
572 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1); 573 reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
573
574 if (onoff) 574 if (onoff)
575 /* Turn off phy power saving */ 575 /* Turn off phy power saving */
576 reg1 &= ~phy_power[port]; 576 reg1 &= ~phy_power[port];
@@ -579,6 +579,7 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
579 579
580 sky2_pci_write32(hw, PCI_DEV_REG1, reg1); 580 sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
581 sky2_pci_read32(hw, PCI_DEV_REG1); 581 sky2_pci_read32(hw, PCI_DEV_REG1);
582 sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
582 udelay(100); 583 udelay(100);
583} 584}
584 585
@@ -1511,6 +1512,13 @@ static int sky2_down(struct net_device *dev)
1511 imask &= ~portirq_msk[port]; 1512 imask &= ~portirq_msk[port];
1512 sky2_write32(hw, B0_IMSK, imask); 1513 sky2_write32(hw, B0_IMSK, imask);
1513 1514
1515 /*
1516 * Both ports share the NAPI poll on port 0, so if necessary undo the
1517 * the disable that is done in dev_close.
1518 */
1519 if (sky2->port == 0 && hw->ports > 1)
1520 netif_poll_enable(dev);
1521
1514 sky2_gmac_reset(hw, port); 1522 sky2_gmac_reset(hw, port);
1515 1523
1516 /* Stop transmitter */ 1524 /* Stop transmitter */
@@ -3631,6 +3639,29 @@ static int sky2_resume(struct pci_dev *pdev)
3631out: 3639out:
3632 return err; 3640 return err;
3633} 3641}
3642
3643/* BIOS resume runs after device (it's a bug in PM)
3644 * as a temporary workaround on suspend/resume leave MSI disabled
3645 */
3646static int sky2_suspend_late(struct pci_dev *pdev, pm_message_t state)
3647{
3648 struct sky2_hw *hw = pci_get_drvdata(pdev);
3649
3650 free_irq(pdev->irq, hw);
3651 if (hw->msi) {
3652 pci_disable_msi(pdev);
3653 hw->msi = 0;
3654 }
3655 return 0;
3656}
3657
3658static int sky2_resume_early(struct pci_dev *pdev)
3659{
3660 struct sky2_hw *hw = pci_get_drvdata(pdev);
3661 struct net_device *dev = hw->dev[0];
3662
3663 return request_irq(pdev->irq, sky2_intr, IRQF_SHARED, dev->name, hw);
3664}
3634#endif 3665#endif
3635 3666
3636static struct pci_driver sky2_driver = { 3667static struct pci_driver sky2_driver = {
@@ -3641,6 +3672,8 @@ static struct pci_driver sky2_driver = {
3641#ifdef CONFIG_PM 3672#ifdef CONFIG_PM
3642 .suspend = sky2_suspend, 3673 .suspend = sky2_suspend,
3643 .resume = sky2_resume, 3674 .resume = sky2_resume,
3675 .suspend_late = sky2_suspend_late,
3676 .resume_early = sky2_resume_early,
3644#endif 3677#endif
3645}; 3678};
3646 3679
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 2c4343395a4d..880d9fdd7c67 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -148,6 +148,8 @@ struct smc911x_local {
148 int tx_throttle; 148 int tx_throttle;
149 spinlock_t lock; 149 spinlock_t lock;
150 150
151 struct net_device *netdev;
152
151#ifdef SMC_USE_DMA 153#ifdef SMC_USE_DMA
152 /* DMA needs the physical address of the chip */ 154 /* DMA needs the physical address of the chip */
153 u_long physaddr; 155 u_long physaddr;
@@ -948,10 +950,11 @@ static void smc911x_phy_check_media(struct net_device *dev, int init)
948 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection 950 * of autonegotiation.) If the RPC ANEG bit is cleared, the selection
949 * is controlled by the RPC SPEED and RPC DPLX bits. 951 * is controlled by the RPC SPEED and RPC DPLX bits.
950 */ 952 */
951static void smc911x_phy_configure(void *data) 953static void smc911x_phy_configure(struct work_struct *work)
952{ 954{
953 struct net_device *dev = data; 955 struct smc911x_local *lp = container_of(work, struct smc911x_local,
954 struct smc911x_local *lp = netdev_priv(dev); 956 phy_configure);
957 struct net_device *dev = lp->netdev;
955 unsigned long ioaddr = dev->base_addr; 958 unsigned long ioaddr = dev->base_addr;
956 int phyaddr = lp->mii.phy_id; 959 int phyaddr = lp->mii.phy_id;
957 int my_phy_caps; /* My PHY capabilities */ 960 int my_phy_caps; /* My PHY capabilities */
@@ -1331,7 +1334,7 @@ smc911x_rx_dma_irq(int dma, void *data)
1331static void smc911x_poll_controller(struct net_device *dev) 1334static void smc911x_poll_controller(struct net_device *dev)
1332{ 1335{
1333 disable_irq(dev->irq); 1336 disable_irq(dev->irq);
1334 smc911x_interrupt(dev->irq, dev, NULL); 1337 smc911x_interrupt(dev->irq, dev);
1335 enable_irq(dev->irq); 1338 enable_irq(dev->irq);
1336} 1339}
1337#endif 1340#endif
@@ -1495,6 +1498,8 @@ static void smc911x_set_multicast_list(struct net_device *dev)
1495static int 1498static int
1496smc911x_open(struct net_device *dev) 1499smc911x_open(struct net_device *dev)
1497{ 1500{
1501 struct smc911x_local *lp = netdev_priv(dev);
1502
1498 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__); 1503 DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
1499 1504
1500 /* 1505 /*
@@ -1511,7 +1516,7 @@ smc911x_open(struct net_device *dev)
1511 smc911x_reset(dev); 1516 smc911x_reset(dev);
1512 1517
1513 /* Configure the PHY, initialize the link state */ 1518 /* Configure the PHY, initialize the link state */
1514 smc911x_phy_configure(dev); 1519 smc911x_phy_configure(&lp->phy_configure);
1515 1520
1516 /* Turn on Tx + Rx */ 1521 /* Turn on Tx + Rx */
1517 smc911x_enable(dev); 1522 smc911x_enable(dev);
@@ -2060,7 +2065,7 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
2060 dev->poll_controller = smc911x_poll_controller; 2065 dev->poll_controller = smc911x_poll_controller;
2061#endif 2066#endif
2062 2067
2063 INIT_WORK(&lp->phy_configure, smc911x_phy_configure, dev); 2068 INIT_WORK(&lp->phy_configure, smc911x_phy_configure);
2064 lp->mii.phy_id_mask = 0x1f; 2069 lp->mii.phy_id_mask = 0x1f;
2065 lp->mii.reg_num_mask = 0x1f; 2070 lp->mii.reg_num_mask = 0x1f;
2066 lp->mii.force_media = 0; 2071 lp->mii.force_media = 0;
@@ -2154,6 +2159,7 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2154{ 2159{
2155 struct net_device *ndev; 2160 struct net_device *ndev;
2156 struct resource *res; 2161 struct resource *res;
2162 struct smc911x_local *lp;
2157 unsigned int *addr; 2163 unsigned int *addr;
2158 int ret; 2164 int ret;
2159 2165
@@ -2183,6 +2189,8 @@ static int smc911x_drv_probe(struct platform_device *pdev)
2183 2189
2184 ndev->dma = (unsigned char)-1; 2190 ndev->dma = (unsigned char)-1;
2185 ndev->irq = platform_get_irq(pdev, 0); 2191 ndev->irq = platform_get_irq(pdev, 0);
2192 lp = netdev_priv(ndev);
2193 lp->netdev = ndev;
2186 2194
2187 addr = ioremap(res->start, SMC911X_IO_EXTENT); 2195 addr = ioremap(res->start, SMC911X_IO_EXTENT);
2188 if (!addr) { 2196 if (!addr) {
@@ -2204,7 +2212,6 @@ out:
2204 } 2212 }
2205#ifdef SMC_USE_DMA 2213#ifdef SMC_USE_DMA
2206 else { 2214 else {
2207 struct smc911x_local *lp = netdev_priv(ndev);
2208 lp->physaddr = res->start; 2215 lp->physaddr = res->start;
2209 lp->dev = &pdev->dev; 2216 lp->dev = &pdev->dev;
2210 } 2217 }
@@ -2275,7 +2282,7 @@ static int smc911x_drv_resume(struct platform_device *dev)
2275 smc911x_reset(ndev); 2282 smc911x_reset(ndev);
2276 smc911x_enable(ndev); 2283 smc911x_enable(ndev);
2277 if (lp->phy_type != 0) 2284 if (lp->phy_type != 0)
2278 smc911x_phy_configure(ndev); 2285 smc911x_phy_configure(&lp->phy_configure);
2279 netif_device_attach(ndev); 2286 netif_device_attach(ndev);
2280 } 2287 }
2281 } 2288 }
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index 571320ae87ab..4056ba1ff3c7 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -68,8 +68,8 @@
68 68
69#define DRV_MODULE_NAME "tg3" 69#define DRV_MODULE_NAME "tg3"
70#define PFX DRV_MODULE_NAME ": " 70#define PFX DRV_MODULE_NAME ": "
71#define DRV_MODULE_VERSION "3.70" 71#define DRV_MODULE_VERSION "3.71"
72#define DRV_MODULE_RELDATE "December 1, 2006" 72#define DRV_MODULE_RELDATE "December 15, 2006"
73 73
74#define TG3_DEF_MAC_MODE 0 74#define TG3_DEF_MAC_MODE 0
75#define TG3_DEF_RX_MODE 0 75#define TG3_DEF_RX_MODE 0
@@ -959,6 +959,13 @@ static int tg3_phy_reset(struct tg3 *tp)
959 u32 phy_status; 959 u32 phy_status;
960 int err; 960 int err;
961 961
962 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
963 u32 val;
964
965 val = tr32(GRC_MISC_CFG);
966 tw32_f(GRC_MISC_CFG, val & ~GRC_MISC_CFG_EPHY_IDDQ);
967 udelay(40);
968 }
962 err = tg3_readphy(tp, MII_BMSR, &phy_status); 969 err = tg3_readphy(tp, MII_BMSR, &phy_status);
963 err |= tg3_readphy(tp, MII_BMSR, &phy_status); 970 err |= tg3_readphy(tp, MII_BMSR, &phy_status);
964 if (err != 0) 971 if (err != 0)
@@ -1170,7 +1177,15 @@ static void tg3_power_down_phy(struct tg3 *tp)
1170 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES) 1177 if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
1171 return; 1178 return;
1172 1179
1173 if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5906) { 1180 if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5906) {
1181 u32 val;
1182
1183 tg3_bmcr_reset(tp);
1184 val = tr32(GRC_MISC_CFG);
1185 tw32_f(GRC_MISC_CFG, val | GRC_MISC_CFG_EPHY_IDDQ);
1186 udelay(40);
1187 return;
1188 } else {
1174 tg3_writephy(tp, MII_TG3_EXT_CTRL, 1189 tg3_writephy(tp, MII_TG3_EXT_CTRL,
1175 MII_TG3_EXT_CTRL_FORCE_LED_OFF); 1190 MII_TG3_EXT_CTRL_FORCE_LED_OFF);
1176 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2); 1191 tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
@@ -4426,7 +4441,7 @@ static void tg3_free_consistent(struct tg3 *tp)
4426 */ 4441 */
4427static int tg3_alloc_consistent(struct tg3 *tp) 4442static int tg3_alloc_consistent(struct tg3 *tp)
4428{ 4443{
4429 tp->rx_std_buffers = kmalloc((sizeof(struct ring_info) * 4444 tp->rx_std_buffers = kzalloc((sizeof(struct ring_info) *
4430 (TG3_RX_RING_SIZE + 4445 (TG3_RX_RING_SIZE +
4431 TG3_RX_JUMBO_RING_SIZE)) + 4446 TG3_RX_JUMBO_RING_SIZE)) +
4432 (sizeof(struct tx_ring_info) * 4447 (sizeof(struct tx_ring_info) *
@@ -4435,13 +4450,6 @@ static int tg3_alloc_consistent(struct tg3 *tp)
4435 if (!tp->rx_std_buffers) 4450 if (!tp->rx_std_buffers)
4436 return -ENOMEM; 4451 return -ENOMEM;
4437 4452
4438 memset(tp->rx_std_buffers, 0,
4439 (sizeof(struct ring_info) *
4440 (TG3_RX_RING_SIZE +
4441 TG3_RX_JUMBO_RING_SIZE)) +
4442 (sizeof(struct tx_ring_info) *
4443 TG3_TX_RING_SIZE));
4444
4445 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE]; 4453 tp->rx_jumbo_buffers = &tp->rx_std_buffers[TG3_RX_RING_SIZE];
4446 tp->tx_buffers = (struct tx_ring_info *) 4454 tp->tx_buffers = (struct tx_ring_info *)
4447 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE]; 4455 &tp->rx_jumbo_buffers[TG3_RX_JUMBO_RING_SIZE];
@@ -6988,6 +6996,8 @@ static int tg3_open(struct net_device *dev)
6988 struct tg3 *tp = netdev_priv(dev); 6996 struct tg3 *tp = netdev_priv(dev);
6989 int err; 6997 int err;
6990 6998
6999 netif_carrier_off(tp->dev);
7000
6991 tg3_full_lock(tp, 0); 7001 tg3_full_lock(tp, 0);
6992 7002
6993 err = tg3_set_power_state(tp, PCI_D0); 7003 err = tg3_set_power_state(tp, PCI_D0);
@@ -7981,6 +7991,10 @@ static int tg3_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
7981 tp->link_config.duplex = cmd->duplex; 7991 tp->link_config.duplex = cmd->duplex;
7982 } 7992 }
7983 7993
7994 tp->link_config.orig_speed = tp->link_config.speed;
7995 tp->link_config.orig_duplex = tp->link_config.duplex;
7996 tp->link_config.orig_autoneg = tp->link_config.autoneg;
7997
7984 if (netif_running(dev)) 7998 if (netif_running(dev))
7985 tg3_setup_phy(tp, 1); 7999 tg3_setup_phy(tp, 1);
7986 8000
@@ -11923,6 +11937,8 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11923 */ 11937 */
11924 pci_save_state(tp->pdev); 11938 pci_save_state(tp->pdev);
11925 11939
11940 pci_set_drvdata(pdev, dev);
11941
11926 err = register_netdev(dev); 11942 err = register_netdev(dev);
11927 if (err) { 11943 if (err) {
11928 printk(KERN_ERR PFX "Cannot register net device, " 11944 printk(KERN_ERR PFX "Cannot register net device, "
@@ -11930,8 +11946,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11930 goto err_out_iounmap; 11946 goto err_out_iounmap;
11931 } 11947 }
11932 11948
11933 pci_set_drvdata(pdev, dev);
11934
11935 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ", 11949 printk(KERN_INFO "%s: Tigon3 [partno(%s) rev %04x PHY(%s)] (%s) %s Ethernet ",
11936 dev->name, 11950 dev->name,
11937 tp->board_part_number, 11951 tp->board_part_number,
@@ -11962,8 +11976,6 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
11962 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 : 11976 (pdev->dma_mask == DMA_32BIT_MASK) ? 32 :
11963 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64)); 11977 (((u64) pdev->dma_mask == DMA_40BIT_MASK) ? 40 : 64));
11964 11978
11965 netif_carrier_off(tp->dev);
11966
11967 return 0; 11979 return 0;
11968 11980
11969err_out_iounmap: 11981err_out_iounmap:
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index dfaf4ed127bd..cf78a7e5997b 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -1350,6 +1350,7 @@
1350#define GRC_MISC_CFG_BOARD_ID_5788 0x00010000 1350#define GRC_MISC_CFG_BOARD_ID_5788 0x00010000
1351#define GRC_MISC_CFG_BOARD_ID_5788M 0x00018000 1351#define GRC_MISC_CFG_BOARD_ID_5788M 0x00018000
1352#define GRC_MISC_CFG_BOARD_ID_AC91002A1 0x00018000 1352#define GRC_MISC_CFG_BOARD_ID_AC91002A1 0x00018000
1353#define GRC_MISC_CFG_EPHY_IDDQ 0x00200000
1353#define GRC_MISC_CFG_KEEP_GPHY_POWER 0x04000000 1354#define GRC_MISC_CFG_KEEP_GPHY_POWER 0x04000000
1354#define GRC_LOCAL_CTRL 0x00006808 1355#define GRC_LOCAL_CTRL 0x00006808
1355#define GRC_LCLCTRL_INT_ACTIVE 0x00000001 1356#define GRC_LCLCTRL_INT_ACTIVE 0x00000001
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 4587f23f4e4b..8e5d82051bd4 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -265,15 +265,19 @@ static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status);
265static int velocity_suspend(struct pci_dev *pdev, pm_message_t state); 265static int velocity_suspend(struct pci_dev *pdev, pm_message_t state);
266static int velocity_resume(struct pci_dev *pdev); 266static int velocity_resume(struct pci_dev *pdev);
267 267
268static DEFINE_SPINLOCK(velocity_dev_list_lock);
269static LIST_HEAD(velocity_dev_list);
270
271#endif
272
273#if defined(CONFIG_PM) && defined(CONFIG_INET)
274
268static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr); 275static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr);
269 276
270static struct notifier_block velocity_inetaddr_notifier = { 277static struct notifier_block velocity_inetaddr_notifier = {
271 .notifier_call = velocity_netdev_event, 278 .notifier_call = velocity_netdev_event,
272}; 279};
273 280
274static DEFINE_SPINLOCK(velocity_dev_list_lock);
275static LIST_HEAD(velocity_dev_list);
276
277static void velocity_register_notifier(void) 281static void velocity_register_notifier(void)
278{ 282{
279 register_inetaddr_notifier(&velocity_inetaddr_notifier); 283 register_inetaddr_notifier(&velocity_inetaddr_notifier);
@@ -284,12 +288,12 @@ static void velocity_unregister_notifier(void)
284 unregister_inetaddr_notifier(&velocity_inetaddr_notifier); 288 unregister_inetaddr_notifier(&velocity_inetaddr_notifier);
285} 289}
286 290
287#else /* CONFIG_PM */ 291#else
288 292
289#define velocity_register_notifier() do {} while (0) 293#define velocity_register_notifier() do {} while (0)
290#define velocity_unregister_notifier() do {} while (0) 294#define velocity_unregister_notifier() do {} while (0)
291 295
292#endif /* !CONFIG_PM */ 296#endif
293 297
294/* 298/*
295 * Internal board variants. At the moment we have only one 299 * Internal board variants. At the moment we have only one
@@ -3292,6 +3296,8 @@ static int velocity_resume(struct pci_dev *pdev)
3292 return 0; 3296 return 0;
3293} 3297}
3294 3298
3299#ifdef CONFIG_INET
3300
3295static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr) 3301static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr)
3296{ 3302{
3297 struct in_ifaddr *ifa = (struct in_ifaddr *) ptr; 3303 struct in_ifaddr *ifa = (struct in_ifaddr *) ptr;
@@ -3312,4 +3318,6 @@ static int velocity_netdev_event(struct notifier_block *nb, unsigned long notifi
3312 } 3318 }
3313 return NOTIFY_DONE; 3319 return NOTIFY_DONE;
3314} 3320}
3321
3322#endif
3315#endif 3323#endif
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index 00ca704ece35..a08524191b5d 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -41,6 +41,8 @@ static void housekeeping_disable(struct zd_mac *mac);
41 41
42static void set_multicast_hash_handler(struct work_struct *work); 42static void set_multicast_hash_handler(struct work_struct *work);
43 43
44static void do_rx(unsigned long mac_ptr);
45
44int zd_mac_init(struct zd_mac *mac, 46int zd_mac_init(struct zd_mac *mac,
45 struct net_device *netdev, 47 struct net_device *netdev,
46 struct usb_interface *intf) 48 struct usb_interface *intf)
@@ -53,6 +55,10 @@ int zd_mac_init(struct zd_mac *mac,
53 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work); 55 INIT_DELAYED_WORK(&mac->set_rts_cts_work, set_rts_cts_work);
54 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work); 56 INIT_DELAYED_WORK(&mac->set_basic_rates_work, set_basic_rates_work);
55 57
58 skb_queue_head_init(&mac->rx_queue);
59 tasklet_init(&mac->rx_tasklet, do_rx, (unsigned long)mac);
60 tasklet_disable(&mac->rx_tasklet);
61
56 ieee_init(ieee); 62 ieee_init(ieee);
57 softmac_init(ieee80211_priv(netdev)); 63 softmac_init(ieee80211_priv(netdev));
58 zd_chip_init(&mac->chip, netdev, intf); 64 zd_chip_init(&mac->chip, netdev, intf);
@@ -140,6 +146,8 @@ out:
140void zd_mac_clear(struct zd_mac *mac) 146void zd_mac_clear(struct zd_mac *mac)
141{ 147{
142 flush_workqueue(zd_workqueue); 148 flush_workqueue(zd_workqueue);
149 skb_queue_purge(&mac->rx_queue);
150 tasklet_kill(&mac->rx_tasklet);
143 zd_chip_clear(&mac->chip); 151 zd_chip_clear(&mac->chip);
144 ZD_ASSERT(!spin_is_locked(&mac->lock)); 152 ZD_ASSERT(!spin_is_locked(&mac->lock));
145 ZD_MEMCLEAR(mac, sizeof(struct zd_mac)); 153 ZD_MEMCLEAR(mac, sizeof(struct zd_mac));
@@ -168,6 +176,8 @@ int zd_mac_open(struct net_device *netdev)
168 struct zd_chip *chip = &mac->chip; 176 struct zd_chip *chip = &mac->chip;
169 int r; 177 int r;
170 178
179 tasklet_enable(&mac->rx_tasklet);
180
171 r = zd_chip_enable_int(chip); 181 r = zd_chip_enable_int(chip);
172 if (r < 0) 182 if (r < 0)
173 goto out; 183 goto out;
@@ -218,6 +228,8 @@ int zd_mac_stop(struct net_device *netdev)
218 */ 228 */
219 229
220 zd_chip_disable_rx(chip); 230 zd_chip_disable_rx(chip);
231 skb_queue_purge(&mac->rx_queue);
232 tasklet_disable(&mac->rx_tasklet);
221 housekeeping_disable(mac); 233 housekeeping_disable(mac);
222 ieee80211softmac_stop(netdev); 234 ieee80211softmac_stop(netdev);
223 235
@@ -470,13 +482,13 @@ static void bssinfo_change(struct net_device *netdev, u32 changes)
470 482
471 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) { 483 if (changes & IEEE80211SOFTMAC_BSSINFOCHG_RATES) {
472 /* Set RTS rate to highest available basic rate */ 484 /* Set RTS rate to highest available basic rate */
473 u8 rate = ieee80211softmac_highest_supported_rate(softmac, 485 u8 hi_rate = ieee80211softmac_highest_supported_rate(softmac,
474 &bssinfo->supported_rates, 1); 486 &bssinfo->supported_rates, 1);
475 rate = rate_to_zd_rate(rate); 487 hi_rate = rate_to_zd_rate(hi_rate);
476 488
477 spin_lock_irqsave(&mac->lock, flags); 489 spin_lock_irqsave(&mac->lock, flags);
478 if (rate != mac->rts_rate) { 490 if (hi_rate != mac->rts_rate) {
479 mac->rts_rate = rate; 491 mac->rts_rate = hi_rate;
480 need_set_rts_cts = 1; 492 need_set_rts_cts = 1;
481 } 493 }
482 spin_unlock_irqrestore(&mac->lock, flags); 494 spin_unlock_irqrestore(&mac->lock, flags);
@@ -1072,43 +1084,75 @@ static int fill_rx_stats(struct ieee80211_rx_stats *stats,
1072 return 0; 1084 return 0;
1073} 1085}
1074 1086
1075int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length) 1087static void zd_mac_rx(struct zd_mac *mac, struct sk_buff *skb)
1076{ 1088{
1077 int r; 1089 int r;
1078 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac); 1090 struct ieee80211_device *ieee = zd_mac_to_ieee80211(mac);
1079 struct ieee80211_rx_stats stats; 1091 struct ieee80211_rx_stats stats;
1080 const struct rx_status *status; 1092 const struct rx_status *status;
1081 struct sk_buff *skb;
1082 1093
1083 if (length < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN + 1094 if (skb->len < ZD_PLCP_HEADER_SIZE + IEEE80211_1ADDR_LEN +
1084 IEEE80211_FCS_LEN + sizeof(struct rx_status)) 1095 IEEE80211_FCS_LEN + sizeof(struct rx_status))
1085 return -EINVAL; 1096 {
1097 dev_dbg_f(zd_mac_dev(mac), "Packet with length %u to small.\n",
1098 skb->len);
1099 goto free_skb;
1100 }
1086 1101
1087 r = fill_rx_stats(&stats, &status, mac, buffer, length); 1102 r = fill_rx_stats(&stats, &status, mac, skb->data, skb->len);
1088 if (r) 1103 if (r) {
1089 return r; 1104 /* Only packets with rx errors are included here. */
1105 goto free_skb;
1106 }
1090 1107
1091 length -= ZD_PLCP_HEADER_SIZE+IEEE80211_FCS_LEN+ 1108 __skb_pull(skb, ZD_PLCP_HEADER_SIZE);
1092 sizeof(struct rx_status); 1109 __skb_trim(skb, skb->len -
1093 buffer += ZD_PLCP_HEADER_SIZE; 1110 (IEEE80211_FCS_LEN + sizeof(struct rx_status)));
1094 1111
1095 update_qual_rssi(mac, buffer, length, stats.signal, stats.rssi); 1112 update_qual_rssi(mac, skb->data, skb->len, stats.signal,
1113 status->signal_strength);
1096 1114
1097 r = filter_rx(ieee, buffer, length, &stats); 1115 r = filter_rx(ieee, skb->data, skb->len, &stats);
1098 if (r <= 0) 1116 if (r <= 0) {
1099 return r; 1117 if (r < 0)
1118 dev_dbg_f(zd_mac_dev(mac), "Error in packet.\n");
1119 goto free_skb;
1120 }
1100 1121
1101 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1102 if (!skb)
1103 return -ENOMEM;
1104 if (ieee->iw_mode == IW_MODE_MONITOR) 1122 if (ieee->iw_mode == IW_MODE_MONITOR)
1105 fill_rt_header(skb_put(skb, sizeof(struct zd_rt_hdr)), mac, 1123 fill_rt_header(skb_push(skb, sizeof(struct zd_rt_hdr)), mac,
1106 &stats, status); 1124 &stats, status);
1107 memcpy(skb_put(skb, length), buffer, length);
1108 1125
1109 r = ieee80211_rx(ieee, skb, &stats); 1126 r = ieee80211_rx(ieee, skb, &stats);
1110 if (!r) 1127 if (r)
1111 dev_kfree_skb_any(skb); 1128 return;
1129free_skb:
1130 /* We are always in a soft irq. */
1131 dev_kfree_skb(skb);
1132}
1133
1134static void do_rx(unsigned long mac_ptr)
1135{
1136 struct zd_mac *mac = (struct zd_mac *)mac_ptr;
1137 struct sk_buff *skb;
1138
1139 while ((skb = skb_dequeue(&mac->rx_queue)) != NULL)
1140 zd_mac_rx(mac, skb);
1141}
1142
1143int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length)
1144{
1145 struct sk_buff *skb;
1146
1147 skb = dev_alloc_skb(sizeof(struct zd_rt_hdr) + length);
1148 if (!skb) {
1149 dev_warn(zd_mac_dev(mac), "Could not allocate skb.\n");
1150 return -ENOMEM;
1151 }
1152 skb_reserve(skb, sizeof(struct zd_rt_hdr));
1153 memcpy(__skb_put(skb, length), buffer, length);
1154 skb_queue_tail(&mac->rx_queue, skb);
1155 tasklet_schedule(&mac->rx_tasklet);
1112 return 0; 1156 return 0;
1113} 1157}
1114 1158
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.h b/drivers/net/wireless/zd1211rw/zd_mac.h
index f0cf05dc7d3e..faf4c7828d4e 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.h
+++ b/drivers/net/wireless/zd1211rw/zd_mac.h
@@ -138,6 +138,9 @@ struct zd_mac {
138 struct delayed_work set_rts_cts_work; 138 struct delayed_work set_rts_cts_work;
139 struct delayed_work set_basic_rates_work; 139 struct delayed_work set_basic_rates_work;
140 140
141 struct tasklet_struct rx_tasklet;
142 struct sk_buff_head rx_queue;
143
141 unsigned int stats_count; 144 unsigned int stats_count;
142 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 145 u8 qual_buffer[ZD_MAC_STATS_BUFFER_SIZE];
143 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE]; 146 u8 rssi_buffer[ZD_MAC_STATS_BUFFER_SIZE];
@@ -193,7 +196,7 @@ int zd_mac_stop(struct net_device *netdev);
193int zd_mac_set_mac_address(struct net_device *dev, void *p); 196int zd_mac_set_mac_address(struct net_device *dev, void *p);
194void zd_mac_set_multicast_list(struct net_device *netdev); 197void zd_mac_set_multicast_list(struct net_device *netdev);
195 198
196int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length); 199int zd_mac_rx_irq(struct zd_mac *mac, const u8 *buffer, unsigned int length);
197 200
198int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain); 201int zd_mac_set_regdomain(struct zd_mac *zd_mac, u8 regdomain);
199u8 zd_mac_get_regdomain(struct zd_mac *zd_mac); 202u8 zd_mac_get_regdomain(struct zd_mac *zd_mac);
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index aa782e88754b..605e96e74057 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -598,13 +598,13 @@ static void handle_rx_packet(struct zd_usb *usb, const u8 *buffer,
598 n = l+k; 598 n = l+k;
599 if (n > length) 599 if (n > length)
600 return; 600 return;
601 zd_mac_rx(mac, buffer+l, k); 601 zd_mac_rx_irq(mac, buffer+l, k);
602 if (i >= 2) 602 if (i >= 2)
603 return; 603 return;
604 l = (n+3) & ~3; 604 l = (n+3) & ~3;
605 } 605 }
606 } else { 606 } else {
607 zd_mac_rx(mac, buffer, length); 607 zd_mac_rx_irq(mac, buffer, length);
608 } 608 }
609} 609}
610 610
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 0b9d0db1590a..bd1faebf61a0 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -1682,7 +1682,7 @@ int __init acpiphp_glue_init(void)
1682 * 1682 *
1683 * This function frees all data allocated in acpiphp_glue_init() 1683 * This function frees all data allocated in acpiphp_glue_init()
1684 */ 1684 */
1685void __exit acpiphp_glue_exit(void) 1685void acpiphp_glue_exit(void)
1686{ 1686{
1687 acpi_pci_unregister_driver(&acpi_pci_hp_driver); 1687 acpi_pci_unregister_driver(&acpi_pci_hp_driver);
1688} 1688}
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index bd40aee10e16..7f03881a8b68 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -319,13 +319,12 @@ static int ibm_get_table_from_acpi(char **bufp)
319 if (bufp == NULL) 319 if (bufp == NULL)
320 goto read_table_done; 320 goto read_table_done;
321 321
322 lbuf = kmalloc(size, GFP_KERNEL); 322 lbuf = kzalloc(size, GFP_KERNEL);
323 dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n", 323 dbg("%s: element count: %i, ASL table size: %i, &table = 0x%p\n",
324 __FUNCTION__, package->package.count, size, lbuf); 324 __FUNCTION__, package->package.count, size, lbuf);
325 325
326 if (lbuf) { 326 if (lbuf) {
327 *bufp = lbuf; 327 *bufp = lbuf;
328 memset(lbuf, 0, size);
329 } else { 328 } else {
330 size = -ENOMEM; 329 size = -ENOMEM;
331 goto read_table_done; 330 goto read_table_done;
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index b771196a654e..3009193f0058 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -47,21 +47,11 @@ static ssize_t location_read_file (struct hotplug_slot *php_slot, char *buf)
47 return retval; 47 return retval;
48} 48}
49 49
50static struct hotplug_slot_attribute hotplug_slot_attr_location = { 50static struct hotplug_slot_attribute php_attr_location = {
51 .attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO}, 51 .attr = {.name = "phy_location", .mode = S_IFREG | S_IRUGO},
52 .show = location_read_file, 52 .show = location_read_file,
53}; 53};
54 54
55static void rpaphp_sysfs_add_attr_location (struct hotplug_slot *slot)
56{
57 sysfs_create_file(&slot->kobj, &hotplug_slot_attr_location.attr);
58}
59
60static void rpaphp_sysfs_remove_attr_location (struct hotplug_slot *slot)
61{
62 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_location.attr);
63}
64
65/* free up the memory used by a slot */ 55/* free up the memory used by a slot */
66static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot) 56static void rpaphp_release_slot(struct hotplug_slot *hotplug_slot)
67{ 57{
@@ -145,7 +135,7 @@ int rpaphp_deregister_slot(struct slot *slot)
145 list_del(&slot->rpaphp_slot_list); 135 list_del(&slot->rpaphp_slot_list);
146 136
147 /* remove "phy_location" file */ 137 /* remove "phy_location" file */
148 rpaphp_sysfs_remove_attr_location(php_slot); 138 sysfs_remove_file(&php_slot->kobj, &php_attr_location.attr);
149 139
150 retval = pci_hp_deregister(php_slot); 140 retval = pci_hp_deregister(php_slot);
151 if (retval) 141 if (retval)
@@ -160,36 +150,45 @@ EXPORT_SYMBOL_GPL(rpaphp_deregister_slot);
160 150
161int rpaphp_register_slot(struct slot *slot) 151int rpaphp_register_slot(struct slot *slot)
162{ 152{
153 struct hotplug_slot *php_slot = slot->hotplug_slot;
163 int retval; 154 int retval;
164 155
165 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n", 156 dbg("%s registering slot:path[%s] index[%x], name[%s] pdomain[%x] type[%d]\n",
166 __FUNCTION__, slot->dn->full_name, slot->index, slot->name, 157 __FUNCTION__, slot->dn->full_name, slot->index, slot->name,
167 slot->power_domain, slot->type); 158 slot->power_domain, slot->type);
159
168 /* should not try to register the same slot twice */ 160 /* should not try to register the same slot twice */
169 if (is_registered(slot)) { /* should't be here */ 161 if (is_registered(slot)) {
170 err("rpaphp_register_slot: slot[%s] is already registered\n", slot->name); 162 err("rpaphp_register_slot: slot[%s] is already registered\n", slot->name);
171 rpaphp_release_slot(slot->hotplug_slot); 163 retval = -EAGAIN;
172 return -EAGAIN; 164 goto register_fail;
173 } 165 }
174 retval = pci_hp_register(slot->hotplug_slot); 166
167 retval = pci_hp_register(php_slot);
175 if (retval) { 168 if (retval) {
176 err("pci_hp_register failed with error %d\n", retval); 169 err("pci_hp_register failed with error %d\n", retval);
177 rpaphp_release_slot(slot->hotplug_slot); 170 goto register_fail;
178 return retval;
179 } 171 }
180
181 /* create "phy_locatoin" file */
182 rpaphp_sysfs_add_attr_location(slot->hotplug_slot);
183 172
184 /* add slot to our internal list */ 173 /* create "phy_location" file */
185 dbg("%s adding slot[%s] to rpaphp_slot_list\n", 174 retval = sysfs_create_file(&php_slot->kobj, &php_attr_location.attr);
186 __FUNCTION__, slot->name); 175 if (retval) {
176 err("sysfs_create_file failed with error %d\n", retval);
177 goto sysfs_fail;
178 }
187 179
180 /* add slot to our internal list */
188 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); 181 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
189 info("Slot [%s](PCI location=%s) registered\n", slot->name, 182 info("Slot [%s](PCI location=%s) registered\n", slot->name,
190 slot->location); 183 slot->location);
191 num_slots++; 184 num_slots++;
192 return 0; 185 return 0;
186
187sysfs_fail:
188 pci_hp_deregister(php_slot);
189register_fail:
190 rpaphp_release_slot(php_slot);
191 return retval;
193} 192}
194 193
195int rpaphp_get_power_status(struct slot *slot, u8 * value) 194int rpaphp_get_power_status(struct slot *slot, u8 * value)
diff --git a/drivers/pci/hotplug/shpchp.h b/drivers/pci/hotplug/shpchp.h
index 50757695844f..3ca6a4f574b3 100644
--- a/drivers/pci/hotplug/shpchp.h
+++ b/drivers/pci/hotplug/shpchp.h
@@ -47,11 +47,17 @@ extern int shpchp_poll_time;
47extern int shpchp_debug; 47extern int shpchp_debug;
48extern struct workqueue_struct *shpchp_wq; 48extern struct workqueue_struct *shpchp_wq;
49 49
50/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/ 50#define dbg(format, arg...) \
51#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0) 51 do { \
52#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) 52 if (shpchp_debug) \
53#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) 53 printk("%s: " format, MY_NAME , ## arg); \
54#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) 54 } while (0)
55#define err(format, arg...) \
56 printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
57#define info(format, arg...) \
58 printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
59#define warn(format, arg...) \
60 printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
55 61
56#define SLOT_NAME_SIZE 10 62#define SLOT_NAME_SIZE 10
57struct slot { 63struct slot {
@@ -83,34 +89,27 @@ struct event_info {
83struct controller { 89struct controller {
84 struct mutex crit_sect; /* critical section mutex */ 90 struct mutex crit_sect; /* critical section mutex */
85 struct mutex cmd_lock; /* command lock */ 91 struct mutex cmd_lock; /* command lock */
86 struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */
87 int num_slots; /* Number of slots on ctlr */ 92 int num_slots; /* Number of slots on ctlr */
88 int slot_num_inc; /* 1 or -1 */ 93 int slot_num_inc; /* 1 or -1 */
89 struct pci_dev *pci_dev; 94 struct pci_dev *pci_dev;
90 struct list_head slot_list; 95 struct list_head slot_list;
91 struct hpc_ops *hpc_ops; 96 struct hpc_ops *hpc_ops;
92 wait_queue_head_t queue; /* sleep & wake process */ 97 wait_queue_head_t queue; /* sleep & wake process */
93 u8 bus;
94 u8 device;
95 u8 function;
96 u8 slot_device_offset; 98 u8 slot_device_offset;
97 u8 add_support;
98 u32 pcix_misc2_reg; /* for amd pogo errata */ 99 u32 pcix_misc2_reg; /* for amd pogo errata */
99 enum pci_bus_speed speed;
100 u32 first_slot; /* First physical slot number */ 100 u32 first_slot; /* First physical slot number */
101 u8 slot_bus; /* Bus where the slots handled by this controller sit */
102 u32 cap_offset; 101 u32 cap_offset;
103 unsigned long mmio_base; 102 unsigned long mmio_base;
104 unsigned long mmio_size; 103 unsigned long mmio_size;
104 void __iomem *creg;
105 struct timer_list poll_timer;
105}; 106};
106 107
107
108/* Define AMD SHPC ID */ 108/* Define AMD SHPC ID */
109#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 109#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
110#define PCI_DEVICE_ID_AMD_POGO_7458 0x7458 110#define PCI_DEVICE_ID_AMD_POGO_7458 0x7458
111 111
112/* AMD PCIX bridge registers */ 112/* AMD PCIX bridge registers */
113
114#define PCIX_MEM_BASE_LIMIT_OFFSET 0x1C 113#define PCIX_MEM_BASE_LIMIT_OFFSET 0x1C
115#define PCIX_MISCII_OFFSET 0x48 114#define PCIX_MISCII_OFFSET 0x48
116#define PCIX_MISC_BRIDGE_ERRORS_OFFSET 0x80 115#define PCIX_MISC_BRIDGE_ERRORS_OFFSET 0x80
@@ -145,8 +144,6 @@ struct controller {
145#define POWERON_STATE 3 144#define POWERON_STATE 3
146#define POWEROFF_STATE 4 145#define POWEROFF_STATE 4
147 146
148#define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
149
150/* Error messages */ 147/* Error messages */
151#define INTERLOCK_OPEN 0x00000002 148#define INTERLOCK_OPEN 0x00000002
152#define ADD_NOT_SUPPORTED 0x00000003 149#define ADD_NOT_SUPPORTED 0x00000003
@@ -158,50 +155,32 @@ struct controller {
158#define WRONG_BUS_FREQUENCY 0x0000000D 155#define WRONG_BUS_FREQUENCY 0x0000000D
159#define POWER_FAILURE 0x0000000E 156#define POWER_FAILURE 0x0000000E
160 157
161#define REMOVE_NOT_SUPPORTED 0x00000003
162
163#define DISABLE_CARD 1
164
165/*
166 * error Messages
167 */
168#define msg_initialization_err "Initialization failure, error=%d\n"
169#define msg_button_on "PCI slot #%s - powering on due to button press.\n"
170#define msg_button_off "PCI slot #%s - powering off due to button press.\n"
171#define msg_button_cancel "PCI slot #%s - action canceled due to button press.\n"
172
173/* sysfs functions for the hotplug controller info */
174extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl); 158extern int __must_check shpchp_create_ctrl_files(struct controller *ctrl);
175 159extern void shpchp_remove_ctrl_files(struct controller *ctrl);
176extern int shpchp_sysfs_enable_slot(struct slot *slot); 160extern int shpchp_sysfs_enable_slot(struct slot *slot);
177extern int shpchp_sysfs_disable_slot(struct slot *slot); 161extern int shpchp_sysfs_disable_slot(struct slot *slot);
178 162extern u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl);
179extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id); 163extern u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl);
180extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id); 164extern u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl);
181extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id); 165extern u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl);
182extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id); 166extern int shpchp_configure_device(struct slot *p_slot);
183 167extern int shpchp_unconfigure_device(struct slot *p_slot);
184/* pci functions */ 168extern void cleanup_slots(struct controller *ctrl);
185extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num); 169extern void queue_pushbutton_work(struct work_struct *work);
186extern int shpchp_configure_device(struct slot *p_slot); 170extern int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
187extern int shpchp_unconfigure_device(struct slot *p_slot);
188extern void shpchp_remove_ctrl_files(struct controller *ctrl);
189extern void cleanup_slots(struct controller *ctrl);
190extern void queue_pushbutton_work(struct work_struct *work);
191
192 171
193#ifdef CONFIG_ACPI 172#ifdef CONFIG_ACPI
194static inline int get_hp_params_from_firmware(struct pci_dev *dev, 173static inline int get_hp_params_from_firmware(struct pci_dev *dev,
195 struct hotplug_params *hpp) 174 struct hotplug_params *hpp)
196{ 175{
197 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp))) 176 if (ACPI_FAILURE(acpi_get_hp_params_from_firmware(dev->bus, hpp)))
198 return -ENODEV; 177 return -ENODEV;
199 return 0; 178 return 0;
200} 179}
201#define get_hp_hw_control_from_firmware(pdev) \ 180#define get_hp_hw_control_from_firmware(pdev) \
202 do { \ 181 do { \
203 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \ 182 if (DEVICE_ACPI_HANDLE(&(pdev->dev))) \
204 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev))); \ 183 acpi_run_oshp(DEVICE_ACPI_HANDLE(&(pdev->dev)));\
205 } while (0) 184 } while (0)
206#else 185#else
207#define get_hp_params_from_firmware(dev, hpp) (-ENODEV) 186#define get_hp_params_from_firmware(dev, hpp) (-ENODEV)
@@ -222,108 +201,40 @@ struct ctrl_reg {
222 volatile u32 serr_loc; 201 volatile u32 serr_loc;
223 volatile u32 serr_intr_enable; 202 volatile u32 serr_intr_enable;
224 volatile u32 slot1; 203 volatile u32 slot1;
225 volatile u32 slot2;
226 volatile u32 slot3;
227 volatile u32 slot4;
228 volatile u32 slot5;
229 volatile u32 slot6;
230 volatile u32 slot7;
231 volatile u32 slot8;
232 volatile u32 slot9;
233 volatile u32 slot10;
234 volatile u32 slot11;
235 volatile u32 slot12;
236} __attribute__ ((packed)); 204} __attribute__ ((packed));
237 205
238/* offsets to the controller registers based on the above structure layout */ 206/* offsets to the controller registers based on the above structure layout */
239enum ctrl_offsets { 207enum ctrl_offsets {
240 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset), 208 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
241 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1), 209 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
242 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2), 210 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
243 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config), 211 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
244 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config), 212 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
245 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl), 213 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
246 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface), 214 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
247 CMD = offsetof(struct ctrl_reg, cmd), 215 CMD = offsetof(struct ctrl_reg, cmd),
248 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status), 216 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
249 INTR_LOC = offsetof(struct ctrl_reg, intr_loc), 217 INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
250 SERR_LOC = offsetof(struct ctrl_reg, serr_loc), 218 SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
251 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable), 219 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
252 SLOT1 = offsetof(struct ctrl_reg, slot1), 220 SLOT1 = offsetof(struct ctrl_reg, slot1),
253 SLOT2 = offsetof(struct ctrl_reg, slot2),
254 SLOT3 = offsetof(struct ctrl_reg, slot3),
255 SLOT4 = offsetof(struct ctrl_reg, slot4),
256 SLOT5 = offsetof(struct ctrl_reg, slot5),
257 SLOT6 = offsetof(struct ctrl_reg, slot6),
258 SLOT7 = offsetof(struct ctrl_reg, slot7),
259 SLOT8 = offsetof(struct ctrl_reg, slot8),
260 SLOT9 = offsetof(struct ctrl_reg, slot9),
261 SLOT10 = offsetof(struct ctrl_reg, slot10),
262 SLOT11 = offsetof(struct ctrl_reg, slot11),
263 SLOT12 = offsetof(struct ctrl_reg, slot12),
264};
265typedef u8(*php_intr_callback_t) (u8 hp_slot, void *instance_id);
266struct php_ctlr_state_s {
267 struct php_ctlr_state_s *pnext;
268 struct pci_dev *pci_dev;
269 unsigned int irq;
270 unsigned long flags; /* spinlock's */
271 u32 slot_device_offset;
272 u32 num_slots;
273 struct timer_list int_poll_timer; /* Added for poll event */
274 php_intr_callback_t attention_button_callback;
275 php_intr_callback_t switch_change_callback;
276 php_intr_callback_t presence_change_callback;
277 php_intr_callback_t power_fault_callback;
278 void *callback_instance_id;
279 void __iomem *creg; /* Ptr to controller register space */
280}; 221};
281/* Inline functions */
282 222
283 223static inline struct slot *get_slot(struct hotplug_slot *hotplug_slot)
284/* Inline functions to check the sanity of a pointer that is passed to us */
285static inline int slot_paranoia_check (struct slot *slot, const char *function)
286{
287 if (!slot) {
288 dbg("%s - slot == NULL", function);
289 return -1;
290 }
291 if (!slot->hotplug_slot) {
292 dbg("%s - slot->hotplug_slot == NULL!", function);
293 return -1;
294 }
295 return 0;
296}
297
298static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
299{ 224{
300 struct slot *slot; 225 return hotplug_slot->private;
301
302 if (!hotplug_slot) {
303 dbg("%s - hotplug_slot == NULL\n", function);
304 return NULL;
305 }
306
307 slot = (struct slot *)hotplug_slot->private;
308 if (slot_paranoia_check (slot, function))
309 return NULL;
310 return slot;
311} 226}
312 227
313static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device) 228static inline struct slot *shpchp_find_slot(struct controller *ctrl, u8 device)
314{ 229{
315 struct slot *slot; 230 struct slot *slot;
316 231
317 if (!ctrl)
318 return NULL;
319
320 list_for_each_entry(slot, &ctrl->slot_list, slot_list) { 232 list_for_each_entry(slot, &ctrl->slot_list, slot_list) {
321 if (slot->device == device) 233 if (slot->device == device)
322 return slot; 234 return slot;
323 } 235 }
324 236
325 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device); 237 err("%s: slot (device=0x%x) not found\n", __FUNCTION__, device);
326
327 return NULL; 238 return NULL;
328} 239}
329 240
@@ -400,44 +311,27 @@ static inline void amd_pogo_errata_restore_misc_reg(struct slot *p_slot)
400 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp); 311 pci_write_config_dword(p_slot->ctrl->pci_dev, PCIX_MISCII_OFFSET, pcix_misc2_temp);
401} 312}
402 313
403enum php_ctlr_type {
404 PCI,
405 ISA,
406 ACPI
407};
408
409int shpc_init( struct controller *ctrl, struct pci_dev *pdev);
410
411int shpc_get_ctlr_slot_config( struct controller *ctrl,
412 int *num_ctlr_slots,
413 int *first_device_num,
414 int *physical_slot_num,
415 int *updown,
416 int *flags);
417
418struct hpc_ops { 314struct hpc_ops {
419 int (*power_on_slot ) (struct slot *slot); 315 int (*power_on_slot)(struct slot *slot);
420 int (*slot_enable ) (struct slot *slot); 316 int (*slot_enable)(struct slot *slot);
421 int (*slot_disable ) (struct slot *slot); 317 int (*slot_disable)(struct slot *slot);
422 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed); 318 int (*set_bus_speed_mode)(struct slot *slot, enum pci_bus_speed speed);
423 int (*get_power_status) (struct slot *slot, u8 *status); 319 int (*get_power_status)(struct slot *slot, u8 *status);
424 int (*get_attention_status) (struct slot *slot, u8 *status); 320 int (*get_attention_status)(struct slot *slot, u8 *status);
425 int (*set_attention_status) (struct slot *slot, u8 status); 321 int (*set_attention_status)(struct slot *slot, u8 status);
426 int (*get_latch_status) (struct slot *slot, u8 *status); 322 int (*get_latch_status)(struct slot *slot, u8 *status);
427 int (*get_adapter_status) (struct slot *slot, u8 *status); 323 int (*get_adapter_status)(struct slot *slot, u8 *status);
428 324 int (*get_max_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
429 int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 325 int (*get_cur_bus_speed)(struct slot *slot, enum pci_bus_speed *speed);
430 int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); 326 int (*get_adapter_speed)(struct slot *slot, enum pci_bus_speed *speed);
431 int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed); 327 int (*get_mode1_ECC_cap)(struct slot *slot, u8 *mode);
432 int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode); 328 int (*get_prog_int)(struct slot *slot, u8 *prog_int);
433 int (*get_prog_int) (struct slot *slot, u8 *prog_int); 329 int (*query_power_fault)(struct slot *slot);
434 330 void (*green_led_on)(struct slot *slot);
435 int (*query_power_fault) (struct slot *slot); 331 void (*green_led_off)(struct slot *slot);
436 void (*green_led_on) (struct slot *slot); 332 void (*green_led_blink)(struct slot *slot);
437 void (*green_led_off) (struct slot *slot); 333 void (*release_ctlr)(struct controller *ctrl);
438 void (*green_led_blink) (struct slot *slot); 334 int (*check_cmd_status)(struct controller *ctrl);
439 void (*release_ctlr) (struct controller *ctrl);
440 int (*check_cmd_status) (struct controller *ctrl);
441}; 335};
442 336
443#endif /* _SHPCHP_H */ 337#endif /* _SHPCHP_H */
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 4eac85b3d90e..590cd3cbe010 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -104,23 +104,6 @@ static void make_slot_name(struct slot *slot)
104 slot->bus, slot->number); 104 slot->bus, slot->number);
105} 105}
106 106
107
108
109
110static int
111shpchprm_get_physical_slot_number(struct controller *ctrl, u32 *sun,
112 u8 busnum, u8 devnum)
113{
114 int offset = devnum - ctrl->slot_device_offset;
115
116 dbg("%s: ctrl->slot_num_inc %d, offset %d\n", __FUNCTION__,
117 ctrl->slot_num_inc, offset);
118 *sun = (u8) (ctrl->first_slot + ctrl->slot_num_inc *offset);
119 return 0;
120}
121
122
123
124static int init_slots(struct controller *ctrl) 107static int init_slots(struct controller *ctrl)
125{ 108{
126 struct slot *slot; 109 struct slot *slot;
@@ -128,7 +111,6 @@ static int init_slots(struct controller *ctrl)
128 struct hotplug_slot_info *info; 111 struct hotplug_slot_info *info;
129 int retval = -ENOMEM; 112 int retval = -ENOMEM;
130 int i; 113 int i;
131 u32 sun;
132 114
133 for (i = 0; i < ctrl->num_slots; i++) { 115 for (i = 0; i < ctrl->num_slots; i++) {
134 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 116 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
@@ -149,16 +131,11 @@ static int init_slots(struct controller *ctrl)
149 131
150 slot->hp_slot = i; 132 slot->hp_slot = i;
151 slot->ctrl = ctrl; 133 slot->ctrl = ctrl;
152 slot->bus = ctrl->slot_bus; 134 slot->bus = ctrl->pci_dev->subordinate->number;
153 slot->device = ctrl->slot_device_offset + i; 135 slot->device = ctrl->slot_device_offset + i;
154 slot->hpc_ops = ctrl->hpc_ops; 136 slot->hpc_ops = ctrl->hpc_ops;
137 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
155 mutex_init(&slot->lock); 138 mutex_init(&slot->lock);
156
157 if (shpchprm_get_physical_slot_number(ctrl, &sun,
158 slot->bus, slot->device))
159 goto error_info;
160
161 slot->number = sun;
162 INIT_DELAYED_WORK(&slot->work, queue_pushbutton_work); 139 INIT_DELAYED_WORK(&slot->work, queue_pushbutton_work);
163 140
164 /* register this slot with the hotplug pci core */ 141 /* register this slot with the hotplug pci core */
@@ -211,42 +188,12 @@ void cleanup_slots(struct controller *ctrl)
211 } 188 }
212} 189}
213 190
214static int get_ctlr_slot_config(struct controller *ctrl)
215{
216 int num_ctlr_slots;
217 int first_device_num;
218 int physical_slot_num;
219 int updown;
220 int rc;
221 int flags;
222
223 rc = shpc_get_ctlr_slot_config(ctrl, &num_ctlr_slots,
224 &first_device_num, &physical_slot_num,
225 &updown, &flags);
226 if (rc) {
227 err("%s: get_ctlr_slot_config fail for b:d (%x:%x)\n",
228 __FUNCTION__, ctrl->bus, ctrl->device);
229 return -1;
230 }
231
232 ctrl->num_slots = num_ctlr_slots;
233 ctrl->slot_device_offset = first_device_num;
234 ctrl->first_slot = physical_slot_num;
235 ctrl->slot_num_inc = updown; /* either -1 or 1 */
236
237 dbg("%s: num_slot(0x%x) 1st_dev(0x%x) psn(0x%x) updown(%d) for b:d "
238 "(%x:%x)\n", __FUNCTION__, num_ctlr_slots, first_device_num,
239 physical_slot_num, updown, ctrl->bus, ctrl->device);
240
241 return 0;
242}
243
244/* 191/*
245 * set_attention_status - Turns the Amber LED for a slot on, off or blink 192 * set_attention_status - Turns the Amber LED for a slot on, off or blink
246 */ 193 */
247static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status) 194static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
248{ 195{
249 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 196 struct slot *slot = get_slot(hotplug_slot);
250 197
251 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 198 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
252 199
@@ -258,7 +205,7 @@ static int set_attention_status (struct hotplug_slot *hotplug_slot, u8 status)
258 205
259static int enable_slot (struct hotplug_slot *hotplug_slot) 206static int enable_slot (struct hotplug_slot *hotplug_slot)
260{ 207{
261 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 208 struct slot *slot = get_slot(hotplug_slot);
262 209
263 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 210 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
264 211
@@ -267,7 +214,7 @@ static int enable_slot (struct hotplug_slot *hotplug_slot)
267 214
268static int disable_slot (struct hotplug_slot *hotplug_slot) 215static int disable_slot (struct hotplug_slot *hotplug_slot)
269{ 216{
270 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 217 struct slot *slot = get_slot(hotplug_slot);
271 218
272 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 219 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
273 220
@@ -276,7 +223,7 @@ static int disable_slot (struct hotplug_slot *hotplug_slot)
276 223
277static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value) 224static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
278{ 225{
279 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 226 struct slot *slot = get_slot(hotplug_slot);
280 int retval; 227 int retval;
281 228
282 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 229 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -290,7 +237,7 @@ static int get_power_status (struct hotplug_slot *hotplug_slot, u8 *value)
290 237
291static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value) 238static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
292{ 239{
293 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 240 struct slot *slot = get_slot(hotplug_slot);
294 int retval; 241 int retval;
295 242
296 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 243 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -304,7 +251,7 @@ static int get_attention_status (struct hotplug_slot *hotplug_slot, u8 *value)
304 251
305static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value) 252static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
306{ 253{
307 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 254 struct slot *slot = get_slot(hotplug_slot);
308 int retval; 255 int retval;
309 256
310 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 257 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -318,7 +265,7 @@ static int get_latch_status (struct hotplug_slot *hotplug_slot, u8 *value)
318 265
319static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value) 266static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
320{ 267{
321 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 268 struct slot *slot = get_slot(hotplug_slot);
322 int retval; 269 int retval;
323 270
324 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 271 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -332,7 +279,7 @@ static int get_adapter_status (struct hotplug_slot *hotplug_slot, u8 *value)
332 279
333static int get_address (struct hotplug_slot *hotplug_slot, u32 *value) 280static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
334{ 281{
335 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 282 struct slot *slot = get_slot(hotplug_slot);
336 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate; 283 struct pci_bus *bus = slot->ctrl->pci_dev->subordinate;
337 284
338 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 285 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -344,7 +291,7 @@ static int get_address (struct hotplug_slot *hotplug_slot, u32 *value)
344 291
345static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 292static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
346{ 293{
347 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 294 struct slot *slot = get_slot(hotplug_slot);
348 int retval; 295 int retval;
349 296
350 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 297 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -358,7 +305,7 @@ static int get_max_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_sp
358 305
359static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value) 306static int get_cur_bus_speed (struct hotplug_slot *hotplug_slot, enum pci_bus_speed *value)
360{ 307{
361 struct slot *slot = get_slot(hotplug_slot, __FUNCTION__); 308 struct slot *slot = get_slot(hotplug_slot);
362 int retval; 309 int retval;
363 310
364 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name); 311 dbg("%s - physical_slot = %s\n", __FUNCTION__, hotplug_slot->name);
@@ -385,9 +332,6 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
385{ 332{
386 int rc; 333 int rc;
387 struct controller *ctrl; 334 struct controller *ctrl;
388 struct slot *t_slot;
389 int first_device_num; /* first PCI device number */
390 int num_ctlr_slots; /* number of slots implemented */
391 335
392 if (!is_shpc_capable(pdev)) 336 if (!is_shpc_capable(pdev))
393 return -ENODEV; 337 return -ENODEV;
@@ -408,47 +352,13 @@ static int shpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
408 352
409 pci_set_drvdata(pdev, ctrl); 353 pci_set_drvdata(pdev, ctrl);
410 354
411 ctrl->bus = pdev->bus->number;
412 ctrl->slot_bus = pdev->subordinate->number;
413 ctrl->device = PCI_SLOT(pdev->devfn);
414 ctrl->function = PCI_FUNC(pdev->devfn);
415
416 dbg("ctrl bus=0x%x, device=%x, function=%x, irq=%x\n",
417 ctrl->bus, ctrl->device, ctrl->function, pdev->irq);
418
419 /*
420 * Save configuration headers for this and subordinate PCI buses
421 */
422 rc = get_ctlr_slot_config(ctrl);
423 if (rc) {
424 err(msg_initialization_err, rc);
425 goto err_out_release_ctlr;
426 }
427 first_device_num = ctrl->slot_device_offset;
428 num_ctlr_slots = ctrl->num_slots;
429
430 ctrl->add_support = 1;
431
432 /* Setup the slot information structures */ 355 /* Setup the slot information structures */
433 rc = init_slots(ctrl); 356 rc = init_slots(ctrl);
434 if (rc) { 357 if (rc) {
435 err(msg_initialization_err, 6); 358 err("%s: slot initialization failed\n", SHPC_MODULE_NAME);
436 goto err_out_release_ctlr; 359 goto err_out_release_ctlr;
437 } 360 }
438 361
439 /* Now hpc_functions (slot->hpc_ops->functions) are ready */
440 t_slot = shpchp_find_slot(ctrl, first_device_num);
441
442 /* Check for operation bus speed */
443 rc = t_slot->hpc_ops->get_cur_bus_speed(t_slot, &ctrl->speed);
444 dbg("%s: t_slot->hp_slot %x\n", __FUNCTION__,t_slot->hp_slot);
445
446 if (rc || ctrl->speed == PCI_SPEED_UNKNOWN) {
447 err(SHPC_MODULE_NAME ": Can't get current bus speed. "
448 "Set to 33MHz PCI.\n");
449 ctrl->speed = PCI_SPEED_33MHz;
450 }
451
452 rc = shpchp_create_ctrl_files(ctrl); 362 rc = shpchp_create_ctrl_files(ctrl);
453 if (rc) 363 if (rc)
454 goto err_cleanup_slots; 364 goto err_cleanup_slots;
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index 158ac7836096..6bb84734cd6c 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -57,9 +57,8 @@ static int queue_interrupt_event(struct slot *p_slot, u32 event_type)
57 return 0; 57 return 0;
58} 58}
59 59
60u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id) 60u8 shpchp_handle_attention_button(u8 hp_slot, struct controller *ctrl)
61{ 61{
62 struct controller *ctrl = (struct controller *) inst_id;
63 struct slot *p_slot; 62 struct slot *p_slot;
64 u32 event_type; 63 u32 event_type;
65 64
@@ -81,9 +80,8 @@ u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id)
81 80
82} 81}
83 82
84u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id) 83u8 shpchp_handle_switch_change(u8 hp_slot, struct controller *ctrl)
85{ 84{
86 struct controller *ctrl = (struct controller *) inst_id;
87 struct slot *p_slot; 85 struct slot *p_slot;
88 u8 getstatus; 86 u8 getstatus;
89 u32 event_type; 87 u32 event_type;
@@ -120,9 +118,8 @@ u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id)
120 return 1; 118 return 1;
121} 119}
122 120
123u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id) 121u8 shpchp_handle_presence_change(u8 hp_slot, struct controller *ctrl)
124{ 122{
125 struct controller *ctrl = (struct controller *) inst_id;
126 struct slot *p_slot; 123 struct slot *p_slot;
127 u32 event_type; 124 u32 event_type;
128 125
@@ -154,9 +151,8 @@ u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id)
154 return 1; 151 return 1;
155} 152}
156 153
157u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id) 154u8 shpchp_handle_power_fault(u8 hp_slot, struct controller *ctrl)
158{ 155{
159 struct controller *ctrl = (struct controller *) inst_id;
160 struct slot *p_slot; 156 struct slot *p_slot;
161 u32 event_type; 157 u32 event_type;
162 158
@@ -497,10 +493,12 @@ static void handle_button_press_event(struct slot *p_slot)
497 p_slot->hpc_ops->get_power_status(p_slot, &getstatus); 493 p_slot->hpc_ops->get_power_status(p_slot, &getstatus);
498 if (getstatus) { 494 if (getstatus) {
499 p_slot->state = BLINKINGOFF_STATE; 495 p_slot->state = BLINKINGOFF_STATE;
500 info(msg_button_off, p_slot->name); 496 info("PCI slot #%s - powering off due to button "
497 "press.\n", p_slot->name);
501 } else { 498 } else {
502 p_slot->state = BLINKINGON_STATE; 499 p_slot->state = BLINKINGON_STATE;
503 info(msg_button_on, p_slot->name); 500 info("PCI slot #%s - powering on due to button "
501 "press.\n", p_slot->name);
504 } 502 }
505 /* blink green LED and turn off amber */ 503 /* blink green LED and turn off amber */
506 p_slot->hpc_ops->green_led_blink(p_slot); 504 p_slot->hpc_ops->green_led_blink(p_slot);
@@ -523,7 +521,8 @@ static void handle_button_press_event(struct slot *p_slot)
523 else 521 else
524 p_slot->hpc_ops->green_led_off(p_slot); 522 p_slot->hpc_ops->green_led_off(p_slot);
525 p_slot->hpc_ops->set_attention_status(p_slot, 0); 523 p_slot->hpc_ops->set_attention_status(p_slot, 0);
526 info(msg_button_cancel, p_slot->name); 524 info("PCI slot #%s - action canceled due to button press\n",
525 p_slot->name);
527 p_slot->state = STATIC_STATE; 526 p_slot->state = STATIC_STATE;
528 break; 527 break;
529 case POWEROFF_STATE: 528 case POWEROFF_STATE:
diff --git a/drivers/pci/hotplug/shpchp_hpc.c b/drivers/pci/hotplug/shpchp_hpc.c
index 83a5226ba9ed..b7bede4b7c27 100644
--- a/drivers/pci/hotplug/shpchp_hpc.c
+++ b/drivers/pci/hotplug/shpchp_hpc.c
@@ -212,44 +212,40 @@
212#define SLOT_SERR_INT_MASK 0x3 212#define SLOT_SERR_INT_MASK 0x3
213 213
214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */ 214DEFINE_DBG_BUFFER /* Debug string buffer for entire HPC defined here */
215static struct php_ctlr_state_s *php_ctlr_list_head; /* HPC state linked list */
216static int ctlr_seq_num = 0; /* Controller sequenc # */
217static spinlock_t list_lock;
218
219static atomic_t shpchp_num_controllers = ATOMIC_INIT(0); 215static atomic_t shpchp_num_controllers = ATOMIC_INIT(0);
220 216
221static irqreturn_t shpc_isr(int irq, void *dev_id); 217static irqreturn_t shpc_isr(int irq, void *dev_id);
222static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec); 218static void start_int_poll_timer(struct controller *ctrl, int sec);
223static int hpc_check_cmd_status(struct controller *ctrl); 219static int hpc_check_cmd_status(struct controller *ctrl);
224 220
225static inline u8 shpc_readb(struct controller *ctrl, int reg) 221static inline u8 shpc_readb(struct controller *ctrl, int reg)
226{ 222{
227 return readb(ctrl->hpc_ctlr_handle->creg + reg); 223 return readb(ctrl->creg + reg);
228} 224}
229 225
230static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val) 226static inline void shpc_writeb(struct controller *ctrl, int reg, u8 val)
231{ 227{
232 writeb(val, ctrl->hpc_ctlr_handle->creg + reg); 228 writeb(val, ctrl->creg + reg);
233} 229}
234 230
235static inline u16 shpc_readw(struct controller *ctrl, int reg) 231static inline u16 shpc_readw(struct controller *ctrl, int reg)
236{ 232{
237 return readw(ctrl->hpc_ctlr_handle->creg + reg); 233 return readw(ctrl->creg + reg);
238} 234}
239 235
240static inline void shpc_writew(struct controller *ctrl, int reg, u16 val) 236static inline void shpc_writew(struct controller *ctrl, int reg, u16 val)
241{ 237{
242 writew(val, ctrl->hpc_ctlr_handle->creg + reg); 238 writew(val, ctrl->creg + reg);
243} 239}
244 240
245static inline u32 shpc_readl(struct controller *ctrl, int reg) 241static inline u32 shpc_readl(struct controller *ctrl, int reg)
246{ 242{
247 return readl(ctrl->hpc_ctlr_handle->creg + reg); 243 return readl(ctrl->creg + reg);
248} 244}
249 245
250static inline void shpc_writel(struct controller *ctrl, int reg, u32 val) 246static inline void shpc_writel(struct controller *ctrl, int reg, u32 val)
251{ 247{
252 writel(val, ctrl->hpc_ctlr_handle->creg + reg); 248 writel(val, ctrl->creg + reg);
253} 249}
254 250
255static inline int shpc_indirect_read(struct controller *ctrl, int index, 251static inline int shpc_indirect_read(struct controller *ctrl, int index,
@@ -268,21 +264,20 @@ static inline int shpc_indirect_read(struct controller *ctrl, int index,
268/* 264/*
269 * This is the interrupt polling timeout function. 265 * This is the interrupt polling timeout function.
270 */ 266 */
271static void int_poll_timeout(unsigned long lphp_ctlr) 267static void int_poll_timeout(unsigned long data)
272{ 268{
273 struct php_ctlr_state_s *php_ctlr = 269 struct controller *ctrl = (struct controller *)data;
274 (struct php_ctlr_state_s *)lphp_ctlr;
275 270
276 DBG_ENTER_ROUTINE 271 DBG_ENTER_ROUTINE
277 272
278 /* Poll for interrupt events. regs == NULL => polling */ 273 /* Poll for interrupt events. regs == NULL => polling */
279 shpc_isr(0, php_ctlr->callback_instance_id); 274 shpc_isr(0, ctrl);
280 275
281 init_timer(&php_ctlr->int_poll_timer); 276 init_timer(&ctrl->poll_timer);
282 if (!shpchp_poll_time) 277 if (!shpchp_poll_time)
283 shpchp_poll_time = 2; /* default polling interval is 2 sec */ 278 shpchp_poll_time = 2; /* default polling interval is 2 sec */
284 279
285 start_int_poll_timer(php_ctlr, shpchp_poll_time); 280 start_int_poll_timer(ctrl, shpchp_poll_time);
286 281
287 DBG_LEAVE_ROUTINE 282 DBG_LEAVE_ROUTINE
288} 283}
@@ -290,16 +285,16 @@ static void int_poll_timeout(unsigned long lphp_ctlr)
290/* 285/*
291 * This function starts the interrupt polling timer. 286 * This function starts the interrupt polling timer.
292 */ 287 */
293static void start_int_poll_timer(struct php_ctlr_state_s *php_ctlr, int sec) 288static void start_int_poll_timer(struct controller *ctrl, int sec)
294{ 289{
295 /* Clamp to sane value */ 290 /* Clamp to sane value */
296 if ((sec <= 0) || (sec > 60)) 291 if ((sec <= 0) || (sec > 60))
297 sec = 2; 292 sec = 2;
298 293
299 php_ctlr->int_poll_timer.function = &int_poll_timeout; 294 ctrl->poll_timer.function = &int_poll_timeout;
300 php_ctlr->int_poll_timer.data = (unsigned long)php_ctlr; 295 ctrl->poll_timer.data = (unsigned long)ctrl;
301 php_ctlr->int_poll_timer.expires = jiffies + sec * HZ; 296 ctrl->poll_timer.expires = jiffies + sec * HZ;
302 add_timer(&php_ctlr->int_poll_timer); 297 add_timer(&ctrl->poll_timer);
303} 298}
304 299
305static inline int is_ctrl_busy(struct controller *ctrl) 300static inline int is_ctrl_busy(struct controller *ctrl)
@@ -666,33 +661,8 @@ static void hpc_set_green_led_blink(struct slot *slot)
666 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK); 661 shpc_write_cmd(slot, slot->hp_slot, SET_PWR_BLINK);
667} 662}
668 663
669int shpc_get_ctlr_slot_config(struct controller *ctrl,
670 int *num_ctlr_slots, /* number of slots in this HPC */
671 int *first_device_num, /* PCI dev num of the first slot in this SHPC */
672 int *physical_slot_num, /* phy slot num of the first slot in this SHPC */
673 int *updown, /* physical_slot_num increament: 1 or -1 */
674 int *flags)
675{
676 u32 slot_config;
677
678 DBG_ENTER_ROUTINE
679
680 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
681 *first_device_num = (slot_config & FIRST_DEV_NUM) >> 8;
682 *num_ctlr_slots = slot_config & SLOT_NUM;
683 *physical_slot_num = (slot_config & PSN) >> 16;
684 *updown = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
685
686 dbg("%s: physical_slot_num = %x\n", __FUNCTION__, *physical_slot_num);
687
688 DBG_LEAVE_ROUTINE
689 return 0;
690}
691
692static void hpc_release_ctlr(struct controller *ctrl) 664static void hpc_release_ctlr(struct controller *ctrl)
693{ 665{
694 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
695 struct php_ctlr_state_s *p, *p_prev;
696 int i; 666 int i;
697 u32 slot_reg, serr_int; 667 u32 slot_reg, serr_int;
698 668
@@ -722,40 +692,15 @@ static void hpc_release_ctlr(struct controller *ctrl)
722 serr_int &= ~SERR_INTR_RSVDZ_MASK; 692 serr_int &= ~SERR_INTR_RSVDZ_MASK;
723 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int); 693 shpc_writel(ctrl, SERR_INTR_ENABLE, serr_int);
724 694
725 if (shpchp_poll_mode) { 695 if (shpchp_poll_mode)
726 del_timer(&php_ctlr->int_poll_timer); 696 del_timer(&ctrl->poll_timer);
727 } else { 697 else {
728 if (php_ctlr->irq) { 698 free_irq(ctrl->pci_dev->irq, ctrl);
729 free_irq(php_ctlr->irq, ctrl); 699 pci_disable_msi(ctrl->pci_dev);
730 php_ctlr->irq = 0;
731 pci_disable_msi(php_ctlr->pci_dev);
732 }
733 }
734
735 if (php_ctlr->pci_dev) {
736 iounmap(php_ctlr->creg);
737 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
738 php_ctlr->pci_dev = NULL;
739 }
740
741 spin_lock(&list_lock);
742 p = php_ctlr_list_head;
743 p_prev = NULL;
744 while (p) {
745 if (p == php_ctlr) {
746 if (p_prev)
747 p_prev->pnext = p->pnext;
748 else
749 php_ctlr_list_head = p->pnext;
750 break;
751 } else {
752 p_prev = p;
753 p = p->pnext;
754 }
755 } 700 }
756 spin_unlock(&list_lock);
757 701
758 kfree(php_ctlr); 702 iounmap(ctrl->creg);
703 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
759 704
760 /* 705 /*
761 * If this is the last controller to be released, destroy the 706 * If this is the last controller to be released, destroy the
@@ -764,8 +709,7 @@ static void hpc_release_ctlr(struct controller *ctrl)
764 if (atomic_dec_and_test(&shpchp_num_controllers)) 709 if (atomic_dec_and_test(&shpchp_num_controllers))
765 destroy_workqueue(shpchp_wq); 710 destroy_workqueue(shpchp_wq);
766 711
767DBG_LEAVE_ROUTINE 712 DBG_LEAVE_ROUTINE
768
769} 713}
770 714
771static int hpc_power_on_slot(struct slot * slot) 715static int hpc_power_on_slot(struct slot * slot)
@@ -891,7 +835,6 @@ static int hpc_set_bus_speed_mode(struct slot * slot, enum pci_bus_speed value)
891static irqreturn_t shpc_isr(int irq, void *dev_id) 835static irqreturn_t shpc_isr(int irq, void *dev_id)
892{ 836{
893 struct controller *ctrl = (struct controller *)dev_id; 837 struct controller *ctrl = (struct controller *)dev_id;
894 struct php_ctlr_state_s *php_ctlr = ctrl->hpc_ctlr_handle;
895 u32 serr_int, slot_reg, intr_loc, intr_loc2; 838 u32 serr_int, slot_reg, intr_loc, intr_loc2;
896 int hp_slot; 839 int hp_slot;
897 840
@@ -942,20 +885,16 @@ static irqreturn_t shpc_isr(int irq, void *dev_id)
942 __FUNCTION__, hp_slot, slot_reg); 885 __FUNCTION__, hp_slot, slot_reg);
943 886
944 if (slot_reg & MRL_CHANGE_DETECTED) 887 if (slot_reg & MRL_CHANGE_DETECTED)
945 php_ctlr->switch_change_callback( 888 shpchp_handle_switch_change(hp_slot, ctrl);
946 hp_slot, php_ctlr->callback_instance_id);
947 889
948 if (slot_reg & BUTTON_PRESS_DETECTED) 890 if (slot_reg & BUTTON_PRESS_DETECTED)
949 php_ctlr->attention_button_callback( 891 shpchp_handle_attention_button(hp_slot, ctrl);
950 hp_slot, php_ctlr->callback_instance_id);
951 892
952 if (slot_reg & PRSNT_CHANGE_DETECTED) 893 if (slot_reg & PRSNT_CHANGE_DETECTED)
953 php_ctlr->presence_change_callback( 894 shpchp_handle_presence_change(hp_slot, ctrl);
954 hp_slot , php_ctlr->callback_instance_id);
955 895
956 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED)) 896 if (slot_reg & (ISO_PFAULT_DETECTED | CON_PFAULT_DETECTED))
957 php_ctlr->power_fault_callback( 897 shpchp_handle_power_fault(hp_slot, ctrl);
958 hp_slot, php_ctlr->callback_instance_id);
959 898
960 /* Clear all slot events */ 899 /* Clear all slot events */
961 slot_reg &= ~SLOT_REG_RSVDZ_MASK; 900 slot_reg &= ~SLOT_REG_RSVDZ_MASK;
@@ -1114,10 +1053,8 @@ static struct hpc_ops shpchp_hpc_ops = {
1114 .release_ctlr = hpc_release_ctlr, 1053 .release_ctlr = hpc_release_ctlr,
1115}; 1054};
1116 1055
1117int shpc_init(struct controller * ctrl, struct pci_dev * pdev) 1056int shpc_init(struct controller *ctrl, struct pci_dev *pdev)
1118{ 1057{
1119 struct php_ctlr_state_s *php_ctlr, *p;
1120 void *instance_id = ctrl;
1121 int rc = -1, num_slots = 0; 1058 int rc = -1, num_slots = 0;
1122 u8 hp_slot; 1059 u8 hp_slot;
1123 u32 shpc_base_offset; 1060 u32 shpc_base_offset;
@@ -1128,16 +1065,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1128 1065
1129 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */ 1066 ctrl->pci_dev = pdev; /* pci_dev of the P2P bridge */
1130 1067
1131 spin_lock_init(&list_lock);
1132 php_ctlr = kzalloc(sizeof(*php_ctlr), GFP_KERNEL);
1133
1134 if (!php_ctlr) { /* allocate controller state data */
1135 err("%s: HPC controller memory allocation error!\n", __FUNCTION__);
1136 goto abort;
1137 }
1138
1139 php_ctlr->pci_dev = pdev; /* save pci_dev in context */
1140
1141 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == 1068 if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==
1142 PCI_DEVICE_ID_AMD_GOLAM_7450)) { 1069 PCI_DEVICE_ID_AMD_GOLAM_7450)) {
1143 /* amd shpc driver doesn't use Base Offset; assume 0 */ 1070 /* amd shpc driver doesn't use Base Offset; assume 0 */
@@ -1147,20 +1074,20 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1147 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC); 1074 ctrl->cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC);
1148 if (!ctrl->cap_offset) { 1075 if (!ctrl->cap_offset) {
1149 err("%s : cap_offset == 0\n", __FUNCTION__); 1076 err("%s : cap_offset == 0\n", __FUNCTION__);
1150 goto abort_free_ctlr; 1077 goto abort;
1151 } 1078 }
1152 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset); 1079 dbg("%s: cap_offset = %x\n", __FUNCTION__, ctrl->cap_offset);
1153 1080
1154 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset); 1081 rc = shpc_indirect_read(ctrl, 0, &shpc_base_offset);
1155 if (rc) { 1082 if (rc) {
1156 err("%s: cannot read base_offset\n", __FUNCTION__); 1083 err("%s: cannot read base_offset\n", __FUNCTION__);
1157 goto abort_free_ctlr; 1084 goto abort;
1158 } 1085 }
1159 1086
1160 rc = shpc_indirect_read(ctrl, 3, &tempdword); 1087 rc = shpc_indirect_read(ctrl, 3, &tempdword);
1161 if (rc) { 1088 if (rc) {
1162 err("%s: cannot read slot config\n", __FUNCTION__); 1089 err("%s: cannot read slot config\n", __FUNCTION__);
1163 goto abort_free_ctlr; 1090 goto abort;
1164 } 1091 }
1165 num_slots = tempdword & SLOT_NUM; 1092 num_slots = tempdword & SLOT_NUM;
1166 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots); 1093 dbg("%s: num_slots (indirect) %x\n", __FUNCTION__, num_slots);
@@ -1170,7 +1097,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1170 if (rc) { 1097 if (rc) {
1171 err("%s: cannot read creg (index = %d)\n", 1098 err("%s: cannot read creg (index = %d)\n",
1172 __FUNCTION__, i); 1099 __FUNCTION__, i);
1173 goto abort_free_ctlr; 1100 goto abort;
1174 } 1101 }
1175 dbg("%s: offset %d: value %x\n", __FUNCTION__,i, 1102 dbg("%s: offset %d: value %x\n", __FUNCTION__,i,
1176 tempdword); 1103 tempdword);
@@ -1187,24 +1114,24 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1187 rc = pci_enable_device(pdev); 1114 rc = pci_enable_device(pdev);
1188 if (rc) { 1115 if (rc) {
1189 err("%s: pci_enable_device failed\n", __FUNCTION__); 1116 err("%s: pci_enable_device failed\n", __FUNCTION__);
1190 goto abort_free_ctlr; 1117 goto abort;
1191 } 1118 }
1192 1119
1193 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) { 1120 if (!request_mem_region(ctrl->mmio_base, ctrl->mmio_size, MY_NAME)) {
1194 err("%s: cannot reserve MMIO region\n", __FUNCTION__); 1121 err("%s: cannot reserve MMIO region\n", __FUNCTION__);
1195 rc = -1; 1122 rc = -1;
1196 goto abort_free_ctlr; 1123 goto abort;
1197 } 1124 }
1198 1125
1199 php_ctlr->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size); 1126 ctrl->creg = ioremap(ctrl->mmio_base, ctrl->mmio_size);
1200 if (!php_ctlr->creg) { 1127 if (!ctrl->creg) {
1201 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, 1128 err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__,
1202 ctrl->mmio_size, ctrl->mmio_base); 1129 ctrl->mmio_size, ctrl->mmio_base);
1203 release_mem_region(ctrl->mmio_base, ctrl->mmio_size); 1130 release_mem_region(ctrl->mmio_base, ctrl->mmio_size);
1204 rc = -1; 1131 rc = -1;
1205 goto abort_free_ctlr; 1132 goto abort;
1206 } 1133 }
1207 dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg); 1134 dbg("%s: ctrl->creg %p\n", __FUNCTION__, ctrl->creg);
1208 1135
1209 mutex_init(&ctrl->crit_sect); 1136 mutex_init(&ctrl->crit_sect);
1210 mutex_init(&ctrl->cmd_lock); 1137 mutex_init(&ctrl->cmd_lock);
@@ -1212,23 +1139,14 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1212 /* Setup wait queue */ 1139 /* Setup wait queue */
1213 init_waitqueue_head(&ctrl->queue); 1140 init_waitqueue_head(&ctrl->queue);
1214 1141
1215 /* Find the IRQ */
1216 php_ctlr->irq = pdev->irq;
1217 php_ctlr->attention_button_callback = shpchp_handle_attention_button,
1218 php_ctlr->switch_change_callback = shpchp_handle_switch_change;
1219 php_ctlr->presence_change_callback = shpchp_handle_presence_change;
1220 php_ctlr->power_fault_callback = shpchp_handle_power_fault;
1221 php_ctlr->callback_instance_id = instance_id;
1222
1223 ctrl->hpc_ctlr_handle = php_ctlr;
1224 ctrl->hpc_ops = &shpchp_hpc_ops; 1142 ctrl->hpc_ops = &shpchp_hpc_ops;
1225 1143
1226 /* Return PCI Controller Info */ 1144 /* Return PCI Controller Info */
1227 slot_config = shpc_readl(ctrl, SLOT_CONFIG); 1145 slot_config = shpc_readl(ctrl, SLOT_CONFIG);
1228 php_ctlr->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8; 1146 ctrl->slot_device_offset = (slot_config & FIRST_DEV_NUM) >> 8;
1229 php_ctlr->num_slots = slot_config & SLOT_NUM; 1147 ctrl->num_slots = slot_config & SLOT_NUM;
1230 dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset); 1148 ctrl->first_slot = (slot_config & PSN) >> 16;
1231 dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots); 1149 ctrl->slot_num_inc = ((slot_config & UPDOWN) >> 29) ? 1 : -1;
1232 1150
1233 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */ 1151 /* Mask Global Interrupt Mask & Command Complete Interrupt Mask */
1234 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE); 1152 tempdword = shpc_readl(ctrl, SERR_INTR_ENABLE);
@@ -1243,7 +1161,7 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1243 /* Mask the MRL sensor SERR Mask of individual slot in 1161 /* Mask the MRL sensor SERR Mask of individual slot in
1244 * Slot SERR-INT Mask & clear all the existing event if any 1162 * Slot SERR-INT Mask & clear all the existing event if any
1245 */ 1163 */
1246 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { 1164 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1247 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); 1165 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
1248 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, 1166 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1249 hp_slot, slot_reg); 1167 hp_slot, slot_reg);
@@ -1255,24 +1173,27 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1255 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg); 1173 shpc_writel(ctrl, SLOT_REG(hp_slot), slot_reg);
1256 } 1174 }
1257 1175
1258 if (shpchp_poll_mode) {/* Install interrupt polling code */ 1176 if (shpchp_poll_mode) {
1259 /* Install and start the interrupt polling timer */ 1177 /* Install interrupt polling timer. Start with 10 sec delay */
1260 init_timer(&php_ctlr->int_poll_timer); 1178 init_timer(&ctrl->poll_timer);
1261 start_int_poll_timer( php_ctlr, 10 ); /* start with 10 second delay */ 1179 start_int_poll_timer(ctrl, 10);
1262 } else { 1180 } else {
1263 /* Installs the interrupt handler */ 1181 /* Installs the interrupt handler */
1264 rc = pci_enable_msi(pdev); 1182 rc = pci_enable_msi(pdev);
1265 if (rc) { 1183 if (rc) {
1266 info("Can't get msi for the hotplug controller\n"); 1184 info("Can't get msi for the hotplug controller\n");
1267 info("Use INTx for the hotplug controller\n"); 1185 info("Use INTx for the hotplug controller\n");
1268 } else 1186 }
1269 php_ctlr->irq = pdev->irq;
1270 1187
1271 rc = request_irq(php_ctlr->irq, shpc_isr, IRQF_SHARED, MY_NAME, (void *) ctrl); 1188 rc = request_irq(ctrl->pci_dev->irq, shpc_isr, IRQF_SHARED,
1272 dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc); 1189 MY_NAME, (void *)ctrl);
1190 dbg("%s: request_irq %d for hpc%d (returns %d)\n",
1191 __FUNCTION__, ctrl->pci_dev->irq,
1192 atomic_read(&shpchp_num_controllers), rc);
1273 if (rc) { 1193 if (rc) {
1274 err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq); 1194 err("Can't get irq %d for the hotplug controller\n",
1275 goto abort_free_ctlr; 1195 ctrl->pci_dev->irq);
1196 goto abort_iounmap;
1276 } 1197 }
1277 } 1198 }
1278 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__, 1199 dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,
@@ -1280,24 +1201,6 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1280 PCI_FUNC(pdev->devfn), pdev->irq); 1201 PCI_FUNC(pdev->devfn), pdev->irq);
1281 get_hp_hw_control_from_firmware(pdev); 1202 get_hp_hw_control_from_firmware(pdev);
1282 1203
1283 /* Add this HPC instance into the HPC list */
1284 spin_lock(&list_lock);
1285 if (php_ctlr_list_head == 0) {
1286 php_ctlr_list_head = php_ctlr;
1287 p = php_ctlr_list_head;
1288 p->pnext = NULL;
1289 } else {
1290 p = php_ctlr_list_head;
1291
1292 while (p->pnext)
1293 p = p->pnext;
1294
1295 p->pnext = php_ctlr;
1296 }
1297 spin_unlock(&list_lock);
1298
1299 ctlr_seq_num++;
1300
1301 /* 1204 /*
1302 * If this is the first controller to be initialized, 1205 * If this is the first controller to be initialized,
1303 * initialize the shpchpd work queue 1206 * initialize the shpchpd work queue
@@ -1306,14 +1209,14 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1306 shpchp_wq = create_singlethread_workqueue("shpchpd"); 1209 shpchp_wq = create_singlethread_workqueue("shpchpd");
1307 if (!shpchp_wq) { 1210 if (!shpchp_wq) {
1308 rc = -ENOMEM; 1211 rc = -ENOMEM;
1309 goto abort_free_ctlr; 1212 goto abort_iounmap;
1310 } 1213 }
1311 } 1214 }
1312 1215
1313 /* 1216 /*
1314 * Unmask all event interrupts of all slots 1217 * Unmask all event interrupts of all slots
1315 */ 1218 */
1316 for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) { 1219 for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) {
1317 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot)); 1220 slot_reg = shpc_readl(ctrl, SLOT_REG(hp_slot));
1318 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__, 1221 dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,
1319 hp_slot, slot_reg); 1222 hp_slot, slot_reg);
@@ -1336,10 +1239,8 @@ int shpc_init(struct controller * ctrl, struct pci_dev * pdev)
1336 return 0; 1239 return 0;
1337 1240
1338 /* We end up here for the many possible ways to fail this API. */ 1241 /* We end up here for the many possible ways to fail this API. */
1339abort_free_ctlr: 1242abort_iounmap:
1340 if (php_ctlr->creg) 1243 iounmap(ctrl->creg);
1341 iounmap(php_ctlr->creg);
1342 kfree(php_ctlr);
1343abort: 1244abort:
1344 DBG_LEAVE_ROUTINE 1245 DBG_LEAVE_ROUTINE
1345 return rc; 1246 return rc;
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index 0a8d1cce9fa0..279c940a0039 100644
--- a/drivers/pci/htirq.c
+++ b/drivers/pci/htirq.c
@@ -99,14 +99,7 @@ int __ht_create_irq(struct pci_dev *dev, int idx, ht_irq_update_t *update)
99 int pos; 99 int pos;
100 int irq; 100 int irq;
101 101
102 pos = pci_find_capability(dev, PCI_CAP_ID_HT); 102 pos = pci_find_ht_capability(dev, HT_CAPTYPE_IRQ);
103 while (pos) {
104 u8 subtype;
105 pci_read_config_byte(dev, pos + 3, &subtype);
106 if (subtype == HT_CAPTYPE_IRQ)
107 break;
108 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT);
109 }
110 if (!pos) 103 if (!pos)
111 return -EINVAL; 104 return -EINVAL;
112 105
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index e5ae3a0c13bb..b8d2385e29bc 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -162,14 +162,9 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
162const struct pci_device_id *pci_match_device(struct pci_driver *drv, 162const struct pci_device_id *pci_match_device(struct pci_driver *drv,
163 struct pci_dev *dev) 163 struct pci_dev *dev)
164{ 164{
165 const struct pci_device_id *id;
166 struct pci_dynid *dynid; 165 struct pci_dynid *dynid;
167 166
168 id = pci_match_id(drv->id_table, dev); 167 /* Look at the dynamic ids first, before the static ones */
169 if (id)
170 return id;
171
172 /* static ids didn't match, lets look at the dynamic ones */
173 spin_lock(&drv->dynids.lock); 168 spin_lock(&drv->dynids.lock);
174 list_for_each_entry(dynid, &drv->dynids.list, node) { 169 list_for_each_entry(dynid, &drv->dynids.list, node) {
175 if (pci_match_one_device(&dynid->id, dev)) { 170 if (pci_match_one_device(&dynid->id, dev)) {
@@ -178,7 +173,8 @@ const struct pci_device_id *pci_match_device(struct pci_driver *drv,
178 } 173 }
179 } 174 }
180 spin_unlock(&drv->dynids.lock); 175 spin_unlock(&drv->dynids.lock);
181 return NULL; 176
177 return pci_match_id(drv->id_table, dev);
182} 178}
183 179
184static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, 180static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
@@ -357,6 +353,8 @@ static int pci_device_resume_early(struct device * dev)
357 struct pci_dev * pci_dev = to_pci_dev(dev); 353 struct pci_dev * pci_dev = to_pci_dev(dev);
358 struct pci_driver * drv = pci_dev->driver; 354 struct pci_driver * drv = pci_dev->driver;
359 355
356 pci_fixup_device(pci_fixup_resume, pci_dev);
357
360 if (drv && drv->resume_early) 358 if (drv && drv->resume_early)
361 error = drv->resume_early(pci_dev); 359 error = drv->resume_early(pci_dev);
362 return error; 360 return error;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 5a14b73cf3a1..6bfb942428e4 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -68,12 +68,14 @@ pci_max_busnr(void)
68 68
69#endif /* 0 */ 69#endif /* 0 */
70 70
71static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn, u8 pos, int cap) 71#define PCI_FIND_CAP_TTL 48
72
73static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
74 u8 pos, int cap, int *ttl)
72{ 75{
73 u8 id; 76 u8 id;
74 int ttl = 48;
75 77
76 while (ttl--) { 78 while ((*ttl)--) {
77 pci_bus_read_config_byte(bus, devfn, pos, &pos); 79 pci_bus_read_config_byte(bus, devfn, pos, &pos);
78 if (pos < 0x40) 80 if (pos < 0x40)
79 break; 81 break;
@@ -89,6 +91,14 @@ static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn, u8 pos,
89 return 0; 91 return 0;
90} 92}
91 93
94static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
95 u8 pos, int cap)
96{
97 int ttl = PCI_FIND_CAP_TTL;
98
99 return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
100}
101
92int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap) 102int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
93{ 103{
94 return __pci_find_next_cap(dev->bus, dev->devfn, 104 return __pci_find_next_cap(dev->bus, dev->devfn,
@@ -96,10 +106,10 @@ int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
96} 106}
97EXPORT_SYMBOL_GPL(pci_find_next_capability); 107EXPORT_SYMBOL_GPL(pci_find_next_capability);
98 108
99static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_type, int cap) 109static int __pci_bus_find_cap_start(struct pci_bus *bus,
110 unsigned int devfn, u8 hdr_type)
100{ 111{
101 u16 status; 112 u16 status;
102 u8 pos;
103 113
104 pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status); 114 pci_bus_read_config_word(bus, devfn, PCI_STATUS, &status);
105 if (!(status & PCI_STATUS_CAP_LIST)) 115 if (!(status & PCI_STATUS_CAP_LIST))
@@ -108,15 +118,14 @@ static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_ty
108 switch (hdr_type) { 118 switch (hdr_type) {
109 case PCI_HEADER_TYPE_NORMAL: 119 case PCI_HEADER_TYPE_NORMAL:
110 case PCI_HEADER_TYPE_BRIDGE: 120 case PCI_HEADER_TYPE_BRIDGE:
111 pos = PCI_CAPABILITY_LIST; 121 return PCI_CAPABILITY_LIST;
112 break;
113 case PCI_HEADER_TYPE_CARDBUS: 122 case PCI_HEADER_TYPE_CARDBUS:
114 pos = PCI_CB_CAPABILITY_LIST; 123 return PCI_CB_CAPABILITY_LIST;
115 break;
116 default: 124 default:
117 return 0; 125 return 0;
118 } 126 }
119 return __pci_find_next_cap(bus, devfn, pos, cap); 127
128 return 0;
120} 129}
121 130
122/** 131/**
@@ -140,7 +149,13 @@ static int __pci_bus_find_cap(struct pci_bus *bus, unsigned int devfn, u8 hdr_ty
140 */ 149 */
141int pci_find_capability(struct pci_dev *dev, int cap) 150int pci_find_capability(struct pci_dev *dev, int cap)
142{ 151{
143 return __pci_bus_find_cap(dev->bus, dev->devfn, dev->hdr_type, cap); 152 int pos;
153
154 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
155 if (pos)
156 pos = __pci_find_next_cap(dev->bus, dev->devfn, pos, cap);
157
158 return pos;
144} 159}
145 160
146/** 161/**
@@ -158,11 +173,16 @@ int pci_find_capability(struct pci_dev *dev, int cap)
158 */ 173 */
159int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap) 174int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
160{ 175{
176 int pos;
161 u8 hdr_type; 177 u8 hdr_type;
162 178
163 pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type); 179 pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
164 180
165 return __pci_bus_find_cap(bus, devfn, hdr_type & 0x7f, cap); 181 pos = __pci_bus_find_cap_start(bus, devfn, hdr_type & 0x7f);
182 if (pos)
183 pos = __pci_find_next_cap(bus, devfn, pos, cap);
184
185 return pos;
166} 186}
167 187
168/** 188/**
@@ -214,6 +234,74 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
214} 234}
215EXPORT_SYMBOL_GPL(pci_find_ext_capability); 235EXPORT_SYMBOL_GPL(pci_find_ext_capability);
216 236
237static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
238{
239 int rc, ttl = PCI_FIND_CAP_TTL;
240 u8 cap, mask;
241
242 if (ht_cap == HT_CAPTYPE_SLAVE || ht_cap == HT_CAPTYPE_HOST)
243 mask = HT_3BIT_CAP_MASK;
244 else
245 mask = HT_5BIT_CAP_MASK;
246
247 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
248 PCI_CAP_ID_HT, &ttl);
249 while (pos) {
250 rc = pci_read_config_byte(dev, pos + 3, &cap);
251 if (rc != PCIBIOS_SUCCESSFUL)
252 return 0;
253
254 if ((cap & mask) == ht_cap)
255 return pos;
256
257 pos = __pci_find_next_cap_ttl(dev->bus, dev->devfn, pos,
258 PCI_CAP_ID_HT, &ttl);
259 }
260
261 return 0;
262}
263/**
264 * pci_find_next_ht_capability - query a device's Hypertransport capabilities
265 * @dev: PCI device to query
266 * @pos: Position from which to continue searching
267 * @ht_cap: Hypertransport capability code
268 *
269 * To be used in conjunction with pci_find_ht_capability() to search for
270 * all capabilities matching @ht_cap. @pos should always be a value returned
271 * from pci_find_ht_capability().
272 *
273 * NB. To be 100% safe against broken PCI devices, the caller should take
274 * steps to avoid an infinite loop.
275 */
276int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap)
277{
278 return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
279}
280EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
281
282/**
283 * pci_find_ht_capability - query a device's Hypertransport capabilities
284 * @dev: PCI device to query
285 * @ht_cap: Hypertransport capability code
286 *
287 * Tell if a device supports a given Hypertransport capability.
288 * Returns an address within the device's PCI configuration space
289 * or 0 in case the device does not support the request capability.
290 * The address points to the PCI capability, of type PCI_CAP_ID_HT,
291 * which has a Hypertransport capability matching @ht_cap.
292 */
293int pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
294{
295 int pos;
296
297 pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
298 if (pos)
299 pos = __pci_find_next_ht_cap(dev, pos, ht_cap);
300
301 return pos;
302}
303EXPORT_SYMBOL_GPL(pci_find_ht_capability);
304
217/** 305/**
218 * pci_find_parent_resource - return resource region of parent bus of given region 306 * pci_find_parent_resource - return resource region of parent bus of given region
219 * @dev: PCI device structure contains resources to be searched 307 * @dev: PCI device structure contains resources to be searched
diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
index b4da7954611e..f17e7ed2b2a5 100644
--- a/drivers/pci/pcie/portdrv_pci.c
+++ b/drivers/pci/pcie/portdrv_pci.c
@@ -90,7 +90,7 @@ static int __devinit pcie_portdrv_probe (struct pci_dev *dev,
90 return -ENODEV; 90 return -ENODEV;
91 91
92 pci_set_master(dev); 92 pci_set_master(dev);
93 if (!dev->irq) { 93 if (!dev->irq && dev->pin) {
94 printk(KERN_WARNING 94 printk(KERN_WARNING
95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n", 95 "%s->Dev[%04x:%04x] has invalid IRQ. Check vendor BIOS\n",
96 __FUNCTION__, dev->device, dev->vendor); 96 __FUNCTION__, dev->device, dev->vendor);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 6a3c1e728900..0e0401dd02cb 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -639,6 +639,8 @@ static void pci_read_irq(struct pci_dev *dev)
639 dev->irq = irq; 639 dev->irq = irq;
640} 640}
641 641
642#define LEGACY_IO_RESOURCE (IORESOURCE_IO | IORESOURCE_PCI_FIXED)
643
642/** 644/**
643 * pci_setup_device - fill in class and map information of a device 645 * pci_setup_device - fill in class and map information of a device
644 * @dev: the device structure to fill 646 * @dev: the device structure to fill
@@ -692,18 +694,18 @@ static int pci_setup_device(struct pci_dev * dev)
692 if ((progif & 1) == 0) { 694 if ((progif & 1) == 0) {
693 dev->resource[0].start = 0x1F0; 695 dev->resource[0].start = 0x1F0;
694 dev->resource[0].end = 0x1F7; 696 dev->resource[0].end = 0x1F7;
695 dev->resource[0].flags = IORESOURCE_IO; 697 dev->resource[0].flags = LEGACY_IO_RESOURCE;
696 dev->resource[1].start = 0x3F6; 698 dev->resource[1].start = 0x3F6;
697 dev->resource[1].end = 0x3F6; 699 dev->resource[1].end = 0x3F6;
698 dev->resource[1].flags = IORESOURCE_IO; 700 dev->resource[1].flags = LEGACY_IO_RESOURCE;
699 } 701 }
700 if ((progif & 4) == 0) { 702 if ((progif & 4) == 0) {
701 dev->resource[2].start = 0x170; 703 dev->resource[2].start = 0x170;
702 dev->resource[2].end = 0x177; 704 dev->resource[2].end = 0x177;
703 dev->resource[2].flags = IORESOURCE_IO; 705 dev->resource[2].flags = LEGACY_IO_RESOURCE;
704 dev->resource[3].start = 0x376; 706 dev->resource[3].start = 0x376;
705 dev->resource[3].end = 0x376; 707 dev->resource[3].end = 0x376;
706 dev->resource[3].flags = IORESOURCE_IO; 708 dev->resource[3].flags = LEGACY_IO_RESOURCE;
707 } 709 }
708 } 710 }
709 break; 711 break;
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 9ca9b9bf6160..8f0322d6f3bf 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -36,7 +36,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX,PCI_DEVICE_ID_MELLANOX_TAVOR_BRID
36 36
37/* Deal with broken BIOS'es that neglect to enable passive release, 37/* Deal with broken BIOS'es that neglect to enable passive release,
38 which can cause problems in combination with the 82441FX/PPro MTRRs */ 38 which can cause problems in combination with the 82441FX/PPro MTRRs */
39static void __devinit quirk_passive_release(struct pci_dev *dev) 39static void quirk_passive_release(struct pci_dev *dev)
40{ 40{
41 struct pci_dev *d = NULL; 41 struct pci_dev *d = NULL;
42 unsigned char dlc; 42 unsigned char dlc;
@@ -53,6 +53,7 @@ static void __devinit quirk_passive_release(struct pci_dev *dev)
53 } 53 }
54} 54}
55DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release ); 55DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release );
56DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release );
56 57
57/* The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround 58/* The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround
58 but VIA don't answer queries. If you happen to have good contacts at VIA 59 but VIA don't answer queries. If you happen to have good contacts at VIA
@@ -134,7 +135,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439TX, quir
134 * Updated based on further information from the site and also on 135 * Updated based on further information from the site and also on
135 * information provided by VIA 136 * information provided by VIA
136 */ 137 */
137static void __devinit quirk_vialatency(struct pci_dev *dev) 138static void quirk_vialatency(struct pci_dev *dev)
138{ 139{
139 struct pci_dev *p; 140 struct pci_dev *p;
140 u8 rev; 141 u8 rev;
@@ -185,6 +186,10 @@ exit:
185DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency ); 186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency );
186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency ); 187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency );
187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency ); 188DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency );
189/* Must restore this on a resume from RAM */
190DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency );
191DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency );
192DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency );
188 193
189/* 194/*
190 * VIA Apollo VP3 needs ETBF on BT848/878 195 * VIA Apollo VP3 needs ETBF on BT848/878
@@ -532,7 +537,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235
532 * TODO: When we have device-specific interrupt routers, 537 * TODO: When we have device-specific interrupt routers,
533 * this code will go away from quirks. 538 * this code will go away from quirks.
534 */ 539 */
535static void __devinit quirk_via_ioapic(struct pci_dev *dev) 540static void quirk_via_ioapic(struct pci_dev *dev)
536{ 541{
537 u8 tmp; 542 u8 tmp;
538 543
@@ -548,6 +553,7 @@ static void __devinit quirk_via_ioapic(struct pci_dev *dev)
548 pci_write_config_byte (dev, 0x58, tmp); 553 pci_write_config_byte (dev, 0x58, tmp);
549} 554}
550DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic ); 555DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic );
556DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic );
551 557
552/* 558/*
553 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit. 559 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
@@ -555,7 +561,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_i
555 * Set this bit to get rid of cycle wastage. 561 * Set this bit to get rid of cycle wastage.
556 * Otherwise uncritical. 562 * Otherwise uncritical.
557 */ 563 */
558static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev) 564static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
559{ 565{
560 u8 misc_control2; 566 u8 misc_control2;
561#define BYPASS_APIC_DEASSERT 8 567#define BYPASS_APIC_DEASSERT 8
@@ -567,6 +573,7 @@ static void __devinit quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
567 } 573 }
568} 574}
569DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert); 575DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
576DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
570 577
571/* 578/*
572 * The AMD io apic can hang the box when an apic irq is masked. 579 * The AMD io apic can hang the box when an apic irq is masked.
@@ -600,7 +607,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_ANY_ID, quirk_ioapic_rmw );
600#define AMD8131_revB0 0x11 607#define AMD8131_revB0 0x11
601#define AMD8131_MISC 0x40 608#define AMD8131_MISC 0x40
602#define AMD8131_NIOAMODE_BIT 0 609#define AMD8131_NIOAMODE_BIT 0
603static void __init quirk_amd_8131_ioapic(struct pci_dev *dev) 610static void quirk_amd_8131_ioapic(struct pci_dev *dev)
604{ 611{
605 unsigned char revid, tmp; 612 unsigned char revid, tmp;
606 613
@@ -616,6 +623,7 @@ static void __init quirk_amd_8131_ioapic(struct pci_dev *dev)
616 } 623 }
617} 624}
618DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic); 625DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
626DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
619#endif /* CONFIG_X86_IO_APIC */ 627#endif /* CONFIG_X86_IO_APIC */
620 628
621 629
@@ -641,65 +649,84 @@ static void __devinit quirk_via_acpi(struct pci_dev *d)
641DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi ); 649DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi );
642DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi ); 650DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi );
643 651
644/*
645 * Via 686A/B: The PCI_INTERRUPT_LINE register for the on-chip
646 * devices, USB0/1, AC97, MC97, and ACPI, has an unusual feature:
647 * when written, it makes an internal connection to the PIC.
648 * For these devices, this register is defined to be 4 bits wide.
649 * Normally this is fine. However for IO-APIC motherboards, or
650 * non-x86 architectures (yes Via exists on PPC among other places),
651 * we must mask the PCI_INTERRUPT_LINE value versus 0xf to get
652 * interrupts delivered properly.
653 *
654 * Some of the on-chip devices are actually '586 devices' so they are
655 * listed here.
656 */
657
658static int via_irq_fixup_needed = -1;
659 652
660/* 653/*
661 * As some VIA hardware is available in PCI-card form, we need to restrict 654 * VIA bridges which have VLink
662 * this quirk to VIA PCI hardware built onto VIA-based motherboards only.
663 * We try to locate a VIA southbridge before deciding whether the quirk
664 * should be applied.
665 */ 655 */
666static const struct pci_device_id via_irq_fixup_tbl[] = { 656
667 { 657static const struct pci_device_id via_vlink_fixup_tbl[] = {
668 .vendor = PCI_VENDOR_ID_VIA, 658 /* Internal devices need IRQ line routing, pre VLink */
669 .device = PCI_ANY_ID, 659 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_82C686), 0 },
670 .subvendor = PCI_ANY_ID, 660 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8231), 17 },
671 .subdevice = PCI_ANY_ID, 661 /* Devices with VLink */
672 .class = PCI_CLASS_BRIDGE_ISA << 8, 662 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233_0), 17},
673 .class_mask = 0xffff00, 663 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233A), 17 },
674 }, 664 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8233C_0), 17 },
665 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8235), 16 },
666 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237), 15 },
667 { PCI_VDEVICE(VIA, PCI_DEVICE_ID_VIA_8237A), 15 },
675 { 0, }, 668 { 0, },
676}; 669};
677 670
678static void quirk_via_irq(struct pci_dev *dev) 671/**
672 * quirk_via_vlink - VIA VLink IRQ number update
673 * @dev: PCI device
674 *
675 * If the device we are dealing with is on a PIC IRQ we need to
676 * ensure that the IRQ line register which usually is not relevant
677 * for PCI cards, is actually written so that interrupts get sent
678 * to the right place
679 */
680
681static void quirk_via_vlink(struct pci_dev *dev)
679{ 682{
683 const struct pci_device_id *via_vlink_fixup;
684 static int dev_lo = -1, dev_hi = 18;
680 u8 irq, new_irq; 685 u8 irq, new_irq;
681 686
682 if (via_irq_fixup_needed == -1) 687 /* Check if we have VLink and cache the result */
683 via_irq_fixup_needed = pci_dev_present(via_irq_fixup_tbl);
684 688
685 if (!via_irq_fixup_needed) 689 /* Checked already - no */
690 if (dev_lo == -2)
686 return; 691 return;
687 692
693 /* Not checked - see what bridge we have and find the device
694 ranges */
695
696 if (dev_lo == -1) {
697 via_vlink_fixup = pci_find_present(via_vlink_fixup_tbl);
698 if (via_vlink_fixup == NULL) {
699 dev_lo = -2;
700 return;
701 }
702 dev_lo = via_vlink_fixup->driver_data;
703 /* 82C686 is special - 0/0 */
704 if (dev_lo == 0)
705 dev_hi = 0;
706 }
688 new_irq = dev->irq; 707 new_irq = dev->irq;
689 708
690 /* Don't quirk interrupts outside the legacy IRQ range */ 709 /* Don't quirk interrupts outside the legacy IRQ range */
691 if (!new_irq || new_irq > 15) 710 if (!new_irq || new_irq > 15)
692 return; 711 return;
693 712
713 /* Internal device ? */
714 if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > dev_hi ||
715 PCI_SLOT(dev->devfn) < dev_lo)
716 return;
717
718 /* This is an internal VLink device on a PIC interrupt. The BIOS
719 ought to have set this but may not have, so we redo it */
720
694 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq); 721 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
695 if (new_irq != irq) { 722 if (new_irq != irq) {
696 printk(KERN_INFO "PCI: VIA IRQ fixup for %s, from %d to %d\n", 723 printk(KERN_INFO "PCI: VIA VLink IRQ fixup for %s, from %d to %d\n",
697 pci_name(dev), irq, new_irq); 724 pci_name(dev), irq, new_irq);
698 udelay(15); /* unknown if delay really needed */ 725 udelay(15); /* unknown if delay really needed */
699 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq); 726 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
700 } 727 }
701} 728}
702DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_irq); 729DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_vlink);
703 730
704/* 731/*
705 * VIA VT82C598 has its device ID settable and many BIOSes 732 * VIA VT82C598 has its device ID settable and many BIOSes
@@ -720,13 +747,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt
720 * do this even if the Linux CardBus driver is not loaded, because 747 * do this even if the Linux CardBus driver is not loaded, because
721 * the Linux i82365 driver does not (and should not) handle CardBus. 748 * the Linux i82365 driver does not (and should not) handle CardBus.
722 */ 749 */
723static void __devinit quirk_cardbus_legacy(struct pci_dev *dev) 750static void quirk_cardbus_legacy(struct pci_dev *dev)
724{ 751{
725 if ((PCI_CLASS_BRIDGE_CARDBUS << 8) ^ dev->class) 752 if ((PCI_CLASS_BRIDGE_CARDBUS << 8) ^ dev->class)
726 return; 753 return;
727 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0); 754 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
728} 755}
729DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy); 756DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
757DECLARE_PCI_FIXUP_RESUME(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
730 758
731/* 759/*
732 * Following the PCI ordering rules is optional on the AMD762. I'm not 760 * Following the PCI ordering rules is optional on the AMD762. I'm not
@@ -735,7 +763,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
735 * To be fair to AMD, it follows the spec by default, its BIOS people 763 * To be fair to AMD, it follows the spec by default, its BIOS people
736 * who turn it off! 764 * who turn it off!
737 */ 765 */
738static void __devinit quirk_amd_ordering(struct pci_dev *dev) 766static void quirk_amd_ordering(struct pci_dev *dev)
739{ 767{
740 u32 pcic; 768 u32 pcic;
741 pci_read_config_dword(dev, 0x4C, &pcic); 769 pci_read_config_dword(dev, 0x4C, &pcic);
@@ -749,6 +777,7 @@ static void __devinit quirk_amd_ordering(struct pci_dev *dev)
749 } 777 }
750} 778}
751DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering ); 779DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
780DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering );
752 781
753/* 782/*
754 * DreamWorks provided workaround for Dunord I-3000 problem 783 * DreamWorks provided workaround for Dunord I-3000 problem
@@ -784,7 +813,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA, 0x605, quirk_transparent_bridge
784 * datasheets found at http://www.national.com/ds/GX for info on what 813 * datasheets found at http://www.national.com/ds/GX for info on what
785 * these bits do. <christer@weinigel.se> 814 * these bits do. <christer@weinigel.se>
786 */ 815 */
787static void __init quirk_mediagx_master(struct pci_dev *dev) 816static void quirk_mediagx_master(struct pci_dev *dev)
788{ 817{
789 u8 reg; 818 u8 reg;
790 pci_read_config_byte(dev, 0x41, &reg); 819 pci_read_config_byte(dev, 0x41, &reg);
@@ -795,13 +824,14 @@ static void __init quirk_mediagx_master(struct pci_dev *dev)
795 } 824 }
796} 825}
797DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master ); 826DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
827DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master );
798 828
799/* 829/*
800 * Ensure C0 rev restreaming is off. This is normally done by 830 * Ensure C0 rev restreaming is off. This is normally done by
801 * the BIOS but in the odd case it is not the results are corruption 831 * the BIOS but in the odd case it is not the results are corruption
802 * hence the presence of a Linux check 832 * hence the presence of a Linux check
803 */ 833 */
804static void __init quirk_disable_pxb(struct pci_dev *pdev) 834static void quirk_disable_pxb(struct pci_dev *pdev)
805{ 835{
806 u16 config; 836 u16 config;
807 u8 rev; 837 u8 rev;
@@ -817,7 +847,25 @@ static void __init quirk_disable_pxb(struct pci_dev *pdev)
817 } 847 }
818} 848}
819DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb ); 849DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb );
850DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb );
851
852
853static void __devinit quirk_sb600_sata(struct pci_dev *pdev)
854{
855 /* set sb600 sata to ahci mode */
856 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
857 u8 tmp;
820 858
859 pci_read_config_byte(pdev, 0x40, &tmp);
860 pci_write_config_byte(pdev, 0x40, tmp|1);
861 pci_write_config_byte(pdev, 0x9, 1);
862 pci_write_config_byte(pdev, 0xa, 6);
863 pci_write_config_byte(pdev, 0x40, tmp);
864
865 pdev->class = 0x010601;
866 }
867}
868DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_sb600_sata);
821 869
822/* 870/*
823 * Serverworks CSB5 IDE does not fully support native mode 871 * Serverworks CSB5 IDE does not fully support native mode
@@ -874,7 +922,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82375, quirk_e
874 * runs everywhere at present we suppress the printk output in most 922 * runs everywhere at present we suppress the printk output in most
875 * irrelevant cases. 923 * irrelevant cases.
876 */ 924 */
877static void __init k8t_sound_hostbridge(struct pci_dev *dev) 925static void k8t_sound_hostbridge(struct pci_dev *dev)
878{ 926{
879 unsigned char val; 927 unsigned char val;
880 928
@@ -893,8 +941,8 @@ static void __init k8t_sound_hostbridge(struct pci_dev *dev)
893 } 941 }
894} 942}
895DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge); 943DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge);
944DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_hostbridge);
896 945
897#ifndef CONFIG_ACPI_SLEEP
898/* 946/*
899 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge 947 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge
900 * is not activated. The myth is that Asus said that they do not want the 948 * is not activated. The myth is that Asus said that they do not want the
@@ -906,10 +954,6 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, k8t_sound_ho
906 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it 954 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it
907 * becomes necessary to do this tweak in two steps -- I've chosen the Host 955 * becomes necessary to do this tweak in two steps -- I've chosen the Host
908 * bridge as trigger. 956 * bridge as trigger.
909 *
910 * Actually, leaving it unhidden and not redoing the quirk over suspend2ram
911 * will cause thermal management to break down, and causing machine to
912 * overheat.
913 */ 957 */
914static int __initdata asus_hides_smbus; 958static int __initdata asus_hides_smbus;
915 959
@@ -1019,7 +1063,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, as
1019DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge ); 1063DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge );
1020DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge ); 1064DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge );
1021 1065
1022static void __init asus_hides_smbus_lpc(struct pci_dev *dev) 1066static void asus_hides_smbus_lpc(struct pci_dev *dev)
1023{ 1067{
1024 u16 val; 1068 u16 val;
1025 1069
@@ -1042,8 +1086,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asu
1042DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc ); 1086DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1043DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc ); 1087DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1044DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc ); 1088DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1089DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc );
1090DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc );
1091DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc );
1092DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc );
1093DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc );
1094DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc );
1045 1095
1046static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev) 1096static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1047{ 1097{
1048 u32 val, rcba; 1098 u32 val, rcba;
1049 void __iomem *base; 1099 void __iomem *base;
@@ -1059,13 +1109,12 @@ static void __init asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1059 printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n"); 1109 printk(KERN_INFO "PCI: Enabled ICH6/i801 SMBus device\n");
1060} 1110}
1061DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 ); 1111DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 );
1062 1112DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6 );
1063#endif
1064 1113
1065/* 1114/*
1066 * SiS 96x south bridge: BIOS typically hides SMBus device... 1115 * SiS 96x south bridge: BIOS typically hides SMBus device...
1067 */ 1116 */
1068static void __init quirk_sis_96x_smbus(struct pci_dev *dev) 1117static void quirk_sis_96x_smbus(struct pci_dev *dev)
1069{ 1118{
1070 u8 val = 0; 1119 u8 val = 0;
1071 printk(KERN_INFO "Enabling SiS 96x SMBus.\n"); 1120 printk(KERN_INFO "Enabling SiS 96x SMBus.\n");
@@ -1086,7 +1135,7 @@ static int __devinitdata sis_96x_compatible = 0;
1086 1135
1087#define SIS_DETECT_REGISTER 0x40 1136#define SIS_DETECT_REGISTER 0x40
1088 1137
1089static void __init quirk_sis_503(struct pci_dev *dev) 1138static void quirk_sis_503(struct pci_dev *dev)
1090{ 1139{
1091 u8 reg; 1140 u8 reg;
1092 u16 devid; 1141 u16 devid;
@@ -1122,13 +1171,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_651, quirk_sis_96x_
1122DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible ); 1171DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_735, quirk_sis_96x_compatible );
1123 1172
1124DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 ); 1173DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 );
1174DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503 );
1125/* 1175/*
1126 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller 1176 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
1127 * and MC97 modem controller are disabled when a second PCI soundcard is 1177 * and MC97 modem controller are disabled when a second PCI soundcard is
1128 * present. This patch, tweaking the VT8237 ISA bridge, enables them. 1178 * present. This patch, tweaking the VT8237 ISA bridge, enables them.
1129 * -- bjd 1179 * -- bjd
1130 */ 1180 */
1131static void __init asus_hides_ac97_lpc(struct pci_dev *dev) 1181static void asus_hides_ac97_lpc(struct pci_dev *dev)
1132{ 1182{
1133 u8 val; 1183 u8 val;
1134 int asus_hides_ac97 = 0; 1184 int asus_hides_ac97 = 0;
@@ -1159,6 +1209,14 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_
1159DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus ); 1209DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus );
1160DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus ); 1210DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus );
1161 1211
1212DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc );
1213
1214
1215DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus );
1216DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus );
1217DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus );
1218DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus );
1219
1162#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE) 1220#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
1163 1221
1164/* 1222/*
@@ -1167,7 +1225,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_
1167 * the PCI scanning. 1225 * the PCI scanning.
1168 */ 1226 */
1169 1227
1170static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev) 1228static void quirk_jmicron_dualfn(struct pci_dev *pdev)
1171{ 1229{
1172 u32 conf; 1230 u32 conf;
1173 u8 hdr; 1231 u8 hdr;
@@ -1205,6 +1263,7 @@ static void __devinit quirk_jmicron_dualfn(struct pci_dev *pdev)
1205} 1263}
1206 1264
1207DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn); 1265DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn);
1266DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, quirk_jmicron_dualfn);
1208 1267
1209#endif 1268#endif
1210 1269
@@ -1532,6 +1591,8 @@ extern struct pci_fixup __start_pci_fixups_final[];
1532extern struct pci_fixup __end_pci_fixups_final[]; 1591extern struct pci_fixup __end_pci_fixups_final[];
1533extern struct pci_fixup __start_pci_fixups_enable[]; 1592extern struct pci_fixup __start_pci_fixups_enable[];
1534extern struct pci_fixup __end_pci_fixups_enable[]; 1593extern struct pci_fixup __end_pci_fixups_enable[];
1594extern struct pci_fixup __start_pci_fixups_resume[];
1595extern struct pci_fixup __end_pci_fixups_resume[];
1535 1596
1536 1597
1537void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev) 1598void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
@@ -1559,6 +1620,11 @@ void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
1559 end = __end_pci_fixups_enable; 1620 end = __end_pci_fixups_enable;
1560 break; 1621 break;
1561 1622
1623 case pci_fixup_resume:
1624 start = __start_pci_fixups_resume;
1625 end = __end_pci_fixups_resume;
1626 break;
1627
1562 default: 1628 default:
1563 /* stupid compiler warning, you would think with an enum... */ 1629 /* stupid compiler warning, you would think with an enum... */
1564 return; 1630 return;
@@ -1596,7 +1662,7 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io);
1596 * Force it to be linked by setting the corresponding control bit in the 1662 * Force it to be linked by setting the corresponding control bit in the
1597 * config space. 1663 * config space.
1598 */ 1664 */
1599static void __devinit quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev) 1665static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1600{ 1666{
1601 uint8_t b; 1667 uint8_t b;
1602 if (pci_read_config_byte(dev, 0xf41, &b) == 0) { 1668 if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
@@ -1610,6 +1676,8 @@ static void __devinit quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1610} 1676}
1611DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE, 1677DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1612 quirk_nvidia_ck804_pcie_aer_ext_cap); 1678 quirk_nvidia_ck804_pcie_aer_ext_cap);
1679DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1680 quirk_nvidia_ck804_pcie_aer_ext_cap);
1613 1681
1614#ifdef CONFIG_PCI_MSI 1682#ifdef CONFIG_PCI_MSI
1615/* To disable MSI globally */ 1683/* To disable MSI globally */
@@ -1644,19 +1712,23 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_
1644 * return 1 if a HT MSI capability is found and enabled */ 1712 * return 1 if a HT MSI capability is found and enabled */
1645static int __devinit msi_ht_cap_enabled(struct pci_dev *dev) 1713static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
1646{ 1714{
1647 u8 pos; 1715 int pos, ttl = 48;
1648 int ttl; 1716
1649 for (pos = pci_find_capability(dev, PCI_CAP_ID_HT), ttl = 48; 1717 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
1650 pos && ttl; 1718 while (pos && ttl--) {
1651 pos = pci_find_next_capability(dev, pos, PCI_CAP_ID_HT), ttl--) { 1719 u8 flags;
1652 u32 cap_hdr; 1720
1653 /* MSI mapping section according to Hypertransport spec */ 1721 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
1654 if (pci_read_config_dword(dev, pos, &cap_hdr) == 0 1722 &flags) == 0)
1655 && (cap_hdr & 0xf8000000) == 0xa8000000 /* MSI mapping */) { 1723 {
1656 printk(KERN_INFO "PCI: Found HT MSI mapping on %s with capability %s\n", 1724 printk(KERN_INFO "PCI: Found %s HT MSI Mapping on %s\n",
1657 pci_name(dev), cap_hdr & 0x10000 ? "enabled" : "disabled"); 1725 flags & HT_MSI_FLAGS_ENABLE ?
1658 return (cap_hdr & 0x10000) != 0; /* MSI mapping cap enabled */ 1726 "enabled" : "disabled", pci_name(dev));
1727 return (flags & HT_MSI_FLAGS_ENABLE) != 0;
1659 } 1728 }
1729
1730 pos = pci_find_next_ht_capability(dev, pos,
1731 HT_CAPTYPE_MSI_MAPPING);
1660 } 1732 }
1661 return 0; 1733 return 0;
1662} 1734}
@@ -1688,8 +1760,9 @@ static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1688 * a single one having MSI is enough to be sure that MSI are supported. 1760 * a single one having MSI is enough to be sure that MSI are supported.
1689 */ 1761 */
1690 pdev = pci_get_slot(dev->bus, 0); 1762 pdev = pci_get_slot(dev->bus, 0);
1691 if (dev->subordinate && !msi_ht_cap_enabled(dev) 1763 if (!pdev)
1692 && !msi_ht_cap_enabled(pdev)) { 1764 return;
1765 if (!msi_ht_cap_enabled(dev) && !msi_ht_cap_enabled(pdev)) {
1693 printk(KERN_WARNING "PCI: MSI quirk detected. " 1766 printk(KERN_WARNING "PCI: MSI quirk detected. "
1694 "MSI disabled on chipset %s.\n", 1767 "MSI disabled on chipset %s.\n",
1695 pci_name(dev)); 1768 pci_name(dev));
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 2f13eba5d5ae..45f2b20ef513 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -413,6 +413,24 @@ exit:
413 return dev; 413 return dev;
414} 414}
415 415
416const struct pci_device_id *pci_find_present(const struct pci_device_id *ids)
417{
418 struct pci_dev *dev;
419 const struct pci_device_id *found = NULL;
420
421 WARN_ON(in_interrupt());
422 down_read(&pci_bus_sem);
423 while (ids->vendor || ids->subvendor || ids->class_mask) {
424 list_for_each_entry(dev, &pci_devices, global_list) {
425 if ((found = pci_match_one_device(ids, dev)) != NULL)
426 break;
427 }
428 ids++;
429 }
430 up_read(&pci_bus_sem);
431 return found;
432}
433
416/** 434/**
417 * pci_dev_present - Returns 1 if device matching the device list is present, 0 if not. 435 * pci_dev_present - Returns 1 if device matching the device list is present, 0 if not.
418 * @ids: A pointer to a null terminated list of struct pci_device_id structures 436 * @ids: A pointer to a null terminated list of struct pci_device_id structures
@@ -426,25 +444,11 @@ exit:
426 */ 444 */
427int pci_dev_present(const struct pci_device_id *ids) 445int pci_dev_present(const struct pci_device_id *ids)
428{ 446{
429 struct pci_dev *dev; 447 return pci_find_present(ids) == NULL ? 0 : 1;
430 int found = 0;
431
432 WARN_ON(in_interrupt());
433 down_read(&pci_bus_sem);
434 while (ids->vendor || ids->subvendor || ids->class_mask) {
435 list_for_each_entry(dev, &pci_devices, global_list) {
436 if (pci_match_one_device(ids, dev)) {
437 found = 1;
438 goto exit;
439 }
440 }
441 ids++;
442 }
443exit:
444 up_read(&pci_bus_sem);
445 return found;
446} 448}
449
447EXPORT_SYMBOL(pci_dev_present); 450EXPORT_SYMBOL(pci_dev_present);
451EXPORT_SYMBOL(pci_find_present);
448 452
449EXPORT_SYMBOL(pci_find_device); 453EXPORT_SYMBOL(pci_find_device);
450EXPORT_SYMBOL(pci_find_device_reverse); 454EXPORT_SYMBOL(pci_find_device_reverse);
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8f7bcf56f149..89f3036f0de8 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -41,7 +41,7 @@
41 * have a P2P bridge below a cardbus bridge, we need 4K. 41 * have a P2P bridge below a cardbus bridge, we need 4K.
42 */ 42 */
43#define CARDBUS_IO_SIZE (256) 43#define CARDBUS_IO_SIZE (256)
44#define CARDBUS_MEM_SIZE (32*1024*1024) 44#define CARDBUS_MEM_SIZE (64*1024*1024)
45 45
46static void __devinit 46static void __devinit
47pbus_assign_resources_sorted(struct pci_bus *bus) 47pbus_assign_resources_sorted(struct pci_bus *bus)
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index ab78e4bbdd83..cb4ced3560e9 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -33,11 +33,22 @@ pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
33 u32 new, check, mask; 33 u32 new, check, mask;
34 int reg; 34 int reg;
35 35
36 /* Ignore resources for unimplemented BARs and unused resource slots 36 /*
37 for 64 bit BARs. */ 37 * Ignore resources for unimplemented BARs and unused resource slots
38 * for 64 bit BARs.
39 */
38 if (!res->flags) 40 if (!res->flags)
39 return; 41 return;
40 42
43 /*
44 * Ignore non-moveable resources. This might be legacy resources for
45 * which no functional BAR register exists or another important
46 * system resource we should better not move around in system address
47 * space.
48 */
49 if (res->flags & IORESOURCE_PCI_FIXED)
50 return;
51
41 pcibios_resource_to_bus(dev, &region, res); 52 pcibios_resource_to_bus(dev, &region, res);
42 53
43 pr_debug(" got res [%llx:%llx] bus [%lx:%lx] flags %lx for " 54 pr_debug(" got res [%llx:%llx] bus [%lx:%lx] flags %lx for "
@@ -212,6 +223,10 @@ pdev_sort_resources(struct pci_dev *dev, struct resource_list *head)
212 resource_size_t r_align; 223 resource_size_t r_align;
213 224
214 r = &dev->resource[i]; 225 r = &dev->resource[i];
226
227 if (r->flags & IORESOURCE_PCI_FIXED)
228 continue;
229
215 r_align = r->end - r->start; 230 r_align = r->end - r->start;
216 231
217 if (!(r->flags) || r->parent) 232 if (!(r->flags) || r->parent)
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index b9b0fc3f812b..cdb24f528112 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -23,7 +23,7 @@
23#include <asm/appldata.h> 23#include <asm/appldata.h>
24#include <asm/monwriter.h> 24#include <asm/monwriter.h>
25 25
26#define MONWRITE_MAX_DATALEN 4024 26#define MONWRITE_MAX_DATALEN 4010
27 27
28static int mon_max_bufs = 255; 28static int mon_max_bufs = 255;
29static int mon_buf_count; 29static int mon_buf_count;
diff --git a/drivers/s390/char/sclp_cpi.c b/drivers/s390/char/sclp_cpi.c
index f7c10d954ec6..4f873ae148b7 100644
--- a/drivers/s390/char/sclp_cpi.c
+++ b/drivers/s390/char/sclp_cpi.c
@@ -49,6 +49,8 @@ static struct sclp_register sclp_cpi_event =
49 .send_mask = EvTyp_CtlProgIdent_Mask 49 .send_mask = EvTyp_CtlProgIdent_Mask
50}; 50};
51 51
52MODULE_LICENSE("GPL");
53
52MODULE_AUTHOR( 54MODULE_AUTHOR(
53 "Martin Peschke, IBM Deutschland Entwicklung GmbH " 55 "Martin Peschke, IBM Deutschland Entwicklung GmbH "
54 "<mpeschke@de.ibm.com>"); 56 "<mpeschke@de.ibm.com>");
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 7835a714a405..b471ac4a1bf6 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -2,8 +2,7 @@
2 * drivers/s390/cio/cio.c 2 * drivers/s390/cio/cio.c
3 * S/390 common I/O routines -- low level i/o calls 3 * S/390 common I/O routines -- low level i/o calls
4 * 4 *
5 * Copyright (C) 1999-2002 IBM Deutschland Entwicklung GmbH, 5 * Copyright (C) IBM Corp. 1999,2006
6 * IBM Corporation
7 * Author(s): Ingo Adlung (adlung@de.ibm.com) 6 * Author(s): Ingo Adlung (adlung@de.ibm.com)
8 * Cornelia Huck (cornelia.huck@de.ibm.com) 7 * Cornelia Huck (cornelia.huck@de.ibm.com)
9 * Arnd Bergmann (arndb@de.ibm.com) 8 * Arnd Bergmann (arndb@de.ibm.com)
@@ -871,11 +870,40 @@ __clear_subchannel_easy(struct subchannel_id schid)
871 return -EBUSY; 870 return -EBUSY;
872} 871}
873 872
873static int pgm_check_occured;
874
875static void cio_reset_pgm_check_handler(void)
876{
877 pgm_check_occured = 1;
878}
879
880static int stsch_reset(struct subchannel_id schid, volatile struct schib *addr)
881{
882 int rc;
883 register struct subchannel_id reg1 asm ("1") = schid;
884
885 pgm_check_occured = 0;
886 s390_reset_pgm_handler = cio_reset_pgm_check_handler;
887
888 asm volatile(
889 " stsch 0(%2)\n"
890 " ipm %0\n"
891 " srl %0,28"
892 : "=d" (rc)
893 : "d" (reg1), "a" (addr), "m" (*addr) : "memory", "cc");
894
895 s390_reset_pgm_handler = NULL;
896 if (pgm_check_occured)
897 return -EIO;
898 else
899 return rc;
900}
901
874static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data) 902static int __shutdown_subchannel_easy(struct subchannel_id schid, void *data)
875{ 903{
876 struct schib schib; 904 struct schib schib;
877 905
878 if (stsch_err(schid, &schib)) 906 if (stsch_reset(schid, &schib))
879 return -ENXIO; 907 return -ENXIO;
880 if (!schib.pmcw.ena) 908 if (!schib.pmcw.ena)
881 return 0; 909 return 0;
@@ -972,7 +1000,7 @@ static int __reipl_subchannel_match(struct subchannel_id schid, void *data)
972 struct schib schib; 1000 struct schib schib;
973 struct sch_match_id *match_id = data; 1001 struct sch_match_id *match_id = data;
974 1002
975 if (stsch_err(schid, &schib)) 1003 if (stsch_reset(schid, &schib))
976 return -ENXIO; 1004 return -ENXIO;
977 if (schib.pmcw.dnv && 1005 if (schib.pmcw.dnv &&
978 (schib.pmcw.dev == match_id->devid.devno) && 1006 (schib.pmcw.dev == match_id->devid.devno) &&
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 4c81d890791e..9d6c02446863 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -139,6 +139,8 @@ css_register_subchannel(struct subchannel *sch)
139 sch->dev.release = &css_subchannel_release; 139 sch->dev.release = &css_subchannel_release;
140 sch->dev.groups = subch_attr_groups; 140 sch->dev.groups = subch_attr_groups;
141 141
142 css_get_ssd_info(sch);
143
142 /* make it known to the system */ 144 /* make it known to the system */
143 ret = css_sch_device_register(sch); 145 ret = css_sch_device_register(sch);
144 if (ret) { 146 if (ret) {
@@ -146,7 +148,6 @@ css_register_subchannel(struct subchannel *sch)
146 __func__, sch->dev.bus_id); 148 __func__, sch->dev.bus_id);
147 return ret; 149 return ret;
148 } 150 }
149 css_get_ssd_info(sch);
150 return ret; 151 return ret;
151} 152}
152 153
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 9d4ea449a608..6fd1940842eb 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -979,12 +979,11 @@ __qdio_outbound_processing(struct qdio_q *q)
979 979
980 if (q->is_iqdio_q) { 980 if (q->is_iqdio_q) {
981 /* 981 /*
982 * for asynchronous queues, we better check, if the fill 982 * for asynchronous queues, we better check, if the sent
983 * level is too high. for synchronous queues, the fill 983 * buffer is already switched from PRIMED to EMPTY.
984 * level will never be that high.
985 */ 984 */
986 if (atomic_read(&q->number_of_buffers_used)> 985 if ((q->queue_type == QDIO_IQDIO_QFMT_ASYNCH) &&
987 IQDIO_FILL_LEVEL_TO_POLL) 986 !qdio_is_outbound_q_done(q))
988 qdio_mark_q(q); 987 qdio_mark_q(q);
989 988
990 } else if (!q->hydra_gives_outbound_pcis) 989 } else if (!q->hydra_gives_outbound_pcis)
@@ -1825,6 +1824,10 @@ qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1825 q->sbal[j]=*(outbound_sbals_array++); 1824 q->sbal[j]=*(outbound_sbals_array++);
1826 1825
1827 q->queue_type=q_format; 1826 q->queue_type=q_format;
1827 if ((q->queue_type == QDIO_IQDIO_QFMT) &&
1828 (no_output_qs > 1) &&
1829 (i == no_output_qs-1))
1830 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH;
1828 q->int_parm=int_parm; 1831 q->int_parm=int_parm;
1829 q->is_input_q=0; 1832 q->is_input_q=0;
1830 q->schid = irq_ptr->schid; 1833 q->schid = irq_ptr->schid;
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index ad60afe5dd11..81b5899f4010 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -1129,7 +1129,15 @@ static void ap_poll_thread_stop(void)
1129 mutex_unlock(&ap_poll_thread_mutex); 1129 mutex_unlock(&ap_poll_thread_mutex);
1130} 1130}
1131 1131
1132static void ap_reset(void) 1132static void ap_reset_domain(void)
1133{
1134 int i;
1135
1136 for (i = 0; i < AP_DEVICES; i++)
1137 ap_reset_queue(AP_MKQID(i, ap_domain_index));
1138}
1139
1140static void ap_reset_all(void)
1133{ 1141{
1134 int i, j; 1142 int i, j;
1135 1143
@@ -1139,7 +1147,7 @@ static void ap_reset(void)
1139} 1147}
1140 1148
1141static struct reset_call ap_reset_call = { 1149static struct reset_call ap_reset_call = {
1142 .fn = ap_reset, 1150 .fn = ap_reset_all,
1143}; 1151};
1144 1152
1145/** 1153/**
@@ -1229,10 +1237,12 @@ void ap_module_exit(void)
1229 int i; 1237 int i;
1230 struct device *dev; 1238 struct device *dev;
1231 1239
1240 ap_reset_domain();
1232 ap_poll_thread_stop(); 1241 ap_poll_thread_stop();
1233 del_timer_sync(&ap_config_timer); 1242 del_timer_sync(&ap_config_timer);
1234 del_timer_sync(&ap_poll_timer); 1243 del_timer_sync(&ap_poll_timer);
1235 destroy_workqueue(ap_work_queue); 1244 destroy_workqueue(ap_work_queue);
1245 tasklet_kill(&ap_tasklet);
1236 s390_root_dev_unregister(ap_root_device); 1246 s390_root_dev_unregister(ap_root_device);
1237 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL, 1247 while ((dev = bus_find_device(&ap_bus_type, NULL, NULL,
1238 __ap_match_all))) 1248 __ap_match_all)))
diff --git a/drivers/scsi/ibmvscsi/Makefile b/drivers/scsi/ibmvscsi/Makefile
index 6ac0633d5452..f67d9efc7a99 100644
--- a/drivers/scsi/ibmvscsi/Makefile
+++ b/drivers/scsi/ibmvscsi/Makefile
@@ -1,7 +1,9 @@
1obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsic.o 1obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsic.o
2 2
3ibmvscsic-y += ibmvscsi.o 3ibmvscsic-y += ibmvscsi.o
4ifndef CONFIG_PPC_PSERIES
4ibmvscsic-$(CONFIG_PPC_ISERIES) += iseries_vscsi.o 5ibmvscsic-$(CONFIG_PPC_ISERIES) += iseries_vscsi.o
6endif
5ibmvscsic-$(CONFIG_PPC_PSERIES) += rpa_vscsi.o 7ibmvscsic-$(CONFIG_PPC_PSERIES) += rpa_vscsi.o
6 8
7obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvstgt.o 9obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvstgt.o
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1748e27501cd..f02f48a882a9 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -265,13 +265,11 @@ static int scsi_merge_bio(struct request *rq, struct bio *bio)
265 265
266 if (!rq->bio) 266 if (!rq->bio)
267 blk_rq_bio_prep(q, rq, bio); 267 blk_rq_bio_prep(q, rq, bio);
268 else if (!q->back_merge_fn(q, rq, bio)) 268 else if (!ll_back_merge_fn(q, rq, bio))
269 return -EINVAL; 269 return -EINVAL;
270 else { 270 else {
271 rq->biotail->bi_next = bio; 271 rq->biotail->bi_next = bio;
272 rq->biotail = bio; 272 rq->biotail = bio;
273 rq->hard_nr_sectors += bio_sectors(bio);
274 rq->nr_sectors = rq->hard_nr_sectors;
275 } 273 }
276 274
277 return 0; 275 return 0;
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 43f5b6aa7dc4..98e3fe10c1dc 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -266,7 +266,7 @@ static struct scsi_host_template *the_template = NULL;
266 (struct NCR5380_hostdata *)(in)->hostdata 266 (struct NCR5380_hostdata *)(in)->hostdata
267#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata) 267#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
268 268
269#define NEXT(cmd) ((struct scsi_cmnd *)((cmd)->host_scribble)) 269#define NEXT(cmd) (*(struct scsi_cmnd **)&((cmd)->host_scribble))
270#define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble)) 270#define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble))
271 271
272#define HOSTNO instance->host_no 272#define HOSTNO instance->host_no
@@ -650,7 +650,7 @@ __inline__ void NCR5380_print_phase(struct Scsi_Host *instance) { };
650#include <linux/interrupt.h> 650#include <linux/interrupt.h>
651 651
652static volatile int main_running = 0; 652static volatile int main_running = 0;
653static DECLARE_WORK(NCR5380_tqueue, (void (*)(void*))NCR5380_main, NULL); 653static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
654 654
655static __inline__ void queue_main(void) 655static __inline__ void queue_main(void)
656{ 656{
@@ -1031,7 +1031,7 @@ static int NCR5380_queue_command(struct scsi_cmnd *cmd,
1031 * reenable them. This prevents reentrancy and kernel stack overflow. 1031 * reenable them. This prevents reentrancy and kernel stack overflow.
1032 */ 1032 */
1033 1033
1034static void NCR5380_main (void *bl) 1034static void NCR5380_main (struct work_struct *bl)
1035{ 1035{
1036 struct scsi_cmnd *tmp, *prev; 1036 struct scsi_cmnd *tmp, *prev;
1037 struct Scsi_Host *instance = first_instance; 1037 struct Scsi_Host *instance = first_instance;
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 92eba893559d..db8607e3d531 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -278,8 +278,8 @@ static int ulite_request_port(struct uart_port *port)
278 278
279static void ulite_config_port(struct uart_port *port, int flags) 279static void ulite_config_port(struct uart_port *port, int flags)
280{ 280{
281 ulite_request_port(port); 281 if (!ulite_request_port(port))
282 port->type = PORT_UARTLITE; 282 port->type = PORT_UARTLITE;
283} 283}
284 284
285static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser) 285static int ulite_verify_port(struct uart_port *port, struct serial_struct *ser)
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index ff0b04895db0..e9798bf7b8c6 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -112,6 +112,8 @@ u32 mpc83xx_spi_tx_buf_##type(struct mpc83xx_spi *mpc83xx_spi) \
112{ \ 112{ \
113 u32 data; \ 113 u32 data; \
114 const type * tx = mpc83xx_spi->tx; \ 114 const type * tx = mpc83xx_spi->tx; \
115 if (!tx) \
116 return 0; \
115 data = *tx++; \ 117 data = *tx++; \
116 mpc83xx_spi->tx = tx; \ 118 mpc83xx_spi->tx = tx; \
117 return data; \ 119 return data; \
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 2ebe1fc4c398..8ca08713528e 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -174,7 +174,7 @@ static int s3c24xx_spi_setup(struct spi_device *spi)
174 174
175static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count) 175static inline unsigned int hw_txbyte(struct s3c24xx_spi *hw, int count)
176{ 176{
177 return hw->tx ? hw->tx[count] : 0xff; 177 return hw->tx ? hw->tx[count] : 0;
178} 178}
179 179
180static int s3c24xx_spi_txrx(struct spi_device *spi, struct spi_transfer *t) 180static int s3c24xx_spi_txrx(struct spi_device *spi, struct spi_transfer *t)
diff --git a/drivers/spi/spi_s3c24xx_gpio.c b/drivers/spi/spi_s3c24xx_gpio.c
index a5d2cdfff46f..eda53ed04cbc 100644
--- a/drivers/spi/spi_s3c24xx_gpio.c
+++ b/drivers/spi/spi_s3c24xx_gpio.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/spinlock.h> 17#include <linux/spinlock.h>
18#include <linux/workqueue.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19 20
20#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
@@ -22,7 +23,7 @@
22 23
23#include <asm/arch/regs-gpio.h> 24#include <asm/arch/regs-gpio.h>
24#include <asm/arch/spi-gpio.h> 25#include <asm/arch/spi-gpio.h>
25#include <asm/arch/hardware.h> 26#include <asm/hardware.h>
26 27
27struct s3c2410_spigpio { 28struct s3c2410_spigpio {
28 struct spi_bitbang bitbang; 29 struct spi_bitbang bitbang;
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 6303970e93c1..24ee8be359f5 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -130,7 +130,7 @@ MFG:HEWLETT-PACKARD;MDL:DESKJET 970C;CMD:MLC,PCL,PML;CLASS:PRINTER;DESCRIPTION:H
130 130
131struct usblp { 131struct usblp {
132 struct usb_device *dev; /* USB device */ 132 struct usb_device *dev; /* USB device */
133 struct semaphore sem; /* locks this struct, especially "dev" */ 133 struct mutex mut; /* locks this struct, especially "dev" */
134 char *writebuf; /* write transfer_buffer */ 134 char *writebuf; /* write transfer_buffer */
135 char *readbuf; /* read transfer_buffer */ 135 char *readbuf; /* read transfer_buffer */
136 char *statusbuf; /* status transfer_buffer */ 136 char *statusbuf; /* status transfer_buffer */
@@ -465,7 +465,7 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
465 int twoints[2]; 465 int twoints[2];
466 int retval = 0; 466 int retval = 0;
467 467
468 down (&usblp->sem); 468 mutex_lock (&usblp->mut);
469 if (!usblp->present) { 469 if (!usblp->present) {
470 retval = -ENODEV; 470 retval = -ENODEV;
471 goto done; 471 goto done;
@@ -644,14 +644,14 @@ static long usblp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
644 } 644 }
645 645
646done: 646done:
647 up (&usblp->sem); 647 mutex_unlock (&usblp->mut);
648 return retval; 648 return retval;
649} 649}
650 650
651static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 651static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
652{ 652{
653 struct usblp *usblp = file->private_data; 653 struct usblp *usblp = file->private_data;
654 int timeout, rv, err = 0, transfer_length = 0; 654 int timeout, intr, rv, err = 0, transfer_length = 0;
655 size_t writecount = 0; 655 size_t writecount = 0;
656 656
657 while (writecount < count) { 657 while (writecount < count) {
@@ -668,14 +668,16 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
668 if (rv < 0) 668 if (rv < 0)
669 return writecount ? writecount : -EINTR; 669 return writecount ? writecount : -EINTR;
670 } 670 }
671 down (&usblp->sem); 671 intr = mutex_lock_interruptible (&usblp->mut);
672 if (intr)
673 return writecount ? writecount : -EINTR;
672 if (!usblp->present) { 674 if (!usblp->present) {
673 up (&usblp->sem); 675 mutex_unlock (&usblp->mut);
674 return -ENODEV; 676 return -ENODEV;
675 } 677 }
676 678
677 if (usblp->sleeping) { 679 if (usblp->sleeping) {
678 up (&usblp->sem); 680 mutex_unlock (&usblp->mut);
679 return writecount ? writecount : -ENODEV; 681 return writecount ? writecount : -ENODEV;
680 } 682 }
681 683
@@ -687,10 +689,10 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
687 err = usblp->writeurb->status; 689 err = usblp->writeurb->status;
688 } else 690 } else
689 err = usblp_check_status(usblp, err); 691 err = usblp_check_status(usblp, err);
690 up (&usblp->sem); 692 mutex_unlock (&usblp->mut);
691 693
692 /* if the fault was due to disconnect, let khubd's 694 /* if the fault was due to disconnect, let khubd's
693 * call to usblp_disconnect() grab usblp->sem ... 695 * call to usblp_disconnect() grab usblp->mut ...
694 */ 696 */
695 schedule (); 697 schedule ();
696 continue; 698 continue;
@@ -702,7 +704,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
702 */ 704 */
703 writecount += transfer_length; 705 writecount += transfer_length;
704 if (writecount == count) { 706 if (writecount == count) {
705 up(&usblp->sem); 707 mutex_unlock(&usblp->mut);
706 break; 708 break;
707 } 709 }
708 710
@@ -714,7 +716,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
714 716
715 if (copy_from_user(usblp->writeurb->transfer_buffer, 717 if (copy_from_user(usblp->writeurb->transfer_buffer,
716 buffer + writecount, transfer_length)) { 718 buffer + writecount, transfer_length)) {
717 up(&usblp->sem); 719 mutex_unlock(&usblp->mut);
718 return writecount ? writecount : -EFAULT; 720 return writecount ? writecount : -EFAULT;
719 } 721 }
720 722
@@ -727,10 +729,10 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
727 count = -EIO; 729 count = -EIO;
728 else 730 else
729 count = writecount ? writecount : -ENOMEM; 731 count = writecount ? writecount : -ENOMEM;
730 up (&usblp->sem); 732 mutex_unlock (&usblp->mut);
731 break; 733 break;
732 } 734 }
733 up (&usblp->sem); 735 mutex_unlock (&usblp->mut);
734 } 736 }
735 737
736 return count; 738 return count;
@@ -739,12 +741,14 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
739static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 741static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
740{ 742{
741 struct usblp *usblp = file->private_data; 743 struct usblp *usblp = file->private_data;
742 int rv; 744 int rv, intr;
743 745
744 if (!usblp->bidir) 746 if (!usblp->bidir)
745 return -EINVAL; 747 return -EINVAL;
746 748
747 down (&usblp->sem); 749 intr = mutex_lock_interruptible (&usblp->mut);
750 if (intr)
751 return -EINTR;
748 if (!usblp->present) { 752 if (!usblp->present) {
749 count = -ENODEV; 753 count = -ENODEV;
750 goto done; 754 goto done;
@@ -757,9 +761,9 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
757 count = -EAGAIN; 761 count = -EAGAIN;
758 goto done; 762 goto done;
759 } 763 }
760 up(&usblp->sem); 764 mutex_unlock(&usblp->mut);
761 rv = wait_event_interruptible(usblp->wait, usblp->rcomplete || !usblp->present); 765 rv = wait_event_interruptible(usblp->wait, usblp->rcomplete || !usblp->present);
762 down(&usblp->sem); 766 mutex_lock(&usblp->mut);
763 if (rv < 0) { 767 if (rv < 0) {
764 count = -EINTR; 768 count = -EINTR;
765 goto done; 769 goto done;
@@ -807,7 +811,7 @@ static ssize_t usblp_read(struct file *file, char __user *buffer, size_t count,
807 } 811 }
808 812
809done: 813done:
810 up (&usblp->sem); 814 mutex_unlock (&usblp->mut);
811 return count; 815 return count;
812} 816}
813 817
@@ -886,7 +890,7 @@ static int usblp_probe(struct usb_interface *intf,
886 goto abort; 890 goto abort;
887 } 891 }
888 usblp->dev = dev; 892 usblp->dev = dev;
889 init_MUTEX (&usblp->sem); 893 mutex_init (&usblp->mut);
890 init_waitqueue_head(&usblp->wait); 894 init_waitqueue_head(&usblp->wait);
891 usblp->ifnum = intf->cur_altsetting->desc.bInterfaceNumber; 895 usblp->ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
892 usblp->intf = intf; 896 usblp->intf = intf;
@@ -1178,7 +1182,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1178 device_remove_file(&intf->dev, &dev_attr_ieee1284_id); 1182 device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
1179 1183
1180 mutex_lock (&usblp_mutex); 1184 mutex_lock (&usblp_mutex);
1181 down (&usblp->sem); 1185 mutex_lock (&usblp->mut);
1182 usblp->present = 0; 1186 usblp->present = 0;
1183 usb_set_intfdata (intf, NULL); 1187 usb_set_intfdata (intf, NULL);
1184 1188
@@ -1187,7 +1191,7 @@ static void usblp_disconnect(struct usb_interface *intf)
1187 usblp->writebuf, usblp->writeurb->transfer_dma); 1191 usblp->writebuf, usblp->writeurb->transfer_dma);
1188 usb_buffer_free (usblp->dev, USBLP_BUF_SIZE, 1192 usb_buffer_free (usblp->dev, USBLP_BUF_SIZE,
1189 usblp->readbuf, usblp->readurb->transfer_dma); 1193 usblp->readbuf, usblp->readurb->transfer_dma);
1190 up (&usblp->sem); 1194 mutex_unlock (&usblp->mut);
1191 1195
1192 if (!usblp->used) 1196 if (!usblp->used)
1193 usblp_cleanup (usblp); 1197 usblp_cleanup (usblp);
@@ -1200,11 +1204,11 @@ static int usblp_suspend (struct usb_interface *intf, pm_message_t message)
1200 1204
1201 /* this races against normal access and open */ 1205 /* this races against normal access and open */
1202 mutex_lock (&usblp_mutex); 1206 mutex_lock (&usblp_mutex);
1203 down (&usblp->sem); 1207 mutex_lock (&usblp->mut);
1204 /* we take no more IO */ 1208 /* we take no more IO */
1205 usblp->sleeping = 1; 1209 usblp->sleeping = 1;
1206 usblp_unlink_urbs(usblp); 1210 usblp_unlink_urbs(usblp);
1207 up (&usblp->sem); 1211 mutex_unlock (&usblp->mut);
1208 mutex_unlock (&usblp_mutex); 1212 mutex_unlock (&usblp_mutex);
1209 1213
1210 return 0; 1214 return 0;
@@ -1216,12 +1220,12 @@ static int usblp_resume (struct usb_interface *intf)
1216 int r; 1220 int r;
1217 1221
1218 mutex_lock (&usblp_mutex); 1222 mutex_lock (&usblp_mutex);
1219 down (&usblp->sem); 1223 mutex_lock (&usblp->mut);
1220 1224
1221 usblp->sleeping = 0; 1225 usblp->sleeping = 0;
1222 r = handle_bidir (usblp); 1226 r = handle_bidir (usblp);
1223 1227
1224 up (&usblp->sem); 1228 mutex_unlock (&usblp->mut);
1225 mutex_unlock (&usblp_mutex); 1229 mutex_unlock (&usblp_mutex);
1226 1230
1227 return r; 1231 return r;
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 3ed4cb2d56d9..4b3a6ab29bd3 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -962,7 +962,11 @@ static int proc_do_submiturb(struct dev_state *ps, struct usbdevfs_urb *uurb,
962 kfree(dr); 962 kfree(dr);
963 return -EFAULT; 963 return -EFAULT;
964 } 964 }
965 snoop(&ps->dev->dev, "control urb\n"); 965 snoop(&ps->dev->dev, "control urb: bRequest=%02x "
966 "bRrequestType=%02x wValue=%04x "
967 "wIndex=%04x wLength=%04x\n",
968 dr->bRequest, dr->bRequestType, dr->wValue,
969 dr->wIndex, dr->wLength);
966 break; 970 break;
967 971
968 case USBDEVFS_URB_TYPE_BULK: 972 case USBDEVFS_URB_TYPE_BULK:
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 3e0abbb49fe1..812c733ba8ce 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -43,14 +43,16 @@
43#include <linux/usb_gadget.h> 43#include <linux/usb_gadget.h>
44 44
45#include <asm/byteorder.h> 45#include <asm/byteorder.h>
46#include <asm/hardware.h>
46#include <asm/io.h> 47#include <asm/io.h>
47#include <asm/irq.h> 48#include <asm/irq.h>
48#include <asm/system.h> 49#include <asm/system.h>
49#include <asm/mach-types.h> 50#include <asm/mach-types.h>
50 51
51#include <asm/arch/hardware.h>
52#include <asm/arch/gpio.h> 52#include <asm/arch/gpio.h>
53#include <asm/arch/board.h> 53#include <asm/arch/board.h>
54#include <asm/arch/cpu.h>
55#include <asm/arch/at91sam9261_matrix.h>
54 56
55#include "at91_udc.h" 57#include "at91_udc.h"
56 58
@@ -78,27 +80,11 @@
78static const char driver_name [] = "at91_udc"; 80static const char driver_name [] = "at91_udc";
79static const char ep0name[] = "ep0"; 81static const char ep0name[] = "ep0";
80 82
81/*-------------------------------------------------------------------------*/
82 83
83/* 84#define at91_udp_read(dev, reg) \
84 * Read from a UDP register. 85 __raw_readl((dev)->udp_baseaddr + (reg))
85 */ 86#define at91_udp_write(dev, reg, val) \
86static inline unsigned long at91_udp_read(unsigned int reg) 87 __raw_writel((val), (dev)->udp_baseaddr + (reg))
87{
88 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
89
90 return __raw_readl(udp_base + reg);
91}
92
93/*
94 * Write to a UDP register.
95 */
96static inline void at91_udp_write(unsigned int reg, unsigned long value)
97{
98 void __iomem *udp_base = (void __iomem *)AT91_VA_BASE_UDP;
99
100 __raw_writel(value, udp_base + reg);
101}
102 88
103/*-------------------------------------------------------------------------*/ 89/*-------------------------------------------------------------------------*/
104 90
@@ -210,13 +196,13 @@ static int proc_udc_show(struct seq_file *s, void *unused)
210 return 0; 196 return 0;
211 } 197 }
212 198
213 tmp = at91_udp_read(AT91_UDP_FRM_NUM); 199 tmp = at91_udp_read(udc, AT91_UDP_FRM_NUM);
214 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp, 200 seq_printf(s, "frame %05x:%s%s frame=%d\n", tmp,
215 (tmp & AT91_UDP_FRM_OK) ? " ok" : "", 201 (tmp & AT91_UDP_FRM_OK) ? " ok" : "",
216 (tmp & AT91_UDP_FRM_ERR) ? " err" : "", 202 (tmp & AT91_UDP_FRM_ERR) ? " err" : "",
217 (tmp & AT91_UDP_NUM)); 203 (tmp & AT91_UDP_NUM));
218 204
219 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 205 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
220 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp, 206 seq_printf(s, "glbstate %02x:%s" FOURBITS "\n", tmp,
221 (tmp & AT91_UDP_RMWUPE) ? " rmwupe" : "", 207 (tmp & AT91_UDP_RMWUPE) ? " rmwupe" : "",
222 (tmp & AT91_UDP_RSMINPR) ? " rsminpr" : "", 208 (tmp & AT91_UDP_RSMINPR) ? " rsminpr" : "",
@@ -224,13 +210,13 @@ static int proc_udc_show(struct seq_file *s, void *unused)
224 (tmp & AT91_UDP_CONFG) ? " confg" : "", 210 (tmp & AT91_UDP_CONFG) ? " confg" : "",
225 (tmp & AT91_UDP_FADDEN) ? " fadden" : ""); 211 (tmp & AT91_UDP_FADDEN) ? " fadden" : "");
226 212
227 tmp = at91_udp_read(AT91_UDP_FADDR); 213 tmp = at91_udp_read(udc, AT91_UDP_FADDR);
228 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp, 214 seq_printf(s, "faddr %03x:%s fadd=%d\n", tmp,
229 (tmp & AT91_UDP_FEN) ? " fen" : "", 215 (tmp & AT91_UDP_FEN) ? " fen" : "",
230 (tmp & AT91_UDP_FADD)); 216 (tmp & AT91_UDP_FADD));
231 217
232 proc_irq_show(s, "imr ", at91_udp_read(AT91_UDP_IMR)); 218 proc_irq_show(s, "imr ", at91_udp_read(udc, AT91_UDP_IMR));
233 proc_irq_show(s, "isr ", at91_udp_read(AT91_UDP_ISR)); 219 proc_irq_show(s, "isr ", at91_udp_read(udc, AT91_UDP_ISR));
234 220
235 if (udc->enabled && udc->vbus) { 221 if (udc->enabled && udc->vbus) {
236 proc_ep_show(s, &udc->ep[0]); 222 proc_ep_show(s, &udc->ep[0]);
@@ -286,6 +272,7 @@ static inline void remove_debug_file(struct at91_udc *udc) {}
286static void done(struct at91_ep *ep, struct at91_request *req, int status) 272static void done(struct at91_ep *ep, struct at91_request *req, int status)
287{ 273{
288 unsigned stopped = ep->stopped; 274 unsigned stopped = ep->stopped;
275 struct at91_udc *udc = ep->udc;
289 276
290 list_del_init(&req->queue); 277 list_del_init(&req->queue);
291 if (req->req.status == -EINPROGRESS) 278 if (req->req.status == -EINPROGRESS)
@@ -301,7 +288,7 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
301 288
302 /* ep0 is always ready; other endpoints need a non-empty queue */ 289 /* ep0 is always ready; other endpoints need a non-empty queue */
303 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0)) 290 if (list_empty(&ep->queue) && ep->int_mask != (1 << 0))
304 at91_udp_write(AT91_UDP_IDR, ep->int_mask); 291 at91_udp_write(udc, AT91_UDP_IDR, ep->int_mask);
305} 292}
306 293
307/*-------------------------------------------------------------------------*/ 294/*-------------------------------------------------------------------------*/
@@ -554,8 +541,8 @@ ok:
554 * reset/init endpoint fifo. NOTE: leaves fifo_bank alone, 541 * reset/init endpoint fifo. NOTE: leaves fifo_bank alone,
555 * since endpoint resets don't reset hw pingpong state. 542 * since endpoint resets don't reset hw pingpong state.
556 */ 543 */
557 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 544 at91_udp_write(dev, AT91_UDP_RST_EP, ep->int_mask);
558 at91_udp_write(AT91_UDP_RST_EP, 0); 545 at91_udp_write(dev, AT91_UDP_RST_EP, 0);
559 546
560 local_irq_restore(flags); 547 local_irq_restore(flags);
561 return 0; 548 return 0;
@@ -564,6 +551,7 @@ ok:
564static int at91_ep_disable (struct usb_ep * _ep) 551static int at91_ep_disable (struct usb_ep * _ep)
565{ 552{
566 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 553 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
554 struct at91_udc *udc = ep->udc;
567 unsigned long flags; 555 unsigned long flags;
568 556
569 if (ep == &ep->udc->ep[0]) 557 if (ep == &ep->udc->ep[0])
@@ -579,8 +567,8 @@ static int at91_ep_disable (struct usb_ep * _ep)
579 567
580 /* reset fifos and endpoint */ 568 /* reset fifos and endpoint */
581 if (ep->udc->clocked) { 569 if (ep->udc->clocked) {
582 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 570 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
583 at91_udp_write(AT91_UDP_RST_EP, 0); 571 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
584 __raw_writel(0, ep->creg); 572 __raw_writel(0, ep->creg);
585 } 573 }
586 574
@@ -695,10 +683,10 @@ static int at91_ep_queue(struct usb_ep *_ep,
695 * reconfigures the endpoints. 683 * reconfigures the endpoints.
696 */ 684 */
697 if (dev->wait_for_config_ack) { 685 if (dev->wait_for_config_ack) {
698 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 686 tmp = at91_udp_read(dev, AT91_UDP_GLB_STAT);
699 tmp ^= AT91_UDP_CONFG; 687 tmp ^= AT91_UDP_CONFG;
700 VDBG("toggle config\n"); 688 VDBG("toggle config\n");
701 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 689 at91_udp_write(dev, AT91_UDP_GLB_STAT, tmp);
702 } 690 }
703 if (req->req.length == 0) { 691 if (req->req.length == 0) {
704ep0_in_status: 692ep0_in_status:
@@ -727,7 +715,7 @@ ep0_in_status:
727 715
728 if (req && !status) { 716 if (req && !status) {
729 list_add_tail (&req->queue, &ep->queue); 717 list_add_tail (&req->queue, &ep->queue);
730 at91_udp_write(AT91_UDP_IER, ep->int_mask); 718 at91_udp_write(dev, AT91_UDP_IER, ep->int_mask);
731 } 719 }
732done: 720done:
733 local_irq_restore(flags); 721 local_irq_restore(flags);
@@ -758,6 +746,7 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
758static int at91_ep_set_halt(struct usb_ep *_ep, int value) 746static int at91_ep_set_halt(struct usb_ep *_ep, int value)
759{ 747{
760 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep); 748 struct at91_ep *ep = container_of(_ep, struct at91_ep, ep);
749 struct at91_udc *udc = ep->udc;
761 u32 __iomem *creg; 750 u32 __iomem *creg;
762 u32 csr; 751 u32 csr;
763 unsigned long flags; 752 unsigned long flags;
@@ -785,8 +774,8 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
785 csr |= AT91_UDP_FORCESTALL; 774 csr |= AT91_UDP_FORCESTALL;
786 VDBG("halt %s\n", ep->ep.name); 775 VDBG("halt %s\n", ep->ep.name);
787 } else { 776 } else {
788 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 777 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
789 at91_udp_write(AT91_UDP_RST_EP, 0); 778 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
790 csr &= ~AT91_UDP_FORCESTALL; 779 csr &= ~AT91_UDP_FORCESTALL;
791 } 780 }
792 __raw_writel(csr, creg); 781 __raw_writel(csr, creg);
@@ -813,9 +802,11 @@ static struct usb_ep_ops at91_ep_ops = {
813 802
814static int at91_get_frame(struct usb_gadget *gadget) 803static int at91_get_frame(struct usb_gadget *gadget)
815{ 804{
805 struct at91_udc *udc = to_udc(gadget);
806
816 if (!to_udc(gadget)->clocked) 807 if (!to_udc(gadget)->clocked)
817 return -EINVAL; 808 return -EINVAL;
818 return at91_udp_read(AT91_UDP_FRM_NUM) & AT91_UDP_NUM; 809 return at91_udp_read(udc, AT91_UDP_FRM_NUM) & AT91_UDP_NUM;
819} 810}
820 811
821static int at91_wakeup(struct usb_gadget *gadget) 812static int at91_wakeup(struct usb_gadget *gadget)
@@ -833,11 +824,11 @@ static int at91_wakeup(struct usb_gadget *gadget)
833 824
834 /* NOTE: some "early versions" handle ESR differently ... */ 825 /* NOTE: some "early versions" handle ESR differently ... */
835 826
836 glbstate = at91_udp_read(AT91_UDP_GLB_STAT); 827 glbstate = at91_udp_read(udc, AT91_UDP_GLB_STAT);
837 if (!(glbstate & AT91_UDP_ESR)) 828 if (!(glbstate & AT91_UDP_ESR))
838 goto done; 829 goto done;
839 glbstate |= AT91_UDP_ESR; 830 glbstate |= AT91_UDP_ESR;
840 at91_udp_write(AT91_UDP_GLB_STAT, glbstate); 831 at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate);
841 832
842done: 833done:
843 local_irq_restore(flags); 834 local_irq_restore(flags);
@@ -861,6 +852,7 @@ static void udc_reinit(struct at91_udc *udc)
861 ep->stopped = 0; 852 ep->stopped = 0;
862 ep->fifo_bank = 0; 853 ep->fifo_bank = 0;
863 ep->ep.maxpacket = ep->maxpacket; 854 ep->ep.maxpacket = ep->maxpacket;
855 ep->creg = (void __iomem *) udc->udp_baseaddr + AT91_UDP_CSR(i);
864 // initialiser une queue par endpoint 856 // initialiser une queue par endpoint
865 INIT_LIST_HEAD(&ep->queue); 857 INIT_LIST_HEAD(&ep->queue);
866 } 858 }
@@ -915,14 +907,41 @@ static void pullup(struct at91_udc *udc, int is_on)
915 if (!udc->enabled || !udc->vbus) 907 if (!udc->enabled || !udc->vbus)
916 is_on = 0; 908 is_on = 0;
917 DBG("%sactive\n", is_on ? "" : "in"); 909 DBG("%sactive\n", is_on ? "" : "in");
910
918 if (is_on) { 911 if (is_on) {
919 clk_on(udc); 912 clk_on(udc);
920 at91_udp_write(AT91_UDP_TXVC, 0); 913 at91_udp_write(udc, AT91_UDP_TXVC, 0);
921 at91_set_gpio_value(udc->board.pullup_pin, 1); 914 if (cpu_is_at91rm9200())
922 } else { 915 at91_set_gpio_value(udc->board.pullup_pin, 1);
916 else if (cpu_is_at91sam9260()) {
917 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
918
919 txvc |= AT91_UDP_TXVC_PUON;
920 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
921 } else if (cpu_is_at91sam9261()) {
922 u32 usbpucr;
923
924 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
925 usbpucr |= AT91_MATRIX_USBPUCR_PUON;
926 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);
927 }
928 } else {
923 stop_activity(udc); 929 stop_activity(udc);
924 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 930 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
925 at91_set_gpio_value(udc->board.pullup_pin, 0); 931 if (cpu_is_at91rm9200())
932 at91_set_gpio_value(udc->board.pullup_pin, 0);
933 else if (cpu_is_at91sam9260()) {
934 u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
935
936 txvc &= ~AT91_UDP_TXVC_PUON;
937 at91_udp_write(udc, AT91_UDP_TXVC, txvc);
938 } else if (cpu_is_at91sam9261()) {
939 u32 usbpucr;
940
941 usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
942 usbpucr &= ~AT91_MATRIX_USBPUCR_PUON;
943 at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);
944 }
926 clk_off(udc); 945 clk_off(udc);
927 } 946 }
928} 947}
@@ -936,7 +955,10 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active)
936 // VDBG("vbus %s\n", is_active ? "on" : "off"); 955 // VDBG("vbus %s\n", is_active ? "on" : "off");
937 local_irq_save(flags); 956 local_irq_save(flags);
938 udc->vbus = (is_active != 0); 957 udc->vbus = (is_active != 0);
939 pullup(udc, is_active); 958 if (udc->driver)
959 pullup(udc, is_active);
960 else
961 pullup(udc, 0);
940 local_irq_restore(flags); 962 local_irq_restore(flags);
941 return 0; 963 return 0;
942} 964}
@@ -1086,7 +1108,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1086 1108
1087 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1109 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1088 | USB_REQ_SET_CONFIGURATION: 1110 | USB_REQ_SET_CONFIGURATION:
1089 tmp = at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_CONFG; 1111 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT) & AT91_UDP_CONFG;
1090 if (pkt.r.wValue) 1112 if (pkt.r.wValue)
1091 udc->wait_for_config_ack = (tmp == 0); 1113 udc->wait_for_config_ack = (tmp == 0);
1092 else 1114 else
@@ -1103,7 +1125,7 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1103 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1125 case ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1104 | USB_REQ_GET_STATUS: 1126 | USB_REQ_GET_STATUS:
1105 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED); 1127 tmp = (udc->selfpowered << USB_DEVICE_SELF_POWERED);
1106 if (at91_udp_read(AT91_UDP_GLB_STAT) & AT91_UDP_ESR) 1128 if (at91_udp_read(udc, AT91_UDP_GLB_STAT) & AT91_UDP_ESR)
1107 tmp |= (1 << USB_DEVICE_REMOTE_WAKEUP); 1129 tmp |= (1 << USB_DEVICE_REMOTE_WAKEUP);
1108 PACKET("get device status\n"); 1130 PACKET("get device status\n");
1109 __raw_writeb(tmp, dreg); 1131 __raw_writeb(tmp, dreg);
@@ -1114,17 +1136,17 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1114 | USB_REQ_SET_FEATURE: 1136 | USB_REQ_SET_FEATURE:
1115 if (w_value != USB_DEVICE_REMOTE_WAKEUP) 1137 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1116 goto stall; 1138 goto stall;
1117 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1139 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1118 tmp |= AT91_UDP_ESR; 1140 tmp |= AT91_UDP_ESR;
1119 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1141 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1120 goto succeed; 1142 goto succeed;
1121 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8) 1143 case ((USB_TYPE_STANDARD|USB_RECIP_DEVICE) << 8)
1122 | USB_REQ_CLEAR_FEATURE: 1144 | USB_REQ_CLEAR_FEATURE:
1123 if (w_value != USB_DEVICE_REMOTE_WAKEUP) 1145 if (w_value != USB_DEVICE_REMOTE_WAKEUP)
1124 goto stall; 1146 goto stall;
1125 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1147 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1126 tmp &= ~AT91_UDP_ESR; 1148 tmp &= ~AT91_UDP_ESR;
1127 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1149 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1128 goto succeed; 1150 goto succeed;
1129 1151
1130 /* 1152 /*
@@ -1206,8 +1228,8 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1206 } else if (ep->is_in) 1228 } else if (ep->is_in)
1207 goto stall; 1229 goto stall;
1208 1230
1209 at91_udp_write(AT91_UDP_RST_EP, ep->int_mask); 1231 at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
1210 at91_udp_write(AT91_UDP_RST_EP, 0); 1232 at91_udp_write(udc, AT91_UDP_RST_EP, 0);
1211 tmp = __raw_readl(ep->creg); 1233 tmp = __raw_readl(ep->creg);
1212 tmp |= CLR_FX; 1234 tmp |= CLR_FX;
1213 tmp &= ~(SET_FX | AT91_UDP_FORCESTALL); 1235 tmp &= ~(SET_FX | AT91_UDP_FORCESTALL);
@@ -1222,7 +1244,10 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
1222#undef w_length 1244#undef w_length
1223 1245
1224 /* pass request up to the gadget driver */ 1246 /* pass request up to the gadget driver */
1225 status = udc->driver->setup(&udc->gadget, &pkt.r); 1247 if (udc->driver)
1248 status = udc->driver->setup(&udc->gadget, &pkt.r);
1249 else
1250 status = -ENODEV;
1226 if (status < 0) { 1251 if (status < 0) {
1227stall: 1252stall:
1228 VDBG("req %02x.%02x protocol STALL; stat %d\n", 1253 VDBG("req %02x.%02x protocol STALL; stat %d\n",
@@ -1300,13 +1325,13 @@ static void handle_ep0(struct at91_udc *udc)
1300 if (udc->wait_for_addr_ack) { 1325 if (udc->wait_for_addr_ack) {
1301 u32 tmp; 1326 u32 tmp;
1302 1327
1303 at91_udp_write(AT91_UDP_FADDR, 1328 at91_udp_write(udc, AT91_UDP_FADDR,
1304 AT91_UDP_FEN | udc->addr); 1329 AT91_UDP_FEN | udc->addr);
1305 tmp = at91_udp_read(AT91_UDP_GLB_STAT); 1330 tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
1306 tmp &= ~AT91_UDP_FADDEN; 1331 tmp &= ~AT91_UDP_FADDEN;
1307 if (udc->addr) 1332 if (udc->addr)
1308 tmp |= AT91_UDP_FADDEN; 1333 tmp |= AT91_UDP_FADDEN;
1309 at91_udp_write(AT91_UDP_GLB_STAT, tmp); 1334 at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
1310 1335
1311 udc->wait_for_addr_ack = 0; 1336 udc->wait_for_addr_ack = 0;
1312 VDBG("address %d\n", udc->addr); 1337 VDBG("address %d\n", udc->addr);
@@ -1374,28 +1399,28 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1374 while (rescans--) { 1399 while (rescans--) {
1375 u32 status; 1400 u32 status;
1376 1401
1377 status = at91_udp_read(AT91_UDP_ISR) 1402 status = at91_udp_read(udc, AT91_UDP_ISR)
1378 & at91_udp_read(AT91_UDP_IMR); 1403 & at91_udp_read(udc, AT91_UDP_IMR);
1379 if (!status) 1404 if (!status)
1380 break; 1405 break;
1381 1406
1382 /* USB reset irq: not maskable */ 1407 /* USB reset irq: not maskable */
1383 if (status & AT91_UDP_ENDBUSRES) { 1408 if (status & AT91_UDP_ENDBUSRES) {
1384 at91_udp_write(AT91_UDP_IDR, ~MINIMUS_INTERRUPTUS); 1409 at91_udp_write(udc, AT91_UDP_IDR, ~MINIMUS_INTERRUPTUS);
1385 at91_udp_write(AT91_UDP_IER, MINIMUS_INTERRUPTUS); 1410 at91_udp_write(udc, AT91_UDP_IER, MINIMUS_INTERRUPTUS);
1386 /* Atmel code clears this irq twice */ 1411 /* Atmel code clears this irq twice */
1387 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES); 1412 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1388 at91_udp_write(AT91_UDP_ICR, AT91_UDP_ENDBUSRES); 1413 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_ENDBUSRES);
1389 VDBG("end bus reset\n"); 1414 VDBG("end bus reset\n");
1390 udc->addr = 0; 1415 udc->addr = 0;
1391 stop_activity(udc); 1416 stop_activity(udc);
1392 1417
1393 /* enable ep0 */ 1418 /* enable ep0 */
1394 at91_udp_write(AT91_UDP_CSR(0), 1419 at91_udp_write(udc, AT91_UDP_CSR(0),
1395 AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL); 1420 AT91_UDP_EPEDS | AT91_UDP_EPTYPE_CTRL);
1396 udc->gadget.speed = USB_SPEED_FULL; 1421 udc->gadget.speed = USB_SPEED_FULL;
1397 udc->suspended = 0; 1422 udc->suspended = 0;
1398 at91_udp_write(AT91_UDP_IER, AT91_UDP_EP(0)); 1423 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_EP(0));
1399 1424
1400 /* 1425 /*
1401 * NOTE: this driver keeps clocks off unless the 1426 * NOTE: this driver keeps clocks off unless the
@@ -1406,9 +1431,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1406 1431
1407 /* host initiated suspend (3+ms bus idle) */ 1432 /* host initiated suspend (3+ms bus idle) */
1408 } else if (status & AT91_UDP_RXSUSP) { 1433 } else if (status & AT91_UDP_RXSUSP) {
1409 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXSUSP); 1434 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXSUSP);
1410 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXRSM); 1435 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXRSM);
1411 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXSUSP); 1436 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXSUSP);
1412 // VDBG("bus suspend\n"); 1437 // VDBG("bus suspend\n");
1413 if (udc->suspended) 1438 if (udc->suspended)
1414 continue; 1439 continue;
@@ -1425,9 +1450,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
1425 1450
1426 /* host initiated resume */ 1451 /* host initiated resume */
1427 } else if (status & AT91_UDP_RXRSM) { 1452 } else if (status & AT91_UDP_RXRSM) {
1428 at91_udp_write(AT91_UDP_IDR, AT91_UDP_RXRSM); 1453 at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
1429 at91_udp_write(AT91_UDP_IER, AT91_UDP_RXSUSP); 1454 at91_udp_write(udc, AT91_UDP_IER, AT91_UDP_RXSUSP);
1430 at91_udp_write(AT91_UDP_ICR, AT91_UDP_RXRSM); 1455 at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
1431 // VDBG("bus resume\n"); 1456 // VDBG("bus resume\n");
1432 if (!udc->suspended) 1457 if (!udc->suspended)
1433 continue; 1458 continue;
@@ -1485,8 +1510,6 @@ static struct at91_udc controller = {
1485 }, 1510 },
1486 .udc = &controller, 1511 .udc = &controller,
1487 .maxpacket = 8, 1512 .maxpacket = 8,
1488 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1489 + AT91_UDP_CSR(0)),
1490 .int_mask = 1 << 0, 1513 .int_mask = 1 << 0,
1491 }, 1514 },
1492 .ep[1] = { 1515 .ep[1] = {
@@ -1497,8 +1520,6 @@ static struct at91_udc controller = {
1497 .udc = &controller, 1520 .udc = &controller,
1498 .is_pingpong = 1, 1521 .is_pingpong = 1,
1499 .maxpacket = 64, 1522 .maxpacket = 64,
1500 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1501 + AT91_UDP_CSR(1)),
1502 .int_mask = 1 << 1, 1523 .int_mask = 1 << 1,
1503 }, 1524 },
1504 .ep[2] = { 1525 .ep[2] = {
@@ -1509,8 +1530,6 @@ static struct at91_udc controller = {
1509 .udc = &controller, 1530 .udc = &controller,
1510 .is_pingpong = 1, 1531 .is_pingpong = 1,
1511 .maxpacket = 64, 1532 .maxpacket = 64,
1512 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1513 + AT91_UDP_CSR(2)),
1514 .int_mask = 1 << 2, 1533 .int_mask = 1 << 2,
1515 }, 1534 },
1516 .ep[3] = { 1535 .ep[3] = {
@@ -1521,8 +1540,6 @@ static struct at91_udc controller = {
1521 }, 1540 },
1522 .udc = &controller, 1541 .udc = &controller,
1523 .maxpacket = 8, 1542 .maxpacket = 8,
1524 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1525 + AT91_UDP_CSR(3)),
1526 .int_mask = 1 << 3, 1543 .int_mask = 1 << 3,
1527 }, 1544 },
1528 .ep[4] = { 1545 .ep[4] = {
@@ -1533,8 +1550,6 @@ static struct at91_udc controller = {
1533 .udc = &controller, 1550 .udc = &controller,
1534 .is_pingpong = 1, 1551 .is_pingpong = 1,
1535 .maxpacket = 256, 1552 .maxpacket = 256,
1536 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1537 + AT91_UDP_CSR(4)),
1538 .int_mask = 1 << 4, 1553 .int_mask = 1 << 4,
1539 }, 1554 },
1540 .ep[5] = { 1555 .ep[5] = {
@@ -1545,8 +1560,6 @@ static struct at91_udc controller = {
1545 .udc = &controller, 1560 .udc = &controller,
1546 .is_pingpong = 1, 1561 .is_pingpong = 1,
1547 .maxpacket = 256, 1562 .maxpacket = 256,
1548 .creg = (void __iomem *)(AT91_VA_BASE_UDP
1549 + AT91_UDP_CSR(5)),
1550 .int_mask = 1 << 5, 1563 .int_mask = 1 << 5,
1551 }, 1564 },
1552 /* ep6 and ep7 are also reserved (custom silicon might use them) */ 1565 /* ep6 and ep7 are also reserved (custom silicon might use them) */
@@ -1572,9 +1585,8 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1572 int retval; 1585 int retval;
1573 1586
1574 if (!driver 1587 if (!driver
1575 || driver->speed != USB_SPEED_FULL 1588 || driver->speed < USB_SPEED_FULL
1576 || !driver->bind 1589 || !driver->bind
1577 || !driver->unbind
1578 || !driver->setup) { 1590 || !driver->setup) {
1579 DBG("bad parameter.\n"); 1591 DBG("bad parameter.\n");
1580 return -EINVAL; 1592 return -EINVAL;
@@ -1595,6 +1607,10 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
1595 if (retval) { 1607 if (retval) {
1596 DBG("driver->bind() returned %d\n", retval); 1608 DBG("driver->bind() returned %d\n", retval);
1597 udc->driver = NULL; 1609 udc->driver = NULL;
1610 udc->gadget.dev.driver = NULL;
1611 udc->gadget.dev.driver_data = NULL;
1612 udc->enabled = 0;
1613 udc->selfpowered = 0;
1598 return retval; 1614 return retval;
1599 } 1615 }
1600 1616
@@ -1611,12 +1627,12 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
1611{ 1627{
1612 struct at91_udc *udc = &controller; 1628 struct at91_udc *udc = &controller;
1613 1629
1614 if (!driver || driver != udc->driver) 1630 if (!driver || driver != udc->driver || !driver->unbind)
1615 return -EINVAL; 1631 return -EINVAL;
1616 1632
1617 local_irq_disable(); 1633 local_irq_disable();
1618 udc->enabled = 0; 1634 udc->enabled = 0;
1619 at91_udp_write(AT91_UDP_IDR, ~0); 1635 at91_udp_write(udc, AT91_UDP_IDR, ~0);
1620 pullup(udc, 0); 1636 pullup(udc, 0);
1621 local_irq_enable(); 1637 local_irq_enable();
1622 1638
@@ -1641,6 +1657,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1641 struct device *dev = &pdev->dev; 1657 struct device *dev = &pdev->dev;
1642 struct at91_udc *udc; 1658 struct at91_udc *udc;
1643 int retval; 1659 int retval;
1660 struct resource *res;
1644 1661
1645 if (!dev->platform_data) { 1662 if (!dev->platform_data) {
1646 /* small (so we copy it) but critical! */ 1663 /* small (so we copy it) but critical! */
@@ -1658,7 +1675,13 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1658 return -ENODEV; 1675 return -ENODEV;
1659 } 1676 }
1660 1677
1661 if (!request_mem_region(AT91RM9200_BASE_UDP, SZ_16K, driver_name)) { 1678 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1679 if (!res)
1680 return -ENXIO;
1681
1682 if (!request_mem_region(res->start,
1683 res->end - res->start + 1,
1684 driver_name)) {
1662 DBG("someone's using UDC memory\n"); 1685 DBG("someone's using UDC memory\n");
1663 return -EBUSY; 1686 return -EBUSY;
1664 } 1687 }
@@ -1668,15 +1691,23 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1668 udc->gadget.dev.parent = dev; 1691 udc->gadget.dev.parent = dev;
1669 udc->board = *(struct at91_udc_data *) dev->platform_data; 1692 udc->board = *(struct at91_udc_data *) dev->platform_data;
1670 udc->pdev = pdev; 1693 udc->pdev = pdev;
1671 udc_reinit(udc);
1672 udc->enabled = 0; 1694 udc->enabled = 0;
1673 1695
1696 udc->udp_baseaddr = ioremap(res->start, res->end - res->start + 1);
1697 if (!udc->udp_baseaddr) {
1698 release_mem_region(res->start, res->end - res->start + 1);
1699 return -ENOMEM;
1700 }
1701
1702 udc_reinit(udc);
1703
1674 /* get interface and function clocks */ 1704 /* get interface and function clocks */
1675 udc->iclk = clk_get(dev, "udc_clk"); 1705 udc->iclk = clk_get(dev, "udc_clk");
1676 udc->fclk = clk_get(dev, "udpck"); 1706 udc->fclk = clk_get(dev, "udpck");
1677 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) { 1707 if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
1678 DBG("clocks missing\n"); 1708 DBG("clocks missing\n");
1679 return -ENODEV; 1709 retval = -ENODEV;
1710 goto fail0;
1680 } 1711 }
1681 1712
1682 retval = device_register(&udc->gadget.dev); 1713 retval = device_register(&udc->gadget.dev);
@@ -1685,8 +1716,10 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1685 1716
1686 /* don't do anything until we have both gadget driver and VBUS */ 1717 /* don't do anything until we have both gadget driver and VBUS */
1687 clk_enable(udc->iclk); 1718 clk_enable(udc->iclk);
1688 at91_udp_write(AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS); 1719 at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
1689 at91_udp_write(AT91_UDP_IDR, 0xffffffff); 1720 at91_udp_write(udc, AT91_UDP_IDR, 0xffffffff);
1721 /* Clear all pending interrupts - UDP may be used by bootloader. */
1722 at91_udp_write(udc, AT91_UDP_ICR, 0xffffffff);
1690 clk_disable(udc->iclk); 1723 clk_disable(udc->iclk);
1691 1724
1692 /* request UDC and maybe VBUS irqs */ 1725 /* request UDC and maybe VBUS irqs */
@@ -1698,6 +1731,11 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1698 goto fail1; 1731 goto fail1;
1699 } 1732 }
1700 if (udc->board.vbus_pin > 0) { 1733 if (udc->board.vbus_pin > 0) {
1734 /*
1735 * Get the initial state of VBUS - we cannot expect
1736 * a pending interrupt.
1737 */
1738 udc->vbus = at91_get_gpio_value(udc->board.vbus_pin);
1701 if (request_irq(udc->board.vbus_pin, at91_vbus_irq, 1739 if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
1702 IRQF_DISABLED, driver_name, udc)) { 1740 IRQF_DISABLED, driver_name, udc)) {
1703 DBG("request vbus irq %d failed\n", 1741 DBG("request vbus irq %d failed\n",
@@ -1720,7 +1758,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1720fail1: 1758fail1:
1721 device_unregister(&udc->gadget.dev); 1759 device_unregister(&udc->gadget.dev);
1722fail0: 1760fail0:
1723 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K); 1761 release_mem_region(res->start, res->end - res->start + 1);
1724 DBG("%s probe failed, %d\n", driver_name, retval); 1762 DBG("%s probe failed, %d\n", driver_name, retval);
1725 return retval; 1763 return retval;
1726} 1764}
@@ -1728,13 +1766,14 @@ fail0:
1728static int __devexit at91udc_remove(struct platform_device *pdev) 1766static int __devexit at91udc_remove(struct platform_device *pdev)
1729{ 1767{
1730 struct at91_udc *udc = platform_get_drvdata(pdev); 1768 struct at91_udc *udc = platform_get_drvdata(pdev);
1769 struct resource *res;
1731 1770
1732 DBG("remove\n"); 1771 DBG("remove\n");
1733 1772
1734 pullup(udc, 0); 1773 if (udc->driver)
1774 return -EBUSY;
1735 1775
1736 if (udc->driver != 0) 1776 pullup(udc, 0);
1737 usb_gadget_unregister_driver(udc->driver);
1738 1777
1739 device_init_wakeup(&pdev->dev, 0); 1778 device_init_wakeup(&pdev->dev, 0);
1740 remove_debug_file(udc); 1779 remove_debug_file(udc);
@@ -1742,7 +1781,10 @@ static int __devexit at91udc_remove(struct platform_device *pdev)
1742 free_irq(udc->board.vbus_pin, udc); 1781 free_irq(udc->board.vbus_pin, udc);
1743 free_irq(udc->udp_irq, udc); 1782 free_irq(udc->udp_irq, udc);
1744 device_unregister(&udc->gadget.dev); 1783 device_unregister(&udc->gadget.dev);
1745 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K); 1784
1785 iounmap(udc->udp_baseaddr);
1786 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1787 release_mem_region(res->start, res->end - res->start + 1);
1746 1788
1747 clk_put(udc->iclk); 1789 clk_put(udc->iclk);
1748 clk_put(udc->fclk); 1790 clk_put(udc->fclk);
diff --git a/drivers/usb/gadget/at91_udc.h b/drivers/usb/gadget/at91_udc.h
index 882af42e86cc..677089baa59d 100644
--- a/drivers/usb/gadget/at91_udc.h
+++ b/drivers/usb/gadget/at91_udc.h
@@ -51,10 +51,10 @@
51#define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */ 51#define AT91_UDP_EP(n) (1 << (n)) /* Endpoint Interrupt Status */
52#define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */ 52#define AT91_UDP_RXSUSP (1 << 8) /* USB Suspend Interrupt Status */
53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */ 53#define AT91_UDP_RXRSM (1 << 9) /* USB Resume Interrupt Status */
54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status */ 54#define AT91_UDP_EXTRSM (1 << 10) /* External Resume Interrupt Status [AT91RM9200 only] */
55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */ 55#define AT91_UDP_SOFINT (1 << 11) /* Start of Frame Interrupt Status */
56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */ 56#define AT91_UDP_ENDBUSRES (1 << 12) /* End of Bus Reset Interrpt Status */
57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status */ 57#define AT91_UDP_WAKEUP (1 << 13) /* USB Wakeup Interrupt Status [AT91RM9200 only] */
58 58
59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */ 59#define AT91_UDP_ICR 0x20 /* Interrupt Clear Register */
60#define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */ 60#define AT91_UDP_RST_EP 0x28 /* Reset Endpoint Register */
@@ -84,7 +84,7 @@
84 84
85#define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */ 85#define AT91_UDP_TXVC 0x74 /* Transceiver Control Register */
86#define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */ 86#define AT91_UDP_TXVC_TXVDIS (1 << 8) /* Transceiver Disable */
87 87#define AT91_UDP_TXVC_PUON (1 << 9) /* PullUp On [AT91SAM9260 only] */
88 88
89/*-------------------------------------------------------------------------*/ 89/*-------------------------------------------------------------------------*/
90 90
@@ -141,6 +141,7 @@ struct at91_udc {
141 struct clk *iclk, *fclk; 141 struct clk *iclk, *fclk;
142 struct platform_device *pdev; 142 struct platform_device *pdev;
143 struct proc_dir_entry *pde; 143 struct proc_dir_entry *pde;
144 void __iomem *udp_baseaddr;
144 int udp_irq; 145 int udp_irq;
145}; 146};
146 147
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index f1f32d7be5f9..3c2bc075ef4f 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -779,7 +779,7 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
779 return -EINVAL; 779 return -EINVAL;
780 if (dum->driver) 780 if (dum->driver)
781 return -EBUSY; 781 return -EBUSY;
782 if (!driver->bind || !driver->unbind || !driver->setup 782 if (!driver->bind || !driver->setup
783 || driver->speed == USB_SPEED_UNKNOWN) 783 || driver->speed == USB_SPEED_UNKNOWN)
784 return -EINVAL; 784 return -EINVAL;
785 785
@@ -837,7 +837,8 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
837err_bind_driver: 837err_bind_driver:
838 driver_unregister (&driver->driver); 838 driver_unregister (&driver->driver);
839err_register: 839err_register:
840 driver->unbind (&dum->gadget); 840 if (driver->unbind)
841 driver->unbind (&dum->gadget);
841 spin_lock_irq (&dum->lock); 842 spin_lock_irq (&dum->lock);
842 dum->pullup = 0; 843 dum->pullup = 0;
843 set_link_state (dum); 844 set_link_state (dum);
@@ -857,7 +858,7 @@ usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
857 858
858 if (!dum) 859 if (!dum)
859 return -ENODEV; 860 return -ENODEV;
860 if (!driver || driver != dum->driver) 861 if (!driver || driver != dum->driver || !driver->unbind)
861 return -EINVAL; 862 return -EINVAL;
862 863
863 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n", 864 dev_dbg (udc_dev(dum), "unregister gadget driver '%s'\n",
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index a265e262a2ee..72f2ae96fbf3 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -4100,7 +4100,7 @@ static struct usb_gadget_driver fsg_driver = {
4100#endif 4100#endif
4101 .function = (char *) longname, 4101 .function = (char *) longname,
4102 .bind = fsg_bind, 4102 .bind = fsg_bind,
4103 .unbind = __exit_p(fsg_unbind), 4103 .unbind = fsg_unbind,
4104 .disconnect = fsg_disconnect, 4104 .disconnect = fsg_disconnect,
4105 .setup = fsg_setup, 4105 .setup = fsg_setup,
4106 .suspend = fsg_suspend, 4106 .suspend = fsg_suspend,
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 31351826f2ba..f1a679656c96 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -123,7 +123,7 @@ struct gmidi_device {
123 struct usb_request *req; /* for control responses */ 123 struct usb_request *req; /* for control responses */
124 u8 config; 124 u8 config;
125 struct usb_ep *in_ep, *out_ep; 125 struct usb_ep *in_ep, *out_ep;
126 struct snd_card *card; 126 struct snd_card *card;
127 struct snd_rawmidi *rmidi; 127 struct snd_rawmidi *rmidi;
128 struct snd_rawmidi_substream *in_substream; 128 struct snd_rawmidi_substream *in_substream;
129 struct snd_rawmidi_substream *out_substream; 129 struct snd_rawmidi_substream *out_substream;
@@ -490,7 +490,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
490 int status = req->status; 490 int status = req->status;
491 491
492 switch (status) { 492 switch (status) {
493 case 0: /* normal completion */ 493 case 0: /* normal completion */
494 if (ep == dev->out_ep) { 494 if (ep == dev->out_ep) {
495 /* we received stuff. 495 /* we received stuff.
496 req is queued again, below */ 496 req is queued again, below */
@@ -505,7 +505,7 @@ static void gmidi_complete(struct usb_ep *ep, struct usb_request *req)
505 break; 505 break;
506 506
507 /* this endpoint is normally active while we're configured */ 507 /* this endpoint is normally active while we're configured */
508 case -ECONNABORTED: /* hardware forced ep reset */ 508 case -ECONNABORTED: /* hardware forced ep reset */
509 case -ECONNRESET: /* request dequeued */ 509 case -ECONNRESET: /* request dequeued */
510 case -ESHUTDOWN: /* disconnect from host */ 510 case -ESHUTDOWN: /* disconnect from host */
511 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status, 511 VDBG(dev, "%s gone (%d), %d/%d\n", ep->name, status,
@@ -656,7 +656,7 @@ gmidi_set_config(struct gmidi_device *dev, unsigned number, gfp_t gfp_flags)
656 case USB_SPEED_LOW: speed = "low"; break; 656 case USB_SPEED_LOW: speed = "low"; break;
657 case USB_SPEED_FULL: speed = "full"; break; 657 case USB_SPEED_FULL: speed = "full"; break;
658 case USB_SPEED_HIGH: speed = "high"; break; 658 case USB_SPEED_HIGH: speed = "high"; break;
659 default: speed = "?"; break; 659 default: speed = "?"; break;
660 } 660 }
661 661
662 dev->config = number; 662 dev->config = number;
@@ -1308,7 +1308,7 @@ static struct usb_gadget_driver gmidi_driver = {
1308 .speed = USB_SPEED_FULL, 1308 .speed = USB_SPEED_FULL,
1309 .function = (char *)longname, 1309 .function = (char *)longname,
1310 .bind = gmidi_bind, 1310 .bind = gmidi_bind,
1311 .unbind = __exit_p(gmidi_unbind), 1311 .unbind = gmidi_unbind,
1312 1312
1313 .setup = gmidi_setup, 1313 .setup = gmidi_setup,
1314 .disconnect = gmidi_disconnect, 1314 .disconnect = gmidi_disconnect,
@@ -1316,7 +1316,7 @@ static struct usb_gadget_driver gmidi_driver = {
1316 .suspend = gmidi_suspend, 1316 .suspend = gmidi_suspend,
1317 .resume = gmidi_resume, 1317 .resume = gmidi_resume,
1318 1318
1319 .driver = { 1319 .driver = {
1320 .name = (char *)shortname, 1320 .name = (char *)shortname,
1321 .owner = THIS_MODULE, 1321 .owner = THIS_MODULE,
1322 }, 1322 },
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 805a9826842d..d0ef1d6b3fac 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1432,7 +1432,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1432 if (!driver 1432 if (!driver
1433 || driver->speed != USB_SPEED_FULL 1433 || driver->speed != USB_SPEED_FULL
1434 || !driver->bind 1434 || !driver->bind
1435 || !driver->unbind
1436 || !driver->disconnect 1435 || !driver->disconnect
1437 || !driver->setup) 1436 || !driver->setup)
1438 return -EINVAL; 1437 return -EINVAL;
@@ -1495,7 +1494,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1495 1494
1496 if (!dev) 1495 if (!dev)
1497 return -ENODEV; 1496 return -ENODEV;
1498 if (!driver || driver != dev->driver) 1497 if (!driver || driver != dev->driver || !driver->unbind)
1499 return -EINVAL; 1498 return -EINVAL;
1500 1499
1501 spin_lock_irqsave(&dev->lock, flags); 1500 spin_lock_irqsave(&dev->lock, flags);
@@ -1808,13 +1807,8 @@ static void goku_remove(struct pci_dev *pdev)
1808 struct goku_udc *dev = pci_get_drvdata(pdev); 1807 struct goku_udc *dev = pci_get_drvdata(pdev);
1809 1808
1810 DBG(dev, "%s\n", __FUNCTION__); 1809 DBG(dev, "%s\n", __FUNCTION__);
1811 /* start with the driver above us */ 1810
1812 if (dev->driver) { 1811 BUG_ON(dev->driver);
1813 /* should have been done already by driver model core */
1814 WARN(dev, "pci remove, driver '%s' is still registered\n",
1815 dev->driver->driver.name);
1816 usb_gadget_unregister_driver(dev->driver);
1817 }
1818 1812
1819#ifdef CONFIG_USB_GADGET_DEBUG_FILES 1813#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1820 remove_proc_entry(proc_node_name, NULL); 1814 remove_proc_entry(proc_node_name, NULL);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index 4a991564a03e..a0a73c08a344 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -422,9 +422,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
422 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name); 422 DEBUG("%s: %s\n", __FUNCTION__, driver->driver.name);
423 423
424 if (!driver 424 if (!driver
425 || driver->speed != USB_SPEED_FULL 425 || driver->speed != USB_SPEED_FULL
426 || !driver->bind 426 || !driver->bind
427 || !driver->unbind || !driver->disconnect || !driver->setup) 427 || !driver->disconnect
428 || !driver->setup)
428 return -EINVAL; 429 return -EINVAL;
429 if (!dev) 430 if (!dev)
430 return -ENODEV; 431 return -ENODEV;
@@ -471,7 +472,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
471 472
472 if (!dev) 473 if (!dev)
473 return -ENODEV; 474 return -ENODEV;
474 if (!driver || driver != dev->driver) 475 if (!driver || driver != dev->driver || !driver->unbind)
475 return -EINVAL; 476 return -EINVAL;
476 477
477 spin_lock_irqsave(&dev->lock, flags); 478 spin_lock_irqsave(&dev->lock, flags);
@@ -2125,9 +2126,11 @@ static int lh7a40x_udc_remove(struct platform_device *pdev)
2125 2126
2126 DEBUG("%s: %p\n", __FUNCTION__, pdev); 2127 DEBUG("%s: %p\n", __FUNCTION__, pdev);
2127 2128
2129 if (dev->driver)
2130 return -EBUSY;
2131
2128 udc_disable(dev); 2132 udc_disable(dev);
2129 remove_proc_files(); 2133 remove_proc_files();
2130 usb_gadget_unregister_driver(dev->driver);
2131 2134
2132 free_irq(IRQ_USBINTR, dev); 2135 free_irq(IRQ_USBINTR, dev);
2133 2136
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 3024c679e38e..569eb8ccf232 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -2020,7 +2020,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2020 if (!driver 2020 if (!driver
2021 || driver->speed != USB_SPEED_HIGH 2021 || driver->speed != USB_SPEED_HIGH
2022 || !driver->bind 2022 || !driver->bind
2023 || !driver->unbind
2024 || !driver->setup) 2023 || !driver->setup)
2025 return -EINVAL; 2024 return -EINVAL;
2026 if (!dev) 2025 if (!dev)
@@ -2107,7 +2106,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2107 2106
2108 if (!dev) 2107 if (!dev)
2109 return -ENODEV; 2108 return -ENODEV;
2110 if (!driver || driver != dev->driver) 2109 if (!driver || driver != dev->driver || !driver->unbind)
2111 return -EINVAL; 2110 return -EINVAL;
2112 2111
2113 spin_lock_irqsave (&dev->lock, flags); 2112 spin_lock_irqsave (&dev->lock, flags);
@@ -2803,13 +2802,7 @@ static void net2280_remove (struct pci_dev *pdev)
2803{ 2802{
2804 struct net2280 *dev = pci_get_drvdata (pdev); 2803 struct net2280 *dev = pci_get_drvdata (pdev);
2805 2804
2806 /* start with the driver above us */ 2805 BUG_ON(dev->driver);
2807 if (dev->driver) {
2808 /* should have been done already by driver model core */
2809 WARN (dev, "pci remove, driver '%s' is still registered\n",
2810 dev->driver->driver.name);
2811 usb_gadget_unregister_driver (dev->driver);
2812 }
2813 2806
2814 /* then clean up the resources we allocated during probe() */ 2807 /* then clean up the resources we allocated during probe() */
2815 net2280_led_shutdown (dev); 2808 net2280_led_shutdown (dev);
diff --git a/drivers/usb/gadget/omap_udc.c b/drivers/usb/gadget/omap_udc.c
index 030d87c28c2f..15d77c307930 100644
--- a/drivers/usb/gadget/omap_udc.c
+++ b/drivers/usb/gadget/omap_udc.c
@@ -2043,7 +2043,6 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2043 // FIXME if otg, check: driver->is_otg 2043 // FIXME if otg, check: driver->is_otg
2044 || driver->speed < USB_SPEED_FULL 2044 || driver->speed < USB_SPEED_FULL
2045 || !driver->bind 2045 || !driver->bind
2046 || !driver->unbind
2047 || !driver->setup) 2046 || !driver->setup)
2048 return -EINVAL; 2047 return -EINVAL;
2049 2048
@@ -2087,9 +2086,11 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
2087 status = otg_set_peripheral(udc->transceiver, &udc->gadget); 2086 status = otg_set_peripheral(udc->transceiver, &udc->gadget);
2088 if (status < 0) { 2087 if (status < 0) {
2089 ERR("can't bind to transceiver\n"); 2088 ERR("can't bind to transceiver\n");
2090 driver->unbind (&udc->gadget); 2089 if (driver->unbind) {
2091 udc->gadget.dev.driver = NULL; 2090 driver->unbind (&udc->gadget);
2092 udc->driver = NULL; 2091 udc->gadget.dev.driver = NULL;
2092 udc->driver = NULL;
2093 }
2093 goto done; 2094 goto done;
2094 } 2095 }
2095 } else { 2096 } else {
@@ -2117,7 +2118,7 @@ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
2117 2118
2118 if (!udc) 2119 if (!udc)
2119 return -ENODEV; 2120 return -ENODEV;
2120 if (!driver || driver != udc->driver) 2121 if (!driver || driver != udc->driver || !driver->unbind)
2121 return -EINVAL; 2122 return -EINVAL;
2122 2123
2123 if (machine_is_omap_innovator() || machine_is_omap_osk()) 2124 if (machine_is_omap_innovator() || machine_is_omap_osk())
@@ -2870,6 +2871,8 @@ static int __exit omap_udc_remove(struct platform_device *pdev)
2870 2871
2871 if (!udc) 2872 if (!udc)
2872 return -ENODEV; 2873 return -ENODEV;
2874 if (udc->driver)
2875 return -EBUSY;
2873 2876
2874 udc->done = &done; 2877 udc->done = &done;
2875 2878
diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
index 1ed506e95985..b78de9694665 100644
--- a/drivers/usb/gadget/pxa2xx_udc.c
+++ b/drivers/usb/gadget/pxa2xx_udc.c
@@ -1623,7 +1623,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1623 if (!driver 1623 if (!driver
1624 || driver->speed < USB_SPEED_FULL 1624 || driver->speed < USB_SPEED_FULL
1625 || !driver->bind 1625 || !driver->bind
1626 || !driver->unbind
1627 || !driver->disconnect 1626 || !driver->disconnect
1628 || !driver->setup) 1627 || !driver->setup)
1629 return -EINVAL; 1628 return -EINVAL;
@@ -1694,7 +1693,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1694 1693
1695 if (!dev) 1694 if (!dev)
1696 return -ENODEV; 1695 return -ENODEV;
1697 if (!driver || driver != dev->driver) 1696 if (!driver || driver != dev->driver || !driver->unbind)
1698 return -EINVAL; 1697 return -EINVAL;
1699 1698
1700 local_irq_disable(); 1699 local_irq_disable();
@@ -2638,9 +2637,11 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
2638{ 2637{
2639 struct pxa2xx_udc *dev = platform_get_drvdata(pdev); 2638 struct pxa2xx_udc *dev = platform_get_drvdata(pdev);
2640 2639
2640 if (dev->driver)
2641 return -EBUSY;
2642
2641 udc_disable(dev); 2643 udc_disable(dev);
2642 remove_proc_files(); 2644 remove_proc_files();
2643 usb_gadget_unregister_driver(dev->driver);
2644 2645
2645 if (dev->got_irq) { 2646 if (dev->got_irq) {
2646 free_irq(IRQ_USB, dev); 2647 free_irq(IRQ_USB, dev);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 2d12bf9f19d6..f8a3ec64635d 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -296,7 +296,7 @@ static struct usb_gadget_driver gs_gadget_driver = {
296#endif /* CONFIG_USB_GADGET_DUALSPEED */ 296#endif /* CONFIG_USB_GADGET_DUALSPEED */
297 .function = GS_LONG_NAME, 297 .function = GS_LONG_NAME,
298 .bind = gs_bind, 298 .bind = gs_bind,
299 .unbind = __exit_p(gs_unbind), 299 .unbind = gs_unbind,
300 .setup = gs_setup, 300 .setup = gs_setup,
301 .disconnect = gs_disconnect, 301 .disconnect = gs_disconnect,
302 .driver = { 302 .driver = {
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index b466581beb4a..cc405512fa1c 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -187,7 +187,6 @@ ohci_at91_start (struct usb_hcd *hcd)
187{ 187{
188 struct at91_usbh_data *board = hcd->self.controller->platform_data; 188 struct at91_usbh_data *board = hcd->self.controller->platform_data;
189 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 189 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
190 struct usb_device *root = hcd->self.root_hub;
191 int ret; 190 int ret;
192 191
193 if ((ret = ohci_init(ohci)) < 0) 192 if ((ret = ohci_init(ohci)) < 0)
@@ -221,7 +220,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
221 */ 220 */
222 .start = ohci_at91_start, 221 .start = ohci_at91_start,
223 .stop = ohci_stop, 222 .stop = ohci_stop,
224 .shutdown = ohci_shutdown, 223 .shutdown = ohci_shutdown,
225 224
226 /* 225 /*
227 * managing i/o requests and associated device resources 226 * managing i/o requests and associated device resources
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 24e23c5783d8..e70b2430e2a9 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -269,7 +269,7 @@ static const struct hc_driver ohci_au1xxx_hc_driver = {
269 */ 269 */
270 .start = ohci_au1xxx_start, 270 .start = ohci_au1xxx_start,
271 .stop = ohci_stop, 271 .stop = ohci_stop,
272 .shutdown = ohci_shutdown, 272 .shutdown = ohci_shutdown,
273 273
274 /* 274 /*
275 * managing i/o requests and associated device resources 275 * managing i/o requests and associated device resources
@@ -336,7 +336,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct platform_device *dev)
336static struct platform_driver ohci_hcd_au1xxx_driver = { 336static struct platform_driver ohci_hcd_au1xxx_driver = {
337 .probe = ohci_hcd_au1xxx_drv_probe, 337 .probe = ohci_hcd_au1xxx_drv_probe,
338 .remove = ohci_hcd_au1xxx_drv_remove, 338 .remove = ohci_hcd_au1xxx_drv_remove,
339 .shutdown = usb_hcd_platform_shutdown, 339 .shutdown = usb_hcd_platform_shutdown,
340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */ 340 /*.suspend = ohci_hcd_au1xxx_drv_suspend, */
341 /*.resume = ohci_hcd_au1xxx_drv_resume, */ 341 /*.resume = ohci_hcd_au1xxx_drv_resume, */
342 .driver = { 342 .driver = {
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index 0f47a57dac28..273d5ddb72be 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -16,7 +16,7 @@
16 case PIPE_CONTROL: temp = "ctrl"; break; \ 16 case PIPE_CONTROL: temp = "ctrl"; break; \
17 case PIPE_BULK: temp = "bulk"; break; \ 17 case PIPE_BULK: temp = "bulk"; break; \
18 case PIPE_INTERRUPT: temp = "intr"; break; \ 18 case PIPE_INTERRUPT: temp = "intr"; break; \
19 default: temp = "isoc"; break; \ 19 default: temp = "isoc"; break; \
20 }; temp;}) 20 }; temp;})
21#define pipestring(pipe) edstring(usb_pipetype(pipe)) 21#define pipestring(pipe) edstring(usb_pipetype(pipe))
22 22
@@ -205,13 +205,13 @@ ohci_dump_status (struct ohci_hcd *controller, char **next, unsigned *size)
205 (temp & RH_PS_PSSC) ? " PSSC" : "", \ 205 (temp & RH_PS_PSSC) ? " PSSC" : "", \
206 (temp & RH_PS_PESC) ? " PESC" : "", \ 206 (temp & RH_PS_PESC) ? " PESC" : "", \
207 (temp & RH_PS_CSC) ? " CSC" : "", \ 207 (temp & RH_PS_CSC) ? " CSC" : "", \
208 \ 208 \
209 (temp & RH_PS_LSDA) ? " LSDA" : "", \ 209 (temp & RH_PS_LSDA) ? " LSDA" : "", \
210 (temp & RH_PS_PPS) ? " PPS" : "", \ 210 (temp & RH_PS_PPS) ? " PPS" : "", \
211 (temp & RH_PS_PRS) ? " PRS" : "", \ 211 (temp & RH_PS_PRS) ? " PRS" : "", \
212 (temp & RH_PS_POCI) ? " POCI" : "", \ 212 (temp & RH_PS_POCI) ? " POCI" : "", \
213 (temp & RH_PS_PSS) ? " PSS" : "", \ 213 (temp & RH_PS_PSS) ? " PSS" : "", \
214 \ 214 \
215 (temp & RH_PS_PES) ? " PES" : "", \ 215 (temp & RH_PS_PES) ? " PES" : "", \
216 (temp & RH_PS_CCS) ? " CCS" : "" \ 216 (temp & RH_PS_CCS) ? " CCS" : "" \
217 ); 217 );
@@ -563,7 +563,7 @@ show_periodic (struct class_device *class_dev, char *buf)
563 (info & ED_SKIP) ? " K" : "", 563 (info & ED_SKIP) ? " K" : "",
564 (ed->hwHeadP & 564 (ed->hwHeadP &
565 cpu_to_hc32(ohci, ED_H)) ? 565 cpu_to_hc32(ohci, ED_H)) ?
566 " H" : ""); 566 " H" : "");
567 size -= temp; 567 size -= temp;
568 next += temp; 568 next += temp;
569 569
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 1bf5e7a4e735..43ae696b2ec2 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -204,7 +204,7 @@ static int ohci_hcd_ep93xx_drv_resume(struct platform_device *pdev)
204static struct platform_driver ohci_hcd_ep93xx_driver = { 204static struct platform_driver ohci_hcd_ep93xx_driver = {
205 .probe = ohci_hcd_ep93xx_drv_probe, 205 .probe = ohci_hcd_ep93xx_drv_probe,
206 .remove = ohci_hcd_ep93xx_drv_remove, 206 .remove = ohci_hcd_ep93xx_drv_remove,
207 .shutdown = usb_hcd_platform_shutdown, 207 .shutdown = usb_hcd_platform_shutdown,
208#ifdef CONFIG_PM 208#ifdef CONFIG_PM
209 .suspend = ohci_hcd_ep93xx_drv_suspend, 209 .suspend = ohci_hcd_ep93xx_drv_suspend,
210 .resume = ohci_hcd_ep93xx_drv_resume, 210 .resume = ohci_hcd_ep93xx_drv_resume,
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b28a9b602066..c1c1d871aba4 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -3,77 +3,21 @@
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * [ Initialisation is based on Linus' ] 7 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ] 8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ] 9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith] 10 * [ (C) Copyright 1999 Gregory P. Smith]
11 * 11 *
12 * 12 *
13 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller 13 * OHCI is the main "non-Intel/VIA" standard for USB 1.1 host controller
14 * interfaces (though some non-x86 Intel chips use it). It supports 14 * interfaces (though some non-x86 Intel chips use it). It supports
15 * smarter hardware than UHCI. A download link for the spec available 15 * smarter hardware than UHCI. A download link for the spec available
16 * through the http://www.usb.org website. 16 * through the http://www.usb.org website.
17 * 17 *
18 * History:
19 *
20 * 2004/03/24 LH7A404 support (Durgesh Pattamatta & Marc Singer)
21 * 2004/02/04 use generic dma_* functions instead of pci_* (dsaxena@plexity.net)
22 * 2003/02/24 show registers in sysfs (Kevin Brosius)
23 *
24 * 2002/09/03 get rid of ed hashtables, rework periodic scheduling and
25 * bandwidth accounting; if debugging, show schedules in driverfs
26 * 2002/07/19 fixes to management of ED and schedule state.
27 * 2002/06/09 SA-1111 support (Christopher Hoover)
28 * 2002/06/01 remember frame when HC won't see EDs any more; use that info
29 * to fix urb unlink races caused by interrupt latency assumptions;
30 * minor ED field and function naming updates
31 * 2002/01/18 package as a patch for 2.5.3; this should match the
32 * 2.4.17 kernel modulo some bugs being fixed.
33 *
34 * 2001/10/18 merge pmac cleanup (Benjamin Herrenschmidt) and bugfixes
35 * from post-2.4.5 patches.
36 * 2001/09/20 URB_ZERO_PACKET support; hcca_dma portability, OPTi warning
37 * 2001/09/07 match PCI PM changes, errnos from Linus' tree
38 * 2001/05/05 fork 2.4.5 version into "hcd" framework, cleanup, simplify;
39 * pbook pci quirks gone (please fix pbook pci sw!) (db)
40 *
41 * 2001/04/08 Identify version on module load (gb)
42 * 2001/03/24 td/ed hashing to remove bus_to_virt (Steve Longerbeam);
43 pci_map_single (db)
44 * 2001/03/21 td and dev/ed allocation uses new pci_pool API (db)
45 * 2001/03/07 hcca allocation uses pci_alloc_consistent (Steve Longerbeam)
46 *
47 * 2000/09/26 fixed races in removing the private portion of the urb
48 * 2000/09/07 disable bulk and control lists when unlinking the last
49 * endpoint descriptor in order to avoid unrecoverable errors on
50 * the Lucent chips. (rwc@sgi)
51 * 2000/08/29 use bandwidth claiming hooks (thanks Randy!), fix some
52 * urb unlink probs, indentation fixes
53 * 2000/08/11 various oops fixes mostly affecting iso and cleanup from
54 * device unplugs.
55 * 2000/06/28 use PCI hotplug framework, for better power management
56 * and for Cardbus support (David Brownell)
57 * 2000/earlier: fixes for NEC/Lucent chips; suspend/resume handling
58 * when the controller loses power; handle UE; cleanup; ...
59 *
60 * v5.2 1999/12/07 URB 3rd preview,
61 * v5.1 1999/11/30 URB 2nd preview, cpia, (usb-scsi)
62 * v5.0 1999/11/22 URB Technical preview, Paul Mackerras powerbook susp/resume
63 * i386: HUB, Keyboard, Mouse, Printer
64 *
65 * v4.3 1999/10/27 multiple HCs, bulk_request
66 * v4.2 1999/09/05 ISO API alpha, new dev alloc, neg Error-codes
67 * v4.1 1999/08/27 Randy Dunlap's - ISO API first impl.
68 * v4.0 1999/08/18
69 * v3.0 1999/06/25
70 * v2.1 1999/05/09 code clean up
71 * v2.0 1999/05/04
72 * v1.0 1999/04/27 initial release
73 *
74 * This file is licenced under the GPL. 18 * This file is licenced under the GPL.
75 */ 19 */
76 20
77#include <linux/module.h> 21#include <linux/module.h>
78#include <linux/moduleparam.h> 22#include <linux/moduleparam.h>
79#include <linux/pci.h> 23#include <linux/pci.h>
@@ -89,7 +33,7 @@
89#include <linux/list.h> 33#include <linux/list.h>
90#include <linux/usb.h> 34#include <linux/usb.h>
91#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
92#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
93#include <linux/dmapool.h> 37#include <linux/dmapool.h>
94#include <linux/reboot.h> 38#include <linux/reboot.h>
95 39
@@ -183,11 +127,11 @@ static int ohci_urb_enqueue (
183 int i, size = 0; 127 int i, size = 0;
184 unsigned long flags; 128 unsigned long flags;
185 int retval = 0; 129 int retval = 0;
186 130
187#ifdef OHCI_VERBOSE_DEBUG 131#ifdef OHCI_VERBOSE_DEBUG
188 urb_print (urb, "SUB", usb_pipein (pipe)); 132 urb_print (urb, "SUB", usb_pipein (pipe));
189#endif 133#endif
190 134
191 /* every endpoint has a ed, locate and maybe (re)initialize it */ 135 /* every endpoint has a ed, locate and maybe (re)initialize it */
192 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval))) 136 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval)))
193 return -ENOMEM; 137 return -ENOMEM;
@@ -232,7 +176,7 @@ static int ohci_urb_enqueue (
232 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *)); 176 memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (struct td *));
233 INIT_LIST_HEAD (&urb_priv->pending); 177 INIT_LIST_HEAD (&urb_priv->pending);
234 urb_priv->length = size; 178 urb_priv->length = size;
235 urb_priv->ed = ed; 179 urb_priv->ed = ed;
236 180
237 /* allocate the TDs (deferring hash chain updates) */ 181 /* allocate the TDs (deferring hash chain updates) */
238 for (i = 0; i < size; i++) { 182 for (i = 0; i < size; i++) {
@@ -242,7 +186,7 @@ static int ohci_urb_enqueue (
242 urb_free_priv (ohci, urb_priv); 186 urb_free_priv (ohci, urb_priv);
243 return -ENOMEM; 187 return -ENOMEM;
244 } 188 }
245 } 189 }
246 190
247 spin_lock_irqsave (&ohci->lock, flags); 191 spin_lock_irqsave (&ohci->lock, flags);
248 192
@@ -313,13 +257,13 @@ static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
313{ 257{
314 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 258 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
315 unsigned long flags; 259 unsigned long flags;
316 260
317#ifdef OHCI_VERBOSE_DEBUG 261#ifdef OHCI_VERBOSE_DEBUG
318 urb_print (urb, "UNLINK", 1); 262 urb_print (urb, "UNLINK", 1);
319#endif 263#endif
320 264
321 spin_lock_irqsave (&ohci->lock, flags); 265 spin_lock_irqsave (&ohci->lock, flags);
322 if (HC_IS_RUNNING(hcd->state)) { 266 if (HC_IS_RUNNING(hcd->state)) {
323 urb_priv_t *urb_priv; 267 urb_priv_t *urb_priv;
324 268
325 /* Unless an IRQ completed the unlink while it was being 269 /* Unless an IRQ completed the unlink while it was being
@@ -512,11 +456,11 @@ static int ohci_init (struct ohci_hcd *ohci)
512 456
513/* Start an OHCI controller, set the BUS operational 457/* Start an OHCI controller, set the BUS operational
514 * resets USB and controller 458 * resets USB and controller
515 * enable interrupts 459 * enable interrupts
516 */ 460 */
517static int ohci_run (struct ohci_hcd *ohci) 461static int ohci_run (struct ohci_hcd *ohci)
518{ 462{
519 u32 mask, temp; 463 u32 mask, temp;
520 int first = ohci->fminterval == 0; 464 int first = ohci->fminterval == 0;
521 struct usb_hcd *hcd = ohci_to_hcd(ohci); 465 struct usb_hcd *hcd = ohci_to_hcd(ohci);
522 466
@@ -534,7 +478,7 @@ static int ohci_run (struct ohci_hcd *ohci)
534 /* also: power/overcurrent flags in roothub.a */ 478 /* also: power/overcurrent flags in roothub.a */
535 } 479 }
536 480
537 /* Reset USB nearly "by the book". RemoteWakeupConnected was 481 /* Reset USB nearly "by the book". RemoteWakeupConnected was
538 * saved if boot firmware (BIOS/SMM/...) told us it's connected, 482 * saved if boot firmware (BIOS/SMM/...) told us it's connected,
539 * or if bus glue did the same (e.g. for PCI add-in cards with 483 * or if bus glue did the same (e.g. for PCI add-in cards with
540 * PCI PM support). 484 * PCI PM support).
@@ -765,9 +709,9 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
765 dl_done_list (ohci); 709 dl_done_list (ohci);
766 spin_unlock (&ohci->lock); 710 spin_unlock (&ohci->lock);
767 if (HC_IS_RUNNING(hcd->state)) 711 if (HC_IS_RUNNING(hcd->state))
768 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable); 712 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrenable);
769 } 713 }
770 714
771 /* could track INTR_SO to reduce available PCI/... bandwidth */ 715 /* could track INTR_SO to reduce available PCI/... bandwidth */
772 716
773 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled 717 /* handle any pending URB/ED unlinks, leaving INTR_SF enabled
@@ -778,12 +722,12 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
778 finish_unlinks (ohci, ohci_frame_no(ohci)); 722 finish_unlinks (ohci, ohci_frame_no(ohci));
779 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list 723 if ((ints & OHCI_INTR_SF) != 0 && !ohci->ed_rm_list
780 && HC_IS_RUNNING(hcd->state)) 724 && HC_IS_RUNNING(hcd->state))
781 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable); 725 ohci_writel (ohci, OHCI_INTR_SF, &regs->intrdisable);
782 spin_unlock (&ohci->lock); 726 spin_unlock (&ohci->lock);
783 727
784 if (HC_IS_RUNNING(hcd->state)) { 728 if (HC_IS_RUNNING(hcd->state)) {
785 ohci_writel (ohci, ints, &regs->intrstatus); 729 ohci_writel (ohci, ints, &regs->intrstatus);
786 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable); 730 ohci_writel (ohci, OHCI_INTR_MIE, &regs->intrenable);
787 // flush those writes 731 // flush those writes
788 (void) ohci_readl (ohci, &ohci->regs->control); 732 (void) ohci_readl (ohci, &ohci->regs->control);
789 } 733 }
@@ -794,7 +738,7 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd)
794/*-------------------------------------------------------------------------*/ 738/*-------------------------------------------------------------------------*/
795 739
796static void ohci_stop (struct usb_hcd *hcd) 740static void ohci_stop (struct usb_hcd *hcd)
797{ 741{
798 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 742 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
799 743
800 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n", 744 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n",
@@ -812,8 +756,8 @@ static void ohci_stop (struct usb_hcd *hcd)
812 remove_debug_files (ohci); 756 remove_debug_files (ohci);
813 ohci_mem_cleanup (ohci); 757 ohci_mem_cleanup (ohci);
814 if (ohci->hcca) { 758 if (ohci->hcca) {
815 dma_free_coherent (hcd->self.controller, 759 dma_free_coherent (hcd->self.controller,
816 sizeof *ohci->hcca, 760 sizeof *ohci->hcca,
817 ohci->hcca, ohci->hcca_dma); 761 ohci->hcca, ohci->hcca_dma);
818 ohci->hcca = NULL; 762 ohci->hcca = NULL;
819 ohci->hcca_dma = 0; 763 ohci->hcca_dma = 0;
@@ -836,7 +780,7 @@ static int ohci_restart (struct ohci_hcd *ohci)
836 * recycle any "live" eds/tds (and urbs) right away. 780 * recycle any "live" eds/tds (and urbs) right away.
837 * later, khubd disconnect processing will recycle the other state, 781 * later, khubd disconnect processing will recycle the other state,
838 * (either as disconnect/reconnect, or maybe someday as a reset). 782 * (either as disconnect/reconnect, or maybe someday as a reset).
839 */ 783 */
840 spin_lock_irq(&ohci->lock); 784 spin_lock_irq(&ohci->lock);
841 disable (ohci); 785 disable (ohci);
842 usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub); 786 usb_root_hub_lost_power(ohci_to_hcd(ohci)->self.root_hub);
@@ -875,11 +819,11 @@ static int ohci_restart (struct ohci_hcd *ohci)
875 /* empty the interrupt branches */ 819 /* empty the interrupt branches */
876 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0; 820 for (i = 0; i < NUM_INTS; i++) ohci->load [i] = 0;
877 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0; 821 for (i = 0; i < NUM_INTS; i++) ohci->hcca->int_table [i] = 0;
878 822
879 /* no EDs to remove */ 823 /* no EDs to remove */
880 ohci->ed_rm_list = NULL; 824 ohci->ed_rm_list = NULL;
881 825
882 /* empty control and bulk lists */ 826 /* empty control and bulk lists */
883 ohci->ed_controltail = NULL; 827 ohci->ed_controltail = NULL;
884 ohci->ed_bulktail = NULL; 828 ohci->ed_bulktail = NULL;
885 829
@@ -941,6 +885,10 @@ MODULE_LICENSE ("GPL");
941#include "ohci-au1xxx.c" 885#include "ohci-au1xxx.c"
942#endif 886#endif
943 887
888#ifdef CONFIG_PNX8550
889#include "ohci-pnx8550.c"
890#endif
891
944#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC 892#ifdef CONFIG_USB_OHCI_HCD_PPC_SOC
945#include "ohci-ppc-soc.c" 893#include "ohci-ppc-soc.c"
946#endif 894#endif
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 2441642cb7b4..216c9c9d4d6d 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2004 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under GPL 7 * This file is licenced under GPL
8 */ 8 */
9 9
@@ -23,13 +23,13 @@
23 (temp & RH_PS_PSSC) ? " PSSC" : "", \ 23 (temp & RH_PS_PSSC) ? " PSSC" : "", \
24 (temp & RH_PS_PESC) ? " PESC" : "", \ 24 (temp & RH_PS_PESC) ? " PESC" : "", \
25 (temp & RH_PS_CSC) ? " CSC" : "", \ 25 (temp & RH_PS_CSC) ? " CSC" : "", \
26 \ 26 \
27 (temp & RH_PS_LSDA) ? " LSDA" : "", \ 27 (temp & RH_PS_LSDA) ? " LSDA" : "", \
28 (temp & RH_PS_PPS) ? " PPS" : "", \ 28 (temp & RH_PS_PPS) ? " PPS" : "", \
29 (temp & RH_PS_PRS) ? " PRS" : "", \ 29 (temp & RH_PS_PRS) ? " PRS" : "", \
30 (temp & RH_PS_POCI) ? " POCI" : "", \ 30 (temp & RH_PS_POCI) ? " POCI" : "", \
31 (temp & RH_PS_PSS) ? " PSS" : "", \ 31 (temp & RH_PS_PSS) ? " PSS" : "", \
32 \ 32 \
33 (temp & RH_PS_PES) ? " PES" : "", \ 33 (temp & RH_PS_PES) ? " PES" : "", \
34 (temp & RH_PS_CCS) ? " CCS" : "" \ 34 (temp & RH_PS_CCS) ? " CCS" : "" \
35 ); 35 );
@@ -484,7 +484,7 @@ ohci_hub_descriptor (
484 temp = 0; 484 temp = 0;
485 if (rh & RH_A_NPS) /* no power switching? */ 485 if (rh & RH_A_NPS) /* no power switching? */
486 temp |= 0x0002; 486 temp |= 0x0002;
487 if (rh & RH_A_PSM) /* per-port power switching? */ 487 if (rh & RH_A_PSM) /* per-port power switching? */
488 temp |= 0x0001; 488 temp |= 0x0001;
489 if (rh & RH_A_NOCP) /* no overcurrent reporting? */ 489 if (rh & RH_A_NOCP) /* no overcurrent reporting? */
490 temp |= 0x0010; 490 temp |= 0x0010;
@@ -555,7 +555,7 @@ static void start_hnp(struct ohci_hcd *ohci);
555#define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 555#define tick_before(t1,t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
556 556
557/* called from some task, normally khubd */ 557/* called from some task, normally khubd */
558static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port) 558static inline int root_port_reset (struct ohci_hcd *ohci, unsigned port)
559{ 559{
560 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port]; 560 __hc32 __iomem *portstat = &ohci->regs->roothub.portstatus [port];
561 u32 temp; 561 u32 temp;
@@ -570,10 +570,13 @@ static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
570 /* spin until any current reset finishes */ 570 /* spin until any current reset finishes */
571 for (;;) { 571 for (;;) {
572 temp = ohci_readl (ohci, portstat); 572 temp = ohci_readl (ohci, portstat);
573 /* handle e.g. CardBus eject */
574 if (temp == ~(u32)0)
575 return -ESHUTDOWN;
573 if (!(temp & RH_PS_PRS)) 576 if (!(temp & RH_PS_PRS))
574 break; 577 break;
575 udelay (500); 578 udelay (500);
576 } 579 }
577 580
578 if (!(temp & RH_PS_CCS)) 581 if (!(temp & RH_PS_CCS))
579 break; 582 break;
@@ -586,6 +589,8 @@ static inline void root_port_reset (struct ohci_hcd *ohci, unsigned port)
586 now = ohci_readl(ohci, &ohci->regs->fmnumber); 589 now = ohci_readl(ohci, &ohci->regs->fmnumber);
587 } while (tick_before(now, reset_done)); 590 } while (tick_before(now, reset_done));
588 /* caller synchronizes using PRSC */ 591 /* caller synchronizes using PRSC */
592
593 return 0;
589} 594}
590 595
591static int ohci_hub_control ( 596static int ohci_hub_control (
@@ -702,7 +707,7 @@ static int ohci_hub_control (
702 &ohci->regs->roothub.portstatus [wIndex]); 707 &ohci->regs->roothub.portstatus [wIndex]);
703 break; 708 break;
704 case USB_PORT_FEAT_RESET: 709 case USB_PORT_FEAT_RESET:
705 root_port_reset (ohci, wIndex); 710 retval = root_port_reset (ohci, wIndex);
706 break; 711 break;
707 default: 712 default:
708 goto error; 713 goto error;
diff --git a/drivers/usb/host/ohci-lh7a404.c b/drivers/usb/host/ohci-lh7a404.c
index e121d97ed91c..e9807cf73a2f 100644
--- a/drivers/usb/host/ohci-lh7a404.c
+++ b/drivers/usb/host/ohci-lh7a404.c
@@ -38,7 +38,7 @@ static void lh7a404_start_hc(struct platform_device *dev)
38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */ 38 CSC_PWRCNT |= CSC_PWRCNT_USBH_EN; /* Enable clock */
39 udelay(1000); 39 udelay(1000);
40 USBH_CMDSTATUS = OHCI_HCR; 40 USBH_CMDSTATUS = OHCI_HCR;
41 41
42 printk(KERN_DEBUG __FILE__ 42 printk(KERN_DEBUG __FILE__
43 ": Clock to USB host has been enabled \n"); 43 ": Clock to USB host has been enabled \n");
44} 44}
@@ -89,7 +89,7 @@ int usb_hcd_lh7a404_probe (const struct hc_driver *driver,
89 retval = -EBUSY; 89 retval = -EBUSY;
90 goto err1; 90 goto err1;
91 } 91 }
92 92
93 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 93 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
94 if (!hcd->regs) { 94 if (!hcd->regs) {
95 pr_debug("ioremap failed"); 95 pr_debug("ioremap failed");
@@ -174,7 +174,7 @@ static const struct hc_driver ohci_lh7a404_hc_driver = {
174 */ 174 */
175 .start = ohci_lh7a404_start, 175 .start = ohci_lh7a404_start,
176 .stop = ohci_stop, 176 .stop = ohci_stop,
177 .shutdown = ohci_shutdown, 177 .shutdown = ohci_shutdown,
178 178
179 /* 179 /*
180 * managing i/o requests and associated device resources 180 * managing i/o requests and associated device resources
@@ -242,7 +242,7 @@ static int ohci_hcd_lh7a404_drv_resume(struct platform_device *dev)
242static struct platform_driver ohci_hcd_lh7a404_driver = { 242static struct platform_driver ohci_hcd_lh7a404_driver = {
243 .probe = ohci_hcd_lh7a404_drv_probe, 243 .probe = ohci_hcd_lh7a404_drv_probe,
244 .remove = ohci_hcd_lh7a404_drv_remove, 244 .remove = ohci_hcd_lh7a404_drv_remove,
245 .shutdown = usb_hcd_platform_shutdown, 245 .shutdown = usb_hcd_platform_shutdown,
246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */ 246 /*.suspend = ohci_hcd_lh7a404_drv_suspend, */
247 /*.resume = ohci_hcd_lh7a404_drv_resume, */ 247 /*.resume = ohci_hcd_lh7a404_drv_resume, */
248 .driver = { 248 .driver = {
diff --git a/drivers/usb/host/ohci-mem.c b/drivers/usb/host/ohci-mem.c
index d976614eebd3..2f20d3dc895b 100644
--- a/drivers/usb/host/ohci-mem.c
+++ b/drivers/usb/host/ohci-mem.c
@@ -1,24 +1,24 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
10/*-------------------------------------------------------------------------*/ 10/*-------------------------------------------------------------------------*/
11 11
12/* 12/*
13 * There's basically three types of memory: 13 * OHCI deals with three types of memory:
14 * - data used only by the HCD ... kmalloc is fine 14 * - data used only by the HCD ... kmalloc is fine
15 * - async and periodic schedules, shared by HC and HCD ... these 15 * - async and periodic schedules, shared by HC and HCD ... these
16 * need to use dma_pool or dma_alloc_coherent 16 * need to use dma_pool or dma_alloc_coherent
17 * - driver buffers, read/written by HC ... the hcd glue or the 17 * - driver buffers, read/written by HC ... the hcd glue or the
18 * device driver provides us with dma addresses 18 * device driver provides us with dma addresses
19 * 19 *
20 * There's also PCI "register" data, which is memory mapped. 20 * There's also "register" data, which is memory mapped.
21 * No memory seen by this driver is pagable. 21 * No memory seen by this driver (or any HCD) may be paged out.
22 */ 22 */
23 23
24/*-------------------------------------------------------------------------*/ 24/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 9c02177de50a..27be1f936885 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -447,7 +447,7 @@ static const struct hc_driver ohci_omap_hc_driver = {
447 .reset = ohci_omap_init, 447 .reset = ohci_omap_init,
448 .start = ohci_omap_start, 448 .start = ohci_omap_start,
449 .stop = ohci_omap_stop, 449 .stop = ohci_omap_stop,
450 .shutdown = ohci_shutdown, 450 .shutdown = ohci_shutdown,
451 451
452 /* 452 /*
453 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -533,7 +533,7 @@ static int ohci_omap_resume(struct platform_device *dev)
533static struct platform_driver ohci_hcd_omap_driver = { 533static struct platform_driver ohci_hcd_omap_driver = {
534 .probe = ohci_hcd_omap_drv_probe, 534 .probe = ohci_hcd_omap_drv_probe,
535 .remove = ohci_hcd_omap_drv_remove, 535 .remove = ohci_hcd_omap_drv_remove,
536 .shutdown = usb_hcd_platform_shutdown, 536 .shutdown = usb_hcd_platform_shutdown,
537#ifdef CONFIG_PM 537#ifdef CONFIG_PM
538 .suspend = ohci_omap_suspend, 538 .suspend = ohci_omap_suspend,
539 .resume = ohci_omap_resume, 539 .resume = ohci_omap_resume,
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 874418552789..596e0b41e606 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -3,17 +3,17 @@
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * [ Initialisation is based on Linus' ] 7 * [ Initialisation is based on Linus' ]
8 * [ uhci code and gregs ohci fragments ] 8 * [ uhci code and gregs ohci fragments ]
9 * [ (C) Copyright 1999 Linus Torvalds ] 9 * [ (C) Copyright 1999 Linus Torvalds ]
10 * [ (C) Copyright 1999 Gregory P. Smith] 10 * [ (C) Copyright 1999 Gregory P. Smith]
11 * 11 *
12 * PCI Bus Glue 12 * PCI Bus Glue
13 * 13 *
14 * This file is licenced under the GPL. 14 * This file is licenced under the GPL.
15 */ 15 */
16 16
17#ifndef CONFIG_PCI 17#ifndef CONFIG_PCI
18#error "This file is PCI bus glue. CONFIG_PCI must be defined." 18#error "This file is PCI bus glue. CONFIG_PCI must be defined."
19#endif 19#endif
@@ -83,7 +83,7 @@ ohci_pci_start (struct usb_hcd *hcd)
83 pci_dev_put(b); 83 pci_dev_put(b);
84 } 84 }
85 85
86 /* Check for Compaq's ZFMicro chipset, which needs short 86 /* Check for Compaq's ZFMicro chipset, which needs short
87 * delays before control or bulk queues get re-activated 87 * delays before control or bulk queues get re-activated
88 * in finish_unlinks() 88 * in finish_unlinks()
89 */ 89 */
@@ -238,8 +238,8 @@ static struct pci_driver ohci_pci_driver = {
238 .shutdown = usb_hcd_pci_shutdown, 238 .shutdown = usb_hcd_pci_shutdown,
239}; 239};
240 240
241 241
242static int __init ohci_hcd_pci_init (void) 242static int __init ohci_hcd_pci_init (void)
243{ 243{
244 printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name); 244 printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name);
245 if (usb_disabled()) 245 if (usb_disabled())
@@ -253,8 +253,8 @@ module_init (ohci_hcd_pci_init);
253 253
254/*-------------------------------------------------------------------------*/ 254/*-------------------------------------------------------------------------*/
255 255
256static void __exit ohci_hcd_pci_cleanup (void) 256static void __exit ohci_hcd_pci_cleanup (void)
257{ 257{
258 pci_unregister_driver (&ohci_pci_driver); 258 pci_unregister_driver (&ohci_pci_driver);
259} 259}
260module_exit (ohci_hcd_pci_cleanup); 260module_exit (ohci_hcd_pci_cleanup);
diff --git a/drivers/usb/host/ohci-pnx4008.c b/drivers/usb/host/ohci-pnx4008.c
index 7f26f9bdbaf1..3a8cbfb69054 100644
--- a/drivers/usb/host/ohci-pnx4008.c
+++ b/drivers/usb/host/ohci-pnx4008.c
@@ -4,7 +4,7 @@
4 * driver for Philips PNX4008 USB Host 4 * driver for Philips PNX4008 USB Host
5 * 5 *
6 * Authors: Dmitry Chigirev <source@mvista.com> 6 * Authors: Dmitry Chigirev <source@mvista.com>
7 * Vitaly Wool <vitalywool@gmail.com> 7 * Vitaly Wool <vitalywool@gmail.com>
8 * 8 *
9 * register initialization is based on code examples provided by Philips 9 * register initialization is based on code examples provided by Philips
10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V. 10 * Copyright (c) 2005 Koninklijke Philips Electronics N.V.
@@ -29,7 +29,7 @@
29#include <asm/arch/irqs.h> 29#include <asm/arch/irqs.h>
30#include <asm/arch/gpio.h> 30#include <asm/arch/gpio.h>
31 31
32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64) 32#define USB_CTRL IO_ADDRESS(PNX4008_PWRMAN_BASE + 0x64)
33 33
34/* USB_CTRL bit defines */ 34/* USB_CTRL bit defines */
35#define USB_SLAVE_HCLK_EN (1 << 24) 35#define USB_SLAVE_HCLK_EN (1 << 24)
diff --git a/drivers/usb/host/ohci-pnx8550.c b/drivers/usb/host/ohci-pnx8550.c
new file mode 100644
index 000000000000..6922b91b1704
--- /dev/null
+++ b/drivers/usb/host/ohci-pnx8550.c
@@ -0,0 +1,258 @@
1/*
2 * OHCI HCD (Host Controller Driver) for USB.
3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2005 Embedded Alley Solutions, Inc.
8 *
9 * Bus Glue for PNX8550
10 *
11 * Written by Christopher Hoover <ch@hpl.hp.com>
12 * Based on fragments of previous driver by Russell King et al.
13 *
14 * Modified for LH7A404 from ohci-sa1111.c
15 * by Durgesh Pattamatta <pattamattad@sharpsec.com>
16 *
17 * Modified for PNX8550 from ohci-sa1111.c and sa-omap.c
18 * by Vitaly Wool <vitalywool@gmail.com>
19 *
20 * This file is licenced under the GPL.
21 */
22
23#include <linux/device.h>
24#include <linux/platform_device.h>
25#include <asm/mach-pnx8550/usb.h>
26#include <asm/mach-pnx8550/int.h>
27#include <asm/mach-pnx8550/pci.h>
28
29#ifndef CONFIG_PNX8550
30#error "This file is PNX8550 bus glue. CONFIG_PNX8550 must be defined."
31#endif
32
33extern int usb_disabled(void);
34
35/*-------------------------------------------------------------------------*/
36
37static void pnx8550_start_hc(struct platform_device *dev)
38{
39 /*
40 * Set register CLK48CTL to enable and 48MHz
41 */
42 outl(0x00000003, PCI_BASE | 0x0004770c);
43
44 /*
45 * Set register CLK12CTL to enable and 48MHz
46 */
47 outl(0x00000003, PCI_BASE | 0x00047710);
48
49 udelay(100);
50}
51
52static void pnx8550_stop_hc(struct platform_device *dev)
53{
54 udelay(10);
55}
56
57
58/*-------------------------------------------------------------------------*/
59
60/* configure so an HC device and id are always provided */
61/* always called with process context; sleeping is OK */
62
63
64/**
65 * usb_hcd_pnx8550_probe - initialize pnx8550-based HCDs
66 * Context: !in_interrupt()
67 *
68 * Allocates basic resources for this USB host controller, and
69 * then invokes the start() method for the HCD associated with it
70 * through the hotplug entry's driver_data.
71 *
72 */
73int usb_hcd_pnx8550_probe (const struct hc_driver *driver,
74 struct platform_device *dev)
75{
76 int retval;
77 struct usb_hcd *hcd;
78
79 if (dev->resource[0].flags != IORESOURCE_MEM ||
80 dev->resource[1].flags != IORESOURCE_IRQ) {
81 dev_err (&dev->dev,"invalid resource type\n");
82 return -ENOMEM;
83 }
84
85 hcd = usb_create_hcd (driver, &dev->dev, "pnx8550");
86 if (!hcd)
87 return -ENOMEM;
88 hcd->rsrc_start = dev->resource[0].start;
89 hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1;
90
91 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
92 dev_err(&dev->dev, "request_mem_region [0x%08llx, 0x%08llx] "
93 "failed\n", hcd->rsrc_start, hcd->rsrc_len);
94 retval = -EBUSY;
95 goto err1;
96 }
97
98 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
99 if (!hcd->regs) {
100 dev_err(&dev->dev, "ioremap [[0x%08llx, 0x%08llx] failed\n",
101 hcd->rsrc_start, hcd->rsrc_len);
102 retval = -ENOMEM;
103 goto err2;
104 }
105
106 pnx8550_start_hc(dev);
107
108 ohci_hcd_init(hcd_to_ohci(hcd));
109
110 retval = usb_add_hcd(hcd, dev->resource[1].start, SA_INTERRUPT);
111 if (retval == 0)
112 return retval;
113
114 pnx8550_stop_hc(dev);
115 iounmap(hcd->regs);
116 err2:
117 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
118 err1:
119 usb_put_hcd(hcd);
120 return retval;
121}
122
123
124/* may be called without controller electrically present */
125/* may be called with controller, bus, and devices active */
126
127/**
128 * usb_hcd_pnx8550_remove - shutdown processing for pnx8550-based HCDs
129 * @dev: USB Host Controller being removed
130 * Context: !in_interrupt()
131 *
132 * Reverses the effect of usb_hcd_pnx8550_probe(), first invoking
133 * the HCD's stop() method. It is always called from a thread
134 * context, normally "rmmod", "apmd", or something similar.
135 *
136 */
137void usb_hcd_pnx8550_remove (struct usb_hcd *hcd, struct platform_device *dev)
138{
139 usb_remove_hcd(hcd);
140 pnx8550_stop_hc(dev);
141 iounmap(hcd->regs);
142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
143 usb_put_hcd(hcd);
144}
145
146/*-------------------------------------------------------------------------*/
147
148static int __devinit
149ohci_pnx8550_start (struct usb_hcd *hcd)
150{
151 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
152 int ret;
153
154 ohci_dbg (ohci, "ohci_pnx8550_start, ohci:%p", ohci);
155
156 if ((ret = ohci_init(ohci)) < 0)
157 return ret;
158
159 if ((ret = ohci_run (ohci)) < 0) {
160 err ("can't start %s", hcd->self.bus_name);
161 ohci_stop (hcd);
162 return ret;
163 }
164
165 return 0;
166}
167
168/*-------------------------------------------------------------------------*/
169
170static const struct hc_driver ohci_pnx8550_hc_driver = {
171 .description = hcd_name,
172 .product_desc = "PNX8550 OHCI",
173 .hcd_priv_size = sizeof(struct ohci_hcd),
174
175 /*
176 * generic hardware linkage
177 */
178 .irq = ohci_irq,
179 .flags = HCD_USB11 | HCD_MEMORY,
180
181 /*
182 * basic lifecycle operations
183 */
184 .start = ohci_pnx8550_start,
185 .stop = ohci_stop,
186
187 /*
188 * managing i/o requests and associated device resources
189 */
190 .urb_enqueue = ohci_urb_enqueue,
191 .urb_dequeue = ohci_urb_dequeue,
192 .endpoint_disable = ohci_endpoint_disable,
193
194 /*
195 * scheduling support
196 */
197 .get_frame_number = ohci_get_frame,
198
199 /*
200 * root hub support
201 */
202 .hub_status_data = ohci_hub_status_data,
203 .hub_control = ohci_hub_control,
204 .hub_irq_enable = ohci_rhsc_enable,
205#ifdef CONFIG_PM
206 .bus_suspend = ohci_bus_suspend,
207 .bus_resume = ohci_bus_resume,
208#endif
209 .start_port_reset = ohci_start_port_reset,
210};
211
212/*-------------------------------------------------------------------------*/
213
214static int ohci_hcd_pnx8550_drv_probe(struct platform_device *pdev)
215{
216 int ret;
217
218 if (usb_disabled())
219 return -ENODEV;
220
221 ret = usb_hcd_pnx8550_probe(&ohci_pnx8550_hc_driver, pdev);
222 return ret;
223}
224
225static int ohci_hcd_pnx8550_drv_remove(struct platform_device *pdev)
226{
227 struct usb_hcd *hcd = platform_get_drvdata(pdev);
228
229 usb_hcd_pnx8550_remove(hcd, pdev);
230 return 0;
231}
232
233MODULE_ALIAS("pnx8550-ohci");
234
235static struct platform_driver ohci_hcd_pnx8550_driver = {
236 .driver = {
237 .name = "pnx8550-ohci",
238 },
239 .probe = ohci_hcd_pnx8550_drv_probe,
240 .remove = ohci_hcd_pnx8550_drv_remove,
241};
242
243static int __init ohci_hcd_pnx8550_init (void)
244{
245 pr_debug (DRIVER_INFO " (pnx8550)");
246 pr_debug ("block sizes: ed %d td %d\n",
247 sizeof (struct ed), sizeof (struct td));
248
249 return platform_driver_register(&ohci_hcd_pnx8550_driver);
250}
251
252static void __exit ohci_hcd_pnx8550_cleanup (void)
253{
254 platform_driver_unregister(&ohci_hcd_pnx8550_driver);
255}
256
257module_init (ohci_hcd_pnx8550_init);
258module_exit (ohci_hcd_pnx8550_cleanup);
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index d9d1ae236bd5..e1a7eb817313 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -5,7 +5,7 @@
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company 6 * (C) Copyright 2002 Hewlett-Packard Company
7 * (C) Copyright 2003-2005 MontaVista Software Inc. 7 * (C) Copyright 2003-2005 MontaVista Software Inc.
8 * 8 *
9 * Bus Glue for PPC On-Chip OHCI driver 9 * Bus Glue for PPC On-Chip OHCI driver
10 * Tested on Freescale MPC5200 and IBM STB04xxx 10 * Tested on Freescale MPC5200 and IBM STB04xxx
11 * 11 *
@@ -85,7 +85,7 @@ static int usb_hcd_ppc_soc_probe(const struct hc_driver *driver,
85 err2: 85 err2:
86 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 86 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
87 err1: 87 err1:
88 usb_put_hcd(hcd); 88 usb_put_hcd(hcd);
89 return retval; 89 return retval;
90} 90}
91 91
@@ -148,7 +148,7 @@ static const struct hc_driver ohci_ppc_soc_hc_driver = {
148 */ 148 */
149 .start = ohci_ppc_soc_start, 149 .start = ohci_ppc_soc_start,
150 .stop = ohci_stop, 150 .stop = ohci_stop,
151 .shutdown = ohci_shutdown, 151 .shutdown = ohci_shutdown,
152 152
153 /* 153 /*
154 * managing i/o requests and associated device resources 154 * managing i/o requests and associated device resources
@@ -197,7 +197,7 @@ static int ohci_hcd_ppc_soc_drv_remove(struct platform_device *pdev)
197static struct platform_driver ohci_hcd_ppc_soc_driver = { 197static struct platform_driver ohci_hcd_ppc_soc_driver = {
198 .probe = ohci_hcd_ppc_soc_drv_probe, 198 .probe = ohci_hcd_ppc_soc_drv_probe,
199 .remove = ohci_hcd_ppc_soc_drv_remove, 199 .remove = ohci_hcd_ppc_soc_drv_remove,
200 .shutdown = usb_hcd_platform_shutdown, 200 .shutdown = usb_hcd_platform_shutdown,
201#ifdef CONFIG_PM 201#ifdef CONFIG_PM
202 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/ 202 /*.suspend = ohci_hcd_ppc_soc_drv_suspend,*/
203 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/ 203 /*.resume = ohci_hcd_ppc_soc_drv_resume,*/
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index e176b04d7aeb..3bbea844a9e3 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -47,7 +47,7 @@ static int pxa27x_ohci_select_pmm( int mode )
47 switch ( mode ) { 47 switch ( mode ) {
48 case PMM_NPS_MODE: 48 case PMM_NPS_MODE:
49 UHCRHDA |= RH_A_NPS; 49 UHCRHDA |= RH_A_NPS;
50 break; 50 break;
51 case PMM_GLOBAL_MODE: 51 case PMM_GLOBAL_MODE:
52 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM); 52 UHCRHDA &= ~(RH_A_NPS & RH_A_PSM);
53 break; 53 break;
@@ -60,7 +60,7 @@ static int pxa27x_ohci_select_pmm( int mode )
60 break; 60 break;
61 default: 61 default:
62 printk( KERN_ERR 62 printk( KERN_ERR
63 "Invalid mode %d, set to non-power switch mode.\n", 63 "Invalid mode %d, set to non-power switch mode.\n",
64 mode ); 64 mode );
65 65
66 UHCRHDA |= RH_A_NPS; 66 UHCRHDA |= RH_A_NPS;
@@ -270,7 +270,7 @@ static const struct hc_driver ohci_pxa27x_hc_driver = {
270 */ 270 */
271 .start = ohci_pxa27x_start, 271 .start = ohci_pxa27x_start,
272 .stop = ohci_stop, 272 .stop = ohci_stop,
273 .shutdown = ohci_shutdown, 273 .shutdown = ohci_shutdown,
274 274
275 /* 275 /*
276 * managing i/o requests and associated device resources 276 * managing i/o requests and associated device resources
@@ -359,9 +359,9 @@ static int ohci_hcd_pxa27x_drv_resume(struct platform_device *pdev)
359static struct platform_driver ohci_hcd_pxa27x_driver = { 359static struct platform_driver ohci_hcd_pxa27x_driver = {
360 .probe = ohci_hcd_pxa27x_drv_probe, 360 .probe = ohci_hcd_pxa27x_drv_probe,
361 .remove = ohci_hcd_pxa27x_drv_remove, 361 .remove = ohci_hcd_pxa27x_drv_remove,
362 .shutdown = usb_hcd_platform_shutdown, 362 .shutdown = usb_hcd_platform_shutdown,
363#ifdef CONFIG_PM 363#ifdef CONFIG_PM
364 .suspend = ohci_hcd_pxa27x_drv_suspend, 364 .suspend = ohci_hcd_pxa27x_drv_suspend,
365 .resume = ohci_hcd_pxa27x_drv_resume, 365 .resume = ohci_hcd_pxa27x_drv_resume,
366#endif 366#endif
367 .driver = { 367 .driver = {
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index fe1fe2f97cb5..830a3fe8615e 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
@@ -89,7 +89,7 @@ __acquires(ohci->lock)
89 89
90/*-------------------------------------------------------------------------* 90/*-------------------------------------------------------------------------*
91 * ED handling functions 91 * ED handling functions
92 *-------------------------------------------------------------------------*/ 92 *-------------------------------------------------------------------------*/
93 93
94/* search for the right schedule branch to use for a periodic ed. 94/* search for the right schedule branch to use for a periodic ed.
95 * does some load balancing; returns the branch, or negative errno. 95 * does some load balancing; returns the branch, or negative errno.
@@ -107,7 +107,6 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
107 */ 107 */
108 for (i = 0; i < interval ; i++) { 108 for (i = 0; i < interval ; i++) {
109 if (branch < 0 || ohci->load [branch] > ohci->load [i]) { 109 if (branch < 0 || ohci->load [branch] > ohci->load [i]) {
110#if 1 /* CONFIG_USB_BANDWIDTH */
111 int j; 110 int j;
112 111
113 /* usb 1.1 says 90% of one frame */ 112 /* usb 1.1 says 90% of one frame */
@@ -117,8 +116,7 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
117 } 116 }
118 if (j < NUM_INTS) 117 if (j < NUM_INTS)
119 continue; 118 continue;
120#endif 119 branch = i;
121 branch = i;
122 } 120 }
123 } 121 }
124 return branch; 122 return branch;
@@ -171,7 +169,7 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
171/* link an ed into one of the HC chains */ 169/* link an ed into one of the HC chains */
172 170
173static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed) 171static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
174{ 172{
175 int branch; 173 int branch;
176 174
177 if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING) 175 if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING)
@@ -248,7 +246,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
248 } 246 }
249 ed->branch = branch; 247 ed->branch = branch;
250 periodic_link (ohci, ed); 248 periodic_link (ohci, ed);
251 } 249 }
252 250
253 /* the HC may not see the schedule updates yet, but if it does 251 /* the HC may not see the schedule updates yet, but if it does
254 * then they'll be properly ordered. 252 * then they'll be properly ordered.
@@ -277,7 +275,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
277 *prev = ed->ed_next; 275 *prev = ed->ed_next;
278 } 276 }
279 ohci->load [i] -= ed->load; 277 ohci->load [i] -= ed->load;
280 } 278 }
281 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval; 279 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval;
282 280
283 ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", 281 ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
@@ -285,7 +283,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
285 ed, ed->branch, ed->load, ed->interval); 283 ed, ed->branch, ed->load, ed->interval);
286} 284}
287 285
288/* unlink an ed from one of the HC chains. 286/* unlink an ed from one of the HC chains.
289 * just the link to the ed is unlinked. 287 * just the link to the ed is unlinked.
290 * the link from the ed still points to another operational ed or 0 288 * the link from the ed still points to another operational ed or 0
291 * so the HC can eventually finish the processing of the unlinked ed 289 * so the HC can eventually finish the processing of the unlinked ed
@@ -307,7 +305,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
307 * When finish_unlinks() runs later, after SOF interrupt, it will often 305 * When finish_unlinks() runs later, after SOF interrupt, it will often
308 * complete one or more URB unlinks before making that state change. 306 * complete one or more URB unlinks before making that state change.
309 */ 307 */
310static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) 308static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
311{ 309{
312 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); 310 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
313 wmb (); 311 wmb ();
@@ -397,7 +395,7 @@ static struct ed *ed_get (
397 unsigned int pipe, 395 unsigned int pipe,
398 int interval 396 int interval
399) { 397) {
400 struct ed *ed; 398 struct ed *ed;
401 unsigned long flags; 399 unsigned long flags;
402 400
403 spin_lock_irqsave (&ohci->lock, flags); 401 spin_lock_irqsave (&ohci->lock, flags);
@@ -413,9 +411,9 @@ static struct ed *ed_get (
413 goto done; 411 goto done;
414 } 412 }
415 413
416 /* dummy td; end of td list for ed */ 414 /* dummy td; end of td list for ed */
417 td = td_alloc (ohci, GFP_ATOMIC); 415 td = td_alloc (ohci, GFP_ATOMIC);
418 if (!td) { 416 if (!td) {
419 /* out of memory */ 417 /* out of memory */
420 ed_free (ohci, ed); 418 ed_free (ohci, ed);
421 ed = NULL; 419 ed = NULL;
@@ -462,7 +460,7 @@ static struct ed *ed_get (
462 460
463done: 461done:
464 spin_unlock_irqrestore (&ohci->lock, flags); 462 spin_unlock_irqrestore (&ohci->lock, flags);
465 return ed; 463 return ed;
466} 464}
467 465
468/*-------------------------------------------------------------------------*/ 466/*-------------------------------------------------------------------------*/
@@ -474,7 +472,7 @@ done:
474 * and that ed->state is ED_OPER 472 * and that ed->state is ED_OPER
475 */ 473 */
476static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed) 474static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
477{ 475{
478 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE); 476 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE);
479 ed_deschedule (ohci, ed); 477 ed_deschedule (ohci, ed);
480 478
@@ -541,7 +539,7 @@ td_fill (struct ohci_hcd *ohci, u32 info,
541 td->ed = urb_priv->ed; 539 td->ed = urb_priv->ed;
542 td->next_dl_td = NULL; 540 td->next_dl_td = NULL;
543 td->index = index; 541 td->index = index;
544 td->urb = urb; 542 td->urb = urb;
545 td->data_dma = data; 543 td->data_dma = data;
546 if (!len) 544 if (!len)
547 data = 0; 545 data = 0;
@@ -553,8 +551,8 @@ td_fill (struct ohci_hcd *ohci, u32 info,
553 (data & 0x0FFF) | 0xE000); 551 (data & 0x0FFF) | 0xE000);
554 td->ed->last_iso = info & 0xffff; 552 td->ed->last_iso = info & 0xffff;
555 } else { 553 } else {
556 td->hwCBP = cpu_to_hc32 (ohci, data); 554 td->hwCBP = cpu_to_hc32 (ohci, data);
557 } 555 }
558 if (data) 556 if (data)
559 td->hwBE = cpu_to_hc32 (ohci, data + len - 1); 557 td->hwBE = cpu_to_hc32 (ohci, data + len - 1);
560 else 558 else
@@ -597,7 +595,7 @@ static void td_submit_urb (
597 * use the device toggle bits for resetting, and rely on the fact 595 * use the device toggle bits for resetting, and rely on the fact
598 * that resetting toggle is meaningless if the endpoint is active. 596 * that resetting toggle is meaningless if the endpoint is active.
599 */ 597 */
600 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) { 598 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
601 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe), 599 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
602 is_out, 1); 600 is_out, 1);
603 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C); 601 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C);
@@ -721,16 +719,16 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
721 list_del (&td->td_list); 719 list_del (&td->td_list);
722 720
723 /* ISO ... drivers see per-TD length/status */ 721 /* ISO ... drivers see per-TD length/status */
724 if (tdINFO & TD_ISO) { 722 if (tdINFO & TD_ISO) {
725 u16 tdPSW = ohci_hwPSW (ohci, td, 0); 723 u16 tdPSW = ohci_hwPSW (ohci, td, 0);
726 int dlen = 0; 724 int dlen = 0;
727 725
728 /* NOTE: assumes FC in tdINFO == 0, and that 726 /* NOTE: assumes FC in tdINFO == 0, and that
729 * only the first of 0..MAXPSW psws is used. 727 * only the first of 0..MAXPSW psws is used.
730 */ 728 */
731 729
732 cc = (tdPSW >> 12) & 0xF; 730 cc = (tdPSW >> 12) & 0xF;
733 if (tdINFO & TD_CC) /* hc didn't touch? */ 731 if (tdINFO & TD_CC) /* hc didn't touch? */
734 return; 732 return;
735 733
736 if (usb_pipeout (urb->pipe)) 734 if (usb_pipeout (urb->pipe))
@@ -758,7 +756,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
758 int type = usb_pipetype (urb->pipe); 756 int type = usb_pipetype (urb->pipe);
759 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE); 757 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE);
760 758
761 cc = TD_CC_GET (tdINFO); 759 cc = TD_CC_GET (tdINFO);
762 760
763 /* update packet status if needed (short is normally ok) */ 761 /* update packet status if needed (short is normally ok) */
764 if (cc == TD_DATAUNDERRUN 762 if (cc == TD_DATAUNDERRUN
@@ -787,7 +785,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
787 urb, td, 1 + td->index, cc, 785 urb, td, 1 + td->index, cc,
788 urb->actual_length, 786 urb->actual_length,
789 urb->transfer_buffer_length); 787 urb->transfer_buffer_length);
790 } 788 }
791} 789}
792 790
793/*-------------------------------------------------------------------------*/ 791/*-------------------------------------------------------------------------*/
@@ -795,7 +793,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
795static inline struct td * 793static inline struct td *
796ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev) 794ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
797{ 795{
798 struct urb *urb = td->urb; 796 struct urb *urb = td->urb;
799 struct ed *ed = td->ed; 797 struct ed *ed = td->ed;
800 struct list_head *tmp = td->td_list.next; 798 struct list_head *tmp = td->td_list.next;
801 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C); 799 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
@@ -805,7 +803,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
805 */ 803 */
806 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); 804 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
807 wmb (); 805 wmb ();
808 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H); 806 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H);
809 807
810 /* put any later tds from this urb onto the donelist, after 'td', 808 /* put any later tds from this urb onto the donelist, after 'td',
811 * order won't matter here: no errors, and nothing was transferred. 809 * order won't matter here: no errors, and nothing was transferred.
@@ -833,7 +831,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
833 info &= ~cpu_to_hc32 (ohci, TD_CC); 831 info &= ~cpu_to_hc32 (ohci, TD_CC);
834 next->hwINFO = info; 832 next->hwINFO = info;
835 833
836 next->next_dl_td = rev; 834 next->next_dl_td = rev;
837 rev = next; 835 rev = next;
838 836
839 ed->hwHeadP = next->hwNextTD | toggle; 837 ed->hwHeadP = next->hwNextTD | toggle;
@@ -881,8 +879,8 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
881 /* get TD from hc's singly linked list, and 879 /* get TD from hc's singly linked list, and
882 * prepend to ours. ed->td_list changes later. 880 * prepend to ours. ed->td_list changes later.
883 */ 881 */
884 while (td_dma) { 882 while (td_dma) {
885 int cc; 883 int cc;
886 884
887 td = dma_to_td (ohci, td_dma); 885 td = dma_to_td (ohci, td_dma);
888 if (!td) { 886 if (!td) {
@@ -901,10 +899,10 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
901 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) 899 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
902 td_rev = ed_halted (ohci, td, cc, td_rev); 900 td_rev = ed_halted (ohci, td, cc, td_rev);
903 901
904 td->next_dl_td = td_rev; 902 td->next_dl_td = td_rev;
905 td_rev = td; 903 td_rev = td;
906 td_dma = hc32_to_cpup (ohci, &td->hwNextTD); 904 td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
907 } 905 }
908 return td_rev; 906 return td_rev;
909} 907}
910 908
@@ -1013,9 +1011,9 @@ rescan_this:
1013 1011
1014 if (modified) 1012 if (modified)
1015 goto rescan_all; 1013 goto rescan_all;
1016 } 1014 }
1017 1015
1018 /* maybe reenable control and bulk lists */ 1016 /* maybe reenable control and bulk lists */
1019 if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state) 1017 if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state)
1020 && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING 1018 && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING
1021 && !ohci->ed_rm_list) { 1019 && !ohci->ed_rm_list) {
@@ -1041,20 +1039,20 @@ rescan_this:
1041 &ohci->regs->ed_bulkcurrent); 1039 &ohci->regs->ed_bulkcurrent);
1042 } 1040 }
1043 } 1041 }
1044 1042
1045 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */ 1043 /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
1046 if (control) { 1044 if (control) {
1047 ohci->hc_control |= control; 1045 ohci->hc_control |= control;
1048 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1046 if (ohci->flags & OHCI_QUIRK_ZFMICRO)
1049 mdelay(1); 1047 mdelay(1);
1050 ohci_writel (ohci, ohci->hc_control, 1048 ohci_writel (ohci, ohci->hc_control,
1051 &ohci->regs->control); 1049 &ohci->regs->control);
1052 } 1050 }
1053 if (command) { 1051 if (command) {
1054 if (ohci->flags & OHCI_QUIRK_ZFMICRO) 1052 if (ohci->flags & OHCI_QUIRK_ZFMICRO)
1055 mdelay(1); 1053 mdelay(1);
1056 ohci_writel (ohci, command, &ohci->regs->cmdstatus); 1054 ohci_writel (ohci, command, &ohci->regs->cmdstatus);
1057 } 1055 }
1058 } 1056 }
1059} 1057}
1060 1058
@@ -1074,19 +1072,19 @@ dl_done_list (struct ohci_hcd *ohci)
1074{ 1072{
1075 struct td *td = dl_reverse_done_list (ohci); 1073 struct td *td = dl_reverse_done_list (ohci);
1076 1074
1077 while (td) { 1075 while (td) {
1078 struct td *td_next = td->next_dl_td; 1076 struct td *td_next = td->next_dl_td;
1079 struct urb *urb = td->urb; 1077 struct urb *urb = td->urb;
1080 urb_priv_t *urb_priv = urb->hcpriv; 1078 urb_priv_t *urb_priv = urb->hcpriv;
1081 struct ed *ed = td->ed; 1079 struct ed *ed = td->ed;
1082 1080
1083 /* update URB's length and status from TD */ 1081 /* update URB's length and status from TD */
1084 td_done (ohci, urb, td); 1082 td_done (ohci, urb, td);
1085 urb_priv->td_cnt++; 1083 urb_priv->td_cnt++;
1086 1084
1087 /* If all this urb's TDs are done, call complete() */ 1085 /* If all this urb's TDs are done, call complete() */
1088 if (urb_priv->td_cnt == urb_priv->length) 1086 if (urb_priv->td_cnt == urb_priv->length)
1089 finish_urb (ohci, urb); 1087 finish_urb (ohci, urb);
1090 1088
1091 /* clean schedule: unlink EDs that are no longer busy */ 1089 /* clean schedule: unlink EDs that are no longer busy */
1092 if (list_empty (&ed->td_list)) { 1090 if (list_empty (&ed->td_list)) {
@@ -1094,25 +1092,26 @@ dl_done_list (struct ohci_hcd *ohci)
1094 start_ed_unlink (ohci, ed); 1092 start_ed_unlink (ohci, ed);
1095 1093
1096 /* ... reenabling halted EDs only after fault cleanup */ 1094 /* ... reenabling halted EDs only after fault cleanup */
1097 } else if ((ed->hwINFO & cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE)) 1095 } else if ((ed->hwINFO & cpu_to_hc32 (ohci,
1096 ED_SKIP | ED_DEQUEUE))
1098 == cpu_to_hc32 (ohci, ED_SKIP)) { 1097 == cpu_to_hc32 (ohci, ED_SKIP)) {
1099 td = list_entry (ed->td_list.next, struct td, td_list); 1098 td = list_entry (ed->td_list.next, struct td, td_list);
1100 if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) { 1099 if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
1101 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP); 1100 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP);
1102 /* ... hc may need waking-up */ 1101 /* ... hc may need waking-up */
1103 switch (ed->type) { 1102 switch (ed->type) {
1104 case PIPE_CONTROL: 1103 case PIPE_CONTROL:
1105 ohci_writel (ohci, OHCI_CLF, 1104 ohci_writel (ohci, OHCI_CLF,
1106 &ohci->regs->cmdstatus); 1105 &ohci->regs->cmdstatus);
1107 break; 1106 break;
1108 case PIPE_BULK: 1107 case PIPE_BULK:
1109 ohci_writel (ohci, OHCI_BLF, 1108 ohci_writel (ohci, OHCI_BLF,
1110 &ohci->regs->cmdstatus); 1109 &ohci->regs->cmdstatus);
1111 break; 1110 break;
1112 } 1111 }
1113 } 1112 }
1114 } 1113 }
1115 1114
1116 td = td_next; 1115 td = td_next;
1117 } 1116 }
1118} 1117}
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 59e436424d41..b350d45033e7 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -447,7 +447,7 @@ static const struct hc_driver ohci_s3c2410_hc_driver = {
447 */ 447 */
448 .start = ohci_s3c2410_start, 448 .start = ohci_s3c2410_start,
449 .stop = ohci_stop, 449 .stop = ohci_stop,
450 .shutdown = ohci_shutdown, 450 .shutdown = ohci_shutdown,
451 451
452 /* 452 /*
453 * managing i/o requests and associated device resources 453 * managing i/o requests and associated device resources
@@ -492,7 +492,7 @@ static int ohci_hcd_s3c2410_drv_remove(struct platform_device *pdev)
492static struct platform_driver ohci_hcd_s3c2410_driver = { 492static struct platform_driver ohci_hcd_s3c2410_driver = {
493 .probe = ohci_hcd_s3c2410_drv_probe, 493 .probe = ohci_hcd_s3c2410_drv_probe,
494 .remove = ohci_hcd_s3c2410_drv_remove, 494 .remove = ohci_hcd_s3c2410_drv_remove,
495 .shutdown = usb_hcd_platform_shutdown, 495 .shutdown = usb_hcd_platform_shutdown,
496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */ 496 /*.suspend = ohci_hcd_s3c2410_drv_suspend, */
497 /*.resume = ohci_hcd_s3c2410_drv_resume, */ 497 /*.resume = ohci_hcd_s3c2410_drv_resume, */
498 .driver = { 498 .driver = {
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index 71371de32ada..fe0090e33675 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -4,7 +4,7 @@
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * (C) Copyright 2002 Hewlett-Packard Company 6 * (C) Copyright 2002 Hewlett-Packard Company
7 * 7 *
8 * SA1111 Bus Glue 8 * SA1111 Bus Glue
9 * 9 *
10 * Written by Christopher Hoover <ch@hpl.hp.com> 10 * Written by Christopher Hoover <ch@hpl.hp.com>
@@ -12,7 +12,7 @@
12 * 12 *
13 * This file is licenced under the GPL. 13 * This file is licenced under the GPL.
14 */ 14 */
15 15
16#include <asm/hardware.h> 16#include <asm/hardware.h>
17#include <asm/mach-types.h> 17#include <asm/mach-types.h>
18#include <asm/arch/assabet.h> 18#include <asm/arch/assabet.h>
@@ -31,7 +31,7 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
31{ 31{
32 unsigned int usb_rst = 0; 32 unsigned int usb_rst = 0;
33 33
34 printk(KERN_DEBUG __FILE__ 34 printk(KERN_DEBUG __FILE__
35 ": starting SA-1111 OHCI USB Controller\n"); 35 ": starting SA-1111 OHCI USB Controller\n");
36 36
37#ifdef CONFIG_SA1100_BADGE4 37#ifdef CONFIG_SA1100_BADGE4
@@ -65,7 +65,7 @@ static void sa1111_start_hc(struct sa1111_dev *dev)
65static void sa1111_stop_hc(struct sa1111_dev *dev) 65static void sa1111_stop_hc(struct sa1111_dev *dev)
66{ 66{
67 unsigned int usb_rst; 67 unsigned int usb_rst;
68 printk(KERN_DEBUG __FILE__ 68 printk(KERN_DEBUG __FILE__
69 ": stopping SA-1111 OHCI USB Controller\n"); 69 ": stopping SA-1111 OHCI USB Controller\n");
70 70
71 /* 71 /*
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index a2f42a2f47c6..405257f3e853 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -1,9 +1,9 @@
1/* 1/*
2 * OHCI HCD (Host Controller Driver) for USB. 2 * OHCI HCD (Host Controller Driver) for USB.
3 * 3 *
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> 4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net> 5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
6 * 6 *
7 * This file is licenced under the GPL. 7 * This file is licenced under the GPL.
8 */ 8 */
9 9
@@ -14,7 +14,7 @@
14 */ 14 */
15typedef __u32 __bitwise __hc32; 15typedef __u32 __bitwise __hc32;
16typedef __u16 __bitwise __hc16; 16typedef __u16 __bitwise __hc16;
17 17
18/* 18/*
19 * OHCI Endpoint Descriptor (ED) ... holds TD queue 19 * OHCI Endpoint Descriptor (ED) ... holds TD queue
20 * See OHCI spec, section 4.2 20 * See OHCI spec, section 4.2
@@ -24,7 +24,7 @@ typedef __u16 __bitwise __hc16;
24 */ 24 */
25struct ed { 25struct ed {
26 /* first fields are hardware-specified */ 26 /* first fields are hardware-specified */
27 __hc32 hwINFO; /* endpoint config bitmap */ 27 __hc32 hwINFO; /* endpoint config bitmap */
28 /* info bits defined by hcd */ 28 /* info bits defined by hcd */
29#define ED_DEQUEUE (1 << 27) 29#define ED_DEQUEUE (1 << 27)
30 /* info bits defined by the hardware */ 30 /* info bits defined by the hardware */
@@ -52,11 +52,11 @@ struct ed {
52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ... 52 * usually: OPER --> UNLINK --> (IDLE | OPER) --> ...
53 */ 53 */
54 u8 state; /* ED_{IDLE,UNLINK,OPER} */ 54 u8 state; /* ED_{IDLE,UNLINK,OPER} */
55#define ED_IDLE 0x00 /* NOT linked to HC */ 55#define ED_IDLE 0x00 /* NOT linked to HC */
56#define ED_UNLINK 0x01 /* being unlinked from hc */ 56#define ED_UNLINK 0x01 /* being unlinked from hc */
57#define ED_OPER 0x02 /* IS linked to hc */ 57#define ED_OPER 0x02 /* IS linked to hc */
58 58
59 u8 type; /* PIPE_{BULK,...} */ 59 u8 type; /* PIPE_{BULK,...} */
60 60
61 /* periodic scheduling params (for intr and iso) */ 61 /* periodic scheduling params (for intr and iso) */
62 u8 branch; 62 u8 branch;
@@ -70,7 +70,7 @@ struct ed {
70 70
71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */ 71#define ED_MASK ((u32)~0x0f) /* strip hw status in low addr bits */
72 72
73 73
74/* 74/*
75 * OHCI Transfer Descriptor (TD) ... one per transfer segment 75 * OHCI Transfer Descriptor (TD) ... one per transfer segment
76 * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt) 76 * See OHCI spec, sections 4.3.1 (general = control/bulk/interrupt)
@@ -107,22 +107,22 @@ struct td {
107 107
108 /* (no hwINFO #defines yet for iso tds) */ 108 /* (no hwINFO #defines yet for iso tds) */
109 109
110 __hc32 hwCBP; /* Current Buffer Pointer (or 0) */ 110 __hc32 hwCBP; /* Current Buffer Pointer (or 0) */
111 __hc32 hwNextTD; /* Next TD Pointer */ 111 __hc32 hwNextTD; /* Next TD Pointer */
112 __hc32 hwBE; /* Memory Buffer End Pointer */ 112 __hc32 hwBE; /* Memory Buffer End Pointer */
113 113
114 /* PSW is only for ISO. Only 1 PSW entry is used, but on 114 /* PSW is only for ISO. Only 1 PSW entry is used, but on
115 * big-endian PPC hardware that's the second entry. 115 * big-endian PPC hardware that's the second entry.
116 */ 116 */
117#define MAXPSW 2 117#define MAXPSW 2
118 __hc16 hwPSW [MAXPSW]; 118 __hc16 hwPSW [MAXPSW];
119 119
120 /* rest are purely for the driver's use */ 120 /* rest are purely for the driver's use */
121 __u8 index; 121 __u8 index;
122 struct ed *ed; 122 struct ed *ed;
123 struct td *td_hash; /* dma-->td hashtable */ 123 struct td *td_hash; /* dma-->td hashtable */
124 struct td *next_dl_td; 124 struct td *next_dl_td;
125 struct urb *urb; 125 struct urb *urb;
126 126
127 dma_addr_t td_dma; /* addr of this TD */ 127 dma_addr_t td_dma; /* addr of this TD */
128 dma_addr_t data_dma; /* addr of data it points to */ 128 dma_addr_t data_dma; /* addr of data it points to */
@@ -152,8 +152,8 @@ struct td {
152#define TD_NOTACCESSED 0x0F 152#define TD_NOTACCESSED 0x0F
153 153
154 154
155/* map OHCI TD status codes (CC) to errno values */ 155/* map OHCI TD status codes (CC) to errno values */
156static const int cc_to_error [16] = { 156static const int cc_to_error [16] = {
157 /* No Error */ 0, 157 /* No Error */ 0,
158 /* CRC Error */ -EILSEQ, 158 /* CRC Error */ -EILSEQ,
159 /* Bit Stuff */ -EPROTO, 159 /* Bit Stuff */ -EPROTO,
@@ -169,7 +169,7 @@ static const int cc_to_error [16] = {
169 /* BufferOver */ -ECOMM, 169 /* BufferOver */ -ECOMM,
170 /* BuffUnder */ -ENOSR, 170 /* BuffUnder */ -ENOSR,
171 /* (for HCD) */ -EALREADY, 171 /* (for HCD) */ -EALREADY,
172 /* (for HCD) */ -EALREADY 172 /* (for HCD) */ -EALREADY
173}; 173};
174 174
175 175
@@ -182,7 +182,7 @@ struct ohci_hcca {
182#define NUM_INTS 32 182#define NUM_INTS 32
183 __hc32 int_table [NUM_INTS]; /* periodic schedule */ 183 __hc32 int_table [NUM_INTS]; /* periodic schedule */
184 184
185 /* 185 /*
186 * OHCI defines u16 frame_no, followed by u16 zero pad. 186 * OHCI defines u16 frame_no, followed by u16 zero pad.
187 * Since some processors can't do 16 bit bus accesses, 187 * Since some processors can't do 16 bit bus accesses,
188 * portable access must be a 32 bits wide. 188 * portable access must be a 32 bits wide.
@@ -262,10 +262,10 @@ struct ohci_regs {
262 * HcCommandStatus (cmdstatus) register masks 262 * HcCommandStatus (cmdstatus) register masks
263 */ 263 */
264#define OHCI_HCR (1 << 0) /* host controller reset */ 264#define OHCI_HCR (1 << 0) /* host controller reset */
265#define OHCI_CLF (1 << 1) /* control list filled */ 265#define OHCI_CLF (1 << 1) /* control list filled */
266#define OHCI_BLF (1 << 2) /* bulk list filled */ 266#define OHCI_BLF (1 << 2) /* bulk list filled */
267#define OHCI_OCR (1 << 3) /* ownership change request */ 267#define OHCI_OCR (1 << 3) /* ownership change request */
268#define OHCI_SOC (3 << 16) /* scheduling overrun count */ 268#define OHCI_SOC (3 << 16) /* scheduling overrun count */
269 269
270/* 270/*
271 * masks used with interrupt registers: 271 * masks used with interrupt registers:
@@ -285,20 +285,20 @@ struct ohci_regs {
285 285
286 286
287/* OHCI ROOT HUB REGISTER MASKS */ 287/* OHCI ROOT HUB REGISTER MASKS */
288 288
289/* roothub.portstatus [i] bits */ 289/* roothub.portstatus [i] bits */
290#define RH_PS_CCS 0x00000001 /* current connect status */ 290#define RH_PS_CCS 0x00000001 /* current connect status */
291#define RH_PS_PES 0x00000002 /* port enable status*/ 291#define RH_PS_PES 0x00000002 /* port enable status*/
292#define RH_PS_PSS 0x00000004 /* port suspend status */ 292#define RH_PS_PSS 0x00000004 /* port suspend status */
293#define RH_PS_POCI 0x00000008 /* port over current indicator */ 293#define RH_PS_POCI 0x00000008 /* port over current indicator */
294#define RH_PS_PRS 0x00000010 /* port reset status */ 294#define RH_PS_PRS 0x00000010 /* port reset status */
295#define RH_PS_PPS 0x00000100 /* port power status */ 295#define RH_PS_PPS 0x00000100 /* port power status */
296#define RH_PS_LSDA 0x00000200 /* low speed device attached */ 296#define RH_PS_LSDA 0x00000200 /* low speed device attached */
297#define RH_PS_CSC 0x00010000 /* connect status change */ 297#define RH_PS_CSC 0x00010000 /* connect status change */
298#define RH_PS_PESC 0x00020000 /* port enable status change */ 298#define RH_PS_PESC 0x00020000 /* port enable status change */
299#define RH_PS_PSSC 0x00040000 /* port suspend status change */ 299#define RH_PS_PSSC 0x00040000 /* port suspend status change */
300#define RH_PS_OCIC 0x00080000 /* over current indicator change */ 300#define RH_PS_OCIC 0x00080000 /* over current indicator change */
301#define RH_PS_PRSC 0x00100000 /* port reset status change */ 301#define RH_PS_PRSC 0x00100000 /* port reset status change */
302 302
303/* roothub.status bits */ 303/* roothub.status bits */
304#define RH_HS_LPS 0x00000001 /* local power status */ 304#define RH_HS_LPS 0x00000001 /* local power status */
@@ -333,7 +333,7 @@ typedef struct urb_priv {
333} urb_priv_t; 333} urb_priv_t;
334 334
335#define TD_HASH_SIZE 64 /* power'o'two */ 335#define TD_HASH_SIZE 64 /* power'o'two */
336// sizeof (struct td) ~= 64 == 2^6 ... 336// sizeof (struct td) ~= 64 == 2^6 ...
337#define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE) 337#define TD_HASH_FUNC(td_dma) ((td_dma ^ (td_dma >> 6)) % TD_HASH_SIZE)
338 338
339 339
@@ -364,11 +364,11 @@ struct ohci_hcd {
364 364
365 struct ed *ed_bulktail; /* last in bulk list */ 365 struct ed *ed_bulktail; /* last in bulk list */
366 struct ed *ed_controltail; /* last in ctrl list */ 366 struct ed *ed_controltail; /* last in ctrl list */
367 struct ed *periodic [NUM_INTS]; /* shadow int_table */ 367 struct ed *periodic [NUM_INTS]; /* shadow int_table */
368 368
369 /* 369 /*
370 * OTG controllers and transceivers need software interaction; 370 * OTG controllers and transceivers need software interaction;
371 * other external transceivers should be software-transparent 371 * other external transceivers should be software-transparent
372 */ 372 */
373 struct otg_transceiver *transceiver; 373 struct otg_transceiver *transceiver;
374 374
@@ -385,7 +385,7 @@ struct ohci_hcd {
385 */ 385 */
386 int num_ports; 386 int num_ports;
387 int load [NUM_INTS]; 387 int load [NUM_INTS];
388 u32 hc_control; /* copy of hc control reg */ 388 u32 hc_control; /* copy of hc control reg */
389 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
390 u32 fminterval; /* saved register */ 390 u32 fminterval; /* saved register */
391 unsigned autostop:1; /* rh auto stopping/stopped */ 391 unsigned autostop:1; /* rh auto stopping/stopped */
@@ -598,11 +598,11 @@ static inline void disable (struct ohci_hcd *ohci)
598} 598}
599 599
600#define FI 0x2edf /* 12000 bits per frame (-1) */ 600#define FI 0x2edf /* 12000 bits per frame (-1) */
601#define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7)) 601#define FSMP(fi) (0x7fff & ((6 * ((fi) - 210)) / 7))
602#define FIT (1 << 31) 602#define FIT (1 << 31)
603#define LSTHRESH 0x628 /* lowspeed bit threshold */ 603#define LSTHRESH 0x628 /* lowspeed bit threshold */
604 604
605static void periodic_reinit (struct ohci_hcd *ohci) 605static inline void periodic_reinit (struct ohci_hcd *ohci)
606{ 606{
607 u32 fi = ohci->fminterval & 0x03fff; 607 u32 fi = ohci->fminterval & 0x03fff;
608 u32 fit = ohci_readl(ohci, &ohci->regs->fminterval) & FIT; 608 u32 fit = ohci_readl(ohci, &ohci->regs->fminterval) & FIT;
@@ -626,11 +626,11 @@ static void periodic_reinit (struct ohci_hcd *ohci)
626 temp = ohci_readl (hc, &hc->regs->roothub.register); \ 626 temp = ohci_readl (hc, &hc->regs->roothub.register); \
627 temp; }) 627 temp; })
628 628
629static u32 roothub_a (struct ohci_hcd *hc) 629static inline u32 roothub_a (struct ohci_hcd *hc)
630 { return read_roothub (hc, a, 0xfc0fe000); } 630 { return read_roothub (hc, a, 0xfc0fe000); }
631static inline u32 roothub_b (struct ohci_hcd *hc) 631static inline u32 roothub_b (struct ohci_hcd *hc)
632 { return ohci_readl (hc, &hc->regs->roothub.b); } 632 { return ohci_readl (hc, &hc->regs->roothub.b); }
633static inline u32 roothub_status (struct ohci_hcd *hc) 633static inline u32 roothub_status (struct ohci_hcd *hc)
634 { return ohci_readl (hc, &hc->regs->roothub.status); } 634 { return ohci_readl (hc, &hc->regs->roothub.status); }
635static u32 roothub_portstatus (struct ohci_hcd *hc, int i) 635static inline u32 roothub_portstatus (struct ohci_hcd *hc, int i)
636 { return read_roothub (hc, portstatus [i], 0xffe0fce0); } 636 { return read_roothub (hc, portstatus [i], 0xffe0fce0); }
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index a9d7119e3176..a7fa0d75567d 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -40,6 +40,7 @@
40#include <linux/moduleparam.h> 40#include <linux/moduleparam.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43#include <linux/pci_ids.h>
43#include <linux/sched.h> 44#include <linux/sched.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45#include <linux/smp_lock.h> 46#include <linux/smp_lock.h>
@@ -210,15 +211,16 @@ struct u132 {
210* these cannot be inlines because we need the structure offset!! 211* these cannot be inlines because we need the structure offset!!
211* Does anyone have a better way????? 212* Does anyone have a better way?????
212*/ 213*/
214#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
215 offsetof(struct ohci_regs, member), 0, data);
216#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
217 offsetof(struct ohci_regs, member), 0, data);
213#define u132_read_pcimem(u132, member, data) \ 218#define u132_read_pcimem(u132, member, data) \
214 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ 219 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
215 ohci_regs, member), 0, data); 220 ohci_regs, member), 0, data);
216#define u132_write_pcimem(u132, member, data) \ 221#define u132_write_pcimem(u132, member, data) \
217 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ 222 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
218 ohci_regs, member), 0, data); 223 ohci_regs, member), 0, data);
219#define u132_write_pcimem_byte(u132, member, data) \
220 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0x0e, data);
222static inline struct u132 *udev_to_u132(struct u132_udev *udev) 224static inline struct u132 *udev_to_u132(struct u132_udev *udev)
223{ 225{
224 u8 udev_number = udev->udev_number; 226 u8 udev_number = udev->udev_number;
@@ -1574,59 +1576,12 @@ static char *hcfs2string(int state)
1574 return "?"; 1576 return "?";
1575} 1577}
1576 1578
1577static int u132_usb_reset(struct u132 *u132)
1578{
1579 int retval;
1580 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1581 if (retval)
1582 return retval;
1583 u132->hc_control &= OHCI_CTRL_RWC;
1584 retval = u132_write_pcimem(u132, control, u132->hc_control);
1585 if (retval)
1586 return retval;
1587 return 0;
1588}
1589
1590static int u132_init(struct u132 *u132) 1579static int u132_init(struct u132 *u132)
1591{ 1580{
1592 int retval; 1581 int retval;
1593 u32 control; 1582 u32 control;
1594 u132_disable(u132); 1583 u132_disable(u132);
1595 u132->next_statechange = 1584 u132->next_statechange = jiffies;
1596 jiffies; /* SMM owns the HC? not for long! */ {
1597 u32 control;
1598 retval = u132_read_pcimem(u132, control, &control);
1599 if (retval)
1600 return retval;
1601 if (control & OHCI_CTRL_IR) {
1602 u32 temp = 50;
1603 retval = u132_write_pcimem(u132, intrenable,
1604 OHCI_INTR_OC);
1605 if (retval)
1606 return retval;
1607 retval = u132_write_pcimem_byte(u132, cmdstatus,
1608 OHCI_OCR);
1609 if (retval)
1610 return retval;
1611 check:{
1612 retval = u132_read_pcimem(u132, control,
1613 &control);
1614 if (retval)
1615 return retval;
1616 }
1617 if (control & OHCI_CTRL_IR) {
1618 msleep(10);
1619 if (--temp == 0) {
1620 dev_err(&u132->platform_dev->dev, "USB "
1621 "HC takeover failed!(BIOS/SMM b"
1622 "ug) control=%08X\n", control);
1623 return -EBUSY;
1624 }
1625 goto check;
1626 }
1627 u132_usb_reset(u132);
1628 }
1629 }
1630 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); 1585 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1631 if (retval) 1586 if (retval)
1632 return retval; 1587 return retval;
@@ -1725,7 +1680,7 @@ static int u132_run(struct u132 *u132)
1725 retry:retval = u132_read_pcimem(u132, cmdstatus, &status); 1680 retry:retval = u132_read_pcimem(u132, cmdstatus, &status);
1726 if (retval) 1681 if (retval)
1727 return retval; 1682 return retval;
1728 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_HCR); 1683 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1729 if (retval) 1684 if (retval)
1730 return retval; 1685 return retval;
1731 extra:{ 1686 extra:{
@@ -1782,7 +1737,7 @@ static int u132_run(struct u132 *u132)
1782 retval = u132_write_pcimem(u132, control, u132->hc_control); 1737 retval = u132_write_pcimem(u132, control, u132->hc_control);
1783 if (retval) 1738 if (retval)
1784 return retval; 1739 return retval;
1785 retval = u132_write_pcimem_byte(u132, cmdstatus, OHCI_BLF); 1740 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1786 if (retval) 1741 if (retval)
1787 return retval; 1742 return retval;
1788 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); 1743 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
@@ -1839,8 +1794,8 @@ static void u132_hcd_stop(struct usb_hcd *hcd)
1839{ 1794{
1840 struct u132 *u132 = hcd_to_u132(hcd); 1795 struct u132 *u132 = hcd_to_u132(hcd);
1841 if (u132->going > 1) { 1796 if (u132->going > 1) {
1842 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1797 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1843 , u132->going); 1798 "een removed %d\n", u132, hcd, u132->going);
1844 } else if (u132->going > 0) { 1799 } else if (u132->going > 0) {
1845 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 1800 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1846 "ed\n", hcd); 1801 "ed\n", hcd);
@@ -2545,8 +2500,9 @@ static void u132_endpoint_disable(struct usb_hcd *hcd,
2545{ 2500{
2546 struct u132 *u132 = hcd_to_u132(hcd); 2501 struct u132 *u132 = hcd_to_u132(hcd);
2547 if (u132->going > 2) { 2502 if (u132->going > 2) {
2548 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2503 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2549 , u132->going); 2504 ") has been removed %d\n", u132, hcd, hep,
2505 u132->going);
2550 } else { 2506 } else {
2551 struct u132_endp *endp = hep->hcpriv; 2507 struct u132_endp *endp = hep->hcpriv;
2552 if (endp) 2508 if (endp)
@@ -2790,7 +2746,6 @@ static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2790 } else if (u132->going > 0) { 2746 } else if (u132->going > 0) {
2791 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 2747 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2792 "ed\n", hcd); 2748 "ed\n", hcd);
2793 dump_stack();
2794 return -ESHUTDOWN; 2749 return -ESHUTDOWN;
2795 } else { 2750 } else {
2796 int i, changed = 0, length = 1; 2751 int i, changed = 0, length = 1;
@@ -3034,12 +2989,15 @@ static int __devexit u132_remove(struct platform_device *pdev)
3034 struct usb_hcd *hcd = platform_get_drvdata(pdev); 2989 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3035 if (hcd) { 2990 if (hcd) {
3036 struct u132 *u132 = hcd_to_u132(hcd); 2991 struct u132 *u132 = hcd_to_u132(hcd);
3037 dump_stack();
3038 if (u132->going++ > 1) { 2992 if (u132->going++ > 1) {
2993 dev_err(&u132->platform_dev->dev, "already being remove"
2994 "d\n");
3039 return -ENODEV; 2995 return -ENODEV;
3040 } else { 2996 } else {
3041 int rings = MAX_U132_RINGS; 2997 int rings = MAX_U132_RINGS;
3042 int endps = MAX_U132_ENDPS; 2998 int endps = MAX_U132_ENDPS;
2999 dev_err(&u132->platform_dev->dev, "removing device u132"
3000 ".%d\n", u132->sequence_num);
3043 msleep(100); 3001 msleep(100);
3044 down(&u132->sw_lock); 3002 down(&u132->sw_lock);
3045 u132_monitor_cancel_work(u132); 3003 u132_monitor_cancel_work(u132);
@@ -3121,10 +3079,24 @@ static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3121static int __devinit u132_probe(struct platform_device *pdev) 3079static int __devinit u132_probe(struct platform_device *pdev)
3122{ 3080{
3123 struct usb_hcd *hcd; 3081 struct usb_hcd *hcd;
3082 int retval;
3083 u32 control;
3084 u32 rh_a = -1;
3085 u32 num_ports;
3124 msleep(100); 3086 msleep(100);
3125 if (u132_exiting > 0) { 3087 if (u132_exiting > 0) {
3126 return -ENODEV; 3088 return -ENODEV;
3127 } /* refuse to confuse usbcore */ 3089 }
3090 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3091 if (retval)
3092 return retval;
3093 retval = ftdi_read_pcimem(pdev, control, &control);
3094 if (retval)
3095 return retval;
3096 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3097 if (retval)
3098 return retval;
3099 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3128 if (pdev->dev.dma_mask) { 3100 if (pdev->dev.dma_mask) {
3129 return -EINVAL; 3101 return -EINVAL;
3130 } 3102 }
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c
index e87692c31be4..acd101caeeeb 100644
--- a/drivers/usb/host/uhci-hcd.c
+++ b/drivers/usb/host/uhci-hcd.c
@@ -60,6 +60,11 @@ Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, \
60Alan Stern" 60Alan Stern"
61#define DRIVER_DESC "USB Universal Host Controller Interface driver" 61#define DRIVER_DESC "USB Universal Host Controller Interface driver"
62 62
63/* for flakey hardware, ignore overcurrent indicators */
64static int ignore_oc;
65module_param(ignore_oc, bool, S_IRUGO);
66MODULE_PARM_DESC(ignore_oc, "ignore hardware overcurrent indications");
67
63/* 68/*
64 * debug = 0, no debugging messages 69 * debug = 0, no debugging messages
65 * debug = 1, dump failed URBs except for stalls 70 * debug = 1, dump failed URBs except for stalls
@@ -169,6 +174,11 @@ static int resume_detect_interrupts_are_broken(struct uhci_hcd *uhci)
169{ 174{
170 int port; 175 int port;
171 176
177 /* If we have to ignore overcurrent events then almost by definition
178 * we can't depend on resume-detect interrupts. */
179 if (ignore_oc)
180 return 1;
181
172 switch (to_pci_dev(uhci_dev(uhci))->vendor) { 182 switch (to_pci_dev(uhci_dev(uhci))->vendor) {
173 default: 183 default:
174 break; 184 break;
@@ -921,7 +931,8 @@ static int __init uhci_hcd_init(void)
921{ 931{
922 int retval = -ENOMEM; 932 int retval = -ENOMEM;
923 933
924 printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION "\n"); 934 printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION "%s\n",
935 ignore_oc ? ", overcurrent ignored" : "");
925 936
926 if (usb_disabled()) 937 if (usb_disabled())
927 return -ENODEV; 938 return -ENODEV;
diff --git a/drivers/usb/host/uhci-hub.c b/drivers/usb/host/uhci-hub.c
index f8347f1a10b6..bacc25c53ba3 100644
--- a/drivers/usb/host/uhci-hub.c
+++ b/drivers/usb/host/uhci-hub.c
@@ -52,10 +52,20 @@ static int any_ports_active(struct uhci_hcd *uhci)
52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf) 52static inline int get_hub_status_data(struct uhci_hcd *uhci, char *buf)
53{ 53{
54 int port; 54 int port;
55 int mask = RWC_BITS;
56
57 /* Some boards (both VIA and Intel apparently) report bogus
58 * overcurrent indications, causing massive log spam unless
59 * we completely ignore them. This doesn't seem to be a problem
60 * with the chipset so much as with the way it is connected on
61 * the motherboard; if the overcurrent input is left to float
62 * then it may constantly register false positives. */
63 if (ignore_oc)
64 mask &= ~USBPORTSC_OCC;
55 65
56 *buf = 0; 66 *buf = 0;
57 for (port = 0; port < uhci->rh_numports; ++port) { 67 for (port = 0; port < uhci->rh_numports; ++port) {
58 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & RWC_BITS) || 68 if ((inw(uhci->io_addr + USBPORTSC1 + port * 2) & mask) ||
59 test_bit(port, &uhci->port_c_suspend)) 69 test_bit(port, &uhci->port_c_suspend))
60 *buf |= (1 << (port + 1)); 70 *buf |= (1 << (port + 1));
61 } 71 }
@@ -263,7 +273,7 @@ static int uhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
263 wPortChange |= USB_PORT_STAT_C_CONNECTION; 273 wPortChange |= USB_PORT_STAT_C_CONNECTION;
264 if (status & USBPORTSC_PEC) 274 if (status & USBPORTSC_PEC)
265 wPortChange |= USB_PORT_STAT_C_ENABLE; 275 wPortChange |= USB_PORT_STAT_C_ENABLE;
266 if (status & USBPORTSC_OCC) 276 if ((status & USBPORTSC_OCC) && !ignore_oc)
267 wPortChange |= USB_PORT_STAT_C_OVERCURRENT; 277 wPortChange |= USB_PORT_STAT_C_OVERCURRENT;
268 278
269 if (test_bit(port, &uhci->port_c_suspend)) { 279 if (test_bit(port, &uhci->port_c_suspend)) {
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 8a62d4785755..f877cd4f317a 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -7,7 +7,8 @@ comment "USB Input Devices"
7config USB_HID 7config USB_HID
8 tristate "USB Human Interface Device (full HID) support" 8 tristate "USB Human Interface Device (full HID) support"
9 default y 9 default y
10 depends on USB && HID 10 depends on USB
11 select HID
11 ---help--- 12 ---help---
12 Say Y here if you want full HID support to connect USB keyboards, 13 Say Y here if you want full HID support to connect USB keyboards,
13 mice, joysticks, graphic tablets, or any other HID based devices 14 mice, joysticks, graphic tablets, or any other HID based devices
@@ -28,7 +29,7 @@ config USB_HID
28comment "Input core support is needed for USB HID input layer or HIDBP support" 29comment "Input core support is needed for USB HID input layer or HIDBP support"
29 depends on USB_HID && INPUT=n 30 depends on USB_HID && INPUT=n
30 31
31config USB_HID_POWERBOOK 32config USB_HIDINPUT_POWERBOOK
32 bool "Enable support for iBook/PowerBook special keys" 33 bool "Enable support for iBook/PowerBook special keys"
33 default n 34 default n
34 depends on USB_HID 35 depends on USB_HID
diff --git a/drivers/usb/input/wacom_sys.c b/drivers/usb/input/wacom_sys.c
index e7cc20ab8155..12b42746ded8 100644
--- a/drivers/usb/input/wacom_sys.c
+++ b/drivers/usb/input/wacom_sys.c
@@ -159,13 +159,13 @@ void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
159{ 159{
160 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER); 160 input_dev->keybit[LONG(BTN_DIGI)] |= BIT(BTN_TOOL_FINGER);
161 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3); 161 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_0) | BIT(BTN_1) | BIT(BTN_2) | BIT(BTN_3);
162 input_set_abs_params(input_dev, ABS_RX, 0, 4097, 0, 0); 162 input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
163} 163}
164 164
165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 165void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
166{ 166{
167 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7); 167 input_dev->keybit[LONG(BTN_LEFT)] |= BIT(BTN_4) | BIT(BTN_5) | BIT(BTN_6) | BIT(BTN_7);
168 input_set_abs_params(input_dev, ABS_RY, 0, 4097, 0, 0); 168 input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
169} 169}
170 170
171void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 171void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
diff --git a/drivers/usb/input/wacom_wac.c b/drivers/usb/input/wacom_wac.c
index 92726fe89379..4142e36730fc 100644
--- a/drivers/usb/input/wacom_wac.c
+++ b/drivers/usb/input/wacom_wac.c
@@ -209,13 +209,15 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02); 209 wacom_report_key(wcombo, BTN_STYLUS, data[1] & 0x02);
210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04); 210 wacom_report_key(wcombo, BTN_STYLUS2, data[1] & 0x04);
211 } 211 }
212 }
213
214 if (data[1] & 0x10)
215 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */ 212 wacom_report_abs(wcombo, ABS_MISC, id); /* report tool id */
213 }
216 else 214 else
217 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */ 215 wacom_report_abs(wcombo, ABS_MISC, 0); /* reset tool id */
218 wacom_report_key(wcombo, wacom->tool[0], data[1] & 0x10); 216
217 if (data[1] & 0x10) /* only report prox-in when in area */
218 wacom_report_key(wcombo, wacom->tool[0], 1);
219 if (!(data[1] & 0x90)) /* report prox-out when physically out */
220 wacom_report_key(wcombo, wacom->tool[0], 0);
219 wacom_input_sync(wcombo); 221 wacom_input_sync(wcombo);
220 222
221 /* send pad data */ 223 /* send pad data */
@@ -405,7 +407,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
405 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) 407 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40))
406 return 0; 408 return 0;
407 409
408 if (wacom->features->type >= INTUOS3) { 410 if (wacom->features->type >= INTUOS3S) {
409 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); 411 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
410 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); 412 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
411 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 413 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
@@ -423,7 +425,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
423 425
424 if (data[1] & 0x02) { 426 if (data[1] & 0x02) {
425 /* Rotation packet */ 427 /* Rotation packet */
426 if (wacom->features->type >= INTUOS3) { 428 if (wacom->features->type >= INTUOS3S) {
427 /* I3 marker pen rotation reported as wheel 429 /* I3 marker pen rotation reported as wheel
428 * due to valuator limitation 430 * due to valuator limitation
429 */ 431 */
@@ -547,11 +549,11 @@ static struct wacom_features wacom_features[] = {
547 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 63, GRAPHIRE }, 549 { "Wacom Graphire3 6x8", 8, 16704, 12064, 511, 63, GRAPHIRE },
548 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 63, WACOM_G4 }, 550 { "Wacom Graphire4 4x5", 8, 10208, 7424, 511, 63, WACOM_G4 },
549 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 63, WACOM_G4 }, 551 { "Wacom Graphire4 6x8", 8, 16704, 12064, 511, 63, WACOM_G4 },
550 { "Wacom Volito", 8, 5104, 3712, 511, 0, GRAPHIRE }, 552 { "Wacom Volito", 8, 5104, 3712, 511, 63, GRAPHIRE },
551 { "Wacom PenStation2", 8, 3250, 2320, 255, 0, GRAPHIRE }, 553 { "Wacom PenStation2", 8, 3250, 2320, 255, 63, GRAPHIRE },
552 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 0, GRAPHIRE }, 554 { "Wacom Volito2 4x5", 8, 5104, 3712, 511, 63, GRAPHIRE },
553 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 0, GRAPHIRE }, 555 { "Wacom Volito2 2x3", 8, 3248, 2320, 511, 63, GRAPHIRE },
554 { "Wacom PenPartner2", 8, 3250, 2320, 255, 0, GRAPHIRE }, 556 { "Wacom PenPartner2", 8, 3250, 2320, 255, 63, GRAPHIRE },
555 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS }, 557 { "Wacom Intuos 4x5", 10, 12700, 10600, 1023, 63, INTUOS },
556 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 558 { "Wacom Intuos 6x8", 10, 20320, 16240, 1023, 63, INTUOS },
557 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS }, 559 { "Wacom Intuos 9x12", 10, 30480, 24060, 1023, 63, INTUOS },
@@ -580,7 +582,7 @@ static struct wacom_features wacom_features[] = {
580 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L }, 582 { "Wacom Intuos3 12x12", 10, 60960, 60960, 1023, 63, INTUOS3L },
581 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L }, 583 { "Wacom Intuos3 12x19", 10, 97536, 60960, 1023, 63, INTUOS3L },
582 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 }, 584 { "Wacom Intuos3 6x11", 10, 54204, 31750, 1023, 63, INTUOS3 },
583 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 15, INTUOS3S }, 585 { "Wacom Intuos3 4x6", 10, 31496, 19685, 1023, 63, INTUOS3S },
584 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ }, 586 { "Wacom Cintiq 21UX", 10, 87200, 65600, 1023, 63, CINTIQ },
585 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS }, 587 { "Wacom Intuos2 6x8", 10, 20320, 16240, 1023, 63, INTUOS },
586 { } 588 { }
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index 02cbb7fff24f..a7932a72d298 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
281 /* Register backlight device */ 281 /* Register backlight device */
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 pdata->bd = backlight_device_register(bl_name, pdata, 284 pdata->bd = backlight_device_register(bl_name, NULL, NULL,
285 &appledisplay_bl_data); 285 &appledisplay_bl_data);
286 if (IS_ERR(pdata->bd)) { 286 if (IS_ERR(pdata->bd)) {
287 err("appledisplay: Backlight registration failed"); 287 err("appledisplay: Backlight registration failed");
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 6c7f3efb1d40..b5332e679c46 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -1376,7 +1376,7 @@ static int auerchar_open (struct inode *inode, struct file *file)
1376 } 1376 }
1377 1377
1378 /* we have access to the device. Now lets allocate memory */ 1378 /* we have access to the device. Now lets allocate memory */
1379 ccp = (pauerchar_t) kmalloc(sizeof(auerchar_t), GFP_KERNEL); 1379 ccp = kzalloc(sizeof(auerchar_t), GFP_KERNEL);
1380 if (ccp == NULL) { 1380 if (ccp == NULL) {
1381 err ("out of memory"); 1381 err ("out of memory");
1382 ret = -ENOMEM; 1382 ret = -ENOMEM;
@@ -1384,7 +1384,6 @@ static int auerchar_open (struct inode *inode, struct file *file)
1384 } 1384 }
1385 1385
1386 /* Initialize device descriptor */ 1386 /* Initialize device descriptor */
1387 memset( ccp, 0, sizeof(auerchar_t));
1388 init_MUTEX( &ccp->mutex); 1387 init_MUTEX( &ccp->mutex);
1389 init_MUTEX( &ccp->readmutex); 1388 init_MUTEX( &ccp->readmutex);
1390 auerbuf_init (&ccp->bufctl); 1389 auerbuf_init (&ccp->bufctl);
@@ -1912,14 +1911,13 @@ static int auerswald_probe (struct usb_interface *intf,
1912 return -ENODEV; 1911 return -ENODEV;
1913 1912
1914 /* allocate memory for our device and initialize it */ 1913 /* allocate memory for our device and initialize it */
1915 cp = kmalloc (sizeof(auerswald_t), GFP_KERNEL); 1914 cp = kzalloc (sizeof(auerswald_t), GFP_KERNEL);
1916 if (cp == NULL) { 1915 if (cp == NULL) {
1917 err ("out of memory"); 1916 err ("out of memory");
1918 goto pfail; 1917 goto pfail;
1919 } 1918 }
1920 1919
1921 /* Initialize device descriptor */ 1920 /* Initialize device descriptor */
1922 memset (cp, 0, sizeof(auerswald_t));
1923 init_MUTEX (&cp->mutex); 1921 init_MUTEX (&cp->mutex);
1924 cp->usbdev = usbdev; 1922 cp->usbdev = usbdev;
1925 auerchain_init (&cp->controlchain); 1923 auerchain_init (&cp->controlchain);
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 18b1925032a8..41c0161abdb9 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -40,6 +40,7 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/ioctl.h> 42#include <linux/ioctl.h>
43#include <linux/pci_ids.h>
43#include <linux/slab.h> 44#include <linux/slab.h>
44#include <linux/module.h> 45#include <linux/module.h>
45#include <linux/kref.h> 46#include <linux/kref.h>
@@ -51,6 +52,10 @@ MODULE_AUTHOR("Tony Olech");
51MODULE_DESCRIPTION("FTDI ELAN driver"); 52MODULE_DESCRIPTION("FTDI ELAN driver");
52MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
53#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444) 54#define INT_MODULE_PARM(n, v) static int n = v;module_param(n, int, 0444)
55static int distrust_firmware = 1;
56module_param(distrust_firmware, bool, 0);
57MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
58 "t setup");
54extern struct platform_driver u132_platform_driver; 59extern struct platform_driver u132_platform_driver;
55static struct workqueue_struct *status_queue; 60static struct workqueue_struct *status_queue;
56static struct workqueue_struct *command_queue; 61static struct workqueue_struct *command_queue;
@@ -66,7 +71,9 @@ static struct list_head ftdi_static_list;
66* end of the global variables protected by ftdi_module_lock 71* end of the global variables protected by ftdi_module_lock
67*/ 72*/
68#include "usb_u132.h" 73#include "usb_u132.h"
69#define TD_DEVNOTRESP 5 74#include <asm/io.h>
75#include "../core/hcd.h"
76#include "../host/ohci.h"
70/* Define these values to match your devices*/ 77/* Define these values to match your devices*/
71#define USB_FTDI_ELAN_VENDOR_ID 0x0403 78#define USB_FTDI_ELAN_VENDOR_ID 0x0403
72#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea 79#define USB_FTDI_ELAN_PRODUCT_ID 0xd6ea
@@ -551,7 +558,7 @@ static void ftdi_elan_status_work(struct work_struct *work)
551 } else { 558 } else {
552 dev_err(&ftdi->udev->dev, "initialized failed - trying " 559 dev_err(&ftdi->udev->dev, "initialized failed - trying "
553 "again in 10 seconds\n"); 560 "again in 10 seconds\n");
554 work_delay_in_msec = 10 *1000; 561 work_delay_in_msec = 1 *1000;
555 } 562 }
556 } else if (ftdi->registered == 0) { 563 } else if (ftdi->registered == 0) {
557 work_delay_in_msec = 10; 564 work_delay_in_msec = 10;
@@ -2288,82 +2295,288 @@ static int ftdi_elan_checkingPCI(struct usb_ftdi *ftdi)
2288 } 2295 }
2289} 2296}
2290 2297
2291static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi) 2298
2299#define ftdi_read_pcimem(ftdi, member, data) ftdi_elan_read_pcimem(ftdi, \
2300 offsetof(struct ohci_regs, member), 0, data);
2301#define ftdi_write_pcimem(ftdi, member, data) ftdi_elan_write_pcimem(ftdi, \
2302 offsetof(struct ohci_regs, member), 0, data);
2303#define OHCI_QUIRK_AMD756 0x01
2304#define OHCI_QUIRK_SUPERIO 0x02
2305#define OHCI_QUIRK_INITRESET 0x04
2306#define OHCI_BIG_ENDIAN 0x08
2307#define OHCI_QUIRK_ZFMICRO 0x10
2308#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
2309#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
2310 OHCI_INTR_WDH)
2311static int ftdi_elan_check_controller(struct usb_ftdi *ftdi, int quirk)
2312{
2313 int devices = 0;
2314 int retval;
2315 u32 hc_control;
2316 int num_ports;
2317 u32 control;
2318 u32 rh_a = -1;
2319 u32 status;
2320 u32 fminterval;
2321 u32 hc_fminterval;
2322 u32 periodicstart;
2323 u32 cmdstatus;
2324 u32 roothub_a;
2325 int mask = OHCI_INTR_INIT;
2326 int sleep_time = 0;
2327 int reset_timeout = 30; /* ... allow extra time */
2328 int temp;
2329 retval = ftdi_write_pcimem(ftdi, intrdisable, OHCI_INTR_MIE);
2330 if (retval)
2331 return retval;
2332 retval = ftdi_read_pcimem(ftdi, control, &control);
2333 if (retval)
2334 return retval;
2335 retval = ftdi_read_pcimem(ftdi, roothub.a, &rh_a);
2336 if (retval)
2337 return retval;
2338 num_ports = rh_a & RH_A_NDP;
2339 retval = ftdi_read_pcimem(ftdi, fminterval, &hc_fminterval);
2340 if (retval)
2341 return retval;
2342 hc_fminterval &= 0x3fff;
2343 if (hc_fminterval != FI) {
2344 }
2345 hc_fminterval |= FSMP(hc_fminterval) << 16;
2346 retval = ftdi_read_pcimem(ftdi, control, &hc_control);
2347 if (retval)
2348 return retval;
2349 switch (hc_control & OHCI_CTRL_HCFS) {
2350 case OHCI_USB_OPER:
2351 sleep_time = 0;
2352 break;
2353 case OHCI_USB_SUSPEND:
2354 case OHCI_USB_RESUME:
2355 hc_control &= OHCI_CTRL_RWC;
2356 hc_control |= OHCI_USB_RESUME;
2357 sleep_time = 10;
2358 break;
2359 default:
2360 hc_control &= OHCI_CTRL_RWC;
2361 hc_control |= OHCI_USB_RESET;
2362 sleep_time = 50;
2363 break;
2364 }
2365 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2366 if (retval)
2367 return retval;
2368 retval = ftdi_read_pcimem(ftdi, control, &control);
2369 if (retval)
2370 return retval;
2371 msleep(sleep_time);
2372 retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
2373 if (retval)
2374 return retval;
2375 if (!(roothub_a & RH_A_NPS)) { /* power down each port */
2376 for (temp = 0; temp < num_ports; temp++) {
2377 retval = ftdi_write_pcimem(ftdi,
2378 roothub.portstatus[temp], RH_PS_LSDA);
2379 if (retval)
2380 return retval;
2381 }
2382 }
2383 retval = ftdi_read_pcimem(ftdi, control, &control);
2384 if (retval)
2385 return retval;
2386 retry:retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
2387 if (retval)
2388 return retval;
2389 retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_HCR);
2390 if (retval)
2391 return retval;
2392 extra:{
2393 retval = ftdi_read_pcimem(ftdi, cmdstatus, &status);
2394 if (retval)
2395 return retval;
2396 if (0 != (status & OHCI_HCR)) {
2397 if (--reset_timeout == 0) {
2398 dev_err(&ftdi->udev->dev, "USB HC reset timed o"
2399 "ut!\n");
2400 return -ENODEV;
2401 } else {
2402 msleep(5);
2403 goto extra;
2404 }
2405 }
2406 }
2407 if (quirk & OHCI_QUIRK_INITRESET) {
2408 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2409 if (retval)
2410 return retval;
2411 retval = ftdi_read_pcimem(ftdi, control, &control);
2412 if (retval)
2413 return retval;
2414 }
2415 retval = ftdi_write_pcimem(ftdi, ed_controlhead, 0x00000000);
2416 if (retval)
2417 return retval;
2418 retval = ftdi_write_pcimem(ftdi, ed_bulkhead, 0x11000000);
2419 if (retval)
2420 return retval;
2421 retval = ftdi_write_pcimem(ftdi, hcca, 0x00000000);
2422 if (retval)
2423 return retval;
2424 retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
2425 if (retval)
2426 return retval;
2427 retval = ftdi_write_pcimem(ftdi, fminterval,
2428 ((fminterval & FIT) ^ FIT) | hc_fminterval);
2429 if (retval)
2430 return retval;
2431 retval = ftdi_write_pcimem(ftdi, periodicstart,
2432 ((9 *hc_fminterval) / 10) & 0x3fff);
2433 if (retval)
2434 return retval;
2435 retval = ftdi_read_pcimem(ftdi, fminterval, &fminterval);
2436 if (retval)
2437 return retval;
2438 retval = ftdi_read_pcimem(ftdi, periodicstart, &periodicstart);
2439 if (retval)
2440 return retval;
2441 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
2442 if (!(quirk & OHCI_QUIRK_INITRESET)) {
2443 quirk |= OHCI_QUIRK_INITRESET;
2444 goto retry;
2445 } else
2446 dev_err(&ftdi->udev->dev, "init err(%08x %04x)\n",
2447 fminterval, periodicstart);
2448 } /* start controller operations */
2449 hc_control &= OHCI_CTRL_RWC;
2450 hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
2451 retval = ftdi_write_pcimem(ftdi, control, hc_control);
2452 if (retval)
2453 return retval;
2454 retval = ftdi_write_pcimem(ftdi, cmdstatus, OHCI_BLF);
2455 if (retval)
2456 return retval;
2457 retval = ftdi_read_pcimem(ftdi, cmdstatus, &cmdstatus);
2458 if (retval)
2459 return retval;
2460 retval = ftdi_read_pcimem(ftdi, control, &control);
2461 if (retval)
2462 return retval;
2463 retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_DRWE);
2464 if (retval)
2465 return retval;
2466 retval = ftdi_write_pcimem(ftdi, intrstatus, mask);
2467 if (retval)
2468 return retval;
2469 retval = ftdi_write_pcimem(ftdi, intrdisable,
2470 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
2471 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
2472 OHCI_INTR_SO);
2473 if (retval)
2474 return retval; /* handle root hub init quirks ... */
2475 retval = ftdi_read_pcimem(ftdi, roothub.a, &roothub_a);
2476 if (retval)
2477 return retval;
2478 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
2479 if (quirk & OHCI_QUIRK_SUPERIO) {
2480 roothub_a |= RH_A_NOCP;
2481 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
2482 retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
2483 if (retval)
2484 return retval;
2485 } else if ((quirk & OHCI_QUIRK_AMD756) || distrust_firmware) {
2486 roothub_a |= RH_A_NPS;
2487 retval = ftdi_write_pcimem(ftdi, roothub.a, roothub_a);
2488 if (retval)
2489 return retval;
2490 }
2491 retval = ftdi_write_pcimem(ftdi, roothub.status, RH_HS_LPSC);
2492 if (retval)
2493 return retval;
2494 retval = ftdi_write_pcimem(ftdi, roothub.b,
2495 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
2496 if (retval)
2497 return retval;
2498 retval = ftdi_read_pcimem(ftdi, control, &control);
2499 if (retval)
2500 return retval;
2501 mdelay((roothub_a >> 23) & 0x1fe);
2502 for (temp = 0; temp < num_ports; temp++) {
2503 u32 portstatus;
2504 retval = ftdi_read_pcimem(ftdi, roothub.portstatus[temp],
2505 &portstatus);
2506 if (retval)
2507 return retval;
2508 if (1 & portstatus)
2509 devices += 1;
2510 }
2511 return devices;
2512}
2513
2514static int ftdi_elan_setup_controller(struct usb_ftdi *ftdi, int fn)
2292{ 2515{
2293 u32 latence_timer; 2516 u32 latence_timer;
2294 u32 controlreg;
2295 int UxxxStatus; 2517 int UxxxStatus;
2296 u32 pcidata; 2518 u32 pcidata;
2297 int reg = 0; 2519 int reg = 0;
2298 int foundOHCI = 0; 2520 int activePCIfn = fn << 8;
2299 u8 fn; 2521 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
2300 int activePCIfn = 0;
2301 u32 pciVID = 0;
2302 u32 pciPID = 0;
2303 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2304 if (UxxxStatus)
2305 return UxxxStatus;
2306 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
2307 if (UxxxStatus)
2308 return UxxxStatus;
2309 msleep(750);
2310 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
2311 if (UxxxStatus) 2522 if (UxxxStatus)
2312 return UxxxStatus; 2523 return UxxxStatus;
2313 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500); 2524 reg = 16;
2525 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2526 0xFFFFFFFF);
2314 if (UxxxStatus) 2527 if (UxxxStatus)
2315 return UxxxStatus; 2528 return UxxxStatus;
2316 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2529 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2530 &pcidata);
2317 if (UxxxStatus) 2531 if (UxxxStatus)
2318 return UxxxStatus; 2532 return UxxxStatus;
2319 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000); 2533 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2534 0xF0000000);
2320 if (UxxxStatus) 2535 if (UxxxStatus)
2321 return UxxxStatus; 2536 return UxxxStatus;
2322 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000); 2537 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2538 &pcidata);
2323 if (UxxxStatus) 2539 if (UxxxStatus)
2324 return UxxxStatus; 2540 return UxxxStatus;
2325 msleep(250); 2541 reg = 12;
2326 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000); 2542 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2543 &latence_timer);
2327 if (UxxxStatus) 2544 if (UxxxStatus)
2328 return UxxxStatus; 2545 return UxxxStatus;
2329 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2546 latence_timer &= 0xFFFF00FF;
2547 latence_timer |= 0x00001600;
2548 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2549 latence_timer);
2330 if (UxxxStatus) 2550 if (UxxxStatus)
2331 return UxxxStatus; 2551 return UxxxStatus;
2332 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800); 2552 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2553 &pcidata);
2333 if (UxxxStatus) 2554 if (UxxxStatus)
2334 return UxxxStatus; 2555 return UxxxStatus;
2335 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2556 reg = 4;
2557 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2558 0x06);
2336 if (UxxxStatus) 2559 if (UxxxStatus)
2337 return UxxxStatus; 2560 return UxxxStatus;
2338 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg); 2561 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2562 &pcidata);
2339 if (UxxxStatus) 2563 if (UxxxStatus)
2340 return UxxxStatus; 2564 return UxxxStatus;
2341 msleep(1000); 2565 for (reg = 0; reg <= 0x54; reg += 4) {
2342 for (fn = 0; (fn < 4) && (!foundOHCI); fn++) { 2566 UxxxStatus = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2343 activePCIfn = fn << 8;
2344 ftdi->function = fn + 1;
2345 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2346 &pcidata);
2347 if (UxxxStatus) 2567 if (UxxxStatus)
2348 return UxxxStatus; 2568 return UxxxStatus;
2349 pciVID = pcidata & 0xFFFF;
2350 pciPID = (pcidata >> 16) & 0xFFFF;
2351 if ((pciVID == 0x1045) && (pciPID == 0xc861)) {
2352 foundOHCI = 1;
2353 } else if ((pciVID == 0x1033) && (pciPID == 0x0035)) {
2354 foundOHCI = 1;
2355 } else if ((pciVID == 0x10b9) && (pciPID == 0x5237)) {
2356 foundOHCI = 1;
2357 } else if ((pciVID == 0x11c1) && (pciPID == 0x5802)) {
2358 foundOHCI = 1;
2359 } else if ((pciVID == 0x11AB) && (pciPID == 0x1FA6)) {
2360 }
2361 }
2362 if (foundOHCI == 0) {
2363 return -ENXIO;
2364 } 2569 }
2365 ftdi->platform_data.vendor = pciVID; 2570 return 0;
2366 ftdi->platform_data.device = pciPID; 2571}
2572
2573static int ftdi_elan_close_controller(struct usb_ftdi *ftdi, int fn)
2574{
2575 u32 latence_timer;
2576 int UxxxStatus;
2577 u32 pcidata;
2578 int reg = 0;
2579 int activePCIfn = fn << 8;
2367 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800); 2580 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x2800);
2368 if (UxxxStatus) 2581 if (UxxxStatus)
2369 return UxxxStatus; 2582 return UxxxStatus;
@@ -2377,7 +2590,7 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2377 if (UxxxStatus) 2590 if (UxxxStatus)
2378 return UxxxStatus; 2591 return UxxxStatus;
2379 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0, 2592 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0,
2380 0xF0000000); 2593 0x00000000);
2381 if (UxxxStatus) 2594 if (UxxxStatus)
2382 return UxxxStatus; 2595 return UxxxStatus;
2383 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, 2596 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
@@ -2401,7 +2614,7 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2401 return UxxxStatus; 2614 return UxxxStatus;
2402 reg = 4; 2615 reg = 4;
2403 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00, 2616 UxxxStatus = ftdi_elan_write_config(ftdi, activePCIfn | reg, 0x00,
2404 0x06); 2617 0x00);
2405 if (UxxxStatus) 2618 if (UxxxStatus)
2406 return UxxxStatus; 2619 return UxxxStatus;
2407 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0, 2620 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
@@ -2411,159 +2624,139 @@ static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2411 return 0; 2624 return 0;
2412} 2625}
2413 2626
2627static int ftdi_elan_found_controller(struct usb_ftdi *ftdi, int fn, int quirk)
2628{
2629 int result;
2630 int UxxxStatus;
2631 UxxxStatus = ftdi_elan_setup_controller(ftdi, fn);
2632 if (UxxxStatus)
2633 return UxxxStatus;
2634 result = ftdi_elan_check_controller(ftdi, quirk);
2635 UxxxStatus = ftdi_elan_close_controller(ftdi, fn);
2636 if (UxxxStatus)
2637 return UxxxStatus;
2638 return result;
2639}
2640
2641static int ftdi_elan_enumeratePCI(struct usb_ftdi *ftdi)
2642{
2643 u32 controlreg;
2644 u8 sensebits;
2645 int UxxxStatus;
2646 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2647 if (UxxxStatus)
2648 return UxxxStatus;
2649 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000000L);
2650 if (UxxxStatus)
2651 return UxxxStatus;
2652 msleep(750);
2653 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x100);
2654 if (UxxxStatus)
2655 return UxxxStatus;
2656 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x00000200L | 0x500);
2657 if (UxxxStatus)
2658 return UxxxStatus;
2659 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2660 if (UxxxStatus)
2661 return UxxxStatus;
2662 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020CL | 0x000);
2663 if (UxxxStatus)
2664 return UxxxStatus;
2665 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020DL | 0x000);
2666 if (UxxxStatus)
2667 return UxxxStatus;
2668 msleep(250);
2669 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000020FL | 0x000);
2670 if (UxxxStatus)
2671 return UxxxStatus;
2672 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2673 if (UxxxStatus)
2674 return UxxxStatus;
2675 UxxxStatus = ftdi_elan_write_reg(ftdi, 0x0000025FL | 0x800);
2676 if (UxxxStatus)
2677 return UxxxStatus;
2678 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2679 if (UxxxStatus)
2680 return UxxxStatus;
2681 UxxxStatus = ftdi_elan_read_reg(ftdi, &controlreg);
2682 if (UxxxStatus)
2683 return UxxxStatus;
2684 msleep(1000);
2685 sensebits = (controlreg >> 16) & 0x000F;
2686 if (0x0D == sensebits)
2687 return 0;
2688 else
2689 return - ENXIO;
2690}
2691
2414static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi) 2692static int ftdi_elan_setupOHCI(struct usb_ftdi *ftdi)
2415{ 2693{
2694 int UxxxStatus;
2416 u32 pcidata; 2695 u32 pcidata;
2417 int U132Status; 2696 int reg = 0;
2418 int reg; 2697 u8 fn;
2419 int reset_repeat = 0; 2698 int activePCIfn = 0;
2420 do_reset:reg = 8; 2699 int max_devices = 0;
2421 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x01); 2700 int controllers = 0;
2422 if (U132Status) 2701 int unrecognized = 0;
2423 return U132Status; 2702 ftdi->function = 0;
2424 reset_check:{ 2703 for (fn = 0; (fn < 4); fn++) {
2425 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); 2704 u32 pciVID = 0;
2426 if (U132Status) 2705 u32 pciPID = 0;
2427 return U132Status; 2706 int devices = 0;
2428 if (pcidata & 1) { 2707 activePCIfn = fn << 8;
2429 msleep(500); 2708 UxxxStatus = ftdi_elan_read_config(ftdi, activePCIfn | reg, 0,
2430 if (reset_repeat++ > 100) { 2709 &pcidata);
2431 reset_repeat = 0; 2710 if (UxxxStatus)
2432 goto do_reset; 2711 return UxxxStatus;
2433 } else 2712 pciVID = pcidata & 0xFFFF;
2434 goto reset_check; 2713 pciPID = (pcidata >> 16) & 0xFFFF;
2714 if ((pciVID == PCI_VENDOR_ID_OPTI) && (pciPID == 0xc861)) {
2715 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2716 controllers += 1;
2717 } else if ((pciVID == PCI_VENDOR_ID_NEC) && (pciPID == 0x0035))
2718 {
2719 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2720 controllers += 1;
2721 } else if ((pciVID == PCI_VENDOR_ID_AL) && (pciPID == 0x5237)) {
2722 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2723 controllers += 1;
2724 } else if ((pciVID == PCI_VENDOR_ID_ATT) && (pciPID == 0x5802))
2725 {
2726 devices = ftdi_elan_found_controller(ftdi, fn, 0);
2727 controllers += 1;
2728 } else if (pciVID == PCI_VENDOR_ID_AMD && pciPID == 0x740c) {
2729 devices = ftdi_elan_found_controller(ftdi, fn,
2730 OHCI_QUIRK_AMD756);
2731 controllers += 1;
2732 } else if (pciVID == PCI_VENDOR_ID_COMPAQ && pciPID == 0xa0f8) {
2733 devices = ftdi_elan_found_controller(ftdi, fn,
2734 OHCI_QUIRK_ZFMICRO);
2735 controllers += 1;
2736 } else if (0 == pcidata) {
2737 } else
2738 unrecognized += 1;
2739 if (devices > max_devices) {
2740 max_devices = devices;
2741 ftdi->function = fn + 1;
2742 ftdi->platform_data.vendor = pciVID;
2743 ftdi->platform_data.device = pciPID;
2435 } 2744 }
2436 } 2745 }
2437 goto dump_regs; 2746 if (ftdi->function > 0) {
2438 msleep(500); 2747 UxxxStatus = ftdi_elan_setup_controller(ftdi,
2439 reg = 0x28; 2748 ftdi->function - 1);
2440 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x11000000); 2749 if (UxxxStatus)
2441 if (U132Status) 2750 return UxxxStatus;
2442 return U132Status; 2751 return 0;
2443 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata); 2752 } else if (controllers > 0) {
2444 if (U132Status) 2753 return -ENXIO;
2445 return U132Status; 2754 } else if (unrecognized > 0) {
2446 reg = 0x40; 2755 return -ENXIO;
2447 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf); 2756 } else {
2448 if (U132Status) 2757 ftdi->enumerated = 0;
2449 return U132Status; 2758 return -ENXIO;
2450 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2451 if (U132Status)
2452 return U132Status;
2453 reg = 0x34;
2454 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x2edf2edf);
2455 if (U132Status)
2456 return U132Status;
2457 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2458 if (U132Status)
2459 return U132Status;
2460 reg = 4;
2461 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0xA0);
2462 if (U132Status)
2463 return U132Status;
2464 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2465 if (U132Status)
2466 return U132Status;
2467 msleep(250);
2468 reg = 8;
2469 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x0e, 0x04);
2470 if (U132Status)
2471 return U132Status;
2472 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2473 if (U132Status)
2474 return U132Status;
2475 reg = 0x28;
2476 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2477 if (U132Status)
2478 return U132Status;
2479 reg = 8;
2480 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2481 if (U132Status)
2482 return U132Status;
2483 reg = 0x48;
2484 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x00001200);
2485 if (U132Status)
2486 return U132Status;
2487 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2488 if (U132Status)
2489 return U132Status;
2490 reg = 0x54;
2491 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2492 if (U132Status)
2493 return U132Status;
2494 reg = 0x58;
2495 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2496 if (U132Status)
2497 return U132Status;
2498 reg = 0x34;
2499 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x28002edf);
2500 if (U132Status)
2501 return U132Status;
2502 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2503 if (U132Status)
2504 return U132Status;
2505 msleep(100);
2506 reg = 0x50;
2507 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10000);
2508 if (U132Status)
2509 return U132Status;
2510 reg = 0x54;
2511 power_check:U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2512 if (U132Status)
2513 return U132Status;
2514 if (!(pcidata & 1)) {
2515 msleep(500);
2516 goto power_check;
2517 }
2518 msleep(3000);
2519 reg = 0x54;
2520 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2521 if (U132Status)
2522 return U132Status;
2523 reg = 0x58;
2524 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2525 if (U132Status)
2526 return U132Status;
2527 reg = 0x54;
2528 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2529 if (U132Status)
2530 return U132Status;
2531 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2532 if (U132Status)
2533 return U132Status;
2534 reg = 0x54;
2535 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x10);
2536 if (U132Status)
2537 return U132Status;
2538 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2539 if (U132Status)
2540 return U132Status;
2541 msleep(750);
2542 reg = 0x54;
2543 if (0) {
2544 U132Status = ftdi_elan_write_pcimem(ftdi, reg, 0x00, 0x02);
2545 if (U132Status)
2546 return U132Status;
2547 }
2548 if (0) {
2549 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2550 if (U132Status)
2551 return U132Status;
2552 }
2553 reg = 0x54;
2554 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2555 if (U132Status)
2556 return U132Status;
2557 reg = 0x58;
2558 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2559 if (U132Status)
2560 return U132Status;
2561 dump_regs:for (reg = 0; reg <= 0x54; reg += 4) {
2562 U132Status = ftdi_elan_read_pcimem(ftdi, reg, 0, &pcidata);
2563 if (U132Status)
2564 return U132Status;
2565 } 2759 }
2566 return 0;
2567} 2760}
2568 2761
2569 2762
@@ -2688,6 +2881,7 @@ static void ftdi_elan_disconnect(struct usb_interface *interface)
2688 platform_device_unregister(&ftdi->platform_dev); 2881 platform_device_unregister(&ftdi->platform_dev);
2689 ftdi->synchronized = 0; 2882 ftdi->synchronized = 0;
2690 ftdi->enumerated = 0; 2883 ftdi->enumerated = 0;
2884 ftdi->initialized = 0;
2691 ftdi->registered = 0; 2885 ftdi->registered = 0;
2692 } 2886 }
2693 flush_workqueue(status_queue); 2887 flush_workqueue(status_queue);
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index 7163f05c5b27..0d9de2f73930 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -282,6 +282,7 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
282 dev->dev = NULL; 282 dev->dev = NULL;
283 goto out; 283 goto out;
284 } 284 }
285 dev_set_drvdata(dev->dev, dev);
285 286
286 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1; 287 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
287 288
diff --git a/drivers/usb/misc/trancevibrator.c b/drivers/usb/misc/trancevibrator.c
index 33cd91d11eca..67e2fc20eeeb 100644
--- a/drivers/usb/misc/trancevibrator.c
+++ b/drivers/usb/misc/trancevibrator.c
@@ -120,8 +120,8 @@ static void tv_disconnect(struct usb_interface *interface)
120 struct trancevibrator *dev; 120 struct trancevibrator *dev;
121 121
122 dev = usb_get_intfdata (interface); 122 dev = usb_get_intfdata (interface);
123 usb_set_intfdata(interface, NULL);
124 device_remove_file(&interface->dev, &dev_attr_speed); 123 device_remove_file(&interface->dev, &dev_attr_speed);
124 usb_set_intfdata(interface, NULL);
125 usb_put_dev(dev->udev); 125 usb_put_dev(dev->udev);
126 kfree(dev); 126 kfree(dev);
127} 127}
diff --git a/drivers/usb/net/gl620a.c b/drivers/usb/net/gl620a.c
index a3242be21959..a6f0f4d934df 100644
--- a/drivers/usb/net/gl620a.c
+++ b/drivers/usb/net/gl620a.c
@@ -79,160 +79,6 @@ struct gl_header {
79 struct gl_packet packets; 79 struct gl_packet packets;
80}; 80};
81 81
82#ifdef GENELINK_ACK
83
84// FIXME: this code is incomplete, not debugged; it doesn't
85// handle interrupts correctly; it should use the generic
86// status IRQ code (which didn't exist back in 2001).
87
88struct gl_priv {
89 struct urb *irq_urb;
90 char irq_buf [INTERRUPT_BUFSIZE];
91};
92
93static inline int gl_control_write(struct usbnet *dev, u8 request, u16 value)
94{
95 int retval;
96
97 retval = usb_control_msg(dev->udev,
98 usb_sndctrlpipe(dev->udev, 0),
99 request,
100 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
101 value,
102 0, // index
103 0, // data buffer
104 0, // size
105 USB_CTRL_SET_TIMEOUT);
106 return retval;
107}
108
109static void gl_interrupt_complete(struct urb *urb)
110{
111 int status = urb->status;
112
113 switch (status) {
114 case 0:
115 /* success */
116 break;
117 case -ECONNRESET:
118 case -ENOENT:
119 case -ESHUTDOWN:
120 /* this urb is terminated, clean up */
121 dbg("%s - urb shutting down with status: %d",
122 __FUNCTION__, status);
123 return;
124 default:
125 dbg("%s - nonzero urb status received: %d",
126 __FUNCTION__, urb->status);
127 }
128
129 status = usb_submit_urb(urb, GFP_ATOMIC);
130 if (status)
131 err("%s - usb_submit_urb failed with result %d",
132 __FUNCTION__, status);
133}
134
135static int gl_interrupt_read(struct usbnet *dev)
136{
137 struct gl_priv *priv = dev->priv_data;
138 int retval;
139
140 // issue usb interrupt read
141 if (priv && priv->irq_urb) {
142 // submit urb
143 if ((retval = usb_submit_urb(priv->irq_urb, GFP_KERNEL)) != 0)
144 dbg("gl_interrupt_read: submit fail - %X...", retval);
145 else
146 dbg("gl_interrupt_read: submit success...");
147 }
148
149 return 0;
150}
151
152// check whether another side is connected
153static int genelink_check_connect(struct usbnet *dev)
154{
155 int retval;
156
157 dbg("genelink_check_connect...");
158
159 // detect whether another side is connected
160 if ((retval = gl_control_write(dev, GENELINK_CONNECT_WRITE, 0)) != 0) {
161 dbg("%s: genelink_check_connect write fail - %X",
162 dev->net->name, retval);
163 return retval;
164 }
165
166 // usb interrupt read to ack another side
167 if ((retval = gl_interrupt_read(dev)) != 0) {
168 dbg("%s: genelink_check_connect read fail - %X",
169 dev->net->name, retval);
170 return retval;
171 }
172
173 dbg("%s: genelink_check_connect read success", dev->net->name);
174 return 0;
175}
176
177// allocate and initialize the private data for genelink
178static int genelink_init(struct usbnet *dev)
179{
180 struct gl_priv *priv;
181
182 // allocate the private data structure
183 if ((priv = kmalloc(sizeof *priv, GFP_KERNEL)) == 0) {
184 dbg("%s: cannot allocate private data per device",
185 dev->net->name);
186 return -ENOMEM;
187 }
188
189 // allocate irq urb
190 if ((priv->irq_urb = usb_alloc_urb(0, GFP_KERNEL)) == 0) {
191 dbg("%s: cannot allocate private irq urb per device",
192 dev->net->name);
193 kfree(priv);
194 return -ENOMEM;
195 }
196
197 // fill irq urb
198 usb_fill_int_urb(priv->irq_urb, dev->udev,
199 usb_rcvintpipe(dev->udev, GENELINK_INTERRUPT_PIPE),
200 priv->irq_buf, INTERRUPT_BUFSIZE,
201 gl_interrupt_complete, 0,
202 GENELINK_INTERRUPT_INTERVAL);
203
204 // set private data pointer
205 dev->priv_data = priv;
206
207 return 0;
208}
209
210// release the private data
211static int genelink_free(struct usbnet *dev)
212{
213 struct gl_priv *priv = dev->priv_data;
214
215 if (!priv)
216 return 0;
217
218// FIXME: can't cancel here; it's synchronous, and
219// should have happened earlier in any case (interrupt
220// handling needs to be generic)
221
222 // cancel irq urb first
223 usb_kill_urb(priv->irq_urb);
224
225 // free irq urb
226 usb_free_urb(priv->irq_urb);
227
228 // free the private data structure
229 kfree(priv);
230
231 return 0;
232}
233
234#endif
235
236static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 82static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
237{ 83{
238 struct gl_header *header; 84 struct gl_header *header;
diff --git a/drivers/usb/net/rtl8150.c b/drivers/usb/net/rtl8150.c
index c54235f73cb6..e0eecda78ec1 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/usb/net/rtl8150.c
@@ -124,10 +124,11 @@
124#define RX_URB_FAIL 3 124#define RX_URB_FAIL 3
125 125
126/* Define these values to match your device */ 126/* Define these values to match your device */
127#define VENDOR_ID_REALTEK 0x0bda 127#define VENDOR_ID_REALTEK 0x0bda
128#define VENDOR_ID_MELCO 0x0411 128#define VENDOR_ID_MELCO 0x0411
129#define VENDOR_ID_MICRONET 0x3980 129#define VENDOR_ID_MICRONET 0x3980
130#define VENDOR_ID_LONGSHINE 0x07b8 130#define VENDOR_ID_LONGSHINE 0x07b8
131#define VENDOR_ID_OQO 0x1557
131#define VENDOR_ID_ZYXEL 0x0586 132#define VENDOR_ID_ZYXEL 0x0586
132 133
133#define PRODUCT_ID_RTL8150 0x8150 134#define PRODUCT_ID_RTL8150 0x8150
@@ -144,6 +145,7 @@ static struct usb_device_id rtl8150_table[] = {
144 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)}, 145 {USB_DEVICE(VENDOR_ID_MELCO, PRODUCT_ID_LUAKTX)},
145 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)}, 146 {USB_DEVICE(VENDOR_ID_MICRONET, PRODUCT_ID_SP128AR)},
146 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)}, 147 {USB_DEVICE(VENDOR_ID_LONGSHINE, PRODUCT_ID_LCS8138TX)},
148 {USB_DEVICE(VENDOR_ID_OQO, PRODUCT_ID_RTL8150)},
147 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)}, 149 {USB_DEVICE(VENDOR_ID_ZYXEL, PRODUCT_ID_PRESTIGE)},
148 {} 150 {}
149}; 151};
diff --git a/drivers/usb/serial/airprime.c b/drivers/usb/serial/airprime.c
index 96c73726d74a..f2ca76a9cbac 100644
--- a/drivers/usb/serial/airprime.c
+++ b/drivers/usb/serial/airprime.c
@@ -19,8 +19,11 @@
19static struct usb_device_id id_table [] = { 19static struct usb_device_id id_table [] = {
20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */ 20 { USB_DEVICE(0x0c88, 0x17da) }, /* Kyocera Wireless KPC650/Passport */
21 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */ 21 { USB_DEVICE(0x1410, 0x1110) }, /* Novatel Wireless Merlin CDMA */
22 { USB_DEVICE(0x1410, 0x1130) }, /* Novatel Wireless S720 CDMA/EV-DO */
23 { USB_DEVICE(0x1410, 0x2110) }, /* Novatel Wireless U720 CDMA/EV-DO */
22 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */ 24 { USB_DEVICE(0x1410, 0x1430) }, /* Novatel Merlin XU870 HSDPA/3G */
23 { USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */ 25 { USB_DEVICE(0x1410, 0x1100) }, /* ExpressCard34 Qualcomm 3G CDMA */
26 { USB_DEVICE(0x413c, 0x8115) }, /* Dell Wireless HSDPA 5500 */
24 { }, 27 { },
25}; 28};
26MODULE_DEVICE_TABLE(usb, id_table); 29MODULE_DEVICE_TABLE(usb, id_table);
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 2f9b7ac32663..7ebaffd6ed86 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -69,6 +69,7 @@ static struct usb_device_id id_table [] = {
69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 69 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 70 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 71 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
72 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
72 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 73 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
73 { } /* Terminating Entry */ 74 { } /* Terminating Entry */
74}; 75};
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 45cdf9bc43b2..6bc1f404e186 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -962,21 +962,6 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
962 cypress_set_termios(port, &priv->tmp_termios); 962 cypress_set_termios(port, &priv->tmp_termios);
963 return (0); 963 return (0);
964 break; 964 break;
965 /* these are called when setting baud rate from gpsd */
966 case TCGETS:
967 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct termios))) {
968 return -EFAULT;
969 }
970 return (0);
971 break;
972 case TCSETS:
973 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct termios))) {
974 return -EFAULT;
975 }
976 /* here we need to call cypress_set_termios to invoke the new settings */
977 cypress_set_termios(port, &priv->tmp_termios);
978 return (0);
979 break;
980 /* This code comes from drivers/char/serial.c and ftdi_sio.c */ 965 /* This code comes from drivers/char/serial.c and ftdi_sio.c */
981 case TIOCMIWAIT: 966 case TIOCMIWAIT:
982 while (priv != NULL) { 967 while (priv != NULL) {
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 41b0ad2d56ac..6986e756f7c0 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -452,6 +452,7 @@ static struct usb_device_id id_table_combined [] = {
452 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) }, 452 { USB_DEVICE(FTDI_VID, LINX_FUTURE_2_PID) },
453 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) }, 453 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU20_0_PID) },
454 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) }, 454 { USB_DEVICE(FTDI_VID, FTDI_CCSICDU40_1_PID) },
455 { USB_DEVICE(FTDI_VID, FTDI_CCSMACHX_2_PID) },
455 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) }, 456 { USB_DEVICE(FTDI_VID, INSIDE_ACCESSO) },
456 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) }, 457 { USB_DEVICE(INTREPID_VID, INTREPID_VALUECAN_PID) },
457 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) }, 458 { USB_DEVICE(INTREPID_VID, INTREPID_NEOVI_PID) },
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index bae117d359af..40dd394de58d 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -312,8 +312,9 @@
312 312
313/* CCS Inc. ICDU/ICDU40 product ID - the FT232BM is used in an in-circuit-debugger */ 313/* CCS Inc. ICDU/ICDU40 product ID - the FT232BM is used in an in-circuit-debugger */
314/* unit for PIC16's/PIC18's */ 314/* unit for PIC16's/PIC18's */
315#define FTDI_CCSICDU20_0_PID 0xF9D0 315#define FTDI_CCSICDU20_0_PID 0xF9D0
316#define FTDI_CCSICDU40_1_PID 0xF9D1 316#define FTDI_CCSICDU40_1_PID 0xF9D1
317#define FTDI_CCSMACHX_2_PID 0xF9D2
317 318
318/* Inside Accesso contactless reader (http://www.insidefr.com) */ 319/* Inside Accesso contactless reader (http://www.insidefr.com) */
319#define INSIDE_ACCESSO 0xFAD0 320#define INSIDE_ACCESSO 0xFAD0
diff --git a/drivers/usb/serial/funsoft.c b/drivers/usb/serial/funsoft.c
index 77b977206a8c..d3be9214c7c1 100644
--- a/drivers/usb/serial/funsoft.c
+++ b/drivers/usb/serial/funsoft.c
@@ -14,6 +14,9 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/serial.h> 16#include <linux/usb/serial.h>
17#include <asm/uaccess.h>
18
19static int debug;
17 20
18static struct usb_device_id id_table [] = { 21static struct usb_device_id id_table [] = {
19 { USB_DEVICE(0x1404, 0xcddc) }, 22 { USB_DEVICE(0x1404, 0xcddc) },
@@ -21,6 +24,26 @@ static struct usb_device_id id_table [] = {
21}; 24};
22MODULE_DEVICE_TABLE(usb, id_table); 25MODULE_DEVICE_TABLE(usb, id_table);
23 26
27static int funsoft_ioctl(struct usb_serial_port *port, struct file *file,
28 unsigned int cmd, unsigned long arg)
29{
30 struct termios t;
31
32 dbg("%s - port %d, cmd 0x%04x", __FUNCTION__, port->number, cmd);
33
34 if (cmd == TCSETSF) {
35 if (user_termios_to_kernel_termios(&t, (void __user *)arg))
36 return -EFAULT;
37
38 dbg("%s - iflag:%x oflag:%x cflag:%x lflag:%x", __FUNCTION__,
39 t.c_iflag, t.c_oflag, t.c_cflag, t.c_lflag);
40
41 if (!(t.c_lflag & ICANON))
42 return -EINVAL;
43 }
44 return -ENOIOCTLCMD;
45}
46
24static struct usb_driver funsoft_driver = { 47static struct usb_driver funsoft_driver = {
25 .name = "funsoft", 48 .name = "funsoft",
26 .probe = usb_serial_probe, 49 .probe = usb_serial_probe,
@@ -39,6 +62,7 @@ static struct usb_serial_driver funsoft_device = {
39 .num_bulk_in = NUM_DONT_CARE, 62 .num_bulk_in = NUM_DONT_CARE,
40 .num_bulk_out = NUM_DONT_CARE, 63 .num_bulk_out = NUM_DONT_CARE,
41 .num_ports = 1, 64 .num_ports = 1,
65 .ioctl = funsoft_ioctl,
42}; 66};
43 67
44static int __init funsoft_init(void) 68static int __init funsoft_init(void)
@@ -63,3 +87,6 @@ static void __exit funsoft_exit(void)
63module_init(funsoft_init); 87module_init(funsoft_init);
64module_exit(funsoft_exit); 88module_exit(funsoft_exit);
65MODULE_LICENSE("GPL"); 89MODULE_LICENSE("GPL");
90
91module_param(debug, bool, S_IRUGO | S_IWUSR);
92MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 73d755df4840..5c4b06a99ac0 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -87,10 +87,6 @@ static int klsi_105_write_room (struct usb_serial_port *port);
87static void klsi_105_read_bulk_callback (struct urb *urb); 87static void klsi_105_read_bulk_callback (struct urb *urb);
88static void klsi_105_set_termios (struct usb_serial_port *port, 88static void klsi_105_set_termios (struct usb_serial_port *port,
89 struct ktermios *old); 89 struct ktermios *old);
90static int klsi_105_ioctl (struct usb_serial_port *port,
91 struct file * file,
92 unsigned int cmd,
93 unsigned long arg);
94static void klsi_105_throttle (struct usb_serial_port *port); 90static void klsi_105_throttle (struct usb_serial_port *port);
95static void klsi_105_unthrottle (struct usb_serial_port *port); 91static void klsi_105_unthrottle (struct usb_serial_port *port);
96/* 92/*
@@ -140,7 +136,6 @@ static struct usb_serial_driver kl5kusb105d_device = {
140 .chars_in_buffer = klsi_105_chars_in_buffer, 136 .chars_in_buffer = klsi_105_chars_in_buffer,
141 .write_room = klsi_105_write_room, 137 .write_room = klsi_105_write_room,
142 .read_bulk_callback =klsi_105_read_bulk_callback, 138 .read_bulk_callback =klsi_105_read_bulk_callback,
143 .ioctl = klsi_105_ioctl,
144 .set_termios = klsi_105_set_termios, 139 .set_termios = klsi_105_set_termios,
145 /*.break_ctl = klsi_105_break_ctl,*/ 140 /*.break_ctl = klsi_105_break_ctl,*/
146 .tiocmget = klsi_105_tiocmget, 141 .tiocmget = klsi_105_tiocmget,
@@ -899,69 +894,6 @@ static int klsi_105_tiocmset (struct usb_serial_port *port, struct file *file,
899*/ 894*/
900 return retval; 895 return retval;
901} 896}
902
903static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
904 unsigned int cmd, unsigned long arg)
905{
906 struct klsi_105_private *priv = usb_get_serial_port_data(port);
907 void __user *user_arg = (void __user *)arg;
908
909 dbg("%scmd=0x%x", __FUNCTION__, cmd);
910
911 /* Based on code from acm.c and others */
912 switch (cmd) {
913 case TIOCMIWAIT:
914 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
915 /* TODO */
916 dbg("%s - TIOCMIWAIT not handled", __FUNCTION__);
917 return -ENOIOCTLCMD;
918 case TIOCGICOUNT:
919 /* return count of modemline transitions */
920 /* TODO */
921 dbg("%s - TIOCGICOUNT not handled", __FUNCTION__);
922 return -ENOIOCTLCMD;
923 case TCGETS:
924 /* return current info to caller */
925 dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
926
927 if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct termios)))
928 return -EFAULT;
929
930 if (kernel_termios_to_user_termios((struct termios __user *)arg,
931 &priv->termios))
932 return -EFAULT;
933 return 0;
934 case TCSETS:
935 /* set port termios to the one given by the user */
936 dbg("%s - TCSETS not handled", __FUNCTION__);
937
938 if (!access_ok(VERIFY_READ, user_arg, sizeof(struct termios)))
939 return -EFAULT;
940
941 if (user_termios_to_kernel_termios(&priv->termios,
942 (struct termios __user *)arg))
943 return -EFAULT;
944 klsi_105_set_termios(port, &priv->termios);
945 return 0;
946 case TCSETSW: {
947 /* set port termios and try to wait for completion of last
948 * write operation */
949 /* We guess here. If there are not too many write urbs
950 * outstanding, we lie. */
951 /* what is the right way to wait here? schedule() ? */
952 /*
953 while (klsi_105_chars_in_buffer(port) > (NUM_URBS / 4 ) * URB_TRANSFER_BUFFER_SIZE)
954 schedule();
955 */
956 return -ENOIOCTLCMD;
957 }
958 default:
959 dbg("%s: arg not supported - 0x%04x", __FUNCTION__,cmd);
960 return(-ENOIOCTLCMD);
961 break;
962 }
963 return 0;
964} /* klsi_105_ioctl */
965 897
966static void klsi_105_throttle (struct usb_serial_port *port) 898static void klsi_105_throttle (struct usb_serial_port *port)
967{ 899{
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 8cc728a49e41..83f661403ba1 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -2460,12 +2460,6 @@ static int mos7840_ioctl(struct usb_serial_port *port, struct file *file,
2460 tty_ldisc_deref(ld); 2460 tty_ldisc_deref(ld);
2461 return 0; 2461 return 0;
2462 2462
2463 case TCGETS:
2464 if (kernel_termios_to_user_termios
2465 ((struct termios __user *)argp, tty->termios))
2466 return -EFAULT;
2467 return 0;
2468
2469 case TIOCSERGETLSR: 2463 case TIOCSERGETLSR:
2470 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number); 2464 dbg("%s (%d) TIOCSERGETLSR", __FUNCTION__, port->number);
2471 return mos7840_get_lsr_info(mos7840_port, argp); 2465 return mos7840_get_lsr_info(mos7840_port, argp);
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 0ae4098718c3..819266b7e2f8 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -79,6 +79,7 @@ static int option_send_setup(struct usb_serial_port *port);
79#define OPTION_PRODUCT_COBRA 0x6500 79#define OPTION_PRODUCT_COBRA 0x6500
80#define OPTION_PRODUCT_COBRA2 0x6600 80#define OPTION_PRODUCT_COBRA2 0x6600
81#define HUAWEI_PRODUCT_E600 0x1001 81#define HUAWEI_PRODUCT_E600 0x1001
82#define HUAWEI_PRODUCT_E220 0x1003
82#define AUDIOVOX_PRODUCT_AIRCARD 0x0112 83#define AUDIOVOX_PRODUCT_AIRCARD 0x0112
83#define NOVATELWIRELESS_PRODUCT_U740 0x1400 84#define NOVATELWIRELESS_PRODUCT_U740 0x1400
84#define ANYDATA_PRODUCT_ID 0x6501 85#define ANYDATA_PRODUCT_ID 0x6501
@@ -90,6 +91,7 @@ static struct usb_device_id option_ids[] = {
90 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
91 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 92 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
92 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 93 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
94 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
93 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 95 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
94 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 96 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
95 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 97 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
@@ -103,6 +105,7 @@ static struct usb_device_id option_ids1[] = {
103 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) }, 105 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA) },
104 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) }, 106 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COBRA2) },
105 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) }, 107 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
108 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E220) },
106 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) }, 109 { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
107 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) }, 110 { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID,NOVATELWIRELESS_PRODUCT_U740) },
108 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) }, 111 { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ID) },
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index db8b26012c75..5fe7ff441a09 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -153,6 +153,13 @@ UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
153 US_SC_DEVICE, US_PR_DEVICE, NULL, 153 US_SC_DEVICE, US_PR_DEVICE, NULL,
154 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 154 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
155 155
156/* Reported by <honkkis@gmail.com> */
157UNUSUAL_DEV( 0x0421, 0x0433, 0x0100, 0x0100,
158 "Nokia",
159 "E70",
160 US_SC_DEVICE, US_PR_DEVICE, NULL,
161 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
162
156/* Reported by Jon Hart <Jon.Hart@web.de> */ 163/* Reported by Jon Hart <Jon.Hart@web.de> */
157UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100, 164UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
158 "Nokia", 165 "Nokia",
@@ -1328,6 +1335,15 @@ UNUSUAL_DEV( 0x1210, 0x0003, 0x0100, 0x0100,
1328 US_SC_DEVICE, US_PR_DEVICE, NULL, 1335 US_SC_DEVICE, US_PR_DEVICE, NULL,
1329 US_FL_IGNORE_RESIDUE ), 1336 US_FL_IGNORE_RESIDUE ),
1330 1337
1338/* This prevents the kernel from detecting the virtual cd-drive with the
1339 * Windows drivers. <johann.wilhelm@student.tugraz.at>
1340*/
1341UNUSUAL_DEV( 0x12d1, 0x1003, 0x0000, 0xffff,
1342 "HUAWEI",
1343 "E220 USB-UMTS Install",
1344 US_SC_DEVICE, US_PR_DEVICE, NULL,
1345 US_FL_IGNORE_DEVICE),
1346
1331/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */ 1347/* Reported by Vilius Bilinkevicius <vilisas AT xxx DOT lt) */
1332UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001, 1348UNUSUAL_DEV( 0x132b, 0x000b, 0x0001, 0x0001,
1333 "Minolta", 1349 "Minolta",
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 3feddf89d100..2e976ffcde0f 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1834,7 +1834,7 @@ static void aty128_bl_init(struct aty128fb_par *par)
1834 1834
1835 snprintf(name, sizeof(name), "aty128bl%d", info->node); 1835 snprintf(name, sizeof(name), "aty128bl%d", info->node);
1836 1836
1837 bd = backlight_device_register(name, par, &aty128_bl_data); 1837 bd = backlight_device_register(name, info->dev, par, &aty128_bl_data);
1838 if (IS_ERR(bd)) { 1838 if (IS_ERR(bd)) {
1839 info->bl_dev = NULL; 1839 info->bl_dev = NULL;
1840 printk(KERN_WARNING "aty128: Backlight registration failed\n"); 1840 printk(KERN_WARNING "aty128: Backlight registration failed\n");
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 09684d7a7ce9..f2ebdd880085 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2211,7 +2211,7 @@ static void aty_bl_init(struct atyfb_par *par)
2211 2211
2212 snprintf(name, sizeof(name), "atybl%d", info->node); 2212 snprintf(name, sizeof(name), "atybl%d", info->node);
2213 2213
2214 bd = backlight_device_register(name, par, &aty_bl_data); 2214 bd = backlight_device_register(name, info->dev, par, &aty_bl_data);
2215 if (IS_ERR(bd)) { 2215 if (IS_ERR(bd)) {
2216 info->bl_dev = NULL; 2216 info->bl_dev = NULL;
2217 printk(KERN_WARNING "aty: Backlight registration failed\n"); 2217 printk(KERN_WARNING "aty: Backlight registration failed\n");
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 585eb7b9e636..3abfd4a380cc 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -163,7 +163,7 @@ void radeonfb_bl_init(struct radeonfb_info *rinfo)
163 163
164 snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node); 164 snprintf(name, sizeof(name), "radeonbl%d", rinfo->info->node);
165 165
166 bd = backlight_device_register(name, pdata, &radeon_bl_data); 166 bd = backlight_device_register(name, rinfo->info->dev, pdata, &radeon_bl_data);
167 if (IS_ERR(bd)) { 167 if (IS_ERR(bd)) {
168 rinfo->info->bl_dev = NULL; 168 rinfo->info->bl_dev = NULL;
169 printk("radeonfb: Backlight registration failed\n"); 169 printk("radeonfb: Backlight registration failed\n");
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index db8c191b1201..9601bfe309ac 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -216,8 +216,10 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
216 * Creates and registers new backlight class_device. Returns either an 216 * Creates and registers new backlight class_device. Returns either an
217 * ERR_PTR() or a pointer to the newly allocated device. 217 * ERR_PTR() or a pointer to the newly allocated device.
218 */ 218 */
219struct backlight_device *backlight_device_register(const char *name, void *devdata, 219struct backlight_device *backlight_device_register(const char *name,
220 struct backlight_properties *bp) 220 struct device *dev,
221 void *devdata,
222 struct backlight_properties *bp)
221{ 223{
222 int i, rc; 224 int i, rc;
223 struct backlight_device *new_bd; 225 struct backlight_device *new_bd;
@@ -232,6 +234,7 @@ struct backlight_device *backlight_device_register(const char *name, void *devda
232 new_bd->props = bp; 234 new_bd->props = bp;
233 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev)); 235 memset(&new_bd->class_dev, 0, sizeof(new_bd->class_dev));
234 new_bd->class_dev.class = &backlight_class; 236 new_bd->class_dev.class = &backlight_class;
237 new_bd->class_dev.dev = dev;
235 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN); 238 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
236 class_set_devdata(&new_bd->class_dev, devdata); 239 class_set_devdata(&new_bd->class_dev, devdata);
237 240
diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
index 3adf6ab0768f..23a6bcc3e3ce 100644
--- a/drivers/video/gxt4500.c
+++ b/drivers/video/gxt4500.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Frame buffer device for IBM GXT4500P display adaptor 2 * Frame buffer device for IBM GXT4500P and GXT6000P display adaptors
3 * 3 *
4 * Copyright (C) 2006 Paul Mackerras, IBM Corp. <paulus@samba.org> 4 * Copyright (C) 2006 Paul Mackerras, IBM Corp. <paulus@samba.org>
5 */ 5 */
@@ -11,8 +11,10 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/pci_ids.h> 12#include <linux/pci_ids.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/string.h>
14 15
15#define PCI_DEVICE_ID_IBM_GXT4500P 0x21c 16#define PCI_DEVICE_ID_IBM_GXT4500P 0x21c
17#define PCI_DEVICE_ID_IBM_GXT6000P 0x170
16 18
17/* GXT4500P registers */ 19/* GXT4500P registers */
18 20
@@ -94,6 +96,7 @@ static const unsigned char pixsize[] = {
94#define PLL_M 0x4040 96#define PLL_M 0x4040
95#define PLL_N 0x4044 97#define PLL_N 0x4044
96#define PLL_POSTDIV 0x4048 98#define PLL_POSTDIV 0x4048
99#define PLL_C 0x404c
97 100
98/* Hardware cursor */ 101/* Hardware cursor */
99#define CURSOR_X 0x4078 102#define CURSOR_X 0x4078
@@ -140,6 +143,7 @@ struct gxt4500_par {
140 int pixfmt; /* pixel format, see DFA_PIX_* values */ 143 int pixfmt; /* pixel format, see DFA_PIX_* values */
141 144
142 /* PLL parameters */ 145 /* PLL parameters */
146 int refclk_ps; /* ref clock period in picoseconds */
143 int pll_m; /* ref clock divisor */ 147 int pll_m; /* ref clock divisor */
144 int pll_n; /* VCO divisor */ 148 int pll_n; /* VCO divisor */
145 int pll_pd1; /* first post-divisor */ 149 int pll_pd1; /* first post-divisor */
@@ -166,6 +170,21 @@ static const struct fb_videomode defaultmode __devinitdata = {
166 .vmode = FB_VMODE_NONINTERLACED 170 .vmode = FB_VMODE_NONINTERLACED
167}; 171};
168 172
173/* List of supported cards */
174enum gxt_cards {
175 GXT4500P,
176 GXT6000P
177};
178
179/* Card-specific information */
180static const struct cardinfo {
181 int refclk_ps; /* period of PLL reference clock in ps */
182 const char *cardname;
183} cardinfo[] = {
184 [GXT4500P] = { .refclk_ps = 9259, .cardname = "IBM GXT4500P" },
185 [GXT6000P] = { .refclk_ps = 40000, .cardname = "IBM GXT6000P" },
186};
187
169/* 188/*
170 * The refclk and VCO dividers appear to use a linear feedback shift 189 * The refclk and VCO dividers appear to use a linear feedback shift
171 * register, which gets reloaded when it reaches a terminal value, at 190 * register, which gets reloaded when it reaches a terminal value, at
@@ -203,27 +222,16 @@ static const unsigned char ndivtab[] = {
203/* 130 */ 0x9e, 0x4f, 0x27, 0x93, 0xc9, 0xe4, 0x72, 0x39, 0x1c, 0x0e, 222/* 130 */ 0x9e, 0x4f, 0x27, 0x93, 0xc9, 0xe4, 0x72, 0x39, 0x1c, 0x0e,
204/* 140 */ 0x87, 0xc3, 0x61, 0x30, 0x18, 0x8c, 0xc6, 0x63, 0x31, 0x98, 223/* 140 */ 0x87, 0xc3, 0x61, 0x30, 0x18, 0x8c, 0xc6, 0x63, 0x31, 0x98,
205/* 150 */ 0xcc, 0xe6, 0x73, 0xb9, 0x5c, 0x2e, 0x97, 0x4b, 0xa5, 0xd2, 224/* 150 */ 0xcc, 0xe6, 0x73, 0xb9, 0x5c, 0x2e, 0x97, 0x4b, 0xa5, 0xd2,
206/* 160 */ 0x69, 0xb4, 0xda, 0xed, 0x76, 0xbb, 0x5d, 0xae, 0xd7, 0x6b, 225/* 160 */ 0x69,
207/* 170 */ 0xb5, 0x5a, 0xad, 0x56, 0xab, 0xd5, 0x6a, 0x35, 0x1a, 0x8d,
208/* 180 */ 0x46, 0x23, 0x11, 0x88, 0x44, 0x22, 0x91, 0xc8, 0x64, 0x32,
209/* 190 */ 0x19, 0x0c, 0x86, 0x43, 0x21, 0x10, 0x08, 0x04, 0x02, 0x81,
210/* 200 */ 0x40, 0xa0, 0xd0, 0x68, 0x34, 0x9a, 0xcd, 0x66, 0x33, 0x99,
211/* 210 */ 0x4c, 0xa6, 0x53, 0xa9, 0xd4, 0xea, 0x75, 0x3a, 0x9d, 0xce,
212/* 220 */ 0xe7, 0xf3, 0xf9, 0x7c, 0x3e, 0x1f, 0x8f, 0x47, 0xa3, 0x51,
213/* 230 */ 0xa8, 0x54, 0xaa, 0x55, 0x2a, 0x15, 0x0a, 0x05, 0x82, 0xc1,
214/* 240 */ 0x60, 0xb0, 0x58, 0xac, 0xd6, 0xeb, 0xf5, 0x7a, 0xbd, 0xde,
215/* 250 */ 0x6f, 0x37, 0x1b, 0x0d, 0x06, 0x03, 0x01,
216}; 226};
217 227
218#define REF_PERIOD_PS 9259 /* period of reference clock in ps */
219
220static int calc_pll(int period_ps, struct gxt4500_par *par) 228static int calc_pll(int period_ps, struct gxt4500_par *par)
221{ 229{
222 int m, n, pdiv1, pdiv2, postdiv; 230 int m, n, pdiv1, pdiv2, postdiv;
223 int pll_period, best_error, t; 231 int pll_period, best_error, t, intf;
224 232
225 /* only deal with range 1MHz - 400MHz */ 233 /* only deal with range 5MHz - 300MHz */
226 if (period_ps < 2500 || period_ps > 1000000) 234 if (period_ps < 3333 || period_ps > 200000)
227 return -1; 235 return -1;
228 236
229 best_error = 1000000; 237 best_error = 1000000;
@@ -231,14 +239,17 @@ static int calc_pll(int period_ps, struct gxt4500_par *par)
231 for (pdiv2 = 1; pdiv2 <= pdiv1; ++pdiv2) { 239 for (pdiv2 = 1; pdiv2 <= pdiv1; ++pdiv2) {
232 postdiv = pdiv1 * pdiv2; 240 postdiv = pdiv1 * pdiv2;
233 pll_period = (period_ps + postdiv - 1) / postdiv; 241 pll_period = (period_ps + postdiv - 1) / postdiv;
234 /* keep pll in range 500..1250 MHz */ 242 /* keep pll in range 350..600 MHz */
235 if (pll_period < 800 || pll_period > 2000) 243 if (pll_period < 1666 || pll_period > 2857)
236 continue; 244 continue;
237 for (m = 3; m <= 40; ++m) { 245 for (m = 1; m <= 64; ++m) {
238 n = REF_PERIOD_PS * m * postdiv / period_ps; 246 intf = m * par->refclk_ps;
239 if (n < 5 || n > 256) 247 if (intf > 500000)
248 break;
249 n = intf * postdiv / period_ps;
250 if (n < 3 || n > 160)
240 continue; 251 continue;
241 t = REF_PERIOD_PS * m * postdiv / n; 252 t = par->refclk_ps * m * postdiv / n;
242 t -= period_ps; 253 t -= period_ps;
243 if (t >= 0 && t < best_error) { 254 if (t >= 0 && t < best_error) {
244 par->pll_m = m; 255 par->pll_m = m;
@@ -257,7 +268,7 @@ static int calc_pll(int period_ps, struct gxt4500_par *par)
257 268
258static int calc_pixclock(struct gxt4500_par *par) 269static int calc_pixclock(struct gxt4500_par *par)
259{ 270{
260 return REF_PERIOD_PS * par->pll_m * par->pll_pd1 * par->pll_pd2 271 return par->refclk_ps * par->pll_m * par->pll_pd1 * par->pll_pd2
261 / par->pll_n; 272 / par->pll_n;
262} 273}
263 274
@@ -357,7 +368,7 @@ static int gxt4500_set_par(struct fb_info *info)
357 struct gxt4500_par *par = info->par; 368 struct gxt4500_par *par = info->par;
358 struct fb_var_screeninfo *var = &info->var; 369 struct fb_var_screeninfo *var = &info->var;
359 int err; 370 int err;
360 u32 ctrlreg; 371 u32 ctrlreg, tmp;
361 unsigned int dfa_ctl, pixfmt, stride; 372 unsigned int dfa_ctl, pixfmt, stride;
362 unsigned int wid_tiles, i; 373 unsigned int wid_tiles, i;
363 unsigned int prefetch_pix, htot; 374 unsigned int prefetch_pix, htot;
@@ -376,10 +387,25 @@ static int gxt4500_set_par(struct fb_info *info)
376 writereg(par, DTG_CONTROL, ctrlreg); 387 writereg(par, DTG_CONTROL, ctrlreg);
377 388
378 /* set PLL registers */ 389 /* set PLL registers */
390 tmp = readreg(par, PLL_C) & ~0x7f;
391 if (par->pll_n < 38)
392 tmp |= 0x29;
393 if (par->pll_n < 69)
394 tmp |= 0x35;
395 else if (par->pll_n < 100)
396 tmp |= 0x76;
397 else
398 tmp |= 0x7e;
399 writereg(par, PLL_C, tmp);
379 writereg(par, PLL_M, mdivtab[par->pll_m - 1]); 400 writereg(par, PLL_M, mdivtab[par->pll_m - 1]);
380 writereg(par, PLL_N, ndivtab[par->pll_n - 2]); 401 writereg(par, PLL_N, ndivtab[par->pll_n - 2]);
381 writereg(par, PLL_POSTDIV, 402 tmp = ((8 - par->pll_pd2) << 3) | (8 - par->pll_pd1);
382 ((8 - par->pll_pd1) << 3) | (8 - par->pll_pd2)); 403 if (par->pll_pd1 == 8 || par->pll_pd2 == 8) {
404 /* work around erratum */
405 writereg(par, PLL_POSTDIV, tmp | 0x9);
406 udelay(1);
407 }
408 writereg(par, PLL_POSTDIV, tmp);
383 msleep(20); 409 msleep(20);
384 410
385 /* turn off hardware cursor */ 411 /* turn off hardware cursor */
@@ -483,8 +509,8 @@ static int gxt4500_setcolreg(unsigned int reg, unsigned int red,
483 509
484 if (reg > 1023) 510 if (reg > 1023)
485 return 1; 511 return 1;
486 cmap_entry = ((transp & 0xff00) << 16) | ((blue & 0xff00) << 8) | 512 cmap_entry = ((transp & 0xff00) << 16) | ((red & 0xff00) << 8) |
487 (green & 0xff00) | (red >> 8); 513 (green & 0xff00) | (blue >> 8);
488 writereg(par, CMAP + reg * 4, cmap_entry); 514 writereg(par, CMAP + reg * 4, cmap_entry);
489 515
490 if (reg < 16 && par->pixfmt != DFA_PIX_8BIT) { 516 if (reg < 16 && par->pixfmt != DFA_PIX_8BIT) {
@@ -585,6 +611,7 @@ static int __devinit gxt4500_probe(struct pci_dev *pdev,
585 struct gxt4500_par *par; 611 struct gxt4500_par *par;
586 struct fb_info *info; 612 struct fb_info *info;
587 struct fb_var_screeninfo var; 613 struct fb_var_screeninfo var;
614 enum gxt_cards cardtype;
588 615
589 err = pci_enable_device(pdev); 616 err = pci_enable_device(pdev);
590 if (err) { 617 if (err) {
@@ -613,7 +640,11 @@ static int __devinit gxt4500_probe(struct pci_dev *pdev,
613 goto err_free_fb; 640 goto err_free_fb;
614 } 641 }
615 par = info->par; 642 par = info->par;
643 cardtype = ent->driver_data;
644 par->refclk_ps = cardinfo[cardtype].refclk_ps;
616 info->fix = gxt4500_fix; 645 info->fix = gxt4500_fix;
646 strlcpy(info->fix.id, cardinfo[cardtype].cardname,
647 sizeof(info->fix.id));
617 info->pseudo_palette = par->pseudo_palette; 648 info->pseudo_palette = par->pseudo_palette;
618 649
619 info->fix.mmio_start = reg_phys; 650 info->fix.mmio_start = reg_phys;
@@ -703,8 +734,10 @@ static void __devexit gxt4500_remove(struct pci_dev *pdev)
703 734
704/* supported chipsets */ 735/* supported chipsets */
705static const struct pci_device_id gxt4500_pci_tbl[] = { 736static const struct pci_device_id gxt4500_pci_tbl[] = {
706 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT4500P, 737 { PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT4500P),
707 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 738 .driver_data = GXT4500P },
739 { PCI_DEVICE(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT6000P),
740 .driver_data = GXT6000P },
708 { 0 } 741 { 0 }
709}; 742};
710 743
@@ -735,7 +768,7 @@ static void __exit gxt4500_exit(void)
735module_exit(gxt4500_exit); 768module_exit(gxt4500_exit);
736 769
737MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>"); 770MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
738MODULE_DESCRIPTION("FBDev driver for IBM GXT4500P"); 771MODULE_DESCRIPTION("FBDev driver for IBM GXT4500P/6000P");
739MODULE_LICENSE("GPL"); 772MODULE_LICENSE("GPL");
740module_param(mode_option, charp, 0); 773module_param(mode_option, charp, 0);
741MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\""); 774MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index 5b75ae4e9457..df934bd21899 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -141,7 +141,7 @@ void nvidia_bl_init(struct nvidia_par *par)
141 141
142 snprintf(name, sizeof(name), "nvidiabl%d", info->node); 142 snprintf(name, sizeof(name), "nvidiabl%d", info->node);
143 143
144 bd = backlight_device_register(name, par, &nvidia_bl_data); 144 bd = backlight_device_register(name, info->dev, par, &nvidia_bl_data);
145 if (IS_ERR(bd)) { 145 if (IS_ERR(bd)) {
146 info->bl_dev = NULL; 146 info->bl_dev = NULL;
147 printk(KERN_WARNING "nvidia: Backlight registration failed\n"); 147 printk(KERN_WARNING "nvidia: Backlight registration failed\n");
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 38eb0b69c2d7..b4947c810706 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -1216,7 +1216,7 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
1216 done: 1216 done:
1217 if (res_specified) { 1217 if (res_specified) {
1218 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres); 1218 dev_info(dev, "overriding resolution: %dx%d\n", xres, yres);
1219 inf->xres = xres; inf->yres = yres; 1219 inf->modes[0].xres = xres; inf->modes[0].yres = yres;
1220 } 1220 }
1221 if (bpp_specified) 1221 if (bpp_specified)
1222 switch (bpp) { 1222 switch (bpp) {
@@ -1225,48 +1225,48 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
1225 case 4: 1225 case 4:
1226 case 8: 1226 case 8:
1227 case 16: 1227 case 16:
1228 inf->bpp = bpp; 1228 inf->modes[0].bpp = bpp;
1229 dev_info(dev, "overriding bit depth: %d\n", bpp); 1229 dev_info(dev, "overriding bit depth: %d\n", bpp);
1230 break; 1230 break;
1231 default: 1231 default:
1232 dev_err(dev, "Depth %d is not valid\n", bpp); 1232 dev_err(dev, "Depth %d is not valid\n", bpp);
1233 } 1233 }
1234 } else if (!strncmp(this_opt, "pixclock:", 9)) { 1234 } else if (!strncmp(this_opt, "pixclock:", 9)) {
1235 inf->pixclock = simple_strtoul(this_opt+9, NULL, 0); 1235 inf->modes[0].pixclock = simple_strtoul(this_opt+9, NULL, 0);
1236 dev_info(dev, "override pixclock: %ld\n", inf->pixclock); 1236 dev_info(dev, "override pixclock: %ld\n", inf->modes[0].pixclock);
1237 } else if (!strncmp(this_opt, "left:", 5)) { 1237 } else if (!strncmp(this_opt, "left:", 5)) {
1238 inf->left_margin = simple_strtoul(this_opt+5, NULL, 0); 1238 inf->modes[0].left_margin = simple_strtoul(this_opt+5, NULL, 0);
1239 dev_info(dev, "override left: %u\n", inf->left_margin); 1239 dev_info(dev, "override left: %u\n", inf->modes[0].left_margin);
1240 } else if (!strncmp(this_opt, "right:", 6)) { 1240 } else if (!strncmp(this_opt, "right:", 6)) {
1241 inf->right_margin = simple_strtoul(this_opt+6, NULL, 0); 1241 inf->modes[0].right_margin = simple_strtoul(this_opt+6, NULL, 0);
1242 dev_info(dev, "override right: %u\n", inf->right_margin); 1242 dev_info(dev, "override right: %u\n", inf->modes[0].right_margin);
1243 } else if (!strncmp(this_opt, "upper:", 6)) { 1243 } else if (!strncmp(this_opt, "upper:", 6)) {
1244 inf->upper_margin = simple_strtoul(this_opt+6, NULL, 0); 1244 inf->modes[0].upper_margin = simple_strtoul(this_opt+6, NULL, 0);
1245 dev_info(dev, "override upper: %u\n", inf->upper_margin); 1245 dev_info(dev, "override upper: %u\n", inf->modes[0].upper_margin);
1246 } else if (!strncmp(this_opt, "lower:", 6)) { 1246 } else if (!strncmp(this_opt, "lower:", 6)) {
1247 inf->lower_margin = simple_strtoul(this_opt+6, NULL, 0); 1247 inf->modes[0].lower_margin = simple_strtoul(this_opt+6, NULL, 0);
1248 dev_info(dev, "override lower: %u\n", inf->lower_margin); 1248 dev_info(dev, "override lower: %u\n", inf->modes[0].lower_margin);
1249 } else if (!strncmp(this_opt, "hsynclen:", 9)) { 1249 } else if (!strncmp(this_opt, "hsynclen:", 9)) {
1250 inf->hsync_len = simple_strtoul(this_opt+9, NULL, 0); 1250 inf->modes[0].hsync_len = simple_strtoul(this_opt+9, NULL, 0);
1251 dev_info(dev, "override hsynclen: %u\n", inf->hsync_len); 1251 dev_info(dev, "override hsynclen: %u\n", inf->modes[0].hsync_len);
1252 } else if (!strncmp(this_opt, "vsynclen:", 9)) { 1252 } else if (!strncmp(this_opt, "vsynclen:", 9)) {
1253 inf->vsync_len = simple_strtoul(this_opt+9, NULL, 0); 1253 inf->modes[0].vsync_len = simple_strtoul(this_opt+9, NULL, 0);
1254 dev_info(dev, "override vsynclen: %u\n", inf->vsync_len); 1254 dev_info(dev, "override vsynclen: %u\n", inf->modes[0].vsync_len);
1255 } else if (!strncmp(this_opt, "hsync:", 6)) { 1255 } else if (!strncmp(this_opt, "hsync:", 6)) {
1256 if (simple_strtoul(this_opt+6, NULL, 0) == 0) { 1256 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1257 dev_info(dev, "override hsync: Active Low\n"); 1257 dev_info(dev, "override hsync: Active Low\n");
1258 inf->sync &= ~FB_SYNC_HOR_HIGH_ACT; 1258 inf->modes[0].sync &= ~FB_SYNC_HOR_HIGH_ACT;
1259 } else { 1259 } else {
1260 dev_info(dev, "override hsync: Active High\n"); 1260 dev_info(dev, "override hsync: Active High\n");
1261 inf->sync |= FB_SYNC_HOR_HIGH_ACT; 1261 inf->modes[0].sync |= FB_SYNC_HOR_HIGH_ACT;
1262 } 1262 }
1263 } else if (!strncmp(this_opt, "vsync:", 6)) { 1263 } else if (!strncmp(this_opt, "vsync:", 6)) {
1264 if (simple_strtoul(this_opt+6, NULL, 0) == 0) { 1264 if (simple_strtoul(this_opt+6, NULL, 0) == 0) {
1265 dev_info(dev, "override vsync: Active Low\n"); 1265 dev_info(dev, "override vsync: Active Low\n");
1266 inf->sync &= ~FB_SYNC_VERT_HIGH_ACT; 1266 inf->modes[0].sync &= ~FB_SYNC_VERT_HIGH_ACT;
1267 } else { 1267 } else {
1268 dev_info(dev, "override vsync: Active High\n"); 1268 dev_info(dev, "override vsync: Active High\n");
1269 inf->sync |= FB_SYNC_VERT_HIGH_ACT; 1269 inf->modes[0].sync |= FB_SYNC_VERT_HIGH_ACT;
1270 } 1270 }
1271 } else if (!strncmp(this_opt, "dpc:", 4)) { 1271 } else if (!strncmp(this_opt, "dpc:", 4)) {
1272 if (simple_strtoul(this_opt+4, NULL, 0) == 0) { 1272 if (simple_strtoul(this_opt+4, NULL, 0) == 0) {
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 345e8b1c1af8..1a13966b7d5b 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -384,7 +384,7 @@ static void riva_bl_init(struct riva_par *par)
384 384
385 snprintf(name, sizeof(name), "rivabl%d", info->node); 385 snprintf(name, sizeof(name), "rivabl%d", info->node);
386 386
387 bd = backlight_device_register(name, par, &riva_bl_data); 387 bd = backlight_device_register(name, info->dev, par, &riva_bl_data);
388 if (IS_ERR(bd)) { 388 if (IS_ERR(bd)) {
389 info->bl_dev = NULL; 389 info->bl_dev = NULL;
390 printk(KERN_WARNING "riva: Backlight registration failed\n"); 390 printk(KERN_WARNING "riva: Backlight registration failed\n");
diff --git a/drivers/video/sa1100fb.c b/drivers/video/sa1100fb.c
index cd10b18150b8..5d2a4a4b731c 100644
--- a/drivers/video/sa1100fb.c
+++ b/drivers/video/sa1100fb.c
@@ -1200,9 +1200,9 @@ static void set_ctrlr_state(struct sa1100fb_info *fbi, u_int state)
1200 * Our LCD controller task (which is called when we blank or unblank) 1200 * Our LCD controller task (which is called when we blank or unblank)
1201 * via keventd. 1201 * via keventd.
1202 */ 1202 */
1203static void sa1100fb_task(void *dummy) 1203static void sa1100fb_task(struct work_struct *w)
1204{ 1204{
1205 struct sa1100fb_info *fbi = dummy; 1205 struct sa1100fb_info *fbi = container_of(w, struct sa1100fb_info, task);
1206 u_int state = xchg(&fbi->task_state, -1); 1206 u_int state = xchg(&fbi->task_state, -1);
1207 1207
1208 set_ctrlr_state(fbi, state); 1208 set_ctrlr_state(fbi, state);
@@ -1444,7 +1444,7 @@ static struct sa1100fb_info * __init sa1100fb_init_fbinfo(struct device *dev)
1444 fbi->max_bpp / 8; 1444 fbi->max_bpp / 8;
1445 1445
1446 init_waitqueue_head(&fbi->ctrlr_wait); 1446 init_waitqueue_head(&fbi->ctrlr_wait);
1447 INIT_WORK(&fbi->task, sa1100fb_task, fbi); 1447 INIT_WORK(&fbi->task, sa1100fb_task);
1448 init_MUTEX(&fbi->ctrlr_sem); 1448 init_MUTEX(&fbi->ctrlr_sem);
1449 1449
1450 return fbi; 1450 return fbi;