Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB Storage: make OneTouch PM-aware

The OneTouch subdriver submits its own interrupt URB for notifications
about button presses. Consequently it needs to know about suspend and
resume events, so it can cancel or restart the URB.

This patch (as593) adds a hook to struct us_data, to be used for
notifying subdrivers about Power Management events, and it implements
the hook in the OneTouch driver.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Nick Sillik <n.sillik@temple.edu>
Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Matthew Dharm and committed by
Greg Kroah-Hartman
7931e1c6 b9b09422

+39 -1
+27
drivers/usb/storage/onetouch.c
··· 52 52 struct urb *irq; /* urb for interrupt in report */ 53 53 unsigned char *data; /* input data */ 54 54 dma_addr_t data_dma; 55 + unsigned int is_open:1; 55 56 }; 56 57 57 58 static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs) ··· 90 89 { 91 90 struct usb_onetouch *onetouch = dev->private; 92 91 92 + onetouch->is_open = 1; 93 93 onetouch->irq->dev = onetouch->udev; 94 94 if (usb_submit_urb(onetouch->irq, GFP_KERNEL)) { 95 95 err("usb_submit_urb failed"); ··· 105 103 struct usb_onetouch *onetouch = dev->private; 106 104 107 105 usb_kill_urb(onetouch->irq); 106 + onetouch->is_open = 0; 108 107 } 108 + 109 + #ifdef CONFIG_PM 110 + static void usb_onetouch_pm_hook(struct us_data *us, int action) 111 + { 112 + struct usb_onetouch *onetouch = (struct usb_onetouch *) us->extra; 113 + 114 + if (onetouch->is_open) { 115 + switch (action) { 116 + case US_SUSPEND: 117 + usb_kill_urb(onetouch->irq); 118 + break; 119 + case US_RESUME: 120 + if (usb_submit_urb(onetouch->irq, GFP_KERNEL) != 0) 121 + err("usb_submit_urb failed"); 122 + break; 123 + default: 124 + break; 125 + } 126 + } 127 + } 128 + #endif /* CONFIG_PM */ 109 129 110 130 int onetouch_connect_input(struct us_data *ss) 111 131 { ··· 209 185 210 186 ss->extra_destructor = onetouch_release_input; 211 187 ss->extra = onetouch; 188 + #ifdef CONFIG_PM 189 + ss->suspend_resume_hook = usb_onetouch_pm_hook; 190 + #endif 212 191 213 192 input_register_device(onetouch->dev); 214 193
+4
drivers/usb/storage/usb.c
··· 188 188 down(&us->dev_semaphore); 189 189 190 190 US_DEBUGP("%s\n", __FUNCTION__); 191 + if (us->suspend_resume_hook) 192 + (us->suspend_resume_hook)(us, US_SUSPEND); 191 193 iface->dev.power.power_state.event = message.event; 192 194 193 195 /* When runtime PM is working, we'll set a flag to indicate ··· 206 204 down(&us->dev_semaphore); 207 205 208 206 US_DEBUGP("%s\n", __FUNCTION__); 207 + if (us->suspend_resume_hook) 208 + (us->suspend_resume_hook)(us, US_RESUME); 209 209 iface->dev.power.power_state.event = PM_EVENT_ON; 210 210 211 211 up(&us->dev_semaphore);
+8 -1
drivers/usb/storage/usb.h
··· 93 93 typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*); 94 94 typedef int (*trans_reset)(struct us_data*); 95 95 typedef void (*proto_cmnd)(struct scsi_cmnd*, struct us_data*); 96 - typedef void (*extra_data_destructor)(void *); /* extra data destructor */ 96 + typedef void (*extra_data_destructor)(void *); /* extra data destructor */ 97 + typedef void (*pm_hook)(struct us_data *, int); /* power management hook */ 98 + 99 + #define US_SUSPEND 0 100 + #define US_RESUME 1 97 101 98 102 /* we allocate one of these for every device that we remember */ 99 103 struct us_data { ··· 153 149 /* subdriver information */ 154 150 void *extra; /* Any extra data */ 155 151 extra_data_destructor extra_destructor;/* extra data destructor */ 152 + #ifdef CONFIG_PM 153 + pm_hook suspend_resume_hook; 154 + #endif 156 155 }; 157 156 158 157 /* Convert between us_data and the corresponding Scsi_Host */