Lines Matching defs:bat
37 bool (*is_present)(struct collie_bat *bat);
56 static unsigned long collie_read_bat(struct collie_bat *bat)
60 if (bat->gpio_bat < 0 || bat->adc_bat < 0)
63 gpio_set_value(bat->gpio_bat, 1);
66 value = ucb1x00_adc_read(ucb, bat->adc_bat, UCB_SYNC);
68 gpio_set_value(bat->gpio_bat, 0);
70 value = value * 1000000 / bat->adc_bat_divider;
75 static unsigned long collie_read_temp(struct collie_bat *bat)
78 if (bat->gpio_temp < 0 || bat->adc_temp < 0)
82 gpio_set_value(bat->gpio_temp, 1);
85 value = ucb1x00_adc_read(ucb, bat->adc_temp, UCB_SYNC);
87 gpio_set_value(bat->gpio_temp, 0);
90 value = value * 10000 / bat->adc_temp_divider;
100 struct collie_bat *bat = container_of(psy, struct collie_bat, psy);
102 if (bat->is_present && !bat->is_present(bat)
109 val->intval = bat->status;
112 val->intval = bat->technology;
115 val->intval = collie_read_bat(bat);
118 if (bat->full_chrg == -1)
119 val->intval = bat->bat_max;
121 val->intval = bat->full_chrg;
124 val->intval = bat->bat_max;
127 val->intval = bat->bat_min;
130 val->intval = collie_read_temp(bat);
133 val->intval = bat->is_present ? bat->is_present(bat) : 1;
154 static void collie_bat_update(struct collie_bat *bat)
157 struct power_supply *psy = &bat->psy;
159 mutex_lock(&bat->work_lock);
161 old = bat->status;
163 if (bat->is_present && !bat->is_present(bat)) {
165 bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
166 bat->full_chrg = -1;
168 if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) {
169 gpio_set_value(bat->gpio_charge_on, 1);
173 if (gpio_get_value(bat->gpio_full)) {
175 bat->full_chrg == -1)
176 bat->full_chrg = collie_read_bat(bat);
178 gpio_set_value(bat->gpio_charge_on, 0);
179 bat->status = POWER_SUPPLY_STATUS_FULL;
181 gpio_set_value(bat->gpio_charge_on, 1);
182 bat->status = POWER_SUPPLY_STATUS_CHARGING;
185 gpio_set_value(bat->gpio_charge_on, 0);
186 bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
189 if (old != bat->status)
192 mutex_unlock(&bat->work_lock);