aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/Kconfig23
-rw-r--r--drivers/acpi/battery.c673
-rw-r--r--drivers/acpi/bay.c19
-rw-r--r--drivers/acpi/bus.c4
-rw-r--r--drivers/acpi/dock.c127
-rw-r--r--drivers/acpi/ec.c247
-rw-r--r--drivers/acpi/event.c153
-rw-r--r--drivers/acpi/events/evgpeblk.c4
-rw-r--r--drivers/acpi/events/evrgnini.c1
-rw-r--r--drivers/acpi/glue.c2
-rw-r--r--drivers/acpi/numa.c31
-rw-r--r--drivers/acpi/osl.c40
-rw-r--r--drivers/acpi/pci_link.c2
-rw-r--r--drivers/acpi/processor_core.c6
-rw-r--r--drivers/acpi/processor_idle.c24
-rw-r--r--drivers/acpi/processor_throttling.c410
-rw-r--r--drivers/acpi/sbs.c33
-rw-r--r--drivers/acpi/sleep/main.c5
-rw-r--r--drivers/acpi/system.c165
-rw-r--r--drivers/acpi/tables/tbfadt.c44
-rw-r--r--drivers/acpi/utilities/uteval.c17
-rw-r--r--drivers/acpi/video.c124
-rw-r--r--drivers/ata/ahci.c255
-rw-r--r--drivers/ata/libata-core.c79
-rw-r--r--drivers/ata/libata-eh.c204
-rw-r--r--drivers/ata/libata-scsi.c63
-rw-r--r--drivers/ata/libata-sff.c4
-rw-r--r--drivers/ata/libata.h3
-rw-r--r--drivers/ata/pata_cs5520.c2
-rw-r--r--drivers/ata/pata_platform.c5
-rw-r--r--drivers/ata/pata_scc.c29
-rw-r--r--drivers/ata/sata_inic162x.c16
-rw-r--r--drivers/ata/sata_mv.c203
-rw-r--r--drivers/ata/sata_nv.c38
-rw-r--r--drivers/ata/sata_promise.c25
-rw-r--r--drivers/ata/sata_qstor.c18
-rw-r--r--drivers/ata/sata_sil.c25
-rw-r--r--drivers/ata/sata_sil24.c139
-rw-r--r--drivers/ata/sata_sis.c22
-rw-r--r--drivers/ata/sata_svw.c13
-rw-r--r--drivers/ata/sata_uli.c16
-rw-r--r--drivers/ata/sata_via.c27
-rw-r--r--drivers/ata/sata_vsc.c13
-rw-r--r--drivers/base/power/trace.c5
-rw-r--r--drivers/block/Makefile1
-rw-r--r--drivers/block/ps3disk.c630
-rw-r--r--drivers/block/sunvdc.c26
-rw-r--r--drivers/char/Kconfig6
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/hpet.c70
-rw-r--r--drivers/char/hvc_iseries.c8
-rw-r--r--drivers/char/hvc_rtas.c2
-rw-r--r--drivers/char/hvcs.c8
-rw-r--r--drivers/char/hw_random/Kconfig2
-rw-r--r--drivers/char/ps3flash.c440
-rw-r--r--drivers/char/rtc.c32
-rw-r--r--drivers/char/serial167.c6
-rw-r--r--drivers/char/tpm/tpm_bios.c22
-rw-r--r--drivers/char/vme_scc.c8
-rw-r--r--drivers/char/watchdog/Kconfig2
-rw-r--r--drivers/clocksource/acpi_pm.c2
-rw-r--r--drivers/ide/legacy/falconide.c2
-rw-r--r--drivers/input/input.c29
-rw-r--r--drivers/input/joystick/Kconfig7
-rw-r--r--drivers/input/joystick/xpad.c190
-rw-r--r--drivers/input/misc/pcspkr.c11
-rw-r--r--drivers/input/mouse/appletouch.c111
-rw-r--r--drivers/input/mouse/lifebook.c2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h36
-rw-r--r--drivers/input/touchscreen/Kconfig13
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/ads7846.c80
-rw-r--r--drivers/input/touchscreen/fujitsu_ts.c189
-rw-r--r--drivers/isdn/Kconfig12
-rw-r--r--drivers/isdn/act2000/Kconfig2
-rw-r--r--drivers/isdn/gigaset/Kconfig10
-rw-r--r--drivers/isdn/hisax/Kconfig1
-rw-r--r--drivers/isdn/i4l/Kconfig3
-rw-r--r--drivers/isdn/icn/Kconfig2
-rw-r--r--drivers/isdn/pcbit/Kconfig2
-rw-r--r--drivers/isdn/sc/Kconfig2
-rw-r--r--drivers/kvm/Kconfig1
-rw-r--r--drivers/kvm/kvm.h10
-rw-r--r--drivers/kvm/kvm_main.c76
-rw-r--r--drivers/kvm/mmu.c140
-rw-r--r--drivers/kvm/paging_tmpl.h2
-rw-r--r--drivers/kvm/x86_emulate.c26
-rw-r--r--drivers/leds/Kconfig22
-rw-r--r--drivers/leds/Makefile1
-rw-r--r--drivers/leds/led-class.c49
-rw-r--r--drivers/leds/led-triggers.c27
-rw-r--r--drivers/leds/leds-gpio.c199
-rw-r--r--drivers/leds/leds-locomo.c2
-rw-r--r--drivers/leds/leds.h8
-rw-r--r--drivers/leds/ledtrig-timer.c49
-rw-r--r--drivers/lguest/interrupts_and_traps.c10
-rw-r--r--drivers/lguest/io.c2
-rw-r--r--drivers/lguest/lguest.c11
-rw-r--r--drivers/lguest/lguest_asm.S4
-rw-r--r--drivers/macintosh/rack-meter.c1
-rw-r--r--drivers/md/dm-crypt.c2
-rw-r--r--drivers/md/raid5.c4
-rw-r--r--drivers/media/common/ir-functions.c4
-rw-r--r--drivers/media/dvb/ttpci/av7110.c2
-rw-r--r--drivers/media/radio/radio-aimslab.c2
-rw-r--r--drivers/media/radio/radio-cadet.c4
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c3
-rw-r--r--drivers/media/video/bt866.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c2
-rw-r--r--drivers/media/video/bt8xx/bttvp.h4
-rw-r--r--drivers/media/video/c-qcam.c4
-rw-r--r--drivers/media/video/cx88/cx88-video.c8
-rw-r--r--drivers/media/video/cx88/cx88.h2
-rw-r--r--drivers/media/video/ivtv/Kconfig5
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c43
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.c25
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c20
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c11
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c33
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c12
-rw-r--r--drivers/media/video/saa5249.c8
-rw-r--r--drivers/media/video/saa7110.c4
-rw-r--r--drivers/media/video/saa7134/saa7134.h2
-rw-r--r--drivers/media/video/tvaudio.c4
-rw-r--r--drivers/media/video/v4l2-common.c19
-rw-r--r--drivers/media/video/vino.c2
-rw-r--r--drivers/media/video/wm8739.c2
-rw-r--r--drivers/media/video/wm8775.c2
-rw-r--r--drivers/misc/Kconfig14
-rw-r--r--drivers/misc/sony-laptop.c368
-rw-r--r--drivers/misc/thinkpad_acpi.c602
-rw-r--r--drivers/misc/thinkpad_acpi.h42
-rw-r--r--drivers/mmc/host/at91_mci.c13
-rw-r--r--drivers/mmc/host/sdhci.c2
-rw-r--r--drivers/mmc/host/sdhci.h1
-rw-r--r--drivers/net/Kconfig1
-rw-r--r--drivers/net/irda/Kconfig11
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/ep7211-sir.c89
-rw-r--r--drivers/net/mac89x0.c2
-rw-r--r--drivers/net/sky2.c7
-rw-r--r--drivers/net/sunvnet.c139
-rw-r--r--drivers/net/sunvnet.h11
-rw-r--r--drivers/of/Kconfig3
-rw-r--r--drivers/of/Makefile2
-rw-r--r--drivers/of/base.c275
-rw-r--r--drivers/of/device.c131
-rw-r--r--drivers/of/platform.c96
-rw-r--r--drivers/oprofile/buffer_sync.c3
-rw-r--r--drivers/oprofile/event_buffer.h20
-rw-r--r--drivers/oprofile/oprof.c28
-rw-r--r--drivers/parport/Kconfig2
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c2
-rw-r--r--drivers/rtc/Kconfig15
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-ds1553.c2
-rw-r--r--drivers/rtc/rtc-ds1742.c2
-rw-r--r--drivers/rtc/rtc-max6900.c96
-rw-r--r--drivers/rtc/rtc-stk17ta8.c420
-rw-r--r--drivers/sbus/sbus.c5
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/NCR53C9x.c7
-rw-r--r--drivers/scsi/iscsi_tcp.c2
-rw-r--r--drivers/scsi/ps3rom.c533
-rw-r--r--drivers/serial/suncore.c123
-rw-r--r--drivers/serial/suncore.h2
-rw-r--r--drivers/serial/sunhv.c13
-rw-r--r--drivers/serial/sunsab.c22
-rw-r--r--drivers/serial/sunsu.c23
-rw-r--r--drivers/serial/sunzilog.c24
-rw-r--r--drivers/spi/spi.c3
-rw-r--r--drivers/usb/atm/cxacru.c3
-rw-r--r--drivers/usb/atm/speedtch.c7
-rw-r--r--drivers/usb/atm/ueagle-atm.c6
-rw-r--r--drivers/usb/atm/usbatm.c11
-rw-r--r--drivers/usb/class/cdc-acm.c18
-rw-r--r--drivers/usb/class/usblp.c27
-rw-r--r--drivers/usb/core/hcd.c131
-rw-r--r--drivers/usb/core/hub.c10
-rw-r--r--drivers/usb/core/message.c34
-rw-r--r--drivers/usb/core/sysfs.c53
-rw-r--r--drivers/usb/core/urb.c88
-rw-r--r--drivers/usb/gadget/Kconfig57
-rw-r--r--drivers/usb/gadget/Makefile1
-rw-r--r--drivers/usb/gadget/amd5536udc.c3454
-rw-r--r--drivers/usb/gadget/amd5536udc.h626
-rw-r--r--drivers/usb/gadget/ether.c4
-rw-r--r--drivers/usb/gadget/gadget_chips.h10
-rw-r--r--drivers/usb/gadget/m66592-udc.c255
-rw-r--r--drivers/usb/gadget/m66592-udc.h610
-rw-r--r--drivers/usb/gadget/serial.c25
-rw-r--r--drivers/usb/host/isp116x-hcd.c187
-rw-r--r--drivers/usb/host/r8a66597-hcd.c110
-rw-r--r--drivers/usb/host/r8a66597.h87
-rw-r--r--drivers/usb/host/u132-hcd.c17
-rw-r--r--drivers/usb/host/uhci-q.c59
-rw-r--r--drivers/usb/image/mdc800.c45
-rw-r--r--drivers/usb/image/microtek.c19
-rw-r--r--drivers/usb/misc/adutux.c59
-rw-r--r--drivers/usb/misc/appledisplay.c13
-rw-r--r--drivers/usb/misc/auerswald.c25
-rw-r--r--drivers/usb/misc/ftdi-elan.c21
-rw-r--r--drivers/usb/misc/iowarrior.c21
-rw-r--r--drivers/usb/misc/ldusb.c20
-rw-r--r--drivers/usb/misc/legousbtower.c28
-rw-r--r--drivers/usb/misc/phidgetkit.c13
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c13
-rw-r--r--drivers/usb/misc/usblcd.c11
-rw-r--r--drivers/usb/misc/usbtest.c4
-rw-r--r--drivers/usb/misc/uss720.c5
-rw-r--r--drivers/usb/serial/io_ti.c10
-rw-r--r--drivers/usb/serial/mos7720.c5
-rw-r--r--drivers/usb/serial/mos7840.c19
-rw-r--r--drivers/usb/serial/sierra.c119
-rw-r--r--drivers/usb/storage/dpcm.c56
-rw-r--r--drivers/usb/storage/onetouch.c13
-rw-r--r--drivers/usb/storage/unusual_devs.h18
-rw-r--r--drivers/video/Kconfig20
-rw-r--r--drivers/video/Makefile3
-rw-r--r--drivers/video/atmel_lcdfb.c67
-rw-r--r--drivers/video/aty/aty128fb.c2
-rw-r--r--drivers/video/aty/atyfb_base.c6
-rw-r--r--drivers/video/aty/radeon_backlight.c4
-rw-r--r--drivers/video/backlight/Kconfig26
-rw-r--r--drivers/video/backlight/backlight.c125
-rw-r--r--drivers/video/backlight/cr_bllcd.c4
-rw-r--r--drivers/video/backlight/lcd.c112
-rw-r--r--drivers/video/console/vgacon.c6
-rw-r--r--drivers/video/igafb.c4
-rw-r--r--drivers/video/nvidia/nv_backlight.c2
-rw-r--r--drivers/video/ps3fb.c2
-rw-r--r--drivers/video/riva/fbdev.c4
239 files changed, 13017 insertions, 3178 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 707650ab77a7..3e1c442deff9 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -8,6 +8,8 @@ source "drivers/connector/Kconfig"
8 8
9source "drivers/mtd/Kconfig" 9source "drivers/mtd/Kconfig"
10 10
11source "drivers/of/Kconfig"
12
11source "drivers/parport/Kconfig" 13source "drivers/parport/Kconfig"
12 14
13source "drivers/pnp/Kconfig" 15source "drivers/pnp/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 0ea8e3237c0d..a9e4c5f922a0 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -86,3 +86,4 @@ obj-$(CONFIG_GENERIC_TIME) += clocksource/
86obj-$(CONFIG_DMA_ENGINE) += dma/ 86obj-$(CONFIG_DMA_ENGINE) += dma/
87obj-$(CONFIG_HID) += hid/ 87obj-$(CONFIG_HID) += hid/
88obj-$(CONFIG_PPC_PS3) += ps3/ 88obj-$(CONFIG_PPC_PS3) += ps3/
89obj-$(CONFIG_OF) += of/
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 139f41f033d8..408b45168aba 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -2,16 +2,12 @@
2# ACPI Configuration 2# ACPI Configuration
3# 3#
4 4
5menu "ACPI (Advanced Configuration and Power Interface) Support" 5menuconfig ACPI
6 bool "ACPI Support (Advanced Configuration and Power Interface) Support"
6 depends on !X86_NUMAQ 7 depends on !X86_NUMAQ
7 depends on !X86_VISWS 8 depends on !X86_VISWS
8 depends on !IA64_HP_SIM 9 depends on !IA64_HP_SIM
9 depends on IA64 || X86 10 depends on IA64 || X86
10 depends on PM
11
12config ACPI
13 bool "ACPI Support"
14 depends on IA64 || X86
15 depends on PCI 11 depends on PCI
16 depends on PM 12 depends on PM
17 select PNP 13 select PNP
@@ -49,7 +45,6 @@ if ACPI
49config ACPI_SLEEP 45config ACPI_SLEEP
50 bool "Sleep States" 46 bool "Sleep States"
51 depends on X86 && (!SMP || SUSPEND_SMP) 47 depends on X86 && (!SMP || SUSPEND_SMP)
52 depends on PM
53 default y 48 default y
54 ---help--- 49 ---help---
55 This option adds support for ACPI suspend states. 50 This option adds support for ACPI suspend states.
@@ -82,7 +77,6 @@ config ACPI_SLEEP_PROC_SLEEP
82 77
83config ACPI_PROCFS 78config ACPI_PROCFS
84 bool "Procfs interface (deprecated)" 79 bool "Procfs interface (deprecated)"
85 depends on ACPI
86 default y 80 default y
87 ---help--- 81 ---help---
88 The Procfs interface for ACPI is made optional for backward compatibility. 82 The Procfs interface for ACPI is made optional for backward compatibility.
@@ -124,7 +118,7 @@ config ACPI_BUTTON
124 118
125config ACPI_VIDEO 119config ACPI_VIDEO
126 tristate "Video" 120 tristate "Video"
127 depends on X86 && BACKLIGHT_CLASS_DEVICE 121 depends on X86 && BACKLIGHT_CLASS_DEVICE && VIDEO_OUTPUT_CONTROL
128 help 122 help
129 This driver implement the ACPI Extensions For Display Adapters 123 This driver implement the ACPI Extensions For Display Adapters
130 for integrated graphics devices on motherboard, as specified in 124 for integrated graphics devices on motherboard, as specified in
@@ -280,6 +274,14 @@ config ACPI_DEBUG
280 of verbosity. Saying Y enables these statements. This will increase 274 of verbosity. Saying Y enables these statements. This will increase
281 your kernel size by around 50K. 275 your kernel size by around 50K.
282 276
277config ACPI_DEBUG_FUNC_TRACE
278 bool "Additionally enable ACPI function tracing"
279 default n
280 depends on ACPI_DEBUG
281 help
282 ACPI Debug Statements slow down ACPI processing. Function trace
283 is about half of the penalty and is rarely useful.
284
283config ACPI_EC 285config ACPI_EC
284 bool 286 bool
285 default y 287 default y
@@ -330,7 +332,6 @@ config ACPI_CONTAINER
330 332
331config ACPI_HOTPLUG_MEMORY 333config ACPI_HOTPLUG_MEMORY
332 tristate "Memory Hotplug" 334 tristate "Memory Hotplug"
333 depends on ACPI
334 depends on MEMORY_HOTPLUG 335 depends on MEMORY_HOTPLUG
335 default n 336 default n
336 help 337 help
@@ -359,5 +360,3 @@ config ACPI_SBS
359 to today's ACPI "Control Method" battery. 360 to today's ACPI "Control Method" battery.
360 361
361endif # ACPI 362endif # ACPI
362
363endmenu
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index e64c76c8b726..cad932de383d 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -43,21 +43,30 @@
43#define ACPI_BATTERY_CLASS "battery" 43#define ACPI_BATTERY_CLASS "battery"
44#define ACPI_BATTERY_HID "PNP0C0A" 44#define ACPI_BATTERY_HID "PNP0C0A"
45#define ACPI_BATTERY_DEVICE_NAME "Battery" 45#define ACPI_BATTERY_DEVICE_NAME "Battery"
46#define ACPI_BATTERY_FILE_INFO "info"
47#define ACPI_BATTERY_FILE_STATUS "state"
48#define ACPI_BATTERY_FILE_ALARM "alarm"
49#define ACPI_BATTERY_NOTIFY_STATUS 0x80 46#define ACPI_BATTERY_NOTIFY_STATUS 0x80
50#define ACPI_BATTERY_NOTIFY_INFO 0x81 47#define ACPI_BATTERY_NOTIFY_INFO 0x81
51#define ACPI_BATTERY_UNITS_WATTS "mW" 48#define ACPI_BATTERY_UNITS_WATTS "mW"
52#define ACPI_BATTERY_UNITS_AMPS "mA" 49#define ACPI_BATTERY_UNITS_AMPS "mA"
53 50
54#define _COMPONENT ACPI_BATTERY_COMPONENT 51#define _COMPONENT ACPI_BATTERY_COMPONENT
52
53#define ACPI_BATTERY_UPDATE_TIME 0
54
55#define ACPI_BATTERY_NONE_UPDATE 0
56#define ACPI_BATTERY_EASY_UPDATE 1
57#define ACPI_BATTERY_INIT_UPDATE 2
58
55ACPI_MODULE_NAME("battery"); 59ACPI_MODULE_NAME("battery");
56 60
57MODULE_AUTHOR("Paul Diefenbaugh"); 61MODULE_AUTHOR("Paul Diefenbaugh");
58MODULE_DESCRIPTION("ACPI Battery Driver"); 62MODULE_DESCRIPTION("ACPI Battery Driver");
59MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
60 64
65static unsigned int update_time = ACPI_BATTERY_UPDATE_TIME;
66
67/* 0 - every time, > 0 - by update_time */
68module_param(update_time, uint, 0644);
69
61extern struct proc_dir_entry *acpi_lock_battery_dir(void); 70extern struct proc_dir_entry *acpi_lock_battery_dir(void);
62extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir); 71extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
63 72
@@ -76,7 +85,7 @@ static struct acpi_driver acpi_battery_driver = {
76 }, 85 },
77}; 86};
78 87
79struct acpi_battery_status { 88struct acpi_battery_state {
80 acpi_integer state; 89 acpi_integer state;
81 acpi_integer present_rate; 90 acpi_integer present_rate;
82 acpi_integer remaining_capacity; 91 acpi_integer remaining_capacity;
@@ -99,33 +108,111 @@ struct acpi_battery_info {
99 acpi_string oem_info; 108 acpi_string oem_info;
100}; 109};
101 110
102struct acpi_battery_flags { 111enum acpi_battery_files{
103 u8 present:1; /* Bay occupied? */ 112 ACPI_BATTERY_INFO = 0,
104 u8 power_unit:1; /* 0=watts, 1=apms */ 113 ACPI_BATTERY_STATE,
105 u8 alarm:1; /* _BTP present? */ 114 ACPI_BATTERY_ALARM,
106 u8 reserved:5; 115 ACPI_BATTERY_NUMFILES,
107}; 116};
108 117
109struct acpi_battery_trips { 118struct acpi_battery_flags {
110 unsigned long warning; 119 u8 battery_present_prev;
111 unsigned long low; 120 u8 alarm_present;
121 u8 init_update;
122 u8 update[ACPI_BATTERY_NUMFILES];
123 u8 power_unit;
112}; 124};
113 125
114struct acpi_battery { 126struct acpi_battery {
115 struct acpi_device * device; 127 struct mutex mutex;
128 struct acpi_device *device;
116 struct acpi_battery_flags flags; 129 struct acpi_battery_flags flags;
117 struct acpi_battery_trips trips; 130 struct acpi_buffer bif_data;
131 struct acpi_buffer bst_data;
118 unsigned long alarm; 132 unsigned long alarm;
119 struct acpi_battery_info *info; 133 unsigned long update_time[ACPI_BATTERY_NUMFILES];
120}; 134};
121 135
136inline int acpi_battery_present(struct acpi_battery *battery)
137{
138 return battery->device->status.battery_present;
139}
140inline char *acpi_battery_power_units(struct acpi_battery *battery)
141{
142 if (battery->flags.power_unit)
143 return ACPI_BATTERY_UNITS_AMPS;
144 else
145 return ACPI_BATTERY_UNITS_WATTS;
146}
147
148inline acpi_handle acpi_battery_handle(struct acpi_battery *battery)
149{
150 return battery->device->handle;
151}
152
122/* -------------------------------------------------------------------------- 153/* --------------------------------------------------------------------------
123 Battery Management 154 Battery Management
124 -------------------------------------------------------------------------- */ 155 -------------------------------------------------------------------------- */
125 156
126static int 157static void acpi_battery_check_result(struct acpi_battery *battery, int result)
127acpi_battery_get_info(struct acpi_battery *battery, 158{
128 struct acpi_battery_info **bif) 159 if (!battery)
160 return;
161
162 if (result) {
163 battery->flags.init_update = 1;
164 }
165}
166
167static int acpi_battery_extract_package(struct acpi_battery *battery,
168 union acpi_object *package,
169 struct acpi_buffer *format,
170 struct acpi_buffer *data,
171 char *package_name)
172{
173 acpi_status status = AE_OK;
174 struct acpi_buffer data_null = { 0, NULL };
175
176 status = acpi_extract_package(package, format, &data_null);
177 if (status != AE_BUFFER_OVERFLOW) {
178 ACPI_EXCEPTION((AE_INFO, status, "Extracting size %s",
179 package_name));
180 return -ENODEV;
181 }
182
183 if (data_null.length != data->length) {
184 kfree(data->pointer);
185 data->pointer = kzalloc(data_null.length, GFP_KERNEL);
186 if (!data->pointer) {
187 ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()"));
188 return -ENOMEM;
189 }
190 data->length = data_null.length;
191 }
192
193 status = acpi_extract_package(package, format, data);
194 if (ACPI_FAILURE(status)) {
195 ACPI_EXCEPTION((AE_INFO, status, "Extracting %s",
196 package_name));
197 return -ENODEV;
198 }
199
200 return 0;
201}
202
203static int acpi_battery_get_status(struct acpi_battery *battery)
204{
205 int result = 0;
206
207 result = acpi_bus_get_status(battery->device);
208 if (result) {
209 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA"));
210 return -ENODEV;
211 }
212 return result;
213}
214
215static int acpi_battery_get_info(struct acpi_battery *battery)
129{ 216{
130 int result = 0; 217 int result = 0;
131 acpi_status status = 0; 218 acpi_status status = 0;
@@ -133,16 +220,20 @@ acpi_battery_get_info(struct acpi_battery *battery,
133 struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BIF), 220 struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BIF),
134 ACPI_BATTERY_FORMAT_BIF 221 ACPI_BATTERY_FORMAT_BIF
135 }; 222 };
136 struct acpi_buffer data = { 0, NULL };
137 union acpi_object *package = NULL; 223 union acpi_object *package = NULL;
224 struct acpi_buffer *data = NULL;
225 struct acpi_battery_info *bif = NULL;
138 226
227 battery->update_time[ACPI_BATTERY_INFO] = get_seconds();
139 228
140 if (!battery || !bif) 229 if (!acpi_battery_present(battery))
141 return -EINVAL; 230 return 0;
142 231
143 /* Evalute _BIF */ 232 /* Evaluate _BIF */
144 233
145 status = acpi_evaluate_object(battery->device->handle, "_BIF", NULL, &buffer); 234 status =
235 acpi_evaluate_object(acpi_battery_handle(battery), "_BIF", NULL,
236 &buffer);
146 if (ACPI_FAILURE(status)) { 237 if (ACPI_FAILURE(status)) {
147 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF")); 238 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
148 return -ENODEV; 239 return -ENODEV;
@@ -150,41 +241,29 @@ acpi_battery_get_info(struct acpi_battery *battery,
150 241
151 package = buffer.pointer; 242 package = buffer.pointer;
152 243
153 /* Extract Package Data */ 244 data = &battery->bif_data;
154
155 status = acpi_extract_package(package, &format, &data);
156 if (status != AE_BUFFER_OVERFLOW) {
157 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF"));
158 result = -ENODEV;
159 goto end;
160 }
161 245
162 data.pointer = kzalloc(data.length, GFP_KERNEL); 246 /* Extract Package Data */
163 if (!data.pointer) {
164 result = -ENOMEM;
165 goto end;
166 }
167 247
168 status = acpi_extract_package(package, &format, &data); 248 result =
169 if (ACPI_FAILURE(status)) { 249 acpi_battery_extract_package(battery, package, &format, data,
170 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BIF")); 250 "_BIF");
171 kfree(data.pointer); 251 if (result)
172 result = -ENODEV;
173 goto end; 252 goto end;
174 }
175 253
176 end: 254 end:
255
177 kfree(buffer.pointer); 256 kfree(buffer.pointer);
178 257
179 if (!result) 258 if (!result) {
180 (*bif) = data.pointer; 259 bif = data->pointer;
260 battery->flags.power_unit = bif->power_unit;
261 }
181 262
182 return result; 263 return result;
183} 264}
184 265
185static int 266static int acpi_battery_get_state(struct acpi_battery *battery)
186acpi_battery_get_status(struct acpi_battery *battery,
187 struct acpi_battery_status **bst)
188{ 267{
189 int result = 0; 268 int result = 0;
190 acpi_status status = 0; 269 acpi_status status = 0;
@@ -192,16 +271,19 @@ acpi_battery_get_status(struct acpi_battery *battery,
192 struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BST), 271 struct acpi_buffer format = { sizeof(ACPI_BATTERY_FORMAT_BST),
193 ACPI_BATTERY_FORMAT_BST 272 ACPI_BATTERY_FORMAT_BST
194 }; 273 };
195 struct acpi_buffer data = { 0, NULL };
196 union acpi_object *package = NULL; 274 union acpi_object *package = NULL;
275 struct acpi_buffer *data = NULL;
197 276
277 battery->update_time[ACPI_BATTERY_STATE] = get_seconds();
198 278
199 if (!battery || !bst) 279 if (!acpi_battery_present(battery))
200 return -EINVAL; 280 return 0;
201 281
202 /* Evalute _BST */ 282 /* Evaluate _BST */
203 283
204 status = acpi_evaluate_object(battery->device->handle, "_BST", NULL, &buffer); 284 status =
285 acpi_evaluate_object(acpi_battery_handle(battery), "_BST", NULL,
286 &buffer);
205 if (ACPI_FAILURE(status)) { 287 if (ACPI_FAILURE(status)) {
206 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST")); 288 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
207 return -ENODEV; 289 return -ENODEV;
@@ -209,55 +291,49 @@ acpi_battery_get_status(struct acpi_battery *battery,
209 291
210 package = buffer.pointer; 292 package = buffer.pointer;
211 293
212 /* Extract Package Data */ 294 data = &battery->bst_data;
213
214 status = acpi_extract_package(package, &format, &data);
215 if (status != AE_BUFFER_OVERFLOW) {
216 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST"));
217 result = -ENODEV;
218 goto end;
219 }
220 295
221 data.pointer = kzalloc(data.length, GFP_KERNEL); 296 /* Extract Package Data */
222 if (!data.pointer) {
223 result = -ENOMEM;
224 goto end;
225 }
226 297
227 status = acpi_extract_package(package, &format, &data); 298 result =
228 if (ACPI_FAILURE(status)) { 299 acpi_battery_extract_package(battery, package, &format, data,
229 ACPI_EXCEPTION((AE_INFO, status, "Extracting _BST")); 300 "_BST");
230 kfree(data.pointer); 301 if (result)
231 result = -ENODEV;
232 goto end; 302 goto end;
233 }
234 303
235 end: 304 end:
236 kfree(buffer.pointer); 305 kfree(buffer.pointer);
237 306
238 if (!result)
239 (*bst) = data.pointer;
240
241 return result; 307 return result;
242} 308}
243 309
244static int 310static int acpi_battery_get_alarm(struct acpi_battery *battery)
245acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm) 311{
312 battery->update_time[ACPI_BATTERY_ALARM] = get_seconds();
313
314 return 0;
315}
316
317static int acpi_battery_set_alarm(struct acpi_battery *battery,
318 unsigned long alarm)
246{ 319{
247 acpi_status status = 0; 320 acpi_status status = 0;
248 union acpi_object arg0 = { ACPI_TYPE_INTEGER }; 321 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
249 struct acpi_object_list arg_list = { 1, &arg0 }; 322 struct acpi_object_list arg_list = { 1, &arg0 };
250 323
324 battery->update_time[ACPI_BATTERY_ALARM] = get_seconds();
251 325
252 if (!battery) 326 if (!acpi_battery_present(battery))
253 return -EINVAL; 327 return -ENODEV;
254 328
255 if (!battery->flags.alarm) 329 if (!battery->flags.alarm_present)
256 return -ENODEV; 330 return -ENODEV;
257 331
258 arg0.integer.value = alarm; 332 arg0.integer.value = alarm;
259 333
260 status = acpi_evaluate_object(battery->device->handle, "_BTP", &arg_list, NULL); 334 status =
335 acpi_evaluate_object(acpi_battery_handle(battery), "_BTP",
336 &arg_list, NULL);
261 if (ACPI_FAILURE(status)) 337 if (ACPI_FAILURE(status))
262 return -ENODEV; 338 return -ENODEV;
263 339
@@ -268,65 +344,114 @@ acpi_battery_set_alarm(struct acpi_battery *battery, unsigned long alarm)
268 return 0; 344 return 0;
269} 345}
270 346
271static int acpi_battery_check(struct acpi_battery *battery) 347static int acpi_battery_init_alarm(struct acpi_battery *battery)
272{ 348{
273 int result = 0; 349 int result = 0;
274 acpi_status status = AE_OK; 350 acpi_status status = AE_OK;
275 acpi_handle handle = NULL; 351 acpi_handle handle = NULL;
276 struct acpi_device *device = NULL; 352 struct acpi_battery_info *bif = battery->bif_data.pointer;
277 struct acpi_battery_info *bif = NULL; 353 unsigned long alarm = battery->alarm;
278 354
355 /* See if alarms are supported, and if so, set default */
279 356
280 if (!battery) 357 status = acpi_get_handle(acpi_battery_handle(battery), "_BTP", &handle);
281 return -EINVAL; 358 if (ACPI_SUCCESS(status)) {
282 359 battery->flags.alarm_present = 1;
283 device = battery->device; 360 if (!alarm && bif) {
361 alarm = bif->design_capacity_warning;
362 }
363 result = acpi_battery_set_alarm(battery, alarm);
364 if (result)
365 goto end;
366 } else {
367 battery->flags.alarm_present = 0;
368 }
284 369
285 result = acpi_bus_get_status(device); 370 end:
286 if (result)
287 return result;
288 371
289 /* Insertion? */ 372 return result;
373}
290 374
291 if (!battery->flags.present && device->status.battery_present) { 375static int acpi_battery_init_update(struct acpi_battery *battery)
376{
377 int result = 0;
292 378
293 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery inserted\n")); 379 result = acpi_battery_get_status(battery);
380 if (result)
381 return result;
294 382
295 /* Evalute _BIF to get certain static information */ 383 battery->flags.battery_present_prev = acpi_battery_present(battery);
296 384
297 result = acpi_battery_get_info(battery, &bif); 385 if (acpi_battery_present(battery)) {
386 result = acpi_battery_get_info(battery);
387 if (result)
388 return result;
389 result = acpi_battery_get_state(battery);
298 if (result) 390 if (result)
299 return result; 391 return result;
300 392
301 battery->flags.power_unit = bif->power_unit; 393 acpi_battery_init_alarm(battery);
302 battery->trips.warning = bif->design_capacity_warning; 394 }
303 battery->trips.low = bif->design_capacity_low; 395
304 kfree(bif); 396 return result;
397}
305 398
306 /* See if alarms are supported, and if so, set default */ 399static int acpi_battery_update(struct acpi_battery *battery,
400 int update, int *update_result_ptr)
401{
402 int result = 0;
403 int update_result = ACPI_BATTERY_NONE_UPDATE;
404
405 if (!acpi_battery_present(battery)) {
406 update = 1;
407 }
307 408
308 status = acpi_get_handle(battery->device->handle, "_BTP", &handle); 409 if (battery->flags.init_update) {
309 if (ACPI_SUCCESS(status)) { 410 result = acpi_battery_init_update(battery);
310 battery->flags.alarm = 1; 411 if (result)
311 acpi_battery_set_alarm(battery, battery->trips.warning); 412 goto end;
413 update_result = ACPI_BATTERY_INIT_UPDATE;
414 } else if (update) {
415 result = acpi_battery_get_status(battery);
416 if (result)
417 goto end;
418 if ((!battery->flags.battery_present_prev & acpi_battery_present(battery))
419 || (battery->flags.battery_present_prev & !acpi_battery_present(battery))) {
420 result = acpi_battery_init_update(battery);
421 if (result)
422 goto end;
423 update_result = ACPI_BATTERY_INIT_UPDATE;
424 } else {
425 update_result = ACPI_BATTERY_EASY_UPDATE;
312 } 426 }
313 } 427 }
314 428
315 /* Removal? */ 429 end:
316 430
317 else if (battery->flags.present && !device->status.battery_present) { 431 battery->flags.init_update = (result != 0);
318 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery removed\n"));
319 }
320 432
321 battery->flags.present = device->status.battery_present; 433 *update_result_ptr = update_result;
322 434
323 return result; 435 return result;
324} 436}
325 437
326static void acpi_battery_check_present(struct acpi_battery *battery) 438static void acpi_battery_notify_update(struct acpi_battery *battery)
327{ 439{
328 if (!battery->flags.present) { 440 acpi_battery_get_status(battery);
329 acpi_battery_check(battery); 441
442 if (battery->flags.init_update) {
443 return;
444 }
445
446 if ((!battery->flags.battery_present_prev &
447 acpi_battery_present(battery)) ||
448 (battery->flags.battery_present_prev &
449 !acpi_battery_present(battery))) {
450 battery->flags.init_update = 1;
451 } else {
452 battery->flags.update[ACPI_BATTERY_INFO] = 1;
453 battery->flags.update[ACPI_BATTERY_STATE] = 1;
454 battery->flags.update[ACPI_BATTERY_ALARM] = 1;
330 } 455 }
331} 456}
332 457
@@ -335,37 +460,33 @@ static void acpi_battery_check_present(struct acpi_battery *battery)
335 -------------------------------------------------------------------------- */ 460 -------------------------------------------------------------------------- */
336 461
337static struct proc_dir_entry *acpi_battery_dir; 462static struct proc_dir_entry *acpi_battery_dir;
338static int acpi_battery_read_info(struct seq_file *seq, void *offset) 463
464static int acpi_battery_print_info(struct seq_file *seq, int result)
339{ 465{
340 int result = 0;
341 struct acpi_battery *battery = seq->private; 466 struct acpi_battery *battery = seq->private;
342 struct acpi_battery_info *bif = NULL; 467 struct acpi_battery_info *bif = NULL;
343 char *units = "?"; 468 char *units = "?";
344 469
345 470 if (result)
346 if (!battery)
347 goto end; 471 goto end;
348 472
349 acpi_battery_check_present(battery); 473 if (acpi_battery_present(battery))
350
351 if (battery->flags.present)
352 seq_printf(seq, "present: yes\n"); 474 seq_printf(seq, "present: yes\n");
353 else { 475 else {
354 seq_printf(seq, "present: no\n"); 476 seq_printf(seq, "present: no\n");
355 goto end; 477 goto end;
356 } 478 }
357 479
358 /* Battery Info (_BIF) */ 480 bif = battery->bif_data.pointer;
359 481 if (!bif) {
360 result = acpi_battery_get_info(battery, &bif); 482 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BIF buffer is NULL"));
361 if (result || !bif) { 483 result = -ENODEV;
362 seq_printf(seq, "ERROR: Unable to read battery information\n");
363 goto end; 484 goto end;
364 } 485 }
365 486
366 units = 487 /* Battery Units */
367 bif-> 488
368 power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS; 489 units = acpi_battery_power_units(battery);
369 490
370 if (bif->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) 491 if (bif->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
371 seq_printf(seq, "design capacity: unknown\n"); 492 seq_printf(seq, "design capacity: unknown\n");
@@ -396,7 +517,6 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
396 else 517 else
397 seq_printf(seq, "design voltage: %d mV\n", 518 seq_printf(seq, "design voltage: %d mV\n",
398 (u32) bif->design_voltage); 519 (u32) bif->design_voltage);
399
400 seq_printf(seq, "design capacity warning: %d %sh\n", 520 seq_printf(seq, "design capacity warning: %d %sh\n",
401 (u32) bif->design_capacity_warning, units); 521 (u32) bif->design_capacity_warning, units);
402 seq_printf(seq, "design capacity low: %d %sh\n", 522 seq_printf(seq, "design capacity low: %d %sh\n",
@@ -411,50 +531,40 @@ static int acpi_battery_read_info(struct seq_file *seq, void *offset)
411 seq_printf(seq, "OEM info: %s\n", bif->oem_info); 531 seq_printf(seq, "OEM info: %s\n", bif->oem_info);
412 532
413 end: 533 end:
414 kfree(bif);
415 534
416 return 0; 535 if (result)
417} 536 seq_printf(seq, "ERROR: Unable to read battery info\n");
418 537
419static int acpi_battery_info_open_fs(struct inode *inode, struct file *file) 538 return result;
420{
421 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
422} 539}
423 540
424static int acpi_battery_read_state(struct seq_file *seq, void *offset) 541static int acpi_battery_print_state(struct seq_file *seq, int result)
425{ 542{
426 int result = 0;
427 struct acpi_battery *battery = seq->private; 543 struct acpi_battery *battery = seq->private;
428 struct acpi_battery_status *bst = NULL; 544 struct acpi_battery_state *bst = NULL;
429 char *units = "?"; 545 char *units = "?";
430 546
431 547 if (result)
432 if (!battery)
433 goto end; 548 goto end;
434 549
435 acpi_battery_check_present(battery); 550 if (acpi_battery_present(battery))
436
437 if (battery->flags.present)
438 seq_printf(seq, "present: yes\n"); 551 seq_printf(seq, "present: yes\n");
439 else { 552 else {
440 seq_printf(seq, "present: no\n"); 553 seq_printf(seq, "present: no\n");
441 goto end; 554 goto end;
442 } 555 }
443 556
444 /* Battery Units */ 557 bst = battery->bst_data.pointer;
445 558 if (!bst) {
446 units = 559 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "BST buffer is NULL"));
447 battery->flags. 560 result = -ENODEV;
448 power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS;
449
450 /* Battery Status (_BST) */
451
452 result = acpi_battery_get_status(battery, &bst);
453 if (result || !bst) {
454 seq_printf(seq, "ERROR: Unable to read battery status\n");
455 goto end; 561 goto end;
456 } 562 }
457 563
564 /* Battery Units */
565
566 units = acpi_battery_power_units(battery);
567
458 if (!(bst->state & 0x04)) 568 if (!(bst->state & 0x04))
459 seq_printf(seq, "capacity state: ok\n"); 569 seq_printf(seq, "capacity state: ok\n");
460 else 570 else
@@ -490,48 +600,43 @@ static int acpi_battery_read_state(struct seq_file *seq, void *offset)
490 (u32) bst->present_voltage); 600 (u32) bst->present_voltage);
491 601
492 end: 602 end:
493 kfree(bst);
494 603
495 return 0; 604 if (result) {
496} 605 seq_printf(seq, "ERROR: Unable to read battery state\n");
606 }
497 607
498static int acpi_battery_state_open_fs(struct inode *inode, struct file *file) 608 return result;
499{
500 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
501} 609}
502 610
503static int acpi_battery_read_alarm(struct seq_file *seq, void *offset) 611static int acpi_battery_print_alarm(struct seq_file *seq, int result)
504{ 612{
505 struct acpi_battery *battery = seq->private; 613 struct acpi_battery *battery = seq->private;
506 char *units = "?"; 614 char *units = "?";
507 615
508 616 if (result)
509 if (!battery)
510 goto end; 617 goto end;
511 618
512 acpi_battery_check_present(battery); 619 if (!acpi_battery_present(battery)) {
513
514 if (!battery->flags.present) {
515 seq_printf(seq, "present: no\n"); 620 seq_printf(seq, "present: no\n");
516 goto end; 621 goto end;
517 } 622 }
518 623
519 /* Battery Units */ 624 /* Battery Units */
520 625
521 units = 626 units = acpi_battery_power_units(battery);
522 battery->flags.
523 power_unit ? ACPI_BATTERY_UNITS_AMPS : ACPI_BATTERY_UNITS_WATTS;
524
525 /* Battery Alarm */
526 627
527 seq_printf(seq, "alarm: "); 628 seq_printf(seq, "alarm: ");
528 if (!battery->alarm) 629 if (!battery->alarm)
529 seq_printf(seq, "unsupported\n"); 630 seq_printf(seq, "unsupported\n");
530 else 631 else
531 seq_printf(seq, "%d %sh\n", (u32) battery->alarm, units); 632 seq_printf(seq, "%lu %sh\n", battery->alarm, units);
532 633
533 end: 634 end:
534 return 0; 635
636 if (result)
637 seq_printf(seq, "ERROR: Unable to read battery alarm\n");
638
639 return result;
535} 640}
536 641
537static ssize_t 642static ssize_t
@@ -543,27 +648,113 @@ acpi_battery_write_alarm(struct file *file,
543 char alarm_string[12] = { '\0' }; 648 char alarm_string[12] = { '\0' };
544 struct seq_file *m = file->private_data; 649 struct seq_file *m = file->private_data;
545 struct acpi_battery *battery = m->private; 650 struct acpi_battery *battery = m->private;
546 651 int update_result = ACPI_BATTERY_NONE_UPDATE;
547 652
548 if (!battery || (count > sizeof(alarm_string) - 1)) 653 if (!battery || (count > sizeof(alarm_string) - 1))
549 return -EINVAL; 654 return -EINVAL;
550 655
551 acpi_battery_check_present(battery); 656 mutex_lock(&battery->mutex);
552 657
553 if (!battery->flags.present) 658 result = acpi_battery_update(battery, 1, &update_result);
554 return -ENODEV; 659 if (result) {
660 result = -ENODEV;
661 goto end;
662 }
663
664 if (!acpi_battery_present(battery)) {
665 result = -ENODEV;
666 goto end;
667 }
555 668
556 if (copy_from_user(alarm_string, buffer, count)) 669 if (copy_from_user(alarm_string, buffer, count)) {
557 return -EFAULT; 670 result = -EFAULT;
671 goto end;
672 }
558 673
559 alarm_string[count] = '\0'; 674 alarm_string[count] = '\0';
560 675
561 result = acpi_battery_set_alarm(battery, 676 result = acpi_battery_set_alarm(battery,
562 simple_strtoul(alarm_string, NULL, 0)); 677 simple_strtoul(alarm_string, NULL, 0));
563 if (result) 678 if (result)
564 return result; 679 goto end;
680
681 end:
565 682
566 return count; 683 acpi_battery_check_result(battery, result);
684
685 if (!result)
686 result = count;
687
688 mutex_unlock(&battery->mutex);
689
690 return result;
691}
692
693typedef int(*print_func)(struct seq_file *seq, int result);
694typedef int(*get_func)(struct acpi_battery *battery);
695
696static struct acpi_read_mux {
697 print_func print;
698 get_func get;
699} acpi_read_funcs[ACPI_BATTERY_NUMFILES] = {
700 {.get = acpi_battery_get_info, .print = acpi_battery_print_info},
701 {.get = acpi_battery_get_state, .print = acpi_battery_print_state},
702 {.get = acpi_battery_get_alarm, .print = acpi_battery_print_alarm},
703};
704
705static int acpi_battery_read(int fid, struct seq_file *seq)
706{
707 struct acpi_battery *battery = seq->private;
708 int result = 0;
709 int update_result = ACPI_BATTERY_NONE_UPDATE;
710 int update = 0;
711
712 mutex_lock(&battery->mutex);
713
714 update = (get_seconds() - battery->update_time[fid] >= update_time);
715 update = (update | battery->flags.update[fid]);
716
717 result = acpi_battery_update(battery, update, &update_result);
718 if (result)
719 goto end;
720
721 if (update_result == ACPI_BATTERY_EASY_UPDATE) {
722 result = acpi_read_funcs[fid].get(battery);
723 if (result)
724 goto end;
725 }
726
727 end:
728 result = acpi_read_funcs[fid].print(seq, result);
729 acpi_battery_check_result(battery, result);
730 battery->flags.update[fid] = result;
731 mutex_unlock(&battery->mutex);
732 return result;
733}
734
735static int acpi_battery_read_info(struct seq_file *seq, void *offset)
736{
737 return acpi_battery_read(ACPI_BATTERY_INFO, seq);
738}
739
740static int acpi_battery_read_state(struct seq_file *seq, void *offset)
741{
742 return acpi_battery_read(ACPI_BATTERY_STATE, seq);
743}
744
745static int acpi_battery_read_alarm(struct seq_file *seq, void *offset)
746{
747 return acpi_battery_read(ACPI_BATTERY_ALARM, seq);
748}
749
750static int acpi_battery_info_open_fs(struct inode *inode, struct file *file)
751{
752 return single_open(file, acpi_battery_read_info, PDE(inode)->data);
753}
754
755static int acpi_battery_state_open_fs(struct inode *inode, struct file *file)
756{
757 return single_open(file, acpi_battery_read_state, PDE(inode)->data);
567} 758}
568 759
569static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file) 760static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
@@ -571,35 +762,51 @@ static int acpi_battery_alarm_open_fs(struct inode *inode, struct file *file)
571 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data); 762 return single_open(file, acpi_battery_read_alarm, PDE(inode)->data);
572} 763}
573 764
574static const struct file_operations acpi_battery_info_ops = { 765static struct battery_file {
766 struct file_operations ops;
767 mode_t mode;
768 char *name;
769} acpi_battery_file[] = {
770 {
771 .name = "info",
772 .mode = S_IRUGO,
773 .ops = {
575 .open = acpi_battery_info_open_fs, 774 .open = acpi_battery_info_open_fs,
576 .read = seq_read, 775 .read = seq_read,
577 .llseek = seq_lseek, 776 .llseek = seq_lseek,
578 .release = single_release, 777 .release = single_release,
579 .owner = THIS_MODULE, 778 .owner = THIS_MODULE,
580}; 779 },
581 780 },
582static const struct file_operations acpi_battery_state_ops = { 781 {
782 .name = "state",
783 .mode = S_IRUGO,
784 .ops = {
583 .open = acpi_battery_state_open_fs, 785 .open = acpi_battery_state_open_fs,
584 .read = seq_read, 786 .read = seq_read,
585 .llseek = seq_lseek, 787 .llseek = seq_lseek,
586 .release = single_release, 788 .release = single_release,
587 .owner = THIS_MODULE, 789 .owner = THIS_MODULE,
588}; 790 },
589 791 },
590static const struct file_operations acpi_battery_alarm_ops = { 792 {
793 .name = "alarm",
794 .mode = S_IFREG | S_IRUGO | S_IWUSR,
795 .ops = {
591 .open = acpi_battery_alarm_open_fs, 796 .open = acpi_battery_alarm_open_fs,
592 .read = seq_read, 797 .read = seq_read,
593 .write = acpi_battery_write_alarm, 798 .write = acpi_battery_write_alarm,
594 .llseek = seq_lseek, 799 .llseek = seq_lseek,
595 .release = single_release, 800 .release = single_release,
596 .owner = THIS_MODULE, 801 .owner = THIS_MODULE,
802 },
803 },
597}; 804};
598 805
599static int acpi_battery_add_fs(struct acpi_device *device) 806static int acpi_battery_add_fs(struct acpi_device *device)
600{ 807{
601 struct proc_dir_entry *entry = NULL; 808 struct proc_dir_entry *entry = NULL;
602 809 int i;
603 810
604 if (!acpi_device_dir(device)) { 811 if (!acpi_device_dir(device)) {
605 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), 812 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
@@ -609,38 +816,16 @@ static int acpi_battery_add_fs(struct acpi_device *device)
609 acpi_device_dir(device)->owner = THIS_MODULE; 816 acpi_device_dir(device)->owner = THIS_MODULE;
610 } 817 }
611 818
612 /* 'info' [R] */ 819 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
613 entry = create_proc_entry(ACPI_BATTERY_FILE_INFO, 820 entry = create_proc_entry(acpi_battery_file[i].name,
614 S_IRUGO, acpi_device_dir(device)); 821 acpi_battery_file[i].mode, acpi_device_dir(device));
615 if (!entry) 822 if (!entry)
616 return -ENODEV; 823 return -ENODEV;
617 else { 824 else {
618 entry->proc_fops = &acpi_battery_info_ops; 825 entry->proc_fops = &acpi_battery_file[i].ops;
619 entry->data = acpi_driver_data(device); 826 entry->data = acpi_driver_data(device);
620 entry->owner = THIS_MODULE; 827 entry->owner = THIS_MODULE;
621 } 828 }
622
623 /* 'status' [R] */
624 entry = create_proc_entry(ACPI_BATTERY_FILE_STATUS,
625 S_IRUGO, acpi_device_dir(device));
626 if (!entry)
627 return -ENODEV;
628 else {
629 entry->proc_fops = &acpi_battery_state_ops;
630 entry->data = acpi_driver_data(device);
631 entry->owner = THIS_MODULE;
632 }
633
634 /* 'alarm' [R/W] */
635 entry = create_proc_entry(ACPI_BATTERY_FILE_ALARM,
636 S_IFREG | S_IRUGO | S_IWUSR,
637 acpi_device_dir(device));
638 if (!entry)
639 return -ENODEV;
640 else {
641 entry->proc_fops = &acpi_battery_alarm_ops;
642 entry->data = acpi_driver_data(device);
643 entry->owner = THIS_MODULE;
644 } 829 }
645 830
646 return 0; 831 return 0;
@@ -648,15 +833,12 @@ static int acpi_battery_add_fs(struct acpi_device *device)
648 833
649static int acpi_battery_remove_fs(struct acpi_device *device) 834static int acpi_battery_remove_fs(struct acpi_device *device)
650{ 835{
651 836 int i;
652 if (acpi_device_dir(device)) { 837 if (acpi_device_dir(device)) {
653 remove_proc_entry(ACPI_BATTERY_FILE_ALARM, 838 for (i = 0; i < ACPI_BATTERY_NUMFILES; ++i) {
839 remove_proc_entry(acpi_battery_file[i].name,
654 acpi_device_dir(device)); 840 acpi_device_dir(device));
655 remove_proc_entry(ACPI_BATTERY_FILE_STATUS, 841 }
656 acpi_device_dir(device));
657 remove_proc_entry(ACPI_BATTERY_FILE_INFO,
658 acpi_device_dir(device));
659
660 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir); 842 remove_proc_entry(acpi_device_bid(device), acpi_battery_dir);
661 acpi_device_dir(device) = NULL; 843 acpi_device_dir(device) = NULL;
662 } 844 }
@@ -673,7 +855,6 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
673 struct acpi_battery *battery = data; 855 struct acpi_battery *battery = data;
674 struct acpi_device *device = NULL; 856 struct acpi_device *device = NULL;
675 857
676
677 if (!battery) 858 if (!battery)
678 return; 859 return;
679 860
@@ -684,8 +865,10 @@ static void acpi_battery_notify(acpi_handle handle, u32 event, void *data)
684 case ACPI_BATTERY_NOTIFY_INFO: 865 case ACPI_BATTERY_NOTIFY_INFO:
685 case ACPI_NOTIFY_BUS_CHECK: 866 case ACPI_NOTIFY_BUS_CHECK:
686 case ACPI_NOTIFY_DEVICE_CHECK: 867 case ACPI_NOTIFY_DEVICE_CHECK:
687 acpi_battery_check(battery); 868 device = battery->device;
688 acpi_bus_generate_event(device, event, battery->flags.present); 869 acpi_battery_notify_update(battery);
870 acpi_bus_generate_event(device, event,
871 acpi_battery_present(battery));
689 break; 872 break;
690 default: 873 default:
691 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 874 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -702,7 +885,6 @@ static int acpi_battery_add(struct acpi_device *device)
702 acpi_status status = 0; 885 acpi_status status = 0;
703 struct acpi_battery *battery = NULL; 886 struct acpi_battery *battery = NULL;
704 887
705
706 if (!device) 888 if (!device)
707 return -EINVAL; 889 return -EINVAL;
708 890
@@ -710,15 +892,21 @@ static int acpi_battery_add(struct acpi_device *device)
710 if (!battery) 892 if (!battery)
711 return -ENOMEM; 893 return -ENOMEM;
712 894
895 mutex_init(&battery->mutex);
896
897 mutex_lock(&battery->mutex);
898
713 battery->device = device; 899 battery->device = device;
714 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME); 900 strcpy(acpi_device_name(device), ACPI_BATTERY_DEVICE_NAME);
715 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS); 901 strcpy(acpi_device_class(device), ACPI_BATTERY_CLASS);
716 acpi_driver_data(device) = battery; 902 acpi_driver_data(device) = battery;
717 903
718 result = acpi_battery_check(battery); 904 result = acpi_battery_get_status(battery);
719 if (result) 905 if (result)
720 goto end; 906 goto end;
721 907
908 battery->flags.init_update = 1;
909
722 result = acpi_battery_add_fs(device); 910 result = acpi_battery_add_fs(device);
723 if (result) 911 if (result)
724 goto end; 912 goto end;
@@ -727,6 +915,7 @@ static int acpi_battery_add(struct acpi_device *device)
727 ACPI_ALL_NOTIFY, 915 ACPI_ALL_NOTIFY,
728 acpi_battery_notify, battery); 916 acpi_battery_notify, battery);
729 if (ACPI_FAILURE(status)) { 917 if (ACPI_FAILURE(status)) {
918 ACPI_EXCEPTION((AE_INFO, status, "Installing notify handler"));
730 result = -ENODEV; 919 result = -ENODEV;
731 goto end; 920 goto end;
732 } 921 }
@@ -736,11 +925,14 @@ static int acpi_battery_add(struct acpi_device *device)
736 device->status.battery_present ? "present" : "absent"); 925 device->status.battery_present ? "present" : "absent");
737 926
738 end: 927 end:
928
739 if (result) { 929 if (result) {
740 acpi_battery_remove_fs(device); 930 acpi_battery_remove_fs(device);
741 kfree(battery); 931 kfree(battery);
742 } 932 }
743 933
934 mutex_unlock(&battery->mutex);
935
744 return result; 936 return result;
745} 937}
746 938
@@ -749,18 +941,27 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
749 acpi_status status = 0; 941 acpi_status status = 0;
750 struct acpi_battery *battery = NULL; 942 struct acpi_battery *battery = NULL;
751 943
752
753 if (!device || !acpi_driver_data(device)) 944 if (!device || !acpi_driver_data(device))
754 return -EINVAL; 945 return -EINVAL;
755 946
756 battery = acpi_driver_data(device); 947 battery = acpi_driver_data(device);
757 948
949 mutex_lock(&battery->mutex);
950
758 status = acpi_remove_notify_handler(device->handle, 951 status = acpi_remove_notify_handler(device->handle,
759 ACPI_ALL_NOTIFY, 952 ACPI_ALL_NOTIFY,
760 acpi_battery_notify); 953 acpi_battery_notify);
761 954
762 acpi_battery_remove_fs(device); 955 acpi_battery_remove_fs(device);
763 956
957 kfree(battery->bif_data.pointer);
958
959 kfree(battery->bst_data.pointer);
960
961 mutex_unlock(&battery->mutex);
962
963 mutex_destroy(&battery->mutex);
964
764 kfree(battery); 965 kfree(battery);
765 966
766 return 0; 967 return 0;
@@ -775,7 +976,10 @@ static int acpi_battery_resume(struct acpi_device *device)
775 return -EINVAL; 976 return -EINVAL;
776 977
777 battery = device->driver_data; 978 battery = device->driver_data;
778 return acpi_battery_check(battery); 979
980 battery->flags.init_update = 1;
981
982 return 0;
779} 983}
780 984
781static int __init acpi_battery_init(void) 985static int __init acpi_battery_init(void)
@@ -800,7 +1004,6 @@ static int __init acpi_battery_init(void)
800 1004
801static void __exit acpi_battery_exit(void) 1005static void __exit acpi_battery_exit(void)
802{ 1006{
803
804 acpi_bus_unregister_driver(&acpi_battery_driver); 1007 acpi_bus_unregister_driver(&acpi_battery_driver);
805 1008
806 acpi_unlock_battery_dir(acpi_battery_dir); 1009 acpi_unlock_battery_dir(acpi_battery_dir);
diff --git a/drivers/acpi/bay.c b/drivers/acpi/bay.c
index fb3f31b5e69f..56a5b3fffeb3 100644
--- a/drivers/acpi/bay.c
+++ b/drivers/acpi/bay.c
@@ -288,6 +288,11 @@ static int bay_add(acpi_handle handle, int id)
288 new_bay->pdev = pdev; 288 new_bay->pdev = pdev;
289 platform_set_drvdata(pdev, new_bay); 289 platform_set_drvdata(pdev, new_bay);
290 290
291 /*
292 * we want the bay driver to be able to send uevents
293 */
294 pdev->dev.uevent_suppress = 0;
295
291 if (acpi_bay_add_fs(new_bay)) { 296 if (acpi_bay_add_fs(new_bay)) {
292 platform_device_unregister(new_bay->pdev); 297 platform_device_unregister(new_bay->pdev);
293 goto bay_add_err; 298 goto bay_add_err;
@@ -328,18 +333,12 @@ static void bay_notify(acpi_handle handle, u32 event, void *data)
328{ 333{
329 struct bay *bay_dev = (struct bay *)data; 334 struct bay *bay_dev = (struct bay *)data;
330 struct device *dev = &bay_dev->pdev->dev; 335 struct device *dev = &bay_dev->pdev->dev;
336 char event_string[12];
337 char *envp[] = { event_string, NULL };
331 338
332 bay_dprintk(handle, "Bay event"); 339 bay_dprintk(handle, "Bay event");
333 340 sprintf(event_string, "BAY_EVENT=%d\n", event);
334 switch(event) { 341 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
335 case ACPI_NOTIFY_BUS_CHECK:
336 case ACPI_NOTIFY_DEVICE_CHECK:
337 case ACPI_NOTIFY_EJECT_REQUEST:
338 kobject_uevent(&dev->kobj, KOBJ_CHANGE);
339 break;
340 default:
341 printk(KERN_ERR PREFIX "Bay: unknown event %d\n", event);
342 }
343} 342}
344 343
345static acpi_status 344static acpi_status
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index e5084ececb6f..6b2658c96242 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -292,6 +292,10 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
292 if (!device) 292 if (!device)
293 return -EINVAL; 293 return -EINVAL;
294 294
295 if (acpi_bus_generate_genetlink_event(device, type, data))
296 printk(KERN_WARNING PREFIX
297 "Failed to generate an ACPI event via genetlink!\n");
298
295 /* drop event on the floor if no one's listening */ 299 /* drop event on the floor if no one's listening */
296 if (!event_is_open) 300 if (!event_is_open)
297 return 0; 301 return 0;
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 4546bf873aea..6192c8be66df 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -40,8 +40,15 @@ MODULE_AUTHOR("Kristen Carlson Accardi");
40MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION); 40MODULE_DESCRIPTION(ACPI_DOCK_DRIVER_DESCRIPTION);
41MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
42 42
43static int immediate_undock = 1;
44module_param(immediate_undock, bool, 0644);
45MODULE_PARM_DESC(immediate_undock, "1 (default) will cause the driver to "
46 "undock immediately when the undock button is pressed, 0 will cause"
47 " the driver to wait for userspace to write the undock sysfs file "
48 " before undocking");
49
43static struct atomic_notifier_head dock_notifier_list; 50static struct atomic_notifier_head dock_notifier_list;
44static struct platform_device dock_device; 51static struct platform_device *dock_device;
45static char dock_device_name[] = "dock"; 52static char dock_device_name[] = "dock";
46 53
47struct dock_station { 54struct dock_station {
@@ -63,6 +70,7 @@ struct dock_dependent_device {
63}; 70};
64 71
65#define DOCK_DOCKING 0x00000001 72#define DOCK_DOCKING 0x00000001
73#define DOCK_UNDOCKING 0x00000002
66#define DOCK_EVENT 3 74#define DOCK_EVENT 3
67#define UNDOCK_EVENT 2 75#define UNDOCK_EVENT 2
68 76
@@ -327,12 +335,20 @@ static void hotplug_dock_devices(struct dock_station *ds, u32 event)
327 335
328static void dock_event(struct dock_station *ds, u32 event, int num) 336static void dock_event(struct dock_station *ds, u32 event, int num)
329{ 337{
330 struct device *dev = &dock_device.dev; 338 struct device *dev = &dock_device->dev;
339 char event_string[7];
340 char *envp[] = { event_string, NULL };
341
342 if (num == UNDOCK_EVENT)
343 sprintf(event_string, "UNDOCK");
344 else
345 sprintf(event_string, "DOCK");
346
331 /* 347 /*
332 * Indicate that the status of the dock station has 348 * Indicate that the status of the dock station has
333 * changed. 349 * changed.
334 */ 350 */
335 kobject_uevent(&dev->kobj, KOBJ_CHANGE); 351 kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, envp);
336} 352}
337 353
338/** 354/**
@@ -380,12 +396,11 @@ static void handle_dock(struct dock_station *ds, int dock)
380 union acpi_object arg; 396 union acpi_object arg;
381 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 397 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
382 struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 398 struct acpi_buffer name_buffer = { ACPI_ALLOCATE_BUFFER, NULL };
383 union acpi_object *obj;
384 399
385 acpi_get_name(ds->handle, ACPI_FULL_PATHNAME, &name_buffer); 400 acpi_get_name(ds->handle, ACPI_FULL_PATHNAME, &name_buffer);
386 obj = name_buffer.pointer;
387 401
388 printk(KERN_INFO PREFIX "%s\n", dock ? "docking" : "undocking"); 402 printk(KERN_INFO PREFIX "%s - %s\n",
403 (char *)name_buffer.pointer, dock ? "docking" : "undocking");
389 404
390 /* _DCK method has one argument */ 405 /* _DCK method has one argument */
391 arg_list.count = 1; 406 arg_list.count = 1;
@@ -394,7 +409,8 @@ static void handle_dock(struct dock_station *ds, int dock)
394 arg.integer.value = dock; 409 arg.integer.value = dock;
395 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer); 410 status = acpi_evaluate_object(ds->handle, "_DCK", &arg_list, &buffer);
396 if (ACPI_FAILURE(status)) 411 if (ACPI_FAILURE(status))
397 pr_debug("%s: failed to execute _DCK\n", obj->string.pointer); 412 printk(KERN_ERR PREFIX "%s - failed to execute _DCK\n",
413 (char *)name_buffer.pointer);
398 kfree(buffer.pointer); 414 kfree(buffer.pointer);
399 kfree(name_buffer.pointer); 415 kfree(name_buffer.pointer);
400} 416}
@@ -420,6 +436,16 @@ static inline void complete_dock(struct dock_station *ds)
420 ds->last_dock_time = jiffies; 436 ds->last_dock_time = jiffies;
421} 437}
422 438
439static inline void begin_undock(struct dock_station *ds)
440{
441 ds->flags |= DOCK_UNDOCKING;
442}
443
444static inline void complete_undock(struct dock_station *ds)
445{
446 ds->flags &= ~(DOCK_UNDOCKING);
447}
448
423/** 449/**
424 * dock_in_progress - see if we are in the middle of handling a dock event 450 * dock_in_progress - see if we are in the middle of handling a dock event
425 * @ds: the dock station 451 * @ds: the dock station
@@ -550,7 +576,7 @@ static int handle_eject_request(struct dock_station *ds, u32 event)
550 printk(KERN_ERR PREFIX "Unable to undock!\n"); 576 printk(KERN_ERR PREFIX "Unable to undock!\n");
551 return -EBUSY; 577 return -EBUSY;
552 } 578 }
553 579 complete_undock(ds);
554 return 0; 580 return 0;
555} 581}
556 582
@@ -594,7 +620,11 @@ static void dock_notify(acpi_handle handle, u32 event, void *data)
594 * to the driver who wish to hotplug. 620 * to the driver who wish to hotplug.
595 */ 621 */
596 case ACPI_NOTIFY_EJECT_REQUEST: 622 case ACPI_NOTIFY_EJECT_REQUEST:
597 handle_eject_request(ds, event); 623 begin_undock(ds);
624 if (immediate_undock)
625 handle_eject_request(ds, event);
626 else
627 dock_event(ds, event, UNDOCK_EVENT);
598 break; 628 break;
599 default: 629 default:
600 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event); 630 printk(KERN_ERR PREFIX "Unknown dock event %d\n", event);
@@ -653,6 +683,17 @@ static ssize_t show_docked(struct device *dev,
653DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL); 683DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
654 684
655/* 685/*
686 * show_flags - read method for flags file in sysfs
687 */
688static ssize_t show_flags(struct device *dev,
689 struct device_attribute *attr, char *buf)
690{
691 return snprintf(buf, PAGE_SIZE, "%d\n", dock_station->flags);
692
693}
694DEVICE_ATTR(flags, S_IRUGO, show_flags, NULL);
695
696/*
656 * write_undock - write method for "undock" file in sysfs 697 * write_undock - write method for "undock" file in sysfs
657 */ 698 */
658static ssize_t write_undock(struct device *dev, struct device_attribute *attr, 699static ssize_t write_undock(struct device *dev, struct device_attribute *attr,
@@ -675,16 +716,15 @@ static ssize_t show_dock_uid(struct device *dev,
675 struct device_attribute *attr, char *buf) 716 struct device_attribute *attr, char *buf)
676{ 717{
677 unsigned long lbuf; 718 unsigned long lbuf;
678 acpi_status status = acpi_evaluate_integer(dock_station->handle, "_UID", NULL, &lbuf); 719 acpi_status status = acpi_evaluate_integer(dock_station->handle,
679 if(ACPI_FAILURE(status)) { 720 "_UID", NULL, &lbuf);
721 if (ACPI_FAILURE(status))
680 return 0; 722 return 0;
681 } 723
682 return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf); 724 return snprintf(buf, PAGE_SIZE, "%lx\n", lbuf);
683} 725}
684DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL); 726DEVICE_ATTR(uid, S_IRUGO, show_dock_uid, NULL);
685 727
686
687
688/** 728/**
689 * dock_add - add a new dock station 729 * dock_add - add a new dock station
690 * @handle: the dock station handle 730 * @handle: the dock station handle
@@ -711,33 +751,53 @@ static int dock_add(acpi_handle handle)
711 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list); 751 ATOMIC_INIT_NOTIFIER_HEAD(&dock_notifier_list);
712 752
713 /* initialize platform device stuff */ 753 /* initialize platform device stuff */
714 dock_device.name = dock_device_name; 754 dock_device =
715 ret = platform_device_register(&dock_device); 755 platform_device_register_simple(dock_device_name, 0, NULL, 0);
756 if (IS_ERR(dock_device)) {
757 kfree(dock_station);
758 dock_station = NULL;
759 return PTR_ERR(dock_device);
760 }
761
762 /* we want the dock device to send uevents */
763 dock_device->dev.uevent_suppress = 0;
764
765 ret = device_create_file(&dock_device->dev, &dev_attr_docked);
716 if (ret) { 766 if (ret) {
717 printk(KERN_ERR PREFIX "Error %d registering dock device\n", ret); 767 printk("Error %d adding sysfs file\n", ret);
768 platform_device_unregister(dock_device);
718 kfree(dock_station); 769 kfree(dock_station);
770 dock_station = NULL;
719 return ret; 771 return ret;
720 } 772 }
721 ret = device_create_file(&dock_device.dev, &dev_attr_docked); 773 ret = device_create_file(&dock_device->dev, &dev_attr_undock);
722 if (ret) { 774 if (ret) {
723 printk("Error %d adding sysfs file\n", ret); 775 printk("Error %d adding sysfs file\n", ret);
724 platform_device_unregister(&dock_device); 776 device_remove_file(&dock_device->dev, &dev_attr_docked);
777 platform_device_unregister(dock_device);
725 kfree(dock_station); 778 kfree(dock_station);
779 dock_station = NULL;
726 return ret; 780 return ret;
727 } 781 }
728 ret = device_create_file(&dock_device.dev, &dev_attr_undock); 782 ret = device_create_file(&dock_device->dev, &dev_attr_uid);
729 if (ret) { 783 if (ret) {
730 printk("Error %d adding sysfs file\n", ret); 784 printk("Error %d adding sysfs file\n", ret);
731 device_remove_file(&dock_device.dev, &dev_attr_docked); 785 device_remove_file(&dock_device->dev, &dev_attr_docked);
732 platform_device_unregister(&dock_device); 786 device_remove_file(&dock_device->dev, &dev_attr_undock);
787 platform_device_unregister(dock_device);
733 kfree(dock_station); 788 kfree(dock_station);
789 dock_station = NULL;
734 return ret; 790 return ret;
735 } 791 }
736 ret = device_create_file(&dock_device.dev, &dev_attr_uid); 792 ret = device_create_file(&dock_device->dev, &dev_attr_flags);
737 if (ret) { 793 if (ret) {
738 printk("Error %d adding sysfs file\n", ret); 794 printk("Error %d adding sysfs file\n", ret);
739 platform_device_unregister(&dock_device); 795 device_remove_file(&dock_device->dev, &dev_attr_docked);
796 device_remove_file(&dock_device->dev, &dev_attr_undock);
797 device_remove_file(&dock_device->dev, &dev_attr_uid);
798 platform_device_unregister(dock_device);
740 kfree(dock_station); 799 kfree(dock_station);
800 dock_station = NULL;
741 return ret; 801 return ret;
742 } 802 }
743 803
@@ -750,6 +810,7 @@ static int dock_add(acpi_handle handle)
750 dd = alloc_dock_dependent_device(handle); 810 dd = alloc_dock_dependent_device(handle);
751 if (!dd) { 811 if (!dd) {
752 kfree(dock_station); 812 kfree(dock_station);
813 dock_station = NULL;
753 ret = -ENOMEM; 814 ret = -ENOMEM;
754 goto dock_add_err_unregister; 815 goto dock_add_err_unregister;
755 } 816 }
@@ -773,10 +834,13 @@ static int dock_add(acpi_handle handle)
773dock_add_err: 834dock_add_err:
774 kfree(dd); 835 kfree(dd);
775dock_add_err_unregister: 836dock_add_err_unregister:
776 device_remove_file(&dock_device.dev, &dev_attr_docked); 837 device_remove_file(&dock_device->dev, &dev_attr_docked);
777 device_remove_file(&dock_device.dev, &dev_attr_undock); 838 device_remove_file(&dock_device->dev, &dev_attr_undock);
778 platform_device_unregister(&dock_device); 839 device_remove_file(&dock_device->dev, &dev_attr_uid);
840 device_remove_file(&dock_device->dev, &dev_attr_flags);
841 platform_device_unregister(dock_device);
779 kfree(dock_station); 842 kfree(dock_station);
843 dock_station = NULL;
780 return ret; 844 return ret;
781} 845}
782 846
@@ -804,12 +868,15 @@ static int dock_remove(void)
804 printk(KERN_ERR "Error removing notify handler\n"); 868 printk(KERN_ERR "Error removing notify handler\n");
805 869
806 /* cleanup sysfs */ 870 /* cleanup sysfs */
807 device_remove_file(&dock_device.dev, &dev_attr_docked); 871 device_remove_file(&dock_device->dev, &dev_attr_docked);
808 device_remove_file(&dock_device.dev, &dev_attr_undock); 872 device_remove_file(&dock_device->dev, &dev_attr_undock);
809 platform_device_unregister(&dock_device); 873 device_remove_file(&dock_device->dev, &dev_attr_uid);
874 device_remove_file(&dock_device->dev, &dev_attr_flags);
875 platform_device_unregister(dock_device);
810 876
811 /* free dock station memory */ 877 /* free dock station memory */
812 kfree(dock_station); 878 kfree(dock_station);
879 dock_station = NULL;
813 return 0; 880 return 0;
814} 881}
815 882
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 82f496c07675..10e851021eca 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -34,25 +34,26 @@
34#include <linux/proc_fs.h> 34#include <linux/proc_fs.h>
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/list.h>
37#include <asm/io.h> 38#include <asm/io.h>
38#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
39#include <acpi/acpi_drivers.h> 40#include <acpi/acpi_drivers.h>
40#include <acpi/actypes.h> 41#include <acpi/actypes.h>
41 42
42#define _COMPONENT ACPI_EC_COMPONENT
43ACPI_MODULE_NAME("ec");
44#define ACPI_EC_COMPONENT 0x00100000
45#define ACPI_EC_CLASS "embedded_controller" 43#define ACPI_EC_CLASS "embedded_controller"
46#define ACPI_EC_HID "PNP0C09" 44#define ACPI_EC_HID "PNP0C09"
47#define ACPI_EC_DEVICE_NAME "Embedded Controller" 45#define ACPI_EC_DEVICE_NAME "Embedded Controller"
48#define ACPI_EC_FILE_INFO "info" 46#define ACPI_EC_FILE_INFO "info"
47
49#undef PREFIX 48#undef PREFIX
50#define PREFIX "ACPI: EC: " 49#define PREFIX "ACPI: EC: "
50
51/* EC status register */ 51/* EC status register */
52#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */ 52#define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
53#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */ 53#define ACPI_EC_FLAG_IBF 0x02 /* Input buffer full */
54#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */ 54#define ACPI_EC_FLAG_BURST 0x10 /* burst mode */
55#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */ 55#define ACPI_EC_FLAG_SCI 0x20 /* EC-SCI occurred */
56
56/* EC commands */ 57/* EC commands */
57enum ec_command { 58enum ec_command {
58 ACPI_EC_COMMAND_READ = 0x80, 59 ACPI_EC_COMMAND_READ = 0x80,
@@ -61,6 +62,7 @@ enum ec_command {
61 ACPI_EC_BURST_DISABLE = 0x83, 62 ACPI_EC_BURST_DISABLE = 0x83,
62 ACPI_EC_COMMAND_QUERY = 0x84, 63 ACPI_EC_COMMAND_QUERY = 0x84,
63}; 64};
65
64/* EC events */ 66/* EC events */
65enum ec_event { 67enum ec_event {
66 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */ 68 ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
@@ -94,6 +96,16 @@ static struct acpi_driver acpi_ec_driver = {
94 96
95/* If we find an EC via the ECDT, we need to keep a ptr to its context */ 97/* If we find an EC via the ECDT, we need to keep a ptr to its context */
96/* External interfaces use first EC only, so remember */ 98/* External interfaces use first EC only, so remember */
99typedef int (*acpi_ec_query_func) (void *data);
100
101struct acpi_ec_query_handler {
102 struct list_head node;
103 acpi_ec_query_func func;
104 acpi_handle handle;
105 void *data;
106 u8 query_bit;
107};
108
97static struct acpi_ec { 109static struct acpi_ec {
98 acpi_handle handle; 110 acpi_handle handle;
99 unsigned long gpe; 111 unsigned long gpe;
@@ -104,6 +116,7 @@ static struct acpi_ec {
104 atomic_t query_pending; 116 atomic_t query_pending;
105 atomic_t event_count; 117 atomic_t event_count;
106 wait_queue_head_t wait; 118 wait_queue_head_t wait;
119 struct list_head list;
107} *boot_ec, *first_ec; 120} *boot_ec, *first_ec;
108 121
109/* -------------------------------------------------------------------------- 122/* --------------------------------------------------------------------------
@@ -245,7 +258,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
245 258
246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0); 259 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0);
247 if (status) { 260 if (status) {
248 printk(KERN_DEBUG PREFIX 261 printk(KERN_ERR PREFIX
249 "input buffer is not empty, aborting transaction\n"); 262 "input buffer is not empty, aborting transaction\n");
250 goto end; 263 goto end;
251 } 264 }
@@ -394,21 +407,67 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
394/* -------------------------------------------------------------------------- 407/* --------------------------------------------------------------------------
395 Event Management 408 Event Management
396 -------------------------------------------------------------------------- */ 409 -------------------------------------------------------------------------- */
410int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
411 acpi_handle handle, acpi_ec_query_func func,
412 void *data)
413{
414 struct acpi_ec_query_handler *handler =
415 kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
416 if (!handler)
417 return -ENOMEM;
418
419 handler->query_bit = query_bit;
420 handler->handle = handle;
421 handler->func = func;
422 handler->data = data;
423 mutex_lock(&ec->lock);
424 list_add_tail(&handler->node, &ec->list);
425 mutex_unlock(&ec->lock);
426 return 0;
427}
428
429EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
430
431void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
432{
433 struct acpi_ec_query_handler *handler;
434 mutex_lock(&ec->lock);
435 list_for_each_entry(handler, &ec->list, node) {
436 if (query_bit == handler->query_bit) {
437 list_del(&handler->node);
438 kfree(handler);
439 break;
440 }
441 }
442 mutex_unlock(&ec->lock);
443}
444
445EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
397 446
398static void acpi_ec_gpe_query(void *ec_cxt) 447static void acpi_ec_gpe_query(void *ec_cxt)
399{ 448{
400 struct acpi_ec *ec = ec_cxt; 449 struct acpi_ec *ec = ec_cxt;
401 u8 value = 0; 450 u8 value = 0;
402 char object_name[8]; 451 struct acpi_ec_query_handler *handler, copy;
403 452
404 if (!ec || acpi_ec_query(ec, &value)) 453 if (!ec || acpi_ec_query(ec, &value))
405 return; 454 return;
406 455 mutex_lock(&ec->lock);
407 snprintf(object_name, 8, "_Q%2.2X", value); 456 list_for_each_entry(handler, &ec->list, node) {
408 457 if (value == handler->query_bit) {
409 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Evaluating %s", object_name)); 458 /* have custom handler for this bit */
410 459 memcpy(&copy, handler, sizeof(copy));
411 acpi_evaluate_object(ec->handle, object_name, NULL, NULL); 460 mutex_unlock(&ec->lock);
461 if (copy.func) {
462 copy.func(copy.data);
463 } else if (copy.handle) {
464 acpi_evaluate_object(copy.handle, NULL, NULL, NULL);
465 }
466 return;
467 }
468 }
469 mutex_unlock(&ec->lock);
470 printk(KERN_ERR PREFIX "Handler for query 0x%x is not found!\n", value);
412} 471}
413 472
414static u32 acpi_ec_gpe_handler(void *data) 473static u32 acpi_ec_gpe_handler(void *data)
@@ -427,8 +486,7 @@ static u32 acpi_ec_gpe_handler(void *data)
427 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) { 486 if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
428 atomic_set(&ec->query_pending, 1); 487 atomic_set(&ec->query_pending, 1);
429 status = 488 status =
430 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, 489 acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
431 ec);
432 } 490 }
433 491
434 return status == AE_OK ? 492 return status == AE_OK ?
@@ -454,57 +512,35 @@ acpi_ec_space_setup(acpi_handle region_handle,
454} 512}
455 513
456static acpi_status 514static acpi_status
457acpi_ec_space_handler(u32 function, 515acpi_ec_space_handler(u32 function, acpi_physical_address address,
458 acpi_physical_address address, 516 u32 bits, acpi_integer *value,
459 u32 bit_width,
460 acpi_integer * value,
461 void *handler_context, void *region_context) 517 void *handler_context, void *region_context)
462{ 518{
463 int result = 0;
464 struct acpi_ec *ec = handler_context; 519 struct acpi_ec *ec = handler_context;
465 u64 temp = *value; 520 int result = 0, i = 0;
466 acpi_integer f_v = 0; 521 u8 temp = 0;
467 int i = 0;
468 522
469 if ((address > 0xFF) || !value || !handler_context) 523 if ((address > 0xFF) || !value || !handler_context)
470 return AE_BAD_PARAMETER; 524 return AE_BAD_PARAMETER;
471 525
472 if (bit_width != 8 && acpi_strict) { 526 if (function != ACPI_READ && function != ACPI_WRITE)
473 return AE_BAD_PARAMETER; 527 return AE_BAD_PARAMETER;
474 }
475
476 next_byte:
477 switch (function) {
478 case ACPI_READ:
479 temp = 0;
480 result = acpi_ec_read(ec, (u8) address, (u8 *) & temp);
481 break;
482 case ACPI_WRITE:
483 result = acpi_ec_write(ec, (u8) address, (u8) temp);
484 break;
485 default:
486 result = -EINVAL;
487 goto out;
488 break;
489 }
490 528
491 bit_width -= 8; 529 if (bits != 8 && acpi_strict)
492 if (bit_width) { 530 return AE_BAD_PARAMETER;
493 if (function == ACPI_READ)
494 f_v |= temp << 8 * i;
495 if (function == ACPI_WRITE)
496 temp >>= 8;
497 i++;
498 address++;
499 goto next_byte;
500 }
501 531
502 if (function == ACPI_READ) { 532 while (bits - i > 0) {
503 f_v |= temp << 8 * i; 533 if (function == ACPI_READ) {
504 *value = f_v; 534 result = acpi_ec_read(ec, address, &temp);
535 (*value) |= ((acpi_integer)temp) << i;
536 } else {
537 temp = 0xff & ((*value) >> i);
538 result = acpi_ec_write(ec, address, temp);
539 }
540 i += 8;
541 ++address;
505 } 542 }
506 543
507 out:
508 switch (result) { 544 switch (result) {
509 case -EINVAL: 545 case -EINVAL:
510 return AE_BAD_PARAMETER; 546 return AE_BAD_PARAMETER;
@@ -597,9 +633,6 @@ static int acpi_ec_remove_fs(struct acpi_device *device)
597static acpi_status 633static acpi_status
598ec_parse_io_ports(struct acpi_resource *resource, void *context); 634ec_parse_io_ports(struct acpi_resource *resource, void *context);
599 635
600static acpi_status
601ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval);
602
603static struct acpi_ec *make_acpi_ec(void) 636static struct acpi_ec *make_acpi_ec(void)
604{ 637{
605 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL); 638 struct acpi_ec *ec = kzalloc(sizeof(struct acpi_ec), GFP_KERNEL);
@@ -610,13 +643,52 @@ static struct acpi_ec *make_acpi_ec(void)
610 atomic_set(&ec->event_count, 1); 643 atomic_set(&ec->event_count, 1);
611 mutex_init(&ec->lock); 644 mutex_init(&ec->lock);
612 init_waitqueue_head(&ec->wait); 645 init_waitqueue_head(&ec->wait);
646 INIT_LIST_HEAD(&ec->list);
613 647
614 return ec; 648 return ec;
615} 649}
616 650
651static acpi_status
652acpi_ec_register_query_methods(acpi_handle handle, u32 level,
653 void *context, void **return_value)
654{
655 struct acpi_namespace_node *node = handle;
656 struct acpi_ec *ec = context;
657 int value = 0;
658 if (sscanf(node->name.ascii, "_Q%x", &value) == 1) {
659 acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
660 }
661 return AE_OK;
662}
663
664static int ec_parse_device(struct acpi_ec *ec, acpi_handle handle)
665{
666 if (ACPI_FAILURE(acpi_walk_resources(handle, METHOD_NAME__CRS,
667 ec_parse_io_ports, ec)))
668 return -EINVAL;
669
670 /* Get GPE bit assignment (EC events). */
671 /* TODO: Add support for _GPE returning a package */
672 if (ACPI_FAILURE(acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe)))
673 return -EINVAL;
674
675 /* Use the global lock for all EC transactions? */
676 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
677
678 /* Find and register all query methods */
679 acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1,
680 acpi_ec_register_query_methods, ec, NULL);
681
682 ec->handle = handle;
683
684 printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx",
685 ec->gpe, ec->command_addr, ec->data_addr);
686
687 return 0;
688}
689
617static int acpi_ec_add(struct acpi_device *device) 690static int acpi_ec_add(struct acpi_device *device)
618{ 691{
619 acpi_status status = AE_OK;
620 struct acpi_ec *ec = NULL; 692 struct acpi_ec *ec = NULL;
621 693
622 if (!device) 694 if (!device)
@@ -629,8 +701,7 @@ static int acpi_ec_add(struct acpi_device *device)
629 if (!ec) 701 if (!ec)
630 return -ENOMEM; 702 return -ENOMEM;
631 703
632 status = ec_parse_device(device->handle, 0, ec, NULL); 704 if (ec_parse_device(ec, device->handle)) {
633 if (status != AE_CTRL_TERMINATE) {
634 kfree(ec); 705 kfree(ec);
635 return -EINVAL; 706 return -EINVAL;
636 } 707 }
@@ -641,6 +712,8 @@ static int acpi_ec_add(struct acpi_device *device)
641 /* We might have incorrect info for GL at boot time */ 712 /* We might have incorrect info for GL at boot time */
642 mutex_lock(&boot_ec->lock); 713 mutex_lock(&boot_ec->lock);
643 boot_ec->global_lock = ec->global_lock; 714 boot_ec->global_lock = ec->global_lock;
715 /* Copy handlers from new ec into boot ec */
716 list_splice(&ec->list, &boot_ec->list);
644 mutex_unlock(&boot_ec->lock); 717 mutex_unlock(&boot_ec->lock);
645 kfree(ec); 718 kfree(ec);
646 ec = boot_ec; 719 ec = boot_ec;
@@ -651,22 +724,24 @@ static int acpi_ec_add(struct acpi_device *device)
651 acpi_driver_data(device) = ec; 724 acpi_driver_data(device) = ec;
652 725
653 acpi_ec_add_fs(device); 726 acpi_ec_add_fs(device);
654
655 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "%s [%s] (gpe %d) interrupt mode.",
656 acpi_device_name(device), acpi_device_bid(device),
657 (u32) ec->gpe));
658
659 return 0; 727 return 0;
660} 728}
661 729
662static int acpi_ec_remove(struct acpi_device *device, int type) 730static int acpi_ec_remove(struct acpi_device *device, int type)
663{ 731{
664 struct acpi_ec *ec; 732 struct acpi_ec *ec;
733 struct acpi_ec_query_handler *handler;
665 734
666 if (!device) 735 if (!device)
667 return -EINVAL; 736 return -EINVAL;
668 737
669 ec = acpi_driver_data(device); 738 ec = acpi_driver_data(device);
739 mutex_lock(&ec->lock);
740 list_for_each_entry(handler, &ec->list, node) {
741 list_del(&handler->node);
742 kfree(handler);
743 }
744 mutex_unlock(&ec->lock);
670 acpi_ec_remove_fs(device); 745 acpi_ec_remove_fs(device);
671 acpi_driver_data(device) = NULL; 746 acpi_driver_data(device) = NULL;
672 if (ec == first_ec) 747 if (ec == first_ec)
@@ -722,15 +797,13 @@ static int ec_install_handlers(struct acpi_ec *ec)
722 return -ENODEV; 797 return -ENODEV;
723 } 798 }
724 799
725 /* EC is fully operational, allow queries */
726 atomic_set(&ec->query_pending, 0);
727
728 return 0; 800 return 0;
729} 801}
730 802
731static int acpi_ec_start(struct acpi_device *device) 803static int acpi_ec_start(struct acpi_device *device)
732{ 804{
733 struct acpi_ec *ec; 805 struct acpi_ec *ec;
806 int ret = 0;
734 807
735 if (!device) 808 if (!device)
736 return -EINVAL; 809 return -EINVAL;
@@ -740,14 +813,14 @@ static int acpi_ec_start(struct acpi_device *device)
740 if (!ec) 813 if (!ec)
741 return -EINVAL; 814 return -EINVAL;
742 815
743 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "gpe=0x%02lx, ports=0x%2lx,0x%2lx",
744 ec->gpe, ec->command_addr, ec->data_addr));
745
746 /* Boot EC is already working */ 816 /* Boot EC is already working */
747 if (ec == boot_ec) 817 if (ec != boot_ec)
748 return 0; 818 ret = ec_install_handlers(ec);
819
820 /* EC is fully operational, allow queries */
821 atomic_set(&ec->query_pending, 0);
749 822
750 return ec_install_handlers(ec); 823 return ret;
751} 824}
752 825
753static int acpi_ec_stop(struct acpi_device *device, int type) 826static int acpi_ec_stop(struct acpi_device *device, int type)
@@ -779,34 +852,6 @@ static int acpi_ec_stop(struct acpi_device *device, int type)
779 return 0; 852 return 0;
780} 853}
781 854
782static acpi_status
783ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
784{
785 acpi_status status;
786
787 struct acpi_ec *ec = context;
788 status = acpi_walk_resources(handle, METHOD_NAME__CRS,
789 ec_parse_io_ports, ec);
790 if (ACPI_FAILURE(status))
791 return status;
792
793 /* Get GPE bit assignment (EC events). */
794 /* TODO: Add support for _GPE returning a package */
795 status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe);
796 if (ACPI_FAILURE(status))
797 return status;
798
799 /* Use the global lock for all EC transactions? */
800 acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock);
801
802 ec->handle = handle;
803
804 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "GPE=0x%02lx, ports=0x%2lx, 0x%2lx",
805 ec->gpe, ec->command_addr, ec->data_addr));
806
807 return AE_CTRL_TERMINATE;
808}
809
810int __init acpi_ec_ecdt_probe(void) 855int __init acpi_ec_ecdt_probe(void)
811{ 856{
812 int ret; 857 int ret;
@@ -825,7 +870,7 @@ int __init acpi_ec_ecdt_probe(void)
825 if (ACPI_FAILURE(status)) 870 if (ACPI_FAILURE(status))
826 goto error; 871 goto error;
827 872
828 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found ECDT")); 873 printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n");
829 874
830 boot_ec->command_addr = ecdt_ptr->control.address; 875 boot_ec->command_addr = ecdt_ptr->control.address;
831 boot_ec->data_addr = ecdt_ptr->data.address; 876 boot_ec->data_addr = ecdt_ptr->data.address;
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 3b23562e6f92..dfa5853b17f0 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -11,6 +11,8 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/poll.h> 12#include <linux/poll.h>
13#include <acpi/acpi_drivers.h> 13#include <acpi/acpi_drivers.h>
14#include <net/netlink.h>
15#include <net/genetlink.h>
14 16
15#define _COMPONENT ACPI_SYSTEM_COMPONENT 17#define _COMPONENT ACPI_SYSTEM_COMPONENT
16ACPI_MODULE_NAME("event"); 18ACPI_MODULE_NAME("event");
@@ -48,7 +50,6 @@ acpi_system_read_event(struct file *file, char __user * buffer, size_t count,
48 static int chars_remaining = 0; 50 static int chars_remaining = 0;
49 static char *ptr; 51 static char *ptr;
50 52
51
52 if (!chars_remaining) { 53 if (!chars_remaining) {
53 memset(&event, 0, sizeof(struct acpi_bus_event)); 54 memset(&event, 0, sizeof(struct acpi_bus_event));
54 55
@@ -106,23 +107,161 @@ static const struct file_operations acpi_system_event_ops = {
106 .poll = acpi_system_poll_event, 107 .poll = acpi_system_poll_event,
107}; 108};
108 109
110#ifdef CONFIG_NET
111unsigned int acpi_event_seqnum;
112struct acpi_genl_event {
113 acpi_device_class device_class;
114 char bus_id[15];
115 u32 type;
116 u32 data;
117};
118
119/* attributes of acpi_genl_family */
120enum {
121 ACPI_GENL_ATTR_UNSPEC,
122 ACPI_GENL_ATTR_EVENT, /* ACPI event info needed by user space */
123 __ACPI_GENL_ATTR_MAX,
124};
125#define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1)
126
127/* commands supported by the acpi_genl_family */
128enum {
129 ACPI_GENL_CMD_UNSPEC,
130 ACPI_GENL_CMD_EVENT, /* kernel->user notifications for ACPI events */
131 __ACPI_GENL_CMD_MAX,
132};
133#define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
134
135#define ACPI_GENL_FAMILY_NAME "acpi_event"
136#define ACPI_GENL_VERSION 0x01
137#define ACPI_GENL_MCAST_GROUP_NAME "acpi_mc_group"
138
139static struct genl_family acpi_event_genl_family = {
140 .id = GENL_ID_GENERATE,
141 .name = ACPI_GENL_FAMILY_NAME,
142 .version = ACPI_GENL_VERSION,
143 .maxattr = ACPI_GENL_ATTR_MAX,
144};
145
146static struct genl_multicast_group acpi_event_mcgrp = {
147 .name = ACPI_GENL_MCAST_GROUP_NAME,
148};
149
150int acpi_bus_generate_genetlink_event(struct acpi_device *device,
151 u8 type, int data)
152{
153 struct sk_buff *skb;
154 struct nlattr *attr;
155 struct acpi_genl_event *event;
156 void *msg_header;
157 int size;
158 int result;
159
160 /* allocate memory */
161 size = nla_total_size(sizeof(struct acpi_genl_event)) +
162 nla_total_size(0);
163
164 skb = genlmsg_new(size, GFP_ATOMIC);
165 if (!skb)
166 return -ENOMEM;
167
168 /* add the genetlink message header */
169 msg_header = genlmsg_put(skb, 0, acpi_event_seqnum++,
170 &acpi_event_genl_family, 0,
171 ACPI_GENL_CMD_EVENT);
172 if (!msg_header) {
173 nlmsg_free(skb);
174 return -ENOMEM;
175 }
176
177 /* fill the data */
178 attr =
179 nla_reserve(skb, ACPI_GENL_ATTR_EVENT,
180 sizeof(struct acpi_genl_event));
181 if (!attr) {
182 nlmsg_free(skb);
183 return -EINVAL;
184 }
185
186 event = nla_data(attr);
187 if (!event) {
188 nlmsg_free(skb);
189 return -EINVAL;
190 }
191
192 memset(event, 0, sizeof(struct acpi_genl_event));
193
194 strcpy(event->device_class, device->pnp.device_class);
195 strcpy(event->bus_id, device->dev.bus_id);
196 event->type = type;
197 event->data = data;
198
199 /* send multicast genetlink message */
200 result = genlmsg_end(skb, msg_header);
201 if (result < 0) {
202 nlmsg_free(skb);
203 return result;
204 }
205
206 result =
207 genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
208 if (result)
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
210 "Failed to send a Genetlink message!\n"));
211 return 0;
212}
213
214static int acpi_event_genetlink_init(void)
215{
216 int result;
217
218 result = genl_register_family(&acpi_event_genl_family);
219 if (result)
220 return result;
221
222 result = genl_register_mc_group(&acpi_event_genl_family,
223 &acpi_event_mcgrp);
224 if (result)
225 genl_unregister_family(&acpi_event_genl_family);
226
227 return result;
228}
229
230#else
231int acpi_bus_generate_genetlink_event(struct acpi_device *device, u8 type,
232 int data)
233{
234 return 0;
235}
236
237static int acpi_event_genetlink_init(void)
238{
239 return -ENODEV;
240}
241#endif
242
109static int __init acpi_event_init(void) 243static int __init acpi_event_init(void)
110{ 244{
111 struct proc_dir_entry *entry; 245 struct proc_dir_entry *entry;
112 int error = 0; 246 int error = 0;
113 247
114
115 if (acpi_disabled) 248 if (acpi_disabled)
116 return 0; 249 return 0;
117 250
251 /* create genetlink for acpi event */
252 error = acpi_event_genetlink_init();
253 if (error)
254 printk(KERN_WARNING PREFIX
255 "Failed to create genetlink family for ACPI event\n");
256
118 /* 'event' [R] */ 257 /* 'event' [R] */
119 entry = create_proc_entry("event", S_IRUSR, acpi_root_dir); 258 entry = create_proc_entry("event", S_IRUSR, acpi_root_dir);
120 if (entry) 259 if (entry)
121 entry->proc_fops = &acpi_system_event_ops; 260 entry->proc_fops = &acpi_system_event_ops;
122 else { 261 else
123 error = -ENODEV; 262 return -ENODEV;
124 } 263
125 return error; 264 return 0;
126} 265}
127 266
128subsys_initcall(acpi_event_init); 267fs_initcall(acpi_event_init);
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index 902c287b3a4f..361ebe6c4a6f 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -586,6 +586,10 @@ acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
586 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 586 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
587 if (gpe_xrupt->previous) { 587 if (gpe_xrupt->previous) {
588 gpe_xrupt->previous->next = gpe_xrupt->next; 588 gpe_xrupt->previous->next = gpe_xrupt->next;
589 } else {
590 /* No previous, update list head */
591
592 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
589 } 593 }
590 594
591 if (gpe_xrupt->next) { 595 if (gpe_xrupt->next) {
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index 400d90fca966..23ee7bc4a705 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -284,6 +284,7 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
284 } 284 }
285 285
286 if (!pci_device_node) { 286 if (!pci_device_node) {
287 ACPI_FREE(pci_id);
287 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); 288 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
288 } 289 }
289 290
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 41427a41f620..4893e256e399 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -16,7 +16,7 @@
16#if ACPI_GLUE_DEBUG 16#if ACPI_GLUE_DEBUG
17#define DBG(x...) printk(PREFIX x) 17#define DBG(x...) printk(PREFIX x)
18#else 18#else
19#define DBG(x...) 19#define DBG(x...) do { } while(0)
20#endif 20#endif
21static LIST_HEAD(bus_type_list); 21static LIST_HEAD(bus_type_list);
22static DECLARE_RWSEM(bus_type_sem); 22static DECLARE_RWSEM(bus_type_sem);
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 0c9f15c54e8c..ab04d848b19d 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -36,13 +36,11 @@
36ACPI_MODULE_NAME("numa"); 36ACPI_MODULE_NAME("numa");
37 37
38static nodemask_t nodes_found_map = NODE_MASK_NONE; 38static nodemask_t nodes_found_map = NODE_MASK_NONE;
39#define PXM_INVAL -1
40#define NID_INVAL -1
41 39
42/* maps to convert between proximity domain and logical node ID */ 40/* maps to convert between proximity domain and logical node ID */
43static int pxm_to_node_map[MAX_PXM_DOMAINS] 41static int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS]
44 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL }; 42 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
45static int node_to_pxm_map[MAX_NUMNODES] 43static int __cpuinitdata node_to_pxm_map[MAX_NUMNODES]
46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 44 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
47 45
48int pxm_to_node(int pxm) 46int pxm_to_node(int pxm)
@@ -59,6 +57,12 @@ int node_to_pxm(int node)
59 return node_to_pxm_map[node]; 57 return node_to_pxm_map[node];
60} 58}
61 59
60void __acpi_map_pxm_to_node(int pxm, int node)
61{
62 pxm_to_node_map[pxm] = node;
63 node_to_pxm_map[node] = pxm;
64}
65
62int acpi_map_pxm_to_node(int pxm) 66int acpi_map_pxm_to_node(int pxm)
63{ 67{
64 int node = pxm_to_node_map[pxm]; 68 int node = pxm_to_node_map[pxm];
@@ -67,8 +71,7 @@ int acpi_map_pxm_to_node(int pxm)
67 if (nodes_weight(nodes_found_map) >= MAX_NUMNODES) 71 if (nodes_weight(nodes_found_map) >= MAX_NUMNODES)
68 return NID_INVAL; 72 return NID_INVAL;
69 node = first_unset_node(nodes_found_map); 73 node = first_unset_node(nodes_found_map);
70 pxm_to_node_map[pxm] = node; 74 __acpi_map_pxm_to_node(pxm, node);
71 node_to_pxm_map[node] = pxm;
72 node_set(node, nodes_found_map); 75 node_set(node, nodes_found_map);
73 } 76 }
74 77
@@ -83,7 +86,8 @@ void __cpuinit acpi_unmap_pxm_to_node(int node)
83 node_clear(node, nodes_found_map); 86 node_clear(node, nodes_found_map);
84} 87}
85 88
86void __init acpi_table_print_srat_entry(struct acpi_subtable_header * header) 89static void __init
90acpi_table_print_srat_entry(struct acpi_subtable_header *header)
87{ 91{
88 92
89 ACPI_FUNCTION_NAME("acpi_table_print_srat_entry"); 93 ACPI_FUNCTION_NAME("acpi_table_print_srat_entry");
@@ -200,7 +204,7 @@ static int __init acpi_parse_srat(struct acpi_table_header *table)
200 return 0; 204 return 0;
201} 205}
202 206
203int __init 207static int __init
204acpi_table_parse_srat(enum acpi_srat_type id, 208acpi_table_parse_srat(enum acpi_srat_type id,
205 acpi_table_entry_handler handler, unsigned int max_entries) 209 acpi_table_entry_handler handler, unsigned int max_entries)
206{ 210{
@@ -211,14 +215,13 @@ acpi_table_parse_srat(enum acpi_srat_type id,
211 215
212int __init acpi_numa_init(void) 216int __init acpi_numa_init(void)
213{ 217{
214 int result;
215
216 /* SRAT: Static Resource Affinity Table */ 218 /* SRAT: Static Resource Affinity Table */
217 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) { 219 if (!acpi_table_parse(ACPI_SIG_SRAT, acpi_parse_srat)) {
218 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY, 220 acpi_table_parse_srat(ACPI_SRAT_TYPE_CPU_AFFINITY,
219 acpi_parse_processor_affinity, 221 acpi_parse_processor_affinity, NR_CPUS);
220 NR_CPUS); 222 acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY,
221 result = acpi_table_parse_srat(ACPI_SRAT_TYPE_MEMORY_AFFINITY, acpi_parse_memory_affinity, NR_NODE_MEMBLKS); // IA64 specific 223 acpi_parse_memory_affinity,
224 NR_NODE_MEMBLKS);
222 } 225 }
223 226
224 /* SLIT: System Locality Information Table */ 227 /* SLIT: System Locality Information Table */
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 00d53c2fd1e8..12c09fafce9a 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -77,13 +77,7 @@ static struct workqueue_struct *kacpi_notify_wq;
77#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */ 77#define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
78static char osi_additional_string[OSI_STRING_LENGTH_MAX]; 78static char osi_additional_string[OSI_STRING_LENGTH_MAX];
79 79
80#define OSI_LINUX_ENABLED 80static int osi_linux; /* disable _OSI(Linux) by default */
81#ifdef OSI_LINUX_ENABLED
82int osi_linux = 1; /* enable _OSI(Linux) by default */
83#else
84int osi_linux; /* disable _OSI(Linux) by default */
85#endif
86
87 81
88#ifdef CONFIG_DMI 82#ifdef CONFIG_DMI
89static struct __initdata dmi_system_id acpi_osl_dmi_table[]; 83static struct __initdata dmi_system_id acpi_osl_dmi_table[];
@@ -1183,17 +1177,10 @@ acpi_os_validate_interface (char *interface)
1183 if (!strcmp("Linux", interface)) { 1177 if (!strcmp("Linux", interface)) {
1184 printk(KERN_WARNING PREFIX 1178 printk(KERN_WARNING PREFIX
1185 "System BIOS is requesting _OSI(Linux)\n"); 1179 "System BIOS is requesting _OSI(Linux)\n");
1186#ifdef OSI_LINUX_ENABLED
1187 printk(KERN_WARNING PREFIX
1188 "Please test with \"acpi_osi=!Linux\"\n"
1189 "Please send dmidecode "
1190 "to linux-acpi@vger.kernel.org\n");
1191#else
1192 printk(KERN_WARNING PREFIX 1180 printk(KERN_WARNING PREFIX
1193 "If \"acpi_osi=Linux\" works better,\n" 1181 "If \"acpi_osi=Linux\" works better,\n"
1194 "Please send dmidecode " 1182 "Please send dmidecode "
1195 "to linux-acpi@vger.kernel.org\n"); 1183 "to linux-acpi@vger.kernel.org\n");
1196#endif
1197 if(osi_linux) 1184 if(osi_linux)
1198 return AE_OK; 1185 return AE_OK;
1199 } 1186 }
@@ -1227,36 +1214,14 @@ acpi_os_validate_address (
1227} 1214}
1228 1215
1229#ifdef CONFIG_DMI 1216#ifdef CONFIG_DMI
1230#ifdef OSI_LINUX_ENABLED
1231static int dmi_osi_not_linux(struct dmi_system_id *d)
1232{
1233 printk(KERN_NOTICE "%s detected: requires not _OSI(Linux)\n", d->ident);
1234 enable_osi_linux(0);
1235 return 0;
1236}
1237#else
1238static int dmi_osi_linux(struct dmi_system_id *d) 1217static int dmi_osi_linux(struct dmi_system_id *d)
1239{ 1218{
1240 printk(KERN_NOTICE "%s detected: requires _OSI(Linux)\n", d->ident); 1219 printk(KERN_NOTICE "%s detected: enabling _OSI(Linux)\n", d->ident);
1241 enable_osi_linux(1); 1220 enable_osi_linux(1);
1242 return 0; 1221 return 0;
1243} 1222}
1244#endif
1245 1223
1246static struct dmi_system_id acpi_osl_dmi_table[] __initdata = { 1224static struct dmi_system_id acpi_osl_dmi_table[] __initdata = {
1247#ifdef OSI_LINUX_ENABLED
1248 /*
1249 * Boxes that need NOT _OSI(Linux)
1250 */
1251 {
1252 .callback = dmi_osi_not_linux,
1253 .ident = "Toshiba Satellite P100",
1254 .matches = {
1255 DMI_MATCH(DMI_BOARD_VENDOR, "TOSHIBA"),
1256 DMI_MATCH(DMI_BOARD_NAME, "Satellite P100"),
1257 },
1258 },
1259#else
1260 /* 1225 /*
1261 * Boxes that need _OSI(Linux) 1226 * Boxes that need _OSI(Linux)
1262 */ 1227 */
@@ -1268,7 +1233,6 @@ static struct dmi_system_id acpi_osl_dmi_table[] __initdata = {
1268 DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"), 1233 DMI_MATCH(DMI_BOARD_NAME, "MPAD-MSAE Customer Reference Boards"),
1269 }, 1234 },
1270 }, 1235 },
1271#endif
1272 {} 1236 {}
1273}; 1237};
1274#endif /* CONFIG_DMI */ 1238#endif /* CONFIG_DMI */
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index acc594771379..3448edd61dc4 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -733,7 +733,7 @@ static int acpi_pci_link_add(struct acpi_device *device)
733 /* query and set link->irq.active */ 733 /* query and set link->irq.active */
734 acpi_pci_link_get_current(link); 734 acpi_pci_link_get_current(link);
735 735
736 printk(PREFIX "%s [%s] (IRQs", acpi_device_name(device), 736 printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device),
737 acpi_device_bid(device)); 737 acpi_device_bid(device));
738 for (i = 0; i < link->irq.possible_count; i++) { 738 for (i = 0; i < link->irq.possible_count; i++) {
739 if (link->irq.active == link->irq.possible[i]) { 739 if (link->irq.active == link->irq.possible[i]) {
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index e1ca86dfdd66..81aceb5da7c7 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -66,6 +66,7 @@
66#define ACPI_PROCESSOR_FILE_LIMIT "limit" 66#define ACPI_PROCESSOR_FILE_LIMIT "limit"
67#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 67#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
68#define ACPI_PROCESSOR_NOTIFY_POWER 0x81 68#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
69#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
69 70
70#define ACPI_PROCESSOR_LIMIT_USER 0 71#define ACPI_PROCESSOR_LIMIT_USER 0
71#define ACPI_PROCESSOR_LIMIT_THERMAL 1 72#define ACPI_PROCESSOR_LIMIT_THERMAL 1
@@ -84,6 +85,8 @@ static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
84static void acpi_processor_notify(acpi_handle handle, u32 event, void *data); 85static void acpi_processor_notify(acpi_handle handle, u32 event, void *data);
85static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); 86static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
86static int acpi_processor_handle_eject(struct acpi_processor *pr); 87static int acpi_processor_handle_eject(struct acpi_processor *pr);
88extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
89
87 90
88static struct acpi_driver acpi_processor_driver = { 91static struct acpi_driver acpi_processor_driver = {
89 .name = "processor", 92 .name = "processor",
@@ -696,6 +699,9 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
696 acpi_processor_cst_has_changed(pr); 699 acpi_processor_cst_has_changed(pr);
697 acpi_bus_generate_event(device, event, 0); 700 acpi_bus_generate_event(device, event, 0);
698 break; 701 break;
702 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
703 acpi_processor_tstate_has_changed(pr);
704 acpi_bus_generate_event(device, event, 0);
699 default: 705 default:
700 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 706 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
701 "Unsupported event [0x%x]\n", event)); 707 "Unsupported event [0x%x]\n", event));
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 80ffc7829916..a898991f77cb 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -475,7 +475,7 @@ static void acpi_processor_idle(void)
475 /* Get end time (ticks) */ 475 /* Get end time (ticks) */
476 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 476 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
477 477
478#ifdef CONFIG_GENERIC_TIME 478#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
479 /* TSC halts in C2, so notify users */ 479 /* TSC halts in C2, so notify users */
480 mark_tsc_unstable("possible TSC halt in C2"); 480 mark_tsc_unstable("possible TSC halt in C2");
481#endif 481#endif
@@ -490,7 +490,17 @@ static void acpi_processor_idle(void)
490 490
491 case ACPI_STATE_C3: 491 case ACPI_STATE_C3:
492 492
493 if (pr->flags.bm_check) { 493 /*
494 * disable bus master
495 * bm_check implies we need ARB_DIS
496 * !bm_check implies we need cache flush
497 * bm_control implies whether we can do ARB_DIS
498 *
499 * That leaves a case where bm_check is set and bm_control is
500 * not set. In that case we cannot do much, we enter C3
501 * without doing anything.
502 */
503 if (pr->flags.bm_check && pr->flags.bm_control) {
494 if (atomic_inc_return(&c3_cpu_count) == 504 if (atomic_inc_return(&c3_cpu_count) ==
495 num_online_cpus()) { 505 num_online_cpus()) {
496 /* 506 /*
@@ -499,7 +509,7 @@ static void acpi_processor_idle(void)
499 */ 509 */
500 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1); 510 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
501 } 511 }
502 } else { 512 } else if (!pr->flags.bm_check) {
503 /* SMP with no shared cache... Invalidate cache */ 513 /* SMP with no shared cache... Invalidate cache */
504 ACPI_FLUSH_CPU_CACHE(); 514 ACPI_FLUSH_CPU_CACHE();
505 } 515 }
@@ -511,13 +521,13 @@ static void acpi_processor_idle(void)
511 acpi_cstate_enter(cx); 521 acpi_cstate_enter(cx);
512 /* Get end time (ticks) */ 522 /* Get end time (ticks) */
513 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address); 523 t2 = inl(acpi_gbl_FADT.xpm_timer_block.address);
514 if (pr->flags.bm_check) { 524 if (pr->flags.bm_check && pr->flags.bm_control) {
515 /* Enable bus master arbitration */ 525 /* Enable bus master arbitration */
516 atomic_dec(&c3_cpu_count); 526 atomic_dec(&c3_cpu_count);
517 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); 527 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
518 } 528 }
519 529
520#ifdef CONFIG_GENERIC_TIME 530#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86_TSC)
521 /* TSC halts in C3, so notify users */ 531 /* TSC halts in C3, so notify users */
522 mark_tsc_unstable("TSC halts in C3"); 532 mark_tsc_unstable("TSC halts in C3");
523#endif 533#endif
@@ -961,9 +971,9 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
961 if (pr->flags.bm_check) { 971 if (pr->flags.bm_check) {
962 /* bus mastering control is necessary */ 972 /* bus mastering control is necessary */
963 if (!pr->flags.bm_control) { 973 if (!pr->flags.bm_control) {
974 /* In this case we enter C3 without bus mastering */
964 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 975 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
965 "C3 support requires bus mastering control\n")); 976 "C3 support without bus mastering control\n"));
966 return;
967 } 977 }
968 } else { 978 } else {
969 /* 979 /*
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index b33486009f41..3f55d1f90c11 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -44,17 +44,231 @@
44#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
45ACPI_MODULE_NAME("processor_throttling"); 45ACPI_MODULE_NAME("processor_throttling");
46 46
47static int acpi_processor_get_throttling(struct acpi_processor *pr);
48int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
49
50static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
51{
52 acpi_status status = 0;
53 unsigned long tpc = 0;
54
55 if (!pr)
56 return -EINVAL;
57 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
58 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
59 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
60 return -ENODEV;
61 }
62 pr->throttling_platform_limit = (int)tpc;
63 return 0;
64}
65
66int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
67{
68 return acpi_processor_get_platform_limit(pr);
69}
70
71/* --------------------------------------------------------------------------
72 _PTC, _TSS, _TSD support
73 -------------------------------------------------------------------------- */
74static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
75{
76 int result = 0;
77 acpi_status status = 0;
78 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
79 union acpi_object *ptc = NULL;
80 union acpi_object obj = { 0 };
81
82 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
83 if (ACPI_FAILURE(status)) {
84 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
85 return -ENODEV;
86 }
87
88 ptc = (union acpi_object *)buffer.pointer;
89 if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE)
90 || (ptc->package.count != 2)) {
91 printk(KERN_ERR PREFIX "Invalid _PTC data\n");
92 result = -EFAULT;
93 goto end;
94 }
95
96 /*
97 * control_register
98 */
99
100 obj = ptc->package.elements[0];
101
102 if ((obj.type != ACPI_TYPE_BUFFER)
103 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
104 || (obj.buffer.pointer == NULL)) {
105 printk(KERN_ERR PREFIX
106 "Invalid _PTC data (control_register)\n");
107 result = -EFAULT;
108 goto end;
109 }
110 memcpy(&pr->throttling.control_register, obj.buffer.pointer,
111 sizeof(struct acpi_ptc_register));
112
113 /*
114 * status_register
115 */
116
117 obj = ptc->package.elements[1];
118
119 if ((obj.type != ACPI_TYPE_BUFFER)
120 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
121 || (obj.buffer.pointer == NULL)) {
122 printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
123 result = -EFAULT;
124 goto end;
125 }
126
127 memcpy(&pr->throttling.status_register, obj.buffer.pointer,
128 sizeof(struct acpi_ptc_register));
129
130 end:
131 kfree(buffer.pointer);
132
133 return result;
134}
135static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
136{
137 int result = 0;
138 acpi_status status = AE_OK;
139 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
140 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
141 struct acpi_buffer state = { 0, NULL };
142 union acpi_object *tss = NULL;
143 int i;
144
145 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
146 if (ACPI_FAILURE(status)) {
147 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
148 return -ENODEV;
149 }
150
151 tss = buffer.pointer;
152 if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
153 printk(KERN_ERR PREFIX "Invalid _TSS data\n");
154 result = -EFAULT;
155 goto end;
156 }
157
158 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
159 tss->package.count));
160
161 pr->throttling.state_count = tss->package.count;
162 pr->throttling.states_tss =
163 kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
164 GFP_KERNEL);
165 if (!pr->throttling.states_tss) {
166 result = -ENOMEM;
167 goto end;
168 }
169
170 for (i = 0; i < pr->throttling.state_count; i++) {
171
172 struct acpi_processor_tx_tss *tx =
173 (struct acpi_processor_tx_tss *)&(pr->throttling.
174 states_tss[i]);
175
176 state.length = sizeof(struct acpi_processor_tx_tss);
177 state.pointer = tx;
178
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
180
181 status = acpi_extract_package(&(tss->package.elements[i]),
182 &format, &state);
183 if (ACPI_FAILURE(status)) {
184 ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
185 result = -EFAULT;
186 kfree(pr->throttling.states_tss);
187 goto end;
188 }
189
190 if (!tx->freqpercentage) {
191 printk(KERN_ERR PREFIX
192 "Invalid _TSS data: freq is zero\n");
193 result = -EFAULT;
194 kfree(pr->throttling.states_tss);
195 goto end;
196 }
197 }
198
199 end:
200 kfree(buffer.pointer);
201
202 return result;
203}
204static int acpi_processor_get_tsd(struct acpi_processor *pr)
205{
206 int result = 0;
207 acpi_status status = AE_OK;
208 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
209 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
210 struct acpi_buffer state = { 0, NULL };
211 union acpi_object *tsd = NULL;
212 struct acpi_tsd_package *pdomain;
213
214 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
215 if (ACPI_FAILURE(status)) {
216 return -ENODEV;
217 }
218
219 tsd = buffer.pointer;
220 if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
221 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
222 result = -EFAULT;
223 goto end;
224 }
225
226 if (tsd->package.count != 1) {
227 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
228 result = -EFAULT;
229 goto end;
230 }
231
232 pdomain = &(pr->throttling.domain_info);
233
234 state.length = sizeof(struct acpi_tsd_package);
235 state.pointer = pdomain;
236
237 status = acpi_extract_package(&(tsd->package.elements[0]),
238 &format, &state);
239 if (ACPI_FAILURE(status)) {
240 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
241 result = -EFAULT;
242 goto end;
243 }
244
245 if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
246 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n"));
247 result = -EFAULT;
248 goto end;
249 }
250
251 if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
252 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n"));
253 result = -EFAULT;
254 goto end;
255 }
256
257 end:
258 kfree(buffer.pointer);
259 return result;
260}
261
47/* -------------------------------------------------------------------------- 262/* --------------------------------------------------------------------------
48 Throttling Control 263 Throttling Control
49 -------------------------------------------------------------------------- */ 264 -------------------------------------------------------------------------- */
50static int acpi_processor_get_throttling(struct acpi_processor *pr) 265static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
51{ 266{
52 int state = 0; 267 int state = 0;
53 u32 value = 0; 268 u32 value = 0;
54 u32 duty_mask = 0; 269 u32 duty_mask = 0;
55 u32 duty_value = 0; 270 u32 duty_value = 0;
56 271
57
58 if (!pr) 272 if (!pr)
59 return -EINVAL; 273 return -EINVAL;
60 274
@@ -94,13 +308,115 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
94 return 0; 308 return 0;
95} 309}
96 310
97int acpi_processor_set_throttling(struct acpi_processor *pr, int state) 311static int acpi_read_throttling_status(struct acpi_processor_throttling
312 *throttling)
313{
314 int value = -1;
315 switch (throttling->status_register.space_id) {
316 case ACPI_ADR_SPACE_SYSTEM_IO:
317 acpi_os_read_port((acpi_io_address) throttling->status_register.
318 address, &value,
319 (u32) throttling->status_register.bit_width *
320 8);
321 break;
322 case ACPI_ADR_SPACE_FIXED_HARDWARE:
323 printk(KERN_ERR PREFIX
324 "HARDWARE addr space,NOT supported yet\n");
325 break;
326 default:
327 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
328 (u32) (throttling->status_register.space_id));
329 }
330 return value;
331}
332
333static int acpi_write_throttling_state(struct acpi_processor_throttling
334 *throttling, int value)
335{
336 int ret = -1;
337
338 switch (throttling->control_register.space_id) {
339 case ACPI_ADR_SPACE_SYSTEM_IO:
340 acpi_os_write_port((acpi_io_address) throttling->
341 control_register.address, value,
342 (u32) throttling->control_register.
343 bit_width * 8);
344 ret = 0;
345 break;
346 case ACPI_ADR_SPACE_FIXED_HARDWARE:
347 printk(KERN_ERR PREFIX
348 "HARDWARE addr space,NOT supported yet\n");
349 break;
350 default:
351 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
352 (u32) (throttling->control_register.space_id));
353 }
354 return ret;
355}
356
357static int acpi_get_throttling_state(struct acpi_processor *pr, int value)
358{
359 int i;
360
361 for (i = 0; i < pr->throttling.state_count; i++) {
362 struct acpi_processor_tx_tss *tx =
363 (struct acpi_processor_tx_tss *)&(pr->throttling.
364 states_tss[i]);
365 if (tx->control == value)
366 break;
367 }
368 if (i > pr->throttling.state_count)
369 i = -1;
370 return i;
371}
372
373static int acpi_get_throttling_value(struct acpi_processor *pr, int state)
374{
375 int value = -1;
376 if (state >= 0 && state <= pr->throttling.state_count) {
377 struct acpi_processor_tx_tss *tx =
378 (struct acpi_processor_tx_tss *)&(pr->throttling.
379 states_tss[state]);
380 value = tx->control;
381 }
382 return value;
383}
384
385static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
386{
387 int state = 0;
388 u32 value = 0;
389
390 if (!pr)
391 return -EINVAL;
392
393 if (!pr->flags.throttling)
394 return -ENODEV;
395
396 pr->throttling.state = 0;
397 local_irq_disable();
398 value = acpi_read_throttling_status(&pr->throttling);
399 if (value >= 0) {
400 state = acpi_get_throttling_state(pr, value);
401 pr->throttling.state = state;
402 }
403 local_irq_enable();
404
405 return 0;
406}
407
408static int acpi_processor_get_throttling(struct acpi_processor *pr)
409{
410 return pr->throttling.acpi_processor_get_throttling(pr);
411}
412
413static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
414 int state)
98{ 415{
99 u32 value = 0; 416 u32 value = 0;
100 u32 duty_mask = 0; 417 u32 duty_mask = 0;
101 u32 duty_value = 0; 418 u32 duty_value = 0;
102 419
103
104 if (!pr) 420 if (!pr)
105 return -EINVAL; 421 return -EINVAL;
106 422
@@ -113,6 +429,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
113 if (state == pr->throttling.state) 429 if (state == pr->throttling.state)
114 return 0; 430 return 0;
115 431
432 if (state < pr->throttling_platform_limit)
433 return -EPERM;
116 /* 434 /*
117 * Calculate the duty_value and duty_mask. 435 * Calculate the duty_value and duty_mask.
118 */ 436 */
@@ -165,12 +483,51 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
165 return 0; 483 return 0;
166} 484}
167 485
486static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
487 int state)
488{
489 u32 value = 0;
490
491 if (!pr)
492 return -EINVAL;
493
494 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
495 return -EINVAL;
496
497 if (!pr->flags.throttling)
498 return -ENODEV;
499
500 if (state == pr->throttling.state)
501 return 0;
502
503 if (state < pr->throttling_platform_limit)
504 return -EPERM;
505
506 local_irq_disable();
507
508 value = acpi_get_throttling_value(pr, state);
509 if (value >= 0) {
510 acpi_write_throttling_state(&pr->throttling, value);
511 pr->throttling.state = state;
512 }
513 local_irq_enable();
514
515 return 0;
516}
517
518int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
519{
520 return pr->throttling.acpi_processor_set_throttling(pr, state);
521}
522
168int acpi_processor_get_throttling_info(struct acpi_processor *pr) 523int acpi_processor_get_throttling_info(struct acpi_processor *pr)
169{ 524{
170 int result = 0; 525 int result = 0;
171 int step = 0; 526 int step = 0;
172 int i = 0; 527 int i = 0;
173 528 int no_ptc = 0;
529 int no_tss = 0;
530 int no_tsd = 0;
174 531
175 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 532 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
176 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", 533 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
@@ -182,6 +539,21 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
182 return -EINVAL; 539 return -EINVAL;
183 540
184 /* TBD: Support ACPI 2.0 objects */ 541 /* TBD: Support ACPI 2.0 objects */
542 no_ptc = acpi_processor_get_throttling_control(pr);
543 no_tss = acpi_processor_get_throttling_states(pr);
544 no_tsd = acpi_processor_get_tsd(pr);
545
546 if (no_ptc || no_tss) {
547 pr->throttling.acpi_processor_get_throttling =
548 &acpi_processor_get_throttling_fadt;
549 pr->throttling.acpi_processor_set_throttling =
550 &acpi_processor_set_throttling_fadt;
551 } else {
552 pr->throttling.acpi_processor_get_throttling =
553 &acpi_processor_get_throttling_ptc;
554 pr->throttling.acpi_processor_set_throttling =
555 &acpi_processor_set_throttling_ptc;
556 }
185 557
186 if (!pr->throttling.address) { 558 if (!pr->throttling.address) {
187 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); 559 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
@@ -262,7 +634,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
262 int i = 0; 634 int i = 0;
263 int result = 0; 635 int result = 0;
264 636
265
266 if (!pr) 637 if (!pr)
267 goto end; 638 goto end;
268 639
@@ -280,15 +651,25 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
280 } 651 }
281 652
282 seq_printf(seq, "state count: %d\n" 653 seq_printf(seq, "state count: %d\n"
283 "active state: T%d\n", 654 "active state: T%d\n"
284 pr->throttling.state_count, pr->throttling.state); 655 "state available: T%d to T%d\n",
656 pr->throttling.state_count, pr->throttling.state,
657 pr->throttling_platform_limit,
658 pr->throttling.state_count - 1);
285 659
286 seq_puts(seq, "states:\n"); 660 seq_puts(seq, "states:\n");
287 for (i = 0; i < pr->throttling.state_count; i++) 661 if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt)
288 seq_printf(seq, " %cT%d: %02d%%\n", 662 for (i = 0; i < pr->throttling.state_count; i++)
289 (i == pr->throttling.state ? '*' : ' '), i, 663 seq_printf(seq, " %cT%d: %02d%%\n",
290 (pr->throttling.states[i].performance ? pr-> 664 (i == pr->throttling.state ? '*' : ' '), i,
291 throttling.states[i].performance / 10 : 0)); 665 (pr->throttling.states[i].performance ? pr->
666 throttling.states[i].performance / 10 : 0));
667 else
668 for (i = 0; i < pr->throttling.state_count; i++)
669 seq_printf(seq, " %cT%d: %02d%%\n",
670 (i == pr->throttling.state ? '*' : ' '), i,
671 (int)pr->throttling.states_tss[i].
672 freqpercentage);
292 673
293 end: 674 end:
294 return 0; 675 return 0;
@@ -301,7 +682,7 @@ static int acpi_processor_throttling_open_fs(struct inode *inode,
301 PDE(inode)->data); 682 PDE(inode)->data);
302} 683}
303 684
304static ssize_t acpi_processor_write_throttling(struct file * file, 685static ssize_t acpi_processor_write_throttling(struct file *file,
305 const char __user * buffer, 686 const char __user * buffer,
306 size_t count, loff_t * data) 687 size_t count, loff_t * data)
307{ 688{
@@ -310,7 +691,6 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
310 struct acpi_processor *pr = m->private; 691 struct acpi_processor *pr = m->private;
311 char state_string[12] = { '\0' }; 692 char state_string[12] = { '\0' };
312 693
313
314 if (!pr || (count > sizeof(state_string) - 1)) 694 if (!pr || (count > sizeof(state_string) - 1))
315 return -EINVAL; 695 return -EINVAL;
316 696
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index c1bae106833c..974d00ccfe84 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -127,7 +127,7 @@ static int acpi_sbs_resume(struct acpi_device *device);
127static struct acpi_driver acpi_sbs_driver = { 127static struct acpi_driver acpi_sbs_driver = {
128 .name = "sbs", 128 .name = "sbs",
129 .class = ACPI_SBS_CLASS, 129 .class = ACPI_SBS_CLASS,
130 .ids = ACPI_SBS_HID, 130 .ids = "ACPI0001,ACPI0005",
131 .ops = { 131 .ops = {
132 .add = acpi_sbs_add, 132 .add = acpi_sbs_add,
133 .remove = acpi_sbs_remove, 133 .remove = acpi_sbs_remove,
@@ -176,10 +176,8 @@ struct acpi_battery {
176}; 176};
177 177
178struct acpi_sbs { 178struct acpi_sbs {
179 acpi_handle handle;
180 int base; 179 int base;
181 struct acpi_device *device; 180 struct acpi_device *device;
182 struct acpi_ec_smbus *smbus;
183 struct mutex mutex; 181 struct mutex mutex;
184 int sbsm_present; 182 int sbsm_present;
185 int sbsm_batteries_supported; 183 int sbsm_batteries_supported;
@@ -511,7 +509,7 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
511 "acpi_sbs_read_word() failed")); 509 "acpi_sbs_read_word() failed"));
512 goto end; 510 goto end;
513 } 511 }
514 512 sbs->sbsm_present = 1;
515 sbs->sbsm_batteries_supported = battery_system_info & 0x000f; 513 sbs->sbsm_batteries_supported = battery_system_info & 0x000f;
516 514
517 end: 515 end:
@@ -1630,13 +1628,12 @@ static int acpi_sbs_add(struct acpi_device *device)
1630{ 1628{
1631 struct acpi_sbs *sbs = NULL; 1629 struct acpi_sbs *sbs = NULL;
1632 int result = 0, remove_result = 0; 1630 int result = 0, remove_result = 0;
1633 unsigned long sbs_obj;
1634 int id; 1631 int id;
1635 acpi_status status = AE_OK; 1632 acpi_status status = AE_OK;
1636 unsigned long val; 1633 unsigned long val;
1637 1634
1638 status = 1635 status =
1639 acpi_evaluate_integer(device->parent->handle, "_EC", NULL, &val); 1636 acpi_evaluate_integer(device->handle, "_EC", NULL, &val);
1640 if (ACPI_FAILURE(status)) { 1637 if (ACPI_FAILURE(status)) {
1641 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC")); 1638 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Error obtaining _EC"));
1642 return -EIO; 1639 return -EIO;
@@ -1653,7 +1650,7 @@ static int acpi_sbs_add(struct acpi_device *device)
1653 1650
1654 sbs_mutex_lock(sbs); 1651 sbs_mutex_lock(sbs);
1655 1652
1656 sbs->base = (val & 0xff00ull) >> 8; 1653 sbs->base = 0xff & (val >> 8);
1657 sbs->device = device; 1654 sbs->device = device;
1658 1655
1659 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME); 1656 strcpy(acpi_device_name(device), ACPI_SBS_DEVICE_NAME);
@@ -1665,24 +1662,10 @@ static int acpi_sbs_add(struct acpi_device *device)
1665 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed")); 1662 ACPI_EXCEPTION((AE_INFO, AE_ERROR, "acpi_ac_add() failed"));
1666 goto end; 1663 goto end;
1667 } 1664 }
1668 status = acpi_evaluate_integer(device->handle, "_SBS", NULL, &sbs_obj);
1669 if (status) {
1670 ACPI_EXCEPTION((AE_INFO, status,
1671 "acpi_evaluate_integer() failed"));
1672 result = -EIO;
1673 goto end;
1674 }
1675 if (sbs_obj > 0) {
1676 result = acpi_sbsm_get_info(sbs);
1677 if (result) {
1678 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
1679 "acpi_sbsm_get_info() failed"));
1680 goto end;
1681 }
1682 sbs->sbsm_present = 1;
1683 }
1684 1665
1685 if (sbs->sbsm_present == 0) { 1666 acpi_sbsm_get_info(sbs);
1667
1668 if (!sbs->sbsm_present) {
1686 result = acpi_battery_add(sbs, 0); 1669 result = acpi_battery_add(sbs, 0);
1687 if (result) { 1670 if (result) {
1688 ACPI_EXCEPTION((AE_INFO, AE_ERROR, 1671 ACPI_EXCEPTION((AE_INFO, AE_ERROR,
@@ -1702,8 +1685,6 @@ static int acpi_sbs_add(struct acpi_device *device)
1702 } 1685 }
1703 } 1686 }
1704 1687
1705 sbs->handle = device->handle;
1706
1707 init_timer(&sbs->update_timer); 1688 init_timer(&sbs->update_timer);
1708 result = acpi_check_update_proc(sbs); 1689 result = acpi_check_update_proc(sbs);
1709 if (result) 1690 if (result)
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index 42127c0d612c..3279e72a94f8 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -210,11 +210,6 @@ static void acpi_hibernation_finish(void)
210 210
211 /* reset firmware waking vector */ 211 /* reset firmware waking vector */
212 acpi_set_firmware_waking_vector((acpi_physical_address) 0); 212 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
213
214 if (init_8259A_after_S1) {
215 printk("Broken toshiba laptop -> kicking interrupts\n");
216 init_8259A(0);
217 }
218} 213}
219 214
220static int acpi_hibernation_pre_restore(void) 215static int acpi_hibernation_pre_restore(void)
diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index 83a8d3097904..edee2806e37b 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -39,15 +39,12 @@ ACPI_MODULE_NAME("system");
39 39
40#define ACPI_SYSTEM_CLASS "system" 40#define ACPI_SYSTEM_CLASS "system"
41#define ACPI_SYSTEM_DEVICE_NAME "System" 41#define ACPI_SYSTEM_DEVICE_NAME "System"
42#define ACPI_SYSTEM_FILE_INFO "info"
43#define ACPI_SYSTEM_FILE_EVENT "event"
44#define ACPI_SYSTEM_FILE_DSDT "dsdt"
45#define ACPI_SYSTEM_FILE_FADT "fadt"
46 42
47/* 43/*
48 * Make ACPICA version work as module param 44 * Make ACPICA version work as module param
49 */ 45 */
50static int param_get_acpica_version(char *buffer, struct kernel_param *kp) { 46static int param_get_acpica_version(char *buffer, struct kernel_param *kp)
47{
51 int result; 48 int result;
52 49
53 result = sprintf(buffer, "%x", ACPI_CA_VERSION); 50 result = sprintf(buffer, "%x", ACPI_CA_VERSION);
@@ -58,9 +55,126 @@ static int param_get_acpica_version(char *buffer, struct kernel_param *kp) {
58module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444); 55module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
59 56
60/* -------------------------------------------------------------------------- 57/* --------------------------------------------------------------------------
58 FS Interface (/sys)
59 -------------------------------------------------------------------------- */
60static LIST_HEAD(acpi_table_attr_list);
61static struct kobject tables_kobj;
62
63struct acpi_table_attr {
64 struct bin_attribute attr;
65 char name[8];
66 int instance;
67 struct list_head node;
68};
69
70static ssize_t acpi_table_show(struct kobject *kobj,
71 struct bin_attribute *bin_attr, char *buf,
72 loff_t offset, size_t count)
73{
74 struct acpi_table_attr *table_attr =
75 container_of(bin_attr, struct acpi_table_attr, attr);
76 struct acpi_table_header *table_header = NULL;
77 acpi_status status;
78 ssize_t ret_count = count;
79
80 status =
81 acpi_get_table(table_attr->name, table_attr->instance,
82 &table_header);
83 if (ACPI_FAILURE(status))
84 return -ENODEV;
85
86 if (offset >= table_header->length) {
87 ret_count = 0;
88 goto end;
89 }
90
91 if (offset + ret_count > table_header->length)
92 ret_count = table_header->length - offset;
93
94 memcpy(buf, ((char *)table_header) + offset, ret_count);
95
96 end:
97 return ret_count;
98}
99
100static void acpi_table_attr_init(struct acpi_table_attr *table_attr,
101 struct acpi_table_header *table_header)
102{
103 struct acpi_table_header *header = NULL;
104 struct acpi_table_attr *attr = NULL;
105
106 memcpy(table_attr->name, table_header->signature, ACPI_NAME_SIZE);
107
108 list_for_each_entry(attr, &acpi_table_attr_list, node) {
109 if (!memcmp(table_header->signature, attr->name,
110 ACPI_NAME_SIZE))
111 if (table_attr->instance < attr->instance)
112 table_attr->instance = attr->instance;
113 }
114 table_attr->instance++;
115
116 if (table_attr->instance > 1 || (table_attr->instance == 1 &&
117 !acpi_get_table(table_header->
118 signature, 2,
119 &header)))
120 sprintf(table_attr->name + 4, "%d", table_attr->instance);
121
122 table_attr->attr.size = 0;
123 table_attr->attr.read = acpi_table_show;
124 table_attr->attr.attr.name = table_attr->name;
125 table_attr->attr.attr.mode = 0444;
126 table_attr->attr.attr.owner = THIS_MODULE;
127
128 return;
129}
130
131static int acpi_system_sysfs_init(void)
132{
133 struct acpi_table_attr *table_attr;
134 struct acpi_table_header *table_header = NULL;
135 int table_index = 0;
136 int result;
137
138 tables_kobj.parent = &acpi_subsys.kobj;
139 kobject_set_name(&tables_kobj, "tables");
140 result = kobject_register(&tables_kobj);
141 if (result)
142 return result;
143
144 do {
145 result = acpi_get_table_by_index(table_index, &table_header);
146 if (!result) {
147 table_index++;
148 table_attr = NULL;
149 table_attr =
150 kzalloc(sizeof(struct acpi_table_attr), GFP_KERNEL);
151 if (!table_attr)
152 return -ENOMEM;
153
154 acpi_table_attr_init(table_attr, table_header);
155 result =
156 sysfs_create_bin_file(&tables_kobj,
157 &table_attr->attr);
158 if (result) {
159 kfree(table_attr);
160 return result;
161 } else
162 list_add_tail(&table_attr->node,
163 &acpi_table_attr_list);
164 }
165 } while (!result);
166
167 return 0;
168}
169
170/* --------------------------------------------------------------------------
61 FS Interface (/proc) 171 FS Interface (/proc)
62 -------------------------------------------------------------------------- */ 172 -------------------------------------------------------------------------- */
63#ifdef CONFIG_ACPI_PROCFS 173#ifdef CONFIG_ACPI_PROCFS
174#define ACPI_SYSTEM_FILE_INFO "info"
175#define ACPI_SYSTEM_FILE_EVENT "event"
176#define ACPI_SYSTEM_FILE_DSDT "dsdt"
177#define ACPI_SYSTEM_FILE_FADT "fadt"
64 178
65static int acpi_system_read_info(struct seq_file *seq, void *offset) 179static int acpi_system_read_info(struct seq_file *seq, void *offset)
66{ 180{
@@ -80,7 +194,6 @@ static const struct file_operations acpi_system_info_ops = {
80 .llseek = seq_lseek, 194 .llseek = seq_lseek,
81 .release = single_release, 195 .release = single_release,
82}; 196};
83#endif
84 197
85static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t, 198static ssize_t acpi_system_read_dsdt(struct file *, char __user *, size_t,
86 loff_t *); 199 loff_t *);
@@ -97,13 +210,11 @@ acpi_system_read_dsdt(struct file *file,
97 struct acpi_table_header *dsdt = NULL; 210 struct acpi_table_header *dsdt = NULL;
98 ssize_t res; 211 ssize_t res;
99 212
100
101 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt); 213 status = acpi_get_table(ACPI_SIG_DSDT, 1, &dsdt);
102 if (ACPI_FAILURE(status)) 214 if (ACPI_FAILURE(status))
103 return -ENODEV; 215 return -ENODEV;
104 216
105 res = simple_read_from_buffer(buffer, count, ppos, 217 res = simple_read_from_buffer(buffer, count, ppos, dsdt, dsdt->length);
106 dsdt, dsdt->length);
107 218
108 return res; 219 return res;
109} 220}
@@ -123,28 +234,21 @@ acpi_system_read_fadt(struct file *file,
123 struct acpi_table_header *fadt = NULL; 234 struct acpi_table_header *fadt = NULL;
124 ssize_t res; 235 ssize_t res;
125 236
126
127 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt); 237 status = acpi_get_table(ACPI_SIG_FADT, 1, &fadt);
128 if (ACPI_FAILURE(status)) 238 if (ACPI_FAILURE(status))
129 return -ENODEV; 239 return -ENODEV;
130 240
131 res = simple_read_from_buffer(buffer, count, ppos, 241 res = simple_read_from_buffer(buffer, count, ppos, fadt, fadt->length);
132 fadt, fadt->length);
133 242
134 return res; 243 return res;
135} 244}
136 245
137static int __init acpi_system_init(void) 246static int acpi_system_procfs_init(void)
138{ 247{
139 struct proc_dir_entry *entry; 248 struct proc_dir_entry *entry;
140 int error = 0; 249 int error = 0;
141 char *name; 250 char *name;
142 251
143
144 if (acpi_disabled)
145 return 0;
146
147#ifdef CONFIG_ACPI_PROCFS
148 /* 'info' [R] */ 252 /* 'info' [R] */
149 name = ACPI_SYSTEM_FILE_INFO; 253 name = ACPI_SYSTEM_FILE_INFO;
150 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir); 254 entry = create_proc_entry(name, S_IRUGO, acpi_root_dir);
@@ -153,7 +257,6 @@ static int __init acpi_system_init(void)
153 else { 257 else {
154 entry->proc_fops = &acpi_system_info_ops; 258 entry->proc_fops = &acpi_system_info_ops;
155 } 259 }
156#endif
157 260
158 /* 'dsdt' [R] */ 261 /* 'dsdt' [R] */
159 name = ACPI_SYSTEM_FILE_DSDT; 262 name = ACPI_SYSTEM_FILE_DSDT;
@@ -177,12 +280,32 @@ static int __init acpi_system_init(void)
177 Error: 280 Error:
178 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir); 281 remove_proc_entry(ACPI_SYSTEM_FILE_FADT, acpi_root_dir);
179 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir); 282 remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_root_dir);
180#ifdef CONFIG_ACPI_PROCFS
181 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir); 283 remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_root_dir);
182#endif
183 284
184 error = -EFAULT; 285 error = -EFAULT;
185 goto Done; 286 goto Done;
186} 287}
288#else
289static int acpi_system_procfs_init(void)
290{
291 return 0;
292}
293#endif
294
295static int __init acpi_system_init(void)
296{
297 int result = 0;
298
299 if (acpi_disabled)
300 return 0;
301
302 result = acpi_system_procfs_init();
303 if (result)
304 return result;
305
306 result = acpi_system_sysfs_init();
307
308 return result;
309}
187 310
188subsys_initcall(acpi_system_init); 311subsys_initcall(acpi_system_init);
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index 1285e91474fb..002bb33003af 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -211,14 +211,17 @@ void acpi_tb_parse_fadt(acpi_native_uint table_index, u8 flags)
211 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format. 211 * DESCRIPTION: Get a local copy of the FADT and convert it to a common format.
212 * Performs validation on some important FADT fields. 212 * Performs validation on some important FADT fields.
213 * 213 *
214 * NOTE: We create a local copy of the FADT regardless of the version.
215 *
214 ******************************************************************************/ 216 ******************************************************************************/
215 217
216void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length) 218void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
217{ 219{
218 220
219 /* 221 /*
220 * Check if the FADT is larger than what we know about (ACPI 2.0 version). 222 * Check if the FADT is larger than the largest table that we expect
221 * Truncate the table, but make some noise. 223 * (the ACPI 2.0/3.0 version). If so, truncate the table, and issue
224 * a warning.
222 */ 225 */
223 if (length > sizeof(struct acpi_table_fadt)) { 226 if (length > sizeof(struct acpi_table_fadt)) {
224 ACPI_WARNING((AE_INFO, 227 ACPI_WARNING((AE_INFO,
@@ -227,10 +230,12 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
227 sizeof(struct acpi_table_fadt))); 230 sizeof(struct acpi_table_fadt)));
228 } 231 }
229 232
230 /* Copy the entire FADT locally. Zero first for tb_convert_fadt */ 233 /* Clear the entire local FADT */
231 234
232 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt)); 235 ACPI_MEMSET(&acpi_gbl_FADT, 0, sizeof(struct acpi_table_fadt));
233 236
237 /* Copy the original FADT, up to sizeof (struct acpi_table_fadt) */
238
234 ACPI_MEMCPY(&acpi_gbl_FADT, table, 239 ACPI_MEMCPY(&acpi_gbl_FADT, table,
235 ACPI_MIN(length, sizeof(struct acpi_table_fadt))); 240 ACPI_MIN(length, sizeof(struct acpi_table_fadt)));
236 241
@@ -251,7 +256,7 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
251 * RETURN: None 256 * RETURN: None
252 * 257 *
253 * DESCRIPTION: Converts all versions of the FADT to a common internal format. 258 * DESCRIPTION: Converts all versions of the FADT to a common internal format.
254 * -> Expand all 32-bit addresses to 64-bit. 259 * Expand all 32-bit addresses to 64-bit.
255 * 260 *
256 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt), 261 * NOTE: acpi_gbl_FADT must be of size (struct acpi_table_fadt),
257 * and must contain a copy of the actual FADT. 262 * and must contain a copy of the actual FADT.
@@ -292,8 +297,23 @@ static void acpi_tb_convert_fadt(void)
292 } 297 }
293 298
294 /* 299 /*
295 * Expand the 32-bit V1.0 addresses to the 64-bit "X" generic address 300 * For ACPI 1.0 FADTs (revision 1 or 2), ensure that reserved fields which
296 * structures as necessary. 301 * should be zero are indeed zero. This will workaround BIOSs that
302 * inadvertently place values in these fields.
303 *
304 * The ACPI 1.0 reserved fields that will be zeroed are the bytes located at
305 * offset 45, 55, 95, and the word located at offset 109, 110.
306 */
307 if (acpi_gbl_FADT.header.revision < 3) {
308 acpi_gbl_FADT.preferred_profile = 0;
309 acpi_gbl_FADT.pstate_control = 0;
310 acpi_gbl_FADT.cst_control = 0;
311 acpi_gbl_FADT.boot_flags = 0;
312 }
313
314 /*
315 * Expand the ACPI 1.0 32-bit V1.0 addresses to the ACPI 2.0 64-bit "X"
316 * generic address structures as necessary.
297 */ 317 */
298 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) { 318 for (i = 0; i < ACPI_FADT_INFO_ENTRIES; i++) {
299 target = 319 target =
@@ -349,18 +369,6 @@ static void acpi_tb_convert_fadt(void)
349 acpi_gbl_FADT.xpm1a_event_block.space_id; 369 acpi_gbl_FADT.xpm1a_event_block.space_id;
350 370
351 } 371 }
352
353 /*
354 * For ACPI 1.0 FADTs, ensure that reserved fields (which should be zero)
355 * are indeed zero. This will workaround BIOSs that inadvertently placed
356 * values in these fields.
357 */
358 if (acpi_gbl_FADT.header.revision < 3) {
359 acpi_gbl_FADT.preferred_profile = 0;
360 acpi_gbl_FADT.pstate_control = 0;
361 acpi_gbl_FADT.cst_control = 0;
362 acpi_gbl_FADT.boot_flags = 0;
363 }
364} 372}
365 373
366/****************************************************************************** 374/******************************************************************************
diff --git a/drivers/acpi/utilities/uteval.c b/drivers/acpi/utilities/uteval.c
index 8ec6f8e48138..f112af433e36 100644
--- a/drivers/acpi/utilities/uteval.c
+++ b/drivers/acpi/utilities/uteval.c
@@ -62,16 +62,13 @@ acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
62static char *acpi_interfaces_supported[] = { 62static char *acpi_interfaces_supported[] = {
63 /* Operating System Vendor Strings */ 63 /* Operating System Vendor Strings */
64 64
65 "Windows 2000", 65 "Windows 2000", /* Windows 2000 */
66 "Windows 2001", 66 "Windows 2001", /* Windows XP */
67 "Windows 2001 SP0", 67 "Windows 2001 SP1", /* Windows XP SP1 */
68 "Windows 2001 SP1", 68 "Windows 2001 SP2", /* Windows XP SP2 */
69 "Windows 2001 SP2", 69 "Windows 2001.1", /* Windows Server 2003 */
70 "Windows 2001 SP3", 70 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */
71 "Windows 2001 SP4", 71 "Windows 2006", /* Windows Vista - Added 03/2006 */
72 "Windows 2001.1",
73 "Windows 2001.1 SP1", /* Added 03/2006 */
74 "Windows 2006", /* Added 03/2006 */
75 72
76 /* Feature Group Strings */ 73 /* Feature Group Strings */
77 74
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 00d25b347255..04ea697f72bf 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -33,6 +33,7 @@
33#include <linux/seq_file.h> 33#include <linux/seq_file.h>
34 34
35#include <linux/backlight.h> 35#include <linux/backlight.h>
36#include <linux/video_output.h>
36#include <asm/uaccess.h> 37#include <asm/uaccess.h>
37 38
38#include <acpi/acpi_bus.h> 39#include <acpi/acpi_bus.h>
@@ -169,6 +170,7 @@ struct acpi_video_device {
169 struct acpi_device *dev; 170 struct acpi_device *dev;
170 struct acpi_video_device_brightness *brightness; 171 struct acpi_video_device_brightness *brightness;
171 struct backlight_device *backlight; 172 struct backlight_device *backlight;
173 struct output_device *output_dev;
172}; 174};
173 175
174/* bus */ 176/* bus */
@@ -272,13 +274,17 @@ static int acpi_video_get_next_level(struct acpi_video_device *device,
272 u32 level_current, u32 event); 274 u32 level_current, u32 event);
273static void acpi_video_switch_brightness(struct acpi_video_device *device, 275static void acpi_video_switch_brightness(struct acpi_video_device *device,
274 int event); 276 int event);
277static int acpi_video_device_get_state(struct acpi_video_device *device,
278 unsigned long *state);
279static int acpi_video_output_get(struct output_device *od);
280static int acpi_video_device_set_state(struct acpi_video_device *device, int state);
275 281
276/*backlight device sysfs support*/ 282/*backlight device sysfs support*/
277static int acpi_video_get_brightness(struct backlight_device *bd) 283static int acpi_video_get_brightness(struct backlight_device *bd)
278{ 284{
279 unsigned long cur_level; 285 unsigned long cur_level;
280 struct acpi_video_device *vd = 286 struct acpi_video_device *vd =
281 (struct acpi_video_device *)class_get_devdata(&bd->class_dev); 287 (struct acpi_video_device *)bl_get_data(bd);
282 acpi_video_device_lcd_get_level_current(vd, &cur_level); 288 acpi_video_device_lcd_get_level_current(vd, &cur_level);
283 return (int) cur_level; 289 return (int) cur_level;
284} 290}
@@ -287,7 +293,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
287{ 293{
288 int request_level = bd->props.brightness; 294 int request_level = bd->props.brightness;
289 struct acpi_video_device *vd = 295 struct acpi_video_device *vd =
290 (struct acpi_video_device *)class_get_devdata(&bd->class_dev); 296 (struct acpi_video_device *)bl_get_data(bd);
291 acpi_video_device_lcd_set_level(vd, request_level); 297 acpi_video_device_lcd_set_level(vd, request_level);
292 return 0; 298 return 0;
293} 299}
@@ -297,6 +303,28 @@ static struct backlight_ops acpi_backlight_ops = {
297 .update_status = acpi_video_set_brightness, 303 .update_status = acpi_video_set_brightness,
298}; 304};
299 305
306/*video output device sysfs support*/
307static int acpi_video_output_get(struct output_device *od)
308{
309 unsigned long state;
310 struct acpi_video_device *vd =
311 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
312 acpi_video_device_get_state(vd, &state);
313 return (int)state;
314}
315
316static int acpi_video_output_set(struct output_device *od)
317{
318 unsigned long state = od->request_state;
319 struct acpi_video_device *vd=
320 (struct acpi_video_device *)class_get_devdata(&od->class_dev);
321 return acpi_video_device_set_state(vd, state);
322}
323
324static struct output_properties acpi_output_properties = {
325 .set_state = acpi_video_output_set,
326 .get_status = acpi_video_output_get,
327};
300/* -------------------------------------------------------------------------- 328/* --------------------------------------------------------------------------
301 Video Management 329 Video Management
302 -------------------------------------------------------------------------- */ 330 -------------------------------------------------------------------------- */
@@ -531,7 +559,6 @@ acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
531 559
532static void acpi_video_device_find_cap(struct acpi_video_device *device) 560static void acpi_video_device_find_cap(struct acpi_video_device *device)
533{ 561{
534 acpi_integer status;
535 acpi_handle h_dummy1; 562 acpi_handle h_dummy1;
536 int i; 563 int i;
537 u32 max_level = 0; 564 u32 max_level = 0;
@@ -565,50 +592,55 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
565 device->cap._DSS = 1; 592 device->cap._DSS = 1;
566 } 593 }
567 594
568 status = acpi_video_device_lcd_query_levels(device, &obj); 595 if (ACPI_SUCCESS(acpi_video_device_lcd_query_levels(device, &obj))) {
569 596
570 if (obj && obj->type == ACPI_TYPE_PACKAGE && obj->package.count >= 2) { 597 if (obj->package.count >= 2) {
571 int count = 0; 598 int count = 0;
572 union acpi_object *o; 599 union acpi_object *o;
573 600
574 br = kzalloc(sizeof(*br), GFP_KERNEL); 601 br = kzalloc(sizeof(*br), GFP_KERNEL);
575 if (!br) { 602 if (!br) {
576 printk(KERN_ERR "can't allocate memory\n"); 603 printk(KERN_ERR "can't allocate memory\n");
577 } else {
578 br->levels = kmalloc(obj->package.count *
579 sizeof *(br->levels), GFP_KERNEL);
580 if (!br->levels)
581 goto out;
582
583 for (i = 0; i < obj->package.count; i++) {
584 o = (union acpi_object *)&obj->package.
585 elements[i];
586 if (o->type != ACPI_TYPE_INTEGER) {
587 printk(KERN_ERR PREFIX "Invalid data\n");
588 continue;
589 }
590 br->levels[count] = (u32) o->integer.value;
591 if (br->levels[count] > max_level)
592 max_level = br->levels[count];
593 count++;
594 }
595 out:
596 if (count < 2) {
597 kfree(br->levels);
598 kfree(br);
599 } else { 604 } else {
600 br->count = count; 605 br->levels = kmalloc(obj->package.count *
601 device->brightness = br; 606 sizeof *(br->levels), GFP_KERNEL);
602 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 607 if (!br->levels)
603 "found %d brightness levels\n", 608 goto out;
604 count)); 609
610 for (i = 0; i < obj->package.count; i++) {
611 o = (union acpi_object *)&obj->package.
612 elements[i];
613 if (o->type != ACPI_TYPE_INTEGER) {
614 printk(KERN_ERR PREFIX "Invalid data\n");
615 continue;
616 }
617 br->levels[count] = (u32) o->integer.value;
618
619 if (br->levels[count] > max_level)
620 max_level = br->levels[count];
621 count++;
622 }
623 out:
624 if (count < 2) {
625 kfree(br->levels);
626 kfree(br);
627 } else {
628 br->count = count;
629 device->brightness = br;
630 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
631 "found %d brightness levels\n",
632 count));
633 }
605 } 634 }
606 } 635 }
636
637 } else {
638 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Could not query available LCD brightness level\n"));
607 } 639 }
608 640
609 kfree(obj); 641 kfree(obj);
610 642
611 if (device->cap._BCL && device->cap._BCM && device->cap._BQC){ 643 if (device->cap._BCL && device->cap._BCM && device->cap._BQC && max_level > 0){
612 unsigned long tmp; 644 unsigned long tmp;
613 static int count = 0; 645 static int count = 0;
614 char *name; 646 char *name;
@@ -626,6 +658,17 @@ static void acpi_video_device_find_cap(struct acpi_video_device *device)
626 658
627 kfree(name); 659 kfree(name);
628 } 660 }
661 if (device->cap._DCS && device->cap._DSS){
662 static int count = 0;
663 char *name;
664 name = kzalloc(MAX_NAME_LEN, GFP_KERNEL);
665 if (!name)
666 return;
667 sprintf(name, "acpi_video%d", count++);
668 device->output_dev = video_output_register(name,
669 NULL, device, &acpi_output_properties);
670 kfree(name);
671 }
629 return; 672 return;
630} 673}
631 674
@@ -1669,6 +1712,7 @@ static int acpi_video_bus_put_one_device(struct acpi_video_device *device)
1669 ACPI_DEVICE_NOTIFY, 1712 ACPI_DEVICE_NOTIFY,
1670 acpi_video_device_notify); 1713 acpi_video_device_notify);
1671 backlight_device_unregister(device->backlight); 1714 backlight_device_unregister(device->backlight);
1715 video_output_unregister(device->output_dev);
1672 return 0; 1716 return 0;
1673} 1717}
1674 1718
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 11e4eb9f304e..06f212ff2b4f 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -99,6 +99,7 @@ enum {
99 HOST_CAP_SSC = (1 << 14), /* Slumber capable */ 99 HOST_CAP_SSC = (1 << 14), /* Slumber capable */
100 HOST_CAP_CLO = (1 << 24), /* Command List Override support */ 100 HOST_CAP_CLO = (1 << 24), /* Command List Override support */
101 HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */ 101 HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */
102 HOST_CAP_SNTF = (1 << 29), /* SNotification register */
102 HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */ 103 HOST_CAP_NCQ = (1 << 30), /* Native Command Queueing */
103 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ 104 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */
104 105
@@ -113,11 +114,11 @@ enum {
113 PORT_TFDATA = 0x20, /* taskfile data */ 114 PORT_TFDATA = 0x20, /* taskfile data */
114 PORT_SIG = 0x24, /* device TF signature */ 115 PORT_SIG = 0x24, /* device TF signature */
115 PORT_CMD_ISSUE = 0x38, /* command issue */ 116 PORT_CMD_ISSUE = 0x38, /* command issue */
116 PORT_SCR = 0x28, /* SATA phy register block */
117 PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */ 117 PORT_SCR_STAT = 0x28, /* SATA phy register: SStatus */
118 PORT_SCR_CTL = 0x2c, /* SATA phy register: SControl */ 118 PORT_SCR_CTL = 0x2c, /* SATA phy register: SControl */
119 PORT_SCR_ERR = 0x30, /* SATA phy register: SError */ 119 PORT_SCR_ERR = 0x30, /* SATA phy register: SError */
120 PORT_SCR_ACT = 0x34, /* SATA phy register: SActive */ 120 PORT_SCR_ACT = 0x34, /* SATA phy register: SActive */
121 PORT_SCR_NTF = 0x3c, /* SATA phy register: SNotification */
121 122
122 /* PORT_IRQ_{STAT,MASK} bits */ 123 /* PORT_IRQ_{STAT,MASK} bits */
123 PORT_IRQ_COLD_PRES = (1 << 31), /* cold presence detect */ 124 PORT_IRQ_COLD_PRES = (1 << 31), /* cold presence detect */
@@ -216,8 +217,8 @@ struct ahci_port_priv {
216 unsigned int ncq_saw_sdb:1; 217 unsigned int ncq_saw_sdb:1;
217}; 218};
218 219
219static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 220static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
220static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 221static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
221static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 222static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
222static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); 223static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
223static void ahci_irq_clear(struct ata_port *ap); 224static void ahci_irq_clear(struct ata_port *ap);
@@ -417,7 +418,10 @@ static const struct pci_device_id ahci_pci_tbl[] = {
417 418
418 /* ATI */ 419 /* ATI */
419 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ 420 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
420 { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb600 }, /* ATI SB700 */ 421 { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb600 }, /* ATI SB700 IDE */
422 { PCI_VDEVICE(ATI, 0x4391), board_ahci_sb600 }, /* ATI SB700 AHCI */
423 { PCI_VDEVICE(ATI, 0x4392), board_ahci_sb600 }, /* ATI SB700 nraid5 */
424 { PCI_VDEVICE(ATI, 0x4393), board_ahci_sb600 }, /* ATI SB700 raid5 */
421 425
422 /* VIA */ 426 /* VIA */
423 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ 427 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */
@@ -545,13 +549,19 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
545 hpriv->saved_cap = cap = readl(mmio + HOST_CAP); 549 hpriv->saved_cap = cap = readl(mmio + HOST_CAP);
546 hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL); 550 hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL);
547 551
548 /* some chips lie about 64bit support */ 552 /* some chips have errata preventing 64bit use */
549 if ((cap & HOST_CAP_64) && (pi->flags & AHCI_FLAG_32BIT_ONLY)) { 553 if ((cap & HOST_CAP_64) && (pi->flags & AHCI_FLAG_32BIT_ONLY)) {
550 dev_printk(KERN_INFO, &pdev->dev, 554 dev_printk(KERN_INFO, &pdev->dev,
551 "controller can't do 64bit DMA, forcing 32bit\n"); 555 "controller can't do 64bit DMA, forcing 32bit\n");
552 cap &= ~HOST_CAP_64; 556 cap &= ~HOST_CAP_64;
553 } 557 }
554 558
559 if ((cap & HOST_CAP_NCQ) && (pi->flags & AHCI_FLAG_NO_NCQ)) {
560 dev_printk(KERN_INFO, &pdev->dev,
561 "controller can't do NCQ, turning off CAP_NCQ\n");
562 cap &= ~HOST_CAP_NCQ;
563 }
564
555 /* fixup zero port_map */ 565 /* fixup zero port_map */
556 if (!port_map) { 566 if (!port_map) {
557 port_map = (1 << ahci_nr_ports(cap)) - 1; 567 port_map = (1 << ahci_nr_ports(cap)) - 1;
@@ -625,38 +635,45 @@ static void ahci_restore_initial_config(struct ata_host *host)
625 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */ 635 (void) readl(mmio + HOST_PORTS_IMPL); /* flush */
626} 636}
627 637
628static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 638static unsigned ahci_scr_offset(struct ata_port *ap, unsigned int sc_reg)
629{ 639{
630 unsigned int sc_reg; 640 static const int offset[] = {
631 641 [SCR_STATUS] = PORT_SCR_STAT,
632 switch (sc_reg_in) { 642 [SCR_CONTROL] = PORT_SCR_CTL,
633 case SCR_STATUS: sc_reg = 0; break; 643 [SCR_ERROR] = PORT_SCR_ERR,
634 case SCR_CONTROL: sc_reg = 1; break; 644 [SCR_ACTIVE] = PORT_SCR_ACT,
635 case SCR_ERROR: sc_reg = 2; break; 645 [SCR_NOTIFICATION] = PORT_SCR_NTF,
636 case SCR_ACTIVE: sc_reg = 3; break; 646 };
637 default: 647 struct ahci_host_priv *hpriv = ap->host->private_data;
638 return 0xffffffffU;
639 }
640 648
641 return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 649 if (sc_reg < ARRAY_SIZE(offset) &&
650 (sc_reg != SCR_NOTIFICATION || (hpriv->cap & HOST_CAP_SNTF)))
651 return offset[sc_reg];
652 return 0;
642} 653}
643 654
644 655static int ahci_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
645static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
646 u32 val)
647{ 656{
648 unsigned int sc_reg; 657 void __iomem *port_mmio = ahci_port_base(ap);
649 658 int offset = ahci_scr_offset(ap, sc_reg);
650 switch (sc_reg_in) { 659
651 case SCR_STATUS: sc_reg = 0; break; 660 if (offset) {
652 case SCR_CONTROL: sc_reg = 1; break; 661 *val = readl(port_mmio + offset);
653 case SCR_ERROR: sc_reg = 2; break; 662 return 0;
654 case SCR_ACTIVE: sc_reg = 3; break;
655 default:
656 return;
657 } 663 }
664 return -EINVAL;
665}
658 666
659 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 667static int ahci_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
668{
669 void __iomem *port_mmio = ahci_port_base(ap);
670 int offset = ahci_scr_offset(ap, sc_reg);
671
672 if (offset) {
673 writel(val, port_mmio + offset);
674 return 0;
675 }
676 return -EINVAL;
660} 677}
661 678
662static void ahci_start_engine(struct ata_port *ap) 679static void ahci_start_engine(struct ata_port *ap)
@@ -948,37 +965,87 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
948 pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16); 965 pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
949} 966}
950 967
951static int ahci_clo(struct ata_port *ap) 968static int ahci_kick_engine(struct ata_port *ap, int force_restart)
952{ 969{
953 void __iomem *port_mmio = ap->ioaddr.cmd_addr; 970 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
954 struct ahci_host_priv *hpriv = ap->host->private_data; 971 struct ahci_host_priv *hpriv = ap->host->private_data;
955 u32 tmp; 972 u32 tmp;
973 int busy, rc;
974
975 /* do we need to kick the port? */
976 busy = ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ);
977 if (!busy && !force_restart)
978 return 0;
979
980 /* stop engine */
981 rc = ahci_stop_engine(ap);
982 if (rc)
983 goto out_restart;
956 984
957 if (!(hpriv->cap & HOST_CAP_CLO)) 985 /* need to do CLO? */
958 return -EOPNOTSUPP; 986 if (!busy) {
987 rc = 0;
988 goto out_restart;
989 }
959 990
991 if (!(hpriv->cap & HOST_CAP_CLO)) {
992 rc = -EOPNOTSUPP;
993 goto out_restart;
994 }
995
996 /* perform CLO */
960 tmp = readl(port_mmio + PORT_CMD); 997 tmp = readl(port_mmio + PORT_CMD);
961 tmp |= PORT_CMD_CLO; 998 tmp |= PORT_CMD_CLO;
962 writel(tmp, port_mmio + PORT_CMD); 999 writel(tmp, port_mmio + PORT_CMD);
963 1000
1001 rc = 0;
964 tmp = ata_wait_register(port_mmio + PORT_CMD, 1002 tmp = ata_wait_register(port_mmio + PORT_CMD,
965 PORT_CMD_CLO, PORT_CMD_CLO, 1, 500); 1003 PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
966 if (tmp & PORT_CMD_CLO) 1004 if (tmp & PORT_CMD_CLO)
967 return -EIO; 1005 rc = -EIO;
968 1006
969 return 0; 1007 /* restart engine */
1008 out_restart:
1009 ahci_start_engine(ap);
1010 return rc;
970} 1011}
971 1012
972static int ahci_softreset(struct ata_port *ap, unsigned int *class, 1013static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
973 unsigned long deadline) 1014 struct ata_taskfile *tf, int is_cmd, u16 flags,
1015 unsigned long timeout_msec)
974{ 1016{
1017 const u32 cmd_fis_len = 5; /* five dwords */
975 struct ahci_port_priv *pp = ap->private_data; 1018 struct ahci_port_priv *pp = ap->private_data;
976 void __iomem *port_mmio = ahci_port_base(ap); 1019 void __iomem *port_mmio = ahci_port_base(ap);
977 const u32 cmd_fis_len = 5; /* five dwords */ 1020 u8 *fis = pp->cmd_tbl;
1021 u32 tmp;
1022
1023 /* prep the command */
1024 ata_tf_to_fis(tf, pmp, is_cmd, fis);
1025 ahci_fill_cmd_slot(pp, 0, cmd_fis_len | flags | (pmp << 12));
1026
1027 /* issue & wait */
1028 writel(1, port_mmio + PORT_CMD_ISSUE);
1029
1030 if (timeout_msec) {
1031 tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1,
1032 1, timeout_msec);
1033 if (tmp & 0x1) {
1034 ahci_kick_engine(ap, 1);
1035 return -EBUSY;
1036 }
1037 } else
1038 readl(port_mmio + PORT_CMD_ISSUE); /* flush */
1039
1040 return 0;
1041}
1042
1043static int ahci_do_softreset(struct ata_port *ap, unsigned int *class,
1044 int pmp, unsigned long deadline)
1045{
978 const char *reason = NULL; 1046 const char *reason = NULL;
1047 unsigned long now, msecs;
979 struct ata_taskfile tf; 1048 struct ata_taskfile tf;
980 u32 tmp;
981 u8 *fis;
982 int rc; 1049 int rc;
983 1050
984 DPRINTK("ENTER\n"); 1051 DPRINTK("ENTER\n");
@@ -990,43 +1057,22 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
990 } 1057 }
991 1058
992 /* prepare for SRST (AHCI-1.1 10.4.1) */ 1059 /* prepare for SRST (AHCI-1.1 10.4.1) */
993 rc = ahci_stop_engine(ap); 1060 rc = ahci_kick_engine(ap, 1);
994 if (rc) { 1061 if (rc)
995 reason = "failed to stop engine"; 1062 ata_port_printk(ap, KERN_WARNING,
996 goto fail_restart; 1063 "failed to reset engine (errno=%d)", rc);
997 }
998
999 /* check BUSY/DRQ, perform Command List Override if necessary */
1000 if (ahci_check_status(ap) & (ATA_BUSY | ATA_DRQ)) {
1001 rc = ahci_clo(ap);
1002
1003 if (rc == -EOPNOTSUPP) {
1004 reason = "port busy but CLO unavailable";
1005 goto fail_restart;
1006 } else if (rc) {
1007 reason = "port busy but CLO failed";
1008 goto fail_restart;
1009 }
1010 }
1011
1012 /* restart engine */
1013 ahci_start_engine(ap);
1014 1064
1015 ata_tf_init(ap->device, &tf); 1065 ata_tf_init(ap->device, &tf);
1016 fis = pp->cmd_tbl;
1017 1066
1018 /* issue the first D2H Register FIS */ 1067 /* issue the first D2H Register FIS */
1019 ahci_fill_cmd_slot(pp, 0, 1068 msecs = 0;
1020 cmd_fis_len | AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY); 1069 now = jiffies;
1070 if (time_after(now, deadline))
1071 msecs = jiffies_to_msecs(deadline - now);
1021 1072
1022 tf.ctl |= ATA_SRST; 1073 tf.ctl |= ATA_SRST;
1023 ata_tf_to_fis(&tf, fis, 0); 1074 if (ahci_exec_polled_cmd(ap, pmp, &tf, 0,
1024 fis[1] &= ~(1 << 7); /* turn off Command FIS bit */ 1075 AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY, msecs)) {
1025
1026 writel(1, port_mmio + PORT_CMD_ISSUE);
1027
1028 tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1, 1, 500);
1029 if (tmp & 0x1) {
1030 rc = -EIO; 1076 rc = -EIO;
1031 reason = "1st FIS failed"; 1077 reason = "1st FIS failed";
1032 goto fail; 1078 goto fail;
@@ -1036,14 +1082,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
1036 msleep(1); 1082 msleep(1);
1037 1083
1038 /* issue the second D2H Register FIS */ 1084 /* issue the second D2H Register FIS */
1039 ahci_fill_cmd_slot(pp, 0, cmd_fis_len);
1040
1041 tf.ctl &= ~ATA_SRST; 1085 tf.ctl &= ~ATA_SRST;
1042 ata_tf_to_fis(&tf, fis, 0); 1086 ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0);
1043 fis[1] &= ~(1 << 7); /* turn off Command FIS bit */
1044
1045 writel(1, port_mmio + PORT_CMD_ISSUE);
1046 readl(port_mmio + PORT_CMD_ISSUE); /* flush */
1047 1087
1048 /* spec mandates ">= 2ms" before checking status. 1088 /* spec mandates ">= 2ms" before checking status.
1049 * We wait 150ms, because that was the magic delay used for 1089 * We wait 150ms, because that was the magic delay used for
@@ -1066,13 +1106,17 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class,
1066 DPRINTK("EXIT, class=%u\n", *class); 1106 DPRINTK("EXIT, class=%u\n", *class);
1067 return 0; 1107 return 0;
1068 1108
1069 fail_restart:
1070 ahci_start_engine(ap);
1071 fail: 1109 fail:
1072 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason); 1110 ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason);
1073 return rc; 1111 return rc;
1074} 1112}
1075 1113
1114static int ahci_softreset(struct ata_port *ap, unsigned int *class,
1115 unsigned long deadline)
1116{
1117 return ahci_do_softreset(ap, class, 0, deadline);
1118}
1119
1076static int ahci_hardreset(struct ata_port *ap, unsigned int *class, 1120static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
1077 unsigned long deadline) 1121 unsigned long deadline)
1078{ 1122{
@@ -1088,7 +1132,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
1088 /* clear D2H reception area to properly wait for D2H FIS */ 1132 /* clear D2H reception area to properly wait for D2H FIS */
1089 ata_tf_init(ap->device, &tf); 1133 ata_tf_init(ap->device, &tf);
1090 tf.command = 0x80; 1134 tf.command = 0x80;
1091 ata_tf_to_fis(&tf, d2h_fis, 0); 1135 ata_tf_to_fis(&tf, 0, 0, d2h_fis);
1092 1136
1093 rc = sata_std_hardreset(ap, class, deadline); 1137 rc = sata_std_hardreset(ap, class, deadline);
1094 1138
@@ -1106,6 +1150,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
1106static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class, 1150static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class,
1107 unsigned long deadline) 1151 unsigned long deadline)
1108{ 1152{
1153 u32 serror;
1109 int rc; 1154 int rc;
1110 1155
1111 DPRINTK("ENTER\n"); 1156 DPRINTK("ENTER\n");
@@ -1116,7 +1161,8 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class,
1116 deadline); 1161 deadline);
1117 1162
1118 /* vt8251 needs SError cleared for the port to operate */ 1163 /* vt8251 needs SError cleared for the port to operate */
1119 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR)); 1164 ahci_scr_read(ap, SCR_ERROR, &serror);
1165 ahci_scr_write(ap, SCR_ERROR, serror);
1120 1166
1121 ahci_start_engine(ap); 1167 ahci_start_engine(ap);
1122 1168
@@ -1205,7 +1251,7 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
1205 */ 1251 */
1206 cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ; 1252 cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
1207 1253
1208 ata_tf_to_fis(&qc->tf, cmd_tbl, 0); 1254 ata_tf_to_fis(&qc->tf, 0, 1, cmd_tbl);
1209 if (is_atapi) { 1255 if (is_atapi) {
1210 memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32); 1256 memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
1211 memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len); 1257 memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len);
@@ -1238,7 +1284,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1238 ata_ehi_clear_desc(ehi); 1284 ata_ehi_clear_desc(ehi);
1239 1285
1240 /* AHCI needs SError cleared; otherwise, it might lock up */ 1286 /* AHCI needs SError cleared; otherwise, it might lock up */
1241 serror = ahci_scr_read(ap, SCR_ERROR); 1287 ahci_scr_read(ap, SCR_ERROR, &serror);
1242 ahci_scr_write(ap, SCR_ERROR, serror); 1288 ahci_scr_write(ap, SCR_ERROR, serror);
1243 1289
1244 /* analyze @irq_stat */ 1290 /* analyze @irq_stat */
@@ -1262,12 +1308,12 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1262 if (irq_stat & PORT_IRQ_IF_ERR) { 1308 if (irq_stat & PORT_IRQ_IF_ERR) {
1263 err_mask |= AC_ERR_ATA_BUS; 1309 err_mask |= AC_ERR_ATA_BUS;
1264 action |= ATA_EH_SOFTRESET; 1310 action |= ATA_EH_SOFTRESET;
1265 ata_ehi_push_desc(ehi, ", interface fatal error"); 1311 ata_ehi_push_desc(ehi, "interface fatal error");
1266 } 1312 }
1267 1313
1268 if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) { 1314 if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) {
1269 ata_ehi_hotplugged(ehi); 1315 ata_ehi_hotplugged(ehi);
1270 ata_ehi_push_desc(ehi, ", %s", irq_stat & PORT_IRQ_CONNECT ? 1316 ata_ehi_push_desc(ehi, "%s", irq_stat & PORT_IRQ_CONNECT ?
1271 "connection status changed" : "PHY RDY changed"); 1317 "connection status changed" : "PHY RDY changed");
1272 } 1318 }
1273 1319
@@ -1276,7 +1322,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1276 1322
1277 err_mask |= AC_ERR_HSM; 1323 err_mask |= AC_ERR_HSM;
1278 action |= ATA_EH_SOFTRESET; 1324 action |= ATA_EH_SOFTRESET;
1279 ata_ehi_push_desc(ehi, ", unknown FIS %08x %08x %08x %08x", 1325 ata_ehi_push_desc(ehi, "unknown FIS %08x %08x %08x %08x",
1280 unk[0], unk[1], unk[2], unk[3]); 1326 unk[0], unk[1], unk[2], unk[3]);
1281 } 1327 }
1282 1328
@@ -1512,11 +1558,17 @@ static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
1512{ 1558{
1513 struct ata_port *ap = qc->ap; 1559 struct ata_port *ap = qc->ap;
1514 1560
1515 if (qc->flags & ATA_QCFLAG_FAILED) { 1561 /* make DMA engine forget about the failed command */
1516 /* make DMA engine forget about the failed command */ 1562 if (qc->flags & ATA_QCFLAG_FAILED)
1517 ahci_stop_engine(ap); 1563 ahci_kick_engine(ap, 1);
1518 ahci_start_engine(ap); 1564}
1519 } 1565
1566static int ahci_port_resume(struct ata_port *ap)
1567{
1568 ahci_power_up(ap);
1569 ahci_start_port(ap);
1570
1571 return 0;
1520} 1572}
1521 1573
1522#ifdef CONFIG_PM 1574#ifdef CONFIG_PM
@@ -1536,14 +1588,6 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1536 return rc; 1588 return rc;
1537} 1589}
1538 1590
1539static int ahci_port_resume(struct ata_port *ap)
1540{
1541 ahci_power_up(ap);
1542 ahci_start_port(ap);
1543
1544 return 0;
1545}
1546
1547static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) 1591static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
1548{ 1592{
1549 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1593 struct ata_host *host = dev_get_drvdata(&pdev->dev);
@@ -1734,12 +1778,13 @@ static void ahci_print_info(struct ata_host *host)
1734 1778
1735 dev_printk(KERN_INFO, &pdev->dev, 1779 dev_printk(KERN_INFO, &pdev->dev,
1736 "flags: " 1780 "flags: "
1737 "%s%s%s%s%s%s" 1781 "%s%s%s%s%s%s%s"
1738 "%s%s%s%s%s%s%s\n" 1782 "%s%s%s%s%s%s%s\n"
1739 , 1783 ,
1740 1784
1741 cap & (1 << 31) ? "64bit " : "", 1785 cap & (1 << 31) ? "64bit " : "",
1742 cap & (1 << 30) ? "ncq " : "", 1786 cap & (1 << 30) ? "ncq " : "",
1787 cap & (1 << 29) ? "sntf " : "",
1743 cap & (1 << 28) ? "ilck " : "", 1788 cap & (1 << 28) ? "ilck " : "",
1744 cap & (1 << 27) ? "stag " : "", 1789 cap & (1 << 27) ? "stag " : "",
1745 cap & (1 << 26) ? "pm " : "", 1790 cap & (1 << 26) ? "pm " : "",
@@ -1794,7 +1839,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1794 ahci_save_initial_config(pdev, &pi, hpriv); 1839 ahci_save_initial_config(pdev, &pi, hpriv);
1795 1840
1796 /* prepare host */ 1841 /* prepare host */
1797 if (!(pi.flags & AHCI_FLAG_NO_NCQ) && (hpriv->cap & HOST_CAP_NCQ)) 1842 if (hpriv->cap & HOST_CAP_NCQ)
1798 pi.flags |= ATA_FLAG_NCQ; 1843 pi.flags |= ATA_FLAG_NCQ;
1799 1844
1800 host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map)); 1845 host = ata_host_alloc_pinfo(&pdev->dev, ppi, fls(hpriv->port_map));
@@ -1808,10 +1853,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1808 void __iomem *port_mmio = ahci_port_base(ap); 1853 void __iomem *port_mmio = ahci_port_base(ap);
1809 1854
1810 /* standard SATA port setup */ 1855 /* standard SATA port setup */
1811 if (hpriv->port_map & (1 << i)) { 1856 if (hpriv->port_map & (1 << i))
1812 ap->ioaddr.cmd_addr = port_mmio; 1857 ap->ioaddr.cmd_addr = port_mmio;
1813 ap->ioaddr.scr_addr = port_mmio + PORT_SCR;
1814 }
1815 1858
1816 /* disabled/not-implemented port */ 1859 /* disabled/not-implemented port */
1817 else 1860 else
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 88e2dd0983b5..6001aae0b884 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -111,8 +111,9 @@ MODULE_VERSION(DRV_VERSION);
111/** 111/**
112 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure 112 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
113 * @tf: Taskfile to convert 113 * @tf: Taskfile to convert
114 * @fis: Buffer into which data will output
115 * @pmp: Port multiplier port 114 * @pmp: Port multiplier port
115 * @is_cmd: This FIS is for command
116 * @fis: Buffer into which data will output
116 * 117 *
117 * Converts a standard ATA taskfile to a Serial ATA 118 * Converts a standard ATA taskfile to a Serial ATA
118 * FIS structure (Register - Host to Device). 119 * FIS structure (Register - Host to Device).
@@ -120,12 +121,13 @@ MODULE_VERSION(DRV_VERSION);
120 * LOCKING: 121 * LOCKING:
121 * Inherited from caller. 122 * Inherited from caller.
122 */ 123 */
123 124void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis)
124void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp)
125{ 125{
126 fis[0] = 0x27; /* Register - Host to Device FIS */ 126 fis[0] = 0x27; /* Register - Host to Device FIS */
127 fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number, 127 fis[1] = pmp & 0xf; /* Port multiplier number*/
128 bit 7 indicates Command FIS */ 128 if (is_cmd)
129 fis[1] |= (1 << 7); /* bit 7 indicates Command FIS */
130
129 fis[2] = tf->command; 131 fis[2] = tf->command;
130 fis[3] = tf->feature; 132 fis[3] = tf->feature;
131 133
@@ -2387,21 +2389,35 @@ int sata_down_spd_limit(struct ata_port *ap)
2387 u32 sstatus, spd, mask; 2389 u32 sstatus, spd, mask;
2388 int rc, highbit; 2390 int rc, highbit;
2389 2391
2392 if (!sata_scr_valid(ap))
2393 return -EOPNOTSUPP;
2394
2395 /* If SCR can be read, use it to determine the current SPD.
2396 * If not, use cached value in ap->sata_spd.
2397 */
2390 rc = sata_scr_read(ap, SCR_STATUS, &sstatus); 2398 rc = sata_scr_read(ap, SCR_STATUS, &sstatus);
2391 if (rc) 2399 if (rc == 0)
2392 return rc; 2400 spd = (sstatus >> 4) & 0xf;
2401 else
2402 spd = ap->sata_spd;
2393 2403
2394 mask = ap->sata_spd_limit; 2404 mask = ap->sata_spd_limit;
2395 if (mask <= 1) 2405 if (mask <= 1)
2396 return -EINVAL; 2406 return -EINVAL;
2407
2408 /* unconditionally mask off the highest bit */
2397 highbit = fls(mask) - 1; 2409 highbit = fls(mask) - 1;
2398 mask &= ~(1 << highbit); 2410 mask &= ~(1 << highbit);
2399 2411
2400 spd = (sstatus >> 4) & 0xf; 2412 /* Mask off all speeds higher than or equal to the current
2401 if (spd <= 1) 2413 * one. Force 1.5Gbps if current SPD is not available.
2402 return -EINVAL; 2414 */
2403 spd--; 2415 if (spd > 1)
2404 mask &= (1 << spd) - 1; 2416 mask &= (1 << (spd - 1)) - 1;
2417 else
2418 mask &= 1;
2419
2420 /* were we already at the bottom? */
2405 if (!mask) 2421 if (!mask)
2406 return -EINVAL; 2422 return -EINVAL;
2407 2423
@@ -3251,9 +3267,11 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3251 last = cur; 3267 last = cur;
3252 last_jiffies = jiffies; 3268 last_jiffies = jiffies;
3253 3269
3254 /* check deadline */ 3270 /* Check deadline. If debouncing failed, return
3271 * -EPIPE to tell upper layer to lower link speed.
3272 */
3255 if (time_after(jiffies, deadline)) 3273 if (time_after(jiffies, deadline))
3256 return -EBUSY; 3274 return -EPIPE;
3257 } 3275 }
3258} 3276}
3259 3277
@@ -3769,6 +3787,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3769 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, }, 3787 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
3770 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, }, 3788 { "WDC WD740ADFD-00NLR1", NULL, ATA_HORKAGE_NONCQ, },
3771 { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, }, 3789 { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ, },
3790 { "ST9160821AS", "3.CLF", ATA_HORKAGE_NONCQ, },
3772 3791
3773 /* Devices with NCQ limits */ 3792 /* Devices with NCQ limits */
3774 3793
@@ -5729,10 +5748,8 @@ int sata_scr_valid(struct ata_port *ap)
5729 */ 5748 */
5730int sata_scr_read(struct ata_port *ap, int reg, u32 *val) 5749int sata_scr_read(struct ata_port *ap, int reg, u32 *val)
5731{ 5750{
5732 if (sata_scr_valid(ap)) { 5751 if (sata_scr_valid(ap))
5733 *val = ap->ops->scr_read(ap, reg); 5752 return ap->ops->scr_read(ap, reg, val);
5734 return 0;
5735 }
5736 return -EOPNOTSUPP; 5753 return -EOPNOTSUPP;
5737} 5754}
5738 5755
@@ -5754,10 +5771,8 @@ int sata_scr_read(struct ata_port *ap, int reg, u32 *val)
5754 */ 5771 */
5755int sata_scr_write(struct ata_port *ap, int reg, u32 val) 5772int sata_scr_write(struct ata_port *ap, int reg, u32 val)
5756{ 5773{
5757 if (sata_scr_valid(ap)) { 5774 if (sata_scr_valid(ap))
5758 ap->ops->scr_write(ap, reg, val); 5775 return ap->ops->scr_write(ap, reg, val);
5759 return 0;
5760 }
5761 return -EOPNOTSUPP; 5776 return -EOPNOTSUPP;
5762} 5777}
5763 5778
@@ -5778,10 +5793,13 @@ int sata_scr_write(struct ata_port *ap, int reg, u32 val)
5778 */ 5793 */
5779int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val) 5794int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val)
5780{ 5795{
5796 int rc;
5797
5781 if (sata_scr_valid(ap)) { 5798 if (sata_scr_valid(ap)) {
5782 ap->ops->scr_write(ap, reg, val); 5799 rc = ap->ops->scr_write(ap, reg, val);
5783 ap->ops->scr_read(ap, reg); 5800 if (rc == 0)
5784 return 0; 5801 rc = ap->ops->scr_read(ap, reg, &val);
5802 return rc;
5785 } 5803 }
5786 return -EOPNOTSUPP; 5804 return -EOPNOTSUPP;
5787} 5805}
@@ -5993,6 +6011,7 @@ void ata_dev_init(struct ata_device *dev)
5993 6011
5994 /* SATA spd limit is bound to the first device */ 6012 /* SATA spd limit is bound to the first device */
5995 ap->sata_spd_limit = ap->hw_sata_spd_limit; 6013 ap->sata_spd_limit = ap->hw_sata_spd_limit;
6014 ap->sata_spd = 0;
5996 6015
5997 /* High bits of dev->flags are used to record warm plug 6016 /* High bits of dev->flags are used to record warm plug
5998 * requests which occur asynchronously. Synchronize using 6017 * requests which occur asynchronously. Synchronize using
@@ -6058,6 +6077,9 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
6058 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan); 6077 INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
6059 INIT_LIST_HEAD(&ap->eh_done_q); 6078 INIT_LIST_HEAD(&ap->eh_done_q);
6060 init_waitqueue_head(&ap->eh_wait_q); 6079 init_waitqueue_head(&ap->eh_wait_q);
6080 init_timer_deferrable(&ap->fastdrain_timer);
6081 ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn;
6082 ap->fastdrain_timer.data = (unsigned long)ap;
6061 6083
6062 ap->cbl = ATA_CBL_NONE; 6084 ap->cbl = ATA_CBL_NONE;
6063 6085
@@ -6434,7 +6456,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6434 for (i = 0; i < host->n_ports; i++) { 6456 for (i = 0; i < host->n_ports; i++) {
6435 struct ata_port *ap = host->ports[i]; 6457 struct ata_port *ap = host->ports[i];
6436 6458
6437 ata_scsi_scan_host(ap); 6459 ata_scsi_scan_host(ap, 1);
6438 } 6460 }
6439 6461
6440 return 0; 6462 return 0;
@@ -6942,6 +6964,9 @@ EXPORT_SYMBOL_GPL(ata_pci_default_filter);
6942EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6964EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
6943#endif /* CONFIG_PCI */ 6965#endif /* CONFIG_PCI */
6944 6966
6967EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
6968EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
6969EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
6945EXPORT_SYMBOL_GPL(ata_eng_timeout); 6970EXPORT_SYMBOL_GPL(ata_eng_timeout);
6946EXPORT_SYMBOL_GPL(ata_port_schedule_eh); 6971EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
6947EXPORT_SYMBOL_GPL(ata_port_abort); 6972EXPORT_SYMBOL_GPL(ata_port_abort);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 9aa62a0754f6..ac6ceed4bb60 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -56,6 +56,7 @@ enum {
56 */ 56 */
57enum { 57enum {
58 ATA_EH_PRERESET_TIMEOUT = 10 * HZ, 58 ATA_EH_PRERESET_TIMEOUT = 10 * HZ,
59 ATA_EH_FASTDRAIN_INTERVAL = 3 * HZ,
59}; 60};
60 61
61/* The following table determines how we sequence resets. Each entry 62/* The following table determines how we sequence resets. Each entry
@@ -85,6 +86,71 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
85{ } 86{ }
86#endif /* CONFIG_PM */ 87#endif /* CONFIG_PM */
87 88
89static void __ata_ehi_pushv_desc(struct ata_eh_info *ehi, const char *fmt,
90 va_list args)
91{
92 ehi->desc_len += vscnprintf(ehi->desc + ehi->desc_len,
93 ATA_EH_DESC_LEN - ehi->desc_len,
94 fmt, args);
95}
96
97/**
98 * __ata_ehi_push_desc - push error description without adding separator
99 * @ehi: target EHI
100 * @fmt: printf format string
101 *
102 * Format string according to @fmt and append it to @ehi->desc.
103 *
104 * LOCKING:
105 * spin_lock_irqsave(host lock)
106 */
107void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
108{
109 va_list args;
110
111 va_start(args, fmt);
112 __ata_ehi_pushv_desc(ehi, fmt, args);
113 va_end(args);
114}
115
116/**
117 * ata_ehi_push_desc - push error description with separator
118 * @ehi: target EHI
119 * @fmt: printf format string
120 *
121 * Format string according to @fmt and append it to @ehi->desc.
122 * If @ehi->desc is not empty, ", " is added in-between.
123 *
124 * LOCKING:
125 * spin_lock_irqsave(host lock)
126 */
127void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...)
128{
129 va_list args;
130
131 if (ehi->desc_len)
132 __ata_ehi_push_desc(ehi, ", ");
133
134 va_start(args, fmt);
135 __ata_ehi_pushv_desc(ehi, fmt, args);
136 va_end(args);
137}
138
139/**
140 * ata_ehi_clear_desc - clean error description
141 * @ehi: target EHI
142 *
143 * Clear @ehi->desc.
144 *
145 * LOCKING:
146 * spin_lock_irqsave(host lock)
147 */
148void ata_ehi_clear_desc(struct ata_eh_info *ehi)
149{
150 ehi->desc[0] = '\0';
151 ehi->desc_len = 0;
152}
153
88static void ata_ering_record(struct ata_ering *ering, int is_io, 154static void ata_ering_record(struct ata_ering *ering, int is_io,
89 unsigned int err_mask) 155 unsigned int err_mask)
90{ 156{
@@ -296,6 +362,9 @@ void ata_scsi_error(struct Scsi_Host *host)
296 repeat: 362 repeat:
297 /* invoke error handler */ 363 /* invoke error handler */
298 if (ap->ops->error_handler) { 364 if (ap->ops->error_handler) {
365 /* kill fast drain timer */
366 del_timer_sync(&ap->fastdrain_timer);
367
299 /* process port resume request */ 368 /* process port resume request */
300 ata_eh_handle_port_resume(ap); 369 ata_eh_handle_port_resume(ap);
301 370
@@ -511,6 +580,94 @@ void ata_eng_timeout(struct ata_port *ap)
511 DPRINTK("EXIT\n"); 580 DPRINTK("EXIT\n");
512} 581}
513 582
583static int ata_eh_nr_in_flight(struct ata_port *ap)
584{
585 unsigned int tag;
586 int nr = 0;
587
588 /* count only non-internal commands */
589 for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++)
590 if (ata_qc_from_tag(ap, tag))
591 nr++;
592
593 return nr;
594}
595
596void ata_eh_fastdrain_timerfn(unsigned long arg)
597{
598 struct ata_port *ap = (void *)arg;
599 unsigned long flags;
600 int cnt;
601
602 spin_lock_irqsave(ap->lock, flags);
603
604 cnt = ata_eh_nr_in_flight(ap);
605
606 /* are we done? */
607 if (!cnt)
608 goto out_unlock;
609
610 if (cnt == ap->fastdrain_cnt) {
611 unsigned int tag;
612
613 /* No progress during the last interval, tag all
614 * in-flight qcs as timed out and freeze the port.
615 */
616 for (tag = 0; tag < ATA_MAX_QUEUE - 1; tag++) {
617 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
618 if (qc)
619 qc->err_mask |= AC_ERR_TIMEOUT;
620 }
621
622 ata_port_freeze(ap);
623 } else {
624 /* some qcs have finished, give it another chance */
625 ap->fastdrain_cnt = cnt;
626 ap->fastdrain_timer.expires =
627 jiffies + ATA_EH_FASTDRAIN_INTERVAL;
628 add_timer(&ap->fastdrain_timer);
629 }
630
631 out_unlock:
632 spin_unlock_irqrestore(ap->lock, flags);
633}
634
635/**
636 * ata_eh_set_pending - set ATA_PFLAG_EH_PENDING and activate fast drain
637 * @ap: target ATA port
638 * @fastdrain: activate fast drain
639 *
640 * Set ATA_PFLAG_EH_PENDING and activate fast drain if @fastdrain
641 * is non-zero and EH wasn't pending before. Fast drain ensures
642 * that EH kicks in in timely manner.
643 *
644 * LOCKING:
645 * spin_lock_irqsave(host lock)
646 */
647static void ata_eh_set_pending(struct ata_port *ap, int fastdrain)
648{
649 int cnt;
650
651 /* already scheduled? */
652 if (ap->pflags & ATA_PFLAG_EH_PENDING)
653 return;
654
655 ap->pflags |= ATA_PFLAG_EH_PENDING;
656
657 if (!fastdrain)
658 return;
659
660 /* do we have in-flight qcs? */
661 cnt = ata_eh_nr_in_flight(ap);
662 if (!cnt)
663 return;
664
665 /* activate fast drain */
666 ap->fastdrain_cnt = cnt;
667 ap->fastdrain_timer.expires = jiffies + ATA_EH_FASTDRAIN_INTERVAL;
668 add_timer(&ap->fastdrain_timer);
669}
670
514/** 671/**
515 * ata_qc_schedule_eh - schedule qc for error handling 672 * ata_qc_schedule_eh - schedule qc for error handling
516 * @qc: command to schedule error handling for 673 * @qc: command to schedule error handling for
@@ -528,7 +685,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
528 WARN_ON(!ap->ops->error_handler); 685 WARN_ON(!ap->ops->error_handler);
529 686
530 qc->flags |= ATA_QCFLAG_FAILED; 687 qc->flags |= ATA_QCFLAG_FAILED;
531 qc->ap->pflags |= ATA_PFLAG_EH_PENDING; 688 ata_eh_set_pending(ap, 1);
532 689
533 /* The following will fail if timeout has already expired. 690 /* The following will fail if timeout has already expired.
534 * ata_scsi_error() takes care of such scmds on EH entry. 691 * ata_scsi_error() takes care of such scmds on EH entry.
@@ -555,7 +712,7 @@ void ata_port_schedule_eh(struct ata_port *ap)
555 if (ap->pflags & ATA_PFLAG_INITIALIZING) 712 if (ap->pflags & ATA_PFLAG_INITIALIZING)
556 return; 713 return;
557 714
558 ap->pflags |= ATA_PFLAG_EH_PENDING; 715 ata_eh_set_pending(ap, 1);
559 scsi_schedule_eh(ap->scsi_host); 716 scsi_schedule_eh(ap->scsi_host);
560 717
561 DPRINTK("port EH scheduled\n"); 718 DPRINTK("port EH scheduled\n");
@@ -579,6 +736,9 @@ int ata_port_abort(struct ata_port *ap)
579 736
580 WARN_ON(!ap->ops->error_handler); 737 WARN_ON(!ap->ops->error_handler);
581 738
739 /* we're gonna abort all commands, no need for fast drain */
740 ata_eh_set_pending(ap, 0);
741
582 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { 742 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
583 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag); 743 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
584 744
@@ -1130,7 +1290,7 @@ static void ata_eh_analyze_ncq_error(struct ata_port *ap)
1130 /* we've got the perpetrator, condemn it */ 1290 /* we've got the perpetrator, condemn it */
1131 qc = __ata_qc_from_tag(ap, tag); 1291 qc = __ata_qc_from_tag(ap, tag);
1132 memcpy(&qc->result_tf, &tf, sizeof(tf)); 1292 memcpy(&qc->result_tf, &tf, sizeof(tf));
1133 qc->err_mask |= AC_ERR_DEV; 1293 qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1134 ehc->i.err_mask &= ~AC_ERR_DEV; 1294 ehc->i.err_mask &= ~AC_ERR_DEV;
1135} 1295}
1136 1296
@@ -1413,8 +1573,12 @@ static void ata_eh_autopsy(struct ata_port *ap)
1413 if (rc == 0) { 1573 if (rc == 0) {
1414 ehc->i.serror |= serror; 1574 ehc->i.serror |= serror;
1415 ata_eh_analyze_serror(ap); 1575 ata_eh_analyze_serror(ap);
1416 } else if (rc != -EOPNOTSUPP) 1576 } else if (rc != -EOPNOTSUPP) {
1577 /* SError read failed, force hardreset and probing */
1578 ata_ehi_schedule_probe(&ehc->i);
1417 ehc->i.action |= ATA_EH_HARDRESET; 1579 ehc->i.action |= ATA_EH_HARDRESET;
1580 ehc->i.err_mask |= AC_ERR_OTHER;
1581 }
1418 1582
1419 /* analyze NCQ failure */ 1583 /* analyze NCQ failure */
1420 ata_eh_analyze_ncq_error(ap); 1584 ata_eh_analyze_ncq_error(ap);
@@ -1524,14 +1688,14 @@ static void ata_eh_report(struct ata_port *ap)
1524 ehc->i.err_mask, ap->sactive, ehc->i.serror, 1688 ehc->i.err_mask, ap->sactive, ehc->i.serror,
1525 ehc->i.action, frozen); 1689 ehc->i.action, frozen);
1526 if (desc) 1690 if (desc)
1527 ata_dev_printk(ehc->i.dev, KERN_ERR, "(%s)\n", desc); 1691 ata_dev_printk(ehc->i.dev, KERN_ERR, "%s\n", desc);
1528 } else { 1692 } else {
1529 ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x " 1693 ata_port_printk(ap, KERN_ERR, "exception Emask 0x%x "
1530 "SAct 0x%x SErr 0x%x action 0x%x%s\n", 1694 "SAct 0x%x SErr 0x%x action 0x%x%s\n",
1531 ehc->i.err_mask, ap->sactive, ehc->i.serror, 1695 ehc->i.err_mask, ap->sactive, ehc->i.serror,
1532 ehc->i.action, frozen); 1696 ehc->i.action, frozen);
1533 if (desc) 1697 if (desc)
1534 ata_port_printk(ap, KERN_ERR, "(%s)\n", desc); 1698 ata_port_printk(ap, KERN_ERR, "%s\n", desc);
1535 } 1699 }
1536 1700
1537 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) { 1701 for (tag = 0; tag < ATA_MAX_QUEUE; tag++) {
@@ -1551,7 +1715,7 @@ static void ata_eh_report(struct ata_port *ap)
1551 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " 1715 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
1552 "tag %d cdb 0x%x data %u %s\n " 1716 "tag %d cdb 0x%x data %u %s\n "
1553 "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " 1717 "res %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
1554 "Emask 0x%x (%s)\n", 1718 "Emask 0x%x (%s)%s\n",
1555 cmd->command, cmd->feature, cmd->nsect, 1719 cmd->command, cmd->feature, cmd->nsect,
1556 cmd->lbal, cmd->lbam, cmd->lbah, 1720 cmd->lbal, cmd->lbam, cmd->lbah,
1557 cmd->hob_feature, cmd->hob_nsect, 1721 cmd->hob_feature, cmd->hob_nsect,
@@ -1562,7 +1726,8 @@ static void ata_eh_report(struct ata_port *ap)
1562 res->lbal, res->lbam, res->lbah, 1726 res->lbal, res->lbam, res->lbah,
1563 res->hob_feature, res->hob_nsect, 1727 res->hob_feature, res->hob_nsect,
1564 res->hob_lbal, res->hob_lbam, res->hob_lbah, 1728 res->hob_lbal, res->hob_lbam, res->hob_lbah,
1565 res->device, qc->err_mask, ata_err_string(qc->err_mask)); 1729 res->device, qc->err_mask, ata_err_string(qc->err_mask),
1730 qc->err_mask & AC_ERR_NCQ ? " <F>" : "");
1566 } 1731 }
1567} 1732}
1568 1733
@@ -1648,7 +1813,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1648 } else 1813 } else
1649 ata_port_printk(ap, KERN_ERR, 1814 ata_port_printk(ap, KERN_ERR,
1650 "prereset failed (errno=%d)\n", rc); 1815 "prereset failed (errno=%d)\n", rc);
1651 return rc; 1816 goto out;
1652 } 1817 }
1653 } 1818 }
1654 1819
@@ -1661,7 +1826,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1661 /* prereset told us not to reset, bang classes and return */ 1826 /* prereset told us not to reset, bang classes and return */
1662 for (i = 0; i < ATA_MAX_DEVICES; i++) 1827 for (i = 0; i < ATA_MAX_DEVICES; i++)
1663 classes[i] = ATA_DEV_NONE; 1828 classes[i] = ATA_DEV_NONE;
1664 return 0; 1829 rc = 0;
1830 goto out;
1665 } 1831 }
1666 1832
1667 /* did prereset() screw up? if so, fix up to avoid oopsing */ 1833 /* did prereset() screw up? if so, fix up to avoid oopsing */
@@ -1697,7 +1863,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1697 ata_port_printk(ap, KERN_ERR, 1863 ata_port_printk(ap, KERN_ERR,
1698 "follow-up softreset required " 1864 "follow-up softreset required "
1699 "but no softreset avaliable\n"); 1865 "but no softreset avaliable\n");
1700 return -EINVAL; 1866 rc = -EINVAL;
1867 goto out;
1701 } 1868 }
1702 1869
1703 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK); 1870 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
@@ -1707,7 +1874,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1707 classes[0] == ATA_DEV_UNKNOWN) { 1874 classes[0] == ATA_DEV_UNKNOWN) {
1708 ata_port_printk(ap, KERN_ERR, 1875 ata_port_printk(ap, KERN_ERR,
1709 "classification failed\n"); 1876 "classification failed\n");
1710 return -EINVAL; 1877 rc = -EINVAL;
1878 goto out;
1711 } 1879 }
1712 } 1880 }
1713 1881
@@ -1724,7 +1892,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1724 schedule_timeout_uninterruptible(delta); 1892 schedule_timeout_uninterruptible(delta);
1725 } 1893 }
1726 1894
1727 if (reset == hardreset && 1895 if (rc == -EPIPE ||
1728 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1) 1896 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1)
1729 sata_down_spd_limit(ap); 1897 sata_down_spd_limit(ap);
1730 if (hardreset) 1898 if (hardreset)
@@ -1733,12 +1901,18 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1733 } 1901 }
1734 1902
1735 if (rc == 0) { 1903 if (rc == 0) {
1904 u32 sstatus;
1905
1736 /* After the reset, the device state is PIO 0 and the 1906 /* After the reset, the device state is PIO 0 and the
1737 * controller state is undefined. Record the mode. 1907 * controller state is undefined. Record the mode.
1738 */ 1908 */
1739 for (i = 0; i < ATA_MAX_DEVICES; i++) 1909 for (i = 0; i < ATA_MAX_DEVICES; i++)
1740 ap->device[i].pio_mode = XFER_PIO_0; 1910 ap->device[i].pio_mode = XFER_PIO_0;
1741 1911
1912 /* record current link speed */
1913 if (sata_scr_read(ap, SCR_STATUS, &sstatus) == 0)
1914 ap->sata_spd = (sstatus >> 4) & 0xf;
1915
1742 if (postreset) 1916 if (postreset)
1743 postreset(ap, classes); 1917 postreset(ap, classes);
1744 1918
@@ -1746,7 +1920,9 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1746 ata_eh_done(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK); 1920 ata_eh_done(ap, NULL, ehc->i.action & ATA_EH_RESET_MASK);
1747 ehc->i.action |= ATA_EH_REVALIDATE; 1921 ehc->i.action |= ATA_EH_REVALIDATE;
1748 } 1922 }
1749 1923 out:
1924 /* clear hotplug flag */
1925 ehc->i.flags &= ~ATA_EHI_HOTPLUGGED;
1750 return rc; 1926 return rc;
1751} 1927}
1752 1928
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index cfde22da07ac..12ac0b511f79 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2947,17 +2947,22 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht)
2947 return rc; 2947 return rc;
2948} 2948}
2949 2949
2950void ata_scsi_scan_host(struct ata_port *ap) 2950void ata_scsi_scan_host(struct ata_port *ap, int sync)
2951{ 2951{
2952 int tries = 5;
2953 struct ata_device *last_failed_dev = NULL;
2954 struct ata_device *dev;
2952 unsigned int i; 2955 unsigned int i;
2953 2956
2954 if (ap->flags & ATA_FLAG_DISABLED) 2957 if (ap->flags & ATA_FLAG_DISABLED)
2955 return; 2958 return;
2956 2959
2960 repeat:
2957 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2961 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2958 struct ata_device *dev = &ap->device[i];
2959 struct scsi_device *sdev; 2962 struct scsi_device *sdev;
2960 2963
2964 dev = &ap->device[i];
2965
2961 if (!ata_dev_enabled(dev) || dev->sdev) 2966 if (!ata_dev_enabled(dev) || dev->sdev)
2962 continue; 2967 continue;
2963 2968
@@ -2967,6 +2972,45 @@ void ata_scsi_scan_host(struct ata_port *ap)
2967 scsi_device_put(sdev); 2972 scsi_device_put(sdev);
2968 } 2973 }
2969 } 2974 }
2975
2976 /* If we scanned while EH was in progress or allocation
2977 * failure occurred, scan would have failed silently. Check
2978 * whether all devices are attached.
2979 */
2980 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2981 dev = &ap->device[i];
2982 if (ata_dev_enabled(dev) && !dev->sdev)
2983 break;
2984 }
2985 if (i == ATA_MAX_DEVICES)
2986 return;
2987
2988 /* we're missing some SCSI devices */
2989 if (sync) {
2990 /* If caller requested synchrnous scan && we've made
2991 * any progress, sleep briefly and repeat.
2992 */
2993 if (dev != last_failed_dev) {
2994 msleep(100);
2995 last_failed_dev = dev;
2996 goto repeat;
2997 }
2998
2999 /* We might be failing to detect boot device, give it
3000 * a few more chances.
3001 */
3002 if (--tries) {
3003 msleep(100);
3004 goto repeat;
3005 }
3006
3007 ata_port_printk(ap, KERN_ERR, "WARNING: synchronous SCSI scan "
3008 "failed without making any progress,\n"
3009 " switching to async\n");
3010 }
3011
3012 queue_delayed_work(ata_aux_wq, &ap->hotplug_task,
3013 round_jiffies_relative(HZ));
2970} 3014}
2971 3015
2972/** 3016/**
@@ -3093,20 +3137,7 @@ void ata_scsi_hotplug(struct work_struct *work)
3093 } 3137 }
3094 3138
3095 /* scan for new ones */ 3139 /* scan for new ones */
3096 ata_scsi_scan_host(ap); 3140 ata_scsi_scan_host(ap, 0);
3097
3098 /* If we scanned while EH was in progress, scan would have
3099 * failed silently. Requeue if there are enabled but
3100 * unattached devices.
3101 */
3102 for (i = 0; i < ATA_MAX_DEVICES; i++) {
3103 struct ata_device *dev = &ap->device[i];
3104 if (ata_dev_enabled(dev) && !dev->sdev) {
3105 queue_delayed_work(ata_aux_wq, &ap->hotplug_task,
3106 round_jiffies_relative(HZ));
3107 break;
3108 }
3109 }
3110 3141
3111 DPRINTK("EXIT\n"); 3142 DPRINTK("EXIT\n");
3112} 3143}
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index ca7d2245d684..6c289c7b1322 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * libata-bmdma.c - helper library for PCI IDE BMDMA 2 * libata-sff.c - helper library for PCI IDE BMDMA
3 * 3 *
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com> 4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org 5 * Please ALWAYS copy linux-ide@vger.kernel.org
@@ -211,6 +211,8 @@ void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
211 tf->hob_lbal = ioread8(ioaddr->lbal_addr); 211 tf->hob_lbal = ioread8(ioaddr->lbal_addr);
212 tf->hob_lbam = ioread8(ioaddr->lbam_addr); 212 tf->hob_lbam = ioread8(ioaddr->lbam_addr);
213 tf->hob_lbah = ioread8(ioaddr->lbah_addr); 213 tf->hob_lbah = ioread8(ioaddr->lbah_addr);
214 iowrite8(tf->ctl, ioaddr->ctl_addr);
215 ap->last_ctl = tf->ctl;
214 } 216 }
215} 217}
216 218
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index ba17fc5f2e99..564cd234c805 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -112,7 +112,7 @@ static inline int ata_acpi_on_devcfg(struct ata_device *adev) { return 0; }
112/* libata-scsi.c */ 112/* libata-scsi.c */
113extern int ata_scsi_add_hosts(struct ata_host *host, 113extern int ata_scsi_add_hosts(struct ata_host *host,
114 struct scsi_host_template *sht); 114 struct scsi_host_template *sht);
115extern void ata_scsi_scan_host(struct ata_port *ap); 115extern void ata_scsi_scan_host(struct ata_port *ap, int sync);
116extern int ata_scsi_offline_dev(struct ata_device *dev); 116extern int ata_scsi_offline_dev(struct ata_device *dev);
117extern void ata_scsi_hotplug(struct work_struct *work); 117extern void ata_scsi_hotplug(struct work_struct *work);
118extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf, 118extern unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
@@ -151,6 +151,7 @@ extern int ata_bus_probe(struct ata_port *ap);
151extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd); 151extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
152extern void ata_scsi_error(struct Scsi_Host *host); 152extern void ata_scsi_error(struct Scsi_Host *host);
153extern void ata_port_wait_eh(struct ata_port *ap); 153extern void ata_port_wait_eh(struct ata_port *ap);
154extern void ata_eh_fastdrain_timerfn(unsigned long arg);
154extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc); 155extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc);
155 156
156/* libata-sff.c */ 157/* libata-sff.c */
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 6bf037d82b5a..7dc76e71bd55 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -275,7 +275,7 @@ static int __devinit cs5520_init_one(struct pci_dev *pdev, const struct pci_devi
275 275
276 for (i = 0; i < 2; i++) { 276 for (i = 0; i < 2; i++) {
277 static const int irq[] = { 14, 15 }; 277 static const int irq[] = { 14, 15 };
278 struct ata_port *ap = host->ports[0]; 278 struct ata_port *ap = host->ports[i];
279 279
280 if (ata_port_is_dummy(ap)) 280 if (ata_port_is_dummy(ap))
281 continue; 281 continue;
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 79f841bca593..a909f793ffc1 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -213,8 +213,9 @@ static int __devinit pata_platform_probe(struct platform_device *pdev)
213 pata_platform_setup_port(&ap->ioaddr, pp_info); 213 pata_platform_setup_port(&ap->ioaddr, pp_info);
214 214
215 /* activate */ 215 /* activate */
216 return ata_host_activate(host, platform_get_irq(pdev, 0), ata_interrupt, 216 return ata_host_activate(host, platform_get_irq(pdev, 0),
217 pp_info->irq_flags, &pata_platform_sht); 217 ata_interrupt, pp_info ? pp_info->irq_flags
218 : 0, &pata_platform_sht);
218} 219}
219 220
220/** 221/**
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index c55667e0eb65..36cdbd2b0bd5 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -238,12 +238,6 @@ static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
238 else 238 else
239 offset = 0; /* 100MHz */ 239 offset = 0; /* 100MHz */
240 240
241 /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */
242 if (adev->class == ATA_DEV_ATAPI && speed > XFER_UDMA_4) {
243 printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
244 speed = XFER_UDMA_4;
245 }
246
247 if (speed >= XFER_UDMA_0) 241 if (speed >= XFER_UDMA_0)
248 idx = speed - XFER_UDMA_0; 242 idx = speed - XFER_UDMA_0;
249 else 243 else
@@ -264,6 +258,17 @@ static void scc_set_dmamode (struct ata_port *ap, struct ata_device *adev)
264 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]); 258 JCTSStbl[offset][idx] << 16 | JCENVTtbl[offset][idx]);
265} 259}
266 260
261unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask)
262{
263 /* errata A308 workaround: limit ATAPI UDMA mode to UDMA4 */
264 if (adev->class == ATA_DEV_ATAPI &&
265 (mask & (0xE0 << ATA_SHIFT_UDMA))) {
266 printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
267 mask &= ~(0xE0 << ATA_SHIFT_UDMA);
268 }
269 return ata_pci_default_filter(adev, mask);
270}
271
267/** 272/**
268 * scc_tf_load - send taskfile registers to host controller 273 * scc_tf_load - send taskfile registers to host controller
269 * @ap: Port to which output is sent 274 * @ap: Port to which output is sent
@@ -358,6 +363,8 @@ static void scc_tf_read (struct ata_port *ap, struct ata_taskfile *tf)
358 tf->hob_lbal = in_be32(ioaddr->lbal_addr); 363 tf->hob_lbal = in_be32(ioaddr->lbal_addr);
359 tf->hob_lbam = in_be32(ioaddr->lbam_addr); 364 tf->hob_lbam = in_be32(ioaddr->lbam_addr);
360 tf->hob_lbah = in_be32(ioaddr->lbah_addr); 365 tf->hob_lbah = in_be32(ioaddr->lbah_addr);
366 out_be32(ioaddr->ctl_addr, tf->ctl);
367 ap->last_ctl = tf->ctl;
361 } 368 }
362} 369}
363 370
@@ -741,7 +748,7 @@ static u8 scc_bmdma_status (struct ata_port *ap)
741 return host_stat; 748 return host_stat;
742 749
743 /* errata A252,A308 workaround: Step4 */ 750 /* errata A252,A308 workaround: Step4 */
744 if (ata_altstatus(ap) & ATA_ERR && int_status & INTSTS_INTRQ) 751 if ((ata_altstatus(ap) & ATA_ERR) && (int_status & INTSTS_INTRQ))
745 return (host_stat | ATA_DMA_INTR); 752 return (host_stat | ATA_DMA_INTR);
746 753
747 /* errata A308 workaround Step5 */ 754 /* errata A308 workaround Step5 */
@@ -752,11 +759,11 @@ static u8 scc_bmdma_status (struct ata_port *ap)
752 if ((qc->tf.protocol == ATA_PROT_DMA && 759 if ((qc->tf.protocol == ATA_PROT_DMA &&
753 qc->dev->xfer_mode > XFER_UDMA_4)) { 760 qc->dev->xfer_mode > XFER_UDMA_4)) {
754 if (!(int_status & INTSTS_ACTEINT)) { 761 if (!(int_status & INTSTS_ACTEINT)) {
755 printk(KERN_WARNING "ata%u: data lost occurred. (ACTEINT==0, retry:%d)\n", 762 printk(KERN_WARNING "ata%u: operation failed (transfer data loss)\n",
756 ap->print_id, retry); 763 ap->print_id);
757 host_stat |= ATA_DMA_ERR; 764 host_stat |= ATA_DMA_ERR;
758 if (retry++) 765 if (retry++)
759 ap->udma_mask >>= 1; 766 ap->udma_mask &= ~(1 << qc->dev->xfer_mode);
760 } else 767 } else
761 retry = 0; 768 retry = 0;
762 } 769 }
@@ -1016,7 +1023,7 @@ static const struct ata_port_operations scc_pata_ops = {
1016 .port_disable = ata_port_disable, 1023 .port_disable = ata_port_disable,
1017 .set_piomode = scc_set_piomode, 1024 .set_piomode = scc_set_piomode,
1018 .set_dmamode = scc_set_dmamode, 1025 .set_dmamode = scc_set_dmamode,
1019 .mode_filter = ata_pci_default_filter, 1026 .mode_filter = scc_mode_filter,
1020 1027
1021 .tf_load = scc_tf_load, 1028 .tf_load = scc_tf_load,
1022 .tf_read = scc_tf_read, 1029 .tf_read = scc_tf_read,
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index 3de183461c3c..a9c948d7604a 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -190,34 +190,34 @@ static void inic_reset_port(void __iomem *port_base)
190 writew(ctl, idma_ctl); 190 writew(ctl, idma_ctl);
191} 191}
192 192
193static u32 inic_scr_read(struct ata_port *ap, unsigned sc_reg) 193static int inic_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val)
194{ 194{
195 void __iomem *scr_addr = ap->ioaddr.scr_addr; 195 void __iomem *scr_addr = ap->ioaddr.scr_addr;
196 void __iomem *addr; 196 void __iomem *addr;
197 u32 val;
198 197
199 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) 198 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
200 return 0xffffffffU; 199 return -EINVAL;
201 200
202 addr = scr_addr + scr_map[sc_reg] * 4; 201 addr = scr_addr + scr_map[sc_reg] * 4;
203 val = readl(scr_addr + scr_map[sc_reg] * 4); 202 *val = readl(scr_addr + scr_map[sc_reg] * 4);
204 203
205 /* this controller has stuck DIAG.N, ignore it */ 204 /* this controller has stuck DIAG.N, ignore it */
206 if (sc_reg == SCR_ERROR) 205 if (sc_reg == SCR_ERROR)
207 val &= ~SERR_PHYRDY_CHG; 206 *val &= ~SERR_PHYRDY_CHG;
208 return val; 207 return 0;
209} 208}
210 209
211static void inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 210static int inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
212{ 211{
213 void __iomem *scr_addr = ap->ioaddr.scr_addr; 212 void __iomem *scr_addr = ap->ioaddr.scr_addr;
214 void __iomem *addr; 213 void __iomem *addr;
215 214
216 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map))) 215 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
217 return; 216 return -EINVAL;
218 217
219 addr = scr_addr + scr_map[sc_reg] * 4; 218 addr = scr_addr + scr_map[sc_reg] * 4;
220 writel(val, scr_addr + scr_map[sc_reg] * 4); 219 writel(val, scr_addr + scr_map[sc_reg] * 4);
220 return 0;
221} 221}
222 222
223/* 223/*
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index fb8a749423ca..8ec520885b95 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -35,8 +35,6 @@
35 35
36 6) Add port multiplier support (intermediate) 36 6) Add port multiplier support (intermediate)
37 37
38 7) Test and verify 3.0 Gbps support
39
40 8) Develop a low-power-consumption strategy, and implement it. 38 8) Develop a low-power-consumption strategy, and implement it.
41 39
42 9) [Experiment, low priority] See if ATAPI can be supported using 40 9) [Experiment, low priority] See if ATAPI can be supported using
@@ -227,26 +225,26 @@ enum {
227 225
228 EDMA_ERR_IRQ_CAUSE_OFS = 0x8, 226 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
229 EDMA_ERR_IRQ_MASK_OFS = 0xc, 227 EDMA_ERR_IRQ_MASK_OFS = 0xc,
230 EDMA_ERR_D_PAR = (1 << 0), 228 EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */
231 EDMA_ERR_PRD_PAR = (1 << 1), 229 EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */
232 EDMA_ERR_DEV = (1 << 2), 230 EDMA_ERR_DEV = (1 << 2), /* device error */
233 EDMA_ERR_DEV_DCON = (1 << 3), 231 EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */
234 EDMA_ERR_DEV_CON = (1 << 4), 232 EDMA_ERR_DEV_CON = (1 << 4), /* device connected */
235 EDMA_ERR_SERR = (1 << 5), 233 EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */
236 EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ 234 EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */
237 EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ 235 EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */
238 EDMA_ERR_BIST_ASYNC = (1 << 8), 236 EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */
239 EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ 237 EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */
240 EDMA_ERR_CRBQ_PAR = (1 << 9), 238 EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */
241 EDMA_ERR_CRPB_PAR = (1 << 10), 239 EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */
242 EDMA_ERR_INTRL_PAR = (1 << 11), 240 EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */
243 EDMA_ERR_IORDY = (1 << 12), 241 EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */
244 EDMA_ERR_LNK_CTRL_RX = (0xf << 13), 242 EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */
245 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), 243 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
246 EDMA_ERR_LNK_DATA_RX = (0xf << 17), 244 EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */
247 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), 245 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */
248 EDMA_ERR_LNK_DATA_TX = (0x1f << 26), 246 EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */
249 EDMA_ERR_TRANS_PROTO = (1 << 31), 247 EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */
250 EDMA_ERR_OVERRUN_5 = (1 << 5), 248 EDMA_ERR_OVERRUN_5 = (1 << 5),
251 EDMA_ERR_UNDERRUN_5 = (1 << 6), 249 EDMA_ERR_UNDERRUN_5 = (1 << 6),
252 EDMA_EH_FREEZE = EDMA_ERR_D_PAR | 250 EDMA_EH_FREEZE = EDMA_ERR_D_PAR |
@@ -255,7 +253,7 @@ enum {
255 EDMA_ERR_DEV_CON | 253 EDMA_ERR_DEV_CON |
256 EDMA_ERR_SERR | 254 EDMA_ERR_SERR |
257 EDMA_ERR_SELF_DIS | 255 EDMA_ERR_SELF_DIS |
258 EDMA_ERR_CRBQ_PAR | 256 EDMA_ERR_CRQB_PAR |
259 EDMA_ERR_CRPB_PAR | 257 EDMA_ERR_CRPB_PAR |
260 EDMA_ERR_INTRL_PAR | 258 EDMA_ERR_INTRL_PAR |
261 EDMA_ERR_IORDY | 259 EDMA_ERR_IORDY |
@@ -270,7 +268,7 @@ enum {
270 EDMA_ERR_OVERRUN_5 | 268 EDMA_ERR_OVERRUN_5 |
271 EDMA_ERR_UNDERRUN_5 | 269 EDMA_ERR_UNDERRUN_5 |
272 EDMA_ERR_SELF_DIS_5 | 270 EDMA_ERR_SELF_DIS_5 |
273 EDMA_ERR_CRBQ_PAR | 271 EDMA_ERR_CRQB_PAR |
274 EDMA_ERR_CRPB_PAR | 272 EDMA_ERR_CRPB_PAR |
275 EDMA_ERR_INTRL_PAR | 273 EDMA_ERR_INTRL_PAR |
276 EDMA_ERR_IORDY, 274 EDMA_ERR_IORDY,
@@ -286,10 +284,10 @@ enum {
286 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ 284 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
287 EDMA_RSP_Q_PTR_SHIFT = 3, 285 EDMA_RSP_Q_PTR_SHIFT = 3,
288 286
289 EDMA_CMD_OFS = 0x28, 287 EDMA_CMD_OFS = 0x28, /* EDMA command register */
290 EDMA_EN = (1 << 0), 288 EDMA_EN = (1 << 0), /* enable EDMA */
291 EDMA_DS = (1 << 1), 289 EDMA_DS = (1 << 1), /* disable EDMA; self-negated */
292 ATA_RST = (1 << 2), 290 ATA_RST = (1 << 2), /* reset trans/link/phy */
293 291
294 EDMA_IORDY_TMOUT = 0x34, 292 EDMA_IORDY_TMOUT = 0x34,
295 EDMA_ARB_CFG = 0x38, 293 EDMA_ARB_CFG = 0x38,
@@ -301,14 +299,13 @@ enum {
301 MV_HP_ERRATA_60X1B2 = (1 << 3), 299 MV_HP_ERRATA_60X1B2 = (1 << 3),
302 MV_HP_ERRATA_60X1C0 = (1 << 4), 300 MV_HP_ERRATA_60X1C0 = (1 << 4),
303 MV_HP_ERRATA_XX42A0 = (1 << 5), 301 MV_HP_ERRATA_XX42A0 = (1 << 5),
304 MV_HP_GEN_I = (1 << 6), 302 MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */
305 MV_HP_GEN_II = (1 << 7), 303 MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */
306 MV_HP_GEN_IIE = (1 << 8), 304 MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */
307 305
308 /* Port private flags (pp_flags) */ 306 /* Port private flags (pp_flags) */
309 MV_PP_FLAG_EDMA_EN = (1 << 0), 307 MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
310 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), 308 MV_PP_FLAG_HAD_A_RESET = (1 << 2), /* 1st hard reset complete? */
311 MV_PP_FLAG_HAD_A_RESET = (1 << 2),
312}; 309};
313 310
314#define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) 311#define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I)
@@ -318,8 +315,12 @@ enum {
318enum { 315enum {
319 MV_DMA_BOUNDARY = 0xffffffffU, 316 MV_DMA_BOUNDARY = 0xffffffffU,
320 317
318 /* mask of register bits containing lower 32 bits
319 * of EDMA request queue DMA address
320 */
321 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 321 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
322 322
323 /* ditto, for response queue */
323 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, 324 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
324}; 325};
325 326
@@ -403,10 +404,10 @@ struct mv_host_priv {
403}; 404};
404 405
405static void mv_irq_clear(struct ata_port *ap); 406static void mv_irq_clear(struct ata_port *ap);
406static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 407static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
407static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 408static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
408static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 409static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
409static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 410static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
410static int mv_port_start(struct ata_port *ap); 411static int mv_port_start(struct ata_port *ap);
411static void mv_port_stop(struct ata_port *ap); 412static void mv_port_stop(struct ata_port *ap);
412static void mv_qc_prep(struct ata_queued_cmd *qc); 413static void mv_qc_prep(struct ata_queued_cmd *qc);
@@ -823,7 +824,7 @@ static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv,
823} 824}
824 825
825/** 826/**
826 * mv_stop_dma - Disable eDMA engine 827 * __mv_stop_dma - Disable eDMA engine
827 * @ap: ATA channel to manipulate 828 * @ap: ATA channel to manipulate
828 * 829 *
829 * Verify the local cache of the eDMA state is accurate with a 830 * Verify the local cache of the eDMA state is accurate with a
@@ -832,7 +833,7 @@ static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv,
832 * LOCKING: 833 * LOCKING:
833 * Inherited from caller. 834 * Inherited from caller.
834 */ 835 */
835static int mv_stop_dma(struct ata_port *ap) 836static int __mv_stop_dma(struct ata_port *ap)
836{ 837{
837 void __iomem *port_mmio = mv_ap_base(ap); 838 void __iomem *port_mmio = mv_ap_base(ap);
838 struct mv_port_priv *pp = ap->private_data; 839 struct mv_port_priv *pp = ap->private_data;
@@ -865,6 +866,18 @@ static int mv_stop_dma(struct ata_port *ap)
865 return err; 866 return err;
866} 867}
867 868
869static int mv_stop_dma(struct ata_port *ap)
870{
871 unsigned long flags;
872 int rc;
873
874 spin_lock_irqsave(&ap->host->lock, flags);
875 rc = __mv_stop_dma(ap);
876 spin_unlock_irqrestore(&ap->host->lock, flags);
877
878 return rc;
879}
880
868#ifdef ATA_DEBUG 881#ifdef ATA_DEBUG
869static void mv_dump_mem(void __iomem *start, unsigned bytes) 882static void mv_dump_mem(void __iomem *start, unsigned bytes)
870{ 883{
@@ -961,22 +974,26 @@ static unsigned int mv_scr_offset(unsigned int sc_reg_in)
961 return ofs; 974 return ofs;
962} 975}
963 976
964static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in) 977static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
965{ 978{
966 unsigned int ofs = mv_scr_offset(sc_reg_in); 979 unsigned int ofs = mv_scr_offset(sc_reg_in);
967 980
968 if (0xffffffffU != ofs) 981 if (ofs != 0xffffffffU) {
969 return readl(mv_ap_base(ap) + ofs); 982 *val = readl(mv_ap_base(ap) + ofs);
970 else 983 return 0;
971 return (u32) ofs; 984 } else
985 return -EINVAL;
972} 986}
973 987
974static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 988static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
975{ 989{
976 unsigned int ofs = mv_scr_offset(sc_reg_in); 990 unsigned int ofs = mv_scr_offset(sc_reg_in);
977 991
978 if (0xffffffffU != ofs) 992 if (ofs != 0xffffffffU) {
979 writelfl(val, mv_ap_base(ap) + ofs); 993 writelfl(val, mv_ap_base(ap) + ofs);
994 return 0;
995 } else
996 return -EINVAL;
980} 997}
981 998
982static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv, 999static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv,
@@ -1029,6 +1046,7 @@ static int mv_port_start(struct ata_port *ap)
1029 void __iomem *port_mmio = mv_ap_base(ap); 1046 void __iomem *port_mmio = mv_ap_base(ap);
1030 void *mem; 1047 void *mem;
1031 dma_addr_t mem_dma; 1048 dma_addr_t mem_dma;
1049 unsigned long flags;
1032 int rc; 1050 int rc;
1033 1051
1034 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 1052 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
@@ -1067,10 +1085,14 @@ static int mv_port_start(struct ata_port *ap)
1067 pp->sg_tbl = mem; 1085 pp->sg_tbl = mem;
1068 pp->sg_tbl_dma = mem_dma; 1086 pp->sg_tbl_dma = mem_dma;
1069 1087
1088 spin_lock_irqsave(&ap->host->lock, flags);
1089
1070 mv_edma_cfg(ap, hpriv, port_mmio); 1090 mv_edma_cfg(ap, hpriv, port_mmio);
1071 1091
1072 mv_set_edma_ptrs(port_mmio, hpriv, pp); 1092 mv_set_edma_ptrs(port_mmio, hpriv, pp);
1073 1093
1094 spin_unlock_irqrestore(&ap->host->lock, flags);
1095
1074 /* Don't turn on EDMA here...do it before DMA commands only. Else 1096 /* Don't turn on EDMA here...do it before DMA commands only. Else
1075 * we'll be unable to send non-data, PIO, etc due to restricted access 1097 * we'll be unable to send non-data, PIO, etc due to restricted access
1076 * to shadow regs. 1098 * to shadow regs.
@@ -1090,11 +1112,7 @@ static int mv_port_start(struct ata_port *ap)
1090 */ 1112 */
1091static void mv_port_stop(struct ata_port *ap) 1113static void mv_port_stop(struct ata_port *ap)
1092{ 1114{
1093 unsigned long flags;
1094
1095 spin_lock_irqsave(&ap->host->lock, flags);
1096 mv_stop_dma(ap); 1115 mv_stop_dma(ap);
1097 spin_unlock_irqrestore(&ap->host->lock, flags);
1098} 1116}
1099 1117
1100/** 1118/**
@@ -1325,7 +1343,7 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1325 * port. Turn off EDMA so there won't be problems accessing 1343 * port. Turn off EDMA so there won't be problems accessing
1326 * shadow block, etc registers. 1344 * shadow block, etc registers.
1327 */ 1345 */
1328 mv_stop_dma(ap); 1346 __mv_stop_dma(ap);
1329 return ata_qc_issue_prot(qc); 1347 return ata_qc_issue_prot(qc);
1330 } 1348 }
1331 1349
@@ -1393,16 +1411,16 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1393 if (edma_err_cause & EDMA_ERR_DEV) 1411 if (edma_err_cause & EDMA_ERR_DEV)
1394 err_mask |= AC_ERR_DEV; 1412 err_mask |= AC_ERR_DEV;
1395 if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 1413 if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
1396 EDMA_ERR_CRBQ_PAR | EDMA_ERR_CRPB_PAR | 1414 EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR |
1397 EDMA_ERR_INTRL_PAR)) { 1415 EDMA_ERR_INTRL_PAR)) {
1398 err_mask |= AC_ERR_ATA_BUS; 1416 err_mask |= AC_ERR_ATA_BUS;
1399 action |= ATA_EH_HARDRESET; 1417 action |= ATA_EH_HARDRESET;
1400 ata_ehi_push_desc(ehi, ", parity error"); 1418 ata_ehi_push_desc(ehi, "parity error");
1401 } 1419 }
1402 if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { 1420 if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) {
1403 ata_ehi_hotplugged(ehi); 1421 ata_ehi_hotplugged(ehi);
1404 ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? 1422 ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ?
1405 ", dev disconnect" : ", dev connect"); 1423 "dev disconnect" : "dev connect");
1406 } 1424 }
1407 1425
1408 if (IS_GEN_I(hpriv)) { 1426 if (IS_GEN_I(hpriv)) {
@@ -1411,7 +1429,7 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1411 if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 1429 if (edma_err_cause & EDMA_ERR_SELF_DIS_5) {
1412 struct mv_port_priv *pp = ap->private_data; 1430 struct mv_port_priv *pp = ap->private_data;
1413 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1431 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1414 ata_ehi_push_desc(ehi, ", EDMA self-disable"); 1432 ata_ehi_push_desc(ehi, "EDMA self-disable");
1415 } 1433 }
1416 } else { 1434 } else {
1417 eh_freeze_mask = EDMA_EH_FREEZE; 1435 eh_freeze_mask = EDMA_EH_FREEZE;
@@ -1419,7 +1437,7 @@ static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
1419 if (edma_err_cause & EDMA_ERR_SELF_DIS) { 1437 if (edma_err_cause & EDMA_ERR_SELF_DIS) {
1420 struct mv_port_priv *pp = ap->private_data; 1438 struct mv_port_priv *pp = ap->private_data;
1421 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1439 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1422 ata_ehi_push_desc(ehi, ", EDMA self-disable"); 1440 ata_ehi_push_desc(ehi, "EDMA self-disable");
1423 } 1441 }
1424 1442
1425 if (edma_err_cause & EDMA_ERR_SERR) { 1443 if (edma_err_cause & EDMA_ERR_SERR) {
@@ -1489,33 +1507,30 @@ static void mv_intr_edma(struct ata_port *ap)
1489 1507
1490 while (1) { 1508 while (1) {
1491 u16 status; 1509 u16 status;
1510 unsigned int tag;
1492 1511
1493 /* get s/w response queue last-read pointer, and compare */ 1512 /* get s/w response queue last-read pointer, and compare */
1494 out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; 1513 out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK;
1495 if (in_index == out_index) 1514 if (in_index == out_index)
1496 break; 1515 break;
1497 1516
1498
1499 /* 50xx: get active ATA command */ 1517 /* 50xx: get active ATA command */
1500 if (IS_GEN_I(hpriv)) 1518 if (IS_GEN_I(hpriv))
1501 qc = ata_qc_from_tag(ap, ap->active_tag); 1519 tag = ap->active_tag;
1502 1520
1503 /* 60xx: get active ATA command via tag, to enable support 1521 /* Gen II/IIE: get active ATA command via tag, to enable
1504 * for queueing. this works transparently for queued and 1522 * support for queueing. this works transparently for
1505 * non-queued modes. 1523 * queued and non-queued modes.
1506 */ 1524 */
1507 else { 1525 else if (IS_GEN_II(hpriv))
1508 unsigned int tag; 1526 tag = (le16_to_cpu(pp->crpb[out_index].id)
1527 >> CRPB_IOID_SHIFT_6) & 0x3f;
1509 1528
1510 if (IS_GEN_II(hpriv)) 1529 else /* IS_GEN_IIE */
1511 tag = (le16_to_cpu(pp->crpb[out_index].id) 1530 tag = (le16_to_cpu(pp->crpb[out_index].id)
1512 >> CRPB_IOID_SHIFT_6) & 0x3f; 1531 >> CRPB_IOID_SHIFT_7) & 0x3f;
1513 else
1514 tag = (le16_to_cpu(pp->crpb[out_index].id)
1515 >> CRPB_IOID_SHIFT_7) & 0x3f;
1516 1532
1517 qc = ata_qc_from_tag(ap, tag); 1533 qc = ata_qc_from_tag(ap, tag);
1518 }
1519 1534
1520 /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS 1535 /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS
1521 * bits (WARNING: might not necessarily be associated 1536 * bits (WARNING: might not necessarily be associated
@@ -1535,7 +1550,7 @@ static void mv_intr_edma(struct ata_port *ap)
1535 ata_qc_complete(qc); 1550 ata_qc_complete(qc);
1536 } 1551 }
1537 1552
1538 /* advance software response queue pointer, to 1553 /* advance software response queue pointer, to
1539 * indicate (after the loop completes) to hardware 1554 * indicate (after the loop completes) to hardware
1540 * that we have consumed a response queue entry. 1555 * that we have consumed a response queue entry.
1541 */ 1556 */
@@ -1741,26 +1756,30 @@ static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
1741 return ofs; 1756 return ofs;
1742} 1757}
1743 1758
1744static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in) 1759static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
1745{ 1760{
1746 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1761 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1747 void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1762 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
1748 unsigned int ofs = mv5_scr_offset(sc_reg_in); 1763 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1749 1764
1750 if (ofs != 0xffffffffU) 1765 if (ofs != 0xffffffffU) {
1751 return readl(addr + ofs); 1766 *val = readl(addr + ofs);
1752 else 1767 return 0;
1753 return (u32) ofs; 1768 } else
1769 return -EINVAL;
1754} 1770}
1755 1771
1756static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1772static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
1757{ 1773{
1758 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1774 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1759 void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1775 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
1760 unsigned int ofs = mv5_scr_offset(sc_reg_in); 1776 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1761 1777
1762 if (ofs != 0xffffffffU) 1778 if (ofs != 0xffffffffU) {
1763 writelfl(val, addr + ofs); 1779 writelfl(val, addr + ofs);
1780 return 0;
1781 } else
1782 return -EINVAL;
1764} 1783}
1765 1784
1766static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) 1785static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
@@ -2138,9 +2157,17 @@ static void mv_phy_reset(struct ata_port *ap, unsigned int *class,
2138 2157
2139 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 2158 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
2140 2159
2141 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 2160#ifdef DEBUG
2142 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 2161 {
2143 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 2162 u32 sstatus, serror, scontrol;
2163
2164 mv_scr_read(ap, SCR_STATUS, &sstatus);
2165 mv_scr_read(ap, SCR_ERROR, &serror);
2166 mv_scr_read(ap, SCR_CONTROL, &scontrol);
2167 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
2168 "SCtrl 0x%08x\n", status, serror, scontrol);
2169 }
2170#endif
2144 2171
2145 /* Issue COMRESET via SControl */ 2172 /* Issue COMRESET via SControl */
2146comreset_retry: 2173comreset_retry:
@@ -2164,9 +2191,17 @@ comreset_retry:
2164 (retry-- > 0)) 2191 (retry-- > 0))
2165 goto comreset_retry; 2192 goto comreset_retry;
2166 2193
2167 DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " 2194#ifdef DEBUG
2168 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 2195 {
2169 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 2196 u32 sstatus, serror, scontrol;
2197
2198 mv_scr_read(ap, SCR_STATUS, &sstatus);
2199 mv_scr_read(ap, SCR_ERROR, &serror);
2200 mv_scr_read(ap, SCR_CONTROL, &scontrol);
2201 DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
2202 "SCtrl 0x%08x\n", sstatus, serror, scontrol);
2203 }
2204#endif
2170 2205
2171 if (ata_port_offline(ap)) { 2206 if (ata_port_offline(ap)) {
2172 *class = ATA_DEV_NONE; 2207 *class = ATA_DEV_NONE;
@@ -2209,7 +2244,7 @@ static int mv_prereset(struct ata_port *ap, unsigned long deadline)
2209 struct mv_port_priv *pp = ap->private_data; 2244 struct mv_port_priv *pp = ap->private_data;
2210 struct ata_eh_context *ehc = &ap->eh_context; 2245 struct ata_eh_context *ehc = &ap->eh_context;
2211 int rc; 2246 int rc;
2212 2247
2213 rc = mv_stop_dma(ap); 2248 rc = mv_stop_dma(ap);
2214 if (rc) 2249 if (rc)
2215 ehc->i.action |= ATA_EH_HARDRESET; 2250 ehc->i.action |= ATA_EH_HARDRESET;
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index db81e3efa5ec..0b58c4df6fd2 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -236,8 +236,8 @@ static void nv_ck804_host_stop(struct ata_host *host);
236static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); 236static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance);
237static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); 237static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance);
238static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance); 238static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance);
239static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg); 239static int nv_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val);
240static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 240static int nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
241 241
242static void nv_nf2_freeze(struct ata_port *ap); 242static void nv_nf2_freeze(struct ata_port *ap);
243static void nv_nf2_thaw(struct ata_port *ap); 243static void nv_nf2_thaw(struct ata_port *ap);
@@ -715,19 +715,20 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
715 int freeze = 0; 715 int freeze = 0;
716 716
717 ata_ehi_clear_desc(ehi); 717 ata_ehi_clear_desc(ehi);
718 ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x", flags ); 718 __ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x: ", flags );
719 if (flags & NV_CPB_RESP_ATA_ERR) { 719 if (flags & NV_CPB_RESP_ATA_ERR) {
720 ata_ehi_push_desc(ehi, ": ATA error"); 720 ata_ehi_push_desc(ehi, "ATA error");
721 ehi->err_mask |= AC_ERR_DEV; 721 ehi->err_mask |= AC_ERR_DEV;
722 } else if (flags & NV_CPB_RESP_CMD_ERR) { 722 } else if (flags & NV_CPB_RESP_CMD_ERR) {
723 ata_ehi_push_desc(ehi, ": CMD error"); 723 ata_ehi_push_desc(ehi, "CMD error");
724 ehi->err_mask |= AC_ERR_DEV; 724 ehi->err_mask |= AC_ERR_DEV;
725 } else if (flags & NV_CPB_RESP_CPB_ERR) { 725 } else if (flags & NV_CPB_RESP_CPB_ERR) {
726 ata_ehi_push_desc(ehi, ": CPB error"); 726 ata_ehi_push_desc(ehi, "CPB error");
727 ehi->err_mask |= AC_ERR_SYSTEM; 727 ehi->err_mask |= AC_ERR_SYSTEM;
728 freeze = 1; 728 freeze = 1;
729 } else { 729 } else {
730 /* notifier error, but no error in CPB flags? */ 730 /* notifier error, but no error in CPB flags? */
731 ata_ehi_push_desc(ehi, "unknown");
731 ehi->err_mask |= AC_ERR_OTHER; 732 ehi->err_mask |= AC_ERR_OTHER;
732 freeze = 1; 733 freeze = 1;
733 } 734 }
@@ -854,20 +855,21 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
854 struct ata_eh_info *ehi = &ap->eh_info; 855 struct ata_eh_info *ehi = &ap->eh_info;
855 856
856 ata_ehi_clear_desc(ehi); 857 ata_ehi_clear_desc(ehi);
857 ata_ehi_push_desc(ehi, "ADMA status 0x%08x", status ); 858 __ata_ehi_push_desc(ehi, "ADMA status 0x%08x: ", status );
858 if (status & NV_ADMA_STAT_TIMEOUT) { 859 if (status & NV_ADMA_STAT_TIMEOUT) {
859 ehi->err_mask |= AC_ERR_SYSTEM; 860 ehi->err_mask |= AC_ERR_SYSTEM;
860 ata_ehi_push_desc(ehi, ": timeout"); 861 ata_ehi_push_desc(ehi, "timeout");
861 } else if (status & NV_ADMA_STAT_HOTPLUG) { 862 } else if (status & NV_ADMA_STAT_HOTPLUG) {
862 ata_ehi_hotplugged(ehi); 863 ata_ehi_hotplugged(ehi);
863 ata_ehi_push_desc(ehi, ": hotplug"); 864 ata_ehi_push_desc(ehi, "hotplug");
864 } else if (status & NV_ADMA_STAT_HOTUNPLUG) { 865 } else if (status & NV_ADMA_STAT_HOTUNPLUG) {
865 ata_ehi_hotplugged(ehi); 866 ata_ehi_hotplugged(ehi);
866 ata_ehi_push_desc(ehi, ": hot unplug"); 867 ata_ehi_push_desc(ehi, "hot unplug");
867 } else if (status & NV_ADMA_STAT_SERROR) { 868 } else if (status & NV_ADMA_STAT_SERROR) {
868 /* let libata analyze SError and figure out the cause */ 869 /* let libata analyze SError and figure out the cause */
869 ata_ehi_push_desc(ehi, ": SError"); 870 ata_ehi_push_desc(ehi, "SError");
870 } 871 } else
872 ata_ehi_push_desc(ehi, "unknown");
871 ata_port_freeze(ap); 873 ata_port_freeze(ap);
872 continue; 874 continue;
873 } 875 }
@@ -1391,20 +1393,22 @@ static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance)
1391 return ret; 1393 return ret;
1392} 1394}
1393 1395
1394static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg) 1396static int nv_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
1395{ 1397{
1396 if (sc_reg > SCR_CONTROL) 1398 if (sc_reg > SCR_CONTROL)
1397 return 0xffffffffU; 1399 return -EINVAL;
1398 1400
1399 return ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); 1401 *val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4));
1402 return 0;
1400} 1403}
1401 1404
1402static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 1405static int nv_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
1403{ 1406{
1404 if (sc_reg > SCR_CONTROL) 1407 if (sc_reg > SCR_CONTROL)
1405 return; 1408 return -EINVAL;
1406 1409
1407 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 1410 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4));
1411 return 0;
1408} 1412}
1409 1413
1410static void nv_nf2_freeze(struct ata_port *ap) 1414static void nv_nf2_freeze(struct ata_port *ap)
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index d2fcb9a6bec2..d39ebc23c4a9 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -128,8 +128,8 @@ struct pdc_port_priv {
128 dma_addr_t pkt_dma; 128 dma_addr_t pkt_dma;
129}; 129};
130 130
131static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 131static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
132static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 132static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
133static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 133static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
134static int pdc_common_port_start(struct ata_port *ap); 134static int pdc_common_port_start(struct ata_port *ap);
135static int pdc_sata_port_start(struct ata_port *ap); 135static int pdc_sata_port_start(struct ata_port *ap);
@@ -427,19 +427,20 @@ static int pdc_sata_cable_detect(struct ata_port *ap)
427 return ATA_CBL_SATA; 427 return ATA_CBL_SATA;
428} 428}
429 429
430static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 430static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
431{ 431{
432 if (sc_reg > SCR_CONTROL) 432 if (sc_reg > SCR_CONTROL)
433 return 0xffffffffU; 433 return -EINVAL;
434 return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 434 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4));
435 return 0;
435} 436}
436 437
437static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 438static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
438 u32 val)
439{ 439{
440 if (sc_reg > SCR_CONTROL) 440 if (sc_reg > SCR_CONTROL)
441 return; 441 return -EINVAL;
442 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 442 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
443 return 0;
443} 444}
444 445
445static void pdc_atapi_pkt(struct ata_queued_cmd *qc) 446static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
@@ -642,8 +643,12 @@ static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
642 | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR)) 643 | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
643 ac_err_mask |= AC_ERR_HOST_BUS; 644 ac_err_mask |= AC_ERR_HOST_BUS;
644 645
645 if (sata_scr_valid(ap)) 646 if (sata_scr_valid(ap)) {
646 ehi->serror |= pdc_sata_scr_read(ap, SCR_ERROR); 647 u32 serror;
648
649 pdc_sata_scr_read(ap, SCR_ERROR, &serror);
650 ehi->serror |= serror;
651 }
647 652
648 qc->err_mask |= ac_err_mask; 653 qc->err_mask |= ac_err_mask;
649 654
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 9ab554da89bf..c8f9242e7f44 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -111,8 +111,8 @@ struct qs_port_priv {
111 qs_state_t state; 111 qs_state_t state;
112}; 112};
113 113
114static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg); 114static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
115static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 115static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
116static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 116static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
117static int qs_port_start(struct ata_port *ap); 117static int qs_port_start(struct ata_port *ap);
118static void qs_host_stop(struct ata_host *host); 118static void qs_host_stop(struct ata_host *host);
@@ -255,18 +255,20 @@ static void qs_eng_timeout(struct ata_port *ap)
255 ata_eng_timeout(ap); 255 ata_eng_timeout(ap);
256} 256}
257 257
258static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg) 258static int qs_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
259{ 259{
260 if (sc_reg > SCR_CONTROL) 260 if (sc_reg > SCR_CONTROL)
261 return ~0U; 261 return -EINVAL;
262 return readl(ap->ioaddr.scr_addr + (sc_reg * 8)); 262 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 8));
263 return 0;
263} 264}
264 265
265static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 266static int qs_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
266{ 267{
267 if (sc_reg > SCR_CONTROL) 268 if (sc_reg > SCR_CONTROL)
268 return; 269 return -EINVAL;
269 writel(val, ap->ioaddr.scr_addr + (sc_reg * 8)); 270 writel(val, ap->ioaddr.scr_addr + (sc_reg * 8));
271 return 0;
270} 272}
271 273
272static unsigned int qs_fill_sg(struct ata_queued_cmd *qc) 274static unsigned int qs_fill_sg(struct ata_queued_cmd *qc)
@@ -337,7 +339,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
337 buf[28] = dflags; 339 buf[28] = dflags;
338 340
339 /* frame information structure (FIS) */ 341 /* frame information structure (FIS) */
340 ata_tf_to_fis(&qc->tf, &buf[32], 0); 342 ata_tf_to_fis(&qc->tf, 0, 1, &buf[32]);
341} 343}
342 344
343static inline void qs_packet_start(struct ata_queued_cmd *qc) 345static inline void qs_packet_start(struct ata_queued_cmd *qc)
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 2a86dc4598d0..db6763758952 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -115,8 +115,8 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
115static int sil_pci_device_resume(struct pci_dev *pdev); 115static int sil_pci_device_resume(struct pci_dev *pdev);
116#endif 116#endif
117static void sil_dev_config(struct ata_device *dev); 117static void sil_dev_config(struct ata_device *dev);
118static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg); 118static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
119static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 119static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
120static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed); 120static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed);
121static void sil_freeze(struct ata_port *ap); 121static void sil_freeze(struct ata_port *ap);
122static void sil_thaw(struct ata_port *ap); 122static void sil_thaw(struct ata_port *ap);
@@ -350,19 +350,26 @@ static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_re
350 return NULL; 350 return NULL;
351} 351}
352 352
353static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg) 353static int sil_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
354{ 354{
355 void __iomem *mmio = sil_scr_addr(ap, sc_reg); 355 void __iomem *mmio = sil_scr_addr(ap, sc_reg);
356 if (mmio) 356
357 return readl(mmio); 357 if (mmio) {
358 return 0xffffffffU; 358 *val = readl(mmio);
359 return 0;
360 }
361 return -EINVAL;
359} 362}
360 363
361static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 364static int sil_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
362{ 365{
363 void __iomem *mmio = sil_scr_addr(ap, sc_reg); 366 void __iomem *mmio = sil_scr_addr(ap, sc_reg);
364 if (mmio) 367
368 if (mmio) {
365 writel(val, mmio); 369 writel(val, mmio);
370 return 0;
371 }
372 return -EINVAL;
366} 373}
367 374
368static void sil_host_intr(struct ata_port *ap, u32 bmdma2) 375static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
@@ -378,7 +385,7 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
378 * controllers continue to assert IRQ as long as 385 * controllers continue to assert IRQ as long as
379 * SError bits are pending. Clear SError immediately. 386 * SError bits are pending. Clear SError immediately.
380 */ 387 */
381 serror = sil_scr_read(ap, SCR_ERROR); 388 sil_scr_read(ap, SCR_ERROR, &serror);
382 sil_scr_write(ap, SCR_ERROR, serror); 389 sil_scr_write(ap, SCR_ERROR, serror);
383 390
384 /* Trigger hotplug and accumulate SError only if the 391 /* Trigger hotplug and accumulate SError only if the
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index ac43a30ebe29..46fbbe7f121c 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -326,8 +326,8 @@ struct sil24_port_priv {
326 326
327static void sil24_dev_config(struct ata_device *dev); 327static void sil24_dev_config(struct ata_device *dev);
328static u8 sil24_check_status(struct ata_port *ap); 328static u8 sil24_check_status(struct ata_port *ap);
329static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 329static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val);
330static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); 330static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
331static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 331static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
332static void sil24_qc_prep(struct ata_queued_cmd *qc); 332static void sil24_qc_prep(struct ata_queued_cmd *qc);
333static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); 333static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
@@ -464,15 +464,15 @@ static void sil24_dev_config(struct ata_device *dev)
464 writel(PORT_CS_CDB16, port + PORT_CTRL_CLR); 464 writel(PORT_CS_CDB16, port + PORT_CTRL_CLR);
465} 465}
466 466
467static inline void sil24_update_tf(struct ata_port *ap) 467static void sil24_read_tf(struct ata_port *ap, int tag, struct ata_taskfile *tf)
468{ 468{
469 struct sil24_port_priv *pp = ap->private_data;
470 void __iomem *port = ap->ioaddr.cmd_addr; 469 void __iomem *port = ap->ioaddr.cmd_addr;
471 struct sil24_prb __iomem *prb = port; 470 struct sil24_prb __iomem *prb;
472 u8 fis[6 * 4]; 471 u8 fis[6 * 4];
473 472
474 memcpy_fromio(fis, prb->fis, 6 * 4); 473 prb = port + PORT_LRAM + sil24_tag(tag) * PORT_LRAM_SLOT_SZ;
475 ata_tf_from_fis(fis, &pp->tf); 474 memcpy_fromio(fis, prb->fis, sizeof(fis));
475 ata_tf_from_fis(fis, tf);
476} 476}
477 477
478static u8 sil24_check_status(struct ata_port *ap) 478static u8 sil24_check_status(struct ata_port *ap)
@@ -488,25 +488,30 @@ static int sil24_scr_map[] = {
488 [SCR_ACTIVE] = 3, 488 [SCR_ACTIVE] = 3,
489}; 489};
490 490
491static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg) 491static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val)
492{ 492{
493 void __iomem *scr_addr = ap->ioaddr.scr_addr; 493 void __iomem *scr_addr = ap->ioaddr.scr_addr;
494
494 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 495 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
495 void __iomem *addr; 496 void __iomem *addr;
496 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 497 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
497 return readl(scr_addr + sil24_scr_map[sc_reg] * 4); 498 *val = readl(scr_addr + sil24_scr_map[sc_reg] * 4);
499 return 0;
498 } 500 }
499 return 0xffffffffU; 501 return -EINVAL;
500} 502}
501 503
502static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 504static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
503{ 505{
504 void __iomem *scr_addr = ap->ioaddr.scr_addr; 506 void __iomem *scr_addr = ap->ioaddr.scr_addr;
507
505 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 508 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
506 void __iomem *addr; 509 void __iomem *addr;
507 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 510 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
508 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4); 511 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4);
512 return 0;
509 } 513 }
514 return -EINVAL;
510} 515}
511 516
512static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf) 517static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
@@ -531,15 +536,60 @@ static int sil24_init_port(struct ata_port *ap)
531 return 0; 536 return 0;
532} 537}
533 538
534static int sil24_softreset(struct ata_port *ap, unsigned int *class, 539static int sil24_exec_polled_cmd(struct ata_port *ap, int pmp,
535 unsigned long deadline) 540 const struct ata_taskfile *tf,
541 int is_cmd, u32 ctrl,
542 unsigned long timeout_msec)
536{ 543{
537 void __iomem *port = ap->ioaddr.cmd_addr; 544 void __iomem *port = ap->ioaddr.cmd_addr;
538 struct sil24_port_priv *pp = ap->private_data; 545 struct sil24_port_priv *pp = ap->private_data;
539 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; 546 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
540 dma_addr_t paddr = pp->cmd_block_dma; 547 dma_addr_t paddr = pp->cmd_block_dma;
541 u32 mask, irq_stat; 548 u32 irq_enabled, irq_mask, irq_stat;
549 int rc;
550
551 prb->ctrl = cpu_to_le16(ctrl);
552 ata_tf_to_fis(tf, pmp, is_cmd, prb->fis);
553
554 /* temporarily plug completion and error interrupts */
555 irq_enabled = readl(port + PORT_IRQ_ENABLE_SET);
556 writel(PORT_IRQ_COMPLETE | PORT_IRQ_ERROR, port + PORT_IRQ_ENABLE_CLR);
557
558 writel((u32)paddr, port + PORT_CMD_ACTIVATE);
559 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4);
560
561 irq_mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
562 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, irq_mask, 0x0,
563 10, timeout_msec);
564
565 writel(irq_mask, port + PORT_IRQ_STAT); /* clear IRQs */
566 irq_stat >>= PORT_IRQ_RAW_SHIFT;
567
568 if (irq_stat & PORT_IRQ_COMPLETE)
569 rc = 0;
570 else {
571 /* force port into known state */
572 sil24_init_port(ap);
573
574 if (irq_stat & PORT_IRQ_ERROR)
575 rc = -EIO;
576 else
577 rc = -EBUSY;
578 }
579
580 /* restore IRQ enabled */
581 writel(irq_enabled, port + PORT_IRQ_ENABLE_SET);
582
583 return rc;
584}
585
586static int sil24_do_softreset(struct ata_port *ap, unsigned int *class,
587 int pmp, unsigned long deadline)
588{
589 unsigned long timeout_msec = 0;
590 struct ata_taskfile tf;
542 const char *reason; 591 const char *reason;
592 int rc;
543 593
544 DPRINTK("ENTER\n"); 594 DPRINTK("ENTER\n");
545 595
@@ -556,29 +606,22 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class,
556 } 606 }
557 607
558 /* do SRST */ 608 /* do SRST */
559 prb->ctrl = cpu_to_le16(PRB_CTRL_SRST); 609 if (time_after(deadline, jiffies))
560 prb->fis[1] = 0; /* no PMP yet */ 610 timeout_msec = jiffies_to_msecs(deadline - jiffies);
561 611
562 writel((u32)paddr, port + PORT_CMD_ACTIVATE); 612 ata_tf_init(ap->device, &tf); /* doesn't really matter */
563 writel((u64)paddr >> 32, port + PORT_CMD_ACTIVATE + 4); 613 rc = sil24_exec_polled_cmd(ap, pmp, &tf, 0, PRB_CTRL_SRST,
564 614 timeout_msec);
565 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; 615 if (rc == -EBUSY) {
566 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0, 616 reason = "timeout";
567 100, jiffies_to_msecs(deadline - jiffies)); 617 goto err;
568 618 } else if (rc) {
569 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */ 619 reason = "SRST command error";
570 irq_stat >>= PORT_IRQ_RAW_SHIFT;
571
572 if (!(irq_stat & PORT_IRQ_COMPLETE)) {
573 if (irq_stat & PORT_IRQ_ERROR)
574 reason = "SRST command error";
575 else
576 reason = "timeout";
577 goto err; 620 goto err;
578 } 621 }
579 622
580 sil24_update_tf(ap); 623 sil24_read_tf(ap, 0, &tf);
581 *class = ata_dev_classify(&pp->tf); 624 *class = ata_dev_classify(&tf);
582 625
583 if (*class == ATA_DEV_UNKNOWN) 626 if (*class == ATA_DEV_UNKNOWN)
584 *class = ATA_DEV_NONE; 627 *class = ATA_DEV_NONE;
@@ -592,6 +635,12 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class,
592 return -EIO; 635 return -EIO;
593} 636}
594 637
638static int sil24_softreset(struct ata_port *ap, unsigned int *class,
639 unsigned long deadline)
640{
641 return sil24_do_softreset(ap, class, 0, deadline);
642}
643
595static int sil24_hardreset(struct ata_port *ap, unsigned int *class, 644static int sil24_hardreset(struct ata_port *ap, unsigned int *class,
596 unsigned long deadline) 645 unsigned long deadline)
597{ 646{
@@ -699,7 +748,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
699 } 748 }
700 749
701 prb->ctrl = cpu_to_le16(ctrl); 750 prb->ctrl = cpu_to_le16(ctrl);
702 ata_tf_to_fis(&qc->tf, prb->fis, 0); 751 ata_tf_to_fis(&qc->tf, 0, 1, prb->fis);
703 752
704 if (qc->flags & ATA_QCFLAG_DMAMAP) 753 if (qc->flags & ATA_QCFLAG_DMAMAP)
705 sil24_fill_sg(qc, sge); 754 sil24_fill_sg(qc, sge);
@@ -754,6 +803,7 @@ static void sil24_thaw(struct ata_port *ap)
754static void sil24_error_intr(struct ata_port *ap) 803static void sil24_error_intr(struct ata_port *ap)
755{ 804{
756 void __iomem *port = ap->ioaddr.cmd_addr; 805 void __iomem *port = ap->ioaddr.cmd_addr;
806 struct sil24_port_priv *pp = ap->private_data;
757 struct ata_eh_info *ehi = &ap->eh_info; 807 struct ata_eh_info *ehi = &ap->eh_info;
758 int freeze = 0; 808 int freeze = 0;
759 u32 irq_stat; 809 u32 irq_stat;
@@ -769,16 +819,16 @@ static void sil24_error_intr(struct ata_port *ap)
769 819
770 if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) { 820 if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) {
771 ata_ehi_hotplugged(ehi); 821 ata_ehi_hotplugged(ehi);
772 ata_ehi_push_desc(ehi, ", %s", 822 ata_ehi_push_desc(ehi, "%s",
773 irq_stat & PORT_IRQ_PHYRDY_CHG ? 823 irq_stat & PORT_IRQ_PHYRDY_CHG ?
774 "PHY RDY changed" : "device exchanged"); 824 "PHY RDY changed" : "device exchanged");
775 freeze = 1; 825 freeze = 1;
776 } 826 }
777 827
778 if (irq_stat & PORT_IRQ_UNK_FIS) { 828 if (irq_stat & PORT_IRQ_UNK_FIS) {
779 ehi->err_mask |= AC_ERR_HSM; 829 ehi->err_mask |= AC_ERR_HSM;
780 ehi->action |= ATA_EH_SOFTRESET; 830 ehi->action |= ATA_EH_SOFTRESET;
781 ata_ehi_push_desc(ehi , ", unknown FIS"); 831 ata_ehi_push_desc(ehi, "unknown FIS");
782 freeze = 1; 832 freeze = 1;
783 } 833 }
784 834
@@ -797,18 +847,18 @@ static void sil24_error_intr(struct ata_port *ap)
797 if (ci && ci->desc) { 847 if (ci && ci->desc) {
798 err_mask |= ci->err_mask; 848 err_mask |= ci->err_mask;
799 action |= ci->action; 849 action |= ci->action;
800 ata_ehi_push_desc(ehi, ", %s", ci->desc); 850 ata_ehi_push_desc(ehi, "%s", ci->desc);
801 } else { 851 } else {
802 err_mask |= AC_ERR_OTHER; 852 err_mask |= AC_ERR_OTHER;
803 action |= ATA_EH_SOFTRESET; 853 action |= ATA_EH_SOFTRESET;
804 ata_ehi_push_desc(ehi, ", unknown command error %d", 854 ata_ehi_push_desc(ehi, "unknown command error %d",
805 cerr); 855 cerr);
806 } 856 }
807 857
808 /* record error info */ 858 /* record error info */
809 qc = ata_qc_from_tag(ap, ap->active_tag); 859 qc = ata_qc_from_tag(ap, ap->active_tag);
810 if (qc) { 860 if (qc) {
811 sil24_update_tf(ap); 861 sil24_read_tf(ap, qc->tag, &pp->tf);
812 qc->err_mask |= err_mask; 862 qc->err_mask |= err_mask;
813 } else 863 } else
814 ehi->err_mask |= err_mask; 864 ehi->err_mask |= err_mask;
@@ -825,8 +875,11 @@ static void sil24_error_intr(struct ata_port *ap)
825 875
826static void sil24_finish_qc(struct ata_queued_cmd *qc) 876static void sil24_finish_qc(struct ata_queued_cmd *qc)
827{ 877{
878 struct ata_port *ap = qc->ap;
879 struct sil24_port_priv *pp = ap->private_data;
880
828 if (qc->flags & ATA_QCFLAG_RESULT_TF) 881 if (qc->flags & ATA_QCFLAG_RESULT_TF)
829 sil24_update_tf(qc->ap); 882 sil24_read_tf(ap, qc->tag, &pp->tf);
830} 883}
831 884
832static inline void sil24_host_intr(struct ata_port *ap) 885static inline void sil24_host_intr(struct ata_port *ap)
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 33716b00c6b7..31a2f55aae66 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -64,8 +64,8 @@ enum {
64}; 64};
65 65
66static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 66static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
67static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg); 67static int sis_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val);
68static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 68static int sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
69 69
70static const struct pci_device_id sis_pci_tbl[] = { 70static const struct pci_device_id sis_pci_tbl[] = {
71 { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */ 71 { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */
@@ -207,36 +207,37 @@ static void sis_scr_cfg_write (struct ata_port *ap, unsigned int sc_reg, u32 val
207 pci_write_config_dword(pdev, cfg_addr+0x10, val); 207 pci_write_config_dword(pdev, cfg_addr+0x10, val);
208} 208}
209 209
210static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg) 210static int sis_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
211{ 211{
212 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 212 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
213 u32 val, val2 = 0;
214 u8 pmr; 213 u8 pmr;
215 214
216 if (sc_reg > SCR_CONTROL) 215 if (sc_reg > SCR_CONTROL)
217 return 0xffffffffU; 216 return -EINVAL;
218 217
219 if (ap->flags & SIS_FLAG_CFGSCR) 218 if (ap->flags & SIS_FLAG_CFGSCR)
220 return sis_scr_cfg_read(ap, sc_reg); 219 return sis_scr_cfg_read(ap, sc_reg);
221 220
222 pci_read_config_byte(pdev, SIS_PMR, &pmr); 221 pci_read_config_byte(pdev, SIS_PMR, &pmr);
223 222
224 val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4)); 223 *val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4));
225 224
226 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || 225 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) ||
227 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) 226 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED))
228 val2 = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10); 227 *val |= ioread32(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10);
228
229 *val &= 0xfffffffb;
229 230
230 return (val | val2) & 0xfffffffb; 231 return 0;
231} 232}
232 233
233static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 234static int sis_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
234{ 235{
235 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 236 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
236 u8 pmr; 237 u8 pmr;
237 238
238 if (sc_reg > SCR_CONTROL) 239 if (sc_reg > SCR_CONTROL)
239 return; 240 return -EINVAL;
240 241
241 pci_read_config_byte(pdev, SIS_PMR, &pmr); 242 pci_read_config_byte(pdev, SIS_PMR, &pmr);
242 243
@@ -248,6 +249,7 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
248 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED)) 249 (pdev->device == 0x1182) || (pmr & SIS_PMR_COMBINED))
249 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10); 250 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10);
250 } 251 }
252 return 0;
251} 253}
252 254
253static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 255static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index 63fe99afd59f..92e877075037 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -103,20 +103,21 @@ static int k2_sata_check_atapi_dma(struct ata_queued_cmd *qc)
103 return 0; 103 return 0;
104} 104}
105 105
106static u32 k2_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 106static int k2_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
107{ 107{
108 if (sc_reg > SCR_CONTROL) 108 if (sc_reg > SCR_CONTROL)
109 return 0xffffffffU; 109 return -EINVAL;
110 return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 110 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4));
111 return 0;
111} 112}
112 113
113 114
114static void k2_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 115static int k2_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
115 u32 val)
116{ 116{
117 if (sc_reg > SCR_CONTROL) 117 if (sc_reg > SCR_CONTROL)
118 return; 118 return -EINVAL;
119 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 119 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
120 return 0;
120} 121}
121 122
122 123
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index b52f83ab056a..78c28512f01c 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -57,8 +57,8 @@ struct uli_priv {
57}; 57};
58 58
59static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 59static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
60static u32 uli_scr_read (struct ata_port *ap, unsigned int sc_reg); 60static int uli_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val);
61static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 61static int uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
62 62
63static const struct pci_device_id uli_pci_tbl[] = { 63static const struct pci_device_id uli_pci_tbl[] = {
64 { PCI_VDEVICE(AL, 0x5289), uli_5289 }, 64 { PCI_VDEVICE(AL, 0x5289), uli_5289 },
@@ -164,20 +164,22 @@ static void uli_scr_cfg_write (struct ata_port *ap, unsigned int scr, u32 val)
164 pci_write_config_dword(pdev, cfg_addr, val); 164 pci_write_config_dword(pdev, cfg_addr, val);
165} 165}
166 166
167static u32 uli_scr_read (struct ata_port *ap, unsigned int sc_reg) 167static int uli_scr_read (struct ata_port *ap, unsigned int sc_reg, u32 *val)
168{ 168{
169 if (sc_reg > SCR_CONTROL) 169 if (sc_reg > SCR_CONTROL)
170 return 0xffffffffU; 170 return -EINVAL;
171 171
172 return uli_scr_cfg_read(ap, sc_reg); 172 *val = uli_scr_cfg_read(ap, sc_reg);
173 return 0;
173} 174}
174 175
175static void uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 176static int uli_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
176{ 177{
177 if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0 178 if (sc_reg > SCR_CONTROL) //SCR_CONTROL=2, SCR_ERROR=1, SCR_STATUS=0
178 return; 179 return -EINVAL;
179 180
180 uli_scr_cfg_write(ap, sc_reg, val); 181 uli_scr_cfg_write(ap, sc_reg, val);
182 return 0;
181} 183}
182 184
183static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 185static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index c4124475f754..86b7bfc17324 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -72,8 +72,8 @@ enum {
72}; 72};
73 73
74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 74static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
75static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg); 75static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 76static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void svia_noop_freeze(struct ata_port *ap); 77static void svia_noop_freeze(struct ata_port *ap);
78static void vt6420_error_handler(struct ata_port *ap); 78static void vt6420_error_handler(struct ata_port *ap);
79static int vt6421_pata_cable_detect(struct ata_port *ap); 79static int vt6421_pata_cable_detect(struct ata_port *ap);
@@ -249,18 +249,20 @@ MODULE_LICENSE("GPL");
249MODULE_DEVICE_TABLE(pci, svia_pci_tbl); 249MODULE_DEVICE_TABLE(pci, svia_pci_tbl);
250MODULE_VERSION(DRV_VERSION); 250MODULE_VERSION(DRV_VERSION);
251 251
252static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg) 252static int svia_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
253{ 253{
254 if (sc_reg > SCR_CONTROL) 254 if (sc_reg > SCR_CONTROL)
255 return 0xffffffffU; 255 return -EINVAL;
256 return ioread32(ap->ioaddr.scr_addr + (4 * sc_reg)); 256 *val = ioread32(ap->ioaddr.scr_addr + (4 * sc_reg));
257 return 0;
257} 258}
258 259
259static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 260static int svia_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
260{ 261{
261 if (sc_reg > SCR_CONTROL) 262 if (sc_reg > SCR_CONTROL)
262 return; 263 return -EINVAL;
263 iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 264 iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg));
265 return 0;
264} 266}
265 267
266static void svia_noop_freeze(struct ata_port *ap) 268static void svia_noop_freeze(struct ata_port *ap)
@@ -305,18 +307,19 @@ static int vt6420_prereset(struct ata_port *ap, unsigned long deadline)
305 307
306 /* Resume phy. This is the old SATA resume sequence */ 308 /* Resume phy. This is the old SATA resume sequence */
307 svia_scr_write(ap, SCR_CONTROL, 0x300); 309 svia_scr_write(ap, SCR_CONTROL, 0x300);
308 svia_scr_read(ap, SCR_CONTROL); /* flush */ 310 svia_scr_read(ap, SCR_CONTROL, &scontrol); /* flush */
309 311
310 /* wait for phy to become ready, if necessary */ 312 /* wait for phy to become ready, if necessary */
311 do { 313 do {
312 msleep(200); 314 msleep(200);
313 if ((svia_scr_read(ap, SCR_STATUS) & 0xf) != 1) 315 svia_scr_read(ap, SCR_STATUS, &sstatus);
316 if ((sstatus & 0xf) != 1)
314 break; 317 break;
315 } while (time_before(jiffies, timeout)); 318 } while (time_before(jiffies, timeout));
316 319
317 /* open code sata_print_link_status() */ 320 /* open code sata_print_link_status() */
318 sstatus = svia_scr_read(ap, SCR_STATUS); 321 svia_scr_read(ap, SCR_STATUS, &sstatus);
319 scontrol = svia_scr_read(ap, SCR_CONTROL); 322 svia_scr_read(ap, SCR_CONTROL, &scontrol);
320 323
321 online = (sstatus & 0xf) == 0x3; 324 online = (sstatus & 0xf) == 0x3;
322 325
@@ -325,7 +328,7 @@ static int vt6420_prereset(struct ata_port *ap, unsigned long deadline)
325 online ? "up" : "down", sstatus, scontrol); 328 online ? "up" : "down", sstatus, scontrol);
326 329
327 /* SStatus is read one more time */ 330 /* SStatus is read one more time */
328 svia_scr_read(ap, SCR_STATUS); 331 svia_scr_read(ap, SCR_STATUS, &sstatus);
329 332
330 if (!online) { 333 if (!online) {
331 /* tell EH to bail */ 334 /* tell EH to bail */
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 1b5d81faa102..24344d0d0575 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -98,20 +98,21 @@ enum {
98 VSC_SATA_INT_PHY_CHANGE), 98 VSC_SATA_INT_PHY_CHANGE),
99}; 99};
100 100
101static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 101static int vsc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
102{ 102{
103 if (sc_reg > SCR_CONTROL) 103 if (sc_reg > SCR_CONTROL)
104 return 0xffffffffU; 104 return -EINVAL;
105 return readl(ap->ioaddr.scr_addr + (sc_reg * 4)); 105 *val = readl(ap->ioaddr.scr_addr + (sc_reg * 4));
106 return 0;
106} 107}
107 108
108 109
109static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 110static int vsc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
110 u32 val)
111{ 111{
112 if (sc_reg > SCR_CONTROL) 112 if (sc_reg > SCR_CONTROL)
113 return; 113 return -EINVAL;
114 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 114 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
115 return 0;
115} 116}
116 117
117 118
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index a9ab30fefffc..2b0c601e422e 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -142,6 +142,7 @@ void set_trace_device(struct device *dev)
142{ 142{
143 dev_hash_value = hash_string(DEVSEED, dev->bus_id, DEVHASH); 143 dev_hash_value = hash_string(DEVSEED, dev->bus_id, DEVHASH);
144} 144}
145EXPORT_SYMBOL(set_trace_device);
145 146
146/* 147/*
147 * We could just take the "tracedata" index into the .tracedata 148 * We could just take the "tracedata" index into the .tracedata
@@ -162,6 +163,7 @@ void generate_resume_trace(void *tracedata, unsigned int user)
162 file_hash_value = hash_string(lineno, file, FILEHASH); 163 file_hash_value = hash_string(lineno, file, FILEHASH);
163 set_magic_time(user_hash_value, file_hash_value, dev_hash_value); 164 set_magic_time(user_hash_value, file_hash_value, dev_hash_value);
164} 165}
166EXPORT_SYMBOL(generate_resume_trace);
165 167
166extern char __tracedata_start, __tracedata_end; 168extern char __tracedata_start, __tracedata_end;
167static int show_file_hash(unsigned int value) 169static int show_file_hash(unsigned int value)
@@ -170,7 +172,8 @@ static int show_file_hash(unsigned int value)
170 char *tracedata; 172 char *tracedata;
171 173
172 match = 0; 174 match = 0;
173 for (tracedata = &__tracedata_start ; tracedata < &__tracedata_end ; tracedata += 6) { 175 for (tracedata = &__tracedata_start ; tracedata < &__tracedata_end ;
176 tracedata += 2 + sizeof(unsigned long)) {
174 unsigned short lineno = *(unsigned short *)tracedata; 177 unsigned short lineno = *(unsigned short *)tracedata;
175 const char *file = *(const char **)(tracedata + 2); 178 const char *file = *(const char **)(tracedata + 2);
176 unsigned int hash = hash_string(lineno, file, FILEHASH); 179 unsigned int hash = hash_string(lineno, file, FILEHASH);
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 819c829125fb..a7a099027fca 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -8,6 +8,7 @@
8obj-$(CONFIG_MAC_FLOPPY) += swim3.o 8obj-$(CONFIG_MAC_FLOPPY) += swim3.o
9obj-$(CONFIG_BLK_DEV_FD) += floppy.o 9obj-$(CONFIG_BLK_DEV_FD) += floppy.o
10obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o 10obj-$(CONFIG_AMIGA_FLOPPY) += amiflop.o
11obj-$(CONFIG_PS3_DISK) += ps3disk.o
11obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o 12obj-$(CONFIG_ATARI_FLOPPY) += ataflop.o
12obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o 13obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o
13obj-$(CONFIG_BLK_DEV_RAM) += rd.o 14obj-$(CONFIG_BLK_DEV_RAM) += rd.o
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
new file mode 100644
index 000000000000..170fb33dba97
--- /dev/null
+++ b/drivers/block/ps3disk.c
@@ -0,0 +1,630 @@
1/*
2 * PS3 Disk Storage Driver
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/ata.h>
22#include <linux/blkdev.h>
23
24#include <asm/lv1call.h>
25#include <asm/ps3stor.h>
26#include <asm/firmware.h>
27
28
29#define DEVICE_NAME "ps3disk"
30
31#define BOUNCE_SIZE (64*1024)
32
33#define PS3DISK_MAX_DISKS 16
34#define PS3DISK_MINORS 16
35
36
37#define PS3DISK_NAME "ps3d%c"
38
39
40struct ps3disk_private {
41 spinlock_t lock; /* Request queue spinlock */
42 struct request_queue *queue;
43 struct gendisk *gendisk;
44 unsigned int blocking_factor;
45 struct request *req;
46 u64 raw_capacity;
47 unsigned char model[ATA_ID_PROD_LEN+1];
48};
49
50
51#define LV1_STORAGE_SEND_ATA_COMMAND (2)
52#define LV1_STORAGE_ATA_HDDOUT (0x23)
53
54struct lv1_ata_cmnd_block {
55 u16 features;
56 u16 sector_count;
57 u16 LBA_low;
58 u16 LBA_mid;
59 u16 LBA_high;
60 u8 device;
61 u8 command;
62 u32 is_ext;
63 u32 proto;
64 u32 in_out;
65 u32 size;
66 u64 buffer;
67 u32 arglen;
68};
69
70enum lv1_ata_proto {
71 NON_DATA_PROTO = 0,
72 PIO_DATA_IN_PROTO = 1,
73 PIO_DATA_OUT_PROTO = 2,
74 DMA_PROTO = 3
75};
76
77enum lv1_ata_in_out {
78 DIR_WRITE = 0, /* memory -> device */
79 DIR_READ = 1 /* device -> memory */
80};
81
82static int ps3disk_major;
83
84
85static struct block_device_operations ps3disk_fops = {
86 .owner = THIS_MODULE,
87};
88
89
90static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
91 struct request *req, int gather)
92{
93 unsigned int offset = 0;
94 struct bio *bio;
95 sector_t sector;
96 struct bio_vec *bvec;
97 unsigned int i = 0, j;
98 size_t size;
99 void *buf;
100
101 rq_for_each_bio(bio, req) {
102 sector = bio->bi_sector;
103 dev_dbg(&dev->sbd.core,
104 "%s:%u: bio %u: %u segs %u sectors from %lu\n",
105 __func__, __LINE__, i, bio_segments(bio),
106 bio_sectors(bio), sector);
107 bio_for_each_segment(bvec, bio, j) {
108 size = bvec->bv_len;
109 buf = __bio_kmap_atomic(bio, j, KM_IRQ0);
110 if (gather)
111 memcpy(dev->bounce_buf+offset, buf, size);
112 else
113 memcpy(buf, dev->bounce_buf+offset, size);
114 offset += size;
115 flush_kernel_dcache_page(bio_iovec_idx(bio, j)->bv_page);
116 __bio_kunmap_atomic(bio, KM_IRQ0);
117 }
118 i++;
119 }
120}
121
122static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
123 struct request *req)
124{
125 struct ps3disk_private *priv = dev->sbd.core.driver_data;
126 int write = rq_data_dir(req), res;
127 const char *op = write ? "write" : "read";
128 u64 start_sector, sectors;
129 unsigned int region_id = dev->regions[dev->region_idx].id;
130
131#ifdef DEBUG
132 unsigned int n = 0;
133 struct bio *bio;
134
135 rq_for_each_bio(bio, req)
136 n++;
137 dev_dbg(&dev->sbd.core,
138 "%s:%u: %s req has %u bios for %lu sectors %lu hard sectors\n",
139 __func__, __LINE__, op, n, req->nr_sectors,
140 req->hard_nr_sectors);
141#endif
142
143 start_sector = req->sector * priv->blocking_factor;
144 sectors = req->nr_sectors * priv->blocking_factor;
145 dev_dbg(&dev->sbd.core, "%s:%u: %s %lu sectors starting at %lu\n",
146 __func__, __LINE__, op, sectors, start_sector);
147
148 if (write) {
149 ps3disk_scatter_gather(dev, req, 1);
150
151 res = lv1_storage_write(dev->sbd.dev_id, region_id,
152 start_sector, sectors, 0,
153 dev->bounce_lpar, &dev->tag);
154 } else {
155 res = lv1_storage_read(dev->sbd.dev_id, region_id,
156 start_sector, sectors, 0,
157 dev->bounce_lpar, &dev->tag);
158 }
159 if (res) {
160 dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
161 __LINE__, op, res);
162 end_request(req, 0);
163 return 0;
164 }
165
166 priv->req = req;
167 return 1;
168}
169
170static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
171 struct request *req)
172{
173 struct ps3disk_private *priv = dev->sbd.core.driver_data;
174 u64 res;
175
176 dev_dbg(&dev->sbd.core, "%s:%u: flush request\n", __func__, __LINE__);
177
178 res = lv1_storage_send_device_command(dev->sbd.dev_id,
179 LV1_STORAGE_ATA_HDDOUT, 0, 0, 0,
180 0, &dev->tag);
181 if (res) {
182 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%lx\n",
183 __func__, __LINE__, res);
184 end_request(req, 0);
185 return 0;
186 }
187
188 priv->req = req;
189 return 1;
190}
191
192static void ps3disk_do_request(struct ps3_storage_device *dev,
193 request_queue_t *q)
194{
195 struct request *req;
196
197 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
198
199 while ((req = elv_next_request(q))) {
200 if (blk_fs_request(req)) {
201 if (ps3disk_submit_request_sg(dev, req))
202 break;
203 } else if (req->cmd_type == REQ_TYPE_FLUSH) {
204 if (ps3disk_submit_flush_request(dev, req))
205 break;
206 } else {
207 blk_dump_rq_flags(req, DEVICE_NAME " bad request");
208 end_request(req, 0);
209 continue;
210 }
211 }
212}
213
214static void ps3disk_request(request_queue_t *q)
215{
216 struct ps3_storage_device *dev = q->queuedata;
217 struct ps3disk_private *priv = dev->sbd.core.driver_data;
218
219 if (priv->req) {
220 dev_dbg(&dev->sbd.core, "%s:%u busy\n", __func__, __LINE__);
221 return;
222 }
223
224 ps3disk_do_request(dev, q);
225}
226
227static irqreturn_t ps3disk_interrupt(int irq, void *data)
228{
229 struct ps3_storage_device *dev = data;
230 struct ps3disk_private *priv;
231 struct request *req;
232 int res, read, uptodate;
233 u64 tag, status;
234 unsigned long num_sectors;
235 const char *op;
236
237 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
238
239 if (tag != dev->tag)
240 dev_err(&dev->sbd.core,
241 "%s:%u: tag mismatch, got %lx, expected %lx\n",
242 __func__, __LINE__, tag, dev->tag);
243
244 if (res) {
245 dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%lx\n",
246 __func__, __LINE__, res, status);
247 return IRQ_HANDLED;
248 }
249
250 priv = dev->sbd.core.driver_data;
251 req = priv->req;
252 if (!req) {
253 dev_dbg(&dev->sbd.core,
254 "%s:%u non-block layer request completed\n", __func__,
255 __LINE__);
256 dev->lv1_status = status;
257 complete(&dev->done);
258 return IRQ_HANDLED;
259 }
260
261 if (req->cmd_type == REQ_TYPE_FLUSH) {
262 read = 0;
263 num_sectors = req->hard_cur_sectors;
264 op = "flush";
265 } else {
266 read = !rq_data_dir(req);
267 num_sectors = req->nr_sectors;
268 op = read ? "read" : "write";
269 }
270 if (status) {
271 dev_dbg(&dev->sbd.core, "%s:%u: %s failed 0x%lx\n", __func__,
272 __LINE__, op, status);
273 uptodate = 0;
274 } else {
275 dev_dbg(&dev->sbd.core, "%s:%u: %s completed\n", __func__,
276 __LINE__, op);
277 uptodate = 1;
278 if (read)
279 ps3disk_scatter_gather(dev, req, 0);
280 }
281
282 spin_lock(&priv->lock);
283 if (!end_that_request_first(req, uptodate, num_sectors)) {
284 add_disk_randomness(req->rq_disk);
285 blkdev_dequeue_request(req);
286 end_that_request_last(req, uptodate);
287 }
288 priv->req = NULL;
289 ps3disk_do_request(dev, priv->queue);
290 spin_unlock(&priv->lock);
291
292 return IRQ_HANDLED;
293}
294
295static int ps3disk_sync_cache(struct ps3_storage_device *dev)
296{
297 u64 res;
298
299 dev_dbg(&dev->sbd.core, "%s:%u: sync cache\n", __func__, __LINE__);
300
301 res = ps3stor_send_command(dev, LV1_STORAGE_ATA_HDDOUT, 0, 0, 0, 0);
302 if (res) {
303 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%lx\n",
304 __func__, __LINE__, res);
305 return -EIO;
306 }
307 return 0;
308}
309
310
311/* ATA helpers copied from drivers/ata/libata-core.c */
312
313static void swap_buf_le16(u16 *buf, unsigned int buf_words)
314{
315#ifdef __BIG_ENDIAN
316 unsigned int i;
317
318 for (i = 0; i < buf_words; i++)
319 buf[i] = le16_to_cpu(buf[i]);
320#endif /* __BIG_ENDIAN */
321}
322
323static u64 ata_id_n_sectors(const u16 *id)
324{
325 if (ata_id_has_lba(id)) {
326 if (ata_id_has_lba48(id))
327 return ata_id_u64(id, 100);
328 else
329 return ata_id_u32(id, 60);
330 } else {
331 if (ata_id_current_chs_valid(id))
332 return ata_id_u32(id, 57);
333 else
334 return id[1] * id[3] * id[6];
335 }
336}
337
338static void ata_id_string(const u16 *id, unsigned char *s, unsigned int ofs,
339 unsigned int len)
340{
341 unsigned int c;
342
343 while (len > 0) {
344 c = id[ofs] >> 8;
345 *s = c;
346 s++;
347
348 c = id[ofs] & 0xff;
349 *s = c;
350 s++;
351
352 ofs++;
353 len -= 2;
354 }
355}
356
357static void ata_id_c_string(const u16 *id, unsigned char *s, unsigned int ofs,
358 unsigned int len)
359{
360 unsigned char *p;
361
362 WARN_ON(!(len & 1));
363
364 ata_id_string(id, s, ofs, len - 1);
365
366 p = s + strnlen(s, len - 1);
367 while (p > s && p[-1] == ' ')
368 p--;
369 *p = '\0';
370}
371
372static int ps3disk_identify(struct ps3_storage_device *dev)
373{
374 struct ps3disk_private *priv = dev->sbd.core.driver_data;
375 struct lv1_ata_cmnd_block ata_cmnd;
376 u16 *id = dev->bounce_buf;
377 u64 res;
378
379 dev_dbg(&dev->sbd.core, "%s:%u: identify disk\n", __func__, __LINE__);
380
381 memset(&ata_cmnd, 0, sizeof(struct lv1_ata_cmnd_block));
382 ata_cmnd.command = ATA_CMD_ID_ATA;
383 ata_cmnd.sector_count = 1;
384 ata_cmnd.size = ata_cmnd.arglen = ATA_ID_WORDS * 2;
385 ata_cmnd.buffer = dev->bounce_lpar;
386 ata_cmnd.proto = PIO_DATA_IN_PROTO;
387 ata_cmnd.in_out = DIR_READ;
388
389 res = ps3stor_send_command(dev, LV1_STORAGE_SEND_ATA_COMMAND,
390 ps3_mm_phys_to_lpar(__pa(&ata_cmnd)),
391 sizeof(ata_cmnd), ata_cmnd.buffer,
392 ata_cmnd.arglen);
393 if (res) {
394 dev_err(&dev->sbd.core, "%s:%u: identify disk failed 0x%lx\n",
395 __func__, __LINE__, res);
396 return -EIO;
397 }
398
399 swap_buf_le16(id, ATA_ID_WORDS);
400
401 /* All we're interested in are raw capacity and model name */
402 priv->raw_capacity = ata_id_n_sectors(id);
403 ata_id_c_string(id, priv->model, ATA_ID_PROD, sizeof(priv->model));
404 return 0;
405}
406
407static void ps3disk_prepare_flush(request_queue_t *q, struct request *req)
408{
409 struct ps3_storage_device *dev = q->queuedata;
410
411 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
412
413 memset(req->cmd, 0, sizeof(req->cmd));
414 req->cmd_type = REQ_TYPE_FLUSH;
415}
416
417static int ps3disk_issue_flush(request_queue_t *q, struct gendisk *gendisk,
418 sector_t *sector)
419{
420 struct ps3_storage_device *dev = q->queuedata;
421 struct request *req;
422 int res;
423
424 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
425
426 req = blk_get_request(q, WRITE, __GFP_WAIT);
427 ps3disk_prepare_flush(q, req);
428 res = blk_execute_rq(q, gendisk, req, 0);
429 if (res)
430 dev_err(&dev->sbd.core, "%s:%u: flush request failed %d\n",
431 __func__, __LINE__, res);
432 blk_put_request(req);
433 return res;
434}
435
436
437static unsigned long ps3disk_mask;
438
439static DEFINE_MUTEX(ps3disk_mask_mutex);
440
441static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
442{
443 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
444 struct ps3disk_private *priv;
445 int error;
446 unsigned int devidx;
447 struct request_queue *queue;
448 struct gendisk *gendisk;
449
450 if (dev->blk_size < 512) {
451 dev_err(&dev->sbd.core,
452 "%s:%u: cannot handle block size %lu\n", __func__,
453 __LINE__, dev->blk_size);
454 return -EINVAL;
455 }
456
457 BUILD_BUG_ON(PS3DISK_MAX_DISKS > BITS_PER_LONG);
458 mutex_lock(&ps3disk_mask_mutex);
459 devidx = find_first_zero_bit(&ps3disk_mask, PS3DISK_MAX_DISKS);
460 if (devidx >= PS3DISK_MAX_DISKS) {
461 dev_err(&dev->sbd.core, "%s:%u: Too many disks\n", __func__,
462 __LINE__);
463 mutex_unlock(&ps3disk_mask_mutex);
464 return -ENOSPC;
465 }
466 __set_bit(devidx, &ps3disk_mask);
467 mutex_unlock(&ps3disk_mask_mutex);
468
469 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
470 if (!priv) {
471 error = -ENOMEM;
472 goto fail;
473 }
474
475 dev->sbd.core.driver_data = priv;
476 spin_lock_init(&priv->lock);
477
478 dev->bounce_size = BOUNCE_SIZE;
479 dev->bounce_buf = kmalloc(BOUNCE_SIZE, GFP_DMA);
480 if (!dev->bounce_buf) {
481 error = -ENOMEM;
482 goto fail_free_priv;
483 }
484
485 error = ps3stor_setup(dev, ps3disk_interrupt);
486 if (error)
487 goto fail_free_bounce;
488
489 ps3disk_identify(dev);
490
491 queue = blk_init_queue(ps3disk_request, &priv->lock);
492 if (!queue) {
493 dev_err(&dev->sbd.core, "%s:%u: blk_init_queue failed\n",
494 __func__, __LINE__);
495 error = -ENOMEM;
496 goto fail_teardown;
497 }
498
499 priv->queue = queue;
500 queue->queuedata = dev;
501
502 blk_queue_bounce_limit(queue, BLK_BOUNCE_HIGH);
503
504 blk_queue_max_sectors(queue, dev->bounce_size >> 9);
505 blk_queue_segment_boundary(queue, -1UL);
506 blk_queue_dma_alignment(queue, dev->blk_size-1);
507 blk_queue_hardsect_size(queue, dev->blk_size);
508
509 blk_queue_issue_flush_fn(queue, ps3disk_issue_flush);
510 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH,
511 ps3disk_prepare_flush);
512
513 blk_queue_max_phys_segments(queue, -1);
514 blk_queue_max_hw_segments(queue, -1);
515 blk_queue_max_segment_size(queue, dev->bounce_size);
516
517 gendisk = alloc_disk(PS3DISK_MINORS);
518 if (!gendisk) {
519 dev_err(&dev->sbd.core, "%s:%u: alloc_disk failed\n", __func__,
520 __LINE__);
521 error = -ENOMEM;
522 goto fail_cleanup_queue;
523 }
524
525 priv->gendisk = gendisk;
526 gendisk->major = ps3disk_major;
527 gendisk->first_minor = devidx * PS3DISK_MINORS;
528 gendisk->fops = &ps3disk_fops;
529 gendisk->queue = queue;
530 gendisk->private_data = dev;
531 gendisk->driverfs_dev = &dev->sbd.core;
532 snprintf(gendisk->disk_name, sizeof(gendisk->disk_name), PS3DISK_NAME,
533 devidx+'a');
534 priv->blocking_factor = dev->blk_size >> 9;
535 set_capacity(gendisk,
536 dev->regions[dev->region_idx].size*priv->blocking_factor);
537
538 dev_info(&dev->sbd.core,
539 "%s is a %s (%lu MiB total, %lu MiB for OtherOS)\n",
540 gendisk->disk_name, priv->model, priv->raw_capacity >> 11,
541 get_capacity(gendisk) >> 11);
542
543 add_disk(gendisk);
544 return 0;
545
546fail_cleanup_queue:
547 blk_cleanup_queue(queue);
548fail_teardown:
549 ps3stor_teardown(dev);
550fail_free_bounce:
551 kfree(dev->bounce_buf);
552fail_free_priv:
553 kfree(priv);
554 dev->sbd.core.driver_data = NULL;
555fail:
556 mutex_lock(&ps3disk_mask_mutex);
557 __clear_bit(devidx, &ps3disk_mask);
558 mutex_unlock(&ps3disk_mask_mutex);
559 return error;
560}
561
562static int ps3disk_remove(struct ps3_system_bus_device *_dev)
563{
564 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
565 struct ps3disk_private *priv = dev->sbd.core.driver_data;
566
567 mutex_lock(&ps3disk_mask_mutex);
568 __clear_bit(priv->gendisk->first_minor / PS3DISK_MINORS,
569 &ps3disk_mask);
570 mutex_unlock(&ps3disk_mask_mutex);
571 del_gendisk(priv->gendisk);
572 blk_cleanup_queue(priv->queue);
573 put_disk(priv->gendisk);
574 dev_notice(&dev->sbd.core, "Synchronizing disk cache\n");
575 ps3disk_sync_cache(dev);
576 ps3stor_teardown(dev);
577 kfree(dev->bounce_buf);
578 kfree(priv);
579 dev->sbd.core.driver_data = NULL;
580 return 0;
581}
582
583static struct ps3_system_bus_driver ps3disk = {
584 .match_id = PS3_MATCH_ID_STOR_DISK,
585 .core.name = DEVICE_NAME,
586 .core.owner = THIS_MODULE,
587 .probe = ps3disk_probe,
588 .remove = ps3disk_remove,
589 .shutdown = ps3disk_remove,
590};
591
592
593static int __init ps3disk_init(void)
594{
595 int error;
596
597 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
598 return -ENODEV;
599
600 error = register_blkdev(0, DEVICE_NAME);
601 if (error <= 0) {
602 printk(KERN_ERR "%s:%u: register_blkdev failed %d\n", __func__,
603 __LINE__, error);
604 return error;
605 }
606 ps3disk_major = error;
607
608 pr_info("%s:%u: registered block device major %d\n", __func__,
609 __LINE__, ps3disk_major);
610
611 error = ps3_system_bus_driver_register(&ps3disk);
612 if (error)
613 unregister_blkdev(ps3disk_major, DEVICE_NAME);
614
615 return error;
616}
617
618static void __exit ps3disk_exit(void)
619{
620 ps3_system_bus_driver_unregister(&ps3disk);
621 unregister_blkdev(ps3disk_major, DEVICE_NAME);
622}
623
624module_init(ps3disk_init);
625module_exit(ps3disk_exit);
626
627MODULE_LICENSE("GPL");
628MODULE_DESCRIPTION("PS3 Disk Storage Driver");
629MODULE_AUTHOR("Sony Corporation");
630MODULE_ALIAS(PS3_MODULE_ALIAS_STOR_DISK);
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 2288b55d916f..d50b82381155 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -64,7 +64,6 @@ struct vdc_port {
64 u64 operations; 64 u64 operations;
65 u32 vdisk_size; 65 u32 vdisk_size;
66 u8 vdisk_type; 66 u8 vdisk_type;
67 u8 dev_no;
68 67
69 char disk_name[32]; 68 char disk_name[32];
70 69
@@ -703,7 +702,7 @@ static int probe_disk(struct vdc_port *port)
703 blk_queue_max_phys_segments(q, port->ring_cookies); 702 blk_queue_max_phys_segments(q, port->ring_cookies);
704 blk_queue_max_sectors(q, port->max_xfer_size); 703 blk_queue_max_sectors(q, port->max_xfer_size);
705 g->major = vdc_major; 704 g->major = vdc_major;
706 g->first_minor = port->dev_no << PARTITION_SHIFT; 705 g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
707 strcpy(g->disk_name, port->disk_name); 706 strcpy(g->disk_name, port->disk_name);
708 707
709 g->fops = &vdc_fops; 708 g->fops = &vdc_fops;
@@ -747,21 +746,16 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
747{ 746{
748 struct mdesc_handle *hp; 747 struct mdesc_handle *hp;
749 struct vdc_port *port; 748 struct vdc_port *port;
750 const u64 *port_id;
751 int err; 749 int err;
752 750
753 print_version(); 751 print_version();
754 752
755 hp = mdesc_grab(); 753 hp = mdesc_grab();
756 754
757 port_id = mdesc_get_property(hp, vdev->mp, "id", NULL);
758 err = -ENODEV; 755 err = -ENODEV;
759 if (!port_id) { 756 if ((vdev->dev_no << PARTITION_SHIFT) & ~(u64)MINORMASK) {
760 printk(KERN_ERR PFX "Port lacks id property.\n"); 757 printk(KERN_ERR PFX "Port id [%lu] too large.\n",
761 goto err_out_release_mdesc; 758 vdev->dev_no);
762 }
763 if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) {
764 printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id);
765 goto err_out_release_mdesc; 759 goto err_out_release_mdesc;
766 } 760 }
767 761
@@ -772,16 +766,14 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
772 goto err_out_release_mdesc; 766 goto err_out_release_mdesc;
773 } 767 }
774 768
775 port->dev_no = *port_id; 769 if (vdev->dev_no >= 26)
776
777 if (port->dev_no >= 26)
778 snprintf(port->disk_name, sizeof(port->disk_name), 770 snprintf(port->disk_name, sizeof(port->disk_name),
779 VDCBLK_NAME "%c%c", 771 VDCBLK_NAME "%c%c",
780 'a' + (port->dev_no / 26) - 1, 772 'a' + ((int)vdev->dev_no / 26) - 1,
781 'a' + (port->dev_no % 26)); 773 'a' + ((int)vdev->dev_no % 26));
782 else 774 else
783 snprintf(port->disk_name, sizeof(port->disk_name), 775 snprintf(port->disk_name, sizeof(port->disk_name),
784 VDCBLK_NAME "%c", 'a' + (port->dev_no % 26)); 776 VDCBLK_NAME "%c", 'a' + ((int)vdev->dev_no % 26));
785 777
786 err = vio_driver_init(&port->vio, vdev, VDEV_DISK, 778 err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
787 vdc_versions, ARRAY_SIZE(vdc_versions), 779 vdc_versions, ARRAY_SIZE(vdc_versions),
@@ -849,7 +841,7 @@ static struct vio_device_id vdc_port_match[] = {
849 }, 841 },
850 {}, 842 {},
851}; 843};
852MODULE_DEVICE_TABLE(vio, vdc_match); 844MODULE_DEVICE_TABLE(vio, vdc_port_match);
853 845
854static struct vio_driver vdc_port_driver = { 846static struct vio_driver vdc_port_driver = {
855 .id_table = vdc_port_match, 847 .id_table = vdc_port_match,
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 9e8f21410d2d..c8dfd18bea44 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -185,7 +185,7 @@ config ESPSERIAL
185 185
186config MOXA_INTELLIO 186config MOXA_INTELLIO
187 tristate "Moxa Intellio support" 187 tristate "Moxa Intellio support"
188 depends on SERIAL_NONSTANDARD 188 depends on SERIAL_NONSTANDARD && (ISA || EISA || PCI)
189 help 189 help
190 Say Y here if you have a Moxa Intellio multiport serial card. 190 Say Y here if you have a Moxa Intellio multiport serial card.
191 191
@@ -241,7 +241,7 @@ config SYNCLINK
241 241
242config SYNCLINKMP 242config SYNCLINKMP
243 tristate "SyncLink Multiport support" 243 tristate "SyncLink Multiport support"
244 depends on SERIAL_NONSTANDARD 244 depends on SERIAL_NONSTANDARD && PCI
245 help 245 help
246 Enable support for the SyncLink Multiport (2 or 4 ports) 246 Enable support for the SyncLink Multiport (2 or 4 ports)
247 serial adapter, running asynchronous and HDLC communications up 247 serial adapter, running asynchronous and HDLC communications up
@@ -726,7 +726,7 @@ config NVRAM
726 726
727config RTC 727config RTC
728 tristate "Enhanced Real Time Clock Support" 728 tristate "Enhanced Real Time Clock Support"
729 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM && !SUPERH && !S390 729 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC64 && (!SPARC32 || PCI) && !FRV && !ARM && !SUPERH && !S390
730 ---help--- 730 ---help---
731 If you say Y here and create a character special file /dev/rtc with 731 If you say Y here and create a character special file /dev/rtc with
732 major number 10 and minor number 135 using mknod ("man mknod"), you 732 major number 10 and minor number 135 using mknod ("man mknod"), you
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 4e6f387fd189..8fecaf4010b1 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -107,6 +107,8 @@ obj-$(CONFIG_IPMI_HANDLER) += ipmi/
107obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o 107obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
108obj-$(CONFIG_TCG_TPM) += tpm/ 108obj-$(CONFIG_TCG_TPM) += tpm/
109 109
110obj-$(CONFIG_PS3_FLASH) += ps3flash.o
111
110# Files generated that shall be removed upon make clean 112# Files generated that shall be removed upon make clean
111clean-files := consolemap_deftbl.c defkeymap.c 113clean-files := consolemap_deftbl.c defkeymap.c
112 114
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 0be700f4e8fd..ba0e74ad74bb 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -29,6 +29,7 @@
29#include <linux/bcd.h> 29#include <linux/bcd.h>
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <linux/bitops.h> 31#include <linux/bitops.h>
32#include <linux/clocksource.h>
32 33
33#include <asm/current.h> 34#include <asm/current.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
@@ -51,8 +52,34 @@
51 52
52#define HPET_RANGE_SIZE 1024 /* from HPET spec */ 53#define HPET_RANGE_SIZE 1024 /* from HPET spec */
53 54
55#if BITS_PER_LONG == 64
56#define write_counter(V, MC) writeq(V, MC)
57#define read_counter(MC) readq(MC)
58#else
59#define write_counter(V, MC) writel(V, MC)
60#define read_counter(MC) readl(MC)
61#endif
62
54static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ; 63static u32 hpet_nhpet, hpet_max_freq = HPET_USER_FREQ;
55 64
65static void __iomem *hpet_mctr;
66
67static cycle_t read_hpet(void)
68{
69 return (cycle_t)read_counter((void __iomem *)hpet_mctr);
70}
71
72static struct clocksource clocksource_hpet = {
73 .name = "hpet",
74 .rating = 250,
75 .read = read_hpet,
76 .mask = 0xffffffffffffffff,
77 .mult = 0, /*to be caluclated*/
78 .shift = 10,
79 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
80};
81static struct clocksource *hpet_clocksource;
82
56/* A lock for concurrent access by app and isr hpet activity. */ 83/* A lock for concurrent access by app and isr hpet activity. */
57static DEFINE_SPINLOCK(hpet_lock); 84static DEFINE_SPINLOCK(hpet_lock);
58/* A lock for concurrent intermodule access to hpet and isr hpet activity. */ 85/* A lock for concurrent intermodule access to hpet and isr hpet activity. */
@@ -79,7 +106,7 @@ struct hpets {
79 struct hpets *hp_next; 106 struct hpets *hp_next;
80 struct hpet __iomem *hp_hpet; 107 struct hpet __iomem *hp_hpet;
81 unsigned long hp_hpet_phys; 108 unsigned long hp_hpet_phys;
82 struct time_interpolator *hp_interpolator; 109 struct clocksource *hp_clocksource;
83 unsigned long long hp_tick_freq; 110 unsigned long long hp_tick_freq;
84 unsigned long hp_delta; 111 unsigned long hp_delta;
85 unsigned int hp_ntimer; 112 unsigned int hp_ntimer;
@@ -94,13 +121,6 @@ static struct hpets *hpets;
94#define HPET_PERIODIC 0x0004 121#define HPET_PERIODIC 0x0004
95#define HPET_SHARED_IRQ 0x0008 122#define HPET_SHARED_IRQ 0x0008
96 123
97#if BITS_PER_LONG == 64
98#define write_counter(V, MC) writeq(V, MC)
99#define read_counter(MC) readq(MC)
100#else
101#define write_counter(V, MC) writel(V, MC)
102#define read_counter(MC) readl(MC)
103#endif
104 124
105#ifndef readq 125#ifndef readq
106static inline unsigned long long readq(void __iomem *addr) 126static inline unsigned long long readq(void __iomem *addr)
@@ -737,27 +757,6 @@ static ctl_table dev_root[] = {
737 757
738static struct ctl_table_header *sysctl_header; 758static struct ctl_table_header *sysctl_header;
739 759
740static void hpet_register_interpolator(struct hpets *hpetp)
741{
742#ifdef CONFIG_TIME_INTERPOLATION
743 struct time_interpolator *ti;
744
745 ti = kzalloc(sizeof(*ti), GFP_KERNEL);
746 if (!ti)
747 return;
748
749 ti->source = TIME_SOURCE_MMIO64;
750 ti->shift = 10;
751 ti->addr = &hpetp->hp_hpet->hpet_mc;
752 ti->frequency = hpetp->hp_tick_freq;
753 ti->drift = HPET_DRIFT;
754 ti->mask = -1;
755
756 hpetp->hp_interpolator = ti;
757 register_time_interpolator(ti);
758#endif
759}
760
761/* 760/*
762 * Adjustment for when arming the timer with 761 * Adjustment for when arming the timer with
763 * initial conditions. That is, main counter 762 * initial conditions. That is, main counter
@@ -909,7 +908,16 @@ int hpet_alloc(struct hpet_data *hdp)
909 } 908 }
910 909
911 hpetp->hp_delta = hpet_calibrate(hpetp); 910 hpetp->hp_delta = hpet_calibrate(hpetp);
912 hpet_register_interpolator(hpetp); 911
912 if (!hpet_clocksource) {
913 hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc;
914 CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr);
915 clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq,
916 clocksource_hpet.shift);
917 clocksource_register(&clocksource_hpet);
918 hpetp->hp_clocksource = &clocksource_hpet;
919 hpet_clocksource = &clocksource_hpet;
920 }
913 921
914 return 0; 922 return 0;
915} 923}
@@ -995,7 +1003,7 @@ static int hpet_acpi_add(struct acpi_device *device)
995 1003
996static int hpet_acpi_remove(struct acpi_device *device, int type) 1004static int hpet_acpi_remove(struct acpi_device *device, int type)
997{ 1005{
998 /* XXX need to unregister interpolator, dealloc mem, etc */ 1006 /* XXX need to unregister clocksource, dealloc mem, etc */
999 return -EINVAL; 1007 return -EINVAL;
1000} 1008}
1001 1009
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index b37f1d5a5be6..a08f8f981c11 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -472,7 +472,7 @@ static void hvc_handle_event(struct HvLpEvent *event)
472 } 472 }
473} 473}
474 474
475static int send_open(HvLpIndex remoteLp, void *sem) 475static int __init send_open(HvLpIndex remoteLp, void *sem)
476{ 476{
477 return HvCallEvent_signalLpEventFast(remoteLp, 477 return HvCallEvent_signalLpEventFast(remoteLp,
478 HvLpEvent_Type_VirtualIo, 478 HvLpEvent_Type_VirtualIo,
@@ -484,7 +484,7 @@ static int send_open(HvLpIndex remoteLp, void *sem)
484 0, 0, 0, 0); 484 0, 0, 0, 0);
485} 485}
486 486
487static int hvc_vio_init(void) 487static int __init hvc_vio_init(void)
488{ 488{
489 atomic_t wait_flag; 489 atomic_t wait_flag;
490 int rc; 490 int rc;
@@ -552,14 +552,14 @@ static int hvc_vio_init(void)
552} 552}
553module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */ 553module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */
554 554
555static void hvc_vio_exit(void) 555static void __exit hvc_vio_exit(void)
556{ 556{
557 vio_unregister_driver(&hvc_vio_driver); 557 vio_unregister_driver(&hvc_vio_driver);
558} 558}
559module_exit(hvc_vio_exit); 559module_exit(hvc_vio_exit);
560 560
561/* the device tree order defines our numbering */ 561/* the device tree order defines our numbering */
562static int hvc_find_vtys(void) 562static int __init hvc_find_vtys(void)
563{ 563{
564 struct device_node *vty; 564 struct device_node *vty;
565 int num_found = 0; 565 int num_found = 0;
diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
index 4b97eaf18602..bb09413d5a21 100644
--- a/drivers/char/hvc_rtas.c
+++ b/drivers/char/hvc_rtas.c
@@ -115,7 +115,7 @@ static void __exit hvc_rtas_exit(void)
115module_exit(hvc_rtas_exit); 115module_exit(hvc_rtas_exit);
116 116
117/* This will happen prior to module init. There is no tty at this time? */ 117/* This will happen prior to module init. There is no tty at this time? */
118static int hvc_rtas_console_init(void) 118static int __init hvc_rtas_console_init(void)
119{ 119{
120 rtascons_put_char_token = rtas_token("put-term-char"); 120 rtascons_put_char_token = rtas_token("put-term-char");
121 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) 121 if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE)
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 17f96e04266f..69d8866de783 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -210,9 +210,9 @@ static struct ktermios hvcs_tty_termios = {
210static int hvcs_parm_num_devs = -1; 210static int hvcs_parm_num_devs = -1;
211module_param(hvcs_parm_num_devs, int, 0); 211module_param(hvcs_parm_num_devs, int, 0);
212 212
213char hvcs_driver_name[] = "hvcs"; 213static const char hvcs_driver_name[] = "hvcs";
214char hvcs_device_node[] = "hvcs"; 214static const char hvcs_device_node[] = "hvcs";
215char hvcs_driver_string[] 215static const char hvcs_driver_string[]
216 = "IBM hvcs (Hypervisor Virtual Console Server) Driver"; 216 = "IBM hvcs (Hypervisor Virtual Console Server) Driver";
217 217
218/* Status of partner info rescan triggered via sysfs. */ 218/* Status of partner info rescan triggered via sysfs. */
@@ -1092,7 +1092,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
1092 * NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when 1092 * NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when
1093 * calling this function or you will get deadlock. 1093 * calling this function or you will get deadlock.
1094 */ 1094 */
1095struct hvcs_struct *hvcs_get_by_index(int index) 1095static struct hvcs_struct *hvcs_get_by_index(int index)
1096{ 1096{
1097 struct hvcs_struct *hvcsd = NULL; 1097 struct hvcs_struct *hvcsd = NULL;
1098 unsigned long flags; 1098 unsigned long flags;
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 7cda04b33534..2d7cd486e025 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -41,7 +41,7 @@ config HW_RANDOM_AMD
41 41
42config HW_RANDOM_GEODE 42config HW_RANDOM_GEODE
43 tristate "AMD Geode HW Random Number Generator support" 43 tristate "AMD Geode HW Random Number Generator support"
44 depends on HW_RANDOM && X86 && PCI 44 depends on HW_RANDOM && X86_32 && PCI
45 default HW_RANDOM 45 default HW_RANDOM
46 ---help--- 46 ---help---
47 This driver provides kernel-side support for the Random Number 47 This driver provides kernel-side support for the Random Number
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c
new file mode 100644
index 000000000000..79b6f461be75
--- /dev/null
+++ b/drivers/char/ps3flash.c
@@ -0,0 +1,440 @@
1/*
2 * PS3 FLASH ROM Storage Driver
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/fs.h>
22#include <linux/miscdevice.h>
23#include <linux/uaccess.h>
24
25#include <asm/lv1call.h>
26#include <asm/ps3stor.h>
27
28
29#define DEVICE_NAME "ps3flash"
30
31#define FLASH_BLOCK_SIZE (256*1024)
32
33
34struct ps3flash_private {
35 struct mutex mutex; /* Bounce buffer mutex */
36};
37
38static struct ps3_storage_device *ps3flash_dev;
39
40static ssize_t ps3flash_read_write_sectors(struct ps3_storage_device *dev,
41 u64 lpar, u64 start_sector,
42 u64 sectors, int write)
43{
44 u64 res = ps3stor_read_write_sectors(dev, lpar, start_sector, sectors,
45 write);
46 if (res) {
47 dev_err(&dev->sbd.core, "%s:%u: %s failed 0x%lx\n", __func__,
48 __LINE__, write ? "write" : "read", res);
49 return -EIO;
50 }
51 return sectors;
52}
53
54static ssize_t ps3flash_read_sectors(struct ps3_storage_device *dev,
55 u64 start_sector, u64 sectors,
56 unsigned int sector_offset)
57{
58 u64 max_sectors, lpar;
59
60 max_sectors = dev->bounce_size / dev->blk_size;
61 if (sectors > max_sectors) {
62 dev_dbg(&dev->sbd.core, "%s:%u Limiting sectors to %lu\n",
63 __func__, __LINE__, max_sectors);
64 sectors = max_sectors;
65 }
66
67 lpar = dev->bounce_lpar + sector_offset * dev->blk_size;
68 return ps3flash_read_write_sectors(dev, lpar, start_sector, sectors,
69 0);
70}
71
72static ssize_t ps3flash_write_chunk(struct ps3_storage_device *dev,
73 u64 start_sector)
74{
75 u64 sectors = dev->bounce_size / dev->blk_size;
76 return ps3flash_read_write_sectors(dev, dev->bounce_lpar, start_sector,
77 sectors, 1);
78}
79
80static loff_t ps3flash_llseek(struct file *file, loff_t offset, int origin)
81{
82 struct ps3_storage_device *dev = ps3flash_dev;
83 loff_t res;
84
85 mutex_lock(&file->f_mapping->host->i_mutex);
86 switch (origin) {
87 case 1:
88 offset += file->f_pos;
89 break;
90 case 2:
91 offset += dev->regions[dev->region_idx].size*dev->blk_size;
92 break;
93 }
94 if (offset < 0) {
95 res = -EINVAL;
96 goto out;
97 }
98
99 file->f_pos = offset;
100 res = file->f_pos;
101
102out:
103 mutex_unlock(&file->f_mapping->host->i_mutex);
104 return res;
105}
106
107static ssize_t ps3flash_read(struct file *file, char __user *buf, size_t count,
108 loff_t *pos)
109{
110 struct ps3_storage_device *dev = ps3flash_dev;
111 struct ps3flash_private *priv = dev->sbd.core.driver_data;
112 u64 size, start_sector, end_sector, offset;
113 ssize_t sectors_read;
114 size_t remaining, n;
115
116 dev_dbg(&dev->sbd.core,
117 "%s:%u: Reading %zu bytes at position %lld to user 0x%p\n",
118 __func__, __LINE__, count, *pos, buf);
119
120 size = dev->regions[dev->region_idx].size*dev->blk_size;
121 if (*pos >= size || !count)
122 return 0;
123
124 if (*pos + count > size) {
125 dev_dbg(&dev->sbd.core,
126 "%s:%u Truncating count from %zu to %llu\n", __func__,
127 __LINE__, count, size - *pos);
128 count = size - *pos;
129 }
130
131 start_sector = *pos / dev->blk_size;
132 offset = *pos % dev->blk_size;
133 end_sector = DIV_ROUND_UP(*pos + count, dev->blk_size);
134
135 remaining = count;
136 do {
137 mutex_lock(&priv->mutex);
138
139 sectors_read = ps3flash_read_sectors(dev, start_sector,
140 end_sector-start_sector,
141 0);
142 if (sectors_read < 0) {
143 mutex_unlock(&priv->mutex);
144 goto fail;
145 }
146
147 n = min(remaining, sectors_read*dev->blk_size-offset);
148 dev_dbg(&dev->sbd.core,
149 "%s:%u: copy %lu bytes from 0x%p to user 0x%p\n",
150 __func__, __LINE__, n, dev->bounce_buf+offset, buf);
151 if (copy_to_user(buf, dev->bounce_buf+offset, n)) {
152 mutex_unlock(&priv->mutex);
153 sectors_read = -EFAULT;
154 goto fail;
155 }
156
157 mutex_unlock(&priv->mutex);
158
159 *pos += n;
160 buf += n;
161 remaining -= n;
162 start_sector += sectors_read;
163 offset = 0;
164 } while (remaining > 0);
165
166 return count;
167
168fail:
169 return sectors_read;
170}
171
172static ssize_t ps3flash_write(struct file *file, const char __user *buf,
173 size_t count, loff_t *pos)
174{
175 struct ps3_storage_device *dev = ps3flash_dev;
176 struct ps3flash_private *priv = dev->sbd.core.driver_data;
177 u64 size, chunk_sectors, start_write_sector, end_write_sector,
178 end_read_sector, start_read_sector, head, tail, offset;
179 ssize_t res;
180 size_t remaining, n;
181 unsigned int sec_off;
182
183 dev_dbg(&dev->sbd.core,
184 "%s:%u: Writing %zu bytes at position %lld from user 0x%p\n",
185 __func__, __LINE__, count, *pos, buf);
186
187 size = dev->regions[dev->region_idx].size*dev->blk_size;
188 if (*pos >= size || !count)
189 return 0;
190
191 if (*pos + count > size) {
192 dev_dbg(&dev->sbd.core,
193 "%s:%u Truncating count from %zu to %llu\n", __func__,
194 __LINE__, count, size - *pos);
195 count = size - *pos;
196 }
197
198 chunk_sectors = dev->bounce_size / dev->blk_size;
199
200 start_write_sector = *pos / dev->bounce_size * chunk_sectors;
201 offset = *pos % dev->bounce_size;
202 end_write_sector = DIV_ROUND_UP(*pos + count, dev->bounce_size) *
203 chunk_sectors;
204
205 end_read_sector = DIV_ROUND_UP(*pos, dev->blk_size);
206 start_read_sector = (*pos + count) / dev->blk_size;
207
208 /*
209 * As we have to write in 256 KiB chunks, while we can read in blk_size
210 * (usually 512 bytes) chunks, we perform the following steps:
211 * 1. Read from start_write_sector to end_read_sector ("head")
212 * 2. Read from start_read_sector to end_write_sector ("tail")
213 * 3. Copy data to buffer
214 * 4. Write from start_write_sector to end_write_sector
215 * All of this is complicated by using only one 256 KiB bounce buffer.
216 */
217
218 head = end_read_sector - start_write_sector;
219 tail = end_write_sector - start_read_sector;
220
221 remaining = count;
222 do {
223 mutex_lock(&priv->mutex);
224
225 if (end_read_sector >= start_read_sector) {
226 /* Merge head and tail */
227 dev_dbg(&dev->sbd.core,
228 "Merged head and tail: %lu sectors at %lu\n",
229 chunk_sectors, start_write_sector);
230 res = ps3flash_read_sectors(dev, start_write_sector,
231 chunk_sectors, 0);
232 if (res < 0)
233 goto fail;
234 } else {
235 if (head) {
236 /* Read head */
237 dev_dbg(&dev->sbd.core,
238 "head: %lu sectors at %lu\n", head,
239 start_write_sector);
240 res = ps3flash_read_sectors(dev,
241 start_write_sector,
242 head, 0);
243 if (res < 0)
244 goto fail;
245 }
246 if (start_read_sector <
247 start_write_sector+chunk_sectors) {
248 /* Read tail */
249 dev_dbg(&dev->sbd.core,
250 "tail: %lu sectors at %lu\n", tail,
251 start_read_sector);
252 sec_off = start_read_sector-start_write_sector;
253 res = ps3flash_read_sectors(dev,
254 start_read_sector,
255 tail, sec_off);
256 if (res < 0)
257 goto fail;
258 }
259 }
260
261 n = min(remaining, dev->bounce_size-offset);
262 dev_dbg(&dev->sbd.core,
263 "%s:%u: copy %lu bytes from user 0x%p to 0x%p\n",
264 __func__, __LINE__, n, buf, dev->bounce_buf+offset);
265 if (copy_from_user(dev->bounce_buf+offset, buf, n)) {
266 res = -EFAULT;
267 goto fail;
268 }
269
270 res = ps3flash_write_chunk(dev, start_write_sector);
271 if (res < 0)
272 goto fail;
273
274 mutex_unlock(&priv->mutex);
275
276 *pos += n;
277 buf += n;
278 remaining -= n;
279 start_write_sector += chunk_sectors;
280 head = 0;
281 offset = 0;
282 } while (remaining > 0);
283
284 return count;
285
286fail:
287 mutex_unlock(&priv->mutex);
288 return res;
289}
290
291
292static irqreturn_t ps3flash_interrupt(int irq, void *data)
293{
294 struct ps3_storage_device *dev = data;
295 int res;
296 u64 tag, status;
297
298 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
299
300 if (tag != dev->tag)
301 dev_err(&dev->sbd.core,
302 "%s:%u: tag mismatch, got %lx, expected %lx\n",
303 __func__, __LINE__, tag, dev->tag);
304
305 if (res) {
306 dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%lx\n",
307 __func__, __LINE__, res, status);
308 } else {
309 dev->lv1_status = status;
310 complete(&dev->done);
311 }
312 return IRQ_HANDLED;
313}
314
315
316static const struct file_operations ps3flash_fops = {
317 .owner = THIS_MODULE,
318 .llseek = ps3flash_llseek,
319 .read = ps3flash_read,
320 .write = ps3flash_write,
321};
322
323static struct miscdevice ps3flash_misc = {
324 .minor = MISC_DYNAMIC_MINOR,
325 .name = DEVICE_NAME,
326 .fops = &ps3flash_fops,
327};
328
329static int __devinit ps3flash_probe(struct ps3_system_bus_device *_dev)
330{
331 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
332 struct ps3flash_private *priv;
333 int error;
334 unsigned long tmp;
335
336 tmp = dev->regions[dev->region_idx].start*dev->blk_size;
337 if (tmp % FLASH_BLOCK_SIZE) {
338 dev_err(&dev->sbd.core,
339 "%s:%u region start %lu is not aligned\n", __func__,
340 __LINE__, tmp);
341 return -EINVAL;
342 }
343 tmp = dev->regions[dev->region_idx].size*dev->blk_size;
344 if (tmp % FLASH_BLOCK_SIZE) {
345 dev_err(&dev->sbd.core,
346 "%s:%u region size %lu is not aligned\n", __func__,
347 __LINE__, tmp);
348 return -EINVAL;
349 }
350
351 /* use static buffer, kmalloc cannot allocate 256 KiB */
352 if (!ps3flash_bounce_buffer.address)
353 return -ENODEV;
354
355 if (ps3flash_dev) {
356 dev_err(&dev->sbd.core,
357 "Only one FLASH device is supported\n");
358 return -EBUSY;
359 }
360
361 ps3flash_dev = dev;
362
363 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
364 if (!priv) {
365 error = -ENOMEM;
366 goto fail;
367 }
368
369 dev->sbd.core.driver_data = priv;
370 mutex_init(&priv->mutex);
371
372 dev->bounce_size = ps3flash_bounce_buffer.size;
373 dev->bounce_buf = ps3flash_bounce_buffer.address;
374
375 error = ps3stor_setup(dev, ps3flash_interrupt);
376 if (error)
377 goto fail_free_priv;
378
379 ps3flash_misc.parent = &dev->sbd.core;
380 error = misc_register(&ps3flash_misc);
381 if (error) {
382 dev_err(&dev->sbd.core, "%s:%u: misc_register failed %d\n",
383 __func__, __LINE__, error);
384 goto fail_teardown;
385 }
386
387 dev_info(&dev->sbd.core, "%s:%u: registered misc device %d\n",
388 __func__, __LINE__, ps3flash_misc.minor);
389 return 0;
390
391fail_teardown:
392 ps3stor_teardown(dev);
393fail_free_priv:
394 kfree(priv);
395 dev->sbd.core.driver_data = NULL;
396fail:
397 ps3flash_dev = NULL;
398 return error;
399}
400
401static int ps3flash_remove(struct ps3_system_bus_device *_dev)
402{
403 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
404
405 misc_deregister(&ps3flash_misc);
406 ps3stor_teardown(dev);
407 kfree(dev->sbd.core.driver_data);
408 dev->sbd.core.driver_data = NULL;
409 ps3flash_dev = NULL;
410 return 0;
411}
412
413
414static struct ps3_system_bus_driver ps3flash = {
415 .match_id = PS3_MATCH_ID_STOR_FLASH,
416 .core.name = DEVICE_NAME,
417 .core.owner = THIS_MODULE,
418 .probe = ps3flash_probe,
419 .remove = ps3flash_remove,
420 .shutdown = ps3flash_remove,
421};
422
423
424static int __init ps3flash_init(void)
425{
426 return ps3_system_bus_driver_register(&ps3flash);
427}
428
429static void __exit ps3flash_exit(void)
430{
431 ps3_system_bus_driver_unregister(&ps3flash);
432}
433
434module_init(ps3flash_init);
435module_exit(ps3flash_exit);
436
437MODULE_LICENSE("GPL");
438MODULE_DESCRIPTION("PS3 FLASH ROM Storage Driver");
439MODULE_AUTHOR("Sony Corporation");
440MODULE_ALIAS(PS3_MODULE_ALIAS_STOR_FLASH);
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 22cf7aa56cc4..ec6b65ec69ea 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -82,16 +82,13 @@
82#include <asm/uaccess.h> 82#include <asm/uaccess.h>
83#include <asm/system.h> 83#include <asm/system.h>
84 84
85#if defined(__i386__) 85#ifdef CONFIG_X86
86#include <asm/hpet.h> 86#include <asm/hpet.h>
87#endif 87#endif
88 88
89#ifdef __sparc__ 89#ifdef CONFIG_SPARC32
90#include <linux/pci.h> 90#include <linux/pci.h>
91#include <asm/ebus.h> 91#include <asm/ebus.h>
92#ifdef __sparc_v9__
93#include <asm/isa.h>
94#endif
95 92
96static unsigned long rtc_port; 93static unsigned long rtc_port;
97static int rtc_irq = PCI_IRQ_NONE; 94static int rtc_irq = PCI_IRQ_NONE;
@@ -930,13 +927,9 @@ static int __init rtc_init(void)
930 unsigned int year, ctrl; 927 unsigned int year, ctrl;
931 char *guess = NULL; 928 char *guess = NULL;
932#endif 929#endif
933#ifdef __sparc__ 930#ifdef CONFIG_SPARC32
934 struct linux_ebus *ebus; 931 struct linux_ebus *ebus;
935 struct linux_ebus_device *edev; 932 struct linux_ebus_device *edev;
936#ifdef __sparc_v9__
937 struct sparc_isa_bridge *isa_br;
938 struct sparc_isa_device *isa_dev;
939#endif
940#else 933#else
941 void *r; 934 void *r;
942#ifdef RTC_IRQ 935#ifdef RTC_IRQ
@@ -944,7 +937,7 @@ static int __init rtc_init(void)
944#endif 937#endif
945#endif 938#endif
946 939
947#ifdef __sparc__ 940#ifdef CONFIG_SPARC32
948 for_each_ebus(ebus) { 941 for_each_ebus(ebus) {
949 for_each_ebusdev(edev, ebus) { 942 for_each_ebusdev(edev, ebus) {
950 if(strcmp(edev->prom_node->name, "rtc") == 0) { 943 if(strcmp(edev->prom_node->name, "rtc") == 0) {
@@ -954,17 +947,6 @@ static int __init rtc_init(void)
954 } 947 }
955 } 948 }
956 } 949 }
957#ifdef __sparc_v9__
958 for_each_isa(isa_br) {
959 for_each_isadev(isa_dev, isa_br) {
960 if (strcmp(isa_dev->prom_node->name, "rtc") == 0) {
961 rtc_port = isa_dev->resource.start;
962 rtc_irq = isa_dev->irq;
963 goto found;
964 }
965 }
966 }
967#endif
968 rtc_has_irq = 0; 950 rtc_has_irq = 0;
969 printk(KERN_ERR "rtc_init: no PC rtc found\n"); 951 printk(KERN_ERR "rtc_init: no PC rtc found\n");
970 return -EIO; 952 return -EIO;
@@ -1020,7 +1002,7 @@ no_irq:
1020 1002
1021#endif 1003#endif
1022 1004
1023#endif /* __sparc__ vs. others */ 1005#endif /* CONFIG_SPARC32 vs. others */
1024 1006
1025 if (misc_register(&rtc_dev)) { 1007 if (misc_register(&rtc_dev)) {
1026#ifdef RTC_IRQ 1008#ifdef RTC_IRQ
@@ -1105,7 +1087,7 @@ static void __exit rtc_exit (void)
1105 remove_proc_entry ("driver/rtc", NULL); 1087 remove_proc_entry ("driver/rtc", NULL);
1106 misc_deregister(&rtc_dev); 1088 misc_deregister(&rtc_dev);
1107 1089
1108#ifdef __sparc__ 1090#ifdef CONFIG_SPARC32
1109 if (rtc_has_irq) 1091 if (rtc_has_irq)
1110 free_irq (rtc_irq, &rtc_port); 1092 free_irq (rtc_irq, &rtc_port);
1111#else 1093#else
@@ -1117,7 +1099,7 @@ static void __exit rtc_exit (void)
1117 if (rtc_has_irq) 1099 if (rtc_has_irq)
1118 free_irq (RTC_IRQ, NULL); 1100 free_irq (RTC_IRQ, NULL);
1119#endif 1101#endif
1120#endif /* __sparc__ */ 1102#endif /* CONFIG_SPARC32 */
1121} 1103}
1122 1104
1123module_init(rtc_init); 1105module_init(rtc_init);
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index c585b4738f86..f1497cecffd8 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -2573,16 +2573,10 @@ static struct tty_driver *serial167_console_device(struct console *c,
2573 return cy_serial_driver; 2573 return cy_serial_driver;
2574} 2574}
2575 2575
2576static int __init serial167_console_setup(struct console *co, char *options)
2577{
2578 return 0;
2579}
2580
2581static struct console sercons = { 2576static struct console sercons = {
2582 .name = "ttyS", 2577 .name = "ttyS",
2583 .write = serial167_console_write, 2578 .write = serial167_console_write,
2584 .device = serial167_console_device, 2579 .device = serial167_console_device,
2585 .setup = serial167_console_setup,
2586 .flags = CON_PRINTBUFFER, 2580 .flags = CON_PRINTBUFFER,
2587 .index = -1, 2581 .index = -1,
2588}; 2582};
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
index 4eba32b23b29..8677fc6a545e 100644
--- a/drivers/char/tpm/tpm_bios.c
+++ b/drivers/char/tpm/tpm_bios.c
@@ -427,7 +427,7 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
427 return -ENOMEM; 427 return -ENOMEM;
428 428
429 if ((err = read_log(log))) 429 if ((err = read_log(log)))
430 return err; 430 goto out_free;
431 431
432 /* now register seq file */ 432 /* now register seq file */
433 err = seq_open(file, &tpm_ascii_b_measurments_seqops); 433 err = seq_open(file, &tpm_ascii_b_measurments_seqops);
@@ -435,10 +435,15 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
435 seq = file->private_data; 435 seq = file->private_data;
436 seq->private = log; 436 seq->private = log;
437 } else { 437 } else {
438 kfree(log->bios_event_log); 438 goto out_free;
439 kfree(log);
440 } 439 }
440
441out:
441 return err; 442 return err;
443out_free:
444 kfree(log->bios_event_log);
445 kfree(log);
446 goto out;
442} 447}
443 448
444const struct file_operations tpm_ascii_bios_measurements_ops = { 449const struct file_operations tpm_ascii_bios_measurements_ops = {
@@ -460,7 +465,7 @@ static int tpm_binary_bios_measurements_open(struct inode *inode,
460 return -ENOMEM; 465 return -ENOMEM;
461 466
462 if ((err = read_log(log))) 467 if ((err = read_log(log)))
463 return err; 468 goto out_free;
464 469
465 /* now register seq file */ 470 /* now register seq file */
466 err = seq_open(file, &tpm_binary_b_measurments_seqops); 471 err = seq_open(file, &tpm_binary_b_measurments_seqops);
@@ -468,10 +473,15 @@ static int tpm_binary_bios_measurements_open(struct inode *inode,
468 seq = file->private_data; 473 seq = file->private_data;
469 seq->private = log; 474 seq->private = log;
470 } else { 475 } else {
471 kfree(log->bios_event_log); 476 goto out_free;
472 kfree(log);
473 } 477 }
478
479out:
474 return err; 480 return err;
481out_free:
482 kfree(log->bios_event_log);
483 kfree(log);
484 goto out;
475} 485}
476 486
477const struct file_operations tpm_binary_bios_measurements_ops = { 487const struct file_operations tpm_binary_bios_measurements_ops = {
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index bef6d886d4fb..e122a0e87bb0 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -1013,18 +1013,10 @@ static struct tty_driver *scc_console_device(struct console *c, int *index)
1013 return scc_driver; 1013 return scc_driver;
1014} 1014}
1015 1015
1016
1017static int __init scc_console_setup(struct console *co, char *options)
1018{
1019 return 0;
1020}
1021
1022
1023static struct console sercons = { 1016static struct console sercons = {
1024 .name = "ttyS", 1017 .name = "ttyS",
1025 .write = scc_console_write, 1018 .write = scc_console_write,
1026 .device = scc_console_device, 1019 .device = scc_console_device,
1027 .setup = scc_console_setup,
1028 .flags = CON_PRINTBUFFER, 1020 .flags = CON_PRINTBUFFER,
1029 .index = -1, 1021 .index = -1,
1030}; 1022};
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index a4d81cda479e..16fb23125e96 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -618,7 +618,7 @@ config ZVM_WATCHDOG
618 618
619config SH_WDT 619config SH_WDT
620 tristate "SuperH Watchdog" 620 tristate "SuperH Watchdog"
621 depends on SUPERH 621 depends on SUPERH && (CPU_SH3 || CPU_SH4)
622 help 622 help
623 This driver adds watchdog support for the integrated watchdog in the 623 This driver adds watchdog support for the integrated watchdog in the
624 SuperH processors. If you have one of these processors and wish 624 SuperH processors. If you have one of these processors and wish
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index e783dbf0f162..7b46faf22318 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -71,7 +71,7 @@ static struct clocksource clocksource_acpi_pm = {
71 .rating = 200, 71 .rating = 200,
72 .read = acpi_pm_read, 72 .read = acpi_pm_read,
73 .mask = (cycle_t)ACPI_PM_MASK, 73 .mask = (cycle_t)ACPI_PM_MASK,
74 .mult = 0, /*to be caluclated*/ 74 .mult = 0, /*to be calculated*/
75 .shift = 22, 75 .shift = 22,
76 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 76 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
77 77
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index e1e9d9d6893f..f0829b83e970 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -8,6 +8,7 @@
8 * more details. 8 * more details.
9 */ 9 */
10 10
11#include <linux/module.h>
11#include <linux/types.h> 12#include <linux/types.h>
12#include <linux/mm.h> 13#include <linux/mm.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
@@ -54,6 +55,7 @@ static int falconide_offsets[IDE_NR_PORTS] __initdata = {
54 */ 55 */
55 56
56int falconide_intr_lock; 57int falconide_intr_lock;
58EXPORT_SYMBOL(falconide_intr_lock);
57 59
58 60
59 /* 61 /*
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 75b4d2a83dd9..5fe755586623 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -471,37 +471,16 @@ static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
471 return 0; 471 return 0;
472} 472}
473 473
474static struct list_head *list_get_nth_element(struct list_head *list, loff_t *pos)
475{
476 struct list_head *node;
477 loff_t i = 0;
478
479 list_for_each(node, list)
480 if (i++ == *pos)
481 return node;
482
483 return NULL;
484}
485
486static struct list_head *list_get_next_element(struct list_head *list, struct list_head *element, loff_t *pos)
487{
488 if (element->next == list)
489 return NULL;
490
491 ++(*pos);
492 return element->next;
493}
494
495static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos) 474static void *input_devices_seq_start(struct seq_file *seq, loff_t *pos)
496{ 475{
497 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ 476 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
498 477
499 return list_get_nth_element(&input_dev_list, pos); 478 return seq_list_start(&input_dev_list, *pos);
500} 479}
501 480
502static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos) 481static void *input_devices_seq_next(struct seq_file *seq, void *v, loff_t *pos)
503{ 482{
504 return list_get_next_element(&input_dev_list, v, pos); 483 return seq_list_next(v, &input_dev_list, pos);
505} 484}
506 485
507static void input_devices_seq_stop(struct seq_file *seq, void *v) 486static void input_devices_seq_stop(struct seq_file *seq, void *v)
@@ -592,13 +571,13 @@ static void *input_handlers_seq_start(struct seq_file *seq, loff_t *pos)
592{ 571{
593 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */ 572 /* acquire lock here ... Yes, we do need locking, I knowi, I know... */
594 seq->private = (void *)(unsigned long)*pos; 573 seq->private = (void *)(unsigned long)*pos;
595 return list_get_nth_element(&input_handler_list, pos); 574 return seq_list_start(&input_handler_list, *pos);
596} 575}
597 576
598static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos) 577static void *input_handlers_seq_next(struct seq_file *seq, void *v, loff_t *pos)
599{ 578{
600 seq->private = (void *)(unsigned long)(*pos + 1); 579 seq->private = (void *)(unsigned long)(*pos + 1);
601 return list_get_next_element(&input_handler_list, v, pos); 580 return seq_list_next(v, &input_handler_list, pos);
602} 581}
603 582
604static void input_handlers_seq_stop(struct seq_file *seq, void *v) 583static void input_handlers_seq_stop(struct seq_file *seq, void *v)
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 12db72d83ea0..e2abe18e575d 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -275,4 +275,11 @@ config JOYSTICK_XPAD_FF
275 ---help--- 275 ---help---
276 Say Y here if you want to take advantage of xbox 360 rumble features. 276 Say Y here if you want to take advantage of xbox 360 rumble features.
277 277
278config JOYSTICK_XPAD_LEDS
279 bool "LED Support for Xbox360 controller 'BigX' LED"
280 depends on LEDS_CLASS && JOYSTICK_XPAD
281 ---help---
282 This option enables support for the LED which surrounds the Big X on
283 XBox 360 controller.
284
278endif 285endif
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 244089c52650..28080395899c 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -191,13 +191,18 @@ struct usb_xpad {
191 unsigned char *idata; /* input data */ 191 unsigned char *idata; /* input data */
192 dma_addr_t idata_dma; 192 dma_addr_t idata_dma;
193 193
194#ifdef CONFIG_JOYSTICK_XPAD_FF 194#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
195 struct urb *irq_out; /* urb for interrupt out report */ 195 struct urb *irq_out; /* urb for interrupt out report */
196 unsigned char *odata; /* output data */ 196 unsigned char *odata; /* output data */
197 dma_addr_t odata_dma; 197 dma_addr_t odata_dma;
198 struct mutex odata_mutex;
199#endif
200
201#if defined(CONFIG_JOYSTICK_XPAD_LEDS)
202 struct xpad_led *led;
198#endif 203#endif
199 204
200 char phys[65]; /* physical device path */ 205 char phys[64]; /* physical device path */
201 206
202 int dpad_mapping; /* map d-pad to buttons or to axes */ 207 int dpad_mapping; /* map d-pad to buttons or to axes */
203 int xtype; /* type of xbox device */ 208 int xtype; /* type of xbox device */
@@ -349,7 +354,7 @@ exit:
349 __FUNCTION__, retval); 354 __FUNCTION__, retval);
350} 355}
351 356
352#ifdef CONFIG_JOYSTICK_XPAD_FF 357#if defined(CONFIG_JOYSTICK_XPAD_FF) || defined(CONFIG_JOYSTICK_XPAD_LEDS)
353static void xpad_irq_out(struct urb *urb) 358static void xpad_irq_out(struct urb *urb)
354{ 359{
355 int retval; 360 int retval;
@@ -376,29 +381,7 @@ exit:
376 __FUNCTION__, retval); 381 __FUNCTION__, retval);
377} 382}
378 383
379static int xpad_play_effect(struct input_dev *dev, void *data, 384static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
380 struct ff_effect *effect)
381{
382 struct usb_xpad *xpad = input_get_drvdata(dev);
383
384 if (effect->type == FF_RUMBLE) {
385 __u16 strong = effect->u.rumble.strong_magnitude;
386 __u16 weak = effect->u.rumble.weak_magnitude;
387 xpad->odata[0] = 0x00;
388 xpad->odata[1] = 0x08;
389 xpad->odata[2] = 0x00;
390 xpad->odata[3] = strong / 256;
391 xpad->odata[4] = weak / 256;
392 xpad->odata[5] = 0x00;
393 xpad->odata[6] = 0x00;
394 xpad->odata[7] = 0x00;
395 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
396 }
397
398 return 0;
399}
400
401static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad)
402{ 385{
403 struct usb_endpoint_descriptor *ep_irq_out; 386 struct usb_endpoint_descriptor *ep_irq_out;
404 int error = -ENOMEM; 387 int error = -ENOMEM;
@@ -411,6 +394,8 @@ static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad)
411 if (!xpad->odata) 394 if (!xpad->odata)
412 goto fail1; 395 goto fail1;
413 396
397 mutex_init(&xpad->odata_mutex);
398
414 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); 399 xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
415 if (!xpad->irq_out) 400 if (!xpad->irq_out)
416 goto fail2; 401 goto fail2;
@@ -423,25 +408,19 @@ static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad)
423 xpad->irq_out->transfer_dma = xpad->odata_dma; 408 xpad->irq_out->transfer_dma = xpad->odata_dma;
424 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 409 xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
425 410
426 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
427
428 error = input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
429 if (error)
430 goto fail2;
431
432 return 0; 411 return 0;
433 412
434 fail2: usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma); 413 fail2: usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
435 fail1: return error; 414 fail1: return error;
436} 415}
437 416
438static void xpad_stop_ff(struct usb_xpad *xpad) 417static void xpad_stop_output(struct usb_xpad *xpad)
439{ 418{
440 if (xpad->xtype == XTYPE_XBOX360) 419 if (xpad->xtype == XTYPE_XBOX360)
441 usb_kill_urb(xpad->irq_out); 420 usb_kill_urb(xpad->irq_out);
442} 421}
443 422
444static void xpad_deinit_ff(struct usb_xpad *xpad) 423static void xpad_deinit_output(struct usb_xpad *xpad)
445{ 424{
446 if (xpad->xtype == XTYPE_XBOX360) { 425 if (xpad->xtype == XTYPE_XBOX360) {
447 usb_free_urb(xpad->irq_out); 426 usb_free_urb(xpad->irq_out);
@@ -449,13 +428,130 @@ static void xpad_deinit_ff(struct usb_xpad *xpad)
449 xpad->odata, xpad->odata_dma); 428 xpad->odata, xpad->odata_dma);
450 } 429 }
451} 430}
431#else
432static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; }
433static void xpad_deinit_output(struct usb_xpad *xpad) {}
434static void xpad_stop_output(struct usb_xpad *xpad) {}
435#endif
436
437#ifdef CONFIG_JOYSTICK_XPAD_FF
438static int xpad_play_effect(struct input_dev *dev, void *data,
439 struct ff_effect *effect)
440{
441 struct usb_xpad *xpad = input_get_drvdata(dev);
452 442
443 if (effect->type == FF_RUMBLE) {
444 __u16 strong = effect->u.rumble.strong_magnitude;
445 __u16 weak = effect->u.rumble.weak_magnitude;
446 xpad->odata[0] = 0x00;
447 xpad->odata[1] = 0x08;
448 xpad->odata[2] = 0x00;
449 xpad->odata[3] = strong / 256;
450 xpad->odata[4] = weak / 256;
451 xpad->odata[5] = 0x00;
452 xpad->odata[6] = 0x00;
453 xpad->odata[7] = 0x00;
454 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
455 }
456
457 return 0;
458}
459
460static int xpad_init_ff(struct usb_xpad *xpad)
461{
462 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
463
464 return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
465}
466
467#else
468static int xpad_init_ff(struct usb_xpad *xpad) { return 0; }
469#endif
470
471#if defined(CONFIG_JOYSTICK_XPAD_LEDS)
472#include <linux/leds.h>
473
474struct xpad_led {
475 char name[16];
476 struct led_classdev led_cdev;
477 struct usb_xpad *xpad;
478};
479
480static void xpad_send_led_command(struct usb_xpad *xpad, int command)
481{
482 if (command >= 0 && command < 14) {
483 mutex_lock(&xpad->odata_mutex);
484 xpad->odata[0] = 0x01;
485 xpad->odata[1] = 0x03;
486 xpad->odata[2] = command;
487 usb_submit_urb(xpad->irq_out, GFP_KERNEL);
488 mutex_unlock(&xpad->odata_mutex);
489 }
490}
491
492static void xpad_led_set(struct led_classdev *led_cdev,
493 enum led_brightness value)
494{
495 struct xpad_led *xpad_led = container_of(led_cdev,
496 struct xpad_led, led_cdev);
497
498 xpad_send_led_command(xpad_led->xpad, value);
499}
500
501static int xpad_led_probe(struct usb_xpad *xpad)
502{
503 static atomic_t led_seq = ATOMIC_INIT(0);
504 long led_no;
505 struct xpad_led *led;
506 struct led_classdev *led_cdev;
507 int error;
508
509 if (xpad->xtype != XTYPE_XBOX360)
510 return 0;
511
512 xpad->led = led = kzalloc(sizeof(struct xpad_led), GFP_KERNEL);
513 if (!led)
514 return -ENOMEM;
515
516 led_no = (long)atomic_inc_return(&led_seq) - 1;
517
518 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
519 led->xpad = xpad;
520
521 led_cdev = &led->led_cdev;
522 led_cdev->name = led->name;
523 led_cdev->brightness_set = xpad_led_set;
524
525 error = led_classdev_register(&xpad->udev->dev, led_cdev);
526 if (error) {
527 kfree(led);
528 xpad->led = NULL;
529 return error;
530 }
531
532 /*
533 * Light up the segment corresponding to controller number
534 */
535 xpad_send_led_command(xpad, (led_no % 4) + 2);
536
537 return 0;
538}
539
540static void xpad_led_disconnect(struct usb_xpad *xpad)
541{
542 struct xpad_led *xpad_led = xpad->led;
543
544 if (xpad_led) {
545 led_classdev_unregister(&xpad_led->led_cdev);
546 kfree(xpad_led->name);
547 }
548}
453#else 549#else
454static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad) { return 0; } 550static int xpad_led_probe(struct usb_xpad *xpad) { return 0; }
455static void xpad_stop_ff(struct usb_xpad *xpad) { } 551static void xpad_led_disconnect(struct usb_xpad *xpad) { }
456static void xpad_deinit_ff(struct usb_xpad *xpad) { }
457#endif 552#endif
458 553
554
459static int xpad_open(struct input_dev *dev) 555static int xpad_open(struct input_dev *dev)
460{ 556{
461 struct usb_xpad *xpad = input_get_drvdata(dev); 557 struct usb_xpad *xpad = input_get_drvdata(dev);
@@ -472,7 +568,7 @@ static void xpad_close(struct input_dev *dev)
472 struct usb_xpad *xpad = input_get_drvdata(dev); 568 struct usb_xpad *xpad = input_get_drvdata(dev);
473 569
474 usb_kill_urb(xpad->irq_in); 570 usb_kill_urb(xpad->irq_in);
475 xpad_stop_ff(xpad); 571 xpad_stop_output(xpad);
476} 572}
477 573
478static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) 574static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
@@ -564,10 +660,18 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
564 for (i = 0; xpad_abs_pad[i] >= 0; i++) 660 for (i = 0; xpad_abs_pad[i] >= 0; i++)
565 xpad_set_up_abs(input_dev, xpad_abs_pad[i]); 661 xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
566 662
567 error = xpad_init_ff(intf, xpad); 663 error = xpad_init_output(intf, xpad);
568 if (error) 664 if (error)
569 goto fail2; 665 goto fail2;
570 666
667 error = xpad_init_ff(xpad);
668 if (error)
669 goto fail3;
670
671 error = xpad_led_probe(xpad);
672 if (error)
673 goto fail3;
674
571 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; 675 ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
572 usb_fill_int_urb(xpad->irq_in, udev, 676 usb_fill_int_urb(xpad->irq_in, udev,
573 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), 677 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
@@ -578,12 +682,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
578 682
579 error = input_register_device(xpad->dev); 683 error = input_register_device(xpad->dev);
580 if (error) 684 if (error)
581 goto fail3; 685 goto fail4;
582 686
583 usb_set_intfdata(intf, xpad); 687 usb_set_intfdata(intf, xpad);
584 return 0; 688 return 0;
585 689
586 fail3: usb_free_urb(xpad->irq_in); 690 fail4: usb_free_urb(xpad->irq_in);
691 fail3: xpad_deinit_output(xpad);
587 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); 692 fail2: usb_buffer_free(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma);
588 fail1: input_free_device(input_dev); 693 fail1: input_free_device(input_dev);
589 kfree(xpad); 694 kfree(xpad);
@@ -597,8 +702,9 @@ static void xpad_disconnect(struct usb_interface *intf)
597 702
598 usb_set_intfdata(intf, NULL); 703 usb_set_intfdata(intf, NULL);
599 if (xpad) { 704 if (xpad) {
705 xpad_led_disconnect(xpad);
600 input_unregister_device(xpad->dev); 706 input_unregister_device(xpad->dev);
601 xpad_deinit_ff(xpad); 707 xpad_deinit_output(xpad);
602 usb_free_urb(xpad->irq_in); 708 usb_free_urb(xpad->irq_in);
603 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 709 usb_buffer_free(xpad->udev, XPAD_PKT_LEN,
604 xpad->idata, xpad->idata_dma); 710 xpad->idata, xpad->idata_dma);
diff --git a/drivers/input/misc/pcspkr.c b/drivers/input/misc/pcspkr.c
index 31989dcd922c..906bf5e8de89 100644
--- a/drivers/input/misc/pcspkr.c
+++ b/drivers/input/misc/pcspkr.c
@@ -24,7 +24,12 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
24MODULE_DESCRIPTION("PC Speaker beeper driver"); 24MODULE_DESCRIPTION("PC Speaker beeper driver");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27static DEFINE_SPINLOCK(i8253_beep_lock); 27#ifdef CONFIG_X86
28/* Use the global PIT lock ! */
29#include <asm/i8253.h>
30#else
31static DEFINE_SPINLOCK(i8253_lock);
32#endif
28 33
29static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 34static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
30{ 35{
@@ -43,7 +48,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
43 if (value > 20 && value < 32767) 48 if (value > 20 && value < 32767)
44 count = PIT_TICK_RATE / value; 49 count = PIT_TICK_RATE / value;
45 50
46 spin_lock_irqsave(&i8253_beep_lock, flags); 51 spin_lock_irqsave(&i8253_lock, flags);
47 52
48 if (count) { 53 if (count) {
49 /* enable counter 2 */ 54 /* enable counter 2 */
@@ -58,7 +63,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
58 outb(inb_p(0x61) & 0xFC, 0x61); 63 outb(inb_p(0x61) & 0xFC, 0x61);
59 } 64 }
60 65
61 spin_unlock_irqrestore(&i8253_beep_lock, flags); 66 spin_unlock_irqrestore(&i8253_lock, flags);
62 67
63 return 0; 68 return 0;
64} 69}
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index e3215267db11..2bea1b2c631c 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -155,6 +155,8 @@ struct atp {
155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS]; 155 int xy_acc[ATP_XSENSORS + ATP_YSENSORS];
156 int overflowwarn; /* overflow warning printed? */ 156 int overflowwarn; /* overflow warning printed? */
157 int datalen; /* size of an USB urb transfer */ 157 int datalen; /* size of an USB urb transfer */
158 int idlecount; /* number of empty packets */
159 struct work_struct work;
158}; 160};
159 161
160#define dbg_dump(msg, tab) \ 162#define dbg_dump(msg, tab) \
@@ -208,6 +210,55 @@ static inline int atp_is_geyser_3(struct atp *dev)
208 (productId == GEYSER4_JIS_PRODUCT_ID); 210 (productId == GEYSER4_JIS_PRODUCT_ID);
209} 211}
210 212
213/*
214 * By default Geyser 3 device sends standard USB HID mouse
215 * packets (Report ID 2). This code changes device mode, so it
216 * sends raw sensor reports (Report ID 5).
217 */
218static int atp_geyser3_init(struct usb_device *udev)
219{
220 char data[8];
221 int size;
222
223 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
224 ATP_GEYSER3_MODE_READ_REQUEST_ID,
225 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
226 ATP_GEYSER3_MODE_REQUEST_VALUE,
227 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
228
229 if (size != 8) {
230 err("Could not do mode read request from device"
231 " (Geyser 3 mode)");
232 return -EIO;
233 }
234
235 /* Apply the mode switch */
236 data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE;
237
238 size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
239 ATP_GEYSER3_MODE_WRITE_REQUEST_ID,
240 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
241 ATP_GEYSER3_MODE_REQUEST_VALUE,
242 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
243
244 if (size != 8) {
245 err("Could not do mode write request to device"
246 " (Geyser 3 mode)");
247 return -EIO;
248 }
249 return 0;
250}
251
252/* Reinitialise the device if it's a geyser 3 */
253static void atp_reinit(struct work_struct *work)
254{
255 struct atp *dev = container_of(work, struct atp, work);
256 struct usb_device *udev = dev->udev;
257
258 dev->idlecount = 0;
259 atp_geyser3_init(udev);
260}
261
211static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, 262static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
212 int *z, int *fingers) 263 int *z, int *fingers)
213{ 264{
@@ -439,8 +490,8 @@ static void atp_complete(struct urb* urb)
439 } 490 }
440 dev->x_old = x; 491 dev->x_old = x;
441 dev->y_old = y; 492 dev->y_old = y;
442 } 493
443 else if (!x && !y) { 494 } else if (!x && !y) {
444 495
445 dev->x_old = dev->y_old = -1; 496 dev->x_old = dev->y_old = -1;
446 input_report_key(dev->input, BTN_TOUCH, 0); 497 input_report_key(dev->input, BTN_TOUCH, 0);
@@ -449,11 +500,21 @@ static void atp_complete(struct urb* urb)
449 500
450 /* reset the accumulator on release */ 501 /* reset the accumulator on release */
451 memset(dev->xy_acc, 0, sizeof(dev->xy_acc)); 502 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
452 }
453 503
454 input_report_key(dev->input, BTN_LEFT, 504 /* Geyser 3 will continue to send packets continually after
455 !!dev->data[dev->datalen - 1]); 505 the first touch unless reinitialised. Do so if it's been
506 idle for a while in order to avoid waking the kernel up
507 several hundred times a second */
508 if (atp_is_geyser_3(dev)) {
509 dev->idlecount++;
510 if (dev->idlecount == 10) {
511 dev->valid = 0;
512 schedule_work(&dev->work);
513 }
514 }
515 }
456 516
517 input_report_key(dev->input, BTN_LEFT, dev->data[dev->datalen - 1] & 1);
457 input_sync(dev->input); 518 input_sync(dev->input);
458 519
459exit: 520exit:
@@ -480,6 +541,7 @@ static void atp_close(struct input_dev *input)
480 struct atp *dev = input_get_drvdata(input); 541 struct atp *dev = input_get_drvdata(input);
481 542
482 usb_kill_urb(dev->urb); 543 usb_kill_urb(dev->urb);
544 cancel_work_sync(&dev->work);
483 dev->open = 0; 545 dev->open = 0;
484} 546}
485 547
@@ -528,40 +590,10 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
528 dev->datalen = 81; 590 dev->datalen = 81;
529 591
530 if (atp_is_geyser_3(dev)) { 592 if (atp_is_geyser_3(dev)) {
531 /* 593 /* switch to raw sensor mode */
532 * By default Geyser 3 device sends standard USB HID mouse 594 if (atp_geyser3_init(udev))
533 * packets (Report ID 2). This code changes device mode, so it
534 * sends raw sensor reports (Report ID 5).
535 */
536 char data[8];
537 int size;
538
539 size = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
540 ATP_GEYSER3_MODE_READ_REQUEST_ID,
541 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
542 ATP_GEYSER3_MODE_REQUEST_VALUE,
543 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
544
545 if (size != 8) {
546 err("Could not do mode read request from device"
547 " (Geyser 3 mode)");
548 goto err_free_devs; 595 goto err_free_devs;
549 }
550
551 /* Apply the mode switch */
552 data[0] = ATP_GEYSER3_MODE_VENDOR_VALUE;
553
554 size = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
555 ATP_GEYSER3_MODE_WRITE_REQUEST_ID,
556 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
557 ATP_GEYSER3_MODE_REQUEST_VALUE,
558 ATP_GEYSER3_MODE_REQUEST_INDEX, &data, 8, 5000);
559 596
560 if (size != 8) {
561 err("Could not do mode write request to device"
562 " (Geyser 3 mode)");
563 goto err_free_devs;
564 }
565 printk("appletouch Geyser 3 inited.\n"); 597 printk("appletouch Geyser 3 inited.\n");
566 } 598 }
567 599
@@ -636,6 +668,8 @@ static int atp_probe(struct usb_interface *iface, const struct usb_device_id *id
636 /* save our data pointer in this interface device */ 668 /* save our data pointer in this interface device */
637 usb_set_intfdata(iface, dev); 669 usb_set_intfdata(iface, dev);
638 670
671 INIT_WORK(&dev->work, atp_reinit);
672
639 return 0; 673 return 0;
640 674
641 err_free_buffer: 675 err_free_buffer:
@@ -669,14 +703,17 @@ static void atp_disconnect(struct usb_interface *iface)
669static int atp_suspend(struct usb_interface *iface, pm_message_t message) 703static int atp_suspend(struct usb_interface *iface, pm_message_t message)
670{ 704{
671 struct atp *dev = usb_get_intfdata(iface); 705 struct atp *dev = usb_get_intfdata(iface);
706
672 usb_kill_urb(dev->urb); 707 usb_kill_urb(dev->urb);
673 dev->valid = 0; 708 dev->valid = 0;
709
674 return 0; 710 return 0;
675} 711}
676 712
677static int atp_resume(struct usb_interface *iface) 713static int atp_resume(struct usb_interface *iface)
678{ 714{
679 struct atp *dev = usb_get_intfdata(iface); 715 struct atp *dev = usb_get_intfdata(iface);
716
680 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC)) 717 if (dev->open && usb_submit_urb(dev->urb, GFP_ATOMIC))
681 return -EIO; 718 return -EIO;
682 719
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
index 1740cadd9594..91109b49fde1 100644
--- a/drivers/input/mouse/lifebook.c
+++ b/drivers/input/mouse/lifebook.c
@@ -109,7 +109,7 @@ static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
109{ 109{
110 struct lifebook_data *priv = psmouse->private; 110 struct lifebook_data *priv = psmouse->private;
111 struct input_dev *dev1 = psmouse->dev; 111 struct input_dev *dev1 = psmouse->dev;
112 struct input_dev *dev2 = priv->dev2; 112 struct input_dev *dev2 = priv ? priv->dev2 : NULL;
113 unsigned char *packet = psmouse->packet; 113 unsigned char *packet = psmouse->packet;
114 int relative_packet = packet[0] & 0x08; 114 int relative_packet = packet[0] & 0x08;
115 115
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 4fca1e7f2678..702a526cf45b 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -366,6 +366,7 @@ static void i8042_pnp_exit(void)
366static int __init i8042_pnp_init(void) 366static int __init i8042_pnp_init(void)
367{ 367{
368 char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 }; 368 char kbd_irq_str[4] = { 0 }, aux_irq_str[4] = { 0 };
369 int pnp_data_busted = 0;
369 int err; 370 int err;
370 371
371 if (i8042_nopnp) { 372 if (i8042_nopnp) {
@@ -413,27 +414,48 @@ static int __init i8042_pnp_init(void)
413#endif 414#endif
414 415
415 if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) && 416 if (((i8042_pnp_data_reg & ~0xf) == (i8042_data_reg & ~0xf) &&
416 i8042_pnp_data_reg != i8042_data_reg) || !i8042_pnp_data_reg) { 417 i8042_pnp_data_reg != i8042_data_reg) ||
417 printk(KERN_WARNING "PNP: PS/2 controller has invalid data port %#x; using default %#x\n", 418 !i8042_pnp_data_reg) {
419 printk(KERN_WARNING
420 "PNP: PS/2 controller has invalid data port %#x; "
421 "using default %#x\n",
418 i8042_pnp_data_reg, i8042_data_reg); 422 i8042_pnp_data_reg, i8042_data_reg);
419 i8042_pnp_data_reg = i8042_data_reg; 423 i8042_pnp_data_reg = i8042_data_reg;
424 pnp_data_busted = 1;
420 } 425 }
421 426
422 if (((i8042_pnp_command_reg & ~0xf) == (i8042_command_reg & ~0xf) && 427 if (((i8042_pnp_command_reg & ~0xf) == (i8042_command_reg & ~0xf) &&
423 i8042_pnp_command_reg != i8042_command_reg) || !i8042_pnp_command_reg) { 428 i8042_pnp_command_reg != i8042_command_reg) ||
424 printk(KERN_WARNING "PNP: PS/2 controller has invalid command port %#x; using default %#x\n", 429 !i8042_pnp_command_reg) {
430 printk(KERN_WARNING
431 "PNP: PS/2 controller has invalid command port %#x; "
432 "using default %#x\n",
425 i8042_pnp_command_reg, i8042_command_reg); 433 i8042_pnp_command_reg, i8042_command_reg);
426 i8042_pnp_command_reg = i8042_command_reg; 434 i8042_pnp_command_reg = i8042_command_reg;
435 pnp_data_busted = 1;
427 } 436 }
428 437
429 if (!i8042_nokbd && !i8042_pnp_kbd_irq) { 438 if (!i8042_nokbd && !i8042_pnp_kbd_irq) {
430 printk(KERN_WARNING "PNP: PS/2 controller doesn't have KBD irq; using default %d\n", i8042_kbd_irq); 439 printk(KERN_WARNING
440 "PNP: PS/2 controller doesn't have KBD irq; "
441 "using default %d\n", i8042_kbd_irq);
431 i8042_pnp_kbd_irq = i8042_kbd_irq; 442 i8042_pnp_kbd_irq = i8042_kbd_irq;
443 pnp_data_busted = 1;
432 } 444 }
433 445
434 if (!i8042_noaux && !i8042_pnp_aux_irq) { 446 if (!i8042_noaux && !i8042_pnp_aux_irq) {
435 printk(KERN_WARNING "PNP: PS/2 controller doesn't have AUX irq; using default %d\n", i8042_aux_irq); 447 if (!pnp_data_busted && i8042_pnp_kbd_irq) {
436 i8042_pnp_aux_irq = i8042_aux_irq; 448 printk(KERN_WARNING
449 "PNP: PS/2 appears to have AUX port disabled, "
450 "if this is incorrect please boot with "
451 "i8042.nopnp\n");
452 i8042_noaux = 1;
453 } else {
454 printk(KERN_WARNING
455 "PNP: PS/2 controller doesn't have AUX irq; "
456 "using default %d\n", i8042_aux_irq);
457 i8042_pnp_aux_irq = i8042_aux_irq;
458 }
437 } 459 }
438 460
439 i8042_data_reg = i8042_pnp_data_reg; 461 i8042_data_reg = i8042_pnp_data_reg;
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 69371779806a..f929fcdbae2e 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -54,6 +54,19 @@ config TOUCHSCREEN_CORGI
54 To compile this driver as a module, choose M here: the 54 To compile this driver as a module, choose M here: the
55 module will be called corgi_ts. 55 module will be called corgi_ts.
56 56
57config TOUCHSCREEN_FUJITSU
58 tristate "Fujitsu serial touchscreen"
59 select SERIO
60 help
61 Say Y here if you have the Fujitsu touchscreen (such as one
62 installed in Lifebook P series laptop) connected to your
63 system.
64
65 If unsure, say N.
66
67 To compile this driver as a module, choose M here: the
68 module will be called fujitsu-ts.
69
57config TOUCHSCREEN_GUNZE 70config TOUCHSCREEN_GUNZE
58 tristate "Gunze AHL-51S touchscreen" 71 tristate "Gunze AHL-51S touchscreen"
59 select SERIO 72 select SERIO
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 2f86d6ad06d3..5de8933c4993 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o
9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o 9obj-$(CONFIG_TOUCHSCREEN_CORGI) += corgi_ts.o
10obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o 10obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
11obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o 11obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
12obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
12obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o 13obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o
13obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o 14obj-$(CONFIG_TOUCHSCREEN_MK712) += mk712.o
14obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o 15obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 1c9069cd3bae..96581d08774f 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -95,7 +95,7 @@ struct ads7846 {
95 u16 dummy; /* for the pwrdown read */ 95 u16 dummy; /* for the pwrdown read */
96 struct ts_event tc; 96 struct ts_event tc;
97 97
98 struct spi_transfer xfer[10]; 98 struct spi_transfer xfer[18];
99 struct spi_message msg[5]; 99 struct spi_message msg[5];
100 struct spi_message *last_msg; 100 struct spi_message *last_msg;
101 int msg_idx; 101 int msg_idx;
@@ -107,6 +107,8 @@ struct ads7846 {
107 u16 debounce_tol; 107 u16 debounce_tol;
108 u16 debounce_rep; 108 u16 debounce_rep;
109 109
110 u16 penirq_recheck_delay_usecs;
111
110 spinlock_t lock; 112 spinlock_t lock;
111 struct hrtimer timer; 113 struct hrtimer timer;
112 unsigned pendown:1; /* P: lock */ 114 unsigned pendown:1; /* P: lock */
@@ -553,6 +555,15 @@ static void ads7846_rx(void *ads)
553 return; 555 return;
554 } 556 }
555 557
558 /* Maybe check the pendown state before reporting. This discards
559 * false readings when the pen is lifted.
560 */
561 if (ts->penirq_recheck_delay_usecs) {
562 udelay(ts->penirq_recheck_delay_usecs);
563 if (!ts->get_pendown_state())
564 Rt = 0;
565 }
566
556 /* NOTE: We can't rely on the pressure to determine the pen down 567 /* NOTE: We can't rely on the pressure to determine the pen down
557 * state, even this controller has a pressure sensor. The pressure 568 * state, even this controller has a pressure sensor. The pressure
558 * value can fluctuate for quite a while after lifting the pen and 569 * value can fluctuate for quite a while after lifting the pen and
@@ -896,6 +907,10 @@ static int __devinit ads7846_probe(struct spi_device *spi)
896 ts->filter = ads7846_no_filter; 907 ts->filter = ads7846_no_filter;
897 ts->get_pendown_state = pdata->get_pendown_state; 908 ts->get_pendown_state = pdata->get_pendown_state;
898 909
910 if (pdata->penirq_recheck_delay_usecs)
911 ts->penirq_recheck_delay_usecs =
912 pdata->penirq_recheck_delay_usecs;
913
899 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); 914 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
900 915
901 input_dev->name = "ADS784x Touchscreen"; 916 input_dev->name = "ADS784x Touchscreen";
@@ -936,6 +951,24 @@ static int __devinit ads7846_probe(struct spi_device *spi)
936 x->len = 2; 951 x->len = 2;
937 spi_message_add_tail(x, m); 952 spi_message_add_tail(x, m);
938 953
954 /* the first sample after switching drivers can be low quality;
955 * optionally discard it, using a second one after the signals
956 * have had enough time to stabilize.
957 */
958 if (pdata->settle_delay_usecs) {
959 x->delay_usecs = pdata->settle_delay_usecs;
960
961 x++;
962 x->tx_buf = &ts->read_y;
963 x->len = 1;
964 spi_message_add_tail(x, m);
965
966 x++;
967 x->rx_buf = &ts->tc.y;
968 x->len = 2;
969 spi_message_add_tail(x, m);
970 }
971
939 m->complete = ads7846_rx_val; 972 m->complete = ads7846_rx_val;
940 m->context = ts; 973 m->context = ts;
941 974
@@ -954,6 +987,21 @@ static int __devinit ads7846_probe(struct spi_device *spi)
954 x->len = 2; 987 x->len = 2;
955 spi_message_add_tail(x, m); 988 spi_message_add_tail(x, m);
956 989
990 /* ... maybe discard first sample ... */
991 if (pdata->settle_delay_usecs) {
992 x->delay_usecs = pdata->settle_delay_usecs;
993
994 x++;
995 x->tx_buf = &ts->read_x;
996 x->len = 1;
997 spi_message_add_tail(x, m);
998
999 x++;
1000 x->rx_buf = &ts->tc.x;
1001 x->len = 2;
1002 spi_message_add_tail(x, m);
1003 }
1004
957 m->complete = ads7846_rx_val; 1005 m->complete = ads7846_rx_val;
958 m->context = ts; 1006 m->context = ts;
959 1007
@@ -973,6 +1021,21 @@ static int __devinit ads7846_probe(struct spi_device *spi)
973 x->len = 2; 1021 x->len = 2;
974 spi_message_add_tail(x, m); 1022 spi_message_add_tail(x, m);
975 1023
1024 /* ... maybe discard first sample ... */
1025 if (pdata->settle_delay_usecs) {
1026 x->delay_usecs = pdata->settle_delay_usecs;
1027
1028 x++;
1029 x->tx_buf = &ts->read_z1;
1030 x->len = 1;
1031 spi_message_add_tail(x, m);
1032
1033 x++;
1034 x->rx_buf = &ts->tc.z1;
1035 x->len = 2;
1036 spi_message_add_tail(x, m);
1037 }
1038
976 m->complete = ads7846_rx_val; 1039 m->complete = ads7846_rx_val;
977 m->context = ts; 1040 m->context = ts;
978 1041
@@ -990,6 +1053,21 @@ static int __devinit ads7846_probe(struct spi_device *spi)
990 x->len = 2; 1053 x->len = 2;
991 spi_message_add_tail(x, m); 1054 spi_message_add_tail(x, m);
992 1055
1056 /* ... maybe discard first sample ... */
1057 if (pdata->settle_delay_usecs) {
1058 x->delay_usecs = pdata->settle_delay_usecs;
1059
1060 x++;
1061 x->tx_buf = &ts->read_z2;
1062 x->len = 1;
1063 spi_message_add_tail(x, m);
1064
1065 x++;
1066 x->rx_buf = &ts->tc.z2;
1067 x->len = 2;
1068 spi_message_add_tail(x, m);
1069 }
1070
993 m->complete = ads7846_rx_val; 1071 m->complete = ads7846_rx_val;
994 m->context = ts; 1072 m->context = ts;
995 } 1073 }
diff --git a/drivers/input/touchscreen/fujitsu_ts.c b/drivers/input/touchscreen/fujitsu_ts.c
new file mode 100644
index 000000000000..daf7a4afc935
--- /dev/null
+++ b/drivers/input/touchscreen/fujitsu_ts.c
@@ -0,0 +1,189 @@
1/*
2 * Fujitsu serial touchscreen driver
3 *
4 * Copyright (c) Dmitry Torokhov <dtor@mail.ru>
5 */
6
7/*
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published
10 * by the Free Software Foundation.
11 */
12
13#include <linux/errno.h>
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/slab.h>
17#include <linux/input.h>
18#include <linux/serio.h>
19#include <linux/init.h>
20
21#define DRIVER_DESC "Fujitsu serial touchscreen driver"
22
23MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
24MODULE_DESCRIPTION(DRIVER_DESC);
25MODULE_LICENSE("GPL");
26
27#define FUJITSU_LENGTH 5
28
29/*
30 * Per-touchscreen data.
31 */
32struct fujitsu {
33 struct input_dev *dev;
34 struct serio *serio;
35 int idx;
36 unsigned char data[FUJITSU_LENGTH];
37 char phys[32];
38};
39
40/*
41 * Decode serial data (5 bytes per packet)
42 * First byte
43 * 1 C 0 0 R S S S
44 * Where C is 1 while in calibration mode (which we don't use)
45 * R is 1 when no coordinate corection was done.
46 * S are button state
47 */
48static irqreturn_t fujitsu_interrupt(struct serio *serio,
49 unsigned char data, unsigned int flags)
50{
51 struct fujitsu *fujitsu = serio_get_drvdata(serio);
52 struct input_dev *dev = fujitsu->dev;
53
54 if (fujitsu->idx == 0) {
55 /* resync skip until start of frame */
56 if ((data & 0xf0) != 0x80)
57 return IRQ_HANDLED;
58 } else {
59 /* resync skip garbage */
60 if (data & 0x80) {
61 fujitsu->idx = 0;
62 return IRQ_HANDLED;
63 }
64 }
65
66 fujitsu->data[fujitsu->idx++] = data;
67 if (fujitsu->idx == FUJITSU_LENGTH) {
68 input_report_abs(dev, ABS_X,
69 (fujitsu->data[2] << 7) | fujitsu->data[1]);
70 input_report_abs(dev, ABS_Y,
71 (fujitsu->data[4] << 7) | fujitsu->data[3]);
72 input_report_key(dev, BTN_TOUCH,
73 (fujitsu->data[0] & 0x03) != 2);
74 input_sync(dev);
75 fujitsu->idx = 0;
76 }
77
78 return IRQ_HANDLED;
79}
80
81/*
82 * fujitsu_disconnect() is the opposite of fujitsu_connect()
83 */
84static void fujitsu_disconnect(struct serio *serio)
85{
86 struct fujitsu *fujitsu = serio_get_drvdata(serio);
87
88 input_get_device(fujitsu->dev);
89 input_unregister_device(fujitsu->dev);
90 serio_close(serio);
91 serio_set_drvdata(serio, NULL);
92 input_put_device(fujitsu->dev);
93 kfree(fujitsu);
94}
95
96/*
97 * fujitsu_connect() is the routine that is called when someone adds a
98 * new serio device that supports the Fujitsu protocol and registers it
99 * as input device.
100 */
101static int fujitsu_connect(struct serio *serio, struct serio_driver *drv)
102{
103 struct fujitsu *fujitsu;
104 struct input_dev *input_dev;
105 int err;
106
107 fujitsu = kzalloc(sizeof(struct fujitsu), GFP_KERNEL);
108 input_dev = input_allocate_device();
109 if (!fujitsu || !input_dev) {
110 err = -ENOMEM;
111 goto fail1;
112 }
113
114 fujitsu->serio = serio;
115 fujitsu->dev = input_dev;
116 snprintf(fujitsu->phys, sizeof(fujitsu->phys),
117 "%s/input0", serio->phys);
118
119 input_dev->name = "Fujitsu Serial Touchscreen";
120 input_dev->phys = fujitsu->phys;
121 input_dev->id.bustype = BUS_RS232;
122 input_dev->id.vendor = SERIO_FUJITSU;
123 input_dev->id.product = 0;
124 input_dev->id.version = 0x0100;
125 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
126 input_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
127
128 input_set_abs_params(input_dev, ABS_X, 0, 4096, 0, 0);
129 input_set_abs_params(input_dev, ABS_Y, 0, 4096, 0, 0);
130 serio_set_drvdata(serio, fujitsu);
131
132 err = serio_open(serio, drv);
133 if (err)
134 goto fail2;
135
136 err = input_register_device(fujitsu->dev);
137 if (err)
138 goto fail3;
139
140 return 0;
141
142 fail3:
143 serio_close(serio);
144 fail2:
145 serio_set_drvdata(serio, NULL);
146 fail1:
147 input_free_device(input_dev);
148 kfree(fujitsu);
149 return err;
150}
151
152/*
153 * The serio driver structure.
154 */
155static struct serio_device_id fujitsu_serio_ids[] = {
156 {
157 .type = SERIO_RS232,
158 .proto = SERIO_FUJITSU,
159 .id = SERIO_ANY,
160 .extra = SERIO_ANY,
161 },
162 { 0 }
163};
164
165MODULE_DEVICE_TABLE(serio, fujitsu_serio_ids);
166
167static struct serio_driver fujitsu_drv = {
168 .driver = {
169 .name = "fujitsu_ts",
170 },
171 .description = DRIVER_DESC,
172 .id_table = fujitsu_serio_ids,
173 .interrupt = fujitsu_interrupt,
174 .connect = fujitsu_connect,
175 .disconnect = fujitsu_disconnect,
176};
177
178static int __init fujitsu_init(void)
179{
180 return serio_register_driver(&fujitsu_drv);
181}
182
183static void __exit fujitsu_exit(void)
184{
185 serio_unregister_driver(&fujitsu_drv);
186}
187
188module_init(fujitsu_init);
189module_exit(fujitsu_exit);
diff --git a/drivers/isdn/Kconfig b/drivers/isdn/Kconfig
index cf906c8cee4d..66f946aa30b3 100644
--- a/drivers/isdn/Kconfig
+++ b/drivers/isdn/Kconfig
@@ -21,9 +21,7 @@ menuconfig ISDN
21 21
22if ISDN 22if ISDN
23 23
24menu "Old ISDN4Linux" 24menuconfig ISDN_I4L
25
26config ISDN_I4L
27 tristate "Old ISDN4Linux (deprecated)" 25 tristate "Old ISDN4Linux (deprecated)"
28 ---help--- 26 ---help---
29 This driver allows you to use an ISDN adapter for networking 27 This driver allows you to use an ISDN adapter for networking
@@ -45,12 +43,8 @@ if ISDN_I4L
45source "drivers/isdn/i4l/Kconfig" 43source "drivers/isdn/i4l/Kconfig"
46endif 44endif
47 45
48endmenu 46menuconfig ISDN_CAPI
49 47 tristate "CAPI 2.0 subsystem"
50comment "CAPI subsystem"
51
52config ISDN_CAPI
53 tristate "CAPI2.0 support"
54 help 48 help
55 This provides the CAPI (Common ISDN Application Programming 49 This provides the CAPI (Common ISDN Application Programming
56 Interface, a standard making it easy for programs to access ISDN 50 Interface, a standard making it easy for programs to access ISDN
diff --git a/drivers/isdn/act2000/Kconfig b/drivers/isdn/act2000/Kconfig
index 78e6ad8d57c5..3fc1a5434ef7 100644
--- a/drivers/isdn/act2000/Kconfig
+++ b/drivers/isdn/act2000/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4config ISDN_DRV_ACT2000 4config ISDN_DRV_ACT2000
5 tristate "IBM Active 2000 support" 5 tristate "IBM Active 2000 support"
6 depends on ISDN_I4L && ISA 6 depends on ISA
7 help 7 help
8 Say Y here if you have an IBM Active 2000 ISDN card. In order to use 8 Say Y here if you have an IBM Active 2000 ISDN card. In order to use
9 this card, additional firmware is necessary, which has to be loaded 9 this card, additional firmware is necessary, which has to be loaded
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index bcbb6502a773..0017e50c6948 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -1,9 +1,5 @@
1menu "Siemens Gigaset" 1menuconfig ISDN_DRV_GIGASET
2 depends on ISDN_I4L
3
4config ISDN_DRV_GIGASET
5 tristate "Siemens Gigaset support (isdn)" 2 tristate "Siemens Gigaset support (isdn)"
6 depends on ISDN_I4L
7 select CRC_CCITT 3 select CRC_CCITT
8 select BITREVERSE 4 select BITREVERSE
9 help 5 help
@@ -55,6 +51,4 @@ config GIGASET_UNDOCREQ
55 features like configuration mode of M105, say yes. If you 51 features like configuration mode of M105, say yes. If you
56 care about your device, say no. 52 care about your device, say no.
57 53
58endif 54endif # ISDN_DRV_GIGASET != n
59
60endmenu
diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig
index 12d91fb9f8cb..a3b945ac3256 100644
--- a/drivers/isdn/hisax/Kconfig
+++ b/drivers/isdn/hisax/Kconfig
@@ -1,6 +1,5 @@
1 1
2menu "Passive cards" 2menu "Passive cards"
3 depends on ISDN_I4L
4 3
5config ISDN_DRV_HISAX 4config ISDN_DRV_HISAX
6 tristate "HiSax SiemensChipSet driver support" 5 tristate "HiSax SiemensChipSet driver support"
diff --git a/drivers/isdn/i4l/Kconfig b/drivers/isdn/i4l/Kconfig
index e91c187992dd..36778b270c30 100644
--- a/drivers/isdn/i4l/Kconfig
+++ b/drivers/isdn/i4l/Kconfig
@@ -99,7 +99,6 @@ config ISDN_DRV_LOOP
99 99
100config ISDN_DIVERSION 100config ISDN_DIVERSION
101 tristate "Support isdn diversion services" 101 tristate "Support isdn diversion services"
102 depends on ISDN_I4L
103 help 102 help
104 This option allows you to use some supplementary diversion 103 This option allows you to use some supplementary diversion
105 services in conjunction with the HiSax driver on an EURO/DSS1 104 services in conjunction with the HiSax driver on an EURO/DSS1
@@ -119,13 +118,11 @@ config ISDN_DIVERSION
119endmenu 118endmenu
120 119
121comment "ISDN4Linux hardware drivers" 120comment "ISDN4Linux hardware drivers"
122 depends on ISDN_I4L
123 121
124source "drivers/isdn/hisax/Kconfig" 122source "drivers/isdn/hisax/Kconfig"
125 123
126 124
127menu "Active cards" 125menu "Active cards"
128 depends on ISDN_I4L!=n
129 126
130source "drivers/isdn/icn/Kconfig" 127source "drivers/isdn/icn/Kconfig"
131 128
diff --git a/drivers/isdn/icn/Kconfig b/drivers/isdn/icn/Kconfig
index fcb99f5f0b26..89d15eed765e 100644
--- a/drivers/isdn/icn/Kconfig
+++ b/drivers/isdn/icn/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4config ISDN_DRV_ICN 4config ISDN_DRV_ICN
5 tristate "ICN 2B and 4B support" 5 tristate "ICN 2B and 4B support"
6 depends on ISDN_I4L && ISA 6 depends on ISA
7 help 7 help
8 This enables support for two kinds of ISDN-cards made by a German 8 This enables support for two kinds of ISDN-cards made by a German
9 company called ICN. 2B is the standard version for a single ISDN 9 company called ICN. 2B is the standard version for a single ISDN
diff --git a/drivers/isdn/pcbit/Kconfig b/drivers/isdn/pcbit/Kconfig
index 0933881ab0c2..ffba6eca1244 100644
--- a/drivers/isdn/pcbit/Kconfig
+++ b/drivers/isdn/pcbit/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4config ISDN_DRV_PCBIT 4config ISDN_DRV_PCBIT
5 tristate "PCBIT-D support" 5 tristate "PCBIT-D support"
6 depends on ISDN_I4L && ISA && (BROKEN || X86) 6 depends on ISA && (BROKEN || X86)
7 help 7 help
8 This enables support for the PCBIT ISDN-card. This card is 8 This enables support for the PCBIT ISDN-card. This card is
9 manufactured in Portugal by Octal. For running this card, 9 manufactured in Portugal by Octal. For running this card,
diff --git a/drivers/isdn/sc/Kconfig b/drivers/isdn/sc/Kconfig
index 5346e33d816c..e6510ca7bf43 100644
--- a/drivers/isdn/sc/Kconfig
+++ b/drivers/isdn/sc/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4config ISDN_DRV_SC 4config ISDN_DRV_SC
5 tristate "Spellcaster support" 5 tristate "Spellcaster support"
6 depends on ISDN_I4L && ISA 6 depends on ISA
7 help 7 help
8 This enables support for the Spellcaster BRI ISDN boards. This 8 This enables support for the Spellcaster BRI ISDN boards. This
9 driver currently builds only in a modularized version. 9 driver currently builds only in a modularized version.
diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig
index 2f661e5f0dae..6cecc396e040 100644
--- a/drivers/kvm/Kconfig
+++ b/drivers/kvm/Kconfig
@@ -11,6 +11,7 @@ if VIRTUALIZATION
11config KVM 11config KVM
12 tristate "Kernel-based Virtual Machine (KVM) support" 12 tristate "Kernel-based Virtual Machine (KVM) support"
13 depends on X86 && EXPERIMENTAL 13 depends on X86 && EXPERIMENTAL
14 select ANON_INODES
14 ---help--- 15 ---help---
15 Support hosting fully virtualized guest machines using hardware 16 Support hosting fully virtualized guest machines using hardware
16 virtualization extensions. You will need a fairly recent 17 virtualization extensions. You will need a fairly recent
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index a7c5e6bee034..3ac9cbce3369 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -121,7 +121,7 @@ struct kvm_pte_chain {
121 * bits 4:7 - page table level for this shadow (1-4) 121 * bits 4:7 - page table level for this shadow (1-4)
122 * bits 8:9 - page table quadrant for 2-level guests 122 * bits 8:9 - page table quadrant for 2-level guests
123 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode) 123 * bit 16 - "metaphysical" - gfn is not a real page (huge page/real mode)
124 * bits 17:18 - "access" - the user and writable bits of a huge page pde 124 * bits 17:19 - "access" - the user, writable, and nx bits of a huge page pde
125 */ 125 */
126union kvm_mmu_page_role { 126union kvm_mmu_page_role {
127 unsigned word; 127 unsigned word;
@@ -131,7 +131,7 @@ union kvm_mmu_page_role {
131 unsigned quadrant : 2; 131 unsigned quadrant : 2;
132 unsigned pad_for_nice_hex_output : 6; 132 unsigned pad_for_nice_hex_output : 6;
133 unsigned metaphysical : 1; 133 unsigned metaphysical : 1;
134 unsigned hugepage_access : 2; 134 unsigned hugepage_access : 3;
135 }; 135 };
136}; 136};
137 137
@@ -535,8 +535,8 @@ int kvm_mmu_create(struct kvm_vcpu *vcpu);
535int kvm_mmu_setup(struct kvm_vcpu *vcpu); 535int kvm_mmu_setup(struct kvm_vcpu *vcpu);
536 536
537int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 537int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
538void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot); 538void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
539void kvm_mmu_zap_all(struct kvm_vcpu *vcpu); 539void kvm_mmu_zap_all(struct kvm *kvm);
540 540
541hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa); 541hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
542#define HPA_MSB ((sizeof(hpa_t) * 8) - 1) 542#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
@@ -569,6 +569,8 @@ void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
569unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr); 569unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr);
570void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value, 570void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,
571 unsigned long *rflags); 571 unsigned long *rflags);
572int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *data);
573int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
572 574
573struct x86_emulate_ctxt; 575struct x86_emulate_ctxt;
574 576
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 1b206f197c6b..bcbe6835beb4 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -238,23 +238,6 @@ static void vcpu_load(struct kvm_vcpu *vcpu)
238 kvm_arch_ops->vcpu_load(vcpu); 238 kvm_arch_ops->vcpu_load(vcpu);
239} 239}
240 240
241/*
242 * Switches to specified vcpu, until a matching vcpu_put(). Will return NULL
243 * if the slot is not populated.
244 */
245static struct kvm_vcpu *vcpu_load_slot(struct kvm *kvm, int slot)
246{
247 struct kvm_vcpu *vcpu = &kvm->vcpus[slot];
248
249 mutex_lock(&vcpu->mutex);
250 if (!vcpu->vmcs) {
251 mutex_unlock(&vcpu->mutex);
252 return NULL;
253 }
254 kvm_arch_ops->vcpu_load(vcpu);
255 return vcpu;
256}
257
258static void vcpu_put(struct kvm_vcpu *vcpu) 241static void vcpu_put(struct kvm_vcpu *vcpu)
259{ 242{
260 kvm_arch_ops->vcpu_put(vcpu); 243 kvm_arch_ops->vcpu_put(vcpu);
@@ -663,13 +646,6 @@ void fx_init(struct kvm_vcpu *vcpu)
663} 646}
664EXPORT_SYMBOL_GPL(fx_init); 647EXPORT_SYMBOL_GPL(fx_init);
665 648
666static void do_remove_write_access(struct kvm_vcpu *vcpu, int slot)
667{
668 spin_lock(&vcpu->kvm->lock);
669 kvm_mmu_slot_remove_write_access(vcpu, slot);
670 spin_unlock(&vcpu->kvm->lock);
671}
672
673/* 649/*
674 * Allocate some memory and give it an address in the guest physical address 650 * Allocate some memory and give it an address in the guest physical address
675 * space. 651 * space.
@@ -792,19 +768,10 @@ raced:
792 *memslot = new; 768 *memslot = new;
793 ++kvm->memory_config_version; 769 ++kvm->memory_config_version;
794 770
795 spin_unlock(&kvm->lock); 771 kvm_mmu_slot_remove_write_access(kvm, mem->slot);
796 772 kvm_flush_remote_tlbs(kvm);
797 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
798 struct kvm_vcpu *vcpu;
799 773
800 vcpu = vcpu_load_slot(kvm, i); 774 spin_unlock(&kvm->lock);
801 if (!vcpu)
802 continue;
803 if (new.flags & KVM_MEM_LOG_DIRTY_PAGES)
804 do_remove_write_access(vcpu, mem->slot);
805 kvm_mmu_reset_context(vcpu);
806 vcpu_put(vcpu);
807 }
808 775
809 kvm_free_physmem_slot(&old, &new); 776 kvm_free_physmem_slot(&old, &new);
810 return 0; 777 return 0;
@@ -826,7 +793,6 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
826 struct kvm_memory_slot *memslot; 793 struct kvm_memory_slot *memslot;
827 int r, i; 794 int r, i;
828 int n; 795 int n;
829 int cleared;
830 unsigned long any = 0; 796 unsigned long any = 0;
831 797
832 spin_lock(&kvm->lock); 798 spin_lock(&kvm->lock);
@@ -855,23 +821,11 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
855 if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n)) 821 if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
856 goto out; 822 goto out;
857 823
858 if (any) { 824 spin_lock(&kvm->lock);
859 cleared = 0; 825 kvm_mmu_slot_remove_write_access(kvm, log->slot);
860 for (i = 0; i < KVM_MAX_VCPUS; ++i) { 826 kvm_flush_remote_tlbs(kvm);
861 struct kvm_vcpu *vcpu; 827 memset(memslot->dirty_bitmap, 0, n);
862 828 spin_unlock(&kvm->lock);
863 vcpu = vcpu_load_slot(kvm, i);
864 if (!vcpu)
865 continue;
866 if (!cleared) {
867 do_remove_write_access(vcpu, log->slot);
868 memset(memslot->dirty_bitmap, 0, n);
869 cleared = 1;
870 }
871 kvm_arch_ops->tlb_flush(vcpu);
872 vcpu_put(vcpu);
873 }
874 }
875 829
876 r = 0; 830 r = 0;
877 831
@@ -920,13 +874,9 @@ static int kvm_vm_ioctl_set_memory_alias(struct kvm *kvm,
920 break; 874 break;
921 kvm->naliases = n; 875 kvm->naliases = n;
922 876
923 spin_unlock(&kvm->lock); 877 kvm_mmu_zap_all(kvm);
924 878
925 vcpu_load(&kvm->vcpus[0]);
926 spin_lock(&kvm->lock);
927 kvm_mmu_zap_all(&kvm->vcpus[0]);
928 spin_unlock(&kvm->lock); 879 spin_unlock(&kvm->lock);
929 vcpu_put(&kvm->vcpus[0]);
930 880
931 return 0; 881 return 0;
932 882
@@ -1567,7 +1517,7 @@ EXPORT_SYMBOL_GPL(kvm_get_msr_common);
1567 * Returns 0 on success, non-0 otherwise. 1517 * Returns 0 on success, non-0 otherwise.
1568 * Assumes vcpu_load() was already called. 1518 * Assumes vcpu_load() was already called.
1569 */ 1519 */
1570static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata) 1520int kvm_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
1571{ 1521{
1572 return kvm_arch_ops->get_msr(vcpu, msr_index, pdata); 1522 return kvm_arch_ops->get_msr(vcpu, msr_index, pdata);
1573} 1523}
@@ -1645,7 +1595,7 @@ EXPORT_SYMBOL_GPL(kvm_set_msr_common);
1645 * Returns 0 on success, non-0 otherwise. 1595 * Returns 0 on success, non-0 otherwise.
1646 * Assumes vcpu_load() was already called. 1596 * Assumes vcpu_load() was already called.
1647 */ 1597 */
1648static int set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data) 1598int kvm_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
1649{ 1599{
1650 return kvm_arch_ops->set_msr(vcpu, msr_index, data); 1600 return kvm_arch_ops->set_msr(vcpu, msr_index, data);
1651} 1601}
@@ -2183,7 +2133,7 @@ static __init void kvm_init_msr_list(void)
2183 */ 2133 */
2184static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data) 2134static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
2185{ 2135{
2186 return set_msr(vcpu, index, *data); 2136 return kvm_set_msr(vcpu, index, *data);
2187} 2137}
2188 2138
2189/* 2139/*
@@ -2667,7 +2617,7 @@ static long kvm_vcpu_ioctl(struct file *filp,
2667 break; 2617 break;
2668 } 2618 }
2669 case KVM_GET_MSRS: 2619 case KVM_GET_MSRS:
2670 r = msr_io(vcpu, argp, get_msr, 1); 2620 r = msr_io(vcpu, argp, kvm_get_msr, 1);
2671 break; 2621 break;
2672 case KVM_SET_MSRS: 2622 case KVM_SET_MSRS:
2673 r = msr_io(vcpu, argp, do_set_msr, 0); 2623 r = msr_io(vcpu, argp, do_set_msr, 0);
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index 1199d3f32ac3..1a87ba9d5156 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -154,7 +154,6 @@ struct kvm_rmap_desc {
154 154
155static struct kmem_cache *pte_chain_cache; 155static struct kmem_cache *pte_chain_cache;
156static struct kmem_cache *rmap_desc_cache; 156static struct kmem_cache *rmap_desc_cache;
157static struct kmem_cache *mmu_page_cache;
158static struct kmem_cache *mmu_page_header_cache; 157static struct kmem_cache *mmu_page_header_cache;
159 158
160static int is_write_protection(struct kvm_vcpu *vcpu) 159static int is_write_protection(struct kvm_vcpu *vcpu)
@@ -225,6 +224,29 @@ static void mmu_free_memory_cache(struct kvm_mmu_memory_cache *mc)
225 kfree(mc->objects[--mc->nobjs]); 224 kfree(mc->objects[--mc->nobjs]);
226} 225}
227 226
227static int mmu_topup_memory_cache_page(struct kvm_mmu_memory_cache *cache,
228 int min, gfp_t gfp_flags)
229{
230 struct page *page;
231
232 if (cache->nobjs >= min)
233 return 0;
234 while (cache->nobjs < ARRAY_SIZE(cache->objects)) {
235 page = alloc_page(gfp_flags);
236 if (!page)
237 return -ENOMEM;
238 set_page_private(page, 0);
239 cache->objects[cache->nobjs++] = page_address(page);
240 }
241 return 0;
242}
243
244static void mmu_free_memory_cache_page(struct kvm_mmu_memory_cache *mc)
245{
246 while (mc->nobjs)
247 free_page((unsigned long)mc->objects[--mc->nobjs]);
248}
249
228static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags) 250static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags)
229{ 251{
230 int r; 252 int r;
@@ -237,8 +259,7 @@ static int __mmu_topup_memory_caches(struct kvm_vcpu *vcpu, gfp_t gfp_flags)
237 rmap_desc_cache, 1, gfp_flags); 259 rmap_desc_cache, 1, gfp_flags);
238 if (r) 260 if (r)
239 goto out; 261 goto out;
240 r = mmu_topup_memory_cache(&vcpu->mmu_page_cache, 262 r = mmu_topup_memory_cache_page(&vcpu->mmu_page_cache, 4, gfp_flags);
241 mmu_page_cache, 4, gfp_flags);
242 if (r) 263 if (r)
243 goto out; 264 goto out;
244 r = mmu_topup_memory_cache(&vcpu->mmu_page_header_cache, 265 r = mmu_topup_memory_cache(&vcpu->mmu_page_header_cache,
@@ -266,7 +287,7 @@ static void mmu_free_memory_caches(struct kvm_vcpu *vcpu)
266{ 287{
267 mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache); 288 mmu_free_memory_cache(&vcpu->mmu_pte_chain_cache);
268 mmu_free_memory_cache(&vcpu->mmu_rmap_desc_cache); 289 mmu_free_memory_cache(&vcpu->mmu_rmap_desc_cache);
269 mmu_free_memory_cache(&vcpu->mmu_page_cache); 290 mmu_free_memory_cache_page(&vcpu->mmu_page_cache);
270 mmu_free_memory_cache(&vcpu->mmu_page_header_cache); 291 mmu_free_memory_cache(&vcpu->mmu_page_header_cache);
271} 292}
272 293
@@ -281,24 +302,15 @@ static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc,
281 return p; 302 return p;
282} 303}
283 304
284static void mmu_memory_cache_free(struct kvm_mmu_memory_cache *mc, void *obj)
285{
286 if (mc->nobjs < KVM_NR_MEM_OBJS)
287 mc->objects[mc->nobjs++] = obj;
288 else
289 kfree(obj);
290}
291
292static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu) 305static struct kvm_pte_chain *mmu_alloc_pte_chain(struct kvm_vcpu *vcpu)
293{ 306{
294 return mmu_memory_cache_alloc(&vcpu->mmu_pte_chain_cache, 307 return mmu_memory_cache_alloc(&vcpu->mmu_pte_chain_cache,
295 sizeof(struct kvm_pte_chain)); 308 sizeof(struct kvm_pte_chain));
296} 309}
297 310
298static void mmu_free_pte_chain(struct kvm_vcpu *vcpu, 311static void mmu_free_pte_chain(struct kvm_pte_chain *pc)
299 struct kvm_pte_chain *pc)
300{ 312{
301 mmu_memory_cache_free(&vcpu->mmu_pte_chain_cache, pc); 313 kfree(pc);
302} 314}
303 315
304static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu) 316static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu)
@@ -307,10 +319,9 @@ static struct kvm_rmap_desc *mmu_alloc_rmap_desc(struct kvm_vcpu *vcpu)
307 sizeof(struct kvm_rmap_desc)); 319 sizeof(struct kvm_rmap_desc));
308} 320}
309 321
310static void mmu_free_rmap_desc(struct kvm_vcpu *vcpu, 322static void mmu_free_rmap_desc(struct kvm_rmap_desc *rd)
311 struct kvm_rmap_desc *rd)
312{ 323{
313 mmu_memory_cache_free(&vcpu->mmu_rmap_desc_cache, rd); 324 kfree(rd);
314} 325}
315 326
316/* 327/*
@@ -355,8 +366,7 @@ static void rmap_add(struct kvm_vcpu *vcpu, u64 *spte)
355 } 366 }
356} 367}
357 368
358static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu, 369static void rmap_desc_remove_entry(struct page *page,
359 struct page *page,
360 struct kvm_rmap_desc *desc, 370 struct kvm_rmap_desc *desc,
361 int i, 371 int i,
362 struct kvm_rmap_desc *prev_desc) 372 struct kvm_rmap_desc *prev_desc)
@@ -376,10 +386,10 @@ static void rmap_desc_remove_entry(struct kvm_vcpu *vcpu,
376 prev_desc->more = desc->more; 386 prev_desc->more = desc->more;
377 else 387 else
378 set_page_private(page,(unsigned long)desc->more | 1); 388 set_page_private(page,(unsigned long)desc->more | 1);
379 mmu_free_rmap_desc(vcpu, desc); 389 mmu_free_rmap_desc(desc);
380} 390}
381 391
382static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte) 392static void rmap_remove(u64 *spte)
383{ 393{
384 struct page *page; 394 struct page *page;
385 struct kvm_rmap_desc *desc; 395 struct kvm_rmap_desc *desc;
@@ -407,7 +417,7 @@ static void rmap_remove(struct kvm_vcpu *vcpu, u64 *spte)
407 while (desc) { 417 while (desc) {
408 for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i) 418 for (i = 0; i < RMAP_EXT && desc->shadow_ptes[i]; ++i)
409 if (desc->shadow_ptes[i] == spte) { 419 if (desc->shadow_ptes[i] == spte) {
410 rmap_desc_remove_entry(vcpu, page, 420 rmap_desc_remove_entry(page,
411 desc, i, 421 desc, i,
412 prev_desc); 422 prev_desc);
413 return; 423 return;
@@ -442,7 +452,7 @@ static void rmap_write_protect(struct kvm_vcpu *vcpu, u64 gfn)
442 BUG_ON(!(*spte & PT_PRESENT_MASK)); 452 BUG_ON(!(*spte & PT_PRESENT_MASK));
443 BUG_ON(!(*spte & PT_WRITABLE_MASK)); 453 BUG_ON(!(*spte & PT_WRITABLE_MASK));
444 rmap_printk("rmap_write_protect: spte %p %llx\n", spte, *spte); 454 rmap_printk("rmap_write_protect: spte %p %llx\n", spte, *spte);
445 rmap_remove(vcpu, spte); 455 rmap_remove(spte);
446 set_shadow_pte(spte, *spte & ~PT_WRITABLE_MASK); 456 set_shadow_pte(spte, *spte & ~PT_WRITABLE_MASK);
447 kvm_flush_remote_tlbs(vcpu->kvm); 457 kvm_flush_remote_tlbs(vcpu->kvm);
448 } 458 }
@@ -464,14 +474,14 @@ static int is_empty_shadow_page(u64 *spt)
464} 474}
465#endif 475#endif
466 476
467static void kvm_mmu_free_page(struct kvm_vcpu *vcpu, 477static void kvm_mmu_free_page(struct kvm *kvm,
468 struct kvm_mmu_page *page_head) 478 struct kvm_mmu_page *page_head)
469{ 479{
470 ASSERT(is_empty_shadow_page(page_head->spt)); 480 ASSERT(is_empty_shadow_page(page_head->spt));
471 list_del(&page_head->link); 481 list_del(&page_head->link);
472 mmu_memory_cache_free(&vcpu->mmu_page_cache, page_head->spt); 482 __free_page(virt_to_page(page_head->spt));
473 mmu_memory_cache_free(&vcpu->mmu_page_header_cache, page_head); 483 kfree(page_head);
474 ++vcpu->kvm->n_free_mmu_pages; 484 ++kvm->n_free_mmu_pages;
475} 485}
476 486
477static unsigned kvm_page_table_hashfn(gfn_t gfn) 487static unsigned kvm_page_table_hashfn(gfn_t gfn)
@@ -537,8 +547,7 @@ static void mmu_page_add_parent_pte(struct kvm_vcpu *vcpu,
537 pte_chain->parent_ptes[0] = parent_pte; 547 pte_chain->parent_ptes[0] = parent_pte;
538} 548}
539 549
540static void mmu_page_remove_parent_pte(struct kvm_vcpu *vcpu, 550static void mmu_page_remove_parent_pte(struct kvm_mmu_page *page,
541 struct kvm_mmu_page *page,
542 u64 *parent_pte) 551 u64 *parent_pte)
543{ 552{
544 struct kvm_pte_chain *pte_chain; 553 struct kvm_pte_chain *pte_chain;
@@ -565,7 +574,7 @@ static void mmu_page_remove_parent_pte(struct kvm_vcpu *vcpu,
565 pte_chain->parent_ptes[i] = NULL; 574 pte_chain->parent_ptes[i] = NULL;
566 if (i == 0) { 575 if (i == 0) {
567 hlist_del(&pte_chain->link); 576 hlist_del(&pte_chain->link);
568 mmu_free_pte_chain(vcpu, pte_chain); 577 mmu_free_pte_chain(pte_chain);
569 if (hlist_empty(&page->parent_ptes)) { 578 if (hlist_empty(&page->parent_ptes)) {
570 page->multimapped = 0; 579 page->multimapped = 0;
571 page->parent_pte = NULL; 580 page->parent_pte = NULL;
@@ -643,7 +652,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
643 return page; 652 return page;
644} 653}
645 654
646static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu, 655static void kvm_mmu_page_unlink_children(struct kvm *kvm,
647 struct kvm_mmu_page *page) 656 struct kvm_mmu_page *page)
648{ 657{
649 unsigned i; 658 unsigned i;
@@ -655,10 +664,10 @@ static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu,
655 if (page->role.level == PT_PAGE_TABLE_LEVEL) { 664 if (page->role.level == PT_PAGE_TABLE_LEVEL) {
656 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) { 665 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) {
657 if (pt[i] & PT_PRESENT_MASK) 666 if (pt[i] & PT_PRESENT_MASK)
658 rmap_remove(vcpu, &pt[i]); 667 rmap_remove(&pt[i]);
659 pt[i] = 0; 668 pt[i] = 0;
660 } 669 }
661 kvm_flush_remote_tlbs(vcpu->kvm); 670 kvm_flush_remote_tlbs(kvm);
662 return; 671 return;
663 } 672 }
664 673
@@ -669,19 +678,18 @@ static void kvm_mmu_page_unlink_children(struct kvm_vcpu *vcpu,
669 if (!(ent & PT_PRESENT_MASK)) 678 if (!(ent & PT_PRESENT_MASK))
670 continue; 679 continue;
671 ent &= PT64_BASE_ADDR_MASK; 680 ent &= PT64_BASE_ADDR_MASK;
672 mmu_page_remove_parent_pte(vcpu, page_header(ent), &pt[i]); 681 mmu_page_remove_parent_pte(page_header(ent), &pt[i]);
673 } 682 }
674 kvm_flush_remote_tlbs(vcpu->kvm); 683 kvm_flush_remote_tlbs(kvm);
675} 684}
676 685
677static void kvm_mmu_put_page(struct kvm_vcpu *vcpu, 686static void kvm_mmu_put_page(struct kvm_mmu_page *page,
678 struct kvm_mmu_page *page,
679 u64 *parent_pte) 687 u64 *parent_pte)
680{ 688{
681 mmu_page_remove_parent_pte(vcpu, page, parent_pte); 689 mmu_page_remove_parent_pte(page, parent_pte);
682} 690}
683 691
684static void kvm_mmu_zap_page(struct kvm_vcpu *vcpu, 692static void kvm_mmu_zap_page(struct kvm *kvm,
685 struct kvm_mmu_page *page) 693 struct kvm_mmu_page *page)
686{ 694{
687 u64 *parent_pte; 695 u64 *parent_pte;
@@ -697,15 +705,15 @@ static void kvm_mmu_zap_page(struct kvm_vcpu *vcpu,
697 parent_pte = chain->parent_ptes[0]; 705 parent_pte = chain->parent_ptes[0];
698 } 706 }
699 BUG_ON(!parent_pte); 707 BUG_ON(!parent_pte);
700 kvm_mmu_put_page(vcpu, page, parent_pte); 708 kvm_mmu_put_page(page, parent_pte);
701 set_shadow_pte(parent_pte, 0); 709 set_shadow_pte(parent_pte, 0);
702 } 710 }
703 kvm_mmu_page_unlink_children(vcpu, page); 711 kvm_mmu_page_unlink_children(kvm, page);
704 if (!page->root_count) { 712 if (!page->root_count) {
705 hlist_del(&page->hash_link); 713 hlist_del(&page->hash_link);
706 kvm_mmu_free_page(vcpu, page); 714 kvm_mmu_free_page(kvm, page);
707 } else 715 } else
708 list_move(&page->link, &vcpu->kvm->active_mmu_pages); 716 list_move(&page->link, &kvm->active_mmu_pages);
709} 717}
710 718
711static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn) 719static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn)
@@ -724,7 +732,7 @@ static int kvm_mmu_unprotect_page(struct kvm_vcpu *vcpu, gfn_t gfn)
724 if (page->gfn == gfn && !page->role.metaphysical) { 732 if (page->gfn == gfn && !page->role.metaphysical) {
725 pgprintk("%s: gfn %lx role %x\n", __FUNCTION__, gfn, 733 pgprintk("%s: gfn %lx role %x\n", __FUNCTION__, gfn,
726 page->role.word); 734 page->role.word);
727 kvm_mmu_zap_page(vcpu, page); 735 kvm_mmu_zap_page(vcpu->kvm, page);
728 r = 1; 736 r = 1;
729 } 737 }
730 return r; 738 return r;
@@ -737,7 +745,7 @@ static void mmu_unshadow(struct kvm_vcpu *vcpu, gfn_t gfn)
737 while ((page = kvm_mmu_lookup_page(vcpu, gfn)) != NULL) { 745 while ((page = kvm_mmu_lookup_page(vcpu, gfn)) != NULL) {
738 pgprintk("%s: zap %lx %x\n", 746 pgprintk("%s: zap %lx %x\n",
739 __FUNCTION__, gfn, page->role.word); 747 __FUNCTION__, gfn, page->role.word);
740 kvm_mmu_zap_page(vcpu, page); 748 kvm_mmu_zap_page(vcpu->kvm, page);
741 } 749 }
742} 750}
743 751
@@ -1089,10 +1097,10 @@ static void mmu_pte_write_zap_pte(struct kvm_vcpu *vcpu,
1089 pte = *spte; 1097 pte = *spte;
1090 if (is_present_pte(pte)) { 1098 if (is_present_pte(pte)) {
1091 if (page->role.level == PT_PAGE_TABLE_LEVEL) 1099 if (page->role.level == PT_PAGE_TABLE_LEVEL)
1092 rmap_remove(vcpu, spte); 1100 rmap_remove(spte);
1093 else { 1101 else {
1094 child = page_header(pte & PT64_BASE_ADDR_MASK); 1102 child = page_header(pte & PT64_BASE_ADDR_MASK);
1095 mmu_page_remove_parent_pte(vcpu, child, spte); 1103 mmu_page_remove_parent_pte(child, spte);
1096 } 1104 }
1097 } 1105 }
1098 *spte = 0; 1106 *spte = 0;
@@ -1161,7 +1169,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
1161 */ 1169 */
1162 pgprintk("misaligned: gpa %llx bytes %d role %x\n", 1170 pgprintk("misaligned: gpa %llx bytes %d role %x\n",
1163 gpa, bytes, page->role.word); 1171 gpa, bytes, page->role.word);
1164 kvm_mmu_zap_page(vcpu, page); 1172 kvm_mmu_zap_page(vcpu->kvm, page);
1165 continue; 1173 continue;
1166 } 1174 }
1167 page_offset = offset; 1175 page_offset = offset;
@@ -1207,7 +1215,7 @@ void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu)
1207 1215
1208 page = container_of(vcpu->kvm->active_mmu_pages.prev, 1216 page = container_of(vcpu->kvm->active_mmu_pages.prev,
1209 struct kvm_mmu_page, link); 1217 struct kvm_mmu_page, link);
1210 kvm_mmu_zap_page(vcpu, page); 1218 kvm_mmu_zap_page(vcpu->kvm, page);
1211 } 1219 }
1212} 1220}
1213EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages); 1221EXPORT_SYMBOL_GPL(kvm_mmu_free_some_pages);
@@ -1219,7 +1227,7 @@ static void free_mmu_pages(struct kvm_vcpu *vcpu)
1219 while (!list_empty(&vcpu->kvm->active_mmu_pages)) { 1227 while (!list_empty(&vcpu->kvm->active_mmu_pages)) {
1220 page = container_of(vcpu->kvm->active_mmu_pages.next, 1228 page = container_of(vcpu->kvm->active_mmu_pages.next,
1221 struct kvm_mmu_page, link); 1229 struct kvm_mmu_page, link);
1222 kvm_mmu_zap_page(vcpu, page); 1230 kvm_mmu_zap_page(vcpu->kvm, page);
1223 } 1231 }
1224 free_page((unsigned long)vcpu->mmu.pae_root); 1232 free_page((unsigned long)vcpu->mmu.pae_root);
1225} 1233}
@@ -1277,9 +1285,8 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
1277 mmu_free_memory_caches(vcpu); 1285 mmu_free_memory_caches(vcpu);
1278} 1286}
1279 1287
1280void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot) 1288void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
1281{ 1289{
1282 struct kvm *kvm = vcpu->kvm;
1283 struct kvm_mmu_page *page; 1290 struct kvm_mmu_page *page;
1284 1291
1285 list_for_each_entry(page, &kvm->active_mmu_pages, link) { 1292 list_for_each_entry(page, &kvm->active_mmu_pages, link) {
@@ -1293,27 +1300,20 @@ void kvm_mmu_slot_remove_write_access(struct kvm_vcpu *vcpu, int slot)
1293 for (i = 0; i < PT64_ENT_PER_PAGE; ++i) 1300 for (i = 0; i < PT64_ENT_PER_PAGE; ++i)
1294 /* avoid RMW */ 1301 /* avoid RMW */
1295 if (pt[i] & PT_WRITABLE_MASK) { 1302 if (pt[i] & PT_WRITABLE_MASK) {
1296 rmap_remove(vcpu, &pt[i]); 1303 rmap_remove(&pt[i]);
1297 pt[i] &= ~PT_WRITABLE_MASK; 1304 pt[i] &= ~PT_WRITABLE_MASK;
1298 } 1305 }
1299 } 1306 }
1300} 1307}
1301 1308
1302void kvm_mmu_zap_all(struct kvm_vcpu *vcpu) 1309void kvm_mmu_zap_all(struct kvm *kvm)
1303{ 1310{
1304 destroy_kvm_mmu(vcpu); 1311 struct kvm_mmu_page *page, *node;
1305
1306 while (!list_empty(&vcpu->kvm->active_mmu_pages)) {
1307 struct kvm_mmu_page *page;
1308 1312
1309 page = container_of(vcpu->kvm->active_mmu_pages.next, 1313 list_for_each_entry_safe(page, node, &kvm->active_mmu_pages, link)
1310 struct kvm_mmu_page, link); 1314 kvm_mmu_zap_page(kvm, page);
1311 kvm_mmu_zap_page(vcpu, page);
1312 }
1313 1315
1314 mmu_free_memory_caches(vcpu); 1316 kvm_flush_remote_tlbs(kvm);
1315 kvm_flush_remote_tlbs(vcpu->kvm);
1316 init_kvm_mmu(vcpu);
1317} 1317}
1318 1318
1319void kvm_mmu_module_exit(void) 1319void kvm_mmu_module_exit(void)
@@ -1322,8 +1322,6 @@ void kvm_mmu_module_exit(void)
1322 kmem_cache_destroy(pte_chain_cache); 1322 kmem_cache_destroy(pte_chain_cache);
1323 if (rmap_desc_cache) 1323 if (rmap_desc_cache)
1324 kmem_cache_destroy(rmap_desc_cache); 1324 kmem_cache_destroy(rmap_desc_cache);
1325 if (mmu_page_cache)
1326 kmem_cache_destroy(mmu_page_cache);
1327 if (mmu_page_header_cache) 1325 if (mmu_page_header_cache)
1328 kmem_cache_destroy(mmu_page_header_cache); 1326 kmem_cache_destroy(mmu_page_header_cache);
1329} 1327}
@@ -1341,12 +1339,6 @@ int kvm_mmu_module_init(void)
1341 if (!rmap_desc_cache) 1339 if (!rmap_desc_cache)
1342 goto nomem; 1340 goto nomem;
1343 1341
1344 mmu_page_cache = kmem_cache_create("kvm_mmu_page",
1345 PAGE_SIZE,
1346 PAGE_SIZE, 0, NULL);
1347 if (!mmu_page_cache)
1348 goto nomem;
1349
1350 mmu_page_header_cache = kmem_cache_create("kvm_mmu_page_header", 1342 mmu_page_header_cache = kmem_cache_create("kvm_mmu_page_header",
1351 sizeof(struct kvm_mmu_page), 1343 sizeof(struct kvm_mmu_page),
1352 0, 0, NULL); 1344 0, 0, NULL);
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index a7c5cb0319ea..4b5391c717f8 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -366,6 +366,8 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
366 metaphysical = 1; 366 metaphysical = 1;
367 hugepage_access = *guest_ent; 367 hugepage_access = *guest_ent;
368 hugepage_access &= PT_USER_MASK | PT_WRITABLE_MASK; 368 hugepage_access &= PT_USER_MASK | PT_WRITABLE_MASK;
369 if (*guest_ent & PT64_NX_MASK)
370 hugepage_access |= (1 << 2);
369 hugepage_access >>= PT_WRITABLE_SHIFT; 371 hugepage_access >>= PT_WRITABLE_SHIFT;
370 table_gfn = (*guest_ent & PT_BASE_ADDR_MASK) 372 table_gfn = (*guest_ent & PT_BASE_ADDR_MASK)
371 >> PAGE_SHIFT; 373 >> PAGE_SHIFT;
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
index f60012d62610..1b800fc00342 100644
--- a/drivers/kvm/x86_emulate.c
+++ b/drivers/kvm/x86_emulate.c
@@ -163,7 +163,7 @@ static u16 twobyte_table[256] = {
163 ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0, 163 ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0,
164 0, 0, 0, 0, 0, 0, 0, 0, 164 0, 0, 0, 0, 0, 0, 0, 0,
165 /* 0x30 - 0x3F */ 165 /* 0x30 - 0x3F */
166 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 166 ImplicitOps, 0, ImplicitOps, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
167 /* 0x40 - 0x47 */ 167 /* 0x40 - 0x47 */
168 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, 168 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
169 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov, 169 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
@@ -486,6 +486,7 @@ x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
486 unsigned long modrm_ea; 486 unsigned long modrm_ea;
487 int use_modrm_ea, index_reg = 0, base_reg = 0, scale, rip_relative = 0; 487 int use_modrm_ea, index_reg = 0, base_reg = 0, scale, rip_relative = 0;
488 int no_wb = 0; 488 int no_wb = 0;
489 u64 msr_data;
489 490
490 /* Shadow copy of register state. Committed on successful emulation. */ 491 /* Shadow copy of register state. Committed on successful emulation. */
491 unsigned long _regs[NR_VCPU_REGS]; 492 unsigned long _regs[NR_VCPU_REGS];
@@ -1344,6 +1345,29 @@ twobyte_special_insn:
1344 goto cannot_emulate; 1345 goto cannot_emulate;
1345 realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags); 1346 realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags);
1346 break; 1347 break;
1348 case 0x30:
1349 /* wrmsr */
1350 msr_data = (u32)_regs[VCPU_REGS_RAX]
1351 | ((u64)_regs[VCPU_REGS_RDX] << 32);
1352 rc = kvm_set_msr(ctxt->vcpu, _regs[VCPU_REGS_RCX], msr_data);
1353 if (rc) {
1354 kvm_arch_ops->inject_gp(ctxt->vcpu, 0);
1355 _eip = ctxt->vcpu->rip;
1356 }
1357 rc = X86EMUL_CONTINUE;
1358 break;
1359 case 0x32:
1360 /* rdmsr */
1361 rc = kvm_get_msr(ctxt->vcpu, _regs[VCPU_REGS_RCX], &msr_data);
1362 if (rc) {
1363 kvm_arch_ops->inject_gp(ctxt->vcpu, 0);
1364 _eip = ctxt->vcpu->rip;
1365 } else {
1366 _regs[VCPU_REGS_RAX] = (u32)msr_data;
1367 _regs[VCPU_REGS_RDX] = msr_data >> 32;
1368 }
1369 rc = X86EMUL_CONTINUE;
1370 break;
1347 case 0xc7: /* Grp9 (cmpxchg8b) */ 1371 case 0xc7: /* Grp9 (cmpxchg8b) */
1348 { 1372 {
1349 u64 old, new; 1373 u64 old, new;
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 87d2046f866c..4468cb3a8d24 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -1,9 +1,6 @@
1 1menuconfig NEW_LEDS
2menu "LED devices"
3 depends on HAS_IOMEM
4
5config NEW_LEDS
6 bool "LED Support" 2 bool "LED Support"
3 depends on HAS_IOMEM
7 help 4 help
8 Say Y to enable Linux LED support. This allows control of supported 5 Say Y to enable Linux LED support. This allows control of supported
9 LEDs from both userspace and optionally, by kernel events (triggers). 6 LEDs from both userspace and optionally, by kernel events (triggers).
@@ -11,9 +8,10 @@ config NEW_LEDS
11 This is not related to standard keyboard LEDs which are controlled 8 This is not related to standard keyboard LEDs which are controlled
12 via the input system. 9 via the input system.
13 10
11if NEW_LEDS
12
14config LEDS_CLASS 13config LEDS_CLASS
15 tristate "LED Class Support" 14 tristate "LED Class Support"
16 depends on NEW_LEDS
17 help 15 help
18 This option enables the led sysfs class in /sys/class/leds. You'll 16 This option enables the led sysfs class in /sys/class/leds. You'll
19 need this to do anything useful with LEDs. If unsure, say N. 17 need this to do anything useful with LEDs. If unsure, say N.
@@ -95,11 +93,18 @@ config LEDS_COBALT
95 help 93 help
96 This option enables support for the front LED on Cobalt Server 94 This option enables support for the front LED on Cobalt Server
97 95
96config LEDS_GPIO
97 tristate "LED Support for GPIO connected LEDs"
98 depends on LEDS_CLASS && GENERIC_GPIO
99 help
100 This option enables support for the LEDs connected to GPIO
101 outputs. To be useful the particular board must have LEDs
102 and they must be connected to the GPIO lines.
103
98comment "LED Triggers" 104comment "LED Triggers"
99 105
100config LEDS_TRIGGERS 106config LEDS_TRIGGERS
101 bool "LED Trigger support" 107 bool "LED Trigger support"
102 depends on NEW_LEDS
103 help 108 help
104 This option enables trigger support for the leds class. 109 This option enables trigger support for the leds class.
105 These triggers allow kernel events to drive the LEDs and can 110 These triggers allow kernel events to drive the LEDs and can
@@ -128,5 +133,4 @@ config LEDS_TRIGGER_HEARTBEAT
128 load average. 133 load average.
129 If unsure, say Y. 134 If unsure, say Y.
130 135
131endmenu 136endif # NEW_LEDS
132
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index aa2c18efa5b2..f8995c9bc2ea 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
16obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o 16obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
17obj-$(CONFIG_LEDS_H1940) += leds-h1940.o 17obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
18obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o 18obj-$(CONFIG_LEDS_COBALT) += leds-cobalt.o
19obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
19 20
20# LED Triggers 21# LED Triggers
21obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 22obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 3c1711210e38..4211293ce862 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -2,7 +2,7 @@
2 * LED Class Core 2 * LED Class Core
3 * 3 *
4 * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu> 4 * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
5 * Copyright (C) 2005-2006 Richard Purdie <rpurdie@openedhand.com> 5 * Copyright (C) 2005-2007 Richard Purdie <rpurdie@openedhand.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -24,9 +24,10 @@
24 24
25static struct class *leds_class; 25static struct class *leds_class;
26 26
27static ssize_t led_brightness_show(struct class_device *dev, char *buf) 27static ssize_t led_brightness_show(struct device *dev,
28 struct device_attribute *attr, char *buf)
28{ 29{
29 struct led_classdev *led_cdev = class_get_devdata(dev); 30 struct led_classdev *led_cdev = dev_get_drvdata(dev);
30 ssize_t ret = 0; 31 ssize_t ret = 0;
31 32
32 /* no lock needed for this */ 33 /* no lock needed for this */
@@ -36,10 +37,10 @@ static ssize_t led_brightness_show(struct class_device *dev, char *buf)
36 return ret; 37 return ret;
37} 38}
38 39
39static ssize_t led_brightness_store(struct class_device *dev, 40static ssize_t led_brightness_store(struct device *dev,
40 const char *buf, size_t size) 41 struct device_attribute *attr, const char *buf, size_t size)
41{ 42{
42 struct led_classdev *led_cdev = class_get_devdata(dev); 43 struct led_classdev *led_cdev = dev_get_drvdata(dev);
43 ssize_t ret = -EINVAL; 44 ssize_t ret = -EINVAL;
44 char *after; 45 char *after;
45 unsigned long state = simple_strtoul(buf, &after, 10); 46 unsigned long state = simple_strtoul(buf, &after, 10);
@@ -56,10 +57,9 @@ static ssize_t led_brightness_store(struct class_device *dev,
56 return ret; 57 return ret;
57} 58}
58 59
59static CLASS_DEVICE_ATTR(brightness, 0644, led_brightness_show, 60static DEVICE_ATTR(brightness, 0644, led_brightness_show, led_brightness_store);
60 led_brightness_store);
61#ifdef CONFIG_LEDS_TRIGGERS 61#ifdef CONFIG_LEDS_TRIGGERS
62static CLASS_DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); 62static DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store);
63#endif 63#endif
64 64
65/** 65/**
@@ -93,16 +93,15 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
93{ 93{
94 int rc; 94 int rc;
95 95
96 led_cdev->class_dev = class_device_create(leds_class, NULL, 0, 96 led_cdev->dev = device_create(leds_class, parent, 0, "%s",
97 parent, "%s", led_cdev->name); 97 led_cdev->name);
98 if (unlikely(IS_ERR(led_cdev->class_dev))) 98 if (unlikely(IS_ERR(led_cdev->dev)))
99 return PTR_ERR(led_cdev->class_dev); 99 return PTR_ERR(led_cdev->dev);
100 100
101 class_set_devdata(led_cdev->class_dev, led_cdev); 101 dev_set_drvdata(led_cdev->dev, led_cdev);
102 102
103 /* register the attributes */ 103 /* register the attributes */
104 rc = class_device_create_file(led_cdev->class_dev, 104 rc = device_create_file(led_cdev->dev, &dev_attr_brightness);
105 &class_device_attr_brightness);
106 if (rc) 105 if (rc)
107 goto err_out; 106 goto err_out;
108 107
@@ -114,8 +113,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
114#ifdef CONFIG_LEDS_TRIGGERS 113#ifdef CONFIG_LEDS_TRIGGERS
115 rwlock_init(&led_cdev->trigger_lock); 114 rwlock_init(&led_cdev->trigger_lock);
116 115
117 rc = class_device_create_file(led_cdev->class_dev, 116 rc = device_create_file(led_cdev->dev, &dev_attr_trigger);
118 &class_device_attr_trigger);
119 if (rc) 117 if (rc)
120 goto err_out_led_list; 118 goto err_out_led_list;
121 119
@@ -123,18 +121,17 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
123#endif 121#endif
124 122
125 printk(KERN_INFO "Registered led device: %s\n", 123 printk(KERN_INFO "Registered led device: %s\n",
126 led_cdev->class_dev->class_id); 124 led_cdev->name);
127 125
128 return 0; 126 return 0;
129 127
130#ifdef CONFIG_LEDS_TRIGGERS 128#ifdef CONFIG_LEDS_TRIGGERS
131err_out_led_list: 129err_out_led_list:
132 class_device_remove_file(led_cdev->class_dev, 130 device_remove_file(led_cdev->dev, &dev_attr_brightness);
133 &class_device_attr_brightness);
134 list_del(&led_cdev->node); 131 list_del(&led_cdev->node);
135#endif 132#endif
136err_out: 133err_out:
137 class_device_unregister(led_cdev->class_dev); 134 device_unregister(led_cdev->dev);
138 return rc; 135 return rc;
139} 136}
140EXPORT_SYMBOL_GPL(led_classdev_register); 137EXPORT_SYMBOL_GPL(led_classdev_register);
@@ -147,18 +144,16 @@ EXPORT_SYMBOL_GPL(led_classdev_register);
147 */ 144 */
148void led_classdev_unregister(struct led_classdev *led_cdev) 145void led_classdev_unregister(struct led_classdev *led_cdev)
149{ 146{
150 class_device_remove_file(led_cdev->class_dev, 147 device_remove_file(led_cdev->dev, &dev_attr_brightness);
151 &class_device_attr_brightness);
152#ifdef CONFIG_LEDS_TRIGGERS 148#ifdef CONFIG_LEDS_TRIGGERS
153 class_device_remove_file(led_cdev->class_dev, 149 device_remove_file(led_cdev->dev, &dev_attr_trigger);
154 &class_device_attr_trigger);
155 write_lock(&led_cdev->trigger_lock); 150 write_lock(&led_cdev->trigger_lock);
156 if (led_cdev->trigger) 151 if (led_cdev->trigger)
157 led_trigger_set(led_cdev, NULL); 152 led_trigger_set(led_cdev, NULL);
158 write_unlock(&led_cdev->trigger_lock); 153 write_unlock(&led_cdev->trigger_lock);
159#endif 154#endif
160 155
161 class_device_unregister(led_cdev->class_dev); 156 device_unregister(led_cdev->dev);
162 157
163 write_lock(&leds_list_lock); 158 write_lock(&leds_list_lock);
164 list_del(&led_cdev->node); 159 list_del(&led_cdev->node);
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 454fb0901f82..575368c2b100 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * LED Triggers Core 2 * LED Triggers Core
3 * 3 *
4 * Copyright 2005-2006 Openedhand Ltd. 4 * Copyright 2005-2007 Openedhand Ltd.
5 * 5 *
6 * Author: Richard Purdie <rpurdie@openedhand.com> 6 * Author: Richard Purdie <rpurdie@openedhand.com>
7 * 7 *
@@ -28,10 +28,10 @@
28static DEFINE_RWLOCK(triggers_list_lock); 28static DEFINE_RWLOCK(triggers_list_lock);
29static LIST_HEAD(trigger_list); 29static LIST_HEAD(trigger_list);
30 30
31ssize_t led_trigger_store(struct class_device *dev, const char *buf, 31ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
32 size_t count) 32 const char *buf, size_t count)
33{ 33{
34 struct led_classdev *led_cdev = class_get_devdata(dev); 34 struct led_classdev *led_cdev = dev_get_drvdata(dev);
35 char trigger_name[TRIG_NAME_MAX]; 35 char trigger_name[TRIG_NAME_MAX];
36 struct led_trigger *trig; 36 struct led_trigger *trig;
37 size_t len; 37 size_t len;
@@ -67,9 +67,10 @@ ssize_t led_trigger_store(struct class_device *dev, const char *buf,
67} 67}
68 68
69 69
70ssize_t led_trigger_show(struct class_device *dev, char *buf) 70ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
71 char *buf)
71{ 72{
72 struct led_classdev *led_cdev = class_get_devdata(dev); 73 struct led_classdev *led_cdev = dev_get_drvdata(dev);
73 struct led_trigger *trig; 74 struct led_trigger *trig;
74 int len = 0; 75 int len = 0;
75 76
@@ -183,13 +184,20 @@ int led_trigger_register(struct led_trigger *trigger)
183void led_trigger_register_simple(const char *name, struct led_trigger **tp) 184void led_trigger_register_simple(const char *name, struct led_trigger **tp)
184{ 185{
185 struct led_trigger *trigger; 186 struct led_trigger *trigger;
187 int err;
186 188
187 trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL); 189 trigger = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
188 190
189 if (trigger) { 191 if (trigger) {
190 trigger->name = name; 192 trigger->name = name;
191 led_trigger_register(trigger); 193 err = led_trigger_register(trigger);
192 } 194 if (err < 0)
195 printk(KERN_WARNING "LED trigger %s failed to register"
196 " (%d)\n", name, err);
197 } else
198 printk(KERN_WARNING "LED trigger %s failed to register"
199 " (no memory)\n", name);
200
193 *tp = trigger; 201 *tp = trigger;
194} 202}
195 203
@@ -215,7 +223,8 @@ void led_trigger_unregister(struct led_trigger *trigger)
215 223
216void led_trigger_unregister_simple(struct led_trigger *trigger) 224void led_trigger_unregister_simple(struct led_trigger *trigger)
217{ 225{
218 led_trigger_unregister(trigger); 226 if (trigger)
227 led_trigger_unregister(trigger);
219 kfree(trigger); 228 kfree(trigger);
220} 229}
221 230
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
new file mode 100644
index 000000000000..47d90db280ce
--- /dev/null
+++ b/drivers/leds/leds-gpio.c
@@ -0,0 +1,199 @@
1/*
2 * LEDs driver for GPIOs
3 *
4 * Copyright (C) 2007 8D Technologies inc.
5 * Raphael Assenat <raph@8d.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/leds.h>
16#include <linux/workqueue.h>
17
18#include <asm/gpio.h>
19
20struct gpio_led_data {
21 struct led_classdev cdev;
22 unsigned gpio;
23 struct work_struct work;
24 u8 new_level;
25 u8 can_sleep;
26 u8 active_low;
27};
28
29static void gpio_led_work(struct work_struct *work)
30{
31 struct gpio_led_data *led_dat =
32 container_of(work, struct gpio_led_data, work);
33
34 gpio_set_value_cansleep(led_dat->gpio, led_dat->new_level);
35}
36
37static void gpio_led_set(struct led_classdev *led_cdev,
38 enum led_brightness value)
39{
40 struct gpio_led_data *led_dat =
41 container_of(led_cdev, struct gpio_led_data, cdev);
42 int level;
43
44 if (value == LED_OFF)
45 level = 0;
46 else
47 level = 1;
48
49 if (led_dat->active_low)
50 level = !level;
51
52 /* setting GPIOs with I2C/etc requires a preemptible task context */
53 if (led_dat->can_sleep) {
54 if (preempt_count()) {
55 led_dat->new_level = level;
56 schedule_work(&led_dat->work);
57 } else
58 gpio_set_value_cansleep(led_dat->gpio, level);
59 } else
60 gpio_set_value(led_dat->gpio, level);
61}
62
63static int __init gpio_led_probe(struct platform_device *pdev)
64{
65 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
66 struct gpio_led *cur_led;
67 struct gpio_led_data *leds_data, *led_dat;
68 int i, ret = 0;
69
70 if (!pdata)
71 return -EBUSY;
72
73 leds_data = kzalloc(sizeof(struct gpio_led_data) * pdata->num_leds,
74 GFP_KERNEL);
75 if (!leds_data)
76 return -ENOMEM;
77
78 for (i = 0; i < pdata->num_leds; i++) {
79 cur_led = &pdata->leds[i];
80 led_dat = &leds_data[i];
81
82 led_dat->cdev.name = cur_led->name;
83 led_dat->cdev.default_trigger = cur_led->default_trigger;
84 led_dat->gpio = cur_led->gpio;
85 led_dat->can_sleep = gpio_cansleep(cur_led->gpio);
86 led_dat->active_low = cur_led->active_low;
87 led_dat->cdev.brightness_set = gpio_led_set;
88 led_dat->cdev.brightness = cur_led->active_low ? LED_FULL : LED_OFF;
89
90 ret = gpio_request(led_dat->gpio, led_dat->cdev.name);
91 if (ret < 0)
92 goto err;
93
94 gpio_direction_output(led_dat->gpio, led_dat->active_low);
95
96 ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
97 if (ret < 0) {
98 gpio_free(led_dat->gpio);
99 goto err;
100 }
101
102 INIT_WORK(&led_dat->work, gpio_led_work);
103 }
104
105 platform_set_drvdata(pdev, leds_data);
106
107 return 0;
108
109err:
110 if (i > 0) {
111 for (i = i - 1; i >= 0; i--) {
112 led_classdev_unregister(&leds_data[i].cdev);
113 gpio_free(leds_data[i].gpio);
114 }
115 }
116
117 flush_scheduled_work();
118 kfree(leds_data);
119
120 return ret;
121}
122
123static int __exit gpio_led_remove(struct platform_device *pdev)
124{
125 int i;
126 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
127 struct gpio_led_data *leds_data;
128
129 leds_data = platform_get_drvdata(pdev);
130
131 for (i = 0; i < pdata->num_leds; i++) {
132 led_classdev_unregister(&leds_data[i].cdev);
133 gpio_free(leds_data[i].gpio);
134 }
135
136 kfree(leds_data);
137
138 return 0;
139}
140
141#ifdef CONFIG_PM
142static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
143{
144 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
145 struct gpio_led_data *leds_data;
146 int i;
147
148 leds_data = platform_get_drvdata(pdev);
149
150 for (i = 0; i < pdata->num_leds; i++)
151 led_classdev_suspend(&leds_data[i].cdev);
152
153 return 0;
154}
155
156static int gpio_led_resume(struct platform_device *pdev)
157{
158 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
159 struct gpio_led_data *leds_data;
160 int i;
161
162 leds_data = platform_get_drvdata(pdev);
163
164 for (i = 0; i < pdata->num_leds; i++)
165 led_classdev_resume(&leds_data[i].cdev);
166
167 return 0;
168}
169#else
170#define gpio_led_suspend NULL
171#define gpio_led_resume NULL
172#endif
173
174static struct platform_driver gpio_led_driver = {
175 .remove = __exit_p(gpio_led_remove),
176 .suspend = gpio_led_suspend,
177 .resume = gpio_led_resume,
178 .driver = {
179 .name = "leds-gpio",
180 .owner = THIS_MODULE,
181 },
182};
183
184static int __init gpio_led_init(void)
185{
186 return platform_driver_probe(&gpio_led_driver, gpio_led_probe);
187}
188
189static void __exit gpio_led_exit(void)
190{
191 platform_driver_unregister(&gpio_led_driver);
192}
193
194module_init(gpio_led_init);
195module_exit(gpio_led_exit);
196
197MODULE_AUTHOR("Raphael Assenat <raph@8d.com>");
198MODULE_DESCRIPTION("GPIO LED driver");
199MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-locomo.c b/drivers/leds/leds-locomo.c
index 6f2d449ba983..bfac499f3258 100644
--- a/drivers/leds/leds-locomo.c
+++ b/drivers/leds/leds-locomo.c
@@ -19,7 +19,7 @@
19static void locomoled_brightness_set(struct led_classdev *led_cdev, 19static void locomoled_brightness_set(struct led_classdev *led_cdev,
20 enum led_brightness value, int offset) 20 enum led_brightness value, int offset)
21{ 21{
22 struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->class_dev->dev); 22 struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->dev);
23 unsigned long flags; 23 unsigned long flags;
24 24
25 local_irq_save(flags); 25 local_irq_save(flags);
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h
index a715c4ed93ff..f2f3884fe063 100644
--- a/drivers/leds/leds.h
+++ b/drivers/leds/leds.h
@@ -13,6 +13,7 @@
13#ifndef __LEDS_H_INCLUDED 13#ifndef __LEDS_H_INCLUDED
14#define __LEDS_H_INCLUDED 14#define __LEDS_H_INCLUDED
15 15
16#include <linux/device.h>
16#include <linux/leds.h> 17#include <linux/leds.h>
17 18
18static inline void led_set_brightness(struct led_classdev *led_cdev, 19static inline void led_set_brightness(struct led_classdev *led_cdev,
@@ -37,8 +38,9 @@ void led_trigger_set(struct led_classdev *led_cdev,
37#define led_trigger_set(x, y) do {} while(0) 38#define led_trigger_set(x, y) do {} while(0)
38#endif 39#endif
39 40
40ssize_t led_trigger_store(struct class_device *dev, const char *buf, 41ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
41 size_t count); 42 const char *buf, size_t count);
42ssize_t led_trigger_show(struct class_device *dev, char *buf); 43ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
44 char *buf);
43 45
44#endif /* __LEDS_H_INCLUDED */ 46#endif /* __LEDS_H_INCLUDED */
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index d756bdb01c59..ed9ff02c77ea 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -52,9 +52,10 @@ static void led_timer_function(unsigned long data)
52 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay)); 52 mod_timer(&timer_data->timer, jiffies + msecs_to_jiffies(delay));
53} 53}
54 54
55static ssize_t led_delay_on_show(struct class_device *dev, char *buf) 55static ssize_t led_delay_on_show(struct device *dev,
56 struct device_attribute *attr, char *buf)
56{ 57{
57 struct led_classdev *led_cdev = class_get_devdata(dev); 58 struct led_classdev *led_cdev = dev_get_drvdata(dev);
58 struct timer_trig_data *timer_data = led_cdev->trigger_data; 59 struct timer_trig_data *timer_data = led_cdev->trigger_data;
59 60
60 sprintf(buf, "%lu\n", timer_data->delay_on); 61 sprintf(buf, "%lu\n", timer_data->delay_on);
@@ -62,10 +63,10 @@ static ssize_t led_delay_on_show(struct class_device *dev, char *buf)
62 return strlen(buf) + 1; 63 return strlen(buf) + 1;
63} 64}
64 65
65static ssize_t led_delay_on_store(struct class_device *dev, const char *buf, 66static ssize_t led_delay_on_store(struct device *dev,
66 size_t size) 67 struct device_attribute *attr, const char *buf, size_t size)
67{ 68{
68 struct led_classdev *led_cdev = class_get_devdata(dev); 69 struct led_classdev *led_cdev = dev_get_drvdata(dev);
69 struct timer_trig_data *timer_data = led_cdev->trigger_data; 70 struct timer_trig_data *timer_data = led_cdev->trigger_data;
70 int ret = -EINVAL; 71 int ret = -EINVAL;
71 char *after; 72 char *after;
@@ -84,9 +85,10 @@ static ssize_t led_delay_on_store(struct class_device *dev, const char *buf,
84 return ret; 85 return ret;
85} 86}
86 87
87static ssize_t led_delay_off_show(struct class_device *dev, char *buf) 88static ssize_t led_delay_off_show(struct device *dev,
89 struct device_attribute *attr, char *buf)
88{ 90{
89 struct led_classdev *led_cdev = class_get_devdata(dev); 91 struct led_classdev *led_cdev = dev_get_drvdata(dev);
90 struct timer_trig_data *timer_data = led_cdev->trigger_data; 92 struct timer_trig_data *timer_data = led_cdev->trigger_data;
91 93
92 sprintf(buf, "%lu\n", timer_data->delay_off); 94 sprintf(buf, "%lu\n", timer_data->delay_off);
@@ -94,10 +96,10 @@ static ssize_t led_delay_off_show(struct class_device *dev, char *buf)
94 return strlen(buf) + 1; 96 return strlen(buf) + 1;
95} 97}
96 98
97static ssize_t led_delay_off_store(struct class_device *dev, const char *buf, 99static ssize_t led_delay_off_store(struct device *dev,
98 size_t size) 100 struct device_attribute *attr, const char *buf, size_t size)
99{ 101{
100 struct led_classdev *led_cdev = class_get_devdata(dev); 102 struct led_classdev *led_cdev = dev_get_drvdata(dev);
101 struct timer_trig_data *timer_data = led_cdev->trigger_data; 103 struct timer_trig_data *timer_data = led_cdev->trigger_data;
102 int ret = -EINVAL; 104 int ret = -EINVAL;
103 char *after; 105 char *after;
@@ -116,10 +118,8 @@ static ssize_t led_delay_off_store(struct class_device *dev, const char *buf,
116 return ret; 118 return ret;
117} 119}
118 120
119static CLASS_DEVICE_ATTR(delay_on, 0644, led_delay_on_show, 121static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
120 led_delay_on_store); 122static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
121static CLASS_DEVICE_ATTR(delay_off, 0644, led_delay_off_show,
122 led_delay_off_store);
123 123
124static void timer_trig_activate(struct led_classdev *led_cdev) 124static void timer_trig_activate(struct led_classdev *led_cdev)
125{ 125{
@@ -136,18 +136,17 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
136 timer_data->timer.function = led_timer_function; 136 timer_data->timer.function = led_timer_function;
137 timer_data->timer.data = (unsigned long) led_cdev; 137 timer_data->timer.data = (unsigned long) led_cdev;
138 138
139 rc = class_device_create_file(led_cdev->class_dev, 139 rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
140 &class_device_attr_delay_on); 140 if (rc)
141 if (rc) goto err_out; 141 goto err_out;
142 rc = class_device_create_file(led_cdev->class_dev, 142 rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
143 &class_device_attr_delay_off); 143 if (rc)
144 if (rc) goto err_out_delayon; 144 goto err_out_delayon;
145 145
146 return; 146 return;
147 147
148err_out_delayon: 148err_out_delayon:
149 class_device_remove_file(led_cdev->class_dev, 149 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
150 &class_device_attr_delay_on);
151err_out: 150err_out:
152 led_cdev->trigger_data = NULL; 151 led_cdev->trigger_data = NULL;
153 kfree(timer_data); 152 kfree(timer_data);
@@ -158,10 +157,8 @@ static void timer_trig_deactivate(struct led_classdev *led_cdev)
158 struct timer_trig_data *timer_data = led_cdev->trigger_data; 157 struct timer_trig_data *timer_data = led_cdev->trigger_data;
159 158
160 if (timer_data) { 159 if (timer_data) {
161 class_device_remove_file(led_cdev->class_dev, 160 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
162 &class_device_attr_delay_on); 161 device_remove_file(led_cdev->dev, &dev_attr_delay_off);
163 class_device_remove_file(led_cdev->class_dev,
164 &class_device_attr_delay_off);
165 del_timer_sync(&timer_data->timer); 162 del_timer_sync(&timer_data->timer);
166 kfree(timer_data); 163 kfree(timer_data);
167 } 164 }
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index d9de5bbc613f..bee029bb2c7b 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -38,12 +38,12 @@ static void set_guest_interrupt(struct lguest *lg, u32 lo, u32 hi, int has_err)
38 ss = lg->regs->ss; 38 ss = lg->regs->ss;
39 } 39 }
40 40
41 /* We use IF bit in eflags to indicate whether irqs were disabled 41 /* We use IF bit in eflags to indicate whether irqs were enabled
42 (it's always 0, since irqs are enabled when guest is running). */ 42 (it's always 1, since irqs are enabled when guest is running). */
43 eflags = lg->regs->eflags; 43 eflags = lg->regs->eflags;
44 if (get_user(irq_enable, &lg->lguest_data->irq_enabled)) 44 if (get_user(irq_enable, &lg->lguest_data->irq_enabled) == 0
45 irq_enable = 0; 45 && !(irq_enable & X86_EFLAGS_IF))
46 eflags |= (irq_enable & X86_EFLAGS_IF); 46 eflags &= ~X86_EFLAGS_IF;
47 47
48 push_guest_stack(lg, &gstack, eflags); 48 push_guest_stack(lg, &gstack, eflags);
49 push_guest_stack(lg, &gstack, lg->regs->cs); 49 push_guest_stack(lg, &gstack, lg->regs->cs);
diff --git a/drivers/lguest/io.c b/drivers/lguest/io.c
index 06bdba2337ef..c8eb79266991 100644
--- a/drivers/lguest/io.c
+++ b/drivers/lguest/io.c
@@ -187,7 +187,7 @@ static u32 copy_data(struct lguest *srclg,
187 /* FIXME: This is not completely portable, since 187 /* FIXME: This is not completely portable, since
188 archs do different things for copy_to_user_page. */ 188 archs do different things for copy_to_user_page. */
189 if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE, 189 if (copy_from_user(maddr + (dst->addr[di] + dstoff)%PAGE_SIZE,
190 (void *__user)src->addr[si], len) != 0) { 190 (void __user *)src->addr[si], len) != 0) {
191 kill_guest(srclg, "bad address in sending DMA"); 191 kill_guest(srclg, "bad address in sending DMA");
192 totlen = 0; 192 totlen = 0;
193 break; 193 break;
diff --git a/drivers/lguest/lguest.c b/drivers/lguest/lguest.c
index b9a58b78c990..18dade06d4a9 100644
--- a/drivers/lguest/lguest.c
+++ b/drivers/lguest/lguest.c
@@ -39,7 +39,6 @@
39#include <asm/e820.h> 39#include <asm/e820.h>
40#include <asm/mce.h> 40#include <asm/mce.h>
41#include <asm/io.h> 41#include <asm/io.h>
42//#include <asm/sched-clock.h>
43 42
44/* Declarations for definitions in lguest_guest.S */ 43/* Declarations for definitions in lguest_guest.S */
45extern char lguest_noirq_start[], lguest_noirq_end[]; 44extern char lguest_noirq_start[], lguest_noirq_end[];
@@ -57,6 +56,7 @@ struct lguest_data lguest_data = {
57 .blocked_interrupts = { 1 }, /* Block timer interrupts */ 56 .blocked_interrupts = { 1 }, /* Block timer interrupts */
58}; 57};
59struct lguest_device_desc *lguest_devices; 58struct lguest_device_desc *lguest_devices;
59static cycle_t clock_base;
60 60
61static enum paravirt_lazy_mode lazy_mode; 61static enum paravirt_lazy_mode lazy_mode;
62static void lguest_lazy_mode(enum paravirt_lazy_mode mode) 62static void lguest_lazy_mode(enum paravirt_lazy_mode mode)
@@ -363,6 +363,11 @@ static struct clocksource lguest_clock = {
363 .read = lguest_clock_read, 363 .read = lguest_clock_read,
364}; 364};
365 365
366static unsigned long long lguest_sched_clock(void)
367{
368 return cyc2ns(&lguest_clock, lguest_clock_read() - clock_base);
369}
370
366/* We also need a "struct clock_event_device": Linux asks us to set it to go 371/* We also need a "struct clock_event_device": Linux asks us to set it to go
367 * off some time in the future. Actually, James Morris figured all this out, I 372 * off some time in the future. Actually, James Morris figured all this out, I
368 * just applied the patch. */ 373 * just applied the patch. */
@@ -393,6 +398,8 @@ static void lguest_clockevent_set_mode(enum clock_event_mode mode,
393 break; 398 break;
394 case CLOCK_EVT_MODE_PERIODIC: 399 case CLOCK_EVT_MODE_PERIODIC:
395 BUG(); 400 BUG();
401 case CLOCK_EVT_MODE_RESUME:
402 break;
396 } 403 }
397} 404}
398 405
@@ -439,6 +446,7 @@ static void lguest_time_init(void)
439 lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8; 446 lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8;
440 lguest_clock.mask = CLOCKSOURCE_MASK(32); 447 lguest_clock.mask = CLOCKSOURCE_MASK(32);
441 } 448 }
449 clock_base = lguest_clock_read();
442 clocksource_register(&lguest_clock); 450 clocksource_register(&lguest_clock);
443 451
444 /* We can't set cpumask in the initializer: damn C limitations! */ 452 /* We can't set cpumask in the initializer: damn C limitations! */
@@ -584,6 +592,7 @@ __init void lguest_init(void *boot)
584 paravirt_ops.time_init = lguest_time_init; 592 paravirt_ops.time_init = lguest_time_init;
585 paravirt_ops.set_lazy_mode = lguest_lazy_mode; 593 paravirt_ops.set_lazy_mode = lguest_lazy_mode;
586 paravirt_ops.wbinvd = lguest_wbinvd; 594 paravirt_ops.wbinvd = lguest_wbinvd;
595 paravirt_ops.sched_clock = lguest_sched_clock;
587 596
588 hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0); 597 hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0);
589 598
diff --git a/drivers/lguest/lguest_asm.S b/drivers/lguest/lguest_asm.S
index 00046c57b5ba..a3dbf22ee365 100644
--- a/drivers/lguest/lguest_asm.S
+++ b/drivers/lguest/lguest_asm.S
@@ -2,9 +2,7 @@
2#include <linux/lguest.h> 2#include <linux/lguest.h>
3#include <asm/asm-offsets.h> 3#include <asm/asm-offsets.h>
4#include <asm/thread_info.h> 4#include <asm/thread_info.h>
5 5#include <asm/processor-flags.h>
6/* FIXME: Once asm/processor-flags.h goes in, include that */
7#define X86_EFLAGS_IF 0x00000200
8 6
9/* 7/*
10 * This is where we begin: we have a magic signature which the launcher looks 8 * This is where we begin: we have a magic signature which the launcher looks
diff --git a/drivers/macintosh/rack-meter.c b/drivers/macintosh/rack-meter.c
index 4177ff004753..2c21d4f25cc8 100644
--- a/drivers/macintosh/rack-meter.c
+++ b/drivers/macintosh/rack-meter.c
@@ -30,7 +30,6 @@
30#include <asm/machdep.h> 30#include <asm/machdep.h>
31#include <asm/pmac_feature.h> 31#include <asm/pmac_feature.h>
32#include <asm/dbdma.h> 32#include <asm/dbdma.h>
33#include <asm/dbdma.h>
34#include <asm/macio.h> 33#include <asm/macio.h>
35#include <asm/keylargo.h> 34#include <asm/keylargo.h>
36 35
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index ba952a032598..bdc52d6922b7 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -920,6 +920,8 @@ static void crypt_dtr(struct dm_target *ti)
920{ 920{
921 struct crypt_config *cc = (struct crypt_config *) ti->private; 921 struct crypt_config *cc = (struct crypt_config *) ti->private;
922 922
923 flush_workqueue(_kcryptd_workqueue);
924
923 bioset_free(cc->bs); 925 bioset_free(cc->bs);
924 mempool_destroy(cc->page_pool); 926 mempool_destroy(cc->page_pool);
925 mempool_destroy(cc->io_pool); 927 mempool_destroy(cc->io_pool);
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index c8dfdb302916..d90ee145effe 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -493,12 +493,12 @@ async_copy_data(int frombio, struct bio *bio, struct page *page,
493 if (frombio) 493 if (frombio)
494 tx = async_memcpy(page, bio_page, page_offset, 494 tx = async_memcpy(page, bio_page, page_offset,
495 b_offset, clen, 495 b_offset, clen,
496 ASYNC_TX_DEP_ACK | ASYNC_TX_KMAP_SRC, 496 ASYNC_TX_DEP_ACK,
497 tx, NULL, NULL); 497 tx, NULL, NULL);
498 else 498 else
499 tx = async_memcpy(bio_page, page, b_offset, 499 tx = async_memcpy(bio_page, page, b_offset,
500 page_offset, clen, 500 page_offset, clen,
501 ASYNC_TX_DEP_ACK | ASYNC_TX_KMAP_DST, 501 ASYNC_TX_DEP_ACK,
502 tx, NULL, NULL); 502 tx, NULL, NULL);
503 } 503 }
504 if (clen < len) /* hit end of page */ 504 if (clen < len) /* hit end of page */
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index fe447a06e24e..a3292e955aaa 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -345,8 +345,8 @@ void ir_rc5_timer_end(unsigned long data)
345 } 345 }
346 346
347 /* Set/reset key-up timer */ 347 /* Set/reset key-up timer */
348 timeout = current_jiffies + (500 + ir->rc5_key_timeout 348 timeout = current_jiffies +
349 * HZ) / 1000; 349 msecs_to_jiffies(ir->rc5_key_timeout);
350 mod_timer(&ir->timer_keyup, timeout); 350 mod_timer(&ir->timer_keyup, timeout);
351 351
352 /* Save code for repeat test */ 352 /* Save code for repeat test */
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 2cee9e3bd29f..8178832d14a8 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -2267,7 +2267,7 @@ static int frontend_init(struct av7110 *av7110)
2267 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_master_cmd, av7110->fe_diseqc_send_master_cmd, av7110_fe_diseqc_send_master_cmd); 2267 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_master_cmd, av7110->fe_diseqc_send_master_cmd, av7110_fe_diseqc_send_master_cmd);
2268 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_burst, av7110->fe_diseqc_send_burst, av7110_fe_diseqc_send_burst); 2268 FE_FUNC_OVERRIDE(av7110->fe->ops.diseqc_send_burst, av7110->fe_diseqc_send_burst, av7110_fe_diseqc_send_burst);
2269 FE_FUNC_OVERRIDE(av7110->fe->ops.set_tone, av7110->fe_set_tone, av7110_fe_set_tone); 2269 FE_FUNC_OVERRIDE(av7110->fe->ops.set_tone, av7110->fe_set_tone, av7110_fe_set_tone);
2270 FE_FUNC_OVERRIDE(av7110->fe->ops.set_voltage, av7110->fe_set_voltage, av7110_fe_set_voltage;) 2270 FE_FUNC_OVERRIDE(av7110->fe->ops.set_voltage, av7110->fe_set_voltage, av7110_fe_set_voltage);
2271 FE_FUNC_OVERRIDE(av7110->fe->ops.dishnetwork_send_legacy_command, av7110->fe_dishnetwork_send_legacy_command, av7110_fe_dishnetwork_send_legacy_command); 2271 FE_FUNC_OVERRIDE(av7110->fe->ops.dishnetwork_send_legacy_command, av7110->fe_dishnetwork_send_legacy_command, av7110_fe_dishnetwork_send_legacy_command);
2272 FE_FUNC_OVERRIDE(av7110->fe->ops.set_frontend, av7110->fe_set_frontend, av7110_fe_set_frontend); 2272 FE_FUNC_OVERRIDE(av7110->fe->ops.set_frontend, av7110->fe_set_frontend, av7110_fe_set_frontend);
2273 2273
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index ce940b1b787f..f0a67e93d7fd 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -63,7 +63,7 @@ struct rt_device
63static void sleep_delay(long n) 63static void sleep_delay(long n)
64{ 64{
65 /* Sleep nicely for 'n' uS */ 65 /* Sleep nicely for 'n' uS */
66 int d=n/(1000000/HZ); 66 int d=n/msecs_to_jiffies(1000);
67 if(!d) 67 if(!d)
68 udelay(n); 68 udelay(n);
69 else 69 else
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 8cf2e9df5c8a..34e317ced5a3 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -329,7 +329,7 @@ cadet_handler(unsigned long data)
329 init_timer(&readtimer); 329 init_timer(&readtimer);
330 readtimer.function=cadet_handler; 330 readtimer.function=cadet_handler;
331 readtimer.data=(unsigned long)0; 331 readtimer.data=(unsigned long)0;
332 readtimer.expires=jiffies+(HZ/20); 332 readtimer.expires=jiffies+msecs_to_jiffies(50);
333 add_timer(&readtimer); 333 add_timer(&readtimer);
334} 334}
335 335
@@ -349,7 +349,7 @@ cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
349 init_timer(&readtimer); 349 init_timer(&readtimer);
350 readtimer.function=cadet_handler; 350 readtimer.function=cadet_handler;
351 readtimer.data=(unsigned long)0; 351 readtimer.data=(unsigned long)0;
352 readtimer.expires=jiffies+(HZ/20); 352 readtimer.expires=jiffies+msecs_to_jiffies(50);
353 add_timer(&readtimer); 353 add_timer(&readtimer);
354 } 354 }
355 if(rdsin==rdsout) { 355 if(rdsin==rdsout) {
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 4db05b2b1b6e..99a323131333 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -94,7 +94,6 @@ struct gemtek_pci_card {
94 94
95 u32 iobase; 95 u32 iobase;
96 u32 length; 96 u32 length;
97 u16 model;
98 97
99 u32 current_frequency; 98 u32 current_frequency;
100 u8 mute; 99 u8 mute;
@@ -413,8 +412,6 @@ static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci
413 goto err_pci; 412 goto err_pci;
414 } 413 }
415 414
416 pci_read_config_word( pci_dev, PCI_SUBSYSTEM_ID, &card->model );
417
418 pci_set_drvdata( pci_dev, card ); 415 pci_set_drvdata( pci_dev, card );
419 416
420 if ( (devradio = kmalloc( sizeof( struct video_device ), GFP_KERNEL )) == NULL ) { 417 if ( (devradio = kmalloc( sizeof( struct video_device ), GFP_KERNEL )) == NULL ) {
diff --git a/drivers/media/video/bt866.c b/drivers/media/video/bt866.c
index 2e4cf1efdd21..b767b098d14b 100644
--- a/drivers/media/video/bt866.c
+++ b/drivers/media/video/bt866.c
@@ -257,7 +257,7 @@ static int bt866_write(struct bt866 *encoder,
257 printk(KERN_WARNING "%s: I/O error #%d " 257 printk(KERN_WARNING "%s: I/O error #%d "
258 "(write 0x%02x/0x%02x)\n", 258 "(write 0x%02x/0x%02x)\n",
259 encoder->i2c->name, err, encoder->addr, subaddr); 259 encoder->i2c->name, err, encoder->addr, subaddr);
260 schedule_timeout_interruptible(HZ/10); 260 schedule_timeout_interruptible(msecs_to_jiffies(100));
261 } 261 }
262 if (err == 3) { 262 if (err == 3) {
263 printk(KERN_WARNING "%s: giving up\n", 263 printk(KERN_WARNING "%s: giving up\n",
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 2aea09c72093..387cb2122d4f 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -4209,7 +4209,7 @@ static int tea5757_read(struct bttv *btv)
4209 bus_low(btv,btv->mbox_clk); 4209 bus_low(btv,btv->mbox_clk);
4210 4210
4211 udelay(10); 4211 udelay(10);
4212 timeout= jiffies + HZ; 4212 timeout= jiffies + msecs_to_jiffies(1000);
4213 4213
4214 /* wait for DATA line to go low; error if it doesn't */ 4214 /* wait for DATA line to go low; error if it doesn't */
4215 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout)) 4215 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 94a13d0ee614..4201552bc3c0 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -153,7 +153,7 @@ static void bttv_ir_start(struct bttv *btv, struct card_ir *ir)
153{ 153{
154 if (ir->polling) { 154 if (ir->polling) {
155 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv); 155 setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv);
156 ir->timer.expires = jiffies + HZ; 156 ir->timer.expires = jiffies + msecs_to_jiffies(1000);
157 add_timer(&ir->timer); 157 add_timer(&ir->timer);
158 } else if (ir->rc5_gpio) { 158 } else if (ir->rc5_gpio) {
159 /* set timer_end for code completion */ 159 /* set timer_end for code completion */
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index bd85f6d0fbe3..5b25faca1504 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -284,8 +284,8 @@ extern int fini_bttv_i2c(struct bttv *btv);
284#define d2printk if (bttv_debug >= 2) printk 284#define d2printk if (bttv_debug >= 2) printk
285 285
286#define BTTV_MAX_FBUF 0x208000 286#define BTTV_MAX_FBUF 0x208000
287#define BTTV_TIMEOUT (HZ/2) /* 0.5 seconds */ 287#define BTTV_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
288#define BTTV_FREE_IDLE (HZ) /* one second */ 288#define BTTV_FREE_IDLE msecs_to_jiffies(1000) /* one second */
289 289
290 290
291struct bttv_pll_info { 291struct bttv_pll_info {
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index 925ff17efbbc..f76c6a6c3766 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -95,7 +95,7 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam,
95 unsigned long oldjiffies = jiffies; 95 unsigned long oldjiffies = jiffies;
96 unsigned int i; 96 unsigned int i;
97 97
98 for (oldjiffies = jiffies; (jiffies - oldjiffies) < (HZ/25); ) 98 for (oldjiffies = jiffies; (jiffies - oldjiffies) < msecs_to_jiffies(40); )
99 if (qcam_ready1(qcam) == value) 99 if (qcam_ready1(qcam) == value)
100 return 0; 100 return 0;
101 101
@@ -120,7 +120,7 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
120 unsigned long oldjiffies = jiffies; 120 unsigned long oldjiffies = jiffies;
121 unsigned int i; 121 unsigned int i;
122 122
123 for (oldjiffies = jiffies; (jiffies - oldjiffies) < (HZ/25); ) 123 for (oldjiffies = jiffies; (jiffies - oldjiffies) < msecs_to_jiffies(40); )
124 if (qcam_ready2(qcam) == value) 124 if (qcam_ready2(qcam) == value)
125 return 0; 125 return 0;
126 126
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 98fa35421bdd..06b233a7b20b 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1881,8 +1881,14 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1881 mutex_unlock(&core->lock); 1881 mutex_unlock(&core->lock);
1882 1882
1883 /* start tvaudio thread */ 1883 /* start tvaudio thread */
1884 if (core->tuner_type != TUNER_ABSENT) 1884 if (core->tuner_type != TUNER_ABSENT) {
1885 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); 1885 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
1886 if (IS_ERR(core->kthread)) {
1887 err = PTR_ERR(core->kthread);
1888 printk(KERN_ERR "Failed to create cx88 audio thread, err=%d\n",
1889 err);
1890 }
1891 }
1886 return 0; 1892 return 0;
1887 1893
1888fail_unreg: 1894fail_unreg:
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index c4f656ec46b0..809126866a3e 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -259,7 +259,7 @@ struct cx88_subid {
259#define RESOURCE_VIDEO 2 259#define RESOURCE_VIDEO 2
260#define RESOURCE_VBI 4 260#define RESOURCE_VBI 4
261 261
262#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */ 262#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
263 263
264/* buffer for one video frame */ 264/* buffer for one video frame */
265struct cx88_buffer { 265struct cx88_buffer {
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index 1aaeaa02f158..e43beb2c9cbf 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -1,6 +1,7 @@
1config VIDEO_IVTV 1config VIDEO_IVTV
2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support" 2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support"
3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL
4 select I2C_ALGOBIT
4 select FW_LOADER 5 select FW_LOADER
5 select VIDEO_TUNER 6 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
@@ -16,11 +17,11 @@ config VIDEO_IVTV
16 select VIDEO_UPD64031A 17 select VIDEO_UPD64031A
17 select VIDEO_UPD64083 18 select VIDEO_UPD64083
18 ---help--- 19 ---help---
19 This is a video4linux driver for Conexant cx23416 or cx23416 based 20 This is a video4linux driver for Conexant cx23416 or cx23415 based
20 PCI personal video recorder devices. 21 PCI personal video recorder devices.
21 22
22 This is used in devices such as the Hauppauge PVR-150/250/350/500 23 This is used in devices such as the Hauppauge PVR-150/250/350/500
23 cards. 24 cards. There is a driver homepage at <http://www.ivtvdriver.org>.
24 25
25 To compile this driver as a module, choose M here: the 26 To compile this driver as a module, choose M here: the
26 module will be called ivtv. 27 module will be called ivtv.
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 4c93466a89e5..d73d433a4ff6 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -56,7 +56,6 @@
56#include "ivtv-gpio.h" 56#include "ivtv-gpio.h"
57#include "ivtv-yuv.h" 57#include "ivtv-yuv.h"
58 58
59#include <linux/vermagic.h>
60#include <media/tveeprom.h> 59#include <media/tveeprom.h>
61#include <media/v4l2-chip-ident.h> 60#include <media/v4l2-chip-ident.h>
62 61
@@ -276,9 +275,10 @@ int ivtv_waitq(wait_queue_head_t *waitq)
276} 275}
277 276
278/* Generic utility functions */ 277/* Generic utility functions */
279int ivtv_sleep_timeout(int timeout, int intr) 278int ivtv_msleep_timeout(unsigned int msecs, int intr)
280{ 279{
281 int ret; 280 int ret;
281 int timeout = msecs_to_jiffies(msecs);
282 282
283 do { 283 do {
284 set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); 284 set_current_state(intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
@@ -427,7 +427,7 @@ static void ivtv_process_eeprom(struct ivtv *itv)
427 if (itv->options.newi2c == -1 && tv.has_ir != -1 && tv.has_ir != 2) { 427 if (itv->options.newi2c == -1 && tv.has_ir != -1 && tv.has_ir != 2) {
428 itv->options.newi2c = (tv.has_ir & 2) ? 1 : 0; 428 itv->options.newi2c = (tv.has_ir & 2) ? 1 : 0;
429 if (itv->options.newi2c) { 429 if (itv->options.newi2c) {
430 IVTV_INFO("reopen i2c bus for IR-blaster support\n"); 430 IVTV_INFO("Reopen i2c bus for IR-blaster support\n");
431 exit_ivtv_i2c(itv); 431 exit_ivtv_i2c(itv);
432 init_ivtv_i2c(itv); 432 init_ivtv_i2c(itv);
433 } 433 }
@@ -951,7 +951,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
951 951
952 /* Make sure we've got a place for this card */ 952 /* Make sure we've got a place for this card */
953 if (ivtv_cards_active == IVTV_MAX_CARDS) { 953 if (ivtv_cards_active == IVTV_MAX_CARDS) {
954 printk(KERN_ERR "ivtv: Maximum number of cards detected (%d).\n", 954 printk(KERN_ERR "ivtv: Maximum number of cards detected (%d)\n",
955 ivtv_cards_active); 955 ivtv_cards_active);
956 spin_unlock(&ivtv_cards_lock); 956 spin_unlock(&ivtv_cards_lock);
957 return -ENOMEM; 957 return -ENOMEM;
@@ -966,9 +966,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
966 itv->dev = dev; 966 itv->dev = dev;
967 itv->num = ivtv_cards_active++; 967 itv->num = ivtv_cards_active++;
968 snprintf(itv->name, sizeof(itv->name) - 1, "ivtv%d", itv->num); 968 snprintf(itv->name, sizeof(itv->name) - 1, "ivtv%d", itv->num);
969 if (itv->num) { 969 IVTV_INFO("Initializing card #%d\n", itv->num);
970 printk(KERN_INFO "ivtv: ====================== NEXT CARD ======================\n");
971 }
972 970
973 spin_unlock(&ivtv_cards_lock); 971 spin_unlock(&ivtv_cards_lock);
974 972
@@ -1215,7 +1213,7 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1215 if (itv->has_cx23415) 1213 if (itv->has_cx23415)
1216 ivtv_set_osd_alpha(itv); 1214 ivtv_set_osd_alpha(itv);
1217 1215
1218 IVTV_INFO("Initialized %s, card #%d\n", itv->card_name, itv->num); 1216 IVTV_INFO("Initialized card #%d: %s\n", itv->num, itv->card_name);
1219 1217
1220 return 0; 1218 return 0;
1221 1219
@@ -1248,15 +1246,15 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1248{ 1246{
1249 struct ivtv *itv = pci_get_drvdata(pci_dev); 1247 struct ivtv *itv = pci_get_drvdata(pci_dev);
1250 1248
1251 IVTV_DEBUG_INFO("Removing Card #%d.\n", itv->num); 1249 IVTV_DEBUG_INFO("Removing Card #%d\n", itv->num);
1252 1250
1253 /* Stop all captures */ 1251 /* Stop all captures */
1254 IVTV_DEBUG_INFO(" Stopping all streams.\n"); 1252 IVTV_DEBUG_INFO("Stopping all streams\n");
1255 if (atomic_read(&itv->capturing) > 0) 1253 if (atomic_read(&itv->capturing) > 0)
1256 ivtv_stop_all_captures(itv); 1254 ivtv_stop_all_captures(itv);
1257 1255
1258 /* Stop all decoding */ 1256 /* Stop all decoding */
1259 IVTV_DEBUG_INFO(" Stopping decoding.\n"); 1257 IVTV_DEBUG_INFO("Stopping decoding\n");
1260 if (atomic_read(&itv->decoding) > 0) { 1258 if (atomic_read(&itv->decoding) > 0) {
1261 int type; 1259 int type;
1262 1260
@@ -1269,30 +1267,30 @@ static void ivtv_remove(struct pci_dev *pci_dev)
1269 } 1267 }
1270 1268
1271 /* Interrupts */ 1269 /* Interrupts */
1272 IVTV_DEBUG_INFO(" Disabling interrupts.\n"); 1270 IVTV_DEBUG_INFO("Disabling interrupts\n");
1273 ivtv_set_irq_mask(itv, 0xffffffff); 1271 ivtv_set_irq_mask(itv, 0xffffffff);
1274 del_timer_sync(&itv->dma_timer); 1272 del_timer_sync(&itv->dma_timer);
1275 1273
1276 /* Stop all Work Queues */ 1274 /* Stop all Work Queues */
1277 IVTV_DEBUG_INFO(" Stop Work Queues.\n"); 1275 IVTV_DEBUG_INFO("Stop Work Queues\n");
1278 flush_workqueue(itv->irq_work_queues); 1276 flush_workqueue(itv->irq_work_queues);
1279 destroy_workqueue(itv->irq_work_queues); 1277 destroy_workqueue(itv->irq_work_queues);
1280 1278
1281 IVTV_DEBUG_INFO(" Stopping Firmware.\n"); 1279 IVTV_DEBUG_INFO("Stopping Firmware\n");
1282 ivtv_halt_firmware(itv); 1280 ivtv_halt_firmware(itv);
1283 1281
1284 IVTV_DEBUG_INFO(" Unregistering v4l devices.\n"); 1282 IVTV_DEBUG_INFO("Unregistering v4l devices\n");
1285 ivtv_streams_cleanup(itv); 1283 ivtv_streams_cleanup(itv);
1286 IVTV_DEBUG_INFO(" Freeing dma resources.\n"); 1284 IVTV_DEBUG_INFO("Freeing dma resources\n");
1287 ivtv_udma_free(itv); 1285 ivtv_udma_free(itv);
1288 1286
1289 exit_ivtv_i2c(itv); 1287 exit_ivtv_i2c(itv);
1290 1288
1291 IVTV_DEBUG_INFO(" Releasing irq.\n"); 1289 IVTV_DEBUG_INFO(" Releasing irq\n");
1292 free_irq(itv->dev->irq, (void *)itv); 1290 free_irq(itv->dev->irq, (void *)itv);
1293 ivtv_iounmap(itv); 1291 ivtv_iounmap(itv);
1294 1292
1295 IVTV_DEBUG_INFO(" Releasing mem.\n"); 1293 IVTV_DEBUG_INFO(" Releasing mem\n");
1296 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 1294 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
1297 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE); 1295 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
1298 if (itv->has_cx23415) 1296 if (itv->has_cx23415)
@@ -1313,28 +1311,27 @@ static struct pci_driver ivtv_pci_driver = {
1313 1311
1314static int module_start(void) 1312static int module_start(void)
1315{ 1313{
1316 printk(KERN_INFO "ivtv: ==================== START INIT IVTV ====================\n"); 1314 printk(KERN_INFO "ivtv: Start initialization, version %s\n", IVTV_VERSION);
1317 printk(KERN_INFO "ivtv: version %s (" VERMAGIC_STRING ") loading\n", IVTV_VERSION);
1318 1315
1319 memset(ivtv_cards, 0, sizeof(ivtv_cards)); 1316 memset(ivtv_cards, 0, sizeof(ivtv_cards));
1320 1317
1321 /* Validate parameters */ 1318 /* Validate parameters */
1322 if (ivtv_first_minor < 0 || ivtv_first_minor >= IVTV_MAX_CARDS) { 1319 if (ivtv_first_minor < 0 || ivtv_first_minor >= IVTV_MAX_CARDS) {
1323 printk(KERN_ERR "ivtv: ivtv_first_minor must be between 0 and %d. Exiting...\n", 1320 printk(KERN_ERR "ivtv: Exiting, ivtv_first_minor must be between 0 and %d\n",
1324 IVTV_MAX_CARDS - 1); 1321 IVTV_MAX_CARDS - 1);
1325 return -1; 1322 return -1;
1326 } 1323 }
1327 1324
1328 if (ivtv_debug < 0 || ivtv_debug > 1023) { 1325 if (ivtv_debug < 0 || ivtv_debug > 1023) {
1329 ivtv_debug = 0; 1326 ivtv_debug = 0;
1330 printk(KERN_INFO "ivtv: debug value must be >= 0 and <= 1023!\n"); 1327 printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 1023\n");
1331 } 1328 }
1332 1329
1333 if (pci_register_driver(&ivtv_pci_driver)) { 1330 if (pci_register_driver(&ivtv_pci_driver)) {
1334 printk(KERN_ERR "ivtv: Error detecting PCI card\n"); 1331 printk(KERN_ERR "ivtv: Error detecting PCI card\n");
1335 return -ENODEV; 1332 return -ENODEV;
1336 } 1333 }
1337 printk(KERN_INFO "ivtv: ==================== END INIT IVTV ====================\n"); 1334 printk(KERN_INFO "ivtv: End initialization\n");
1338 return 0; 1335 return 0;
1339} 1336}
1340 1337
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 6c1a85f1ee1b..91b588d261ae 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -848,7 +848,7 @@ int ivtv_set_output_mode(struct ivtv *itv, int mode);
848struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv); 848struct ivtv_stream *ivtv_get_output_stream(struct ivtv *itv);
849 849
850/* Return non-zero if a signal is pending */ 850/* Return non-zero if a signal is pending */
851int ivtv_sleep_timeout(int timeout, int intr); 851int ivtv_msleep_timeout(unsigned int msecs, int intr);
852 852
853/* Wait on queue, returns -EINTR if interrupted */ 853/* Wait on queue, returns -EINTR if interrupted */
854int ivtv_waitq(wait_queue_head_t *waitq); 854int ivtv_waitq(wait_queue_head_t *waitq);
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index ee7e884e9c4f..8e97a938398f 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -218,7 +218,7 @@ static struct ivtv_buffer *ivtv_get_buffer(struct ivtv_stream *s, int non_block,
218 /* Process pending program info updates and pending VBI data */ 218 /* Process pending program info updates and pending VBI data */
219 ivtv_update_pgm_info(itv); 219 ivtv_update_pgm_info(itv);
220 220
221 if (jiffies - itv->dualwatch_jiffies > HZ) { 221 if (jiffies - itv->dualwatch_jiffies > msecs_to_jiffies(1000)) {
222 itv->dualwatch_jiffies = jiffies; 222 itv->dualwatch_jiffies = jiffies;
223 ivtv_dualwatch(itv); 223 ivtv_dualwatch(itv);
224 } 224 }
@@ -832,7 +832,7 @@ int ivtv_v4l2_open(struct inode *inode, struct file *filp)
832 if (itv == NULL) { 832 if (itv == NULL) {
833 /* Couldn't find a device registered 833 /* Couldn't find a device registered
834 on that minor, shouldn't happen! */ 834 on that minor, shouldn't happen! */
835 printk(KERN_WARNING "ivtv: no ivtv device found on minor %d\n", minor); 835 printk(KERN_WARNING "ivtv: No ivtv device found on minor %d\n", minor);
836 return -ENXIO; 836 return -ENXIO;
837 } 837 }
838 838
@@ -924,7 +924,7 @@ void ivtv_unmute(struct ivtv *itv)
924 if (atomic_read(&itv->capturing) == 0) 924 if (atomic_read(&itv->capturing) == 0)
925 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 925 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
926 926
927 ivtv_sleep_timeout(HZ / 10, 0); 927 ivtv_msleep_timeout(100, 0);
928 928
929 if (atomic_read(&itv->capturing)) { 929 if (atomic_read(&itv->capturing)) {
930 ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12); 930 ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12);
diff --git a/drivers/media/video/ivtv/ivtv-firmware.c b/drivers/media/video/ivtv/ivtv-firmware.c
index 2b6208a6a108..d0feabf93080 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.c
+++ b/drivers/media/video/ivtv/ivtv-firmware.c
@@ -36,7 +36,7 @@
36#define IVTV_CMD_SPU_STOP 0x00000001 36#define IVTV_CMD_SPU_STOP 0x00000001
37#define IVTV_CMD_SDRAM_PRECHARGE_INIT 0x0000001A 37#define IVTV_CMD_SDRAM_PRECHARGE_INIT 0x0000001A
38#define IVTV_CMD_SDRAM_REFRESH_INIT 0x80000640 38#define IVTV_CMD_SDRAM_REFRESH_INIT 0x80000640
39#define IVTV_SDRAM_SLEEPTIME (60 * HZ / 100) /* 600 ms */ 39#define IVTV_SDRAM_SLEEPTIME 600
40 40
41#define IVTV_DECODE_INIT_MPEG_FILENAME "v4l-cx2341x-init.mpg" 41#define IVTV_DECODE_INIT_MPEG_FILENAME "v4l-cx2341x-init.mpg"
42#define IVTV_DECODE_INIT_MPEG_SIZE (152*1024) 42#define IVTV_DECODE_INIT_MPEG_SIZE (152*1024)
@@ -61,7 +61,7 @@ retry:
61 the wrong file was sometimes loaded. So we check filesizes to 61 the wrong file was sometimes loaded. So we check filesizes to
62 see if at least the right-sized file was loaded. If not, then we 62 see if at least the right-sized file was loaded. If not, then we
63 retry. */ 63 retry. */
64 IVTV_INFO("retry: file loaded was not %s (expected size %ld, got %zd)\n", fn, size, fw->size); 64 IVTV_INFO("Retry: file loaded was not %s (expected size %ld, got %zd)\n", fn, size, fw->size);
65 release_firmware(fw); 65 release_firmware(fw);
66 retries--; 66 retries--;
67 goto retry; 67 goto retry;
@@ -73,11 +73,11 @@ retry:
73 src++; 73 src++;
74 } 74 }
75 release_firmware(fw); 75 release_firmware(fw);
76 IVTV_INFO("loaded %s firmware (%zd bytes)\n", fn, fw->size); 76 IVTV_INFO("Loaded %s firmware (%zd bytes)\n", fn, fw->size);
77 return size; 77 return size;
78 } 78 }
79 IVTV_ERR("unable to open firmware %s (must be %ld bytes)\n", fn, size); 79 IVTV_ERR("Unable to open firmware %s (must be %ld bytes)\n", fn, size);
80 IVTV_ERR("did you put the firmware in the hotplug firmware directory?\n"); 80 IVTV_ERR("Did you put the firmware in the hotplug firmware directory?\n");
81 return -ENOMEM; 81 return -ENOMEM;
82} 82}
83 83
@@ -89,7 +89,7 @@ void ivtv_halt_firmware(struct ivtv *itv)
89 if (itv->enc_mbox.mbox) 89 if (itv->enc_mbox.mbox)
90 ivtv_vapi(itv, CX2341X_ENC_HALT_FW, 0); 90 ivtv_vapi(itv, CX2341X_ENC_HALT_FW, 0);
91 91
92 ivtv_sleep_timeout(HZ / 100, 0); 92 ivtv_msleep_timeout(10, 0);
93 itv->enc_mbox.mbox = itv->dec_mbox.mbox = NULL; 93 itv->enc_mbox.mbox = itv->dec_mbox.mbox = NULL;
94 94
95 IVTV_DEBUG_INFO("Stopping VDM\n"); 95 IVTV_DEBUG_INFO("Stopping VDM\n");
@@ -113,7 +113,7 @@ void ivtv_halt_firmware(struct ivtv *itv)
113 IVTV_DEBUG_INFO("Stopping SPU\n"); 113 IVTV_DEBUG_INFO("Stopping SPU\n");
114 write_reg(IVTV_CMD_SPU_STOP, IVTV_REG_SPU); 114 write_reg(IVTV_CMD_SPU_STOP, IVTV_REG_SPU);
115 115
116 ivtv_sleep_timeout(HZ / 100, 0); 116 ivtv_msleep_timeout(10, 0);
117 117
118 IVTV_DEBUG_INFO("init Encoder SDRAM pre-charge\n"); 118 IVTV_DEBUG_INFO("init Encoder SDRAM pre-charge\n");
119 write_reg(IVTV_CMD_SDRAM_PRECHARGE_INIT, IVTV_REG_ENC_SDRAM_PRECHARGE); 119 write_reg(IVTV_CMD_SDRAM_PRECHARGE_INIT, IVTV_REG_ENC_SDRAM_PRECHARGE);
@@ -129,9 +129,8 @@ void ivtv_halt_firmware(struct ivtv *itv)
129 write_reg(IVTV_CMD_SDRAM_REFRESH_INIT, IVTV_REG_DEC_SDRAM_REFRESH); 129 write_reg(IVTV_CMD_SDRAM_REFRESH_INIT, IVTV_REG_DEC_SDRAM_REFRESH);
130 } 130 }
131 131
132 IVTV_DEBUG_INFO("Sleeping for %dms (600 recommended)\n", 132 IVTV_DEBUG_INFO("Sleeping for %dms\n", IVTV_SDRAM_SLEEPTIME);
133 (int)(IVTV_SDRAM_SLEEPTIME * 1000 / HZ)); 133 ivtv_msleep_timeout(IVTV_SDRAM_SLEEPTIME, 0);
134 ivtv_sleep_timeout(IVTV_SDRAM_SLEEPTIME, 0);
135} 134}
136 135
137void ivtv_firmware_versions(struct ivtv *itv) 136void ivtv_firmware_versions(struct ivtv *itv)
@@ -204,12 +203,12 @@ int ivtv_firmware_init(struct ivtv *itv)
204 203
205 /* start firmware */ 204 /* start firmware */
206 write_reg(read_reg(IVTV_REG_SPU) & IVTV_MASK_SPU_ENABLE, IVTV_REG_SPU); 205 write_reg(read_reg(IVTV_REG_SPU) & IVTV_MASK_SPU_ENABLE, IVTV_REG_SPU);
207 ivtv_sleep_timeout(HZ / 10, 0); 206 ivtv_msleep_timeout(100, 0);
208 if (itv->has_cx23415) 207 if (itv->has_cx23415)
209 write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE15, IVTV_REG_VPU); 208 write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE15, IVTV_REG_VPU);
210 else 209 else
211 write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE16, IVTV_REG_VPU); 210 write_reg(read_reg(IVTV_REG_VPU) & IVTV_MASK_VPU_ENABLE16, IVTV_REG_VPU);
212 ivtv_sleep_timeout(HZ / 10, 0); 211 ivtv_msleep_timeout(100, 0);
213 212
214 /* find mailboxes and ping firmware */ 213 /* find mailboxes and ping firmware */
215 itv->enc_mbox.mbox = ivtv_search_mailbox(itv->enc_mem, IVTV_ENCODER_SIZE); 214 itv->enc_mbox.mbox = ivtv_search_mailbox(itv->enc_mem, IVTV_ENCODER_SIZE);
@@ -264,7 +263,7 @@ void ivtv_init_mpeg_decoder(struct ivtv *itv)
264 IVTV_DECODE_INIT_MPEG_FILENAME); 263 IVTV_DECODE_INIT_MPEG_FILENAME);
265 } else { 264 } else {
266 ivtv_vapi(itv, CX2341X_DEC_SCHED_DMA_FROM_HOST, 3, 0, readbytes, 0); 265 ivtv_vapi(itv, CX2341X_DEC_SCHED_DMA_FROM_HOST, 3, 0, readbytes, 0);
267 ivtv_sleep_timeout(HZ / 10, 0); 266 ivtv_msleep_timeout(100, 0);
268 } 267 }
269 ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 4, 0, 0, 0, 1); 268 ivtv_vapi(itv, CX2341X_DEC_STOP_PLAYBACK, 4, 0, 0, 0, 1);
270} 269}
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index 676418cbaaad..6a5a7aa66976 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -130,7 +130,7 @@ int ivtv_reset_tuner_gpio(enum v4l2_tuner_type mode, void *priv, int ptr)
130 130
131 if (itv->card->type != IVTV_CARD_PG600V2 || itv->options.tuner != TUNER_XCEIVE_XC3028) 131 if (itv->card->type != IVTV_CARD_PG600V2 || itv->options.tuner != TUNER_XCEIVE_XC3028)
132 return -EINVAL; 132 return -EINVAL;
133 IVTV_INFO("Resetting tuner.\n"); 133 IVTV_INFO("Resetting tuner\n");
134 curout = read_reg(IVTV_REG_GPIO_OUT); 134 curout = read_reg(IVTV_REG_GPIO_OUT);
135 curdir = read_reg(IVTV_REG_GPIO_DIR); 135 curdir = read_reg(IVTV_REG_GPIO_DIR);
136 curdir |= (1 << 12); /* GPIO bit 12 */ 136 curdir |= (1 << 12); /* GPIO bit 12 */
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index 50624c6a62a5..b3557435456d 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -144,7 +144,7 @@ static int attach_inform(struct i2c_client *client)
144 } 144 }
145 } 145 }
146 if (i == I2C_CLIENTS_MAX) { 146 if (i == I2C_CLIENTS_MAX) {
147 IVTV_ERR("insufficient room for new I2C client!\n"); 147 IVTV_ERR("Insufficient room for new I2C client\n");
148 } 148 }
149 return 0; 149 return 0;
150} 150}
@@ -236,7 +236,7 @@ static int ivtv_ack(struct ivtv *itv)
236 int ret = 0; 236 int ret = 0;
237 237
238 if (ivtv_getscl(itv) == 1) { 238 if (ivtv_getscl(itv) == 1) {
239 IVTV_DEBUG_I2C("SCL was high starting an ack\n"); 239 IVTV_DEBUG_HI_I2C("SCL was high starting an ack\n");
240 ivtv_setscl(itv, 0); 240 ivtv_setscl(itv, 0);
241 if (!ivtv_waitscl(itv, 0)) { 241 if (!ivtv_waitscl(itv, 0)) {
242 IVTV_DEBUG_I2C("Could not set SCL low starting an ack\n"); 242 IVTV_DEBUG_I2C("Could not set SCL low starting an ack\n");
@@ -263,7 +263,7 @@ static int ivtv_sendbyte(struct ivtv *itv, unsigned char byte)
263{ 263{
264 int i, bit; 264 int i, bit;
265 265
266 IVTV_DEBUG_I2C("write %x\n",byte); 266 IVTV_DEBUG_HI_I2C("write %x\n",byte);
267 for (i = 0; i < 8; ++i, byte<<=1) { 267 for (i = 0; i < 8; ++i, byte<<=1) {
268 ivtv_setscl(itv, 0); 268 ivtv_setscl(itv, 0);
269 if (!ivtv_waitscl(itv, 0)) { 269 if (!ivtv_waitscl(itv, 0)) {
@@ -318,7 +318,7 @@ static int ivtv_readbyte(struct ivtv *itv, unsigned char *byte, int nack)
318 ivtv_scldelay(itv); 318 ivtv_scldelay(itv);
319 ivtv_setscl(itv, 0); 319 ivtv_setscl(itv, 0);
320 ivtv_scldelay(itv); 320 ivtv_scldelay(itv);
321 IVTV_DEBUG_I2C("read %x\n",*byte); 321 IVTV_DEBUG_HI_I2C("read %x\n",*byte);
322 return 0; 322 return 0;
323} 323}
324 324
@@ -330,7 +330,7 @@ static int ivtv_start(struct ivtv *itv)
330 330
331 sda = ivtv_getsda(itv); 331 sda = ivtv_getsda(itv);
332 if (sda != 1) { 332 if (sda != 1) {
333 IVTV_DEBUG_I2C("SDA was low at start\n"); 333 IVTV_DEBUG_HI_I2C("SDA was low at start\n");
334 ivtv_setsda(itv, 1); 334 ivtv_setsda(itv, 1);
335 if (!ivtv_waitsda(itv, 1)) { 335 if (!ivtv_waitsda(itv, 1)) {
336 IVTV_DEBUG_I2C("SDA stuck low\n"); 336 IVTV_DEBUG_I2C("SDA stuck low\n");
@@ -355,7 +355,7 @@ static int ivtv_stop(struct ivtv *itv)
355 int i; 355 int i;
356 356
357 if (ivtv_getscl(itv) != 0) { 357 if (ivtv_getscl(itv) != 0) {
358 IVTV_DEBUG_I2C("SCL not low when stopping\n"); 358 IVTV_DEBUG_HI_I2C("SCL not low when stopping\n");
359 ivtv_setscl(itv, 0); 359 ivtv_setscl(itv, 0);
360 if (!ivtv_waitscl(itv, 0)) { 360 if (!ivtv_waitscl(itv, 0)) {
361 IVTV_DEBUG_I2C("SCL could not be set low\n"); 361 IVTV_DEBUG_I2C("SCL could not be set low\n");
@@ -569,7 +569,7 @@ int ivtv_call_i2c_client(struct ivtv *itv, int addr, unsigned int cmd, void *arg
569 } 569 }
570 } 570 }
571 if (cmd != VIDIOC_G_CHIP_IDENT) 571 if (cmd != VIDIOC_G_CHIP_IDENT)
572 IVTV_ERR("i2c addr 0x%02x not found for command 0x%x!\n", addr, cmd); 572 IVTV_ERR("i2c addr 0x%02x not found for command 0x%x\n", addr, cmd);
573 return -ENODEV; 573 return -ENODEV;
574} 574}
575 575
@@ -640,7 +640,7 @@ int ivtv_i2c_hw(struct ivtv *itv, u32 hw, unsigned int cmd, void *arg)
640 640
641 addr = ivtv_i2c_hw_addr(itv, hw); 641 addr = ivtv_i2c_hw_addr(itv, hw);
642 if (addr < 0) { 642 if (addr < 0) {
643 IVTV_ERR("i2c hardware 0x%08x (%s) not found for command 0x%x!\n", 643 IVTV_ERR("i2c hardware 0x%08x (%s) not found for command 0x%x\n",
644 hw, ivtv_i2c_hw_name(hw), cmd); 644 hw, ivtv_i2c_hw_name(hw), cmd);
645 return addr; 645 return addr;
646 } 646 }
@@ -655,7 +655,7 @@ int ivtv_i2c_id(struct ivtv *itv, u32 id, unsigned int cmd, void *arg)
655 addr = ivtv_i2c_id_addr(itv, id); 655 addr = ivtv_i2c_id_addr(itv, id);
656 if (addr < 0) { 656 if (addr < 0) {
657 if (cmd != VIDIOC_G_CHIP_IDENT) 657 if (cmd != VIDIOC_G_CHIP_IDENT)
658 IVTV_ERR("i2c ID 0x%08x (%s) not found for command 0x%x!\n", 658 IVTV_ERR("i2c ID 0x%08x (%s) not found for command 0x%x\n",
659 id, ivtv_i2c_id_name(id), cmd); 659 id, ivtv_i2c_id_name(id), cmd);
660 return addr; 660 return addr;
661 } 661 }
@@ -696,7 +696,7 @@ int ivtv_upd64083(struct ivtv *itv, unsigned int cmd, void *arg)
696void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg) 696void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg)
697{ 697{
698 if (itv->i2c_adap.algo == NULL) { 698 if (itv->i2c_adap.algo == NULL) {
699 IVTV_ERR("adapter is not set"); 699 IVTV_ERR("Adapter is not set");
700 return; 700 return;
701 } 701 }
702 i2c_clients_command(&itv->i2c_adap, cmd, arg); 702 i2c_clients_command(&itv->i2c_adap, cmd, arg);
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index 1a3ee464a826..fcd6e7f5f121 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -403,6 +403,11 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
403 /* Mark last buffer size for Interrupt flag */ 403 /* Mark last buffer size for Interrupt flag */
404 s->SGarray[s->SG_length - 1].size |= cpu_to_le32(0x80000000); 404 s->SGarray[s->SG_length - 1].size |= cpu_to_le32(0x80000000);
405 405
406 if (s->type == IVTV_ENC_STREAM_TYPE_VBI)
407 set_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
408 else
409 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
410
406 if (ivtv_use_pio(s)) { 411 if (ivtv_use_pio(s)) {
407 for (i = 0; i < s->SG_length; i++) { 412 for (i = 0; i < s->SG_length; i++) {
408 s->PIOarray[i].src = le32_to_cpu(s->SGarray[i].src); 413 s->PIOarray[i].src = le32_to_cpu(s->SGarray[i].src);
@@ -420,7 +425,7 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
420 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER); 425 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER);
421 set_bit(IVTV_F_I_DMA, &itv->i_flags); 426 set_bit(IVTV_F_I_DMA, &itv->i_flags);
422 itv->cur_dma_stream = s->type; 427 itv->cur_dma_stream = s->type;
423 itv->dma_timer.expires = jiffies + HZ / 10; 428 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
424 add_timer(&itv->dma_timer); 429 add_timer(&itv->dma_timer);
425 } 430 }
426} 431}
@@ -437,7 +442,7 @@ static void ivtv_dma_dec_start(struct ivtv_stream *s)
437 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER); 442 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
438 set_bit(IVTV_F_I_DMA, &itv->i_flags); 443 set_bit(IVTV_F_I_DMA, &itv->i_flags);
439 itv->cur_dma_stream = s->type; 444 itv->cur_dma_stream = s->type;
440 itv->dma_timer.expires = jiffies + HZ / 10; 445 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
441 add_timer(&itv->dma_timer); 446 add_timer(&itv->dma_timer);
442} 447}
443 448
@@ -597,7 +602,6 @@ static void ivtv_irq_enc_start_cap(struct ivtv *itv)
597 data[0], data[1], data[2]); 602 data[0], data[1], data[2]);
598 return; 603 return;
599 } 604 }
600 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
601 s = &itv->streams[ivtv_stream_map[data[0]]]; 605 s = &itv->streams[ivtv_stream_map[data[0]]];
602 if (!stream_enc_dma_append(s, data)) { 606 if (!stream_enc_dma_append(s, data)) {
603 set_bit(ivtv_use_pio(s) ? IVTV_F_S_PIO_PENDING : IVTV_F_S_DMA_PENDING, &s->s_flags); 607 set_bit(ivtv_use_pio(s) ? IVTV_F_S_PIO_PENDING : IVTV_F_S_DMA_PENDING, &s->s_flags);
@@ -634,7 +638,6 @@ static void ivtv_irq_enc_vbi_cap(struct ivtv *itv)
634 then start a DMA request for just the VBI data. */ 638 then start a DMA request for just the VBI data. */
635 if (!stream_enc_dma_append(s, data) && 639 if (!stream_enc_dma_append(s, data) &&
636 !test_bit(IVTV_F_S_STREAMING, &s_mpg->s_flags)) { 640 !test_bit(IVTV_F_S_STREAMING, &s_mpg->s_flags)) {
637 set_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
638 set_bit(ivtv_use_pio(s) ? IVTV_F_S_PIO_PENDING : IVTV_F_S_DMA_PENDING, &s->s_flags); 641 set_bit(ivtv_use_pio(s) ? IVTV_F_S_PIO_PENDING : IVTV_F_S_DMA_PENDING, &s->s_flags);
639 } 642 }
640} 643}
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index 6ae42a3b03cc..814a673712b3 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -37,6 +37,7 @@
37#define API_RESULT (1 << 1) /* Allow 1 second for this cmd to end */ 37#define API_RESULT (1 << 1) /* Allow 1 second for this cmd to end */
38#define API_FAST_RESULT (3 << 1) /* Allow 0.1 second for this cmd to end */ 38#define API_FAST_RESULT (3 << 1) /* Allow 0.1 second for this cmd to end */
39#define API_DMA (1 << 3) /* DMA mailbox, has special handling */ 39#define API_DMA (1 << 3) /* DMA mailbox, has special handling */
40#define API_HIGH_VOL (1 << 5) /* High volume command (i.e. called during encoding or decoding) */
40#define API_NO_WAIT_MB (1 << 4) /* Command may not wait for a free mailbox */ 41#define API_NO_WAIT_MB (1 << 4) /* Command may not wait for a free mailbox */
41#define API_NO_WAIT_RES (1 << 5) /* Command may not wait for the result */ 42#define API_NO_WAIT_RES (1 << 5) /* Command may not wait for the result */
42 43
@@ -77,11 +78,11 @@ static const struct ivtv_api_info api_info[256] = {
77 API_ENTRY(CX2341X_ENC_SET_DMA_BLOCK_SIZE, API_CACHE), 78 API_ENTRY(CX2341X_ENC_SET_DMA_BLOCK_SIZE, API_CACHE),
78 API_ENTRY(CX2341X_ENC_GET_PREV_DMA_INFO_MB_10, API_FAST_RESULT), 79 API_ENTRY(CX2341X_ENC_GET_PREV_DMA_INFO_MB_10, API_FAST_RESULT),
79 API_ENTRY(CX2341X_ENC_GET_PREV_DMA_INFO_MB_9, API_FAST_RESULT), 80 API_ENTRY(CX2341X_ENC_GET_PREV_DMA_INFO_MB_9, API_FAST_RESULT),
80 API_ENTRY(CX2341X_ENC_SCHED_DMA_TO_HOST, API_DMA), 81 API_ENTRY(CX2341X_ENC_SCHED_DMA_TO_HOST, API_DMA | API_HIGH_VOL),
81 API_ENTRY(CX2341X_ENC_INITIALIZE_INPUT, API_RESULT), 82 API_ENTRY(CX2341X_ENC_INITIALIZE_INPUT, API_RESULT),
82 API_ENTRY(CX2341X_ENC_SET_FRAME_DROP_RATE, API_CACHE), 83 API_ENTRY(CX2341X_ENC_SET_FRAME_DROP_RATE, API_CACHE),
83 API_ENTRY(CX2341X_ENC_PAUSE_ENCODER, API_RESULT), 84 API_ENTRY(CX2341X_ENC_PAUSE_ENCODER, API_RESULT),
84 API_ENTRY(CX2341X_ENC_REFRESH_INPUT, API_NO_WAIT_MB), 85 API_ENTRY(CX2341X_ENC_REFRESH_INPUT, API_NO_WAIT_MB | API_HIGH_VOL),
85 API_ENTRY(CX2341X_ENC_SET_COPYRIGHT, API_CACHE), 86 API_ENTRY(CX2341X_ENC_SET_COPYRIGHT, API_CACHE),
86 API_ENTRY(CX2341X_ENC_SET_EVENT_NOTIFICATION, API_RESULT), 87 API_ENTRY(CX2341X_ENC_SET_EVENT_NOTIFICATION, API_RESULT),
87 API_ENTRY(CX2341X_ENC_SET_NUM_VSYNC_LINES, API_CACHE), 88 API_ENTRY(CX2341X_ENC_SET_NUM_VSYNC_LINES, API_CACHE),
@@ -102,7 +103,7 @@ static const struct ivtv_api_info api_info[256] = {
102 API_ENTRY(CX2341X_DEC_SET_DMA_BLOCK_SIZE, API_CACHE), 103 API_ENTRY(CX2341X_DEC_SET_DMA_BLOCK_SIZE, API_CACHE),
103 API_ENTRY(CX2341X_DEC_GET_XFER_INFO, API_FAST_RESULT), 104 API_ENTRY(CX2341X_DEC_GET_XFER_INFO, API_FAST_RESULT),
104 API_ENTRY(CX2341X_DEC_GET_DMA_STATUS, API_FAST_RESULT), 105 API_ENTRY(CX2341X_DEC_GET_DMA_STATUS, API_FAST_RESULT),
105 API_ENTRY(CX2341X_DEC_SCHED_DMA_FROM_HOST, API_DMA), 106 API_ENTRY(CX2341X_DEC_SCHED_DMA_FROM_HOST, API_DMA | API_HIGH_VOL),
106 API_ENTRY(CX2341X_DEC_PAUSE_PLAYBACK, API_RESULT), 107 API_ENTRY(CX2341X_DEC_PAUSE_PLAYBACK, API_RESULT),
107 API_ENTRY(CX2341X_DEC_HALT_FW, API_FAST_RESULT), 108 API_ENTRY(CX2341X_DEC_HALT_FW, API_FAST_RESULT),
108 API_ENTRY(CX2341X_DEC_SET_STANDARD, API_CACHE), 109 API_ENTRY(CX2341X_DEC_SET_STANDARD, API_CACHE),
@@ -175,9 +176,9 @@ static int get_mailbox(struct ivtv *itv, struct ivtv_mailbox_data *mbdata, int f
175 176
176 /* Sleep before a retry, if not atomic */ 177 /* Sleep before a retry, if not atomic */
177 if (!(flags & API_NO_WAIT_MB)) { 178 if (!(flags & API_NO_WAIT_MB)) {
178 if (jiffies - then > retries * HZ / 100) 179 if (jiffies - then > msecs_to_jiffies(10*retries))
179 break; 180 break;
180 ivtv_sleep_timeout(HZ / 100, 0); 181 ivtv_msleep_timeout(10, 0);
181 } 182 }
182 } 183 }
183 return -ENODEV; 184 return -ENODEV;
@@ -212,7 +213,7 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
212{ 213{
213 struct ivtv_mailbox_data *mbdata = (cmd >= 128) ? &itv->enc_mbox : &itv->dec_mbox; 214 struct ivtv_mailbox_data *mbdata = (cmd >= 128) ? &itv->enc_mbox : &itv->dec_mbox;
214 volatile struct ivtv_mailbox __iomem *mbox; 215 volatile struct ivtv_mailbox __iomem *mbox;
215 int api_timeout = HZ; 216 int api_timeout = msecs_to_jiffies(1000);
216 int flags, mb, i; 217 int flags, mb, i;
217 unsigned long then; 218 unsigned long then;
218 219
@@ -227,7 +228,12 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
227 return -EINVAL; 228 return -EINVAL;
228 } 229 }
229 230
230 IVTV_DEBUG_API("API Call: %s\n", api_info[cmd].name); 231 if (api_info[cmd].flags & API_HIGH_VOL) {
232 IVTV_DEBUG_HI_API("API Call: %s\n", api_info[cmd].name);
233 }
234 else {
235 IVTV_DEBUG_API("API Call: %s\n", api_info[cmd].name);
236 }
231 237
232 /* clear possibly uninitialized part of data array */ 238 /* clear possibly uninitialized part of data array */
233 for (i = args; i < CX2341X_MBOX_MAX_DATA; i++) 239 for (i = args; i < CX2341X_MBOX_MAX_DATA; i++)
@@ -237,7 +243,7 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
237 data, then just return 0 as there is no need to issue this command again. 243 data, then just return 0 as there is no need to issue this command again.
238 Just an optimization to prevent unnecessary use of mailboxes. */ 244 Just an optimization to prevent unnecessary use of mailboxes. */
239 if (itv->api_cache[cmd].last_jiffies && 245 if (itv->api_cache[cmd].last_jiffies &&
240 jiffies - itv->api_cache[cmd].last_jiffies < HZ * 1800 && 246 jiffies - itv->api_cache[cmd].last_jiffies < msecs_to_jiffies(1800000) &&
241 !memcmp(data, itv->api_cache[cmd].data, sizeof(itv->api_cache[cmd].data))) { 247 !memcmp(data, itv->api_cache[cmd].data, sizeof(itv->api_cache[cmd].data))) {
242 itv->api_cache[cmd].last_jiffies = jiffies; 248 itv->api_cache[cmd].last_jiffies = jiffies;
243 return 0; 249 return 0;
@@ -262,7 +268,7 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
262 } 268 }
263 269
264 if ((flags & API_FAST_RESULT) == API_FAST_RESULT) 270 if ((flags & API_FAST_RESULT) == API_FAST_RESULT)
265 api_timeout = HZ / 10; 271 api_timeout = msecs_to_jiffies(100);
266 272
267 mb = get_mailbox(itv, mbdata, flags); 273 mb = get_mailbox(itv, mbdata, flags);
268 if (mb < 0) { 274 if (mb < 0) {
@@ -295,11 +301,12 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
295 if (flags & API_NO_WAIT_RES) 301 if (flags & API_NO_WAIT_RES)
296 mdelay(1); 302 mdelay(1);
297 else 303 else
298 ivtv_sleep_timeout(HZ / 100, 0); 304 ivtv_msleep_timeout(10, 0);
299 } 305 }
300 if (jiffies - then > HZ / 10) 306 if (jiffies - then > msecs_to_jiffies(100))
301 IVTV_DEBUG_WARN("%s took %lu jiffies (%d per HZ)\n", 307 IVTV_DEBUG_WARN("%s took %u jiffies\n",
302 api_info[cmd].name, jiffies - then, HZ); 308 api_info[cmd].name,
309 jiffies_to_msecs(jiffies - then));
303 310
304 for (i = 0; i < CX2341X_MBOX_MAX_DATA; i++) 311 for (i = 0; i < CX2341X_MBOX_MAX_DATA; i++)
305 data[i] = readl(&mbox->data[i]); 312 data[i] = readl(&mbox->data[i]);
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 287117187499..322b347b67c2 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -565,7 +565,7 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
565 /* Initialize Digitizer for Capture */ 565 /* Initialize Digitizer for Capture */
566 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 566 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
567 567
568 ivtv_sleep_timeout(HZ / 10, 0); 568 ivtv_msleep_timeout(100, 0);
569 } 569 }
570 570
571 /* begin_capture */ 571 /* begin_capture */
@@ -781,8 +781,9 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
781 set_current_state(TASK_INTERRUPTIBLE); 781 set_current_state(TASK_INTERRUPTIBLE);
782 782
783 /* wait 2s for EOS interrupt */ 783 /* wait 2s for EOS interrupt */
784 while (!test_bit(IVTV_F_I_EOS, &itv->i_flags) && jiffies < then + 2 * HZ) { 784 while (!test_bit(IVTV_F_I_EOS, &itv->i_flags) &&
785 schedule_timeout(HZ / 100); 785 jiffies < then + msecs_to_jiffies (2000)) {
786 schedule_timeout(msecs_to_jiffies(10));
786 } 787 }
787 788
788 /* To convert jiffies to ms, we must multiply by 1000 789 /* To convert jiffies to ms, we must multiply by 1000
@@ -821,7 +822,8 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
821 } else if (read_reg(IVTV_REG_DMASTATUS) & 0x02) { 822 } else if (read_reg(IVTV_REG_DMASTATUS) & 0x02) {
822 break; 823 break;
823 } 824 }
824 } while (!ivtv_sleep_timeout(HZ / 100, 1) && then + HZ * 2 > jiffies); 825 } while (!ivtv_msleep_timeout(10, 1) &&
826 then + msecs_to_jiffies(2000) > jiffies);
825 827
826 set_current_state(TASK_RUNNING); 828 set_current_state(TASK_RUNNING);
827 remove_wait_queue(&s->waitq, &wait); 829 remove_wait_queue(&s->waitq, &wait);
@@ -892,7 +894,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
892 break; 894 break;
893 tmp = data[3]; 895 tmp = data[3];
894 } 896 }
895 if (ivtv_sleep_timeout(HZ/10, 1)) 897 if (ivtv_msleep_timeout(100, 1))
896 break; 898 break;
897 } 899 }
898 } 900 }
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index f2a2f34cd626..17f1e2e9a66b 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -86,9 +86,9 @@ static const int disp_modes[8][3] =
86 86
87 87
88 88
89#define PAGE_WAIT (300*HZ/1000) /* Time between requesting page and */ 89#define PAGE_WAIT msecs_to_jiffies(300) /* Time between requesting page and */
90 /* checking status bits */ 90 /* checking status bits */
91#define PGBUF_EXPIRE (15*HZ) /* Time to wait before retransmitting */ 91#define PGBUF_EXPIRE msecs_to_jiffies(15000) /* Time to wait before retransmitting */
92 /* page regardless of infobits */ 92 /* page regardless of infobits */
93typedef struct { 93typedef struct {
94 u8 pgbuf[VTX_VIRTUALSIZE]; /* Page-buffer */ 94 u8 pgbuf[VTX_VIRTUALSIZE]; /* Page-buffer */
@@ -115,8 +115,8 @@ struct saa5249_device
115#define CCTWR 34 /* I²C write/read-address of vtx-chip */ 115#define CCTWR 34 /* I²C write/read-address of vtx-chip */
116#define CCTRD 35 116#define CCTRD 35
117#define NOACK_REPEAT 10 /* Retry access this many times on failure */ 117#define NOACK_REPEAT 10 /* Retry access this many times on failure */
118#define CLEAR_DELAY (HZ/20) /* Time required to clear a page */ 118#define CLEAR_DELAY msecs_to_jiffies(50) /* Time required to clear a page */
119#define READY_TIMEOUT (30*HZ/1000) /* Time to wait for ready signal of I²C-bus interface */ 119#define READY_TIMEOUT msecs_to_jiffies(30) /* Time to wait for ready signal of I2C-bus interface */
120#define INIT_DELAY 500 /* Time in usec to wait at initialization of CEA interface */ 120#define INIT_DELAY 500 /* Time in usec to wait at initialization of CEA interface */
121#define START_DELAY 10 /* Time in usec to wait before starting write-cycle (CEA) */ 121#define START_DELAY 10 /* Time in usec to wait before starting write-cycle (CEA) */
122 122
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 676b9970eb2e..061134a7ba9f 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -208,7 +208,7 @@ determine_norm (struct i2c_client *client)
208 saa7110_write_block(client, initseq, sizeof(initseq)); 208 saa7110_write_block(client, initseq, sizeof(initseq));
209 saa7110_selmux(client, decoder->input); 209 saa7110_selmux(client, decoder->input);
210 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); 210 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE);
211 schedule_timeout(HZ/4); 211 schedule_timeout(msecs_to_jiffies(250));
212 finish_wait(&decoder->wq, &wait); 212 finish_wait(&decoder->wq, &wait);
213 status = saa7110_read(client); 213 status = saa7110_read(client);
214 if (status & 0x40) { 214 if (status & 0x40) {
@@ -249,7 +249,7 @@ determine_norm (struct i2c_client *client)
249 //saa7110_write(client,0x2E,0x9A); 249 //saa7110_write(client,0x2E,0x9A);
250 250
251 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); 251 prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE);
252 schedule_timeout(HZ/4); 252 schedule_timeout(msecs_to_jiffies(250));
253 finish_wait(&decoder->wq, &wait); 253 finish_wait(&decoder->wq, &wait);
254 254
255 status = saa7110_read(client); 255 status = saa7110_read(client);
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index d32a856192d7..346255468dad 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -314,7 +314,7 @@ struct saa7134_board {
314#define INTERLACE_ON 1 314#define INTERLACE_ON 1
315#define INTERLACE_OFF 2 315#define INTERLACE_OFF 2
316 316
317#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */ 317#define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
318 318
319struct saa7134_dev; 319struct saa7134_dev;
320struct saa7134_dma; 320struct saa7134_dma;
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 9da338dc4f3b..cffb011590e3 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -290,7 +290,7 @@ static int chip_thread(void *data)
290 desc->checkmode(chip); 290 desc->checkmode(chip);
291 291
292 /* schedule next check */ 292 /* schedule next check */
293 mod_timer(&chip->wt, jiffies+2*HZ); 293 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
294 } 294 }
295 295
296 v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name); 296 v4l_dbg(1, debug, &chip->c, "%s: thread exiting\n", chip->c.name);
@@ -1770,7 +1770,7 @@ static int chip_command(struct i2c_client *client,
1770 desc->setmode(chip,VIDEO_SOUND_MONO); 1770 desc->setmode(chip,VIDEO_SOUND_MONO);
1771 if (chip->prevmode != VIDEO_SOUND_MONO) 1771 if (chip->prevmode != VIDEO_SOUND_MONO)
1772 chip->prevmode = -1; /* reset previous mode */ 1772 chip->prevmode = -1; /* reset previous mode */
1773 mod_timer(&chip->wt, jiffies+2*HZ); 1773 mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000));
1774 /* the thread will call checkmode() later */ 1774 /* the thread will call checkmode() later */
1775 } 1775 }
1776 break; 1776 break;
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 13ee550d3215..d2915d3530ea 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -939,16 +939,25 @@ int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qc
939 When no more controls are available 0 is returned. */ 939 When no more controls are available 0 is returned. */
940u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id) 940u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
941{ 941{
942 u32 ctrl_class; 942 u32 ctrl_class = V4L2_CTRL_ID2CLASS(id);
943 const u32 *pctrl; 943 const u32 *pctrl;
944 944
945 /* if no query is desired, then just return the control ID */
946 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0)
947 return id;
948 if (ctrl_classes == NULL) 945 if (ctrl_classes == NULL)
949 return 0; 946 return 0;
947
948 /* if no query is desired, then check if the ID is part of ctrl_classes */
949 if ((id & V4L2_CTRL_FLAG_NEXT_CTRL) == 0) {
950 /* find class */
951 while (*ctrl_classes && V4L2_CTRL_ID2CLASS(**ctrl_classes) != ctrl_class)
952 ctrl_classes++;
953 if (*ctrl_classes == NULL)
954 return 0;
955 pctrl = *ctrl_classes;
956 /* find control ID */
957 while (*pctrl && *pctrl != id) pctrl++;
958 return *pctrl ? id : 0;
959 }
950 id &= V4L2_CTRL_ID_MASK; 960 id &= V4L2_CTRL_ID_MASK;
951 ctrl_class = V4L2_CTRL_ID2CLASS(id);
952 id++; /* select next control */ 961 id++; /* select next control */
953 /* find first class that matches (or is greater than) the class of 962 /* find first class that matches (or is greater than) the class of
954 the ID */ 963 the ID */
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index e94a9a6036f5..a0c1647a2ba4 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -2080,7 +2080,7 @@ static int vino_wait_for_frame(struct vino_channel_settings *vcs)
2080 2080
2081 /* to ensure that schedule_timeout will return immediately 2081 /* to ensure that schedule_timeout will return immediately
2082 * if VINO interrupt was triggered meanwhile */ 2082 * if VINO interrupt was triggered meanwhile */
2083 schedule_timeout_interruptible(HZ / 10); 2083 schedule_timeout_interruptible(msecs_to_jiffies(100));
2084 2084
2085 if (signal_pending(current)) 2085 if (signal_pending(current))
2086 err = -EINTR; 2086 err = -EINTR;
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index 8f6741a28a47..1bf4cbec6a87 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -321,12 +321,14 @@ static int wm8739_probe(struct i2c_adapter *adapter)
321 321
322static int wm8739_detach(struct i2c_client *client) 322static int wm8739_detach(struct i2c_client *client)
323{ 323{
324 struct wm8739_state *state = i2c_get_clientdata(client);
324 int err; 325 int err;
325 326
326 err = i2c_detach_client(client); 327 err = i2c_detach_client(client);
327 if (err) 328 if (err)
328 return err; 329 return err;
329 330
331 kfree(state);
330 kfree(client); 332 kfree(client);
331 return 0; 333 return 0;
332} 334}
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 4df5d30d4d09..9f7e894ef962 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -222,12 +222,14 @@ static int wm8775_probe(struct i2c_adapter *adapter)
222 222
223static int wm8775_detach(struct i2c_client *client) 223static int wm8775_detach(struct i2c_client *client)
224{ 224{
225 struct wm8775_state *state = i2c_get_clientdata(client);
225 int err; 226 int err;
226 227
227 err = i2c_detach_client(client); 228 err = i2c_detach_client(client);
228 if (err) { 229 if (err) {
229 return err; 230 return err;
230 } 231 }
232 kfree(state);
231 kfree(client); 233 kfree(client);
232 234
233 return 0; 235 return 0;
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 1d516f24ba53..aaaa61ea4217 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -150,6 +150,7 @@ config THINKPAD_ACPI
150 depends on X86 && ACPI 150 depends on X86 && ACPI
151 select BACKLIGHT_CLASS_DEVICE 151 select BACKLIGHT_CLASS_DEVICE
152 select HWMON 152 select HWMON
153 select NVRAM
153 ---help--- 154 ---help---
154 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds 155 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
155 support for Fn-Fx key combinations, Bluetooth control, video 156 support for Fn-Fx key combinations, Bluetooth control, video
@@ -196,4 +197,17 @@ config THINKPAD_ACPI_BAY
196 197
197 If you are not sure, say Y here. 198 If you are not sure, say Y here.
198 199
200config THINKPAD_ACPI_INPUT_ENABLED
201 bool "Enable input layer support by default"
202 depends on THINKPAD_ACPI
203 default y
204 ---help---
205 Enables hot key handling over the input layer by default. If unset,
206 the driver does not enable any hot key handling by default, and also
207 starts up with a mostly empty keymap.
208
209 If you are not sure, say Y here. Say N to retain the deprecated
210 behavior of ibm-acpi, and thinkpad-acpi for kernels up to 2.6.21.
211
212
199endif # MISC_DEVICES 213endif # MISC_DEVICES
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index 9623eaf4f89f..303e48ca0e8a 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -142,43 +142,124 @@ struct sony_laptop_keypress {
142 int key; 142 int key;
143}; 143};
144 144
145/* Correspondance table between sonypi events and input layer events */ 145/* Correspondance table between sonypi events
146static struct { 146 * and input layer indexes in the keymap
147 int sonypiev; 147 */
148 int inputev; 148static int sony_laptop_input_index[] = {
149} sony_laptop_inputkeys[] = { 149 -1, /* no event */
150 { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA }, 150 -1, /* SONYPI_EVENT_JOGDIAL_DOWN */
151 { SONYPI_EVENT_FNKEY_ONLY, KEY_FN }, 151 -1, /* SONYPI_EVENT_JOGDIAL_UP */
152 { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC }, 152 -1, /* SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */
153 { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 }, 153 -1, /* SONYPI_EVENT_JOGDIAL_UP_PRESSED */
154 { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 }, 154 -1, /* SONYPI_EVENT_JOGDIAL_PRESSED */
155 { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 }, 155 -1, /* SONYPI_EVENT_JOGDIAL_RELEASED */
156 { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 }, 156 0, /* SONYPI_EVENT_CAPTURE_PRESSED */
157 { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 }, 157 1, /* SONYPI_EVENT_CAPTURE_RELEASED */
158 { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 }, 158 2, /* SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
159 { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 }, 159 3, /* SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
160 { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 }, 160 4, /* SONYPI_EVENT_FNKEY_ESC */
161 { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 }, 161 5, /* SONYPI_EVENT_FNKEY_F1 */
162 { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 }, 162 6, /* SONYPI_EVENT_FNKEY_F2 */
163 { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 }, 163 7, /* SONYPI_EVENT_FNKEY_F3 */
164 { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 }, 164 8, /* SONYPI_EVENT_FNKEY_F4 */
165 { SONYPI_EVENT_FNKEY_1, KEY_FN_1 }, 165 9, /* SONYPI_EVENT_FNKEY_F5 */
166 { SONYPI_EVENT_FNKEY_2, KEY_FN_2 }, 166 10, /* SONYPI_EVENT_FNKEY_F6 */
167 { SONYPI_EVENT_FNKEY_D, KEY_FN_D }, 167 11, /* SONYPI_EVENT_FNKEY_F7 */
168 { SONYPI_EVENT_FNKEY_E, KEY_FN_E }, 168 12, /* SONYPI_EVENT_FNKEY_F8 */
169 { SONYPI_EVENT_FNKEY_F, KEY_FN_F }, 169 13, /* SONYPI_EVENT_FNKEY_F9 */
170 { SONYPI_EVENT_FNKEY_S, KEY_FN_S }, 170 14, /* SONYPI_EVENT_FNKEY_F10 */
171 { SONYPI_EVENT_FNKEY_B, KEY_FN_B }, 171 15, /* SONYPI_EVENT_FNKEY_F11 */
172 { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE }, 172 16, /* SONYPI_EVENT_FNKEY_F12 */
173 { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE }, 173 17, /* SONYPI_EVENT_FNKEY_1 */
174 { SONYPI_EVENT_PKEY_P1, KEY_PROG1 }, 174 18, /* SONYPI_EVENT_FNKEY_2 */
175 { SONYPI_EVENT_PKEY_P2, KEY_PROG2 }, 175 19, /* SONYPI_EVENT_FNKEY_D */
176 { SONYPI_EVENT_PKEY_P3, KEY_PROG3 }, 176 20, /* SONYPI_EVENT_FNKEY_E */
177 { SONYPI_EVENT_BACK_PRESSED, KEY_BACK }, 177 21, /* SONYPI_EVENT_FNKEY_F */
178 { SONYPI_EVENT_HELP_PRESSED, KEY_HELP }, 178 22, /* SONYPI_EVENT_FNKEY_S */
179 { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM }, 179 23, /* SONYPI_EVENT_FNKEY_B */
180 { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB }, 180 24, /* SONYPI_EVENT_BLUETOOTH_PRESSED */
181 { 0, 0 }, 181 25, /* SONYPI_EVENT_PKEY_P1 */
182 26, /* SONYPI_EVENT_PKEY_P2 */
183 27, /* SONYPI_EVENT_PKEY_P3 */
184 28, /* SONYPI_EVENT_BACK_PRESSED */
185 -1, /* SONYPI_EVENT_LID_CLOSED */
186 -1, /* SONYPI_EVENT_LID_OPENED */
187 29, /* SONYPI_EVENT_BLUETOOTH_ON */
188 30, /* SONYPI_EVENT_BLUETOOTH_OFF */
189 31, /* SONYPI_EVENT_HELP_PRESSED */
190 32, /* SONYPI_EVENT_FNKEY_ONLY */
191 33, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN */
192 34, /* SONYPI_EVENT_JOGDIAL_FAST_UP */
193 35, /* SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
194 36, /* SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
195 37, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
196 38, /* SONYPI_EVENT_JOGDIAL_VFAST_UP */
197 39, /* SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
198 40, /* SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
199 41, /* SONYPI_EVENT_ZOOM_PRESSED */
200 42, /* SONYPI_EVENT_THUMBPHRASE_PRESSED */
201 43, /* SONYPI_EVENT_MEYE_FACE */
202 44, /* SONYPI_EVENT_MEYE_OPPOSITE */
203 45, /* SONYPI_EVENT_MEMORYSTICK_INSERT */
204 46, /* SONYPI_EVENT_MEMORYSTICK_EJECT */
205 -1, /* SONYPI_EVENT_ANYBUTTON_RELEASED */
206 -1, /* SONYPI_EVENT_BATTERY_INSERT */
207 -1, /* SONYPI_EVENT_BATTERY_REMOVE */
208 -1, /* SONYPI_EVENT_FNKEY_RELEASED */
209 47, /* SONYPI_EVENT_WIRELESS_ON */
210 48, /* SONYPI_EVENT_WIRELESS_OFF */
211};
212
213static int sony_laptop_input_keycode_map[] = {
214 KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */
215 KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */
216 KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */
217 KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */
218 KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */
219 KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */
220 KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */
221 KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */
222 KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */
223 KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */
224 KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */
225 KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */
226 KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */
227 KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */
228 KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */
229 KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */
230 KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */
231 KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */
232 KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */
233 KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */
234 KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */
235 KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */
236 KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */
237 KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */
238 KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */
239 KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */
240 KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */
241 KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */
242 KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */
243 KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */
244 KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */
245 KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */
246 KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */
247 KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */
248 KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */
249 KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */
250 KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */
251 KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */
252 KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */
253 KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */
254 KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */
255 KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */
256 BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */
257 KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */
258 KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */
259 KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */
260 KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */
261 KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */
262 KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */
182}; 263};
183 264
184/* release buttons after a short delay if pressed */ 265/* release buttons after a short delay if pressed */
@@ -202,7 +283,6 @@ static void sony_laptop_report_input_event(u8 event)
202 struct input_dev *jog_dev = sony_laptop_input.jog_dev; 283 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
203 struct input_dev *key_dev = sony_laptop_input.key_dev; 284 struct input_dev *key_dev = sony_laptop_input.key_dev;
204 struct sony_laptop_keypress kp = { NULL }; 285 struct sony_laptop_keypress kp = { NULL };
205 int i;
206 286
207 if (event == SONYPI_EVENT_FNKEY_RELEASED) { 287 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
208 /* Nothing, not all VAIOs generate this event */ 288 /* Nothing, not all VAIOs generate this event */
@@ -231,17 +311,22 @@ static void sony_laptop_report_input_event(u8 event)
231 break; 311 break;
232 312
233 default: 313 default:
234 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++) 314 if (event > ARRAY_SIZE (sony_laptop_input_keycode_map)) {
235 if (event == sony_laptop_inputkeys[i].sonypiev) { 315 dprintk("sony_laptop_report_input_event, event not known: %d\n", event);
316 break;
317 }
318 if (sony_laptop_input_index[event] != -1) {
319 kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]];
320 if (kp.key != KEY_UNKNOWN)
236 kp.dev = key_dev; 321 kp.dev = key_dev;
237 kp.key = sony_laptop_inputkeys[i].inputev; 322 }
238 break;
239 }
240 break; 323 break;
241 } 324 }
242 325
243 if (kp.dev) { 326 if (kp.dev) {
244 input_report_key(kp.dev, kp.key, 1); 327 input_report_key(kp.dev, kp.key, 1);
328 /* we emit the scancode so we can always remap the key */
329 input_event(kp.dev, EV_MSC, MSC_SCAN, event);
245 input_sync(kp.dev); 330 input_sync(kp.dev);
246 kfifo_put(sony_laptop_input.fifo, 331 kfifo_put(sony_laptop_input.fifo,
247 (unsigned char *)&kp, sizeof(kp)); 332 (unsigned char *)&kp, sizeof(kp));
@@ -296,11 +381,18 @@ static int sony_laptop_setup_input(void)
296 key_dev->id.vendor = PCI_VENDOR_ID_SONY; 381 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
297 382
298 /* Initialize the Input Drivers: special keys */ 383 /* Initialize the Input Drivers: special keys */
299 key_dev->evbit[0] = BIT(EV_KEY); 384 set_bit(EV_KEY, key_dev->evbit);
300 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++) 385 set_bit(EV_MSC, key_dev->evbit);
301 if (sony_laptop_inputkeys[i].inputev) 386 set_bit(MSC_SCAN, key_dev->mscbit);
302 set_bit(sony_laptop_inputkeys[i].inputev, 387 key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]);
303 key_dev->keybit); 388 key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map);
389 key_dev->keycode = &sony_laptop_input_keycode_map;
390 for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) {
391 if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) {
392 set_bit(sony_laptop_input_keycode_map[i],
393 key_dev->keybit);
394 }
395 }
304 396
305 error = input_register_device(key_dev); 397 error = input_register_device(key_dev);
306 if (error) 398 if (error)
@@ -487,6 +579,14 @@ SNC_HANDLE_NAMES(audiopower_set, "AZPW");
487SNC_HANDLE_NAMES(lanpower_get, "GLNP"); 579SNC_HANDLE_NAMES(lanpower_get, "GLNP");
488SNC_HANDLE_NAMES(lanpower_set, "LNPW"); 580SNC_HANDLE_NAMES(lanpower_set, "LNPW");
489 581
582SNC_HANDLE_NAMES(lidstate_get, "GLID");
583
584SNC_HANDLE_NAMES(indicatorlamp_get, "GILS");
585SNC_HANDLE_NAMES(indicatorlamp_set, "SILS");
586
587SNC_HANDLE_NAMES(gainbass_get, "GMGB");
588SNC_HANDLE_NAMES(gainbass_set, "CMGB");
589
490SNC_HANDLE_NAMES(PID_get, "GPID"); 590SNC_HANDLE_NAMES(PID_get, "GPID");
491 591
492SNC_HANDLE_NAMES(CTR_get, "GCTR"); 592SNC_HANDLE_NAMES(CTR_get, "GCTR");
@@ -507,6 +607,12 @@ static struct sony_nc_value sony_nc_values[] = {
507 boolean_validate, 0), 607 boolean_validate, 0),
508 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set, 608 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
509 boolean_validate, 1), 609 boolean_validate, 1),
610 SNC_HANDLE(lidstate, snc_lidstate_get, NULL,
611 boolean_validate, 0),
612 SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set,
613 boolean_validate, 0),
614 SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set,
615 boolean_validate, 0),
510 /* unknown methods */ 616 /* unknown methods */
511 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1), 617 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
512 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), 618 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
@@ -689,13 +795,116 @@ static struct backlight_ops sony_backlight_ops = {
689}; 795};
690 796
691/* 797/*
798 * New SNC-only Vaios event mapping to driver known keys
799 */
800struct sony_nc_event {
801 u8 data;
802 u8 event;
803};
804
805static struct sony_nc_event *sony_nc_events;
806
807/* Vaio C* --maybe also FE*, N* and AR* ?-- special init sequence
808 * for Fn keys
809 */
810static int sony_nc_C_enable(struct dmi_system_id *id)
811{
812 int result = 0;
813
814 printk(KERN_NOTICE DRV_PFX "detected %s\n", id->ident);
815
816 sony_nc_events = id->driver_data;
817
818 if (acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x4, &result) < 0
819 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x2, &result) < 0
820 || acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x10, &result) < 0
821 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x0, &result) < 0
822 || acpi_callsetfunc(sony_nc_acpi_handle, "SN03", 0x2, &result) < 0
823 || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x101, &result) < 0) {
824 printk(KERN_WARNING DRV_PFX "failed to initialize SNC, some "
825 "functionalities may be missing\n");
826 return 1;
827 }
828 return 0;
829}
830
831static struct sony_nc_event sony_C_events[] = {
832 { 0x81, SONYPI_EVENT_FNKEY_F1 },
833 { 0x01, SONYPI_EVENT_FNKEY_RELEASED },
834 { 0x85, SONYPI_EVENT_FNKEY_F5 },
835 { 0x05, SONYPI_EVENT_FNKEY_RELEASED },
836 { 0x86, SONYPI_EVENT_FNKEY_F6 },
837 { 0x06, SONYPI_EVENT_FNKEY_RELEASED },
838 { 0x87, SONYPI_EVENT_FNKEY_F7 },
839 { 0x07, SONYPI_EVENT_FNKEY_RELEASED },
840 { 0x8A, SONYPI_EVENT_FNKEY_F10 },
841 { 0x0A, SONYPI_EVENT_FNKEY_RELEASED },
842 { 0x8C, SONYPI_EVENT_FNKEY_F12 },
843 { 0x0C, SONYPI_EVENT_FNKEY_RELEASED },
844 { 0, 0 },
845};
846
847/* SNC-only model map */
848struct dmi_system_id sony_nc_ids[] = {
849 {
850 .ident = "Sony Vaio FE Series",
851 .callback = sony_nc_C_enable,
852 .driver_data = sony_C_events,
853 .matches = {
854 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
855 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FE"),
856 },
857 },
858 {
859 .ident = "Sony Vaio C Series",
860 .callback = sony_nc_C_enable,
861 .driver_data = sony_C_events,
862 .matches = {
863 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
864 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"),
865 },
866 },
867 { }
868};
869
870/*
692 * ACPI callbacks 871 * ACPI callbacks
693 */ 872 */
694static void sony_acpi_notify(acpi_handle handle, u32 event, void *data) 873static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
695{ 874{
696 dprintk("sony_acpi_notify, event: %d\n", event); 875 struct sony_nc_event *evmap;
697 sony_laptop_report_input_event(event); 876 u32 ev = event;
698 acpi_bus_generate_event(sony_nc_acpi_device, 1, event); 877 int result;
878
879 if (ev == 0x92) {
880 /* read the key pressed from EC.GECR
881 * A call to SN07 with 0x0202 will do it as well respecting
882 * the current protocol on different OSes
883 *
884 * Note: the path for GECR may be
885 * \_SB.PCI0.LPCB.EC (C, FE, AR, N and friends)
886 * \_SB.PCI0.PIB.EC0 (VGN-FR notifications are sent directly, no GECR)
887 *
888 * TODO: we may want to do the same for the older GHKE -need
889 * dmi list- so this snippet may become one more callback.
890 */
891 if (acpi_callsetfunc(handle, "SN07", 0x0202, &result) < 0)
892 dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev);
893 else
894 ev = result & 0xFF;
895 }
896
897 if (sony_nc_events)
898 for (evmap = sony_nc_events; evmap->event; evmap++) {
899 if (evmap->data == ev) {
900 ev = evmap->event;
901 break;
902 }
903 }
904
905 dprintk("sony_acpi_notify, event: 0x%.2x\n", ev);
906 sony_laptop_report_input_event(ev);
907 acpi_bus_generate_event(sony_nc_acpi_device, 1, ev);
699} 908}
700 909
701static acpi_status sony_walk_callback(acpi_handle handle, u32 level, 910static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
@@ -732,6 +941,10 @@ static int sony_nc_resume(struct acpi_device *device)
732 break; 941 break;
733 } 942 }
734 } 943 }
944
945 /* re-initialize models with specific requirements */
946 dmi_check_system(sony_nc_ids);
947
735 return 0; 948 return 0;
736} 949}
737 950
@@ -750,6 +963,15 @@ static int sony_nc_add(struct acpi_device *device)
750 963
751 sony_nc_acpi_handle = device->handle; 964 sony_nc_acpi_handle = device->handle;
752 965
966 /* read device status */
967 result = acpi_bus_get_status(device);
968 /* bail IFF the above call was successful and the device is not present */
969 if (!result && !device->status.present) {
970 dprintk("Device not present\n");
971 result = -ENODEV;
972 goto outwalk;
973 }
974
753 if (debug) { 975 if (debug) {
754 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle, 976 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
755 1, sony_walk_callback, NULL, NULL); 977 1, sony_walk_callback, NULL, NULL);
@@ -760,6 +982,15 @@ static int sony_nc_add(struct acpi_device *device)
760 } 982 }
761 } 983 }
762 984
985 /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1
986 * should be respected as we already checked for the device presence above */
987 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) {
988 dprintk("Invoking _INI\n");
989 if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI,
990 NULL, NULL)))
991 dprintk("_INI Method failed\n");
992 }
993
763 /* setup input devices and helper fifo */ 994 /* setup input devices and helper fifo */
764 result = sony_laptop_setup_input(); 995 result = sony_laptop_setup_input();
765 if (result) { 996 if (result) {
@@ -772,7 +1003,7 @@ static int sony_nc_add(struct acpi_device *device)
772 ACPI_DEVICE_NOTIFY, 1003 ACPI_DEVICE_NOTIFY,
773 sony_acpi_notify, NULL); 1004 sony_acpi_notify, NULL);
774 if (ACPI_FAILURE(status)) { 1005 if (ACPI_FAILURE(status)) {
775 printk(KERN_WARNING DRV_PFX "unable to install notify handler\n"); 1006 printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status);
776 result = -ENODEV; 1007 result = -ENODEV;
777 goto outinput; 1008 goto outinput;
778 } 1009 }
@@ -795,6 +1026,9 @@ static int sony_nc_add(struct acpi_device *device)
795 1026
796 } 1027 }
797 1028
1029 /* initialize models with specific requirements */
1030 dmi_check_system(sony_nc_ids);
1031
798 result = sony_pf_add(); 1032 result = sony_pf_add();
799 if (result) 1033 if (result)
800 goto outbacklight; 1034 goto outbacklight;
@@ -908,7 +1142,9 @@ static struct acpi_driver sony_nc_driver = {
908#define SONYPI_DEVICE_TYPE2 0x00000002 1142#define SONYPI_DEVICE_TYPE2 0x00000002
909#define SONYPI_DEVICE_TYPE3 0x00000004 1143#define SONYPI_DEVICE_TYPE3 0x00000004
910 1144
911#define SONY_PIC_EV_MASK 0xff 1145#define SONYPI_TYPE1_OFFSET 0x04
1146#define SONYPI_TYPE2_OFFSET 0x12
1147#define SONYPI_TYPE3_OFFSET 0x12
912 1148
913struct sony_pic_ioport { 1149struct sony_pic_ioport {
914 struct acpi_resource_io io; 1150 struct acpi_resource_io io;
@@ -922,6 +1158,7 @@ struct sony_pic_irq {
922 1158
923struct sony_pic_dev { 1159struct sony_pic_dev {
924 int model; 1160 int model;
1161 u16 evport_offset;
925 u8 camera_power; 1162 u8 camera_power;
926 u8 bluetooth_power; 1163 u8 bluetooth_power;
927 u8 wwan_power; 1164 u8 wwan_power;
@@ -1999,20 +2236,17 @@ end:
1999static irqreturn_t sony_pic_irq(int irq, void *dev_id) 2236static irqreturn_t sony_pic_irq(int irq, void *dev_id)
2000{ 2237{
2001 int i, j; 2238 int i, j;
2002 u32 port_val = 0;
2003 u8 ev = 0; 2239 u8 ev = 0;
2004 u8 data_mask = 0; 2240 u8 data_mask = 0;
2005 u8 device_event = 0; 2241 u8 device_event = 0;
2006 2242
2007 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id; 2243 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
2008 2244
2009 acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val, 2245 ev = inb_p(dev->cur_ioport->io.minimum);
2010 dev->cur_ioport->io.address_length); 2246 data_mask = inb_p(dev->cur_ioport->io.minimum + dev->evport_offset);
2011 ev = port_val & SONY_PIC_EV_MASK;
2012 data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
2013 2247
2014 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n", 2248 dprintk("event ([%.2x] [%.2x]) at port 0x%.4x(+0x%.2x)\n",
2015 port_val, ev, data_mask, dev->cur_ioport->io.minimum); 2249 ev, data_mask, dev->cur_ioport->io.minimum, dev->evport_offset);
2016 2250
2017 if (ev == 0x00 || ev == 0xff) 2251 if (ev == 0x00 || ev == 0xff)
2018 return IRQ_HANDLED; 2252 return IRQ_HANDLED;
@@ -2103,6 +2337,20 @@ static int sony_pic_add(struct acpi_device *device)
2103 spic_dev.model = sony_pic_detect_device_type(); 2337 spic_dev.model = sony_pic_detect_device_type();
2104 mutex_init(&spic_dev.lock); 2338 mutex_init(&spic_dev.lock);
2105 2339
2340 /* model specific characteristics */
2341 switch(spic_dev.model) {
2342 case SONYPI_DEVICE_TYPE1:
2343 spic_dev.evport_offset = SONYPI_TYPE1_OFFSET;
2344 break;
2345 case SONYPI_DEVICE_TYPE3:
2346 spic_dev.evport_offset = SONYPI_TYPE3_OFFSET;
2347 break;
2348 case SONYPI_DEVICE_TYPE2:
2349 default:
2350 spic_dev.evport_offset = SONYPI_TYPE2_OFFSET;
2351 break;
2352 }
2353
2106 /* read _PRS resources */ 2354 /* read _PRS resources */
2107 result = sony_pic_possible_resources(device); 2355 result = sony_pic_possible_resources(device);
2108 if (result) { 2356 if (result) {
diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
index 95c0b96e83f2..f15a58f7403f 100644
--- a/drivers/misc/thinkpad_acpi.c
+++ b/drivers/misc/thinkpad_acpi.c
@@ -21,8 +21,8 @@
21 * 02110-1301, USA. 21 * 02110-1301, USA.
22 */ 22 */
23 23
24#define IBM_VERSION "0.14" 24#define IBM_VERSION "0.15"
25#define TPACPI_SYSFS_VERSION 0x000100 25#define TPACPI_SYSFS_VERSION 0x010000
26 26
27/* 27/*
28 * Changelog: 28 * Changelog:
@@ -92,6 +92,29 @@ MODULE_LICENSE("GPL");
92/* Please remove this in year 2009 */ 92/* Please remove this in year 2009 */
93MODULE_ALIAS("ibm_acpi"); 93MODULE_ALIAS("ibm_acpi");
94 94
95/*
96 * DMI matching for module autoloading
97 *
98 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
99 * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads
100 *
101 * Only models listed in thinkwiki will be supported, so add yours
102 * if it is not there yet.
103 */
104#define IBM_BIOS_MODULE_ALIAS(__type) \
105 MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW")
106
107/* Non-ancient thinkpads */
108MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*");
109MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*");
110
111/* Ancient thinkpad BIOSes have to be identified by
112 * BIOS type or model number, and there are far less
113 * BIOS types than model numbers... */
114IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]");
115IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]");
116IBM_BIOS_MODULE_ALIAS("K[U,X-Z]");
117
95#define __unused __attribute__ ((unused)) 118#define __unused __attribute__ ((unused))
96 119
97/**************************************************************************** 120/****************************************************************************
@@ -106,7 +129,7 @@ MODULE_ALIAS("ibm_acpi");
106 * ACPI basic handles 129 * ACPI basic handles
107 */ 130 */
108 131
109static acpi_handle root_handle = NULL; 132static acpi_handle root_handle;
110 133
111#define IBM_HANDLE(object, parent, paths...) \ 134#define IBM_HANDLE(object, parent, paths...) \
112 static acpi_handle object##_handle; \ 135 static acpi_handle object##_handle; \
@@ -487,19 +510,36 @@ static char *next_cmd(char **cmds)
487/**************************************************************************** 510/****************************************************************************
488 **************************************************************************** 511 ****************************************************************************
489 * 512 *
490 * Device model: hwmon and platform 513 * Device model: input, hwmon and platform
491 * 514 *
492 **************************************************************************** 515 ****************************************************************************
493 ****************************************************************************/ 516 ****************************************************************************/
494 517
495static struct platform_device *tpacpi_pdev = NULL; 518static struct platform_device *tpacpi_pdev;
496static struct class_device *tpacpi_hwmon = NULL; 519static struct class_device *tpacpi_hwmon;
520static struct input_dev *tpacpi_inputdev;
521
522
523static int tpacpi_resume_handler(struct platform_device *pdev)
524{
525 struct ibm_struct *ibm, *itmp;
526
527 list_for_each_entry_safe(ibm, itmp,
528 &tpacpi_all_drivers,
529 all_drivers) {
530 if (ibm->resume)
531 (ibm->resume)();
532 }
533
534 return 0;
535}
497 536
498static struct platform_driver tpacpi_pdriver = { 537static struct platform_driver tpacpi_pdriver = {
499 .driver = { 538 .driver = {
500 .name = IBM_DRVR_NAME, 539 .name = IBM_DRVR_NAME,
501 .owner = THIS_MODULE, 540 .owner = THIS_MODULE,
502 }, 541 },
542 .resume = tpacpi_resume_handler,
503}; 543};
504 544
505 545
@@ -677,9 +717,19 @@ static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
677 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); 717 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
678 printk(IBM_INFO "%s\n", IBM_URL); 718 printk(IBM_INFO "%s\n", IBM_URL);
679 719
680 if (ibm_thinkpad_ec_found) 720 printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n",
681 printk(IBM_INFO "ThinkPad EC firmware %s\n", 721 (thinkpad_id.bios_version_str) ?
682 ibm_thinkpad_ec_found); 722 thinkpad_id.bios_version_str : "unknown",
723 (thinkpad_id.ec_version_str) ?
724 thinkpad_id.ec_version_str : "unknown");
725
726 if (thinkpad_id.vendor && thinkpad_id.model_str)
727 printk(IBM_INFO "%s %s\n",
728 (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ?
729 "IBM" : ((thinkpad_id.vendor ==
730 PCI_VENDOR_ID_LENOVO) ?
731 "Lenovo" : "Unknown vendor"),
732 thinkpad_id.model_str);
683 733
684 return 0; 734 return 0;
685} 735}
@@ -704,16 +754,28 @@ static struct ibm_struct thinkpad_acpi_driver_data = {
704 */ 754 */
705 755
706static int hotkey_orig_status; 756static int hotkey_orig_status;
707static int hotkey_orig_mask; 757static u32 hotkey_orig_mask;
758static u32 hotkey_all_mask;
759static u32 hotkey_reserved_mask;
760
761static u16 *hotkey_keycode_map;
708 762
709static struct attribute_set *hotkey_dev_attributes = NULL; 763static struct attribute_set *hotkey_dev_attributes;
764
765static int hotkey_get_wlsw(int *status)
766{
767 if (!acpi_evalf(hkey_handle, status, "WLSW", "d"))
768 return -EIO;
769 return 0;
770}
710 771
711/* sysfs hotkey enable ------------------------------------------------- */ 772/* sysfs hotkey enable ------------------------------------------------- */
712static ssize_t hotkey_enable_show(struct device *dev, 773static ssize_t hotkey_enable_show(struct device *dev,
713 struct device_attribute *attr, 774 struct device_attribute *attr,
714 char *buf) 775 char *buf)
715{ 776{
716 int res, status, mask; 777 int res, status;
778 u32 mask;
717 779
718 res = hotkey_get(&status, &mask); 780 res = hotkey_get(&status, &mask);
719 if (res) 781 if (res)
@@ -727,7 +789,8 @@ static ssize_t hotkey_enable_store(struct device *dev,
727 const char *buf, size_t count) 789 const char *buf, size_t count)
728{ 790{
729 unsigned long t; 791 unsigned long t;
730 int res, status, mask; 792 int res, status;
793 u32 mask;
731 794
732 if (parse_strtoul(buf, 1, &t)) 795 if (parse_strtoul(buf, 1, &t))
733 return -EINVAL; 796 return -EINVAL;
@@ -748,13 +811,14 @@ static ssize_t hotkey_mask_show(struct device *dev,
748 struct device_attribute *attr, 811 struct device_attribute *attr,
749 char *buf) 812 char *buf)
750{ 813{
751 int res, status, mask; 814 int res, status;
815 u32 mask;
752 816
753 res = hotkey_get(&status, &mask); 817 res = hotkey_get(&status, &mask);
754 if (res) 818 if (res)
755 return res; 819 return res;
756 820
757 return snprintf(buf, PAGE_SIZE, "0x%04x\n", mask); 821 return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask);
758} 822}
759 823
760static ssize_t hotkey_mask_store(struct device *dev, 824static ssize_t hotkey_mask_store(struct device *dev,
@@ -762,9 +826,10 @@ static ssize_t hotkey_mask_store(struct device *dev,
762 const char *buf, size_t count) 826 const char *buf, size_t count)
763{ 827{
764 unsigned long t; 828 unsigned long t;
765 int res, status, mask; 829 int res, status;
830 u32 mask;
766 831
767 if (parse_strtoul(buf, 0xffff, &t)) 832 if (parse_strtoul(buf, 0xffffffffUL, &t))
768 return -EINVAL; 833 return -EINVAL;
769 834
770 res = hotkey_get(&status, &mask); 835 res = hotkey_get(&status, &mask);
@@ -794,26 +859,123 @@ static ssize_t hotkey_bios_mask_show(struct device *dev,
794 struct device_attribute *attr, 859 struct device_attribute *attr,
795 char *buf) 860 char *buf)
796{ 861{
797 return snprintf(buf, PAGE_SIZE, "0x%04x\n", hotkey_orig_mask); 862 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask);
798} 863}
799 864
800static struct device_attribute dev_attr_hotkey_bios_mask = 865static struct device_attribute dev_attr_hotkey_bios_mask =
801 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); 866 __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL);
802 867
868/* sysfs hotkey all_mask ----------------------------------------------- */
869static ssize_t hotkey_all_mask_show(struct device *dev,
870 struct device_attribute *attr,
871 char *buf)
872{
873 return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask);
874}
875
876static struct device_attribute dev_attr_hotkey_all_mask =
877 __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL);
878
879/* sysfs hotkey recommended_mask --------------------------------------- */
880static ssize_t hotkey_recommended_mask_show(struct device *dev,
881 struct device_attribute *attr,
882 char *buf)
883{
884 return snprintf(buf, PAGE_SIZE, "0x%08x\n",
885 hotkey_all_mask & ~hotkey_reserved_mask);
886}
887
888static struct device_attribute dev_attr_hotkey_recommended_mask =
889 __ATTR(hotkey_recommended_mask, S_IRUGO,
890 hotkey_recommended_mask_show, NULL);
891
892/* sysfs hotkey radio_sw ----------------------------------------------- */
893static ssize_t hotkey_radio_sw_show(struct device *dev,
894 struct device_attribute *attr,
895 char *buf)
896{
897 int res, s;
898 res = hotkey_get_wlsw(&s);
899 if (res < 0)
900 return res;
901
902 return snprintf(buf, PAGE_SIZE, "%d\n", !!s);
903}
904
905static struct device_attribute dev_attr_hotkey_radio_sw =
906 __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL);
907
803/* --------------------------------------------------------------------- */ 908/* --------------------------------------------------------------------- */
804 909
805static struct attribute *hotkey_mask_attributes[] = { 910static struct attribute *hotkey_mask_attributes[] = {
806 &dev_attr_hotkey_mask.attr, 911 &dev_attr_hotkey_mask.attr,
807 &dev_attr_hotkey_bios_enabled.attr, 912 &dev_attr_hotkey_bios_enabled.attr,
808 &dev_attr_hotkey_bios_mask.attr, 913 &dev_attr_hotkey_bios_mask.attr,
914 &dev_attr_hotkey_all_mask.attr,
915 &dev_attr_hotkey_recommended_mask.attr,
809}; 916};
810 917
811static int __init hotkey_init(struct ibm_init_struct *iibm) 918static int __init hotkey_init(struct ibm_init_struct *iibm)
812{ 919{
813 int res; 920
921 static u16 ibm_keycode_map[] __initdata = {
922 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
923 KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP,
924 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
925 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
926 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
927 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
928 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
929 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
930 KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */
931 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
932 KEY_RESERVED, /* 0x10: FN+END (brightness down) */
933 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
934 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
935 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
936 KEY_RESERVED, /* 0x14: VOLUME UP */
937 KEY_RESERVED, /* 0x15: VOLUME DOWN */
938 KEY_RESERVED, /* 0x16: MUTE */
939 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
940 /* (assignments unknown, please report if found) */
941 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
942 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
943 };
944 static u16 lenovo_keycode_map[] __initdata = {
945 /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */
946 KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP,
947 KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8,
948 KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND,
949 /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */
950 KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */
951 KEY_UNKNOWN, /* 0x0D: FN+INSERT */
952 KEY_UNKNOWN, /* 0x0E: FN+DELETE */
953 KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */
954 /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */
955 KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */
956 KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */
957 KEY_UNKNOWN, /* 0x12: FN+PGDOWN */
958 KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */
959 KEY_RESERVED, /* 0x14: VOLUME UP */
960 KEY_RESERVED, /* 0x15: VOLUME DOWN */
961 KEY_RESERVED, /* 0x16: MUTE */
962 KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */
963 /* (assignments unknown, please report if found) */
964 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
965 KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
966 };
967
968#define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map)
969#define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map)
970#define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0])
971
972 int res, i;
973 int status;
814 974
815 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); 975 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
816 976
977 BUG_ON(!tpacpi_inputdev);
978
817 IBM_ACPIHANDLE_INIT(hkey); 979 IBM_ACPIHANDLE_INIT(hkey);
818 mutex_init(&hotkey_mutex); 980 mutex_init(&hotkey_mutex);
819 981
@@ -824,7 +986,7 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
824 str_supported(tp_features.hotkey)); 986 str_supported(tp_features.hotkey));
825 987
826 if (tp_features.hotkey) { 988 if (tp_features.hotkey) {
827 hotkey_dev_attributes = create_attr_set(4, NULL); 989 hotkey_dev_attributes = create_attr_set(7, NULL);
828 if (!hotkey_dev_attributes) 990 if (!hotkey_dev_attributes)
829 return -ENOMEM; 991 return -ENOMEM;
830 res = add_to_attr_set(hotkey_dev_attributes, 992 res = add_to_attr_set(hotkey_dev_attributes,
@@ -840,19 +1002,92 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
840 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", 1002 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
841 str_supported(tp_features.hotkey_mask)); 1003 str_supported(tp_features.hotkey_mask));
842 1004
1005 if (tp_features.hotkey_mask) {
1006 /* MHKA available in A31, R40, R40e, T4x, X31, and later */
1007 if (!acpi_evalf(hkey_handle, &hotkey_all_mask,
1008 "MHKA", "qd"))
1009 hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */
1010 }
1011
843 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); 1012 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
844 if (!res && tp_features.hotkey_mask) { 1013 if (!res && tp_features.hotkey_mask) {
845 res = add_many_to_attr_set(hotkey_dev_attributes, 1014 res = add_many_to_attr_set(hotkey_dev_attributes,
846 hotkey_mask_attributes, 1015 hotkey_mask_attributes,
847 ARRAY_SIZE(hotkey_mask_attributes)); 1016 ARRAY_SIZE(hotkey_mask_attributes));
848 } 1017 }
1018
1019 /* Not all thinkpads have a hardware radio switch */
1020 if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) {
1021 tp_features.hotkey_wlsw = 1;
1022 printk(IBM_INFO
1023 "radio switch found; radios are %s\n",
1024 enabled(status, 0));
1025 res = add_to_attr_set(hotkey_dev_attributes,
1026 &dev_attr_hotkey_radio_sw.attr);
1027 }
1028
849 if (!res) 1029 if (!res)
850 res = register_attr_set_with_sysfs( 1030 res = register_attr_set_with_sysfs(
851 hotkey_dev_attributes, 1031 hotkey_dev_attributes,
852 &tpacpi_pdev->dev.kobj); 1032 &tpacpi_pdev->dev.kobj);
1033 if (res)
1034 return res;
1035
1036 /* Set up key map */
1037
1038 hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE,
1039 GFP_KERNEL);
1040 if (!hotkey_keycode_map) {
1041 printk(IBM_ERR "failed to allocate memory for key map\n");
1042 return -ENOMEM;
1043 }
1044
1045 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) {
1046 dbg_printk(TPACPI_DBG_INIT,
1047 "using Lenovo default hot key map\n");
1048 memcpy(hotkey_keycode_map, &lenovo_keycode_map,
1049 TPACPI_HOTKEY_MAP_SIZE);
1050 } else {
1051 dbg_printk(TPACPI_DBG_INIT,
1052 "using IBM default hot key map\n");
1053 memcpy(hotkey_keycode_map, &ibm_keycode_map,
1054 TPACPI_HOTKEY_MAP_SIZE);
1055 }
853 1056
1057#ifndef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1058 for (i = 0; i < 12; i++)
1059 hotkey_keycode_map[i] = KEY_UNKNOWN;
1060#endif /* ! CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
1061
1062 set_bit(EV_KEY, tpacpi_inputdev->evbit);
1063 set_bit(EV_MSC, tpacpi_inputdev->evbit);
1064 set_bit(MSC_SCAN, tpacpi_inputdev->mscbit);
1065 tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE;
1066 tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN;
1067 tpacpi_inputdev->keycode = hotkey_keycode_map;
1068 for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) {
1069 if (hotkey_keycode_map[i] != KEY_RESERVED) {
1070 set_bit(hotkey_keycode_map[i],
1071 tpacpi_inputdev->keybit);
1072 } else {
1073 if (i < sizeof(hotkey_reserved_mask)*8)
1074 hotkey_reserved_mask |= 1 << i;
1075 }
1076 }
1077
1078 if (tp_features.hotkey_wlsw) {
1079 set_bit(EV_SW, tpacpi_inputdev->evbit);
1080 set_bit(SW_RADIO, tpacpi_inputdev->swbit);
1081 }
1082
1083#ifdef CONFIG_THINKPAD_ACPI_INPUT_ENABLED
1084 dbg_printk(TPACPI_DBG_INIT,
1085 "enabling hot key handling\n");
1086 res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask)
1087 | hotkey_orig_mask);
854 if (res) 1088 if (res)
855 return res; 1089 return res;
1090#endif /* CONFIG_THINKPAD_ACPI_INPUT_ENABLED */
856 } 1091 }
857 1092
858 return (tp_features.hotkey)? 0 : 1; 1093 return (tp_features.hotkey)? 0 : 1;
@@ -875,22 +1110,101 @@ static void hotkey_exit(void)
875 } 1110 }
876} 1111}
877 1112
1113static void tpacpi_input_send_key(unsigned int scancode,
1114 unsigned int keycode)
1115{
1116 if (keycode != KEY_RESERVED) {
1117 input_report_key(tpacpi_inputdev, keycode, 1);
1118 if (keycode == KEY_UNKNOWN)
1119 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1120 scancode);
1121 input_sync(tpacpi_inputdev);
1122
1123 input_report_key(tpacpi_inputdev, keycode, 0);
1124 if (keycode == KEY_UNKNOWN)
1125 input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN,
1126 scancode);
1127 input_sync(tpacpi_inputdev);
1128 }
1129}
1130
1131static void tpacpi_input_send_radiosw(void)
1132{
1133 int wlsw;
1134
1135 if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw))
1136 input_report_switch(tpacpi_inputdev,
1137 SW_RADIO, !!wlsw);
1138}
1139
878static void hotkey_notify(struct ibm_struct *ibm, u32 event) 1140static void hotkey_notify(struct ibm_struct *ibm, u32 event)
879{ 1141{
880 int hkey; 1142 u32 hkey;
1143 unsigned int keycode, scancode;
1144 int sendacpi = 1;
1145
1146 if (event == 0x80 && acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) {
1147 if (tpacpi_inputdev->users > 0) {
1148 switch (hkey >> 12) {
1149 case 1:
1150 /* 0x1000-0x1FFF: key presses */
1151 scancode = hkey & 0xfff;
1152 if (scancode > 0 && scancode < 0x21) {
1153 scancode--;
1154 keycode = hotkey_keycode_map[scancode];
1155 tpacpi_input_send_key(scancode, keycode);
1156 sendacpi = (keycode == KEY_RESERVED
1157 || keycode == KEY_UNKNOWN);
1158 } else {
1159 printk(IBM_ERR
1160 "hotkey 0x%04x out of range for keyboard map\n",
1161 hkey);
1162 }
1163 break;
1164 case 5:
1165 /* 0x5000-0x5FFF: LID */
1166 /* we don't handle it through this path, just
1167 * eat up known LID events */
1168 if (hkey != 0x5001 && hkey != 0x5002) {
1169 printk(IBM_ERR
1170 "unknown LID-related hotkey event: 0x%04x\n",
1171 hkey);
1172 }
1173 break;
1174 case 7:
1175 /* 0x7000-0x7FFF: misc */
1176 if (tp_features.hotkey_wlsw && hkey == 0x7000) {
1177 tpacpi_input_send_radiosw();
1178 sendacpi = 0;
1179 break;
1180 }
1181 /* fallthrough to default */
1182 default:
1183 /* case 2: dock-related */
1184 /* 0x2305 - T43 waking up due to bay lever eject while aslept */
1185 /* case 3: ultra-bay related. maybe bay in dock? */
1186 /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */
1187 printk(IBM_NOTICE "unhandled hotkey event 0x%04x\n", hkey);
1188 }
1189 }
881 1190
882 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) 1191 if (sendacpi)
883 acpi_bus_generate_event(ibm->acpi->device, event, hkey); 1192 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
884 else { 1193 } else {
885 printk(IBM_ERR "unknown hotkey event %d\n", event); 1194 printk(IBM_ERR "unknown hotkey notification event %d\n", event);
886 acpi_bus_generate_event(ibm->acpi->device, event, 0); 1195 acpi_bus_generate_event(ibm->acpi->device, event, 0);
887 } 1196 }
888} 1197}
889 1198
1199static void hotkey_resume(void)
1200{
1201 tpacpi_input_send_radiosw();
1202}
1203
890/* 1204/*
891 * Call with hotkey_mutex held 1205 * Call with hotkey_mutex held
892 */ 1206 */
893static int hotkey_get(int *status, int *mask) 1207static int hotkey_get(int *status, u32 *mask)
894{ 1208{
895 if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) 1209 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
896 return -EIO; 1210 return -EIO;
@@ -905,7 +1219,7 @@ static int hotkey_get(int *status, int *mask)
905/* 1219/*
906 * Call with hotkey_mutex held 1220 * Call with hotkey_mutex held
907 */ 1221 */
908static int hotkey_set(int status, int mask) 1222static int hotkey_set(int status, u32 mask)
909{ 1223{
910 int i; 1224 int i;
911 1225
@@ -926,7 +1240,8 @@ static int hotkey_set(int status, int mask)
926/* procfs -------------------------------------------------------------- */ 1240/* procfs -------------------------------------------------------------- */
927static int hotkey_read(char *p) 1241static int hotkey_read(char *p)
928{ 1242{
929 int res, status, mask; 1243 int res, status;
1244 u32 mask;
930 int len = 0; 1245 int len = 0;
931 1246
932 if (!tp_features.hotkey) { 1247 if (!tp_features.hotkey) {
@@ -944,7 +1259,7 @@ static int hotkey_read(char *p)
944 1259
945 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); 1260 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
946 if (tp_features.hotkey_mask) { 1261 if (tp_features.hotkey_mask) {
947 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); 1262 len += sprintf(p + len, "mask:\t\t0x%08x\n", mask);
948 len += sprintf(p + len, 1263 len += sprintf(p + len,
949 "commands:\tenable, disable, reset, <mask>\n"); 1264 "commands:\tenable, disable, reset, <mask>\n");
950 } else { 1265 } else {
@@ -957,7 +1272,8 @@ static int hotkey_read(char *p)
957 1272
958static int hotkey_write(char *buf) 1273static int hotkey_write(char *buf)
959{ 1274{
960 int res, status, mask; 1275 int res, status;
1276 u32 mask;
961 char *cmd; 1277 char *cmd;
962 int do_cmd = 0; 1278 int do_cmd = 0;
963 1279
@@ -1012,6 +1328,7 @@ static struct ibm_struct hotkey_driver_data = {
1012 .read = hotkey_read, 1328 .read = hotkey_read,
1013 .write = hotkey_write, 1329 .write = hotkey_write,
1014 .exit = hotkey_exit, 1330 .exit = hotkey_exit,
1331 .resume = hotkey_resume,
1015 .acpi = &ibm_hotkey_acpidriver, 1332 .acpi = &ibm_hotkey_acpidriver,
1016}; 1333};
1017 1334
@@ -1770,7 +2087,10 @@ static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
1770 .type = ACPI_SYSTEM_NOTIFY, 2087 .type = ACPI_SYSTEM_NOTIFY,
1771 }, 2088 },
1772 { 2089 {
1773 .hid = IBM_PCI_HID, 2090 /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING.
2091 * We just use it to get notifications of dock hotplug
2092 * in very old thinkpads */
2093 .hid = PCI_ROOT_HID_STRING,
1774 .notify = dock_notify, 2094 .notify = dock_notify,
1775 .handle = &pci_handle, 2095 .handle = &pci_handle,
1776 .type = ACPI_SYSTEM_NOTIFY, 2096 .type = ACPI_SYSTEM_NOTIFY,
@@ -1829,7 +2149,7 @@ static int __init dock_init2(struct ibm_init_struct *iibm)
1829static void dock_notify(struct ibm_struct *ibm, u32 event) 2149static void dock_notify(struct ibm_struct *ibm, u32 event)
1830{ 2150{
1831 int docked = dock_docked(); 2151 int docked = dock_docked();
1832 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID); 2152 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, PCI_ROOT_HID_STRING);
1833 2153
1834 if (event == 1 && !pci) /* 570 */ 2154 if (event == 1 && !pci) /* 570 */
1835 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */ 2155 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
@@ -2389,7 +2709,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
2389 2709
2390 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); 2710 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
2391 2711
2392 if (ibm_thinkpad_ec_found && experimental) { 2712 if (thinkpad_id.ec_model) {
2393 /* 2713 /*
2394 * Direct EC access mode: sensors at registers 2714 * Direct EC access mode: sensors at registers
2395 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for 2715 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
@@ -2533,6 +2853,8 @@ static int thermal_get_sensor(int idx, s32 *value)
2533 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); 2853 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
2534 if (!acpi_evalf(ec_handle, &t, tmpi, "d")) 2854 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
2535 return -EIO; 2855 return -EIO;
2856 if (t > 127 || t < -127)
2857 t = TP_EC_THERMAL_TMP_NA;
2536 *value = t * 1000; 2858 *value = t * 1000;
2537 return 0; 2859 return 0;
2538 } 2860 }
@@ -2671,22 +2993,39 @@ static struct ibm_struct ecdump_driver_data = {
2671 * Backlight/brightness subdriver 2993 * Backlight/brightness subdriver
2672 */ 2994 */
2673 2995
2674static struct backlight_device *ibm_backlight_device = NULL; 2996static struct backlight_device *ibm_backlight_device;
2675 2997
2676static struct backlight_ops ibm_backlight_data = { 2998static struct backlight_ops ibm_backlight_data = {
2677 .get_brightness = brightness_get, 2999 .get_brightness = brightness_get,
2678 .update_status = brightness_update_status, 3000 .update_status = brightness_update_status,
2679}; 3001};
2680 3002
3003static struct mutex brightness_mutex;
3004
2681static int __init brightness_init(struct ibm_init_struct *iibm) 3005static int __init brightness_init(struct ibm_init_struct *iibm)
2682{ 3006{
2683 int b; 3007 int b;
2684 3008
2685 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); 3009 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2686 3010
3011 mutex_init(&brightness_mutex);
3012
3013 if (!brightness_mode) {
3014 if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO)
3015 brightness_mode = 2;
3016 else
3017 brightness_mode = 3;
3018
3019 dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n",
3020 brightness_mode);
3021 }
3022
3023 if (brightness_mode > 3)
3024 return -EINVAL;
3025
2687 b = brightness_get(NULL); 3026 b = brightness_get(NULL);
2688 if (b < 0) 3027 if (b < 0)
2689 return b; 3028 return 1;
2690 3029
2691 ibm_backlight_device = backlight_device_register( 3030 ibm_backlight_device = backlight_device_register(
2692 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, 3031 TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL,
@@ -2722,34 +3061,79 @@ static int brightness_update_status(struct backlight_device *bd)
2722 bd->props.brightness : 0); 3061 bd->props.brightness : 0);
2723} 3062}
2724 3063
3064/*
3065 * ThinkPads can read brightness from two places: EC 0x31, or
3066 * CMOS NVRAM byte 0x5E, bits 0-3.
3067 */
2725static int brightness_get(struct backlight_device *bd) 3068static int brightness_get(struct backlight_device *bd)
2726{ 3069{
2727 u8 level; 3070 u8 lec = 0, lcmos = 0, level = 0;
2728 if (!acpi_ec_read(brightness_offset, &level))
2729 return -EIO;
2730 3071
2731 level &= 0x7; 3072 if (brightness_mode & 1) {
3073 if (!acpi_ec_read(brightness_offset, &lec))
3074 return -EIO;
3075 lec &= 7;
3076 level = lec;
3077 };
3078 if (brightness_mode & 2) {
3079 lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS)
3080 & TP_NVRAM_MASK_LEVEL_BRIGHTNESS)
3081 >> TP_NVRAM_POS_LEVEL_BRIGHTNESS;
3082 level = lcmos;
3083 }
3084
3085 if (brightness_mode == 3 && lec != lcmos) {
3086 printk(IBM_ERR
3087 "CMOS NVRAM (%u) and EC (%u) do not agree "
3088 "on display brightness level\n",
3089 (unsigned int) lcmos,
3090 (unsigned int) lec);
3091 return -EIO;
3092 }
2732 3093
2733 return level; 3094 return level;
2734} 3095}
2735 3096
2736static int brightness_set(int value) 3097static int brightness_set(int value)
2737{ 3098{
2738 int cmos_cmd, inc, i; 3099 int cmos_cmd, inc, i, res;
2739 int current_value = brightness_get(NULL); 3100 int current_value;
3101
3102 if (value > 7)
3103 return -EINVAL;
2740 3104
2741 value &= 7; 3105 res = mutex_lock_interruptible(&brightness_mutex);
3106 if (res < 0)
3107 return res;
3108
3109 current_value = brightness_get(NULL);
3110 if (current_value < 0) {
3111 res = current_value;
3112 goto errout;
3113 }
2742 3114
2743 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; 3115 cmos_cmd = value > current_value ?
3116 TP_CMOS_BRIGHTNESS_UP :
3117 TP_CMOS_BRIGHTNESS_DOWN;
2744 inc = value > current_value ? 1 : -1; 3118 inc = value > current_value ? 1 : -1;
3119
3120 res = 0;
2745 for (i = current_value; i != value; i += inc) { 3121 for (i = current_value; i != value; i += inc) {
2746 if (issue_thinkpad_cmos_command(cmos_cmd)) 3122 if ((brightness_mode & 2) &&
2747 return -EIO; 3123 issue_thinkpad_cmos_command(cmos_cmd)) {
2748 if (!acpi_ec_write(brightness_offset, i + inc)) 3124 res = -EIO;
2749 return -EIO; 3125 goto errout;
3126 }
3127 if ((brightness_mode & 1) &&
3128 !acpi_ec_write(brightness_offset, i + inc)) {
3129 res = -EIO;
3130 goto errout;;
3131 }
2750 } 3132 }
2751 3133
2752 return 0; 3134errout:
3135 mutex_unlock(&brightness_mutex);
3136 return res;
2753} 3137}
2754 3138
2755static int brightness_read(char *p) 3139static int brightness_read(char *p)
@@ -3273,20 +3657,19 @@ static int __init fan_init(struct ibm_init_struct *iibm)
3273 * Enable for TP-1Y (T43), TP-78 (R51e), 3657 * Enable for TP-1Y (T43), TP-78 (R51e),
3274 * TP-76 (R52), TP-70 (T43, R52), which are known 3658 * TP-76 (R52), TP-70 (T43, R52), which are known
3275 * to be buggy. */ 3659 * to be buggy. */
3276 if (fan_control_initial_status == 0x07 && 3660 if (fan_control_initial_status == 0x07) {
3277 ibm_thinkpad_ec_found && 3661 switch (thinkpad_id.ec_model) {
3278 ((ibm_thinkpad_ec_found[0] == '1' && 3662 case 0x5931: /* TP-1Y */
3279 ibm_thinkpad_ec_found[1] == 'Y') || 3663 case 0x3837: /* TP-78 */
3280 (ibm_thinkpad_ec_found[0] == '7' && 3664 case 0x3637: /* TP-76 */
3281 (ibm_thinkpad_ec_found[1] == '6' || 3665 case 0x3037: /* TP-70 */
3282 ibm_thinkpad_ec_found[1] == '8' || 3666 printk(IBM_NOTICE
3283 ibm_thinkpad_ec_found[1] == '0')) 3667 "fan_init: initial fan status is "
3284 )) { 3668 "unknown, assuming it is in auto "
3285 printk(IBM_NOTICE 3669 "mode\n");
3286 "fan_init: initial fan status is " 3670 tp_features.fan_ctrl_status_undef = 1;
3287 "unknown, assuming it is in auto " 3671 ;;
3288 "mode\n"); 3672 }
3289 tp_features.fan_ctrl_status_undef = 1;
3290 } 3673 }
3291 } else { 3674 } else {
3292 printk(IBM_ERR 3675 printk(IBM_ERR
@@ -3474,7 +3857,7 @@ static void fan_watchdog_fire(struct work_struct *ignored)
3474 3857
3475static void fan_watchdog_reset(void) 3858static void fan_watchdog_reset(void)
3476{ 3859{
3477 static int fan_watchdog_active = 0; 3860 static int fan_watchdog_active;
3478 3861
3479 if (fan_control_access_mode == TPACPI_FAN_WR_NONE) 3862 if (fan_control_access_mode == TPACPI_FAN_WR_NONE)
3480 return; 3863 return;
@@ -3877,7 +4260,7 @@ static struct ibm_struct fan_driver_data = {
3877 ****************************************************************************/ 4260 ****************************************************************************/
3878 4261
3879/* /proc support */ 4262/* /proc support */
3880static struct proc_dir_entry *proc_dir = NULL; 4263static struct proc_dir_entry *proc_dir;
3881 4264
3882/* Subdriver registry */ 4265/* Subdriver registry */
3883static LIST_HEAD(tpacpi_all_drivers); 4266static LIST_HEAD(tpacpi_all_drivers);
@@ -4020,13 +4403,30 @@ static void ibm_exit(struct ibm_struct *ibm)
4020 4403
4021/* Probing */ 4404/* Probing */
4022 4405
4023static char *ibm_thinkpad_ec_found = NULL; 4406static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp)
4024
4025static char* __init check_dmi_for_ec(void)
4026{ 4407{
4027 struct dmi_device *dev = NULL; 4408 struct dmi_device *dev = NULL;
4028 char ec_fw_string[18]; 4409 char ec_fw_string[18];
4029 4410
4411 if (!tp)
4412 return;
4413
4414 memset(tp, 0, sizeof(*tp));
4415
4416 if (dmi_name_in_vendors("IBM"))
4417 tp->vendor = PCI_VENDOR_ID_IBM;
4418 else if (dmi_name_in_vendors("LENOVO"))
4419 tp->vendor = PCI_VENDOR_ID_LENOVO;
4420 else
4421 return;
4422
4423 tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION),
4424 GFP_KERNEL);
4425 if (!tp->bios_version_str)
4426 return;
4427 tp->bios_model = tp->bios_version_str[0]
4428 | (tp->bios_version_str[1] << 8);
4429
4030 /* 4430 /*
4031 * ThinkPad T23 or newer, A31 or newer, R50e or newer, 4431 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
4032 * X32 or newer, all Z series; Some models must have an 4432 * X32 or newer, all Z series; Some models must have an
@@ -4040,10 +4440,20 @@ static char* __init check_dmi_for_ec(void)
4040 ec_fw_string) == 1) { 4440 ec_fw_string) == 1) {
4041 ec_fw_string[sizeof(ec_fw_string) - 1] = 0; 4441 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
4042 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; 4442 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
4043 return kstrdup(ec_fw_string, GFP_KERNEL); 4443
4444 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL);
4445 tp->ec_model = ec_fw_string[0]
4446 | (ec_fw_string[1] << 8);
4447 break;
4044 } 4448 }
4045 } 4449 }
4046 return NULL; 4450
4451 tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION),
4452 GFP_KERNEL);
4453 if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) {
4454 kfree(tp->model_str);
4455 tp->model_str = NULL;
4456 }
4047} 4457}
4048 4458
4049static int __init probe_for_thinkpad(void) 4459static int __init probe_for_thinkpad(void)
@@ -4057,7 +4467,7 @@ static int __init probe_for_thinkpad(void)
4057 * Non-ancient models have better DMI tagging, but very old models 4467 * Non-ancient models have better DMI tagging, but very old models
4058 * don't. 4468 * don't.
4059 */ 4469 */
4060 is_thinkpad = dmi_name_in_vendors("ThinkPad"); 4470 is_thinkpad = (thinkpad_id.model_str != NULL);
4061 4471
4062 /* ec is required because many other handles are relative to it */ 4472 /* ec is required because many other handles are relative to it */
4063 IBM_ACPIHANDLE_INIT(ec); 4473 IBM_ACPIHANDLE_INIT(ec);
@@ -4073,7 +4483,7 @@ static int __init probe_for_thinkpad(void)
4073 * false positives a damn great deal 4483 * false positives a damn great deal
4074 */ 4484 */
4075 if (!is_thinkpad) 4485 if (!is_thinkpad)
4076 is_thinkpad = dmi_name_in_vendors("IBM"); 4486 is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM);
4077 4487
4078 if (!is_thinkpad && !force_load) 4488 if (!is_thinkpad && !force_load)
4079 return -ENODEV; 4489 return -ENODEV;
@@ -4185,10 +4595,13 @@ static u32 dbg_level;
4185module_param_named(debug, dbg_level, uint, 0); 4595module_param_named(debug, dbg_level, uint, 0);
4186 4596
4187static int force_load; 4597static int force_load;
4188module_param(force_load, int, 0); 4598module_param(force_load, bool, 0);
4189 4599
4190static int fan_control_allowed; 4600static int fan_control_allowed;
4191module_param_named(fan_control, fan_control_allowed, int, 0); 4601module_param_named(fan_control, fan_control_allowed, bool, 0);
4602
4603static int brightness_mode;
4604module_param_named(brightness_mode, brightness_mode, int, 0);
4192 4605
4193#define IBM_PARAM(feature) \ 4606#define IBM_PARAM(feature) \
4194 module_param_call(feature, set_ibm_param, NULL, NULL, 0) 4607 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
@@ -4216,12 +4629,16 @@ static int __init thinkpad_acpi_module_init(void)
4216 int ret, i; 4629 int ret, i;
4217 4630
4218 /* Driver-level probe */ 4631 /* Driver-level probe */
4632
4633 get_thinkpad_model_data(&thinkpad_id);
4219 ret = probe_for_thinkpad(); 4634 ret = probe_for_thinkpad();
4220 if (ret) 4635 if (ret) {
4636 thinkpad_acpi_module_exit();
4221 return ret; 4637 return ret;
4638 }
4222 4639
4223 /* Driver initialization */ 4640 /* Driver initialization */
4224 ibm_thinkpad_ec_found = check_dmi_for_ec(); 4641
4225 IBM_ACPIHANDLE_INIT(ecrd); 4642 IBM_ACPIHANDLE_INIT(ecrd);
4226 IBM_ACPIHANDLE_INIT(ecwr); 4643 IBM_ACPIHANDLE_INIT(ecwr);
4227 4644
@@ -4265,6 +4682,22 @@ static int __init thinkpad_acpi_module_init(void)
4265 thinkpad_acpi_module_exit(); 4682 thinkpad_acpi_module_exit();
4266 return ret; 4683 return ret;
4267 } 4684 }
4685 tpacpi_inputdev = input_allocate_device();
4686 if (!tpacpi_inputdev) {
4687 printk(IBM_ERR "unable to allocate input device\n");
4688 thinkpad_acpi_module_exit();
4689 return -ENOMEM;
4690 } else {
4691 /* Prepare input device, but don't register */
4692 tpacpi_inputdev->name = "ThinkPad Extra Buttons";
4693 tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0";
4694 tpacpi_inputdev->id.bustype = BUS_HOST;
4695 tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ?
4696 thinkpad_id.vendor :
4697 PCI_VENDOR_ID_IBM;
4698 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT;
4699 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION;
4700 }
4268 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { 4701 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
4269 ret = ibm_init(&ibms_init[i]); 4702 ret = ibm_init(&ibms_init[i]);
4270 if (ret >= 0 && *ibms_init[i].param) 4703 if (ret >= 0 && *ibms_init[i].param)
@@ -4274,6 +4707,14 @@ static int __init thinkpad_acpi_module_init(void)
4274 return ret; 4707 return ret;
4275 } 4708 }
4276 } 4709 }
4710 ret = input_register_device(tpacpi_inputdev);
4711 if (ret < 0) {
4712 printk(IBM_ERR "unable to register input device\n");
4713 thinkpad_acpi_module_exit();
4714 return ret;
4715 } else {
4716 tp_features.input_device_registered = 1;
4717 }
4277 4718
4278 return 0; 4719 return 0;
4279} 4720}
@@ -4290,6 +4731,13 @@ static void thinkpad_acpi_module_exit(void)
4290 4731
4291 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); 4732 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
4292 4733
4734 if (tpacpi_inputdev) {
4735 if (tp_features.input_device_registered)
4736 input_unregister_device(tpacpi_inputdev);
4737 else
4738 input_free_device(tpacpi_inputdev);
4739 }
4740
4293 if (tpacpi_hwmon) 4741 if (tpacpi_hwmon)
4294 hwmon_device_unregister(tpacpi_hwmon); 4742 hwmon_device_unregister(tpacpi_hwmon);
4295 4743
@@ -4302,7 +4750,9 @@ static void thinkpad_acpi_module_exit(void)
4302 if (proc_dir) 4750 if (proc_dir)
4303 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); 4751 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
4304 4752
4305 kfree(ibm_thinkpad_ec_found); 4753 kfree(thinkpad_id.bios_version_str);
4754 kfree(thinkpad_id.ec_version_str);
4755 kfree(thinkpad_id.model_str);
4306} 4756}
4307 4757
4308module_init(thinkpad_acpi_module_init); 4758module_init(thinkpad_acpi_module_init);
diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
index 72d62f2dabb9..b7a4a888cc8b 100644
--- a/drivers/misc/thinkpad_acpi.h
+++ b/drivers/misc/thinkpad_acpi.h
@@ -32,6 +32,7 @@
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34 34
35#include <linux/nvram.h>
35#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
36#include <linux/sysfs.h> 37#include <linux/sysfs.h>
37#include <linux/backlight.h> 38#include <linux/backlight.h>
@@ -39,6 +40,7 @@
39#include <linux/platform_device.h> 40#include <linux/platform_device.h>
40#include <linux/hwmon.h> 41#include <linux/hwmon.h>
41#include <linux/hwmon-sysfs.h> 42#include <linux/hwmon-sysfs.h>
43#include <linux/input.h>
42#include <asm/uaccess.h> 44#include <asm/uaccess.h>
43 45
44#include <linux/dmi.h> 46#include <linux/dmi.h>
@@ -48,6 +50,7 @@
48#include <acpi/acpi_drivers.h> 50#include <acpi/acpi_drivers.h>
49#include <acpi/acnamesp.h> 51#include <acpi/acnamesp.h>
50 52
53#include <linux/pci_ids.h>
51 54
52/**************************************************************************** 55/****************************************************************************
53 * Main driver 56 * Main driver
@@ -78,6 +81,11 @@
78#define TP_CMOS_BRIGHTNESS_UP 4 81#define TP_CMOS_BRIGHTNESS_UP 4
79#define TP_CMOS_BRIGHTNESS_DOWN 5 82#define TP_CMOS_BRIGHTNESS_DOWN 5
80 83
84/* ThinkPad CMOS NVRAM constants */
85#define TP_NVRAM_ADDR_BRIGHTNESS 0x5e
86#define TP_NVRAM_MASK_LEVEL_BRIGHTNESS 0x07
87#define TP_NVRAM_POS_LEVEL_BRIGHTNESS 0
88
81#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off") 89#define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
82#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled") 90#define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
83#define strlencmp(a,b) (strncmp((a), (b), strlen(b))) 91#define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
@@ -98,9 +106,13 @@ static const char *str_supported(int is_supported);
98#define vdbg_printk(a_dbg_level, format, arg...) 106#define vdbg_printk(a_dbg_level, format, arg...)
99#endif 107#endif
100 108
109/* Input IDs */
110#define TPACPI_HKEY_INPUT_VENDOR PCI_VENDOR_ID_IBM
111#define TPACPI_HKEY_INPUT_PRODUCT 0x5054 /* "TP" */
112#define TPACPI_HKEY_INPUT_VERSION 0x4101
113
101/* ACPI HIDs */ 114/* ACPI HIDs */
102#define IBM_HKEY_HID "IBM0068" 115#define IBM_HKEY_HID "IBM0068"
103#define IBM_PCI_HID "PNP0A03"
104 116
105/* ACPI helpers */ 117/* ACPI helpers */
106static int __must_check acpi_evalf(acpi_handle handle, 118static int __must_check acpi_evalf(acpi_handle handle,
@@ -161,6 +173,7 @@ static int parse_strtoul(const char *buf, unsigned long max,
161static struct platform_device *tpacpi_pdev; 173static struct platform_device *tpacpi_pdev;
162static struct class_device *tpacpi_hwmon; 174static struct class_device *tpacpi_hwmon;
163static struct platform_driver tpacpi_pdriver; 175static struct platform_driver tpacpi_pdriver;
176static struct input_dev *tpacpi_inputdev;
164static int tpacpi_create_driver_attributes(struct device_driver *drv); 177static int tpacpi_create_driver_attributes(struct device_driver *drv);
165static void tpacpi_remove_driver_attributes(struct device_driver *drv); 178static void tpacpi_remove_driver_attributes(struct device_driver *drv);
166 179
@@ -168,9 +181,7 @@ static void tpacpi_remove_driver_attributes(struct device_driver *drv);
168static int experimental; 181static int experimental;
169static u32 dbg_level; 182static u32 dbg_level;
170static int force_load; 183static int force_load;
171static char *ibm_thinkpad_ec_found;
172 184
173static char* check_dmi_for_ec(void);
174static int thinkpad_acpi_module_init(void); 185static int thinkpad_acpi_module_init(void);
175static void thinkpad_acpi_module_exit(void); 186static void thinkpad_acpi_module_exit(void);
176 187
@@ -197,6 +208,7 @@ struct ibm_struct {
197 int (*read) (char *); 208 int (*read) (char *);
198 int (*write) (char *); 209 int (*write) (char *);
199 void (*exit) (void); 210 void (*exit) (void);
211 void (*resume) (void);
200 212
201 struct list_head all_drivers; 213 struct list_head all_drivers;
202 214
@@ -228,12 +240,29 @@ static struct {
228 u16 bluetooth:1; 240 u16 bluetooth:1;
229 u16 hotkey:1; 241 u16 hotkey:1;
230 u16 hotkey_mask:1; 242 u16 hotkey_mask:1;
243 u16 hotkey_wlsw:1;
231 u16 light:1; 244 u16 light:1;
232 u16 light_status:1; 245 u16 light_status:1;
233 u16 wan:1; 246 u16 wan:1;
234 u16 fan_ctrl_status_undef:1; 247 u16 fan_ctrl_status_undef:1;
248 u16 input_device_registered:1;
235} tp_features; 249} tp_features;
236 250
251struct thinkpad_id_data {
252 unsigned int vendor; /* ThinkPad vendor:
253 * PCI_VENDOR_ID_IBM/PCI_VENDOR_ID_LENOVO */
254
255 char *bios_version_str; /* Something like 1ZET51WW (1.03z) */
256 char *ec_version_str; /* Something like 1ZHT51WW-1.04a */
257
258 u16 bios_model; /* Big Endian, TP-1Y = 0x5931, 0 = unknown */
259 u16 ec_model;
260
261 char *model_str;
262};
263
264static struct thinkpad_id_data thinkpad_id;
265
237static struct list_head tpacpi_all_drivers; 266static struct list_head tpacpi_all_drivers;
238 267
239static struct ibm_init_struct ibms_init[]; 268static struct ibm_init_struct ibms_init[];
@@ -300,6 +329,7 @@ static int bluetooth_write(char *buf);
300 329
301static struct backlight_device *ibm_backlight_device; 330static struct backlight_device *ibm_backlight_device;
302static int brightness_offset = 0x31; 331static int brightness_offset = 0x31;
332static int brightness_mode;
303 333
304static int brightness_init(struct ibm_init_struct *iibm); 334static int brightness_init(struct ibm_init_struct *iibm);
305static void brightness_exit(void); 335static void brightness_exit(void);
@@ -415,14 +445,14 @@ static int fan_write_cmd_watchdog(const char *cmd, int *rc);
415 */ 445 */
416 446
417static int hotkey_orig_status; 447static int hotkey_orig_status;
418static int hotkey_orig_mask; 448static u32 hotkey_orig_mask;
419 449
420static struct mutex hotkey_mutex; 450static struct mutex hotkey_mutex;
421 451
422static int hotkey_init(struct ibm_init_struct *iibm); 452static int hotkey_init(struct ibm_init_struct *iibm);
423static void hotkey_exit(void); 453static void hotkey_exit(void);
424static int hotkey_get(int *status, int *mask); 454static int hotkey_get(int *status, u32 *mask);
425static int hotkey_set(int status, int mask); 455static int hotkey_set(int status, u32 mask);
426static void hotkey_notify(struct ibm_struct *ibm, u32 event); 456static void hotkey_notify(struct ibm_struct *ibm, u32 event);
427static int hotkey_read(char *p); 457static int hotkey_read(char *p);
428static int hotkey_write(char *buf); 458static int hotkey_write(char *buf);
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index 28c881895ab7..15aab374127e 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -903,8 +903,10 @@ static int __init at91_mci_probe(struct platform_device *pdev)
903 /* 903 /*
904 * Add host to MMC layer 904 * Add host to MMC layer
905 */ 905 */
906 if (host->board->det_pin) 906 if (host->board->det_pin) {
907 host->present = !at91_get_gpio_value(host->board->det_pin); 907 host->present = !at91_get_gpio_value(host->board->det_pin);
908 device_init_wakeup(&pdev->dev, 1);
909 }
908 else 910 else
909 host->present = -1; 911 host->present = -1;
910 912
@@ -940,6 +942,7 @@ static int __exit at91_mci_remove(struct platform_device *pdev)
940 host = mmc_priv(mmc); 942 host = mmc_priv(mmc);
941 943
942 if (host->present != -1) { 944 if (host->present != -1) {
945 device_init_wakeup(&pdev->dev, 0);
943 free_irq(host->board->det_pin, host); 946 free_irq(host->board->det_pin, host);
944 cancel_delayed_work(&host->mmc->detect); 947 cancel_delayed_work(&host->mmc->detect);
945 } 948 }
@@ -966,8 +969,12 @@ static int __exit at91_mci_remove(struct platform_device *pdev)
966static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state) 969static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
967{ 970{
968 struct mmc_host *mmc = platform_get_drvdata(pdev); 971 struct mmc_host *mmc = platform_get_drvdata(pdev);
972 struct at91mci_host *host = mmc_priv(mmc);
969 int ret = 0; 973 int ret = 0;
970 974
975 if (device_may_wakeup(&pdev->dev))
976 enable_irq_wake(host->board->det_pin);
977
971 if (mmc) 978 if (mmc)
972 ret = mmc_suspend_host(mmc, state); 979 ret = mmc_suspend_host(mmc, state);
973 980
@@ -977,8 +984,12 @@ static int at91_mci_suspend(struct platform_device *pdev, pm_message_t state)
977static int at91_mci_resume(struct platform_device *pdev) 984static int at91_mci_resume(struct platform_device *pdev)
978{ 985{
979 struct mmc_host *mmc = platform_get_drvdata(pdev); 986 struct mmc_host *mmc = platform_get_drvdata(pdev);
987 struct at91mci_host *host = mmc_priv(mmc);
980 int ret = 0; 988 int ret = 0;
981 989
990 if (device_may_wakeup(&pdev->dev))
991 disable_irq_wake(host->board->det_pin);
992
982 if (mmc) 993 if (mmc)
983 ret = mmc_resume_host(mmc); 994 ret = mmc_resume_host(mmc);
984 995
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 10d15c39d003..4a24db028d87 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1024,6 +1024,8 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
1024 1024
1025 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK); 1025 intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
1026 1026
1027 intmask &= ~SDHCI_INT_ERROR;
1028
1027 if (intmask & SDHCI_INT_BUS_POWER) { 1029 if (intmask & SDHCI_INT_BUS_POWER) {
1028 printk(KERN_ERR "%s: Card is consuming too much power!\n", 1030 printk(KERN_ERR "%s: Card is consuming too much power!\n",
1029 mmc_hostname(host->mmc)); 1031 mmc_hostname(host->mmc));
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 7400f4bc114f..a6c870480b8a 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -107,6 +107,7 @@
107#define SDHCI_INT_CARD_INSERT 0x00000040 107#define SDHCI_INT_CARD_INSERT 0x00000040
108#define SDHCI_INT_CARD_REMOVE 0x00000080 108#define SDHCI_INT_CARD_REMOVE 0x00000080
109#define SDHCI_INT_CARD_INT 0x00000100 109#define SDHCI_INT_CARD_INT 0x00000100
110#define SDHCI_INT_ERROR 0x00008000
110#define SDHCI_INT_TIMEOUT 0x00010000 111#define SDHCI_INT_TIMEOUT 0x00010000
111#define SDHCI_INT_CRC 0x00020000 112#define SDHCI_INT_CRC 0x00020000
112#define SDHCI_INT_END_BIT 0x00040000 113#define SDHCI_INT_END_BIT 0x00040000
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 3073f679584b..f8a602caabcb 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -5,6 +5,7 @@
5 5
6menuconfig NETDEVICES 6menuconfig NETDEVICES
7 default y if UML 7 default y if UML
8 depends on NET
8 bool "Network device support" 9 bool "Network device support"
9 ---help--- 10 ---help---
10 You can say N here if you don't intend to connect your Linux box to 11 You can say N here if you don't intend to connect your Linux box to
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index 829da9a1d113..2098d0af8ff5 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -155,6 +155,15 @@ config KINGSUN_DONGLE
155 To compile it as a module, choose M here: the module will be called 155 To compile it as a module, choose M here: the module will be called
156 kingsun-sir. 156 kingsun-sir.
157 157
158config EP7211_DONGLE
159 tristate "EP7211 I/R support"
160 depends on IRTTY_SIR && ARCH_EP7211 && IRDA && EXPERIMENTAL
161 help
162 Say Y here if you want to build support for the Cirrus logic
163 EP7211 chipset's infrared module.
164
165
166
158comment "Old SIR device drivers" 167comment "Old SIR device drivers"
159 168
160config IRPORT_SIR 169config IRPORT_SIR
@@ -355,7 +364,7 @@ config WINBOND_FIR
355 364
356config TOSHIBA_FIR 365config TOSHIBA_FIR
357 tristate "Toshiba Type-O IR Port" 366 tristate "Toshiba Type-O IR Port"
358 depends on IRDA && PCI && !64BIT 367 depends on IRDA && PCI && !64BIT && VIRT_TO_BUS
359 help 368 help
360 Say Y here if you want to build support for the Toshiba Type-O IR 369 Say Y here if you want to build support for the Toshiba Type-O IR
361 and Donau oboe chipsets. These chipsets are used by the Toshiba 370 and Donau oboe chipsets. These chipsets are used by the Toshiba
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index 233a2f923730..2808ef5c7b79 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_MCP2120_DONGLE) += mcp2120-sir.o
45obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o 45obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o
46obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o 46obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o
47obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o 47obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o
48obj-$(CONFIG_EP7211_DONGLE) += ep7211-sir.o
48obj-$(CONFIG_KINGSUN_DONGLE) += kingsun-sir.o 49obj-$(CONFIG_KINGSUN_DONGLE) += kingsun-sir.o
49 50
50# The SIR helper module 51# The SIR helper module
diff --git a/drivers/net/irda/ep7211-sir.c b/drivers/net/irda/ep7211-sir.c
new file mode 100644
index 000000000000..831572429bb9
--- /dev/null
+++ b/drivers/net/irda/ep7211-sir.c
@@ -0,0 +1,89 @@
1/*
2 * IR port driver for the Cirrus Logic EP7211 processor.
3 *
4 * Copyright 2001, Blue Mug Inc. All rights reserved.
5 * Copyright 2007, Samuel Ortiz <samuel@sortiz.org>
6 */
7#include <linux/module.h>
8#include <linux/delay.h>
9#include <linux/tty.h>
10#include <linux/init.h>
11#include <linux/spinlock.h>
12
13#include <net/irda/irda.h>
14#include <net/irda/irda_device.h>
15
16#include <asm/io.h>
17#include <asm/hardware.h>
18
19#include "sir-dev.h"
20
21#define MIN_DELAY 25 /* 15 us, but wait a little more to be sure */
22#define MAX_DELAY 10000 /* 1 ms */
23
24static int ep7211_open(struct sir_dev *dev);
25static int ep7211_close(struct sir_dev *dev);
26static int ep7211_change_speed(struct sir_dev *dev, unsigned speed);
27static int ep7211_reset(struct sir_dev *dev);
28
29static struct dongle_driver ep7211 = {
30 .owner = THIS_MODULE,
31 .driver_name = "EP7211 IR driver",
32 .type = IRDA_EP7211_DONGLE,
33 .open = ep7211_open,
34 .close = ep7211_close,
35 .reset = ep7211_reset,
36 .set_speed = ep7211_change_speed,
37};
38
39static int __init ep7211_sir_init(void)
40{
41 return irda_register_dongle(&ep7211);
42}
43
44static void __exit ep7211_sir_cleanup(void)
45{
46 irda_unregister_dongle(&ep7211);
47}
48
49static int ep7211_open(struct sir_dev *dev)
50{
51 unsigned int syscon;
52
53 /* Turn on the SIR encoder. */
54 syscon = clps_readl(SYSCON1);
55 syscon |= SYSCON1_SIREN;
56 clps_writel(syscon, SYSCON1);
57
58 return 0;
59}
60
61static int ep7211_close(struct sir_dev *dev)
62{
63 unsigned int syscon;
64
65 /* Turn off the SIR encoder. */
66 syscon = clps_readl(SYSCON1);
67 syscon &= ~SYSCON1_SIREN;
68 clps_writel(syscon, SYSCON1);
69
70 return 0;
71}
72
73static int ep7211_change_speed(struct sir_dev *dev, unsigned speed)
74{
75 return 0;
76}
77
78static int ep7211_reset(struct sir_dev *dev)
79{
80 return 0;
81}
82
83MODULE_AUTHOR("Samuel Ortiz <samuel@sortiz.org>");
84MODULE_DESCRIPTION("EP7211 IR dongle driver");
85MODULE_LICENSE("GPL");
86MODULE_ALIAS("irda-dongle-13"); /* IRDA_EP7211_DONGLE */
87
88module_init(ep7211_sir_init);
89module_exit(ep7211_sir_cleanup);
diff --git a/drivers/net/mac89x0.c b/drivers/net/mac89x0.c
index 26a3b45a4a34..62c1c6262feb 100644
--- a/drivers/net/mac89x0.c
+++ b/drivers/net/mac89x0.c
@@ -608,7 +608,7 @@ module_param(debug, int, 0);
608MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)"); 608MODULE_PARM_DESC(debug, "CS89[02]0 debug level (0-5)");
609MODULE_LICENSE("GPL"); 609MODULE_LICENSE("GPL");
610 610
611int 611int __init
612init_module(void) 612init_module(void)
613{ 613{
614 net_debug = debug; 614 net_debug = debug;
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index a2f32151559e..13f08a390e1f 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -692,6 +692,7 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
692{ 692{
693 struct sky2_port *sky2 = netdev_priv(hw->dev[port]); 693 struct sky2_port *sky2 = netdev_priv(hw->dev[port]);
694 u16 reg; 694 u16 reg;
695 u32 rx_reg;
695 int i; 696 int i;
696 const u8 *addr = hw->dev[port]->dev_addr; 697 const u8 *addr = hw->dev[port]->dev_addr;
697 698
@@ -768,11 +769,11 @@ static void sky2_mac_init(struct sky2_hw *hw, unsigned port)
768 769
769 /* Configure Rx MAC FIFO */ 770 /* Configure Rx MAC FIFO */
770 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR); 771 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_CLR);
771 reg = GMF_OPER_ON | GMF_RX_F_FL_ON; 772 rx_reg = GMF_OPER_ON | GMF_RX_F_FL_ON;
772 if (hw->chip_id == CHIP_ID_YUKON_EX) 773 if (hw->chip_id == CHIP_ID_YUKON_EX)
773 reg |= GMF_RX_OVER_ON; 774 rx_reg |= GMF_RX_OVER_ON;
774 775
775 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), reg); 776 sky2_write32(hw, SK_REG(port, RX_GMF_CTRL_T), rx_reg);
776 777
777 /* Flush Rx MAC FIFO on any flow control or error */ 778 /* Flush Rx MAC FIFO on any flow control or error */
778 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR); 779 sky2_write16(hw, SK_REG(port, RX_GMF_FL_MSK), GMR_FS_ANY_ERR);
diff --git a/drivers/net/sunvnet.c b/drivers/net/sunvnet.c
index b801e3b3a11a..61f98251feab 100644
--- a/drivers/net/sunvnet.c
+++ b/drivers/net/sunvnet.c
@@ -459,6 +459,22 @@ static int vnet_nack(struct vnet_port *port, void *msgbuf)
459 return 0; 459 return 0;
460} 460}
461 461
462static int handle_mcast(struct vnet_port *port, void *msgbuf)
463{
464 struct vio_net_mcast_info *pkt = msgbuf;
465
466 if (pkt->tag.stype != VIO_SUBTYPE_ACK)
467 printk(KERN_ERR PFX "%s: Got unexpected MCAST reply "
468 "[%02x:%02x:%04x:%08x]\n",
469 port->vp->dev->name,
470 pkt->tag.type,
471 pkt->tag.stype,
472 pkt->tag.stype_env,
473 pkt->tag.sid);
474
475 return 0;
476}
477
462static void maybe_tx_wakeup(struct vnet *vp) 478static void maybe_tx_wakeup(struct vnet *vp)
463{ 479{
464 struct net_device *dev = vp->dev; 480 struct net_device *dev = vp->dev;
@@ -544,7 +560,10 @@ static void vnet_event(void *arg, int event)
544 err = vnet_nack(port, &msgbuf); 560 err = vnet_nack(port, &msgbuf);
545 } 561 }
546 } else if (msgbuf.tag.type == VIO_TYPE_CTRL) { 562 } else if (msgbuf.tag.type == VIO_TYPE_CTRL) {
547 err = vio_control_pkt_engine(vio, &msgbuf); 563 if (msgbuf.tag.stype_env == VNET_MCAST_INFO)
564 err = handle_mcast(port, &msgbuf);
565 else
566 err = vio_control_pkt_engine(vio, &msgbuf);
548 if (err) 567 if (err)
549 break; 568 break;
550 } else { 569 } else {
@@ -731,9 +750,122 @@ static int vnet_close(struct net_device *dev)
731 return 0; 750 return 0;
732} 751}
733 752
753static struct vnet_mcast_entry *__vnet_mc_find(struct vnet *vp, u8 *addr)
754{
755 struct vnet_mcast_entry *m;
756
757 for (m = vp->mcast_list; m; m = m->next) {
758 if (!memcmp(m->addr, addr, ETH_ALEN))
759 return m;
760 }
761 return NULL;
762}
763
764static void __update_mc_list(struct vnet *vp, struct net_device *dev)
765{
766 struct dev_addr_list *p;
767
768 for (p = dev->mc_list; p; p = p->next) {
769 struct vnet_mcast_entry *m;
770
771 m = __vnet_mc_find(vp, p->dmi_addr);
772 if (m) {
773 m->hit = 1;
774 continue;
775 }
776
777 if (!m) {
778 m = kzalloc(sizeof(*m), GFP_ATOMIC);
779 if (!m)
780 continue;
781 memcpy(m->addr, p->dmi_addr, ETH_ALEN);
782 m->hit = 1;
783
784 m->next = vp->mcast_list;
785 vp->mcast_list = m;
786 }
787 }
788}
789
790static void __send_mc_list(struct vnet *vp, struct vnet_port *port)
791{
792 struct vio_net_mcast_info info;
793 struct vnet_mcast_entry *m, **pp;
794 int n_addrs;
795
796 memset(&info, 0, sizeof(info));
797
798 info.tag.type = VIO_TYPE_CTRL;
799 info.tag.stype = VIO_SUBTYPE_INFO;
800 info.tag.stype_env = VNET_MCAST_INFO;
801 info.tag.sid = vio_send_sid(&port->vio);
802 info.set = 1;
803
804 n_addrs = 0;
805 for (m = vp->mcast_list; m; m = m->next) {
806 if (m->sent)
807 continue;
808 m->sent = 1;
809 memcpy(&info.mcast_addr[n_addrs * ETH_ALEN],
810 m->addr, ETH_ALEN);
811 if (++n_addrs == VNET_NUM_MCAST) {
812 info.count = n_addrs;
813
814 (void) vio_ldc_send(&port->vio, &info,
815 sizeof(info));
816 n_addrs = 0;
817 }
818 }
819 if (n_addrs) {
820 info.count = n_addrs;
821 (void) vio_ldc_send(&port->vio, &info, sizeof(info));
822 }
823
824 info.set = 0;
825
826 n_addrs = 0;
827 pp = &vp->mcast_list;
828 while ((m = *pp) != NULL) {
829 if (m->hit) {
830 m->hit = 0;
831 pp = &m->next;
832 continue;
833 }
834
835 memcpy(&info.mcast_addr[n_addrs * ETH_ALEN],
836 m->addr, ETH_ALEN);
837 if (++n_addrs == VNET_NUM_MCAST) {
838 info.count = n_addrs;
839 (void) vio_ldc_send(&port->vio, &info,
840 sizeof(info));
841 n_addrs = 0;
842 }
843
844 *pp = m->next;
845 kfree(m);
846 }
847 if (n_addrs) {
848 info.count = n_addrs;
849 (void) vio_ldc_send(&port->vio, &info, sizeof(info));
850 }
851}
852
734static void vnet_set_rx_mode(struct net_device *dev) 853static void vnet_set_rx_mode(struct net_device *dev)
735{ 854{
736 /* XXX Implement multicast support XXX */ 855 struct vnet *vp = netdev_priv(dev);
856 struct vnet_port *port;
857 unsigned long flags;
858
859 spin_lock_irqsave(&vp->lock, flags);
860 if (!list_empty(&vp->port_list)) {
861 port = list_entry(vp->port_list.next, struct vnet_port, list);
862
863 if (port->switch_port) {
864 __update_mc_list(vp, dev);
865 __send_mc_list(vp, port);
866 }
867 }
868 spin_unlock_irqrestore(&vp->lock, flags);
737} 869}
738 870
739static int vnet_change_mtu(struct net_device *dev, int new_mtu) 871static int vnet_change_mtu(struct net_device *dev, int new_mtu)
@@ -1070,6 +1202,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
1070 switch_port = 0; 1202 switch_port = 0;
1071 if (mdesc_get_property(hp, vdev->mp, "switch-port", NULL) != NULL) 1203 if (mdesc_get_property(hp, vdev->mp, "switch-port", NULL) != NULL)
1072 switch_port = 1; 1204 switch_port = 1;
1205 port->switch_port = switch_port;
1073 1206
1074 spin_lock_irqsave(&vp->lock, flags); 1207 spin_lock_irqsave(&vp->lock, flags);
1075 if (switch_port) 1208 if (switch_port)
@@ -1136,7 +1269,7 @@ static struct vio_device_id vnet_port_match[] = {
1136 }, 1269 },
1137 {}, 1270 {},
1138}; 1271};
1139MODULE_DEVICE_TABLE(vio, vnet_match); 1272MODULE_DEVICE_TABLE(vio, vnet_port_match);
1140 1273
1141static struct vio_driver vnet_port_driver = { 1274static struct vio_driver vnet_port_driver = {
1142 .id_table = vnet_port_match, 1275 .id_table = vnet_port_match,
diff --git a/drivers/net/sunvnet.h b/drivers/net/sunvnet.h
index 7d3a0cac727b..d347a5bf24b0 100644
--- a/drivers/net/sunvnet.h
+++ b/drivers/net/sunvnet.h
@@ -30,6 +30,8 @@ struct vnet_port {
30 30
31 struct hlist_node hash; 31 struct hlist_node hash;
32 u8 raddr[ETH_ALEN]; 32 u8 raddr[ETH_ALEN];
33 u8 switch_port;
34 u8 __pad;
33 35
34 struct vnet *vp; 36 struct vnet *vp;
35 37
@@ -53,6 +55,13 @@ static inline unsigned int vnet_hashfn(u8 *mac)
53 return val & (VNET_PORT_HASH_MASK); 55 return val & (VNET_PORT_HASH_MASK);
54} 56}
55 57
58struct vnet_mcast_entry {
59 u8 addr[ETH_ALEN];
60 u8 sent;
61 u8 hit;
62 struct vnet_mcast_entry *next;
63};
64
56struct vnet { 65struct vnet {
57 /* Protects port_list and port_hash. */ 66 /* Protects port_list and port_hash. */
58 spinlock_t lock; 67 spinlock_t lock;
@@ -65,6 +74,8 @@ struct vnet {
65 74
66 struct hlist_head port_hash[VNET_PORT_HASH_SIZE]; 75 struct hlist_head port_hash[VNET_PORT_HASH_SIZE];
67 76
77 struct vnet_mcast_entry *mcast_list;
78
68 struct list_head list; 79 struct list_head list;
69 u64 local_mac; 80 u64 local_mac;
70}; 81};
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
new file mode 100644
index 000000000000..c03072b12f42
--- /dev/null
+++ b/drivers/of/Kconfig
@@ -0,0 +1,3 @@
1config OF_DEVICE
2 def_bool y
3 depends on OF && (SPARC || PPC_OF)
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
new file mode 100644
index 000000000000..ab9be5d5255b
--- /dev/null
+++ b/drivers/of/Makefile
@@ -0,0 +1,2 @@
1obj-y = base.o
2obj-$(CONFIG_OF_DEVICE) += device.o platform.o
diff --git a/drivers/of/base.c b/drivers/of/base.c
new file mode 100644
index 000000000000..9377f3bc410a
--- /dev/null
+++ b/drivers/of/base.c
@@ -0,0 +1,275 @@
1/*
2 * Procedures for creating, accessing and interpreting the device tree.
3 *
4 * Paul Mackerras August 1996.
5 * Copyright (C) 1996-2005 Paul Mackerras.
6 *
7 * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
8 * {engebret|bergner}@us.ibm.com
9 *
10 * Adapted for sparc and sparc64 by David S. Miller davem@davemloft.net
11 *
12 * Reconsolidated from arch/x/kernel/prom.c by Stephen Rothwell.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version
17 * 2 of the License, or (at your option) any later version.
18 */
19#include <linux/module.h>
20#include <linux/of.h>
21#include <linux/spinlock.h>
22
23struct device_node *allnodes;
24
25/* use when traversing tree through the allnext, child, sibling,
26 * or parent members of struct device_node.
27 */
28DEFINE_RWLOCK(devtree_lock);
29
30int of_n_addr_cells(struct device_node *np)
31{
32 const int *ip;
33
34 do {
35 if (np->parent)
36 np = np->parent;
37 ip = of_get_property(np, "#address-cells", NULL);
38 if (ip)
39 return *ip;
40 } while (np->parent);
41 /* No #address-cells property for the root node */
42 return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
43}
44EXPORT_SYMBOL(of_n_addr_cells);
45
46int of_n_size_cells(struct device_node *np)
47{
48 const int *ip;
49
50 do {
51 if (np->parent)
52 np = np->parent;
53 ip = of_get_property(np, "#size-cells", NULL);
54 if (ip)
55 return *ip;
56 } while (np->parent);
57 /* No #size-cells property for the root node */
58 return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
59}
60EXPORT_SYMBOL(of_n_size_cells);
61
62struct property *of_find_property(const struct device_node *np,
63 const char *name,
64 int *lenp)
65{
66 struct property *pp;
67
68 read_lock(&devtree_lock);
69 for (pp = np->properties; pp != 0; pp = pp->next) {
70 if (of_prop_cmp(pp->name, name) == 0) {
71 if (lenp != 0)
72 *lenp = pp->length;
73 break;
74 }
75 }
76 read_unlock(&devtree_lock);
77
78 return pp;
79}
80EXPORT_SYMBOL(of_find_property);
81
82/*
83 * Find a property with a given name for a given node
84 * and return the value.
85 */
86const void *of_get_property(const struct device_node *np, const char *name,
87 int *lenp)
88{
89 struct property *pp = of_find_property(np, name, lenp);
90
91 return pp ? pp->value : NULL;
92}
93EXPORT_SYMBOL(of_get_property);
94
95/** Checks if the given "compat" string matches one of the strings in
96 * the device's "compatible" property
97 */
98int of_device_is_compatible(const struct device_node *device,
99 const char *compat)
100{
101 const char* cp;
102 int cplen, l;
103
104 cp = of_get_property(device, "compatible", &cplen);
105 if (cp == NULL)
106 return 0;
107 while (cplen > 0) {
108 if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
109 return 1;
110 l = strlen(cp) + 1;
111 cp += l;
112 cplen -= l;
113 }
114
115 return 0;
116}
117EXPORT_SYMBOL(of_device_is_compatible);
118
119/**
120 * of_get_parent - Get a node's parent if any
121 * @node: Node to get parent
122 *
123 * Returns a node pointer with refcount incremented, use
124 * of_node_put() on it when done.
125 */
126struct device_node *of_get_parent(const struct device_node *node)
127{
128 struct device_node *np;
129
130 if (!node)
131 return NULL;
132
133 read_lock(&devtree_lock);
134 np = of_node_get(node->parent);
135 read_unlock(&devtree_lock);
136 return np;
137}
138EXPORT_SYMBOL(of_get_parent);
139
140/**
141 * of_get_next_child - Iterate a node childs
142 * @node: parent node
143 * @prev: previous child of the parent node, or NULL to get first
144 *
145 * Returns a node pointer with refcount incremented, use
146 * of_node_put() on it when done.
147 */
148struct device_node *of_get_next_child(const struct device_node *node,
149 struct device_node *prev)
150{
151 struct device_node *next;
152
153 read_lock(&devtree_lock);
154 next = prev ? prev->sibling : node->child;
155 for (; next; next = next->sibling)
156 if (of_node_get(next))
157 break;
158 of_node_put(prev);
159 read_unlock(&devtree_lock);
160 return next;
161}
162EXPORT_SYMBOL(of_get_next_child);
163
164/**
165 * of_find_node_by_path - Find a node matching a full OF path
166 * @path: The full path to match
167 *
168 * Returns a node pointer with refcount incremented, use
169 * of_node_put() on it when done.
170 */
171struct device_node *of_find_node_by_path(const char *path)
172{
173 struct device_node *np = allnodes;
174
175 read_lock(&devtree_lock);
176 for (; np; np = np->allnext) {
177 if (np->full_name && (of_node_cmp(np->full_name, path) == 0)
178 && of_node_get(np))
179 break;
180 }
181 read_unlock(&devtree_lock);
182 return np;
183}
184EXPORT_SYMBOL(of_find_node_by_path);
185
186/**
187 * of_find_node_by_name - Find a node by its "name" property
188 * @from: The node to start searching from or NULL, the node
189 * you pass will not be searched, only the next one
190 * will; typically, you pass what the previous call
191 * returned. of_node_put() will be called on it
192 * @name: The name string to match against
193 *
194 * Returns a node pointer with refcount incremented, use
195 * of_node_put() on it when done.
196 */
197struct device_node *of_find_node_by_name(struct device_node *from,
198 const char *name)
199{
200 struct device_node *np;
201
202 read_lock(&devtree_lock);
203 np = from ? from->allnext : allnodes;
204 for (; np; np = np->allnext)
205 if (np->name && (of_node_cmp(np->name, name) == 0)
206 && of_node_get(np))
207 break;
208 of_node_put(from);
209 read_unlock(&devtree_lock);
210 return np;
211}
212EXPORT_SYMBOL(of_find_node_by_name);
213
214/**
215 * of_find_node_by_type - Find a node by its "device_type" property
216 * @from: The node to start searching from, or NULL to start searching
217 * the entire device tree. The node you pass will not be
218 * searched, only the next one will; typically, you pass
219 * what the previous call returned. of_node_put() will be
220 * called on from for you.
221 * @type: The type string to match against
222 *
223 * Returns a node pointer with refcount incremented, use
224 * of_node_put() on it when done.
225 */
226struct device_node *of_find_node_by_type(struct device_node *from,
227 const char *type)
228{
229 struct device_node *np;
230
231 read_lock(&devtree_lock);
232 np = from ? from->allnext : allnodes;
233 for (; np; np = np->allnext)
234 if (np->type && (of_node_cmp(np->type, type) == 0)
235 && of_node_get(np))
236 break;
237 of_node_put(from);
238 read_unlock(&devtree_lock);
239 return np;
240}
241EXPORT_SYMBOL(of_find_node_by_type);
242
243/**
244 * of_find_compatible_node - Find a node based on type and one of the
245 * tokens in its "compatible" property
246 * @from: The node to start searching from or NULL, the node
247 * you pass will not be searched, only the next one
248 * will; typically, you pass what the previous call
249 * returned. of_node_put() will be called on it
250 * @type: The type string to match "device_type" or NULL to ignore
251 * @compatible: The string to match to one of the tokens in the device
252 * "compatible" list.
253 *
254 * Returns a node pointer with refcount incremented, use
255 * of_node_put() on it when done.
256 */
257struct device_node *of_find_compatible_node(struct device_node *from,
258 const char *type, const char *compatible)
259{
260 struct device_node *np;
261
262 read_lock(&devtree_lock);
263 np = from ? from->allnext : allnodes;
264 for (; np; np = np->allnext) {
265 if (type
266 && !(np->type && (of_node_cmp(np->type, type) == 0)))
267 continue;
268 if (of_device_is_compatible(np, compatible) && of_node_get(np))
269 break;
270 }
271 of_node_put(from);
272 read_unlock(&devtree_lock);
273 return np;
274}
275EXPORT_SYMBOL(of_find_compatible_node);
diff --git a/drivers/of/device.c b/drivers/of/device.c
new file mode 100644
index 000000000000..6245f060fb77
--- /dev/null
+++ b/drivers/of/device.c
@@ -0,0 +1,131 @@
1#include <linux/string.h>
2#include <linux/kernel.h>
3#include <linux/of.h>
4#include <linux/of_device.h>
5#include <linux/init.h>
6#include <linux/module.h>
7#include <linux/mod_devicetable.h>
8#include <linux/slab.h>
9
10#include <asm/errno.h>
11
12/**
13 * of_match_node - Tell if an device_node has a matching of_match structure
14 * @ids: array of of device match structures to search in
15 * @node: the of device structure to match against
16 *
17 * Low level utility function used by device matching.
18 */
19const struct of_device_id *of_match_node(const struct of_device_id *matches,
20 const struct device_node *node)
21{
22 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
23 int match = 1;
24 if (matches->name[0])
25 match &= node->name
26 && !strcmp(matches->name, node->name);
27 if (matches->type[0])
28 match &= node->type
29 && !strcmp(matches->type, node->type);
30 if (matches->compatible[0])
31 match &= of_device_is_compatible(node,
32 matches->compatible);
33 if (match)
34 return matches;
35 matches++;
36 }
37 return NULL;
38}
39EXPORT_SYMBOL(of_match_node);
40
41/**
42 * of_match_device - Tell if an of_device structure has a matching
43 * of_match structure
44 * @ids: array of of device match structures to search in
45 * @dev: the of device structure to match against
46 *
47 * Used by a driver to check whether an of_device present in the
48 * system is in its list of supported devices.
49 */
50const struct of_device_id *of_match_device(const struct of_device_id *matches,
51 const struct of_device *dev)
52{
53 if (!dev->node)
54 return NULL;
55 return of_match_node(matches, dev->node);
56}
57EXPORT_SYMBOL(of_match_device);
58
59struct of_device *of_dev_get(struct of_device *dev)
60{
61 struct device *tmp;
62
63 if (!dev)
64 return NULL;
65 tmp = get_device(&dev->dev);
66 if (tmp)
67 return to_of_device(tmp);
68 else
69 return NULL;
70}
71EXPORT_SYMBOL(of_dev_get);
72
73void of_dev_put(struct of_device *dev)
74{
75 if (dev)
76 put_device(&dev->dev);
77}
78EXPORT_SYMBOL(of_dev_put);
79
80static ssize_t dev_show_devspec(struct device *dev,
81 struct device_attribute *attr, char *buf)
82{
83 struct of_device *ofdev;
84
85 ofdev = to_of_device(dev);
86 return sprintf(buf, "%s", ofdev->node->full_name);
87}
88
89static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL);
90
91/**
92 * of_release_dev - free an of device structure when all users of it are finished.
93 * @dev: device that's been disconnected
94 *
95 * Will be called only by the device core when all users of this of device are
96 * done.
97 */
98void of_release_dev(struct device *dev)
99{
100 struct of_device *ofdev;
101
102 ofdev = to_of_device(dev);
103 of_node_put(ofdev->node);
104 kfree(ofdev);
105}
106EXPORT_SYMBOL(of_release_dev);
107
108int of_device_register(struct of_device *ofdev)
109{
110 int rc;
111
112 BUG_ON(ofdev->node == NULL);
113
114 rc = device_register(&ofdev->dev);
115 if (rc)
116 return rc;
117
118 rc = device_create_file(&ofdev->dev, &dev_attr_devspec);
119 if (rc)
120 device_unregister(&ofdev->dev);
121
122 return rc;
123}
124EXPORT_SYMBOL(of_device_register);
125
126void of_device_unregister(struct of_device *ofdev)
127{
128 device_remove_file(&ofdev->dev, &dev_attr_devspec);
129 device_unregister(&ofdev->dev);
130}
131EXPORT_SYMBOL(of_device_unregister);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
new file mode 100644
index 000000000000..864f09fd9f86
--- /dev/null
+++ b/drivers/of/platform.c
@@ -0,0 +1,96 @@
1/*
2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
3 * <benh@kernel.crashing.org>
4 * and Arnd Bergmann, IBM Corp.
5 * Merged from powerpc/kernel/of_platform.c and
6 * sparc{,64}/kernel/of_device.c by Stephen Rothwell
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 */
14#include <linux/errno.h>
15#include <linux/device.h>
16#include <linux/of_device.h>
17#include <linux/of_platform.h>
18
19static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
20{
21 struct of_device *of_dev = to_of_device(dev);
22 struct of_platform_driver *of_drv = to_of_platform_driver(drv);
23 const struct of_device_id *matches = of_drv->match_table;
24
25 if (!matches)
26 return 0;
27
28 return of_match_device(matches, of_dev) != NULL;
29}
30
31static int of_platform_device_probe(struct device *dev)
32{
33 int error = -ENODEV;
34 struct of_platform_driver *drv;
35 struct of_device *of_dev;
36 const struct of_device_id *match;
37
38 drv = to_of_platform_driver(dev->driver);
39 of_dev = to_of_device(dev);
40
41 if (!drv->probe)
42 return error;
43
44 of_dev_get(of_dev);
45
46 match = of_match_device(drv->match_table, of_dev);
47 if (match)
48 error = drv->probe(of_dev, match);
49 if (error)
50 of_dev_put(of_dev);
51
52 return error;
53}
54
55static int of_platform_device_remove(struct device *dev)
56{
57 struct of_device *of_dev = to_of_device(dev);
58 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
59
60 if (dev->driver && drv->remove)
61 drv->remove(of_dev);
62 return 0;
63}
64
65static int of_platform_device_suspend(struct device *dev, pm_message_t state)
66{
67 struct of_device *of_dev = to_of_device(dev);
68 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
69 int error = 0;
70
71 if (dev->driver && drv->suspend)
72 error = drv->suspend(of_dev, state);
73 return error;
74}
75
76static int of_platform_device_resume(struct device * dev)
77{
78 struct of_device *of_dev = to_of_device(dev);
79 struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
80 int error = 0;
81
82 if (dev->driver && drv->resume)
83 error = drv->resume(of_dev);
84 return error;
85}
86
87int of_bus_type_init(struct bus_type *bus, const char *name)
88{
89 bus->name = name;
90 bus->match = of_platform_bus_match;
91 bus->probe = of_platform_device_probe;
92 bus->remove = of_platform_device_remove;
93 bus->suspend = of_platform_device_suspend;
94 bus->resume = of_platform_device_resume;
95 return bus_register(bus);
96}
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index edd6de995726..8134c7e198a5 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -26,8 +26,9 @@
26#include <linux/profile.h> 26#include <linux/profile.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/fs.h> 28#include <linux/fs.h>
29#include <linux/oprofile.h>
29#include <linux/sched.h> 30#include <linux/sched.h>
30 31
31#include "oprofile_stats.h" 32#include "oprofile_stats.h"
32#include "event_buffer.h" 33#include "event_buffer.h"
33#include "cpu_buffer.h" 34#include "cpu_buffer.h"
diff --git a/drivers/oprofile/event_buffer.h b/drivers/oprofile/event_buffer.h
index 9b6a4ebd03e3..5076ed1ebd8f 100644
--- a/drivers/oprofile/event_buffer.h
+++ b/drivers/oprofile/event_buffer.h
@@ -19,28 +19,10 @@ void free_event_buffer(void);
19 19
20/* wake up the process sleeping on the event file */ 20/* wake up the process sleeping on the event file */
21void wake_up_buffer_waiter(void); 21void wake_up_buffer_waiter(void);
22 22
23/* Each escaped entry is prefixed by ESCAPE_CODE
24 * then one of the following codes, then the
25 * relevant data.
26 */
27#define ESCAPE_CODE ~0UL
28#define CTX_SWITCH_CODE 1
29#define CPU_SWITCH_CODE 2
30#define COOKIE_SWITCH_CODE 3
31#define KERNEL_ENTER_SWITCH_CODE 4
32#define KERNEL_EXIT_SWITCH_CODE 5
33#define MODULE_LOADED_CODE 6
34#define CTX_TGID_CODE 7
35#define TRACE_BEGIN_CODE 8
36#define TRACE_END_CODE 9
37
38#define INVALID_COOKIE ~0UL 23#define INVALID_COOKIE ~0UL
39#define NO_COOKIE 0UL 24#define NO_COOKIE 0UL
40 25
41/* add data to the event buffer */
42void add_event_entry(unsigned long data);
43
44extern const struct file_operations event_buffer_fops; 26extern const struct file_operations event_buffer_fops;
45 27
46/* mutex between sync_cpu_buffers() and the 28/* mutex between sync_cpu_buffers() and the
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
index e5162a64018b..2c645170f06e 100644
--- a/drivers/oprofile/oprof.c
+++ b/drivers/oprofile/oprof.c
@@ -53,9 +53,24 @@ int oprofile_setup(void)
53 * us missing task deaths and eventually oopsing 53 * us missing task deaths and eventually oopsing
54 * when trying to process the event buffer. 54 * when trying to process the event buffer.
55 */ 55 */
56 if (oprofile_ops.sync_start) {
57 int sync_ret = oprofile_ops.sync_start();
58 switch (sync_ret) {
59 case 0:
60 goto post_sync;
61 case 1:
62 goto do_generic;
63 case -1:
64 goto out3;
65 default:
66 goto out3;
67 }
68 }
69do_generic:
56 if ((err = sync_start())) 70 if ((err = sync_start()))
57 goto out3; 71 goto out3;
58 72
73post_sync:
59 is_setup = 1; 74 is_setup = 1;
60 mutex_unlock(&start_mutex); 75 mutex_unlock(&start_mutex);
61 return 0; 76 return 0;
@@ -118,7 +133,20 @@ out:
118void oprofile_shutdown(void) 133void oprofile_shutdown(void)
119{ 134{
120 mutex_lock(&start_mutex); 135 mutex_lock(&start_mutex);
136 if (oprofile_ops.sync_stop) {
137 int sync_ret = oprofile_ops.sync_stop();
138 switch (sync_ret) {
139 case 0:
140 goto post_sync;
141 case 1:
142 goto do_generic;
143 default:
144 goto post_sync;
145 }
146 }
147do_generic:
121 sync_stop(); 148 sync_stop();
149post_sync:
122 if (oprofile_ops.shutdown) 150 if (oprofile_ops.shutdown)
123 oprofile_ops.shutdown(); 151 oprofile_ops.shutdown();
124 is_setup = 0; 152 is_setup = 0;
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig
index 09c93ff932b1..d449b150930e 100644
--- a/drivers/parport/Kconfig
+++ b/drivers/parport/Kconfig
@@ -35,7 +35,7 @@ if PARPORT
35 35
36config PARPORT_PC 36config PARPORT_PC
37 tristate "PC-style hardware" 37 tristate "PC-style hardware"
38 depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV 38 depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV && (!M68K || ISA)
39 ---help--- 39 ---help---
40 You should say Y here if you have a PC-style parallel port. All 40 You should say Y here if you have a PC-style parallel port. All
41 IBM PC compatible computers and some Alphas have PC-style 41 IBM PC compatible computers and some Alphas have PC-style
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index 3c45142c40b2..b01985498460 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -1316,7 +1316,7 @@ static struct of_device_id m8xx_pcmcia_match[] = {
1316MODULE_DEVICE_TABLE(of, m8xx_pcmcia_match); 1316MODULE_DEVICE_TABLE(of, m8xx_pcmcia_match);
1317 1317
1318static struct of_platform_driver m8xx_pcmcia_driver = { 1318static struct of_platform_driver m8xx_pcmcia_driver = {
1319 .name = (char *)driver_name, 1319 .name = driver_name,
1320 .match_table = m8xx_pcmcia_match, 1320 .match_table = m8xx_pcmcia_match,
1321 .probe = m8xx_probe, 1321 .probe = m8xx_probe,
1322 .remove = m8xx_remove, 1322 .remove = m8xx_remove,
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index cea401feb0f3..9d8d40d5c8f7 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -38,6 +38,9 @@ config RTC_HCTOSYS_DEVICE
38 clock, usually rtc0. Initialization is done when the system 38 clock, usually rtc0. Initialization is done when the system
39 starts up, and when it resumes from a low power state. 39 starts up, and when it resumes from a low power state.
40 40
41 The driver for this RTC device must be loaded before late_initcall
42 functions run, so it must usually be statically linked.
43
41 This clock should be battery-backed, so that it reads the correct 44 This clock should be battery-backed, so that it reads the correct
42 time when the system boots from a power-off state. Otherwise, your 45 time when the system boots from a power-off state. Otherwise, your
43 system will need an external clock source (like an NTP server). 46 system will need an external clock source (like an NTP server).
@@ -305,6 +308,16 @@ config RTC_DRV_DS1553
305 This driver can also be built as a module. If so, the module 308 This driver can also be built as a module. If so, the module
306 will be called rtc-ds1553. 309 will be called rtc-ds1553.
307 310
311config RTC_DRV_STK17TA8
312 tristate "Simtek STK17TA8"
313 depends on RTC_CLASS
314 help
315 If you say yes here you get support for the
316 Simtek STK17TA8 timekeeping chip.
317
318 This driver can also be built as a module. If so, the module
319 will be called rtc-stk17ta8.
320
308config RTC_DRV_DS1742 321config RTC_DRV_DS1742
309 tristate "Dallas DS1742/1743" 322 tristate "Dallas DS1742/1743"
310 depends on RTC_CLASS 323 depends on RTC_CLASS
@@ -394,7 +407,7 @@ config RTC_DRV_SA1100
394 407
395config RTC_DRV_SH 408config RTC_DRV_SH
396 tristate "SuperH On-Chip RTC" 409 tristate "SuperH On-Chip RTC"
397 depends on RTC_CLASS && SUPERH 410 depends on RTC_CLASS && SUPERH && (CPU_SH3 || CPU_SH4)
398 help 411 help
399 Say Y here to enable support for the on-chip RTC found in 412 Say Y here to enable support for the on-chip RTC found in
400 most SuperH processors. 413 most SuperH processors.
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 3109af9a1651..7ede9e725360 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
32obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 32obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
33obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 33obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
34obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 34obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
35obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
35obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o 36obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
36obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 37obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
37obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 38obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index f98a83a11aae..46da5714932c 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -407,7 +407,7 @@ static __init int ds1553_init(void)
407 407
408static __exit void ds1553_exit(void) 408static __exit void ds1553_exit(void)
409{ 409{
410 return platform_driver_unregister(&ds1553_rtc_driver); 410 platform_driver_unregister(&ds1553_rtc_driver);
411} 411}
412 412
413module_init(ds1553_init); 413module_init(ds1553_init);
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index d1778ae8bca5..b2e5481ba3b6 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -263,7 +263,7 @@ static __init int ds1742_init(void)
263 263
264static __exit void ds1742_exit(void) 264static __exit void ds1742_exit(void)
265{ 265{
266 return platform_driver_unregister(&ds1742_rtc_driver); 266 platform_driver_unregister(&ds1742_rtc_driver);
267} 267}
268 268
269module_init(ds1742_init); 269module_init(ds1742_init);
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index eee4ee5bb75a..a1cd448639c9 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -31,17 +31,24 @@
31#define MAX6900_REG_DW 5 /* day of week 1-7 */ 31#define MAX6900_REG_DW 5 /* day of week 1-7 */
32#define MAX6900_REG_YR 6 /* year 00-99 */ 32#define MAX6900_REG_YR 6 /* year 00-99 */
33#define MAX6900_REG_CT 7 /* control */ 33#define MAX6900_REG_CT 7 /* control */
34#define MAX6900_REG_LEN 8 34 /* register 8 is undocumented */
35#define MAX6900_REG_CENTURY 9 /* century */
36#define MAX6900_REG_LEN 10
37
38#define MAX6900_BURST_LEN 8 /* can burst r/w first 8 regs */
35 39
36#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */ 40#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
37 41
42
38/* 43/*
39 * register read/write commands 44 * register read/write commands
40 */ 45 */
41#define MAX6900_REG_CONTROL_WRITE 0x8e 46#define MAX6900_REG_CONTROL_WRITE 0x8e
42#define MAX6900_REG_BURST_READ 0xbf 47#define MAX6900_REG_CENTURY_WRITE 0x92
43#define MAX6900_REG_BURST_WRITE 0xbe 48#define MAX6900_REG_CENTURY_READ 0x93
44#define MAX6900_REG_RESERVED_READ 0x96 49#define MAX6900_REG_RESERVED_READ 0x96
50#define MAX6900_REG_BURST_WRITE 0xbe
51#define MAX6900_REG_BURST_READ 0xbf
45 52
46#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */ 53#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
47 54
@@ -58,19 +65,32 @@ static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind);
58 65
59static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf) 66static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
60{ 67{
61 u8 reg_addr[1] = { MAX6900_REG_BURST_READ }; 68 u8 reg_burst_read[1] = { MAX6900_REG_BURST_READ };
62 struct i2c_msg msgs[2] = { 69 u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ };
70 struct i2c_msg msgs[4] = {
63 { 71 {
64 .addr = client->addr, 72 .addr = client->addr,
65 .flags = 0, /* write */ 73 .flags = 0, /* write */
66 .len = sizeof(reg_addr), 74 .len = sizeof(reg_burst_read),
67 .buf = reg_addr 75 .buf = reg_burst_read
68 }, 76 },
69 { 77 {
70 .addr = client->addr, 78 .addr = client->addr,
71 .flags = I2C_M_RD, 79 .flags = I2C_M_RD,
72 .len = MAX6900_REG_LEN, 80 .len = MAX6900_BURST_LEN,
73 .buf = buf 81 .buf = buf
82 },
83 {
84 .addr = client->addr,
85 .flags = 0, /* write */
86 .len = sizeof(reg_century_read),
87 .buf = reg_century_read
88 },
89 {
90 .addr = client->addr,
91 .flags = I2C_M_RD,
92 .len = sizeof(buf[MAX6900_REG_CENTURY]),
93 .buf = &buf[MAX6900_REG_CENTURY]
74 } 94 }
75 }; 95 };
76 int rc; 96 int rc;
@@ -86,33 +106,58 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
86 106
87static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf) 107static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
88{ 108{
89 u8 i2c_buf[MAX6900_REG_LEN + 1] = { MAX6900_REG_BURST_WRITE }; 109 u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE };
90 struct i2c_msg msgs[1] = { 110 struct i2c_msg century_msgs[1] = {
91 { 111 {
92 .addr = client->addr, 112 .addr = client->addr,
93 .flags = 0, /* write */ 113 .flags = 0, /* write */
94 .len = MAX6900_REG_LEN + 1, 114 .len = sizeof(i2c_century_buf),
95 .buf = i2c_buf 115 .buf = i2c_century_buf
116 }
117 };
118 u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
119 struct i2c_msg burst_msgs[1] = {
120 {
121 .addr = client->addr,
122 .flags = 0, /* write */
123 .len = sizeof(i2c_burst_buf),
124 .buf = i2c_burst_buf
96 } 125 }
97 }; 126 };
98 int rc; 127 int rc;
99 128
100 memcpy(&i2c_buf[1], buf, MAX6900_REG_LEN); 129 /*
130 * We have to make separate calls to i2c_transfer because of
131 * the need to delay after each write to the chip. Also,
132 * we write the century byte first, since we set the write-protect
133 * bit as part of the burst write.
134 */
135 i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
136 rc = i2c_transfer(client->adapter, century_msgs,
137 ARRAY_SIZE(century_msgs));
138 if (rc != ARRAY_SIZE(century_msgs))
139 goto write_failed;
140 msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
101 141
102 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 142 memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
103 if (rc != ARRAY_SIZE(msgs)) { 143
104 dev_err(&client->dev, "%s: register write failed\n", 144 rc = i2c_transfer(client->adapter, burst_msgs, ARRAY_SIZE(burst_msgs));
105 __FUNCTION__); 145 if (rc != ARRAY_SIZE(burst_msgs))
106 return -EIO; 146 goto write_failed;
107 }
108 msleep(MAX6900_IDLE_TIME_AFTER_WRITE); 147 msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
148
109 return 0; 149 return 0;
150
151write_failed:
152 dev_err(&client->dev, "%s: register write failed\n",
153 __FUNCTION__);
154 return -EIO;
110} 155}
111 156
112static int max6900_i2c_validate_client(struct i2c_client *client) 157static int max6900_i2c_validate_client(struct i2c_client *client)
113{ 158{
114 u8 regs[MAX6900_REG_LEN]; 159 u8 regs[MAX6900_REG_LEN];
115 u8 zero_mask[MAX6900_REG_LEN] = { 160 u8 zero_mask[] = {
116 0x80, /* seconds */ 161 0x80, /* seconds */
117 0x80, /* minutes */ 162 0x80, /* minutes */
118 0x40, /* hours */ 163 0x40, /* hours */
@@ -134,7 +179,7 @@ static int max6900_i2c_validate_client(struct i2c_client *client)
134 if (rc < 0) 179 if (rc < 0)
135 return rc; 180 return rc;
136 181
137 for (i = 0; i < MAX6900_REG_LEN; ++i) { 182 for (i = 0; i < ARRAY_SIZE(zero_mask); ++i) {
138 if (regs[i] & zero_mask[i]) 183 if (regs[i] & zero_mask[i])
139 return -ENODEV; 184 return -ENODEV;
140 } 185 }
@@ -156,7 +201,8 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
156 tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f); 201 tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f);
157 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]); 202 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]);
158 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1; 203 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1;
159 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + 100; 204 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) +
205 BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
160 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]); 206 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]);
161 207
162 return 0; 208 return 0;
@@ -189,9 +235,11 @@ static int max6900_i2c_set_time(struct i2c_client *client,
189 regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour); 235 regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour);
190 regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday); 236 regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday);
191 regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1); 237 regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1);
192 regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year - 100);
193 regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday); 238 regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday);
194 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; /* set write protect */ 239 regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year % 100);
240 regs[MAX6900_REG_CENTURY] = BIN2BCD((tm->tm_year + 1900) / 100);
241 /* set write protect */
242 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP;
195 243
196 rc = max6900_i2c_write_regs(client, regs); 244 rc = max6900_i2c_write_regs(client, regs);
197 if (rc < 0) 245 if (rc < 0)
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
new file mode 100644
index 000000000000..f10d3facecbe
--- /dev/null
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -0,0 +1,420 @@
1/*
2 * A RTC driver for the Simtek STK17TA8
3 *
4 * By Thomas Hommel <thomas.hommel@gefanuc.com>
5 *
6 * Based on the DS1553 driver from
7 * Atsushi Nemoto <anemo@mba.ocn.ne.jp>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/bcd.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/delay.h>
18#include <linux/jiffies.h>
19#include <linux/interrupt.h>
20#include <linux/rtc.h>
21#include <linux/platform_device.h>
22#include <linux/io.h>
23
24#define DRV_VERSION "0.1"
25
26#define RTC_REG_SIZE 0x20000
27#define RTC_OFFSET 0x1fff0
28
29#define RTC_FLAGS (RTC_OFFSET + 0)
30#define RTC_CENTURY (RTC_OFFSET + 1)
31#define RTC_SECONDS_ALARM (RTC_OFFSET + 2)
32#define RTC_MINUTES_ALARM (RTC_OFFSET + 3)
33#define RTC_HOURS_ALARM (RTC_OFFSET + 4)
34#define RTC_DATE_ALARM (RTC_OFFSET + 5)
35#define RTC_INTERRUPTS (RTC_OFFSET + 6)
36#define RTC_WATCHDOG (RTC_OFFSET + 7)
37#define RTC_CALIBRATION (RTC_OFFSET + 8)
38#define RTC_SECONDS (RTC_OFFSET + 9)
39#define RTC_MINUTES (RTC_OFFSET + 10)
40#define RTC_HOURS (RTC_OFFSET + 11)
41#define RTC_DAY (RTC_OFFSET + 12)
42#define RTC_DATE (RTC_OFFSET + 13)
43#define RTC_MONTH (RTC_OFFSET + 14)
44#define RTC_YEAR (RTC_OFFSET + 15)
45
46#define RTC_SECONDS_MASK 0x7f
47#define RTC_DAY_MASK 0x07
48#define RTC_CAL_MASK 0x3f
49
50/* Bits in the Calibration register */
51#define RTC_STOP 0x80
52
53/* Bits in the Flags register */
54#define RTC_FLAGS_AF 0x40
55#define RTC_FLAGS_PF 0x20
56#define RTC_WRITE 0x02
57#define RTC_READ 0x01
58
59/* Bits in the Interrupts register */
60#define RTC_INTS_AIE 0x40
61
62struct rtc_plat_data {
63 struct rtc_device *rtc;
64 void __iomem *ioaddr;
65 unsigned long baseaddr;
66 unsigned long last_jiffies;
67 int irq;
68 unsigned int irqen;
69 int alrm_sec;
70 int alrm_min;
71 int alrm_hour;
72 int alrm_mday;
73};
74
75static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm)
76{
77 struct platform_device *pdev = to_platform_device(dev);
78 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
79 void __iomem *ioaddr = pdata->ioaddr;
80 u8 flags;
81
82 flags = readb(pdata->ioaddr + RTC_FLAGS);
83 writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
84
85 writeb(BIN2BCD(tm->tm_year % 100), ioaddr + RTC_YEAR);
86 writeb(BIN2BCD(tm->tm_mon + 1), ioaddr + RTC_MONTH);
87 writeb(BIN2BCD(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY);
88 writeb(BIN2BCD(tm->tm_mday), ioaddr + RTC_DATE);
89 writeb(BIN2BCD(tm->tm_hour), ioaddr + RTC_HOURS);
90 writeb(BIN2BCD(tm->tm_min), ioaddr + RTC_MINUTES);
91 writeb(BIN2BCD(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS);
92 writeb(BIN2BCD((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY);
93
94 writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
95 return 0;
96}
97
98static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm)
99{
100 struct platform_device *pdev = to_platform_device(dev);
101 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
102 void __iomem *ioaddr = pdata->ioaddr;
103 unsigned int year, month, day, hour, minute, second, week;
104 unsigned int century;
105 u8 flags;
106
107 /* give enough time to update RTC in case of continuous read */
108 if (pdata->last_jiffies == jiffies)
109 msleep(1);
110 pdata->last_jiffies = jiffies;
111
112 flags = readb(pdata->ioaddr + RTC_FLAGS);
113 writeb(flags | RTC_READ, ioaddr + RTC_FLAGS);
114 second = readb(ioaddr + RTC_SECONDS) & RTC_SECONDS_MASK;
115 minute = readb(ioaddr + RTC_MINUTES);
116 hour = readb(ioaddr + RTC_HOURS);
117 day = readb(ioaddr + RTC_DATE);
118 week = readb(ioaddr + RTC_DAY) & RTC_DAY_MASK;
119 month = readb(ioaddr + RTC_MONTH);
120 year = readb(ioaddr + RTC_YEAR);
121 century = readb(ioaddr + RTC_CENTURY);
122 writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS);
123 tm->tm_sec = BCD2BIN(second);
124 tm->tm_min = BCD2BIN(minute);
125 tm->tm_hour = BCD2BIN(hour);
126 tm->tm_mday = BCD2BIN(day);
127 tm->tm_wday = BCD2BIN(week);
128 tm->tm_mon = BCD2BIN(month) - 1;
129 /* year is 1900 + tm->tm_year */
130 tm->tm_year = BCD2BIN(year) + BCD2BIN(century) * 100 - 1900;
131
132 if (rtc_valid_tm(tm) < 0) {
133 dev_err(dev, "retrieved date/time is not valid.\n");
134 rtc_time_to_tm(0, tm);
135 }
136 return 0;
137}
138
139static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata)
140{
141 void __iomem *ioaddr = pdata->ioaddr;
142 unsigned long irqflags;
143 u8 flags;
144
145 spin_lock_irqsave(&pdata->rtc->irq_lock, irqflags);
146
147 flags = readb(ioaddr + RTC_FLAGS);
148 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
149
150 writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
151 0x80 : BIN2BCD(pdata->alrm_mday),
152 ioaddr + RTC_DATE_ALARM);
153 writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
154 0x80 : BIN2BCD(pdata->alrm_hour),
155 ioaddr + RTC_HOURS_ALARM);
156 writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
157 0x80 : BIN2BCD(pdata->alrm_min),
158 ioaddr + RTC_MINUTES_ALARM);
159 writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
160 0x80 : BIN2BCD(pdata->alrm_sec),
161 ioaddr + RTC_SECONDS_ALARM);
162 writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS);
163 readb(ioaddr + RTC_FLAGS); /* clear interrupts */
164 writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
165 spin_unlock_irqrestore(&pdata->rtc->irq_lock, irqflags);
166}
167
168static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
169{
170 struct platform_device *pdev = to_platform_device(dev);
171 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
172
173 if (pdata->irq < 0)
174 return -EINVAL;
175 pdata->alrm_mday = alrm->time.tm_mday;
176 pdata->alrm_hour = alrm->time.tm_hour;
177 pdata->alrm_min = alrm->time.tm_min;
178 pdata->alrm_sec = alrm->time.tm_sec;
179 if (alrm->enabled)
180 pdata->irqen |= RTC_AF;
181 stk17ta8_rtc_update_alarm(pdata);
182 return 0;
183}
184
185static int stk17ta8_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
186{
187 struct platform_device *pdev = to_platform_device(dev);
188 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
189
190 if (pdata->irq < 0)
191 return -EINVAL;
192 alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday;
193 alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour;
194 alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min;
195 alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec;
196 alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0;
197 return 0;
198}
199
200static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id)
201{
202 struct platform_device *pdev = dev_id;
203 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
204 void __iomem *ioaddr = pdata->ioaddr;
205 unsigned long events = RTC_IRQF;
206
207 /* read and clear interrupt */
208 if (!(readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF))
209 return IRQ_NONE;
210 if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80)
211 events |= RTC_UF;
212 else
213 events |= RTC_AF;
214 rtc_update_irq(pdata->rtc, 1, events);
215 return IRQ_HANDLED;
216}
217
218static void stk17ta8_rtc_release(struct device *dev)
219{
220 struct platform_device *pdev = to_platform_device(dev);
221 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
222
223 if (pdata->irq >= 0) {
224 pdata->irqen = 0;
225 stk17ta8_rtc_update_alarm(pdata);
226 }
227}
228
229static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd,
230 unsigned long arg)
231{
232 struct platform_device *pdev = to_platform_device(dev);
233 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
234
235 if (pdata->irq < 0)
236 return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */
237 switch (cmd) {
238 case RTC_AIE_OFF:
239 pdata->irqen &= ~RTC_AF;
240 stk17ta8_rtc_update_alarm(pdata);
241 break;
242 case RTC_AIE_ON:
243 pdata->irqen |= RTC_AF;
244 stk17ta8_rtc_update_alarm(pdata);
245 break;
246 default:
247 return -ENOIOCTLCMD;
248 }
249 return 0;
250}
251
252static const struct rtc_class_ops stk17ta8_rtc_ops = {
253 .read_time = stk17ta8_rtc_read_time,
254 .set_time = stk17ta8_rtc_set_time,
255 .read_alarm = stk17ta8_rtc_read_alarm,
256 .set_alarm = stk17ta8_rtc_set_alarm,
257 .release = stk17ta8_rtc_release,
258 .ioctl = stk17ta8_rtc_ioctl,
259};
260
261static ssize_t stk17ta8_nvram_read(struct kobject *kobj, char *buf,
262 loff_t pos, size_t size)
263{
264 struct platform_device *pdev =
265 to_platform_device(container_of(kobj, struct device, kobj));
266 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
267 void __iomem *ioaddr = pdata->ioaddr;
268 ssize_t count;
269
270 for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
271 *buf++ = readb(ioaddr + pos++);
272 return count;
273}
274
275static ssize_t stk17ta8_nvram_write(struct kobject *kobj, char *buf,
276 loff_t pos, size_t size)
277{
278 struct platform_device *pdev =
279 to_platform_device(container_of(kobj, struct device, kobj));
280 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
281 void __iomem *ioaddr = pdata->ioaddr;
282 ssize_t count;
283
284 for (count = 0; size > 0 && pos < RTC_OFFSET; count++, size--)
285 writeb(*buf++, ioaddr + pos++);
286 return count;
287}
288
289static struct bin_attribute stk17ta8_nvram_attr = {
290 .attr = {
291 .name = "nvram",
292 .mode = S_IRUGO | S_IWUGO,
293 .owner = THIS_MODULE,
294 },
295 .size = RTC_OFFSET,
296 .read = stk17ta8_nvram_read,
297 .write = stk17ta8_nvram_write,
298};
299
300static int __init stk17ta8_rtc_probe(struct platform_device *pdev)
301{
302 struct rtc_device *rtc;
303 struct resource *res;
304 unsigned int cal;
305 unsigned int flags;
306 struct rtc_plat_data *pdata;
307 void __iomem *ioaddr = NULL;
308 int ret = 0;
309
310 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
311 if (!res)
312 return -ENODEV;
313
314 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
315 if (!pdata)
316 return -ENOMEM;
317 pdata->irq = -1;
318 if (!request_mem_region(res->start, RTC_REG_SIZE, pdev->name)) {
319 ret = -EBUSY;
320 goto out;
321 }
322 pdata->baseaddr = res->start;
323 ioaddr = ioremap(pdata->baseaddr, RTC_REG_SIZE);
324 if (!ioaddr) {
325 ret = -ENOMEM;
326 goto out;
327 }
328 pdata->ioaddr = ioaddr;
329 pdata->irq = platform_get_irq(pdev, 0);
330
331 /* turn RTC on if it was not on */
332 cal = readb(ioaddr + RTC_CALIBRATION);
333 if (cal & RTC_STOP) {
334 cal &= RTC_CAL_MASK;
335 flags = readb(ioaddr + RTC_FLAGS);
336 writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
337 writeb(cal, ioaddr + RTC_CALIBRATION);
338 writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
339 }
340 if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF)
341 dev_warn(&pdev->dev, "voltage-low detected.\n");
342
343 if (pdata->irq >= 0) {
344 writeb(0, ioaddr + RTC_INTERRUPTS);
345 if (request_irq(pdata->irq, stk17ta8_rtc_interrupt,
346 IRQF_DISABLED | IRQF_SHARED,
347 pdev->name, pdev) < 0) {
348 dev_warn(&pdev->dev, "interrupt not available.\n");
349 pdata->irq = -1;
350 }
351 }
352
353 rtc = rtc_device_register(pdev->name, &pdev->dev,
354 &stk17ta8_rtc_ops, THIS_MODULE);
355 if (IS_ERR(rtc)) {
356 ret = PTR_ERR(rtc);
357 goto out;
358 }
359 pdata->rtc = rtc;
360 pdata->last_jiffies = jiffies;
361 platform_set_drvdata(pdev, pdata);
362 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
363 if (ret)
364 goto out;
365 return 0;
366 out:
367 if (pdata->rtc)
368 rtc_device_unregister(pdata->rtc);
369 if (pdata->irq >= 0)
370 free_irq(pdata->irq, pdev);
371 if (ioaddr)
372 iounmap(ioaddr);
373 if (pdata->baseaddr)
374 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
375 kfree(pdata);
376 return ret;
377}
378
379static int __devexit stk17ta8_rtc_remove(struct platform_device *pdev)
380{
381 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
382
383 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
384 rtc_device_unregister(pdata->rtc);
385 if (pdata->irq >= 0) {
386 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
387 free_irq(pdata->irq, pdev);
388 }
389 iounmap(pdata->ioaddr);
390 release_mem_region(pdata->baseaddr, RTC_REG_SIZE);
391 kfree(pdata);
392 return 0;
393}
394
395static struct platform_driver stk17ta8_rtc_driver = {
396 .probe = stk17ta8_rtc_probe,
397 .remove = __devexit_p(stk17ta8_rtc_remove),
398 .driver = {
399 .name = "stk17ta8",
400 .owner = THIS_MODULE,
401 },
402};
403
404static __init int stk17ta8_init(void)
405{
406 return platform_driver_register(&stk17ta8_rtc_driver);
407}
408
409static __exit void stk17ta8_exit(void)
410{
411 return platform_driver_unregister(&stk17ta8_rtc_driver);
412}
413
414module_init(stk17ta8_init);
415module_exit(stk17ta8_exit);
416
417MODULE_AUTHOR("Thomas Hommel <thomas.hommel@gefanuc.com>");
418MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver");
419MODULE_LICENSE("GPL");
420MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index 002643392d42..2553629ec15d 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -33,6 +33,7 @@ struct sbus_bus *sbus_root;
33 33
34static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev) 34static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
35{ 35{
36 struct dev_archdata *sd;
36 unsigned long base; 37 unsigned long base;
37 const void *pval; 38 const void *pval;
38 int len, err; 39 int len, err;
@@ -67,6 +68,10 @@ static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sde
67 68
68 sbus_fill_device_irq(sdev); 69 sbus_fill_device_irq(sdev);
69 70
71 sd = &sdev->ofdev.dev.archdata;
72 sd->prom_node = dp;
73 sd->op = &sdev->ofdev;
74
70 sdev->ofdev.node = dp; 75 sdev->ofdev.node = dp;
71 if (sdev->parent) 76 if (sdev->parent)
72 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev; 77 sdev->ofdev.dev.parent = &sdev->parent->ofdev.dev;
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 372723161c97..a947257b8964 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -483,7 +483,7 @@ source "drivers/scsi/aic94xx/Kconfig"
483# All the I2O code and drivers do not seem to be 64bit safe. 483# All the I2O code and drivers do not seem to be 64bit safe.
484config SCSI_DPT_I2O 484config SCSI_DPT_I2O
485 tristate "Adaptec I2O RAID support " 485 tristate "Adaptec I2O RAID support "
486 depends on !64BIT && SCSI && PCI 486 depends on !64BIT && SCSI && PCI && VIRT_TO_BUS
487 help 487 help
488 This driver supports all of Adaptec's I2O based RAID controllers as 488 This driver supports all of Adaptec's I2O based RAID controllers as
489 well as the DPT SmartRaid V cards. This is an Adaptec maintained 489 well as the DPT SmartRaid V cards. This is an Adaptec maintained
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 0f8689557158..86a7ba7bad63 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -132,6 +132,7 @@ obj-$(CONFIG_SCSI_IBMVSCSI) += ibmvscsi/
132obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvscsi/ 132obj-$(CONFIG_SCSI_IBMVSCSIS) += ibmvscsi/
133obj-$(CONFIG_SCSI_HPTIOP) += hptiop.o 133obj-$(CONFIG_SCSI_HPTIOP) += hptiop.o
134obj-$(CONFIG_SCSI_STEX) += stex.o 134obj-$(CONFIG_SCSI_STEX) += stex.o
135obj-$(CONFIG_PS3_ROM) += ps3rom.o
135 136
136obj-$(CONFIG_ARM) += arm/ 137obj-$(CONFIG_ARM) += arm/
137 138
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
index 773d11dd9953..79b4df158140 100644
--- a/drivers/scsi/NCR53C9x.c
+++ b/drivers/scsi/NCR53C9x.c
@@ -95,6 +95,8 @@ enum {
95/* The master ring of all esp hosts we are managing in this driver. */ 95/* The master ring of all esp hosts we are managing in this driver. */
96static struct NCR_ESP *espchain; 96static struct NCR_ESP *espchain;
97int nesps = 0, esps_in_use = 0, esps_running = 0; 97int nesps = 0, esps_in_use = 0, esps_running = 0;
98EXPORT_SYMBOL(nesps);
99EXPORT_SYMBOL(esps_running);
98 100
99irqreturn_t esp_intr(int irq, void *dev_id); 101irqreturn_t esp_intr(int irq, void *dev_id);
100 102
@@ -524,6 +526,7 @@ void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs)
524 /* Eat any bitrot in the chip and we are done... */ 526 /* Eat any bitrot in the chip and we are done... */
525 trash = esp_read(eregs->esp_intrpt); 527 trash = esp_read(eregs->esp_intrpt);
526} 528}
529EXPORT_SYMBOL(esp_bootup_reset);
527 530
528/* Allocate structure and insert basic data such as SCSI chip frequency 531/* Allocate structure and insert basic data such as SCSI chip frequency
529 * data and a pointer to the device 532 * data and a pointer to the device
@@ -772,6 +775,7 @@ const char *esp_info(struct Scsi_Host *host)
772 panic("Bogon ESP revision"); 775 panic("Bogon ESP revision");
773 }; 776 };
774} 777}
778EXPORT_SYMBOL(esp_info);
775 779
776/* From Wolfgang Stanglmeier's NCR scsi driver. */ 780/* From Wolfgang Stanglmeier's NCR scsi driver. */
777struct info_str 781struct info_str
@@ -902,6 +906,7 @@ int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t off
902 *start = buffer; 906 *start = buffer;
903 return esp_host_info(esp, buffer, offset, length); 907 return esp_host_info(esp, buffer, offset, length);
904} 908}
909EXPORT_SYMBOL(esp_proc_info);
905 910
906static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp) 911static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
907{ 912{
@@ -3535,6 +3540,7 @@ state_machine:
3535 if(esp->dma_irq_exit) 3540 if(esp->dma_irq_exit)
3536 esp->dma_irq_exit(esp); 3541 esp->dma_irq_exit(esp);
3537} 3542}
3543EXPORT_SYMBOL(esp_handle);
3538 3544
3539#ifndef CONFIG_SMP 3545#ifndef CONFIG_SMP
3540irqreturn_t esp_intr(int irq, void *dev_id) 3546irqreturn_t esp_intr(int irq, void *dev_id)
@@ -3631,6 +3637,7 @@ void esp_release(void)
3631 esps_in_use--; 3637 esps_in_use--;
3632 esps_running = esps_in_use; 3638 esps_running = esps_in_use;
3633} 3639}
3640EXPORT_SYMBOL(esp_release);
3634#endif 3641#endif
3635 3642
3636EXPORT_SYMBOL(esp_abort); 3643EXPORT_SYMBOL(esp_abort);
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index aebcd5fcdc55..7829ab1e2fb4 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -1885,7 +1885,7 @@ static int iscsi_tcp_get_addr(struct iscsi_conn *conn, struct socket *sock,
1885 struct sockaddr_in *sin; 1885 struct sockaddr_in *sin;
1886 int rc = 0, len; 1886 int rc = 0, len;
1887 1887
1888 addr = kmalloc(GFP_KERNEL, sizeof(*addr)); 1888 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1889 if (!addr) 1889 if (!addr)
1890 return -ENOMEM; 1890 return -ENOMEM;
1891 1891
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
new file mode 100644
index 000000000000..b50f1e14f2a5
--- /dev/null
+++ b/drivers/scsi/ps3rom.c
@@ -0,0 +1,533 @@
1/*
2 * PS3 BD/DVD/CD-ROM Storage Driver
3 *
4 * Copyright (C) 2007 Sony Computer Entertainment Inc.
5 * Copyright 2007 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/cdrom.h>
22#include <linux/highmem.h>
23
24#include <scsi/scsi.h>
25#include <scsi/scsi_cmnd.h>
26#include <scsi/scsi_dbg.h>
27#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29
30#include <asm/lv1call.h>
31#include <asm/ps3stor.h>
32
33
34#define DEVICE_NAME "ps3rom"
35
36#define BOUNCE_SIZE (64*1024)
37
38#define PS3ROM_MAX_SECTORS (BOUNCE_SIZE / CD_FRAMESIZE)
39
40
41struct ps3rom_private {
42 struct ps3_storage_device *dev;
43 struct scsi_cmnd *curr_cmd;
44};
45
46
47#define LV1_STORAGE_SEND_ATAPI_COMMAND (1)
48
49struct lv1_atapi_cmnd_block {
50 u8 pkt[32]; /* packet command block */
51 u32 pktlen; /* should be 12 for ATAPI 8020 */
52 u32 blocks;
53 u32 block_size;
54 u32 proto; /* transfer mode */
55 u32 in_out; /* transfer direction */
56 u64 buffer; /* parameter except command block */
57 u32 arglen; /* length above */
58};
59
60enum lv1_atapi_proto {
61 NON_DATA_PROTO = 0,
62 PIO_DATA_IN_PROTO = 1,
63 PIO_DATA_OUT_PROTO = 2,
64 DMA_PROTO = 3
65};
66
67enum lv1_atapi_in_out {
68 DIR_WRITE = 0, /* memory -> device */
69 DIR_READ = 1 /* device -> memory */
70};
71
72
73static int ps3rom_slave_configure(struct scsi_device *scsi_dev)
74{
75 struct ps3rom_private *priv = shost_priv(scsi_dev->host);
76 struct ps3_storage_device *dev = priv->dev;
77
78 dev_dbg(&dev->sbd.core, "%s:%u: id %u, lun %u, channel %u\n", __func__,
79 __LINE__, scsi_dev->id, scsi_dev->lun, scsi_dev->channel);
80
81 /*
82 * ATAPI SFF8020 devices use MODE_SENSE_10,
83 * so we can prohibit MODE_SENSE_6
84 */
85 scsi_dev->use_10_for_ms = 1;
86
87 /* we don't support {READ,WRITE}_6 */
88 scsi_dev->use_10_for_rw = 1;
89
90 return 0;
91}
92
93/*
94 * copy data from device into scatter/gather buffer
95 */
96static int fill_from_dev_buffer(struct scsi_cmnd *cmd, const void *buf)
97{
98 int k, req_len, act_len, len, active;
99 void *kaddr;
100 struct scatterlist *sgpnt;
101 unsigned int buflen;
102
103 buflen = cmd->request_bufflen;
104 if (!buflen)
105 return 0;
106
107 if (!cmd->request_buffer)
108 return -1;
109
110 sgpnt = cmd->request_buffer;
111 active = 1;
112 for (k = 0, req_len = 0, act_len = 0; k < cmd->use_sg; ++k, ++sgpnt) {
113 if (active) {
114 kaddr = kmap_atomic(sgpnt->page, KM_IRQ0);
115 len = sgpnt->length;
116 if ((req_len + len) > buflen) {
117 active = 0;
118 len = buflen - req_len;
119 }
120 memcpy(kaddr + sgpnt->offset, buf + req_len, len);
121 flush_kernel_dcache_page(sgpnt->page);
122 kunmap_atomic(kaddr, KM_IRQ0);
123 act_len += len;
124 }
125 req_len += sgpnt->length;
126 }
127 cmd->resid = req_len - act_len;
128 return 0;
129}
130
131/*
132 * copy data from scatter/gather into device's buffer
133 */
134static int fetch_to_dev_buffer(struct scsi_cmnd *cmd, void *buf)
135{
136 int k, req_len, len, fin;
137 void *kaddr;
138 struct scatterlist *sgpnt;
139 unsigned int buflen;
140
141 buflen = cmd->request_bufflen;
142 if (!buflen)
143 return 0;
144
145 if (!cmd->request_buffer)
146 return -1;
147
148 sgpnt = cmd->request_buffer;
149 for (k = 0, req_len = 0, fin = 0; k < cmd->use_sg; ++k, ++sgpnt) {
150 kaddr = kmap_atomic(sgpnt->page, KM_IRQ0);
151 len = sgpnt->length;
152 if ((req_len + len) > buflen) {
153 len = buflen - req_len;
154 fin = 1;
155 }
156 memcpy(buf + req_len, kaddr + sgpnt->offset, len);
157 kunmap_atomic(kaddr, KM_IRQ0);
158 if (fin)
159 return req_len + len;
160 req_len += sgpnt->length;
161 }
162 return req_len;
163}
164
165static int ps3rom_atapi_request(struct ps3_storage_device *dev,
166 struct scsi_cmnd *cmd)
167{
168 struct lv1_atapi_cmnd_block atapi_cmnd;
169 unsigned char opcode = cmd->cmnd[0];
170 int res;
171 u64 lpar;
172
173 dev_dbg(&dev->sbd.core, "%s:%u: send ATAPI command 0x%02x\n", __func__,
174 __LINE__, opcode);
175
176 memset(&atapi_cmnd, 0, sizeof(struct lv1_atapi_cmnd_block));
177 memcpy(&atapi_cmnd.pkt, cmd->cmnd, 12);
178 atapi_cmnd.pktlen = 12;
179 atapi_cmnd.block_size = 1; /* transfer size is block_size * blocks */
180 atapi_cmnd.blocks = atapi_cmnd.arglen = cmd->request_bufflen;
181 atapi_cmnd.buffer = dev->bounce_lpar;
182
183 switch (cmd->sc_data_direction) {
184 case DMA_FROM_DEVICE:
185 if (cmd->request_bufflen >= CD_FRAMESIZE)
186 atapi_cmnd.proto = DMA_PROTO;
187 else
188 atapi_cmnd.proto = PIO_DATA_IN_PROTO;
189 atapi_cmnd.in_out = DIR_READ;
190 break;
191
192 case DMA_TO_DEVICE:
193 if (cmd->request_bufflen >= CD_FRAMESIZE)
194 atapi_cmnd.proto = DMA_PROTO;
195 else
196 atapi_cmnd.proto = PIO_DATA_OUT_PROTO;
197 atapi_cmnd.in_out = DIR_WRITE;
198 res = fetch_to_dev_buffer(cmd, dev->bounce_buf);
199 if (res < 0)
200 return DID_ERROR << 16;
201 break;
202
203 default:
204 atapi_cmnd.proto = NON_DATA_PROTO;
205 break;
206 }
207
208 lpar = ps3_mm_phys_to_lpar(__pa(&atapi_cmnd));
209 res = lv1_storage_send_device_command(dev->sbd.dev_id,
210 LV1_STORAGE_SEND_ATAPI_COMMAND,
211 lpar, sizeof(atapi_cmnd),
212 atapi_cmnd.buffer,
213 atapi_cmnd.arglen, &dev->tag);
214 if (res == LV1_DENIED_BY_POLICY) {
215 dev_dbg(&dev->sbd.core,
216 "%s:%u: ATAPI command 0x%02x denied by policy\n",
217 __func__, __LINE__, opcode);
218 return DID_ERROR << 16;
219 }
220
221 if (res) {
222 dev_err(&dev->sbd.core,
223 "%s:%u: ATAPI command 0x%02x failed %d\n", __func__,
224 __LINE__, opcode, res);
225 return DID_ERROR << 16;
226 }
227
228 return 0;
229}
230
231static inline unsigned int srb10_lba(const struct scsi_cmnd *cmd)
232{
233 return cmd->cmnd[2] << 24 | cmd->cmnd[3] << 16 | cmd->cmnd[4] << 8 |
234 cmd->cmnd[5];
235}
236
237static inline unsigned int srb10_len(const struct scsi_cmnd *cmd)
238{
239 return cmd->cmnd[7] << 8 | cmd->cmnd[8];
240}
241
242static int ps3rom_read_request(struct ps3_storage_device *dev,
243 struct scsi_cmnd *cmd, u32 start_sector,
244 u32 sectors)
245{
246 int res;
247
248 dev_dbg(&dev->sbd.core, "%s:%u: read %u sectors starting at %u\n",
249 __func__, __LINE__, sectors, start_sector);
250
251 res = lv1_storage_read(dev->sbd.dev_id,
252 dev->regions[dev->region_idx].id, start_sector,
253 sectors, 0, dev->bounce_lpar, &dev->tag);
254 if (res) {
255 dev_err(&dev->sbd.core, "%s:%u: read failed %d\n", __func__,
256 __LINE__, res);
257 return DID_ERROR << 16;
258 }
259
260 return 0;
261}
262
263static int ps3rom_write_request(struct ps3_storage_device *dev,
264 struct scsi_cmnd *cmd, u32 start_sector,
265 u32 sectors)
266{
267 int res;
268
269 dev_dbg(&dev->sbd.core, "%s:%u: write %u sectors starting at %u\n",
270 __func__, __LINE__, sectors, start_sector);
271
272 res = fetch_to_dev_buffer(cmd, dev->bounce_buf);
273 if (res < 0)
274 return DID_ERROR << 16;
275
276 res = lv1_storage_write(dev->sbd.dev_id,
277 dev->regions[dev->region_idx].id, start_sector,
278 sectors, 0, dev->bounce_lpar, &dev->tag);
279 if (res) {
280 dev_err(&dev->sbd.core, "%s:%u: write failed %d\n", __func__,
281 __LINE__, res);
282 return DID_ERROR << 16;
283 }
284
285 return 0;
286}
287
288static int ps3rom_queuecommand(struct scsi_cmnd *cmd,
289 void (*done)(struct scsi_cmnd *))
290{
291 struct ps3rom_private *priv = shost_priv(cmd->device->host);
292 struct ps3_storage_device *dev = priv->dev;
293 unsigned char opcode;
294 int res;
295
296#ifdef DEBUG
297 scsi_print_command(cmd);
298#endif
299
300 priv->curr_cmd = cmd;
301 cmd->scsi_done = done;
302
303 opcode = cmd->cmnd[0];
304 /*
305 * While we can submit READ/WRITE SCSI commands as ATAPI commands,
306 * it's recommended for various reasons (performance, error handling,
307 * ...) to use lv1_storage_{read,write}() instead
308 */
309 switch (opcode) {
310 case READ_10:
311 res = ps3rom_read_request(dev, cmd, srb10_lba(cmd),
312 srb10_len(cmd));
313 break;
314
315 case WRITE_10:
316 res = ps3rom_write_request(dev, cmd, srb10_lba(cmd),
317 srb10_len(cmd));
318 break;
319
320 default:
321 res = ps3rom_atapi_request(dev, cmd);
322 break;
323 }
324
325 if (res) {
326 memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
327 cmd->result = res;
328 cmd->sense_buffer[0] = 0x70;
329 cmd->sense_buffer[2] = ILLEGAL_REQUEST;
330 priv->curr_cmd = NULL;
331 cmd->scsi_done(cmd);
332 }
333
334 return 0;
335}
336
337static int decode_lv1_status(u64 status, unsigned char *sense_key,
338 unsigned char *asc, unsigned char *ascq)
339{
340 if (((status >> 24) & 0xff) != SAM_STAT_CHECK_CONDITION)
341 return -1;
342
343 *sense_key = (status >> 16) & 0xff;
344 *asc = (status >> 8) & 0xff;
345 *ascq = status & 0xff;
346 return 0;
347}
348
349static irqreturn_t ps3rom_interrupt(int irq, void *data)
350{
351 struct ps3_storage_device *dev = data;
352 struct Scsi_Host *host;
353 struct ps3rom_private *priv;
354 struct scsi_cmnd *cmd;
355 int res;
356 u64 tag, status;
357 unsigned char sense_key, asc, ascq;
358
359 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
360 /*
361 * status = -1 may mean that ATAPI transport completed OK, but
362 * ATAPI command itself resulted CHECK CONDITION
363 * so, upper layer should issue REQUEST_SENSE to check the sense data
364 */
365
366 if (tag != dev->tag)
367 dev_err(&dev->sbd.core,
368 "%s:%u: tag mismatch, got %lx, expected %lx\n",
369 __func__, __LINE__, tag, dev->tag);
370
371 if (res) {
372 dev_err(&dev->sbd.core, "%s:%u: res=%d status=0x%lx\n",
373 __func__, __LINE__, res, status);
374 return IRQ_HANDLED;
375 }
376
377 host = dev->sbd.core.driver_data;
378 priv = shost_priv(host);
379 cmd = priv->curr_cmd;
380
381 if (!status) {
382 /* OK, completed */
383 if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
384 res = fill_from_dev_buffer(cmd, dev->bounce_buf);
385 if (res) {
386 cmd->result = DID_ERROR << 16;
387 goto done;
388 }
389 }
390 cmd->result = DID_OK << 16;
391 goto done;
392 }
393
394 if (cmd->cmnd[0] == REQUEST_SENSE) {
395 /* SCSI spec says request sense should never get error */
396 dev_err(&dev->sbd.core, "%s:%u: end error without autosense\n",
397 __func__, __LINE__);
398 cmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
399 goto done;
400 }
401
402 if (decode_lv1_status(status, &sense_key, &asc, &ascq)) {
403 cmd->result = DID_ERROR << 16;
404 goto done;
405 }
406
407 cmd->sense_buffer[0] = 0x70;
408 cmd->sense_buffer[2] = sense_key;
409 cmd->sense_buffer[7] = 16 - 6;
410 cmd->sense_buffer[12] = asc;
411 cmd->sense_buffer[13] = ascq;
412 cmd->result = SAM_STAT_CHECK_CONDITION;
413
414done:
415 priv->curr_cmd = NULL;
416 cmd->scsi_done(cmd);
417 return IRQ_HANDLED;
418}
419
420static struct scsi_host_template ps3rom_host_template = {
421 .name = DEVICE_NAME,
422 .slave_configure = ps3rom_slave_configure,
423 .queuecommand = ps3rom_queuecommand,
424 .can_queue = 1,
425 .this_id = 7,
426 .sg_tablesize = SG_ALL,
427 .cmd_per_lun = 1,
428 .emulated = 1, /* only sg driver uses this */
429 .max_sectors = PS3ROM_MAX_SECTORS,
430 .use_clustering = ENABLE_CLUSTERING,
431 .module = THIS_MODULE,
432};
433
434
435static int __devinit ps3rom_probe(struct ps3_system_bus_device *_dev)
436{
437 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
438 int error;
439 struct Scsi_Host *host;
440 struct ps3rom_private *priv;
441
442 if (dev->blk_size != CD_FRAMESIZE) {
443 dev_err(&dev->sbd.core,
444 "%s:%u: cannot handle block size %lu\n", __func__,
445 __LINE__, dev->blk_size);
446 return -EINVAL;
447 }
448
449 dev->bounce_size = BOUNCE_SIZE;
450 dev->bounce_buf = kmalloc(BOUNCE_SIZE, GFP_DMA);
451 if (!dev->bounce_buf)
452 return -ENOMEM;
453
454 error = ps3stor_setup(dev, ps3rom_interrupt);
455 if (error)
456 goto fail_free_bounce;
457
458 host = scsi_host_alloc(&ps3rom_host_template,
459 sizeof(struct ps3rom_private));
460 if (!host) {
461 dev_err(&dev->sbd.core, "%s:%u: scsi_host_alloc failed\n",
462 __func__, __LINE__);
463 goto fail_teardown;
464 }
465
466 priv = shost_priv(host);
467 dev->sbd.core.driver_data = host;
468 priv->dev = dev;
469
470 /* One device/LUN per SCSI bus */
471 host->max_id = 1;
472 host->max_lun = 1;
473
474 error = scsi_add_host(host, &dev->sbd.core);
475 if (error) {
476 dev_err(&dev->sbd.core, "%s:%u: scsi_host_alloc failed %d\n",
477 __func__, __LINE__, error);
478 error = -ENODEV;
479 goto fail_host_put;
480 }
481
482 scsi_scan_host(host);
483 return 0;
484
485fail_host_put:
486 scsi_host_put(host);
487 dev->sbd.core.driver_data = NULL;
488fail_teardown:
489 ps3stor_teardown(dev);
490fail_free_bounce:
491 kfree(dev->bounce_buf);
492 return error;
493}
494
495static int ps3rom_remove(struct ps3_system_bus_device *_dev)
496{
497 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
498 struct Scsi_Host *host = dev->sbd.core.driver_data;
499
500 scsi_remove_host(host);
501 ps3stor_teardown(dev);
502 scsi_host_put(host);
503 dev->sbd.core.driver_data = NULL;
504 kfree(dev->bounce_buf);
505 return 0;
506}
507
508static struct ps3_system_bus_driver ps3rom = {
509 .match_id = PS3_MATCH_ID_STOR_ROM,
510 .core.name = DEVICE_NAME,
511 .core.owner = THIS_MODULE,
512 .probe = ps3rom_probe,
513 .remove = ps3rom_remove
514};
515
516
517static int __init ps3rom_init(void)
518{
519 return ps3_system_bus_driver_register(&ps3rom);
520}
521
522static void __exit ps3rom_exit(void)
523{
524 ps3_system_bus_driver_unregister(&ps3rom);
525}
526
527module_init(ps3rom_init);
528module_exit(ps3rom_exit);
529
530MODULE_LICENSE("GPL");
531MODULE_DESCRIPTION("PS3 BD/DVD/CD-ROM Storage Driver");
532MODULE_AUTHOR("Sony Corporation");
533MODULE_ALIAS(PS3_MODULE_ALIAS_STOR_ROM);
diff --git a/drivers/serial/suncore.c b/drivers/serial/suncore.c
index b45ba5392dd3..70a09a3d5af0 100644
--- a/drivers/serial/suncore.c
+++ b/drivers/serial/suncore.c
@@ -16,9 +16,10 @@
16#include <linux/tty.h> 16#include <linux/tty.h>
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/serial_core.h>
19#include <linux/init.h> 20#include <linux/init.h>
20 21
21#include <asm/oplib.h> 22#include <asm/prom.h>
22 23
23#include "suncore.h" 24#include "suncore.h"
24 25
@@ -26,92 +27,60 @@ int sunserial_current_minor = 64;
26 27
27EXPORT_SYMBOL(sunserial_current_minor); 28EXPORT_SYMBOL(sunserial_current_minor);
28 29
29void 30int sunserial_console_match(struct console *con, struct device_node *dp,
30sunserial_console_termios(struct console *con) 31 struct uart_driver *drv, int line)
31{ 32{
32 char mode[16], buf[16], *s; 33 int off;
33 char mode_prop[] = "ttyX-mode";
34 char cd_prop[] = "ttyX-ignore-cd";
35 char dtr_prop[] = "ttyX-rts-dtr-off";
36 char *ssp_console_modes_prop = "ssp-console-modes";
37 int baud, bits, stop, cflag;
38 char parity;
39 int carrier = 0;
40 int rtsdtr = 1;
41 int topnd, nd;
42
43 if (!serial_console)
44 return;
45
46 switch (serial_console) {
47 case PROMDEV_OTTYA:
48 mode_prop[3] = 'a';
49 cd_prop[3] = 'a';
50 dtr_prop[3] = 'a';
51 break;
52
53 case PROMDEV_OTTYB:
54 mode_prop[3] = 'b';
55 cd_prop[3] = 'b';
56 dtr_prop[3] = 'b';
57 break;
58
59 case PROMDEV_ORSC:
60
61 nd = prom_pathtoinode("rsc");
62 if (!nd) {
63 strcpy(mode, "115200,8,n,1,-");
64 goto no_options;
65 }
66 34
67 if (!prom_node_has_property(nd, ssp_console_modes_prop)) { 35 if (!con || of_console_device != dp)
68 strcpy(mode, "115200,8,n,1,-"); 36 return 0;
69 goto no_options;
70 }
71 37
72 memset(mode, 0, sizeof(mode)); 38 off = 0;
73 prom_getstring(nd, ssp_console_modes_prop, mode, sizeof(mode)); 39 if (of_console_options &&
74 goto no_options; 40 *of_console_options == 'b')
41 off = 1;
75 42
76 default: 43 if ((line & 1) != off)
77 strcpy(mode, "9600,8,n,1,-"); 44 return 0;
78 goto no_options;
79 }
80 45
81 topnd = prom_getchild(prom_root_node); 46 con->index = line;
82 nd = prom_searchsiblings(topnd, "options"); 47 drv->cons = con;
83 if (!nd) { 48 add_preferred_console(con->name, line, NULL);
84 strcpy(mode, "9600,8,n,1,-");
85 goto no_options;
86 }
87
88 if (!prom_node_has_property(nd, mode_prop)) {
89 strcpy(mode, "9600,8,n,1,-");
90 goto no_options;
91 }
92 49
93 memset(mode, 0, sizeof(mode)); 50 return 1;
94 prom_getstring(nd, mode_prop, mode, sizeof(mode)); 51}
95 52EXPORT_SYMBOL(sunserial_console_match);
96 if (prom_node_has_property(nd, cd_prop)) {
97 memset(buf, 0, sizeof(buf));
98 prom_getstring(nd, cd_prop, buf, sizeof(buf));
99 if (!strcmp(buf, "false"))
100 carrier = 1;
101
102 /* XXX: this is unused below. */
103 }
104 53
105 if (prom_node_has_property(nd, dtr_prop)) { 54void
106 memset(buf, 0, sizeof(buf)); 55sunserial_console_termios(struct console *con)
107 prom_getstring(nd, dtr_prop, buf, sizeof(buf)); 56{
108 if (!strcmp(buf, "false")) 57 struct device_node *dp;
109 rtsdtr = 0; 58 const char *od, *mode, *s;
59 char mode_prop[] = "ttyX-mode";
60 int baud, bits, stop, cflag;
61 char parity;
110 62
111 /* XXX: this is unused below. */ 63 dp = of_find_node_by_path("/options");
64 od = of_get_property(dp, "output-device", NULL);
65 if (!strcmp(od, "rsc")) {
66 mode = of_get_property(of_console_device,
67 "ssp-console-modes", NULL);
68 if (!mode)
69 mode = "115200,8,n,1,-";
70 } else {
71 char c;
72
73 c = 'a';
74 if (of_console_options)
75 c = *of_console_options;
76
77 mode_prop[3] = c;
78
79 mode = of_get_property(dp, mode_prop, NULL);
80 if (!mode)
81 mode = "9600,8,n,1,-";
112 } 82 }
113 83
114no_options:
115 cflag = CREAD | HUPCL | CLOCAL; 84 cflag = CREAD | HUPCL | CLOCAL;
116 85
117 s = mode; 86 s = mode;
diff --git a/drivers/serial/suncore.h b/drivers/serial/suncore.h
index 513916a8ce37..829d7d65d6db 100644
--- a/drivers/serial/suncore.h
+++ b/drivers/serial/suncore.h
@@ -24,6 +24,8 @@ extern int suncore_mouse_baud_detection(unsigned char, int);
24 24
25extern int sunserial_current_minor; 25extern int sunserial_current_minor;
26 26
27extern int sunserial_console_match(struct console *, struct device_node *,
28 struct uart_driver *, int);
27extern void sunserial_console_termios(struct console *); 29extern void sunserial_console_termios(struct console *);
28 30
29#endif /* !(_SERIAL_SUN_H) */ 31#endif /* !(_SERIAL_SUN_H) */
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index d82be42ff29a..8ff900b09811 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -520,16 +520,6 @@ static struct console sunhv_console = {
520 .data = &sunhv_reg, 520 .data = &sunhv_reg,
521}; 521};
522 522
523static inline struct console *SUNHV_CONSOLE(void)
524{
525 if (con_is_present())
526 return NULL;
527
528 sunhv_console.index = 0;
529
530 return &sunhv_console;
531}
532
533static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match) 523static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match)
534{ 524{
535 struct uart_port *port; 525 struct uart_port *port;
@@ -582,7 +572,8 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
582 sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64; 572 sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
583 sunserial_current_minor += 1; 573 sunserial_current_minor += 1;
584 574
585 sunhv_reg.cons = SUNHV_CONSOLE(); 575 sunserial_console_match(&sunhv_console, op->node,
576 &sunhv_reg, port->line);
586 577
587 err = uart_add_one_port(&sunhv_reg, port); 578 err = uart_add_one_port(&sunhv_reg, port);
588 if (err) 579 if (err)
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 8a0f9e4408d4..bca57bb94939 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -968,22 +968,6 @@ static struct console sunsab_console = {
968 968
969static inline struct console *SUNSAB_CONSOLE(void) 969static inline struct console *SUNSAB_CONSOLE(void)
970{ 970{
971 int i;
972
973 if (con_is_present())
974 return NULL;
975
976 for (i = 0; i < num_channels; i++) {
977 int this_minor = sunsab_reg.minor + i;
978
979 if ((this_minor - 64) == (serial_console - 1))
980 break;
981 }
982 if (i == num_channels)
983 return NULL;
984
985 sunsab_console.index = i;
986
987 return &sunsab_console; 971 return &sunsab_console;
988} 972}
989#else 973#else
@@ -1080,7 +1064,12 @@ static int __devinit sab_probe(struct of_device *op, const struct of_device_id *
1080 return err; 1064 return err;
1081 } 1065 }
1082 1066
1067 sunserial_console_match(SUNSAB_CONSOLE(), op->node,
1068 &sunsab_reg, up[0].port.line);
1083 uart_add_one_port(&sunsab_reg, &up[0].port); 1069 uart_add_one_port(&sunsab_reg, &up[0].port);
1070
1071 sunserial_console_match(SUNSAB_CONSOLE(), op->node,
1072 &sunsab_reg, up[1].port.line);
1084 uart_add_one_port(&sunsab_reg, &up[1].port); 1073 uart_add_one_port(&sunsab_reg, &up[1].port);
1085 1074
1086 dev_set_drvdata(&op->dev, &up[0]); 1075 dev_set_drvdata(&op->dev, &up[0]);
@@ -1164,7 +1153,6 @@ static int __init sunsab_init(void)
1164 } 1153 }
1165 1154
1166 sunsab_reg.tty_driver->name_base = sunsab_reg.minor - 64; 1155 sunsab_reg.tty_driver->name_base = sunsab_reg.minor - 64;
1167 sunsab_reg.cons = SUNSAB_CONSOLE();
1168 sunserial_current_minor += num_channels; 1156 sunserial_current_minor += num_channels;
1169 } 1157 }
1170 1158
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index 26d720baf88c..79b13685bdfa 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -1371,28 +1371,12 @@ static struct console sunsu_console = {
1371 * Register console. 1371 * Register console.
1372 */ 1372 */
1373 1373
1374static inline struct console *SUNSU_CONSOLE(int num_uart) 1374static inline struct console *SUNSU_CONSOLE(void)
1375{ 1375{
1376 int i;
1377
1378 if (con_is_present())
1379 return NULL;
1380
1381 for (i = 0; i < num_uart; i++) {
1382 int this_minor = sunsu_reg.minor + i;
1383
1384 if ((this_minor - 64) == (serial_console - 1))
1385 break;
1386 }
1387 if (i == num_uart)
1388 return NULL;
1389
1390 sunsu_console.index = i;
1391
1392 return &sunsu_console; 1376 return &sunsu_console;
1393} 1377}
1394#else 1378#else
1395#define SUNSU_CONSOLE(num_uart) (NULL) 1379#define SUNSU_CONSOLE() (NULL)
1396#define sunsu_serial_console_init() do { } while (0) 1380#define sunsu_serial_console_init() do { } while (0)
1397#endif 1381#endif
1398 1382
@@ -1482,6 +1466,8 @@ static int __devinit su_probe(struct of_device *op, const struct of_device_id *m
1482 1466
1483 up->port.ops = &sunsu_pops; 1467 up->port.ops = &sunsu_pops;
1484 1468
1469 sunserial_console_match(SUNSU_CONSOLE(), dp,
1470 &sunsu_reg, up->port.line);
1485 err = uart_add_one_port(&sunsu_reg, &up->port); 1471 err = uart_add_one_port(&sunsu_reg, &up->port);
1486 if (err) 1472 if (err)
1487 goto out_unmap; 1473 goto out_unmap;
@@ -1572,7 +1558,6 @@ static int __init sunsu_init(void)
1572 return err; 1558 return err;
1573 sunsu_reg.tty_driver->name_base = sunsu_reg.minor - 64; 1559 sunsu_reg.tty_driver->name_base = sunsu_reg.minor - 64;
1574 sunserial_current_minor += num_uart; 1560 sunserial_current_minor += num_uart;
1575 sunsu_reg.cons = SUNSU_CONSOLE(num_uart);
1576 } 1561 }
1577 1562
1578 err = of_register_driver(&su_driver, &of_bus_type); 1563 err = of_register_driver(&su_driver, &of_bus_type);
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 0a3e10a4a35d..1d262c0c613f 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1226,23 +1226,6 @@ static struct console sunzilog_console_ops = {
1226 1226
1227static inline struct console *SUNZILOG_CONSOLE(void) 1227static inline struct console *SUNZILOG_CONSOLE(void)
1228{ 1228{
1229 int i;
1230
1231 if (con_is_present())
1232 return NULL;
1233
1234 for (i = 0; i < NUM_CHANNELS; i++) {
1235 int this_minor = sunzilog_reg.minor + i;
1236
1237 if ((this_minor - 64) == (serial_console - 1))
1238 break;
1239 }
1240 if (i == NUM_CHANNELS)
1241 return NULL;
1242
1243 sunzilog_console_ops.index = i;
1244 sunzilog_port_table[i].flags |= SUNZILOG_FLAG_IS_CONS;
1245
1246 return &sunzilog_console_ops; 1229 return &sunzilog_console_ops;
1247} 1230}
1248 1231
@@ -1428,12 +1411,18 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1428 sunzilog_init_hw(&up[1]); 1411 sunzilog_init_hw(&up[1]);
1429 1412
1430 if (!keyboard_mouse) { 1413 if (!keyboard_mouse) {
1414 if (sunserial_console_match(SUNZILOG_CONSOLE(), op->node,
1415 &sunzilog_reg, up[0].port.line))
1416 up->flags |= SUNZILOG_FLAG_IS_CONS;
1431 err = uart_add_one_port(&sunzilog_reg, &up[0].port); 1417 err = uart_add_one_port(&sunzilog_reg, &up[0].port);
1432 if (err) { 1418 if (err) {
1433 of_iounmap(&op->resource[0], 1419 of_iounmap(&op->resource[0],
1434 rp, sizeof(struct zilog_layout)); 1420 rp, sizeof(struct zilog_layout));
1435 return err; 1421 return err;
1436 } 1422 }
1423 if (sunserial_console_match(SUNZILOG_CONSOLE(), op->node,
1424 &sunzilog_reg, up[1].port.line))
1425 up->flags |= SUNZILOG_FLAG_IS_CONS;
1437 err = uart_add_one_port(&sunzilog_reg, &up[1].port); 1426 err = uart_add_one_port(&sunzilog_reg, &up[1].port);
1438 if (err) { 1427 if (err) {
1439 uart_remove_one_port(&sunzilog_reg, &up[0].port); 1428 uart_remove_one_port(&sunzilog_reg, &up[0].port);
@@ -1531,7 +1520,6 @@ static int __init sunzilog_init(void)
1531 goto out_free_tables; 1520 goto out_free_tables;
1532 1521
1533 sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64; 1522 sunzilog_reg.tty_driver->name_base = sunzilog_reg.minor - 64;
1534 sunzilog_reg.cons = SUNZILOG_CONSOLE();
1535 1523
1536 sunserial_current_minor += uart_count; 1524 sunserial_current_minor += uart_count;
1537 } 1525 }
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 018884d7a5fa..b05de30b5d9b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -303,8 +303,7 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
303 * creates board info from kernel command lines 303 * creates board info from kernel command lines
304 */ 304 */
305 305
306static void __init_or_module 306static void scan_boardinfo(struct spi_master *master)
307scan_boardinfo(struct spi_master *master)
308{ 307{
309 struct boardinfo *bi; 308 struct boardinfo *bi;
310 struct device *dev = master->cdev.dev; 309 struct device *dev = master->cdev.dev;
diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
index 1bc884051e0f..02c52f8d5dbf 100644
--- a/drivers/usb/atm/cxacru.c
+++ b/drivers/usb/atm/cxacru.c
@@ -456,7 +456,7 @@ static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
456 int* actual_length) 456 int* actual_length)
457{ 457{
458 struct timer_list timer; 458 struct timer_list timer;
459 int status; 459 int status = urb->status;
460 460
461 init_timer(&timer); 461 init_timer(&timer);
462 timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT); 462 timer.expires = jiffies + msecs_to_jiffies(CMD_TIMEOUT);
@@ -464,7 +464,6 @@ static int cxacru_start_wait_urb(struct urb *urb, struct completion *done,
464 timer.function = cxacru_timeout_kill; 464 timer.function = cxacru_timeout_kill;
465 add_timer(&timer); 465 add_timer(&timer);
466 wait_for_completion(done); 466 wait_for_completion(done);
467 status = urb->status;
468 del_timer_sync(&timer); 467 del_timer_sync(&timer);
469 468
470 if (actual_length) 469 if (actual_length)
diff --git a/drivers/usb/atm/speedtch.c b/drivers/usb/atm/speedtch.c
index 638b8009b3bc..eb0615abff68 100644
--- a/drivers/usb/atm/speedtch.c
+++ b/drivers/usb/atm/speedtch.c
@@ -612,7 +612,8 @@ static void speedtch_handle_int(struct urb *int_urb)
612 struct speedtch_instance_data *instance = int_urb->context; 612 struct speedtch_instance_data *instance = int_urb->context;
613 struct usbatm_data *usbatm = instance->usbatm; 613 struct usbatm_data *usbatm = instance->usbatm;
614 unsigned int count = int_urb->actual_length; 614 unsigned int count = int_urb->actual_length;
615 int ret = int_urb->status; 615 int status = int_urb->status;
616 int ret;
616 617
617 /* The magic interrupt for "up state" */ 618 /* The magic interrupt for "up state" */
618 static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 }; 619 static const unsigned char up_int[6] = { 0xa1, 0x00, 0x01, 0x00, 0x00, 0x00 };
@@ -621,8 +622,8 @@ static void speedtch_handle_int(struct urb *int_urb)
621 622
622 atm_dbg(usbatm, "%s entered\n", __func__); 623 atm_dbg(usbatm, "%s entered\n", __func__);
623 624
624 if (ret < 0) { 625 if (status < 0) {
625 atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, ret); 626 atm_dbg(usbatm, "%s: nonzero urb status %d!\n", __func__, status);
626 goto fail; 627 goto fail;
627 } 628 }
628 629
diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index 8f046659b4e9..a1a1c9d467e0 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -1308,11 +1308,13 @@ static void uea_intr(struct urb *urb)
1308{ 1308{
1309 struct uea_softc *sc = urb->context; 1309 struct uea_softc *sc = urb->context;
1310 struct intr_pkt *intr = urb->transfer_buffer; 1310 struct intr_pkt *intr = urb->transfer_buffer;
1311 int status = urb->status;
1312
1311 uea_enters(INS_TO_USBDEV(sc)); 1313 uea_enters(INS_TO_USBDEV(sc));
1312 1314
1313 if (unlikely(urb->status < 0)) { 1315 if (unlikely(status < 0)) {
1314 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n", 1316 uea_err(INS_TO_USBDEV(sc), "uea_intr() failed with %d\n",
1315 urb->status); 1317 status);
1316 return; 1318 return;
1317 } 1319 }
1318 1320
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 11e9b15ca45a..e717f5b1caee 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -257,9 +257,10 @@ static void usbatm_complete(struct urb *urb)
257{ 257{
258 struct usbatm_channel *channel = urb->context; 258 struct usbatm_channel *channel = urb->context;
259 unsigned long flags; 259 unsigned long flags;
260 int status = urb->status;
260 261
261 vdbg("%s: urb 0x%p, status %d, actual_length %d", 262 vdbg("%s: urb 0x%p, status %d, actual_length %d",
262 __func__, urb, urb->status, urb->actual_length); 263 __func__, urb, status, urb->actual_length);
263 264
264 /* usually in_interrupt(), but not always */ 265 /* usually in_interrupt(), but not always */
265 spin_lock_irqsave(&channel->lock, flags); 266 spin_lock_irqsave(&channel->lock, flags);
@@ -269,16 +270,16 @@ static void usbatm_complete(struct urb *urb)
269 270
270 spin_unlock_irqrestore(&channel->lock, flags); 271 spin_unlock_irqrestore(&channel->lock, flags);
271 272
272 if (unlikely(urb->status) && 273 if (unlikely(status) &&
273 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) || 274 (!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) ||
274 urb->status != -EILSEQ )) 275 status != -EILSEQ ))
275 { 276 {
276 if (urb->status == -ESHUTDOWN) 277 if (status == -ESHUTDOWN)
277 return; 278 return;
278 279
279 if (printk_ratelimit()) 280 if (printk_ratelimit())
280 atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n", 281 atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
281 __func__, urb, urb->status); 282 __func__, urb, status);
282 /* throttle processing in case of an error */ 283 /* throttle processing in case of an error */
283 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS)); 284 mod_timer(&channel->delay, jiffies + msecs_to_jiffies(THROTTLE_MSECS));
284 } else 285 } else
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index cd51520c7e72..fe940e0536e0 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -257,9 +257,10 @@ static void acm_ctrl_irq(struct urb *urb)
257 struct usb_cdc_notification *dr = urb->transfer_buffer; 257 struct usb_cdc_notification *dr = urb->transfer_buffer;
258 unsigned char *data; 258 unsigned char *data;
259 int newctrl; 259 int newctrl;
260 int status; 260 int retval;
261 int status = urb->status;
261 262
262 switch (urb->status) { 263 switch (status) {
263 case 0: 264 case 0:
264 /* success */ 265 /* success */
265 break; 266 break;
@@ -267,10 +268,10 @@ static void acm_ctrl_irq(struct urb *urb)
267 case -ENOENT: 268 case -ENOENT:
268 case -ESHUTDOWN: 269 case -ESHUTDOWN:
269 /* this urb is terminated, clean up */ 270 /* this urb is terminated, clean up */
270 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 271 dbg("%s - urb shutting down with status: %d", __FUNCTION__, status);
271 return; 272 return;
272 default: 273 default:
273 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 274 dbg("%s - nonzero urb status received: %d", __FUNCTION__, status);
274 goto exit; 275 goto exit;
275 } 276 }
276 277
@@ -311,10 +312,10 @@ static void acm_ctrl_irq(struct urb *urb)
311 break; 312 break;
312 } 313 }
313exit: 314exit:
314 status = usb_submit_urb (urb, GFP_ATOMIC); 315 retval = usb_submit_urb (urb, GFP_ATOMIC);
315 if (status) 316 if (retval)
316 err ("%s - usb_submit_urb failed with result %d", 317 err ("%s - usb_submit_urb failed with result %d",
317 __FUNCTION__, status); 318 __FUNCTION__, retval);
318} 319}
319 320
320/* data interface returns incoming bytes, or we got unthrottled */ 321/* data interface returns incoming bytes, or we got unthrottled */
@@ -324,7 +325,8 @@ static void acm_read_bulk(struct urb *urb)
324 struct acm_ru *rcv = urb->context; 325 struct acm_ru *rcv = urb->context;
325 struct acm *acm = rcv->instance; 326 struct acm *acm = rcv->instance;
326 int status = urb->status; 327 int status = urb->status;
327 dbg("Entering acm_read_bulk with status %d", urb->status); 328
329 dbg("Entering acm_read_bulk with status %d", status);
328 330
329 if (!ACM_READY(acm)) 331 if (!ACM_READY(acm))
330 return; 332 return;
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 9a1478972bf5..5192cd9356de 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -289,16 +289,17 @@ static int proto_bias = -1;
289static void usblp_bulk_read(struct urb *urb) 289static void usblp_bulk_read(struct urb *urb)
290{ 290{
291 struct usblp *usblp = urb->context; 291 struct usblp *usblp = urb->context;
292 int status = urb->status;
292 293
293 if (usblp->present && usblp->used) { 294 if (usblp->present && usblp->used) {
294 if (urb->status) 295 if (status)
295 printk(KERN_WARNING "usblp%d: " 296 printk(KERN_WARNING "usblp%d: "
296 "nonzero read bulk status received: %d\n", 297 "nonzero read bulk status received: %d\n",
297 usblp->minor, urb->status); 298 usblp->minor, status);
298 } 299 }
299 spin_lock(&usblp->lock); 300 spin_lock(&usblp->lock);
300 if (urb->status < 0) 301 if (status < 0)
301 usblp->rstatus = urb->status; 302 usblp->rstatus = status;
302 else 303 else
303 usblp->rstatus = urb->actual_length; 304 usblp->rstatus = urb->actual_length;
304 usblp->rcomplete = 1; 305 usblp->rcomplete = 1;
@@ -311,16 +312,17 @@ static void usblp_bulk_read(struct urb *urb)
311static void usblp_bulk_write(struct urb *urb) 312static void usblp_bulk_write(struct urb *urb)
312{ 313{
313 struct usblp *usblp = urb->context; 314 struct usblp *usblp = urb->context;
315 int status = urb->status;
314 316
315 if (usblp->present && usblp->used) { 317 if (usblp->present && usblp->used) {
316 if (urb->status) 318 if (status)
317 printk(KERN_WARNING "usblp%d: " 319 printk(KERN_WARNING "usblp%d: "
318 "nonzero write bulk status received: %d\n", 320 "nonzero write bulk status received: %d\n",
319 usblp->minor, urb->status); 321 usblp->minor, status);
320 } 322 }
321 spin_lock(&usblp->lock); 323 spin_lock(&usblp->lock);
322 if (urb->status < 0) 324 if (status < 0)
323 usblp->wstatus = urb->status; 325 usblp->wstatus = status;
324 else 326 else
325 usblp->wstatus = urb->actual_length; 327 usblp->wstatus = urb->actual_length;
326 usblp->wcomplete = 1; 328 usblp->wcomplete = 1;
@@ -741,10 +743,11 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
741 */ 743 */
742 rv = usblp_wwait(usblp, !!(file->f_flags&O_NONBLOCK)); 744 rv = usblp_wwait(usblp, !!(file->f_flags&O_NONBLOCK));
743 if (rv < 0) { 745 if (rv < 0) {
744 /* 746 if (rv == -EAGAIN) {
745 * If interrupted, we simply leave the URB to dangle, 747 /* Presume that it's going to complete well. */
746 * so the ->release will call usb_kill_urb(). 748 writecount += transfer_length;
747 */ 749 }
750 /* Leave URB dangling, to be cleaned on close. */
748 goto collect_error; 751 goto collect_error;
749 } 752 }
750 753
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 963520fbef90..42ef1d5f6c8a 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -99,12 +99,17 @@ EXPORT_SYMBOL_GPL (usb_bus_list_lock);
99/* used for controlling access to virtual root hubs */ 99/* used for controlling access to virtual root hubs */
100static DEFINE_SPINLOCK(hcd_root_hub_lock); 100static DEFINE_SPINLOCK(hcd_root_hub_lock);
101 101
102/* used when updating hcd data */ 102/* used when updating an endpoint's URB list */
103static DEFINE_SPINLOCK(hcd_data_lock); 103static DEFINE_SPINLOCK(hcd_urb_list_lock);
104 104
105/* wait queue for synchronous unlinks */ 105/* wait queue for synchronous unlinks */
106DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); 106DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue);
107 107
108static inline int is_root_hub(struct usb_device *udev)
109{
110 return (udev->parent == NULL);
111}
112
108/*-------------------------------------------------------------------------*/ 113/*-------------------------------------------------------------------------*/
109 114
110/* 115/*
@@ -906,14 +911,13 @@ EXPORT_SYMBOL (usb_calc_bus_time);
906static void urb_unlink(struct usb_hcd *hcd, struct urb *urb) 911static void urb_unlink(struct usb_hcd *hcd, struct urb *urb)
907{ 912{
908 unsigned long flags; 913 unsigned long flags;
909 int at_root_hub = (urb->dev == hcd->self.root_hub);
910 914
911 /* clear all state linking urb to this dev (and hcd) */ 915 /* clear all state linking urb to this dev (and hcd) */
912 spin_lock_irqsave (&hcd_data_lock, flags); 916 spin_lock_irqsave(&hcd_urb_list_lock, flags);
913 list_del_init (&urb->urb_list); 917 list_del_init (&urb->urb_list);
914 spin_unlock_irqrestore (&hcd_data_lock, flags); 918 spin_unlock_irqrestore(&hcd_urb_list_lock, flags);
915 919
916 if (hcd->self.uses_dma && !at_root_hub) { 920 if (hcd->self.uses_dma && !is_root_hub(urb->dev)) {
917 if (usb_pipecontrol (urb->pipe) 921 if (usb_pipecontrol (urb->pipe)
918 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP)) 922 && !(urb->transfer_flags & URB_NO_SETUP_DMA_MAP))
919 dma_unmap_single (hcd->self.controller, urb->setup_dma, 923 dma_unmap_single (hcd->self.controller, urb->setup_dma,
@@ -955,7 +959,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
955 959
956 // FIXME: verify that quiescing hc works right (RH cleans up) 960 // FIXME: verify that quiescing hc works right (RH cleans up)
957 961
958 spin_lock_irqsave (&hcd_data_lock, flags); 962 spin_lock_irqsave(&hcd_urb_list_lock, flags);
959 ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out) 963 ep = (usb_pipein(urb->pipe) ? urb->dev->ep_in : urb->dev->ep_out)
960 [usb_pipeendpoint(urb->pipe)]; 964 [usb_pipeendpoint(urb->pipe)];
961 if (unlikely (!ep)) 965 if (unlikely (!ep))
@@ -972,7 +976,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
972 status = -ESHUTDOWN; 976 status = -ESHUTDOWN;
973 break; 977 break;
974 } 978 }
975 spin_unlock_irqrestore (&hcd_data_lock, flags); 979 spin_unlock_irqrestore(&hcd_urb_list_lock, flags);
976 if (status) { 980 if (status) {
977 INIT_LIST_HEAD (&urb->urb_list); 981 INIT_LIST_HEAD (&urb->urb_list);
978 usbmon_urb_submit_error(&hcd->self, urb, status); 982 usbmon_urb_submit_error(&hcd->self, urb, status);
@@ -986,7 +990,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
986 urb = usb_get_urb (urb); 990 urb = usb_get_urb (urb);
987 atomic_inc (&urb->use_count); 991 atomic_inc (&urb->use_count);
988 992
989 if (urb->dev == hcd->self.root_hub) { 993 if (is_root_hub(urb->dev)) {
990 /* NOTE: requirement on hub callers (usbfs and the hub 994 /* NOTE: requirement on hub callers (usbfs and the hub
991 * driver, for now) that URBs' urb->transfer_buffer be 995 * driver, for now) that URBs' urb->transfer_buffer be
992 * valid and usb_buffer_{sync,unmap}() not be needed, since 996 * valid and usb_buffer_{sync,unmap}() not be needed, since
@@ -1033,18 +1037,6 @@ done:
1033 1037
1034/*-------------------------------------------------------------------------*/ 1038/*-------------------------------------------------------------------------*/
1035 1039
1036/* called in any context */
1037int usb_hcd_get_frame_number (struct usb_device *udev)
1038{
1039 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1040
1041 if (!HC_IS_RUNNING (hcd->state))
1042 return -ESHUTDOWN;
1043 return hcd->driver->get_frame_number (hcd);
1044}
1045
1046/*-------------------------------------------------------------------------*/
1047
1048/* this makes the hcd giveback() the urb more quickly, by kicking it 1040/* this makes the hcd giveback() the urb more quickly, by kicking it
1049 * off hardware queues (which may take a while) and returning it as 1041 * off hardware queues (which may take a while) and returning it as
1050 * soon as practical. we've already set up the urb's return status, 1042 * soon as practical. we've already set up the urb's return status,
@@ -1055,7 +1047,7 @@ unlink1 (struct usb_hcd *hcd, struct urb *urb)
1055{ 1047{
1056 int value; 1048 int value;
1057 1049
1058 if (urb->dev == hcd->self.root_hub) 1050 if (is_root_hub(urb->dev))
1059 value = usb_rh_urb_dequeue (hcd, urb); 1051 value = usb_rh_urb_dequeue (hcd, urb);
1060 else { 1052 else {
1061 1053
@@ -1103,11 +1095,11 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1103 * that it was submitted. But as a rule it can't know whether or 1095 * that it was submitted. But as a rule it can't know whether or
1104 * not it's already been unlinked ... so we respect the reversed 1096 * not it's already been unlinked ... so we respect the reversed
1105 * lock sequence needed for the usb_hcd_giveback_urb() code paths 1097 * lock sequence needed for the usb_hcd_giveback_urb() code paths
1106 * (urb lock, then hcd_data_lock) in case some other CPU is now 1098 * (urb lock, then hcd_urb_list_lock) in case some other CPU is now
1107 * unlinking it. 1099 * unlinking it.
1108 */ 1100 */
1109 spin_lock_irqsave (&urb->lock, flags); 1101 spin_lock_irqsave (&urb->lock, flags);
1110 spin_lock (&hcd_data_lock); 1102 spin_lock(&hcd_urb_list_lock);
1111 1103
1112 sys = &urb->dev->dev; 1104 sys = &urb->dev->dev;
1113 hcd = bus_to_hcd(urb->dev->bus); 1105 hcd = bus_to_hcd(urb->dev->bus);
@@ -1139,17 +1131,16 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1139 * finish unlinking the initial failed usb_set_address() 1131 * finish unlinking the initial failed usb_set_address()
1140 * or device descriptor fetch. 1132 * or device descriptor fetch.
1141 */ 1133 */
1142 if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) 1134 if (!test_bit(HCD_FLAG_SAW_IRQ, &hcd->flags) &&
1143 && hcd->self.root_hub != urb->dev) { 1135 !is_root_hub(urb->dev)) {
1144 dev_warn (hcd->self.controller, "Unlink after no-IRQ? " 1136 dev_warn (hcd->self.controller, "Unlink after no-IRQ? "
1145 "Controller is probably using the wrong IRQ." 1137 "Controller is probably using the wrong IRQ.\n");
1146 "\n");
1147 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1138 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
1148 } 1139 }
1149 1140
1150 urb->status = status; 1141 urb->status = status;
1151 1142
1152 spin_unlock (&hcd_data_lock); 1143 spin_unlock(&hcd_urb_list_lock);
1153 spin_unlock_irqrestore (&urb->lock, flags); 1144 spin_unlock_irqrestore (&urb->lock, flags);
1154 1145
1155 retval = unlink1 (hcd, urb); 1146 retval = unlink1 (hcd, urb);
@@ -1158,7 +1149,7 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1158 return retval; 1149 return retval;
1159 1150
1160done: 1151done:
1161 spin_unlock (&hcd_data_lock); 1152 spin_unlock(&hcd_urb_list_lock);
1162 spin_unlock_irqrestore (&urb->lock, flags); 1153 spin_unlock_irqrestore (&urb->lock, flags);
1163 if (retval != -EIDRM && sys && sys->driver) 1154 if (retval != -EIDRM && sys && sys->driver)
1164 dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval); 1155 dev_dbg (sys, "hcd_unlink_urb %p fail %d\n", urb, retval);
@@ -1167,6 +1158,35 @@ done:
1167 1158
1168/*-------------------------------------------------------------------------*/ 1159/*-------------------------------------------------------------------------*/
1169 1160
1161/**
1162 * usb_hcd_giveback_urb - return URB from HCD to device driver
1163 * @hcd: host controller returning the URB
1164 * @urb: urb being returned to the USB device driver.
1165 * Context: in_interrupt()
1166 *
1167 * This hands the URB from HCD to its USB device driver, using its
1168 * completion function. The HCD has freed all per-urb resources
1169 * (and is done using urb->hcpriv). It also released all HCD locks;
1170 * the device driver won't cause problems if it frees, modifies,
1171 * or resubmits this URB.
1172 */
1173void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb)
1174{
1175 urb_unlink(hcd, urb);
1176 usbmon_urb_complete (&hcd->self, urb);
1177 usb_unanchor_urb(urb);
1178
1179 /* pass ownership to the completion handler */
1180 urb->complete (urb);
1181 atomic_dec (&urb->use_count);
1182 if (unlikely (urb->reject))
1183 wake_up (&usb_kill_urb_queue);
1184 usb_put_urb (urb);
1185}
1186EXPORT_SYMBOL (usb_hcd_giveback_urb);
1187
1188/*-------------------------------------------------------------------------*/
1189
1170/* disables the endpoint: cancels any pending urbs, then synchronizes with 1190/* disables the endpoint: cancels any pending urbs, then synchronizes with
1171 * the hcd to make sure all endpoint state is gone from hardware, and then 1191 * the hcd to make sure all endpoint state is gone from hardware, and then
1172 * waits until the endpoint's queue is completely drained. use for 1192 * waits until the endpoint's queue is completely drained. use for
@@ -1186,7 +1206,7 @@ void usb_hcd_endpoint_disable (struct usb_device *udev,
1186 1206
1187 /* ep is already gone from udev->ep_{in,out}[]; no more submits */ 1207 /* ep is already gone from udev->ep_{in,out}[]; no more submits */
1188rescan: 1208rescan:
1189 spin_lock (&hcd_data_lock); 1209 spin_lock(&hcd_urb_list_lock);
1190 list_for_each_entry (urb, &ep->urb_list, urb_list) { 1210 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1191 int tmp; 1211 int tmp;
1192 1212
@@ -1194,7 +1214,7 @@ rescan:
1194 if (urb->status != -EINPROGRESS) 1214 if (urb->status != -EINPROGRESS)
1195 continue; 1215 continue;
1196 usb_get_urb (urb); 1216 usb_get_urb (urb);
1197 spin_unlock (&hcd_data_lock); 1217 spin_unlock(&hcd_urb_list_lock);
1198 1218
1199 spin_lock (&urb->lock); 1219 spin_lock (&urb->lock);
1200 tmp = urb->status; 1220 tmp = urb->status;
@@ -1223,7 +1243,7 @@ rescan:
1223 /* list contents may have changed */ 1243 /* list contents may have changed */
1224 goto rescan; 1244 goto rescan;
1225 } 1245 }
1226 spin_unlock (&hcd_data_lock); 1246 spin_unlock(&hcd_urb_list_lock);
1227 local_irq_enable (); 1247 local_irq_enable ();
1228 1248
1229 /* synchronize with the hardware, so old configuration state 1249 /* synchronize with the hardware, so old configuration state
@@ -1240,7 +1260,7 @@ rescan:
1240 * endpoint_disable methods. 1260 * endpoint_disable methods.
1241 */ 1261 */
1242 while (!list_empty (&ep->urb_list)) { 1262 while (!list_empty (&ep->urb_list)) {
1243 spin_lock_irq (&hcd_data_lock); 1263 spin_lock_irq(&hcd_urb_list_lock);
1244 1264
1245 /* The list may have changed while we acquired the spinlock */ 1265 /* The list may have changed while we acquired the spinlock */
1246 urb = NULL; 1266 urb = NULL;
@@ -1249,7 +1269,7 @@ rescan:
1249 urb_list); 1269 urb_list);
1250 usb_get_urb (urb); 1270 usb_get_urb (urb);
1251 } 1271 }
1252 spin_unlock_irq (&hcd_data_lock); 1272 spin_unlock_irq(&hcd_urb_list_lock);
1253 1273
1254 if (urb) { 1274 if (urb) {
1255 usb_kill_urb (urb); 1275 usb_kill_urb (urb);
@@ -1260,6 +1280,18 @@ rescan:
1260 1280
1261/*-------------------------------------------------------------------------*/ 1281/*-------------------------------------------------------------------------*/
1262 1282
1283/* called in any context */
1284int usb_hcd_get_frame_number (struct usb_device *udev)
1285{
1286 struct usb_hcd *hcd = bus_to_hcd(udev->bus);
1287
1288 if (!HC_IS_RUNNING (hcd->state))
1289 return -ESHUTDOWN;
1290 return hcd->driver->get_frame_number (hcd);
1291}
1292
1293/*-------------------------------------------------------------------------*/
1294
1263#ifdef CONFIG_PM 1295#ifdef CONFIG_PM
1264 1296
1265int hcd_bus_suspend(struct usb_device *rhdev) 1297int hcd_bus_suspend(struct usb_device *rhdev)
@@ -1395,35 +1427,6 @@ EXPORT_SYMBOL (usb_bus_start_enum);
1395/*-------------------------------------------------------------------------*/ 1427/*-------------------------------------------------------------------------*/
1396 1428
1397/** 1429/**
1398 * usb_hcd_giveback_urb - return URB from HCD to device driver
1399 * @hcd: host controller returning the URB
1400 * @urb: urb being returned to the USB device driver.
1401 * Context: in_interrupt()
1402 *
1403 * This hands the URB from HCD to its USB device driver, using its
1404 * completion function. The HCD has freed all per-urb resources
1405 * (and is done using urb->hcpriv). It also released all HCD locks;
1406 * the device driver won't cause problems if it frees, modifies,
1407 * or resubmits this URB.
1408 */
1409void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb)
1410{
1411 urb_unlink(hcd, urb);
1412 usbmon_urb_complete (&hcd->self, urb);
1413 usb_unanchor_urb(urb);
1414
1415 /* pass ownership to the completion handler */
1416 urb->complete (urb);
1417 atomic_dec (&urb->use_count);
1418 if (unlikely (urb->reject))
1419 wake_up (&usb_kill_urb_queue);
1420 usb_put_urb (urb);
1421}
1422EXPORT_SYMBOL (usb_hcd_giveback_urb);
1423
1424/*-------------------------------------------------------------------------*/
1425
1426/**
1427 * usb_hcd_irq - hook IRQs to HCD framework (bus glue) 1430 * usb_hcd_irq - hook IRQs to HCD framework (bus glue)
1428 * @irq: the IRQ being raised 1431 * @irq: the IRQ being raised
1429 * @__hcd: pointer to the HCD whose IRQ is being signaled 1432 * @__hcd: pointer to the HCD whose IRQ is being signaled
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index fd74c50b1804..e341a1da517f 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1335,6 +1335,10 @@ int usb_new_device(struct usb_device *udev)
1335 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR, 1335 udev->dev.devt = MKDEV(USB_DEVICE_MAJOR,
1336 (((udev->bus->busnum-1) * 128) + (udev->devnum-1))); 1336 (((udev->bus->busnum-1) * 128) + (udev->devnum-1)));
1337 1337
1338 /* Increment the parent's count of unsuspended children */
1339 if (udev->parent)
1340 usb_autoresume_device(udev->parent);
1341
1338 /* Register the device. The device driver is responsible 1342 /* Register the device. The device driver is responsible
1339 * for adding the device files to sysfs and for configuring 1343 * for adding the device files to sysfs and for configuring
1340 * the device. 1344 * the device.
@@ -1342,13 +1346,11 @@ int usb_new_device(struct usb_device *udev)
1342 err = device_add(&udev->dev); 1346 err = device_add(&udev->dev);
1343 if (err) { 1347 if (err) {
1344 dev_err(&udev->dev, "can't device_add, error %d\n", err); 1348 dev_err(&udev->dev, "can't device_add, error %d\n", err);
1349 if (udev->parent)
1350 usb_autosuspend_device(udev->parent);
1345 goto fail; 1351 goto fail;
1346 } 1352 }
1347 1353
1348 /* Increment the parent's count of unsuspended children */
1349 if (udev->parent)
1350 usb_autoresume_device(udev->parent);
1351
1352exit: 1354exit:
1353 return err; 1355 return err;
1354 1356
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 530e854961ce..25f63f1096b4 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -34,13 +34,14 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
34{ 34{
35 struct completion done; 35 struct completion done;
36 unsigned long expire; 36 unsigned long expire;
37 int status; 37 int retval;
38 int status = urb->status;
38 39
39 init_completion(&done); 40 init_completion(&done);
40 urb->context = &done; 41 urb->context = &done;
41 urb->actual_length = 0; 42 urb->actual_length = 0;
42 status = usb_submit_urb(urb, GFP_NOIO); 43 retval = usb_submit_urb(urb, GFP_NOIO);
43 if (unlikely(status)) 44 if (unlikely(retval))
44 goto out; 45 goto out;
45 46
46 expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT; 47 expire = timeout ? msecs_to_jiffies(timeout) : MAX_SCHEDULE_TIMEOUT;
@@ -55,15 +56,15 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
55 urb->transfer_buffer_length); 56 urb->transfer_buffer_length);
56 57
57 usb_kill_urb(urb); 58 usb_kill_urb(urb);
58 status = urb->status == -ENOENT ? -ETIMEDOUT : urb->status; 59 retval = status == -ENOENT ? -ETIMEDOUT : status;
59 } else 60 } else
60 status = urb->status; 61 retval = status;
61out: 62out:
62 if (actual_length) 63 if (actual_length)
63 *actual_length = urb->actual_length; 64 *actual_length = urb->actual_length;
64 65
65 usb_free_urb(urb); 66 usb_free_urb(urb);
66 return status; 67 return retval;
67} 68}
68 69
69/*-------------------------------------------------------------------*/ 70/*-------------------------------------------------------------------*/
@@ -250,6 +251,7 @@ static void sg_clean (struct usb_sg_request *io)
250static void sg_complete (struct urb *urb) 251static void sg_complete (struct urb *urb)
251{ 252{
252 struct usb_sg_request *io = urb->context; 253 struct usb_sg_request *io = urb->context;
254 int status = urb->status;
253 255
254 spin_lock (&io->lock); 256 spin_lock (&io->lock);
255 257
@@ -265,21 +267,21 @@ static void sg_complete (struct urb *urb)
265 */ 267 */
266 if (io->status 268 if (io->status
267 && (io->status != -ECONNRESET 269 && (io->status != -ECONNRESET
268 || urb->status != -ECONNRESET) 270 || status != -ECONNRESET)
269 && urb->actual_length) { 271 && urb->actual_length) {
270 dev_err (io->dev->bus->controller, 272 dev_err (io->dev->bus->controller,
271 "dev %s ep%d%s scatterlist error %d/%d\n", 273 "dev %s ep%d%s scatterlist error %d/%d\n",
272 io->dev->devpath, 274 io->dev->devpath,
273 usb_pipeendpoint (urb->pipe), 275 usb_pipeendpoint (urb->pipe),
274 usb_pipein (urb->pipe) ? "in" : "out", 276 usb_pipein (urb->pipe) ? "in" : "out",
275 urb->status, io->status); 277 status, io->status);
276 // BUG (); 278 // BUG ();
277 } 279 }
278 280
279 if (io->status == 0 && urb->status && urb->status != -ECONNRESET) { 281 if (io->status == 0 && status && status != -ECONNRESET) {
280 int i, found, status; 282 int i, found, retval;
281 283
282 io->status = urb->status; 284 io->status = status;
283 285
284 /* the previous urbs, and this one, completed already. 286 /* the previous urbs, and this one, completed already.
285 * unlink pending urbs so they won't rx/tx bad data. 287 * unlink pending urbs so they won't rx/tx bad data.
@@ -290,13 +292,13 @@ static void sg_complete (struct urb *urb)
290 if (!io->urbs [i] || !io->urbs [i]->dev) 292 if (!io->urbs [i] || !io->urbs [i]->dev)
291 continue; 293 continue;
292 if (found) { 294 if (found) {
293 status = usb_unlink_urb (io->urbs [i]); 295 retval = usb_unlink_urb (io->urbs [i]);
294 if (status != -EINPROGRESS 296 if (retval != -EINPROGRESS &&
295 && status != -ENODEV 297 retval != -ENODEV &&
296 && status != -EBUSY) 298 retval != -EBUSY)
297 dev_err (&io->dev->dev, 299 dev_err (&io->dev->dev,
298 "%s, unlink --> %d\n", 300 "%s, unlink --> %d\n",
299 __FUNCTION__, status); 301 __FUNCTION__, retval);
300 } else if (urb == io->urbs [i]) 302 } else if (urb == io->urbs [i])
301 found = 1; 303 found = 1;
302 } 304 }
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index d47ae89154a7..2ab222be8fd1 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -441,6 +441,54 @@ static struct attribute_group dev_attr_grp = {
441 .attrs = dev_attrs, 441 .attrs = dev_attrs,
442}; 442};
443 443
444/* Binary descriptors */
445
446static ssize_t
447read_descriptors(struct kobject *kobj, struct bin_attribute *attr,
448 char *buf, loff_t off, size_t count)
449{
450 struct usb_device *udev = to_usb_device(
451 container_of(kobj, struct device, kobj));
452 size_t nleft = count;
453 size_t srclen, n;
454
455 usb_lock_device(udev);
456
457 /* The binary attribute begins with the device descriptor */
458 srclen = sizeof(struct usb_device_descriptor);
459 if (off < srclen) {
460 n = min_t(size_t, nleft, srclen - off);
461 memcpy(buf, off + (char *) &udev->descriptor, n);
462 nleft -= n;
463 buf += n;
464 off = 0;
465 } else {
466 off -= srclen;
467 }
468
469 /* Then follows the raw descriptor entry for the current
470 * configuration (config plus subsidiary descriptors).
471 */
472 if (udev->actconfig) {
473 int cfgno = udev->actconfig - udev->config;
474
475 srclen = __le16_to_cpu(udev->actconfig->desc.wTotalLength);
476 if (off < srclen) {
477 n = min_t(size_t, nleft, srclen - off);
478 memcpy(buf, off + udev->rawdescriptors[cfgno], n);
479 nleft -= n;
480 }
481 }
482 usb_unlock_device(udev);
483 return count - nleft;
484}
485
486static struct bin_attribute dev_bin_attr_descriptors = {
487 .attr = {.name = "descriptors", .mode = 0444},
488 .read = read_descriptors,
489 .size = 18 + 65535, /* dev descr + max-size raw descriptor */
490};
491
444int usb_create_sysfs_dev_files(struct usb_device *udev) 492int usb_create_sysfs_dev_files(struct usb_device *udev)
445{ 493{
446 struct device *dev = &udev->dev; 494 struct device *dev = &udev->dev;
@@ -450,6 +498,10 @@ int usb_create_sysfs_dev_files(struct usb_device *udev)
450 if (retval) 498 if (retval)
451 return retval; 499 return retval;
452 500
501 retval = device_create_bin_file(dev, &dev_bin_attr_descriptors);
502 if (retval)
503 goto error;
504
453 retval = add_persist_attributes(dev); 505 retval = add_persist_attributes(dev);
454 if (retval) 506 if (retval)
455 goto error; 507 goto error;
@@ -492,6 +544,7 @@ void usb_remove_sysfs_dev_files(struct usb_device *udev)
492 device_remove_file(dev, &dev_attr_serial); 544 device_remove_file(dev, &dev_attr_serial);
493 remove_power_attributes(dev); 545 remove_power_attributes(dev);
494 remove_persist_attributes(dev); 546 remove_persist_attributes(dev);
547 device_remove_bin_file(dev, &dev_bin_attr_descriptors);
495 sysfs_remove_group(&dev->kobj, &dev_attr_grp); 548 sysfs_remove_group(&dev->kobj, &dev_attr_grp);
496} 549}
497 550
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 52ec44b828f3..be630228461c 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -440,55 +440,57 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
440 * @urb: pointer to urb describing a previously submitted request, 440 * @urb: pointer to urb describing a previously submitted request,
441 * may be NULL 441 * may be NULL
442 * 442 *
443 * This routine cancels an in-progress request. URBs complete only 443 * This routine cancels an in-progress request. URBs complete only once
444 * once per submission, and may be canceled only once per submission. 444 * per submission, and may be canceled only once per submission.
445 * Successful cancellation means the requests's completion handler will 445 * Successful cancellation means termination of @urb will be expedited
446 * be called with a status code indicating that the request has been 446 * and the completion handler will be called with a status code
447 * canceled (rather than any other code) and will quickly be removed 447 * indicating that the request has been canceled (rather than any other
448 * from host controller data structures. 448 * code).
449 * 449 *
450 * This request is always asynchronous. 450 * This request is always asynchronous. Success is indicated by
451 * Success is indicated by returning -EINPROGRESS, 451 * returning -EINPROGRESS, at which time the URB will probably not yet
452 * at which time the URB will normally have been unlinked but not yet 452 * have been given back to the device driver. When it is eventually
453 * given back to the device driver. When it is called, the completion 453 * called, the completion function will see @urb->status == -ECONNRESET.
454 * function will see urb->status == -ECONNRESET. Failure is indicated 454 * Failure is indicated by usb_unlink_urb() returning any other value.
455 * by any other return value. Unlinking will fail when the URB is not 455 * Unlinking will fail when @urb is not currently "linked" (i.e., it was
456 * currently "linked" (i.e., it was never submitted, or it was unlinked 456 * never submitted, or it was unlinked before, or the hardware is already
457 * before, or the hardware is already finished with it), even if the 457 * finished with it), even if the completion handler has not yet run.
458 * completion handler has not yet run.
459 * 458 *
460 * Unlinking and Endpoint Queues: 459 * Unlinking and Endpoint Queues:
461 * 460 *
461 * [The behaviors and guarantees described below do not apply to virtual
462 * root hubs but only to endpoint queues for physical USB devices.]
463 *
462 * Host Controller Drivers (HCDs) place all the URBs for a particular 464 * Host Controller Drivers (HCDs) place all the URBs for a particular
463 * endpoint in a queue. Normally the queue advances as the controller 465 * endpoint in a queue. Normally the queue advances as the controller
464 * hardware processes each request. But when an URB terminates with an 466 * hardware processes each request. But when an URB terminates with an
465 * error its queue stops, at least until that URB's completion routine 467 * error its queue generally stops (see below), at least until that URB's
466 * returns. It is guaranteed that the queue will not restart until all 468 * completion routine returns. It is guaranteed that a stopped queue
467 * its unlinked URBs have been fully retired, with their completion 469 * will not restart until all its unlinked URBs have been fully retired,
468 * routines run, even if that's not until some time after the original 470 * with their completion routines run, even if that's not until some time
469 * completion handler returns. Normally the same behavior and guarantees 471 * after the original completion handler returns. The same behavior and
470 * apply when an URB terminates because it was unlinked; however if an 472 * guarantee apply when an URB terminates because it was unlinked.
471 * URB is unlinked before the hardware has started to execute it, then 473 *
472 * its queue is not guaranteed to stop until all the preceding URBs have 474 * Bulk and interrupt endpoint queues are guaranteed to stop whenever an
473 * completed. 475 * URB terminates with any sort of error, including -ECONNRESET, -ENOENT,
474 * 476 * and -EREMOTEIO. Control endpoint queues behave the same way except
475 * This means that USB device drivers can safely build deep queues for 477 * that they are not guaranteed to stop for -EREMOTEIO errors. Queues
476 * large or complex transfers, and clean them up reliably after any sort 478 * for isochronous endpoints are treated differently, because they must
477 * of aborted transfer by unlinking all pending URBs at the first fault. 479 * advance at fixed rates. Such queues do not stop when an URB
478 * 480 * encounters an error or is unlinked. An unlinked isochronous URB may
479 * Note that an URB terminating early because a short packet was received 481 * leave a gap in the stream of packets; it is undefined whether such
480 * will count as an error if and only if the URB_SHORT_NOT_OK flag is set. 482 * gaps can be filled in.
481 * Also, that all unlinks performed in any URB completion handler must 483 *
482 * be asynchronous. 484 * Note that early termination of an URB because a short packet was
483 * 485 * received will generate a -EREMOTEIO error if and only if the
484 * Queues for isochronous endpoints are treated differently, because they 486 * URB_SHORT_NOT_OK flag is set. By setting this flag, USB device
485 * advance at fixed rates. Such queues do not stop when an URB is unlinked. 487 * drivers can build deep queues for large or complex bulk transfers
486 * An unlinked URB may leave a gap in the stream of packets. It is undefined 488 * and clean them up reliably after any sort of aborted transfer by
487 * whether such gaps can be filled in. 489 * unlinking all pending URBs at the first fault.
488 * 490 *
489 * When a control URB terminates with an error, it is likely that the 491 * When a control URB terminates with an error other than -EREMOTEIO, it
490 * status stage of the transfer will not take place, even if it is merely 492 * is quite likely that the status stage of the transfer will not take
491 * a soft error resulting from a short-packet with URB_SHORT_NOT_OK set. 493 * place.
492 */ 494 */
493int usb_unlink_urb(struct urb *urb) 495int usb_unlink_urb(struct urb *urb)
494{ 496{
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 45e01e289455..767aed5b4bea 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -82,6 +82,27 @@ choice
82 Many controller drivers are platform-specific; these 82 Many controller drivers are platform-specific; these
83 often need board-specific hooks. 83 often need board-specific hooks.
84 84
85config USB_GADGET_AMD5536UDC
86 boolean "AMD5536 UDC"
87 depends on PCI
88 select USB_GADGET_DUALSPEED
89 help
90 The AMD5536 UDC is part of the AMD Geode CS5536, an x86 southbridge.
91 It is a USB Highspeed DMA capable USB device controller. Beside ep0
92 it provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
93 The UDC port supports OTG operation, and may be used as a host port
94 if it's not being used to implement peripheral or OTG roles.
95
96 Say "y" to link the driver statically, or "m" to build a
97 dynamically linked module called "amd5536udc" and force all
98 gadget drivers to also be dynamically linked.
99
100config USB_AMD5536UDC
101 tristate
102 depends on USB_GADGET_AMD5536UDC
103 default USB_GADGET
104 select USB_GADGET_SELECTED
105
85config USB_GADGET_FSL_USB2 106config USB_GADGET_FSL_USB2
86 boolean "Freescale Highspeed USB DR Peripheral Controller" 107 boolean "Freescale Highspeed USB DR Peripheral Controller"
87 depends on MPC834x || PPC_MPC831x 108 depends on MPC834x || PPC_MPC831x
@@ -156,6 +177,24 @@ config USB_PXA2XX_SMALL
156 default y if USB_ETH 177 default y if USB_ETH
157 default y if USB_G_SERIAL 178 default y if USB_G_SERIAL
158 179
180config USB_GADGET_M66592
181 boolean "Renesas M66592 USB Peripheral Controller"
182 select USB_GADGET_DUALSPEED
183 help
184 M66592 is a discrete USB peripheral controller chip that
185 supports both full and high speed USB 2.0 data transfers.
186 It has seven configurable endpoints, and endpoint zero.
187
188 Say "y" to link the driver statically, or "m" to build a
189 dynamically linked module called "m66592_udc" and force all
190 gadget drivers to also be dynamically linked.
191
192config USB_M66592
193 tristate
194 depends on USB_GADGET_M66592
195 default USB_GADGET
196 select USB_GADGET_SELECTED
197
159config USB_GADGET_GOKU 198config USB_GADGET_GOKU
160 boolean "Toshiba TC86C001 'Goku-S'" 199 boolean "Toshiba TC86C001 'Goku-S'"
161 depends on PCI 200 depends on PCI
@@ -261,24 +300,6 @@ config USB_AT91
261 depends on USB_GADGET_AT91 300 depends on USB_GADGET_AT91
262 default USB_GADGET 301 default USB_GADGET
263 302
264config USB_GADGET_M66592
265 boolean "M66592 driver"
266 select USB_GADGET_DUALSPEED
267 help
268 M66592 is a USB 2.0 peripheral controller.
269
270 It has seven configurable endpoints, and endpoint zero.
271
272 Say "y" to link the driver statically, or "m" to build a
273 dynamically linked module called "m66592_udc" and force all
274 gadget drivers to also be dynamically linked.
275
276config USB_M66592
277 tristate
278 depends on USB_GADGET_M66592
279 default USB_GADGET
280 select USB_GADGET_SELECTED
281
282config USB_GADGET_DUMMY_HCD 303config USB_GADGET_DUMMY_HCD
283 boolean "Dummy HCD (DEVELOPMENT)" 304 boolean "Dummy HCD (DEVELOPMENT)"
284 depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL 305 depends on (USB=y || (USB=m && USB_GADGET=m)) && EXPERIMENTAL
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 8ae76f738635..1bc0f03550ce 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -7,6 +7,7 @@ endif
7 7
8obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o 8obj-$(CONFIG_USB_DUMMY_HCD) += dummy_hcd.o
9obj-$(CONFIG_USB_NET2280) += net2280.o 9obj-$(CONFIG_USB_NET2280) += net2280.o
10obj-$(CONFIG_USB_AMD5536UDC) += amd5536udc.o
10obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o 11obj-$(CONFIG_USB_PXA2XX) += pxa2xx_udc.o
11obj-$(CONFIG_USB_GOKU) += goku_udc.o 12obj-$(CONFIG_USB_GOKU) += goku_udc.o
12obj-$(CONFIG_USB_OMAP) += omap_udc.o 13obj-$(CONFIG_USB_OMAP) += omap_udc.o
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
new file mode 100644
index 000000000000..714156ca8fe4
--- /dev/null
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -0,0 +1,3454 @@
1/*
2 * amd5536.c -- AMD 5536 UDC high/full speed USB device controller
3 *
4 * Copyright (C) 2005-2007 AMD (http://www.amd.com)
5 * Author: Thomas Dahlmann
6 *
7 * 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 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/*
23 * The AMD5536 UDC is part of the x86 southbridge AMD Geode CS5536.
24 * It is a USB Highspeed DMA capable USB device controller. Beside ep0 it
25 * provides 4 IN and 4 OUT endpoints (bulk or interrupt type).
26 *
27 * Make sure that UDC is assigned to port 4 by BIOS settings (port can also
28 * be used as host port) and UOC bits PAD_EN and APU are set (should be done
29 * by BIOS init).
30 *
31 * UDC DMA requires 32-bit aligned buffers so DMA with gadget ether does not
32 * work without updating NET_IP_ALIGN. Or PIO mode (module param "use_dma=0")
33 * can be used with gadget ether.
34 */
35
36/* debug control */
37/* #define UDC_VERBOSE */
38
39/* Driver strings */
40#define UDC_MOD_DESCRIPTION "AMD 5536 UDC - USB Device Controller"
41#define UDC_DRIVER_VERSION_STRING "01.00.0206 - $Revision: #3 $"
42
43/* system */
44#include <linux/module.h>
45#include <linux/pci.h>
46#include <linux/kernel.h>
47#include <linux/version.h>
48#include <linux/delay.h>
49#include <linux/ioport.h>
50#include <linux/sched.h>
51#include <linux/slab.h>
52#include <linux/smp_lock.h>
53#include <linux/errno.h>
54#include <linux/init.h>
55#include <linux/timer.h>
56#include <linux/list.h>
57#include <linux/interrupt.h>
58#include <linux/ioctl.h>
59#include <linux/fs.h>
60#include <linux/dmapool.h>
61#include <linux/moduleparam.h>
62#include <linux/device.h>
63#include <linux/io.h>
64#include <linux/irq.h>
65
66#include <asm/byteorder.h>
67#include <asm/system.h>
68#include <asm/unaligned.h>
69
70/* gadget stack */
71#include <linux/usb/ch9.h>
72#include <linux/usb_gadget.h>
73
74/* udc specific */
75#include "amd5536udc.h"
76
77
78static void udc_tasklet_disconnect(unsigned long);
79static void empty_req_queue(struct udc_ep *);
80static int udc_probe(struct udc *dev);
81static void udc_basic_init(struct udc *dev);
82static void udc_setup_endpoints(struct udc *dev);
83static void udc_soft_reset(struct udc *dev);
84static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep);
85static void udc_free_request(struct usb_ep *usbep, struct usb_request *usbreq);
86static int udc_free_dma_chain(struct udc *dev, struct udc_request *req);
87static int udc_create_dma_chain(struct udc_ep *ep, struct udc_request *req,
88 unsigned long buf_len, gfp_t gfp_flags);
89static int udc_remote_wakeup(struct udc *dev);
90static int udc_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id);
91static void udc_pci_remove(struct pci_dev *pdev);
92
93/* description */
94static const char mod_desc[] = UDC_MOD_DESCRIPTION;
95static const char name[] = "amd5536udc";
96
97/* structure to hold endpoint function pointers */
98static const struct usb_ep_ops udc_ep_ops;
99
100/* received setup data */
101static union udc_setup_data setup_data;
102
103/* pointer to device object */
104static struct udc *udc;
105
106/* irq spin lock for soft reset */
107static DEFINE_SPINLOCK(udc_irq_spinlock);
108/* stall spin lock */
109static DEFINE_SPINLOCK(udc_stall_spinlock);
110
111/*
112* slave mode: pending bytes in rx fifo after nyet,
113* used if EPIN irq came but no req was available
114*/
115static unsigned int udc_rxfifo_pending;
116
117/* count soft resets after suspend to avoid loop */
118static int soft_reset_occured;
119static int soft_reset_after_usbreset_occured;
120
121/* timer */
122static struct timer_list udc_timer;
123static int stop_timer;
124
125/* set_rde -- Is used to control enabling of RX DMA. Problem is
126 * that UDC has only one bit (RDE) to enable/disable RX DMA for
127 * all OUT endpoints. So we have to handle race conditions like
128 * when OUT data reaches the fifo but no request was queued yet.
129 * This cannot be solved by letting the RX DMA disabled until a
130 * request gets queued because there may be other OUT packets
131 * in the FIFO (important for not blocking control traffic).
132 * The value of set_rde controls the correspondig timer.
133 *
134 * set_rde -1 == not used, means it is alloed to be set to 0 or 1
135 * set_rde 0 == do not touch RDE, do no start the RDE timer
136 * set_rde 1 == timer function will look whether FIFO has data
137 * set_rde 2 == set by timer function to enable RX DMA on next call
138 */
139static int set_rde = -1;
140
141static DECLARE_COMPLETION(on_exit);
142static struct timer_list udc_pollstall_timer;
143static int stop_pollstall_timer;
144static DECLARE_COMPLETION(on_pollstall_exit);
145
146/* tasklet for usb disconnect */
147static DECLARE_TASKLET(disconnect_tasklet, udc_tasklet_disconnect,
148 (unsigned long) &udc);
149
150
151/* endpoint names used for print */
152static const char ep0_string[] = "ep0in";
153static const char *ep_string[] = {
154 ep0_string,
155 "ep1in-int", "ep2in-bulk", "ep3in-bulk", "ep4in-bulk", "ep5in-bulk",
156 "ep6in-bulk", "ep7in-bulk", "ep8in-bulk", "ep9in-bulk", "ep10in-bulk",
157 "ep11in-bulk", "ep12in-bulk", "ep13in-bulk", "ep14in-bulk",
158 "ep15in-bulk", "ep0out", "ep1out-bulk", "ep2out-bulk", "ep3out-bulk",
159 "ep4out-bulk", "ep5out-bulk", "ep6out-bulk", "ep7out-bulk",
160 "ep8out-bulk", "ep9out-bulk", "ep10out-bulk", "ep11out-bulk",
161 "ep12out-bulk", "ep13out-bulk", "ep14out-bulk", "ep15out-bulk"
162};
163
164/* DMA usage flag */
165static int use_dma = 1;
166/* packet per buffer dma */
167static int use_dma_ppb = 1;
168/* with per descr. update */
169static int use_dma_ppb_du;
170/* buffer fill mode */
171static int use_dma_bufferfill_mode;
172/* full speed only mode */
173static int use_fullspeed;
174/* tx buffer size for high speed */
175static unsigned long hs_tx_buf = UDC_EPIN_BUFF_SIZE;
176
177/* module parameters */
178module_param(use_dma, bool, S_IRUGO);
179MODULE_PARM_DESC(use_dma, "true for DMA");
180module_param(use_dma_ppb, bool, S_IRUGO);
181MODULE_PARM_DESC(use_dma_ppb, "true for DMA in packet per buffer mode");
182module_param(use_dma_ppb_du, bool, S_IRUGO);
183MODULE_PARM_DESC(use_dma_ppb_du,
184 "true for DMA in packet per buffer mode with descriptor update");
185module_param(use_fullspeed, bool, S_IRUGO);
186MODULE_PARM_DESC(use_fullspeed, "true for fullspeed only");
187
188/*---------------------------------------------------------------------------*/
189/* Prints UDC device registers and endpoint irq registers */
190static void print_regs(struct udc *dev)
191{
192 DBG(dev, "------- Device registers -------\n");
193 DBG(dev, "dev config = %08x\n", readl(&dev->regs->cfg));
194 DBG(dev, "dev control = %08x\n", readl(&dev->regs->ctl));
195 DBG(dev, "dev status = %08x\n", readl(&dev->regs->sts));
196 DBG(dev, "\n");
197 DBG(dev, "dev int's = %08x\n", readl(&dev->regs->irqsts));
198 DBG(dev, "dev intmask = %08x\n", readl(&dev->regs->irqmsk));
199 DBG(dev, "\n");
200 DBG(dev, "dev ep int's = %08x\n", readl(&dev->regs->ep_irqsts));
201 DBG(dev, "dev ep intmask = %08x\n", readl(&dev->regs->ep_irqmsk));
202 DBG(dev, "\n");
203 DBG(dev, "USE DMA = %d\n", use_dma);
204 if (use_dma && use_dma_ppb && !use_dma_ppb_du) {
205 DBG(dev, "DMA mode = PPBNDU (packet per buffer "
206 "WITHOUT desc. update)\n");
207 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBNDU");
208 } else if (use_dma && use_dma_ppb_du && use_dma_ppb_du) {
209 DBG(dev, "DMA mode = PPBDU (packet per buffer "
210 "WITH desc. update)\n");
211 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "PPBDU");
212 }
213 if (use_dma && use_dma_bufferfill_mode) {
214 DBG(dev, "DMA mode = BF (buffer fill mode)\n");
215 dev_info(&dev->pdev->dev, "DMA mode (%s)\n", "BF");
216 }
217 if (!use_dma) {
218 dev_info(&dev->pdev->dev, "FIFO mode\n");
219 }
220 DBG(dev, "-------------------------------------------------------\n");
221}
222
223/* Masks unused interrupts */
224static int udc_mask_unused_interrupts(struct udc *dev)
225{
226 u32 tmp;
227
228 /* mask all dev interrupts */
229 tmp = AMD_BIT(UDC_DEVINT_SVC) |
230 AMD_BIT(UDC_DEVINT_ENUM) |
231 AMD_BIT(UDC_DEVINT_US) |
232 AMD_BIT(UDC_DEVINT_UR) |
233 AMD_BIT(UDC_DEVINT_ES) |
234 AMD_BIT(UDC_DEVINT_SI) |
235 AMD_BIT(UDC_DEVINT_SOF)|
236 AMD_BIT(UDC_DEVINT_SC);
237 writel(tmp, &dev->regs->irqmsk);
238
239 /* mask all ep interrupts */
240 writel(UDC_EPINT_MSK_DISABLE_ALL, &dev->regs->ep_irqmsk);
241
242 return 0;
243}
244
245/* Enables endpoint 0 interrupts */
246static int udc_enable_ep0_interrupts(struct udc *dev)
247{
248 u32 tmp;
249
250 DBG(dev, "udc_enable_ep0_interrupts()\n");
251
252 /* read irq mask */
253 tmp = readl(&dev->regs->ep_irqmsk);
254 /* enable ep0 irq's */
255 tmp &= AMD_UNMASK_BIT(UDC_EPINT_IN_EP0)
256 & AMD_UNMASK_BIT(UDC_EPINT_OUT_EP0);
257 writel(tmp, &dev->regs->ep_irqmsk);
258
259 return 0;
260}
261
262/* Enables device interrupts for SET_INTF and SET_CONFIG */
263static int udc_enable_dev_setup_interrupts(struct udc *dev)
264{
265 u32 tmp;
266
267 DBG(dev, "enable device interrupts for setup data\n");
268
269 /* read irq mask */
270 tmp = readl(&dev->regs->irqmsk);
271
272 /* enable SET_INTERFACE, SET_CONFIG and other needed irq's */
273 tmp &= AMD_UNMASK_BIT(UDC_DEVINT_SI)
274 & AMD_UNMASK_BIT(UDC_DEVINT_SC)
275 & AMD_UNMASK_BIT(UDC_DEVINT_UR)
276 & AMD_UNMASK_BIT(UDC_DEVINT_SVC)
277 & AMD_UNMASK_BIT(UDC_DEVINT_ENUM);
278 writel(tmp, &dev->regs->irqmsk);
279
280 return 0;
281}
282
283/* Calculates fifo start of endpoint based on preceeding endpoints */
284static int udc_set_txfifo_addr(struct udc_ep *ep)
285{
286 struct udc *dev;
287 u32 tmp;
288 int i;
289
290 if (!ep || !(ep->in))
291 return -EINVAL;
292
293 dev = ep->dev;
294 ep->txfifo = dev->txfifo;
295
296 /* traverse ep's */
297 for (i = 0; i < ep->num; i++) {
298 if (dev->ep[i].regs) {
299 /* read fifo size */
300 tmp = readl(&dev->ep[i].regs->bufin_framenum);
301 tmp = AMD_GETBITS(tmp, UDC_EPIN_BUFF_SIZE);
302 ep->txfifo += tmp;
303 }
304 }
305 return 0;
306}
307
308/* CNAK pending field: bit0 = ep0in, bit16 = ep0out */
309static u32 cnak_pending;
310
311static void UDC_QUEUE_CNAK(struct udc_ep *ep, unsigned num)
312{
313 if (readl(&ep->regs->ctl) & AMD_BIT(UDC_EPCTL_NAK)) {
314 DBG(ep->dev, "NAK could not be cleared for ep%d\n", num);
315 cnak_pending |= 1 << (num);
316 ep->naking = 1;
317 } else
318 cnak_pending = cnak_pending & (~(1 << (num)));
319}
320
321
322/* Enables endpoint, is called by gadget driver */
323static int
324udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
325{
326 struct udc_ep *ep;
327 struct udc *dev;
328 u32 tmp;
329 unsigned long iflags;
330 u8 udc_csr_epix;
331
332 if (!usbep
333 || usbep->name == ep0_string
334 || !desc
335 || desc->bDescriptorType != USB_DT_ENDPOINT)
336 return -EINVAL;
337
338 ep = container_of(usbep, struct udc_ep, ep);
339 dev = ep->dev;
340
341 DBG(dev, "udc_ep_enable() ep %d\n", ep->num);
342
343 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
344 return -ESHUTDOWN;
345
346 spin_lock_irqsave(&dev->lock, iflags);
347 ep->desc = desc;
348
349 ep->halted = 0;
350
351 /* set traffic type */
352 tmp = readl(&dev->ep[ep->num].regs->ctl);
353 tmp = AMD_ADDBITS(tmp, desc->bmAttributes, UDC_EPCTL_ET);
354 writel(tmp, &dev->ep[ep->num].regs->ctl);
355
356 /* set max packet size */
357 tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt);
358 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_EP_MAX_PKT_SIZE);
359 ep->ep.maxpacket = desc->wMaxPacketSize;
360 writel(tmp, &dev->ep[ep->num].regs->bufout_maxpkt);
361
362 /* IN ep */
363 if (ep->in) {
364
365 /* ep ix in UDC CSR register space */
366 udc_csr_epix = ep->num;
367
368 /* set buffer size (tx fifo entries) */
369 tmp = readl(&dev->ep[ep->num].regs->bufin_framenum);
370 /* double buffering: fifo size = 2 x max packet size */
371 tmp = AMD_ADDBITS(
372 tmp,
373 desc->wMaxPacketSize * UDC_EPIN_BUFF_SIZE_MULT
374 / UDC_DWORD_BYTES,
375 UDC_EPIN_BUFF_SIZE);
376 writel(tmp, &dev->ep[ep->num].regs->bufin_framenum);
377
378 /* calc. tx fifo base addr */
379 udc_set_txfifo_addr(ep);
380
381 /* flush fifo */
382 tmp = readl(&ep->regs->ctl);
383 tmp |= AMD_BIT(UDC_EPCTL_F);
384 writel(tmp, &ep->regs->ctl);
385
386 /* OUT ep */
387 } else {
388 /* ep ix in UDC CSR register space */
389 udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS;
390
391 /* set max packet size UDC CSR */
392 tmp = readl(&dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]);
393 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize,
394 UDC_CSR_NE_MAX_PKT);
395 writel(tmp, &dev->csr->ne[ep->num - UDC_CSR_EP_OUT_IX_OFS]);
396
397 if (use_dma && !ep->in) {
398 /* alloc and init BNA dummy request */
399 ep->bna_dummy_req = udc_alloc_bna_dummy(ep);
400 ep->bna_occurred = 0;
401 }
402
403 if (ep->num != UDC_EP0OUT_IX)
404 dev->data_ep_enabled = 1;
405 }
406
407 /* set ep values */
408 tmp = readl(&dev->csr->ne[udc_csr_epix]);
409 /* max packet */
410 tmp = AMD_ADDBITS(tmp, desc->wMaxPacketSize, UDC_CSR_NE_MAX_PKT);
411 /* ep number */
412 tmp = AMD_ADDBITS(tmp, desc->bEndpointAddress, UDC_CSR_NE_NUM);
413 /* ep direction */
414 tmp = AMD_ADDBITS(tmp, ep->in, UDC_CSR_NE_DIR);
415 /* ep type */
416 tmp = AMD_ADDBITS(tmp, desc->bmAttributes, UDC_CSR_NE_TYPE);
417 /* ep config */
418 tmp = AMD_ADDBITS(tmp, ep->dev->cur_config, UDC_CSR_NE_CFG);
419 /* ep interface */
420 tmp = AMD_ADDBITS(tmp, ep->dev->cur_intf, UDC_CSR_NE_INTF);
421 /* ep alt */
422 tmp = AMD_ADDBITS(tmp, ep->dev->cur_alt, UDC_CSR_NE_ALT);
423 /* write reg */
424 writel(tmp, &dev->csr->ne[udc_csr_epix]);
425
426 /* enable ep irq */
427 tmp = readl(&dev->regs->ep_irqmsk);
428 tmp &= AMD_UNMASK_BIT(ep->num);
429 writel(tmp, &dev->regs->ep_irqmsk);
430
431 /*
432 * clear NAK by writing CNAK
433 * avoid BNA for OUT DMA, don't clear NAK until DMA desc. written
434 */
435 if (!use_dma || ep->in) {
436 tmp = readl(&ep->regs->ctl);
437 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
438 writel(tmp, &ep->regs->ctl);
439 ep->naking = 0;
440 UDC_QUEUE_CNAK(ep, ep->num);
441 }
442 tmp = desc->bEndpointAddress;
443 DBG(dev, "%s enabled\n", usbep->name);
444
445 spin_unlock_irqrestore(&dev->lock, iflags);
446 return 0;
447}
448
449/* Resets endpoint */
450static void ep_init(struct udc_regs __iomem *regs, struct udc_ep *ep)
451{
452 u32 tmp;
453
454 VDBG(ep->dev, "ep-%d reset\n", ep->num);
455 ep->desc = NULL;
456 ep->ep.ops = &udc_ep_ops;
457 INIT_LIST_HEAD(&ep->queue);
458
459 ep->ep.maxpacket = (u16) ~0;
460 /* set NAK */
461 tmp = readl(&ep->regs->ctl);
462 tmp |= AMD_BIT(UDC_EPCTL_SNAK);
463 writel(tmp, &ep->regs->ctl);
464 ep->naking = 1;
465
466 /* disable interrupt */
467 tmp = readl(&regs->ep_irqmsk);
468 tmp |= AMD_BIT(ep->num);
469 writel(tmp, &regs->ep_irqmsk);
470
471 if (ep->in) {
472 /* unset P and IN bit of potential former DMA */
473 tmp = readl(&ep->regs->ctl);
474 tmp &= AMD_UNMASK_BIT(UDC_EPCTL_P);
475 writel(tmp, &ep->regs->ctl);
476
477 tmp = readl(&ep->regs->sts);
478 tmp |= AMD_BIT(UDC_EPSTS_IN);
479 writel(tmp, &ep->regs->sts);
480
481 /* flush the fifo */
482 tmp = readl(&ep->regs->ctl);
483 tmp |= AMD_BIT(UDC_EPCTL_F);
484 writel(tmp, &ep->regs->ctl);
485
486 }
487 /* reset desc pointer */
488 writel(0, &ep->regs->desptr);
489}
490
491/* Disables endpoint, is called by gadget driver */
492static int udc_ep_disable(struct usb_ep *usbep)
493{
494 struct udc_ep *ep = NULL;
495 unsigned long iflags;
496
497 if (!usbep)
498 return -EINVAL;
499
500 ep = container_of(usbep, struct udc_ep, ep);
501 if (usbep->name == ep0_string || !ep->desc)
502 return -EINVAL;
503
504 DBG(ep->dev, "Disable ep-%d\n", ep->num);
505
506 spin_lock_irqsave(&ep->dev->lock, iflags);
507 udc_free_request(&ep->ep, &ep->bna_dummy_req->req);
508 empty_req_queue(ep);
509 ep_init(ep->dev->regs, ep);
510 spin_unlock_irqrestore(&ep->dev->lock, iflags);
511
512 return 0;
513}
514
515/* Allocates request packet, called by gadget driver */
516static struct usb_request *
517udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
518{
519 struct udc_request *req;
520 struct udc_data_dma *dma_desc;
521 struct udc_ep *ep;
522
523 if (!usbep)
524 return NULL;
525
526 ep = container_of(usbep, struct udc_ep, ep);
527
528 VDBG(ep->dev, "udc_alloc_req(): ep%d\n", ep->num);
529 req = kzalloc(sizeof(struct udc_request), gfp);
530 if (!req)
531 return NULL;
532
533 req->req.dma = DMA_DONT_USE;
534 INIT_LIST_HEAD(&req->queue);
535
536 if (ep->dma) {
537 /* ep0 in requests are allocated from data pool here */
538 dma_desc = pci_pool_alloc(ep->dev->data_requests, gfp,
539 &req->td_phys);
540 if (!dma_desc) {
541 kfree(req);
542 return NULL;
543 }
544
545 VDBG(ep->dev, "udc_alloc_req: req = %p dma_desc = %p, "
546 "td_phys = %lx\n",
547 req, dma_desc,
548 (unsigned long)req->td_phys);
549 /* prevent from using desc. - set HOST BUSY */
550 dma_desc->status = AMD_ADDBITS(dma_desc->status,
551 UDC_DMA_STP_STS_BS_HOST_BUSY,
552 UDC_DMA_STP_STS_BS);
553 dma_desc->bufptr = __constant_cpu_to_le32(DMA_DONT_USE);
554 req->td_data = dma_desc;
555 req->td_data_last = NULL;
556 req->chain_len = 1;
557 }
558
559 return &req->req;
560}
561
562/* Frees request packet, called by gadget driver */
563static void
564udc_free_request(struct usb_ep *usbep, struct usb_request *usbreq)
565{
566 struct udc_ep *ep;
567 struct udc_request *req;
568
569 if (!usbep || !usbreq)
570 return;
571
572 ep = container_of(usbep, struct udc_ep, ep);
573 req = container_of(usbreq, struct udc_request, req);
574 VDBG(ep->dev, "free_req req=%p\n", req);
575 BUG_ON(!list_empty(&req->queue));
576 if (req->td_data) {
577 VDBG(ep->dev, "req->td_data=%p\n", req->td_data);
578
579 /* free dma chain if created */
580 if (req->chain_len > 1) {
581 udc_free_dma_chain(ep->dev, req);
582 }
583
584 pci_pool_free(ep->dev->data_requests, req->td_data,
585 req->td_phys);
586 }
587 kfree(req);
588}
589
590/* Init BNA dummy descriptor for HOST BUSY and pointing to itself */
591static void udc_init_bna_dummy(struct udc_request *req)
592{
593 if (req) {
594 /* set last bit */
595 req->td_data->status |= AMD_BIT(UDC_DMA_IN_STS_L);
596 /* set next pointer to itself */
597 req->td_data->next = req->td_phys;
598 /* set HOST BUSY */
599 req->td_data->status
600 = AMD_ADDBITS(req->td_data->status,
601 UDC_DMA_STP_STS_BS_DMA_DONE,
602 UDC_DMA_STP_STS_BS);
603#ifdef UDC_VERBOSE
604 pr_debug("bna desc = %p, sts = %08x\n",
605 req->td_data, req->td_data->status);
606#endif
607 }
608}
609
610/* Allocate BNA dummy descriptor */
611static struct udc_request *udc_alloc_bna_dummy(struct udc_ep *ep)
612{
613 struct udc_request *req = NULL;
614 struct usb_request *_req = NULL;
615
616 /* alloc the dummy request */
617 _req = udc_alloc_request(&ep->ep, GFP_ATOMIC);
618 if (_req) {
619 req = container_of(_req, struct udc_request, req);
620 ep->bna_dummy_req = req;
621 udc_init_bna_dummy(req);
622 }
623 return req;
624}
625
626/* Write data to TX fifo for IN packets */
627static void
628udc_txfifo_write(struct udc_ep *ep, struct usb_request *req)
629{
630 u8 *req_buf;
631 u32 *buf;
632 int i, j;
633 unsigned bytes = 0;
634 unsigned remaining = 0;
635
636 if (!req || !ep)
637 return;
638
639 req_buf = req->buf + req->actual;
640 prefetch(req_buf);
641 remaining = req->length - req->actual;
642
643 buf = (u32 *) req_buf;
644
645 bytes = ep->ep.maxpacket;
646 if (bytes > remaining)
647 bytes = remaining;
648
649 /* dwords first */
650 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) {
651 writel(*(buf + i), ep->txfifo);
652 }
653
654 /* remaining bytes must be written by byte access */
655 for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) {
656 writeb((u8)(*(buf + i) >> (j << UDC_BITS_PER_BYTE_SHIFT)),
657 ep->txfifo);
658 }
659
660 /* dummy write confirm */
661 writel(0, &ep->regs->confirm);
662}
663
664/* Read dwords from RX fifo for OUT transfers */
665static int udc_rxfifo_read_dwords(struct udc *dev, u32 *buf, int dwords)
666{
667 int i;
668
669 VDBG(dev, "udc_read_dwords(): %d dwords\n", dwords);
670
671 for (i = 0; i < dwords; i++) {
672 *(buf + i) = readl(dev->rxfifo);
673 }
674 return 0;
675}
676
677/* Read bytes from RX fifo for OUT transfers */
678static int udc_rxfifo_read_bytes(struct udc *dev, u8 *buf, int bytes)
679{
680 int i, j;
681 u32 tmp;
682
683 VDBG(dev, "udc_read_bytes(): %d bytes\n", bytes);
684
685 /* dwords first */
686 for (i = 0; i < bytes / UDC_DWORD_BYTES; i++) {
687 *((u32 *)(buf + (i<<2))) = readl(dev->rxfifo);
688 }
689
690 /* remaining bytes must be read by byte access */
691 if (bytes % UDC_DWORD_BYTES) {
692 tmp = readl(dev->rxfifo);
693 for (j = 0; j < bytes % UDC_DWORD_BYTES; j++) {
694 *(buf + (i<<2) + j) = (u8)(tmp & UDC_BYTE_MASK);
695 tmp = tmp >> UDC_BITS_PER_BYTE;
696 }
697 }
698
699 return 0;
700}
701
702/* Read data from RX fifo for OUT transfers */
703static int
704udc_rxfifo_read(struct udc_ep *ep, struct udc_request *req)
705{
706 u8 *buf;
707 unsigned buf_space;
708 unsigned bytes = 0;
709 unsigned finished = 0;
710
711 /* received number bytes */
712 bytes = readl(&ep->regs->sts);
713 bytes = AMD_GETBITS(bytes, UDC_EPSTS_RX_PKT_SIZE);
714
715 buf_space = req->req.length - req->req.actual;
716 buf = req->req.buf + req->req.actual;
717 if (bytes > buf_space) {
718 if ((buf_space % ep->ep.maxpacket) != 0) {
719 DBG(ep->dev,
720 "%s: rx %d bytes, rx-buf space = %d bytesn\n",
721 ep->ep.name, bytes, buf_space);
722 req->req.status = -EOVERFLOW;
723 }
724 bytes = buf_space;
725 }
726 req->req.actual += bytes;
727
728 /* last packet ? */
729 if (((bytes % ep->ep.maxpacket) != 0) || (!bytes)
730 || ((req->req.actual == req->req.length) && !req->req.zero))
731 finished = 1;
732
733 /* read rx fifo bytes */
734 VDBG(ep->dev, "ep %s: rxfifo read %d bytes\n", ep->ep.name, bytes);
735 udc_rxfifo_read_bytes(ep->dev, buf, bytes);
736
737 return finished;
738}
739
740/* create/re-init a DMA descriptor or a DMA descriptor chain */
741static int prep_dma(struct udc_ep *ep, struct udc_request *req, gfp_t gfp)
742{
743 int retval = 0;
744 u32 tmp;
745
746 VDBG(ep->dev, "prep_dma\n");
747 VDBG(ep->dev, "prep_dma ep%d req->td_data=%p\n",
748 ep->num, req->td_data);
749
750 /* set buffer pointer */
751 req->td_data->bufptr = req->req.dma;
752
753 /* set last bit */
754 req->td_data->status |= AMD_BIT(UDC_DMA_IN_STS_L);
755
756 /* build/re-init dma chain if maxpkt scatter mode, not for EP0 */
757 if (use_dma_ppb) {
758
759 retval = udc_create_dma_chain(ep, req, ep->ep.maxpacket, gfp);
760 if (retval != 0) {
761 if (retval == -ENOMEM)
762 DBG(ep->dev, "Out of DMA memory\n");
763 return retval;
764 }
765 if (ep->in) {
766 if (req->req.length == ep->ep.maxpacket) {
767 /* write tx bytes */
768 req->td_data->status =
769 AMD_ADDBITS(req->td_data->status,
770 ep->ep.maxpacket,
771 UDC_DMA_IN_STS_TXBYTES);
772
773 }
774 }
775
776 }
777
778 if (ep->in) {
779 VDBG(ep->dev, "IN: use_dma_ppb=%d req->req.len=%d "
780 "maxpacket=%d ep%d\n",
781 use_dma_ppb, req->req.length,
782 ep->ep.maxpacket, ep->num);
783 /*
784 * if bytes < max packet then tx bytes must
785 * be written in packet per buffer mode
786 */
787 if (!use_dma_ppb || req->req.length < ep->ep.maxpacket
788 || ep->num == UDC_EP0OUT_IX
789 || ep->num == UDC_EP0IN_IX) {
790 /* write tx bytes */
791 req->td_data->status =
792 AMD_ADDBITS(req->td_data->status,
793 req->req.length,
794 UDC_DMA_IN_STS_TXBYTES);
795 /* reset frame num */
796 req->td_data->status =
797 AMD_ADDBITS(req->td_data->status,
798 0,
799 UDC_DMA_IN_STS_FRAMENUM);
800 }
801 /* set HOST BUSY */
802 req->td_data->status =
803 AMD_ADDBITS(req->td_data->status,
804 UDC_DMA_STP_STS_BS_HOST_BUSY,
805 UDC_DMA_STP_STS_BS);
806 } else {
807 VDBG(ep->dev, "OUT set host ready\n");
808 /* set HOST READY */
809 req->td_data->status =
810 AMD_ADDBITS(req->td_data->status,
811 UDC_DMA_STP_STS_BS_HOST_READY,
812 UDC_DMA_STP_STS_BS);
813
814
815 /* clear NAK by writing CNAK */
816 if (ep->naking) {
817 tmp = readl(&ep->regs->ctl);
818 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
819 writel(tmp, &ep->regs->ctl);
820 ep->naking = 0;
821 UDC_QUEUE_CNAK(ep, ep->num);
822 }
823
824 }
825
826 return retval;
827}
828
829/* Completes request packet ... caller MUST hold lock */
830static void
831complete_req(struct udc_ep *ep, struct udc_request *req, int sts)
832__releases(ep->dev->lock)
833__acquires(ep->dev->lock)
834{
835 struct udc *dev;
836 unsigned halted;
837
838 VDBG(ep->dev, "complete_req(): ep%d\n", ep->num);
839
840 dev = ep->dev;
841 /* unmap DMA */
842 if (req->dma_mapping) {
843 if (ep->in)
844 pci_unmap_single(dev->pdev,
845 req->req.dma,
846 req->req.length,
847 PCI_DMA_TODEVICE);
848 else
849 pci_unmap_single(dev->pdev,
850 req->req.dma,
851 req->req.length,
852 PCI_DMA_FROMDEVICE);
853 req->dma_mapping = 0;
854 req->req.dma = DMA_DONT_USE;
855 }
856
857 halted = ep->halted;
858 ep->halted = 1;
859
860 /* set new status if pending */
861 if (req->req.status == -EINPROGRESS)
862 req->req.status = sts;
863
864 /* remove from ep queue */
865 list_del_init(&req->queue);
866
867 VDBG(ep->dev, "req %p => complete %d bytes at %s with sts %d\n",
868 &req->req, req->req.length, ep->ep.name, sts);
869
870 spin_unlock(&dev->lock);
871 req->req.complete(&ep->ep, &req->req);
872 spin_lock(&dev->lock);
873 ep->halted = halted;
874}
875
876/* frees pci pool descriptors of a DMA chain */
877static int udc_free_dma_chain(struct udc *dev, struct udc_request *req)
878{
879
880 int ret_val = 0;
881 struct udc_data_dma *td;
882 struct udc_data_dma *td_last = NULL;
883 unsigned int i;
884
885 DBG(dev, "free chain req = %p\n", req);
886
887 /* do not free first desc., will be done by free for request */
888 td_last = req->td_data;
889 td = phys_to_virt(td_last->next);
890
891 for (i = 1; i < req->chain_len; i++) {
892
893 pci_pool_free(dev->data_requests, td,
894 (dma_addr_t) td_last->next);
895 td_last = td;
896 td = phys_to_virt(td_last->next);
897 }
898
899 return ret_val;
900}
901
902/* Iterates to the end of a DMA chain and returns last descriptor */
903static struct udc_data_dma *udc_get_last_dma_desc(struct udc_request *req)
904{
905 struct udc_data_dma *td;
906
907 td = req->td_data;
908 while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L))) {
909 td = phys_to_virt(td->next);
910 }
911
912 return td;
913
914}
915
916/* Iterates to the end of a DMA chain and counts bytes received */
917static u32 udc_get_ppbdu_rxbytes(struct udc_request *req)
918{
919 struct udc_data_dma *td;
920 u32 count;
921
922 td = req->td_data;
923 /* received number bytes */
924 count = AMD_GETBITS(td->status, UDC_DMA_OUT_STS_RXBYTES);
925
926 while (td && !(td->status & AMD_BIT(UDC_DMA_IN_STS_L))) {
927 td = phys_to_virt(td->next);
928 /* received number bytes */
929 if (td) {
930 count += AMD_GETBITS(td->status,
931 UDC_DMA_OUT_STS_RXBYTES);
932 }
933 }
934
935 return count;
936
937}
938
939/* Creates or re-inits a DMA chain */
940static int udc_create_dma_chain(
941 struct udc_ep *ep,
942 struct udc_request *req,
943 unsigned long buf_len, gfp_t gfp_flags
944)
945{
946 unsigned long bytes = req->req.length;
947 unsigned int i;
948 dma_addr_t dma_addr;
949 struct udc_data_dma *td = NULL;
950 struct udc_data_dma *last = NULL;
951 unsigned long txbytes;
952 unsigned create_new_chain = 0;
953 unsigned len;
954
955 VDBG(ep->dev, "udc_create_dma_chain: bytes=%ld buf_len=%ld\n",
956 bytes, buf_len);
957 dma_addr = DMA_DONT_USE;
958
959 /* unset L bit in first desc for OUT */
960 if (!ep->in) {
961 req->td_data->status &= AMD_CLEAR_BIT(UDC_DMA_IN_STS_L);
962 }
963
964 /* alloc only new desc's if not already available */
965 len = req->req.length / ep->ep.maxpacket;
966 if (req->req.length % ep->ep.maxpacket) {
967 len++;
968 }
969
970 if (len > req->chain_len) {
971 /* shorter chain already allocated before */
972 if (req->chain_len > 1) {
973 udc_free_dma_chain(ep->dev, req);
974 }
975 req->chain_len = len;
976 create_new_chain = 1;
977 }
978
979 td = req->td_data;
980 /* gen. required number of descriptors and buffers */
981 for (i = buf_len; i < bytes; i += buf_len) {
982 /* create or determine next desc. */
983 if (create_new_chain) {
984
985 td = pci_pool_alloc(ep->dev->data_requests,
986 gfp_flags, &dma_addr);
987 if (!td)
988 return -ENOMEM;
989
990 td->status = 0;
991 } else if (i == buf_len) {
992 /* first td */
993 td = (struct udc_data_dma *) phys_to_virt(
994 req->td_data->next);
995 td->status = 0;
996 } else {
997 td = (struct udc_data_dma *) phys_to_virt(last->next);
998 td->status = 0;
999 }
1000
1001
1002 if (td)
1003 td->bufptr = req->req.dma + i; /* assign buffer */
1004 else
1005 break;
1006
1007 /* short packet ? */
1008 if ((bytes - i) >= buf_len) {
1009 txbytes = buf_len;
1010 } else {
1011 /* short packet */
1012 txbytes = bytes - i;
1013 }
1014
1015 /* link td and assign tx bytes */
1016 if (i == buf_len) {
1017 if (create_new_chain) {
1018 req->td_data->next = dma_addr;
1019 } else {
1020 /* req->td_data->next = virt_to_phys(td); */
1021 }
1022 /* write tx bytes */
1023 if (ep->in) {
1024 /* first desc */
1025 req->td_data->status =
1026 AMD_ADDBITS(req->td_data->status,
1027 ep->ep.maxpacket,
1028 UDC_DMA_IN_STS_TXBYTES);
1029 /* second desc */
1030 td->status = AMD_ADDBITS(td->status,
1031 txbytes,
1032 UDC_DMA_IN_STS_TXBYTES);
1033 }
1034 } else {
1035 if (create_new_chain) {
1036 last->next = dma_addr;
1037 } else {
1038 /* last->next = virt_to_phys(td); */
1039 }
1040 if (ep->in) {
1041 /* write tx bytes */
1042 td->status = AMD_ADDBITS(td->status,
1043 txbytes,
1044 UDC_DMA_IN_STS_TXBYTES);
1045 }
1046 }
1047 last = td;
1048 }
1049 /* set last bit */
1050 if (td) {
1051 td->status |= AMD_BIT(UDC_DMA_IN_STS_L);
1052 /* last desc. points to itself */
1053 req->td_data_last = td;
1054 }
1055
1056 return 0;
1057}
1058
1059/* Enabling RX DMA */
1060static void udc_set_rde(struct udc *dev)
1061{
1062 u32 tmp;
1063
1064 VDBG(dev, "udc_set_rde()\n");
1065 /* stop RDE timer */
1066 if (timer_pending(&udc_timer)) {
1067 set_rde = 0;
1068 mod_timer(&udc_timer, jiffies - 1);
1069 }
1070 /* set RDE */
1071 tmp = readl(&dev->regs->ctl);
1072 tmp |= AMD_BIT(UDC_DEVCTL_RDE);
1073 writel(tmp, &dev->regs->ctl);
1074}
1075
1076/* Queues a request packet, called by gadget driver */
1077static int
1078udc_queue(struct usb_ep *usbep, struct usb_request *usbreq, gfp_t gfp)
1079{
1080 int retval = 0;
1081 u8 open_rxfifo = 0;
1082 unsigned long iflags;
1083 struct udc_ep *ep;
1084 struct udc_request *req;
1085 struct udc *dev;
1086 u32 tmp;
1087
1088 /* check the inputs */
1089 req = container_of(usbreq, struct udc_request, req);
1090
1091 if (!usbep || !usbreq || !usbreq->complete || !usbreq->buf
1092 || !list_empty(&req->queue))
1093 return -EINVAL;
1094
1095 ep = container_of(usbep, struct udc_ep, ep);
1096 if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX))
1097 return -EINVAL;
1098
1099 VDBG(ep->dev, "udc_queue(): ep%d-in=%d\n", ep->num, ep->in);
1100 dev = ep->dev;
1101
1102 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
1103 return -ESHUTDOWN;
1104
1105 /* map dma (usually done before) */
1106 if (ep->dma && usbreq->length != 0
1107 && (usbreq->dma == DMA_DONT_USE || usbreq->dma == 0)) {
1108 VDBG(dev, "DMA map req %p\n", req);
1109 if (ep->in)
1110 usbreq->dma = pci_map_single(dev->pdev,
1111 usbreq->buf,
1112 usbreq->length,
1113 PCI_DMA_TODEVICE);
1114 else
1115 usbreq->dma = pci_map_single(dev->pdev,
1116 usbreq->buf,
1117 usbreq->length,
1118 PCI_DMA_FROMDEVICE);
1119 req->dma_mapping = 1;
1120 }
1121
1122 VDBG(dev, "%s queue req %p, len %d req->td_data=%p buf %p\n",
1123 usbep->name, usbreq, usbreq->length,
1124 req->td_data, usbreq->buf);
1125
1126 spin_lock_irqsave(&dev->lock, iflags);
1127 usbreq->actual = 0;
1128 usbreq->status = -EINPROGRESS;
1129 req->dma_done = 0;
1130
1131 /* on empty queue just do first transfer */
1132 if (list_empty(&ep->queue)) {
1133 /* zlp */
1134 if (usbreq->length == 0) {
1135 /* IN zlp's are handled by hardware */
1136 complete_req(ep, req, 0);
1137 VDBG(dev, "%s: zlp\n", ep->ep.name);
1138 /*
1139 * if set_config or set_intf is waiting for ack by zlp
1140 * then set CSR_DONE
1141 */
1142 if (dev->set_cfg_not_acked) {
1143 tmp = readl(&dev->regs->ctl);
1144 tmp |= AMD_BIT(UDC_DEVCTL_CSR_DONE);
1145 writel(tmp, &dev->regs->ctl);
1146 dev->set_cfg_not_acked = 0;
1147 }
1148 /* setup command is ACK'ed now by zlp */
1149 if (dev->waiting_zlp_ack_ep0in) {
1150 /* clear NAK by writing CNAK in EP0_IN */
1151 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
1152 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1153 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
1154 dev->ep[UDC_EP0IN_IX].naking = 0;
1155 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX],
1156 UDC_EP0IN_IX);
1157 dev->waiting_zlp_ack_ep0in = 0;
1158 }
1159 goto finished;
1160 }
1161 if (ep->dma) {
1162 retval = prep_dma(ep, req, gfp);
1163 if (retval != 0)
1164 goto finished;
1165 /* write desc pointer to enable DMA */
1166 if (ep->in) {
1167 /* set HOST READY */
1168 req->td_data->status =
1169 AMD_ADDBITS(req->td_data->status,
1170 UDC_DMA_IN_STS_BS_HOST_READY,
1171 UDC_DMA_IN_STS_BS);
1172 }
1173
1174 /* disabled rx dma while descriptor update */
1175 if (!ep->in) {
1176 /* stop RDE timer */
1177 if (timer_pending(&udc_timer)) {
1178 set_rde = 0;
1179 mod_timer(&udc_timer, jiffies - 1);
1180 }
1181 /* clear RDE */
1182 tmp = readl(&dev->regs->ctl);
1183 tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE);
1184 writel(tmp, &dev->regs->ctl);
1185 open_rxfifo = 1;
1186
1187 /*
1188 * if BNA occurred then let BNA dummy desc.
1189 * point to current desc.
1190 */
1191 if (ep->bna_occurred) {
1192 VDBG(dev, "copy to BNA dummy desc.\n");
1193 memcpy(ep->bna_dummy_req->td_data,
1194 req->td_data,
1195 sizeof(struct udc_data_dma));
1196 }
1197 }
1198 /* write desc pointer */
1199 writel(req->td_phys, &ep->regs->desptr);
1200
1201 /* clear NAK by writing CNAK */
1202 if (ep->naking) {
1203 tmp = readl(&ep->regs->ctl);
1204 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1205 writel(tmp, &ep->regs->ctl);
1206 ep->naking = 0;
1207 UDC_QUEUE_CNAK(ep, ep->num);
1208 }
1209
1210 if (ep->in) {
1211 /* enable ep irq */
1212 tmp = readl(&dev->regs->ep_irqmsk);
1213 tmp &= AMD_UNMASK_BIT(ep->num);
1214 writel(tmp, &dev->regs->ep_irqmsk);
1215 }
1216 }
1217
1218 } else if (ep->dma) {
1219
1220 /*
1221 * prep_dma not used for OUT ep's, this is not possible
1222 * for PPB modes, because of chain creation reasons
1223 */
1224 if (ep->in) {
1225 retval = prep_dma(ep, req, gfp);
1226 if (retval != 0)
1227 goto finished;
1228 }
1229 }
1230 VDBG(dev, "list_add\n");
1231 /* add request to ep queue */
1232 if (req) {
1233
1234 list_add_tail(&req->queue, &ep->queue);
1235
1236 /* open rxfifo if out data queued */
1237 if (open_rxfifo) {
1238 /* enable DMA */
1239 req->dma_going = 1;
1240 udc_set_rde(dev);
1241 if (ep->num != UDC_EP0OUT_IX)
1242 dev->data_ep_queued = 1;
1243 }
1244 /* stop OUT naking */
1245 if (!ep->in) {
1246 if (!use_dma && udc_rxfifo_pending) {
1247 DBG(dev, "udc_queue(): pending bytes in"
1248 "rxfifo after nyet\n");
1249 /*
1250 * read pending bytes afer nyet:
1251 * referring to isr
1252 */
1253 if (udc_rxfifo_read(ep, req)) {
1254 /* finish */
1255 complete_req(ep, req, 0);
1256 }
1257 udc_rxfifo_pending = 0;
1258
1259 }
1260 }
1261 }
1262
1263finished:
1264 spin_unlock_irqrestore(&dev->lock, iflags);
1265 return retval;
1266}
1267
1268/* Empty request queue of an endpoint; caller holds spinlock */
1269static void empty_req_queue(struct udc_ep *ep)
1270{
1271 struct udc_request *req;
1272
1273 ep->halted = 1;
1274 while (!list_empty(&ep->queue)) {
1275 req = list_entry(ep->queue.next,
1276 struct udc_request,
1277 queue);
1278 complete_req(ep, req, -ESHUTDOWN);
1279 }
1280}
1281
1282/* Dequeues a request packet, called by gadget driver */
1283static int udc_dequeue(struct usb_ep *usbep, struct usb_request *usbreq)
1284{
1285 struct udc_ep *ep;
1286 struct udc_request *req;
1287 unsigned halted;
1288 unsigned long iflags;
1289
1290 ep = container_of(usbep, struct udc_ep, ep);
1291 if (!usbep || !usbreq || (!ep->desc && (ep->num != 0
1292 && ep->num != UDC_EP0OUT_IX)))
1293 return -EINVAL;
1294
1295 req = container_of(usbreq, struct udc_request, req);
1296
1297 spin_lock_irqsave(&ep->dev->lock, iflags);
1298 halted = ep->halted;
1299 ep->halted = 1;
1300 /* request in processing or next one */
1301 if (ep->queue.next == &req->queue) {
1302 if (ep->dma && req->dma_going) {
1303 if (ep->in)
1304 ep->cancel_transfer = 1;
1305 else {
1306 u32 tmp;
1307 u32 dma_sts;
1308 /* stop potential receive DMA */
1309 tmp = readl(&udc->regs->ctl);
1310 writel(tmp & AMD_UNMASK_BIT(UDC_DEVCTL_RDE),
1311 &udc->regs->ctl);
1312 /*
1313 * Cancel transfer later in ISR
1314 * if descriptor was touched.
1315 */
1316 dma_sts = AMD_GETBITS(req->td_data->status,
1317 UDC_DMA_OUT_STS_BS);
1318 if (dma_sts != UDC_DMA_OUT_STS_BS_HOST_READY)
1319 ep->cancel_transfer = 1;
1320 else {
1321 udc_init_bna_dummy(ep->req);
1322 writel(ep->bna_dummy_req->td_phys,
1323 &ep->regs->desptr);
1324 }
1325 writel(tmp, &udc->regs->ctl);
1326 }
1327 }
1328 }
1329 complete_req(ep, req, -ECONNRESET);
1330 ep->halted = halted;
1331
1332 spin_unlock_irqrestore(&ep->dev->lock, iflags);
1333 return 0;
1334}
1335
1336/* Halt or clear halt of endpoint */
1337static int
1338udc_set_halt(struct usb_ep *usbep, int halt)
1339{
1340 struct udc_ep *ep;
1341 u32 tmp;
1342 unsigned long iflags;
1343 int retval = 0;
1344
1345 if (!usbep)
1346 return -EINVAL;
1347
1348 pr_debug("set_halt %s: halt=%d\n", usbep->name, halt);
1349
1350 ep = container_of(usbep, struct udc_ep, ep);
1351 if (!ep->desc && (ep->num != 0 && ep->num != UDC_EP0OUT_IX))
1352 return -EINVAL;
1353 if (!ep->dev->driver || ep->dev->gadget.speed == USB_SPEED_UNKNOWN)
1354 return -ESHUTDOWN;
1355
1356 spin_lock_irqsave(&udc_stall_spinlock, iflags);
1357 /* halt or clear halt */
1358 if (halt) {
1359 if (ep->num == 0)
1360 ep->dev->stall_ep0in = 1;
1361 else {
1362 /*
1363 * set STALL
1364 * rxfifo empty not taken into acount
1365 */
1366 tmp = readl(&ep->regs->ctl);
1367 tmp |= AMD_BIT(UDC_EPCTL_S);
1368 writel(tmp, &ep->regs->ctl);
1369 ep->halted = 1;
1370
1371 /* setup poll timer */
1372 if (!timer_pending(&udc_pollstall_timer)) {
1373 udc_pollstall_timer.expires = jiffies +
1374 HZ * UDC_POLLSTALL_TIMER_USECONDS
1375 / (1000 * 1000);
1376 if (!stop_pollstall_timer) {
1377 DBG(ep->dev, "start polltimer\n");
1378 add_timer(&udc_pollstall_timer);
1379 }
1380 }
1381 }
1382 } else {
1383 /* ep is halted by set_halt() before */
1384 if (ep->halted) {
1385 tmp = readl(&ep->regs->ctl);
1386 /* clear stall bit */
1387 tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S);
1388 /* clear NAK by writing CNAK */
1389 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1390 writel(tmp, &ep->regs->ctl);
1391 ep->halted = 0;
1392 UDC_QUEUE_CNAK(ep, ep->num);
1393 }
1394 }
1395 spin_unlock_irqrestore(&udc_stall_spinlock, iflags);
1396 return retval;
1397}
1398
1399/* gadget interface */
1400static const struct usb_ep_ops udc_ep_ops = {
1401 .enable = udc_ep_enable,
1402 .disable = udc_ep_disable,
1403
1404 .alloc_request = udc_alloc_request,
1405 .free_request = udc_free_request,
1406
1407 .queue = udc_queue,
1408 .dequeue = udc_dequeue,
1409
1410 .set_halt = udc_set_halt,
1411 /* fifo ops not implemented */
1412};
1413
1414/*-------------------------------------------------------------------------*/
1415
1416/* Get frame counter (not implemented) */
1417static int udc_get_frame(struct usb_gadget *gadget)
1418{
1419 return -EOPNOTSUPP;
1420}
1421
1422/* Remote wakeup gadget interface */
1423static int udc_wakeup(struct usb_gadget *gadget)
1424{
1425 struct udc *dev;
1426
1427 if (!gadget)
1428 return -EINVAL;
1429 dev = container_of(gadget, struct udc, gadget);
1430 udc_remote_wakeup(dev);
1431
1432 return 0;
1433}
1434
1435/* gadget operations */
1436static const struct usb_gadget_ops udc_ops = {
1437 .wakeup = udc_wakeup,
1438 .get_frame = udc_get_frame,
1439};
1440
1441/* Setups endpoint parameters, adds endpoints to linked list */
1442static void make_ep_lists(struct udc *dev)
1443{
1444 /* make gadget ep lists */
1445 INIT_LIST_HEAD(&dev->gadget.ep_list);
1446 list_add_tail(&dev->ep[UDC_EPIN_STATUS_IX].ep.ep_list,
1447 &dev->gadget.ep_list);
1448 list_add_tail(&dev->ep[UDC_EPIN_IX].ep.ep_list,
1449 &dev->gadget.ep_list);
1450 list_add_tail(&dev->ep[UDC_EPOUT_IX].ep.ep_list,
1451 &dev->gadget.ep_list);
1452
1453 /* fifo config */
1454 dev->ep[UDC_EPIN_STATUS_IX].fifo_depth = UDC_EPIN_SMALLINT_BUFF_SIZE;
1455 if (dev->gadget.speed == USB_SPEED_FULL)
1456 dev->ep[UDC_EPIN_IX].fifo_depth = UDC_FS_EPIN_BUFF_SIZE;
1457 else if (dev->gadget.speed == USB_SPEED_HIGH)
1458 dev->ep[UDC_EPIN_IX].fifo_depth = hs_tx_buf;
1459 dev->ep[UDC_EPOUT_IX].fifo_depth = UDC_RXFIFO_SIZE;
1460}
1461
1462/* init registers at driver load time */
1463static int startup_registers(struct udc *dev)
1464{
1465 u32 tmp;
1466
1467 /* init controller by soft reset */
1468 udc_soft_reset(dev);
1469
1470 /* mask not needed interrupts */
1471 udc_mask_unused_interrupts(dev);
1472
1473 /* put into initial config */
1474 udc_basic_init(dev);
1475 /* link up all endpoints */
1476 udc_setup_endpoints(dev);
1477
1478 /* program speed */
1479 tmp = readl(&dev->regs->cfg);
1480 if (use_fullspeed) {
1481 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD);
1482 } else {
1483 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_HS, UDC_DEVCFG_SPD);
1484 }
1485 writel(tmp, &dev->regs->cfg);
1486
1487 return 0;
1488}
1489
1490/* Inits UDC context */
1491static void udc_basic_init(struct udc *dev)
1492{
1493 u32 tmp;
1494
1495 DBG(dev, "udc_basic_init()\n");
1496
1497 dev->gadget.speed = USB_SPEED_UNKNOWN;
1498
1499 /* stop RDE timer */
1500 if (timer_pending(&udc_timer)) {
1501 set_rde = 0;
1502 mod_timer(&udc_timer, jiffies - 1);
1503 }
1504 /* stop poll stall timer */
1505 if (timer_pending(&udc_pollstall_timer)) {
1506 mod_timer(&udc_pollstall_timer, jiffies - 1);
1507 }
1508 /* disable DMA */
1509 tmp = readl(&dev->regs->ctl);
1510 tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_RDE);
1511 tmp &= AMD_UNMASK_BIT(UDC_DEVCTL_TDE);
1512 writel(tmp, &dev->regs->ctl);
1513
1514 /* enable dynamic CSR programming */
1515 tmp = readl(&dev->regs->cfg);
1516 tmp |= AMD_BIT(UDC_DEVCFG_CSR_PRG);
1517 /* set self powered */
1518 tmp |= AMD_BIT(UDC_DEVCFG_SP);
1519 /* set remote wakeupable */
1520 tmp |= AMD_BIT(UDC_DEVCFG_RWKP);
1521 writel(tmp, &dev->regs->cfg);
1522
1523 make_ep_lists(dev);
1524
1525 dev->data_ep_enabled = 0;
1526 dev->data_ep_queued = 0;
1527}
1528
1529/* Sets initial endpoint parameters */
1530static void udc_setup_endpoints(struct udc *dev)
1531{
1532 struct udc_ep *ep;
1533 u32 tmp;
1534 u32 reg;
1535
1536 DBG(dev, "udc_setup_endpoints()\n");
1537
1538 /* read enum speed */
1539 tmp = readl(&dev->regs->sts);
1540 tmp = AMD_GETBITS(tmp, UDC_DEVSTS_ENUM_SPEED);
1541 if (tmp == UDC_DEVSTS_ENUM_SPEED_HIGH) {
1542 dev->gadget.speed = USB_SPEED_HIGH;
1543 } else if (tmp == UDC_DEVSTS_ENUM_SPEED_FULL) {
1544 dev->gadget.speed = USB_SPEED_FULL;
1545 }
1546
1547 /* set basic ep parameters */
1548 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) {
1549 ep = &dev->ep[tmp];
1550 ep->dev = dev;
1551 ep->ep.name = ep_string[tmp];
1552 ep->num = tmp;
1553 /* txfifo size is calculated at enable time */
1554 ep->txfifo = dev->txfifo;
1555
1556 /* fifo size */
1557 if (tmp < UDC_EPIN_NUM) {
1558 ep->fifo_depth = UDC_TXFIFO_SIZE;
1559 ep->in = 1;
1560 } else {
1561 ep->fifo_depth = UDC_RXFIFO_SIZE;
1562 ep->in = 0;
1563
1564 }
1565 ep->regs = &dev->ep_regs[tmp];
1566 /*
1567 * ep will be reset only if ep was not enabled before to avoid
1568 * disabling ep interrupts when ENUM interrupt occurs but ep is
1569 * not enabled by gadget driver
1570 */
1571 if (!ep->desc) {
1572 ep_init(dev->regs, ep);
1573 }
1574
1575 if (use_dma) {
1576 /*
1577 * ep->dma is not really used, just to indicate that
1578 * DMA is active: remove this
1579 * dma regs = dev control regs
1580 */
1581 ep->dma = &dev->regs->ctl;
1582
1583 /* nak OUT endpoints until enable - not for ep0 */
1584 if (tmp != UDC_EP0IN_IX && tmp != UDC_EP0OUT_IX
1585 && tmp > UDC_EPIN_NUM) {
1586 /* set NAK */
1587 reg = readl(&dev->ep[tmp].regs->ctl);
1588 reg |= AMD_BIT(UDC_EPCTL_SNAK);
1589 writel(reg, &dev->ep[tmp].regs->ctl);
1590 dev->ep[tmp].naking = 1;
1591
1592 }
1593 }
1594 }
1595 /* EP0 max packet */
1596 if (dev->gadget.speed == USB_SPEED_FULL) {
1597 dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_FS_EP0IN_MAX_PKT_SIZE;
1598 dev->ep[UDC_EP0OUT_IX].ep.maxpacket =
1599 UDC_FS_EP0OUT_MAX_PKT_SIZE;
1600 } else if (dev->gadget.speed == USB_SPEED_HIGH) {
1601 dev->ep[UDC_EP0IN_IX].ep.maxpacket = UDC_EP0IN_MAX_PKT_SIZE;
1602 dev->ep[UDC_EP0OUT_IX].ep.maxpacket = UDC_EP0OUT_MAX_PKT_SIZE;
1603 }
1604
1605 /*
1606 * with suspend bug workaround, ep0 params for gadget driver
1607 * are set at gadget driver bind() call
1608 */
1609 dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IX].ep;
1610 dev->ep[UDC_EP0IN_IX].halted = 0;
1611 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list);
1612
1613 /* init cfg/alt/int */
1614 dev->cur_config = 0;
1615 dev->cur_intf = 0;
1616 dev->cur_alt = 0;
1617}
1618
1619/* Bringup after Connect event, initial bringup to be ready for ep0 events */
1620static void usb_connect(struct udc *dev)
1621{
1622
1623 dev_info(&dev->pdev->dev, "USB Connect\n");
1624
1625 dev->connected = 1;
1626
1627 /* put into initial config */
1628 udc_basic_init(dev);
1629
1630 /* enable device setup interrupts */
1631 udc_enable_dev_setup_interrupts(dev);
1632}
1633
1634/*
1635 * Calls gadget with disconnect event and resets the UDC and makes
1636 * initial bringup to be ready for ep0 events
1637 */
1638static void usb_disconnect(struct udc *dev)
1639{
1640
1641 dev_info(&dev->pdev->dev, "USB Disconnect\n");
1642
1643 dev->connected = 0;
1644
1645 /* mask interrupts */
1646 udc_mask_unused_interrupts(dev);
1647
1648 /* REVISIT there doesn't seem to be a point to having this
1649 * talk to a tasklet ... do it directly, we already hold
1650 * the spinlock needed to process the disconnect.
1651 */
1652
1653 tasklet_schedule(&disconnect_tasklet);
1654}
1655
1656/* Tasklet for disconnect to be outside of interrupt context */
1657static void udc_tasklet_disconnect(unsigned long par)
1658{
1659 struct udc *dev = (struct udc *)(*((struct udc **) par));
1660 u32 tmp;
1661
1662 DBG(dev, "Tasklet disconnect\n");
1663 spin_lock_irq(&dev->lock);
1664
1665 if (dev->driver) {
1666 spin_unlock(&dev->lock);
1667 dev->driver->disconnect(&dev->gadget);
1668 spin_lock(&dev->lock);
1669
1670 /* empty queues */
1671 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) {
1672 empty_req_queue(&dev->ep[tmp]);
1673 }
1674
1675 }
1676
1677 /* disable ep0 */
1678 ep_init(dev->regs,
1679 &dev->ep[UDC_EP0IN_IX]);
1680
1681
1682 if (!soft_reset_occured) {
1683 /* init controller by soft reset */
1684 udc_soft_reset(dev);
1685 soft_reset_occured++;
1686 }
1687
1688 /* re-enable dev interrupts */
1689 udc_enable_dev_setup_interrupts(dev);
1690 /* back to full speed ? */
1691 if (use_fullspeed) {
1692 tmp = readl(&dev->regs->cfg);
1693 tmp = AMD_ADDBITS(tmp, UDC_DEVCFG_SPD_FS, UDC_DEVCFG_SPD);
1694 writel(tmp, &dev->regs->cfg);
1695 }
1696
1697 spin_unlock_irq(&dev->lock);
1698}
1699
1700/* Reset the UDC core */
1701static void udc_soft_reset(struct udc *dev)
1702{
1703 unsigned long flags;
1704
1705 DBG(dev, "Soft reset\n");
1706 /*
1707 * reset possible waiting interrupts, because int.
1708 * status is lost after soft reset,
1709 * ep int. status reset
1710 */
1711 writel(UDC_EPINT_MSK_DISABLE_ALL, &dev->regs->ep_irqsts);
1712 /* device int. status reset */
1713 writel(UDC_DEV_MSK_DISABLE, &dev->regs->irqsts);
1714
1715 spin_lock_irqsave(&udc_irq_spinlock, flags);
1716 writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg);
1717 readl(&dev->regs->cfg);
1718 spin_unlock_irqrestore(&udc_irq_spinlock, flags);
1719
1720}
1721
1722/* RDE timer callback to set RDE bit */
1723static void udc_timer_function(unsigned long v)
1724{
1725 u32 tmp;
1726
1727 spin_lock_irq(&udc_irq_spinlock);
1728
1729 if (set_rde > 0) {
1730 /*
1731 * open the fifo if fifo was filled on last timer call
1732 * conditionally
1733 */
1734 if (set_rde > 1) {
1735 /* set RDE to receive setup data */
1736 tmp = readl(&udc->regs->ctl);
1737 tmp |= AMD_BIT(UDC_DEVCTL_RDE);
1738 writel(tmp, &udc->regs->ctl);
1739 set_rde = -1;
1740 } else if (readl(&udc->regs->sts)
1741 & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) {
1742 /*
1743 * if fifo empty setup polling, do not just
1744 * open the fifo
1745 */
1746 udc_timer.expires = jiffies + HZ/UDC_RDE_TIMER_DIV;
1747 if (!stop_timer) {
1748 add_timer(&udc_timer);
1749 }
1750 } else {
1751 /*
1752 * fifo contains data now, setup timer for opening
1753 * the fifo when timer expires to be able to receive
1754 * setup packets, when data packets gets queued by
1755 * gadget layer then timer will forced to expire with
1756 * set_rde=0 (RDE is set in udc_queue())
1757 */
1758 set_rde++;
1759 /* debug: lhadmot_timer_start = 221070 */
1760 udc_timer.expires = jiffies + HZ*UDC_RDE_TIMER_SECONDS;
1761 if (!stop_timer) {
1762 add_timer(&udc_timer);
1763 }
1764 }
1765
1766 } else
1767 set_rde = -1; /* RDE was set by udc_queue() */
1768 spin_unlock_irq(&udc_irq_spinlock);
1769 if (stop_timer)
1770 complete(&on_exit);
1771
1772}
1773
1774/* Handle halt state, used in stall poll timer */
1775static void udc_handle_halt_state(struct udc_ep *ep)
1776{
1777 u32 tmp;
1778 /* set stall as long not halted */
1779 if (ep->halted == 1) {
1780 tmp = readl(&ep->regs->ctl);
1781 /* STALL cleared ? */
1782 if (!(tmp & AMD_BIT(UDC_EPCTL_S))) {
1783 /*
1784 * FIXME: MSC spec requires that stall remains
1785 * even on receivng of CLEAR_FEATURE HALT. So
1786 * we would set STALL again here to be compliant.
1787 * But with current mass storage drivers this does
1788 * not work (would produce endless host retries).
1789 * So we clear halt on CLEAR_FEATURE.
1790 *
1791 DBG(ep->dev, "ep %d: set STALL again\n", ep->num);
1792 tmp |= AMD_BIT(UDC_EPCTL_S);
1793 writel(tmp, &ep->regs->ctl);*/
1794
1795 /* clear NAK by writing CNAK */
1796 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1797 writel(tmp, &ep->regs->ctl);
1798 ep->halted = 0;
1799 UDC_QUEUE_CNAK(ep, ep->num);
1800 }
1801 }
1802}
1803
1804/* Stall timer callback to poll S bit and set it again after */
1805static void udc_pollstall_timer_function(unsigned long v)
1806{
1807 struct udc_ep *ep;
1808 int halted = 0;
1809
1810 spin_lock_irq(&udc_stall_spinlock);
1811 /*
1812 * only one IN and OUT endpoints are handled
1813 * IN poll stall
1814 */
1815 ep = &udc->ep[UDC_EPIN_IX];
1816 udc_handle_halt_state(ep);
1817 if (ep->halted)
1818 halted = 1;
1819 /* OUT poll stall */
1820 ep = &udc->ep[UDC_EPOUT_IX];
1821 udc_handle_halt_state(ep);
1822 if (ep->halted)
1823 halted = 1;
1824
1825 /* setup timer again when still halted */
1826 if (!stop_pollstall_timer && halted) {
1827 udc_pollstall_timer.expires = jiffies +
1828 HZ * UDC_POLLSTALL_TIMER_USECONDS
1829 / (1000 * 1000);
1830 add_timer(&udc_pollstall_timer);
1831 }
1832 spin_unlock_irq(&udc_stall_spinlock);
1833
1834 if (stop_pollstall_timer)
1835 complete(&on_pollstall_exit);
1836}
1837
1838/* Inits endpoint 0 so that SETUP packets are processed */
1839static void activate_control_endpoints(struct udc *dev)
1840{
1841 u32 tmp;
1842
1843 DBG(dev, "activate_control_endpoints\n");
1844
1845 /* flush fifo */
1846 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
1847 tmp |= AMD_BIT(UDC_EPCTL_F);
1848 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
1849
1850 /* set ep0 directions */
1851 dev->ep[UDC_EP0IN_IX].in = 1;
1852 dev->ep[UDC_EP0OUT_IX].in = 0;
1853
1854 /* set buffer size (tx fifo entries) of EP0_IN */
1855 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->bufin_framenum);
1856 if (dev->gadget.speed == USB_SPEED_FULL)
1857 tmp = AMD_ADDBITS(tmp, UDC_FS_EPIN0_BUFF_SIZE,
1858 UDC_EPIN_BUFF_SIZE);
1859 else if (dev->gadget.speed == USB_SPEED_HIGH)
1860 tmp = AMD_ADDBITS(tmp, UDC_EPIN0_BUFF_SIZE,
1861 UDC_EPIN_BUFF_SIZE);
1862 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->bufin_framenum);
1863
1864 /* set max packet size of EP0_IN */
1865 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->bufout_maxpkt);
1866 if (dev->gadget.speed == USB_SPEED_FULL)
1867 tmp = AMD_ADDBITS(tmp, UDC_FS_EP0IN_MAX_PKT_SIZE,
1868 UDC_EP_MAX_PKT_SIZE);
1869 else if (dev->gadget.speed == USB_SPEED_HIGH)
1870 tmp = AMD_ADDBITS(tmp, UDC_EP0IN_MAX_PKT_SIZE,
1871 UDC_EP_MAX_PKT_SIZE);
1872 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->bufout_maxpkt);
1873
1874 /* set max packet size of EP0_OUT */
1875 tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->bufout_maxpkt);
1876 if (dev->gadget.speed == USB_SPEED_FULL)
1877 tmp = AMD_ADDBITS(tmp, UDC_FS_EP0OUT_MAX_PKT_SIZE,
1878 UDC_EP_MAX_PKT_SIZE);
1879 else if (dev->gadget.speed == USB_SPEED_HIGH)
1880 tmp = AMD_ADDBITS(tmp, UDC_EP0OUT_MAX_PKT_SIZE,
1881 UDC_EP_MAX_PKT_SIZE);
1882 writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->bufout_maxpkt);
1883
1884 /* set max packet size of EP0 in UDC CSR */
1885 tmp = readl(&dev->csr->ne[0]);
1886 if (dev->gadget.speed == USB_SPEED_FULL)
1887 tmp = AMD_ADDBITS(tmp, UDC_FS_EP0OUT_MAX_PKT_SIZE,
1888 UDC_CSR_NE_MAX_PKT);
1889 else if (dev->gadget.speed == USB_SPEED_HIGH)
1890 tmp = AMD_ADDBITS(tmp, UDC_EP0OUT_MAX_PKT_SIZE,
1891 UDC_CSR_NE_MAX_PKT);
1892 writel(tmp, &dev->csr->ne[0]);
1893
1894 if (use_dma) {
1895 dev->ep[UDC_EP0OUT_IX].td->status |=
1896 AMD_BIT(UDC_DMA_OUT_STS_L);
1897 /* write dma desc address */
1898 writel(dev->ep[UDC_EP0OUT_IX].td_stp_dma,
1899 &dev->ep[UDC_EP0OUT_IX].regs->subptr);
1900 writel(dev->ep[UDC_EP0OUT_IX].td_phys,
1901 &dev->ep[UDC_EP0OUT_IX].regs->desptr);
1902 /* stop RDE timer */
1903 if (timer_pending(&udc_timer)) {
1904 set_rde = 0;
1905 mod_timer(&udc_timer, jiffies - 1);
1906 }
1907 /* stop pollstall timer */
1908 if (timer_pending(&udc_pollstall_timer)) {
1909 mod_timer(&udc_pollstall_timer, jiffies - 1);
1910 }
1911 /* enable DMA */
1912 tmp = readl(&dev->regs->ctl);
1913 tmp |= AMD_BIT(UDC_DEVCTL_MODE)
1914 | AMD_BIT(UDC_DEVCTL_RDE)
1915 | AMD_BIT(UDC_DEVCTL_TDE);
1916 if (use_dma_bufferfill_mode) {
1917 tmp |= AMD_BIT(UDC_DEVCTL_BF);
1918 } else if (use_dma_ppb_du) {
1919 tmp |= AMD_BIT(UDC_DEVCTL_DU);
1920 }
1921 writel(tmp, &dev->regs->ctl);
1922 }
1923
1924 /* clear NAK by writing CNAK for EP0IN */
1925 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
1926 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1927 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
1928 dev->ep[UDC_EP0IN_IX].naking = 0;
1929 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX], UDC_EP0IN_IX);
1930
1931 /* clear NAK by writing CNAK for EP0OUT */
1932 tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl);
1933 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
1934 writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->ctl);
1935 dev->ep[UDC_EP0OUT_IX].naking = 0;
1936 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX], UDC_EP0OUT_IX);
1937}
1938
1939/* Make endpoint 0 ready for control traffic */
1940static int setup_ep0(struct udc *dev)
1941{
1942 activate_control_endpoints(dev);
1943 /* enable ep0 interrupts */
1944 udc_enable_ep0_interrupts(dev);
1945 /* enable device setup interrupts */
1946 udc_enable_dev_setup_interrupts(dev);
1947
1948 return 0;
1949}
1950
1951/* Called by gadget driver to register itself */
1952int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1953{
1954 struct udc *dev = udc;
1955 int retval;
1956 u32 tmp;
1957
1958 if (!driver || !driver->bind || !driver->setup
1959 || driver->speed != USB_SPEED_HIGH)
1960 return -EINVAL;
1961 if (!dev)
1962 return -ENODEV;
1963 if (dev->driver)
1964 return -EBUSY;
1965
1966 driver->driver.bus = NULL;
1967 dev->driver = driver;
1968 dev->gadget.dev.driver = &driver->driver;
1969
1970 retval = driver->bind(&dev->gadget);
1971
1972 /* Some gadget drivers use both ep0 directions.
1973 * NOTE: to gadget driver, ep0 is just one endpoint...
1974 */
1975 dev->ep[UDC_EP0OUT_IX].ep.driver_data =
1976 dev->ep[UDC_EP0IN_IX].ep.driver_data;
1977
1978 if (retval) {
1979 DBG(dev, "binding to %s returning %d\n",
1980 driver->driver.name, retval);
1981 dev->driver = NULL;
1982 dev->gadget.dev.driver = NULL;
1983 return retval;
1984 }
1985
1986 /* get ready for ep0 traffic */
1987 setup_ep0(dev);
1988
1989 /* clear SD */
1990 tmp = readl(&dev->regs->ctl);
1991 tmp = tmp & AMD_CLEAR_BIT(UDC_DEVCTL_SD);
1992 writel(tmp, &dev->regs->ctl);
1993
1994 usb_connect(dev);
1995
1996 return 0;
1997}
1998EXPORT_SYMBOL(usb_gadget_register_driver);
1999
2000/* shutdown requests and disconnect from gadget */
2001static void
2002shutdown(struct udc *dev, struct usb_gadget_driver *driver)
2003__releases(dev->lock)
2004__acquires(dev->lock)
2005{
2006 int tmp;
2007
2008 /* empty queues and init hardware */
2009 udc_basic_init(dev);
2010 for (tmp = 0; tmp < UDC_EP_NUM; tmp++) {
2011 empty_req_queue(&dev->ep[tmp]);
2012 }
2013
2014 if (dev->gadget.speed != USB_SPEED_UNKNOWN) {
2015 spin_unlock(&dev->lock);
2016 driver->disconnect(&dev->gadget);
2017 spin_lock(&dev->lock);
2018 }
2019 /* init */
2020 udc_setup_endpoints(dev);
2021}
2022
2023/* Called by gadget driver to unregister itself */
2024int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
2025{
2026 struct udc *dev = udc;
2027 unsigned long flags;
2028 u32 tmp;
2029
2030 if (!dev)
2031 return -ENODEV;
2032 if (!driver || driver != dev->driver || !driver->unbind)
2033 return -EINVAL;
2034
2035 spin_lock_irqsave(&dev->lock, flags);
2036 udc_mask_unused_interrupts(dev);
2037 shutdown(dev, driver);
2038 spin_unlock_irqrestore(&dev->lock, flags);
2039
2040 driver->unbind(&dev->gadget);
2041 dev->driver = NULL;
2042
2043 /* set SD */
2044 tmp = readl(&dev->regs->ctl);
2045 tmp |= AMD_BIT(UDC_DEVCTL_SD);
2046 writel(tmp, &dev->regs->ctl);
2047
2048
2049 DBG(dev, "%s: unregistered\n", driver->driver.name);
2050
2051 return 0;
2052}
2053EXPORT_SYMBOL(usb_gadget_unregister_driver);
2054
2055
2056/* Clear pending NAK bits */
2057static void udc_process_cnak_queue(struct udc *dev)
2058{
2059 u32 tmp;
2060 u32 reg;
2061
2062 /* check epin's */
2063 DBG(dev, "CNAK pending queue processing\n");
2064 for (tmp = 0; tmp < UDC_EPIN_NUM_USED; tmp++) {
2065 if (cnak_pending & (1 << tmp)) {
2066 DBG(dev, "CNAK pending for ep%d\n", tmp);
2067 /* clear NAK by writing CNAK */
2068 reg = readl(&dev->ep[tmp].regs->ctl);
2069 reg |= AMD_BIT(UDC_EPCTL_CNAK);
2070 writel(reg, &dev->ep[tmp].regs->ctl);
2071 dev->ep[tmp].naking = 0;
2072 UDC_QUEUE_CNAK(&dev->ep[tmp], dev->ep[tmp].num);
2073 }
2074 }
2075 /* ... and ep0out */
2076 if (cnak_pending & (1 << UDC_EP0OUT_IX)) {
2077 DBG(dev, "CNAK pending for ep%d\n", UDC_EP0OUT_IX);
2078 /* clear NAK by writing CNAK */
2079 reg = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl);
2080 reg |= AMD_BIT(UDC_EPCTL_CNAK);
2081 writel(reg, &dev->ep[UDC_EP0OUT_IX].regs->ctl);
2082 dev->ep[UDC_EP0OUT_IX].naking = 0;
2083 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX],
2084 dev->ep[UDC_EP0OUT_IX].num);
2085 }
2086}
2087
2088/* Enabling RX DMA after setup packet */
2089static void udc_ep0_set_rde(struct udc *dev)
2090{
2091 if (use_dma) {
2092 /*
2093 * only enable RXDMA when no data endpoint enabled
2094 * or data is queued
2095 */
2096 if (!dev->data_ep_enabled || dev->data_ep_queued) {
2097 udc_set_rde(dev);
2098 } else {
2099 /*
2100 * setup timer for enabling RDE (to not enable
2101 * RXFIFO DMA for data endpoints to early)
2102 */
2103 if (set_rde != 0 && !timer_pending(&udc_timer)) {
2104 udc_timer.expires =
2105 jiffies + HZ/UDC_RDE_TIMER_DIV;
2106 set_rde = 1;
2107 if (!stop_timer) {
2108 add_timer(&udc_timer);
2109 }
2110 }
2111 }
2112 }
2113}
2114
2115
2116/* Interrupt handler for data OUT traffic */
2117static irqreturn_t udc_data_out_isr(struct udc *dev, int ep_ix)
2118{
2119 irqreturn_t ret_val = IRQ_NONE;
2120 u32 tmp;
2121 struct udc_ep *ep;
2122 struct udc_request *req;
2123 unsigned int count;
2124 struct udc_data_dma *td = NULL;
2125 unsigned dma_done;
2126
2127 VDBG(dev, "ep%d irq\n", ep_ix);
2128 ep = &dev->ep[ep_ix];
2129
2130 tmp = readl(&ep->regs->sts);
2131 if (use_dma) {
2132 /* BNA event ? */
2133 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) {
2134 DBG(dev, "BNA ep%dout occured - DESPTR = %x \n",
2135 ep->num, readl(&ep->regs->desptr));
2136 /* clear BNA */
2137 writel(tmp | AMD_BIT(UDC_EPSTS_BNA), &ep->regs->sts);
2138 if (!ep->cancel_transfer)
2139 ep->bna_occurred = 1;
2140 else
2141 ep->cancel_transfer = 0;
2142 ret_val = IRQ_HANDLED;
2143 goto finished;
2144 }
2145 }
2146 /* HE event ? */
2147 if (tmp & AMD_BIT(UDC_EPSTS_HE)) {
2148 dev_err(&dev->pdev->dev, "HE ep%dout occured\n", ep->num);
2149
2150 /* clear HE */
2151 writel(tmp | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts);
2152 ret_val = IRQ_HANDLED;
2153 goto finished;
2154 }
2155
2156 if (!list_empty(&ep->queue)) {
2157
2158 /* next request */
2159 req = list_entry(ep->queue.next,
2160 struct udc_request, queue);
2161 } else {
2162 req = NULL;
2163 udc_rxfifo_pending = 1;
2164 }
2165 VDBG(dev, "req = %p\n", req);
2166 /* fifo mode */
2167 if (!use_dma) {
2168
2169 /* read fifo */
2170 if (req && udc_rxfifo_read(ep, req)) {
2171 ret_val = IRQ_HANDLED;
2172
2173 /* finish */
2174 complete_req(ep, req, 0);
2175 /* next request */
2176 if (!list_empty(&ep->queue) && !ep->halted) {
2177 req = list_entry(ep->queue.next,
2178 struct udc_request, queue);
2179 } else
2180 req = NULL;
2181 }
2182
2183 /* DMA */
2184 } else if (!ep->cancel_transfer && req != NULL) {
2185 ret_val = IRQ_HANDLED;
2186
2187 /* check for DMA done */
2188 if (!use_dma_ppb) {
2189 dma_done = AMD_GETBITS(req->td_data->status,
2190 UDC_DMA_OUT_STS_BS);
2191 /* packet per buffer mode - rx bytes */
2192 } else {
2193 /*
2194 * if BNA occurred then recover desc. from
2195 * BNA dummy desc.
2196 */
2197 if (ep->bna_occurred) {
2198 VDBG(dev, "Recover desc. from BNA dummy\n");
2199 memcpy(req->td_data, ep->bna_dummy_req->td_data,
2200 sizeof(struct udc_data_dma));
2201 ep->bna_occurred = 0;
2202 udc_init_bna_dummy(ep->req);
2203 }
2204 td = udc_get_last_dma_desc(req);
2205 dma_done = AMD_GETBITS(td->status, UDC_DMA_OUT_STS_BS);
2206 }
2207 if (dma_done == UDC_DMA_OUT_STS_BS_DMA_DONE) {
2208 /* buffer fill mode - rx bytes */
2209 if (!use_dma_ppb) {
2210 /* received number bytes */
2211 count = AMD_GETBITS(req->td_data->status,
2212 UDC_DMA_OUT_STS_RXBYTES);
2213 VDBG(dev, "rx bytes=%u\n", count);
2214 /* packet per buffer mode - rx bytes */
2215 } else {
2216 VDBG(dev, "req->td_data=%p\n", req->td_data);
2217 VDBG(dev, "last desc = %p\n", td);
2218 /* received number bytes */
2219 if (use_dma_ppb_du) {
2220 /* every desc. counts bytes */
2221 count = udc_get_ppbdu_rxbytes(req);
2222 } else {
2223 /* last desc. counts bytes */
2224 count = AMD_GETBITS(td->status,
2225 UDC_DMA_OUT_STS_RXBYTES);
2226 if (!count && req->req.length
2227 == UDC_DMA_MAXPACKET) {
2228 /*
2229 * on 64k packets the RXBYTES
2230 * field is zero
2231 */
2232 count = UDC_DMA_MAXPACKET;
2233 }
2234 }
2235 VDBG(dev, "last desc rx bytes=%u\n", count);
2236 }
2237
2238 tmp = req->req.length - req->req.actual;
2239 if (count > tmp) {
2240 if ((tmp % ep->ep.maxpacket) != 0) {
2241 DBG(dev, "%s: rx %db, space=%db\n",
2242 ep->ep.name, count, tmp);
2243 req->req.status = -EOVERFLOW;
2244 }
2245 count = tmp;
2246 }
2247 req->req.actual += count;
2248 req->dma_going = 0;
2249 /* complete request */
2250 complete_req(ep, req, 0);
2251
2252 /* next request */
2253 if (!list_empty(&ep->queue) && !ep->halted) {
2254 req = list_entry(ep->queue.next,
2255 struct udc_request,
2256 queue);
2257 /*
2258 * DMA may be already started by udc_queue()
2259 * called by gadget drivers completion
2260 * routine. This happens when queue
2261 * holds one request only.
2262 */
2263 if (req->dma_going == 0) {
2264 /* next dma */
2265 if (prep_dma(ep, req, GFP_ATOMIC) != 0)
2266 goto finished;
2267 /* write desc pointer */
2268 writel(req->td_phys,
2269 &ep->regs->desptr);
2270 req->dma_going = 1;
2271 /* enable DMA */
2272 udc_set_rde(dev);
2273 }
2274 } else {
2275 /*
2276 * implant BNA dummy descriptor to allow
2277 * RXFIFO opening by RDE
2278 */
2279 if (ep->bna_dummy_req) {
2280 /* write desc pointer */
2281 writel(ep->bna_dummy_req->td_phys,
2282 &ep->regs->desptr);
2283 ep->bna_occurred = 0;
2284 }
2285
2286 /*
2287 * schedule timer for setting RDE if queue
2288 * remains empty to allow ep0 packets pass
2289 * through
2290 */
2291 if (set_rde != 0
2292 && !timer_pending(&udc_timer)) {
2293 udc_timer.expires =
2294 jiffies
2295 + HZ*UDC_RDE_TIMER_SECONDS;
2296 set_rde = 1;
2297 if (!stop_timer) {
2298 add_timer(&udc_timer);
2299 }
2300 }
2301 if (ep->num != UDC_EP0OUT_IX)
2302 dev->data_ep_queued = 0;
2303 }
2304
2305 } else {
2306 /*
2307 * RX DMA must be reenabled for each desc in PPBDU mode
2308 * and must be enabled for PPBNDU mode in case of BNA
2309 */
2310 udc_set_rde(dev);
2311 }
2312
2313 } else if (ep->cancel_transfer) {
2314 ret_val = IRQ_HANDLED;
2315 ep->cancel_transfer = 0;
2316 }
2317
2318 /* check pending CNAKS */
2319 if (cnak_pending) {
2320 /* CNAk processing when rxfifo empty only */
2321 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) {
2322 udc_process_cnak_queue(dev);
2323 }
2324 }
2325
2326 /* clear OUT bits in ep status */
2327 writel(UDC_EPSTS_OUT_CLEAR, &ep->regs->sts);
2328finished:
2329 return ret_val;
2330}
2331
2332/* Interrupt handler for data IN traffic */
2333static irqreturn_t udc_data_in_isr(struct udc *dev, int ep_ix)
2334{
2335 irqreturn_t ret_val = IRQ_NONE;
2336 u32 tmp;
2337 u32 epsts;
2338 struct udc_ep *ep;
2339 struct udc_request *req;
2340 struct udc_data_dma *td;
2341 unsigned dma_done;
2342 unsigned len;
2343
2344 ep = &dev->ep[ep_ix];
2345
2346 epsts = readl(&ep->regs->sts);
2347 if (use_dma) {
2348 /* BNA ? */
2349 if (epsts & AMD_BIT(UDC_EPSTS_BNA)) {
2350 dev_err(&dev->pdev->dev,
2351 "BNA ep%din occured - DESPTR = %08lx \n",
2352 ep->num,
2353 (unsigned long) readl(&ep->regs->desptr));
2354
2355 /* clear BNA */
2356 writel(epsts, &ep->regs->sts);
2357 ret_val = IRQ_HANDLED;
2358 goto finished;
2359 }
2360 }
2361 /* HE event ? */
2362 if (epsts & AMD_BIT(UDC_EPSTS_HE)) {
2363 dev_err(&dev->pdev->dev,
2364 "HE ep%dn occured - DESPTR = %08lx \n",
2365 ep->num, (unsigned long) readl(&ep->regs->desptr));
2366
2367 /* clear HE */
2368 writel(epsts | AMD_BIT(UDC_EPSTS_HE), &ep->regs->sts);
2369 ret_val = IRQ_HANDLED;
2370 goto finished;
2371 }
2372
2373 /* DMA completion */
2374 if (epsts & AMD_BIT(UDC_EPSTS_TDC)) {
2375 VDBG(dev, "TDC set- completion\n");
2376 ret_val = IRQ_HANDLED;
2377 if (!ep->cancel_transfer && !list_empty(&ep->queue)) {
2378 req = list_entry(ep->queue.next,
2379 struct udc_request, queue);
2380 if (req) {
2381 /*
2382 * length bytes transfered
2383 * check dma done of last desc. in PPBDU mode
2384 */
2385 if (use_dma_ppb_du) {
2386 td = udc_get_last_dma_desc(req);
2387 if (td) {
2388 dma_done =
2389 AMD_GETBITS(td->status,
2390 UDC_DMA_IN_STS_BS);
2391 /* don't care DMA done */
2392 req->req.actual =
2393 req->req.length;
2394 }
2395 } else {
2396 /* assume all bytes transferred */
2397 req->req.actual = req->req.length;
2398 }
2399
2400 if (req->req.actual == req->req.length) {
2401 /* complete req */
2402 complete_req(ep, req, 0);
2403 req->dma_going = 0;
2404 /* further request available ? */
2405 if (list_empty(&ep->queue)) {
2406 /* disable interrupt */
2407 tmp = readl(
2408 &dev->regs->ep_irqmsk);
2409 tmp |= AMD_BIT(ep->num);
2410 writel(tmp,
2411 &dev->regs->ep_irqmsk);
2412 }
2413
2414 }
2415 }
2416 }
2417 ep->cancel_transfer = 0;
2418
2419 }
2420 /*
2421 * status reg has IN bit set and TDC not set (if TDC was handled,
2422 * IN must not be handled (UDC defect) ?
2423 */
2424 if ((epsts & AMD_BIT(UDC_EPSTS_IN))
2425 && !(epsts & AMD_BIT(UDC_EPSTS_TDC))) {
2426 ret_val = IRQ_HANDLED;
2427 if (!list_empty(&ep->queue)) {
2428 /* next request */
2429 req = list_entry(ep->queue.next,
2430 struct udc_request, queue);
2431 /* FIFO mode */
2432 if (!use_dma) {
2433 /* write fifo */
2434 udc_txfifo_write(ep, &req->req);
2435 len = req->req.length - req->req.actual;
2436 if (len > ep->ep.maxpacket)
2437 len = ep->ep.maxpacket;
2438 req->req.actual += len;
2439 if (req->req.actual == req->req.length
2440 || (len != ep->ep.maxpacket)) {
2441 /* complete req */
2442 complete_req(ep, req, 0);
2443 }
2444 /* DMA */
2445 } else if (req && !req->dma_going) {
2446 VDBG(dev, "IN DMA : req=%p req->td_data=%p\n",
2447 req, req->td_data);
2448 if (req->td_data) {
2449
2450 req->dma_going = 1;
2451
2452 /*
2453 * unset L bit of first desc.
2454 * for chain
2455 */
2456 if (use_dma_ppb && req->req.length >
2457 ep->ep.maxpacket) {
2458 req->td_data->status &=
2459 AMD_CLEAR_BIT(
2460 UDC_DMA_IN_STS_L);
2461 }
2462
2463 /* write desc pointer */
2464 writel(req->td_phys, &ep->regs->desptr);
2465
2466 /* set HOST READY */
2467 req->td_data->status =
2468 AMD_ADDBITS(
2469 req->td_data->status,
2470 UDC_DMA_IN_STS_BS_HOST_READY,
2471 UDC_DMA_IN_STS_BS);
2472
2473 /* set poll demand bit */
2474 tmp = readl(&ep->regs->ctl);
2475 tmp |= AMD_BIT(UDC_EPCTL_P);
2476 writel(tmp, &ep->regs->ctl);
2477 }
2478 }
2479
2480 }
2481 }
2482 /* clear status bits */
2483 writel(epsts, &ep->regs->sts);
2484
2485finished:
2486 return ret_val;
2487
2488}
2489
2490/* Interrupt handler for Control OUT traffic */
2491static irqreturn_t udc_control_out_isr(struct udc *dev)
2492__releases(dev->lock)
2493__acquires(dev->lock)
2494{
2495 irqreturn_t ret_val = IRQ_NONE;
2496 u32 tmp;
2497 int setup_supported;
2498 u32 count;
2499 int set = 0;
2500 struct udc_ep *ep;
2501 struct udc_ep *ep_tmp;
2502
2503 ep = &dev->ep[UDC_EP0OUT_IX];
2504
2505 /* clear irq */
2506 writel(AMD_BIT(UDC_EPINT_OUT_EP0), &dev->regs->ep_irqsts);
2507
2508 tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->sts);
2509 /* check BNA and clear if set */
2510 if (tmp & AMD_BIT(UDC_EPSTS_BNA)) {
2511 VDBG(dev, "ep0: BNA set\n");
2512 writel(AMD_BIT(UDC_EPSTS_BNA),
2513 &dev->ep[UDC_EP0OUT_IX].regs->sts);
2514 ep->bna_occurred = 1;
2515 ret_val = IRQ_HANDLED;
2516 goto finished;
2517 }
2518
2519 /* type of data: SETUP or DATA 0 bytes */
2520 tmp = AMD_GETBITS(tmp, UDC_EPSTS_OUT);
2521 VDBG(dev, "data_typ = %x\n", tmp);
2522
2523 /* setup data */
2524 if (tmp == UDC_EPSTS_OUT_SETUP) {
2525 ret_val = IRQ_HANDLED;
2526
2527 ep->dev->stall_ep0in = 0;
2528 dev->waiting_zlp_ack_ep0in = 0;
2529
2530 /* set NAK for EP0_IN */
2531 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
2532 tmp |= AMD_BIT(UDC_EPCTL_SNAK);
2533 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
2534 dev->ep[UDC_EP0IN_IX].naking = 1;
2535 /* get setup data */
2536 if (use_dma) {
2537
2538 /* clear OUT bits in ep status */
2539 writel(UDC_EPSTS_OUT_CLEAR,
2540 &dev->ep[UDC_EP0OUT_IX].regs->sts);
2541
2542 setup_data.data[0] =
2543 dev->ep[UDC_EP0OUT_IX].td_stp->data12;
2544 setup_data.data[1] =
2545 dev->ep[UDC_EP0OUT_IX].td_stp->data34;
2546 /* set HOST READY */
2547 dev->ep[UDC_EP0OUT_IX].td_stp->status =
2548 UDC_DMA_STP_STS_BS_HOST_READY;
2549 } else {
2550 /* read fifo */
2551 udc_rxfifo_read_dwords(dev, setup_data.data, 2);
2552 }
2553
2554 /* determine direction of control data */
2555 if ((setup_data.request.bRequestType & USB_DIR_IN) != 0) {
2556 dev->gadget.ep0 = &dev->ep[UDC_EP0IN_IX].ep;
2557 /* enable RDE */
2558 udc_ep0_set_rde(dev);
2559 set = 0;
2560 } else {
2561 dev->gadget.ep0 = &dev->ep[UDC_EP0OUT_IX].ep;
2562 /*
2563 * implant BNA dummy descriptor to allow RXFIFO opening
2564 * by RDE
2565 */
2566 if (ep->bna_dummy_req) {
2567 /* write desc pointer */
2568 writel(ep->bna_dummy_req->td_phys,
2569 &dev->ep[UDC_EP0OUT_IX].regs->desptr);
2570 ep->bna_occurred = 0;
2571 }
2572
2573 set = 1;
2574 dev->ep[UDC_EP0OUT_IX].naking = 1;
2575 /*
2576 * setup timer for enabling RDE (to not enable
2577 * RXFIFO DMA for data to early)
2578 */
2579 set_rde = 1;
2580 if (!timer_pending(&udc_timer)) {
2581 udc_timer.expires = jiffies +
2582 HZ/UDC_RDE_TIMER_DIV;
2583 if (!stop_timer) {
2584 add_timer(&udc_timer);
2585 }
2586 }
2587 }
2588
2589 /*
2590 * mass storage reset must be processed here because
2591 * next packet may be a CLEAR_FEATURE HALT which would not
2592 * clear the stall bit when no STALL handshake was received
2593 * before (autostall can cause this)
2594 */
2595 if (setup_data.data[0] == UDC_MSCRES_DWORD0
2596 && setup_data.data[1] == UDC_MSCRES_DWORD1) {
2597 DBG(dev, "MSC Reset\n");
2598 /*
2599 * clear stall bits
2600 * only one IN and OUT endpoints are handled
2601 */
2602 ep_tmp = &udc->ep[UDC_EPIN_IX];
2603 udc_set_halt(&ep_tmp->ep, 0);
2604 ep_tmp = &udc->ep[UDC_EPOUT_IX];
2605 udc_set_halt(&ep_tmp->ep, 0);
2606 }
2607
2608 /* call gadget with setup data received */
2609 spin_unlock(&dev->lock);
2610 setup_supported = dev->driver->setup(&dev->gadget,
2611 &setup_data.request);
2612 spin_lock(&dev->lock);
2613
2614 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
2615 /* ep0 in returns data (not zlp) on IN phase */
2616 if (setup_supported >= 0 && setup_supported <
2617 UDC_EP0IN_MAXPACKET) {
2618 /* clear NAK by writing CNAK in EP0_IN */
2619 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
2620 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
2621 dev->ep[UDC_EP0IN_IX].naking = 0;
2622 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0IN_IX], UDC_EP0IN_IX);
2623
2624 /* if unsupported request then stall */
2625 } else if (setup_supported < 0) {
2626 tmp |= AMD_BIT(UDC_EPCTL_S);
2627 writel(tmp, &dev->ep[UDC_EP0IN_IX].regs->ctl);
2628 } else
2629 dev->waiting_zlp_ack_ep0in = 1;
2630
2631
2632 /* clear NAK by writing CNAK in EP0_OUT */
2633 if (!set) {
2634 tmp = readl(&dev->ep[UDC_EP0OUT_IX].regs->ctl);
2635 tmp |= AMD_BIT(UDC_EPCTL_CNAK);
2636 writel(tmp, &dev->ep[UDC_EP0OUT_IX].regs->ctl);
2637 dev->ep[UDC_EP0OUT_IX].naking = 0;
2638 UDC_QUEUE_CNAK(&dev->ep[UDC_EP0OUT_IX], UDC_EP0OUT_IX);
2639 }
2640
2641 if (!use_dma) {
2642 /* clear OUT bits in ep status */
2643 writel(UDC_EPSTS_OUT_CLEAR,
2644 &dev->ep[UDC_EP0OUT_IX].regs->sts);
2645 }
2646
2647 /* data packet 0 bytes */
2648 } else if (tmp == UDC_EPSTS_OUT_DATA) {
2649 /* clear OUT bits in ep status */
2650 writel(UDC_EPSTS_OUT_CLEAR, &dev->ep[UDC_EP0OUT_IX].regs->sts);
2651
2652 /* get setup data: only 0 packet */
2653 if (use_dma) {
2654 /* no req if 0 packet, just reactivate */
2655 if (list_empty(&dev->ep[UDC_EP0OUT_IX].queue)) {
2656 VDBG(dev, "ZLP\n");
2657
2658 /* set HOST READY */
2659 dev->ep[UDC_EP0OUT_IX].td->status =
2660 AMD_ADDBITS(
2661 dev->ep[UDC_EP0OUT_IX].td->status,
2662 UDC_DMA_OUT_STS_BS_HOST_READY,
2663 UDC_DMA_OUT_STS_BS);
2664 /* enable RDE */
2665 udc_ep0_set_rde(dev);
2666 ret_val = IRQ_HANDLED;
2667
2668 } else {
2669 /* control write */
2670 ret_val |= udc_data_out_isr(dev, UDC_EP0OUT_IX);
2671 /* re-program desc. pointer for possible ZLPs */
2672 writel(dev->ep[UDC_EP0OUT_IX].td_phys,
2673 &dev->ep[UDC_EP0OUT_IX].regs->desptr);
2674 /* enable RDE */
2675 udc_ep0_set_rde(dev);
2676 }
2677 } else {
2678
2679 /* received number bytes */
2680 count = readl(&dev->ep[UDC_EP0OUT_IX].regs->sts);
2681 count = AMD_GETBITS(count, UDC_EPSTS_RX_PKT_SIZE);
2682 /* out data for fifo mode not working */
2683 count = 0;
2684
2685 /* 0 packet or real data ? */
2686 if (count != 0) {
2687 ret_val |= udc_data_out_isr(dev, UDC_EP0OUT_IX);
2688 } else {
2689 /* dummy read confirm */
2690 readl(&dev->ep[UDC_EP0OUT_IX].regs->confirm);
2691 ret_val = IRQ_HANDLED;
2692 }
2693 }
2694 }
2695
2696 /* check pending CNAKS */
2697 if (cnak_pending) {
2698 /* CNAk processing when rxfifo empty only */
2699 if (readl(&dev->regs->sts) & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY)) {
2700 udc_process_cnak_queue(dev);
2701 }
2702 }
2703
2704finished:
2705 return ret_val;
2706}
2707
2708/* Interrupt handler for Control IN traffic */
2709static irqreturn_t udc_control_in_isr(struct udc *dev)
2710{
2711 irqreturn_t ret_val = IRQ_NONE;
2712 u32 tmp;
2713 struct udc_ep *ep;
2714 struct udc_request *req;
2715 unsigned len;
2716
2717 ep = &dev->ep[UDC_EP0IN_IX];
2718
2719 /* clear irq */
2720 writel(AMD_BIT(UDC_EPINT_IN_EP0), &dev->regs->ep_irqsts);
2721
2722 tmp = readl(&dev->ep[UDC_EP0IN_IX].regs->sts);
2723 /* DMA completion */
2724 if (tmp & AMD_BIT(UDC_EPSTS_TDC)) {
2725 VDBG(dev, "isr: TDC clear \n");
2726 ret_val = IRQ_HANDLED;
2727
2728 /* clear TDC bit */
2729 writel(AMD_BIT(UDC_EPSTS_TDC),
2730 &dev->ep[UDC_EP0IN_IX].regs->sts);
2731
2732 /* status reg has IN bit set ? */
2733 } else if (tmp & AMD_BIT(UDC_EPSTS_IN)) {
2734 ret_val = IRQ_HANDLED;
2735
2736 if (ep->dma) {
2737 /* clear IN bit */
2738 writel(AMD_BIT(UDC_EPSTS_IN),
2739 &dev->ep[UDC_EP0IN_IX].regs->sts);
2740 }
2741 if (dev->stall_ep0in) {
2742 DBG(dev, "stall ep0in\n");
2743 /* halt ep0in */
2744 tmp = readl(&ep->regs->ctl);
2745 tmp |= AMD_BIT(UDC_EPCTL_S);
2746 writel(tmp, &ep->regs->ctl);
2747 } else {
2748 if (!list_empty(&ep->queue)) {
2749 /* next request */
2750 req = list_entry(ep->queue.next,
2751 struct udc_request, queue);
2752
2753 if (ep->dma) {
2754 /* write desc pointer */
2755 writel(req->td_phys, &ep->regs->desptr);
2756 /* set HOST READY */
2757 req->td_data->status =
2758 AMD_ADDBITS(
2759 req->td_data->status,
2760 UDC_DMA_STP_STS_BS_HOST_READY,
2761 UDC_DMA_STP_STS_BS);
2762
2763 /* set poll demand bit */
2764 tmp =
2765 readl(&dev->ep[UDC_EP0IN_IX].regs->ctl);
2766 tmp |= AMD_BIT(UDC_EPCTL_P);
2767 writel(tmp,
2768 &dev->ep[UDC_EP0IN_IX].regs->ctl);
2769
2770 /* all bytes will be transferred */
2771 req->req.actual = req->req.length;
2772
2773 /* complete req */
2774 complete_req(ep, req, 0);
2775
2776 } else {
2777 /* write fifo */
2778 udc_txfifo_write(ep, &req->req);
2779
2780 /* lengh bytes transfered */
2781 len = req->req.length - req->req.actual;
2782 if (len > ep->ep.maxpacket)
2783 len = ep->ep.maxpacket;
2784
2785 req->req.actual += len;
2786 if (req->req.actual == req->req.length
2787 || (len != ep->ep.maxpacket)) {
2788 /* complete req */
2789 complete_req(ep, req, 0);
2790 }
2791 }
2792
2793 }
2794 }
2795 ep->halted = 0;
2796 dev->stall_ep0in = 0;
2797 if (!ep->dma) {
2798 /* clear IN bit */
2799 writel(AMD_BIT(UDC_EPSTS_IN),
2800 &dev->ep[UDC_EP0IN_IX].regs->sts);
2801 }
2802 }
2803
2804 return ret_val;
2805}
2806
2807
2808/* Interrupt handler for global device events */
2809static irqreturn_t udc_dev_isr(struct udc *dev, u32 dev_irq)
2810__releases(dev->lock)
2811__acquires(dev->lock)
2812{
2813 irqreturn_t ret_val = IRQ_NONE;
2814 u32 tmp;
2815 u32 cfg;
2816 struct udc_ep *ep;
2817 u16 i;
2818 u8 udc_csr_epix;
2819
2820 /* SET_CONFIG irq ? */
2821 if (dev_irq & AMD_BIT(UDC_DEVINT_SC)) {
2822 ret_val = IRQ_HANDLED;
2823
2824 /* read config value */
2825 tmp = readl(&dev->regs->sts);
2826 cfg = AMD_GETBITS(tmp, UDC_DEVSTS_CFG);
2827 DBG(dev, "SET_CONFIG interrupt: config=%d\n", cfg);
2828 dev->cur_config = cfg;
2829 dev->set_cfg_not_acked = 1;
2830
2831 /* make usb request for gadget driver */
2832 memset(&setup_data, 0 , sizeof(union udc_setup_data));
2833 setup_data.request.bRequest = USB_REQ_SET_CONFIGURATION;
2834 setup_data.request.wValue = dev->cur_config;
2835
2836 /* programm the NE registers */
2837 for (i = 0; i < UDC_EP_NUM; i++) {
2838 ep = &dev->ep[i];
2839 if (ep->in) {
2840
2841 /* ep ix in UDC CSR register space */
2842 udc_csr_epix = ep->num;
2843
2844
2845 /* OUT ep */
2846 } else {
2847 /* ep ix in UDC CSR register space */
2848 udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS;
2849 }
2850
2851 tmp = readl(&dev->csr->ne[udc_csr_epix]);
2852 /* ep cfg */
2853 tmp = AMD_ADDBITS(tmp, ep->dev->cur_config,
2854 UDC_CSR_NE_CFG);
2855 /* write reg */
2856 writel(tmp, &dev->csr->ne[udc_csr_epix]);
2857
2858 /* clear stall bits */
2859 ep->halted = 0;
2860 tmp = readl(&ep->regs->ctl);
2861 tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S);
2862 writel(tmp, &ep->regs->ctl);
2863 }
2864 /* call gadget zero with setup data received */
2865 spin_unlock(&dev->lock);
2866 tmp = dev->driver->setup(&dev->gadget, &setup_data.request);
2867 spin_lock(&dev->lock);
2868
2869 } /* SET_INTERFACE ? */
2870 if (dev_irq & AMD_BIT(UDC_DEVINT_SI)) {
2871 ret_val = IRQ_HANDLED;
2872
2873 dev->set_cfg_not_acked = 1;
2874 /* read interface and alt setting values */
2875 tmp = readl(&dev->regs->sts);
2876 dev->cur_alt = AMD_GETBITS(tmp, UDC_DEVSTS_ALT);
2877 dev->cur_intf = AMD_GETBITS(tmp, UDC_DEVSTS_INTF);
2878
2879 /* make usb request for gadget driver */
2880 memset(&setup_data, 0 , sizeof(union udc_setup_data));
2881 setup_data.request.bRequest = USB_REQ_SET_INTERFACE;
2882 setup_data.request.bRequestType = USB_RECIP_INTERFACE;
2883 setup_data.request.wValue = dev->cur_alt;
2884 setup_data.request.wIndex = dev->cur_intf;
2885
2886 DBG(dev, "SET_INTERFACE interrupt: alt=%d intf=%d\n",
2887 dev->cur_alt, dev->cur_intf);
2888
2889 /* programm the NE registers */
2890 for (i = 0; i < UDC_EP_NUM; i++) {
2891 ep = &dev->ep[i];
2892 if (ep->in) {
2893
2894 /* ep ix in UDC CSR register space */
2895 udc_csr_epix = ep->num;
2896
2897
2898 /* OUT ep */
2899 } else {
2900 /* ep ix in UDC CSR register space */
2901 udc_csr_epix = ep->num - UDC_CSR_EP_OUT_IX_OFS;
2902 }
2903
2904 /* UDC CSR reg */
2905 /* set ep values */
2906 tmp = readl(&dev->csr->ne[udc_csr_epix]);
2907 /* ep interface */
2908 tmp = AMD_ADDBITS(tmp, ep->dev->cur_intf,
2909 UDC_CSR_NE_INTF);
2910 /* tmp = AMD_ADDBITS(tmp, 2, UDC_CSR_NE_INTF); */
2911 /* ep alt */
2912 tmp = AMD_ADDBITS(tmp, ep->dev->cur_alt,
2913 UDC_CSR_NE_ALT);
2914 /* write reg */
2915 writel(tmp, &dev->csr->ne[udc_csr_epix]);
2916
2917 /* clear stall bits */
2918 ep->halted = 0;
2919 tmp = readl(&ep->regs->ctl);
2920 tmp = tmp & AMD_CLEAR_BIT(UDC_EPCTL_S);
2921 writel(tmp, &ep->regs->ctl);
2922 }
2923
2924 /* call gadget zero with setup data received */
2925 spin_unlock(&dev->lock);
2926 tmp = dev->driver->setup(&dev->gadget, &setup_data.request);
2927 spin_lock(&dev->lock);
2928
2929 } /* USB reset */
2930 if (dev_irq & AMD_BIT(UDC_DEVINT_UR)) {
2931 DBG(dev, "USB Reset interrupt\n");
2932 ret_val = IRQ_HANDLED;
2933
2934 /* allow soft reset when suspend occurs */
2935 soft_reset_occured = 0;
2936
2937 dev->waiting_zlp_ack_ep0in = 0;
2938 dev->set_cfg_not_acked = 0;
2939
2940 /* mask not needed interrupts */
2941 udc_mask_unused_interrupts(dev);
2942
2943 /* call gadget to resume and reset configs etc. */
2944 spin_unlock(&dev->lock);
2945 if (dev->sys_suspended && dev->driver->resume) {
2946 dev->driver->resume(&dev->gadget);
2947 dev->sys_suspended = 0;
2948 }
2949 dev->driver->disconnect(&dev->gadget);
2950 spin_lock(&dev->lock);
2951
2952 /* disable ep0 to empty req queue */
2953 empty_req_queue(&dev->ep[UDC_EP0IN_IX]);
2954 ep_init(dev->regs, &dev->ep[UDC_EP0IN_IX]);
2955
2956 /* soft reset when rxfifo not empty */
2957 tmp = readl(&dev->regs->sts);
2958 if (!(tmp & AMD_BIT(UDC_DEVSTS_RXFIFO_EMPTY))
2959 && !soft_reset_after_usbreset_occured) {
2960 udc_soft_reset(dev);
2961 soft_reset_after_usbreset_occured++;
2962 }
2963
2964 /*
2965 * DMA reset to kill potential old DMA hw hang,
2966 * POLL bit is already reset by ep_init() through
2967 * disconnect()
2968 */
2969 DBG(dev, "DMA machine reset\n");
2970 tmp = readl(&dev->regs->cfg);
2971 writel(tmp | AMD_BIT(UDC_DEVCFG_DMARST), &dev->regs->cfg);
2972 writel(tmp, &dev->regs->cfg);
2973
2974 /* put into initial config */
2975 udc_basic_init(dev);
2976
2977 /* enable device setup interrupts */
2978 udc_enable_dev_setup_interrupts(dev);
2979
2980 /* enable suspend interrupt */
2981 tmp = readl(&dev->regs->irqmsk);
2982 tmp &= AMD_UNMASK_BIT(UDC_DEVINT_US);
2983 writel(tmp, &dev->regs->irqmsk);
2984
2985 } /* USB suspend */
2986 if (dev_irq & AMD_BIT(UDC_DEVINT_US)) {
2987 DBG(dev, "USB Suspend interrupt\n");
2988 ret_val = IRQ_HANDLED;
2989 if (dev->driver->suspend) {
2990 spin_unlock(&dev->lock);
2991 dev->sys_suspended = 1;
2992 dev->driver->suspend(&dev->gadget);
2993 spin_lock(&dev->lock);
2994 }
2995 } /* new speed ? */
2996 if (dev_irq & AMD_BIT(UDC_DEVINT_ENUM)) {
2997 DBG(dev, "ENUM interrupt\n");
2998 ret_val = IRQ_HANDLED;
2999 soft_reset_after_usbreset_occured = 0;
3000
3001 /* disable ep0 to empty req queue */
3002 empty_req_queue(&dev->ep[UDC_EP0IN_IX]);
3003 ep_init(dev->regs, &dev->ep[UDC_EP0IN_IX]);
3004
3005 /* link up all endpoints */
3006 udc_setup_endpoints(dev);
3007 if (dev->gadget.speed == USB_SPEED_HIGH) {
3008 dev_info(&dev->pdev->dev, "Connect: speed = %s\n",
3009 "high");
3010 } else if (dev->gadget.speed == USB_SPEED_FULL) {
3011 dev_info(&dev->pdev->dev, "Connect: speed = %s\n",
3012 "full");
3013 }
3014
3015 /* init ep 0 */
3016 activate_control_endpoints(dev);
3017
3018 /* enable ep0 interrupts */
3019 udc_enable_ep0_interrupts(dev);
3020 }
3021 /* session valid change interrupt */
3022 if (dev_irq & AMD_BIT(UDC_DEVINT_SVC)) {
3023 DBG(dev, "USB SVC interrupt\n");
3024 ret_val = IRQ_HANDLED;
3025
3026 /* check that session is not valid to detect disconnect */
3027 tmp = readl(&dev->regs->sts);
3028 if (!(tmp & AMD_BIT(UDC_DEVSTS_SESSVLD))) {
3029 /* disable suspend interrupt */
3030 tmp = readl(&dev->regs->irqmsk);
3031 tmp |= AMD_BIT(UDC_DEVINT_US);
3032 writel(tmp, &dev->regs->irqmsk);
3033 DBG(dev, "USB Disconnect (session valid low)\n");
3034 /* cleanup on disconnect */
3035 usb_disconnect(udc);
3036 }
3037
3038 }
3039
3040 return ret_val;
3041}
3042
3043/* Interrupt Service Routine, see Linux Kernel Doc for parameters */
3044static irqreturn_t udc_irq(int irq, void *pdev)
3045{
3046 struct udc *dev = pdev;
3047 u32 reg;
3048 u16 i;
3049 u32 ep_irq;
3050 irqreturn_t ret_val = IRQ_NONE;
3051
3052 spin_lock(&dev->lock);
3053
3054 /* check for ep irq */
3055 reg = readl(&dev->regs->ep_irqsts);
3056 if (reg) {
3057 if (reg & AMD_BIT(UDC_EPINT_OUT_EP0))
3058 ret_val |= udc_control_out_isr(dev);
3059 if (reg & AMD_BIT(UDC_EPINT_IN_EP0))
3060 ret_val |= udc_control_in_isr(dev);
3061
3062 /*
3063 * data endpoint
3064 * iterate ep's
3065 */
3066 for (i = 1; i < UDC_EP_NUM; i++) {
3067 ep_irq = 1 << i;
3068 if (!(reg & ep_irq) || i == UDC_EPINT_OUT_EP0)
3069 continue;
3070
3071 /* clear irq status */
3072 writel(ep_irq, &dev->regs->ep_irqsts);
3073
3074 /* irq for out ep ? */
3075 if (i > UDC_EPIN_NUM)
3076 ret_val |= udc_data_out_isr(dev, i);
3077 else
3078 ret_val |= udc_data_in_isr(dev, i);
3079 }
3080
3081 }
3082
3083
3084 /* check for dev irq */
3085 reg = readl(&dev->regs->irqsts);
3086 if (reg) {
3087 /* clear irq */
3088 writel(reg, &dev->regs->irqsts);
3089 ret_val |= udc_dev_isr(dev, reg);
3090 }
3091
3092
3093 spin_unlock(&dev->lock);
3094 return ret_val;
3095}
3096
3097/* Tears down device */
3098static void gadget_release(struct device *pdev)
3099{
3100 struct amd5536udc *dev = dev_get_drvdata(pdev);
3101 kfree(dev);
3102}
3103
3104/* Cleanup on device remove */
3105static void udc_remove(struct udc *dev)
3106{
3107 /* remove timer */
3108 stop_timer++;
3109 if (timer_pending(&udc_timer))
3110 wait_for_completion(&on_exit);
3111 if (udc_timer.data)
3112 del_timer_sync(&udc_timer);
3113 /* remove pollstall timer */
3114 stop_pollstall_timer++;
3115 if (timer_pending(&udc_pollstall_timer))
3116 wait_for_completion(&on_pollstall_exit);
3117 if (udc_pollstall_timer.data)
3118 del_timer_sync(&udc_pollstall_timer);
3119 udc = NULL;
3120}
3121
3122/* Reset all pci context */
3123static void udc_pci_remove(struct pci_dev *pdev)
3124{
3125 struct udc *dev;
3126
3127 dev = pci_get_drvdata(pdev);
3128
3129 /* gadget driver must not be registered */
3130 BUG_ON(dev->driver != NULL);
3131
3132 /* dma pool cleanup */
3133 if (dev->data_requests)
3134 pci_pool_destroy(dev->data_requests);
3135
3136 if (dev->stp_requests) {
3137 /* cleanup DMA desc's for ep0in */
3138 pci_pool_free(dev->stp_requests,
3139 dev->ep[UDC_EP0OUT_IX].td_stp,
3140 dev->ep[UDC_EP0OUT_IX].td_stp_dma);
3141 pci_pool_free(dev->stp_requests,
3142 dev->ep[UDC_EP0OUT_IX].td,
3143 dev->ep[UDC_EP0OUT_IX].td_phys);
3144
3145 pci_pool_destroy(dev->stp_requests);
3146 }
3147
3148 /* reset controller */
3149 writel(AMD_BIT(UDC_DEVCFG_SOFTRESET), &dev->regs->cfg);
3150 if (dev->irq_registered)
3151 free_irq(pdev->irq, dev);
3152 if (dev->regs)
3153 iounmap(dev->regs);
3154 if (dev->mem_region)
3155 release_mem_region(pci_resource_start(pdev, 0),
3156 pci_resource_len(pdev, 0));
3157 if (dev->active)
3158 pci_disable_device(pdev);
3159
3160 device_unregister(&dev->gadget.dev);
3161 pci_set_drvdata(pdev, NULL);
3162
3163 udc_remove(dev);
3164}
3165
3166/* create dma pools on init */
3167static int init_dma_pools(struct udc *dev)
3168{
3169 struct udc_stp_dma *td_stp;
3170 struct udc_data_dma *td_data;
3171 int retval;
3172
3173 /* consistent DMA mode setting ? */
3174 if (use_dma_ppb) {
3175 use_dma_bufferfill_mode = 0;
3176 } else {
3177 use_dma_ppb_du = 0;
3178 use_dma_bufferfill_mode = 1;
3179 }
3180
3181 /* DMA setup */
3182 dev->data_requests = dma_pool_create("data_requests", NULL,
3183 sizeof(struct udc_data_dma), 0, 0);
3184 if (!dev->data_requests) {
3185 DBG(dev, "can't get request data pool\n");
3186 retval = -ENOMEM;
3187 goto finished;
3188 }
3189
3190 /* EP0 in dma regs = dev control regs */
3191 dev->ep[UDC_EP0IN_IX].dma = &dev->regs->ctl;
3192
3193 /* dma desc for setup data */
3194 dev->stp_requests = dma_pool_create("setup requests", NULL,
3195 sizeof(struct udc_stp_dma), 0, 0);
3196 if (!dev->stp_requests) {
3197 DBG(dev, "can't get stp request pool\n");
3198 retval = -ENOMEM;
3199 goto finished;
3200 }
3201 /* setup */
3202 td_stp = dma_pool_alloc(dev->stp_requests, GFP_KERNEL,
3203 &dev->ep[UDC_EP0OUT_IX].td_stp_dma);
3204 if (td_stp == NULL) {
3205 retval = -ENOMEM;
3206 goto finished;
3207 }
3208 dev->ep[UDC_EP0OUT_IX].td_stp = td_stp;
3209
3210 /* data: 0 packets !? */
3211 td_data = dma_pool_alloc(dev->stp_requests, GFP_KERNEL,
3212 &dev->ep[UDC_EP0OUT_IX].td_phys);
3213 if (td_data == NULL) {
3214 retval = -ENOMEM;
3215 goto finished;
3216 }
3217 dev->ep[UDC_EP0OUT_IX].td = td_data;
3218 return 0;
3219
3220finished:
3221 return retval;
3222}
3223
3224/* Called by pci bus driver to init pci context */
3225static int udc_pci_probe(
3226 struct pci_dev *pdev,
3227 const struct pci_device_id *id
3228)
3229{
3230 struct udc *dev;
3231 unsigned long resource;
3232 unsigned long len;
3233 int retval = 0;
3234
3235 /* one udc only */
3236 if (udc) {
3237 dev_dbg(&pdev->dev, "already probed\n");
3238 return -EBUSY;
3239 }
3240
3241 /* init */
3242 dev = kzalloc(sizeof(struct udc), GFP_KERNEL);
3243 if (!dev) {
3244 retval = -ENOMEM;
3245 goto finished;
3246 }
3247 memset(dev, 0, sizeof(struct udc));
3248
3249 /* pci setup */
3250 if (pci_enable_device(pdev) < 0) {
3251 retval = -ENODEV;
3252 goto finished;
3253 }
3254 dev->active = 1;
3255
3256 /* PCI resource allocation */
3257 resource = pci_resource_start(pdev, 0);
3258 len = pci_resource_len(pdev, 0);
3259
3260 if (!request_mem_region(resource, len, name)) {
3261 dev_dbg(&pdev->dev, "pci device used already\n");
3262 retval = -EBUSY;
3263 goto finished;
3264 }
3265 dev->mem_region = 1;
3266
3267 dev->virt_addr = ioremap_nocache(resource, len);
3268 if (dev->virt_addr == NULL) {
3269 dev_dbg(&pdev->dev, "start address cannot be mapped\n");
3270 retval = -EFAULT;
3271 goto finished;
3272 }
3273
3274 if (!pdev->irq) {
3275 dev_err(&dev->pdev->dev, "irq not set\n");
3276 retval = -ENODEV;
3277 goto finished;
3278 }
3279
3280 if (request_irq(pdev->irq, udc_irq, IRQF_SHARED, name, dev) != 0) {
3281 dev_dbg(&dev->pdev->dev, "request_irq(%d) fail\n", pdev->irq);
3282 retval = -EBUSY;
3283 goto finished;
3284 }
3285 dev->irq_registered = 1;
3286
3287 pci_set_drvdata(pdev, dev);
3288
3289 /* chip revision */
3290 dev->chiprev = 0;
3291
3292 pci_set_master(pdev);
3293 pci_set_mwi(pdev);
3294
3295 /* chip rev for Hs AMD5536 */
3296 pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) &dev->chiprev);
3297 /* init dma pools */
3298 if (use_dma) {
3299 retval = init_dma_pools(dev);
3300 if (retval != 0)
3301 goto finished;
3302 }
3303
3304 dev->phys_addr = resource;
3305 dev->irq = pdev->irq;
3306 dev->pdev = pdev;
3307 dev->gadget.dev.parent = &pdev->dev;
3308 dev->gadget.dev.dma_mask = pdev->dev.dma_mask;
3309
3310 /* general probing */
3311 if (udc_probe(dev) == 0)
3312 return 0;
3313
3314finished:
3315 if (dev)
3316 udc_pci_remove(pdev);
3317 return retval;
3318}
3319
3320/* general probe */
3321static int udc_probe(struct udc *dev)
3322{
3323 char tmp[128];
3324 u32 reg;
3325 int retval;
3326
3327 /* mark timer as not initialized */
3328 udc_timer.data = 0;
3329 udc_pollstall_timer.data = 0;
3330
3331 /* device struct setup */
3332 spin_lock_init(&dev->lock);
3333 dev->gadget.ops = &udc_ops;
3334
3335 strcpy(dev->gadget.dev.bus_id, "gadget");
3336 dev->gadget.dev.release = gadget_release;
3337 dev->gadget.name = name;
3338 dev->gadget.name = name;
3339 dev->gadget.is_dualspeed = 1;
3340
3341 /* udc csr registers base */
3342 dev->csr = dev->virt_addr + UDC_CSR_ADDR;
3343 /* dev registers base */
3344 dev->regs = dev->virt_addr + UDC_DEVCFG_ADDR;
3345 /* ep registers base */
3346 dev->ep_regs = dev->virt_addr + UDC_EPREGS_ADDR;
3347 /* fifo's base */
3348 dev->rxfifo = (u32 __iomem *)(dev->virt_addr + UDC_RXFIFO_ADDR);
3349 dev->txfifo = (u32 __iomem *)(dev->virt_addr + UDC_TXFIFO_ADDR);
3350
3351 /* init registers, interrupts, ... */
3352 startup_registers(dev);
3353
3354 dev_info(&dev->pdev->dev, "%s\n", mod_desc);
3355
3356 snprintf(tmp, sizeof tmp, "%d", dev->irq);
3357 dev_info(&dev->pdev->dev,
3358 "irq %s, pci mem %08lx, chip rev %02x(Geode5536 %s)\n",
3359 tmp, dev->phys_addr, dev->chiprev,
3360 (dev->chiprev == UDC_HSA0_REV) ? "A0" : "B1");
3361 strcpy(tmp, UDC_DRIVER_VERSION_STRING);
3362 if (dev->chiprev == UDC_HSA0_REV) {
3363 dev_err(&dev->pdev->dev, "chip revision is A0; too old\n");
3364 retval = -ENODEV;
3365 goto finished;
3366 }
3367 dev_info(&dev->pdev->dev,
3368 "driver version: %s(for Geode5536 B1)\n", tmp);
3369 udc = dev;
3370
3371 retval = device_register(&dev->gadget.dev);
3372 if (retval)
3373 goto finished;
3374
3375 /* timer init */
3376 init_timer(&udc_timer);
3377 udc_timer.function = udc_timer_function;
3378 udc_timer.data = 1;
3379 /* timer pollstall init */
3380 init_timer(&udc_pollstall_timer);
3381 udc_pollstall_timer.function = udc_pollstall_timer_function;
3382 udc_pollstall_timer.data = 1;
3383
3384 /* set SD */
3385 reg = readl(&dev->regs->ctl);
3386 reg |= AMD_BIT(UDC_DEVCTL_SD);
3387 writel(reg, &dev->regs->ctl);
3388
3389 /* print dev register info */
3390 print_regs(dev);
3391
3392 return 0;
3393
3394finished:
3395 return retval;
3396}
3397
3398/* Initiates a remote wakeup */
3399static int udc_remote_wakeup(struct udc *dev)
3400{
3401 unsigned long flags;
3402 u32 tmp;
3403
3404 DBG(dev, "UDC initiates remote wakeup\n");
3405
3406 spin_lock_irqsave(&dev->lock, flags);
3407
3408 tmp = readl(&dev->regs->ctl);
3409 tmp |= AMD_BIT(UDC_DEVCTL_RES);
3410 writel(tmp, &dev->regs->ctl);
3411 tmp &= AMD_CLEAR_BIT(UDC_DEVCTL_RES);
3412 writel(tmp, &dev->regs->ctl);
3413
3414 spin_unlock_irqrestore(&dev->lock, flags);
3415 return 0;
3416}
3417
3418/* PCI device parameters */
3419static const struct pci_device_id pci_id[] = {
3420 {
3421 PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x2096),
3422 .class = (PCI_CLASS_SERIAL_USB << 8) | 0xfe,
3423 .class_mask = 0xffffffff,
3424 },
3425 {},
3426};
3427MODULE_DEVICE_TABLE(pci, pci_id);
3428
3429/* PCI functions */
3430static struct pci_driver udc_pci_driver = {
3431 .name = (char *) name,
3432 .id_table = pci_id,
3433 .probe = udc_pci_probe,
3434 .remove = udc_pci_remove,
3435};
3436
3437/* Inits driver */
3438static int __init init(void)
3439{
3440 return pci_register_driver(&udc_pci_driver);
3441}
3442module_init(init);
3443
3444/* Cleans driver */
3445static void __exit cleanup(void)
3446{
3447 pci_unregister_driver(&udc_pci_driver);
3448}
3449module_exit(cleanup);
3450
3451MODULE_DESCRIPTION(UDC_MOD_DESCRIPTION);
3452MODULE_AUTHOR("Thomas Dahlmann");
3453MODULE_LICENSE("GPL");
3454
diff --git a/drivers/usb/gadget/amd5536udc.h b/drivers/usb/gadget/amd5536udc.h
new file mode 100644
index 000000000000..4bbabbbfc93f
--- /dev/null
+++ b/drivers/usb/gadget/amd5536udc.h
@@ -0,0 +1,626 @@
1/*
2 * amd5536.h -- header for AMD 5536 UDC high/full speed USB device controller
3 *
4 * Copyright (C) 2007 AMD (http://www.amd.com)
5 * Author: Thomas Dahlmann
6 *
7 * 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 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef AMD5536UDC_H
23#define AMD5536UDC_H
24
25/* various constants */
26#define UDC_RDE_TIMER_SECONDS 1
27#define UDC_RDE_TIMER_DIV 10
28#define UDC_POLLSTALL_TIMER_USECONDS 500
29
30/* Hs AMD5536 chip rev. */
31#define UDC_HSA0_REV 1
32#define UDC_HSB1_REV 2
33
34/*
35 * SETUP usb commands
36 * needed, because some SETUP's are handled in hw, but must be passed to
37 * gadget driver above
38 * SET_CONFIG
39 */
40#define UDC_SETCONFIG_DWORD0 0x00000900
41#define UDC_SETCONFIG_DWORD0_VALUE_MASK 0xffff0000
42#define UDC_SETCONFIG_DWORD0_VALUE_OFS 16
43
44#define UDC_SETCONFIG_DWORD1 0x00000000
45
46/* SET_INTERFACE */
47#define UDC_SETINTF_DWORD0 0x00000b00
48#define UDC_SETINTF_DWORD0_ALT_MASK 0xffff0000
49#define UDC_SETINTF_DWORD0_ALT_OFS 16
50
51#define UDC_SETINTF_DWORD1 0x00000000
52#define UDC_SETINTF_DWORD1_INTF_MASK 0x0000ffff
53#define UDC_SETINTF_DWORD1_INTF_OFS 0
54
55/* Mass storage reset */
56#define UDC_MSCRES_DWORD0 0x0000ff21
57#define UDC_MSCRES_DWORD1 0x00000000
58
59/* Global CSR's -------------------------------------------------------------*/
60#define UDC_CSR_ADDR 0x500
61
62/* EP NE bits */
63/* EP number */
64#define UDC_CSR_NE_NUM_MASK 0x0000000f
65#define UDC_CSR_NE_NUM_OFS 0
66/* EP direction */
67#define UDC_CSR_NE_DIR_MASK 0x00000010
68#define UDC_CSR_NE_DIR_OFS 4
69/* EP type */
70#define UDC_CSR_NE_TYPE_MASK 0x00000060
71#define UDC_CSR_NE_TYPE_OFS 5
72/* EP config number */
73#define UDC_CSR_NE_CFG_MASK 0x00000780
74#define UDC_CSR_NE_CFG_OFS 7
75/* EP interface number */
76#define UDC_CSR_NE_INTF_MASK 0x00007800
77#define UDC_CSR_NE_INTF_OFS 11
78/* EP alt setting */
79#define UDC_CSR_NE_ALT_MASK 0x00078000
80#define UDC_CSR_NE_ALT_OFS 15
81
82/* max pkt */
83#define UDC_CSR_NE_MAX_PKT_MASK 0x3ff80000
84#define UDC_CSR_NE_MAX_PKT_OFS 19
85
86/* Device Config Register ---------------------------------------------------*/
87#define UDC_DEVCFG_ADDR 0x400
88
89#define UDC_DEVCFG_SOFTRESET 31
90#define UDC_DEVCFG_HNPSFEN 30
91#define UDC_DEVCFG_DMARST 29
92#define UDC_DEVCFG_SET_DESC 18
93#define UDC_DEVCFG_CSR_PRG 17
94#define UDC_DEVCFG_STATUS 7
95#define UDC_DEVCFG_DIR 6
96#define UDC_DEVCFG_PI 5
97#define UDC_DEVCFG_SS 4
98#define UDC_DEVCFG_SP 3
99#define UDC_DEVCFG_RWKP 2
100
101#define UDC_DEVCFG_SPD_MASK 0x3
102#define UDC_DEVCFG_SPD_OFS 0
103#define UDC_DEVCFG_SPD_HS 0x0
104#define UDC_DEVCFG_SPD_FS 0x1
105#define UDC_DEVCFG_SPD_LS 0x2
106/*#define UDC_DEVCFG_SPD_FS 0x3*/
107
108
109/* Device Control Register --------------------------------------------------*/
110#define UDC_DEVCTL_ADDR 0x404
111
112#define UDC_DEVCTL_THLEN_MASK 0xff000000
113#define UDC_DEVCTL_THLEN_OFS 24
114
115#define UDC_DEVCTL_BRLEN_MASK 0x00ff0000
116#define UDC_DEVCTL_BRLEN_OFS 16
117
118#define UDC_DEVCTL_CSR_DONE 13
119#define UDC_DEVCTL_DEVNAK 12
120#define UDC_DEVCTL_SD 10
121#define UDC_DEVCTL_MODE 9
122#define UDC_DEVCTL_BREN 8
123#define UDC_DEVCTL_THE 7
124#define UDC_DEVCTL_BF 6
125#define UDC_DEVCTL_BE 5
126#define UDC_DEVCTL_DU 4
127#define UDC_DEVCTL_TDE 3
128#define UDC_DEVCTL_RDE 2
129#define UDC_DEVCTL_RES 0
130
131
132/* Device Status Register ---------------------------------------------------*/
133#define UDC_DEVSTS_ADDR 0x408
134
135#define UDC_DEVSTS_TS_MASK 0xfffc0000
136#define UDC_DEVSTS_TS_OFS 18
137
138#define UDC_DEVSTS_SESSVLD 17
139#define UDC_DEVSTS_PHY_ERROR 16
140#define UDC_DEVSTS_RXFIFO_EMPTY 15
141
142#define UDC_DEVSTS_ENUM_SPEED_MASK 0x00006000
143#define UDC_DEVSTS_ENUM_SPEED_OFS 13
144#define UDC_DEVSTS_ENUM_SPEED_FULL 1
145#define UDC_DEVSTS_ENUM_SPEED_HIGH 0
146
147#define UDC_DEVSTS_SUSP 12
148
149#define UDC_DEVSTS_ALT_MASK 0x00000f00
150#define UDC_DEVSTS_ALT_OFS 8
151
152#define UDC_DEVSTS_INTF_MASK 0x000000f0
153#define UDC_DEVSTS_INTF_OFS 4
154
155#define UDC_DEVSTS_CFG_MASK 0x0000000f
156#define UDC_DEVSTS_CFG_OFS 0
157
158
159/* Device Interrupt Register ------------------------------------------------*/
160#define UDC_DEVINT_ADDR 0x40c
161
162#define UDC_DEVINT_SVC 7
163#define UDC_DEVINT_ENUM 6
164#define UDC_DEVINT_SOF 5
165#define UDC_DEVINT_US 4
166#define UDC_DEVINT_UR 3
167#define UDC_DEVINT_ES 2
168#define UDC_DEVINT_SI 1
169#define UDC_DEVINT_SC 0
170
171/* Device Interrupt Mask Register -------------------------------------------*/
172#define UDC_DEVINT_MSK_ADDR 0x410
173
174#define UDC_DEVINT_MSK 0x7f
175
176/* Endpoint Interrupt Register ----------------------------------------------*/
177#define UDC_EPINT_ADDR 0x414
178
179#define UDC_EPINT_OUT_MASK 0xffff0000
180#define UDC_EPINT_OUT_OFS 16
181#define UDC_EPINT_IN_MASK 0x0000ffff
182#define UDC_EPINT_IN_OFS 0
183
184#define UDC_EPINT_IN_EP0 0
185#define UDC_EPINT_IN_EP1 1
186#define UDC_EPINT_IN_EP2 2
187#define UDC_EPINT_IN_EP3 3
188#define UDC_EPINT_OUT_EP0 16
189#define UDC_EPINT_OUT_EP1 17
190#define UDC_EPINT_OUT_EP2 18
191#define UDC_EPINT_OUT_EP3 19
192
193#define UDC_EPINT_EP0_ENABLE_MSK 0x001e001e
194
195/* Endpoint Interrupt Mask Register -----------------------------------------*/
196#define UDC_EPINT_MSK_ADDR 0x418
197
198#define UDC_EPINT_OUT_MSK_MASK 0xffff0000
199#define UDC_EPINT_OUT_MSK_OFS 16
200#define UDC_EPINT_IN_MSK_MASK 0x0000ffff
201#define UDC_EPINT_IN_MSK_OFS 0
202
203#define UDC_EPINT_MSK_DISABLE_ALL 0xffffffff
204/* mask non-EP0 endpoints */
205#define UDC_EPDATAINT_MSK_DISABLE 0xfffefffe
206/* mask all dev interrupts */
207#define UDC_DEV_MSK_DISABLE 0x7f
208
209/* Endpoint-specific CSR's --------------------------------------------------*/
210#define UDC_EPREGS_ADDR 0x0
211#define UDC_EPIN_REGS_ADDR 0x0
212#define UDC_EPOUT_REGS_ADDR 0x200
213
214#define UDC_EPCTL_ADDR 0x0
215
216#define UDC_EPCTL_RRDY 9
217#define UDC_EPCTL_CNAK 8
218#define UDC_EPCTL_SNAK 7
219#define UDC_EPCTL_NAK 6
220
221#define UDC_EPCTL_ET_MASK 0x00000030
222#define UDC_EPCTL_ET_OFS 4
223#define UDC_EPCTL_ET_CONTROL 0
224#define UDC_EPCTL_ET_ISO 1
225#define UDC_EPCTL_ET_BULK 2
226#define UDC_EPCTL_ET_INTERRUPT 3
227
228#define UDC_EPCTL_P 3
229#define UDC_EPCTL_SN 2
230#define UDC_EPCTL_F 1
231#define UDC_EPCTL_S 0
232
233/* Endpoint Status Registers ------------------------------------------------*/
234#define UDC_EPSTS_ADDR 0x4
235
236#define UDC_EPSTS_RX_PKT_SIZE_MASK 0x007ff800
237#define UDC_EPSTS_RX_PKT_SIZE_OFS 11
238
239#define UDC_EPSTS_TDC 10
240#define UDC_EPSTS_HE 9
241#define UDC_EPSTS_BNA 7
242#define UDC_EPSTS_IN 6
243
244#define UDC_EPSTS_OUT_MASK 0x00000030
245#define UDC_EPSTS_OUT_OFS 4
246#define UDC_EPSTS_OUT_DATA 1
247#define UDC_EPSTS_OUT_DATA_CLEAR 0x10
248#define UDC_EPSTS_OUT_SETUP 2
249#define UDC_EPSTS_OUT_SETUP_CLEAR 0x20
250#define UDC_EPSTS_OUT_CLEAR 0x30
251
252/* Endpoint Buffer Size IN/ Receive Packet Frame Number OUT Registers ------*/
253#define UDC_EPIN_BUFF_SIZE_ADDR 0x8
254#define UDC_EPOUT_FRAME_NUMBER_ADDR 0x8
255
256#define UDC_EPIN_BUFF_SIZE_MASK 0x0000ffff
257#define UDC_EPIN_BUFF_SIZE_OFS 0
258/* EP0in txfifo = 128 bytes*/
259#define UDC_EPIN0_BUFF_SIZE 32
260/* EP0in fullspeed txfifo = 128 bytes*/
261#define UDC_FS_EPIN0_BUFF_SIZE 32
262
263/* fifo size mult = fifo size / max packet */
264#define UDC_EPIN_BUFF_SIZE_MULT 2
265
266/* EPin data fifo size = 1024 bytes DOUBLE BUFFERING */
267#define UDC_EPIN_BUFF_SIZE 256
268/* EPin small INT data fifo size = 128 bytes */
269#define UDC_EPIN_SMALLINT_BUFF_SIZE 32
270
271/* EPin fullspeed data fifo size = 128 bytes DOUBLE BUFFERING */
272#define UDC_FS_EPIN_BUFF_SIZE 32
273
274#define UDC_EPOUT_FRAME_NUMBER_MASK 0x0000ffff
275#define UDC_EPOUT_FRAME_NUMBER_OFS 0
276
277/* Endpoint Buffer Size OUT/Max Packet Size Registers -----------------------*/
278#define UDC_EPOUT_BUFF_SIZE_ADDR 0x0c
279#define UDC_EP_MAX_PKT_SIZE_ADDR 0x0c
280
281#define UDC_EPOUT_BUFF_SIZE_MASK 0xffff0000
282#define UDC_EPOUT_BUFF_SIZE_OFS 16
283#define UDC_EP_MAX_PKT_SIZE_MASK 0x0000ffff
284#define UDC_EP_MAX_PKT_SIZE_OFS 0
285/* EP0in max packet size = 64 bytes */
286#define UDC_EP0IN_MAX_PKT_SIZE 64
287/* EP0out max packet size = 64 bytes */
288#define UDC_EP0OUT_MAX_PKT_SIZE 64
289/* EP0in fullspeed max packet size = 64 bytes */
290#define UDC_FS_EP0IN_MAX_PKT_SIZE 64
291/* EP0out fullspeed max packet size = 64 bytes */
292#define UDC_FS_EP0OUT_MAX_PKT_SIZE 64
293
294/*
295 * Endpoint dma descriptors ------------------------------------------------
296 *
297 * Setup data, Status dword
298 */
299#define UDC_DMA_STP_STS_CFG_MASK 0x0fff0000
300#define UDC_DMA_STP_STS_CFG_OFS 16
301#define UDC_DMA_STP_STS_CFG_ALT_MASK 0x000f0000
302#define UDC_DMA_STP_STS_CFG_ALT_OFS 16
303#define UDC_DMA_STP_STS_CFG_INTF_MASK 0x00f00000
304#define UDC_DMA_STP_STS_CFG_INTF_OFS 20
305#define UDC_DMA_STP_STS_CFG_NUM_MASK 0x0f000000
306#define UDC_DMA_STP_STS_CFG_NUM_OFS 24
307#define UDC_DMA_STP_STS_RX_MASK 0x30000000
308#define UDC_DMA_STP_STS_RX_OFS 28
309#define UDC_DMA_STP_STS_BS_MASK 0xc0000000
310#define UDC_DMA_STP_STS_BS_OFS 30
311#define UDC_DMA_STP_STS_BS_HOST_READY 0
312#define UDC_DMA_STP_STS_BS_DMA_BUSY 1
313#define UDC_DMA_STP_STS_BS_DMA_DONE 2
314#define UDC_DMA_STP_STS_BS_HOST_BUSY 3
315/* IN data, Status dword */
316#define UDC_DMA_IN_STS_TXBYTES_MASK 0x0000ffff
317#define UDC_DMA_IN_STS_TXBYTES_OFS 0
318#define UDC_DMA_IN_STS_FRAMENUM_MASK 0x07ff0000
319#define UDC_DMA_IN_STS_FRAMENUM_OFS 0
320#define UDC_DMA_IN_STS_L 27
321#define UDC_DMA_IN_STS_TX_MASK 0x30000000
322#define UDC_DMA_IN_STS_TX_OFS 28
323#define UDC_DMA_IN_STS_BS_MASK 0xc0000000
324#define UDC_DMA_IN_STS_BS_OFS 30
325#define UDC_DMA_IN_STS_BS_HOST_READY 0
326#define UDC_DMA_IN_STS_BS_DMA_BUSY 1
327#define UDC_DMA_IN_STS_BS_DMA_DONE 2
328#define UDC_DMA_IN_STS_BS_HOST_BUSY 3
329/* OUT data, Status dword */
330#define UDC_DMA_OUT_STS_RXBYTES_MASK 0x0000ffff
331#define UDC_DMA_OUT_STS_RXBYTES_OFS 0
332#define UDC_DMA_OUT_STS_FRAMENUM_MASK 0x07ff0000
333#define UDC_DMA_OUT_STS_FRAMENUM_OFS 0
334#define UDC_DMA_OUT_STS_L 27
335#define UDC_DMA_OUT_STS_RX_MASK 0x30000000
336#define UDC_DMA_OUT_STS_RX_OFS 28
337#define UDC_DMA_OUT_STS_BS_MASK 0xc0000000
338#define UDC_DMA_OUT_STS_BS_OFS 30
339#define UDC_DMA_OUT_STS_BS_HOST_READY 0
340#define UDC_DMA_OUT_STS_BS_DMA_BUSY 1
341#define UDC_DMA_OUT_STS_BS_DMA_DONE 2
342#define UDC_DMA_OUT_STS_BS_HOST_BUSY 3
343/* max ep0in packet */
344#define UDC_EP0IN_MAXPACKET 1000
345/* max dma packet */
346#define UDC_DMA_MAXPACKET 65536
347
348/* un-usable DMA address */
349#define DMA_DONT_USE (~(dma_addr_t) 0 )
350
351/* other Endpoint register addresses and values-----------------------------*/
352#define UDC_EP_SUBPTR_ADDR 0x10
353#define UDC_EP_DESPTR_ADDR 0x14
354#define UDC_EP_WRITE_CONFIRM_ADDR 0x1c
355
356/* EP number as layouted in AHB space */
357#define UDC_EP_NUM 32
358#define UDC_EPIN_NUM 16
359#define UDC_EPIN_NUM_USED 5
360#define UDC_EPOUT_NUM 16
361/* EP number of EP's really used = EP0 + 8 data EP's */
362#define UDC_USED_EP_NUM 9
363/* UDC CSR regs are aligned but AHB regs not - offset for OUT EP's */
364#define UDC_CSR_EP_OUT_IX_OFS 12
365
366#define UDC_EP0OUT_IX 16
367#define UDC_EP0IN_IX 0
368
369/* Rx fifo address and size = 1k -------------------------------------------*/
370#define UDC_RXFIFO_ADDR 0x800
371#define UDC_RXFIFO_SIZE 0x400
372
373/* Tx fifo address and size = 1.5k -----------------------------------------*/
374#define UDC_TXFIFO_ADDR 0xc00
375#define UDC_TXFIFO_SIZE 0x600
376
377/* default data endpoints --------------------------------------------------*/
378#define UDC_EPIN_STATUS_IX 1
379#define UDC_EPIN_IX 2
380#define UDC_EPOUT_IX 18
381
382/* general constants -------------------------------------------------------*/
383#define UDC_DWORD_BYTES 4
384#define UDC_BITS_PER_BYTE_SHIFT 3
385#define UDC_BYTE_MASK 0xff
386#define UDC_BITS_PER_BYTE 8
387
388/*---------------------------------------------------------------------------*/
389/* UDC CSR's */
390struct udc_csrs {
391
392 /* sca - setup command address */
393 u32 sca;
394
395 /* ep ne's */
396 u32 ne[UDC_USED_EP_NUM];
397} __attribute__ ((packed));
398
399/* AHB subsystem CSR registers */
400struct udc_regs {
401
402 /* device configuration */
403 u32 cfg;
404
405 /* device control */
406 u32 ctl;
407
408 /* device status */
409 u32 sts;
410
411 /* device interrupt */
412 u32 irqsts;
413
414 /* device interrupt mask */
415 u32 irqmsk;
416
417 /* endpoint interrupt */
418 u32 ep_irqsts;
419
420 /* endpoint interrupt mask */
421 u32 ep_irqmsk;
422} __attribute__ ((packed));
423
424/* endpoint specific registers */
425struct udc_ep_regs {
426
427 /* endpoint control */
428 u32 ctl;
429
430 /* endpoint status */
431 u32 sts;
432
433 /* endpoint buffer size in/ receive packet frame number out */
434 u32 bufin_framenum;
435
436 /* endpoint buffer size out/max packet size */
437 u32 bufout_maxpkt;
438
439 /* endpoint setup buffer pointer */
440 u32 subptr;
441
442 /* endpoint data descriptor pointer */
443 u32 desptr;
444
445 /* reserverd */
446 u32 reserved;
447
448 /* write/read confirmation */
449 u32 confirm;
450
451} __attribute__ ((packed));
452
453/* control data DMA desc */
454struct udc_stp_dma {
455 /* status quadlet */
456 u32 status;
457 /* reserved */
458 u32 _reserved;
459 /* first setup word */
460 u32 data12;
461 /* second setup word */
462 u32 data34;
463} __attribute__ ((aligned (16)));
464
465/* normal data DMA desc */
466struct udc_data_dma {
467 /* status quadlet */
468 u32 status;
469 /* reserved */
470 u32 _reserved;
471 /* buffer pointer */
472 u32 bufptr;
473 /* next descriptor pointer */
474 u32 next;
475} __attribute__ ((aligned (16)));
476
477/* request packet */
478struct udc_request {
479 /* embedded gadget ep */
480 struct usb_request req;
481
482 /* flags */
483 unsigned dma_going : 1,
484 dma_mapping : 1,
485 dma_done : 1;
486 /* phys. address */
487 dma_addr_t td_phys;
488 /* first dma desc. of chain */
489 struct udc_data_dma *td_data;
490 /* last dma desc. of chain */
491 struct udc_data_dma *td_data_last;
492 struct list_head queue;
493
494 /* chain length */
495 unsigned chain_len;
496
497};
498
499/* UDC specific endpoint parameters */
500struct udc_ep {
501 struct usb_ep ep;
502 struct udc_ep_regs __iomem *regs;
503 u32 __iomem *txfifo;
504 u32 __iomem *dma;
505 dma_addr_t td_phys;
506 dma_addr_t td_stp_dma;
507 struct udc_stp_dma *td_stp;
508 struct udc_data_dma *td;
509 /* temp request */
510 struct udc_request *req;
511 unsigned req_used;
512 unsigned req_completed;
513 /* dummy DMA desc for BNA dummy */
514 struct udc_request *bna_dummy_req;
515 unsigned bna_occurred;
516
517 /* NAK state */
518 unsigned naking;
519
520 struct udc *dev;
521
522 /* queue for requests */
523 struct list_head queue;
524 const struct usb_endpoint_descriptor *desc;
525 unsigned halted;
526 unsigned cancel_transfer;
527 unsigned num : 5,
528 fifo_depth : 14,
529 in : 1;
530};
531
532/* device struct */
533struct udc {
534 struct usb_gadget gadget;
535 spinlock_t lock; /* protects all state */
536 /* all endpoints */
537 struct udc_ep ep[UDC_EP_NUM];
538 struct usb_gadget_driver *driver;
539 /* operational flags */
540 unsigned active : 1,
541 stall_ep0in : 1,
542 waiting_zlp_ack_ep0in : 1,
543 set_cfg_not_acked : 1,
544 irq_registered : 1,
545 data_ep_enabled : 1,
546 data_ep_queued : 1,
547 mem_region : 1,
548 sys_suspended : 1,
549 connected;
550
551 u16 chiprev;
552
553 /* registers */
554 struct pci_dev *pdev;
555 struct udc_csrs __iomem *csr;
556 struct udc_regs __iomem *regs;
557 struct udc_ep_regs __iomem *ep_regs;
558 u32 __iomem *rxfifo;
559 u32 __iomem *txfifo;
560
561 /* DMA desc pools */
562 struct pci_pool *data_requests;
563 struct pci_pool *stp_requests;
564
565 /* device data */
566 unsigned long phys_addr;
567 void __iomem *virt_addr;
568 unsigned irq;
569
570 /* states */
571 u16 cur_config;
572 u16 cur_intf;
573 u16 cur_alt;
574};
575
576/* setup request data */
577union udc_setup_data {
578 u32 data[2];
579 struct usb_ctrlrequest request;
580};
581
582/*
583 *---------------------------------------------------------------------------
584 * SET and GET bitfields in u32 values
585 * via constants for mask/offset:
586 * <bit_field_stub_name> is the text between
587 * UDC_ and _MASK|_OFS of appropiate
588 * constant
589 *
590 * set bitfield value in u32 u32Val
591 */
592#define AMD_ADDBITS(u32Val, bitfield_val, bitfield_stub_name) \
593 (((u32Val) & (((u32) ~((u32) bitfield_stub_name##_MASK)))) \
594 | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \
595 & ((u32) bitfield_stub_name##_MASK)))
596
597/*
598 * set bitfield value in zero-initialized u32 u32Val
599 * => bitfield bits in u32Val are all zero
600 */
601#define AMD_INIT_SETBITS(u32Val, bitfield_val, bitfield_stub_name) \
602 ((u32Val) \
603 | (((bitfield_val) << ((u32) bitfield_stub_name##_OFS)) \
604 & ((u32) bitfield_stub_name##_MASK)))
605
606/* get bitfield value from u32 u32Val */
607#define AMD_GETBITS(u32Val, bitfield_stub_name) \
608 ((u32Val & ((u32) bitfield_stub_name##_MASK)) \
609 >> ((u32) bitfield_stub_name##_OFS))
610
611/* SET and GET bits in u32 values ------------------------------------------*/
612#define AMD_BIT(bit_stub_name) (1 << bit_stub_name)
613#define AMD_UNMASK_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name))
614#define AMD_CLEAR_BIT(bit_stub_name) (~AMD_BIT(bit_stub_name))
615
616/* debug macros ------------------------------------------------------------*/
617
618#define DBG(udc , args...) dev_dbg(&(udc)->pdev->dev, args)
619
620#ifdef UDC_VERBOSE
621#define VDBG DBG
622#else
623#define VDBG(udc , args...) do {} while (0)
624#endif
625
626#endif /* #ifdef AMD5536UDC_H */
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index dbaf867436df..a3376739a81b 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -305,6 +305,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
305#define DEV_CONFIG_CDC 305#define DEV_CONFIG_CDC
306#endif 306#endif
307 307
308#ifdef CONFIG_USB_GADGET_AMD5536UDC
309#define DEV_CONFIG_CDC
310#endif
311
308 312
309/*-------------------------------------------------------------------------*/ 313/*-------------------------------------------------------------------------*/
310 314
diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h
index 53e9139ba388..f7f159c1002b 100644
--- a/drivers/usb/gadget/gadget_chips.h
+++ b/drivers/usb/gadget/gadget_chips.h
@@ -17,6 +17,12 @@
17#define gadget_is_net2280(g) 0 17#define gadget_is_net2280(g) 0
18#endif 18#endif
19 19
20#ifdef CONFIG_USB_GADGET_AMD5536UDC
21#define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name)
22#else
23#define gadget_is_amd5536udc(g) 0
24#endif
25
20#ifdef CONFIG_USB_GADGET_DUMMY_HCD 26#ifdef CONFIG_USB_GADGET_DUMMY_HCD
21#define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name) 27#define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name)
22#else 28#else
@@ -202,7 +208,9 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)
202 return 0x18; 208 return 0x18;
203 else if (gadget_is_fsl_usb2(gadget)) 209 else if (gadget_is_fsl_usb2(gadget))
204 return 0x19; 210 return 0x19;
205 else if (gadget_is_m66592(gadget)) 211 else if (gadget_is_amd5536udc(gadget))
206 return 0x20; 212 return 0x20;
213 else if (gadget_is_m66592(gadget))
214 return 0x21;
207 return -ENOENT; 215 return -ENOENT;
208} 216}
diff --git a/drivers/usb/gadget/m66592-udc.c b/drivers/usb/gadget/m66592-udc.c
index 0174a322e007..700dda8a9157 100644
--- a/drivers/usb/gadget/m66592-udc.c
+++ b/drivers/usb/gadget/m66592-udc.c
@@ -21,26 +21,18 @@
21 */ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/sched.h>
26#include <linux/smp_lock.h>
27#include <linux/errno.h>
28#include <linux/init.h>
29#include <linux/timer.h>
30#include <linux/delay.h>
31#include <linux/list.h>
32#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/delay.h>
26#include <linux/io.h>
33#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28
34#include <linux/usb/ch9.h> 29#include <linux/usb/ch9.h>
35#include <linux/usb_gadget.h> 30#include <linux/usb_gadget.h>
36 31
37#include <asm/io.h>
38#include <asm/irq.h>
39#include <asm/system.h>
40
41#include "m66592-udc.h" 32#include "m66592-udc.h"
42 33
43MODULE_DESCRIPTION("M66592 USB gadget driiver"); 34
35MODULE_DESCRIPTION("M66592 USB gadget driver");
44MODULE_LICENSE("GPL"); 36MODULE_LICENSE("GPL");
45MODULE_AUTHOR("Yoshihiro Shimoda"); 37MODULE_AUTHOR("Yoshihiro Shimoda");
46 38
@@ -49,16 +41,21 @@ MODULE_AUTHOR("Yoshihiro Shimoda");
49/* module parameters */ 41/* module parameters */
50static unsigned short clock = M66592_XTAL24; 42static unsigned short clock = M66592_XTAL24;
51module_param(clock, ushort, 0644); 43module_param(clock, ushort, 0644);
52MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=16384)"); 44MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
45 "(default=16384)");
46
53static unsigned short vif = M66592_LDRV; 47static unsigned short vif = M66592_LDRV;
54module_param(vif, ushort, 0644); 48module_param(vif, ushort, 0644);
55MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); 49MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0 (default=32768)");
56static unsigned short endian = 0; 50
51static unsigned short endian;
57module_param(endian, ushort, 0644); 52module_param(endian, ushort, 0644);
58MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); 53MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
54
59static unsigned short irq_sense = M66592_INTL; 55static unsigned short irq_sense = M66592_INTL;
60module_param(irq_sense, ushort, 0644); 56module_param(irq_sense, ushort, 0644);
61MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0(default=2)"); 57MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=2, falling edge=0 "
58 "(default=2)");
62 59
63static const char udc_name[] = "m66592_udc"; 60static const char udc_name[] = "m66592_udc";
64static const char *m66592_ep_name[] = { 61static const char *m66592_ep_name[] = {
@@ -72,8 +69,8 @@ static int m66592_queue(struct usb_ep *_ep, struct usb_request *_req,
72 gfp_t gfp_flags); 69 gfp_t gfp_flags);
73 70
74static void transfer_complete(struct m66592_ep *ep, 71static void transfer_complete(struct m66592_ep *ep,
75 struct m66592_request *req, 72 struct m66592_request *req, int status);
76 int status); 73
77/*-------------------------------------------------------------------------*/ 74/*-------------------------------------------------------------------------*/
78static inline u16 get_usb_speed(struct m66592 *m66592) 75static inline u16 get_usb_speed(struct m66592 *m66592)
79{ 76{
@@ -81,25 +78,25 @@ static inline u16 get_usb_speed(struct m66592 *m66592)
81} 78}
82 79
83static void enable_pipe_irq(struct m66592 *m66592, u16 pipenum, 80static void enable_pipe_irq(struct m66592 *m66592, u16 pipenum,
84 unsigned long reg) 81 unsigned long reg)
85{ 82{
86 u16 tmp; 83 u16 tmp;
87 84
88 tmp = m66592_read(m66592, M66592_INTENB0); 85 tmp = m66592_read(m66592, M66592_INTENB0);
89 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, 86 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE,
90 M66592_INTENB0); 87 M66592_INTENB0);
91 m66592_bset(m66592, (1 << pipenum), reg); 88 m66592_bset(m66592, (1 << pipenum), reg);
92 m66592_write(m66592, tmp, M66592_INTENB0); 89 m66592_write(m66592, tmp, M66592_INTENB0);
93} 90}
94 91
95static void disable_pipe_irq(struct m66592 *m66592, u16 pipenum, 92static void disable_pipe_irq(struct m66592 *m66592, u16 pipenum,
96 unsigned long reg) 93 unsigned long reg)
97{ 94{
98 u16 tmp; 95 u16 tmp;
99 96
100 tmp = m66592_read(m66592, M66592_INTENB0); 97 tmp = m66592_read(m66592, M66592_INTENB0);
101 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE, 98 m66592_bclr(m66592, M66592_BEMPE | M66592_NRDYE | M66592_BRDYE,
102 M66592_INTENB0); 99 M66592_INTENB0);
103 m66592_bclr(m66592, (1 << pipenum), reg); 100 m66592_bclr(m66592, (1 << pipenum), reg);
104 m66592_write(m66592, tmp, M66592_INTENB0); 101 m66592_write(m66592, tmp, M66592_INTENB0);
105} 102}
@@ -108,17 +105,19 @@ static void m66592_usb_connect(struct m66592 *m66592)
108{ 105{
109 m66592_bset(m66592, M66592_CTRE, M66592_INTENB0); 106 m66592_bset(m66592, M66592_CTRE, M66592_INTENB0);
110 m66592_bset(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, 107 m66592_bset(m66592, M66592_WDST | M66592_RDST | M66592_CMPL,
111 M66592_INTENB0); 108 M66592_INTENB0);
112 m66592_bset(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); 109 m66592_bset(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0);
113 110
114 m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG); 111 m66592_bset(m66592, M66592_DPRPU, M66592_SYSCFG);
115} 112}
116 113
117static void m66592_usb_disconnect(struct m66592 *m66592) 114static void m66592_usb_disconnect(struct m66592 *m66592)
115__releases(m66592->lock)
116__acquires(m66592->lock)
118{ 117{
119 m66592_bclr(m66592, M66592_CTRE, M66592_INTENB0); 118 m66592_bclr(m66592, M66592_CTRE, M66592_INTENB0);
120 m66592_bclr(m66592, M66592_WDST | M66592_RDST | M66592_CMPL, 119 m66592_bclr(m66592, M66592_WDST | M66592_RDST | M66592_CMPL,
121 M66592_INTENB0); 120 M66592_INTENB0);
122 m66592_bclr(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0); 121 m66592_bclr(m66592, M66592_BEMPE | M66592_BRDYE, M66592_INTENB0);
123 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG); 122 m66592_bclr(m66592, M66592_DPRPU, M66592_SYSCFG);
124 123
@@ -148,7 +147,7 @@ static inline u16 control_reg_get_pid(struct m66592 *m66592, u16 pipenum)
148} 147}
149 148
150static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum, 149static inline void control_reg_set_pid(struct m66592 *m66592, u16 pipenum,
151 u16 pid) 150 u16 pid)
152{ 151{
153 unsigned long offset; 152 unsigned long offset;
154 153
@@ -250,7 +249,7 @@ static inline void pipe_change(struct m66592 *m66592, u16 pipenum)
250} 249}
251 250
252static int pipe_buffer_setting(struct m66592 *m66592, 251static int pipe_buffer_setting(struct m66592 *m66592,
253 struct m66592_pipe_info *info) 252 struct m66592_pipe_info *info)
254{ 253{
255 u16 bufnum = 0, buf_bsize = 0; 254 u16 bufnum = 0, buf_bsize = 0;
256 u16 pipecfg = 0; 255 u16 pipecfg = 0;
@@ -287,7 +286,7 @@ static int pipe_buffer_setting(struct m66592 *m66592,
287 } 286 }
288 if (m66592->bi_bufnum > M66592_MAX_BUFNUM) { 287 if (m66592->bi_bufnum > M66592_MAX_BUFNUM) {
289 printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n", 288 printk(KERN_ERR "m66592 pipe memory is insufficient(%d)\n",
290 m66592->bi_bufnum); 289 m66592->bi_bufnum);
291 return -ENOMEM; 290 return -ENOMEM;
292 } 291 }
293 292
@@ -328,7 +327,7 @@ static void pipe_buffer_release(struct m66592 *m66592,
328 m66592->bulk--; 327 m66592->bulk--;
329 } else 328 } else
330 printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n", 329 printk(KERN_ERR "ep_release: unexpect pipenum (%d)\n",
331 info->pipe); 330 info->pipe);
332} 331}
333 332
334static void pipe_initialize(struct m66592_ep *ep) 333static void pipe_initialize(struct m66592_ep *ep)
@@ -350,8 +349,8 @@ static void pipe_initialize(struct m66592_ep *ep)
350} 349}
351 350
352static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep, 351static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
353 const struct usb_endpoint_descriptor *desc, 352 const struct usb_endpoint_descriptor *desc,
354 u16 pipenum, int dma) 353 u16 pipenum, int dma)
355{ 354{
356 if ((pipenum != 0) && dma) { 355 if ((pipenum != 0) && dma) {
357 if (m66592->num_dma == 0) { 356 if (m66592->num_dma == 0) {
@@ -385,7 +384,7 @@ static void m66592_ep_setting(struct m66592 *m66592, struct m66592_ep *ep,
385 384
386 ep->pipectr = get_pipectr_addr(pipenum); 385 ep->pipectr = get_pipectr_addr(pipenum);
387 ep->pipenum = pipenum; 386 ep->pipenum = pipenum;
388 ep->ep.maxpacket = desc->wMaxPacketSize; 387 ep->ep.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
389 m66592->pipenum2ep[pipenum] = ep; 388 m66592->pipenum2ep[pipenum] = ep;
390 m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep; 389 m66592->epaddr2ep[desc->bEndpointAddress&USB_ENDPOINT_NUMBER_MASK] = ep;
391 INIT_LIST_HEAD(&ep->queue); 390 INIT_LIST_HEAD(&ep->queue);
@@ -407,7 +406,7 @@ static void m66592_ep_release(struct m66592_ep *ep)
407} 406}
408 407
409static int alloc_pipe_config(struct m66592_ep *ep, 408static int alloc_pipe_config(struct m66592_ep *ep,
410 const struct usb_endpoint_descriptor *desc) 409 const struct usb_endpoint_descriptor *desc)
411{ 410{
412 struct m66592 *m66592 = ep->m66592; 411 struct m66592 *m66592 = ep->m66592;
413 struct m66592_pipe_info info; 412 struct m66592_pipe_info info;
@@ -419,15 +418,15 @@ static int alloc_pipe_config(struct m66592_ep *ep,
419 418
420 BUG_ON(ep->pipenum); 419 BUG_ON(ep->pipenum);
421 420
422 switch(desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 421 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
423 case USB_ENDPOINT_XFER_BULK: 422 case USB_ENDPOINT_XFER_BULK:
424 if (m66592->bulk >= M66592_MAX_NUM_BULK) { 423 if (m66592->bulk >= M66592_MAX_NUM_BULK) {
425 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) { 424 if (m66592->isochronous >= M66592_MAX_NUM_ISOC) {
426 printk(KERN_ERR "bulk pipe is insufficient\n"); 425 printk(KERN_ERR "bulk pipe is insufficient\n");
427 return -ENODEV; 426 return -ENODEV;
428 } else { 427 } else {
429 info.pipe = M66592_BASE_PIPENUM_ISOC + 428 info.pipe = M66592_BASE_PIPENUM_ISOC
430 m66592->isochronous; 429 + m66592->isochronous;
431 counter = &m66592->isochronous; 430 counter = &m66592->isochronous;
432 } 431 }
433 } else { 432 } else {
@@ -462,7 +461,7 @@ static int alloc_pipe_config(struct m66592_ep *ep,
462 ep->type = info.type; 461 ep->type = info.type;
463 462
464 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 463 info.epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
465 info.maxpacket = desc->wMaxPacketSize; 464 info.maxpacket = le16_to_cpu(desc->wMaxPacketSize);
466 info.interval = desc->bInterval; 465 info.interval = desc->bInterval;
467 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 466 if (desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
468 info.dir_in = 1; 467 info.dir_in = 1;
@@ -525,8 +524,8 @@ static void start_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
525 524
526 pipe_change(m66592, ep->pipenum); 525 pipe_change(m66592, ep->pipenum);
527 m66592_mdfy(m66592, M66592_ISEL | M66592_PIPE0, 526 m66592_mdfy(m66592, M66592_ISEL | M66592_PIPE0,
528 (M66592_ISEL | M66592_CURPIPE), 527 (M66592_ISEL | M66592_CURPIPE),
529 M66592_CFIFOSEL); 528 M66592_CFIFOSEL);
530 m66592_write(m66592, M66592_BCLR, ep->fifoctr); 529 m66592_write(m66592, M66592_BCLR, ep->fifoctr);
531 if (req->req.length == 0) { 530 if (req->req.length == 0) {
532 m66592_bset(m66592, M66592_BVAL, ep->fifoctr); 531 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
@@ -561,8 +560,8 @@ static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req)
561 560
562 if (ep->pipenum == 0) { 561 if (ep->pipenum == 0) {
563 m66592_mdfy(m66592, M66592_PIPE0, 562 m66592_mdfy(m66592, M66592_PIPE0,
564 (M66592_ISEL | M66592_CURPIPE), 563 (M66592_ISEL | M66592_CURPIPE),
565 M66592_CFIFOSEL); 564 M66592_CFIFOSEL);
566 m66592_write(m66592, M66592_BCLR, ep->fifoctr); 565 m66592_write(m66592, M66592_BCLR, ep->fifoctr);
567 pipe_start(m66592, pipenum); 566 pipe_start(m66592, pipenum);
568 pipe_irq_enable(m66592, pipenum); 567 pipe_irq_enable(m66592, pipenum);
@@ -572,8 +571,9 @@ static void start_packet_read(struct m66592_ep *ep, struct m66592_request *req)
572 pipe_change(m66592, pipenum); 571 pipe_change(m66592, pipenum);
573 m66592_bset(m66592, M66592_TRENB, ep->fifosel); 572 m66592_bset(m66592, M66592_TRENB, ep->fifosel);
574 m66592_write(m66592, 573 m66592_write(m66592,
575 (req->req.length + ep->ep.maxpacket - 1) / 574 (req->req.length + ep->ep.maxpacket - 1)
576 ep->ep.maxpacket, ep->fifotrn); 575 / ep->ep.maxpacket,
576 ep->fifotrn);
577 } 577 }
578 pipe_start(m66592, pipenum); /* trigger once */ 578 pipe_start(m66592, pipenum); /* trigger once */
579 pipe_irq_enable(m66592, pipenum); 579 pipe_irq_enable(m66592, pipenum);
@@ -614,7 +614,7 @@ static void start_ep0(struct m66592_ep *ep, struct m66592_request *req)
614static void init_controller(struct m66592 *m66592) 614static void init_controller(struct m66592 *m66592)
615{ 615{
616 m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND), 616 m66592_bset(m66592, (vif & M66592_LDRV) | (endian & M66592_BIGEND),
617 M66592_PINCFG); 617 M66592_PINCFG);
618 m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */ 618 m66592_bset(m66592, M66592_HSE, M66592_SYSCFG); /* High spd */
619 m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG); 619 m66592_mdfy(m66592, clock & M66592_XTAL, M66592_XTAL, M66592_SYSCFG);
620 620
@@ -634,7 +634,7 @@ static void init_controller(struct m66592 *m66592)
634 634
635 m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1); 635 m66592_bset(m66592, irq_sense & M66592_INTL, M66592_INTENB1);
636 m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR, 636 m66592_write(m66592, M66592_BURST | M66592_CPU_ADR_RD_WR,
637 M66592_DMA0CFG); 637 M66592_DMA0CFG);
638} 638}
639 639
640static void disable_controller(struct m66592 *m66592) 640static void disable_controller(struct m66592 *m66592)
@@ -659,8 +659,9 @@ static void m66592_start_xclock(struct m66592 *m66592)
659 659
660/*-------------------------------------------------------------------------*/ 660/*-------------------------------------------------------------------------*/
661static void transfer_complete(struct m66592_ep *ep, 661static void transfer_complete(struct m66592_ep *ep,
662 struct m66592_request *req, 662 struct m66592_request *req, int status)
663 int status) 663__releases(m66592->lock)
664__acquires(m66592->lock)
664{ 665{
665 int restart = 0; 666 int restart = 0;
666 667
@@ -680,8 +681,9 @@ static void transfer_complete(struct m66592_ep *ep,
680 if (!list_empty(&ep->queue)) 681 if (!list_empty(&ep->queue))
681 restart = 1; 682 restart = 1;
682 683
683 if (likely(req->req.complete)) 684 spin_unlock(&ep->m66592->lock);
684 req->req.complete(&ep->ep, &req->req); 685 req->req.complete(&ep->ep, &req->req);
686 spin_lock(&ep->m66592->lock);
685 687
686 if (restart) { 688 if (restart) {
687 req = list_entry(ep->queue.next, struct m66592_request, queue); 689 req = list_entry(ep->queue.next, struct m66592_request, queue);
@@ -693,7 +695,7 @@ static void transfer_complete(struct m66592_ep *ep,
693static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req) 695static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
694{ 696{
695 int i; 697 int i;
696 volatile u16 tmp; 698 u16 tmp;
697 unsigned bufsize; 699 unsigned bufsize;
698 size_t size; 700 size_t size;
699 void *buf; 701 void *buf;
@@ -731,8 +733,9 @@ static void irq_ep0_write(struct m66592_ep *ep, struct m66592_request *req)
731 req->req.actual += size; 733 req->req.actual += size;
732 734
733 /* check transfer finish */ 735 /* check transfer finish */
734 if ((!req->req.zero && (req->req.actual == req->req.length)) || 736 if ((!req->req.zero && (req->req.actual == req->req.length))
735 (size % ep->ep.maxpacket) || (size == 0)) { 737 || (size % ep->ep.maxpacket)
738 || (size == 0)) {
736 disable_irq_ready(m66592, pipenum); 739 disable_irq_ready(m66592, pipenum);
737 disable_irq_empty(m66592, pipenum); 740 disable_irq_empty(m66592, pipenum);
738 } else { 741 } else {
@@ -768,16 +771,19 @@ static void irq_packet_write(struct m66592_ep *ep, struct m66592_request *req)
768 /* write fifo */ 771 /* write fifo */
769 if (req->req.buf) { 772 if (req->req.buf) {
770 m66592_write_fifo(m66592, ep->fifoaddr, buf, size); 773 m66592_write_fifo(m66592, ep->fifoaddr, buf, size);
771 if ((size == 0) || ((size % ep->ep.maxpacket) != 0) || 774 if ((size == 0)
772 ((bufsize != ep->ep.maxpacket) && (bufsize > size))) 775 || ((size % ep->ep.maxpacket) != 0)
776 || ((bufsize != ep->ep.maxpacket)
777 && (bufsize > size)))
773 m66592_bset(m66592, M66592_BVAL, ep->fifoctr); 778 m66592_bset(m66592, M66592_BVAL, ep->fifoctr);
774 } 779 }
775 780
776 /* update parameters */ 781 /* update parameters */
777 req->req.actual += size; 782 req->req.actual += size;
778 /* check transfer finish */ 783 /* check transfer finish */
779 if ((!req->req.zero && (req->req.actual == req->req.length)) || 784 if ((!req->req.zero && (req->req.actual == req->req.length))
780 (size % ep->ep.maxpacket) || (size == 0)) { 785 || (size % ep->ep.maxpacket)
786 || (size == 0)) {
781 disable_irq_ready(m66592, pipenum); 787 disable_irq_ready(m66592, pipenum);
782 enable_irq_empty(m66592, pipenum); 788 enable_irq_empty(m66592, pipenum);
783 } else { 789 } else {
@@ -821,8 +827,9 @@ static void irq_packet_read(struct m66592_ep *ep, struct m66592_request *req)
821 req->req.actual += size; 827 req->req.actual += size;
822 828
823 /* check transfer finish */ 829 /* check transfer finish */
824 if ((!req->req.zero && (req->req.actual == req->req.length)) || 830 if ((!req->req.zero && (req->req.actual == req->req.length))
825 (size % ep->ep.maxpacket) || (size == 0)) { 831 || (size % ep->ep.maxpacket)
832 || (size == 0)) {
826 pipe_stop(m66592, pipenum); 833 pipe_stop(m66592, pipenum);
827 pipe_irq_disable(m66592, pipenum); 834 pipe_irq_disable(m66592, pipenum);
828 finish = 1; 835 finish = 1;
@@ -850,7 +857,7 @@ static void irq_pipe_ready(struct m66592 *m66592, u16 status, u16 enb)
850 if ((status & M66592_BRDY0) && (enb & M66592_BRDY0)) { 857 if ((status & M66592_BRDY0) && (enb & M66592_BRDY0)) {
851 m66592_write(m66592, ~M66592_BRDY0, M66592_BRDYSTS); 858 m66592_write(m66592, ~M66592_BRDY0, M66592_BRDYSTS);
852 m66592_mdfy(m66592, M66592_PIPE0, M66592_CURPIPE, 859 m66592_mdfy(m66592, M66592_PIPE0, M66592_CURPIPE,
853 M66592_CFIFOSEL); 860 M66592_CFIFOSEL);
854 861
855 ep = &m66592->ep[0]; 862 ep = &m66592->ep[0];
856 req = list_entry(ep->queue.next, struct m66592_request, queue); 863 req = list_entry(ep->queue.next, struct m66592_request, queue);
@@ -909,23 +916,26 @@ static void irq_pipe_empty(struct m66592 *m66592, u16 status, u16 enb)
909} 916}
910 917
911static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) 918static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
919__releases(m66592->lock)
920__acquires(m66592->lock)
912{ 921{
913 struct m66592_ep *ep; 922 struct m66592_ep *ep;
914 u16 pid; 923 u16 pid;
915 u16 status = 0; 924 u16 status = 0;
925 u16 w_index = le16_to_cpu(ctrl->wIndex);
916 926
917 switch (ctrl->bRequestType & USB_RECIP_MASK) { 927 switch (ctrl->bRequestType & USB_RECIP_MASK) {
918 case USB_RECIP_DEVICE: 928 case USB_RECIP_DEVICE:
919 status = 1; /* selfpower */ 929 status = 1 << USB_DEVICE_SELF_POWERED;
920 break; 930 break;
921 case USB_RECIP_INTERFACE: 931 case USB_RECIP_INTERFACE:
922 status = 0; 932 status = 0;
923 break; 933 break;
924 case USB_RECIP_ENDPOINT: 934 case USB_RECIP_ENDPOINT:
925 ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; 935 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
926 pid = control_reg_get_pid(m66592, ep->pipenum); 936 pid = control_reg_get_pid(m66592, ep->pipenum);
927 if (pid == M66592_PID_STALL) 937 if (pid == M66592_PID_STALL)
928 status = 1; 938 status = 1 << USB_ENDPOINT_HALT;
929 else 939 else
930 status = 0; 940 status = 0;
931 break; 941 break;
@@ -934,11 +944,13 @@ static void get_status(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
934 return; /* exit */ 944 return; /* exit */
935 } 945 }
936 946
937 *m66592->ep0_buf = status; 947 m66592->ep0_data = cpu_to_le16(status);
938 m66592->ep0_req->buf = m66592->ep0_buf; 948 m66592->ep0_req->buf = &m66592->ep0_data;
939 m66592->ep0_req->length = 2; 949 m66592->ep0_req->length = 2;
940 /* AV: what happens if we get called again before that gets through? */ 950 /* AV: what happens if we get called again before that gets through? */
951 spin_unlock(&m66592->lock);
941 m66592_queue(m66592->gadget.ep0, m66592->ep0_req, GFP_KERNEL); 952 m66592_queue(m66592->gadget.ep0, m66592->ep0_req, GFP_KERNEL);
953 spin_lock(&m66592->lock);
942} 954}
943 955
944static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl) 956static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
@@ -953,8 +965,9 @@ static void clear_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
953 case USB_RECIP_ENDPOINT: { 965 case USB_RECIP_ENDPOINT: {
954 struct m66592_ep *ep; 966 struct m66592_ep *ep;
955 struct m66592_request *req; 967 struct m66592_request *req;
968 u16 w_index = le16_to_cpu(ctrl->wIndex);
956 969
957 ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; 970 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
958 pipe_stop(m66592, ep->pipenum); 971 pipe_stop(m66592, ep->pipenum);
959 control_reg_sqclr(m66592, ep->pipenum); 972 control_reg_sqclr(m66592, ep->pipenum);
960 973
@@ -989,8 +1002,9 @@ static void set_feature(struct m66592 *m66592, struct usb_ctrlrequest *ctrl)
989 break; 1002 break;
990 case USB_RECIP_ENDPOINT: { 1003 case USB_RECIP_ENDPOINT: {
991 struct m66592_ep *ep; 1004 struct m66592_ep *ep;
1005 u16 w_index = le16_to_cpu(ctrl->wIndex);
992 1006
993 ep = m66592->epaddr2ep[ctrl->wIndex&USB_ENDPOINT_NUMBER_MASK]; 1007 ep = m66592->epaddr2ep[w_index & USB_ENDPOINT_NUMBER_MASK];
994 pipe_stall(m66592, ep->pipenum); 1008 pipe_stall(m66592, ep->pipenum);
995 1009
996 control_end(m66592, 1); 1010 control_end(m66592, 1);
@@ -1066,14 +1080,16 @@ static void irq_device_state(struct m66592 *m66592)
1066 } 1080 }
1067 if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG) 1081 if (m66592->old_dvsq == M66592_DS_CNFG && dvsq != M66592_DS_CNFG)
1068 m66592_update_usb_speed(m66592); 1082 m66592_update_usb_speed(m66592);
1069 if ((dvsq == M66592_DS_CNFG || dvsq == M66592_DS_ADDS) && 1083 if ((dvsq == M66592_DS_CNFG || dvsq == M66592_DS_ADDS)
1070 m66592->gadget.speed == USB_SPEED_UNKNOWN) 1084 && m66592->gadget.speed == USB_SPEED_UNKNOWN)
1071 m66592_update_usb_speed(m66592); 1085 m66592_update_usb_speed(m66592);
1072 1086
1073 m66592->old_dvsq = dvsq; 1087 m66592->old_dvsq = dvsq;
1074} 1088}
1075 1089
1076static void irq_control_stage(struct m66592 *m66592) 1090static void irq_control_stage(struct m66592 *m66592)
1091__releases(m66592->lock)
1092__acquires(m66592->lock)
1077{ 1093{
1078 struct usb_ctrlrequest ctrl; 1094 struct usb_ctrlrequest ctrl;
1079 u16 ctsq; 1095 u16 ctsq;
@@ -1095,8 +1111,10 @@ static void irq_control_stage(struct m66592 *m66592)
1095 case M66592_CS_WRDS: 1111 case M66592_CS_WRDS:
1096 case M66592_CS_WRND: 1112 case M66592_CS_WRND:
1097 if (setup_packet(m66592, &ctrl)) { 1113 if (setup_packet(m66592, &ctrl)) {
1114 spin_unlock(&m66592->lock);
1098 if (m66592->driver->setup(&m66592->gadget, &ctrl) < 0) 1115 if (m66592->driver->setup(&m66592->gadget, &ctrl) < 0)
1099 pipe_stall(m66592, 0); 1116 pipe_stall(m66592, 0);
1117 spin_lock(&m66592->lock);
1100 } 1118 }
1101 break; 1119 break;
1102 case M66592_CS_RDSS: 1120 case M66592_CS_RDSS:
@@ -1119,6 +1137,8 @@ static irqreturn_t m66592_irq(int irq, void *_m66592)
1119 u16 savepipe; 1137 u16 savepipe;
1120 u16 mask0; 1138 u16 mask0;
1121 1139
1140 spin_lock(&m66592->lock);
1141
1122 intsts0 = m66592_read(m66592, M66592_INTSTS0); 1142 intsts0 = m66592_read(m66592, M66592_INTSTS0);
1123 intenb0 = m66592_read(m66592, M66592_INTENB0); 1143 intenb0 = m66592_read(m66592, M66592_INTENB0);
1124 1144
@@ -1134,27 +1154,27 @@ static irqreturn_t m66592_irq(int irq, void *_m66592)
1134 bempenb = m66592_read(m66592, M66592_BEMPENB); 1154 bempenb = m66592_read(m66592, M66592_BEMPENB);
1135 1155
1136 if (mask0 & M66592_VBINT) { 1156 if (mask0 & M66592_VBINT) {
1137 m66592_write(m66592, (u16)~M66592_VBINT, 1157 m66592_write(m66592, 0xffff & ~M66592_VBINT,
1138 M66592_INTSTS0); 1158 M66592_INTSTS0);
1139 m66592_start_xclock(m66592); 1159 m66592_start_xclock(m66592);
1140 1160
1141 /* start vbus sampling */ 1161 /* start vbus sampling */
1142 m66592->old_vbus = m66592_read(m66592, M66592_INTSTS0) 1162 m66592->old_vbus = m66592_read(m66592, M66592_INTSTS0)
1143 & M66592_VBSTS; 1163 & M66592_VBSTS;
1144 m66592->scount = M66592_MAX_SAMPLING; 1164 m66592->scount = M66592_MAX_SAMPLING;
1145 1165
1146 mod_timer(&m66592->timer, 1166 mod_timer(&m66592->timer,
1147 jiffies + msecs_to_jiffies(50)); 1167 jiffies + msecs_to_jiffies(50));
1148 } 1168 }
1149 if (intsts0 & M66592_DVSQ) 1169 if (intsts0 & M66592_DVSQ)
1150 irq_device_state(m66592); 1170 irq_device_state(m66592);
1151 1171
1152 if ((intsts0 & M66592_BRDY) && (intenb0 & M66592_BRDYE) && 1172 if ((intsts0 & M66592_BRDY) && (intenb0 & M66592_BRDYE)
1153 (brdysts & brdyenb)) { 1173 && (brdysts & brdyenb)) {
1154 irq_pipe_ready(m66592, brdysts, brdyenb); 1174 irq_pipe_ready(m66592, brdysts, brdyenb);
1155 } 1175 }
1156 if ((intsts0 & M66592_BEMP) && (intenb0 & M66592_BEMPE) && 1176 if ((intsts0 & M66592_BEMP) && (intenb0 & M66592_BEMPE)
1157 (bempsts & bempenb)) { 1177 && (bempsts & bempenb)) {
1158 irq_pipe_empty(m66592, bempsts, bempenb); 1178 irq_pipe_empty(m66592, bempsts, bempenb);
1159 } 1179 }
1160 1180
@@ -1164,6 +1184,7 @@ static irqreturn_t m66592_irq(int irq, void *_m66592)
1164 1184
1165 m66592_write(m66592, savepipe, M66592_CFIFOSEL); 1185 m66592_write(m66592, savepipe, M66592_CFIFOSEL);
1166 1186
1187 spin_unlock(&m66592->lock);
1167 return IRQ_HANDLED; 1188 return IRQ_HANDLED;
1168} 1189}
1169 1190
@@ -1191,13 +1212,13 @@ static void m66592_timer(unsigned long _m66592)
1191 m66592_usb_disconnect(m66592); 1212 m66592_usb_disconnect(m66592);
1192 } else { 1213 } else {
1193 mod_timer(&m66592->timer, 1214 mod_timer(&m66592->timer,
1194 jiffies + msecs_to_jiffies(50)); 1215 jiffies + msecs_to_jiffies(50));
1195 } 1216 }
1196 } else { 1217 } else {
1197 m66592->scount = M66592_MAX_SAMPLING; 1218 m66592->scount = M66592_MAX_SAMPLING;
1198 m66592->old_vbus = tmp; 1219 m66592->old_vbus = tmp;
1199 mod_timer(&m66592->timer, 1220 mod_timer(&m66592->timer,
1200 jiffies + msecs_to_jiffies(50)); 1221 jiffies + msecs_to_jiffies(50));
1201 } 1222 }
1202 } 1223 }
1203 spin_unlock_irqrestore(&m66592->lock, flags); 1224 spin_unlock_irqrestore(&m66592->lock, flags);
@@ -1335,11 +1356,6 @@ out:
1335 return ret; 1356 return ret;
1336} 1357}
1337 1358
1338static int m66592_fifo_status(struct usb_ep *_ep)
1339{
1340 return -EOPNOTSUPP;
1341}
1342
1343static void m66592_fifo_flush(struct usb_ep *_ep) 1359static void m66592_fifo_flush(struct usb_ep *_ep)
1344{ 1360{
1345 struct m66592_ep *ep; 1361 struct m66592_ep *ep;
@@ -1365,7 +1381,6 @@ static struct usb_ep_ops m66592_ep_ops = {
1365 .dequeue = m66592_dequeue, 1381 .dequeue = m66592_dequeue,
1366 1382
1367 .set_halt = m66592_set_halt, 1383 .set_halt = m66592_set_halt,
1368 .fifo_status = m66592_fifo_status,
1369 .fifo_flush = m66592_fifo_flush, 1384 .fifo_flush = m66592_fifo_flush,
1370}; 1385};
1371 1386
@@ -1377,11 +1392,10 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1377 struct m66592 *m66592 = the_controller; 1392 struct m66592 *m66592 = the_controller;
1378 int retval; 1393 int retval;
1379 1394
1380 if (!driver || 1395 if (!driver
1381 driver->speed != USB_SPEED_HIGH || 1396 || driver->speed != USB_SPEED_HIGH
1382 !driver->bind || 1397 || !driver->bind
1383 !driver->unbind || 1398 || !driver->setup)
1384 !driver->setup)
1385 return -EINVAL; 1399 return -EINVAL;
1386 if (!m66592) 1400 if (!m66592)
1387 return -ENODEV; 1401 return -ENODEV;
@@ -1413,8 +1427,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1413 m66592->old_vbus = m66592_read(m66592, 1427 m66592->old_vbus = m66592_read(m66592,
1414 M66592_INTSTS0) & M66592_VBSTS; 1428 M66592_INTSTS0) & M66592_VBSTS;
1415 m66592->scount = M66592_MAX_SAMPLING; 1429 m66592->scount = M66592_MAX_SAMPLING;
1416 mod_timer(&m66592->timer, 1430 mod_timer(&m66592->timer, jiffies + msecs_to_jiffies(50));
1417 jiffies + msecs_to_jiffies(50));
1418 } 1431 }
1419 1432
1420 return 0; 1433 return 0;
@@ -1432,6 +1445,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1432 struct m66592 *m66592 = the_controller; 1445 struct m66592 *m66592 = the_controller;
1433 unsigned long flags; 1446 unsigned long flags;
1434 1447
1448 if (driver != m66592->driver || !driver->unbind)
1449 return -EINVAL;
1450
1435 spin_lock_irqsave(&m66592->lock, flags); 1451 spin_lock_irqsave(&m66592->lock, flags);
1436 if (m66592->gadget.speed != USB_SPEED_UNKNOWN) 1452 if (m66592->gadget.speed != USB_SPEED_UNKNOWN)
1437 m66592_usb_disconnect(m66592); 1453 m66592_usb_disconnect(m66592);
@@ -1461,46 +1477,35 @@ static struct usb_gadget_ops m66592_gadget_ops = {
1461 .get_frame = m66592_get_frame, 1477 .get_frame = m66592_get_frame,
1462}; 1478};
1463 1479
1464#if defined(CONFIG_PM) 1480static int __exit m66592_remove(struct platform_device *pdev)
1465static int m66592_suspend(struct platform_device *pdev, pm_message_t state)
1466{
1467 pdev->dev.power.power_state = state;
1468 return 0;
1469}
1470
1471static int m66592_resume(struct platform_device *pdev)
1472{
1473 pdev->dev.power.power_state = PMSG_ON;
1474 return 0;
1475}
1476#else /* if defined(CONFIG_PM) */
1477#define m66592_suspend NULL
1478#define m66592_resume NULL
1479#endif
1480
1481static int __init_or_module m66592_remove(struct platform_device *pdev)
1482{ 1481{
1483 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev); 1482 struct m66592 *m66592 = dev_get_drvdata(&pdev->dev);
1484 1483
1485 del_timer_sync(&m66592->timer); 1484 del_timer_sync(&m66592->timer);
1486 iounmap(m66592->reg); 1485 iounmap(m66592->reg);
1487 free_irq(platform_get_irq(pdev, 0), m66592); 1486 free_irq(platform_get_irq(pdev, 0), m66592);
1487 m66592_free_request(&m66592->ep[0].ep, m66592->ep0_req);
1488 kfree(m66592); 1488 kfree(m66592);
1489 return 0; 1489 return 0;
1490} 1490}
1491 1491
1492static void nop_completion(struct usb_ep *ep, struct usb_request *r)
1493{
1494}
1495
1492#define resource_len(r) (((r)->end - (r)->start) + 1) 1496#define resource_len(r) (((r)->end - (r)->start) + 1)
1497
1493static int __init m66592_probe(struct platform_device *pdev) 1498static int __init m66592_probe(struct platform_device *pdev)
1494{ 1499{
1495 struct resource *res = NULL; 1500 struct resource *res;
1496 int irq = -1; 1501 int irq;
1497 void __iomem *reg = NULL; 1502 void __iomem *reg = NULL;
1498 struct m66592 *m66592 = NULL; 1503 struct m66592 *m66592 = NULL;
1499 int ret = 0; 1504 int ret = 0;
1500 int i; 1505 int i;
1501 1506
1502 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 1507 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1503 (char *)udc_name); 1508 (char *)udc_name);
1504 if (!res) { 1509 if (!res) {
1505 ret = -ENODEV; 1510 ret = -ENODEV;
1506 printk(KERN_ERR "platform_get_resource_byname error.\n"); 1511 printk(KERN_ERR "platform_get_resource_byname error.\n");
@@ -1548,7 +1553,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1548 m66592->bi_bufnum = M66592_BASE_BUFNUM; 1553 m66592->bi_bufnum = M66592_BASE_BUFNUM;
1549 1554
1550 ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED, 1555 ret = request_irq(irq, m66592_irq, IRQF_DISABLED | IRQF_SHARED,
1551 udc_name, m66592); 1556 udc_name, m66592);
1552 if (ret < 0) { 1557 if (ret < 0) {
1553 printk(KERN_ERR "request_irq error (%d)\n", ret); 1558 printk(KERN_ERR "request_irq error (%d)\n", ret);
1554 goto clean_up; 1559 goto clean_up;
@@ -1563,7 +1568,7 @@ static int __init m66592_probe(struct platform_device *pdev)
1563 if (i != 0) { 1568 if (i != 0) {
1564 INIT_LIST_HEAD(&m66592->ep[i].ep.ep_list); 1569 INIT_LIST_HEAD(&m66592->ep[i].ep.ep_list);
1565 list_add_tail(&m66592->ep[i].ep.ep_list, 1570 list_add_tail(&m66592->ep[i].ep.ep_list,
1566 &m66592->gadget.ep_list); 1571 &m66592->gadget.ep_list);
1567 } 1572 }
1568 ep->m66592 = m66592; 1573 ep->m66592 = m66592;
1569 INIT_LIST_HEAD(&ep->queue); 1574 INIT_LIST_HEAD(&ep->queue);
@@ -1583,20 +1588,18 @@ static int __init m66592_probe(struct platform_device *pdev)
1583 1588
1584 the_controller = m66592; 1589 the_controller = m66592;
1585 1590
1586 /* AV: leaks */
1587 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL); 1591 m66592->ep0_req = m66592_alloc_request(&m66592->ep[0].ep, GFP_KERNEL);
1588 if (m66592->ep0_req == NULL) 1592 if (m66592->ep0_req == NULL)
1589 goto clean_up; 1593 goto clean_up2;
1590 /* AV: leaks, and do we really need it separately allocated? */ 1594 m66592->ep0_req->complete = nop_completion;
1591 m66592->ep0_buf = kzalloc(2, GFP_KERNEL);
1592 if (m66592->ep0_buf == NULL)
1593 goto clean_up;
1594 1595
1595 init_controller(m66592); 1596 init_controller(m66592);
1596 1597
1597 printk("driver %s, %s\n", udc_name, DRIVER_VERSION); 1598 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
1598 return 0; 1599 return 0;
1599 1600
1601clean_up2:
1602 free_irq(irq, m66592);
1600clean_up: 1603clean_up:
1601 if (m66592) { 1604 if (m66592) {
1602 if (m66592->ep0_req) 1605 if (m66592->ep0_req)
@@ -1611,10 +1614,7 @@ clean_up:
1611 1614
1612/*-------------------------------------------------------------------------*/ 1615/*-------------------------------------------------------------------------*/
1613static struct platform_driver m66592_driver = { 1616static struct platform_driver m66592_driver = {
1614 .probe = m66592_probe, 1617 .remove = __exit_p(m66592_remove),
1615 .remove = m66592_remove,
1616 .suspend = m66592_suspend,
1617 .resume = m66592_resume,
1618 .driver = { 1618 .driver = {
1619 .name = (char *) udc_name, 1619 .name = (char *) udc_name,
1620 }, 1620 },
@@ -1622,7 +1622,7 @@ static struct platform_driver m66592_driver = {
1622 1622
1623static int __init m66592_udc_init(void) 1623static int __init m66592_udc_init(void)
1624{ 1624{
1625 return platform_driver_register(&m66592_driver); 1625 return platform_driver_probe(&m66592_driver, m66592_probe);
1626} 1626}
1627module_init(m66592_udc_init); 1627module_init(m66592_udc_init);
1628 1628
@@ -1631,4 +1631,3 @@ static void __exit m66592_udc_cleanup(void)
1631 platform_driver_unregister(&m66592_driver); 1631 platform_driver_unregister(&m66592_driver);
1632} 1632}
1633module_exit(m66592_udc_cleanup); 1633module_exit(m66592_udc_cleanup);
1634
diff --git a/drivers/usb/gadget/m66592-udc.h b/drivers/usb/gadget/m66592-udc.h
index 26b54f8b8945..bfa0c645f229 100644
--- a/drivers/usb/gadget/m66592-udc.h
+++ b/drivers/usb/gadget/m66592-udc.h
@@ -24,73 +24,73 @@
24#define __M66592_UDC_H__ 24#define __M66592_UDC_H__
25 25
26#define M66592_SYSCFG 0x00 26#define M66592_SYSCFG 0x00
27#define M66592_XTAL 0xC000 /* b15-14: Crystal selection */ 27#define M66592_XTAL 0xC000 /* b15-14: Crystal selection */
28#define M66592_XTAL48 0x8000 /* 48MHz */ 28#define M66592_XTAL48 0x8000 /* 48MHz */
29#define M66592_XTAL24 0x4000 /* 24MHz */ 29#define M66592_XTAL24 0x4000 /* 24MHz */
30#define M66592_XTAL12 0x0000 /* 12MHz */ 30#define M66592_XTAL12 0x0000 /* 12MHz */
31#define M66592_XCKE 0x2000 /* b13: External clock enable */ 31#define M66592_XCKE 0x2000 /* b13: External clock enable */
32#define M66592_RCKE 0x1000 /* b12: Register clock enable */ 32#define M66592_RCKE 0x1000 /* b12: Register clock enable */
33#define M66592_PLLC 0x0800 /* b11: PLL control */ 33#define M66592_PLLC 0x0800 /* b11: PLL control */
34#define M66592_SCKE 0x0400 /* b10: USB clock enable */ 34#define M66592_SCKE 0x0400 /* b10: USB clock enable */
35#define M66592_ATCKM 0x0100 /* b8: Automatic supply functional enable */ 35#define M66592_ATCKM 0x0100 /* b8: Automatic clock supply */
36#define M66592_HSE 0x0080 /* b7: Hi-speed enable */ 36#define M66592_HSE 0x0080 /* b7: Hi-speed enable */
37#define M66592_DCFM 0x0040 /* b6: Controller function select */ 37#define M66592_DCFM 0x0040 /* b6: Controller function select */
38#define M66592_DMRPD 0x0020 /* b5: D- pull down control */ 38#define M66592_DMRPD 0x0020 /* b5: D- pull down control */
39#define M66592_DPRPU 0x0010 /* b4: D+ pull up control */ 39#define M66592_DPRPU 0x0010 /* b4: D+ pull up control */
40#define M66592_FSRPC 0x0004 /* b2: Full-speed receiver enable */ 40#define M66592_FSRPC 0x0004 /* b2: Full-speed receiver enable */
41#define M66592_PCUT 0x0002 /* b1: Low power sleep enable */ 41#define M66592_PCUT 0x0002 /* b1: Low power sleep enable */
42#define M66592_USBE 0x0001 /* b0: USB module operation enable */ 42#define M66592_USBE 0x0001 /* b0: USB module operation enable */
43 43
44#define M66592_SYSSTS 0x02 44#define M66592_SYSSTS 0x02
45#define M66592_LNST 0x0003 /* b1-0: D+, D- line status */ 45#define M66592_LNST 0x0003 /* b1-0: D+, D- line status */
46#define M66592_SE1 0x0003 /* SE1 */ 46#define M66592_SE1 0x0003 /* SE1 */
47#define M66592_KSTS 0x0002 /* K State */ 47#define M66592_KSTS 0x0002 /* K State */
48#define M66592_JSTS 0x0001 /* J State */ 48#define M66592_JSTS 0x0001 /* J State */
49#define M66592_SE0 0x0000 /* SE0 */ 49#define M66592_SE0 0x0000 /* SE0 */
50 50
51#define M66592_DVSTCTR 0x04 51#define M66592_DVSTCTR 0x04
52#define M66592_WKUP 0x0100 /* b8: Remote wakeup */ 52#define M66592_WKUP 0x0100 /* b8: Remote wakeup */
53#define M66592_RWUPE 0x0080 /* b7: Remote wakeup sense */ 53#define M66592_RWUPE 0x0080 /* b7: Remote wakeup sense */
54#define M66592_USBRST 0x0040 /* b6: USB reset enable */ 54#define M66592_USBRST 0x0040 /* b6: USB reset enable */
55#define M66592_RESUME 0x0020 /* b5: Resume enable */ 55#define M66592_RESUME 0x0020 /* b5: Resume enable */
56#define M66592_UACT 0x0010 /* b4: USB bus enable */ 56#define M66592_UACT 0x0010 /* b4: USB bus enable */
57#define M66592_RHST 0x0003 /* b1-0: Reset handshake status */ 57#define M66592_RHST 0x0003 /* b1-0: Reset handshake status */
58#define M66592_HSMODE 0x0003 /* Hi-Speed mode */ 58#define M66592_HSMODE 0x0003 /* Hi-Speed mode */
59#define M66592_FSMODE 0x0002 /* Full-Speed mode */ 59#define M66592_FSMODE 0x0002 /* Full-Speed mode */
60#define M66592_HSPROC 0x0001 /* HS handshake is processing */ 60#define M66592_HSPROC 0x0001 /* HS handshake is processing */
61 61
62#define M66592_TESTMODE 0x06 62#define M66592_TESTMODE 0x06
63#define M66592_UTST 0x000F /* b4-0: Test select */ 63#define M66592_UTST 0x000F /* b4-0: Test select */
64#define M66592_H_TST_PACKET 0x000C /* HOST TEST Packet */ 64#define M66592_H_TST_PACKET 0x000C /* HOST TEST Packet */
65#define M66592_H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */ 65#define M66592_H_TST_SE0_NAK 0x000B /* HOST TEST SE0 NAK */
66#define M66592_H_TST_K 0x000A /* HOST TEST K */ 66#define M66592_H_TST_K 0x000A /* HOST TEST K */
67#define M66592_H_TST_J 0x0009 /* HOST TEST J */ 67#define M66592_H_TST_J 0x0009 /* HOST TEST J */
68#define M66592_H_TST_NORMAL 0x0000 /* HOST Normal Mode */ 68#define M66592_H_TST_NORMAL 0x0000 /* HOST Normal Mode */
69#define M66592_P_TST_PACKET 0x0004 /* PERI TEST Packet */ 69#define M66592_P_TST_PACKET 0x0004 /* PERI TEST Packet */
70#define M66592_P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */ 70#define M66592_P_TST_SE0_NAK 0x0003 /* PERI TEST SE0 NAK */
71#define M66592_P_TST_K 0x0002 /* PERI TEST K */ 71#define M66592_P_TST_K 0x0002 /* PERI TEST K */
72#define M66592_P_TST_J 0x0001 /* PERI TEST J */ 72#define M66592_P_TST_J 0x0001 /* PERI TEST J */
73#define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */ 73#define M66592_P_TST_NORMAL 0x0000 /* PERI Normal Mode */
74 74
75#define M66592_PINCFG 0x0A 75#define M66592_PINCFG 0x0A
76#define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */ 76#define M66592_LDRV 0x8000 /* b15: Drive Current Adjust */
77#define M66592_BIGEND 0x0100 /* b8: Big endian mode */ 77#define M66592_BIGEND 0x0100 /* b8: Big endian mode */
78 78
79#define M66592_DMA0CFG 0x0C 79#define M66592_DMA0CFG 0x0C
80#define M66592_DMA1CFG 0x0E 80#define M66592_DMA1CFG 0x0E
81#define M66592_DREQA 0x4000 /* b14: Dreq active select */ 81#define M66592_DREQA 0x4000 /* b14: Dreq active select */
82#define M66592_BURST 0x2000 /* b13: Burst mode */ 82#define M66592_BURST 0x2000 /* b13: Burst mode */
83#define M66592_DACKA 0x0400 /* b10: Dack active select */ 83#define M66592_DACKA 0x0400 /* b10: Dack active select */
84#define M66592_DFORM 0x0380 /* b9-7: DMA mode select */ 84#define M66592_DFORM 0x0380 /* b9-7: DMA mode select */
85#define M66592_CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */ 85#define M66592_CPU_ADR_RD_WR 0x0000 /* Address + RD/WR mode (CPU bus) */
86#define M66592_CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */ 86#define M66592_CPU_DACK_RD_WR 0x0100 /* DACK + RD/WR mode (CPU bus) */
87#define M66592_CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */ 87#define M66592_CPU_DACK_ONLY 0x0180 /* DACK only mode (CPU bus) */
88#define M66592_SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */ 88#define M66592_SPLIT_DACK_ONLY 0x0200 /* DACK only mode (SPLIT bus) */
89#define M66592_SPLIT_DACK_DSTB 0x0300 /* DACK + DSTB0 mode (SPLIT bus) */ 89#define M66592_SPLIT_DACK_DSTB 0x0300 /* DACK + DSTB0 mode (SPLIT bus) */
90#define M66592_DENDA 0x0040 /* b6: Dend active select */ 90#define M66592_DENDA 0x0040 /* b6: Dend active select */
91#define M66592_PKTM 0x0020 /* b5: Packet mode */ 91#define M66592_PKTM 0x0020 /* b5: Packet mode */
92#define M66592_DENDE 0x0010 /* b4: Dend enable */ 92#define M66592_DENDE 0x0010 /* b4: Dend enable */
93#define M66592_OBUS 0x0004 /* b2: OUTbus mode */ 93#define M66592_OBUS 0x0004 /* b2: OUTbus mode */
94 94
95#define M66592_CFIFO 0x10 95#define M66592_CFIFO 0x10
96#define M66592_D0FIFO 0x14 96#define M66592_D0FIFO 0x14
@@ -99,300 +99,300 @@
99#define M66592_CFIFOSEL 0x1E 99#define M66592_CFIFOSEL 0x1E
100#define M66592_D0FIFOSEL 0x24 100#define M66592_D0FIFOSEL 0x24
101#define M66592_D1FIFOSEL 0x2A 101#define M66592_D1FIFOSEL 0x2A
102#define M66592_RCNT 0x8000 /* b15: Read count mode */ 102#define M66592_RCNT 0x8000 /* b15: Read count mode */
103#define M66592_REW 0x4000 /* b14: Buffer rewind */ 103#define M66592_REW 0x4000 /* b14: Buffer rewind */
104#define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */ 104#define M66592_DCLRM 0x2000 /* b13: DMA buffer clear mode */
105#define M66592_DREQE 0x1000 /* b12: DREQ output enable */ 105#define M66592_DREQE 0x1000 /* b12: DREQ output enable */
106#define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO access */ 106#define M66592_MBW 0x0400 /* b10: Maximum bit width for FIFO */
107#define M66592_MBW_8 0x0000 /* 8bit */ 107#define M66592_MBW_8 0x0000 /* 8bit */
108#define M66592_MBW_16 0x0400 /* 16bit */ 108#define M66592_MBW_16 0x0400 /* 16bit */
109#define M66592_TRENB 0x0200 /* b9: Transaction counter enable */ 109#define M66592_TRENB 0x0200 /* b9: Transaction counter enable */
110#define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */ 110#define M66592_TRCLR 0x0100 /* b8: Transaction counter clear */
111#define M66592_DEZPM 0x0080 /* b7: Zero-length packet additional mode */ 111#define M66592_DEZPM 0x0080 /* b7: Zero-length packet mode */
112#define M66592_ISEL 0x0020 /* b5: DCP FIFO port direction select */ 112#define M66592_ISEL 0x0020 /* b5: DCP FIFO port direction select */
113#define M66592_CURPIPE 0x0007 /* b2-0: PIPE select */ 113#define M66592_CURPIPE 0x0007 /* b2-0: PIPE select */
114 114
115#define M66592_CFIFOCTR 0x20 115#define M66592_CFIFOCTR 0x20
116#define M66592_D0FIFOCTR 0x26 116#define M66592_D0FIFOCTR 0x26
117#define M66592_D1FIFOCTR 0x2c 117#define M66592_D1FIFOCTR 0x2c
118#define M66592_BVAL 0x8000 /* b15: Buffer valid flag */ 118#define M66592_BVAL 0x8000 /* b15: Buffer valid flag */
119#define M66592_BCLR 0x4000 /* b14: Buffer clear */ 119#define M66592_BCLR 0x4000 /* b14: Buffer clear */
120#define M66592_FRDY 0x2000 /* b13: FIFO ready */ 120#define M66592_FRDY 0x2000 /* b13: FIFO ready */
121#define M66592_DTLN 0x0FFF /* b11-0: FIFO received data length */ 121#define M66592_DTLN 0x0FFF /* b11-0: FIFO received data length */
122 122
123#define M66592_CFIFOSIE 0x22 123#define M66592_CFIFOSIE 0x22
124#define M66592_TGL 0x8000 /* b15: Buffer toggle */ 124#define M66592_TGL 0x8000 /* b15: Buffer toggle */
125#define M66592_SCLR 0x4000 /* b14: Buffer clear */ 125#define M66592_SCLR 0x4000 /* b14: Buffer clear */
126#define M66592_SBUSY 0x2000 /* b13: SIE_FIFO busy */ 126#define M66592_SBUSY 0x2000 /* b13: SIE_FIFO busy */
127 127
128#define M66592_D0FIFOTRN 0x28 128#define M66592_D0FIFOTRN 0x28
129#define M66592_D1FIFOTRN 0x2E 129#define M66592_D1FIFOTRN 0x2E
130#define M66592_TRNCNT 0xFFFF /* b15-0: Transaction counter */ 130#define M66592_TRNCNT 0xFFFF /* b15-0: Transaction counter */
131 131
132#define M66592_INTENB0 0x30 132#define M66592_INTENB0 0x30
133#define M66592_VBSE 0x8000 /* b15: VBUS interrupt */ 133#define M66592_VBSE 0x8000 /* b15: VBUS interrupt */
134#define M66592_RSME 0x4000 /* b14: Resume interrupt */ 134#define M66592_RSME 0x4000 /* b14: Resume interrupt */
135#define M66592_SOFE 0x2000 /* b13: Frame update interrupt */ 135#define M66592_SOFE 0x2000 /* b13: Frame update interrupt */
136#define M66592_DVSE 0x1000 /* b12: Device state transition interrupt */ 136#define M66592_DVSE 0x1000 /* b12: Device state transition interrupt */
137#define M66592_CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ 137#define M66592_CTRE 0x0800 /* b11: Control transfer stage transition irq */
138#define M66592_BEMPE 0x0400 /* b10: Buffer empty interrupt */ 138#define M66592_BEMPE 0x0400 /* b10: Buffer empty interrupt */
139#define M66592_NRDYE 0x0200 /* b9: Buffer not ready interrupt */ 139#define M66592_NRDYE 0x0200 /* b9: Buffer not ready interrupt */
140#define M66592_BRDYE 0x0100 /* b8: Buffer ready interrupt */ 140#define M66592_BRDYE 0x0100 /* b8: Buffer ready interrupt */
141#define M66592_URST 0x0080 /* b7: USB reset detected interrupt */ 141#define M66592_URST 0x0080 /* b7: USB reset detected interrupt */
142#define M66592_SADR 0x0040 /* b6: Set address executed interrupt */ 142#define M66592_SADR 0x0040 /* b6: Set address executed interrupt */
143#define M66592_SCFG 0x0020 /* b5: Set configuration executed interrupt */ 143#define M66592_SCFG 0x0020 /* b5: Set configuration executed interrupt */
144#define M66592_SUSP 0x0010 /* b4: Suspend detected interrupt */ 144#define M66592_SUSP 0x0010 /* b4: Suspend detected interrupt */
145#define M66592_WDST 0x0008 /* b3: Control write data stage completed interrupt */ 145#define M66592_WDST 0x0008 /* b3: Control write data stage completed irq */
146#define M66592_RDST 0x0004 /* b2: Control read data stage completed interrupt */ 146#define M66592_RDST 0x0004 /* b2: Control read data stage completed irq */
147#define M66592_CMPL 0x0002 /* b1: Control transfer complete interrupt */ 147#define M66592_CMPL 0x0002 /* b1: Control transfer complete interrupt */
148#define M66592_SERR 0x0001 /* b0: Sequence error interrupt */ 148#define M66592_SERR 0x0001 /* b0: Sequence error interrupt */
149 149
150#define M66592_INTENB1 0x32 150#define M66592_INTENB1 0x32
151#define M66592_BCHGE 0x4000 /* b14: USB us chenge interrupt */ 151#define M66592_BCHGE 0x4000 /* b14: USB us chenge interrupt */
152#define M66592_DTCHE 0x1000 /* b12: Detach sense interrupt */ 152#define M66592_DTCHE 0x1000 /* b12: Detach sense interrupt */
153#define M66592_SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */ 153#define M66592_SIGNE 0x0020 /* b5: SETUP IGNORE interrupt */
154#define M66592_SACKE 0x0010 /* b4: SETUP ACK interrupt */ 154#define M66592_SACKE 0x0010 /* b4: SETUP ACK interrupt */
155#define M66592_BRDYM 0x0004 /* b2: BRDY clear timing */ 155#define M66592_BRDYM 0x0004 /* b2: BRDY clear timing */
156#define M66592_INTL 0x0002 /* b1: Interrupt sense select */ 156#define M66592_INTL 0x0002 /* b1: Interrupt sense select */
157#define M66592_PCSE 0x0001 /* b0: PCUT enable by CS assert */ 157#define M66592_PCSE 0x0001 /* b0: PCUT enable by CS assert */
158 158
159#define M66592_BRDYENB 0x36 159#define M66592_BRDYENB 0x36
160#define M66592_BRDYSTS 0x46 160#define M66592_BRDYSTS 0x46
161#define M66592_BRDY7 0x0080 /* b7: PIPE7 */ 161#define M66592_BRDY7 0x0080 /* b7: PIPE7 */
162#define M66592_BRDY6 0x0040 /* b6: PIPE6 */ 162#define M66592_BRDY6 0x0040 /* b6: PIPE6 */
163#define M66592_BRDY5 0x0020 /* b5: PIPE5 */ 163#define M66592_BRDY5 0x0020 /* b5: PIPE5 */
164#define M66592_BRDY4 0x0010 /* b4: PIPE4 */ 164#define M66592_BRDY4 0x0010 /* b4: PIPE4 */
165#define M66592_BRDY3 0x0008 /* b3: PIPE3 */ 165#define M66592_BRDY3 0x0008 /* b3: PIPE3 */
166#define M66592_BRDY2 0x0004 /* b2: PIPE2 */ 166#define M66592_BRDY2 0x0004 /* b2: PIPE2 */
167#define M66592_BRDY1 0x0002 /* b1: PIPE1 */ 167#define M66592_BRDY1 0x0002 /* b1: PIPE1 */
168#define M66592_BRDY0 0x0001 /* b1: PIPE0 */ 168#define M66592_BRDY0 0x0001 /* b1: PIPE0 */
169 169
170#define M66592_NRDYENB 0x38 170#define M66592_NRDYENB 0x38
171#define M66592_NRDYSTS 0x48 171#define M66592_NRDYSTS 0x48
172#define M66592_NRDY7 0x0080 /* b7: PIPE7 */ 172#define M66592_NRDY7 0x0080 /* b7: PIPE7 */
173#define M66592_NRDY6 0x0040 /* b6: PIPE6 */ 173#define M66592_NRDY6 0x0040 /* b6: PIPE6 */
174#define M66592_NRDY5 0x0020 /* b5: PIPE5 */ 174#define M66592_NRDY5 0x0020 /* b5: PIPE5 */
175#define M66592_NRDY4 0x0010 /* b4: PIPE4 */ 175#define M66592_NRDY4 0x0010 /* b4: PIPE4 */
176#define M66592_NRDY3 0x0008 /* b3: PIPE3 */ 176#define M66592_NRDY3 0x0008 /* b3: PIPE3 */
177#define M66592_NRDY2 0x0004 /* b2: PIPE2 */ 177#define M66592_NRDY2 0x0004 /* b2: PIPE2 */
178#define M66592_NRDY1 0x0002 /* b1: PIPE1 */ 178#define M66592_NRDY1 0x0002 /* b1: PIPE1 */
179#define M66592_NRDY0 0x0001 /* b1: PIPE0 */ 179#define M66592_NRDY0 0x0001 /* b1: PIPE0 */
180 180
181#define M66592_BEMPENB 0x3A 181#define M66592_BEMPENB 0x3A
182#define M66592_BEMPSTS 0x4A 182#define M66592_BEMPSTS 0x4A
183#define M66592_BEMP7 0x0080 /* b7: PIPE7 */ 183#define M66592_BEMP7 0x0080 /* b7: PIPE7 */
184#define M66592_BEMP6 0x0040 /* b6: PIPE6 */ 184#define M66592_BEMP6 0x0040 /* b6: PIPE6 */
185#define M66592_BEMP5 0x0020 /* b5: PIPE5 */ 185#define M66592_BEMP5 0x0020 /* b5: PIPE5 */
186#define M66592_BEMP4 0x0010 /* b4: PIPE4 */ 186#define M66592_BEMP4 0x0010 /* b4: PIPE4 */
187#define M66592_BEMP3 0x0008 /* b3: PIPE3 */ 187#define M66592_BEMP3 0x0008 /* b3: PIPE3 */
188#define M66592_BEMP2 0x0004 /* b2: PIPE2 */ 188#define M66592_BEMP2 0x0004 /* b2: PIPE2 */
189#define M66592_BEMP1 0x0002 /* b1: PIPE1 */ 189#define M66592_BEMP1 0x0002 /* b1: PIPE1 */
190#define M66592_BEMP0 0x0001 /* b0: PIPE0 */ 190#define M66592_BEMP0 0x0001 /* b0: PIPE0 */
191 191
192#define M66592_SOFCFG 0x3C 192#define M66592_SOFCFG 0x3C
193#define M66592_SOFM 0x000C /* b3-2: SOF palse mode */ 193#define M66592_SOFM 0x000C /* b3-2: SOF palse mode */
194#define M66592_SOF_125US 0x0008 /* SOF OUT 125us uFrame Signal */ 194#define M66592_SOF_125US 0x0008 /* SOF OUT 125us uFrame Signal */
195#define M66592_SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */ 195#define M66592_SOF_1MS 0x0004 /* SOF OUT 1ms Frame Signal */
196#define M66592_SOF_DISABLE 0x0000 /* SOF OUT Disable */ 196#define M66592_SOF_DISABLE 0x0000 /* SOF OUT Disable */
197 197
198#define M66592_INTSTS0 0x40 198#define M66592_INTSTS0 0x40
199#define M66592_VBINT 0x8000 /* b15: VBUS interrupt */ 199#define M66592_VBINT 0x8000 /* b15: VBUS interrupt */
200#define M66592_RESM 0x4000 /* b14: Resume interrupt */ 200#define M66592_RESM 0x4000 /* b14: Resume interrupt */
201#define M66592_SOFR 0x2000 /* b13: SOF frame update interrupt */ 201#define M66592_SOFR 0x2000 /* b13: SOF frame update interrupt */
202#define M66592_DVST 0x1000 /* b12: Device state transition interrupt */ 202#define M66592_DVST 0x1000 /* b12: Device state transition */
203#define M66592_CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ 203#define M66592_CTRT 0x0800 /* b11: Control stage transition */
204#define M66592_BEMP 0x0400 /* b10: Buffer empty interrupt */ 204#define M66592_BEMP 0x0400 /* b10: Buffer empty interrupt */
205#define M66592_NRDY 0x0200 /* b9: Buffer not ready interrupt */ 205#define M66592_NRDY 0x0200 /* b9: Buffer not ready interrupt */
206#define M66592_BRDY 0x0100 /* b8: Buffer ready interrupt */ 206#define M66592_BRDY 0x0100 /* b8: Buffer ready interrupt */
207#define M66592_VBSTS 0x0080 /* b7: VBUS input port */ 207#define M66592_VBSTS 0x0080 /* b7: VBUS input port */
208#define M66592_DVSQ 0x0070 /* b6-4: Device state */ 208#define M66592_DVSQ 0x0070 /* b6-4: Device state */
209#define M66592_DS_SPD_CNFG 0x0070 /* Suspend Configured */ 209#define M66592_DS_SPD_CNFG 0x0070 /* Suspend Configured */
210#define M66592_DS_SPD_ADDR 0x0060 /* Suspend Address */ 210#define M66592_DS_SPD_ADDR 0x0060 /* Suspend Address */
211#define M66592_DS_SPD_DFLT 0x0050 /* Suspend Default */ 211#define M66592_DS_SPD_DFLT 0x0050 /* Suspend Default */
212#define M66592_DS_SPD_POWR 0x0040 /* Suspend Powered */ 212#define M66592_DS_SPD_POWR 0x0040 /* Suspend Powered */
213#define M66592_DS_SUSP 0x0040 /* Suspend */ 213#define M66592_DS_SUSP 0x0040 /* Suspend */
214#define M66592_DS_CNFG 0x0030 /* Configured */ 214#define M66592_DS_CNFG 0x0030 /* Configured */
215#define M66592_DS_ADDS 0x0020 /* Address */ 215#define M66592_DS_ADDS 0x0020 /* Address */
216#define M66592_DS_DFLT 0x0010 /* Default */ 216#define M66592_DS_DFLT 0x0010 /* Default */
217#define M66592_DS_POWR 0x0000 /* Powered */ 217#define M66592_DS_POWR 0x0000 /* Powered */
218#define M66592_DVSQS 0x0030 /* b5-4: Device state */ 218#define M66592_DVSQS 0x0030 /* b5-4: Device state */
219#define M66592_VALID 0x0008 /* b3: Setup packet detected flag */ 219#define M66592_VALID 0x0008 /* b3: Setup packet detected flag */
220#define M66592_CTSQ 0x0007 /* b2-0: Control transfer stage */ 220#define M66592_CTSQ 0x0007 /* b2-0: Control transfer stage */
221#define M66592_CS_SQER 0x0006 /* Sequence error */ 221#define M66592_CS_SQER 0x0006 /* Sequence error */
222#define M66592_CS_WRND 0x0005 /* Control write nodata status stage */ 222#define M66592_CS_WRND 0x0005 /* Control write nodata status */
223#define M66592_CS_WRSS 0x0004 /* Control write status stage */ 223#define M66592_CS_WRSS 0x0004 /* Control write status stage */
224#define M66592_CS_WRDS 0x0003 /* Control write data stage */ 224#define M66592_CS_WRDS 0x0003 /* Control write data stage */
225#define M66592_CS_RDSS 0x0002 /* Control read status stage */ 225#define M66592_CS_RDSS 0x0002 /* Control read status stage */
226#define M66592_CS_RDDS 0x0001 /* Control read data stage */ 226#define M66592_CS_RDDS 0x0001 /* Control read data stage */
227#define M66592_CS_IDST 0x0000 /* Idle or setup stage */ 227#define M66592_CS_IDST 0x0000 /* Idle or setup stage */
228 228
229#define M66592_INTSTS1 0x42 229#define M66592_INTSTS1 0x42
230#define M66592_BCHG 0x4000 /* b14: USB bus chenge interrupt */ 230#define M66592_BCHG 0x4000 /* b14: USB bus chenge interrupt */
231#define M66592_DTCH 0x1000 /* b12: Detach sense interrupt */ 231#define M66592_DTCH 0x1000 /* b12: Detach sense interrupt */
232#define M66592_SIGN 0x0020 /* b5: SETUP IGNORE interrupt */ 232#define M66592_SIGN 0x0020 /* b5: SETUP IGNORE interrupt */
233#define M66592_SACK 0x0010 /* b4: SETUP ACK interrupt */ 233#define M66592_SACK 0x0010 /* b4: SETUP ACK interrupt */
234 234
235#define M66592_FRMNUM 0x4C 235#define M66592_FRMNUM 0x4C
236#define M66592_OVRN 0x8000 /* b15: Overrun error */ 236#define M66592_OVRN 0x8000 /* b15: Overrun error */
237#define M66592_CRCE 0x4000 /* b14: Received data error */ 237#define M66592_CRCE 0x4000 /* b14: Received data error */
238#define M66592_SOFRM 0x0800 /* b11: SOF output mode */ 238#define M66592_SOFRM 0x0800 /* b11: SOF output mode */
239#define M66592_FRNM 0x07FF /* b10-0: Frame number */ 239#define M66592_FRNM 0x07FF /* b10-0: Frame number */
240 240
241#define M66592_UFRMNUM 0x4E 241#define M66592_UFRMNUM 0x4E
242#define M66592_UFRNM 0x0007 /* b2-0: Micro frame number */ 242#define M66592_UFRNM 0x0007 /* b2-0: Micro frame number */
243 243
244#define M66592_RECOVER 0x50 244#define M66592_RECOVER 0x50
245#define M66592_STSRECOV 0x0700 /* Status recovery */ 245#define M66592_STSRECOV 0x0700 /* Status recovery */
246#define M66592_STSR_HI 0x0400 /* FULL(0) or HI(1) Speed */ 246#define M66592_STSR_HI 0x0400 /* FULL(0) or HI(1) Speed */
247#define M66592_STSR_DEFAULT 0x0100 /* Default state */ 247#define M66592_STSR_DEFAULT 0x0100 /* Default state */
248#define M66592_STSR_ADDRESS 0x0200 /* Address state */ 248#define M66592_STSR_ADDRESS 0x0200 /* Address state */
249#define M66592_STSR_CONFIG 0x0300 /* Configured state */ 249#define M66592_STSR_CONFIG 0x0300 /* Configured state */
250#define M66592_USBADDR 0x007F /* b6-0: USB address */ 250#define M66592_USBADDR 0x007F /* b6-0: USB address */
251 251
252#define M66592_USBREQ 0x54 252#define M66592_USBREQ 0x54
253#define M66592_bRequest 0xFF00 /* b15-8: bRequest */ 253#define M66592_bRequest 0xFF00 /* b15-8: bRequest */
254#define M66592_GET_STATUS 0x0000 254#define M66592_GET_STATUS 0x0000
255#define M66592_CLEAR_FEATURE 0x0100 255#define M66592_CLEAR_FEATURE 0x0100
256#define M66592_ReqRESERVED 0x0200 256#define M66592_ReqRESERVED 0x0200
257#define M66592_SET_FEATURE 0x0300 257#define M66592_SET_FEATURE 0x0300
258#define M66592_ReqRESERVED1 0x0400 258#define M66592_ReqRESERVED1 0x0400
259#define M66592_SET_ADDRESS 0x0500 259#define M66592_SET_ADDRESS 0x0500
260#define M66592_GET_DESCRIPTOR 0x0600 260#define M66592_GET_DESCRIPTOR 0x0600
261#define M66592_SET_DESCRIPTOR 0x0700 261#define M66592_SET_DESCRIPTOR 0x0700
262#define M66592_GET_CONFIGURATION 0x0800 262#define M66592_GET_CONFIGURATION 0x0800
263#define M66592_SET_CONFIGURATION 0x0900 263#define M66592_SET_CONFIGURATION 0x0900
264#define M66592_GET_INTERFACE 0x0A00 264#define M66592_GET_INTERFACE 0x0A00
265#define M66592_SET_INTERFACE 0x0B00 265#define M66592_SET_INTERFACE 0x0B00
266#define M66592_SYNCH_FRAME 0x0C00 266#define M66592_SYNCH_FRAME 0x0C00
267#define M66592_bmRequestType 0x00FF /* b7-0: bmRequestType */ 267#define M66592_bmRequestType 0x00FF /* b7-0: bmRequestType */
268#define M66592_bmRequestTypeDir 0x0080 /* b7 : Data transfer direction */ 268#define M66592_bmRequestTypeDir 0x0080 /* b7 : Data direction */
269#define M66592_HOST_TO_DEVICE 0x0000 269#define M66592_HOST_TO_DEVICE 0x0000
270#define M66592_DEVICE_TO_HOST 0x0080 270#define M66592_DEVICE_TO_HOST 0x0080
271#define M66592_bmRequestTypeType 0x0060 /* b6-5: Type */ 271#define M66592_bmRequestTypeType 0x0060 /* b6-5: Type */
272#define M66592_STANDARD 0x0000 272#define M66592_STANDARD 0x0000
273#define M66592_CLASS 0x0020 273#define M66592_CLASS 0x0020
274#define M66592_VENDOR 0x0040 274#define M66592_VENDOR 0x0040
275#define M66592_bmRequestTypeRecip 0x001F /* b4-0: Recipient */ 275#define M66592_bmRequestTypeRecip 0x001F /* b4-0: Recipient */
276#define M66592_DEVICE 0x0000 276#define M66592_DEVICE 0x0000
277#define M66592_INTERFACE 0x0001 277#define M66592_INTERFACE 0x0001
278#define M66592_ENDPOINT 0x0002 278#define M66592_ENDPOINT 0x0002
279 279
280#define M66592_USBVAL 0x56 280#define M66592_USBVAL 0x56
281#define M66592_wValue 0xFFFF /* b15-0: wValue */ 281#define M66592_wValue 0xFFFF /* b15-0: wValue */
282/* Standard Feature Selector */ 282/* Standard Feature Selector */
283#define M66592_ENDPOINT_HALT 0x0000 283#define M66592_ENDPOINT_HALT 0x0000
284#define M66592_DEVICE_REMOTE_WAKEUP 0x0001 284#define M66592_DEVICE_REMOTE_WAKEUP 0x0001
285#define M66592_TEST_MODE 0x0002 285#define M66592_TEST_MODE 0x0002
286/* Descriptor Types */ 286/* Descriptor Types */
287#define M66592_DT_TYPE 0xFF00 287#define M66592_DT_TYPE 0xFF00
288#define M66592_GET_DT_TYPE(v) (((v) & DT_TYPE) >> 8) 288#define M66592_GET_DT_TYPE(v) (((v) & DT_TYPE) >> 8)
289#define M66592_DT_DEVICE 0x01 289#define M66592_DT_DEVICE 0x01
290#define M66592_DT_CONFIGURATION 0x02 290#define M66592_DT_CONFIGURATION 0x02
291#define M66592_DT_STRING 0x03 291#define M66592_DT_STRING 0x03
292#define M66592_DT_INTERFACE 0x04 292#define M66592_DT_INTERFACE 0x04
293#define M66592_DT_ENDPOINT 0x05 293#define M66592_DT_ENDPOINT 0x05
294#define M66592_DT_DEVICE_QUALIFIER 0x06 294#define M66592_DT_DEVICE_QUALIFIER 0x06
295#define M66592_DT_OTHER_SPEED_CONFIGURATION 0x07 295#define M66592_DT_OTHER_SPEED_CONFIGURATION 0x07
296#define M66592_DT_INTERFACE_POWER 0x08 296#define M66592_DT_INTERFACE_POWER 0x08
297#define M66592_DT_INDEX 0x00FF 297#define M66592_DT_INDEX 0x00FF
298#define M66592_CONF_NUM 0x00FF 298#define M66592_CONF_NUM 0x00FF
299#define M66592_ALT_SET 0x00FF 299#define M66592_ALT_SET 0x00FF
300 300
301#define M66592_USBINDEX 0x58 301#define M66592_USBINDEX 0x58
302#define M66592_wIndex 0xFFFF /* b15-0: wIndex */ 302#define M66592_wIndex 0xFFFF /* b15-0: wIndex */
303#define M66592_TEST_SELECT 0xFF00 /* b15-b8: Test Mode Selectors */ 303#define M66592_TEST_SELECT 0xFF00 /* b15-b8: Test Mode */
304#define M66592_TEST_J 0x0100 /* Test_J */ 304#define M66592_TEST_J 0x0100 /* Test_J */
305#define M66592_TEST_K 0x0200 /* Test_K */ 305#define M66592_TEST_K 0x0200 /* Test_K */
306#define M66592_TEST_SE0_NAK 0x0300 /* Test_SE0_NAK */ 306#define M66592_TEST_SE0_NAK 0x0300 /* Test_SE0_NAK */
307#define M66592_TEST_PACKET 0x0400 /* Test_Packet */ 307#define M66592_TEST_PACKET 0x0400 /* Test_Packet */
308#define M66592_TEST_FORCE_ENABLE 0x0500 /* Test_Force_Enable */ 308#define M66592_TEST_FORCE_ENABLE 0x0500 /* Test_Force_Enable */
309#define M66592_TEST_STSelectors 0x0600 /* Standard test selectors */ 309#define M66592_TEST_STSelectors 0x0600 /* Standard test selectors */
310#define M66592_TEST_Reserved 0x4000 /* Reserved */ 310#define M66592_TEST_Reserved 0x4000 /* Reserved */
311#define M66592_TEST_VSTModes 0xC000 /* Vendor-specific test modes */ 311#define M66592_TEST_VSTModes 0xC000 /* Vendor-specific tests */
312#define M66592_EP_DIR 0x0080 /* b7: Endpoint Direction */ 312#define M66592_EP_DIR 0x0080 /* b7: Endpoint Direction */
313#define M66592_EP_DIR_IN 0x0080 313#define M66592_EP_DIR_IN 0x0080
314#define M66592_EP_DIR_OUT 0x0000 314#define M66592_EP_DIR_OUT 0x0000
315 315
316#define M66592_USBLENG 0x5A 316#define M66592_USBLENG 0x5A
317#define M66592_wLength 0xFFFF /* b15-0: wLength */ 317#define M66592_wLength 0xFFFF /* b15-0: wLength */
318 318
319#define M66592_DCPCFG 0x5C 319#define M66592_DCPCFG 0x5C
320#define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode select */ 320#define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode */
321#define M66592_DIR 0x0010 /* b4: Control transfer DIR select */ 321#define M66592_DIR 0x0010 /* b4: Control transfer DIR select */
322 322
323#define M66592_DCPMAXP 0x5E 323#define M66592_DCPMAXP 0x5E
324#define M66592_DEVSEL 0xC000 /* b15-14: Device address select */ 324#define M66592_DEVSEL 0xC000 /* b15-14: Device address select */
325#define M66592_DEVICE_0 0x0000 /* Device address 0 */ 325#define M66592_DEVICE_0 0x0000 /* Device address 0 */
326#define M66592_DEVICE_1 0x4000 /* Device address 1 */ 326#define M66592_DEVICE_1 0x4000 /* Device address 1 */
327#define M66592_DEVICE_2 0x8000 /* Device address 2 */ 327#define M66592_DEVICE_2 0x8000 /* Device address 2 */
328#define M66592_DEVICE_3 0xC000 /* Device address 3 */ 328#define M66592_DEVICE_3 0xC000 /* Device address 3 */
329#define M66592_MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ 329#define M66592_MAXP 0x007F /* b6-0: Maxpacket size of ep0 */
330 330
331#define M66592_DCPCTR 0x60 331#define M66592_DCPCTR 0x60
332#define M66592_BSTS 0x8000 /* b15: Buffer status */ 332#define M66592_BSTS 0x8000 /* b15: Buffer status */
333#define M66592_SUREQ 0x4000 /* b14: Send USB request */ 333#define M66592_SUREQ 0x4000 /* b14: Send USB request */
334#define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ 334#define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */
335#define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ 335#define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */
336#define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ 336#define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */
337#define M66592_CCPL 0x0004 /* b2: Enable control transfer complete */ 337#define M66592_CCPL 0x0004 /* b2: control transfer complete */
338#define M66592_PID 0x0003 /* b1-0: Response PID */ 338#define M66592_PID 0x0003 /* b1-0: Response PID */
339#define M66592_PID_STALL 0x0002 /* STALL */ 339#define M66592_PID_STALL 0x0002 /* STALL */
340#define M66592_PID_BUF 0x0001 /* BUF */ 340#define M66592_PID_BUF 0x0001 /* BUF */
341#define M66592_PID_NAK 0x0000 /* NAK */ 341#define M66592_PID_NAK 0x0000 /* NAK */
342 342
343#define M66592_PIPESEL 0x64 343#define M66592_PIPESEL 0x64
344#define M66592_PIPENM 0x0007 /* b2-0: Pipe select */ 344#define M66592_PIPENM 0x0007 /* b2-0: Pipe select */
345#define M66592_PIPE0 0x0000 /* PIPE 0 */ 345#define M66592_PIPE0 0x0000 /* PIPE 0 */
346#define M66592_PIPE1 0x0001 /* PIPE 1 */ 346#define M66592_PIPE1 0x0001 /* PIPE 1 */
347#define M66592_PIPE2 0x0002 /* PIPE 2 */ 347#define M66592_PIPE2 0x0002 /* PIPE 2 */
348#define M66592_PIPE3 0x0003 /* PIPE 3 */ 348#define M66592_PIPE3 0x0003 /* PIPE 3 */
349#define M66592_PIPE4 0x0004 /* PIPE 4 */ 349#define M66592_PIPE4 0x0004 /* PIPE 4 */
350#define M66592_PIPE5 0x0005 /* PIPE 5 */ 350#define M66592_PIPE5 0x0005 /* PIPE 5 */
351#define M66592_PIPE6 0x0006 /* PIPE 6 */ 351#define M66592_PIPE6 0x0006 /* PIPE 6 */
352#define M66592_PIPE7 0x0007 /* PIPE 7 */ 352#define M66592_PIPE7 0x0007 /* PIPE 7 */
353 353
354#define M66592_PIPECFG 0x66 354#define M66592_PIPECFG 0x66
355#define M66592_TYP 0xC000 /* b15-14: Transfer type */ 355#define M66592_TYP 0xC000 /* b15-14: Transfer type */
356#define M66592_ISO 0xC000 /* Isochronous */ 356#define M66592_ISO 0xC000 /* Isochronous */
357#define M66592_INT 0x8000 /* Interrupt */ 357#define M66592_INT 0x8000 /* Interrupt */
358#define M66592_BULK 0x4000 /* Bulk */ 358#define M66592_BULK 0x4000 /* Bulk */
359#define M66592_BFRE 0x0400 /* b10: Buffer ready interrupt mode select */ 359#define M66592_BFRE 0x0400 /* b10: Buffer ready interrupt mode */
360#define M66592_DBLB 0x0200 /* b9: Double buffer mode select */ 360#define M66592_DBLB 0x0200 /* b9: Double buffer mode select */
361#define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode select */ 361#define M66592_CNTMD 0x0100 /* b8: Continuous transfer mode */
362#define M66592_SHTNAK 0x0080 /* b7: Transfer end NAK */ 362#define M66592_SHTNAK 0x0080 /* b7: Transfer end NAK */
363#define M66592_DIR 0x0010 /* b4: Transfer direction select */ 363#define M66592_DIR 0x0010 /* b4: Transfer direction select */
364#define M66592_DIR_H_OUT 0x0010 /* HOST OUT */ 364#define M66592_DIR_H_OUT 0x0010 /* HOST OUT */
365#define M66592_DIR_P_IN 0x0010 /* PERI IN */ 365#define M66592_DIR_P_IN 0x0010 /* PERI IN */
366#define M66592_DIR_H_IN 0x0000 /* HOST IN */ 366#define M66592_DIR_H_IN 0x0000 /* HOST IN */
367#define M66592_DIR_P_OUT 0x0000 /* PERI OUT */ 367#define M66592_DIR_P_OUT 0x0000 /* PERI OUT */
368#define M66592_EPNUM 0x000F /* b3-0: Eendpoint number select */ 368#define M66592_EPNUM 0x000F /* b3-0: Eendpoint number select */
369#define M66592_EP1 0x0001 369#define M66592_EP1 0x0001
370#define M66592_EP2 0x0002 370#define M66592_EP2 0x0002
371#define M66592_EP3 0x0003 371#define M66592_EP3 0x0003
372#define M66592_EP4 0x0004 372#define M66592_EP4 0x0004
373#define M66592_EP5 0x0005 373#define M66592_EP5 0x0005
374#define M66592_EP6 0x0006 374#define M66592_EP6 0x0006
375#define M66592_EP7 0x0007 375#define M66592_EP7 0x0007
376#define M66592_EP8 0x0008 376#define M66592_EP8 0x0008
377#define M66592_EP9 0x0009 377#define M66592_EP9 0x0009
378#define M66592_EP10 0x000A 378#define M66592_EP10 0x000A
379#define M66592_EP11 0x000B 379#define M66592_EP11 0x000B
380#define M66592_EP12 0x000C 380#define M66592_EP12 0x000C
381#define M66592_EP13 0x000D 381#define M66592_EP13 0x000D
382#define M66592_EP14 0x000E 382#define M66592_EP14 0x000E
383#define M66592_EP15 0x000F 383#define M66592_EP15 0x000F
384 384
385#define M66592_PIPEBUF 0x68 385#define M66592_PIPEBUF 0x68
386#define M66592_BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */ 386#define M66592_BUFSIZE 0x7C00 /* b14-10: Pipe buffer size */
387#define M66592_BUF_SIZE(x) ((((x) / 64) - 1) << 10) 387#define M66592_BUF_SIZE(x) ((((x) / 64) - 1) << 10)
388#define M66592_BUFNMB 0x00FF /* b7-0: Pipe buffer number */ 388#define M66592_BUFNMB 0x00FF /* b7-0: Pipe buffer number */
389 389
390#define M66592_PIPEMAXP 0x6A 390#define M66592_PIPEMAXP 0x6A
391#define M66592_MXPS 0x07FF /* b10-0: Maxpacket size */ 391#define M66592_MXPS 0x07FF /* b10-0: Maxpacket size */
392 392
393#define M66592_PIPEPERI 0x6C 393#define M66592_PIPEPERI 0x6C
394#define M66592_IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ 394#define M66592_IFIS 0x1000 /* b12: ISO in-buffer flush mode */
395#define M66592_IITV 0x0007 /* b2-0: Isochronous interval */ 395#define M66592_IITV 0x0007 /* b2-0: ISO interval */
396 396
397#define M66592_PIPE1CTR 0x70 397#define M66592_PIPE1CTR 0x70
398#define M66592_PIPE2CTR 0x72 398#define M66592_PIPE2CTR 0x72
@@ -401,19 +401,17 @@
401#define M66592_PIPE5CTR 0x78 401#define M66592_PIPE5CTR 0x78
402#define M66592_PIPE6CTR 0x7A 402#define M66592_PIPE6CTR 0x7A
403#define M66592_PIPE7CTR 0x7C 403#define M66592_PIPE7CTR 0x7C
404#define M66592_BSTS 0x8000 /* b15: Buffer status */ 404#define M66592_BSTS 0x8000 /* b15: Buffer status */
405#define M66592_INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ 405#define M66592_INBUFM 0x4000 /* b14: IN buffer monitor (PIPE 1-5) */
406#define M66592_ACLRM 0x0200 /* b9: Out buffer auto clear mode */ 406#define M66592_ACLRM 0x0200 /* b9: Out buffer auto clear mode */
407#define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */ 407#define M66592_SQCLR 0x0100 /* b8: Sequence toggle bit clear */
408#define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */ 408#define M66592_SQSET 0x0080 /* b7: Sequence toggle bit set */
409#define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */ 409#define M66592_SQMON 0x0040 /* b6: Sequence toggle bit monitor */
410#define M66592_PID 0x0003 /* b1-0: Response PID */ 410#define M66592_PID 0x0003 /* b1-0: Response PID */
411 411
412#define M66592_INVALID_REG 0x7E 412#define M66592_INVALID_REG 0x7E
413 413
414 414
415#define __iomem
416
417#define get_pipectr_addr(pipenum) (M66592_PIPE1CTR + (pipenum - 1) * 2) 415#define get_pipectr_addr(pipenum) (M66592_PIPE1CTR + (pipenum - 1) * 2)
418 416
419#define M66592_MAX_SAMPLING 10 417#define M66592_MAX_SAMPLING 10
@@ -449,7 +447,7 @@ struct m66592_ep {
449 struct m66592 *m66592; 447 struct m66592 *m66592;
450 448
451 struct list_head queue; 449 struct list_head queue;
452 unsigned busy:1; 450 unsigned busy:1;
453 unsigned internal_ccpl:1; /* use only control */ 451 unsigned internal_ccpl:1; /* use only control */
454 452
455 /* this member can able to after m66592_enable */ 453 /* this member can able to after m66592_enable */
@@ -477,7 +475,7 @@ struct m66592 {
477 struct m66592_ep *epaddr2ep[16]; 475 struct m66592_ep *epaddr2ep[16];
478 476
479 struct usb_request *ep0_req; /* for internal request */ 477 struct usb_request *ep0_req; /* for internal request */
480 u16 *ep0_buf; /* for internal request */ 478 u16 ep0_data; /* for internal request */
481 479
482 struct timer_list timer; 480 struct timer_list timer;
483 481
@@ -527,8 +525,8 @@ static inline u16 m66592_read(struct m66592 *m66592, unsigned long offset)
527} 525}
528 526
529static inline void m66592_read_fifo(struct m66592 *m66592, 527static inline void m66592_read_fifo(struct m66592 *m66592,
530 unsigned long offset, 528 unsigned long offset,
531 void *buf, unsigned long len) 529 void *buf, unsigned long len)
532{ 530{
533 unsigned long fifoaddr = (unsigned long)m66592->reg + offset; 531 unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
534 532
@@ -543,8 +541,8 @@ static inline void m66592_write(struct m66592 *m66592, u16 val,
543} 541}
544 542
545static inline void m66592_write_fifo(struct m66592 *m66592, 543static inline void m66592_write_fifo(struct m66592 *m66592,
546 unsigned long offset, 544 unsigned long offset,
547 void *buf, unsigned long len) 545 void *buf, unsigned long len)
548{ 546{
549 unsigned long fifoaddr = (unsigned long)m66592->reg + offset; 547 unsigned long fifoaddr = (unsigned long)m66592->reg + offset;
550 unsigned long odd = len & 0x0001; 548 unsigned long odd = len & 0x0001;
@@ -558,7 +556,7 @@ static inline void m66592_write_fifo(struct m66592 *m66592,
558} 556}
559 557
560static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat, 558static inline void m66592_mdfy(struct m66592 *m66592, u16 val, u16 pat,
561 unsigned long offset) 559 unsigned long offset)
562{ 560{
563 u16 tmp; 561 u16 tmp;
564 tmp = m66592_read(m66592, offset); 562 tmp = m66592_read(m66592, offset);
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 38138bb9ddb0..9cd98e73dc1d 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -33,6 +33,7 @@
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/tty.h> 34#include <linux/tty.h>
35#include <linux/tty_flip.h> 35#include <linux/tty_flip.h>
36#include <linux/mutex.h>
36 37
37#include <asm/byteorder.h> 38#include <asm/byteorder.h>
38#include <asm/io.h> 39#include <asm/io.h>
@@ -258,7 +259,7 @@ static const char *EP_IN_NAME;
258static const char *EP_OUT_NAME; 259static const char *EP_OUT_NAME;
259static const char *EP_NOTIFY_NAME; 260static const char *EP_NOTIFY_NAME;
260 261
261static struct semaphore gs_open_close_sem[GS_NUM_PORTS]; 262static struct mutex gs_open_close_lock[GS_NUM_PORTS];
262 263
263static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE; 264static unsigned int read_q_size = GS_DEFAULT_READ_Q_SIZE;
264static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE; 265static unsigned int write_q_size = GS_DEFAULT_WRITE_Q_SIZE;
@@ -595,7 +596,7 @@ static int __init gs_module_init(void)
595 tty_set_operations(gs_tty_driver, &gs_tty_ops); 596 tty_set_operations(gs_tty_driver, &gs_tty_ops);
596 597
597 for (i=0; i < GS_NUM_PORTS; i++) 598 for (i=0; i < GS_NUM_PORTS; i++)
598 sema_init(&gs_open_close_sem[i], 1); 599 mutex_init(&gs_open_close_lock[i]);
599 600
600 retval = tty_register_driver(gs_tty_driver); 601 retval = tty_register_driver(gs_tty_driver);
601 if (retval) { 602 if (retval) {
@@ -635,7 +636,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
635 struct gs_port *port; 636 struct gs_port *port;
636 struct gs_dev *dev; 637 struct gs_dev *dev;
637 struct gs_buf *buf; 638 struct gs_buf *buf;
638 struct semaphore *sem; 639 struct mutex *mtx;
639 int ret; 640 int ret;
640 641
641 port_num = tty->index; 642 port_num = tty->index;
@@ -656,10 +657,10 @@ static int gs_open(struct tty_struct *tty, struct file *file)
656 return -ENODEV; 657 return -ENODEV;
657 } 658 }
658 659
659 sem = &gs_open_close_sem[port_num]; 660 mtx = &gs_open_close_lock[port_num];
660 if (down_interruptible(sem)) { 661 if (mutex_lock_interruptible(mtx)) {
661 printk(KERN_ERR 662 printk(KERN_ERR
662 "gs_open: (%d,%p,%p) interrupted waiting for semaphore\n", 663 "gs_open: (%d,%p,%p) interrupted waiting for mutex\n",
663 port_num, tty, file); 664 port_num, tty, file);
664 return -ERESTARTSYS; 665 return -ERESTARTSYS;
665 } 666 }
@@ -754,12 +755,12 @@ static int gs_open(struct tty_struct *tty, struct file *file)
754 755
755exit_unlock_port: 756exit_unlock_port:
756 spin_unlock_irqrestore(&port->port_lock, flags); 757 spin_unlock_irqrestore(&port->port_lock, flags);
757 up(sem); 758 mutex_unlock(mtx);
758 return ret; 759 return ret;
759 760
760exit_unlock_dev: 761exit_unlock_dev:
761 spin_unlock_irqrestore(&dev->dev_lock, flags); 762 spin_unlock_irqrestore(&dev->dev_lock, flags);
762 up(sem); 763 mutex_unlock(mtx);
763 return ret; 764 return ret;
764 765
765} 766}
@@ -781,7 +782,7 @@ exit_unlock_dev:
781static void gs_close(struct tty_struct *tty, struct file *file) 782static void gs_close(struct tty_struct *tty, struct file *file)
782{ 783{
783 struct gs_port *port = tty->driver_data; 784 struct gs_port *port = tty->driver_data;
784 struct semaphore *sem; 785 struct mutex *mtx;
785 786
786 if (port == NULL) { 787 if (port == NULL) {
787 printk(KERN_ERR "gs_close: NULL port pointer\n"); 788 printk(KERN_ERR "gs_close: NULL port pointer\n");
@@ -790,8 +791,8 @@ static void gs_close(struct tty_struct *tty, struct file *file)
790 791
791 gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file); 792 gs_debug("gs_close: (%d,%p,%p)\n", port->port_num, tty, file);
792 793
793 sem = &gs_open_close_sem[port->port_num]; 794 mtx = &gs_open_close_lock[port->port_num];
794 down(sem); 795 mutex_lock(mtx);
795 796
796 spin_lock_irq(&port->port_lock); 797 spin_lock_irq(&port->port_lock);
797 798
@@ -846,7 +847,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
846 847
847exit: 848exit:
848 spin_unlock_irq(&port->port_lock); 849 spin_unlock_irq(&port->port_lock);
849 up(sem); 850 mutex_unlock(mtx);
850} 851}
851 852
852/* 853/*
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 46873f2534b5..5c851a36de72 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -228,7 +228,6 @@ static void preproc_atl_queue(struct isp116x *isp116x)
228 struct urb, urb_list); 228 struct urb, urb_list);
229 ptd = &ep->ptd; 229 ptd = &ep->ptd;
230 len = ep->length; 230 len = ep->length;
231 spin_lock(&urb->lock);
232 ep->data = (unsigned char *)urb->transfer_buffer 231 ep->data = (unsigned char *)urb->transfer_buffer
233 + urb->actual_length; 232 + urb->actual_length;
234 233
@@ -264,7 +263,6 @@ static void preproc_atl_queue(struct isp116x *isp116x)
264 | PTD_EP(ep->epnum); 263 | PTD_EP(ep->epnum);
265 ptd->len = PTD_LEN(len) | PTD_DIR(dir); 264 ptd->len = PTD_LEN(len) | PTD_DIR(dir);
266 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe)); 265 ptd->faddr = PTD_FA(usb_pipedevice(urb->pipe));
267 spin_unlock(&urb->lock);
268 if (!ep->active) { 266 if (!ep->active) {
269 ptd->mps |= PTD_LAST_MSK; 267 ptd->mps |= PTD_LAST_MSK;
270 isp116x->atl_last_dir = dir; 268 isp116x->atl_last_dir = dir;
@@ -275,6 +273,61 @@ static void preproc_atl_queue(struct isp116x *isp116x)
275} 273}
276 274
277/* 275/*
276 Take done or failed requests out of schedule. Give back
277 processed urbs.
278*/
279static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
280 struct urb *urb)
281__releases(isp116x->lock) __acquires(isp116x->lock)
282{
283 unsigned i;
284
285 urb->hcpriv = NULL;
286 ep->error_count = 0;
287
288 if (usb_pipecontrol(urb->pipe))
289 ep->nextpid = USB_PID_SETUP;
290
291 urb_dbg(urb, "Finish");
292
293 spin_unlock(&isp116x->lock);
294 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb);
295 spin_lock(&isp116x->lock);
296
297 /* take idle endpoints out of the schedule */
298 if (!list_empty(&ep->hep->urb_list))
299 return;
300
301 /* async deschedule */
302 if (!list_empty(&ep->schedule)) {
303 list_del_init(&ep->schedule);
304 return;
305 }
306
307 /* periodic deschedule */
308 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
309 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
310 struct isp116x_ep *temp;
311 struct isp116x_ep **prev = &isp116x->periodic[i];
312
313 while (*prev && ((temp = *prev) != ep))
314 prev = &temp->next;
315 if (*prev)
316 *prev = ep->next;
317 isp116x->load[i] -= ep->load;
318 }
319 ep->branch = PERIODIC_SIZE;
320 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
321 ep->load / ep->period;
322
323 /* switch irq type? */
324 if (!--isp116x->periodic_count) {
325 isp116x->irqenb &= ~HCuPINT_SOF;
326 isp116x->irqenb |= HCuPINT_ATL;
327 }
328}
329
330/*
278 Analyze transfer results, handle partial transfers and errors 331 Analyze transfer results, handle partial transfers and errors
279*/ 332*/
280static void postproc_atl_queue(struct isp116x *isp116x) 333static void postproc_atl_queue(struct isp116x *isp116x)
@@ -284,6 +337,7 @@ static void postproc_atl_queue(struct isp116x *isp116x)
284 struct usb_device *udev; 337 struct usb_device *udev;
285 struct ptd *ptd; 338 struct ptd *ptd;
286 int short_not_ok; 339 int short_not_ok;
340 int status;
287 u8 cc; 341 u8 cc;
288 342
289 for (ep = isp116x->atl_active; ep; ep = ep->active) { 343 for (ep = isp116x->atl_active; ep; ep = ep->active) {
@@ -294,7 +348,7 @@ static void postproc_atl_queue(struct isp116x *isp116x)
294 ptd = &ep->ptd; 348 ptd = &ep->ptd;
295 cc = PTD_GET_CC(ptd); 349 cc = PTD_GET_CC(ptd);
296 short_not_ok = 1; 350 short_not_ok = 1;
297 spin_lock(&urb->lock); 351 status = -EINPROGRESS;
298 352
299 /* Data underrun is special. For allowed underrun 353 /* Data underrun is special. For allowed underrun
300 we clear the error and continue as normal. For 354 we clear the error and continue as normal. For
@@ -302,47 +356,36 @@ static void postproc_atl_queue(struct isp116x *isp116x)
302 immediately while for control transfer, 356 immediately while for control transfer,
303 we do a STATUS stage. */ 357 we do a STATUS stage. */
304 if (cc == TD_DATAUNDERRUN) { 358 if (cc == TD_DATAUNDERRUN) {
305 if (!(urb->transfer_flags & URB_SHORT_NOT_OK)) { 359 if (!(urb->transfer_flags & URB_SHORT_NOT_OK) ||
306 DBG("Allowed data underrun\n"); 360 usb_pipecontrol(urb->pipe)) {
361 DBG("Allowed or control data underrun\n");
307 cc = TD_CC_NOERROR; 362 cc = TD_CC_NOERROR;
308 short_not_ok = 0; 363 short_not_ok = 0;
309 } else { 364 } else {
310 ep->error_count = 1; 365 ep->error_count = 1;
311 if (usb_pipecontrol(urb->pipe)) 366 usb_settoggle(udev, ep->epnum,
312 ep->nextpid = USB_PID_ACK; 367 ep->nextpid == USB_PID_OUT,
313 else 368 PTD_GET_TOGGLE(ptd));
314 usb_settoggle(udev, ep->epnum,
315 ep->nextpid ==
316 USB_PID_OUT,
317 PTD_GET_TOGGLE(ptd));
318 urb->actual_length += PTD_GET_COUNT(ptd); 369 urb->actual_length += PTD_GET_COUNT(ptd);
319 urb->status = cc_to_error[TD_DATAUNDERRUN]; 370 status = cc_to_error[TD_DATAUNDERRUN];
320 spin_unlock(&urb->lock); 371 goto done;
321 continue;
322 } 372 }
323 } 373 }
324 /* Keep underrun error through the STATUS stage */
325 if (urb->status == cc_to_error[TD_DATAUNDERRUN])
326 cc = TD_DATAUNDERRUN;
327 374
328 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED 375 if (cc != TD_CC_NOERROR && cc != TD_NOTACCESSED
329 && (++ep->error_count >= 3 || cc == TD_CC_STALL 376 && (++ep->error_count >= 3 || cc == TD_CC_STALL
330 || cc == TD_DATAOVERRUN)) { 377 || cc == TD_DATAOVERRUN)) {
331 if (urb->status == -EINPROGRESS) 378 status = cc_to_error[cc];
332 urb->status = cc_to_error[cc];
333 if (ep->nextpid == USB_PID_ACK) 379 if (ep->nextpid == USB_PID_ACK)
334 ep->nextpid = 0; 380 ep->nextpid = 0;
335 spin_unlock(&urb->lock); 381 goto done;
336 continue;
337 } 382 }
338 /* According to usb spec, zero-length Int transfer signals 383 /* According to usb spec, zero-length Int transfer signals
339 finishing of the urb. Hey, does this apply only 384 finishing of the urb. Hey, does this apply only
340 for IN endpoints? */ 385 for IN endpoints? */
341 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) { 386 if (usb_pipeint(urb->pipe) && !PTD_GET_LEN(ptd)) {
342 if (urb->status == -EINPROGRESS) 387 status = 0;
343 urb->status = 0; 388 goto done;
344 spin_unlock(&urb->lock);
345 continue;
346 } 389 }
347 390
348 /* Relax after previously failed, but later succeeded 391 /* Relax after previously failed, but later succeeded
@@ -381,8 +424,8 @@ static void postproc_atl_queue(struct isp116x *isp116x)
381 /* All data for this URB is transferred, let's finish */ 424 /* All data for this URB is transferred, let's finish */
382 if (usb_pipecontrol(urb->pipe)) 425 if (usb_pipecontrol(urb->pipe))
383 ep->nextpid = USB_PID_ACK; 426 ep->nextpid = USB_PID_ACK;
384 else if (urb->status == -EINPROGRESS) 427 else
385 urb->status = 0; 428 status = 0;
386 break; 429 break;
387 case USB_PID_SETUP: 430 case USB_PID_SETUP:
388 if (PTD_GET_ACTIVE(ptd) 431 if (PTD_GET_ACTIVE(ptd)
@@ -402,69 +445,27 @@ static void postproc_atl_queue(struct isp116x *isp116x)
402 if (PTD_GET_ACTIVE(ptd) 445 if (PTD_GET_ACTIVE(ptd)
403 || (cc != TD_CC_NOERROR && cc < 0x0E)) 446 || (cc != TD_CC_NOERROR && cc < 0x0E))
404 break; 447 break;
405 if (urb->status == -EINPROGRESS) 448 if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
406 urb->status = 0; 449 urb->actual_length <
450 urb->transfer_buffer_length)
451 status = -EREMOTEIO;
452 else
453 status = 0;
407 ep->nextpid = 0; 454 ep->nextpid = 0;
408 break; 455 break;
409 default: 456 default:
410 BUG(); 457 BUG();
411 } 458 }
412 spin_unlock(&urb->lock);
413 }
414}
415
416/*
417 Take done or failed requests out of schedule. Give back
418 processed urbs.
419*/
420static void finish_request(struct isp116x *isp116x, struct isp116x_ep *ep,
421 struct urb *urb)
422__releases(isp116x->lock) __acquires(isp116x->lock)
423{
424 unsigned i;
425
426 urb->hcpriv = NULL;
427 ep->error_count = 0;
428
429 if (usb_pipecontrol(urb->pipe))
430 ep->nextpid = USB_PID_SETUP;
431
432 urb_dbg(urb, "Finish");
433
434 spin_unlock(&isp116x->lock);
435 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb);
436 spin_lock(&isp116x->lock);
437
438 /* take idle endpoints out of the schedule */
439 if (!list_empty(&ep->hep->urb_list))
440 return;
441
442 /* async deschedule */
443 if (!list_empty(&ep->schedule)) {
444 list_del_init(&ep->schedule);
445 return;
446 }
447 459
448 /* periodic deschedule */ 460 done:
449 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch); 461 if (status != -EINPROGRESS) {
450 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) { 462 spin_lock(&urb->lock);
451 struct isp116x_ep *temp; 463 if (urb->status == -EINPROGRESS)
452 struct isp116x_ep **prev = &isp116x->periodic[i]; 464 urb->status = status;
453 465 spin_unlock(&urb->lock);
454 while (*prev && ((temp = *prev) != ep)) 466 }
455 prev = &temp->next; 467 if (urb->status != -EINPROGRESS)
456 if (*prev) 468 finish_request(isp116x, ep, urb);
457 *prev = ep->next;
458 isp116x->load[i] -= ep->load;
459 }
460 ep->branch = PERIODIC_SIZE;
461 isp116x_to_hcd(isp116x)->self.bandwidth_allocated -=
462 ep->load / ep->period;
463
464 /* switch irq type? */
465 if (!--isp116x->periodic_count) {
466 isp116x->irqenb &= ~HCuPINT_SOF;
467 isp116x->irqenb |= HCuPINT_ATL;
468 } 469 }
469} 470}
470 471
@@ -570,9 +571,6 @@ static void start_atl_transfers(struct isp116x *isp116x)
570*/ 571*/
571static void finish_atl_transfers(struct isp116x *isp116x) 572static void finish_atl_transfers(struct isp116x *isp116x)
572{ 573{
573 struct isp116x_ep *ep;
574 struct urb *urb;
575
576 if (!isp116x->atl_active) 574 if (!isp116x->atl_active)
577 return; 575 return;
578 /* Fifo not ready? */ 576 /* Fifo not ready? */
@@ -582,16 +580,6 @@ static void finish_atl_transfers(struct isp116x *isp116x)
582 atomic_inc(&isp116x->atl_finishing); 580 atomic_inc(&isp116x->atl_finishing);
583 unpack_fifo(isp116x); 581 unpack_fifo(isp116x);
584 postproc_atl_queue(isp116x); 582 postproc_atl_queue(isp116x);
585 for (ep = isp116x->atl_active; ep; ep = ep->active) {
586 urb =
587 container_of(ep->hep->urb_list.next, struct urb, urb_list);
588 /* USB_PID_ACK check here avoids finishing of
589 control transfers, for which TD_DATAUNDERRUN
590 occured, while URB_SHORT_NOT_OK was set */
591 if (urb && urb->status != -EINPROGRESS
592 && ep->nextpid != USB_PID_ACK)
593 finish_request(isp116x, ep, urb);
594 }
595 atomic_dec(&isp116x->atl_finishing); 583 atomic_dec(&isp116x->atl_finishing);
596} 584}
597 585
@@ -821,15 +809,12 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
821 } 809 }
822 810
823 /* in case of unlink-during-submit */ 811 /* in case of unlink-during-submit */
824 spin_lock(&urb->lock);
825 if (urb->status != -EINPROGRESS) { 812 if (urb->status != -EINPROGRESS) {
826 spin_unlock(&urb->lock);
827 finish_request(isp116x, ep, urb); 813 finish_request(isp116x, ep, urb);
828 ret = 0; 814 ret = 0;
829 goto fail; 815 goto fail;
830 } 816 }
831 urb->hcpriv = hep; 817 urb->hcpriv = hep;
832 spin_unlock(&urb->lock);
833 start_atl_transfers(isp116x); 818 start_atl_transfers(isp116x);
834 819
835 fail: 820 fail:
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index a7a7070c6e2a..d60f1985320c 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -35,10 +35,8 @@
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/platform_device.h> 37#include <linux/platform_device.h>
38 38#include <linux/io.h>
39#include <asm/io.h> 39#include <linux/irq.h>
40#include <asm/irq.h>
41#include <asm/system.h>
42 40
43#include "../core/hcd.h" 41#include "../core/hcd.h"
44#include "r8a66597.h" 42#include "r8a66597.h"
@@ -54,16 +52,21 @@ static const char hcd_name[] = "r8a66597_hcd";
54/* module parameters */ 52/* module parameters */
55static unsigned short clock = XTAL12; 53static unsigned short clock = XTAL12;
56module_param(clock, ushort, 0644); 54module_param(clock, ushort, 0644);
57MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0(default=0)"); 55MODULE_PARM_DESC(clock, "input clock: 48MHz=32768, 24MHz=16384, 12MHz=0 "
56 "(default=0)");
57
58static unsigned short vif = LDRV; 58static unsigned short vif = LDRV;
59module_param(vif, ushort, 0644); 59module_param(vif, ushort, 0644);
60MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)"); 60MODULE_PARM_DESC(vif, "input VIF: 3.3V=32768, 1.5V=0(default=32768)");
61static unsigned short endian = 0; 61
62static unsigned short endian;
62module_param(endian, ushort, 0644); 63module_param(endian, ushort, 0644);
63MODULE_PARM_DESC(endian, "data endian: big=256, little=0(default=0)"); 64MODULE_PARM_DESC(endian, "data endian: big=256, little=0 (default=0)");
65
64static unsigned short irq_sense = INTL; 66static unsigned short irq_sense = INTL;
65module_param(irq_sense, ushort, 0644); 67module_param(irq_sense, ushort, 0644);
66MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0(default=32)"); 68MODULE_PARM_DESC(irq_sense, "IRQ sense: low level=32, falling edge=0 "
69 "(default=32)");
67 70
68static void packet_write(struct r8a66597 *r8a66597, u16 pipenum); 71static void packet_write(struct r8a66597 *r8a66597, u16 pipenum);
69static int r8a66597_get_frame(struct usb_hcd *hcd); 72static int r8a66597_get_frame(struct usb_hcd *hcd);
@@ -308,7 +311,7 @@ static int make_r8a66597_device(struct r8a66597 *r8a66597,
308 struct r8a66597_device *dev; 311 struct r8a66597_device *dev;
309 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */ 312 int usb_address = urb->setup_packet[2]; /* urb->pipe is address 0 */
310 313
311 dev = kzalloc(sizeof(struct r8a66597_device), GFP_KERNEL); 314 dev = kzalloc(sizeof(struct r8a66597_device), GFP_ATOMIC);
312 if (dev == NULL) 315 if (dev == NULL)
313 return -ENOMEM; 316 return -ENOMEM;
314 317
@@ -611,33 +614,33 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
611 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; 614 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
612 615
613 memset(array, 0, sizeof(array)); 616 memset(array, 0, sizeof(array));
614 switch(ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 617 switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
615 case USB_ENDPOINT_XFER_BULK: 618 case USB_ENDPOINT_XFER_BULK:
616 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 619 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
617 array[i++] = 4; 620 array[i++] = 4;
618 else { 621 else {
619 array[i++] = 3; 622 array[i++] = 3;
620 array[i++] = 5; 623 array[i++] = 5;
621 } 624 }
622 break; 625 break;
623 case USB_ENDPOINT_XFER_INT: 626 case USB_ENDPOINT_XFER_INT:
624 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { 627 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) {
625 array[i++] = 6; 628 array[i++] = 6;
626 array[i++] = 7; 629 array[i++] = 7;
627 array[i++] = 8; 630 array[i++] = 8;
628 } else 631 } else
629 array[i++] = 9; 632 array[i++] = 9;
630 break; 633 break;
631 case USB_ENDPOINT_XFER_ISOC: 634 case USB_ENDPOINT_XFER_ISOC:
632 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 635 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
633 array[i++] = 2; 636 array[i++] = 2;
634 else 637 else
635 array[i++] = 1; 638 array[i++] = 1;
636 break; 639 break;
637 default: 640 default:
638 err("Illegal type"); 641 err("Illegal type");
639 return 0; 642 return 0;
640 } 643 }
641 644
642 i = 1; 645 i = 1;
643 min = array[0]; 646 min = array[0];
@@ -654,7 +657,7 @@ static u16 get_r8a66597_type(__u8 type)
654{ 657{
655 u16 r8a66597_type; 658 u16 r8a66597_type;
656 659
657 switch(type) { 660 switch (type) {
658 case USB_ENDPOINT_XFER_BULK: 661 case USB_ENDPOINT_XFER_BULK:
659 r8a66597_type = R8A66597_BULK; 662 r8a66597_type = R8A66597_BULK;
660 break; 663 break;
@@ -874,7 +877,7 @@ static void r8a66597_usb_preconnect(struct r8a66597 *r8a66597, int port)
874{ 877{
875 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION) 878 r8a66597->root_hub[port].port |= (1 << USB_PORT_FEAT_CONNECTION)
876 | (1 << USB_PORT_FEAT_C_CONNECTION); 879 | (1 << USB_PORT_FEAT_C_CONNECTION);
877 r8a66597_write(r8a66597, (u16)~DTCH, get_intsts_reg(port)); 880 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
878 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); 881 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
879} 882}
880 883
@@ -917,7 +920,7 @@ static void prepare_setup_packet(struct r8a66597 *r8a66597,
917 920
918 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket, 921 r8a66597_write(r8a66597, make_devsel(td->address) | td->maxpacket,
919 DCPMAXP); 922 DCPMAXP);
920 r8a66597_write(r8a66597, (u16)~(SIGN | SACK), INTSTS1); 923 r8a66597_write(r8a66597, ~(SIGN | SACK), INTSTS1);
921 924
922 for (i = 0; i < 4; i++) { 925 for (i = 0; i < 4; i++) {
923 r8a66597_write(r8a66597, p[i], setup_addr); 926 r8a66597_write(r8a66597, p[i], setup_addr);
@@ -948,19 +951,18 @@ static void prepare_packet_read(struct r8a66597 *r8a66597,
948 pipe_irq_disable(r8a66597, td->pipenum); 951 pipe_irq_disable(r8a66597, td->pipenum);
949 pipe_setting(r8a66597, td); 952 pipe_setting(r8a66597, td);
950 pipe_stop(r8a66597, td->pipe); 953 pipe_stop(r8a66597, td->pipe);
951 r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), 954 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
952 BRDYSTS);
953 955
954 if (td->pipe->pipetre) { 956 if (td->pipe->pipetre) {
955 r8a66597_write(r8a66597, TRCLR, 957 r8a66597_write(r8a66597, TRCLR,
956 td->pipe->pipetre); 958 td->pipe->pipetre);
957 r8a66597_write(r8a66597, 959 r8a66597_write(r8a66597,
958 (urb->transfer_buffer_length 960 (urb->transfer_buffer_length
959 + td->maxpacket - 1) 961 + td->maxpacket - 1)
960 / td->maxpacket, 962 / td->maxpacket,
961 td->pipe->pipetrn); 963 td->pipe->pipetrn);
962 r8a66597_bset(r8a66597, TRENB, 964 r8a66597_bset(r8a66597, TRENB,
963 td->pipe->pipetre); 965 td->pipe->pipetre);
964 } 966 }
965 967
966 pipe_start(r8a66597, td->pipe); 968 pipe_start(r8a66597, td->pipe);
@@ -991,7 +993,7 @@ static void prepare_packet_write(struct r8a66597 *r8a66597,
991 if (td->pipe->pipetre) 993 if (td->pipe->pipetre)
992 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre); 994 r8a66597_bclr(r8a66597, TRENB, td->pipe->pipetre);
993 } 995 }
994 r8a66597_write(r8a66597, (u16)~(1 << td->pipenum), BRDYSTS); 996 r8a66597_write(r8a66597, ~(1 << td->pipenum), BRDYSTS);
995 997
996 fifo_change_from_pipe(r8a66597, td->pipe); 998 fifo_change_from_pipe(r8a66597, td->pipe);
997 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr); 999 tmp = r8a66597_read(r8a66597, td->pipe->fifoctr);
@@ -1009,21 +1011,21 @@ static void prepare_status_packet(struct r8a66597 *r8a66597,
1009 struct urb *urb = td->urb; 1011 struct urb *urb = td->urb;
1010 1012
1011 r8a66597_pipe_toggle(r8a66597, td->pipe, 1); 1013 r8a66597_pipe_toggle(r8a66597, td->pipe, 1);
1014 pipe_stop(r8a66597, td->pipe);
1012 1015
1013 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) { 1016 if (urb->setup_packet[0] & USB_ENDPOINT_DIR_MASK) {
1014 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG); 1017 r8a66597_bset(r8a66597, R8A66597_DIR, DCPCFG);
1015 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL); 1018 r8a66597_mdfy(r8a66597, ISEL, ISEL | CURPIPE, CFIFOSEL);
1016 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); 1019 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1017 r8a66597_write(r8a66597, BVAL | BCLR, CFIFOCTR); 1020 r8a66597_write(r8a66597, ~BEMP0, BEMPSTS);
1018 r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS); 1021 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1022 r8a66597_write(r8a66597, BVAL, CFIFOCTR);
1019 enable_irq_empty(r8a66597, 0); 1023 enable_irq_empty(r8a66597, 0);
1020 } else { 1024 } else {
1021 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG); 1025 r8a66597_bclr(r8a66597, R8A66597_DIR, DCPCFG);
1022 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL); 1026 r8a66597_mdfy(r8a66597, 0, ISEL | CURPIPE, CFIFOSEL);
1023 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0); 1027 r8a66597_reg_wait(r8a66597, CFIFOSEL, CURPIPE, 0);
1024 r8a66597_write(r8a66597, BCLR, CFIFOCTR); 1028 r8a66597_write(r8a66597, BCLR, CFIFOCTR);
1025 r8a66597_write(r8a66597, (u16)~BRDY0, BRDYSTS);
1026 r8a66597_write(r8a66597, (u16)~BEMP0, BEMPSTS);
1027 enable_irq_ready(r8a66597, 0); 1029 enable_irq_ready(r8a66597, 0);
1028 } 1030 }
1029 enable_irq_nrdy(r8a66597, 0); 1031 enable_irq_nrdy(r8a66597, 0);
@@ -1269,7 +1271,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1269 1271
1270 /* write fifo */ 1272 /* write fifo */
1271 if (pipenum > 0) 1273 if (pipenum > 0)
1272 r8a66597_write(r8a66597, (u16)~(1 << pipenum), BEMPSTS); 1274 r8a66597_write(r8a66597, ~(1 << pipenum), BEMPSTS);
1273 if (urb->transfer_buffer) { 1275 if (urb->transfer_buffer) {
1274 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size); 1276 r8a66597_write_fifo(r8a66597, td->pipe->fifoaddr, buf, size);
1275 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size) 1277 if (!usb_pipebulk(urb->pipe) || td->maxpacket != size)
@@ -1362,7 +1364,7 @@ static void irq_pipe_ready(struct r8a66597 *r8a66597)
1362 1364
1363 mask = r8a66597_read(r8a66597, BRDYSTS) 1365 mask = r8a66597_read(r8a66597, BRDYSTS)
1364 & r8a66597_read(r8a66597, BRDYENB); 1366 & r8a66597_read(r8a66597, BRDYENB);
1365 r8a66597_write(r8a66597, (u16)~mask, BRDYSTS); 1367 r8a66597_write(r8a66597, ~mask, BRDYSTS);
1366 if (mask & BRDY0) { 1368 if (mask & BRDY0) {
1367 td = r8a66597_get_td(r8a66597, 0); 1369 td = r8a66597_get_td(r8a66597, 0);
1368 if (td && td->type == USB_PID_IN) 1370 if (td && td->type == USB_PID_IN)
@@ -1397,7 +1399,7 @@ static void irq_pipe_empty(struct r8a66597 *r8a66597)
1397 1399
1398 mask = r8a66597_read(r8a66597, BEMPSTS) 1400 mask = r8a66597_read(r8a66597, BEMPSTS)
1399 & r8a66597_read(r8a66597, BEMPENB); 1401 & r8a66597_read(r8a66597, BEMPENB);
1400 r8a66597_write(r8a66597, (u16)~mask, BEMPSTS); 1402 r8a66597_write(r8a66597, ~mask, BEMPSTS);
1401 if (mask & BEMP0) { 1403 if (mask & BEMP0) {
1402 cfifo_change(r8a66597, 0); 1404 cfifo_change(r8a66597, 0);
1403 td = r8a66597_get_td(r8a66597, 0); 1405 td = r8a66597_get_td(r8a66597, 0);
@@ -1434,7 +1436,7 @@ static void irq_pipe_nrdy(struct r8a66597 *r8a66597)
1434 1436
1435 mask = r8a66597_read(r8a66597, NRDYSTS) 1437 mask = r8a66597_read(r8a66597, NRDYSTS)
1436 & r8a66597_read(r8a66597, NRDYENB); 1438 & r8a66597_read(r8a66597, NRDYENB);
1437 r8a66597_write(r8a66597, (u16)~mask, NRDYSTS); 1439 r8a66597_write(r8a66597, ~mask, NRDYSTS);
1438 if (mask & NRDY0) { 1440 if (mask & NRDY0) {
1439 cfifo_change(r8a66597, 0); 1441 cfifo_change(r8a66597, 0);
1440 set_urb_error(r8a66597, 0); 1442 set_urb_error(r8a66597, 0);
@@ -1488,14 +1490,14 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1488 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY); 1490 mask0 = intsts0 & intenb0 & (BEMP | NRDY | BRDY);
1489 if (mask2) { 1491 if (mask2) {
1490 if (mask2 & ATTCH) { 1492 if (mask2 & ATTCH) {
1491 r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS2); 1493 r8a66597_write(r8a66597, ~ATTCH, INTSTS2);
1492 r8a66597_bclr(r8a66597, ATTCHE, INTENB2); 1494 r8a66597_bclr(r8a66597, ATTCHE, INTENB2);
1493 1495
1494 /* start usb bus sampling */ 1496 /* start usb bus sampling */
1495 start_root_hub_sampling(r8a66597, 1); 1497 start_root_hub_sampling(r8a66597, 1);
1496 } 1498 }
1497 if (mask2 & DTCH) { 1499 if (mask2 & DTCH) {
1498 r8a66597_write(r8a66597, (u16)~DTCH, INTSTS2); 1500 r8a66597_write(r8a66597, ~DTCH, INTSTS2);
1499 r8a66597_bclr(r8a66597, DTCHE, INTENB2); 1501 r8a66597_bclr(r8a66597, DTCHE, INTENB2);
1500 r8a66597_usb_disconnect(r8a66597, 1); 1502 r8a66597_usb_disconnect(r8a66597, 1);
1501 } 1503 }
@@ -1503,24 +1505,24 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1503 1505
1504 if (mask1) { 1506 if (mask1) {
1505 if (mask1 & ATTCH) { 1507 if (mask1 & ATTCH) {
1506 r8a66597_write(r8a66597, (u16)~ATTCH, INTSTS1); 1508 r8a66597_write(r8a66597, ~ATTCH, INTSTS1);
1507 r8a66597_bclr(r8a66597, ATTCHE, INTENB1); 1509 r8a66597_bclr(r8a66597, ATTCHE, INTENB1);
1508 1510
1509 /* start usb bus sampling */ 1511 /* start usb bus sampling */
1510 start_root_hub_sampling(r8a66597, 0); 1512 start_root_hub_sampling(r8a66597, 0);
1511 } 1513 }
1512 if (mask1 & DTCH) { 1514 if (mask1 & DTCH) {
1513 r8a66597_write(r8a66597, (u16)~DTCH, INTSTS1); 1515 r8a66597_write(r8a66597, ~DTCH, INTSTS1);
1514 r8a66597_bclr(r8a66597, DTCHE, INTENB1); 1516 r8a66597_bclr(r8a66597, DTCHE, INTENB1);
1515 r8a66597_usb_disconnect(r8a66597, 0); 1517 r8a66597_usb_disconnect(r8a66597, 0);
1516 } 1518 }
1517 if (mask1 & SIGN) { 1519 if (mask1 & SIGN) {
1518 r8a66597_write(r8a66597, (u16)~SIGN, INTSTS1); 1520 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1519 set_urb_error(r8a66597, 0); 1521 set_urb_error(r8a66597, 0);
1520 check_next_phase(r8a66597); 1522 check_next_phase(r8a66597);
1521 } 1523 }
1522 if (mask1 & SACK) { 1524 if (mask1 & SACK) {
1523 r8a66597_write(r8a66597, (u16)~SACK, INTSTS1); 1525 r8a66597_write(r8a66597, ~SACK, INTSTS1);
1524 check_next_phase(r8a66597); 1526 check_next_phase(r8a66597);
1525 } 1527 }
1526 } 1528 }
@@ -1663,13 +1665,9 @@ static int check_pipe_config(struct r8a66597 *r8a66597, struct urb *urb)
1663static int r8a66597_start(struct usb_hcd *hcd) 1665static int r8a66597_start(struct usb_hcd *hcd)
1664{ 1666{
1665 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1667 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1666 int ret;
1667 1668
1668 hcd->state = HC_STATE_RUNNING; 1669 hcd->state = HC_STATE_RUNNING;
1669 if ((ret = enable_controller(r8a66597)) < 0) 1670 return enable_controller(r8a66597);
1670 return ret;
1671
1672 return 0;
1673} 1671}
1674 1672
1675static void r8a66597_stop(struct usb_hcd *hcd) 1673static void r8a66597_stop(struct usb_hcd *hcd)
@@ -1696,13 +1694,12 @@ static void set_address_zero(struct r8a66597 *r8a66597, struct urb *urb)
1696 1694
1697static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597, 1695static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1698 struct urb *urb, 1696 struct urb *urb,
1699 struct usb_host_endpoint *hep, 1697 struct usb_host_endpoint *hep)
1700 gfp_t mem_flags)
1701{ 1698{
1702 struct r8a66597_td *td; 1699 struct r8a66597_td *td;
1703 u16 pipenum; 1700 u16 pipenum;
1704 1701
1705 td = kzalloc(sizeof(struct r8a66597_td), mem_flags); 1702 td = kzalloc(sizeof(struct r8a66597_td), GFP_ATOMIC);
1706 if (td == NULL) 1703 if (td == NULL)
1707 return NULL; 1704 return NULL;
1708 1705
@@ -1741,7 +1738,8 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1741 } 1738 }
1742 1739
1743 if (!hep->hcpriv) { 1740 if (!hep->hcpriv) {
1744 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), mem_flags); 1741 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1742 GFP_ATOMIC);
1745 if (!hep->hcpriv) { 1743 if (!hep->hcpriv) {
1746 ret = -ENOMEM; 1744 ret = -ENOMEM;
1747 goto error; 1745 goto error;
@@ -1755,7 +1753,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1755 init_pipe_config(r8a66597, urb); 1753 init_pipe_config(r8a66597, urb);
1756 1754
1757 set_address_zero(r8a66597, urb); 1755 set_address_zero(r8a66597, urb);
1758 td = r8a66597_make_td(r8a66597, urb, hep, mem_flags); 1756 td = r8a66597_make_td(r8a66597, urb, hep);
1759 if (td == NULL) { 1757 if (td == NULL) {
1760 ret = -ENOMEM; 1758 ret = -ENOMEM;
1761 goto error; 1759 goto error;
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index 97c2a71ac7a1..fe9ceb077d9b 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -203,14 +203,14 @@
203#define DTLN 0x0FFF /* b11-0: FIFO received data length */ 203#define DTLN 0x0FFF /* b11-0: FIFO received data length */
204 204
205/* Interrupt Enable Register 0 */ 205/* Interrupt Enable Register 0 */
206#define VBSE 0x8000 /* b15: VBUS interrupt */ 206#define VBSE 0x8000 /* b15: VBUS interrupt */
207#define RSME 0x4000 /* b14: Resume interrupt */ 207#define RSME 0x4000 /* b14: Resume interrupt */
208#define SOFE 0x2000 /* b13: Frame update interrupt */ 208#define SOFE 0x2000 /* b13: Frame update interrupt */
209#define DVSE 0x1000 /* b12: Device state transition interrupt */ 209#define DVSE 0x1000 /* b12: Device state transition interrupt */
210#define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */ 210#define CTRE 0x0800 /* b11: Control transfer stage transition interrupt */
211#define BEMPE 0x0400 /* b10: Buffer empty interrupt */ 211#define BEMPE 0x0400 /* b10: Buffer empty interrupt */
212#define NRDYE 0x0200 /* b9: Buffer not ready interrupt */ 212#define NRDYE 0x0200 /* b9: Buffer not ready interrupt */
213#define BRDYE 0x0100 /* b8: Buffer ready interrupt */ 213#define BRDYE 0x0100 /* b8: Buffer ready interrupt */
214 214
215/* Interrupt Enable Register 1 */ 215/* Interrupt Enable Register 1 */
216#define OVRCRE 0x8000 /* b15: Over-current interrupt */ 216#define OVRCRE 0x8000 /* b15: Over-current interrupt */
@@ -268,16 +268,16 @@
268#define SOF_DISABLE 0x0000 /* SOF OUT Disable */ 268#define SOF_DISABLE 0x0000 /* SOF OUT Disable */
269 269
270/* Interrupt Status Register 0 */ 270/* Interrupt Status Register 0 */
271#define VBINT 0x8000 /* b15: VBUS interrupt */ 271#define VBINT 0x8000 /* b15: VBUS interrupt */
272#define RESM 0x4000 /* b14: Resume interrupt */ 272#define RESM 0x4000 /* b14: Resume interrupt */
273#define SOFR 0x2000 /* b13: SOF frame update interrupt */ 273#define SOFR 0x2000 /* b13: SOF frame update interrupt */
274#define DVST 0x1000 /* b12: Device state transition interrupt */ 274#define DVST 0x1000 /* b12: Device state transition interrupt */
275#define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */ 275#define CTRT 0x0800 /* b11: Control transfer stage transition interrupt */
276#define BEMP 0x0400 /* b10: Buffer empty interrupt */ 276#define BEMP 0x0400 /* b10: Buffer empty interrupt */
277#define NRDY 0x0200 /* b9: Buffer not ready interrupt */ 277#define NRDY 0x0200 /* b9: Buffer not ready interrupt */
278#define BRDY 0x0100 /* b8: Buffer ready interrupt */ 278#define BRDY 0x0100 /* b8: Buffer ready interrupt */
279#define VBSTS 0x0080 /* b7: VBUS input port */ 279#define VBSTS 0x0080 /* b7: VBUS input port */
280#define DVSQ 0x0070 /* b6-4: Device state */ 280#define DVSQ 0x0070 /* b6-4: Device state */
281#define DS_SPD_CNFG 0x0070 /* Suspend Configured */ 281#define DS_SPD_CNFG 0x0070 /* Suspend Configured */
282#define DS_SPD_ADDR 0x0060 /* Suspend Address */ 282#define DS_SPD_ADDR 0x0060 /* Suspend Address */
283#define DS_SPD_DFLT 0x0050 /* Suspend Default */ 283#define DS_SPD_DFLT 0x0050 /* Suspend Default */
@@ -315,13 +315,10 @@
315/* Micro Frame Number Register */ 315/* Micro Frame Number Register */
316#define UFRNM 0x0007 /* b2-0: Micro frame number */ 316#define UFRNM 0x0007 /* b2-0: Micro frame number */
317 317
318/* USB Address / Low Power Status Recovery Register */
319//#define USBADDR 0x007F /* b6-0: USB address */
320
321/* Default Control Pipe Maxpacket Size Register */ 318/* Default Control Pipe Maxpacket Size Register */
322/* Pipe Maxpacket Size Register */ 319/* Pipe Maxpacket Size Register */
323#define DEVSEL 0xF000 /* b15-14: Device address select */ 320#define DEVSEL 0xF000 /* b15-14: Device address select */
324#define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */ 321#define MAXP 0x007F /* b6-0: Maxpacket size of default control pipe */
325 322
326/* Default Control Pipe Control Register */ 323/* Default Control Pipe Control Register */
327#define BSTS 0x8000 /* b15: Buffer status */ 324#define BSTS 0x8000 /* b15: Buffer status */
@@ -366,21 +363,21 @@
366#define MXPS 0x07FF /* b10-0: Maxpacket size */ 363#define MXPS 0x07FF /* b10-0: Maxpacket size */
367 364
368/* Pipe Cycle Configuration Register */ 365/* Pipe Cycle Configuration Register */
369#define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */ 366#define IFIS 0x1000 /* b12: Isochronous in-buffer flush mode select */
370#define IITV 0x0007 /* b2-0: Isochronous interval */ 367#define IITV 0x0007 /* b2-0: Isochronous interval */
371 368
372/* Pipex Control Register */ 369/* Pipex Control Register */
373#define BSTS 0x8000 /* b15: Buffer status */ 370#define BSTS 0x8000 /* b15: Buffer status */
374#define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */ 371#define INBUFM 0x4000 /* b14: IN buffer monitor (Only for PIPE1 to 5) */
375#define CSCLR 0x2000 /* b13: complete-split status clear */ 372#define CSCLR 0x2000 /* b13: complete-split status clear */
376#define CSSTS 0x1000 /* b12: complete-split status */ 373#define CSSTS 0x1000 /* b12: complete-split status */
377#define ATREPM 0x0400 /* b10: Auto repeat mode */ 374#define ATREPM 0x0400 /* b10: Auto repeat mode */
378#define ACLRM 0x0200 /* b9: Out buffer auto clear mode */ 375#define ACLRM 0x0200 /* b9: Out buffer auto clear mode */
379#define SQCLR 0x0100 /* b8: Sequence toggle bit clear */ 376#define SQCLR 0x0100 /* b8: Sequence toggle bit clear */
380#define SQSET 0x0080 /* b7: Sequence toggle bit set */ 377#define SQSET 0x0080 /* b7: Sequence toggle bit set */
381#define SQMON 0x0040 /* b6: Sequence toggle bit monitor */ 378#define SQMON 0x0040 /* b6: Sequence toggle bit monitor */
382#define PBUSY 0x0020 /* b5: pipe busy */ 379#define PBUSY 0x0020 /* b5: pipe busy */
383#define PID 0x0003 /* b1-0: Response PID */ 380#define PID 0x0003 /* b1-0: Response PID */
384 381
385/* PIPExTRE */ 382/* PIPExTRE */
386#define TRENB 0x0200 /* b9: Transaction counter enable */ 383#define TRENB 0x0200 /* b9: Transaction counter enable */
@@ -407,15 +404,15 @@
407#define make_devsel(addr) (addr << 12) 404#define make_devsel(addr) (addr << 12)
408 405
409struct r8a66597_pipe_info { 406struct r8a66597_pipe_info {
410 u16 pipenum; 407 u16 pipenum;
411 u16 address; /* R8A66597 HCD usb addres */ 408 u16 address; /* R8A66597 HCD usb addres */
412 u16 epnum; 409 u16 epnum;
413 u16 maxpacket; 410 u16 maxpacket;
414 u16 type; 411 u16 type;
415 u16 bufnum; 412 u16 bufnum;
416 u16 buf_bsize; 413 u16 buf_bsize;
417 u16 interval; 414 u16 interval;
418 u16 dir_in; 415 u16 dir_in;
419}; 416};
420 417
421struct r8a66597_pipe { 418struct r8a66597_pipe {
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index e98df2ee9901..7f765ec038cd 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -52,6 +52,7 @@
52#include <linux/workqueue.h> 52#include <linux/workqueue.h>
53#include <linux/platform_device.h> 53#include <linux/platform_device.h>
54#include <linux/pci_ids.h> 54#include <linux/pci_ids.h>
55#include <linux/mutex.h>
55#include <asm/io.h> 56#include <asm/io.h>
56#include <asm/irq.h> 57#include <asm/irq.h>
57#include <asm/system.h> 58#include <asm/system.h>
@@ -83,7 +84,7 @@ static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
83* u132_module_lock exists to protect access to global variables 84* u132_module_lock exists to protect access to global variables
84* 85*
85*/ 86*/
86static struct semaphore u132_module_lock; 87static struct mutex u132_module_lock;
87static int u132_exiting = 0; 88static int u132_exiting = 0;
88static int u132_instances = 0; 89static int u132_instances = 0;
89static struct list_head u132_static_list; 90static struct list_head u132_static_list;
@@ -258,10 +259,10 @@ static void u132_hcd_delete(struct kref *kref)
258 struct platform_device *pdev = u132->platform_dev; 259 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132); 260 struct usb_hcd *hcd = u132_to_hcd(u132);
260 u132->going += 1; 261 u132->going += 1;
261 down(&u132_module_lock); 262 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list); 263 list_del_init(&u132->u132_list);
263 u132_instances -= 1; 264 u132_instances -= 1;
264 up(&u132_module_lock); 265 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" 266 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); 267 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
267 usb_put_hcd(hcd); 268 usb_put_hcd(hcd);
@@ -3111,10 +3112,10 @@ static int __devinit u132_probe(struct platform_device *pdev)
3111 int retval = 0; 3112 int retval = 0;
3112 struct u132 *u132 = hcd_to_u132(hcd); 3113 struct u132 *u132 = hcd_to_u132(hcd);
3113 hcd->rsrc_start = 0; 3114 hcd->rsrc_start = 0;
3114 down(&u132_module_lock); 3115 mutex_lock(&u132_module_lock);
3115 list_add_tail(&u132->u132_list, &u132_static_list); 3116 list_add_tail(&u132->u132_list, &u132_static_list);
3116 u132->sequence_num = ++u132_instances; 3117 u132->sequence_num = ++u132_instances;
3117 up(&u132_module_lock); 3118 mutex_unlock(&u132_module_lock);
3118 u132_u132_init_kref(u132); 3119 u132_u132_init_kref(u132);
3119 u132_initialise(u132, pdev); 3120 u132_initialise(u132, pdev);
3120 hcd->product_desc = "ELAN U132 Host Controller"; 3121 hcd->product_desc = "ELAN U132 Host Controller";
@@ -3216,7 +3217,7 @@ static int __init u132_hcd_init(void)
3216 INIT_LIST_HEAD(&u132_static_list); 3217 INIT_LIST_HEAD(&u132_static_list);
3217 u132_instances = 0; 3218 u132_instances = 0;
3218 u132_exiting = 0; 3219 u132_exiting = 0;
3219 init_MUTEX(&u132_module_lock); 3220 mutex_init(&u132_module_lock);
3220 if (usb_disabled()) 3221 if (usb_disabled())
3221 return -ENODEV; 3222 return -ENODEV;
3222 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, 3223 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
@@ -3232,9 +3233,9 @@ static void __exit u132_hcd_exit(void)
3232{ 3233{
3233 struct u132 *u132; 3234 struct u132 *u132;
3234 struct u132 *temp; 3235 struct u132 *temp;
3235 down(&u132_module_lock); 3236 mutex_lock(&u132_module_lock);
3236 u132_exiting += 1; 3237 u132_exiting += 1;
3237 up(&u132_module_lock); 3238 mutex_unlock(&u132_module_lock);
3238 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { 3239 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3239 platform_device_unregister(u132->platform_dev); 3240 platform_device_unregister(u132->platform_dev);
3240 } platform_driver_unregister(&u132_platform_driver); 3241 } platform_driver_unregister(&u132_platform_driver);
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 4aed305982ec..3bb908ca38e9 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -827,8 +827,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
827 * If direction is "send", change the packet ID from SETUP (0x2D) 827 * If direction is "send", change the packet ID from SETUP (0x2D)
828 * to OUT (0xE1). Else change it from SETUP to IN (0x69) and 828 * to OUT (0xE1). Else change it from SETUP to IN (0x69) and
829 * set Short Packet Detect (SPD) for all data packets. 829 * set Short Packet Detect (SPD) for all data packets.
830 *
831 * 0-length transfers always get treated as "send".
830 */ 832 */
831 if (usb_pipeout(urb->pipe)) 833 if (usb_pipeout(urb->pipe) || len == 0)
832 destination ^= (USB_PID_SETUP ^ USB_PID_OUT); 834 destination ^= (USB_PID_SETUP ^ USB_PID_OUT);
833 else { 835 else {
834 destination ^= (USB_PID_SETUP ^ USB_PID_IN); 836 destination ^= (USB_PID_SETUP ^ USB_PID_IN);
@@ -839,7 +841,12 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
839 * Build the DATA TDs 841 * Build the DATA TDs
840 */ 842 */
841 while (len > 0) { 843 while (len > 0) {
842 int pktsze = min(len, maxsze); 844 int pktsze = maxsze;
845
846 if (len <= pktsze) { /* The last data packet */
847 pktsze = len;
848 status &= ~TD_CTRL_SPD;
849 }
843 850
844 td = uhci_alloc_td(uhci); 851 td = uhci_alloc_td(uhci);
845 if (!td) 852 if (!td)
@@ -866,20 +873,10 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
866 goto nomem; 873 goto nomem;
867 *plink = LINK_TO_TD(td); 874 *plink = LINK_TO_TD(td);
868 875
869 /* 876 /* Change direction for the status transaction */
870 * It's IN if the pipe is an output pipe or we're not expecting 877 destination ^= (USB_PID_IN ^ USB_PID_OUT);
871 * data back.
872 */
873 destination &= ~TD_TOKEN_PID_MASK;
874 if (usb_pipeout(urb->pipe) || !urb->transfer_buffer_length)
875 destination |= USB_PID_IN;
876 else
877 destination |= USB_PID_OUT;
878
879 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */ 878 destination |= TD_TOKEN_TOGGLE; /* End in Data1 */
880 879
881 status &= ~TD_CTRL_SPD;
882
883 uhci_add_td_to_urbp(td, urbp); 880 uhci_add_td_to_urbp(td, urbp);
884 uhci_fill_td(td, status | TD_CTRL_IOC, 881 uhci_fill_td(td, status | TD_CTRL_IOC,
885 destination | uhci_explen(0), 0); 882 destination | uhci_explen(0), 0);
@@ -1185,10 +1182,18 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1185 } 1182 }
1186 } 1183 }
1187 1184
1185 /* Did we receive a short packet? */
1188 } else if (len < uhci_expected_length(td_token(td))) { 1186 } else if (len < uhci_expected_length(td_token(td))) {
1189 1187
1190 /* We received a short packet */ 1188 /* For control transfers, go to the status TD if
1191 if (urb->transfer_flags & URB_SHORT_NOT_OK) 1189 * this isn't already the last data TD */
1190 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1191 if (td->list.next != urbp->td_list.prev)
1192 ret = 1;
1193 }
1194
1195 /* For bulk and interrupt, this may be an error */
1196 else if (urb->transfer_flags & URB_SHORT_NOT_OK)
1192 ret = -EREMOTEIO; 1197 ret = -EREMOTEIO;
1193 1198
1194 /* Fixup needed only if this isn't the URB's last TD */ 1199 /* Fixup needed only if this isn't the URB's last TD */
@@ -1208,10 +1213,6 @@ static int uhci_result_common(struct uhci_hcd *uhci, struct urb *urb)
1208 1213
1209err: 1214err:
1210 if (ret < 0) { 1215 if (ret < 0) {
1211 /* In case a control transfer gets an error
1212 * during the setup stage */
1213 urb->actual_length = max(urb->actual_length, 0);
1214
1215 /* Note that the queue has stopped and save 1216 /* Note that the queue has stopped and save
1216 * the next toggle value */ 1217 * the next toggle value */
1217 qh->element = UHCI_PTR_TERM; 1218 qh->element = UHCI_PTR_TERM;
@@ -1489,9 +1490,25 @@ __acquires(uhci->lock)
1489{ 1490{
1490 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv; 1491 struct urb_priv *urbp = (struct urb_priv *) urb->hcpriv;
1491 1492
1493 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1494
1495 /* urb->actual_length < 0 means the setup transaction didn't
1496 * complete successfully. Either it failed or the URB was
1497 * unlinked first. Regardless, don't confuse people with a
1498 * negative length. */
1499 urb->actual_length = max(urb->actual_length, 0);
1500
1501 /* Report erroneous short transfers */
1502 if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) &&
1503 urb->actual_length <
1504 urb->transfer_buffer_length &&
1505 urb->status == 0))
1506 urb->status = -EREMOTEIO;
1507 }
1508
1492 /* When giving back the first URB in an Isochronous queue, 1509 /* When giving back the first URB in an Isochronous queue,
1493 * reinitialize the QH's iso-related members for the next URB. */ 1510 * reinitialize the QH's iso-related members for the next URB. */
1494 if (qh->type == USB_ENDPOINT_XFER_ISOC && 1511 else if (qh->type == USB_ENDPOINT_XFER_ISOC &&
1495 urbp->node.prev == &qh->queue && 1512 urbp->node.prev == &qh->queue &&
1496 urbp->node.next != &qh->queue) { 1513 urbp->node.next != &qh->queue) {
1497 struct urb *nurb = list_entry(urbp->node.next, 1514 struct urb *nurb = list_entry(urbp->node.next,
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index 36502a06f73a..d1131a87a5b1 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -284,9 +284,9 @@ static void mdc800_usb_irq (struct urb *urb)
284 int data_received=0, wake_up; 284 int data_received=0, wake_up;
285 unsigned char* b=urb->transfer_buffer; 285 unsigned char* b=urb->transfer_buffer;
286 struct mdc800_data* mdc800=urb->context; 286 struct mdc800_data* mdc800=urb->context;
287 int status = urb->status;
287 288
288 if (urb->status >= 0) 289 if (status >= 0) {
289 {
290 290
291 //dbg ("%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]); 291 //dbg ("%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]);
292 292
@@ -324,7 +324,7 @@ static void mdc800_usb_irq (struct urb *urb)
324 || 324 ||
325 ((mdc800->camera_request_ready == 3) && (mdc800->camera_busy)) 325 ((mdc800->camera_request_ready == 3) && (mdc800->camera_busy))
326 || 326 ||
327 (urb->status < 0) 327 (status < 0)
328 ); 328 );
329 329
330 if (wake_up) 330 if (wake_up)
@@ -376,15 +376,12 @@ static int mdc800_usb_waitForIRQ (int mode, int msec)
376static void mdc800_usb_write_notify (struct urb *urb) 376static void mdc800_usb_write_notify (struct urb *urb)
377{ 377{
378 struct mdc800_data* mdc800=urb->context; 378 struct mdc800_data* mdc800=urb->context;
379 int status = urb->status;
379 380
380 if (urb->status != 0) 381 if (status != 0)
381 { 382 err ("writing command fails (status=%i)", status);
382 err ("writing command fails (status=%i)", urb->status);
383 }
384 else 383 else
385 {
386 mdc800->state=READY; 384 mdc800->state=READY;
387 }
388 mdc800->written = 1; 385 mdc800->written = 1;
389 wake_up (&mdc800->write_wait); 386 wake_up (&mdc800->write_wait);
390} 387}
@@ -396,9 +393,9 @@ static void mdc800_usb_write_notify (struct urb *urb)
396static void mdc800_usb_download_notify (struct urb *urb) 393static void mdc800_usb_download_notify (struct urb *urb)
397{ 394{
398 struct mdc800_data* mdc800=urb->context; 395 struct mdc800_data* mdc800=urb->context;
396 int status = urb->status;
399 397
400 if (urb->status == 0) 398 if (status == 0) {
401 {
402 /* Fill output buffer with these data */ 399 /* Fill output buffer with these data */
403 memcpy (mdc800->out, urb->transfer_buffer, 64); 400 memcpy (mdc800->out, urb->transfer_buffer, 64);
404 mdc800->out_count=64; 401 mdc800->out_count=64;
@@ -408,10 +405,8 @@ static void mdc800_usb_download_notify (struct urb *urb)
408 { 405 {
409 mdc800->state=READY; 406 mdc800->state=READY;
410 } 407 }
411 } 408 } else {
412 else 409 err ("request bytes fails (status:%i)", status);
413 {
414 err ("request bytes fails (status:%i)", urb->status);
415 } 410 }
416 mdc800->downloaded = 1; 411 mdc800->downloaded = 1;
417 wake_up (&mdc800->download_wait); 412 wake_up (&mdc800->download_wait);
@@ -649,9 +644,9 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
649 644
650 retval=0; 645 retval=0;
651 mdc800->irq_urb->dev = mdc800->dev; 646 mdc800->irq_urb->dev = mdc800->dev;
652 if (usb_submit_urb (mdc800->irq_urb, GFP_KERNEL)) 647 retval = usb_submit_urb (mdc800->irq_urb, GFP_KERNEL);
653 { 648 if (retval) {
654 err ("request USB irq fails (submit_retval=%i urb_status=%i).",retval, mdc800->irq_urb->status); 649 err ("request USB irq fails (submit_retval=%i).", retval);
655 errn = -EIO; 650 errn = -EIO;
656 goto error_out; 651 goto error_out;
657 } 652 }
@@ -698,6 +693,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
698{ 693{
699 size_t left=len, sts=len; /* single transfer size */ 694 size_t left=len, sts=len; /* single transfer size */
700 char __user *ptr = buf; 695 char __user *ptr = buf;
696 int retval;
701 697
702 mutex_lock(&mdc800->io_lock); 698 mutex_lock(&mdc800->io_lock);
703 if (mdc800->state == NOT_CONNECTED) 699 if (mdc800->state == NOT_CONNECTED)
@@ -737,9 +733,9 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
737 733
738 /* Download -> Request new bytes */ 734 /* Download -> Request new bytes */
739 mdc800->download_urb->dev = mdc800->dev; 735 mdc800->download_urb->dev = mdc800->dev;
740 if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) 736 retval = usb_submit_urb (mdc800->download_urb, GFP_KERNEL);
741 { 737 if (retval) {
742 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); 738 err ("Can't submit download urb (retval=%i)",retval);
743 mutex_unlock(&mdc800->io_lock); 739 mutex_unlock(&mdc800->io_lock);
744 return len-left; 740 return len-left;
745 } 741 }
@@ -788,6 +784,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
788static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos) 784static ssize_t mdc800_device_write (struct file *file, const char __user *buf, size_t len, loff_t *pos)
789{ 785{
790 size_t i=0; 786 size_t i=0;
787 int retval;
791 788
792 mutex_lock(&mdc800->io_lock); 789 mutex_lock(&mdc800->io_lock);
793 if (mdc800->state != READY) 790 if (mdc800->state != READY)
@@ -854,9 +851,9 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
854 mdc800->state=WORKING; 851 mdc800->state=WORKING;
855 memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8); 852 memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8);
856 mdc800->write_urb->dev = mdc800->dev; 853 mdc800->write_urb->dev = mdc800->dev;
857 if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) 854 retval = usb_submit_urb (mdc800->write_urb, GFP_KERNEL);
858 { 855 if (retval) {
859 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); 856 err ("submitting write urb fails (retval=%i)", retval);
860 mutex_unlock(&mdc800->io_lock); 857 mutex_unlock(&mdc800->io_lock);
861 return -EIO; 858 return -EIO;
862 } 859 }
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 51bd80d2b8cc..768b2c11a231 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -189,7 +189,7 @@ static struct usb_driver mts_usb_driver = {
189#define MTS_DEBUG_INT() \ 189#define MTS_DEBUG_INT() \
190 do { MTS_DEBUG_GOT_HERE(); \ 190 do { MTS_DEBUG_GOT_HERE(); \
191 MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \ 191 MTS_DEBUG("transfer = 0x%x context = 0x%x\n",(int)transfer,(int)context ); \
192 MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",(int)transfer->status,(int)context->data_length, (int)transfer->actual_length ); \ 192 MTS_DEBUG("status = 0x%x data-length = 0x%x sent = 0x%x\n",transfer->status,(int)context->data_length, (int)transfer->actual_length ); \
193 mts_debug_dump(context->instance);\ 193 mts_debug_dump(context->instance);\
194 } while(0) 194 } while(0)
195#else 195#else
@@ -393,8 +393,6 @@ void mts_int_submit_urb (struct urb* transfer,
393 context 393 context
394 ); 394 );
395 395
396 transfer->status = 0;
397
398 res = usb_submit_urb( transfer, GFP_ATOMIC ); 396 res = usb_submit_urb( transfer, GFP_ATOMIC );
399 if ( unlikely(res) ) { 397 if ( unlikely(res) ) {
400 MTS_INT_ERROR( "could not submit URB! Error was %d\n",(int)res ); 398 MTS_INT_ERROR( "could not submit URB! Error was %d\n",(int)res );
@@ -444,12 +442,13 @@ static void mts_get_status( struct urb *transfer )
444static void mts_data_done( struct urb* transfer ) 442static void mts_data_done( struct urb* transfer )
445/* Interrupt context! */ 443/* Interrupt context! */
446{ 444{
445 int status = transfer->status;
447 MTS_INT_INIT(); 446 MTS_INT_INIT();
448 447
449 if ( context->data_length != transfer->actual_length ) { 448 if ( context->data_length != transfer->actual_length ) {
450 context->srb->resid = context->data_length - transfer->actual_length; 449 context->srb->resid = context->data_length - transfer->actual_length;
451 } else if ( unlikely(transfer->status) ) { 450 } else if ( unlikely(status) ) {
452 context->srb->result = (transfer->status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; 451 context->srb->result = (status == -ENOENT ? DID_ABORT : DID_ERROR)<<16;
453 } 452 }
454 453
455 mts_get_status(transfer); 454 mts_get_status(transfer);
@@ -461,10 +460,11 @@ static void mts_data_done( struct urb* transfer )
461static void mts_command_done( struct urb *transfer ) 460static void mts_command_done( struct urb *transfer )
462/* Interrupt context! */ 461/* Interrupt context! */
463{ 462{
463 int status = transfer->status;
464 MTS_INT_INIT(); 464 MTS_INT_INIT();
465 465
466 if ( unlikely(transfer->status) ) { 466 if ( unlikely(status) ) {
467 if (transfer->status == -ENOENT) { 467 if (status == -ENOENT) {
468 /* We are being killed */ 468 /* We are being killed */
469 MTS_DEBUG_GOT_HERE(); 469 MTS_DEBUG_GOT_HERE();
470 context->srb->result = DID_ABORT<<16; 470 context->srb->result = DID_ABORT<<16;
@@ -502,12 +502,13 @@ static void mts_command_done( struct urb *transfer )
502static void mts_do_sg (struct urb* transfer) 502static void mts_do_sg (struct urb* transfer)
503{ 503{
504 struct scatterlist * sg; 504 struct scatterlist * sg;
505 int status = transfer->status;
505 MTS_INT_INIT(); 506 MTS_INT_INIT();
506 507
507 MTS_DEBUG("Processing fragment %d of %d\n", context->fragment,context->srb->use_sg); 508 MTS_DEBUG("Processing fragment %d of %d\n", context->fragment,context->srb->use_sg);
508 509
509 if (unlikely(transfer->status)) { 510 if (unlikely(status)) {
510 context->srb->result = (transfer->status == -ENOENT ? DID_ABORT : DID_ERROR)<<16; 511 context->srb->result = (status == -ENOENT ? DID_ABORT : DID_ERROR)<<16;
511 mts_transfer_cleanup(transfer); 512 mts_transfer_cleanup(transfer);
512 } 513 }
513 514
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index d72c42e5f22d..e9fdbc8997b3 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/mutex.h>
27#include <asm/uaccess.h> 28#include <asm/uaccess.h>
28 29
29#ifdef CONFIG_USB_DEBUG 30#ifdef CONFIG_USB_DEBUG
@@ -80,7 +81,7 @@ MODULE_DEVICE_TABLE(usb, device_table);
80 81
81/* Structure to hold all of our device specific stuff */ 82/* Structure to hold all of our device specific stuff */
82struct adu_device { 83struct adu_device {
83 struct semaphore sem; /* locks this structure */ 84 struct mutex mtx; /* locks this structure */
84 struct usb_device* udev; /* save off the usb device pointer */ 85 struct usb_device* udev; /* save off the usb device pointer */
85 struct usb_interface* interface; 86 struct usb_interface* interface;
86 unsigned char minor; /* the starting minor number for this device */ 87 unsigned char minor; /* the starting minor number for this device */
@@ -178,17 +179,18 @@ static void adu_delete(struct adu_device *dev)
178static void adu_interrupt_in_callback(struct urb *urb) 179static void adu_interrupt_in_callback(struct urb *urb)
179{ 180{
180 struct adu_device *dev = urb->context; 181 struct adu_device *dev = urb->context;
182 int status = urb->status;
181 183
182 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); 184 dbg(4," %s : enter, status %d", __FUNCTION__, status);
183 adu_debug_data(5, __FUNCTION__, urb->actual_length, 185 adu_debug_data(5, __FUNCTION__, urb->actual_length,
184 urb->transfer_buffer); 186 urb->transfer_buffer);
185 187
186 spin_lock(&dev->buflock); 188 spin_lock(&dev->buflock);
187 189
188 if (urb->status != 0) { 190 if (status != 0) {
189 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) { 191 if ((status != -ENOENT) && (status != -ECONNRESET)) {
190 dbg(1," %s : nonzero status received: %d", 192 dbg(1," %s : nonzero status received: %d",
191 __FUNCTION__, urb->status); 193 __FUNCTION__, status);
192 } 194 }
193 goto exit; 195 goto exit;
194 } 196 }
@@ -216,21 +218,22 @@ exit:
216 wake_up_interruptible(&dev->read_wait); 218 wake_up_interruptible(&dev->read_wait);
217 adu_debug_data(5, __FUNCTION__, urb->actual_length, 219 adu_debug_data(5, __FUNCTION__, urb->actual_length,
218 urb->transfer_buffer); 220 urb->transfer_buffer);
219 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); 221 dbg(4," %s : leave, status %d", __FUNCTION__, status);
220} 222}
221 223
222static void adu_interrupt_out_callback(struct urb *urb) 224static void adu_interrupt_out_callback(struct urb *urb)
223{ 225{
224 struct adu_device *dev = urb->context; 226 struct adu_device *dev = urb->context;
227 int status = urb->status;
225 228
226 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status); 229 dbg(4," %s : enter, status %d", __FUNCTION__, status);
227 adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer); 230 adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer);
228 231
229 if (urb->status != 0) { 232 if (status != 0) {
230 if ((urb->status != -ENOENT) && 233 if ((status != -ENOENT) &&
231 (urb->status != -ECONNRESET)) { 234 (status != -ECONNRESET)) {
232 dbg(1, " %s :nonzero status received: %d", 235 dbg(1, " %s :nonzero status received: %d",
233 __FUNCTION__, urb->status); 236 __FUNCTION__, status);
234 } 237 }
235 goto exit; 238 goto exit;
236 } 239 }
@@ -240,7 +243,7 @@ exit:
240 243
241 adu_debug_data(5, __FUNCTION__, urb->actual_length, 244 adu_debug_data(5, __FUNCTION__, urb->actual_length,
242 urb->transfer_buffer); 245 urb->transfer_buffer);
243 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status); 246 dbg(4," %s : leave, status %d", __FUNCTION__, status);
244} 247}
245 248
246static int adu_open(struct inode *inode, struct file *file) 249static int adu_open(struct inode *inode, struct file *file)
@@ -269,8 +272,8 @@ static int adu_open(struct inode *inode, struct file *file)
269 } 272 }
270 273
271 /* lock this device */ 274 /* lock this device */
272 if ((retval = down_interruptible(&dev->sem))) { 275 if ((retval = mutex_lock_interruptible(&dev->mtx))) {
273 dbg(2, "%s : sem down failed", __FUNCTION__); 276 dbg(2, "%s : mutex lock failed", __FUNCTION__);
274 goto exit_no_device; 277 goto exit_no_device;
275 } 278 }
276 279
@@ -299,7 +302,7 @@ static int adu_open(struct inode *inode, struct file *file)
299 if (retval) 302 if (retval)
300 --dev->open_count; 303 --dev->open_count;
301 } 304 }
302 up(&dev->sem); 305 mutex_unlock(&dev->mtx);
303 306
304exit_no_device: 307exit_no_device:
305 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval); 308 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
@@ -347,7 +350,7 @@ static int adu_release(struct inode *inode, struct file *file)
347 } 350 }
348 351
349 /* lock our device */ 352 /* lock our device */
350 down(&dev->sem); /* not interruptible */ 353 mutex_lock(&dev->mtx); /* not interruptible */
351 354
352 if (dev->open_count <= 0) { 355 if (dev->open_count <= 0) {
353 dbg(1," %s : device not opened", __FUNCTION__); 356 dbg(1," %s : device not opened", __FUNCTION__);
@@ -357,7 +360,7 @@ static int adu_release(struct inode *inode, struct file *file)
357 360
358 if (dev->udev == NULL) { 361 if (dev->udev == NULL) {
359 /* the device was unplugged before the file was released */ 362 /* the device was unplugged before the file was released */
360 up(&dev->sem); 363 mutex_unlock(&dev->mtx);
361 adu_delete(dev); 364 adu_delete(dev);
362 dev = NULL; 365 dev = NULL;
363 } else { 366 } else {
@@ -367,7 +370,7 @@ static int adu_release(struct inode *inode, struct file *file)
367 370
368exit: 371exit:
369 if (dev) 372 if (dev)
370 up(&dev->sem); 373 mutex_unlock(&dev->mtx);
371 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 374 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
372 return retval; 375 return retval;
373} 376}
@@ -390,7 +393,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
390 dev = file->private_data; 393 dev = file->private_data;
391 dbg(2," %s : dev=%p", __FUNCTION__, dev); 394 dbg(2," %s : dev=%p", __FUNCTION__, dev);
392 /* lock this object */ 395 /* lock this object */
393 if (down_interruptible(&dev->sem)) 396 if (mutex_lock_interruptible(&dev->mtx))
394 return -ERESTARTSYS; 397 return -ERESTARTSYS;
395 398
396 /* verify that the device wasn't unplugged */ 399 /* verify that the device wasn't unplugged */
@@ -522,7 +525,7 @@ static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
522 525
523exit: 526exit:
524 /* unlock the device */ 527 /* unlock the device */
525 up(&dev->sem); 528 mutex_unlock(&dev->mtx);
526 529
527 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 530 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
528 return retval; 531 return retval;
@@ -543,7 +546,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
543 dev = file->private_data; 546 dev = file->private_data;
544 547
545 /* lock this object */ 548 /* lock this object */
546 retval = down_interruptible(&dev->sem); 549 retval = mutex_lock_interruptible(&dev->mtx);
547 if (retval) 550 if (retval)
548 goto exit_nolock; 551 goto exit_nolock;
549 552
@@ -571,9 +574,9 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
571 retval = -EINTR; 574 retval = -EINTR;
572 goto exit; 575 goto exit;
573 } 576 }
574 up(&dev->sem); 577 mutex_unlock(&dev->mtx);
575 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout); 578 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
576 retval = down_interruptible(&dev->sem); 579 retval = mutex_lock_interruptible(&dev->mtx);
577 if (retval) { 580 if (retval) {
578 retval = bytes_written ? bytes_written : retval; 581 retval = bytes_written ? bytes_written : retval;
579 goto exit_nolock; 582 goto exit_nolock;
@@ -638,7 +641,7 @@ static ssize_t adu_write(struct file *file, const __user char *buffer,
638 641
639exit: 642exit:
640 /* unlock the device */ 643 /* unlock the device */
641 up(&dev->sem); 644 mutex_unlock(&dev->mtx);
642exit_nolock: 645exit_nolock:
643 646
644 dbg(2," %s : leave, return value %d", __FUNCTION__, retval); 647 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
@@ -698,7 +701,7 @@ static int adu_probe(struct usb_interface *interface,
698 goto exit; 701 goto exit;
699 } 702 }
700 703
701 init_MUTEX(&dev->sem); 704 mutex_init(&dev->mtx);
702 spin_lock_init(&dev->buflock); 705 spin_lock_init(&dev->buflock);
703 dev->udev = udev; 706 dev->udev = udev;
704 init_waitqueue_head(&dev->read_wait); 707 init_waitqueue_head(&dev->read_wait);
@@ -835,16 +838,16 @@ static void adu_disconnect(struct usb_interface *interface)
835 usb_deregister_dev(interface, &adu_class); 838 usb_deregister_dev(interface, &adu_class);
836 dev->minor = 0; 839 dev->minor = 0;
837 840
838 down(&dev->sem); /* not interruptible */ 841 mutex_lock(&dev->mtx); /* not interruptible */
839 842
840 /* if the device is not opened, then we clean up right now */ 843 /* if the device is not opened, then we clean up right now */
841 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count); 844 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
842 if (!dev->open_count) { 845 if (!dev->open_count) {
843 up(&dev->sem); 846 mutex_unlock(&dev->mtx);
844 adu_delete(dev); 847 adu_delete(dev);
845 } else { 848 } else {
846 dev->udev = NULL; 849 dev->udev = NULL;
847 up(&dev->sem); 850 mutex_unlock(&dev->mtx);
848 } 851 }
849 852
850 dev_info(&interface->dev, "ADU device adutux%d now disconnected", 853 dev_info(&interface->dev, "ADU device adutux%d now disconnected",
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index cf70c16f0e3f..1cb56f2d5c84 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -88,9 +88,10 @@ static void appledisplay_complete(struct urb *urb)
88{ 88{
89 struct appledisplay *pdata = urb->context; 89 struct appledisplay *pdata = urb->context;
90 unsigned long flags; 90 unsigned long flags;
91 int status = urb->status;
91 int retval; 92 int retval;
92 93
93 switch (urb->status) { 94 switch (status) {
94 case 0: 95 case 0:
95 /* success */ 96 /* success */
96 break; 97 break;
@@ -102,12 +103,12 @@ static void appledisplay_complete(struct urb *urb)
102 case -ENOENT: 103 case -ENOENT:
103 case -ESHUTDOWN: 104 case -ESHUTDOWN:
104 /* This urb is terminated, clean up */ 105 /* This urb is terminated, clean up */
105 dbg("%s - urb shutting down with status: %d", 106 dbg("%s - urb shuttingdown with status: %d",
106 __FUNCTION__, urb->status); 107 __FUNCTION__, status);
107 return; 108 return;
108 default: 109 default:
109 dbg("%s - nonzero urb status received: %d", 110 dbg("%s - nonzero urb status received: %d",
110 __FUNCTION__, urb->status); 111 __FUNCTION__, status);
111 goto exit; 112 goto exit;
112 } 113 }
113 114
@@ -137,7 +138,7 @@ exit:
137 138
138static int appledisplay_bl_update_status(struct backlight_device *bd) 139static int appledisplay_bl_update_status(struct backlight_device *bd)
139{ 140{
140 struct appledisplay *pdata = class_get_devdata(&bd->class_dev); 141 struct appledisplay *pdata = bl_get_data(bd);
141 int retval; 142 int retval;
142 143
143 pdata->msgdata[0] = 0x10; 144 pdata->msgdata[0] = 0x10;
@@ -158,7 +159,7 @@ static int appledisplay_bl_update_status(struct backlight_device *bd)
158 159
159static int appledisplay_bl_get_brightness(struct backlight_device *bd) 160static int appledisplay_bl_get_brightness(struct backlight_device *bd)
160{ 161{
161 struct appledisplay *pdata = class_get_devdata(&bd->class_dev); 162 struct appledisplay *pdata = bl_get_data(bd);
162 int retval; 163 int retval;
163 164
164 retval = usb_control_msg( 165 retval = usb_control_msg(
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index 42d4e6454a77..df7e1ecc810a 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -862,14 +862,16 @@ static void auerswald_ctrlread_wretcomplete (struct urb * urb)
862 pauerbuf_t bp = (pauerbuf_t) urb->context; 862 pauerbuf_t bp = (pauerbuf_t) urb->context;
863 pauerswald_t cp; 863 pauerswald_t cp;
864 int ret; 864 int ret;
865 int status = urb->status;
866
865 dbg ("auerswald_ctrlread_wretcomplete called"); 867 dbg ("auerswald_ctrlread_wretcomplete called");
866 dbg ("complete with status: %d", urb->status); 868 dbg ("complete with status: %d", status);
867 cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); 869 cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl)));
868 870
869 /* check if it is possible to advance */ 871 /* check if it is possible to advance */
870 if (!auerswald_status_retry (urb->status) || !cp->usbdev) { 872 if (!auerswald_status_retry(status) || !cp->usbdev) {
871 /* reuse the buffer */ 873 /* reuse the buffer */
872 err ("control dummy: transmission error %d, can not retry", urb->status); 874 err ("control dummy: transmission error %d, can not retry", status);
873 auerbuf_releasebuf (bp); 875 auerbuf_releasebuf (bp);
874 /* Wake up all processes waiting for a buffer */ 876 /* Wake up all processes waiting for a buffer */
875 wake_up (&cp->bufferwait); 877 wake_up (&cp->bufferwait);
@@ -902,21 +904,23 @@ static void auerswald_ctrlread_complete (struct urb * urb)
902 pauerswald_t cp; 904 pauerswald_t cp;
903 pauerscon_t scp; 905 pauerscon_t scp;
904 pauerbuf_t bp = (pauerbuf_t) urb->context; 906 pauerbuf_t bp = (pauerbuf_t) urb->context;
907 int status = urb->status;
905 int ret; 908 int ret;
909
906 dbg ("auerswald_ctrlread_complete called"); 910 dbg ("auerswald_ctrlread_complete called");
907 911
908 cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl))); 912 cp = ((pauerswald_t)((char *)(bp->list)-(unsigned long)(&((pauerswald_t)0)->bufctl)));
909 913
910 /* check if there is valid data in this urb */ 914 /* check if there is valid data in this urb */
911 if (urb->status) { 915 if (status) {
912 dbg ("complete with non-zero status: %d", urb->status); 916 dbg ("complete with non-zero status: %d", status);
913 /* should we do a retry? */ 917 /* should we do a retry? */
914 if (!auerswald_status_retry (urb->status) 918 if (!auerswald_status_retry(status)
915 || !cp->usbdev 919 || !cp->usbdev
916 || (cp->version < AUV_RETRY) 920 || (cp->version < AUV_RETRY)
917 || (bp->retries >= AU_RETRIES)) { 921 || (bp->retries >= AU_RETRIES)) {
918 /* reuse the buffer */ 922 /* reuse the buffer */
919 err ("control read: transmission error %d, can not retry", urb->status); 923 err ("control read: transmission error %d, can not retry", status);
920 auerbuf_releasebuf (bp); 924 auerbuf_releasebuf (bp);
921 /* Wake up all processes waiting for a buffer */ 925 /* Wake up all processes waiting for a buffer */
922 wake_up (&cp->bufferwait); 926 wake_up (&cp->bufferwait);
@@ -974,12 +978,13 @@ static void auerswald_int_complete (struct urb * urb)
974 unsigned int channelid; 978 unsigned int channelid;
975 unsigned int bytecount; 979 unsigned int bytecount;
976 int ret; 980 int ret;
981 int status = urb->status;
977 pauerbuf_t bp = NULL; 982 pauerbuf_t bp = NULL;
978 pauerswald_t cp = (pauerswald_t) urb->context; 983 pauerswald_t cp = (pauerswald_t) urb->context;
979 984
980 dbg ("%s called", __FUNCTION__); 985 dbg ("%s called", __FUNCTION__);
981 986
982 switch (urb->status) { 987 switch (status) {
983 case 0: 988 case 0:
984 /* success */ 989 /* success */
985 break; 990 break;
@@ -987,10 +992,10 @@ static void auerswald_int_complete (struct urb * urb)
987 case -ENOENT: 992 case -ENOENT:
988 case -ESHUTDOWN: 993 case -ESHUTDOWN:
989 /* this urb is terminated, clean up */ 994 /* this urb is terminated, clean up */
990 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 995 dbg("%s - urb shutting down with status: %d", __FUNCTION__, status);
991 return; 996 return;
992 default: 997 default:
993 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 998 dbg("%s - nonzero urb status received: %d", __FUNCTION__, status);
994 goto exit; 999 goto exit;
995 } 1000 }
996 1001
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index e0f122e131d7..538b535e955b 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -44,6 +44,7 @@
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/module.h> 45#include <linux/module.h>
46#include <linux/kref.h> 46#include <linux/kref.h>
47#include <linux/mutex.h>
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48#include <linux/usb.h> 49#include <linux/usb.h>
49#include <linux/workqueue.h> 50#include <linux/workqueue.h>
@@ -64,7 +65,7 @@ static struct workqueue_struct *respond_queue;
64* ftdi_module_lock exists to protect access to global variables 65* ftdi_module_lock exists to protect access to global variables
65* 66*
66*/ 67*/
67static struct semaphore ftdi_module_lock; 68static struct mutex ftdi_module_lock;
68static int ftdi_instances = 0; 69static int ftdi_instances = 0;
69static struct list_head ftdi_static_list; 70static struct list_head ftdi_static_list;
70/* 71/*
@@ -199,10 +200,10 @@ static void ftdi_elan_delete(struct kref *kref)
199 dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi); 200 dev_warn(&ftdi->udev->dev, "FREEING ftdi=%p\n", ftdi);
200 usb_put_dev(ftdi->udev); 201 usb_put_dev(ftdi->udev);
201 ftdi->disconnected += 1; 202 ftdi->disconnected += 1;
202 down(&ftdi_module_lock); 203 mutex_lock(&ftdi_module_lock);
203 list_del_init(&ftdi->ftdi_list); 204 list_del_init(&ftdi->ftdi_list);
204 ftdi_instances -= 1; 205 ftdi_instances -= 1;
205 up(&ftdi_module_lock); 206 mutex_unlock(&ftdi_module_lock);
206 kfree(ftdi->bulk_in_buffer); 207 kfree(ftdi->bulk_in_buffer);
207 ftdi->bulk_in_buffer = NULL; 208 ftdi->bulk_in_buffer = NULL;
208} 209}
@@ -746,10 +747,12 @@ static ssize_t ftdi_elan_read(struct file *file, char __user *buffer,
746static void ftdi_elan_write_bulk_callback(struct urb *urb) 747static void ftdi_elan_write_bulk_callback(struct urb *urb)
747{ 748{
748 struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context; 749 struct usb_ftdi *ftdi = (struct usb_ftdi *)urb->context;
749 if (urb->status && !(urb->status == -ENOENT || urb->status == 750 int status = urb->status;
750 -ECONNRESET || urb->status == -ESHUTDOWN)) { 751
752 if (status && !(status == -ENOENT || status == -ECONNRESET ||
753 status == -ESHUTDOWN)) {
751 dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %" 754 dev_err(&ftdi->udev->dev, "urb=%p write bulk status received: %"
752 "d\n", urb, urb->status); 755 "d\n", urb, status);
753 } 756 }
754 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 757 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
755 urb->transfer_buffer, urb->transfer_dma); 758 urb->transfer_buffer, urb->transfer_dma);
@@ -2780,10 +2783,10 @@ static int ftdi_elan_probe(struct usb_interface *interface,
2780 return -ENOMEM; 2783 return -ENOMEM;
2781 } 2784 }
2782 memset(ftdi, 0x00, sizeof(struct usb_ftdi)); 2785 memset(ftdi, 0x00, sizeof(struct usb_ftdi));
2783 down(&ftdi_module_lock); 2786 mutex_lock(&ftdi_module_lock);
2784 list_add_tail(&ftdi->ftdi_list, &ftdi_static_list); 2787 list_add_tail(&ftdi->ftdi_list, &ftdi_static_list);
2785 ftdi->sequence_num = ++ftdi_instances; 2788 ftdi->sequence_num = ++ftdi_instances;
2786 up(&ftdi_module_lock); 2789 mutex_unlock(&ftdi_module_lock);
2787 ftdi_elan_init_kref(ftdi); 2790 ftdi_elan_init_kref(ftdi);
2788 init_MUTEX(&ftdi->sw_lock); 2791 init_MUTEX(&ftdi->sw_lock);
2789 ftdi->udev = usb_get_dev(interface_to_usbdev(interface)); 2792 ftdi->udev = usb_get_dev(interface_to_usbdev(interface));
@@ -2909,7 +2912,7 @@ static int __init ftdi_elan_init(void)
2909 int result; 2912 int result;
2910 printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name, 2913 printk(KERN_INFO "driver %s built at %s on %s\n", ftdi_elan_driver.name,
2911 __TIME__, __DATE__); 2914 __TIME__, __DATE__);
2912 init_MUTEX(&ftdi_module_lock); 2915 mutex_init(&ftdi_module_lock);
2913 INIT_LIST_HEAD(&ftdi_static_list); 2916 INIT_LIST_HEAD(&ftdi_static_list);
2914 status_queue = create_singlethread_workqueue("ftdi-status-control"); 2917 status_queue = create_singlethread_workqueue("ftdi-status-control");
2915 if (!status_queue) 2918 if (!status_queue)
diff --git a/drivers/usb/misc/iowarrior.c b/drivers/usb/misc/iowarrior.c
index 28548d186712..46d9f27ec173 100644
--- a/drivers/usb/misc/iowarrior.c
+++ b/drivers/usb/misc/iowarrior.c
@@ -158,9 +158,10 @@ static void iowarrior_callback(struct urb *urb)
158 int read_idx; 158 int read_idx;
159 int aux_idx; 159 int aux_idx;
160 int offset; 160 int offset;
161 int status; 161 int status = urb->status;
162 int retval;
162 163
163 switch (urb->status) { 164 switch (status) {
164 case 0: 165 case 0:
165 /* success */ 166 /* success */
166 break; 167 break;
@@ -213,10 +214,10 @@ static void iowarrior_callback(struct urb *urb)
213 wake_up_interruptible(&dev->read_wait); 214 wake_up_interruptible(&dev->read_wait);
214 215
215exit: 216exit:
216 status = usb_submit_urb(urb, GFP_ATOMIC); 217 retval = usb_submit_urb(urb, GFP_ATOMIC);
217 if (status) 218 if (retval)
218 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d", 219 dev_err(&dev->interface->dev, "%s - usb_submit_urb failed with result %d",
219 __FUNCTION__, status); 220 __FUNCTION__, retval);
220 221
221} 222}
222 223
@@ -226,13 +227,15 @@ exit:
226static void iowarrior_write_callback(struct urb *urb) 227static void iowarrior_write_callback(struct urb *urb)
227{ 228{
228 struct iowarrior *dev; 229 struct iowarrior *dev;
230 int status = urb->status;
231
229 dev = (struct iowarrior *)urb->context; 232 dev = (struct iowarrior *)urb->context;
230 /* sync/async unlink faults aren't errors */ 233 /* sync/async unlink faults aren't errors */
231 if (urb->status && 234 if (status &&
232 !(urb->status == -ENOENT || 235 !(status == -ENOENT ||
233 urb->status == -ECONNRESET || urb->status == -ESHUTDOWN)) { 236 status == -ECONNRESET || status == -ESHUTDOWN)) {
234 dbg("%s - nonzero write bulk status received: %d", 237 dbg("%s - nonzero write bulk status received: %d",
235 __func__, urb->status); 238 __func__, status);
236 } 239 }
237 /* free up our allocated buffer */ 240 /* free up our allocated buffer */
238 usb_buffer_free(urb->dev, urb->transfer_buffer_length, 241 usb_buffer_free(urb->dev, urb->transfer_buffer_length,
diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 5e950b90c541..8208496dfc63 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -219,16 +219,17 @@ static void ld_usb_interrupt_in_callback(struct urb *urb)
219 struct ld_usb *dev = urb->context; 219 struct ld_usb *dev = urb->context;
220 size_t *actual_buffer; 220 size_t *actual_buffer;
221 unsigned int next_ring_head; 221 unsigned int next_ring_head;
222 int status = urb->status;
222 int retval; 223 int retval;
223 224
224 if (urb->status) { 225 if (status) {
225 if (urb->status == -ENOENT || 226 if (status == -ENOENT ||
226 urb->status == -ECONNRESET || 227 status == -ECONNRESET ||
227 urb->status == -ESHUTDOWN) { 228 status == -ESHUTDOWN) {
228 goto exit; 229 goto exit;
229 } else { 230 } else {
230 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", 231 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
231 __FUNCTION__, urb->status); 232 __FUNCTION__, status);
232 spin_lock(&dev->rbsl); 233 spin_lock(&dev->rbsl);
233 goto resubmit; /* maybe we can recover */ 234 goto resubmit; /* maybe we can recover */
234 } 235 }
@@ -275,14 +276,15 @@ exit:
275static void ld_usb_interrupt_out_callback(struct urb *urb) 276static void ld_usb_interrupt_out_callback(struct urb *urb)
276{ 277{
277 struct ld_usb *dev = urb->context; 278 struct ld_usb *dev = urb->context;
279 int status = urb->status;
278 280
279 /* sync/async unlink faults aren't errors */ 281 /* sync/async unlink faults aren't errors */
280 if (urb->status && !(urb->status == -ENOENT || 282 if (status && !(status == -ENOENT ||
281 urb->status == -ECONNRESET || 283 status == -ECONNRESET ||
282 urb->status == -ESHUTDOWN)) 284 status == -ESHUTDOWN))
283 dbg_info(&dev->intf->dev, 285 dbg_info(&dev->intf->dev,
284 "%s - nonzero write interrupt status received: %d\n", 286 "%s - nonzero write interrupt status received: %d\n",
285 __FUNCTION__, urb->status); 287 __FUNCTION__, status);
286 288
287 dev->interrupt_out_busy = 0; 289 dev->interrupt_out_busy = 0;
288 wake_up_interruptible(&dev->write_wait); 290 wake_up_interruptible(&dev->write_wait);
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 2ed0daea894c..561970b889a5 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -742,19 +742,20 @@ exit:
742static void tower_interrupt_in_callback (struct urb *urb) 742static void tower_interrupt_in_callback (struct urb *urb)
743{ 743{
744 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; 744 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context;
745 int status = urb->status;
745 int retval; 746 int retval;
746 747
747 dbg(4, "%s: enter, status %d", __FUNCTION__, urb->status); 748 dbg(4, "%s: enter, status %d", __FUNCTION__, status);
748 749
749 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 750 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
750 751
751 if (urb->status) { 752 if (status) {
752 if (urb->status == -ENOENT || 753 if (status == -ENOENT ||
753 urb->status == -ECONNRESET || 754 status == -ECONNRESET ||
754 urb->status == -ESHUTDOWN) { 755 status == -ESHUTDOWN) {
755 goto exit; 756 goto exit;
756 } else { 757 } else {
757 dbg(1, "%s: nonzero status received: %d", __FUNCTION__, urb->status); 758 dbg(1, "%s: nonzero status received: %d", __FUNCTION__, status);
758 goto resubmit; /* maybe we can recover */ 759 goto resubmit; /* maybe we can recover */
759 } 760 }
760 } 761 }
@@ -788,7 +789,7 @@ exit:
788 wake_up_interruptible (&dev->read_wait); 789 wake_up_interruptible (&dev->read_wait);
789 790
790 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 791 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
791 dbg(4, "%s: leave, status %d", __FUNCTION__, urb->status); 792 dbg(4, "%s: leave, status %d", __FUNCTION__, status);
792} 793}
793 794
794 795
@@ -798,23 +799,24 @@ exit:
798static void tower_interrupt_out_callback (struct urb *urb) 799static void tower_interrupt_out_callback (struct urb *urb)
799{ 800{
800 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context; 801 struct lego_usb_tower *dev = (struct lego_usb_tower *)urb->context;
802 int status = urb->status;
801 803
802 dbg(4, "%s: enter, status %d", __FUNCTION__, urb->status); 804 dbg(4, "%s: enter, status %d", __FUNCTION__, status);
803 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 805 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
804 806
805 /* sync/async unlink faults aren't errors */ 807 /* sync/async unlink faults aren't errors */
806 if (urb->status && !(urb->status == -ENOENT || 808 if (status && !(status == -ENOENT ||
807 urb->status == -ECONNRESET || 809 status == -ECONNRESET ||
808 urb->status == -ESHUTDOWN)) { 810 status == -ESHUTDOWN)) {
809 dbg(1, "%s - nonzero write bulk status received: %d", 811 dbg(1, "%s - nonzero write bulk status received: %d",
810 __FUNCTION__, urb->status); 812 __FUNCTION__, status);
811 } 813 }
812 814
813 dev->interrupt_out_busy = 0; 815 dev->interrupt_out_busy = 0;
814 wake_up_interruptible(&dev->write_wait); 816 wake_up_interruptible(&dev->write_wait);
815 817
816 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer); 818 lego_usb_tower_debug_data(5, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
817 dbg(4, "%s: leave, status %d", __FUNCTION__, urb->status); 819 dbg(4, "%s: leave, status %d", __FUNCTION__, status);
818} 820}
819 821
820 822
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index 371bf2b1197d..aa9bcceabe74 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -305,9 +305,10 @@ static void interfacekit_irq(struct urb *urb)
305 struct interfacekit *kit = urb->context; 305 struct interfacekit *kit = urb->context;
306 unsigned char *buffer = kit->data; 306 unsigned char *buffer = kit->data;
307 int i, level, sensor; 307 int i, level, sensor;
308 int status; 308 int retval;
309 int status = urb->status;
309 310
310 switch (urb->status) { 311 switch (status) {
311 case 0: /* success */ 312 case 0: /* success */
312 break; 313 break;
313 case -ECONNRESET: /* unlink */ 314 case -ECONNRESET: /* unlink */
@@ -377,11 +378,11 @@ static void interfacekit_irq(struct urb *urb)
377 schedule_delayed_work(&kit->do_notify, 0); 378 schedule_delayed_work(&kit->do_notify, 0);
378 379
379resubmit: 380resubmit:
380 status = usb_submit_urb(urb, GFP_ATOMIC); 381 retval = usb_submit_urb(urb, GFP_ATOMIC);
381 if (status) 382 if (retval)
382 err("can't resubmit intr, %s-%s/interfacekit0, status %d", 383 err("can't resubmit intr, %s-%s/interfacekit0, retval %d",
383 kit->udev->bus->bus_name, 384 kit->udev->bus->bus_name,
384 kit->udev->devpath, status); 385 kit->udev->devpath, retval);
385} 386}
386 387
387static void do_notify(struct work_struct *work) 388static void do_notify(struct work_struct *work)
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
index 5727e1ea2f91..df0ebcdb9d6a 100644
--- a/drivers/usb/misc/phidgetmotorcontrol.c
+++ b/drivers/usb/misc/phidgetmotorcontrol.c
@@ -95,9 +95,10 @@ static void motorcontrol_irq(struct urb *urb)
95 struct motorcontrol *mc = urb->context; 95 struct motorcontrol *mc = urb->context;
96 unsigned char *buffer = mc->data; 96 unsigned char *buffer = mc->data;
97 int i, level; 97 int i, level;
98 int status; 98 int retval;
99 int status = urb->status;;
99 100
100 switch (urb->status) { 101 switch (status) {
101 case 0: /* success */ 102 case 0: /* success */
102 break; 103 break;
103 case -ECONNRESET: /* unlink */ 104 case -ECONNRESET: /* unlink */
@@ -151,12 +152,12 @@ static void motorcontrol_irq(struct urb *urb)
151 schedule_delayed_work(&mc->do_notify, 0); 152 schedule_delayed_work(&mc->do_notify, 0);
152 153
153resubmit: 154resubmit:
154 status = usb_submit_urb(urb, GFP_ATOMIC); 155 retval = usb_submit_urb(urb, GFP_ATOMIC);
155 if (status) 156 if (retval)
156 dev_err(&mc->intf->dev, 157 dev_err(&mc->intf->dev,
157 "can't resubmit intr, %s-%s/motorcontrol0, status %d", 158 "can't resubmit intr, %s-%s/motorcontrol0, retval %d",
158 mc->udev->bus->bus_name, 159 mc->udev->bus->bus_name,
159 mc->udev->devpath, status); 160 mc->udev->devpath, retval);
160} 161}
161 162
162static void do_notify(struct work_struct *work) 163static void do_notify(struct work_struct *work)
diff --git a/drivers/usb/misc/usblcd.c b/drivers/usb/misc/usblcd.c
index 504f7221b0d0..719842032712 100644
--- a/drivers/usb/misc/usblcd.c
+++ b/drivers/usb/misc/usblcd.c
@@ -176,16 +176,17 @@ static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
176static void lcd_write_bulk_callback(struct urb *urb) 176static void lcd_write_bulk_callback(struct urb *urb)
177{ 177{
178 struct usb_lcd *dev; 178 struct usb_lcd *dev;
179 int status = urb->status;
179 180
180 dev = (struct usb_lcd *)urb->context; 181 dev = (struct usb_lcd *)urb->context;
181 182
182 /* sync/async unlink faults aren't errors */ 183 /* sync/async unlink faults aren't errors */
183 if (urb->status && 184 if (status &&
184 !(urb->status == -ENOENT || 185 !(status == -ENOENT ||
185 urb->status == -ECONNRESET || 186 status == -ECONNRESET ||
186 urb->status == -ESHUTDOWN)) { 187 status == -ESHUTDOWN)) {
187 dbg("USBLCD: %s - nonzero write bulk status received: %d", 188 dbg("USBLCD: %s - nonzero write bulk status received: %d",
188 __FUNCTION__, urb->status); 189 __FUNCTION__, status);
189 } 190 }
190 191
191 /* free up our allocated buffer */ 192 /* free up our allocated buffer */
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index fb321864a92d..e901d31e051b 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -768,8 +768,8 @@ static void ctrl_complete (struct urb *urb)
768 768
769 /* some faults are allowed, not required */ 769 /* some faults are allowed, not required */
770 if (subcase->expected > 0 && ( 770 if (subcase->expected > 0 && (
771 ((urb->status == -subcase->expected /* happened */ 771 ((status == -subcase->expected /* happened */
772 || urb->status == 0)))) /* didn't */ 772 || status == 0)))) /* didn't */
773 status = 0; 773 status = 0;
774 /* sometimes more than one fault is allowed */ 774 /* sometimes more than one fault is allowed */
775 else if (subcase->number == 12 && status == -EPIPE) 775 else if (subcase->number == 12 && status == -EPIPE)
diff --git a/drivers/usb/misc/uss720.c b/drivers/usb/misc/uss720.c
index 1a60f9c473ad..2734fe2b9c43 100644
--- a/drivers/usb/misc/uss720.c
+++ b/drivers/usb/misc/uss720.c
@@ -111,12 +111,13 @@ static void async_complete(struct urb *urb)
111 struct uss720_async_request *rq; 111 struct uss720_async_request *rq;
112 struct parport *pp; 112 struct parport *pp;
113 struct parport_uss720_private *priv; 113 struct parport_uss720_private *priv;
114 int status = urb->status;
114 115
115 rq = urb->context; 116 rq = urb->context;
116 priv = rq->priv; 117 priv = rq->priv;
117 pp = priv->pp; 118 pp = priv->pp;
118 if (urb->status) { 119 if (status) {
119 err("async_complete: urb error %d", urb->status); 120 err("async_complete: urb error %d", status);
120 } else if (rq->dr.bRequest == 3) { 121 } else if (rq->dr.bRequest == 3) {
121 memcpy(priv->reg, rq->reg, sizeof(priv->reg)); 122 memcpy(priv->reg, rq->reg, sizeof(priv->reg));
122#if 0 123#if 0
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 0d3903691e8c..b8670905bc3a 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2794,16 +2794,14 @@ static void edge_shutdown (struct usb_serial *serial)
2794 2794
2795 dbg ("%s", __FUNCTION__); 2795 dbg ("%s", __FUNCTION__);
2796 2796
2797 for (i=0; i < serial->num_ports; ++i) { 2797 for (i = 0; i < serial->num_ports; ++i) {
2798 edge_port = usb_get_serial_port_data(serial->port[i]); 2798 edge_port = usb_get_serial_port_data(serial->port[i]);
2799 edge_remove_sysfs_attrs(edge_port->port); 2799 edge_remove_sysfs_attrs(edge_port->port);
2800 if (edge_port) { 2800 edge_buf_free(edge_port->ep_out_buf);
2801 edge_buf_free(edge_port->ep_out_buf); 2801 kfree(edge_port);
2802 kfree(edge_port);
2803 }
2804 usb_set_serial_port_data(serial->port[i], NULL); 2802 usb_set_serial_port_data(serial->port[i], NULL);
2805 } 2803 }
2806 kfree (usb_get_serial_data(serial)); 2804 kfree(usb_get_serial_data(serial));
2807 usb_set_serial_data(serial, NULL); 2805 usb_set_serial_data(serial, NULL);
2808} 2806}
2809 2807
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 231b584f6d0f..01e811becec4 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -110,11 +110,6 @@ static void mos7720_interrupt_callback(struct urb *urb)
110 110
111 dbg("%s"," : Entering\n"); 111 dbg("%s"," : Entering\n");
112 112
113 if (!urb) {
114 dbg("%s","Invalid Pointer !!!!:\n");
115 return;
116 }
117
118 switch (status) { 113 switch (status) {
119 case 0: 114 case 0:
120 /* success */ 115 /* success */
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 37f41f576d3d..f76480f1455d 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -436,11 +436,6 @@ static void mos7840_control_callback(struct urb *urb)
436 int result = 0; 436 int result = 0;
437 int status = urb->status; 437 int status = urb->status;
438 438
439 if (!urb) {
440 dbg("%s", "Invalid Pointer !!!!:\n");
441 return;
442 }
443
444 mos7840_port = (struct moschip_port *)urb->context; 439 mos7840_port = (struct moschip_port *)urb->context;
445 440
446 switch (status) { 441 switch (status) {
@@ -525,10 +520,6 @@ static void mos7840_interrupt_callback(struct urb *urb)
525 int status = urb->status; 520 int status = urb->status;
526 521
527 dbg("%s", " : Entering\n"); 522 dbg("%s", " : Entering\n");
528 if (!urb) {
529 dbg("%s", "Invalid Pointer !!!!:\n");
530 return;
531 }
532 523
533 switch (status) { 524 switch (status) {
534 case 0: 525 case 0:
@@ -676,11 +667,6 @@ static void mos7840_bulk_in_callback(struct urb *urb)
676 struct tty_struct *tty; 667 struct tty_struct *tty;
677 int status = urb->status; 668 int status = urb->status;
678 669
679 if (!urb) {
680 dbg("%s", "Invalid Pointer !!!!:\n");
681 return;
682 }
683
684 if (status) { 670 if (status) {
685 dbg("nonzero read bulk status received: %d", status); 671 dbg("nonzero read bulk status received: %d", status);
686 return; 672 return;
@@ -753,11 +739,6 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
753 int status = urb->status; 739 int status = urb->status;
754 int i; 740 int i;
755 741
756 if (!urb) {
757 dbg("%s", "Invalid Pointer !!!!:\n");
758 return;
759 }
760
761 mos7840_port = (struct moschip_port *)urb->context; 742 mos7840_port = (struct moschip_port *)urb->context;
762 spin_lock(&mos7840_port->pool_lock); 743 spin_lock(&mos7840_port->pool_lock);
763 for (i = 0; i < NUM_URBS; i++) { 744 for (i = 0; i < NUM_URBS; i++) {
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index e7db20343d1a..0794ccdebfd4 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -1,7 +1,7 @@
1/* 1/*
2 USB Driver for Sierra Wireless 2 USB Driver for Sierra Wireless
3 3
4 Copyright (C) 2006 Kevin Lloyd <linux@sierrawireless.com> 4 Copyright (C) 2006, 2007 Kevin Lloyd <linux@sierrawireless.com>
5 5
6 IMPORTANT DISCLAIMER: This driver is not commercially supported by 6 IMPORTANT DISCLAIMER: This driver is not commercially supported by
7 Sierra Wireless. Use at your own risk. 7 Sierra Wireless. Use at your own risk.
@@ -12,10 +12,9 @@
12 12
13 Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de> 13 Portions based on the option driver by Matthias Urlichs <smurf@smurf.noris.de>
14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org> 14 Whom based his on the Keyspan driver by Hugh Blemings <hugh@blemings.org>
15
16*/ 15*/
17 16
18#define DRIVER_VERSION "v.1.0.6" 17#define DRIVER_VERSION "v.1.2.5b"
19#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>" 18#define DRIVER_AUTHOR "Kevin Lloyd <linux@sierrawireless.com>"
20#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" 19#define DRIVER_DESC "USB Driver for Sierra Wireless USB modems"
21 20
@@ -28,23 +27,98 @@
28#include <linux/usb.h> 27#include <linux/usb.h>
29#include <linux/usb/serial.h> 28#include <linux/usb/serial.h>
30 29
30#define SWIMS_USB_REQUEST_SetMode 0x0B
31#define SWIMS_USB_REQUEST_TYPE_SetMode 0x40
32#define SWIMS_USB_INDEX_SetMode 0x0000
33#define SWIMS_SET_MODE_Modem 0x0001
34
35/* per port private data */
36#define N_IN_URB 4
37#define N_OUT_URB 4
38#define IN_BUFLEN 4096
39
40static int debug;
41
42enum devicetype {
43 DEVICE_3_PORT = 0,
44 DEVICE_1_PORT = 1,
45 DEVICE_INSTALLER = 2,
46};
47
48int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
49{
50 int result;
51 dev_dbg(&udev->dev, "%s", "SET POWER STATE");
52 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
53 0x00, /* __u8 request */
54 0x40, /* __u8 request type */
55 swiState, /* __u16 value */
56 0, /* __u16 index */
57 NULL, /* void *data */
58 0, /* __u16 size */
59 USB_CTRL_SET_TIMEOUT); /* int timeout */
60 return result;
61}
62
63int sierra_set_ms_mode(struct usb_device *udev, __u16 eSocMode)
64{
65 int result;
66 dev_dbg(&udev->dev, "%s", "DEVICE MODE SWITCH");
67 result = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
68 SWIMS_USB_REQUEST_SetMode, /* __u8 request */
69 SWIMS_USB_REQUEST_TYPE_SetMode, /* __u8 request type */
70 eSocMode, /* __u16 value */
71 SWIMS_USB_INDEX_SetMode, /* __u16 index */
72 NULL, /* void *data */
73 0, /* __u16 size */
74 USB_CTRL_SET_TIMEOUT); /* int timeout */
75 return result;
76}
77
78int sierra_probe(struct usb_interface *iface, const struct usb_device_id *id)
79{
80 int result;
81 struct usb_device *udev;
82
83 udev = usb_get_dev(interface_to_usbdev(iface));
84
85 /* Check if in installer mode */
86 if (id->driver_info == DEVICE_INSTALLER) {
87 dev_dbg(&udev->dev, "%s", "FOUND DEVICE(SW)\n");
88 result = sierra_set_ms_mode(udev, SWIMS_SET_MODE_Modem);
89 /*We do not want to bind to the device when in installer mode*/
90 return -EIO;
91 }
92
93 return usb_serial_probe(iface, id);
94}
31 95
32static struct usb_device_id id_table [] = { 96static struct usb_device_id id_table [] = {
33 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ 97 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
34 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ 98 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
35 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ 99 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
100 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
36 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ 101 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
37 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 102 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
38 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
39 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 103 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
104 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U */
105
40 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ 106 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
41 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 107 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
42 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ 108 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
43 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */ 109 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
44 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ 110 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
111 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
112 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
113 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
114 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
115 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
116 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881 E */
45 117
46 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ 118 { USB_DEVICE(0x1199, 0x0112), .driver_info = DEVICE_1_PORT }, /* Sierra Wireless AirCard 580 */
47 { USB_DEVICE(0x0F3D, 0x0112) }, /* AirPrime/Sierra PC 5220 */ 119 { USB_DEVICE(0x0F3D, 0x0112), .driver_info = DEVICE_1_PORT }, /* Airprime/Sierra PC 5220 */
120
121 { USB_DEVICE(0x1199, 0x0FFF), .driver_info = DEVICE_INSTALLER},
48 { } 122 { }
49}; 123};
50MODULE_DEVICE_TABLE(usb, id_table); 124MODULE_DEVICE_TABLE(usb, id_table);
@@ -58,35 +132,36 @@ static struct usb_device_id id_table_1port [] = {
58static struct usb_device_id id_table_3port [] = { 132static struct usb_device_id id_table_3port [] = {
59 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ 133 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
60 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ 134 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
135 { USB_DEVICE(0x0f30, 0x1b1d) }, /* Sierra Wireless MC5720 */
61 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */ 136 { USB_DEVICE(0x1199, 0x0218) }, /* Sierra Wireless MC5720 */
62 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */ 137 { USB_DEVICE(0x1199, 0x0020) }, /* Sierra Wireless MC5725 */
63 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */ 138 { USB_DEVICE(0x1199, 0x0019) }, /* Sierra Wireless AirCard 595 */
64 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless AirCard 595U */
65 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */ 139 { USB_DEVICE(0x1199, 0x0021) }, /* Sierra Wireless AirCard 597E */
140 { USB_DEVICE(0x1199, 0x0120) }, /* Sierra Wireless USB Dongle 595U*/
141
66 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */ 142 { USB_DEVICE(0x1199, 0x6802) }, /* Sierra Wireless MC8755 */
67 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */ 143 { USB_DEVICE(0x1199, 0x6804) }, /* Sierra Wireless MC8755 */
68 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */ 144 { USB_DEVICE(0x1199, 0x6803) }, /* Sierra Wireless MC8765 */
69 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 */ 145 { USB_DEVICE(0x1199, 0x6812) }, /* Sierra Wireless MC8775 & AC 875U */
70 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */ 146 { USB_DEVICE(0x1199, 0x6820) }, /* Sierra Wireless AirCard 875 */
147 { USB_DEVICE(0x1199, 0x6832) }, /* Sierra Wireless MC8780*/
148 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781*/
149 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
150 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
151 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880E */
152 { USB_DEVICE(0x1199, 0x6853) }, /* Sierra Wireless AirCard 881E */
71 { } 153 { }
72}; 154};
73 155
74static struct usb_driver sierra_driver = { 156static struct usb_driver sierra_driver = {
75 .name = "sierra", 157 .name = "sierra",
76 .probe = usb_serial_probe, 158 .probe = sierra_probe,
77 .disconnect = usb_serial_disconnect, 159 .disconnect = usb_serial_disconnect,
78 .id_table = id_table, 160 .id_table = id_table,
79 .no_dynamic_id = 1, 161 .no_dynamic_id = 1,
80}; 162};
81 163
82 164
83static int debug;
84
85/* per port private data */
86#define N_IN_URB 4
87#define N_OUT_URB 4
88#define IN_BUFLEN 4096
89
90struct sierra_port_private { 165struct sierra_port_private {
91 spinlock_t lock; /* lock the structure */ 166 spinlock_t lock; /* lock the structure */
92 int outstanding_urbs; /* number of out urbs in flight */ 167 int outstanding_urbs; /* number of out urbs in flight */
@@ -421,7 +496,6 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
421 int i; 496 int i;
422 struct urb *urb; 497 struct urb *urb;
423 int result; 498 int result;
424 __u16 set_mode_dzero = 0x0000;
425 499
426 portdata = usb_get_serial_port_data(port); 500 portdata = usb_get_serial_port_data(port);
427 501
@@ -457,12 +531,6 @@ static int sierra_open(struct usb_serial_port *port, struct file *filp)
457 531
458 port->tty->low_latency = 1; 532 port->tty->low_latency = 1;
459 533
460 /* set mode to D0 */
461 result = usb_control_msg(serial->dev,
462 usb_rcvctrlpipe(serial->dev, 0),
463 0x00, 0x40, set_mode_dzero, 0, NULL,
464 0, USB_CTRL_SET_TIMEOUT);
465
466 sierra_send_setup(port); 534 sierra_send_setup(port);
467 535
468 /* start up the interrupt endpoint if we have one */ 536 /* start up the interrupt endpoint if we have one */
@@ -510,6 +578,9 @@ static int sierra_startup(struct usb_serial *serial)
510 578
511 dbg("%s", __FUNCTION__); 579 dbg("%s", __FUNCTION__);
512 580
581 /*Set Device mode to D0 */
582 sierra_set_power_state(serial->dev, 0x0000);
583
513 /* Now setup per port private data */ 584 /* Now setup per port private data */
514 for (i = 0; i < serial->num_ports; i++) { 585 for (i = 0; i < serial->num_ports; i++) {
515 port = serial->port[i]; 586 port = serial->port[i];
diff --git a/drivers/usb/storage/dpcm.c b/drivers/usb/storage/dpcm.c
index 1628cb258562..9a410b5a6e5b 100644
--- a/drivers/usb/storage/dpcm.c
+++ b/drivers/usb/storage/dpcm.c
@@ -46,43 +46,43 @@
46 */ 46 */
47int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) 47int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
48{ 48{
49 int ret; 49 int ret;
50 50
51 if(srb == NULL) 51 if (srb == NULL)
52 return USB_STOR_TRANSPORT_ERROR; 52 return USB_STOR_TRANSPORT_ERROR;
53 53
54 US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun); 54 US_DEBUGP("dpcm_transport: LUN=%d\n", srb->device->lun);
55 55
56 switch(srb->device->lun) { 56 switch (srb->device->lun) {
57 case 0: 57 case 0:
58 58
59 /* 59 /*
60 * LUN 0 corresponds to the CompactFlash card reader. 60 * LUN 0 corresponds to the CompactFlash card reader.
61 */ 61 */
62 ret = usb_stor_CB_transport(srb, us); 62 ret = usb_stor_CB_transport(srb, us);
63 break; 63 break;
64 64
65#ifdef CONFIG_USB_STORAGE_SDDR09 65#ifdef CONFIG_USB_STORAGE_SDDR09
66 case 1: 66 case 1:
67 67
68 /* 68 /*
69 * LUN 1 corresponds to the SmartMedia card reader. 69 * LUN 1 corresponds to the SmartMedia card reader.
70 */ 70 */
71 71
72 /* 72 /*
73 * Set the LUN to 0 (just in case). 73 * Set the LUN to 0 (just in case).
74 */ 74 */
75 srb->device->lun = 0; us->srb->device->lun = 0; 75 srb->device->lun = 0; us->srb->device->lun = 0;
76 ret = sddr09_transport(srb, us); 76 ret = sddr09_transport(srb, us);
77 srb->device->lun = 1; us->srb->device->lun = 1; 77 srb->device->lun = 1; us->srb->device->lun = 1;
78 break; 78 break;
79 79
80#endif 80#endif
81 81
82 default: 82 default:
83 US_DEBUGP("dpcm_transport: Invalid LUN %d\n", srb->device->lun); 83 US_DEBUGP("dpcm_transport: Invalid LUN %d\n", srb->device->lun);
84 ret = USB_STOR_TRANSPORT_ERROR; 84 ret = USB_STOR_TRANSPORT_ERROR;
85 break; 85 break;
86 } 86 }
87 return ret; 87 return ret;
88} 88}
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index d35369392fed..dfd42fe9e5f0 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -57,9 +57,10 @@ static void usb_onetouch_irq(struct urb *urb)
57 struct usb_onetouch *onetouch = urb->context; 57 struct usb_onetouch *onetouch = urb->context;
58 signed char *data = onetouch->data; 58 signed char *data = onetouch->data;
59 struct input_dev *dev = onetouch->dev; 59 struct input_dev *dev = onetouch->dev;
60 int status; 60 int status = urb->status;
61 int retval;
61 62
62 switch (urb->status) { 63 switch (status) {
63 case 0: /* success */ 64 case 0: /* success */
64 break; 65 break;
65 case -ECONNRESET: /* unlink */ 66 case -ECONNRESET: /* unlink */
@@ -75,11 +76,11 @@ static void usb_onetouch_irq(struct urb *urb)
75 input_sync(dev); 76 input_sync(dev);
76 77
77resubmit: 78resubmit:
78 status = usb_submit_urb (urb, GFP_ATOMIC); 79 retval = usb_submit_urb (urb, GFP_ATOMIC);
79 if (status) 80 if (retval)
80 err ("can't resubmit intr, %s-%s/input0, status %d", 81 err ("can't resubmit intr, %s-%s/input0, retval %d",
81 onetouch->udev->bus->bus_name, 82 onetouch->udev->bus->bus_name,
82 onetouch->udev->devpath, status); 83 onetouch->udev->devpath, retval);
83} 84}
84 85
85static int usb_onetouch_open(struct input_dev *dev) 86static int usb_onetouch_open(struct input_dev *dev)
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index b6bf31a97b60..a624e72f81dc 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -313,6 +313,13 @@ UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010,
313 US_SC_DEVICE, US_PR_DEVICE,NULL, 313 US_SC_DEVICE, US_PR_DEVICE,NULL,
314 US_FL_NOT_LOCKABLE ), 314 US_FL_NOT_LOCKABLE ),
315 315
316/* Reported by Stefan de Konink <skinkie@xs4all.nl> */
317UNUSUAL_DEV( 0x04b0, 0x0401, 0x0200, 0x0200,
318 "NIKON",
319 "NIKON DSC D100",
320 US_SC_DEVICE, US_PR_DEVICE, NULL,
321 US_FL_FIX_CAPACITY),
322
316/* Reported by Andreas Bockhold <andreas@bockionline.de> */ 323/* Reported by Andreas Bockhold <andreas@bockionline.de> */
317UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100, 324UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100,
318 "NIKON", 325 "NIKON",
@@ -1384,6 +1391,17 @@ UNUSUAL_DEV( 0x1019, 0x0c55, 0x0000, 0x0110,
1384 US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init, 1391 US_SC_DEVICE, US_PR_DEVICE, usb_stor_ucr61s2b_init,
1385 0 ), 1392 0 ),
1386 1393
1394/* Reported by Kevin Lloyd <linux@sierrawireless.com>
1395 * Entry is needed for the initializer function override,
1396 * which instructs the device to load as a modem
1397 * device.
1398 */
1399UNUSUAL_DEV( 0x1199, 0x0fff, 0x0000, 0x9999,
1400 "Sierra Wireless",
1401 "USB MMC Storage",
1402 US_SC_DEVICE, US_PR_DEVICE, NULL,
1403 US_FL_IGNORE_DEVICE),
1404
1387/* Reported by Jaco Kroon <jaco@kroon.co.za> 1405/* Reported by Jaco Kroon <jaco@kroon.co.za>
1388 * The usb-storage module found on the Digitech GNX4 (and supposedly other 1406 * The usb-storage module found on the Digitech GNX4 (and supposedly other
1389 * devices) misbehaves and causes a bunch of invalid I/O errors. 1407 * devices) misbehaves and causes a bunch of invalid I/O errors.
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 0c5644bb59af..564cc9b51822 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -12,6 +12,13 @@ config VGASTATE
12 tristate 12 tristate
13 default n 13 default n
14 14
15config VIDEO_OUTPUT_CONTROL
16 tristate "Lowlevel video output switch controls"
17 default m
18 help
19 This framework adds support for low-level control of the video
20 output switch.
21
15config FB 22config FB
16 tristate "Support for frame buffer devices" 23 tristate "Support for frame buffer devices"
17 ---help--- 24 ---help---
@@ -849,6 +856,16 @@ config FB_INTSRAM
849 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want 856 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
850 to let frame buffer in external SDRAM. 857 to let frame buffer in external SDRAM.
851 858
859config FB_ATMEL_STN
860 bool "Use a STN display with AT91/AT32 LCD Controller"
861 depends on FB_ATMEL && MACH_AT91SAM9261EK
862 default n
863 help
864 Say Y if you want to connect a STN LCD display to the AT91/AT32 LCD
865 Controller. Say N if you want to connect a TFT.
866
867 If unsure, say N.
868
852config FB_NVIDIA 869config FB_NVIDIA
853 tristate "nVidia Framebuffer Support" 870 tristate "nVidia Framebuffer Support"
854 depends on FB && PCI 871 depends on FB && PCI
@@ -1796,13 +1813,14 @@ config FB_PS3
1796 select FB_SYS_COPYAREA 1813 select FB_SYS_COPYAREA
1797 select FB_SYS_IMAGEBLIT 1814 select FB_SYS_IMAGEBLIT
1798 select FB_SYS_FOPS 1815 select FB_SYS_FOPS
1816 select VT_HW_CONSOLE_BINDING if FRAMEBUFFER_CONSOLE
1799 ---help--- 1817 ---help---
1800 Include support for the virtual frame buffer in the PS3 platform. 1818 Include support for the virtual frame buffer in the PS3 platform.
1801 1819
1802config FB_PS3_DEFAULT_SIZE_M 1820config FB_PS3_DEFAULT_SIZE_M
1803 int "PS3 default frame buffer size (in MiB)" 1821 int "PS3 default frame buffer size (in MiB)"
1804 depends on FB_PS3 1822 depends on FB_PS3
1805 default 18 1823 default 9
1806 ---help--- 1824 ---help---
1807 This is the default size (in MiB) of the virtual frame buffer in 1825 This is the default size (in MiB) of the virtual frame buffer in
1808 the PS3. 1826 the PS3.
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index a562f9d69d2c..518933d4905f 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -123,3 +123,6 @@ obj-$(CONFIG_FB_OF) += offb.o
123 123
124# the test framebuffer is last 124# the test framebuffer is last
125obj-$(CONFIG_FB_VIRTUAL) += vfb.o 125obj-$(CONFIG_FB_VIRTUAL) += vfb.o
126
127#video output switch sysfs driver
128obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index e1d5bd0c98c4..235b618b4117 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -79,6 +79,29 @@ static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
79 .accel = FB_ACCEL_NONE, 79 .accel = FB_ACCEL_NONE,
80}; 80};
81 81
82static unsigned long compute_hozval(unsigned long xres, unsigned long lcdcon2)
83{
84 unsigned long value;
85
86 if (!(cpu_is_at91sam9261() || cpu_is_at32ap7000()))
87 return xres;
88
89 value = xres;
90 if ((lcdcon2 & ATMEL_LCDC_DISTYPE) != ATMEL_LCDC_DISTYPE_TFT) {
91 /* STN display */
92 if ((lcdcon2 & ATMEL_LCDC_DISTYPE) == ATMEL_LCDC_DISTYPE_STNCOLOR) {
93 value *= 3;
94 }
95 if ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_4
96 || ( (lcdcon2 & ATMEL_LCDC_IFWIDTH) == ATMEL_LCDC_IFWIDTH_8
97 && (lcdcon2 & ATMEL_LCDC_SCANMOD) == ATMEL_LCDC_SCANMOD_DUAL ))
98 value = DIV_ROUND_UP(value, 4);
99 else
100 value = DIV_ROUND_UP(value, 8);
101 }
102
103 return value;
104}
82 105
83static void atmel_lcdfb_update_dma(struct fb_info *info, 106static void atmel_lcdfb_update_dma(struct fb_info *info,
84 struct fb_var_screeninfo *var) 107 struct fb_var_screeninfo *var)
@@ -181,6 +204,7 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
181 var->xoffset = var->yoffset = 0; 204 var->xoffset = var->yoffset = 0;
182 205
183 switch (var->bits_per_pixel) { 206 switch (var->bits_per_pixel) {
207 case 1:
184 case 2: 208 case 2:
185 case 4: 209 case 4:
186 case 8: 210 case 8:
@@ -195,8 +219,11 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
195 var->blue.offset = 10; 219 var->blue.offset = 10;
196 var->red.length = var->green.length = var->blue.length = 5; 220 var->red.length = var->green.length = var->blue.length = 5;
197 break; 221 break;
198 case 24:
199 case 32: 222 case 32:
223 var->transp.offset = 24;
224 var->transp.length = 8;
225 /* fall through */
226 case 24:
200 var->red.offset = 0; 227 var->red.offset = 0;
201 var->green.offset = 8; 228 var->green.offset = 8;
202 var->blue.offset = 16; 229 var->blue.offset = 16;
@@ -228,8 +255,10 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
228static int atmel_lcdfb_set_par(struct fb_info *info) 255static int atmel_lcdfb_set_par(struct fb_info *info)
229{ 256{
230 struct atmel_lcdfb_info *sinfo = info->par; 257 struct atmel_lcdfb_info *sinfo = info->par;
258 unsigned long hozval_linesz;
231 unsigned long value; 259 unsigned long value;
232 unsigned long clk_value_khz; 260 unsigned long clk_value_khz;
261 unsigned long bits_per_line;
233 262
234 dev_dbg(info->device, "%s:\n", __func__); 263 dev_dbg(info->device, "%s:\n", __func__);
235 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n", 264 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
@@ -241,12 +270,15 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
241 270
242 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0); 271 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
243 272
244 if (info->var.bits_per_pixel <= 8) 273 if (info->var.bits_per_pixel == 1)
274 info->fix.visual = FB_VISUAL_MONO01;
275 else if (info->var.bits_per_pixel <= 8)
245 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 276 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
246 else 277 else
247 info->fix.visual = FB_VISUAL_TRUECOLOR; 278 info->fix.visual = FB_VISUAL_TRUECOLOR;
248 279
249 info->fix.line_length = info->var.xres_virtual * (info->var.bits_per_pixel / 8); 280 bits_per_line = info->var.xres_virtual * info->var.bits_per_pixel;
281 info->fix.line_length = DIV_ROUND_UP(bits_per_line, 8);
250 282
251 /* Re-initialize the DMA engine... */ 283 /* Re-initialize the DMA engine... */
252 dev_dbg(info->device, " * update DMA engine\n"); 284 dev_dbg(info->device, " * update DMA engine\n");
@@ -262,18 +294,21 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
262 /* Set pixel clock */ 294 /* Set pixel clock */
263 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000; 295 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
264 296
265 value = clk_value_khz / PICOS2KHZ(info->var.pixclock); 297 value = DIV_ROUND_UP(clk_value_khz, PICOS2KHZ(info->var.pixclock));
266
267 if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
268 value++;
269 298
270 value = (value / 2) - 1; 299 value = (value / 2) - 1;
300 dev_dbg(info->device, " * programming CLKVAL = 0x%08lx\n", value);
271 301
272 if (value <= 0) { 302 if (value <= 0) {
273 dev_notice(info->device, "Bypassing pixel clock divider\n"); 303 dev_notice(info->device, "Bypassing pixel clock divider\n");
274 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS); 304 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
275 } else 305 } else {
276 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET); 306 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET);
307 info->var.pixclock = KHZ2PICOS(clk_value_khz / (2 * (value + 1)));
308 dev_dbg(info->device, " updated pixclk: %lu KHz\n",
309 PICOS2KHZ(info->var.pixclock));
310 }
311
277 312
278 /* Initialize control register 2 */ 313 /* Initialize control register 2 */
279 value = sinfo->default_lcdcon2; 314 value = sinfo->default_lcdcon2;
@@ -311,9 +346,14 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
311 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value); 346 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
312 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value); 347 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
313 348
349 /* Horizontal value (aka line size) */
350 hozval_linesz = compute_hozval(info->var.xres,
351 lcdc_readl(sinfo, ATMEL_LCDC_LCDCON2));
352
314 /* Display size */ 353 /* Display size */
315 value = (info->var.xres - 1) << ATMEL_LCDC_HOZVAL_OFFSET; 354 value = (hozval_linesz - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
316 value |= info->var.yres - 1; 355 value |= info->var.yres - 1;
356 dev_dbg(info->device, " * LCDFRMCFG = %08lx\n", value);
317 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value); 357 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
318 358
319 /* FIFO Threshold: Use formula from data sheet */ 359 /* FIFO Threshold: Use formula from data sheet */
@@ -421,6 +461,15 @@ static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
421 ret = 0; 461 ret = 0;
422 } 462 }
423 break; 463 break;
464
465 case FB_VISUAL_MONO01:
466 if (regno < 2) {
467 val = (regno == 0) ? 0x00 : 0x1F;
468 lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
469 ret = 0;
470 }
471 break;
472
424 } 473 }
425 474
426 return ret; 475 return ret;
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 7fea4d8ae8e2..cfcbe37d2d70 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1733,7 +1733,7 @@ static int aty128_bl_get_level_brightness(struct aty128fb_par *par,
1733 1733
1734static int aty128_bl_update_status(struct backlight_device *bd) 1734static int aty128_bl_update_status(struct backlight_device *bd)
1735{ 1735{
1736 struct aty128fb_par *par = class_get_devdata(&bd->class_dev); 1736 struct aty128fb_par *par = bl_get_data(bd);
1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL); 1737 unsigned int reg = aty_ld_le32(LVDS_GEN_CNTL);
1738 int level; 1738 int level;
1739 1739
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 0c7bf75732ea..bc6f0096aa04 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2141,7 +2141,7 @@ static int aty_bl_get_level_brightness(struct atyfb_par *par, int level)
2141 2141
2142static int aty_bl_update_status(struct backlight_device *bd) 2142static int aty_bl_update_status(struct backlight_device *bd)
2143{ 2143{
2144 struct atyfb_par *par = class_get_devdata(&bd->class_dev); 2144 struct atyfb_par *par = bl_get_data(bd);
2145 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par); 2145 unsigned int reg = aty_ld_lcd(LCD_MISC_CNTL, par);
2146 int level; 2146 int level;
2147 2147
@@ -2913,10 +2913,6 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
2913 int node, len, i, j, ret; 2913 int node, len, i, j, ret;
2914 u32 mem, chip_id; 2914 u32 mem, chip_id;
2915 2915
2916 /* Do not attach when we have a serial console. */
2917 if (!con_is_present())
2918 return -ENXIO;
2919
2920 /* 2916 /*
2921 * Map memory-mapped registers. 2917 * Map memory-mapped registers.
2922 */ 2918 */
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 0be25fa5540c..1a056adb61c8 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -47,7 +47,7 @@ static int radeon_bl_get_level_brightness(struct radeon_bl_privdata *pdata,
47 47
48static int radeon_bl_update_status(struct backlight_device *bd) 48static int radeon_bl_update_status(struct backlight_device *bd)
49{ 49{
50 struct radeon_bl_privdata *pdata = class_get_devdata(&bd->class_dev); 50 struct radeon_bl_privdata *pdata = bl_get_data(bd);
51 struct radeonfb_info *rinfo = pdata->rinfo; 51 struct radeonfb_info *rinfo = pdata->rinfo;
52 u32 lvds_gen_cntl, tmpPixclksCntl; 52 u32 lvds_gen_cntl, tmpPixclksCntl;
53 int level; 53 int level;
@@ -206,7 +206,7 @@ void radeonfb_bl_exit(struct radeonfb_info *rinfo)
206 if (bd) { 206 if (bd) {
207 struct radeon_bl_privdata *pdata; 207 struct radeon_bl_privdata *pdata;
208 208
209 pdata = class_get_devdata(&bd->class_dev); 209 pdata = bl_get_data(bd);
210 backlight_device_unregister(bd); 210 backlight_device_unregister(bd);
211 kfree(pdata); 211 kfree(pdata);
212 rinfo->info->bl_dev = NULL; 212 rinfo->info->bl_dev = NULL;
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index fbef663fc057..2580f5fa2486 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -8,26 +8,32 @@ menuconfig BACKLIGHT_LCD_SUPPORT
8 Enable this to be able to choose the drivers for controlling the 8 Enable this to be able to choose the drivers for controlling the
9 backlight and the LCD panel on some platforms, for example on PDAs. 9 backlight and the LCD panel on some platforms, for example on PDAs.
10 10
11config BACKLIGHT_CLASS_DEVICE 11#
12 tristate "Lowlevel Backlight controls" 12# LCD
13#
14config LCD_CLASS_DEVICE
15 tristate "Lowlevel LCD controls"
13 depends on BACKLIGHT_LCD_SUPPORT 16 depends on BACKLIGHT_LCD_SUPPORT
14 default m 17 default m
15 help 18 help
16 This framework adds support for low-level control of the LCD 19 This framework adds support for low-level control of LCD.
17 backlight. This includes support for brightness and power. 20 Some framebuffer devices connect to platform-specific LCD modules
21 in order to have a platform-specific way to control the flat panel
22 (contrast and applying power to the LCD (not to the backlight!)).
18 23
19 To have support for your specific LCD panel you will have to 24 To have support for your specific LCD panel you will have to
20 select the proper drivers which depend on this option. 25 select the proper drivers which depend on this option.
21 26
22config LCD_CLASS_DEVICE 27#
23 tristate "Lowlevel LCD controls" 28# Backlight
29#
30config BACKLIGHT_CLASS_DEVICE
31 tristate "Lowlevel Backlight controls"
24 depends on BACKLIGHT_LCD_SUPPORT 32 depends on BACKLIGHT_LCD_SUPPORT
25 default m 33 default m
26 help 34 help
27 This framework adds support for low-level control of LCD. 35 This framework adds support for low-level control of the LCD
28 Some framebuffer devices connect to platform-specific LCD modules 36 backlight. This includes support for brightness and power.
29 in order to have a platform-specific way to control the flat panel
30 (contrast and applying power to the LCD (not to the backlight!)).
31 37
32 To have support for your specific LCD panel you will have to 38 To have support for your specific LCD panel you will have to
33 select the proper drivers which depend on this option. 39 select the proper drivers which depend on this option.
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 7e06223bca94..b26de8cf3112 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -69,18 +69,20 @@ static inline void backlight_unregister_fb(struct backlight_device *bd)
69} 69}
70#endif /* CONFIG_FB */ 70#endif /* CONFIG_FB */
71 71
72static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 72static ssize_t backlight_show_power(struct device *dev,
73 struct device_attribute *attr,char *buf)
73{ 74{
74 struct backlight_device *bd = to_backlight_device(cdev); 75 struct backlight_device *bd = to_backlight_device(dev);
75 76
76 return sprintf(buf, "%d\n", bd->props.power); 77 return sprintf(buf, "%d\n", bd->props.power);
77} 78}
78 79
79static ssize_t backlight_store_power(struct class_device *cdev, const char *buf, size_t count) 80static ssize_t backlight_store_power(struct device *dev,
81 struct device_attribute *attr, const char *buf, size_t count)
80{ 82{
81 int rc = -ENXIO; 83 int rc = -ENXIO;
82 char *endp; 84 char *endp;
83 struct backlight_device *bd = to_backlight_device(cdev); 85 struct backlight_device *bd = to_backlight_device(dev);
84 int power = simple_strtoul(buf, &endp, 0); 86 int power = simple_strtoul(buf, &endp, 0);
85 size_t size = endp - buf; 87 size_t size = endp - buf;
86 88
@@ -101,18 +103,20 @@ static ssize_t backlight_store_power(struct class_device *cdev, const char *buf,
101 return rc; 103 return rc;
102} 104}
103 105
104static ssize_t backlight_show_brightness(struct class_device *cdev, char *buf) 106static ssize_t backlight_show_brightness(struct device *dev,
107 struct device_attribute *attr, char *buf)
105{ 108{
106 struct backlight_device *bd = to_backlight_device(cdev); 109 struct backlight_device *bd = to_backlight_device(dev);
107 110
108 return sprintf(buf, "%d\n", bd->props.brightness); 111 return sprintf(buf, "%d\n", bd->props.brightness);
109} 112}
110 113
111static ssize_t backlight_store_brightness(struct class_device *cdev, const char *buf, size_t count) 114static ssize_t backlight_store_brightness(struct device *dev,
115 struct device_attribute *attr, const char *buf, size_t count)
112{ 116{
113 int rc = -ENXIO; 117 int rc = -ENXIO;
114 char *endp; 118 char *endp;
115 struct backlight_device *bd = to_backlight_device(cdev); 119 struct backlight_device *bd = to_backlight_device(dev);
116 int brightness = simple_strtoul(buf, &endp, 0); 120 int brightness = simple_strtoul(buf, &endp, 0);
117 size_t size = endp - buf; 121 size_t size = endp - buf;
118 122
@@ -138,18 +142,19 @@ static ssize_t backlight_store_brightness(struct class_device *cdev, const char
138 return rc; 142 return rc;
139} 143}
140 144
141static ssize_t backlight_show_max_brightness(struct class_device *cdev, char *buf) 145static ssize_t backlight_show_max_brightness(struct device *dev,
146 struct device_attribute *attr, char *buf)
142{ 147{
143 struct backlight_device *bd = to_backlight_device(cdev); 148 struct backlight_device *bd = to_backlight_device(dev);
144 149
145 return sprintf(buf, "%d\n", bd->props.max_brightness); 150 return sprintf(buf, "%d\n", bd->props.max_brightness);
146} 151}
147 152
148static ssize_t backlight_show_actual_brightness(struct class_device *cdev, 153static ssize_t backlight_show_actual_brightness(struct device *dev,
149 char *buf) 154 struct device_attribute *attr, char *buf)
150{ 155{
151 int rc = -ENXIO; 156 int rc = -ENXIO;
152 struct backlight_device *bd = to_backlight_device(cdev); 157 struct backlight_device *bd = to_backlight_device(dev);
153 158
154 mutex_lock(&bd->ops_lock); 159 mutex_lock(&bd->ops_lock);
155 if (bd->ops && bd->ops->get_brightness) 160 if (bd->ops && bd->ops->get_brightness)
@@ -159,31 +164,22 @@ static ssize_t backlight_show_actual_brightness(struct class_device *cdev,
159 return rc; 164 return rc;
160} 165}
161 166
162static void backlight_class_release(struct class_device *dev) 167struct class *backlight_class;
168
169static void bl_device_release(struct device *dev)
163{ 170{
164 struct backlight_device *bd = to_backlight_device(dev); 171 struct backlight_device *bd = to_backlight_device(dev);
165 kfree(bd); 172 kfree(bd);
166} 173}
167 174
168static struct class backlight_class = { 175static struct device_attribute bl_device_attributes[] = {
169 .name = "backlight", 176 __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power),
170 .release = backlight_class_release, 177 __ATTR(brightness, 0644, backlight_show_brightness,
171};
172
173#define DECLARE_ATTR(_name,_mode,_show,_store) \
174{ \
175 .attr = { .name = __stringify(_name), .mode = _mode }, \
176 .show = _show, \
177 .store = _store, \
178}
179
180static const struct class_device_attribute bl_class_device_attributes[] = {
181 DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power),
182 DECLARE_ATTR(brightness, 0644, backlight_show_brightness,
183 backlight_store_brightness), 178 backlight_store_brightness),
184 DECLARE_ATTR(actual_brightness, 0444, backlight_show_actual_brightness, 179 __ATTR(actual_brightness, 0444, backlight_show_actual_brightness,
185 NULL), 180 NULL),
186 DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), 181 __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
182 __ATTR_NULL,
187}; 183};
188 184
189/** 185/**
@@ -191,22 +187,20 @@ static const struct class_device_attribute bl_class_device_attributes[] = {
191 * backlight_device class. 187 * backlight_device class.
192 * @name: the name of the new object(must be the same as the name of the 188 * @name: the name of the new object(must be the same as the name of the
193 * respective framebuffer device). 189 * respective framebuffer device).
194 * @devdata: an optional pointer to be stored in the class_device. The 190 * @devdata: an optional pointer to be stored for private driver use. The
195 * methods may retrieve it by using class_get_devdata(&bd->class_dev). 191 * methods may retrieve it by using bl_get_data(bd).
196 * @ops: the backlight operations structure. 192 * @ops: the backlight operations structure.
197 * 193 *
198 * Creates and registers new backlight class_device. Returns either an 194 * Creates and registers new backlight device. Returns either an
199 * ERR_PTR() or a pointer to the newly allocated device. 195 * ERR_PTR() or a pointer to the newly allocated device.
200 */ 196 */
201struct backlight_device *backlight_device_register(const char *name, 197struct backlight_device *backlight_device_register(const char *name,
202 struct device *dev, 198 struct device *parent, void *devdata, struct backlight_ops *ops)
203 void *devdata,
204 struct backlight_ops *ops)
205{ 199{
206 int i, rc;
207 struct backlight_device *new_bd; 200 struct backlight_device *new_bd;
201 int rc;
208 202
209 pr_debug("backlight_device_alloc: name=%s\n", name); 203 pr_debug("backlight_device_register: name=%s\n", name);
210 204
211 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL); 205 new_bd = kzalloc(sizeof(struct backlight_device), GFP_KERNEL);
212 if (!new_bd) 206 if (!new_bd)
@@ -214,13 +208,14 @@ struct backlight_device *backlight_device_register(const char *name,
214 208
215 mutex_init(&new_bd->update_lock); 209 mutex_init(&new_bd->update_lock);
216 mutex_init(&new_bd->ops_lock); 210 mutex_init(&new_bd->ops_lock);
217 new_bd->ops = ops;
218 new_bd->class_dev.class = &backlight_class;
219 new_bd->class_dev.dev = dev;
220 strlcpy(new_bd->class_dev.class_id, name, KOBJ_NAME_LEN);
221 class_set_devdata(&new_bd->class_dev, devdata);
222 211
223 rc = class_device_register(&new_bd->class_dev); 212 new_bd->dev.class = backlight_class;
213 new_bd->dev.parent = parent;
214 new_bd->dev.release = bl_device_release;
215 strlcpy(new_bd->dev.bus_id, name, BUS_ID_SIZE);
216 dev_set_drvdata(&new_bd->dev, devdata);
217
218 rc = device_register(&new_bd->dev);
224 if (rc) { 219 if (rc) {
225 kfree(new_bd); 220 kfree(new_bd);
226 return ERR_PTR(rc); 221 return ERR_PTR(rc);
@@ -228,23 +223,11 @@ struct backlight_device *backlight_device_register(const char *name,
228 223
229 rc = backlight_register_fb(new_bd); 224 rc = backlight_register_fb(new_bd);
230 if (rc) { 225 if (rc) {
231 class_device_unregister(&new_bd->class_dev); 226 device_unregister(&new_bd->dev);
232 return ERR_PTR(rc); 227 return ERR_PTR(rc);
233 } 228 }
234 229
235 230 new_bd->ops = ops;
236 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++) {
237 rc = class_device_create_file(&new_bd->class_dev,
238 &bl_class_device_attributes[i]);
239 if (rc) {
240 while (--i >= 0)
241 class_device_remove_file(&new_bd->class_dev,
242 &bl_class_device_attributes[i]);
243 class_device_unregister(&new_bd->class_dev);
244 /* No need to kfree(new_bd) since release() method was called */
245 return ERR_PTR(rc);
246 }
247 }
248 231
249#ifdef CONFIG_PMAC_BACKLIGHT 232#ifdef CONFIG_PMAC_BACKLIGHT
250 mutex_lock(&pmac_backlight_mutex); 233 mutex_lock(&pmac_backlight_mutex);
@@ -265,42 +248,40 @@ EXPORT_SYMBOL(backlight_device_register);
265 */ 248 */
266void backlight_device_unregister(struct backlight_device *bd) 249void backlight_device_unregister(struct backlight_device *bd)
267{ 250{
268 int i;
269
270 if (!bd) 251 if (!bd)
271 return; 252 return;
272 253
273 pr_debug("backlight_device_unregister: name=%s\n", bd->class_dev.class_id);
274
275#ifdef CONFIG_PMAC_BACKLIGHT 254#ifdef CONFIG_PMAC_BACKLIGHT
276 mutex_lock(&pmac_backlight_mutex); 255 mutex_lock(&pmac_backlight_mutex);
277 if (pmac_backlight == bd) 256 if (pmac_backlight == bd)
278 pmac_backlight = NULL; 257 pmac_backlight = NULL;
279 mutex_unlock(&pmac_backlight_mutex); 258 mutex_unlock(&pmac_backlight_mutex);
280#endif 259#endif
281
282 for (i = 0; i < ARRAY_SIZE(bl_class_device_attributes); i++)
283 class_device_remove_file(&bd->class_dev,
284 &bl_class_device_attributes[i]);
285
286 mutex_lock(&bd->ops_lock); 260 mutex_lock(&bd->ops_lock);
287 bd->ops = NULL; 261 bd->ops = NULL;
288 mutex_unlock(&bd->ops_lock); 262 mutex_unlock(&bd->ops_lock);
289 263
290 backlight_unregister_fb(bd); 264 backlight_unregister_fb(bd);
291 265 device_unregister(&bd->dev);
292 class_device_unregister(&bd->class_dev);
293} 266}
294EXPORT_SYMBOL(backlight_device_unregister); 267EXPORT_SYMBOL(backlight_device_unregister);
295 268
296static void __exit backlight_class_exit(void) 269static void __exit backlight_class_exit(void)
297{ 270{
298 class_unregister(&backlight_class); 271 class_destroy(backlight_class);
299} 272}
300 273
301static int __init backlight_class_init(void) 274static int __init backlight_class_init(void)
302{ 275{
303 return class_register(&backlight_class); 276 backlight_class = class_create(THIS_MODULE, "backlight");
277 if (IS_ERR(backlight_class)) {
278 printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n",
279 PTR_ERR(backlight_class));
280 return PTR_ERR(backlight_class);
281 }
282
283 backlight_class->dev_attrs = bl_device_attributes;
284 return 0;
304} 285}
305 286
306/* 287/*
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
index e9bbc3455c94..b7904da51b23 100644
--- a/drivers/video/backlight/cr_bllcd.c
+++ b/drivers/video/backlight/cr_bllcd.c
@@ -174,7 +174,7 @@ static int cr_backlight_probe(struct platform_device *pdev)
174 struct cr_panel *crp; 174 struct cr_panel *crp;
175 u8 dev_en; 175 u8 dev_en;
176 176
177 crp = kzalloc(sizeof(crp), GFP_KERNEL); 177 crp = kzalloc(sizeof(*crp), GFP_KERNEL);
178 if (crp == NULL) 178 if (crp == NULL)
179 return -ENOMEM; 179 return -ENOMEM;
180 180
@@ -202,7 +202,7 @@ static int cr_backlight_probe(struct platform_device *pdev)
202 } 202 }
203 203
204 crp->cr_lcd_device = lcd_device_register("cr-lcd", 204 crp->cr_lcd_device = lcd_device_register("cr-lcd",
205 &pdev->dev, 205 &pdev->dev, NULL,
206 &cr_lcd_ops); 206 &cr_lcd_ops);
207 207
208 if (IS_ERR(crp->cr_lcd_device)) { 208 if (IS_ERR(crp->cr_lcd_device)) {
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 648b53c1fdea..6f652c65fae1 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -61,10 +61,11 @@ static inline void lcd_unregister_fb(struct lcd_device *ld)
61} 61}
62#endif /* CONFIG_FB */ 62#endif /* CONFIG_FB */
63 63
64static ssize_t lcd_show_power(struct class_device *cdev, char *buf) 64static ssize_t lcd_show_power(struct device *dev, struct device_attribute *attr,
65 char *buf)
65{ 66{
66 int rc; 67 int rc;
67 struct lcd_device *ld = to_lcd_device(cdev); 68 struct lcd_device *ld = to_lcd_device(dev);
68 69
69 mutex_lock(&ld->ops_lock); 70 mutex_lock(&ld->ops_lock);
70 if (ld->ops && ld->ops->get_power) 71 if (ld->ops && ld->ops->get_power)
@@ -76,11 +77,12 @@ static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
76 return rc; 77 return rc;
77} 78}
78 79
79static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_t count) 80static ssize_t lcd_store_power(struct device *dev,
81 struct device_attribute *attr, const char *buf, size_t count)
80{ 82{
81 int rc = -ENXIO; 83 int rc = -ENXIO;
82 char *endp; 84 char *endp;
83 struct lcd_device *ld = to_lcd_device(cdev); 85 struct lcd_device *ld = to_lcd_device(dev);
84 int power = simple_strtoul(buf, &endp, 0); 86 int power = simple_strtoul(buf, &endp, 0);
85 size_t size = endp - buf; 87 size_t size = endp - buf;
86 88
@@ -100,10 +102,11 @@ static ssize_t lcd_store_power(struct class_device *cdev, const char *buf, size_
100 return rc; 102 return rc;
101} 103}
102 104
103static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf) 105static ssize_t lcd_show_contrast(struct device *dev,
106 struct device_attribute *attr, char *buf)
104{ 107{
105 int rc = -ENXIO; 108 int rc = -ENXIO;
106 struct lcd_device *ld = to_lcd_device(cdev); 109 struct lcd_device *ld = to_lcd_device(dev);
107 110
108 mutex_lock(&ld->ops_lock); 111 mutex_lock(&ld->ops_lock);
109 if (ld->ops && ld->ops->get_contrast) 112 if (ld->ops && ld->ops->get_contrast)
@@ -113,11 +116,12 @@ static ssize_t lcd_show_contrast(struct class_device *cdev, char *buf)
113 return rc; 116 return rc;
114} 117}
115 118
116static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, size_t count) 119static ssize_t lcd_store_contrast(struct device *dev,
120 struct device_attribute *attr, const char *buf, size_t count)
117{ 121{
118 int rc = -ENXIO; 122 int rc = -ENXIO;
119 char *endp; 123 char *endp;
120 struct lcd_device *ld = to_lcd_device(cdev); 124 struct lcd_device *ld = to_lcd_device(dev);
121 int contrast = simple_strtoul(buf, &endp, 0); 125 int contrast = simple_strtoul(buf, &endp, 0);
122 size_t size = endp - buf; 126 size_t size = endp - buf;
123 127
@@ -137,53 +141,45 @@ static ssize_t lcd_store_contrast(struct class_device *cdev, const char *buf, si
137 return rc; 141 return rc;
138} 142}
139 143
140static ssize_t lcd_show_max_contrast(struct class_device *cdev, char *buf) 144static ssize_t lcd_show_max_contrast(struct device *dev,
145 struct device_attribute *attr, char *buf)
141{ 146{
142 struct lcd_device *ld = to_lcd_device(cdev); 147 struct lcd_device *ld = to_lcd_device(dev);
143 148
144 return sprintf(buf, "%d\n", ld->props.max_contrast); 149 return sprintf(buf, "%d\n", ld->props.max_contrast);
145} 150}
146 151
147static void lcd_class_release(struct class_device *dev) 152struct class *lcd_class;
153
154static void lcd_device_release(struct device *dev)
148{ 155{
149 struct lcd_device *ld = to_lcd_device(dev); 156 struct lcd_device *ld = to_lcd_device(dev);
150 kfree(ld); 157 kfree(ld);
151} 158}
152 159
153static struct class lcd_class = { 160static struct device_attribute lcd_device_attributes[] = {
154 .name = "lcd", 161 __ATTR(lcd_power, 0644, lcd_show_power, lcd_store_power),
155 .release = lcd_class_release, 162 __ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast),
156}; 163 __ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL),
157 164 __ATTR_NULL,
158#define DECLARE_ATTR(_name,_mode,_show,_store) \
159{ \
160 .attr = { .name = __stringify(_name), .mode = _mode }, \
161 .show = _show, \
162 .store = _store, \
163}
164
165static const struct class_device_attribute lcd_class_device_attributes[] = {
166 DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power),
167 DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast),
168 DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL),
169}; 165};
170 166
171/** 167/**
172 * lcd_device_register - register a new object of lcd_device class. 168 * lcd_device_register - register a new object of lcd_device class.
173 * @name: the name of the new object(must be the same as the name of the 169 * @name: the name of the new object(must be the same as the name of the
174 * respective framebuffer device). 170 * respective framebuffer device).
175 * @devdata: an optional pointer to be stored in the class_device. The 171 * @devdata: an optional pointer to be stored in the device. The
176 * methods may retrieve it by using class_get_devdata(ld->class_dev). 172 * methods may retrieve it by using lcd_get_data(ld).
177 * @ops: the lcd operations structure. 173 * @ops: the lcd operations structure.
178 * 174 *
179 * Creates and registers a new lcd class_device. Returns either an ERR_PTR() 175 * Creates and registers a new lcd device. Returns either an ERR_PTR()
180 * or a pointer to the newly allocated device. 176 * or a pointer to the newly allocated device.
181 */ 177 */
182struct lcd_device *lcd_device_register(const char *name, void *devdata, 178struct lcd_device *lcd_device_register(const char *name, struct device *parent,
183 struct lcd_ops *ops) 179 void *devdata, struct lcd_ops *ops)
184{ 180{
185 int i, rc;
186 struct lcd_device *new_ld; 181 struct lcd_device *new_ld;
182 int rc;
187 183
188 pr_debug("lcd_device_register: name=%s\n", name); 184 pr_debug("lcd_device_register: name=%s\n", name);
189 185
@@ -193,12 +189,14 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
193 189
194 mutex_init(&new_ld->ops_lock); 190 mutex_init(&new_ld->ops_lock);
195 mutex_init(&new_ld->update_lock); 191 mutex_init(&new_ld->update_lock);
196 new_ld->ops = ops;
197 new_ld->class_dev.class = &lcd_class;
198 strlcpy(new_ld->class_dev.class_id, name, KOBJ_NAME_LEN);
199 class_set_devdata(&new_ld->class_dev, devdata);
200 192
201 rc = class_device_register(&new_ld->class_dev); 193 new_ld->dev.class = lcd_class;
194 new_ld->dev.parent = parent;
195 new_ld->dev.release = lcd_device_release;
196 strlcpy(new_ld->dev.bus_id, name, BUS_ID_SIZE);
197 dev_set_drvdata(&new_ld->dev, devdata);
198
199 rc = device_register(&new_ld->dev);
202 if (rc) { 200 if (rc) {
203 kfree(new_ld); 201 kfree(new_ld);
204 return ERR_PTR(rc); 202 return ERR_PTR(rc);
@@ -206,22 +204,11 @@ struct lcd_device *lcd_device_register(const char *name, void *devdata,
206 204
207 rc = lcd_register_fb(new_ld); 205 rc = lcd_register_fb(new_ld);
208 if (rc) { 206 if (rc) {
209 class_device_unregister(&new_ld->class_dev); 207 device_unregister(&new_ld->dev);
210 return ERR_PTR(rc); 208 return ERR_PTR(rc);
211 } 209 }
212 210
213 for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++) { 211 new_ld->ops = ops;
214 rc = class_device_create_file(&new_ld->class_dev,
215 &lcd_class_device_attributes[i]);
216 if (rc) {
217 while (--i >= 0)
218 class_device_remove_file(&new_ld->class_dev,
219 &lcd_class_device_attributes[i]);
220 class_device_unregister(&new_ld->class_dev);
221 /* No need to kfree(new_ld) since release() method was called */
222 return ERR_PTR(rc);
223 }
224 }
225 212
226 return new_ld; 213 return new_ld;
227} 214}
@@ -235,33 +222,34 @@ EXPORT_SYMBOL(lcd_device_register);
235 */ 222 */
236void lcd_device_unregister(struct lcd_device *ld) 223void lcd_device_unregister(struct lcd_device *ld)
237{ 224{
238 int i;
239
240 if (!ld) 225 if (!ld)
241 return; 226 return;
242 227
243 pr_debug("lcd_device_unregister: name=%s\n", ld->class_dev.class_id);
244
245 for (i = 0; i < ARRAY_SIZE(lcd_class_device_attributes); i++)
246 class_device_remove_file(&ld->class_dev,
247 &lcd_class_device_attributes[i]);
248
249 mutex_lock(&ld->ops_lock); 228 mutex_lock(&ld->ops_lock);
250 ld->ops = NULL; 229 ld->ops = NULL;
251 mutex_unlock(&ld->ops_lock); 230 mutex_unlock(&ld->ops_lock);
252 lcd_unregister_fb(ld); 231 lcd_unregister_fb(ld);
253 class_device_unregister(&ld->class_dev); 232
233 device_unregister(&ld->dev);
254} 234}
255EXPORT_SYMBOL(lcd_device_unregister); 235EXPORT_SYMBOL(lcd_device_unregister);
256 236
257static void __exit lcd_class_exit(void) 237static void __exit lcd_class_exit(void)
258{ 238{
259 class_unregister(&lcd_class); 239 class_destroy(lcd_class);
260} 240}
261 241
262static int __init lcd_class_init(void) 242static int __init lcd_class_init(void)
263{ 243{
264 return class_register(&lcd_class); 244 lcd_class = class_create(THIS_MODULE, "lcd");
245 if (IS_ERR(lcd_class)) {
246 printk(KERN_WARNING "Unable to create backlight class; errno = %ld\n",
247 PTR_ERR(lcd_class));
248 return PTR_ERR(lcd_class);
249 }
250
251 lcd_class->dev_attrs = lcd_device_attributes;
252 return 0;
265} 253}
266 254
267/* 255/*
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index f46fe95f69fb..d18b73aafa0d 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -187,7 +187,11 @@ static void vgacon_scrollback_init(int pitch)
187 } 187 }
188} 188}
189 189
190static void vgacon_scrollback_startup(void) 190/*
191 * Called only duing init so call of alloc_bootmen is ok.
192 * Marked __init_refok to silence modpost.
193 */
194static void __init_refok vgacon_scrollback_startup(void)
191{ 195{
192 vgacon_scrollback = alloc_bootmem(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE 196 vgacon_scrollback = alloc_bootmem(CONFIG_VGACON_SOFT_SCROLLBACK_SIZE
193 * 1024); 197 * 1024);
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index eb1a4812ad1d..b87ea21d3d78 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -379,10 +379,6 @@ int __init igafb_init(void)
379 if (fb_get_options("igafb", NULL)) 379 if (fb_get_options("igafb", NULL))
380 return -ENODEV; 380 return -ENODEV;
381 381
382 /* Do not attach when we have a serial console. */
383 if (!con_is_present())
384 return -ENXIO;
385
386 pdev = pci_get_device(PCI_VENDOR_ID_INTERG, 382 pdev = pci_get_device(PCI_VENDOR_ID_INTERG,
387 PCI_DEVICE_ID_INTERG_1682, 0); 383 PCI_DEVICE_ID_INTERG_1682, 0);
388 if (pdev == NULL) { 384 if (pdev == NULL) {
diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
index 43f62d8ee41d..443e3c85a9a0 100644
--- a/drivers/video/nvidia/nv_backlight.c
+++ b/drivers/video/nvidia/nv_backlight.c
@@ -50,7 +50,7 @@ static int nvidia_bl_get_level_brightness(struct nvidia_par *par,
50 50
51static int nvidia_bl_update_status(struct backlight_device *bd) 51static int nvidia_bl_update_status(struct backlight_device *bd)
52{ 52{
53 struct nvidia_par *par = class_get_devdata(&bd->class_dev); 53 struct nvidia_par *par = bl_get_data(bd);
54 u32 tmp_pcrt, tmp_pmc, fpcontrol; 54 u32 tmp_pcrt, tmp_pmc, fpcontrol;
55 int level; 55 int level;
56 56
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index 3972aa8cf859..646ec823c168 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -1067,7 +1067,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1067 info->fix.smem_len = ps3fb_videomemory.size - offset; 1067 info->fix.smem_len = ps3fb_videomemory.size - offset;
1068 info->pseudo_palette = info->par; 1068 info->pseudo_palette = info->par;
1069 info->par = NULL; 1069 info->par = NULL;
1070 info->flags = FBINFO_FLAG_DEFAULT; 1070 info->flags = FBINFO_DEFAULT | FBINFO_READS_FAST;
1071 1071
1072 retval = fb_alloc_cmap(&info->cmap, 256, 0); 1072 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1073 if (retval < 0) 1073 if (retval < 0)
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 0fe547842c64..5c47968e7f21 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -307,7 +307,7 @@ static int riva_bl_get_level_brightness(struct riva_par *par,
307 307
308static int riva_bl_update_status(struct backlight_device *bd) 308static int riva_bl_update_status(struct backlight_device *bd)
309{ 309{
310 struct riva_par *par = class_get_devdata(&bd->class_dev); 310 struct riva_par *par = bl_get_data(bd);
311 U032 tmp_pcrt, tmp_pmc; 311 U032 tmp_pcrt, tmp_pmc;
312 int level; 312 int level;
313 313
@@ -2146,7 +2146,7 @@ static void __devexit rivafb_remove(struct pci_dev *pd)
2146 * ------------------------------------------------------------------------- */ 2146 * ------------------------------------------------------------------------- */
2147 2147
2148#ifndef MODULE 2148#ifndef MODULE
2149static int __init rivafb_setup(char *options) 2149static int __devinit rivafb_setup(char *options)
2150{ 2150{
2151 char *this_opt; 2151 char *this_opt;
2152 2152