/* * sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $) * * Copyright (c) 2007 Alexey Starikovskiy * Copyright (c) 2005-2007 Vladimir Lebedev * Copyright (c) 2005 Rich Townsend * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #include #include #include #include #include #include #include #include #include #include #include #include "sbshc.h" #include "battery.h" #define PREFIX "ACPI: " #define ACPI_SBS_CLASS "sbs" #define ACPI_AC_CLASS "ac_adapter" #define ACPI_SBS_DEVICE_NAME "Smart Battery System" #define ACPI_SBS_FILE_INFO "info" #define ACPI_SBS_FILE_STATE "state" #define ACPI_SBS_FILE_ALARM "alarm" #define ACPI_BATTERY_DIR_NAME "BAT%i" #define ACPI_AC_DIR_NAME "AC0" #define ACPI_SBS_NOTIFY_STATUS 0x80 #define ACPI_SBS_NOTIFY_INFO 0x81 MODULE_AUTHOR("Alexey Starikovskiy "); MODULE_DESCRIPTION("Smart Battery System ACPI interface driver"); MODULE_LICENSE("GPL"); static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); static bool sbs_manager_broken; #define MAX_SBS_BAT 4 #define ACPI_SBS_BLOCK_MAX 32 static const struct acpi_device_id sbs_device_ids[] = { {"ACPI0002", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, sbs_device_ids); struct acpi_battery { struct power_supply *bat; struct power_supply_desc bat_desc; struct acpi_sbs *sbs; unsigned long update_time; char name[8]; char manufacturer_name[ACPI_SBS_BLOCK_MAX]; char device_name[ACPI_SBS_BLOCK_MAX]; char device_chemistry[ACPI_SBS_BLOCK_MAX]; u16 alarm_capacity; u16 full_charge_capacity; u16 design_capacity; u16 design_voltage; u16 serial_number; u16 cycle_count; u16 temp_now; u16 voltage_now; s16 rate_now; s16 rate_avg; u16 capacity_now; u16 state_of_charge; u16 state; u16 mode; u16 spec; u8 id; u8 present:1; u8 have_sysfs_alarm:1; }; #define to_acpi_battery(x) power_supply_get_drvdata(x) struct acpi_sbs { struct power_supply *charger; struct acpi_device *device; struct acpi_smb_hc *hc; struct mutex lock; struct acpi_battery battery[MAX_SBS_BAT]; u8 batteries_supported:4; u8 manager_present:1; u8 charger_present:1; u8 charger_exists:1; }; #define to_acpi_sbs(x) power_supply_get_drvdata(x) static int acpi_sbs_remove(struct acpi_device *device); static int acpi_battery_get_state(struct acpi_battery *battery); static inline int battery_scale(int log) { int scale = 1; while (log--) scale *= 10; return scale; } static inline int acpi_battery_vscale(struct acpi_battery *battery) { return battery_scale((battery->spec & 0x0f00) >> 8); } static inline int acpi_battery_ipscale(struct acpi_battery *battery) { return battery_scale((battery->spec & 0xf000) >> 12); } static inline int acpi_battery_mode(struct acpi_battery *battery) { return (battery->mode & 0x8000); } static inline int acpi_battery_scale(struct acpi_battery *battery) { return (acpi_battery_mode(battery) ? 10 : 1) * acpi_battery_ipscale(battery); } static int sbs_get_ac_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct acpi_sbs *sbs = to_acpi_sbs(psy); switch (psp) { case POWER_SUPPLY_PROP_ONLINE: val->intval = sbs->charger_present; break; default: return -EINVAL; } return 0; } static int acpi_battery_technology(struct acpi_battery *battery) { if (!strcasecmp("NiCd", battery->device_chemistry)) return POWER_SUPPLY_TECHNOLOGY_NiCd; if (!strcasecmp("NiMH", battery->device_chemistry)) return POWER_SUPPLY_TECHNOLOGY_NiMH; if (!strcasecmp("LION", battery->device_chemistry)) return POWER_SUPPLY_TECHNOLOGY_LION; if (!strcasecmp("LiP", battery->device_chemistry)) return POWER_SUPPLY_TECHNOLOGY_LIPO; return POWER_SUPPLY_TECHNOLOGY_UNKNOWN; } static int acpi_sbs_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct acpi_battery *battery = to_acpi_battery(psy); if ((!battery->present) && psp != POWER_SUPPLY_PROP_PRESENT) return -ENODEV; acpi_battery_get_state(battery); switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (battery->rate_now < 0) val->intval = POWER_SUPPLY_STATUS_DISCHARGING; else if (battery->rate_now > 0) val->intval = POWER_SUPPLY_STATUS_CHARGING; else val->intval = POWER_SUPPLY_STATUS_FULL; break; case POWER_SUPPLY_PROP_PRESENT: val->intval = battery->present; break; case POWER_SUPPLY_PROP_TECHNOLOGY: val->intval = acpi_battery_technology(battery); break; case POWER_SUPPLY_PROP_CYCLE_COUNT: val->intval = battery->cycle_count; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: val->intval = battery->design_voltage * acpi_battery_vscale(battery) * 1000; break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = battery->voltage_now * acpi_battery_vscale(battery) * 1000; break; case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_POWER_NOW: val->intval = abs(battery->rate_now) * acpi_battery_ipscale(battery) * 1000; val->intval *= (acpi_battery_mode(battery)) ? (battery->voltage_now * acpi_battery_vscale(battery) / 1000) : 1; break; case POWER_SUPPLY_PROP_CURRENT_AVG: case POWER_SUPPLY_PROP_POWER_AVG: val->intval = abs(battery->rate_avg) * acpi_battery_ipscale(battery) * 1000; val->intval *= (acpi_battery_mode(battery)) ? (battery->voltage_now * acpi_battery_vscale(battery) / 1000) : 1; break; case POWER_SUPPLY_PROP_CAPACITY: val->intval = battery->state_of_charge; break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: val->intval = battery->design_capacity * acpi_battery_scale(battery) * 1000; break; case POWER_SUPPLY_PROP_CHARGE_FULL: case POWER_SUPPLY_PROP_ENERGY_FULL: val->intval = battery->full_charge_capacity * acpi_battery_scale(battery) * 1000; break; case POWER_SUPPLY_PROP_CHARGE_NOW: case POWER_SUPPLY_PROP_ENERGY_NOW: val->intval = battery->capacity_now * acpi_battery_scale(battery) * 1000; break; case POWER_SUPPLY_PROP_TEMP: val->intval = battery->temp_now - 2730; // dK -> dC break; case POWER_SUPPLY_PROP_MODEL_NAME: val->strval = battery->device_name; break; case POWER_SUPPLY_PROP_MANUFACTURER: val->strval = battery->manufacturer_name; break; default: return -EINVAL; } return 0; } static enum power_supply_property sbs_ac_props[] = { POWER_SUPPLY_PROP_ONLINE, }; static enum power_supply_property sbs_charge_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_TECHNOLOGY, POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; static enum power_supply_property sbs_energy_battery_props[] = { POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_TECHNOLOGY, POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_POWER_NOW, POWER_SUPPLY_PROP_POWER_AVG, POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_FULL, POWER_SUPPLY_PROP_ENERGY_NOW, POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, }; static const struct power_supply_desc acpi_sbs_charger_desc = { .name = "sbs-charger", .type = POWER_SUPPLY_TYPE_MAINS, .properties = sbs_ac_props, .num_properties = ARRAY_SIZE(sbs_ac_props), .get_property = sbs_get_ac_property, }; /* -------------------------------------------------------------------------- Smart Battery System Management -------------------------------------------------------------------------- */ struct acpi_battery_reader { u8 command; /* command for battery */ u8 mode; /* word or block? */ size_t offset; /* offset inside struct acpi_sbs_battery */ }; static struct acpi_battery_reader info_readers[] = { {0x01, SMBUS_READ_WORD, offsetof(struct acpi_battery, alarm_capacity)}, {0x03, SMBUS_READ_WORD, offsetof(struct acpi_
/*
 * linux/drivers/pcmcia/soc_common.h
 *
 * Copyright (C) 2000 John G Dorsey <john+@cs.cmu.edu>
 *
 * This file contains definitions for the PCMCIA support code common to
 * integrated SOCs like the SA-11x0 and PXA2xx microprocessors.
 */
#ifndef _ASM_ARCH_PCMCIA
#define _ASM_ARCH_PCMCIA

/* include the world */
#include <linux/clk.h>
#include <linux/cpufreq.h>
#include <pcmcia/ss.h>
#include <pcmcia/cistpl.h>


struct device;
struct pcmcia_low_level;

/*
 * This structure encapsulates per-socket state which we might need to
 * use when responding to a Card Services query of some kind.
 */
struct soc_pcmcia_socket {
	struct pcmcia_socket	socket;

	/*
	 * Info from low level handler
	 */
	unsigned int		nr;
	struct clk		*clk;

	/*
	 * Core PCMCIA state
	 */
	const struct pcmcia_low_level *ops;

	unsigned int		status;
	socket_state_t		cs_state;

	unsigned short		spd_io[MAX_IO_WIN];
	unsigned short		spd_mem[MAX_WIN];
	unsigned short		spd_attr[MAX_WIN];

	struct resource		res_skt;
	struct resource		res_io;
	struct resource		res_mem;
	struct resource		res_attr;
	void __iomem		*virt_io;

	struct {
		int		gpio;
		unsigned int	irq;
		const char	*name;
	} stat[4];
#define SOC_STAT_CD		0	/* Card detect */
#define SOC_STAT_BVD1		1	/* BATDEAD / IOSTSCHG */
#define SOC_STAT_BVD2		2	/* BATWARN / IOSPKR */
#define SOC_STAT_RDY		3	/* Ready / Interrupt */

	unsigned int