Created
November 1, 2022 13:55
-
-
Save smx-smx/fa2db35f730e03b90f7570bd03c4a674 to your computer and use it in GitHub Desktop.
GPIO generator for Kabylake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class IntelToolGpio { | |
| private SplFileObject $logFile; | |
| public function __construct(string $logPath){ | |
| $this->logFile = new SplFileObject($logPath, 'r'); | |
| } | |
| private function gpioRows(){ | |
| $HEX = "0x[0-9a-fA-F]+"; | |
| $fh = $this->logFile; | |
| while(!$fh->eof()){ | |
| $line = $fh->fgets(); | |
| if($line === false) continue; | |
| if(!preg_match("/({$HEX}): ({$HEX}) (GP[PD].*?)\s+(.*?)(?:\s|$)/", $line, $m)){ | |
| continue; | |
| } | |
| $m[1] = hexdec($m[1]); | |
| $m[2] = hexdec($m[2]); | |
| yield [$m[1], $m[2], $m[3], $m[4]]; | |
| } | |
| } | |
| private static $RESET_TBL = ['PWROK', 'DEEP', 'PLTRST', 'RSMRST']; | |
| private static $PULL_TBL = ['NONE', 'DN_5K', 'DN_20K', 'UP_1K', 'UP_5K', 'UP_2K', 'UP_20K', 'UP_667', 'NATIVE']; | |
| private static $MODE_TBL = ['GPIO','NF1','NF2','NF3','NF4','NF5','NF6','NF7']; | |
| private static function reset_name(int $value){ | |
| return self::$RESET_TBL[$value] ?? '<unknown>'; | |
| } | |
| private static function pull_name(int $value){ | |
| return self::$PULL_TBL[$value] ?? '<unknown>'; | |
| } | |
| private static function mode_name(int $value){ | |
| return self::$MODE_TBL[$value] ?? '<unknown>'; | |
| } | |
| public function generate(){ | |
| /** | |
| //uint32// .pad = 0, | |
| //uint32// .pad_config[0] = (2U << 30) | ((1) << 10), | |
| //uint32// .pad_config[1] = (0x0 << 10) | 0, | |
| //enum// .lock_action = GPIO_UNLOCK, | |
| */ | |
| foreach($this->gpioRows() as $item){ | |
| list($pad_cfg, $pad_value, $pad_name, $pad_func) = $item; | |
| $pad_rst = ($pad_cfg >> 30) & 0x3; | |
| $pad_pull = ($pad_cfg >> 10) & 0xF; | |
| //$pad_mode = ($pad_cfg >> 10) & 0x7; | |
| $pad_mode = 0; | |
| printf("rst: %s, pull: %s, mode: %s [%s (%s)]\n", | |
| self::reset_name($pad_rst), | |
| self::pull_name($pad_pull), | |
| self::mode_name($pad_mode), | |
| $pad_name, $pad_func | |
| ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment