Lines Matching +full:pmod +full:- +full:enabled

5  *	       2004-2007 Matt Reimer
40 MODULE_PARM_DESC(pmod_enabled, "PMOD enable bit");
127 mutex_lock(&sl->master->bus_mutex); in w1_ds2760_io()
134 count = DS2760_DATA_SIZE - addr; in w1_ds2760_io()
138 w1_write_8(sl->master, W1_DS2760_READ_DATA); in w1_ds2760_io()
139 w1_write_8(sl->master, addr); in w1_ds2760_io()
140 count = w1_read_block(sl->master, buf, count); in w1_ds2760_io()
142 w1_write_8(sl->master, W1_DS2760_WRITE_DATA); in w1_ds2760_io()
143 w1_write_8(sl->master, addr); in w1_ds2760_io()
144 w1_write_block(sl->master, buf, count); in w1_ds2760_io()
150 mutex_unlock(&sl->master->bus_mutex); in w1_ds2760_io()
174 return -EINVAL; in w1_ds2760_eeprom_cmd()
176 mutex_lock(&sl->master->bus_mutex); in w1_ds2760_eeprom_cmd()
179 w1_write_8(sl->master, cmd); in w1_ds2760_eeprom_cmd()
180 w1_write_8(sl->master, addr); in w1_ds2760_eeprom_cmd()
183 mutex_unlock(&sl->master->bus_mutex); in w1_ds2760_eeprom_cmd()
252 return array[index] + (((array[index + 1] - array[index]) * dt) / 10); in battery_interpolate()
259 if (di->update_time && time_before(jiffies, di->update_time + in ds2760_battery_read_status()
265 if (di->update_time == 0) { in ds2760_battery_read_status()
270 count = DS2760_TEMP_LSB - start + 1; in ds2760_battery_read_status()
273 ret = w1_ds2760_read(di->dev, di->raw + start, start, count); in ds2760_battery_read_status()
275 dev_warn(di->dev, "call to w1_ds2760_read failed (0x%p)\n", in ds2760_battery_read_status()
276 di->dev); in ds2760_battery_read_status()
280 di->update_time = jiffies; in ds2760_battery_read_status()
284 di->voltage_raw = (di->raw[DS2760_VOLTAGE_MSB] << 3) | in ds2760_battery_read_status()
285 (di->raw[DS2760_VOLTAGE_LSB] >> 5); in ds2760_battery_read_status()
286 di->voltage_uV = di->voltage_raw * 4880; in ds2760_battery_read_status()
290 di->current_raw = in ds2760_battery_read_status()
291 (((signed char)di->raw[DS2760_CURRENT_MSB]) << 5) | in ds2760_battery_read_status()
292 (di->raw[DS2760_CURRENT_LSB] >> 3); in ds2760_battery_read_status()
293 di->current_uA = di->current_raw * 625; in ds2760_battery_read_status()
296 di->accum_current_raw = in ds2760_battery_read_status()
297 (((signed char)di->raw[DS2760_CURRENT_ACCUM_MSB]) << 8) | in ds2760_battery_read_status()
298 di->raw[DS2760_CURRENT_ACCUM_LSB]; in ds2760_battery_read_status()
299 di->accum_current_uAh = di->accum_current_raw * 250; in ds2760_battery_read_status()
304 di->temp_raw = (((signed char)di->raw[DS2760_TEMP_MSB]) << 3) | in ds2760_battery_read_status()
305 (di->raw[DS2760_TEMP_LSB] >> 5); in ds2760_battery_read_status()
306 di->temp_C = di->temp_raw + (di->temp_raw / 4); in ds2760_battery_read_status()
310 if (di->raw[DS2760_RATED_CAPACITY] < ARRAY_SIZE(rated_capacities)) in ds2760_battery_read_status()
311 di->rated_capacity = rated_capacities[ in ds2760_battery_read_status()
312 (unsigned int)di->raw[DS2760_RATED_CAPACITY]]; in ds2760_battery_read_status()
314 di->rated_capacity = di->raw[DS2760_RATED_CAPACITY] * 10; in ds2760_battery_read_status()
316 di->rated_capacity *= 1000; /* convert to µAh */ in ds2760_battery_read_status()
319 di->full_active_uAh = di->raw[DS2760_ACTIVE_FULL] << 8 | in ds2760_battery_read_status()
320 di->raw[DS2760_ACTIVE_FULL + 1]; in ds2760_battery_read_status()
325 if (di->full_active_uAh == 0) in ds2760_battery_read_status()
326 di->full_active_uAh = di->rated_capacity / 1000L; in ds2760_battery_read_status()
328 scale[0] = di->full_active_uAh; in ds2760_battery_read_status()
330 scale[i] = scale[i - 1] + di->raw[DS2760_ACTIVE_FULL + 1 + i]; in ds2760_battery_read_status()
332 di->full_active_uAh = battery_interpolate(scale, di->temp_C / 10); in ds2760_battery_read_status()
333 di->full_active_uAh *= 1000; /* convert to µAh */ in ds2760_battery_read_status()
336 scale[4] = di->raw[DS2760_ACTIVE_EMPTY + 4]; in ds2760_battery_read_status()
337 for (i = 3; i >= 0; i--) in ds2760_battery_read_status()
338 scale[i] = scale[i + 1] + di->raw[DS2760_ACTIVE_EMPTY + i]; in ds2760_battery_read_status()
340 di->empty_uAh = battery_interpolate(scale, di->temp_C / 10); in ds2760_battery_read_status()
341 di->empty_uAh *= 1000; /* convert to µAh */ in ds2760_battery_read_status()
343 if (di->full_active_uAh == di->empty_uAh) in ds2760_battery_read_status()
344 di->rem_capacity = 0; in ds2760_battery_read_status()
347 * ((ICA - Empty Value) / (Full Value - Empty Value)) x 100% */ in ds2760_battery_read_status()
348 di->rem_capacity = ((di->accum_current_uAh - di->empty_uAh) * 100L) / in ds2760_battery_read_status()
349 (di->full_active_uAh - di->empty_uAh); in ds2760_battery_read_status()
351 if (di->rem_capacity < 0) in ds2760_battery_read_status()
352 di->rem_capacity = 0; in ds2760_battery_read_status()
353 if (di->rem_capacity > 100) in ds2760_battery_read_status()
354 di->rem_capacity = 100; in ds2760_battery_read_status()
356 if (di->current_uA < -100L) in ds2760_battery_read_status()
357 di->life_sec = -((di->accum_current_uAh - di->empty_uAh) * 36L) in ds2760_battery_read_status()
358 / (di->current_uA / 100L); in ds2760_battery_read_status()
360 di->life_sec = 0; in ds2760_battery_read_status()
377 if (w1_ds2760_write(di->dev, acr, DS2760_CURRENT_ACCUM_MSB, 2) < 2) in ds2760_battery_set_current_accum()
378 dev_warn(di->dev, "ACR write failed\n"); in ds2760_battery_set_current_accum()
383 int old_charge_status = di->charge_status; in ds2760_battery_update_status()
387 if (di->charge_status == POWER_SUPPLY_STATUS_UNKNOWN) in ds2760_battery_update_status()
388 di->full_counter = 0; in ds2760_battery_update_status()
390 if (power_supply_am_i_supplied(di->bat)) { in ds2760_battery_update_status()
391 if (di->current_uA > 10000) { in ds2760_battery_update_status()
392 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; in ds2760_battery_update_status()
393 di->full_counter = 0; in ds2760_battery_update_status()
394 } else if (di->current_uA < -5000) { in ds2760_battery_update_status()
395 if (di->charge_status != POWER_SUPPLY_STATUS_NOT_CHARGING) in ds2760_battery_update_status()
396 dev_notice(di->dev, "not enough power to " in ds2760_battery_update_status()
398 di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; in ds2760_battery_update_status()
399 di->full_counter = 0; in ds2760_battery_update_status()
400 } else if (di->current_uA < 10000 && in ds2760_battery_update_status()
401 di->charge_status != POWER_SUPPLY_STATUS_FULL) { in ds2760_battery_update_status()
407 di->full_counter++; in ds2760_battery_update_status()
409 if (di->full_counter < 2) { in ds2760_battery_update_status()
410 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; in ds2760_battery_update_status()
412 di->charge_status = POWER_SUPPLY_STATUS_FULL; in ds2760_battery_update_status()
414 di->full_active_uAh); in ds2760_battery_update_status()
418 di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING; in ds2760_battery_update_status()
419 di->full_counter = 0; in ds2760_battery_update_status()
422 if (di->charge_status != old_charge_status) in ds2760_battery_update_status()
423 power_supply_changed(di->bat); in ds2760_battery_update_status()
429 if (status == di->raw[DS2760_STATUS_REG]) in ds2760_battery_write_status()
432 w1_ds2760_write(di->dev, &status, DS2760_STATUS_WRITE_REG, 1); in ds2760_battery_write_status()
433 w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_write_status()
434 w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_write_status()
440 if (rated_capacity == di->raw[DS2760_RATED_CAPACITY]) in ds2760_battery_write_rated_capacity()
443 w1_ds2760_write(di->dev, &rated_capacity, DS2760_RATED_CAPACITY, 1); in ds2760_battery_write_rated_capacity()
444 w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_write_rated_capacity()
445 w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_write_rated_capacity()
456 if (tmp[0] == di->raw[DS2760_ACTIVE_FULL] && in ds2760_battery_write_active_full()
457 tmp[1] == di->raw[DS2760_ACTIVE_FULL + 1]) in ds2760_battery_write_active_full()
460 w1_ds2760_write(di->dev, tmp, DS2760_ACTIVE_FULL, sizeof(tmp)); in ds2760_battery_write_active_full()
461 w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK0); in ds2760_battery_write_active_full()
462 w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK0); in ds2760_battery_write_active_full()
464 /* Write to the di->raw[] buffer directly - the DS2760_ACTIVE_FULL in ds2760_battery_write_active_full()
466 di->raw[DS2760_ACTIVE_FULL] = tmp[0]; in ds2760_battery_write_active_full()
467 di->raw[DS2760_ACTIVE_FULL + 1] = tmp[1]; in ds2760_battery_write_active_full()
476 dev_dbg(di->dev, "%s\n", __func__); in ds2760_battery_work()
479 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, interval); in ds2760_battery_work()
486 dev_dbg(di->dev, "%s\n", __func__); in ds2760_battery_external_power_changed()
488 mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ/10); in ds2760_battery_external_power_changed()
498 dev_dbg(di->dev, "%s\n", __func__); in ds2760_battery_set_charged_work()
505 * too inaccurate to rely on - spec say something ~15% failure. in ds2760_battery_set_charged_work()
510 if (!power_supply_am_i_supplied(di->bat)) in ds2760_battery_set_charged_work()
513 bias = (signed char) di->current_raw + in ds2760_battery_set_charged_work()
514 (signed char) di->raw[DS2760_CURRENT_OFFSET_BIAS]; in ds2760_battery_set_charged_work()
516 dev_dbg(di->dev, "%s: bias = %d\n", __func__, bias); in ds2760_battery_set_charged_work()
518 w1_ds2760_write(di->dev, &bias, DS2760_CURRENT_OFFSET_BIAS, 1); in ds2760_battery_set_charged_work()
519 w1_ds2760_store_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_set_charged_work()
520 w1_ds2760_recall_eeprom(di->dev, DS2760_EEPROM_BLOCK1); in ds2760_battery_set_charged_work()
522 /* Write to the di->raw[] buffer directly - the CURRENT_OFFSET_BIAS in ds2760_battery_set_charged_work()
524 di->raw[DS2760_CURRENT_OFFSET_BIAS] = bias; in ds2760_battery_set_charged_work()
533 mod_delayed_work(di->monitor_wqueue, &di->set_charged_work, HZ * 20); in ds2760_battery_set_charged()
544 val->intval = di->charge_status; in ds2760_battery_get_property()
554 val->intval = di->voltage_uV; in ds2760_battery_get_property()
557 val->intval = di->current_uA; in ds2760_battery_get_property()
560 val->intval = di->rated_capacity; in ds2760_battery_get_property()
563 val->intval = di->full_active_uAh; in ds2760_battery_get_property()
566 val->intval = di->empty_uAh; in ds2760_battery_get_property()
569 val->intval = di->accum_current_uAh; in ds2760_battery_get_property()
572 val->intval = di->temp_C; in ds2760_battery_get_property()
575 val->intval = di->life_sec; in ds2760_battery_get_property()
578 val->intval = di->rem_capacity; in ds2760_battery_get_property()
581 return -EINVAL; in ds2760_battery_get_property()
596 ds2760_battery_write_active_full(di, val->intval / 1000L); in ds2760_battery_set_property()
601 ds2760_battery_set_current_accum(di, val->intval); in ds2760_battery_set_property()
605 return -EPERM; in ds2760_battery_set_property()
649 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; in ds2760_pm_notifier()
655 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; in ds2760_pm_notifier()
656 power_supply_changed(di->bat); in ds2760_pm_notifier()
657 mod_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ); in ds2760_pm_notifier()
673 struct device *dev = &sl->dev; in w1_ds2760_add_slave()
680 retval = -ENOMEM; in w1_ds2760_add_slave()
684 snprintf(name, sizeof(name), "ds2760-battery.%d", dev->id); in w1_ds2760_add_slave()
686 di->dev = dev; in w1_ds2760_add_slave()
687 di->bat_desc.name = name; in w1_ds2760_add_slave()
688 di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY; in w1_ds2760_add_slave()
689 di->bat_desc.properties = ds2760_battery_props; in w1_ds2760_add_slave()
690 di->bat_desc.num_properties = ARRAY_SIZE(ds2760_battery_props); in w1_ds2760_add_slave()
691 di->bat_desc.get_property = ds2760_battery_get_property; in w1_ds2760_add_slave()
692 di->bat_desc.set_property = ds2760_battery_set_property; in w1_ds2760_add_slave()
693 di->bat_desc.property_is_writeable = in w1_ds2760_add_slave()
695 di->bat_desc.set_charged = ds2760_battery_set_charged; in w1_ds2760_add_slave()
696 di->bat_desc.external_power_changed = in w1_ds2760_add_slave()
701 if (dev->of_node) { in w1_ds2760_add_slave()
704 psy_cfg.of_node = dev->of_node; in w1_ds2760_add_slave()
706 if (!of_property_read_bool(dev->of_node, "maxim,pmod-enabled")) in w1_ds2760_add_slave()
709 if (!of_property_read_u32(dev->of_node, in w1_ds2760_add_slave()
710 "maxim,cache-time-ms", &tmp)) in w1_ds2760_add_slave()
713 if (!of_property_read_u32(dev->of_node, in w1_ds2760_add_slave()
714 "rated-capacity-microamp-hours", in w1_ds2760_add_slave()
719 di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN; in w1_ds2760_add_slave()
721 sl->family_data = di; in w1_ds2760_add_slave()
725 status = di->raw[DS2760_STATUS_REG]; in w1_ds2760_add_slave()
742 di->bat = power_supply_register(dev, &di->bat_desc, &psy_cfg); in w1_ds2760_add_slave()
743 if (IS_ERR(di->bat)) { in w1_ds2760_add_slave()
744 dev_err(di->dev, "failed to register battery\n"); in w1_ds2760_add_slave()
745 retval = PTR_ERR(di->bat); in w1_ds2760_add_slave()
749 INIT_DELAYED_WORK(&di->monitor_work, ds2760_battery_work); in w1_ds2760_add_slave()
750 INIT_DELAYED_WORK(&di->set_charged_work, in w1_ds2760_add_slave()
752 di->monitor_wqueue = alloc_ordered_workqueue(name, WQ_MEM_RECLAIM); in w1_ds2760_add_slave()
753 if (!di->monitor_wqueue) { in w1_ds2760_add_slave()
754 retval = -ESRCH; in w1_ds2760_add_slave()
757 queue_delayed_work(di->monitor_wqueue, &di->monitor_work, HZ * 1); in w1_ds2760_add_slave()
759 di->pm_notifier.notifier_call = ds2760_pm_notifier; in w1_ds2760_add_slave()
760 register_pm_notifier(&di->pm_notifier); in w1_ds2760_add_slave()
765 power_supply_unregister(di->bat); in w1_ds2760_add_slave()
774 struct ds2760_device_info *di = sl->family_data; in w1_ds2760_remove_slave()
776 unregister_pm_notifier(&di->pm_notifier); in w1_ds2760_remove_slave()
777 cancel_delayed_work_sync(&di->monitor_work); in w1_ds2760_remove_slave()
778 cancel_delayed_work_sync(&di->set_charged_work); in w1_ds2760_remove_slave()
779 destroy_workqueue(di->monitor_wqueue); in w1_ds2760_remove_slave()
780 power_supply_unregister(di->bat); in w1_ds2760_remove_slave()
806 MODULE_DESCRIPTION("1-wire Driver Dallas 2760 battery monitor chip");
808 MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS2760));