/* applesmc_write_key - writes len bytes from buffer to a given key. Returns zero on success or a negative error on failure. Callers must hold applesmc_lock.  */
static int applesmc_write_key(const char *key, u8 *buffer, u8 len)
/* applesmc_write_key - writes len bytes from buffer to a given key. Returns zero on success or a negative error on failure. Callers must hold applesmc_lock.  */
static int applesmc_write_key(const char *key, u8 *buffer, u8 len)
{
	int i;
	if (len > APPLESMC_MAX_DATA_LENGTH) {
		printk(KERN_ERR	"applesmc_write_key: cannot write more than "
					"%d bytes\n", APPLESMC_MAX_DATA_LENGTH);
		return -EINVAL;
	}
	if (send_command(APPLESMC_WRITE_CMD))
		return -EIO;
	for (i = 0; i < 4; i++) {
		outb(key[i], APPLESMC_DATA_PORT);
		if (__wait_status(0x04))
			return -EIO;
	}
	outb(len, APPLESMC_DATA_PORT);
	for (i = 0; i < len; i++) {
		if (__wait_status(0x04))
			return -EIO;
		outb(buffer[i], APPLESMC_DATA_PORT);
	}
	return 0;
}