]>
Commit | Line | Data |
---|---|---|
e2984c62 BZ |
1 | #include <linux/kernel.h> |
2 | #include <linux/ide.h> | |
e2984c62 BZ |
3 | |
4 | int generic_ide_suspend(struct device *dev, pm_message_t mesg) | |
5 | { | |
6 | ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive); | |
898ec223 | 7 | ide_hwif_t *hwif = drive->hwif; |
e2984c62 BZ |
8 | struct request *rq; |
9 | struct request_pm_state rqpm; | |
e2984c62 BZ |
10 | int ret; |
11 | ||
12 | /* call ACPI _GTM only once */ | |
13 | if ((drive->dn & 1) == 0 || pair == NULL) | |
14 | ide_acpi_get_timing(hwif); | |
15 | ||
16 | memset(&rqpm, 0, sizeof(rqpm)); | |
e2984c62 BZ |
17 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
18 | rq->cmd_type = REQ_TYPE_PM_SUSPEND; | |
fc38b521 | 19 | rq->special = &rqpm; |
e2984c62 BZ |
20 | rqpm.pm_step = IDE_PM_START_SUSPEND; |
21 | if (mesg.event == PM_EVENT_PRETHAW) | |
22 | mesg.event = PM_EVENT_FREEZE; | |
23 | rqpm.pm_state = mesg.event; | |
24 | ||
25 | ret = blk_execute_rq(drive->queue, NULL, rq, 0); | |
26 | blk_put_request(rq); | |
27 | ||
28 | /* call ACPI _PS3 only after both devices are suspended */ | |
29 | if (ret == 0 && ((drive->dn & 1) || pair == NULL)) | |
30 | ide_acpi_set_state(hwif, 0); | |
31 | ||
32 | return ret; | |
33 | } | |
34 | ||
35 | int generic_ide_resume(struct device *dev) | |
36 | { | |
37 | ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive); | |
898ec223 | 38 | ide_hwif_t *hwif = drive->hwif; |
e2984c62 BZ |
39 | struct request *rq; |
40 | struct request_pm_state rqpm; | |
e2984c62 BZ |
41 | int err; |
42 | ||
43 | /* call ACPI _PS0 / _STM only once */ | |
44 | if ((drive->dn & 1) == 0 || pair == NULL) { | |
45 | ide_acpi_set_state(hwif, 1); | |
46 | ide_acpi_push_timing(hwif); | |
47 | } | |
48 | ||
49 | ide_acpi_exec_tfs(drive); | |
50 | ||
51 | memset(&rqpm, 0, sizeof(rqpm)); | |
e2984c62 BZ |
52 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
53 | rq->cmd_type = REQ_TYPE_PM_RESUME; | |
54 | rq->cmd_flags |= REQ_PREEMPT; | |
fc38b521 | 55 | rq->special = &rqpm; |
e2984c62 BZ |
56 | rqpm.pm_step = IDE_PM_START_RESUME; |
57 | rqpm.pm_state = PM_EVENT_ON; | |
58 | ||
59 | err = blk_execute_rq(drive->queue, NULL, rq, 1); | |
60 | blk_put_request(rq); | |
61 | ||
62 | if (err == 0 && dev->driver) { | |
7f3c868b | 63 | struct ide_driver *drv = to_ide_driver(dev->driver); |
e2984c62 BZ |
64 | |
65 | if (drv->resume) | |
66 | drv->resume(drive); | |
67 | } | |
68 | ||
69 | return err; | |
70 | } | |
71 | ||
72 | void ide_complete_power_step(ide_drive_t *drive, struct request *rq) | |
73 | { | |
fc38b521 | 74 | struct request_pm_state *pm = rq->special; |
e2984c62 BZ |
75 | |
76 | #ifdef DEBUG_PM | |
77 | printk(KERN_INFO "%s: complete_power_step(step: %d)\n", | |
78 | drive->name, pm->pm_step); | |
79 | #endif | |
80 | if (drive->media != ide_disk) | |
81 | return; | |
82 | ||
83 | switch (pm->pm_step) { | |
84 | case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ | |
85 | if (pm->pm_state == PM_EVENT_FREEZE) | |
86 | pm->pm_step = IDE_PM_COMPLETED; | |
87 | else | |
88 | pm->pm_step = IDE_PM_STANDBY; | |
89 | break; | |
90 | case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ | |
91 | pm->pm_step = IDE_PM_COMPLETED; | |
92 | break; | |
93 | case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ | |
94 | pm->pm_step = IDE_PM_IDLE; | |
95 | break; | |
96 | case IDE_PM_IDLE: /* Resume step 2 (idle)*/ | |
97 | pm->pm_step = IDE_PM_RESTORE_DMA; | |
98 | break; | |
99 | } | |
100 | } | |
101 | ||
102 | ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) | |
103 | { | |
fc38b521 TH |
104 | struct request_pm_state *pm = rq->special; |
105 | struct ide_cmd cmd = { }; | |
e2984c62 BZ |
106 | |
107 | switch (pm->pm_step) { | |
108 | case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ | |
109 | if (drive->media != ide_disk) | |
110 | break; | |
111 | /* Not supported? Switch to next step now. */ | |
112 | if (ata_id_flush_enabled(drive->id) == 0 || | |
113 | (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) { | |
114 | ide_complete_power_step(drive, rq); | |
115 | return ide_stopped; | |
116 | } | |
117 | if (ata_id_flush_ext_enabled(drive->id)) | |
fc38b521 | 118 | cmd.tf.command = ATA_CMD_FLUSH_EXT; |
e2984c62 | 119 | else |
fc38b521 | 120 | cmd.tf.command = ATA_CMD_FLUSH; |
e2984c62 BZ |
121 | goto out_do_tf; |
122 | case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ | |
fc38b521 | 123 | cmd.tf.command = ATA_CMD_STANDBYNOW1; |
e2984c62 BZ |
124 | goto out_do_tf; |
125 | case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ | |
126 | ide_set_max_pio(drive); | |
127 | /* | |
128 | * skip IDE_PM_IDLE for ATAPI devices | |
129 | */ | |
130 | if (drive->media != ide_disk) | |
131 | pm->pm_step = IDE_PM_RESTORE_DMA; | |
132 | else | |
133 | ide_complete_power_step(drive, rq); | |
134 | return ide_stopped; | |
135 | case IDE_PM_IDLE: /* Resume step 2 (idle) */ | |
fc38b521 | 136 | cmd.tf.command = ATA_CMD_IDLEIMMEDIATE; |
e2984c62 BZ |
137 | goto out_do_tf; |
138 | case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */ | |
139 | /* | |
140 | * Right now, all we do is call ide_set_dma(drive), | |
141 | * we could be smarter and check for current xfer_speed | |
142 | * in struct drive etc... | |
143 | */ | |
144 | if (drive->hwif->dma_ops == NULL) | |
145 | break; | |
146 | /* | |
147 | * TODO: respect IDE_DFLAG_USING_DMA | |
148 | */ | |
149 | ide_set_dma(drive); | |
150 | break; | |
151 | } | |
152 | ||
153 | pm->pm_step = IDE_PM_COMPLETED; | |
22aa4b32 | 154 | |
e2984c62 BZ |
155 | return ide_stopped; |
156 | ||
157 | out_do_tf: | |
fc38b521 TH |
158 | cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; |
159 | cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; | |
160 | cmd.protocol = ATA_PROT_NODATA; | |
22aa4b32 | 161 | |
fc38b521 | 162 | return do_rw_taskfile(drive, &cmd); |
e2984c62 BZ |
163 | } |
164 | ||
165 | /** | |
3616b653 | 166 | * ide_complete_pm_rq - end the current Power Management request |
e2984c62 BZ |
167 | * @drive: target drive |
168 | * @rq: request | |
169 | * | |
170 | * This function cleans up the current PM request and stops the queue | |
171 | * if necessary. | |
172 | */ | |
3616b653 | 173 | void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq) |
e2984c62 BZ |
174 | { |
175 | struct request_queue *q = drive->queue; | |
fc38b521 | 176 | struct request_pm_state *pm = rq->special; |
e2984c62 BZ |
177 | unsigned long flags; |
178 | ||
3616b653 BZ |
179 | ide_complete_power_step(drive, rq); |
180 | if (pm->pm_step != IDE_PM_COMPLETED) | |
181 | return; | |
182 | ||
e2984c62 BZ |
183 | #ifdef DEBUG_PM |
184 | printk("%s: completing PM request, %s\n", drive->name, | |
185 | blk_pm_suspend_request(rq) ? "suspend" : "resume"); | |
186 | #endif | |
187 | spin_lock_irqsave(q->queue_lock, flags); | |
2ea55210 | 188 | if (blk_pm_suspend_request(rq)) |
e2984c62 | 189 | blk_stop_queue(q); |
2ea55210 | 190 | else |
e2984c62 | 191 | drive->dev_flags &= ~IDE_DFLAG_BLOCKED; |
e2984c62 BZ |
192 | spin_unlock_irqrestore(q->queue_lock, flags); |
193 | ||
b65fac32 | 194 | drive->hwif->rq = NULL; |
e2984c62 BZ |
195 | |
196 | if (blk_end_request(rq, 0, 0)) | |
197 | BUG(); | |
198 | } | |
199 | ||
200 | void ide_check_pm_state(ide_drive_t *drive, struct request *rq) | |
201 | { | |
fc38b521 | 202 | struct request_pm_state *pm = rq->special; |
e2984c62 BZ |
203 | |
204 | if (blk_pm_suspend_request(rq) && | |
205 | pm->pm_step == IDE_PM_START_SUSPEND) | |
206 | /* Mark drive blocked when starting the suspend sequence. */ | |
207 | drive->dev_flags |= IDE_DFLAG_BLOCKED; | |
208 | else if (blk_pm_resume_request(rq) && | |
209 | pm->pm_step == IDE_PM_START_RESUME) { | |
210 | /* | |
211 | * The first thing we do on wakeup is to wait for BSY bit to | |
212 | * go away (with a looong timeout) as a drive on this hwif may | |
213 | * just be POSTing itself. | |
214 | * We do that before even selecting as the "other" device on | |
215 | * the bus may be broken enough to walk on our toes at this | |
216 | * point. | |
217 | */ | |
218 | ide_hwif_t *hwif = drive->hwif; | |
fdd88f0a | 219 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
2ea55210 BZ |
220 | struct request_queue *q = drive->queue; |
221 | unsigned long flags; | |
e2984c62 BZ |
222 | int rc; |
223 | #ifdef DEBUG_PM | |
224 | printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name); | |
225 | #endif | |
226 | rc = ide_wait_not_busy(hwif, 35000); | |
227 | if (rc) | |
228 | printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name); | |
fdd88f0a SS |
229 | tp_ops->dev_select(drive); |
230 | tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS); | |
e2984c62 BZ |
231 | rc = ide_wait_not_busy(hwif, 100000); |
232 | if (rc) | |
233 | printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); | |
2ea55210 BZ |
234 | |
235 | spin_lock_irqsave(q->queue_lock, flags); | |
236 | blk_start_queue(q); | |
237 | spin_unlock_irqrestore(q->queue_lock, flags); | |
e2984c62 BZ |
238 | } |
239 | } |