tici: speedup power save setting (#29100)

* speedup

* update type

---------

Co-authored-by: Comma Device <device@comma.ai>
old-commit-hash: d92c9aef23fc789d50bfd03ae09a3abbf23a8429
This commit is contained in:
Adeeb Shihadeh
2023-07-22 17:15:58 -07:00
committed by GitHub
parent 2295bc3848
commit 3dfd770fb0
5 changed files with 76 additions and 26 deletions
+15 -7
View File
@@ -1,4 +1,4 @@
import glob
from functools import cache
from typing import Optional, List
def gpio_init(pin: int, output: bool) -> None:
@@ -25,12 +25,20 @@ def gpio_read(pin: int) -> Optional[bool]:
return val
def get_irq_for_action(action: str) -> List[int]:
ret = []
for fn in glob.glob('/sys/kernel/irq/*/actions'):
with open(fn) as f:
@cache
def get_irq_action(irq: int) -> List[str]:
try:
with open(f"/sys/kernel/irq/{irq}/actions") as f:
actions = f.read().strip().split(',')
if action in actions:
irq = int(fn.split('/')[-2])
return actions
except FileNotFoundError:
return []
def get_irqs_for_action(action: str) -> List[str]:
ret = []
with open("/proc/interrupts") as f:
for l in f.readlines():
irq = l.split(':')[0].strip()
if irq.isdigit() and action in get_irq_action(irq):
ret.append(irq)
return ret