Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MNT Reform Tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reform
MNT Reform Tools
Commits
4402f3ad
Commit
4402f3ad
authored
5 months ago
by
Michal Suchanek
Committed by
Johannes Schauer Marin Rodrigues
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
reform2_lpc: Detect battery reading glitches
Link:
https://community.mnt.re/t/random-shutdown/2561/4
parent
804a0500
No related branches found
No related tags found
2 merge requests
!90
reform-tools 1.55
,
!88
reform2_lpc: Detect battery reading glitches
Pipeline
#2825
passed
5 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lpc/reform2_lpc.c
+44
-0
44 additions, 0 deletions
lpc/reform2_lpc.c
with
44 additions
and
0 deletions
lpc/reform2_lpc.c
+
44
−
0
View file @
4402f3ad
#include
<linux/module.h>
#include
<linux/slab.h>
#include
<linux/math.h>
#include
<linux/mutex.h>
#include
<linux/spi/spi.h>
#include
<linux/delay.h>
...
...
@@ -24,10 +25,17 @@ static int getBatProperty(struct power_supply *psy,
enum
power_supply_property
psp
,
union
power_supply_propval
*
val
);
#define VOL_JUMP 1000000
#define CAP_JUMP 1000000
#define CUR_JUMP 1000000
typedef
struct
lpc_driver_data
{
struct
spi_device
*
spi
;
struct
power_supply
*
bat
;
struct
mutex
lock
;
int
last_batt_cap
;
int
last_batt_vol
;
int
last_batt_cur
;
}
lpc_driver_data
;
static
DEVICE_ATTR
(
status
,
0444
,
showStatus
,
NULL
);
...
...
@@ -347,6 +355,18 @@ static int getBatProperty(struct power_supply *psy,
ret
=
-
EINVAL
;
}
val
->
intval
=
(
buffer
[
0
]
|
buffer
[
1
]
<<
8
)
*
1000
;
if
(
data
->
last_batt_vol
&&
(
abs_diff
(
val
->
intval
,
data
->
last_batt_vol
)
>
VOL_JUMP
))
{
printk
(
KERN_INFO
"%s: Voltage jump from %i to %i
\n
"
,
__func__
,
data
->
last_batt_vol
,
val
->
intval
);
val
->
intval
=
data
->
last_batt_vol
+
(
val
->
intval
>
data
->
last_batt_vol
?
VOL_JUMP
:
-
VOL_JUMP
);
printk
(
KERN_INFO
"%s: Clamping to %i
\n
"
,
__func__
,
val
->
intval
);
}
data
->
last_batt_vol
=
val
->
intval
;
break
;
case
POWER_SUPPLY_PROP_CURRENT_NOW
:
...
...
@@ -362,6 +382,18 @@ static int getBatProperty(struct power_supply *psy,
amp
=
0
;
}
val
->
intval
=
amp
*
1000
;
if
(
data
->
last_batt_cur
&&
(
abs_diff
(
val
->
intval
,
data
->
last_batt_cur
)
>
CUR_JUMP
))
{
printk
(
KERN_INFO
"%s: Current jump from %i to %i
\n
"
,
__func__
,
data
->
last_batt_cur
,
val
->
intval
);
val
->
intval
=
data
->
last_batt_cur
+
(
val
->
intval
>
data
->
last_batt_cur
?
CUR_JUMP
:
-
CUR_JUMP
);
printk
(
KERN_INFO
"%s: Clamping to %i
\n
"
,
__func__
,
val
->
intval
);
}
data
->
last_batt_cur
=
val
->
intval
;
break
;
case
POWER_SUPPLY_PROP_CAPACITY
:
...
...
@@ -390,6 +422,18 @@ static int getBatProperty(struct power_supply *psy,
ret
=
-
EINVAL
;
}
val
->
intval
=
(
buffer
[
0
]
|
buffer
[
1
]
<<
8
)
*
1000
;
if
(
data
->
last_batt_cap
&&
(
abs_diff
(
val
->
intval
,
data
->
last_batt_cap
)
>
CAP_JUMP
))
{
printk
(
KERN_INFO
"%s: Charge jump from %i to %i
\n
"
,
__func__
,
data
->
last_batt_cap
,
val
->
intval
);
val
->
intval
=
data
->
last_batt_cap
+
(
val
->
intval
>
data
->
last_batt_cap
?
CAP_JUMP
:
-
CAP_JUMP
);
printk
(
KERN_INFO
"%s: Clamping to %i
\n
"
,
__func__
,
val
->
intval
);
}
data
->
last_batt_cap
=
val
->
intval
;
break
;
case
POWER_SUPPLY_PROP_CHARGE_EMPTY
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment