// SPDX-License-Identifier: GPL-2.0-only OR MIT /* * Apple SMC GPIO driver * Copyright The Asahi Linux Contributors * * This driver implements basic SMC PMU GPIO support that can read inputs * and write outputs. Mode changes and IRQ config are not yet implemented.
*/
/* * Commands 0-6 are, presumably, the intended API. * Command 0xff lets you get/set the pin configuration in detail directly, * but the bit meanings seem not to be stable between devices/PMU hardware * versions. * * We're going to try to make do with the low commands for now. * We don't implement pin mode changes at this time.
*/
/* Return early if the key is out of bounds */
ret = apple_smc_get_key_by_index(smc, 0, &first_key); if (ret) return ret; if (key <= first_key) return -ENODEV;
ret = apple_smc_get_key_by_index(smc, smc->key_count - 1, &last_key); if (ret) return ret; if (key > last_key) return -ENODEV;
/* Binary search to find index of first SMC key bigger or equal to key */
start = 0;
count = smc->key_count; while (count > 1) {
smc_key pkey; int pivot = start + ((count - 1) >> 1);
ret = apple_smc_get_key_by_index(smc, pivot, &pkey); if (ret < 0) return ret;
/* First try reading the explicit pin mode register */
ret = apple_smc_rw_u32(smcgp->smc, key, CMD_PINMODE, &val); if (!ret) return (val & MODE_OUTPUT) ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
/* * Less common IRQ configs cause CMD_PINMODE to fail, and so does open drain mode. * Fall back to reading IRQ mode, which will only succeed for inputs.
*/
ret = apple_smc_rw_u32(smcgp->smc, key, CMD_IRQ_MODE, &val); return ret ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.