Skip to content

Commit da3e8fa

Browse files
authored
fix: use iowrite8 for byte-sized MMIO registers in applesmc (#43)
The iomem_write_smc, iomem_read_smc, and iomem_get_smc_key_type functions used iowrite32 to write to byte-sized registers at non-aligned addresses (KEY_DATA_LEN at 0x7D, KEY_SMC_ID at 0x7E, KEY_CMD at 0x7F). On some T2 Macs (confirmed on MacBook Air 8,1), the 32-bit writes at these consecutive addresses cause the T2 SMC to receive corrupted data, resulting in SmcKeySizeMismatch (error 0x87) on every write operation. This made fan control via t2fanrd completely non-functional since the F0Md (fan manual mode) key could never be written. Fix by using iowrite8 for these byte-sized registers, matching the ioread8 already used to read them. The 4-byte KEY_NAME register at 0x78 correctly remains iowrite32. Tested on MacBook Air 8,1 (T2) with kernel 6.18.13 - fan control works after this fix.
1 parent 122588c commit da3e8fa

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

3005-applesmc-basic-mmio-interface-implementation.patch

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ index 5442897e3..435541f9f 100644
102102
+
103103
+ iomem_clear_status(smc);
104104
+ iowrite32(key_int, smc->iomem_base + APPLESMC_IOMEM_KEY_NAME);
105-
+ iowrite32(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
106-
+ iowrite32(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
105+
+ iowrite8(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
106+
+ iowrite8(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
107107
+
108108
+ if (iomem_wait_read(smc))
109109
+ return -EIO;
@@ -145,8 +145,8 @@ index 5442897e3..435541f9f 100644
145145
+
146146
+ iomem_clear_status(smc);
147147
+ iowrite32(key_int, smc->iomem_base + APPLESMC_IOMEM_KEY_NAME);
148-
+ iowrite32(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
149-
+ iowrite32(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
148+
+ iowrite8(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
149+
+ iowrite8(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
150150
+
151151
+ if (iomem_wait_read(smc))
152152
+ return -EIO;
@@ -176,9 +176,9 @@ index 5442897e3..435541f9f 100644
176176
+ iomem_clear_status(smc);
177177
+ iowrite32(key_int, smc->iomem_base + APPLESMC_IOMEM_KEY_NAME);
178178
+ memcpy_toio(smc->iomem_base + APPLESMC_IOMEM_KEY_DATA, buffer, len);
179-
+ iowrite32(len, smc->iomem_base + APPLESMC_IOMEM_KEY_DATA_LEN);
180-
+ iowrite32(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
181-
+ iowrite32(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
179+
+ iowrite8(len, smc->iomem_base + APPLESMC_IOMEM_KEY_DATA_LEN);
180+
+ iowrite8(0, smc->iomem_base + APPLESMC_IOMEM_KEY_SMC_ID);
181+
+ iowrite8(cmd, smc->iomem_base + APPLESMC_IOMEM_KEY_CMD);
182182
+
183183
+ if (iomem_wait_read(smc))
184184
+ return -EIO;

0 commit comments

Comments
 (0)