Re: [PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Zhang Rui
On Fri, 2007-08-17 at 13:11 +0800, Alexey Starikovskiy wrote:
> Zhang Rui wrote:
> > On Thu, 2007-08-16 at 18:03 +0400, Alexey Starikovskiy wrote:
> >> From: Alexey Starikovskiy <[EMAIL PROTECTED]>
> >>
> >> acpi_bus_generate_event() takes two strings out of passed device
> object.
> >> SBS needs to supply these strings directly.
> >>
> > This doesn't make sense.
> > acpi_dev->dev.bus_id is the name we are using for ACPI device in
> sysfs.
> > That's why acpi_dev->dev.bus_id is exported via netlink message
> rather
> > than the acpi_dev.pnp.bus_id.
> > BTW: what's wrong with the old acpi_sbs_generate_event thing?
> There are up to 5 devices in SBS which could send a message.
those devices all have a device node in sysfs if they support the
power_supply class, right?
> From ACPI point of view this is one device.
That doesn't matter.
Both the device_class and bus_id are for user space to identify what the
event is.
So why not export "power_supply" as the device_class, and the sysfs
nodes name for these devices as the bus_id?
So that it's easy for user space to know this is a "power supply" event
and can configure the sys I/F in /sys/class/power_supply/bus_id/...

Thanks,
Rui
> Copying strings before and after sending event seems to be mess to me.
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Alexey Starikovskiy
Alexey Starikovskiy wrote:
> Zhang Rui wrote:
>   
>> On Thu, 2007-08-16 at 18:03 +0400, Alexey Starikovskiy wrote:
>> 
>>> From: Alexey Starikovskiy <[EMAIL PROTECTED]>
>>>
>>> acpi_bus_generate_event() takes two strings out of passed device object.
>>> SBS needs to supply these strings directly.
>>>
>>>   
>> This doesn't make sense.
>> 
How much sense in sending different bus_id from the same device?
>> acpi_dev->dev.bus_id is the name we are using for ACPI device in sysfs.
>> That's why acpi_dev->dev.bus_id is exported via netlink message rather
>> than the acpi_dev.pnp.bus_id.
>> BTW: what's wrong with the old acpi_sbs_generate_event thing?
>> 
> There are up to 5 devices in SBS which could send a message.
> From ACPI point of view this is one device.
> Copying strings before and after sending event seems to be mess to me.

Regards,
Alex.

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Alexey Starikovskiy
Zhang Rui wrote:
> On Thu, 2007-08-16 at 18:03 +0400, Alexey Starikovskiy wrote:
>> From: Alexey Starikovskiy <[EMAIL PROTECTED]>
>>
>> acpi_bus_generate_event() takes two strings out of passed device object.
>> SBS needs to supply these strings directly.
>>
> This doesn't make sense.
> acpi_dev->dev.bus_id is the name we are using for ACPI device in sysfs.
> That's why acpi_dev->dev.bus_id is exported via netlink message rather
> than the acpi_dev.pnp.bus_id.
> BTW: what's wrong with the old acpi_sbs_generate_event thing?
There are up to 5 devices in SBS which could send a message.
>From ACPI point of view this is one device.
Copying strings before and after sending event seems to be mess to me.

Regards,
Alex.
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Zhang Rui
On Thu, 2007-08-16 at 18:03 +0400, Alexey Starikovskiy wrote:
> From: Alexey Starikovskiy <[EMAIL PROTECTED]>
> 
> acpi_bus_generate_event() takes two strings out of passed device object.
> SBS needs to supply these strings directly.
> 
This doesn't make sense.
acpi_dev->dev.bus_id is the name we are using for ACPI device in sysfs.
That's why acpi_dev->dev.bus_id is exported via netlink message rather
than the acpi_dev.pnp.bus_id.
BTW: what's wrong with the old acpi_sbs_generate_event thing?

Thanks,
Rui
> Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
> ---
> 
>  drivers/acpi/bus.c  |   25 -
>  drivers/acpi/event.c|7 ---
>  drivers/acpi/sbs.c  |   39 ---
>  include/acpi/acpi_bus.h |6 --
>  4 files changed, 32 insertions(+), 45 deletions(-)
> 
> diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> index 6b2658c..992bb30 100644
> --- a/drivers/acpi/bus.c
> +++ b/drivers/acpi/bus.c
> @@ -283,16 +283,12 @@ DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
>  
>  extern int event_is_open;
>  
> -int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
> +int acpi_bus_generate_event4(const char *device_class, const char *bus_id, 
> u8 type, int data)
>  {
> - struct acpi_bus_event *event = NULL;
> + struct acpi_bus_event *event;
>   unsigned long flags = 0;
>  
> -
> - if (!device)
> - return -EINVAL;
> -
> - if (acpi_bus_generate_genetlink_event(device, type, data))
> + if (acpi_bus_generate_genetlink_event(device_class, bus_id, type, data))
>   printk(KERN_WARNING PREFIX
>   "Failed to generate an ACPI event via genetlink!\n");
>  
> @@ -304,8 +300,8 @@ int acpi_bus_generate_event(struct acpi_device *device, 
> u8 type, int data)
>   if (!event)
>   return -ENOMEM;
>  
> - strcpy(event->device_class, device->pnp.device_class);
> - strcpy(event->bus_id, device->pnp.bus_id);
> + strcpy(event->device_class, device_class);
> + strcpy(event->bus_id, bus_id);
>   event->type = type;
>   event->data = data;
>  
> @@ -316,6 +312,17 @@ int acpi_bus_generate_event(struct acpi_device *device, 
> u8 type, int data)
>   wake_up_interruptible(&acpi_bus_event_queue);
>  
>   return 0;
> +
> +}
> +
> +EXPORT_SYMBOL_GPL(acpi_bus_generate_event4);
> +
> +int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
> +{
> + if (!device)
> + return -EINVAL;
> + return acpi_bus_generate_event4(device->pnp.device_class,
> + device->pnp.bus_id, type, data);
>  }
>  
>  EXPORT_SYMBOL(acpi_bus_generate_event);
> diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
> index 95637a4..6529280 100644
> --- a/drivers/acpi/event.c
> +++ b/drivers/acpi/event.c
> @@ -147,7 +147,8 @@ static struct genl_multicast_group acpi_event_mcgrp = {
>   .name = ACPI_GENL_MCAST_GROUP_NAME,
>  };
>  
> -int acpi_bus_generate_genetlink_event(struct acpi_device *device,
> +int acpi_bus_generate_genetlink_event(const char *device_class,
> +   const char *bus_id,
> u8 type, int data)
>  {
>   struct sk_buff *skb;
> @@ -191,8 +192,8 @@ int acpi_bus_generate_genetlink_event(struct acpi_device 
> *device,
>  
>   memset(event, 0, sizeof(struct acpi_genl_event));
>  
> - strcpy(event->device_class, device->pnp.device_class);
> - strcpy(event->bus_id, device->dev.bus_id);
> + strcpy(event->device_class, device_class);
> + strcpy(event->bus_id, bus_id);
>   event->type = type;
>   event->data = data;
>  
> diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
> index 82c3a55..88af657 100644
> --- a/drivers/acpi/sbs.c
> +++ b/drivers/acpi/sbs.c
> @@ -427,27 +427,6 @@ static int acpi_check_update_proc(struct acpi_sbs *sbs)
>   return 0;
>  }
>  
> -static int acpi_sbs_generate_event(struct acpi_device *device,
> -int event, int state, char *bid, char *class)
> -{
> - char bid_saved[5];
> - char class_saved[20];
> - int result = 0;
> -
> - strcpy(bid_saved, acpi_device_bid(device));
> - strcpy(class_saved, acpi_device_class(device));
> -
> - strcpy(acpi_device_bid(device), bid);
> - strcpy(acpi_device_class(device), class);
> -
> - result = acpi_bus_generate_event(device, event, state);
> -
> - strcpy(acpi_device_bid(device), bid_saved);
> - strcpy(acpi_device_class(device), class_saved);
> -
> - return result;
> -}
> -
>  static int acpi_battery_get_present(struct acpi_battery *battery)
>  {
>   s16 state;
> @@ -1451,14 +1430,13 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, 
> int id, int data_type)
>   }
>  
>   if (do_ac_init) {
> - result = acpi_sbs_generate_event(sbs->device,
> -  ACPI_SBS_AC_NOTIFY_STATUS,
> -

BIOS update breaks HP2125nr backlight keys

2007-08-16 Thread Ryan May
Hi,

I recently updated the BIOS on my HP Pavilion dv2125nr laptop to F.34
(to enable the virtualization instructions).  Since I did this, the Fn
keys to control brightness have failed to work properly under Linux,
though they work fine before booting (ie. at Grub).  Hitting the Fn keys
caused the brightness to change to the minimum possible.  In fact,
/proc/acpi/video/VGA/LCD/brightness would show that the level was set to
0 (though 20 was the lowest available).  I was still able to control the
brightness manually via /proc interface however.

My investigations seem to indicate that HP, in their wisdom, seem to
have removed the _BQC method from their BIOS code.  It seems that the
ACPI code in Linux that handles the key events to change the brightness
use the _BQC method without checking for success, which explains why the
level being set was garbage.  However, the /proc interface for
brightness seems to only use device->brightness->curr to get the current
level.

The attached patch, which I'm sure isn't correct, fixes my problems by
making use of the brightness->curr field to track the current brightness.

I'd love to know your opinion(s) on the problem and a proper fix
(including perhaps sysfs backlight support?).

Thanks,

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
--- video.c.old	2007-08-16 14:20:14.0 -0500
+++ video.c	2007-08-16 18:02:23.0 -0500
@@ -380,7 +380,7 @@
 
 	arg0.integer.value = level;
 	status = acpi_evaluate_object(device->dev->handle, "_BCM", &args, NULL);
-
+	device->brightness->curr = level;
 	printk(KERN_DEBUG "set_level status: %x\n", status);
 	return status;
 }
@@ -392,7 +392,11 @@
 	int status;
 
 	status = acpi_evaluate_integer(device->dev->handle, "_BQC", NULL, level);
-
+	if (status)
+	*level = device->brightness->curr;
+	
+	printk(KERN_DEBUG "get_level status: %x\n", status);
+	status = 0;
 	return status;
 }
 


Re: [PATCH] ACPI: boot correctly with "nosmp" or "maxcpus=0"

2007-08-16 Thread Andi Kleen
On Friday 17 August 2007 01:06:47 Len Brown wrote:
> On Thursday 16 August 2007 15:36, Andi Kleen wrote:
> > > @@ -157,10 +162,13 @@ early_param("nosmp", nosmp);
> > >  static int __init maxcpus(char *str)
> > >  {
> > >   get_option(&str, &max_cpus);
> > > - return 1;
> > > + if (max_cpus == 0)
> > > + disable_ioapic_setup();
> > 
> > I must say I never liked that maxcpus=0 ... does disable the APIC
> > too. There can be situations where you want only a single CPU,
> > but still full APICs because modern systems don't boot without. 
> 
> maxcpus=1 will give you that.
> new kernel-parameters.txt in patch should say this
> (matching what comment in the code says)

Ok.

> The only reason I fixed it instead of changing it per above
> is because people may be used to it in non ACPI configurations
> and get surprised when it doesn't do exactly the same
> thing (or in this case doesn't boot at all) in an ACPI configuration.

Patch is fine for me.

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] ACPI: boot correctly with "nosmp" or "maxcpus=0"

2007-08-16 Thread Len Brown
On Thursday 16 August 2007 15:36, Andi Kleen wrote:
> > @@ -157,10 +162,13 @@ early_param("nosmp", nosmp);
> >  static int __init maxcpus(char *str)
> >  {
> > get_option(&str, &max_cpus);
> > -   return 1;
> > +   if (max_cpus == 0)
> > +   disable_ioapic_setup();
> 
> I must say I never liked that maxcpus=0 ... does disable the APIC
> too. There can be situations where you want only a single CPU,
> but still full APICs because modern systems don't boot without. 

maxcpus=1 will give you that.
new kernel-parameters.txt in patch should say this
(matching what comment in the code says)

> It's the old traditional documented semantics though,
> but on the other hand if it never worked with ACPI i guess people are
> not relying on it.
> 
> So perhaps it would be better to change that? 
> Or add a new option to limit CPUs without disabling ACPIC?

If we cared not for tradition, I'd delete "nosmp",
maxcpus=0 would be a synonym for maxcpus=1
and if you didn't want an IOAPIC, you'd use "noapic"
(heh, don't get me started on the noapic vs. nolapic legacy:-)

The only reason I fixed it instead of changing it per above
is because people may be used to it in non ACPI configurations
and get surprised when it doesn't do exactly the same
thing (or in this case doesn't boot at all) in an ACPI configuration.

Either way is fine with me, but I can't leave it as
"nosmp" and "maxcpus=0" not booting at all on ACPI boxes.

thanks,
-Len
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


ACPI: Battery: Add alarm sysfs support

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |   36 +++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 2be9f45..3968d3b 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -697,6 +697,37 @@ static void acpi_battery_remove_fs(struct acpi_device 
*device)
 }
 
 #endif
+
+#ifdef ENABLE_POWER_SUPPLY
+
+static ssize_t acpi_battery_alarm_show(struct device *dev,
+   struct device_attribute *attr,
+   char *buf)
+{
+   struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
+   return sprintf(buf, "%d\n", battery->alarm * 1000);
+}
+
+static ssize_t acpi_battery_alarm_store(struct device *dev,
+   struct device_attribute *attr,
+   const char *buf, size_t count)
+{
+   unsigned long x;
+   struct acpi_battery *battery = to_acpi_battery(dev_get_drvdata(dev));
+   if (sscanf(buf, "%ld\n", &x) == 1)
+   battery->alarm = x/1000;
+   if (acpi_battery_present(battery))
+   acpi_battery_set_alarm(battery);
+   return count;
+}
+
+static struct device_attribute alarm_attr = {
+   .attr = {.name = "alarm", .mode = 0644, .owner = THIS_MODULE},
+   .show = acpi_battery_alarm_show,
+   .store = acpi_battery_alarm_store,
+};
+
+#endif
 /* --
  Driver Interface
-- 
*/
@@ -740,6 +771,7 @@ static int acpi_battery_add(struct acpi_device *device)
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
battery->bat.get_property = acpi_battery_get_property;
result = power_supply_register(&battery->device->dev, &battery->bat);
+   result = device_create_file(battery->bat.dev, &alarm_attr);
 #endif
status = acpi_install_notify_handler(device->handle,
 ACPI_ALL_NOTIFY,
@@ -777,8 +809,10 @@ static int acpi_battery_remove(struct acpi_device *device, 
int type)
acpi_battery_remove_fs(device);
 #endif
 #ifdef ENABLE_POWER_SUPPLY
-   if (battery->bat.dev)
+   if (battery->bat.dev) {
+   device_remove_file(battery->bat.dev, &alarm_attr);
power_supply_unregister(&battery->bat);
+   }
 #endif
mutex_destroy(&battery->lock);
kfree(battery);
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/12] ACPI: SBS: Add ACPI_PROCFS around procfs handling code.

2007-08-16 Thread Alexey Starikovskiy
Make procfs support optional under ACPI_PROCFS

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |   25 +
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 87bee1e..abf7b94 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -29,9 +29,11 @@
 #include 
 #include 
 
+#ifdef CONFIG_ACPI_PROCFS
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
@@ -91,7 +93,9 @@ struct acpi_battery {
struct power_supply bat;
 #endif
struct acpi_sbs *sbs;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *proc_entry;
+#endif
unsigned long update_time;
char name[8];
char manufacturer_name[ACPI_SBS_BLOCK_MAX];
@@ -125,7 +129,9 @@ struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *charger_entry;
+#endif
struct acpi_battery battery[MAX_SBS_BAT];
u8 batteries_supported:4;
u8 manager_present:1;
@@ -389,6 +395,8 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
return result;
 }
 
+#ifdef CONFIG_ACPI_PROCFS
+
 static int acpi_battery_get_alarm(struct acpi_battery *battery)
 {
return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
@@ -425,6 +433,8 @@ static int acpi_battery_set_alarm(struct acpi_battery 
*battery)
return ret;
 }
 
+#endif
+
 static int acpi_ac_get_present(struct acpi_sbs *sbs)
 {
int result;
@@ -441,6 +451,7 @@ static int acpi_ac_get_present(struct acpi_sbs *sbs)
   FS Interface (/proc/acpi)
-- 
*/
 
+#ifdef CONFIG_ACPI_PROCFS
 /* Generic Routines */
 static int
 acpi_sbs_add_fs(struct proc_dir_entry **dir,
@@ -714,6 +725,8 @@ static struct file_operations acpi_ac_state_fops = {
.owner = THIS_MODULE,
 };
 
+#endif
+
 /* --
  Driver Interface
-- 
*/
@@ -759,10 +772,12 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
return result;
 
sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
+#ifdef CONFIG_ACPI_PROCFS
acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir,
battery->name, &acpi_battery_info_fops,
&acpi_battery_state_fops, &acpi_battery_alarm_fops,
battery);
+#endif
 #ifdef ENABLE_POWER_SUPPLY
battery->bat.name = battery->name;
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -790,10 +805,12 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int 
id)
if (sbs->battery[id].bat.dev)
power_supply_unregister(&sbs->battery[id].bat);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->battery[id].proc_entry) {
acpi_sbs_remove_fs(&(sbs->battery[id].proc_entry),
   acpi_battery_dir);
}
+#endif
 }
 
 static int acpi_charger_add(struct acpi_sbs *sbs)
@@ -803,11 +820,13 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
result = acpi_ac_get_present(sbs);
if (result)
goto end;
+#ifdef CONFIG_ACPI_PROCFS
result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir,
 ACPI_AC_DIR_NAME, NULL,
 &acpi_ac_state_fops, NULL, sbs);
if (result)
goto end;
+#endif
 #ifdef ENABLE_POWER_SUPPLY
sbs->charger.name = "sbs-charger";
sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
@@ -829,8 +848,10 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
if (sbs->charger.dev)
power_supply_unregister(&sbs->charger);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->charger_entry)
acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
+#endif
 }
 
 void acpi_sbs_callback(void *context)
@@ -933,6 +954,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int 
type)
 
 static void acpi_sbs_rmdirs(void)
 {
+#ifdef CONFIG_ACPI_PROCFS
if (acpi_ac_dir) {
acpi_unlock_ac_dir(acpi_ac_dir);
acpi_ac_dir = NULL;
@@ -941,6 +963,7 @@ static void acpi_sbs_rmdirs(void)
acpi_unlock_battery_dir(acpi_battery_dir);
acpi_battery_dir = NULL;
}
+#endif
 }
 
 static int acpi_sbs_resume(struct acpi_device *device)
@@ -970,6 +993,7 @@ static int __init acpi_sbs_init(void)
 
if (acpi_disabled)
return -ENODEV;
+#ifdef CONFIG_ACPI_PROCFS
acpi_ac_dir = acpi_lock_ac_dir();
if (!acpi_ac_dir)
return -ENODEV;
@@ -978,6 +1002,7 @@ static int __init acpi_sbs_init(void)
acpi_sb

Re: [PATCH] ACPI: boot correctly with "nosmp" or "maxcpus=0"

2007-08-16 Thread Andi Kleen
> @@ -157,10 +162,13 @@ early_param("nosmp", nosmp);
>  static int __init maxcpus(char *str)
>  {
>   get_option(&str, &max_cpus);
> - return 1;
> + if (max_cpus == 0)
> + disable_ioapic_setup();

I must say I never liked that maxcpus=0 ... does disable the APIC
too. There can be situations where you want only a single CPU,
but still full APICs because modern systems don't boot without. 

It's the old traditional documented semantics though,
but on the other hand if it never worked with ACPI i guess people are
not relying on it.

So perhaps it would be better to change that? 
Or add a new option to limit CPUs without disabling ACPIC?

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: scripts/mod/file2alias.c cross compile problem

2007-08-16 Thread Thomas Renninger
On Thu, 2007-08-16 at 09:26 -0700, Luck, Tony wrote:
> > -#define ACPI_ID_LEN9
> > +#define ACPI_ID_LEN16 /* only 9 bytes needed here, 16 bytes are 
> > used */
> 
> What will happen if someone uses more than 9 bytes?  With the old
> limit there would be a compile time error it someone initialized
> with:
> 
>   {"PNP0C0ABCDEFGH", 0},
> 
> But if we change ACPI_ID_LEN the error will move to run-time.

That should not harm.
>From spec point of view only 8 bytes are needed. Here 9 bytes are used
as then string functions can be used. The whole rest of the kernel does
not use ACPI_ID_LEN.
If someone defines such an id, his driver won't ever get loaded and he
gets bug reports very soon anyway.

Hmm, I wonder whether this even may come in handy later:
Some BIOSes have some spec violating strange hids like:
"*PNP0C0A"
or
"_PNP0C0A"
While I thought the "_" or "*" should be cut away by ACPI parser, it
might be a hint to the OS to do something special. AFAIK only very
specific devices (WMI and some graphics?) have such strange hids
defined, those drivers could explicitly match for the spec violating
string then.

   Thomas

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: scripts/mod/file2alias.c cross compile problem

2007-08-16 Thread Luck, Tony
> -#define ACPI_ID_LEN  9
> +#define ACPI_ID_LEN  16 /* only 9 bytes needed here, 16 bytes are used */

What will happen if someone uses more than 9 bytes?  With the old
limit there would be a compile time error it someone initialized
with:

{"PNP0C0ABCDEFGH", 0},

But if we change ACPI_ID_LEN the error will move to run-time.

-Tony
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Fix rmmod of asus_laptop

2007-08-16 Thread Guillaume Chazarain
[Resent, with a bigger recipients list]

Hi,

The asus laptop driver conditionnaly registers leds in asus_led_register()
depending on their availability, but unconditionnaly registers them all at
exit time or when the module fails to load. Unregistering not registered leds
result in the following Oops. So we should check before unregistering.

DEV: Unregistering device. ID = 'asus-laptop'
PM: Removing info for No Bus:asus-laptop
kobject_uevent_env
fill_kobj_path: path = '/class/backlight/asus-laptop'
kobject asus-laptop: cleaning up
DEV: Unregistering device. ID = ''
BUG: unable to handle kernel NULL pointer dereference at virtual
address 0064
 printing eip:
c026a9a3
*pde = 
Oops:  [#1]
PREEMPT
Modules linked in: radeon drm cpufreq_ondemand acpi_cpufreq freq_table
lm90 hwmon ipv6 binfmt_misc dm_mirror dm_mod snd_intel8x0
snd_intel8x0m snd_ac97_codec snd_seq_dummy ac97_bus snd_seq_oss
snd_seq_midi_event snd_seq snd_seq_device snd_pcm_oss hci_usb
snd_mixer_oss bluetooth snd_pcm ohci1394 snd_timer ieee1394 sr_mod snd
cdrom ipw2200 ieee80211 firewire_ohci asus_laptop rtc_cmos
firewire_core button video i2c_i801 rtc_core serio_raw soundcore irda
crc_ccitt crc_itu_t output ac ieee80211_crypt battery i2c_core
led_class sdhci mmc_core snd_page_alloc iTCO_wdt sg rtc_lib skge
ehci_hcd ohci_hcd uhci_hcd
CPU:0
EIP:0060:[]Not tainted VLI
EFLAGS: 00210296   (2.6.23-rc3-patched #2)
EIP is at device_del+0xb/0x23a
eax:    ebx:    ecx: 0033   edx: f7d0c7c0
esi: f88ab580   edi: 0880   ebp: f594ef1c   esp: f594ef0c
ds: 007b   es: 007b   fs:   gs: 0033  ss: 0068
Process rmmod (pid: 2552, ti=f594e000 task=f628e5b0 task.ti=f594e000)
Stack: c011fb2e  f88ab580 0880 f594ef30 c026abf8 c03a85df 00a4
   f88ab780 f594ef40 f8864218 f88ab780  f594ef48 f88a90f8 f594ef50
   f88a91c9 f594efb0 c013cee1 73757361 70616c5f 00706f74 c015c10a 0004
Call Trace:
 [] show_trace_log_lvl+0x1a/0x2f
 [] show_stack_log_lvl+0x9d/0xa5
 [] show_registers+0x1cd/0x2e3
 [] die+0x11d/0x218
 [] do_page_fault+0x511/0x5e9
 [] error_code+0x6a/0x70
 [] device_unregister+0x26/0x32
 [] led_classdev_unregister+0x58/0x94 [led_class]
 [] asus_led_exit+0x17/0x41 [asus_laptop]
 [] asus_laptop_exit+0xd/0x3f [asus_laptop]
 [] sys_delete_module+0x17b/0x1a2
 [] sysenter_past_esp+0x6b/0xa1
 ===
Code: 8b 56 04 89 d8 e8 10 fb ff ff 85 ff 74 0d 8b 97 d0 00 00 00 89
d8 e8 9d ff ff ff 5b 5e 5f 5d c3 55 89 e5 57 56 53 89 c3 83 ec 04 <8b>
40 64 85 c0 89 45 f0 74 08 8d 43 10 e8 e0 ee 0b 00 8b 83 20
EIP: [] device_del+0xb/0x23a SS:ESP 0068:f594ef0c

Signed-off-by: Guillaume Chazarain <[EMAIL PROTECTED]>
---

diff -r 1559df81a153 drivers/misc/asus-laptop.c
--- a/drivers/misc/asus-laptop.cMon Aug 13 05:00:33 2007 +
+++ b/drivers/misc/asus-laptop.cTue Aug 14 13:06:40 2007 +0200
@@ -1072,7 +1072,8 @@ static void asus_backlight_exit(void)
 }

 #define  ASUS_LED_UNREGISTER(object)   \
-   led_classdev_unregister(&object##_led)
+   if (object##_led.dev)   \
+   led_classdev_unregister(&object##_led)

 static void asus_led_exit(void)
 {

-- 
Guillaume
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


dmidecode output

2007-08-16 Thread John Haywood

# dmidecode 2.9
SMBIOS 2.4 present.
47 structures occupying 2141 bytes.
Table at 0x000E.

Handle 0x, DMI type 4, 35 bytes
Processor Information
Socket Designation: U2E1
Type: Central Processor
Family: Unknown
Manufacturer: Intel(R) Corporation
ID: FA 06 00 00 FF FB EB BF
Version: Intel(R) Core(TM)2 Duo CPU T7700  @ 2.40GHz
Voltage: 1.6 V
External Clock: 200 MHz
Max Speed: 2400 MHz
Current Speed: 2400 MHz
Status: Populated, Enabled
Upgrade: ZIF Socket
L1 Cache Handle: 0x0003
L2 Cache Handle: 0x0001
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Unknown
Part Number: Not Specified

Handle 0x0001, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 2
Operational Mode: Write Back
Location: Internal
Installed Size: 4096 KB
Maximum Size: 4096 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Unified
Associativity: 16-way Set-associative

Handle 0x0002, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 32 KB
Maximum Size: 32 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Instruction
Associativity: 8-way Set-associative

Handle 0x0003, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 32 KB
Maximum Size: 32 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Data
Associativity: 8-way Set-associative

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
Socket Designation: U2E1
Type: Central Processor
Family: Unknown
Manufacturer: Intel(R) Corporation
ID: FA 06 00 00 FF FB EB BF
Version: Intel(R) Core(TM)2 Duo CPU T7700  @ 2.40GHz
Voltage: 1.6 V
External Clock: 200 MHz
Max Speed: 2400 MHz
Current Speed: 2400 MHz
Status: Populated, Enabled
Upgrade: ZIF Socket
L1 Cache Handle: 0x0007
L2 Cache Handle: 0x0005
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Unknown
Part Number: Not Specified

Handle 0x0005, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 2
Operational Mode: Write Back
Location: Internal
Installed Size: 4096 KB
Maximum Size: 4096 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Unified
Associativity: 16-way Set-associative

Handle 0x0006, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 32 KB
Maximum Size: 32 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Instruction
Associativity: 8-way Set-associative

Handle 0x0007, DMI type 7, 19 bytes
Cache Information
Socket Designation: Unknown
Configuration: Enabled, Not Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 32 KB
Maximum Size: 32 KB
Supported SRAM Types:
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Single-bit ECC
System Type: Data
Associativity: 8-way Set-associative

Handle 0x0008, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 4 GB
Error Information Handle: Not Provided
Number Of Devices: 2

Handle 0x0009, DMI type 19, 15 bytes
Memory Array Mapped Address
Starting Address: 0x000
Ending Address: 0x0007FFF
Range Size: 2 GB
Physical Array Handle: 0x0008
  

dmidecode report

2007-08-16 Thread Brian ABTrafco
# dmidecode 2.8
SMBIOS 2.4 present.
34 structures occupying 1157 bytes.
Table at 0x000DC010.

Handle 0x, DMI type 0, 24 bytes
BIOS Information
Vendor: Phoenix Technologies LTD
Version: NAPA0001.86C..D.0704231854
Release Date: 04/23/2007
Address: 0xE5850
Runtime Size: 108464 bytes
ROM Size: 1024 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
APM is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
Boot from CD is supported
ACPI is supported
USB legacy is supported
AGP is supported
BIOS boot specification is supported
Targeted content distribution is supported

Handle 0x0001, DMI type 1, 27 bytes
System Information
Manufacturer: Dialogue Technology Corporation
Product Name: Flybook V5
Version: Not Applicable
Serial Number: Not Applicable
UUID: 01010101-0101-0101-0101-010101010101
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Not Specified

Handle 0x0002, DMI type 2, 8 bytes
Base Board Information
Manufacturer: Dialogue Technology Corporation
Product Name: Flybook V5
Version: Not Applicable
Serial Number: Not Applicable

Handle 0x0003, DMI type 3, 17 bytes
Chassis Information
Manufacturer: No Enclosure
Type: Other
Lock: Not Present
Version: N/A
Serial Number: None
Asset Tag: No Asset Tag
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: None
OEM Information: 0x1234

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
Socket Designation: U2E1
Type: Central Processor
Family: 
Manufacturer: Intel
ID: E8 06 00 00 FF FB E9 BF
Version: A0
Voltage: 3.3 V
External Clock: Unknown
Max Speed: 2048 MHz
Current Speed: 1200 MHz
Status: Populated, Enabled
Upgrade: ZIF Socket
L1 Cache Handle: 0x0005
L2 Cache Handle: 0x0006
L3 Cache Handle: Not Provided
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified

Handle 0x0005, DMI type 7, 19 bytes
Cache Information
Socket Designation: L1 Cache
Configuration: Enabled, Socketed, Level 1
Operational Mode: Write Back
Location: Internal
Installed Size: 64 KB
Maximum Size: 64 KB
Supported SRAM Types:
Burst
Pipeline Burst
Asynchronous
Installed SRAM Type: Asynchronous
Speed: Unknown
Error Correction Type: Unknown
System Type: Unknown
Associativity: Unknown

Handle 0x0006, DMI type 7, 19 bytes
Cache Information
Socket Designation: L2 Cache
Configuration: Enabled, Socketed, Level 2
Operational Mode: Write Back
Location: External
Installed Size: 2048 KB
Maximum Size: 4096 KB
Supported SRAM Types:
Burst
Pipeline Burst
Asynchronous
Installed SRAM Type: Burst
Speed: Unknown
Error Correction Type: Unknown
System Type: Unknown
Associativity: Unknown

Handle 0x0007, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: J19
Internal Connector Type: 9 Pin Dual Inline (pin 10 cut)
External Reference Designator: COM 1
External Connector Type: DB-9 male
Port Type: Serial Port 16550A Compatible

Handle 0x0008, DMI type 8, 9 bytes
Port Connector Information
Internal Reference Designator: J1A1
Internal Connector Type: None
External Reference Designator: Trackpoint
External Connector Type: Circular DIN-8 male
Port Type: Mouse Port

Handle 0x0009, DMI type 9, 13 bytes
System Slot Information
Designation: PCI Express Slot J7C1
Type: 32-bit PCI Express
Current Usage: Available
Length: Long
Characteristics:
5.0 V is provided
3.3 V is provided

Handle 0x000A, DMI type 9, 13 bytes
System Slot Information
Designation: PCI Express Slot J8C1
Type: 32-bit PCI Express
Current Usage: Available
Length: Long
Characteristics:
5.0 V is provided
3.3 V is provided

Handle 0x000B, DMI type 10, 6 bytes
On Board Device Information
Type: Sound
Status: Disabled
Description: HD-Audio

Handle 0x000C, DMI type 11, 5 bytes
OEM Strings
String 1: This is the Dialogue Flybook V5
String 2: Calistoga 

[PATCH 08/12] ACPI: SBS: Split host controller (ACPI0001) from SBS driver (ACPI0002)

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Replace poll-based host controller driver with the notify-based one.
Split it out of sbs.c.
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/Makefile |1 
 drivers/acpi/sbs.c|  374 ++---
 drivers/acpi/sbshc.c  |  309 
 drivers/acpi/sbshc.h  |   27 
 4 files changed, 412 insertions(+), 299 deletions(-)

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index d4336f1..54e3ab0 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -60,3 +60,4 @@ obj-$(CONFIG_ACPI_TOSHIBA)+= toshiba_acpi.o
 obj-$(CONFIG_ACPI_HOTPLUG_MEMORY)  += acpi_memhotplug.o
 obj-y  += cm_sbs.o
 obj-$(CONFIG_ACPI_SBS) += sbs.o
+obj-$(CONFIG_ACPI_SBS) += sbshc.o
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 88af657..1c2365a 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -34,6 +34,8 @@
 #include 
 #include 
 
+#include "sbshc.h"
+
 #define ACPI_SBS_COMPONENT 0x0008
 #define ACPI_SBS_CLASS "sbs"
 #define ACPI_AC_CLASS  "ac_adapter"
@@ -59,28 +61,6 @@ MODULE_AUTHOR("Rich Townsend");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
 
-#definexmsleep(t)  msleep(t)
-
-#define ACPI_EC_SMB_PRTCL  0x00/* protocol, PEC */
-
-#define ACPI_EC_SMB_STS0x01/* status */
-#define ACPI_EC_SMB_ADDR   0x02/* address */
-#define ACPI_EC_SMB_CMD0x03/* command */
-#define ACPI_EC_SMB_DATA   0x04/* 32 data registers */
-#define ACPI_EC_SMB_BCNT   0x24/* number of data bytes */
-
-#define ACPI_EC_SMB_STS_DONE   0x80
-#define ACPI_EC_SMB_STS_STATUS 0x1f
-
-#define ACPI_EC_SMB_PRTCL_WRITE0x00
-#define ACPI_EC_SMB_PRTCL_READ 0x01
-#define ACPI_EC_SMB_PRTCL_WORD_DATA0x08
-#define ACPI_EC_SMB_PRTCL_BLOCK_DATA   0x0a
-
-#define ACPI_EC_SMB_TRANSACTION_SLEEP  1
-#define ACPI_EC_SMB_ACCESS_SLEEP1  1
-#define ACPI_EC_SMB_ACCESS_SLEEP2  10
-
 #defineDEF_CAPACITY_UNIT   3
 #defineMAH_CAPACITY_UNIT   1
 #defineMWH_CAPACITY_UNIT   2
@@ -103,12 +83,6 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 #defineMAX_SBS_BAT 4
 #define ACPI_SBS_BLOCK_MAX 32
 
-#define ACPI_SBS_SMBUS_READ1
-#define ACPI_SBS_SMBUS_WRITE   2
-
-#define ACPI_SBS_WORD_DATA 1
-#define ACPI_SBS_BLOCK_DATA2
-
 #defineUPDATE_DELAY10
 
 /* 0 - every time, > 0 - by update_time */
@@ -124,8 +98,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int 
type);
 static int acpi_sbs_resume(struct acpi_device *device);
 
 static const struct acpi_device_id sbs_device_ids[] = {
-   {"ACPI0001", 0},
-   {"ACPI0005", 0},
+   {"ACPI0002", 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
@@ -182,8 +155,8 @@ struct acpi_battery {
 };
 
 struct acpi_sbs {
-   int base;
struct acpi_device *device;
+   struct acpi_smb_hc *hc;
struct mutex mutex;
int sbsm_present;
int sbsm_batteries_supported;
@@ -199,190 +172,6 @@ struct acpi_sbs {
 static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
 static void acpi_sbs_update_time(void *data);
 
-union sbs_rw_data {
-   u16 word;
-   u8 block[ACPI_SBS_BLOCK_MAX + 2];
-};
-
-static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
- char read_write, u8 command, int size,
- union sbs_rw_data *data);
-
-/* --
-   SMBus Communication
-   -- 
*/
-
-static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data)
-{
-   u8 val;
-   int err;
-
-   err = ec_read(sbs->base + address, &val);
-   if (!err) {
-   *data = val;
-   }
-   xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
-   return (err);
-}
-
-static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data)
-{
-   int err;
-
-   err = ec_write(sbs->base + address, data);
-   return (err);
-}
-
-static int
-acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
-  char read_write, u8 command, int size,
-  union sbs_rw_data *data)
-{
-   unsigned char protocol, len = 0, temp[2] = { 0, 0 };
-   int i;
-
-   if (read_write == ACPI_SBS_SMBUS_READ) {
-   protocol = ACPI_EC_SMB_PRTCL_READ;
-   } else {
-   protocol = ACPI_EC_SMB_PRTCL_WRITE;
-   }
-
-   switch (size) {
-
-   case ACPI_SBS_WORD_DATA:
-   acpi_ec_sbs_write(sbs, ACPI_EC_SMB

[PATCH 07/12] ACPI: EC: Add new query handler to list head.

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/ec.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 56bee9e..25a84af 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -425,7 +425,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 
query_bit,
handler->func = func;
handler->data = data;
mutex_lock(&ec->lock);
-   list_add_tail(&handler->node, &ec->list);
+   list_add(&handler->node, &ec->list);
mutex_unlock(&ec->lock);
return 0;
 }
@@ -440,7 +440,6 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 
query_bit)
if (query_bit == handler->query_bit) {
list_del(&handler->node);
kfree(handler);
-   break;
}
}
mutex_unlock(&ec->lock);

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

acpi_bus_generate_event() takes two strings out of passed device object.
SBS needs to supply these strings directly.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/bus.c  |   25 -
 drivers/acpi/event.c|7 ---
 drivers/acpi/sbs.c  |   39 ---
 include/acpi/acpi_bus.h |6 --
 4 files changed, 32 insertions(+), 45 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 6b2658c..992bb30 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -283,16 +283,12 @@ DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
 
 extern int event_is_open;
 
-int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
+int acpi_bus_generate_event4(const char *device_class, const char *bus_id, u8 
type, int data)
 {
-   struct acpi_bus_event *event = NULL;
+   struct acpi_bus_event *event;
unsigned long flags = 0;
 
-
-   if (!device)
-   return -EINVAL;
-
-   if (acpi_bus_generate_genetlink_event(device, type, data))
+   if (acpi_bus_generate_genetlink_event(device_class, bus_id, type, data))
printk(KERN_WARNING PREFIX
"Failed to generate an ACPI event via genetlink!\n");
 
@@ -304,8 +300,8 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 
type, int data)
if (!event)
return -ENOMEM;
 
-   strcpy(event->device_class, device->pnp.device_class);
-   strcpy(event->bus_id, device->pnp.bus_id);
+   strcpy(event->device_class, device_class);
+   strcpy(event->bus_id, bus_id);
event->type = type;
event->data = data;
 
@@ -316,6 +312,17 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 
type, int data)
wake_up_interruptible(&acpi_bus_event_queue);
 
return 0;
+
+}
+
+EXPORT_SYMBOL_GPL(acpi_bus_generate_event4);
+
+int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
+{
+   if (!device)
+   return -EINVAL;
+   return acpi_bus_generate_event4(device->pnp.device_class,
+   device->pnp.bus_id, type, data);
 }
 
 EXPORT_SYMBOL(acpi_bus_generate_event);
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 95637a4..6529280 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -147,7 +147,8 @@ static struct genl_multicast_group acpi_event_mcgrp = {
.name = ACPI_GENL_MCAST_GROUP_NAME,
 };
 
-int acpi_bus_generate_genetlink_event(struct acpi_device *device,
+int acpi_bus_generate_genetlink_event(const char *device_class,
+ const char *bus_id,
  u8 type, int data)
 {
struct sk_buff *skb;
@@ -191,8 +192,8 @@ int acpi_bus_generate_genetlink_event(struct acpi_device 
*device,
 
memset(event, 0, sizeof(struct acpi_genl_event));
 
-   strcpy(event->device_class, device->pnp.device_class);
-   strcpy(event->bus_id, device->dev.bus_id);
+   strcpy(event->device_class, device_class);
+   strcpy(event->bus_id, bus_id);
event->type = type;
event->data = data;
 
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 82c3a55..88af657 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -427,27 +427,6 @@ static int acpi_check_update_proc(struct acpi_sbs *sbs)
return 0;
 }
 
-static int acpi_sbs_generate_event(struct acpi_device *device,
-  int event, int state, char *bid, char *class)
-{
-   char bid_saved[5];
-   char class_saved[20];
-   int result = 0;
-
-   strcpy(bid_saved, acpi_device_bid(device));
-   strcpy(class_saved, acpi_device_class(device));
-
-   strcpy(acpi_device_bid(device), bid);
-   strcpy(acpi_device_class(device), class);
-
-   result = acpi_bus_generate_event(device, event, state);
-
-   strcpy(acpi_device_bid(device), bid_saved);
-   strcpy(acpi_device_class(device), class_saved);
-
-   return result;
-}
-
 static int acpi_battery_get_present(struct acpi_battery *battery)
 {
s16 state;
@@ -1451,14 +1430,13 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, 
int id, int data_type)
}
 
if (do_ac_init) {
-   result = acpi_sbs_generate_event(sbs->device,
-ACPI_SBS_AC_NOTIFY_STATUS,
-new_ac_present,
+   result = acpi_bus_generate_event4(ACPI_AC_CLASS,
 ACPI_AC_DIR_NAME,
-ACPI_AC_CLASS);
+ACPI_SBS_AC_NOTIFY_STATUS,
+new_ac_present);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
-  

[PATCH 10/12] ACPI: SBS: Make SBS reads table-driven.

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Re-factor SBS functions to use tables and cycles for repeated operations.
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c | 1286 +++-
 1 files changed, 275 insertions(+), 1011 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 4aee7fb..8651e5f 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -1,6 +1,8 @@
 /*
- *  acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $)
+ *  sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $)
  *
+ *  Copyright (c) 2007 Alexey Starikovskiy <[EMAIL PROTECTED]>
+ *  Copyright (c) 2005-2007 Vladimir Lebedev <[EMAIL PROTECTED]>
  *  Copyright (c) 2005 Rich Townsend <[EMAIL PROTECTED]>
  *
  * ~~
@@ -46,53 +48,34 @@
 #define ACPI_SBS_FILE_ALARM"alarm"
 #define ACPI_BATTERY_DIR_NAME  "BAT%i"
 #define ACPI_AC_DIR_NAME   "AC0"
-#define ACPI_SBC_SMBUS_ADDR0x9
-#define ACPI_SBSM_SMBUS_ADDR   0xa
-#define ACPI_SB_SMBUS_ADDR 0xb
-#define ACPI_SBS_AC_NOTIFY_STATUS  0x80
-#define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80
-#define ACPI_SBS_BATTERY_NOTIFY_INFO   0x81
 
-#define _COMPONENT ACPI_SBS_COMPONENT
+enum acpi_sbs_device_addr {
+   ACPI_SBS_CHARGER = 0x9,
+   ACPI_SBS_MANAGER = 0xa,
+   ACPI_SBS_BATTERY = 0xb,
+};
+
+#define ACPI_SBS_NOTIFY_STATUS 0x80
+#define ACPI_SBS_NOTIFY_INFO   0x81
 
 ACPI_MODULE_NAME("sbs");
 
-MODULE_AUTHOR("Rich Townsend");
+MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
 
-#defineDEF_CAPACITY_UNIT   3
-#defineMAH_CAPACITY_UNIT   1
-#defineMWH_CAPACITY_UNIT   2
-#defineCAPACITY_UNIT   DEF_CAPACITY_UNIT
-
-#defineREQUEST_UPDATE_MODE 1
-#defineQUEUE_UPDATE_MODE   2
-
-#defineDATA_TYPE_COMMON0
-#defineDATA_TYPE_INFO  1
-#defineDATA_TYPE_STATE 2
-#defineDATA_TYPE_ALARM 3
-#defineDATA_TYPE_AC_STATE  4
+static unsigned int cache_time = 1000;
+module_param(cache_time, uint, 0644);
+MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
 extern struct proc_dir_entry *acpi_lock_ac_dir(void);
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
 extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
-#defineMAX_SBS_BAT 4
+#define MAX_SBS_BAT4
 #define ACPI_SBS_BLOCK_MAX 32
 
-#defineUPDATE_DELAY10
-
-/* 0 - every time, > 0 - by update_time */
-static unsigned int update_time = 120;
-
-static unsigned int mode = CAPACITY_UNIT;
-
-module_param(update_time, uint, 0644);
-module_param(mode, uint, 0444);
-
 static int acpi_sbs_add(struct acpi_device *device);
 static int acpi_sbs_remove(struct acpi_device *device, int type);
 static int acpi_sbs_resume(struct acpi_device *device);
@@ -117,486 +100,187 @@ static struct acpi_driver acpi_sbs_driver = {
 struct acpi_battery {
struct acpi_sbs *sbs;
struct proc_dir_entry *proc_entry;
-   int vscale;
-   int ipscale;
+   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];
+   u32 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 current_now;
+   s16 current_avg;
u16 capacity_now;
+   u16 state_of_charge;
u16 state;
-   u16 alarm_capacity;
u16 mode;
+   u16 spec;
u8 id;
-   u8 alive:1;
-   u8 init_state:1;
u8 present:1;
 };
 
 struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
-   struct mutex mutex;
-   struct proc_dir_entry *ac_entry;
+   struct mutex lock;
+   struct proc_dir_entry *charger_entry;
struct acpi_battery battery[MAX_SBS_BAT];
-   int zombie;
-   struct timer_list update_timer;
-   int run_cnt;
-   int update_proc_flg;
-   u8 batteries_supported;
+   u8 batteries_supported:4;
u8 manager_present:1;
u8 charger_present:1;
 };
 
-static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
-static void acpi_sbs_update_time(void *data);
-
-static int sbs_zombie(struct acpi_sbs *sbs)
+static inline int battery_scale(int log)
 {
-   return (sbs->zombie);
+   int scale = 1;
+   while (log--)
+   scale *= 

[PATCH 11/12] ACPI: SBS: Add support for power_supply class (and sysfs)

2007-08-16 Thread Alexey Starikovskiy
Add support for power_supply class and sysfs interface of it.
Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |  331 +++-
 1 files changed, 250 insertions(+), 81 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 8651e5f..87bee1e 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -28,17 +28,23 @@
 #include 
 #include 
 #include 
+
 #include 
 #include 
 #include 
+
 #include 
 #include 
 #include 
 #include 
 
+#if defined(CONFIG_POWER_SUPPLY) || defined (CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #include "sbshc.h"
 
-#define ACPI_SBS_COMPONENT 0x0008
 #define ACPI_SBS_CLASS "sbs"
 #define ACPI_AC_CLASS  "ac_adapter"
 #define ACPI_BATTERY_CLASS "battery"
@@ -58,8 +64,6 @@ enum acpi_sbs_device_addr {
 #define ACPI_SBS_NOTIFY_STATUS 0x80
 #define ACPI_SBS_NOTIFY_INFO   0x81
 
-ACPI_MODULE_NAME("sbs");
-
 MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
@@ -76,28 +80,16 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 #define MAX_SBS_BAT4
 #define ACPI_SBS_BLOCK_MAX 32
 
-static int acpi_sbs_add(struct acpi_device *device);
-static int acpi_sbs_remove(struct acpi_device *device, int type);
-static int acpi_sbs_resume(struct acpi_device *device);
-
 static const struct acpi_device_id sbs_device_ids[] = {
{"ACPI0002", 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
 
-static struct acpi_driver acpi_sbs_driver = {
-   .name = "sbs",
-   .class = ACPI_SBS_CLASS,
-   .ids = sbs_device_ids,
-   .ops = {
-   .add = acpi_sbs_add,
-   .remove = acpi_sbs_remove,
-   .resume = acpi_sbs_resume,
-   },
-};
-
 struct acpi_battery {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply bat;
+#endif
struct acpi_sbs *sbs;
struct proc_dir_entry *proc_entry;
unsigned long update_time;
@@ -105,7 +97,7 @@ struct acpi_battery {
char manufacturer_name[ACPI_SBS_BLOCK_MAX];
char device_name[ACPI_SBS_BLOCK_MAX];
char device_chemistry[ACPI_SBS_BLOCK_MAX];
-   u32 alarm_capacity;
+   u16 alarm_capacity;
u16 full_charge_capacity;
u16 design_capacity;
u16 design_voltage;
@@ -124,7 +116,12 @@ struct acpi_battery {
u8 present:1;
 };
 
+#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
+
 struct acpi_sbs {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply charger;
+#endif
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
@@ -135,6 +132,8 @@ struct acpi_sbs {
u8 charger_present:1;
 };
 
+#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger)
+
 static inline int battery_scale(int log)
 {
int scale = 1;
@@ -164,6 +163,146 @@ static inline int acpi_battery_scale(struct acpi_battery 
*battery)
acpi_battery_ipscale(battery);
 }
 
+#ifdef ENABLE_POWER_SUPPLY
+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;
+   switch (psp) {
+   case POWER_SUPPLY_PROP_STATUS:
+   if (battery->current_now < 0)
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   else if (battery->current_now > 0)
+   val->intval = P

[PATCH 12/12] ACPI: SBS: Add ACPI_PROCFS around procfs handling code.

2007-08-16 Thread Alexey Starikovskiy
Make procfs support optional under ACPI_PROCFS

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |   21 +
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 87bee1e..7db85a9 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -29,9 +29,11 @@
 #include 
 #include 
 
+#ifdef CONFIG_ACPI_PROCFS
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
@@ -91,7 +93,9 @@ struct acpi_battery {
struct power_supply bat;
 #endif
struct acpi_sbs *sbs;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *proc_entry;
+#endif
unsigned long update_time;
char name[8];
char manufacturer_name[ACPI_SBS_BLOCK_MAX];
@@ -125,7 +129,9 @@ struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *charger_entry;
+#endif
struct acpi_battery battery[MAX_SBS_BAT];
u8 batteries_supported:4;
u8 manager_present:1;
@@ -389,6 +395,8 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
return result;
 }
 
+#ifdef CONFIG_ACPI_PROCFS
+
 static int acpi_battery_get_alarm(struct acpi_battery *battery)
 {
return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
@@ -424,6 +432,7 @@ static int acpi_battery_set_alarm(struct acpi_battery 
*battery)
   end:
return ret;
 }
+#endif
 
 static int acpi_ac_get_present(struct acpi_sbs *sbs)
 {
@@ -759,10 +768,12 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
return result;
 
sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
+#ifdef CONFIG_ACPI_PROCFS
acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir,
battery->name, &acpi_battery_info_fops,
&acpi_battery_state_fops, &acpi_battery_alarm_fops,
battery);
+#endif
 #ifdef ENABLE_POWER_SUPPLY
battery->bat.name = battery->name;
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -790,10 +801,12 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int 
id)
if (sbs->battery[id].bat.dev)
power_supply_unregister(&sbs->battery[id].bat);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->battery[id].proc_entry) {
acpi_sbs_remove_fs(&(sbs->battery[id].proc_entry),
   acpi_battery_dir);
}
+#endif
 }
 
 static int acpi_charger_add(struct acpi_sbs *sbs)
@@ -803,11 +816,13 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
result = acpi_ac_get_present(sbs);
if (result)
goto end;
+#ifdef CONFIG_ACPI_PROCFS
result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir,
 ACPI_AC_DIR_NAME, NULL,
 &acpi_ac_state_fops, NULL, sbs);
if (result)
goto end;
+#endif
 #ifdef ENABLE_POWER_SUPPLY
sbs->charger.name = "sbs-charger";
sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
@@ -829,8 +844,10 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
if (sbs->charger.dev)
power_supply_unregister(&sbs->charger);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->charger_entry)
acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
+#endif
 }
 
 void acpi_sbs_callback(void *context)
@@ -933,6 +950,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int 
type)
 
 static void acpi_sbs_rmdirs(void)
 {
+#ifdef CONFIG_ACPI_PROCFS
if (acpi_ac_dir) {
acpi_unlock_ac_dir(acpi_ac_dir);
acpi_ac_dir = NULL;
@@ -941,6 +959,7 @@ static void acpi_sbs_rmdirs(void)
acpi_unlock_battery_dir(acpi_battery_dir);
acpi_battery_dir = NULL;
}
+#endif
 }
 
 static int acpi_sbs_resume(struct acpi_device *device)
@@ -970,6 +989,7 @@ static int __init acpi_sbs_init(void)
 
if (acpi_disabled)
return -ENODEV;
+#ifdef CONFIG_ACPI_PROCFS
acpi_ac_dir = acpi_lock_ac_dir();
if (!acpi_ac_dir)
return -ENODEV;
@@ -978,6 +998,7 @@ static int __init acpi_sbs_init(void)
acpi_sbs_rmdirs();
return -ENODEV;
}
+#endif
result = acpi_bus_register_driver(&acpi_sbs_driver);
if (result < 0) {
acpi_sbs_rmdirs();

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/12] ACPI: SBS: Simplify data structures in SBS

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |  280 +---
 1 files changed, 134 insertions(+), 146 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 1c2365a..4aee7fb 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -88,10 +88,10 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 /* 0 - every time, > 0 - by update_time */
 static unsigned int update_time = 120;
 
-static unsigned int capacity_mode = CAPACITY_UNIT;
+static unsigned int mode = CAPACITY_UNIT;
 
 module_param(update_time, uint, 0644);
-module_param(capacity_mode, uint, 0444);
+module_param(mode, uint, 0444);
 
 static int acpi_sbs_add(struct acpi_device *device);
 static int acpi_sbs_remove(struct acpi_device *device, int type);
@@ -114,59 +114,43 @@ static struct acpi_driver acpi_sbs_driver = {
},
 };
 
-struct acpi_ac {
-   int ac_present;
-};
-
-struct acpi_battery_info {
-   int capacity_mode;
-   s16 full_charge_capacity;
-   s16 design_capacity;
-   s16 design_voltage;
-   int vscale;
-   int ipscale;
-   s16 serial_number;
-   char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3];
-   char device_name[ACPI_SBS_BLOCK_MAX + 3];
-   char device_chemistry[ACPI_SBS_BLOCK_MAX + 3];
-};
-
-struct acpi_battery_state {
-   s16 voltage;
-   s16 amperage;
-   s16 remaining_capacity;
-   s16 battery_state;
-};
-
-struct acpi_battery_alarm {
-   s16 remaining_capacity;
-};
-
 struct acpi_battery {
-   int alive;
-   int id;
-   int init_state;
-   int battery_present;
struct acpi_sbs *sbs;
-   struct acpi_battery_info info;
-   struct acpi_battery_state state;
-   struct acpi_battery_alarm alarm;
-   struct proc_dir_entry *battery_entry;
+   struct proc_dir_entry *proc_entry;
+   int vscale;
+   int ipscale;
+   char manufacturer_name[ACPI_SBS_BLOCK_MAX];
+   char device_name[ACPI_SBS_BLOCK_MAX];
+   char device_chemistry[ACPI_SBS_BLOCK_MAX];
+   u16 full_charge_capacity;
+   u16 design_capacity;
+   u16 design_voltage;
+   u16 serial_number;
+   u16 voltage_now;
+   s16 current_now;
+   u16 capacity_now;
+   u16 state;
+   u16 alarm_capacity;
+   u16 mode;
+   u8 id;
+   u8 alive:1;
+   u8 init_state:1;
+   u8 present:1;
 };
 
 struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex mutex;
-   int sbsm_present;
-   int sbsm_batteries_supported;
struct proc_dir_entry *ac_entry;
-   struct acpi_ac ac;
struct acpi_battery battery[MAX_SBS_BAT];
int zombie;
struct timer_list update_timer;
int run_cnt;
int update_proc_flg;
+   u8 batteries_supported;
+   u8 manager_present:1;
+   u8 charger_present:1;
 };
 
 static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
@@ -231,7 +215,7 @@ static int acpi_battery_get_present(struct acpi_battery 
*battery)
if (!result) {
is_present = (state & 0x000f) & (1 << battery->id);
}
-   battery->battery_present = is_present;
+   battery->present = is_present;
 
return result;
 }
@@ -243,14 +227,14 @@ static int acpi_battery_select(struct acpi_battery 
*battery)
s16 state;
int foo;
 
-   if (sbs->sbsm_present) {
+   if (sbs->manager_present) {
 
/* Take special care not to knobble other nibbles of
 * state (aka selector_state), since
 * it causes charging to halt on SBSELs */
 
-   result =
-   acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, 
ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&state);
+   result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
+ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 
*)&state);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
@@ -258,8 +242,8 @@ static int acpi_battery_select(struct acpi_battery *battery)
}
 
foo = (state & 0x0fff) | (1 << (battery->id + 12));
-   result =
-   acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, 
ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&foo, 2);
+   result = acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD,
+ ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 
*)&foo, 2);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_write() failed"));
@@ -283,8 +267,7 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
"acpi_smbus_read() failed"))

[PATCH 04/12] ACPI: Battery: Misc clean-ups, no functional changes

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  346 +---
 1 files changed, 126 insertions(+), 220 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index eea4dd9..0a20e80 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1,6 +1,8 @@
 /*
- *  acpi_battery.c - ACPI Battery Driver ($Revision: 37 $)
+ *  battery.c - ACPI Battery Driver (Revision: 2.0)
  *
+ *  Copyright (C) 2007 Alexey Starikovskiy <[EMAIL PROTECTED]>
+ *  Copyright (C) 2004-2007 Vladimir Lebedev <[EMAIL PROTECTED]>
  *  Copyright (C) 2001, 2002 Andy Grover <[EMAIL PROTECTED]>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <[EMAIL PROTECTED]>
  *
@@ -48,6 +50,7 @@
 ACPI_MODULE_NAME("battery");
 
 MODULE_AUTHOR("Paul Diefenbaugh");
+MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("ACPI Battery Driver");
 MODULE_LICENSE("GPL");
 
@@ -58,31 +61,17 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
-static int acpi_battery_add(struct acpi_device *device);
-static int acpi_battery_remove(struct acpi_device *device, int type);
-static int acpi_battery_resume(struct acpi_device *device);
-
 static const struct acpi_device_id battery_device_ids[] = {
{"PNP0C0A", 0},
{"", 0},
 };
-MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
-static struct acpi_driver acpi_battery_driver = {
-   .name = "battery",
-   .class = ACPI_BATTERY_CLASS,
-   .ids = battery_device_ids,
-   .ops = {
-   .add = acpi_battery_add,
-   .resume = acpi_battery_resume,
-   .remove = acpi_battery_remove,
-   },
-};
+MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
 enum acpi_battery_files {
-   ACPI_BATTERY_INFO = 0,
-   ACPI_BATTERY_STATE,
-   ACPI_BATTERY_ALARM,
+   info_tag = 0,
+   state_tag,
+   alarm_tag,
ACPI_BATTERY_NUMFILES,
 };
 
@@ -124,7 +113,6 @@ inline char *acpi_battery_units(struct acpi_battery 
*battery)
 /* --
Battery Management
-- 
*/
-
 struct acpi_offsets {
size_t offset;  /* offset inside struct acpi_sbs_battery */
u8 mode;/* int or string? */
@@ -183,19 +171,16 @@ static int extract_package(struct acpi_battery *battery,
 
 static int acpi_battery_get_status(struct acpi_battery *battery)
 {
-   int result = 0;
-
-   result = acpi_bus_get_status(battery->device);
-   if (result) {
+   if (acpi_bus_get_status(battery->device)) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA"));
return -ENODEV;
}
-   return result;
+   return 0;
 }
 
 static int acpi_battery_get_info(struct acpi_battery *battery)
 {
-   int result = 0;
+   int result = -EFAULT;
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
@@ -205,10 +190,12 @@ static int acpi_battery_get_info(struct acpi_battery 
*battery)
status = acpi_evaluate_object(battery->device->handle, "_BIF",
  NULL, &buffer);
mutex_unlock(&battery->lock);
+
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
return -ENODEV;
}
+
result = extract_package(battery, buffer.pointer,
 info_offsets, ARRAY_SIZE(info_offsets));
kfree(buffer.pointer);
@@ -234,10 +221,12 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
status = acpi_evaluate_object(battery->device->handle, "_BST",
  NULL, &buffer);
mutex_unlock(&battery->lock);
+
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
return -ENODEV;
}
+
result = extract_package(battery, buffer.pointer,
 state_offsets, ARRAY_SIZE(state_offsets));
battery->update_time = jiffies;
@@ -245,37 +234,26 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
return result;
 }
 
-static int acpi_battery_get_alarm(struct acpi_battery *battery)
-{
-   return 0;
-}
-
-static int acpi_battery_set_alarm(struct acpi_battery *battery,
- unsigned long alarm)
+static int acpi_battery_set_alarm(struct acpi_battery *battery)
 {
acpi_status status = 0;
-   union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+   union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER };
struc

[PATCH 02/12] ACPI: Battery: don't use acpi_extract_package()

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

acpi_extract_package() creates more problems with memory management than
solves as helper for package handling.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  309 +++-
 1 files changed, 123 insertions(+), 186 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index d7b499f..14bdfad 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -36,9 +36,6 @@
 
 #define ACPI_BATTERY_VALUE_UNKNOWN 0x
 
-#define ACPI_BATTERY_FORMAT_BIF"N"
-#define ACPI_BATTERY_FORMAT_BST""
-
 #define ACPI_BATTERY_COMPONENT 0x0004
 #define ACPI_BATTERY_CLASS "battery"
 #define ACPI_BATTERY_DEVICE_NAME   "Battery"
@@ -90,29 +87,6 @@ static struct acpi_driver acpi_battery_driver = {
},
 };
 
-struct acpi_battery_state {
-   acpi_integer state;
-   acpi_integer present_rate;
-   acpi_integer remaining_capacity;
-   acpi_integer present_voltage;
-};
-
-struct acpi_battery_info {
-   acpi_integer power_unit;
-   acpi_integer design_capacity;
-   acpi_integer last_full_capacity;
-   acpi_integer battery_technology;
-   acpi_integer design_voltage;
-   acpi_integer design_capacity_warning;
-   acpi_integer design_capacity_low;
-   acpi_integer battery_capacity_granularity_1;
-   acpi_integer battery_capacity_granularity_2;
-   acpi_string model_number;
-   acpi_string serial_number;
-   acpi_string battery_type;
-   acpi_string oem_info;
-};
-
 enum acpi_battery_files {
ACPI_BATTERY_INFO = 0,
ACPI_BATTERY_STATE,
@@ -120,32 +94,42 @@ enum acpi_battery_files {
ACPI_BATTERY_NUMFILES,
 };
 
-struct acpi_battery_flags {
-   u8 battery_present_prev;
-   u8 alarm_present;
-   u8 init_update;
-   u8 update[ACPI_BATTERY_NUMFILES];
-   u8 power_unit;
-};
-
 struct acpi_battery {
struct acpi_device *device;
-   struct acpi_battery_flags flags;
-   struct acpi_buffer bif_data;
-   struct acpi_buffer bst_data;
struct mutex lock;
unsigned long alarm;
unsigned long update_time[ACPI_BATTERY_NUMFILES];
-
+   int state;
+   int present_rate;
+   int remaining_capacity;
+   int present_voltage;
+   int power_unit;
+   int design_capacity;
+   int last_full_capacity;
+   int technology;
+   int design_voltage;
+   int design_capacity_warning;
+   int design_capacity_low;
+   int capacity_granularity_1;
+   int capacity_granularity_2;
+   char model_number[32];
+   char serial_number[32];
+   char type[32];
+   char oem_info[32];
+   u8 present_prev;
+   u8 alarm_present;
+   u8 init_update;
+   u8 update[ACPI_BATTERY_NUMFILES];
 };
 
 inline int acpi_battery_present(struct acpi_battery *battery)
 {
return battery->device->status.battery_present;
 }
+
 inline char *acpi_battery_power_units(struct acpi_battery *battery)
 {
-   if (battery->flags.power_unit)
+   if (battery->power_unit)
return ACPI_BATTERY_UNITS_AMPS;
else
return ACPI_BATTERY_UNITS_WATTS;
@@ -166,43 +150,63 @@ static void acpi_battery_check_result(struct acpi_battery 
*battery, int result)
return;
 
if (result) {
-   battery->flags.init_update = 1;
+   battery->init_update = 1;
}
 }
 
-static int acpi_battery_extract_package(struct acpi_battery *battery,
-   union acpi_object *package,
-   struct acpi_buffer *format,
-   struct acpi_buffer *data,
-   char *package_name)
-{
-   acpi_status status = AE_OK;
-   struct acpi_buffer data_null = { 0, NULL };
+struct acpi_offsets {
+   size_t offset;  /* offset inside struct acpi_sbs_battery */
+   u8 mode;/* int or string? */
+};
 
-   status = acpi_extract_package(package, format, &data_null);
-   if (status != AE_BUFFER_OVERFLOW) {
-   ACPI_EXCEPTION((AE_INFO, status, "Extracting size %s",
-   package_name));
-   return -ENODEV;
-   }
+static struct acpi_offsets state_offsets[] = {
+   {offsetof(struct acpi_battery, state), 0},
+   {offsetof(struct acpi_battery, present_rate), 0},
+   {offsetof(struct acpi_battery, remaining_capacity), 0},
+   {offsetof(struct acpi_battery, present_voltage), 0},
+};
 
-   if (data_null.length != data->length) {
-   kfree(data->pointer);
-   data->pointer = kzalloc(data_null.length, GFP_KERNEL);
-   if (!data->pointer) {
-   ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()"));
-   return 

[PATCH 05/12] ACPI: Battery: Add sysfs support

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  201 +++-
 1 files changed, 179 insertions(+), 22 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 0a20e80..2be9f45 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -30,13 +30,21 @@
 #include 
 #include 
 #include 
+
+#ifdef CONFIG_ACPI_PROC
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
 
+#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #define ACPI_BATTERY_VALUE_UNKNOWN 0x
 
 #define ACPI_BATTERY_COMPONENT 0x0004
@@ -58,9 +66,19 @@ static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
+#ifdef CONFIG_ACPI_PROC
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
+enum acpi_battery_files {
+   info_tag = 0,
+   state_tag,
+   alarm_tag,
+   ACPI_BATTERY_NUMFILES,
+};
+
+#endif
+
 static const struct acpi_device_id battery_device_ids[] = {
{"PNP0C0A", 0},
{"", 0},
@@ -68,22 +86,19 @@ static const struct acpi_device_id battery_device_ids[] = {
 
 MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
-enum acpi_battery_files {
-   info_tag = 0,
-   state_tag,
-   alarm_tag,
-   ACPI_BATTERY_NUMFILES,
-};
 
 struct acpi_battery {
struct mutex lock;
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply bat;
+#endif
struct acpi_device *device;
unsigned long update_time;
-   int present_rate;
-   int remaining_capacity;
-   int present_voltage;
+   int current_now;
+   int capacity_now;
+   int voltage_now;
int design_capacity;
-   int last_full_capacity;
+   int full_charge_capacity;
int technology;
int design_voltage;
int design_capacity_warning;
@@ -100,15 +115,119 @@ struct acpi_battery {
u8 alarm_present;
 };
 
+#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
+
 inline int acpi_battery_present(struct acpi_battery *battery)
 {
return battery->device->status.battery_present;
 }
 
+#ifdef ENABLE_POWER_SUPPLY
+static int acpi_battery_technology(struct acpi_battery *battery)
+{
+   if (!strcasecmp("NiCd", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_NiCd;
+   if (!strcasecmp("NiMH", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_NiMH;
+   if (!strcasecmp("LION", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_LION;
+   if (!strcasecmp("LiP", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_LIPO;
+   return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
+}
+
+static int acpi_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 ((!acpi_battery_present(battery)) &&
+psp != POWER_SUPPLY_PROP_PRESENT)
+   return -ENODEV;
+   switch (psp) {
+   case POWER_SUPPLY_PROP_STATUS:
+   if (battery->state & 0x01)
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   else if (battery->state & 0x02)
+   val->intval = POWER_SUPPLY_STATUS_CHARGING;
+   else if (battery->state == 0)
+   val->intval = POWER_SUPPLY_STATUS_FULL;
+   break;
+   case POWER_SUPPLY_PROP_PRESENT:
+   val->intval = acpi_battery_present(battery);
+   break;
+   case POWER_SUPPLY_PROP_TECHNOLOGY:
+   val->intval = acpi_battery_technology(battery);
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
+   val->intval = battery->design_voltage * 1000;
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+   val->intval = battery->voltage_now * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CURRENT_NOW:
+   val->intval = battery->current_now * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
+   case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
+   val->intval = battery->design_capacity * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL:
+   case POWER_SUPPLY_PROP_ENERGY_FULL:
+   val->intval = battery->full_charge_capacity * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_NOW:
+   case POWER_SUPPLY_PROP_ENERGY_NOW:
+   val->intval = battery->capacity_now * 1000;
+  

[PATCH 03/12] ACPI: Battery: simplify update scheme

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  274 +---
 1 files changed, 52 insertions(+), 222 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 14bdfad..eea4dd9 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,27 +42,18 @@
 #define ACPI_BATTERY_DEVICE_NAME   "Battery"
 #define ACPI_BATTERY_NOTIFY_STATUS 0x80
 #define ACPI_BATTERY_NOTIFY_INFO   0x81
-#define ACPI_BATTERY_UNITS_WATTS   "mW"
-#define ACPI_BATTERY_UNITS_AMPS"mA"
 
 #define _COMPONENT ACPI_BATTERY_COMPONENT
 
-#define ACPI_BATTERY_UPDATE_TIME   0
-
-#define ACPI_BATTERY_NONE_UPDATE   0
-#define ACPI_BATTERY_EASY_UPDATE   1
-#define ACPI_BATTERY_INIT_UPDATE   2
-
 ACPI_MODULE_NAME("battery");
 
 MODULE_AUTHOR("Paul Diefenbaugh");
 MODULE_DESCRIPTION("ACPI Battery Driver");
 MODULE_LICENSE("GPL");
 
-static unsigned int update_time = ACPI_BATTERY_UPDATE_TIME;
-
-/* 0 - every time, > 0 - by update_time */
-module_param(update_time, uint, 0644);
+static unsigned int cache_time = 1000;
+module_param(cache_time, uint, 0644);
+MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
@@ -95,15 +87,12 @@ enum acpi_battery_files {
 };
 
 struct acpi_battery {
-   struct acpi_device *device;
struct mutex lock;
-   unsigned long alarm;
-   unsigned long update_time[ACPI_BATTERY_NUMFILES];
-   int state;
+   struct acpi_device *device;
+   unsigned long update_time;
int present_rate;
int remaining_capacity;
int present_voltage;
-   int power_unit;
int design_capacity;
int last_full_capacity;
int technology;
@@ -112,14 +101,14 @@ struct acpi_battery {
int design_capacity_low;
int capacity_granularity_1;
int capacity_granularity_2;
+   int alarm;
char model_number[32];
char serial_number[32];
char type[32];
char oem_info[32];
-   u8 present_prev;
+   int state;
+   int power_unit;
u8 alarm_present;
-   u8 init_update;
-   u8 update[ACPI_BATTERY_NUMFILES];
 };
 
 inline int acpi_battery_present(struct acpi_battery *battery)
@@ -127,33 +116,15 @@ inline int acpi_battery_present(struct acpi_battery 
*battery)
return battery->device->status.battery_present;
 }
 
-inline char *acpi_battery_power_units(struct acpi_battery *battery)
+inline char *acpi_battery_units(struct acpi_battery *battery)
 {
-   if (battery->power_unit)
-   return ACPI_BATTERY_UNITS_AMPS;
-   else
-   return ACPI_BATTERY_UNITS_WATTS;
-}
-
-inline acpi_handle acpi_battery_handle(struct acpi_battery *battery)
-{
-   return battery->device->handle;
+   return (battery->power_unit)?"mA":"mW";
 }
 
 /* --
Battery Management
-- 
*/
 
-static void acpi_battery_check_result(struct acpi_battery *battery, int result)
-{
-   if (!battery)
-   return;
-
-   if (result) {
-   battery->init_update = 1;
-   }
-}
-
 struct acpi_offsets {
size_t offset;  /* offset inside struct acpi_sbs_battery */
u8 mode;/* int or string? */
@@ -228,11 +199,10 @@ static int acpi_battery_get_info(struct acpi_battery 
*battery)
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
-   battery->update_time[ACPI_BATTERY_INFO] = get_seconds();
if (!acpi_battery_present(battery))
return 0;
mutex_lock(&battery->lock);
-   status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF",
+   status = acpi_evaluate_object(battery->device->handle, "_BIF",
  NULL, &buffer);
mutex_unlock(&battery->lock);
if (ACPI_FAILURE(status)) {
@@ -251,14 +221,17 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
-   battery->update_time[ACPI_BATTERY_STATE] = get_seconds();
-
if (!acpi_battery_present(battery))
return 0;
 
+   if (battery->update_time &&
+   time_before(jiffies, battery->update_time +
+   msecs_to_jiffies(cache_time)))
+   return 0;
+
/* Evaluate _BST */
mutex_lock(&battery->lock);
-   status = acpi_evaluate_object(acpi_battery_handle(batt

[PATCH 01/12] ACPI: AC: Add sysfs interface

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/ac.c |   49 +++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index d8b3509..d13b961 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -29,6 +29,12 @@
 #include 
 #include 
 #include 
+
+#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #include 
 #include 
 
@@ -72,16 +78,42 @@ static struct acpi_driver acpi_ac_driver = {
 };
 
 struct acpi_ac {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply charger;
+#endif
struct acpi_device * device;
unsigned long state;
 };
 
+#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger);
+
 static const struct file_operations acpi_ac_fops = {
.open = acpi_ac_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
 };
+#ifdef ENABLE_POWER_SUPPLY
+static int get_ac_property(struct power_supply *psy,
+  enum power_supply_property psp,
+  union power_supply_propval *val)
+{
+   struct acpi_ac *ac = to_acpi_ac(psy);
+   switch (psp) {
+   case POWER_SUPPLY_PROP_ONLINE:
+   val->intval = ac->state;
+   break;
+   default:
+   return -EINVAL;
+   }
+   return 0;
+}
+
+static enum power_supply_property ac_props[] = {
+   POWER_SUPPLY_PROP_ONLINE,
+};
+
+#endif
 
 /* --
AC Adapter Management
@@ -205,6 +237,9 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, 
void *data)
case ACPI_NOTIFY_DEVICE_CHECK:
acpi_ac_get_state(ac);
acpi_bus_generate_event(device, event, (u32) ac->state);
+#ifdef ENABLE_POWER_SUPPLY
+   kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
+#endif
break;
default:
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -241,7 +276,14 @@ static int acpi_ac_add(struct acpi_device *device)
result = acpi_ac_add_fs(device);
if (result)
goto end;
-
+#ifdef ENABLE_POWER_SUPPLY
+   ac->charger.name = acpi_device_bid(device);
+   ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
+   ac->charger.properties = ac_props;
+   ac->charger.num_properties = ARRAY_SIZE(ac_props);
+   ac->charger.get_property = get_ac_property;
+   power_supply_register(&ac->device->dev, &ac->charger);
+#endif
status = acpi_install_notify_handler(device->handle,
 ACPI_ALL_NOTIFY, acpi_ac_notify,
 ac);
@@ -276,7 +318,10 @@ static int acpi_ac_remove(struct acpi_device *device, int 
type)
 
status = acpi_remove_notify_handler(device->handle,
ACPI_ALL_NOTIFY, acpi_ac_notify);
-
+#ifdef ENABLE_POWER_SUPPLY
+   if (ac->charger.dev)
+   power_supply_unregister(&ac->charger);
+#endif
acpi_ac_remove_fs(device);
 
kfree(ac);

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/12] ACPI: SBS: Add ACPI_PROCFS around procfs handling code.

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Make procfs support optional under ACPI_PROCFS

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |   21 +
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 87bee1e..7db85a9 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -29,9 +29,11 @@
 #include 
 #include 
 
+#ifdef CONFIG_ACPI_PROCFS
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
@@ -91,7 +93,9 @@ struct acpi_battery {
struct power_supply bat;
 #endif
struct acpi_sbs *sbs;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *proc_entry;
+#endif
unsigned long update_time;
char name[8];
char manufacturer_name[ACPI_SBS_BLOCK_MAX];
@@ -125,7 +129,9 @@ struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
+#ifdef CONFIG_ACPI_PROCFS
struct proc_dir_entry *charger_entry;
+#endif
struct acpi_battery battery[MAX_SBS_BAT];
u8 batteries_supported:4;
u8 manager_present:1;
@@ -389,6 +395,8 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
return result;
 }
 
+#ifdef CONFIG_ACPI_PROCFS
+
 static int acpi_battery_get_alarm(struct acpi_battery *battery)
 {
return acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
@@ -424,6 +432,7 @@ static int acpi_battery_set_alarm(struct acpi_battery 
*battery)
   end:
return ret;
 }
+#endif
 
 static int acpi_ac_get_present(struct acpi_sbs *sbs)
 {
@@ -759,10 +768,12 @@ static int acpi_battery_add(struct acpi_sbs *sbs, int id)
return result;
 
sprintf(battery->name, ACPI_BATTERY_DIR_NAME, id);
+#ifdef CONFIG_ACPI_PROCFS
acpi_sbs_add_fs(&battery->proc_entry, acpi_battery_dir,
battery->name, &acpi_battery_info_fops,
&acpi_battery_state_fops, &acpi_battery_alarm_fops,
battery);
+#endif
 #ifdef ENABLE_POWER_SUPPLY
battery->bat.name = battery->name;
battery->bat.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -790,10 +801,12 @@ static void acpi_battery_remove(struct acpi_sbs *sbs, int 
id)
if (sbs->battery[id].bat.dev)
power_supply_unregister(&sbs->battery[id].bat);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->battery[id].proc_entry) {
acpi_sbs_remove_fs(&(sbs->battery[id].proc_entry),
   acpi_battery_dir);
}
+#endif
 }
 
 static int acpi_charger_add(struct acpi_sbs *sbs)
@@ -803,11 +816,13 @@ static int acpi_charger_add(struct acpi_sbs *sbs)
result = acpi_ac_get_present(sbs);
if (result)
goto end;
+#ifdef CONFIG_ACPI_PROCFS
result = acpi_sbs_add_fs(&sbs->charger_entry, acpi_ac_dir,
 ACPI_AC_DIR_NAME, NULL,
 &acpi_ac_state_fops, NULL, sbs);
if (result)
goto end;
+#endif
 #ifdef ENABLE_POWER_SUPPLY
sbs->charger.name = "sbs-charger";
sbs->charger.type = POWER_SUPPLY_TYPE_MAINS;
@@ -829,8 +844,10 @@ static void acpi_charger_remove(struct acpi_sbs *sbs)
if (sbs->charger.dev)
power_supply_unregister(&sbs->charger);
 #endif
+#ifdef CONFIG_ACPI_PROCFS
if (sbs->charger_entry)
acpi_sbs_remove_fs(&sbs->charger_entry, acpi_ac_dir);
+#endif
 }
 
 void acpi_sbs_callback(void *context)
@@ -933,6 +950,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int 
type)
 
 static void acpi_sbs_rmdirs(void)
 {
+#ifdef CONFIG_ACPI_PROCFS
if (acpi_ac_dir) {
acpi_unlock_ac_dir(acpi_ac_dir);
acpi_ac_dir = NULL;
@@ -941,6 +959,7 @@ static void acpi_sbs_rmdirs(void)
acpi_unlock_battery_dir(acpi_battery_dir);
acpi_battery_dir = NULL;
}
+#endif
 }
 
 static int acpi_sbs_resume(struct acpi_device *device)
@@ -970,6 +989,7 @@ static int __init acpi_sbs_init(void)
 
if (acpi_disabled)
return -ENODEV;
+#ifdef CONFIG_ACPI_PROCFS
acpi_ac_dir = acpi_lock_ac_dir();
if (!acpi_ac_dir)
return -ENODEV;
@@ -978,6 +998,7 @@ static int __init acpi_sbs_init(void)
acpi_sbs_rmdirs();
return -ENODEV;
}
+#endif
result = acpi_bus_register_driver(&acpi_sbs_driver);
if (result < 0) {
acpi_sbs_rmdirs();

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/12] ACPI: SBS: Make SBS reads table-driven.

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Re-factor SBS functions to use tables and cycles for repeated operations.
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c | 1286 +++-
 1 files changed, 275 insertions(+), 1011 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 4aee7fb..8651e5f 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -1,6 +1,8 @@
 /*
- *  acpi_sbs.c - ACPI Smart Battery System Driver ($Revision: 1.16 $)
+ *  sbs.c - ACPI Smart Battery System Driver ($Revision: 2.0 $)
  *
+ *  Copyright (c) 2007 Alexey Starikovskiy <[EMAIL PROTECTED]>
+ *  Copyright (c) 2005-2007 Vladimir Lebedev <[EMAIL PROTECTED]>
  *  Copyright (c) 2005 Rich Townsend <[EMAIL PROTECTED]>
  *
  * ~~
@@ -46,53 +48,34 @@
 #define ACPI_SBS_FILE_ALARM"alarm"
 #define ACPI_BATTERY_DIR_NAME  "BAT%i"
 #define ACPI_AC_DIR_NAME   "AC0"
-#define ACPI_SBC_SMBUS_ADDR0x9
-#define ACPI_SBSM_SMBUS_ADDR   0xa
-#define ACPI_SB_SMBUS_ADDR 0xb
-#define ACPI_SBS_AC_NOTIFY_STATUS  0x80
-#define ACPI_SBS_BATTERY_NOTIFY_STATUS 0x80
-#define ACPI_SBS_BATTERY_NOTIFY_INFO   0x81
 
-#define _COMPONENT ACPI_SBS_COMPONENT
+enum acpi_sbs_device_addr {
+   ACPI_SBS_CHARGER = 0x9,
+   ACPI_SBS_MANAGER = 0xa,
+   ACPI_SBS_BATTERY = 0xb,
+};
+
+#define ACPI_SBS_NOTIFY_STATUS 0x80
+#define ACPI_SBS_NOTIFY_INFO   0x81
 
 ACPI_MODULE_NAME("sbs");
 
-MODULE_AUTHOR("Rich Townsend");
+MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
 
-#defineDEF_CAPACITY_UNIT   3
-#defineMAH_CAPACITY_UNIT   1
-#defineMWH_CAPACITY_UNIT   2
-#defineCAPACITY_UNIT   DEF_CAPACITY_UNIT
-
-#defineREQUEST_UPDATE_MODE 1
-#defineQUEUE_UPDATE_MODE   2
-
-#defineDATA_TYPE_COMMON0
-#defineDATA_TYPE_INFO  1
-#defineDATA_TYPE_STATE 2
-#defineDATA_TYPE_ALARM 3
-#defineDATA_TYPE_AC_STATE  4
+static unsigned int cache_time = 1000;
+module_param(cache_time, uint, 0644);
+MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
 extern struct proc_dir_entry *acpi_lock_ac_dir(void);
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
 extern void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
-#defineMAX_SBS_BAT 4
+#define MAX_SBS_BAT4
 #define ACPI_SBS_BLOCK_MAX 32
 
-#defineUPDATE_DELAY10
-
-/* 0 - every time, > 0 - by update_time */
-static unsigned int update_time = 120;
-
-static unsigned int mode = CAPACITY_UNIT;
-
-module_param(update_time, uint, 0644);
-module_param(mode, uint, 0444);
-
 static int acpi_sbs_add(struct acpi_device *device);
 static int acpi_sbs_remove(struct acpi_device *device, int type);
 static int acpi_sbs_resume(struct acpi_device *device);
@@ -117,486 +100,187 @@ static struct acpi_driver acpi_sbs_driver = {
 struct acpi_battery {
struct acpi_sbs *sbs;
struct proc_dir_entry *proc_entry;
-   int vscale;
-   int ipscale;
+   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];
+   u32 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 current_now;
+   s16 current_avg;
u16 capacity_now;
+   u16 state_of_charge;
u16 state;
-   u16 alarm_capacity;
u16 mode;
+   u16 spec;
u8 id;
-   u8 alive:1;
-   u8 init_state:1;
u8 present:1;
 };
 
 struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
-   struct mutex mutex;
-   struct proc_dir_entry *ac_entry;
+   struct mutex lock;
+   struct proc_dir_entry *charger_entry;
struct acpi_battery battery[MAX_SBS_BAT];
-   int zombie;
-   struct timer_list update_timer;
-   int run_cnt;
-   int update_proc_flg;
-   u8 batteries_supported;
+   u8 batteries_supported:4;
u8 manager_present:1;
u8 charger_present:1;
 };
 
-static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
-static void acpi_sbs_update_time(void *data);
-
-static int sbs_zombie(struct acpi_sbs *sbs)
+static inline int battery_scale(int log)
 {
-   return (sbs->zombie);
+   int scale = 1;
+   while (log--)
+   scale *= 

RE: scripts/mod/file2alias.c cross compile problem

2007-08-16 Thread Thomas Renninger
On Fri, 2007-08-03 at 08:08 +1000, Rusty Russell wrote:
> On Thu, 2007-08-02 at 09:25 -0700, Luck, Tony wrote:
> > > Adrian Bunk: scripts/mod/file2alias.c is compiled with HOSTCC and ensures 
> > > that
> > > kernel_ulong_t is correct, but it can't cope with different padding on
> > > different architectures.
> > 
> > Surely this is the root cause ... you can't expect that the alignment
> > rules of HOSTCC to make any sense for an arbitraty target.
> > 
> > > +#define FILLUP_LEN   7 /* dirty fix for i386 -> 64bit 
> > > cross-compilation */
> > >  
> > >  struct acpi_device_id {
> > >   __u8 id[ACPI_ID_LEN];
> > > + __u8 dummy[FILLUP_LEN];
> > >   kernel_ulong_t driver_data;
> > >  };
> > 
> > What's so special about this structure that we get an error?
> 
> It's in mod_devicetable.h: see comment at top of that file.  These
> structures serve dual purpose: to describe the capabilities of the
> driver to the kernel probing functions, *and* to export them to
> userspace tables.  The former purpose is why there's a data pointer in
> there.
> 
> scripts/mod/file2alias is the program that reads this: although it can
> be altered to parse 32-vs-64, Adrian's fix is the simplest.

Oops, this will cause a lot build warnings, as this struct gets
initialized like that:
..
{"PNP0C0A", 0},
..
at a lot places. It would be better to bump up the id itself like the
attached patch does...

Thanks,

Thomas

--

Cross-compilation between e.g. i386 -> 64bit could break -> work around it

Adrian Bunk: scripts/mod/file2alias.c is compiled with HOSTCC and ensures that
kernel_ulong_t is correct, but it can't cope with different padding on
different architectures.

Signed-off-by: Thomas Renninger <[EMAIL PROTECTED]>

---
 include/linux/mod_devicetable.h |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Index: linux-2.6.23-rc3/include/linux/mod_devicetable.h
===
--- linux-2.6.23-rc3.orig/include/linux/mod_devicetable.h
+++ linux-2.6.23-rc3/include/linux/mod_devicetable.h
@@ -159,7 +159,8 @@ struct ap_device_id {
 
 #define AP_DEVICE_ID_MATCH_DEVICE_TYPE 0x01
 
-#define ACPI_ID_LEN9
+#define ACPI_ID_LEN16 /* only 9 bytes needed here, 16 bytes are used */
+  /* to workaround crosscompile issues */
 
 struct acpi_device_id {
__u8 id[ACPI_ID_LEN];


-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/12] ACPI: SBS: Add support for power_supply class (and sysfs)

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Add support for power_supply class and sysfs interface of it.
Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |  331 +++-
 1 files changed, 250 insertions(+), 81 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 8651e5f..87bee1e 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -28,17 +28,23 @@
 #include 
 #include 
 #include 
+
 #include 
 #include 
 #include 
+
 #include 
 #include 
 #include 
 #include 
 
+#if defined(CONFIG_POWER_SUPPLY) || defined (CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #include "sbshc.h"
 
-#define ACPI_SBS_COMPONENT 0x0008
 #define ACPI_SBS_CLASS "sbs"
 #define ACPI_AC_CLASS  "ac_adapter"
 #define ACPI_BATTERY_CLASS "battery"
@@ -58,8 +64,6 @@ enum acpi_sbs_device_addr {
 #define ACPI_SBS_NOTIFY_STATUS 0x80
 #define ACPI_SBS_NOTIFY_INFO   0x81
 
-ACPI_MODULE_NAME("sbs");
-
 MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
@@ -76,28 +80,16 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 #define MAX_SBS_BAT4
 #define ACPI_SBS_BLOCK_MAX 32
 
-static int acpi_sbs_add(struct acpi_device *device);
-static int acpi_sbs_remove(struct acpi_device *device, int type);
-static int acpi_sbs_resume(struct acpi_device *device);
-
 static const struct acpi_device_id sbs_device_ids[] = {
{"ACPI0002", 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
 
-static struct acpi_driver acpi_sbs_driver = {
-   .name = "sbs",
-   .class = ACPI_SBS_CLASS,
-   .ids = sbs_device_ids,
-   .ops = {
-   .add = acpi_sbs_add,
-   .remove = acpi_sbs_remove,
-   .resume = acpi_sbs_resume,
-   },
-};
-
 struct acpi_battery {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply bat;
+#endif
struct acpi_sbs *sbs;
struct proc_dir_entry *proc_entry;
unsigned long update_time;
@@ -105,7 +97,7 @@ struct acpi_battery {
char manufacturer_name[ACPI_SBS_BLOCK_MAX];
char device_name[ACPI_SBS_BLOCK_MAX];
char device_chemistry[ACPI_SBS_BLOCK_MAX];
-   u32 alarm_capacity;
+   u16 alarm_capacity;
u16 full_charge_capacity;
u16 design_capacity;
u16 design_voltage;
@@ -124,7 +116,12 @@ struct acpi_battery {
u8 present:1;
 };
 
+#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
+
 struct acpi_sbs {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply charger;
+#endif
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex lock;
@@ -135,6 +132,8 @@ struct acpi_sbs {
u8 charger_present:1;
 };
 
+#define to_acpi_sbs(x) container_of(x, struct acpi_sbs, charger)
+
 static inline int battery_scale(int log)
 {
int scale = 1;
@@ -164,6 +163,146 @@ static inline int acpi_battery_scale(struct acpi_battery 
*battery)
acpi_battery_ipscale(battery);
 }
 
+#ifdef ENABLE_POWER_SUPPLY
+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;
+   switch (psp) {
+   case POWER_SUPPLY_PROP_STATUS:
+   if (battery->current_now < 0)
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   else if (battery->current_n

[PATCH 09/12] ACPI: SBS: Simplify data structures in SBS

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/sbs.c |  280 +---
 1 files changed, 134 insertions(+), 146 deletions(-)

diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 1c2365a..4aee7fb 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -88,10 +88,10 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 /* 0 - every time, > 0 - by update_time */
 static unsigned int update_time = 120;
 
-static unsigned int capacity_mode = CAPACITY_UNIT;
+static unsigned int mode = CAPACITY_UNIT;
 
 module_param(update_time, uint, 0644);
-module_param(capacity_mode, uint, 0444);
+module_param(mode, uint, 0444);
 
 static int acpi_sbs_add(struct acpi_device *device);
 static int acpi_sbs_remove(struct acpi_device *device, int type);
@@ -114,59 +114,43 @@ static struct acpi_driver acpi_sbs_driver = {
},
 };
 
-struct acpi_ac {
-   int ac_present;
-};
-
-struct acpi_battery_info {
-   int capacity_mode;
-   s16 full_charge_capacity;
-   s16 design_capacity;
-   s16 design_voltage;
-   int vscale;
-   int ipscale;
-   s16 serial_number;
-   char manufacturer_name[ACPI_SBS_BLOCK_MAX + 3];
-   char device_name[ACPI_SBS_BLOCK_MAX + 3];
-   char device_chemistry[ACPI_SBS_BLOCK_MAX + 3];
-};
-
-struct acpi_battery_state {
-   s16 voltage;
-   s16 amperage;
-   s16 remaining_capacity;
-   s16 battery_state;
-};
-
-struct acpi_battery_alarm {
-   s16 remaining_capacity;
-};
-
 struct acpi_battery {
-   int alive;
-   int id;
-   int init_state;
-   int battery_present;
struct acpi_sbs *sbs;
-   struct acpi_battery_info info;
-   struct acpi_battery_state state;
-   struct acpi_battery_alarm alarm;
-   struct proc_dir_entry *battery_entry;
+   struct proc_dir_entry *proc_entry;
+   int vscale;
+   int ipscale;
+   char manufacturer_name[ACPI_SBS_BLOCK_MAX];
+   char device_name[ACPI_SBS_BLOCK_MAX];
+   char device_chemistry[ACPI_SBS_BLOCK_MAX];
+   u16 full_charge_capacity;
+   u16 design_capacity;
+   u16 design_voltage;
+   u16 serial_number;
+   u16 voltage_now;
+   s16 current_now;
+   u16 capacity_now;
+   u16 state;
+   u16 alarm_capacity;
+   u16 mode;
+   u8 id;
+   u8 alive:1;
+   u8 init_state:1;
+   u8 present:1;
 };
 
 struct acpi_sbs {
struct acpi_device *device;
struct acpi_smb_hc *hc;
struct mutex mutex;
-   int sbsm_present;
-   int sbsm_batteries_supported;
struct proc_dir_entry *ac_entry;
-   struct acpi_ac ac;
struct acpi_battery battery[MAX_SBS_BAT];
int zombie;
struct timer_list update_timer;
int run_cnt;
int update_proc_flg;
+   u8 batteries_supported;
+   u8 manager_present:1;
+   u8 charger_present:1;
 };
 
 static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
@@ -231,7 +215,7 @@ static int acpi_battery_get_present(struct acpi_battery 
*battery)
if (!result) {
is_present = (state & 0x000f) & (1 << battery->id);
}
-   battery->battery_present = is_present;
+   battery->present = is_present;
 
return result;
 }
@@ -243,14 +227,14 @@ static int acpi_battery_select(struct acpi_battery 
*battery)
s16 state;
int foo;
 
-   if (sbs->sbsm_present) {
+   if (sbs->manager_present) {
 
/* Take special care not to knobble other nibbles of
 * state (aka selector_state), since
 * it causes charging to halt on SBSELs */
 
-   result =
-   acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, 
ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&state);
+   result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD,
+ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 
*)&state);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_read() failed"));
@@ -258,8 +242,8 @@ static int acpi_battery_select(struct acpi_battery *battery)
}
 
foo = (state & 0x0fff) | (1 << (battery->id + 12));
-   result =
-   acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, 
ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 *)&foo, 2);
+   result = acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD,
+ ACPI_SBSM_SMBUS_ADDR, 0x01, (u8 
*)&foo, 2);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
"acpi_smbus_write() failed"));
@@ -283,8 +267,7 @@ static int acpi_sbsm_get_info(struct acpi_sbs *sbs)
"acpi_smbus_read() failed"))

[PATCH 08/12] ACPI: SBS: Split host controller (ACPI0001) from SBS driver (ACPI0002)

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Replace poll-based host controller driver with the notify-based one.
Split it out of sbs.c.
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/Makefile |1 
 drivers/acpi/sbs.c|  374 ++---
 drivers/acpi/sbshc.c  |  309 
 drivers/acpi/sbshc.h  |   27 
 4 files changed, 412 insertions(+), 299 deletions(-)

diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index d4336f1..54e3ab0 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -60,3 +60,4 @@ obj-$(CONFIG_ACPI_TOSHIBA)+= toshiba_acpi.o
 obj-$(CONFIG_ACPI_HOTPLUG_MEMORY)  += acpi_memhotplug.o
 obj-y  += cm_sbs.o
 obj-$(CONFIG_ACPI_SBS) += sbs.o
+obj-$(CONFIG_ACPI_SBS) += sbshc.o
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 88af657..1c2365a 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -34,6 +34,8 @@
 #include 
 #include 
 
+#include "sbshc.h"
+
 #define ACPI_SBS_COMPONENT 0x0008
 #define ACPI_SBS_CLASS "sbs"
 #define ACPI_AC_CLASS  "ac_adapter"
@@ -59,28 +61,6 @@ MODULE_AUTHOR("Rich Townsend");
 MODULE_DESCRIPTION("Smart Battery System ACPI interface driver");
 MODULE_LICENSE("GPL");
 
-#definexmsleep(t)  msleep(t)
-
-#define ACPI_EC_SMB_PRTCL  0x00/* protocol, PEC */
-
-#define ACPI_EC_SMB_STS0x01/* status */
-#define ACPI_EC_SMB_ADDR   0x02/* address */
-#define ACPI_EC_SMB_CMD0x03/* command */
-#define ACPI_EC_SMB_DATA   0x04/* 32 data registers */
-#define ACPI_EC_SMB_BCNT   0x24/* number of data bytes */
-
-#define ACPI_EC_SMB_STS_DONE   0x80
-#define ACPI_EC_SMB_STS_STATUS 0x1f
-
-#define ACPI_EC_SMB_PRTCL_WRITE0x00
-#define ACPI_EC_SMB_PRTCL_READ 0x01
-#define ACPI_EC_SMB_PRTCL_WORD_DATA0x08
-#define ACPI_EC_SMB_PRTCL_BLOCK_DATA   0x0a
-
-#define ACPI_EC_SMB_TRANSACTION_SLEEP  1
-#define ACPI_EC_SMB_ACCESS_SLEEP1  1
-#define ACPI_EC_SMB_ACCESS_SLEEP2  10
-
 #defineDEF_CAPACITY_UNIT   3
 #defineMAH_CAPACITY_UNIT   1
 #defineMWH_CAPACITY_UNIT   2
@@ -103,12 +83,6 @@ extern void acpi_unlock_battery_dir(struct proc_dir_entry 
*acpi_battery_dir);
 #defineMAX_SBS_BAT 4
 #define ACPI_SBS_BLOCK_MAX 32
 
-#define ACPI_SBS_SMBUS_READ1
-#define ACPI_SBS_SMBUS_WRITE   2
-
-#define ACPI_SBS_WORD_DATA 1
-#define ACPI_SBS_BLOCK_DATA2
-
 #defineUPDATE_DELAY10
 
 /* 0 - every time, > 0 - by update_time */
@@ -124,8 +98,7 @@ static int acpi_sbs_remove(struct acpi_device *device, int 
type);
 static int acpi_sbs_resume(struct acpi_device *device);
 
 static const struct acpi_device_id sbs_device_ids[] = {
-   {"ACPI0001", 0},
-   {"ACPI0005", 0},
+   {"ACPI0002", 0},
{"", 0},
 };
 MODULE_DEVICE_TABLE(acpi, sbs_device_ids);
@@ -182,8 +155,8 @@ struct acpi_battery {
 };
 
 struct acpi_sbs {
-   int base;
struct acpi_device *device;
+   struct acpi_smb_hc *hc;
struct mutex mutex;
int sbsm_present;
int sbsm_batteries_supported;
@@ -199,190 +172,6 @@ struct acpi_sbs {
 static int acpi_sbs_update_run(struct acpi_sbs *sbs, int id, int data_type);
 static void acpi_sbs_update_time(void *data);
 
-union sbs_rw_data {
-   u16 word;
-   u8 block[ACPI_SBS_BLOCK_MAX + 2];
-};
-
-static int acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
- char read_write, u8 command, int size,
- union sbs_rw_data *data);
-
-/* --
-   SMBus Communication
-   -- 
*/
-
-static int acpi_ec_sbs_read(struct acpi_sbs *sbs, u8 address, u8 * data)
-{
-   u8 val;
-   int err;
-
-   err = ec_read(sbs->base + address, &val);
-   if (!err) {
-   *data = val;
-   }
-   xmsleep(ACPI_EC_SMB_TRANSACTION_SLEEP);
-   return (err);
-}
-
-static int acpi_ec_sbs_write(struct acpi_sbs *sbs, u8 address, u8 data)
-{
-   int err;
-
-   err = ec_write(sbs->base + address, data);
-   return (err);
-}
-
-static int
-acpi_ec_sbs_access(struct acpi_sbs *sbs, u16 addr,
-  char read_write, u8 command, int size,
-  union sbs_rw_data *data)
-{
-   unsigned char protocol, len = 0, temp[2] = { 0, 0 };
-   int i;
-
-   if (read_write == ACPI_SBS_SMBUS_READ) {
-   protocol = ACPI_EC_SMB_PRTCL_READ;
-   } else {
-   protocol = ACPI_EC_SMB_PRTCL_WRITE;
-   }
-
-   switch (size) {
-
-   case ACPI_SBS_WORD_DATA:
-   acpi_ec_sbs_write(sbs, ACPI_EC_SMB

[PATCH 06/12] ACPI: Add acpi_bus_generate_event4() function

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

acpi_bus_generate_event() takes two strings out of passed device object.
SBS needs to supply these strings directly.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/bus.c  |   25 -
 drivers/acpi/event.c|7 ---
 drivers/acpi/sbs.c  |   39 ---
 include/acpi/acpi_bus.h |6 --
 4 files changed, 32 insertions(+), 45 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 6b2658c..992bb30 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -283,16 +283,12 @@ DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
 
 extern int event_is_open;
 
-int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
+int acpi_bus_generate_event4(const char *device_class, const char *bus_id, u8 
type, int data)
 {
-   struct acpi_bus_event *event = NULL;
+   struct acpi_bus_event *event;
unsigned long flags = 0;
 
-
-   if (!device)
-   return -EINVAL;
-
-   if (acpi_bus_generate_genetlink_event(device, type, data))
+   if (acpi_bus_generate_genetlink_event(device_class, bus_id, type, data))
printk(KERN_WARNING PREFIX
"Failed to generate an ACPI event via genetlink!\n");
 
@@ -304,8 +300,8 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 
type, int data)
if (!event)
return -ENOMEM;
 
-   strcpy(event->device_class, device->pnp.device_class);
-   strcpy(event->bus_id, device->pnp.bus_id);
+   strcpy(event->device_class, device_class);
+   strcpy(event->bus_id, bus_id);
event->type = type;
event->data = data;
 
@@ -316,6 +312,17 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 
type, int data)
wake_up_interruptible(&acpi_bus_event_queue);
 
return 0;
+
+}
+
+EXPORT_SYMBOL_GPL(acpi_bus_generate_event4);
+
+int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
+{
+   if (!device)
+   return -EINVAL;
+   return acpi_bus_generate_event4(device->pnp.device_class,
+   device->pnp.bus_id, type, data);
 }
 
 EXPORT_SYMBOL(acpi_bus_generate_event);
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 95637a4..6529280 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -147,7 +147,8 @@ static struct genl_multicast_group acpi_event_mcgrp = {
.name = ACPI_GENL_MCAST_GROUP_NAME,
 };
 
-int acpi_bus_generate_genetlink_event(struct acpi_device *device,
+int acpi_bus_generate_genetlink_event(const char *device_class,
+ const char *bus_id,
  u8 type, int data)
 {
struct sk_buff *skb;
@@ -191,8 +192,8 @@ int acpi_bus_generate_genetlink_event(struct acpi_device 
*device,
 
memset(event, 0, sizeof(struct acpi_genl_event));
 
-   strcpy(event->device_class, device->pnp.device_class);
-   strcpy(event->bus_id, device->dev.bus_id);
+   strcpy(event->device_class, device_class);
+   strcpy(event->bus_id, bus_id);
event->type = type;
event->data = data;
 
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 82c3a55..88af657 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -427,27 +427,6 @@ static int acpi_check_update_proc(struct acpi_sbs *sbs)
return 0;
 }
 
-static int acpi_sbs_generate_event(struct acpi_device *device,
-  int event, int state, char *bid, char *class)
-{
-   char bid_saved[5];
-   char class_saved[20];
-   int result = 0;
-
-   strcpy(bid_saved, acpi_device_bid(device));
-   strcpy(class_saved, acpi_device_class(device));
-
-   strcpy(acpi_device_bid(device), bid);
-   strcpy(acpi_device_class(device), class);
-
-   result = acpi_bus_generate_event(device, event, state);
-
-   strcpy(acpi_device_bid(device), bid_saved);
-   strcpy(acpi_device_class(device), class_saved);
-
-   return result;
-}
-
 static int acpi_battery_get_present(struct acpi_battery *battery)
 {
s16 state;
@@ -1451,14 +1430,13 @@ static int acpi_sbs_update_run(struct acpi_sbs *sbs, 
int id, int data_type)
}
 
if (do_ac_init) {
-   result = acpi_sbs_generate_event(sbs->device,
-ACPI_SBS_AC_NOTIFY_STATUS,
-new_ac_present,
+   result = acpi_bus_generate_event4(ACPI_AC_CLASS,
 ACPI_AC_DIR_NAME,
-ACPI_AC_CLASS);
+ACPI_SBS_AC_NOTIFY_STATUS,
+new_ac_present);
if (result) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR,
-  

[PATCH 07/12] ACPI: EC: Add new query handler to list head.

2007-08-16 Thread Alexey Starikovskiy
From: Alexey Starikovskiy <[EMAIL PROTECTED]>

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/ec.c |3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 56bee9e..25a84af 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -425,7 +425,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 
query_bit,
handler->func = func;
handler->data = data;
mutex_lock(&ec->lock);
-   list_add_tail(&handler->node, &ec->list);
+   list_add(&handler->node, &ec->list);
mutex_unlock(&ec->lock);
return 0;
 }
@@ -440,7 +440,6 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 
query_bit)
if (query_bit == handler->query_bit) {
list_del(&handler->node);
kfree(handler);
-   break;
}
}
mutex_unlock(&ec->lock);

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/12] ACPI: Battery: Add sysfs support

2007-08-16 Thread Alexey Starikovskiy
Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  201 +++-
 1 files changed, 179 insertions(+), 22 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 0a20e80..2be9f45 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -30,13 +30,21 @@
 #include 
 #include 
 #include 
+
+#ifdef CONFIG_ACPI_PROC
 #include 
 #include 
 #include 
+#endif
 
 #include 
 #include 
 
+#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #define ACPI_BATTERY_VALUE_UNKNOWN 0x
 
 #define ACPI_BATTERY_COMPONENT 0x0004
@@ -58,9 +66,19 @@ static unsigned int cache_time = 1000;
 module_param(cache_time, uint, 0644);
 MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
+#ifdef CONFIG_ACPI_PROC
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
+enum acpi_battery_files {
+   info_tag = 0,
+   state_tag,
+   alarm_tag,
+   ACPI_BATTERY_NUMFILES,
+};
+
+#endif
+
 static const struct acpi_device_id battery_device_ids[] = {
{"PNP0C0A", 0},
{"", 0},
@@ -68,22 +86,19 @@ static const struct acpi_device_id battery_device_ids[] = {
 
 MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
-enum acpi_battery_files {
-   info_tag = 0,
-   state_tag,
-   alarm_tag,
-   ACPI_BATTERY_NUMFILES,
-};
 
 struct acpi_battery {
struct mutex lock;
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply bat;
+#endif
struct acpi_device *device;
unsigned long update_time;
-   int present_rate;
-   int remaining_capacity;
-   int present_voltage;
+   int current_now;
+   int capacity_now;
+   int voltage_now;
int design_capacity;
-   int last_full_capacity;
+   int full_charge_capacity;
int technology;
int design_voltage;
int design_capacity_warning;
@@ -100,15 +115,119 @@ struct acpi_battery {
u8 alarm_present;
 };
 
+#define to_acpi_battery(x) container_of(x, struct acpi_battery, bat);
+
 inline int acpi_battery_present(struct acpi_battery *battery)
 {
return battery->device->status.battery_present;
 }
 
+#ifdef ENABLE_POWER_SUPPLY
+static int acpi_battery_technology(struct acpi_battery *battery)
+{
+   if (!strcasecmp("NiCd", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_NiCd;
+   if (!strcasecmp("NiMH", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_NiMH;
+   if (!strcasecmp("LION", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_LION;
+   if (!strcasecmp("LiP", battery->type))
+   return POWER_SUPPLY_TECHNOLOGY_LIPO;
+   return POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
+}
+
+static int acpi_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 ((!acpi_battery_present(battery)) &&
+psp != POWER_SUPPLY_PROP_PRESENT)
+   return -ENODEV;
+   switch (psp) {
+   case POWER_SUPPLY_PROP_STATUS:
+   if (battery->state & 0x01)
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   else if (battery->state & 0x02)
+   val->intval = POWER_SUPPLY_STATUS_CHARGING;
+   else if (battery->state == 0)
+   val->intval = POWER_SUPPLY_STATUS_FULL;
+   break;
+   case POWER_SUPPLY_PROP_PRESENT:
+   val->intval = acpi_battery_present(battery);
+   break;
+   case POWER_SUPPLY_PROP_TECHNOLOGY:
+   val->intval = acpi_battery_technology(battery);
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
+   val->intval = battery->design_voltage * 1000;
+   break;
+   case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+   val->intval = battery->voltage_now * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CURRENT_NOW:
+   val->intval = battery->current_now * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
+   case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
+   val->intval = battery->design_capacity * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_FULL:
+   case POWER_SUPPLY_PROP_ENERGY_FULL:
+   val->intval = battery->full_charge_capacity * 1000;
+   break;
+   case POWER_SUPPLY_PROP_CHARGE_NOW:
+   case POWER_SUPPLY_PROP_ENERGY_NOW:
+   val->intval = battery->capacity_now * 1000;
+   break;
+   case POWER_SUPPLY_P

[PATCH 03/12] ACPI: Battery: simplify update scheme

2007-08-16 Thread Alexey Starikovskiy
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  274 +---
 1 files changed, 52 insertions(+), 222 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 14bdfad..eea4dd9 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -41,27 +42,18 @@
 #define ACPI_BATTERY_DEVICE_NAME   "Battery"
 #define ACPI_BATTERY_NOTIFY_STATUS 0x80
 #define ACPI_BATTERY_NOTIFY_INFO   0x81
-#define ACPI_BATTERY_UNITS_WATTS   "mW"
-#define ACPI_BATTERY_UNITS_AMPS"mA"
 
 #define _COMPONENT ACPI_BATTERY_COMPONENT
 
-#define ACPI_BATTERY_UPDATE_TIME   0
-
-#define ACPI_BATTERY_NONE_UPDATE   0
-#define ACPI_BATTERY_EASY_UPDATE   1
-#define ACPI_BATTERY_INIT_UPDATE   2
-
 ACPI_MODULE_NAME("battery");
 
 MODULE_AUTHOR("Paul Diefenbaugh");
 MODULE_DESCRIPTION("ACPI Battery Driver");
 MODULE_LICENSE("GPL");
 
-static unsigned int update_time = ACPI_BATTERY_UPDATE_TIME;
-
-/* 0 - every time, > 0 - by update_time */
-module_param(update_time, uint, 0644);
+static unsigned int cache_time = 1000;
+module_param(cache_time, uint, 0644);
+MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
@@ -95,15 +87,12 @@ enum acpi_battery_files {
 };
 
 struct acpi_battery {
-   struct acpi_device *device;
struct mutex lock;
-   unsigned long alarm;
-   unsigned long update_time[ACPI_BATTERY_NUMFILES];
-   int state;
+   struct acpi_device *device;
+   unsigned long update_time;
int present_rate;
int remaining_capacity;
int present_voltage;
-   int power_unit;
int design_capacity;
int last_full_capacity;
int technology;
@@ -112,14 +101,14 @@ struct acpi_battery {
int design_capacity_low;
int capacity_granularity_1;
int capacity_granularity_2;
+   int alarm;
char model_number[32];
char serial_number[32];
char type[32];
char oem_info[32];
-   u8 present_prev;
+   int state;
+   int power_unit;
u8 alarm_present;
-   u8 init_update;
-   u8 update[ACPI_BATTERY_NUMFILES];
 };
 
 inline int acpi_battery_present(struct acpi_battery *battery)
@@ -127,33 +116,15 @@ inline int acpi_battery_present(struct acpi_battery 
*battery)
return battery->device->status.battery_present;
 }
 
-inline char *acpi_battery_power_units(struct acpi_battery *battery)
+inline char *acpi_battery_units(struct acpi_battery *battery)
 {
-   if (battery->power_unit)
-   return ACPI_BATTERY_UNITS_AMPS;
-   else
-   return ACPI_BATTERY_UNITS_WATTS;
-}
-
-inline acpi_handle acpi_battery_handle(struct acpi_battery *battery)
-{
-   return battery->device->handle;
+   return (battery->power_unit)?"mA":"mW";
 }
 
 /* --
Battery Management
-- 
*/
 
-static void acpi_battery_check_result(struct acpi_battery *battery, int result)
-{
-   if (!battery)
-   return;
-
-   if (result) {
-   battery->init_update = 1;
-   }
-}
-
 struct acpi_offsets {
size_t offset;  /* offset inside struct acpi_sbs_battery */
u8 mode;/* int or string? */
@@ -228,11 +199,10 @@ static int acpi_battery_get_info(struct acpi_battery 
*battery)
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
-   battery->update_time[ACPI_BATTERY_INFO] = get_seconds();
if (!acpi_battery_present(battery))
return 0;
mutex_lock(&battery->lock);
-   status = acpi_evaluate_object(acpi_battery_handle(battery), "_BIF",
+   status = acpi_evaluate_object(battery->device->handle, "_BIF",
  NULL, &buffer);
mutex_unlock(&battery->lock);
if (ACPI_FAILURE(status)) {
@@ -251,14 +221,17 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
-   battery->update_time[ACPI_BATTERY_STATE] = get_seconds();
-
if (!acpi_battery_present(battery))
return 0;
 
+   if (battery->update_time &&
+   time_before(jiffies, battery->update_time +
+   msecs_to_jiffies(cache_time)))
+   return 0;
+
/* Evaluate _BST */
mutex_lock(&battery->lock);
-   status = acpi_evaluate_object(acpi_battery_handle(battery), "_BST",
+   status = acpi_evaluate_ob

[PATCH 04/12] ACPI: Battery: Misc clean-ups, no functional changes

2007-08-16 Thread Alexey Starikovskiy
Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  346 +---
 1 files changed, 126 insertions(+), 220 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index eea4dd9..0a20e80 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1,6 +1,8 @@
 /*
- *  acpi_battery.c - ACPI Battery Driver ($Revision: 37 $)
+ *  battery.c - ACPI Battery Driver (Revision: 2.0)
  *
+ *  Copyright (C) 2007 Alexey Starikovskiy <[EMAIL PROTECTED]>
+ *  Copyright (C) 2004-2007 Vladimir Lebedev <[EMAIL PROTECTED]>
  *  Copyright (C) 2001, 2002 Andy Grover <[EMAIL PROTECTED]>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <[EMAIL PROTECTED]>
  *
@@ -48,6 +50,7 @@
 ACPI_MODULE_NAME("battery");
 
 MODULE_AUTHOR("Paul Diefenbaugh");
+MODULE_AUTHOR("Alexey Starikovskiy <[EMAIL PROTECTED]>");
 MODULE_DESCRIPTION("ACPI Battery Driver");
 MODULE_LICENSE("GPL");
 
@@ -58,31 +61,17 @@ MODULE_PARM_DESC(cache_time, "cache time in milliseconds");
 extern struct proc_dir_entry *acpi_lock_battery_dir(void);
 extern void *acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir);
 
-static int acpi_battery_add(struct acpi_device *device);
-static int acpi_battery_remove(struct acpi_device *device, int type);
-static int acpi_battery_resume(struct acpi_device *device);
-
 static const struct acpi_device_id battery_device_ids[] = {
{"PNP0C0A", 0},
{"", 0},
 };
-MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
-static struct acpi_driver acpi_battery_driver = {
-   .name = "battery",
-   .class = ACPI_BATTERY_CLASS,
-   .ids = battery_device_ids,
-   .ops = {
-   .add = acpi_battery_add,
-   .resume = acpi_battery_resume,
-   .remove = acpi_battery_remove,
-   },
-};
+MODULE_DEVICE_TABLE(acpi, battery_device_ids);
 
 enum acpi_battery_files {
-   ACPI_BATTERY_INFO = 0,
-   ACPI_BATTERY_STATE,
-   ACPI_BATTERY_ALARM,
+   info_tag = 0,
+   state_tag,
+   alarm_tag,
ACPI_BATTERY_NUMFILES,
 };
 
@@ -124,7 +113,6 @@ inline char *acpi_battery_units(struct acpi_battery 
*battery)
 /* --
Battery Management
-- 
*/
-
 struct acpi_offsets {
size_t offset;  /* offset inside struct acpi_sbs_battery */
u8 mode;/* int or string? */
@@ -183,19 +171,16 @@ static int extract_package(struct acpi_battery *battery,
 
 static int acpi_battery_get_status(struct acpi_battery *battery)
 {
-   int result = 0;
-
-   result = acpi_bus_get_status(battery->device);
-   if (result) {
+   if (acpi_bus_get_status(battery->device)) {
ACPI_EXCEPTION((AE_INFO, AE_ERROR, "Evaluating _STA"));
return -ENODEV;
}
-   return result;
+   return 0;
 }
 
 static int acpi_battery_get_info(struct acpi_battery *battery)
 {
-   int result = 0;
+   int result = -EFAULT;
acpi_status status = 0;
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
@@ -205,10 +190,12 @@ static int acpi_battery_get_info(struct acpi_battery 
*battery)
status = acpi_evaluate_object(battery->device->handle, "_BIF",
  NULL, &buffer);
mutex_unlock(&battery->lock);
+
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BIF"));
return -ENODEV;
}
+
result = extract_package(battery, buffer.pointer,
 info_offsets, ARRAY_SIZE(info_offsets));
kfree(buffer.pointer);
@@ -234,10 +221,12 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
status = acpi_evaluate_object(battery->device->handle, "_BST",
  NULL, &buffer);
mutex_unlock(&battery->lock);
+
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _BST"));
return -ENODEV;
}
+
result = extract_package(battery, buffer.pointer,
 state_offsets, ARRAY_SIZE(state_offsets));
battery->update_time = jiffies;
@@ -245,37 +234,26 @@ static int acpi_battery_get_state(struct acpi_battery 
*battery)
return result;
 }
 
-static int acpi_battery_get_alarm(struct acpi_battery *battery)
-{
-   return 0;
-}
-
-static int acpi_battery_set_alarm(struct acpi_battery *battery,
- unsigned long alarm)
+static int acpi_battery_set_alarm(struct acpi_battery *battery)
 {
acpi_status status = 0;
-   union acpi_object arg0 = { ACPI_TYPE_INTEGER };
+   union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER };
struct acpi_object_list arg_list = { 1, &arg0 };
 
-

[PATCH 02/12] ACPI: Battery: don't use acpi_extract_package()

2007-08-16 Thread Alexey Starikovskiy
acpi_extract_package() creates more problems with memory management than
solves as helper for package handling.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/battery.c |  309 +++-
 1 files changed, 123 insertions(+), 186 deletions(-)

diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index d7b499f..14bdfad 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -36,9 +36,6 @@
 
 #define ACPI_BATTERY_VALUE_UNKNOWN 0x
 
-#define ACPI_BATTERY_FORMAT_BIF"N"
-#define ACPI_BATTERY_FORMAT_BST""
-
 #define ACPI_BATTERY_COMPONENT 0x0004
 #define ACPI_BATTERY_CLASS "battery"
 #define ACPI_BATTERY_DEVICE_NAME   "Battery"
@@ -90,29 +87,6 @@ static struct acpi_driver acpi_battery_driver = {
},
 };
 
-struct acpi_battery_state {
-   acpi_integer state;
-   acpi_integer present_rate;
-   acpi_integer remaining_capacity;
-   acpi_integer present_voltage;
-};
-
-struct acpi_battery_info {
-   acpi_integer power_unit;
-   acpi_integer design_capacity;
-   acpi_integer last_full_capacity;
-   acpi_integer battery_technology;
-   acpi_integer design_voltage;
-   acpi_integer design_capacity_warning;
-   acpi_integer design_capacity_low;
-   acpi_integer battery_capacity_granularity_1;
-   acpi_integer battery_capacity_granularity_2;
-   acpi_string model_number;
-   acpi_string serial_number;
-   acpi_string battery_type;
-   acpi_string oem_info;
-};
-
 enum acpi_battery_files {
ACPI_BATTERY_INFO = 0,
ACPI_BATTERY_STATE,
@@ -120,32 +94,42 @@ enum acpi_battery_files {
ACPI_BATTERY_NUMFILES,
 };
 
-struct acpi_battery_flags {
-   u8 battery_present_prev;
-   u8 alarm_present;
-   u8 init_update;
-   u8 update[ACPI_BATTERY_NUMFILES];
-   u8 power_unit;
-};
-
 struct acpi_battery {
struct acpi_device *device;
-   struct acpi_battery_flags flags;
-   struct acpi_buffer bif_data;
-   struct acpi_buffer bst_data;
struct mutex lock;
unsigned long alarm;
unsigned long update_time[ACPI_BATTERY_NUMFILES];
-
+   int state;
+   int present_rate;
+   int remaining_capacity;
+   int present_voltage;
+   int power_unit;
+   int design_capacity;
+   int last_full_capacity;
+   int technology;
+   int design_voltage;
+   int design_capacity_warning;
+   int design_capacity_low;
+   int capacity_granularity_1;
+   int capacity_granularity_2;
+   char model_number[32];
+   char serial_number[32];
+   char type[32];
+   char oem_info[32];
+   u8 present_prev;
+   u8 alarm_present;
+   u8 init_update;
+   u8 update[ACPI_BATTERY_NUMFILES];
 };
 
 inline int acpi_battery_present(struct acpi_battery *battery)
 {
return battery->device->status.battery_present;
 }
+
 inline char *acpi_battery_power_units(struct acpi_battery *battery)
 {
-   if (battery->flags.power_unit)
+   if (battery->power_unit)
return ACPI_BATTERY_UNITS_AMPS;
else
return ACPI_BATTERY_UNITS_WATTS;
@@ -166,43 +150,63 @@ static void acpi_battery_check_result(struct acpi_battery 
*battery, int result)
return;
 
if (result) {
-   battery->flags.init_update = 1;
+   battery->init_update = 1;
}
 }
 
-static int acpi_battery_extract_package(struct acpi_battery *battery,
-   union acpi_object *package,
-   struct acpi_buffer *format,
-   struct acpi_buffer *data,
-   char *package_name)
-{
-   acpi_status status = AE_OK;
-   struct acpi_buffer data_null = { 0, NULL };
+struct acpi_offsets {
+   size_t offset;  /* offset inside struct acpi_sbs_battery */
+   u8 mode;/* int or string? */
+};
 
-   status = acpi_extract_package(package, format, &data_null);
-   if (status != AE_BUFFER_OVERFLOW) {
-   ACPI_EXCEPTION((AE_INFO, status, "Extracting size %s",
-   package_name));
-   return -ENODEV;
-   }
+static struct acpi_offsets state_offsets[] = {
+   {offsetof(struct acpi_battery, state), 0},
+   {offsetof(struct acpi_battery, present_rate), 0},
+   {offsetof(struct acpi_battery, remaining_capacity), 0},
+   {offsetof(struct acpi_battery, present_voltage), 0},
+};
 
-   if (data_null.length != data->length) {
-   kfree(data->pointer);
-   data->pointer = kzalloc(data_null.length, GFP_KERNEL);
-   if (!data->pointer) {
-   ACPI_EXCEPTION((AE_INFO, AE_NO_MEMORY, "kzalloc()"));
-   return -ENOMEM;
-   }
-   data

[PATCH 01/12] ACPI: AC: Add sysfs interface

2007-08-16 Thread Alexey Starikovskiy
Refer to Documentation/power_supply_class.txt for interface description.

Signed-off-by: Alexey Starikovskiy <[EMAIL PROTECTED]>
---

 drivers/acpi/ac.c |   49 +++--
 1 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index d8b3509..d13b961 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -29,6 +29,12 @@
 #include 
 #include 
 #include 
+
+#if defined(CONFIG_POWER_SUPPLY) || defined(CONFIG_POWER_SUPPLY_MODULE)
+#define ENABLE_POWER_SUPPLY
+#include 
+#endif
+
 #include 
 #include 
 
@@ -72,16 +78,42 @@ static struct acpi_driver acpi_ac_driver = {
 };
 
 struct acpi_ac {
+#ifdef ENABLE_POWER_SUPPLY
+   struct power_supply charger;
+#endif
struct acpi_device * device;
unsigned long state;
 };
 
+#define to_acpi_ac(x) container_of(x, struct acpi_ac, charger);
+
 static const struct file_operations acpi_ac_fops = {
.open = acpi_ac_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
 };
+#ifdef ENABLE_POWER_SUPPLY
+static int get_ac_property(struct power_supply *psy,
+  enum power_supply_property psp,
+  union power_supply_propval *val)
+{
+   struct acpi_ac *ac = to_acpi_ac(psy);
+   switch (psp) {
+   case POWER_SUPPLY_PROP_ONLINE:
+   val->intval = ac->state;
+   break;
+   default:
+   return -EINVAL;
+   }
+   return 0;
+}
+
+static enum power_supply_property ac_props[] = {
+   POWER_SUPPLY_PROP_ONLINE,
+};
+
+#endif
 
 /* --
AC Adapter Management
@@ -205,6 +237,9 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, 
void *data)
case ACPI_NOTIFY_DEVICE_CHECK:
acpi_ac_get_state(ac);
acpi_bus_generate_event(device, event, (u32) ac->state);
+#ifdef ENABLE_POWER_SUPPLY
+   kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
+#endif
break;
default:
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -241,7 +276,14 @@ static int acpi_ac_add(struct acpi_device *device)
result = acpi_ac_add_fs(device);
if (result)
goto end;
-
+#ifdef ENABLE_POWER_SUPPLY
+   ac->charger.name = acpi_device_bid(device);
+   ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
+   ac->charger.properties = ac_props;
+   ac->charger.num_properties = ARRAY_SIZE(ac_props);
+   ac->charger.get_property = get_ac_property;
+   power_supply_register(&ac->device->dev, &ac->charger);
+#endif
status = acpi_install_notify_handler(device->handle,
 ACPI_ALL_NOTIFY, acpi_ac_notify,
 ac);
@@ -276,7 +318,10 @@ static int acpi_ac_remove(struct acpi_device *device, int 
type)
 
status = acpi_remove_notify_handler(device->handle,
ACPI_ALL_NOTIFY, acpi_ac_notify);
-
+#ifdef ENABLE_POWER_SUPPLY
+   if (ac->charger.dev)
+   power_supply_unregister(&ac->charger);
+#endif
acpi_ac_remove_fs(device);
 
kfree(ac);

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: fan problem on new mainboard

2007-08-16 Thread Thomas Renninger
On Sat, 2007-08-11 at 17:13 +0200, Robert Lemmen wrote:
> On Thu, Aug 09, 2007 at 06:01:29PM +0800, Zhang Rui wrote:
> > Hi, Robert,
> > Please attach the full _dmesg_ output as well as the acpidump.
> 
> sorry for the delay, the list seems to eat mails with lareg attachemnts,
> therefore you can find the files here:
> 
> http://www.semistable.com/files/dmesg
> http://www.semistable.com/files/acpidump
> 
> (perhaps) interestingly acpidump also said (on stderr):
> Wrong checksum for generic table!
> 
> as a reminder because it took so long: the problem is that i have
> nothing in /proc/acpi/thermal_zone or proc/acpi//fan, and my cpu fan is
> spinning like crazy even though my cpu is ice cold

Your ACPI DSDT table does not show any thermal/fan control code.
So you won't be able to do much through ACPI.
Have you already searched for a BIOS update?
If you still have problems, maybe you find something in the BIOS
configuration...

   Thomas

-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] [-mm] ACPI: use GFP_KERNEL instead of GFP_ATOMIC

2007-08-16 Thread Mattia Dongili
On Thu, Aug 16, 2007 at 12:06:18PM +0800, Zhang Rui wrote:
> On Thu, 2007-08-16 at 11:36 +0800, Len Brown wrote:
> > On Tuesday 31 July 2007 19:00, Zhang Rui wrote:
> > > Use GFP_KERNEL instead of GFP_ATOMIC.
> > >
> > > GFP_ATOMIC is still needed by the sonypi and sony-laptop driver.
> > 
> > Why?
> > Sony can't events from user-context like everybody else does?
> Mattia has the plan to do this. But it won't be finished recently.

Hopefully I'll be able to get some more spare time in the next week or
two.

-- 
mattia
:wq!
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] FS: file name should be unique in the same dir in procfs

2007-08-16 Thread Zhang Rui
Files name should be unique in the same directory.

Bug is reported here: 
http://bugzilla.kernel.org/show_bug.cgi?id=8798

Signed-off-by: Zhang Rui <[EMAIL PROTECTED]>
---
 fs/proc/generic.c |8 
 1 file changed, 8 insertions(+)

Index: linux-2.6.23-rc3/fs/proc/generic.c
===
--- linux-2.6.23-rc3.orig/fs/proc/generic.c
+++ linux-2.6.23-rc3/fs/proc/generic.c
@@ -523,6 +523,7 @@ static const struct inode_operations pro
 
 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * 
dp)
 {
+   struct proc_dir_entry * tmp = NULL;
unsigned int i;

i = get_inode_number();
@@ -547,6 +548,13 @@ static int proc_register(struct proc_dir
}
 
spin_lock(&proc_subdir_lock);
+   for(tmp = dir->subdir; tmp; tmp = tmp->next)
+   if(!strcmp(dp->name, tmp->name)) {
+   spin_unlock(&proc_subdir_lock);
+   release_inode_number(i);
+   return -EEXIST;
+   }
+
dp->next = dir->subdir;
dp->parent = dir;
dir->subdir = dp;
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [linux-pm] [PATCH] ACPI: Make pnpacpi_suspend handle errors

2007-08-16 Thread Pavel Machek
Hi!

> pnpacpi_suspend() doesn't check the result returned by
> acpi_pm_device_sleep_state() before passing it to acpi_bus_set_power(), which
> may not be desirable.  Make it select the target power state of the device
> using its second argument if acpi_pm_device_sleep_state() fails.
> 
> Signed-off-by: Rafael J. Wysocki <[EMAIL PROTECTED]>

Looks ok to me.
Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) 
http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] ACPI: boot correctly with "nosmp" or "maxcpus=0"

2007-08-16 Thread Len Brown
From: Len Brown <[EMAIL PROTECTED]>

In MPS mode, "nosmp" and "maxcpus=0" boot a UP kernel with IOAPIC disabled.
However, in ACPI mode, these parameters didn't completely disable
the IO APIC initialization code and boot failed.

init/main.c:
Disable the IO_APIC if "nosmp" or "maxcpus=0"
undefine disable_ioapic_setup() when it doesn't apply.

i386:
delete ioapic_setup(), it was a duplicate of parse_noapic()
delete undefinition of disable_ioapic_setup()

x86_64:
rename disable_ioapic_setup() to parse_noapic() to match i386
define disable_ioapic_setup() in header to match i386

http://bugzilla.kernel.org/show_bug.cgi?id=1641

Signed-off-by: Len Brown <[EMAIL PROTECTED]>
---
 Documentation/kernel-parameters.txt |   15 ++-
 arch/i386/kernel/io_apic.c  |8 
 arch/x86_64/kernel/io_apic.c|8 +++-
 include/asm-i386/io_apic.h  |1 -
 include/asm-x86_64/io_apic.h|6 ++
 init/main.c |   12 ++--
 6 files changed, 25 insertions(+), 25 deletions(-)

Index: linus/Documentation/kernel-parameters.txt
===
--- linus.orig/Documentation/kernel-parameters.txt
+++ linus/Documentation/kernel-parameters.txt
@@ -952,14 +952,10 @@ and is between 256 and 4096 characters. 
Format: <1-256>
 
maxcpus=[SMP] Maximum number of processors that an SMP kernel
-   should make use of.
-   Using "nosmp" or "maxcpus=0" will disable SMP
-   entirely (the MPS table probe still happens, though).
-   A command-line option of "maxcpus=", where 
-   is an integer greater than 0, limits the maximum number
-   of CPUs activated in SMP mode to .
-   Using "maxcpus=1" on an SMP kernel is the trivial
-   case of an SMP kernel with only one CPU.
+   should make use of.  maxcpus=n : n >= 0 limits the
+   kernel to using 'n' processors.  n=0 is a special case,
+   it is equivalent to "nosmp", which also disables
+   the IO APIC.
 
max_addr=[KMG]  [KNL,BOOT,ia64] All physical memory greater than or
equal to this physical address is ignored.
@@ -1184,7 +1180,8 @@ and is between 256 and 4096 characters. 
 
nosep   [BUGS=X86-32] Disables x86 SYSENTER/SYSEXIT support.
 
-   nosmp   [SMP] Tells an SMP kernel to act as a UP kernel.
+   nosmp   [SMP] Tells an SMP kernel to act as a UP kernel,
+   and disable the IO APIC.  legacy for "maxcpus=0".
 
nosoftlockup[KNL] Disable the soft-lockup detector.
 
Index: linus/arch/i386/kernel/io_apic.c
===
--- linus.orig/arch/i386/kernel/io_apic.c
+++ linus/arch/i386/kernel/io_apic.c
@@ -754,14 +754,6 @@ static int pirq_entries [MAX_PIRQS];
 static int pirqs_enabled;
 int skip_ioapic_setup;
 
-static int __init ioapic_setup(char *str)
-{
-   skip_ioapic_setup = 1;
-   return 1;
-}
-
-__setup("noapic", ioapic_setup);
-
 static int __init ioapic_pirq_setup(char *str)
 {
int i, max;
Index: linus/arch/x86_64/kernel/io_apic.c
===
--- linus.orig/arch/x86_64/kernel/io_apic.c
+++ linus/arch/x86_64/kernel/io_apic.c
@@ -397,14 +397,12 @@ static void clear_IO_APIC (void)
 int skip_ioapic_setup;
 int ioapic_force;
 
-/* dummy parsing: see setup.c */
-
-static int __init disable_ioapic_setup(char *str)
+static int __init parse_noapic(char *str)
 {
-   skip_ioapic_setup = 1;
+   disable_ioapic_setup();
return 0;
 }
-early_param("noapic", disable_ioapic_setup);
+early_param("noapic", parse_noapic);
 
 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
 static int __init disable_timer_pin_setup(char *arg)
Index: linus/include/asm-i386/io_apic.h
===
--- linus.orig/include/asm-i386/io_apic.h
+++ linus/include/asm-i386/io_apic.h
@@ -150,7 +150,6 @@ extern int (*ioapic_renumber_irq)(int io
 
 #else  /* !CONFIG_X86_IO_APIC */
 #define io_apic_assign_pci_irqs 0
-static inline void disable_ioapic_setup(void) { }
 #endif
 
 #endif
Index: linus/include/asm-x86_64/io_apic.h
===
--- linus.orig/include/asm-x86_64/io_apic.h
+++ linus/include/asm-x86_64/io_apic.h
@@ -109,6 +109,12 @@ extern int mpc_default_type;
 /* 1 if "noapic" boot option passed */
 extern int skip_ioapic_setup;
 
+static inline void disable_ioapic_setup(void)
+{
+   skip_ioapic_setup = 1;
+}
+
+
 /*
  * If we use the IO-APIC for IRQ routing, disable automatic
  * assignment of PCI IRQ's.
Index

Re: ACPI issue

2007-08-16 Thread Len Brown
On Wednesday 15 August 2007 18:12, Robert Gomulka wrote:
> Hello,
> I have just bought Compaq 572US laptop with AMD X64 dual core on board. I 
> installed Debian Etch on it. After first reboot I experienced many problems 
> with system freeze at many random moments. I had no idea what to do, as a 
> blind shot I disabled acpi in boot parameters (acpi=off). Those problems 
> disappeared and my system works for an hour fine (previously it was a 
> question of minutes).
> I have read article about ACPI myths and found this e-mail address there. 
> What 
> steps would you suggest next in order to improve my system situation with 
> ACPI?

Start by upgrading to a 2.6.22.stable kernel.

If you still have problems with ACPI mode, then open a bug report here:
http://bugzilla.kernel.org/enter_bug.cgi?product=ACPI

and attach the output from dmesg -s64000 from the default and acpi=off boots.
check that the driver to IRQ mapping in /proc/interrupts is the same
in both cases.

Look if there is a temperature reported under 
/proc/acpi/thermal_zone/*/temperature
and see if perhaps your system is getting hot when it fails.  Make a note
if you can hear the fans turn on/off, and at what temperature.

provide the output from acpidump in the bug report.

thanks,
-Len
-
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html