summaryrefslogtreecommitdiff
path: root/smc.h
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2019-05-29 16:41:40 +0300
committerEvgeny Zinoviev <me@ch1p.io>2019-05-29 16:41:40 +0300
commit984d8f39dcc84eb01b7daf85de50f4026f342528 (patch)
tree5d280788c3708fbe3a29eca33255c4b50ee32573 /smc.h
initial
Diffstat (limited to 'smc.h')
-rw-r--r--smc.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/smc.h b/smc.h
new file mode 100644
index 0000000..dffd8db
--- /dev/null
+++ b/smc.h
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2019 Evgeny Zinoviev <me@ch1p.io>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef SMC_H
+#define SMC_H
+
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdint.h>
+
+/* data port used by Apple SMC */
+#define APPLESMC_DATA_PORT 0x300
+/* command/status port used by Apple SMC */
+#define APPLESMC_CMD_PORT 0x304
+
+#define APPLESMC_MAX_DATA_LENGTH 32
+
+/* wait up to 128 ms for a status change. */
+#define APPLESMC_MIN_WAIT 0x0010
+#define APPLESMC_RETRY_WAIT 0x0100
+#define APPLESMC_MAX_WAIT 0x20000
+
+#define APPLESMC_READ_CMD 0x10
+#define APPLESMC_WRITE_CMD 0x11
+
+int wait_read(void);
+int send_byte(uint8_t cmd, uint16_t port);
+int send_command(uint8_t cmd);
+int send_argument(const char *key);
+int read_smc(uint8_t cmd, const char *key, uint8_t *buffer, uint8_t len);
+int write_smc(uint8_t cmd, const char *key, const uint8_t *buffer, uint8_t len);
+
+#endif /* SMC_H */