|
66 | 66 | #define UG3105_LOW_BAT_UV 3700000
|
67 | 67 | #define UG3105_FULL_BAT_HYST_UV 38000
|
68 | 68 |
|
| 69 | +#define AMBIENT_TEMP_CELCIUS 25 |
| 70 | + |
69 | 71 | struct ug3105_chip {
|
70 | 72 | struct i2c_client *client;
|
71 | 73 | struct power_supply *psy;
|
@@ -117,62 +119,6 @@ static int ug3105_get_status(struct ug3105_chip *chip)
|
117 | 119 | return POWER_SUPPLY_STATUS_NOT_CHARGING;
|
118 | 120 | }
|
119 | 121 |
|
120 |
| -static int ug3105_get_capacity(struct ug3105_chip *chip) |
121 |
| -{ |
122 |
| - /* |
123 |
| - * OCV voltages in uV for 0-110% in 5% increments, the 100-110% is |
124 |
| - * for LiPo HV (High-Voltage) bateries which can go up to 4.35V |
125 |
| - * instead of the usual 4.2V. |
126 |
| - */ |
127 |
| - static const int ocv_capacity_tbl[23] = { |
128 |
| - 3350000, |
129 |
| - 3610000, |
130 |
| - 3690000, |
131 |
| - 3710000, |
132 |
| - 3730000, |
133 |
| - 3750000, |
134 |
| - 3770000, |
135 |
| - 3786667, |
136 |
| - 3803333, |
137 |
| - 3820000, |
138 |
| - 3836667, |
139 |
| - 3853333, |
140 |
| - 3870000, |
141 |
| - 3907500, |
142 |
| - 3945000, |
143 |
| - 3982500, |
144 |
| - 4020000, |
145 |
| - 4075000, |
146 |
| - 4110000, |
147 |
| - 4150000, |
148 |
| - 4200000, |
149 |
| - 4250000, |
150 |
| - 4300000, |
151 |
| - }; |
152 |
| - int i, ocv_diff, ocv_step; |
153 |
| - |
154 |
| - if (chip->ocv_avg < ocv_capacity_tbl[0]) |
155 |
| - return 0; |
156 |
| - |
157 |
| - if (chip->status == POWER_SUPPLY_STATUS_FULL) |
158 |
| - return 100; |
159 |
| - |
160 |
| - for (i = 1; i < ARRAY_SIZE(ocv_capacity_tbl); i++) { |
161 |
| - if (chip->ocv_avg > ocv_capacity_tbl[i]) |
162 |
| - continue; |
163 |
| - |
164 |
| - ocv_diff = ocv_capacity_tbl[i] - chip->ocv_avg; |
165 |
| - ocv_step = ocv_capacity_tbl[i] - ocv_capacity_tbl[i - 1]; |
166 |
| - /* scale 0-110% down to 0-100% for LiPo HV */ |
167 |
| - if (chip->psy->battery_info->constant_charge_voltage_max_uv >= 4300000) |
168 |
| - return (i * 500 - ocv_diff * 500 / ocv_step) / 110; |
169 |
| - else |
170 |
| - return i * 5 - ocv_diff * 5 / ocv_step; |
171 |
| - } |
172 |
| - |
173 |
| - return 100; |
174 |
| -} |
175 |
| - |
176 | 122 | static void ug3105_work(struct work_struct *work)
|
177 | 123 | {
|
178 | 124 | struct ug3105_chip *chip = container_of(work, struct ug3105_chip,
|
@@ -231,7 +177,12 @@ static void ug3105_work(struct work_struct *work)
|
231 | 177 |
|
232 | 178 | chip->supplied = power_supply_am_i_supplied(psy);
|
233 | 179 | chip->status = ug3105_get_status(chip);
|
234 |
| - chip->capacity = ug3105_get_capacity(chip); |
| 180 | + if (chip->status == POWER_SUPPLY_STATUS_FULL) |
| 181 | + chip->capacity = 100; |
| 182 | + else |
| 183 | + chip->capacity = power_supply_batinfo_ocv2cap(chip->psy->battery_info, |
| 184 | + chip->ocv_avg, |
| 185 | + AMBIENT_TEMP_CELCIUS); |
235 | 186 |
|
236 | 187 | /*
|
237 | 188 | * Skip internal resistance calc on charger [un]plug and
|
@@ -403,7 +354,8 @@ static int ug3105_probe(struct i2c_client *client)
|
403 | 354 |
|
404 | 355 | if (!psy->battery_info ||
|
405 | 356 | psy->battery_info->factory_internal_resistance_uohm == -EINVAL ||
|
406 |
| - psy->battery_info->constant_charge_voltage_max_uv == -EINVAL) { |
| 357 | + psy->battery_info->constant_charge_voltage_max_uv == -EINVAL || |
| 358 | + !psy->battery_info->ocv_table[0]) { |
407 | 359 | dev_err(dev, "error required properties are missing\n");
|
408 | 360 | return -ENODEV;
|
409 | 361 | }
|
|
0 commit comments