gbpsy 84 drivers/staging/greybus/power_supply.c void (*prop_changed)(struct gb_power_supply *gbpsy, gbpsy 88 drivers/staging/greybus/power_supply.c static void gb_power_supply_state_change(struct gb_power_supply *gbpsy, gbpsy 310 drivers/staging/greybus/power_supply.c static struct gb_connection *get_conn_from_psy(struct gb_power_supply *gbpsy) gbpsy 312 drivers/staging/greybus/power_supply.c return gbpsy->supplies->connection; gbpsy 315 drivers/staging/greybus/power_supply.c static struct gb_power_supply_prop *get_psy_prop(struct gb_power_supply *gbpsy, gbpsy 320 drivers/staging/greybus/power_supply.c for (i = 0; i < gbpsy->properties_count; i++) gbpsy 321 drivers/staging/greybus/power_supply.c if (gbpsy->props[i].prop == psp) gbpsy 322 drivers/staging/greybus/power_supply.c return &gbpsy->props[i]; gbpsy 326 drivers/staging/greybus/power_supply.c static int is_psy_prop_writeable(struct gb_power_supply *gbpsy, gbpsy 331 drivers/staging/greybus/power_supply.c prop = get_psy_prop(gbpsy, psp); gbpsy 342 drivers/staging/greybus/power_supply.c static void next_interval(struct gb_power_supply *gbpsy) gbpsy 344 drivers/staging/greybus/power_supply.c if (gbpsy->update_interval == update_interval_max) gbpsy 348 drivers/staging/greybus/power_supply.c gbpsy->update_interval *= 2; gbpsy 349 drivers/staging/greybus/power_supply.c if (gbpsy->update_interval > update_interval_max) gbpsy 350 drivers/staging/greybus/power_supply.c gbpsy->update_interval = update_interval_max; gbpsy 353 drivers/staging/greybus/power_supply.c static void __gb_power_supply_changed(struct gb_power_supply *gbpsy) gbpsy 355 drivers/staging/greybus/power_supply.c power_supply_changed(gbpsy->psy); gbpsy 358 drivers/staging/greybus/power_supply.c static void gb_power_supply_state_change(struct gb_power_supply *gbpsy, gbpsy 361 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 368 drivers/staging/greybus/power_supply.c mutex_lock(&gbpsy->supply_lock); gbpsy 371 drivers/staging/greybus/power_supply.c !gbpsy->pm_acquired) { gbpsy 377 drivers/staging/greybus/power_supply.c gbpsy->pm_acquired = true; gbpsy 379 drivers/staging/greybus/power_supply.c if (gbpsy->pm_acquired) { gbpsy 385 drivers/staging/greybus/power_supply.c gbpsy->pm_acquired = false; gbpsy 389 drivers/staging/greybus/power_supply.c mutex_unlock(&gbpsy->supply_lock); gbpsy 392 drivers/staging/greybus/power_supply.c static void check_changed(struct gb_power_supply *gbpsy, gbpsy 414 drivers/staging/greybus/power_supply.c psyc->prop_changed(gbpsy, prop); gbpsy 417 drivers/staging/greybus/power_supply.c gbpsy->changed = true; gbpsy 423 drivers/staging/greybus/power_supply.c static int total_props(struct gb_power_supply *gbpsy) gbpsy 426 drivers/staging/greybus/power_supply.c return (gbpsy->properties_count + gbpsy->properties_count_str); gbpsy 429 drivers/staging/greybus/power_supply.c static void prop_append(struct gb_power_supply *gbpsy, gbpsy 434 drivers/staging/greybus/power_supply.c gbpsy->properties_count_str++; gbpsy 435 drivers/staging/greybus/power_supply.c new_props_raw = krealloc(gbpsy->props_raw, total_props(gbpsy) * gbpsy 440 drivers/staging/greybus/power_supply.c gbpsy->props_raw = new_props_raw; gbpsy 441 drivers/staging/greybus/power_supply.c gbpsy->props_raw[total_props(gbpsy) - 1] = prop; gbpsy 464 drivers/staging/greybus/power_supply.c static void _gb_power_supply_append_props(struct gb_power_supply *gbpsy) gbpsy 466 drivers/staging/greybus/power_supply.c if (strlen(gbpsy->manufacturer)) gbpsy 467 drivers/staging/greybus/power_supply.c prop_append(gbpsy, POWER_SUPPLY_PROP_MANUFACTURER); gbpsy 468 drivers/staging/greybus/power_supply.c if (strlen(gbpsy->model_name)) gbpsy 469 drivers/staging/greybus/power_supply.c prop_append(gbpsy, POWER_SUPPLY_PROP_MODEL_NAME); gbpsy 470 drivers/staging/greybus/power_supply.c if (strlen(gbpsy->serial_number)) gbpsy 471 drivers/staging/greybus/power_supply.c prop_append(gbpsy, POWER_SUPPLY_PROP_SERIAL_NUMBER); gbpsy 474 drivers/staging/greybus/power_supply.c static int gb_power_supply_description_get(struct gb_power_supply *gbpsy) gbpsy 476 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 481 drivers/staging/greybus/power_supply.c req.psy_id = gbpsy->id; gbpsy 489 drivers/staging/greybus/power_supply.c gbpsy->manufacturer = kstrndup(resp.manufacturer, PROP_MAX, GFP_KERNEL); gbpsy 490 drivers/staging/greybus/power_supply.c if (!gbpsy->manufacturer) gbpsy 492 drivers/staging/greybus/power_supply.c gbpsy->model_name = kstrndup(resp.model, PROP_MAX, GFP_KERNEL); gbpsy 493 drivers/staging/greybus/power_supply.c if (!gbpsy->model_name) gbpsy 495 drivers/staging/greybus/power_supply.c gbpsy->serial_number = kstrndup(resp.serial_number, PROP_MAX, gbpsy 497 drivers/staging/greybus/power_supply.c if (!gbpsy->serial_number) gbpsy 500 drivers/staging/greybus/power_supply.c gbpsy->type = le16_to_cpu(resp.type); gbpsy 501 drivers/staging/greybus/power_supply.c gbpsy->properties_count = resp.properties_count; gbpsy 506 drivers/staging/greybus/power_supply.c static int gb_power_supply_prop_descriptors_get(struct gb_power_supply *gbpsy) gbpsy 508 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 512 drivers/staging/greybus/power_supply.c u8 props_count = gbpsy->properties_count; gbpsy 529 drivers/staging/greybus/power_supply.c req->psy_id = gbpsy->id; gbpsy 544 drivers/staging/greybus/power_supply.c gbpsy->properties_count--; gbpsy 548 drivers/staging/greybus/power_supply.c gbpsy->props = kcalloc(gbpsy->properties_count, sizeof(*gbpsy->props), gbpsy 550 drivers/staging/greybus/power_supply.c if (!gbpsy->props) { gbpsy 555 drivers/staging/greybus/power_supply.c gbpsy->props_raw = kcalloc(gbpsy->properties_count, gbpsy 556 drivers/staging/greybus/power_supply.c sizeof(*gbpsy->props_raw), GFP_KERNEL); gbpsy 557 drivers/staging/greybus/power_supply.c if (!gbpsy->props_raw) { gbpsy 569 drivers/staging/greybus/power_supply.c gbpsy->props[i - r].prop = psp; gbpsy 570 drivers/staging/greybus/power_supply.c gbpsy->props[i - r].gb_prop = resp->props[i].property; gbpsy 571 drivers/staging/greybus/power_supply.c gbpsy->props_raw[i - r] = psp; gbpsy 573 drivers/staging/greybus/power_supply.c gbpsy->props[i - r].is_writeable = true; gbpsy 580 drivers/staging/greybus/power_supply.c _gb_power_supply_append_props(gbpsy); gbpsy 589 drivers/staging/greybus/power_supply.c static int __gb_power_supply_property_update(struct gb_power_supply *gbpsy, gbpsy 592 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 599 drivers/staging/greybus/power_supply.c prop = get_psy_prop(gbpsy, psp); gbpsy 602 drivers/staging/greybus/power_supply.c req.psy_id = gbpsy->id; gbpsy 617 drivers/staging/greybus/power_supply.c check_changed(gbpsy, prop); gbpsy 622 drivers/staging/greybus/power_supply.c static int __gb_power_supply_property_get(struct gb_power_supply *gbpsy, gbpsy 628 drivers/staging/greybus/power_supply.c prop = get_psy_prop(gbpsy, psp); gbpsy 636 drivers/staging/greybus/power_supply.c static int __gb_power_supply_property_strval_get(struct gb_power_supply *gbpsy, gbpsy 642 drivers/staging/greybus/power_supply.c val->strval = gbpsy->model_name; gbpsy 645 drivers/staging/greybus/power_supply.c val->strval = gbpsy->manufacturer; gbpsy 648 drivers/staging/greybus/power_supply.c val->strval = gbpsy->serial_number; gbpsy 657 drivers/staging/greybus/power_supply.c static int _gb_power_supply_property_get(struct gb_power_supply *gbpsy, gbpsy 661 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 669 drivers/staging/greybus/power_supply.c ret = __gb_power_supply_property_get(gbpsy, psp, val); gbpsy 671 drivers/staging/greybus/power_supply.c ret = __gb_power_supply_property_strval_get(gbpsy, psp, val); gbpsy 679 drivers/staging/greybus/power_supply.c static int is_cache_valid(struct gb_power_supply *gbpsy) gbpsy 682 drivers/staging/greybus/power_supply.c if (gbpsy->cache_invalid) { gbpsy 683 drivers/staging/greybus/power_supply.c gbpsy->cache_invalid = 0; gbpsy 687 drivers/staging/greybus/power_supply.c if (gbpsy->last_update && gbpsy 688 drivers/staging/greybus/power_supply.c time_is_after_jiffies(gbpsy->last_update + gbpsy 695 drivers/staging/greybus/power_supply.c static int gb_power_supply_status_get(struct gb_power_supply *gbpsy) gbpsy 697 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 701 drivers/staging/greybus/power_supply.c if (is_cache_valid(gbpsy)) gbpsy 708 drivers/staging/greybus/power_supply.c for (i = 0; i < gbpsy->properties_count; i++) { gbpsy 709 drivers/staging/greybus/power_supply.c ret = __gb_power_supply_property_update(gbpsy, gbpsy 710 drivers/staging/greybus/power_supply.c gbpsy->props[i].prop); gbpsy 716 drivers/staging/greybus/power_supply.c gbpsy->last_update = jiffies; gbpsy 722 drivers/staging/greybus/power_supply.c static void gb_power_supply_status_update(struct gb_power_supply *gbpsy) gbpsy 725 drivers/staging/greybus/power_supply.c gb_power_supply_status_get(gbpsy); gbpsy 727 drivers/staging/greybus/power_supply.c if (!gbpsy->changed) gbpsy 730 drivers/staging/greybus/power_supply.c gbpsy->update_interval = update_interval_init; gbpsy 731 drivers/staging/greybus/power_supply.c __gb_power_supply_changed(gbpsy); gbpsy 732 drivers/staging/greybus/power_supply.c gbpsy->changed = false; gbpsy 737 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy = container_of(work, gbpsy 745 drivers/staging/greybus/power_supply.c if (!gbpsy->update_interval) gbpsy 748 drivers/staging/greybus/power_supply.c gb_power_supply_status_update(gbpsy); gbpsy 749 drivers/staging/greybus/power_supply.c next_interval(gbpsy); gbpsy 750 drivers/staging/greybus/power_supply.c schedule_delayed_work(&gbpsy->work, gbpsy->update_interval); gbpsy 757 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy = to_gb_power_supply(b); gbpsy 759 drivers/staging/greybus/power_supply.c gb_power_supply_status_get(gbpsy); gbpsy 761 drivers/staging/greybus/power_supply.c return _gb_power_supply_property_get(gbpsy, psp, val); gbpsy 764 drivers/staging/greybus/power_supply.c static int gb_power_supply_property_set(struct gb_power_supply *gbpsy, gbpsy 768 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 777 drivers/staging/greybus/power_supply.c prop = get_psy_prop(gbpsy, psp); gbpsy 783 drivers/staging/greybus/power_supply.c req.psy_id = gbpsy->id; gbpsy 804 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy = to_gb_power_supply(b); gbpsy 806 drivers/staging/greybus/power_supply.c return gb_power_supply_property_set(gbpsy, psp, val->intval); gbpsy 812 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy = to_gb_power_supply(b); gbpsy 814 drivers/staging/greybus/power_supply.c return is_psy_prop_writeable(gbpsy, psp); gbpsy 817 drivers/staging/greybus/power_supply.c static int gb_power_supply_register(struct gb_power_supply *gbpsy) gbpsy 819 drivers/staging/greybus/power_supply.c struct gb_connection *connection = get_conn_from_psy(gbpsy); gbpsy 822 drivers/staging/greybus/power_supply.c cfg.drv_data = gbpsy; gbpsy 824 drivers/staging/greybus/power_supply.c gbpsy->desc.name = gbpsy->name; gbpsy 825 drivers/staging/greybus/power_supply.c gbpsy->desc.type = gbpsy->type; gbpsy 826 drivers/staging/greybus/power_supply.c gbpsy->desc.properties = gbpsy->props_raw; gbpsy 827 drivers/staging/greybus/power_supply.c gbpsy->desc.num_properties = total_props(gbpsy); gbpsy 828 drivers/staging/greybus/power_supply.c gbpsy->desc.get_property = get_property; gbpsy 829 drivers/staging/greybus/power_supply.c gbpsy->desc.set_property = set_property; gbpsy 830 drivers/staging/greybus/power_supply.c gbpsy->desc.property_is_writeable = property_is_writeable; gbpsy 832 drivers/staging/greybus/power_supply.c gbpsy->psy = power_supply_register(&connection->bundle->dev, gbpsy 833 drivers/staging/greybus/power_supply.c &gbpsy->desc, &cfg); gbpsy 834 drivers/staging/greybus/power_supply.c return PTR_ERR_OR_ZERO(gbpsy->psy); gbpsy 837 drivers/staging/greybus/power_supply.c static void _gb_power_supply_free(struct gb_power_supply *gbpsy) gbpsy 839 drivers/staging/greybus/power_supply.c kfree(gbpsy->serial_number); gbpsy 840 drivers/staging/greybus/power_supply.c kfree(gbpsy->model_name); gbpsy 841 drivers/staging/greybus/power_supply.c kfree(gbpsy->manufacturer); gbpsy 842 drivers/staging/greybus/power_supply.c kfree(gbpsy->props_raw); gbpsy 843 drivers/staging/greybus/power_supply.c kfree(gbpsy->props); gbpsy 846 drivers/staging/greybus/power_supply.c static void _gb_power_supply_release(struct gb_power_supply *gbpsy) gbpsy 848 drivers/staging/greybus/power_supply.c gbpsy->update_interval = 0; gbpsy 850 drivers/staging/greybus/power_supply.c cancel_delayed_work_sync(&gbpsy->work); gbpsy 852 drivers/staging/greybus/power_supply.c if (gbpsy->registered) gbpsy 853 drivers/staging/greybus/power_supply.c power_supply_unregister(gbpsy->psy); gbpsy 855 drivers/staging/greybus/power_supply.c _gb_power_supply_free(gbpsy); gbpsy 894 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy = &supplies->supply[id]; gbpsy 897 drivers/staging/greybus/power_supply.c gbpsy->supplies = supplies; gbpsy 898 drivers/staging/greybus/power_supply.c gbpsy->id = id; gbpsy 900 drivers/staging/greybus/power_supply.c ret = gb_power_supply_description_get(gbpsy); gbpsy 904 drivers/staging/greybus/power_supply.c return gb_power_supply_prop_descriptors_get(gbpsy); gbpsy 907 drivers/staging/greybus/power_supply.c static int gb_power_supply_enable(struct gb_power_supply *gbpsy) gbpsy 912 drivers/staging/greybus/power_supply.c ret = __gb_power_supply_set_name(gbpsy->model_name, gbpsy->name, gbpsy 913 drivers/staging/greybus/power_supply.c sizeof(gbpsy->name)); gbpsy 917 drivers/staging/greybus/power_supply.c mutex_init(&gbpsy->supply_lock); gbpsy 919 drivers/staging/greybus/power_supply.c ret = gb_power_supply_register(gbpsy); gbpsy 923 drivers/staging/greybus/power_supply.c gbpsy->update_interval = update_interval_init; gbpsy 924 drivers/staging/greybus/power_supply.c INIT_DELAYED_WORK(&gbpsy->work, gb_power_supply_work); gbpsy 925 drivers/staging/greybus/power_supply.c schedule_delayed_work(&gbpsy->work, 0); gbpsy 928 drivers/staging/greybus/power_supply.c gbpsy->registered = true; gbpsy 992 drivers/staging/greybus/power_supply.c struct gb_power_supply *gbpsy; gbpsy 1031 drivers/staging/greybus/power_supply.c gbpsy = &supplies->supply[psy_id]; gbpsy 1032 drivers/staging/greybus/power_supply.c if (!gbpsy->update_interval) { gbpsy 1043 drivers/staging/greybus/power_supply.c gbpsy->cache_invalid = 1; gbpsy 1044 drivers/staging/greybus/power_supply.c gb_power_supply_status_update(gbpsy);