Skip to contentSkip to conversation

smart battery

DISCUSSION James Klaas 2 participants 3 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

I hope this is the right place to post this.

I don't know if anyone has e-mailed you all about the SonicBlue ProGear tablet computer. This has an ali1535 smbus with an adm1024 thermal monitoring chip. It also has an unidentified smart battery and something hanging at 0x69 which is probably a timer (as noted in your documentation).

The code for reading the battery was released and the actual code for retrieving the data from the battery is GPL. The other code for displaying and setting the battery is of unknown license. After reading through the code for the battery and your instructions for creating a chip driver I don't think I have the capability to write the driver. I would be happy to post the GPL code if someone else is able to write the driver.

I'm also confused as to whether the smart battery is the chip (to create a driver for) or if there's a separate chip that drives the smart battery that needs to be identified. I can see the top half of the circuit board but I am not comfortable with taking the circuit board out of the case as it's all packed rather tightly and I don't want to risk making the unit non-operational. I also have no idea what I should be looking for.

Thank you for your help.

Signature · 5 lines
"Don't try to use a 'hard copy' manual. It will take you hours (or possibly
days) to find out that it won't tell you what you want to know. Using the
'Help' menu, it normally take less than 20 minutes to find out that it isn't
going to tell you what you want to know." -- Pete Moody
			James Klaas
#1 lore raw

we don't know much about 'smart batteries' but
the smart battery people were the original authors of the SMBus spec. There are some smart battery specs on the web too -
it may be that the interface is standard.

We'd love to see the GPL code. If anybody would like to write a driver then we will have the code to give them.

mds

Quoted 25 lines · James Klaas

I hope this is the right place to post this.

I don't know if anyone has e-mailed you all about the SonicBlue ProGear tablet computer. This has an ali1535 smbus with an adm1024 thermal monitoring chip. It also has an unidentified smart battery and something hanging at 0x69 which is probably a timer (as noted in your documentation).

The code for reading the battery was released and the actual code for retrieving the data from the battery is GPL. The other code for displaying and setting the battery is of unknown license. After reading through the code for the battery and your instructions for creating a chip driver I don't think I have the capability to write the driver. I would be happy to post the GPL code if someone else is able to write the driver.

I'm also confused as to whether the smart battery is the chip (to create a driver for) or if there's a separate chip that drives the smart battery that needs to be identified. I can see the top half of the circuit board but I am not comfortable with taking the circuit board out of the case as it's all packed rather tightly and I don't want to risk making the unit non-operational. I also have no idea what I should be looking for.

Thank you for your help.

#2 lore raw
In reply to James Klaas

I don't know if the code should be inlined or attached. I've attached it, and I would be happy to resend inlined instead. I would also be very happy to test any drivers as needed.

Quoted 5 lines · Mark D. Studebaker

we don't know much about 'smart batteries' but
the smart battery people were the original authors of the SMBus spec. There are some smart battery specs on the web too -
it may be that the interface is standard.

Quoted 11 lines

We'd love to see the GPL code. If anybody would like to write a driver then we will have the code to give them.

mds

Quoted 3 lines · James Klaas

I hope this is the right place to post this.

James Klaas
-------------- next part --------------
/* battery.c
Copyright (C) 2000 Linuxcare, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */

# include <sys/ioctl.h>
# include <fcntl.h>
# include <unistd.h>
#include <errno.h>

#include <linux/i2c-dev.h>

#include "battery.h"

#ifndef PATH_SMBUS

# define PATH_SMBUS "/dev/i2c-0"
#endif

#define COMM_TIMEOUT 16

int
battery_status(int fd)
{
int n = COMM_TIMEOUT;
int status;

  do
    status = i2c_smbus_read_word_data(fd, 0x16);
  while ((status = -1) && (n-- > 0));

return status;
}

int
battery_info(int fd, struct battery_info *info)
{
int n;
int val;

  n = COMM_TIMEOUT;
  /* ManufactureDate */
  do {
    val = i2c_smbus_read_word_data(fd, 0x1b); 
  } while ((val = -1) && (n-- > 0));

  info->manufacture_date.day=val & 0x1F;
  info->manufacture_date.month=(val >> 5) & 0x0F;
  info->manufacture_date.year=(val >> 9) & 0x7F;

  /* SerialNumber */
  n = COMM_TIMEOUT;
  do {
    val = i2c_smbus_read_word_data(fd, 0x1c);
  } while ((val = -1) && (n-- > 0));
  info->serial=val;

  /* ManufacturerName */
  n = COMM_TIMEOUT;
  do {
    val = i2c_smbus_read_block_data(fd, 0x20, info->manufacturer);
  } while ((val = -1) && (n-- > 0));
  info->manufacturer[val]=0;	

  /* DeviceName */
  n = COMM_TIMEOUT;
  do {
    val = i2c_smbus_read_block_data(fd, 0x21, info->device);
  } while ((val = -1) && (n-- > 0));
  info->device[val]=0;	

  /* DeviceChemistry */
  n = COMM_TIMEOUT;
  do {
    val = i2c_smbus_read_block_data(fd, 0x22, info->chemistry);
  } while ((val = -1) && (n-- > 0));
  info->chemistry[val]=0;	

return 0;
}

int
battery_mode(int fd)
{
int n = COMM_TIMEOUT;
int mode;

  do
    mode = i2c_smbus_read_word_data(fd, 0x3);
  while ((mode = -1) && (n-- > 0));

return mode;
}

int
battery_set_mode(int fd, int mode)
{
int n = COMM_TIMEOUT;
int result;

  do
    result = i2c_smbus_write_word_data(fd, 0x3, mode);
  while ((result = -1) && (n-- > 0));

return result;
}

int battery_get_current(int fd, int *value)
{
int n = COMM_TIMEOUT;
int current;

  do
    current = i2c_smbus_read_word_data(fd, 0xa);
  while ((current = -1) && (n-- > 0));

if (current = -1)

    return -1;

*value = (short) current;
return 0;
}

int battery_get_average_current(int fd, int *value) {
int n = COMM_TIMEOUT;
int current;

  do
    current = i2c_smbus_read_word_data(fd, 0xb);
  while ((current = -1) && (n-- > 0));

if (current = -1)

    return -1;

*value = (short) current;
return 0;
}

int battery_get_voltage(int fd, int *value)
{
int n = COMM_TIMEOUT;
int voltage;

  do
    voltage = i2c_smbus_read_word_data(fd, 0x9);
  while ((voltage = -1) && (n-- > 0));

if (voltage = -1)

    return -1;

*value = (short) voltage;
return 0;
}

int
battery_relative_state(int fd)
{
int n = COMM_TIMEOUT;
int state;

  do
    state = i2c_smbus_read_word_data(fd, 0xd);
  while ((state = -1) && (n-- > 0));

return state;
}

int
battery_average_time_to_empty(int fd)
{
int n = COMM_TIMEOUT;
int tte;

  do
    tte = i2c_smbus_read_word_data(fd, 0x12);
  while ((tte = -1) && (n-- > 0));

return tte;
}

int
battery_timeout(int fd,int timeout)
{
return ioctl(fd,I2C_TIMEOUT,timeout);
}

int
battery_close(int fd)
{
return close(fd);
}

int
battery_open(void)
{
int fd,err;

  fd = open(PATH_SMBUS, O_RDWR);
  
  if (fd<0) {
     return -1;
  }

err = ioctl(fd,I2C_SLAVE_FORCE,0x0b);

  if (err<0) {
	close(fd);
	return err;

}

return fd;
}

-------------- next part --------------
/* sbsutils
Copyright (C) 2000 Hypercore Software Design, Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */

#ifndef _BATTERY_H
#define _BATTERY_H 1

#define BATTERY_STRING_MAX 1024

struct battery_info {
	char manufacturer[BATTERY_STRING_MAX];
	char device[BATTERY_STRING_MAX];
	char chemistry[BATTERY_STRING_MAX];
	int  serial;
	struct {
		unsigned int day:5;	/* Day (1-31) */
		unsigned int month:4;	/* Month (1-12) */
		unsigned int year:7;	/* Year (1980 + 0-127) */
	} manufacture_date;
};

extern int battery_open(void); /* Returns battery handle */
extern int battery_close(int batt_handle);
extern int battery_info(int batt_handle, struct battery_info *info); extern int battery_timeout(int batt_handle, int timeout_msecs);

extern int battery_status(int batt_handle); extern int battery_mode(int batt_handle); extern int battery_set_mode(int batt_handle, int mode);

extern int battery_get_current(int batt_handle, int *value); extern int battery_get_average_current(int batt_handle, int *value); extern int battery_relative_state(int batt_handle); extern int battery_average_time_to_empty(int batt_handle); extern int battery_get_voltage(int batt_handl,int *millivolts);

#endif /* not _BATTERY_H */