From 414774ec8c7e3549d7ad5c0f2c22c3ccadc417c1 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 23 Oct 2009 00:13:22 +0200 Subject: pcf50606-charger: serveral minor cleanups. --- drivers/power/pcf50606-charger.c | 55 ++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'drivers/power') diff --git a/drivers/power/pcf50606-charger.c b/drivers/power/pcf50606-charger.c index f90c5ed25b3..04b30a67e5a 100644 --- a/drivers/power/pcf50606-charger.c +++ b/drivers/power/pcf50606-charger.c @@ -33,7 +33,7 @@ struct pcf50606_mbc { struct power_supply charger; }; -void pcf50606_charge_fast(struct pcf50606 *pcf, int on) +int pcf50606_charge_fast(struct pcf50606 *pcf, int on) { struct pcf50606_mbc *mbc = platform_get_drvdata(pcf->mbc_pdev); @@ -43,7 +43,7 @@ void pcf50606_charge_fast(struct pcf50606 *pcf, int on) * ready. */ if (!mbc) - return; + return -ENODEV; if (on) { pcf50606_reg_set_bit_mask(pcf, PCF50606_REG_MBCC1, @@ -60,25 +60,27 @@ void pcf50606_charge_fast(struct pcf50606 *pcf, int on) PCF50606_MBCC1_CHGMOD_IDLE); mbc->charger_online = 0; } + + return 0; } EXPORT_SYMBOL_GPL(pcf50606_charge_fast); static ssize_t -show_chgmode(struct device *dev, struct device_attribute *attr, char *buf) +show_charge_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct pcf50606_mbc *mbc = dev_get_drvdata(dev); - u8 mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1); - u8 chgmod = (mbcc1 & PCF50606_MBCC1_CHGMOD_MASK); + uint8_t charge_mode = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1); + charge_mode &= PCF50606_MBCC1_CHGMOD_MASK; - return sprintf(buf, "%d\n", chgmod); + return sprintf(buf, "%d\n", charge_mode); } -static ssize_t set_chgmode(struct device *dev, struct device_attribute *attr, +static ssize_t set_charge_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct pcf50606_mbc *mbc = dev_get_drvdata(dev); - u_int8_t mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1); + uint8_t mbcc1 = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1); mbcc1 &= ~PCF50606_MBCC1_CHGMOD_MASK; @@ -101,18 +103,7 @@ static ssize_t set_chgmode(struct device *dev, struct device_attribute *attr, return count; } -static DEVICE_ATTR(chgmode, S_IRUGO, show_chgmode, set_chgmode); - - -static struct attribute *pcf50606_mbc_sysfs_entries[] = { - &dev_attr_chgmode.attr, - NULL, -}; - -static struct attribute_group mbc_attr_group = { - .name = NULL, /* put in device directory */ - .attrs = pcf50606_mbc_sysfs_entries, -}; +static DEVICE_ATTR(charge_mode, S_IRUGO, show_charge_mode, set_charge_mode); static void pcf50606_mbc_irq_handler(int irq, void *data) @@ -147,7 +138,7 @@ static enum power_supply_property power_props[] = { POWER_SUPPLY_PROP_ONLINE, }; -static const u8 mbc_irq_handlers[] = { +static const uint8_t mbc_irq_handlers[] = { PCF50606_IRQ_CHGINS, PCF50606_IRQ_CHGRM, PCF50606_IRQ_CHGFOK, @@ -160,21 +151,15 @@ static int __devinit pcf50606_mbc_probe(struct platform_device *pdev) { struct pcf50606_mbc *mbc; int ret; - int i; - u8 oocs; + size_t i; + uint8_t oocs; mbc = kzalloc(sizeof(*mbc), GFP_KERNEL); if (!mbc) return -ENOMEM; - platform_set_drvdata(pdev, mbc); mbc->pcf = dev_to_pcf50606(pdev->dev.parent); - /* Set up IRQ handlers */ - for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++) - pcf50606_register_irq(mbc->pcf, mbc_irq_handlers[i], - pcf50606_mbc_irq_handler, mbc); - mbc->charger.name = "charger"; mbc->charger.type = POWER_SUPPLY_TYPE_MAINS; mbc->charger.properties = power_props; @@ -190,7 +175,12 @@ static int __devinit pcf50606_mbc_probe(struct platform_device *pdev) return ret; } - ret = sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group); + /* Set up IRQ handlers */ + for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++) + pcf50606_register_irq(mbc->pcf, mbc_irq_handlers[i], + pcf50606_mbc_irq_handler, mbc); + + ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_charge_mode) if (ret) dev_err(mbc->pcf->dev, "failed to create sysfs entries\n"); @@ -198,13 +188,15 @@ static int __devinit pcf50606_mbc_probe(struct platform_device *pdev) if (oocs & PCF50606_OOCS_CHGOK) pcf50606_mbc_irq_handler(PCF50606_IRQ_CHGINS, mbc); + platform_set_drvdata(pdev, mbc); + return 0; } static int __devexit pcf50606_mbc_remove(struct platform_device *pdev) { struct pcf50606_mbc *mbc = platform_get_drvdata(pdev); - int i; + size_t i; /* Remove IRQ handlers */ for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++) @@ -212,6 +204,7 @@ static int __devexit pcf50606_mbc_remove(struct platform_device *pdev) power_supply_unregister(&mbc->charger); + platform_set_drvdata(pdev, NULL); kfree(mbc); return 0; -- cgit v1.2.3 From 110d73980b6cb58c067553a29c5697e4e41f98df Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 23 Oct 2009 00:24:54 +0200 Subject: pcf50606-charger: Add owner = THIS_MODULE, --- drivers/power/pcf50606-charger.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/power') diff --git a/drivers/power/pcf50606-charger.c b/drivers/power/pcf50606-charger.c index 04b30a67e5a..c803dce1acc 100644 --- a/drivers/power/pcf50606-charger.c +++ b/drivers/power/pcf50606-charger.c @@ -61,7 +61,7 @@ int pcf50606_charge_fast(struct pcf50606 *pcf, int on) mbc->charger_online = 0; } - return 0; + return 0; } EXPORT_SYMBOL_GPL(pcf50606_charge_fast); @@ -213,6 +213,7 @@ static int __devexit pcf50606_mbc_remove(struct platform_device *pdev) static struct platform_driver pcf50606_mbc_driver = { .driver = { .name = "pcf50606-mbc", + .owner = THIS_MODULE, }, .probe = pcf50606_mbc_probe, .remove = __devexit_p(pcf50606_mbc_remove), -- cgit v1.2.3 From bbfeb9cbfdf307a6d707243ffbb9a9849358ae9f Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 4 Nov 2009 10:31:25 +0100 Subject: pcf50606-charger: Set proper mode for charge_mode sysfsfile The owner of the file should be able to modify it's content. Also output the string representation of a charge mode if it exists. --- drivers/power/pcf50606-charger.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'drivers/power') diff --git a/drivers/power/pcf50606-charger.c b/drivers/power/pcf50606-charger.c index c803dce1acc..ee270714a74 100644 --- a/drivers/power/pcf50606-charger.c +++ b/drivers/power/pcf50606-charger.c @@ -65,15 +65,38 @@ int pcf50606_charge_fast(struct pcf50606 *pcf, int on) } EXPORT_SYMBOL_GPL(pcf50606_charge_fast); +static const char *charge_mode_descs[] = { + "qualification", + "pre", + "trickle", + "fast_cccv", + "idle", +}; + static ssize_t show_charge_mode(struct device *dev, struct device_attribute *attr, char *buf) { struct pcf50606_mbc *mbc = dev_get_drvdata(dev); + const char **desc = charge_mode_descs; uint8_t charge_mode = pcf50606_reg_read(mbc->pcf, PCF50606_REG_MBCC1); charge_mode &= PCF50606_MBCC1_CHGMOD_MASK; - - return sprintf(buf, "%d\n", charge_mode); + switch (charge_mode) { + case PCF50606_MBCC1_CHGMOD_IDLE: + ++desc; + case PCF50606_MBCC1_CHGMOD_FAST_CCCV: + ++desc; + case PCF50606_MBCC1_CHGMOD_TRICKLE: + ++desc; + case PCF50606_MBCC1_CHGMOD_PRE: + ++desc; + case PCF50606_MBCC1_CHGMOD_QUAL: + return sprintf(buf, "%s\n", *desc); + break; + default: + return sprintf(buf, "unkown: %d\n", charge_mode); + break; + } } static ssize_t set_charge_mode(struct device *dev, struct device_attribute *attr, @@ -103,7 +126,7 @@ static ssize_t set_charge_mode(struct device *dev, struct device_attribute *attr return count; } -static DEVICE_ATTR(charge_mode, S_IRUGO, show_charge_mode, set_charge_mode); +static DEVICE_ATTR(charge_mode, S_IRUGO | S_IWUSR, show_charge_mode, set_charge_mode); static void pcf50606_mbc_irq_handler(int irq, void *data) -- cgit v1.2.3