Ejemplo n.º 1
0
static int
acpi_battery_write_alarm (
	struct file		*file,
	const char		*buffer,
	unsigned long		count,
	void			*data)
{
	int			result = 0;
	struct acpi_battery	*battery = (struct acpi_battery *) data;
	char			alarm_string[12] = {'\0'};

	ACPI_FUNCTION_TRACE("acpi_battery_write_alarm");

	if (!battery || (count > sizeof(alarm_string) - 1))
		return_VALUE(-EINVAL);

	if (!battery->flags.present)
		return_VALUE(-ENODEV);

	if (copy_from_user(alarm_string, buffer, count))
		return_VALUE(-EFAULT);
	
	alarm_string[count] = '\0';

	result = acpi_battery_set_alarm(battery, 
		simple_strtoul(alarm_string, NULL, 0));
	if (result)
		return_VALUE(result);

	return_VALUE(count);
}
static ssize_t
acpi_battery_write_alarm(struct file *file,
			 const char __user * buffer,
			 size_t count, loff_t * ppos)
{
	int result = 0;
	char alarm_string[12] = { '\0' };
	struct seq_file *m = (struct seq_file *)file->private_data;
	struct acpi_battery *battery = (struct acpi_battery *)m->private;


	if (!battery || (count > sizeof(alarm_string) - 1))
		return -EINVAL;

	if (!battery->flags.present)
		return -ENODEV;

	if (copy_from_user(alarm_string, buffer, count))
		return -EFAULT;

	alarm_string[count] = '\0';

	result = acpi_battery_set_alarm(battery,
					simple_strtoul(alarm_string, NULL, 0));
	if (result)
		return result;

	return count;
}
Ejemplo n.º 3
0
static int
acpi_battery_check (
	struct acpi_battery	*battery)
{
	int			result = 0;
	acpi_status		status = AE_OK;
	acpi_handle		handle = NULL;
	struct acpi_device	*device = NULL;
	struct acpi_battery_info *bif = NULL;

	ACPI_FUNCTION_TRACE("acpi_battery_check");
	
	if (!battery)
		return_VALUE(-EINVAL);

	result = acpi_bus_get_device(battery->handle, &device);
	if (result)
		return_VALUE(result);

	result = acpi_bus_get_status(device);
	if (result)
		return_VALUE(result);

	/* Insertion? */

	if (!battery->flags.present && device->status.battery_present) {

		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery inserted\n"));

		/* Evalute _BIF to get certain static information */

		result = acpi_battery_get_info(battery, &bif);
		if (result)
			return_VALUE(result);

		battery->flags.power_unit = bif->power_unit;
		battery->trips.warning = bif->design_capacity_warning;
		battery->trips.low = bif->design_capacity_low;
		kfree(bif);

		/* See if alarms are supported, and if so, set default */

		status = acpi_get_handle(battery->handle, "_BTP", &handle);
		if (ACPI_SUCCESS(status)) {
			battery->flags.alarm = 1;
			acpi_battery_set_alarm(battery, battery->trips.warning);
		}
	}

	/* Removal? */

	else if (battery->flags.present && !device->status.battery_present) {
		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Battery removed\n"));
	}

	battery->flags.present = device->status.battery_present;

	return_VALUE(result);
}