|
Lines 155-160
Link Here
|
| 155 |
#include <linux/device.h> |
155 |
#include <linux/device.h> |
| 156 |
#include <linux/bitops.h> |
156 |
#include <linux/bitops.h> |
| 157 |
|
157 |
|
|
|
158 |
#ifdef CONFIG_ACPI |
| 159 |
#include <linux/acpi.h> |
| 160 |
#include <acpi/acpixf.h> |
| 161 |
#endif |
| 162 |
|
| 158 |
#include <asm/byteorder.h> |
163 |
#include <asm/byteorder.h> |
| 159 |
#include <asm/irq.h> |
164 |
#include <asm/irq.h> |
| 160 |
#include <asm/uaccess.h> |
165 |
#include <asm/uaccess.h> |
|
Lines 1214-1219
int system_bus_clock (void)
Link Here
|
| 1214 |
|
1219 |
|
| 1215 |
EXPORT_SYMBOL(system_bus_clock); |
1220 |
EXPORT_SYMBOL(system_bus_clock); |
| 1216 |
|
1221 |
|
|
|
1222 |
#ifdef CONFIG_ACPI |
| 1223 |
static int ide_acpi_find_device(struct device *dev, acpi_handle *handle) |
| 1224 |
{ |
| 1225 |
int i, tmp; |
| 1226 |
acpi_integer addr; |
| 1227 |
|
| 1228 |
if (sscanf(dev->bus_id, "%u.%u", &tmp, &i) != 2) |
| 1229 |
return -ENODEV; |
| 1230 |
|
| 1231 |
addr = (acpi_integer)i; |
| 1232 |
*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); |
| 1233 |
if (!*handle) |
| 1234 |
return -ENODEV; |
| 1235 |
return 0; |
| 1236 |
} |
| 1237 |
|
| 1238 |
/* This assumes the ide controller is a PCI device */ |
| 1239 |
static int ide_acpi_find_channel(struct device *dev, acpi_handle *handle) |
| 1240 |
{ |
| 1241 |
int num; |
| 1242 |
int channel; |
| 1243 |
acpi_integer addr; |
| 1244 |
|
| 1245 |
num = sscanf(dev->bus_id, "ide%x", &channel); |
| 1246 |
|
| 1247 |
if (num != 1 || !dev->parent) |
| 1248 |
return -ENODEV; |
| 1249 |
addr = (acpi_integer)channel; |
| 1250 |
*handle = acpi_get_child(DEVICE_ACPI_HANDLE(dev->parent), addr); |
| 1251 |
if (!*handle) |
| 1252 |
return -ENODEV; |
| 1253 |
return 0; |
| 1254 |
} |
| 1255 |
|
| 1256 |
static struct acpi_bus_type ide_acpi_bus = { |
| 1257 |
.bus = &ide_bus_type, |
| 1258 |
.find_device = ide_acpi_find_device, |
| 1259 |
.find_bridge = ide_acpi_find_channel, |
| 1260 |
}; |
| 1261 |
|
| 1262 |
static int __init ide_acpi_init(void) |
| 1263 |
{ |
| 1264 |
return register_acpi_bus_type(&ide_acpi_bus); |
| 1265 |
} |
| 1266 |
|
| 1267 |
/* The _GTM return package length is 5 dwords */ |
| 1268 |
#define GTM_LEN (sizeof(u32) * 5) |
| 1269 |
struct acpi_ide_state { |
| 1270 |
acpi_handle handle; /* channel device's handle */ |
| 1271 |
u32 gtm[GTM_LEN/sizeof(u32)]; /* info from _GTM */ |
| 1272 |
struct hd_driveid id_buff[2]; /* one chanel has two drives */ |
| 1273 |
int suspend_drives; |
| 1274 |
int resume_drives; |
| 1275 |
}; |
| 1276 |
|
| 1277 |
static void acpi_ide_data_handler(acpi_handle handle, |
| 1278 |
u32 function, void *context) |
| 1279 |
{ |
| 1280 |
/* nothing to do */ |
| 1281 |
} |
| 1282 |
|
| 1283 |
/* acpi data for a chanel */ |
| 1284 |
static struct acpi_ide_state *ide_alloc_acpi_state(acpi_handle handle) |
| 1285 |
{ |
| 1286 |
struct acpi_ide_state * state; |
| 1287 |
acpi_status status; |
| 1288 |
|
| 1289 |
state = kzalloc(sizeof(struct acpi_ide_state), GFP_KERNEL); |
| 1290 |
if (!state) |
| 1291 |
return NULL; |
| 1292 |
status = acpi_attach_data(handle, acpi_ide_data_handler, state); |
| 1293 |
if (ACPI_FAILURE(status)) |
| 1294 |
return NULL; |
| 1295 |
return state; |
| 1296 |
} |
| 1297 |
|
| 1298 |
static struct acpi_ide_state *ide_get_acpi_state(acpi_handle handle) |
| 1299 |
{ |
| 1300 |
struct acpi_ide_state * state; |
| 1301 |
acpi_status status; |
| 1302 |
|
| 1303 |
status = acpi_get_data(handle, acpi_ide_data_handler, (void **)&state); |
| 1304 |
if (ACPI_FAILURE(status)) |
| 1305 |
return NULL; |
| 1306 |
return state; |
| 1307 |
} |
| 1308 |
|
| 1309 |
static void ide_free_acpi_state(acpi_handle handle) |
| 1310 |
{ |
| 1311 |
struct acpi_ide_state *state; |
| 1312 |
|
| 1313 |
state = ide_get_acpi_state(handle); |
| 1314 |
acpi_detach_data(handle, acpi_ide_data_handler); |
| 1315 |
kfree(state); |
| 1316 |
} |
| 1317 |
|
| 1318 |
static int acpi_ide_suspend(struct device *dev) |
| 1319 |
{ |
| 1320 |
acpi_handle handle, parent_handle; |
| 1321 |
struct acpi_ide_state *state; |
| 1322 |
acpi_status status; |
| 1323 |
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 1324 |
union acpi_object *package; |
| 1325 |
ide_drive_t *drive = dev->driver_data; |
| 1326 |
int drive_id = 0; |
| 1327 |
|
| 1328 |
handle = DEVICE_ACPI_HANDLE(dev); |
| 1329 |
if (!handle) { |
| 1330 |
printk(KERN_DEBUG "IDE device's ACPI handler is NULL\n"); |
| 1331 |
return -ENODEV; |
| 1332 |
} |
| 1333 |
if (ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))) { |
| 1334 |
printk(KERN_ERR "ACPI get parent handler error\n"); |
| 1335 |
return -ENODEV; |
| 1336 |
} |
| 1337 |
state = ide_get_acpi_state(parent_handle); |
| 1338 |
if (!state) { |
| 1339 |
state = ide_alloc_acpi_state(parent_handle); |
| 1340 |
if (!state) |
| 1341 |
return -ENODEV; |
| 1342 |
} |
| 1343 |
|
| 1344 |
/* invoke _GTM only once */ |
| 1345 |
state->suspend_drives++; |
| 1346 |
if (state->suspend_drives > 1) { |
| 1347 |
drive_id = 1; |
| 1348 |
goto id; |
| 1349 |
} |
| 1350 |
|
| 1351 |
status = acpi_evaluate_object(parent_handle, "_GTM", NULL, &buffer); |
| 1352 |
if (ACPI_FAILURE(status)) { |
| 1353 |
printk(KERN_ERR "Error evaluating _GTM\n"); |
| 1354 |
return -ENODEV; |
| 1355 |
} |
| 1356 |
package = (union acpi_object *) buffer.pointer; |
| 1357 |
if (package->buffer.length != GTM_LEN) { |
| 1358 |
printk(KERN_ERR "Buffer length returned by _GTM is wrong\n"); |
| 1359 |
acpi_os_free(buffer.pointer); |
| 1360 |
return -ENODEV; |
| 1361 |
} |
| 1362 |
memcpy(state->gtm, package->buffer.pointer, GTM_LEN); |
| 1363 |
state->handle = parent_handle; |
| 1364 |
acpi_os_free(buffer.pointer); |
| 1365 |
id: |
| 1366 |
taskfile_lib_get_identify(drive, (u8*)&state->id_buff[drive_id]); |
| 1367 |
return 0; |
| 1368 |
} |
| 1369 |
|
| 1370 |
static int acpi_ide_invoke_stm(struct acpi_ide_state *state) |
| 1371 |
{ |
| 1372 |
struct acpi_object_list input; |
| 1373 |
union acpi_object params[3]; |
| 1374 |
acpi_status status; |
| 1375 |
|
| 1376 |
input.count = 3; |
| 1377 |
input.pointer = params; |
| 1378 |
params[0].type = ACPI_TYPE_BUFFER; |
| 1379 |
params[0].buffer.length = sizeof(state->gtm); |
| 1380 |
params[0].buffer.pointer = (char*)state->gtm; |
| 1381 |
|
| 1382 |
params[1].type = ACPI_TYPE_BUFFER; |
| 1383 |
params[1].buffer.length = sizeof(state->id_buff[0]); |
| 1384 |
params[1].buffer.pointer = (char *)&state->id_buff[0]; |
| 1385 |
|
| 1386 |
params[2].type = ACPI_TYPE_BUFFER; |
| 1387 |
params[2].buffer.length = sizeof(state->id_buff[1]); |
| 1388 |
params[2].buffer.pointer = (char *)&state->id_buff[1]; |
| 1389 |
|
| 1390 |
status = acpi_evaluate_object(state->handle, "_STM", &input, NULL); |
| 1391 |
if (ACPI_FAILURE(status)) { |
| 1392 |
printk(KERN_ERR "Evaluating _STM error\n"); |
| 1393 |
return -ENODEV; |
| 1394 |
} |
| 1395 |
return 0; |
| 1396 |
} |
| 1397 |
|
| 1398 |
static int acpi_ide_invoke_gtf(acpi_handle handle, ide_drive_t *drive) |
| 1399 |
{ |
| 1400 |
struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 1401 |
#if 0 |
| 1402 |
ide_task_t args; |
| 1403 |
int index = 0; |
| 1404 |
unsigned char *data; |
| 1405 |
#endif |
| 1406 |
union acpi_object *package; |
| 1407 |
acpi_status status; |
| 1408 |
|
| 1409 |
status = acpi_evaluate_object(handle, "_GTF", NULL, &output); |
| 1410 |
if (ACPI_FAILURE(status)) { |
| 1411 |
printk(KERN_ERR "evaluate _GTF error\n"); |
| 1412 |
return -ENODEV; |
| 1413 |
} |
| 1414 |
|
| 1415 |
package = (union acpi_object *) output.pointer; |
| 1416 |
if (package->type != ACPI_TYPE_BUFFER |
| 1417 |
|| (package->buffer.length % 7) != 0) { |
| 1418 |
acpi_os_free(output.pointer); |
| 1419 |
printk(KERN_ERR "_GTF returned value is wrong\n"); |
| 1420 |
return -ENODEV; |
| 1421 |
} |
| 1422 |
#if 0 |
| 1423 |
printk(KERN_DEBUG "Start invoking _GTF commands\n"); |
| 1424 |
|
| 1425 |
data = package->buffer.pointer; |
| 1426 |
/* sumbit ATA commands */ |
| 1427 |
while (index < package->buffer.length) { |
| 1428 |
memset(&args, 0, sizeof(ide_task_t)); |
| 1429 |
args.tfRegister[IDE_ERROR_OFFSET] = data[index]; |
| 1430 |
args.tfRegister[IDE_NSECTOR_OFFSET] = data[index + 1]; |
| 1431 |
args.tfRegister[IDE_SECTOR_OFFSET] = data[index + 2]; |
| 1432 |
args.tfRegister[IDE_LCYL_OFFSET] = data[index + 3]; |
| 1433 |
args.tfRegister[IDE_HCYL_OFFSET] = data[index + 4]; |
| 1434 |
args.tfRegister[IDE_SELECT_OFFSET] = data[index + 5]; |
| 1435 |
args.tfRegister[IDE_STATUS_OFFSET] = data[index + 6]; |
| 1436 |
args.command_type = IDE_DRIVE_TASK_NO_DATA; |
| 1437 |
args.handler = &task_no_data_intr; |
| 1438 |
/* submit command */ |
| 1439 |
index += 7; |
| 1440 |
} |
| 1441 |
#endif |
| 1442 |
acpi_os_free(output.pointer); |
| 1443 |
return 0; |
| 1444 |
} |
| 1445 |
|
| 1446 |
static int acpi_ide_resume(struct device *dev) |
| 1447 |
{ |
| 1448 |
acpi_handle handle, parent_handle; |
| 1449 |
struct acpi_ide_state *state; |
| 1450 |
ide_drive_t *drive = dev->driver_data; |
| 1451 |
|
| 1452 |
handle = DEVICE_ACPI_HANDLE(dev); |
| 1453 |
if (!handle) { |
| 1454 |
printk(KERN_DEBUG "IDE device's ACPI handler is NULL\n"); |
| 1455 |
return -ENODEV; |
| 1456 |
} |
| 1457 |
if (ACPI_FAILURE(acpi_get_parent(handle, &parent_handle))) { |
| 1458 |
printk(KERN_ERR "ACPI get parent handler error\n"); |
| 1459 |
return -ENODEV; |
| 1460 |
} |
| 1461 |
state = ide_get_acpi_state(parent_handle); |
| 1462 |
if (state == NULL) |
| 1463 |
return -ENODEV; |
| 1464 |
|
| 1465 |
/* invoke _STM only once */ |
| 1466 |
state->resume_drives++; |
| 1467 |
if (state->resume_drives == 1) { |
| 1468 |
printk(KERN_DEBUG "Start invoking _STM\n"); |
| 1469 |
if (acpi_ide_invoke_stm(state)) |
| 1470 |
return -ENODEV; |
| 1471 |
} |
| 1472 |
|
| 1473 |
if (state->resume_drives == state->suspend_drives) |
| 1474 |
ide_free_acpi_state(parent_handle); |
| 1475 |
return acpi_ide_invoke_gtf(handle, drive); |
| 1476 |
} |
| 1477 |
|
| 1478 |
#else |
| 1479 |
static int __init ide_acpi_init(void) |
| 1480 |
{ |
| 1481 |
return 0; |
| 1482 |
} |
| 1483 |
|
| 1484 |
static int acpi_ide_suspend(struct device *dev) |
| 1485 |
{ |
| 1486 |
return 0; |
| 1487 |
} |
| 1488 |
|
| 1489 |
static int acpi_ide_resume(struct device *dev) |
| 1490 |
{ |
| 1491 |
return 0; |
| 1492 |
} |
| 1493 |
#endif |
| 1494 |
|
| 1217 |
static int generic_ide_suspend(struct device *dev, pm_message_t state) |
1495 |
static int generic_ide_suspend(struct device *dev, pm_message_t state) |
| 1218 |
{ |
1496 |
{ |
| 1219 |
ide_drive_t *drive = dev->driver_data; |
1497 |
ide_drive_t *drive = dev->driver_data; |
|
Lines 1221-1226
static int generic_ide_suspend(struct de
Link Here
|
| 1221 |
struct request_pm_state rqpm; |
1499 |
struct request_pm_state rqpm; |
| 1222 |
ide_task_t args; |
1500 |
ide_task_t args; |
| 1223 |
|
1501 |
|
|
|
1502 |
acpi_ide_suspend(dev); |
| 1503 |
|
| 1224 |
memset(&rq, 0, sizeof(rq)); |
1504 |
memset(&rq, 0, sizeof(rq)); |
| 1225 |
memset(&rqpm, 0, sizeof(rqpm)); |
1505 |
memset(&rqpm, 0, sizeof(rqpm)); |
| 1226 |
memset(&args, 0, sizeof(args)); |
1506 |
memset(&args, 0, sizeof(args)); |
|
Lines 1240-1245
static int generic_ide_resume(struct dev
Link Here
|
| 1240 |
struct request_pm_state rqpm; |
1520 |
struct request_pm_state rqpm; |
| 1241 |
ide_task_t args; |
1521 |
ide_task_t args; |
| 1242 |
|
1522 |
|
|
|
1523 |
acpi_ide_resume(dev); |
| 1524 |
|
| 1243 |
memset(&rq, 0, sizeof(rq)); |
1525 |
memset(&rq, 0, sizeof(rq)); |
| 1244 |
memset(&rqpm, 0, sizeof(rqpm)); |
1526 |
memset(&rqpm, 0, sizeof(rqpm)); |
| 1245 |
memset(&args, 0, sizeof(args)); |
1527 |
memset(&args, 0, sizeof(args)); |
|
Lines 2004-2009
static int __init ide_init(void)
Link Here
|
| 2004 |
system_bus_speed = ide_system_bus_speed(); |
2286 |
system_bus_speed = ide_system_bus_speed(); |
| 2005 |
|
2287 |
|
| 2006 |
bus_register(&ide_bus_type); |
2288 |
bus_register(&ide_bus_type); |
|
|
2289 |
ide_acpi_init(); |
| 2007 |
|
2290 |
|
| 2008 |
init_ide_data(); |
2291 |
init_ide_data(); |
| 2009 |
|
2292 |
|