/* applesmc_get_key_at_index - get key at index, and put the result in key (char). Returns zero on success or a negative error on failure. Callers must hold applesmc_lock.  */
static int applesmc_get_key_at_index(int index, char *key)
/* applesmc_get_key_at_index - get key at index, and put the result in key (char). Returns zero on success or a negative error on failure. Callers must hold applesmc_lock.  */
static int applesmc_get_key_at_index(int index, char *key)
{
	int i;
	u8 readkey[4];
	readkey[0] = index >> 24;
	readkey[1] = index >> 16;
	readkey[2] = index >> 8;
	readkey[3] = index;
	if (send_command(APPLESMC_GET_KEY_BY_INDEX_CMD))
		return -EIO;
	for (i = 0; i < 4; i++) {
		outb(readkey[i], APPLESMC_DATA_PORT);
		if (__wait_status(0x04))
			return -EIO;
	}
	outb(4, APPLESMC_DATA_PORT);
	for (i = 0; i < 4; i++) {
		if (__wait_status(0x05))
			return -EIO;
		key[i] = inb(APPLESMC_DATA_PORT);
	}
	key[4] = 0;
	return 0;
}