lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130120020002.GA13085@lizard.sbx05663.mountca.wayport.net>
Date:	Sat, 19 Jan 2013 18:00:03 -0800
From:	Anton Vorontsov <anton@...msg.org>
To:	Pali Rohár <pali.rohar@...il.com>
Cc:	David Woodhouse <dwmw2@...radead.org>,
	linux-kernel@...r.kernel.org,
	Mark Brown <broonie@...nsource.wolfsonmicro.com>
Subject: Re: [PATCH] power: bq27x00_battery: Export all battery registers via
 sysfs

On Sat, Jan 19, 2013 at 03:01:43PM +0100, Pali Rohár wrote:
> bq27xxx batteries have a lot of properties, more than power_supply interface.
> Some of them can be usefull for userspace applications (like CI bit) but
> does not make sense to add bq specified property to power_supply interface.
> When bq27x00_battery is not loaded userspace application (like i2cget) can
> use /dev/i2c-* interface for raw access. But when kernel module is attached
> to i2c device, userspace applications cannot access it via /dev/i2c-*.
> Also it is not usefull for userspace to unload module before reading values
> form /dev/i2c-* and then load it again.

If it is useful for userspace applications, you probably do want to
make a proper interface for it? What is "CI" bit?

We were discussing it before, right?

  http://permalink.gmane.org/gmane.linux.kernel/1220570

I said:

  In any case, I just think that being able to access already bound
  I2C devices from userspace might be a good thing for debugging,
  but having such an interface per-driver is impractical.

So, I still think that making a generic interface is the way to go.

And Mark Brown said:

  if this is a device that has registers that fit within regmap then the
  regmap API provides a debugfs interface for dumping the register map as
  standard.
  ...
  The regmap debug file is a file of lines in the format 'regnum: value'
  where both fields have a fixed width so should be easily parsable.

So, it seems that we have that interface already.

Here is the whole discussion:

  http://comments.gmane.org/gmane.linux.kernel/1209421

Thanks,

> This patch exporting all battery registers to sysfs entry "registers" in
> battery power_supply directory. Format is "register=value" on separate line.
> Because length of registers are different for each bq battery more for loops
> are needed.
> 
> Signed-off-by: Pali Rohár <pali.rohar@...il.com>
> ---
>  drivers/power/bq27x00_battery.c |   98 +++++++++++++++++++++++++++++++++++++--
>  1 file changed, 95 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
> index 7087d0d..af0f68f 100644
> --- a/drivers/power/bq27x00_battery.c
> +++ b/drivers/power/bq27x00_battery.c
> @@ -690,6 +690,90 @@ static void bq27x00_external_power_changed(struct power_supply *psy)
>  	schedule_delayed_work(&di->work, 0);
>  }
>  
> +/* code for register device access via sysfs */
> +
> +static ssize_t bq27x00_battery_sysfs_print_reg(struct bq27x00_device_info *di,
> +					u8 reg, bool single, char *buf)
> +{
> +	int ret = bq27x00_read(di, reg, single);
> +	if (ret < 0)
> +		return sprintf(buf, "%#.2x=error %d\n", reg, ret);
> +	else
> +		return sprintf(buf, "%#.2x=%#.2x\n", reg, ret);
> +}
> +
> +static ssize_t bq27x00_battery_sysfs_show_registers(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct power_supply *psy = dev_get_drvdata(dev);
> +	struct bq27x00_device_info *di = container_of(psy,
> +						struct bq27x00_device_info,
> +						bat);
> +	u8 reg;
> +	ssize_t ret = 0;
> +
> +	switch (di->chip) {
> +
> +	case BQ27000:
> +		for (reg=0x00; reg<=0x01; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		for (reg=0x02; reg<=0x08; reg+=2)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, false, buf+ret);
> +		for (reg=0x0A; reg<=0x0B; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		for (reg=0x0C; reg<=0x2A; reg+=2)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, false, buf+ret);
> +		for (reg=0x2C; reg<=0x7F; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		break;
> +
> +	case BQ27500:
> +		for (reg=0x00; reg<=0x2C; reg+=2)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, false, buf+ret);
> +		for (reg=0x2E; reg<=0x3B; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		for (reg=0x3C; reg<=0x3C; reg+=2)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, false, buf+ret);
> +		for (reg=0x3E; reg<=0x7F; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		break;
> +
> +	case BQ27425:
> +		for (reg=0x00; reg<=0x3C; reg+=2)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, false, buf+ret);
> +		for (reg=0x3E; reg<=0x7F; reg+=1)
> +			ret += bq27x00_battery_sysfs_print_reg(di, reg, true, buf+ret);
> +		break;
> +
> +	}
> +
> +	return ret;
> +}
> +
> +static DEVICE_ATTR(registers, S_IRUGO,
> +		bq27x00_battery_sysfs_show_registers, NULL);
> +
> +static struct attribute *bq27x00_battery_sysfs_attributes[] = {
> +	&dev_attr_registers.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group bq27x00_battery_sysfs_attr_group = {
> +	.attrs = bq27x00_battery_sysfs_attributes,
> +};
> +
> +static int bq27x00_battery_sysfs_init(struct bq27x00_device_info *di)
> +{
> +	return sysfs_create_group(&di->bat.dev->kobj,
> +			&bq27x00_battery_sysfs_attr_group);
> +}
> +
> +static void bq27x00_battery_sysfs_exit(struct bq27x00_device_info *di)
> +{
> +	sysfs_remove_group(&di->bat.dev->kobj,
> +			&bq27x00_battery_sysfs_attr_group);
> +}
> +
>  static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
>  {
>  	int ret;
> @@ -705,15 +789,22 @@ static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
>  	di->bat.get_property = bq27x00_battery_get_property;
>  	di->bat.external_power_changed = bq27x00_external_power_changed;
>  
> -	INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
> -	mutex_init(&di->lock);
> -
>  	ret = power_supply_register(di->dev, &di->bat);
>  	if (ret) {
>  		dev_err(di->dev, "failed to register battery: %d\n", ret);
>  		return ret;
>  	}
>  
> +	ret = bq27x00_battery_sysfs_init(di);
> +	if (ret) {
> +		dev_err(di->dev, "failed to register battery: %d\n", ret);
> +		power_supply_unregister(&di->bat);
> +		return ret;
> +	}
> +
> +	INIT_DELAYED_WORK(&di->work, bq27x00_battery_poll);
> +	mutex_init(&di->lock);
> +
>  	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);
>  
>  	bq27x00_update(di);
> @@ -733,6 +824,7 @@ static void bq27x00_powersupply_unregister(struct bq27x00_device_info *di)
>  
>  	cancel_delayed_work_sync(&di->work);
>  
> +	bq27x00_battery_sysfs_exit(di);
>  	power_supply_unregister(&di->bat);
>  
>  	mutex_destroy(&di->lock);
> -- 
> 1.7.10.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ