static int __init pm8941_charger_init(void)
{
	int err;

	printk("pm8941_charger_init +\n");

	err = power_supply_register(NULL, &usb_psy);
	if (err < 0) {
		printk("power_supply_register usb failed rc = %d\n", err);
	}

	err = power_supply_register(NULL, &main_psy);
	if (err < 0) {
		printk("power_supply_register ac failed rc = %d\n", err);
	}

	//Eason: AICL work around +++
	INIT_DELAYED_WORK(&AICLWorker,checkAICL); 
	//Eason: AICL work around ---

	create_pm8941_proc_file();

	
	return err;
}
Beispiel #2
0
static int pcf50633_mbc_probe(struct platform_device *pdev)
{
	struct power_supply_config psy_cfg = {};
	struct pcf50633_mbc *mbc;
	int i;
	u8 mbcs1;

	mbc = devm_kzalloc(&pdev->dev, sizeof(*mbc), GFP_KERNEL);
	if (!mbc)
		return -ENOMEM;

	platform_set_drvdata(pdev, mbc);
	mbc->pcf = dev_to_pcf50633(pdev->dev.parent);

	/* Set up IRQ handlers */
	for (i = 0; i < ARRAY_SIZE(mbc_irq_handlers); i++)
		pcf50633_register_irq(mbc->pcf, mbc_irq_handlers[i],
					pcf50633_mbc_irq_handler, mbc);

	psy_cfg.supplied_to		= mbc->pcf->pdata->batteries;
	psy_cfg.num_supplicants		= mbc->pcf->pdata->num_batteries;
	psy_cfg.drv_data		= mbc;

	/* Create power supplies */
	mbc->adapter = power_supply_register(&pdev->dev,
					     &pcf50633_mbc_adapter_desc,
					     &psy_cfg);
	if (IS_ERR(mbc->adapter)) {
		dev_err(mbc->pcf->dev, "failed to register adapter\n");
		return PTR_ERR(mbc->adapter);
	}

	mbc->usb = power_supply_register(&pdev->dev, &pcf50633_mbc_usb_desc,
					 &psy_cfg);
	if (IS_ERR(mbc->usb)) {
		dev_err(mbc->pcf->dev, "failed to register usb\n");
		power_supply_unregister(mbc->adapter);
		return PTR_ERR(mbc->usb);
	}

	mbc->ac = power_supply_register(&pdev->dev, &pcf50633_mbc_ac_desc,
					&psy_cfg);
	if (IS_ERR(mbc->ac)) {
		dev_err(mbc->pcf->dev, "failed to register ac\n");
		power_supply_unregister(mbc->adapter);
		power_supply_unregister(mbc->usb);
		return PTR_ERR(mbc->ac);
	}

	if (sysfs_create_group(&pdev->dev.kobj, &mbc_attr_group))
		dev_err(mbc->pcf->dev, "failed to create sysfs entries\n");

	mbcs1 = pcf50633_reg_read(mbc->pcf, PCF50633_REG_MBCS1);
	if (mbcs1 & PCF50633_MBCS1_USBPRES)
		pcf50633_mbc_irq_handler(PCF50633_IRQ_USBINS, mbc);
	if (mbcs1 & PCF50633_MBCS1_ADAPTPRES)
		pcf50633_mbc_irq_handler(PCF50633_IRQ_ADPINS, mbc);

	return 0;
}
Beispiel #3
0
static int __devinit battery_probe(struct platform_device *dev)
{
   int ret;

   printk("%s:\n",__FUNCTION__);

   ret = power_supply_register(&dev->dev, &psy_ac);
   if (ret)
      goto err_psy_reg_ac;
   ret = power_supply_register(&dev->dev, &psy_usb);
   if (ret)
      goto err_psy_reg_usb;
   ret = power_supply_register(&dev->dev, &psy_battery);
   if (ret)
      goto err_psy_reg_battery;

   printk("%s: return 0\n",__FUNCTION__);
   return 0;

err_psy_reg_battery:
   power_supply_unregister(&psy_usb);
err_psy_reg_usb:
   power_supply_unregister(&psy_ac);
err_psy_reg_ac:

   printk("%s: return %d\n",__FUNCTION__, ret);
   return ret;
}
static int lp8788_psy_register(struct platform_device *pdev,
				struct lp8788_charger *pchg)
{
	pchg->charger.name = LP8788_CHARGER_NAME;
	pchg->charger.type = POWER_SUPPLY_TYPE_MAINS;
	pchg->charger.properties = lp8788_charger_prop;
	pchg->charger.num_properties = ARRAY_SIZE(lp8788_charger_prop);
	pchg->charger.get_property = lp8788_charger_get_property;
	pchg->charger.supplied_to = battery_supplied_to;
	pchg->charger.num_supplicants = ARRAY_SIZE(battery_supplied_to);

	if (power_supply_register(&pdev->dev, &pchg->charger))
		return -EPERM;

	pchg->battery.name = LP8788_BATTERY_NAME;
	pchg->battery.type = POWER_SUPPLY_TYPE_BATTERY;
	pchg->battery.properties = lp8788_battery_prop;
	pchg->battery.num_properties = ARRAY_SIZE(lp8788_battery_prop);
	pchg->battery.get_property = lp8788_battery_get_property;

	if (power_supply_register(&pdev->dev, &pchg->battery)) {
		power_supply_unregister(&pchg->charger);
		return -EPERM;
	}

	return 0;
}
Beispiel #5
0
static int __init android_bat_init(void)
{
	int ret = 0;

	bat_pdev = platform_device_register_simple("battery", 0, NULL, 0);

	ret = power_supply_register(&bat_pdev->dev, &android_ac);
	if (ret)
	  goto ac_failed;

	android_bat.name = bat_pdev->name;

	ret = power_supply_register(&bat_pdev->dev, &android_bat);
	if (ret)
	  goto battery_failed;

	goto success;

	power_supply_unregister(&android_bat);
battery_failed:
	power_supply_unregister(&android_ac);
ac_failed:
	platform_device_unregister(bat_pdev);
success:
	return ret;
}
static int htc_battery_probe(struct platform_device *pdev)
{
	struct rpc_request_hdr req;	
	struct htc_get_batt_info_rep {
		struct rpc_reply_hdr hdr;
		struct battery_info_reply info;
	} rep;

	int rc;

	endpoint = msm_rpc_connect(APP_BATT_PROG, APP_BATT_VER, 0);
	if (IS_ERR(endpoint)) {
		printk(KERN_ERR "%s: init rpc failed! rc = %ld\n",
		       __FUNCTION__, PTR_ERR(endpoint));
		return PTR_ERR(endpoint);
	}

	/* must do this or we won't get cable status updates */
	rc = msm_rpc_call_reply(endpoint, HTC_PROCEDURE_GET_BATT_INFO,
				&req, sizeof(req),
				&rep, sizeof(rep),
				5 * HZ);
	if (rc < 0)
		printk(KERN_ERR "%s: get info failed\n", __FUNCTION__);

	power_supply_register(&pdev->dev, &ac_supply);
	power_supply_register(&pdev->dev, &usb_supply);

	return 0;
}
static int __init adbattery_init(void)
{
    int ret = 0;

    adbattery_pdev = platform_device_register_simple("battery", 0, NULL, 0);
    if (IS_ERR(adbattery_pdev))
        return PTR_ERR(adbattery_pdev);
    ret = power_supply_register(&adbattery_pdev->dev, &adbattery_bat);
    if (ret)
        goto bat_failed;
    ret = power_supply_register(&adbattery_pdev->dev, &adbattery_ac);
    if (ret)
        goto ac_failed;
    ret = power_supply_register(&adbattery_pdev->dev, &adbattery_usb);
    if (ret)
        goto usb_failed;
    printk(KERN_INFO "adbattery: android dummy battery driver loaded\n");
    goto success;

bat_failed:
    power_supply_unregister(&adbattery_bat);
ac_failed:
    power_supply_unregister(&adbattery_ac);
usb_failed:
    power_supply_unregister(&adbattery_usb);
    platform_device_unregister(adbattery_pdev);
success:
    return ret;
}
Beispiel #8
0
static int __init olpc_bat_init(void)
{
	int ret = 0;
	uint8_t status;

	if (!olpc_platform_info.ecver)
		return -ENXIO;

	/*
	 * We've seen a number of EC protocol changes; this driver requires
	 * the latest EC protocol, supported by 0x44 and above.
	 */
	if (olpc_platform_info.ecver < 0x44) {
		printk(KERN_NOTICE "OLPC EC version 0x%02x too old for "
			"battery driver.\n", olpc_platform_info.ecver);
		return -ENXIO;
	}

	ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
	if (ret)
		return ret;

	/* Ignore the status. It doesn't actually matter */

	bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0);
	if (IS_ERR(bat_pdev))
		return PTR_ERR(bat_pdev);

	ret = power_supply_register(&bat_pdev->dev, &olpc_ac);
	if (ret)
		goto ac_failed;

	olpc_bat.name = bat_pdev->name;

	ret = power_supply_register(&bat_pdev->dev, &olpc_bat);
	if (ret)
		goto battery_failed;

	ret = device_create_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
	if (ret)
		goto eeprom_failed;

	ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
	if (ret)
		goto error_failed;

	goto success;

error_failed:
	device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
eeprom_failed:
	power_supply_unregister(&olpc_bat);
battery_failed:
	power_supply_unregister(&olpc_ac);
ac_failed:
	platform_device_unregister(bat_pdev);
success:
	return ret;
}
static int zeus_power_probe(struct platform_device *pdev)
{

	power_supply_register(&pdev->dev, &ac_supply);
	power_supply_register(&pdev->dev, &usb_supply);

	return 0;
}
static __devinit int wm8350_power_probe(struct platform_device *pdev)
{
	struct wm8350 *wm8350 = platform_get_drvdata(pdev);
	struct wm8350_power *power = &wm8350->power;
	struct wm8350_charger_policy *policy = power->policy;
	struct power_supply *usb = &power->usb;
	struct power_supply *battery = &power->battery;
	struct power_supply *ac = &power->ac;
	int ret;

	ac->name = "wm8350-ac";
	ac->type = POWER_SUPPLY_TYPE_MAINS;
	ac->properties = wm8350_ac_props;
	ac->num_properties = ARRAY_SIZE(wm8350_ac_props);
	ac->get_property = wm8350_ac_get_prop;
	ret = power_supply_register(&pdev->dev, ac);
	if (ret)
		return ret;

	battery->name = "wm8350-battery";
	battery->properties = wm8350_bat_props;
	battery->num_properties = ARRAY_SIZE(wm8350_bat_props);
	battery->get_property = wm8350_bat_get_property;
	battery->use_for_apm = 1;
	ret = power_supply_register(&pdev->dev, battery);
	if (ret)
		goto battery_failed;

	usb->name = "wm8350-usb",
	usb->type = POWER_SUPPLY_TYPE_USB;
	usb->properties = wm8350_usb_props;
	usb->num_properties = ARRAY_SIZE(wm8350_usb_props);
	usb->get_property = wm8350_usb_get_prop;
	ret = power_supply_register(&pdev->dev, usb);
	if (ret)
		goto usb_failed;

	ret = device_create_file(&pdev->dev, &dev_attr_charger_state);
	if (ret < 0)
		dev_warn(wm8350->dev, "failed to add charge sysfs: %d\n", ret);
	ret = 0;

	wm8350_init_charger(wm8350);
	if (wm8350_charger_config(wm8350, policy) == 0) {
		wm8350_reg_unlock(wm8350);
		wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CHG_ENA);
		wm8350_reg_lock(wm8350);
	}

	return ret;

usb_failed:
	power_supply_unregister(battery);
battery_failed:
	power_supply_unregister(ac);

	return ret;
}
Beispiel #11
0
static int acpower_battery_probe(struct platform_device *pdev)
{
	int ret;
	struct acpower_battery_data *data;

	data = kzalloc(sizeof(*data), GFP_KERNEL);
	if (data == NULL) {
		ret = -ENOMEM;
		goto err_data_alloc_failed;
	}
	spin_lock_init(&data->lock);

	data->battery.properties = acpower_battery_props;
	data->battery.num_properties = ARRAY_SIZE(acpower_battery_props);
	data->battery.get_property = acpower_battery_get_property;
	data->battery.name = "battery";
	data->battery.type = POWER_SUPPLY_TYPE_BATTERY;

	data->ac.properties = acpower_ac_props;
	data->ac.num_properties = ARRAY_SIZE(acpower_ac_props);
	data->ac.get_property = acpower_ac_get_property;
	data->ac.name = "ac";
	data->ac.type = POWER_SUPPLY_TYPE_MAINS;

	data->usb.properties = acpower_usb_props;
	data->usb.num_properties = ARRAY_SIZE(acpower_usb_props);
	data->usb.get_property = acpower_usb_get_property;
	data->usb.name = "usb";
	data->usb.type = POWER_SUPPLY_TYPE_USB;

	ret = power_supply_register(&pdev->dev, &data->ac);
	if (ret)
		goto err_ac_failed;

	ret = power_supply_register(&pdev->dev, &data->battery);
	if (ret)
		goto err_battery_failed;

	ret = power_supply_register(&pdev->dev, &data->usb);
	if (ret)
		goto err_usb_failed;
	
	platform_set_drvdata(pdev, data);
	battery_data = data;

	return 0;


err_usb_failed:
	power_supply_unregister(&data->usb);
err_battery_failed:
	power_supply_unregister(&data->ac);
err_ac_failed:
	kfree(data);
err_data_alloc_failed:
	return ret;
}
static int bq3060_battery_probe(struct i2c_client *client,
                                const struct i2c_device_id *id)
{
    struct bq3060_device_info *di;
    int retval = 0;

    u8 buf[2];

    di = kzalloc(sizeof(*di), GFP_KERNEL);
    if (!di) {
        dev_err(&client->dev, "failed to allocate device info data\n");
        retval = -ENOMEM;
        goto batt_failed_2;
    }
    i2c_set_clientdata(client, di);
    di->dev = &client->dev;
    di->bat.name = "bq3060-battery";
    di->client = client;
    /* 4 seconds between monotor runs interval */
    di->interval = msecs_to_jiffies(1 * 1000);

    gpio_request(DC_CHECK_PIN,"dc_check");
    gpio_direction_input(DC_CHECK_PIN);
    bq3060_powersupply_init(di);
    buf[0] = 0x41;
    buf[1] = 0x00;
    bq3060_write(di->client,0x00,buf,2);
    buf[0] = 0x21;
    buf[1] = 0x00;
    bq3060_write(di->client,0x00,buf,2);
    retval = power_supply_register(&client->dev, &di->bat);
    if (retval) {
        dev_err(&client->dev, "failed to register battery\n");
        goto batt_failed_4;
    }
    //retval = power_supply_register(&client->dev, &di->usb);
    if (retval) {
        dev_err(&client->dev, "failed to register usb battery\n");
        goto batt_failed_4;
    }
    retval = power_supply_register(&client->dev, &di->ac);
    if (retval) {
        dev_err(&client->dev, "failed to register ac adapter\n");
        goto batt_failed_4;
    }
    INIT_DELAYED_WORK(&di->work, bq3060_battery_work);
    schedule_delayed_work(&di->work, di->interval);
    dev_info(&client->dev, "support ver. %s enabled\n", DRIVER_VERSION);

    return 0;

batt_failed_4:
    kfree(di);
batt_failed_2:
    return retval;
}
Beispiel #13
0
static int __init olpc_bat_init(void)
{
	int ret = 0;
	uint8_t status;

	if (!olpc_platform_info.ecver)
		return -ENXIO;

	
	if (olpc_platform_info.ecver < 0x44) {
		printk(KERN_NOTICE "OLPC EC version 0x%02x too old for "
			"battery driver.\n", olpc_platform_info.ecver);
		return -ENXIO;
	}

	ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
	if (ret)
		return ret;

	

	bat_pdev = platform_device_register_simple("olpc-battery", 0, NULL, 0);
	if (IS_ERR(bat_pdev))
		return PTR_ERR(bat_pdev);

	ret = power_supply_register(&bat_pdev->dev, &olpc_ac);
	if (ret)
		goto ac_failed;

	olpc_bat.name = bat_pdev->name;

	ret = power_supply_register(&bat_pdev->dev, &olpc_bat);
	if (ret)
		goto battery_failed;

	ret = device_create_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
	if (ret)
		goto eeprom_failed;

	ret = device_create_file(olpc_bat.dev, &olpc_bat_error);
	if (ret)
		goto error_failed;

	goto success;

error_failed:
	device_remove_bin_file(olpc_bat.dev, &olpc_bat_eeprom);
eeprom_failed:
	power_supply_unregister(&olpc_bat);
battery_failed:
	power_supply_unregister(&olpc_ac);
ac_failed:
	platform_device_unregister(bat_pdev);
success:
	return ret;
}
Beispiel #14
0
static int goldfish_battery_probe(struct platform_device *pdev)
{
	int ret;
	struct resource *r;
	struct goldfish_battery_data *data;
	struct power_supply_config psy_cfg = {};

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (data == NULL)
		return -ENOMEM;

	spin_lock_init(&data->lock);

	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	if (r == NULL) {
		dev_err(&pdev->dev, "platform_get_resource failed\n");
		return -ENODEV;
	}

	data->reg_base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
	if (data->reg_base == NULL) {
		dev_err(&pdev->dev, "unable to remap MMIO\n");
		return -ENOMEM;
	}

	data->irq = platform_get_irq(pdev, 0);
	if (data->irq < 0) {
		dev_err(&pdev->dev, "platform_get_irq failed\n");
		return -ENODEV;
	}

	ret = devm_request_irq(&pdev->dev, data->irq,
			       goldfish_battery_interrupt,
			       IRQF_SHARED, pdev->name, data);
	if (ret)
		return ret;

	psy_cfg.drv_data = data;

	data->ac = power_supply_register(&pdev->dev, &ac_desc, &psy_cfg);
	if (IS_ERR(data->ac))
		return PTR_ERR(data->ac);

	data->battery = power_supply_register(&pdev->dev, &battery_desc,
						&psy_cfg);
	if (IS_ERR(data->battery)) {
		power_supply_unregister(data->ac);
		return PTR_ERR(data->battery);
	}

	platform_set_drvdata(pdev, data);

	GOLDFISH_BATTERY_WRITE(data, BATTERY_INT_ENABLE, BATTERY_INT_MASK);
	return 0;
}
Beispiel #15
0
static int __init pmu_bat_init(void)
{
	int ret;
	int i;

	bat_pdev = platform_device_register_simple("pmu-battery",
						   0, NULL, 0);
	if (IS_ERR(bat_pdev)) {
		ret = PTR_ERR(bat_pdev);
		goto pdev_register_failed;
	}

	ret = power_supply_register(&bat_pdev->dev, &pmu_ac);
	if (ret)
		goto ac_register_failed;

	for (i = 0; i < pmu_battery_count; i++) {
		struct pmu_battery_dev *pbat = kzalloc(sizeof(*pbat),
						       GFP_KERNEL);
		if (!pbat)
			break;

		sprintf(pbat->name, "PMU_battery_%d", i);
		pbat->bat.name = pbat->name;
		pbat->bat.properties = pmu_bat_props;
		pbat->bat.num_properties = ARRAY_SIZE(pmu_bat_props);
		pbat->bat.get_property = pmu_bat_get_property;
		pbat->pbi = &pmu_batteries[i];

		ret = power_supply_register(&bat_pdev->dev, &pbat->bat);
		if (ret) {
			kfree(pbat);
			goto battery_register_failed;
		}
		pbats[i] = pbat;
	}

	goto success;

battery_register_failed:
	while (i--) {
		if (!pbats[i])
			continue;
		power_supply_unregister(&pbats[i]->bat);
		kfree(pbats[i]);
	}
	power_supply_unregister(&pmu_ac);
ac_register_failed:
	platform_device_unregister(bat_pdev);
pdev_register_failed:
success:
	return ret;
}
Beispiel #16
0
static int lp8727_register_psy(struct lp8727_chg *pchg)
{
	struct lp8727_psy *psy;

	psy = devm_kzalloc(pchg->dev, sizeof(*psy), GFP_KERNEL);
	if (!psy)
		return -ENOMEM;

	pchg->psy = psy;

	psy->ac.name = "ac";
	psy->ac.type = POWER_SUPPLY_TYPE_MAINS;
	psy->ac.properties = lp8727_charger_prop;
	psy->ac.num_properties = ARRAY_SIZE(lp8727_charger_prop);
	psy->ac.get_property = lp8727_charger_get_property;
	psy->ac.supplied_to = battery_supplied_to;
	psy->ac.num_supplicants = ARRAY_SIZE(battery_supplied_to);

	if (power_supply_register(pchg->dev, &psy->ac))
		goto err_psy_ac;

	psy->usb.name = "usb";
	psy->usb.type = POWER_SUPPLY_TYPE_USB;
	psy->usb.properties = lp8727_charger_prop;
	psy->usb.num_properties = ARRAY_SIZE(lp8727_charger_prop);
	psy->usb.get_property = lp8727_charger_get_property;
	psy->usb.supplied_to = battery_supplied_to;
	psy->usb.num_supplicants = ARRAY_SIZE(battery_supplied_to);

	if (power_supply_register(pchg->dev, &psy->usb))
		goto err_psy_usb;

	psy->batt.name = "main_batt";
	psy->batt.type = POWER_SUPPLY_TYPE_BATTERY;
	psy->batt.properties = lp8727_battery_prop;
	psy->batt.num_properties = ARRAY_SIZE(lp8727_battery_prop);
	psy->batt.get_property = lp8727_battery_get_property;
	psy->batt.external_power_changed = lp8727_charger_changed;

	if (power_supply_register(pchg->dev, &psy->batt))
		goto err_psy_batt;

	return 0;

err_psy_batt:
	power_supply_unregister(&psy->usb);
err_psy_usb:
	power_supply_unregister(&psy->ac);
err_psy_ac:
	return -EPERM;
}
static int ec_battery_probe(struct platform_device *pdev)
{
	struct ec_battery_info *chip;
	int ret;

	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
	if (!chip) {
		dev_err(&pdev->dev, "mem alloc failed\n");
		return -ENOMEM;
	}

	chip->pdev = pdev;
	platform_set_drvdata(pdev, chip);
	mutex_init(&chip->lock);

	chip->bat.name = "byt_battery";
	chip->bat.type = POWER_SUPPLY_TYPE_BATTERY;
	chip->bat.properties = ec_battery_props;
	chip->bat.num_properties = ARRAY_SIZE(ec_battery_props);
	chip->bat.get_property = ec_get_battery_property;
	ret = power_supply_register(&pdev->dev, &chip->bat);
	if (ret) {
		dev_err(&pdev->dev, "failed to register battery: %d\n", ret);
		goto probe_failed_1;
	}

	chip->chrg.name = "byt_charger";
	chip->chrg.type = POWER_SUPPLY_TYPE_MAINS;
	chip->chrg.properties = ec_charger_properties;
	chip->chrg.num_properties = ARRAY_SIZE(ec_charger_properties);
	chip->chrg.get_property = ec_get_charger_property;
	ret = power_supply_register(&pdev->dev, &chip->chrg);
	if (ret) {
		dev_err(&pdev->dev, "failed to register charger: %d\n", ret);
		goto probe_failed_2;
	}

	/* register for EC SCI events */
	chip->nb.notifier_call = &byt_ec_evt_batt_callback;
	byt_ec_evt_register_notify(&chip->nb);

	return 0;

probe_failed_2:
	power_supply_unregister(&chip->bat);
probe_failed_1:
	kfree(chip);
	return ret;
}
Beispiel #18
0
static int tegra_battery_probe(struct platform_device *pdev)
{
	int i, rc;
	NvBool result;

	batt_dev = kzalloc(sizeof(*batt_dev), GFP_KERNEL);
	if (!batt_dev) {
		return -ENOMEM;
	}
	memset(batt_dev, 0, sizeof(*batt_dev));

	/* Assume battery is present at start */
	batt_dev->present = 1;
	batt_dev->batt_id = 0;
	batt_dev->charging_source = NvCharger_Type_AC;
	batt_dev->charging_enabled = NvCharge_Control_Charging_Enable;

	result = NvOdmBatteryDeviceOpen(&(batt_dev->hOdmBattDev), NULL);
	if (!result) {
		pr_err("NvOdmBatteryDeviceOpen FAILED\n");
		goto err;
	}

	for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) {
		rc = power_supply_register(&pdev->dev, &tegra_supplies[i]);
		if (rc) {
			printk(KERN_ERR "Failed to register power supply\n");
			while (i--)
				power_supply_unregister(&tegra_supplies[i]);
			kfree(batt_dev);
			return rc;
		}
	}
	printk(KERN_INFO "%s: battery driver registered\n", pdev->name);

	batt_dev->batt_status_poll_period = NVBATTERY_POLLING_INTERVAL;
	setup_timer(&(batt_dev->battery_poll_timer), tegra_battery_poll_timer_func, 0);
	mod_timer(&(batt_dev->battery_poll_timer),
		jiffies + msecs_to_jiffies(batt_dev->batt_status_poll_period));

	rc = device_create_file(&pdev->dev, &tegra_battery_attr);
	if (rc) {
		for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) {
			power_supply_unregister(&tegra_supplies[i]);
		}

		del_timer_sync(&(batt_dev->battery_poll_timer));

		pr_err("tegra_battery_probe:device_create_file FAILED");
		return rc;
	}

	return 0;
err:
	if (batt_dev) {
		kfree(batt_dev);
		batt_dev = NULL;
	}
	return -1;
}
static int __init exynos5_manta_battery_late_init(void)
{
	int ret;
	struct usb_phy *usb_xceiv;

	ret = power_supply_register(NULL, &manta_battery_psy);
	if (ret)
		pr_err("%s: failed to register power_supply\n",
		       __func__);

	ret = request_threaded_irq(gpio_to_irq(GPIO_OTG_VBUS_SENSE),
				   NULL, ta_int_intr,
				   IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
				   IRQF_ONESHOT, "usb_vbus", NULL);
	if (ret) {
		pr_err("%s: usb_vbus irq register failed, ret=%d\n",
		       __func__, ret);
	} else {
		ret = enable_irq_wake(gpio_to_irq(GPIO_OTG_VBUS_SENSE));
		if (ret)
			pr_warn("%s: failed to enable irq_wake for usb_vbus\n",
				__func__);
	}

	ret = request_threaded_irq(gpio_to_irq(GPIO_VBUS_POGO_5V), NULL,
				   ta_int_intr,
				   IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
				   IRQF_ONESHOT, "pogo_vbus", NULL);
	if (ret) {
		pr_err("%s: pogo_vbus irq register failed, ret=%d\n",
		       __func__, ret);
	} else {
		ret = enable_irq_wake(gpio_to_irq(GPIO_VBUS_POGO_5V));
		if (ret)
			pr_warn("%s: failed to enable irq_wake for pogo_vbus\n",
				__func__);
	}

	ret = register_pm_notifier(&exynos5_manta_battery_pm_notifier_block);
	if (ret)
		pr_warn("%s: failed to register PM notifier; ret=%d\n",
			__func__, ret);

	usb_xceiv = usb_get_transceiver();

	if (!usb_xceiv) {
		pr_err("%s: No USB transceiver found\n", __func__);
	} else {
		ret = usb_register_notifier(usb_xceiv, &manta_bat_usb_nb);

		if (ret) {
			pr_err("%s: usb_register_notifier on transceiver %s failed\n",
			       __func__, dev_name(usb_xceiv->dev));
		}
	}

	/* get initial charger status */
	change_charger_status(false, false);
	return 0;
}
int sample_battery_init(void)
{
	int ret;

	memset(&sample_battery_psy, 0, sizeof(sample_battery_psy));
	sample_battery_psy.name = "sample_battery";
	sample_battery_psy.type = POWER_SUPPLY_TYPE_BATTERY;
	sample_battery_psy.properties = sample_battery_props;
	sample_battery_psy.num_properties = ARRAY_SIZE(sample_battery_props);
	sample_battery_psy.get_property = sample_battery_get_property;
	sample_battery_psy.external_power_changed =
	    sample_battery_ext_power_changed;

	ret = power_supply_register(NULL, &sample_battery_psy);
	if (ret) {
		printk("ERROR: power_supply_register failed (ret=%d)\n", ret);
		return ret;
	}
	printk("Sample battery registered\n");

	init_timer(&sample_battery_timer);

	sample_battery_timer.function = sample_battery_timer_func;
	sample_battery_timer.expires = jiffies + msecs_to_jiffies(interval);
	add_timer(&sample_battery_timer);

	return 0;
}
Beispiel #21
0
static int micro_batt_probe (struct platform_device *pdev)
{
	if (1) printk(KERN_ERR "micro battery probe : begin\n");

	power_supply_register(&pdev->dev, &h3600_battery);

	{ /*--- callback ---*/
		p_micro = platform_get_drvdata(pdev);
		spin_lock(p_micro->lock);
		p_micro->h_batt = micro_battery_receive;
		p_micro->h_temp = micro_temperature_receive;
		spin_unlock(p_micro->lock);
	}

	{ /*--- timer ---*/
		init_timer(&batt_timer);
		batt_timer.expires = jiffies + BATT_PERIOD;
		batt_timer.data = 0;
		batt_timer.function = h3600_battery_read_status;

		add_timer(&batt_timer);
	}

	if (1) printk(KERN_ERR "micro battery probe : end\n");
	return 0;
}
static int twl4030_madc_battery_probe(struct platform_device *pdev)
{
	struct twl4030_madc_battery *twl4030_madc_bat;
	struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;
	struct power_supply_config psy_cfg = {};
	int ret = 0;

	twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat),
				GFP_KERNEL);
	if (!twl4030_madc_bat)
		return -ENOMEM;

	twl4030_madc_bat->channel_temp = iio_channel_get(&pdev->dev, "temp");
	if (IS_ERR(twl4030_madc_bat->channel_temp)) {
		ret = PTR_ERR(twl4030_madc_bat->channel_temp);
		goto err;
	}

	twl4030_madc_bat->channel_ichg = iio_channel_get(&pdev->dev, "ichg");
	if (IS_ERR(twl4030_madc_bat->channel_ichg)) {
		ret = PTR_ERR(twl4030_madc_bat->channel_ichg);
		goto err_temp;
	}

	twl4030_madc_bat->channel_vbat = iio_channel_get(&pdev->dev, "vbat");
	if (IS_ERR(twl4030_madc_bat->channel_vbat)) {
		ret = PTR_ERR(twl4030_madc_bat->channel_vbat);
		goto err_ichg;
	}

	/* sort charging and discharging calibration data */
	sort(pdata->charging, pdata->charging_size,
		sizeof(struct twl4030_madc_bat_calibration),
		twl4030_cmp, NULL);
	sort(pdata->discharging, pdata->discharging_size,
		sizeof(struct twl4030_madc_bat_calibration),
		twl4030_cmp, NULL);

	twl4030_madc_bat->pdata = pdata;
	platform_set_drvdata(pdev, twl4030_madc_bat);
	psy_cfg.drv_data = twl4030_madc_bat;
	twl4030_madc_bat->psy = power_supply_register(&pdev->dev,
						      &twl4030_madc_bat_desc,
						      &psy_cfg);
	if (IS_ERR(twl4030_madc_bat->psy)) {
		ret = PTR_ERR(twl4030_madc_bat->psy);
		goto err_vbat;
	}

	return 0;

err_vbat:
	iio_channel_release(twl4030_madc_bat->channel_vbat);
err_ichg:
	iio_channel_release(twl4030_madc_bat->channel_ichg);
err_temp:
	iio_channel_release(twl4030_madc_bat->channel_temp);
err:
	return ret;
}
static int rt_battery_probe(struct platform_device *pdev)
{
    struct rt_battery_info *rbi;
    int ret;

    rbi = devm_kzalloc(&pdev->dev, sizeof(*rbi), GFP_KERNEL);
    if (!rbi)
        return -ENOMEM;
    rbi->dev = &pdev->dev;
    rbi->chg_status = POWER_SUPPLY_STATUS_DISCHARGING;
    rbi->batt_present = 1;
    platform_set_drvdata(pdev, rbi);

    rbi->psy.name = RT_BATT_NAME;
    rbi->psy.type = POWER_SUPPLY_TYPE_BATTERY;
    rbi->psy.set_property = rt_battery_set_property;
    rbi->psy.get_property = rt_battery_get_property;
    rbi->psy.properties = rt_battery_props;
    rbi->psy.num_properties = ARRAY_SIZE(rt_battery_props);
    ret = power_supply_register(&pdev->dev, &rbi->psy);
    if (ret < 0) {
        dev_err(&pdev->dev, "battery supply registered fail\n");
        goto out_dev;
    }
    dev_info(&pdev->dev, "driver successfully loaded\n");
    return 0;
out_dev:
    return ret;
}
static int __init test_power_init(void)
{
	int i;
	int ret;
	struct device_node *dev_node;

	dev_node = of_find_node_by_name(NULL, "test-power");

	if (IS_ERR_OR_NULL(dev_node)) {
		pr_info("not find %s dev node\n",  __func__);
		return 0;
	}
	if (!of_device_is_available(dev_node)) {
		pr_info("test power disabled\n");
		return 0;
	}

	for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
		ret = power_supply_register(NULL, &test_power_supplies[i]);
		if (ret) {
			pr_err("%s: failed to register %s\n", __func__,
				test_power_supplies[i].name);
			goto failed;
		}
	}

	module_initialized = true;
	return 0;
failed:
	while (--i >= 0)
		power_supply_unregister(&test_power_supplies[i]);
	return ret;
}
Beispiel #25
0
static int twl4030_madc_battery_probe(struct platform_device *pdev)
{
	struct twl4030_madc_battery *twl4030_madc_bat;
	struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data;

	twl4030_madc_bat = kzalloc(sizeof(*twl4030_madc_bat), GFP_KERNEL);
	if (!twl4030_madc_bat)
		return -ENOMEM;

	twl4030_madc_bat->psy.name = "twl4030_battery";
	twl4030_madc_bat->psy.type = POWER_SUPPLY_TYPE_BATTERY;
	twl4030_madc_bat->psy.properties = twl4030_madc_bat_props;
	twl4030_madc_bat->psy.num_properties =
					ARRAY_SIZE(twl4030_madc_bat_props);
	twl4030_madc_bat->psy.get_property = twl4030_madc_bat_get_property;
	twl4030_madc_bat->psy.external_power_changed =
					twl4030_madc_bat_ext_changed;

	/* sort charging and discharging calibration data */
	sort(pdata->charging, pdata->charging_size,
		sizeof(struct twl4030_madc_bat_calibration),
		twl4030_cmp, NULL);
	sort(pdata->discharging, pdata->discharging_size,
		sizeof(struct twl4030_madc_bat_calibration),
		twl4030_cmp, NULL);

	twl4030_madc_bat->pdata = pdata;
	platform_set_drvdata(pdev, twl4030_madc_bat);
	power_supply_register(&pdev->dev, &twl4030_madc_bat->psy);

	return 0;
}
static int bq27x00_powersupply_init(struct bq27x00_device_info *di)
{
	int ret;

	di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
	di->chip = BQ27425;
	if (di->chip == BQ27425) {
		di->bat.properties = bq27425_battery_props;
		di->bat.num_properties = ARRAY_SIZE(bq27425_battery_props);
	} else {
		di->bat.properties = bq27x00_battery_props;
		di->bat.num_properties = ARRAY_SIZE(bq27x00_battery_props);
	}
	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;
	}

	dev_info(di->dev, "support ver. %s enabled\n", DRIVER_VERSION);

	bq27x00_update(di);

	return 0;
}
Beispiel #27
0
static int rx51_battery_probe(struct platform_device *pdev)
{
	struct rx51_device_info *di;
	int ret;

	di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
	if (!di)
		return -ENOMEM;

	platform_set_drvdata(pdev, di);

	di->bat.name = dev_name(&pdev->dev);
	di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
	di->bat.properties = rx51_battery_props;
	di->bat.num_properties = ARRAY_SIZE(rx51_battery_props);
	di->bat.get_property = rx51_battery_get_property;

	ret = power_supply_register(di->dev, &di->bat);
	if (ret) {
		platform_set_drvdata(pdev, NULL);
		return ret;
	}

	return 0;
}
/*
 * imx6_usb_create_charger - create a USB charger
 * @charger: the charger to be initialized
 * @name: name for the power supply

 * Registers a power supply for the charger. The USB Controller
 * driver will call this after filling struct usb_charger.
 */
int imx6_usb_create_charger(struct usb_charger *charger,
		const char *name)
{
	struct power_supply	*psy = &charger->psy;

	if (!charger->dev)
		return -EINVAL;

	if (name)
		psy->name = name;
	else
		psy->name = "imx6_usb_charger";

	charger->bc = BATTERY_CHARGING_SPEC_1_2;
	mutex_init(&charger->lock);

	psy->type		= POWER_SUPPLY_TYPE_MAINS;
	psy->properties		= imx6_usb_charger_power_props;
	psy->num_properties	= ARRAY_SIZE(imx6_usb_charger_power_props);
	psy->get_property	= imx6_usb_charger_get_property;
	psy->supplied_to	= imx6_usb_charger_supplied_to;
	psy->num_supplicants	= sizeof(imx6_usb_charger_supplied_to)
		/ sizeof(char *);

	return power_supply_register(charger->dev, psy);
}
Beispiel #29
0
static int __init test_power_init(void)
{
	int i;
	int ret;

	BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_supplies));
	BUILD_BUG_ON(TEST_POWER_NUM != ARRAY_SIZE(test_power_configs));

	for (i = 0; i < ARRAY_SIZE(test_power_supplies); i++) {
		test_power_supplies[i] = power_supply_register(NULL,
						&test_power_desc[i],
						&test_power_configs[i]);
		if (IS_ERR(test_power_supplies[i])) {
			pr_err("%s: failed to register %s\n", __func__,
				test_power_desc[i].name);
			ret = PTR_ERR(test_power_supplies[i]);
			goto failed;
		}
	}

	module_initialized = true;
	return 0;
failed:
	while (--i >= 0)
		power_supply_unregister(test_power_supplies[i]);
	return ret;
}
static __devinit int max8998_power_probe(struct platform_device *pdev)
{
	struct max8998_dev *chip = dev_get_drvdata(pdev->dev.parent);
	struct max8998_platform_data *max8998_pdata;
	struct max8998_power_data *pdata = NULL;
	struct max8998_power_info *info;
	int ret, i;

	if (pdev->dev.parent->platform_data) {
		max8998_pdata = pdev->dev.parent->platform_data;
		pdata = max8998_pdata->power;
	}

	if (!pdata) {
		dev_err(&pdev->dev, "platform data isn't assigned to "
			"power supply\n");
		return -EINVAL;
	}

	info = kzalloc(sizeof(struct max8998_power_info), GFP_KERNEL);
	if (!info)
		return -ENOMEM;
	info->chip = chip;
	info->i2c = chip->i2c;

	info->batt_detect = pdata->batt_detect;
	info->topoff_threshold = pdata->topoff_threshold;
	info->fast_charge = pdata->fast_charge;
	info->set_charger = pdata->set_charger;
	info->ac_online = 0;
	info->usb_online = 0;
	info->bat_online = 0;
	wake_lock_init(&info->vbus_wake_lock, WAKE_LOCK_SUSPEND, "vbus_present");

	dev_set_drvdata(&pdev->dev, info);

	platform_set_drvdata(pdev, info);

	/* init power supplier framework */
	for (i = 0; i < ARRAY_SIZE(max8998_power_supplies); i++) {
		ret = power_supply_register(&pdev->dev,
				&max8998_power_supplies[i]);
		if (ret) {
			dev_err(&pdev->dev, "Failed to register"
					"power supply %d,%d\n", i, ret);
			goto __end__;
		}
		max8998_power_supplies[i].dev->parent = &pdev->dev;
	}

	max8998_check_charger(info);

	REQUEST_IRQ(MAX8998_IRQ_DCINF, "DCIN falling");
	REQUEST_IRQ(MAX8998_IRQ_DCINR, "DCIN rising");
	REQUEST_IRQ(MAX8998_IRQ_JIGF, "JIG falling");
	REQUEST_IRQ(MAX8998_IRQ_JIGR, "JIG rising");

__end__:
	return ret;
}