/* Maximum row/column supported by Tegra KBC yet is 16x8 */ #define KBC_MAX_GPIO 24 /* Maximum keys supported by Tegra KBC yet is 16 x 8*/ #define KBC_MAX_KEY (16 * 8)
#define KBC_MAX_DEBOUNCE_CNT 0x3ffu
/* KBC row scan time and delay for beginning the row scan. */ #define KBC_ROW_SCAN_TIME 16 #define KBC_ROW_SCAN_DLY 5
/* KBC uses a 32KHz clock so a cycle = 1/32Khz */ #define KBC_CYCLE_MS 32
for (i = 0; i < KBC_MAX_KPENT; i++) { if ((i % 4) == 0)
val = readl(kbc->mmio + KBC_KP_ENT0_0 + i);
if (val & 0x80) { unsignedint col = val & 0x07; unsignedint row = (val >> 3) & 0x0f; unsignedchar scancode =
MATRIX_SCAN_CODE(row, col, KBC_ROW_SHIFT);
scancodes[num_down] = scancode;
keycodes[num_down] = kbc->keycode[scancode]; /* If driver uses Fn map, do not report the Fn key. */ if ((keycodes[num_down] == KEY_FN) && kbc->use_fn_map)
fn_keypress = true; else
num_down++;
}
val >>= 8;
}
/* * Matrix keyboard designs are prone to keyboard ghosting. * Ghosting occurs if there are 3 keys such that - * any 2 of the 3 keys share a row, and any 2 of them share a column. * If so ignore the key presses for this iteration.
*/ if (kbc->use_ghost_filter && num_down >= 3) { for (i = 0; i < num_down; i++) { unsignedint j;
u8 curr_col = scancodes[i] & 0x07;
u8 curr_row = scancodes[i] >> KBC_ROW_SHIFT;
/* * Find 2 keys such that one key is in the same row * and the other is in the same column as the i-th key.
*/ for (j = i + 1; j < num_down; j++) {
u8 col = scancodes[j] & 0x07;
u8 row = scancodes[j] >> KBC_ROW_SHIFT;
if (col == curr_col)
key_in_same_col = true; if (row == curr_row)
key_in_same_row = true;
}
}
}
/* * If the platform uses Fn keymaps, translate keys on a Fn keypress. * Function keycodes are max_keys apart from the plain keycodes.
*/ if (fn_keypress) { for (i = 0; i < num_down; i++) {
scancodes[i] += kbc->max_keys;
keycodes[i] = kbc->keycode[scancodes[i]];
}
}
/* Ignore the key presses for this iteration? */ if (key_in_same_col && key_in_same_row) return;
val = readl(kbc->mmio + KBC_CONTROL_0); if (enable)
val |= KBC_CONTROL_FIFO_CNT_INT_EN; else
val &= ~KBC_CONTROL_FIFO_CNT_INT_EN;
writel(val, kbc->mmio + KBC_CONTROL_0);
}
val = (readl(kbc->mmio + KBC_INT_0) >> 4) & 0xf; if (val) { unsignedlong dly;
tegra_kbc_report_keys(kbc);
/* * If more than one keys are pressed we need not wait * for the repoll delay.
*/
dly = (val == 1) ? kbc->repoll_dly : 1;
mod_timer(&kbc->timer, jiffies + msecs_to_jiffies(dly));
} else { /* Release any pressed keys and exit the polling loop */ for (i = 0; i < kbc->num_pressed_keys; i++)
input_report_key(kbc->idev, kbc->current_keys[i], 0);
input_sync(kbc->idev);
kbc->num_pressed_keys = 0;
/* All keys are released so enable the keypress interrupt */
tegra_kbc_set_fifo_interrupt(kbc, true);
}
}
/* * Quickly bail out & reenable interrupts if the fifo threshold * count interrupt wasn't the interrupt source
*/
val = readl(kbc->mmio + KBC_INT_0);
writel(val, kbc->mmio + KBC_INT_0);
if (val & KBC_INT_FIFO_CNT_INT_STATUS) { /* * Until all keys are released, defer further processing to * the polling loop in tegra_kbc_keypress_timer.
*/
tegra_kbc_set_fifo_interrupt(kbc, false);
mod_timer(&kbc->timer, jiffies + kbc->cp_dly_jiffies);
} elseif (val & KBC_INT_KEYPRESS_INT_STATUS) { /* We can be here only through system resume path */
kbc->keypress_caused_wake = true;
}
staticint tegra_kbc_start(struct tegra_kbc *kbc)
{ unsignedint debounce_cnt;
u32 val = 0; int ret;
ret = clk_prepare_enable(kbc->clk); if (ret) return ret;
/* Reset the KBC controller to clear all previous status.*/
reset_control_assert(kbc->rst);
udelay(100);
reset_control_deassert(kbc->rst);
udelay(100);
/* Keyboard debounce count is maximum of 12 bits. */
debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT);
val = KBC_DEBOUNCE_CNT_SHIFT(debounce_cnt);
val |= KBC_FIFO_TH_CNT_SHIFT(1); /* set fifo interrupt threshold to 1 */
val |= KBC_CONTROL_FIFO_CNT_INT_EN; /* interrupt on FIFO threshold */
val |= KBC_CONTROL_KBC_EN; /* enable */
writel(val, kbc->mmio + KBC_CONTROL_0);
/* * Compute the delay(ns) from interrupt mode to continuous polling * mode so the timer routine is scheduled appropriately.
*/
val = readl(kbc->mmio + KBC_INIT_DLY_0);
kbc->cp_dly_jiffies = usecs_to_jiffies((val & 0xfffff) * 32);
kbc->num_pressed_keys = 0;
/* * Atomically clear out any remaining entries in the key FIFO * and enable keyboard interrupts.
*/ while (1) {
val = readl(kbc->mmio + KBC_INT_0);
val >>= 4; if (!val) break;
val = readl(kbc->mmio + KBC_KP_ENT0_0);
val = readl(kbc->mmio + KBC_KP_ENT1_0);
}
writel(0x7, kbc->mmio + KBC_INT_0);
staticbool tegra_kbc_check_pin_cfg(conststruct tegra_kbc *kbc, unsignedint *num_rows)
{ int i;
*num_rows = 0;
for (i = 0; i < KBC_MAX_GPIO; i++) { conststruct tegra_kbc_pin_cfg *pin_cfg = &kbc->pin_cfg[i];
switch (pin_cfg->type) { case PIN_CFG_ROW: if (pin_cfg->num >= kbc->hw_support->max_rows) {
dev_err(kbc->dev, "pin_cfg[%d]: invalid row number %d\n",
i, pin_cfg->num); returnfalse;
}
(*num_rows)++; break;
case PIN_CFG_COL: if (pin_cfg->num >= kbc->hw_support->max_columns) {
dev_err(kbc->dev, "pin_cfg[%d]: invalid column number %d\n",
i, pin_cfg->num); returnfalse;
} break;
if (!of_property_present(np, "linux,keymap")) {
dev_err(kbc->dev, "property linux,keymap not found\n"); return -ENOENT;
}
/* Set all pins as non-configured */ for (i = 0; i < kbc->num_rows_and_columns; i++)
kbc->pin_cfg[i].type = PIN_CFG_IGNORE;
num_rows = of_property_read_variable_u32_array(np, "nvidia,kbc-row-pins",
rows_cfg, 1, KBC_MAX_GPIO); if (num_rows < 0) {
dev_err(kbc->dev, "Rows configurations are not proper\n"); return num_rows;
} elseif (num_rows > kbc->hw_support->max_rows) {
dev_err(kbc->dev, "Number of rows is more than supported by hardware\n"); return -EINVAL;
}
for (i = 0; i < num_rows; i++) {
kbc->pin_cfg[rows_cfg[i]].type = PIN_CFG_ROW;
kbc->pin_cfg[rows_cfg[i]].num = i;
}
num_cols = of_property_read_variable_u32_array(np, "nvidia,kbc-col-pins",
cols_cfg, 1, KBC_MAX_GPIO); if (num_cols < 0) {
dev_err(kbc->dev, "Cols configurations are not proper\n"); return num_cols;
} elseif (num_cols > kbc->hw_support->max_columns) {
dev_err(kbc->dev, "Number of cols is more than supported by hardware\n"); return -EINVAL;
}
for (i = 0; i < num_cols; i++) {
kbc->pin_cfg[cols_cfg[i]].type = PIN_CFG_COL;
kbc->pin_cfg[cols_cfg[i]].num = i;
}
if (!num_rows || !num_cols || ((num_rows + num_cols) > KBC_MAX_GPIO)) {
dev_err(kbc->dev, "keypad rows/columns not properly specified\n"); return -EINVAL;
}
kbc->mmio = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(kbc->mmio)) return PTR_ERR(kbc->mmio);
kbc->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(kbc->clk)) {
dev_err(&pdev->dev, "failed to get keyboard clock\n"); return PTR_ERR(kbc->clk);
}
kbc->rst = devm_reset_control_get(&pdev->dev, "kbc"); if (IS_ERR(kbc->rst)) {
dev_err(&pdev->dev, "failed to get keyboard reset\n"); return PTR_ERR(kbc->rst);
}
/* * The time delay between two consecutive reads of the FIFO is * the sum of the repeat time and the time taken for scanning * the rows. There is an additional delay before the row scanning * starts. The repoll delay is computed in milliseconds.
*/
debounce_cnt = min(kbc->debounce_cnt, KBC_MAX_DEBOUNCE_CNT);
scan_time_rows = (KBC_ROW_SCAN_TIME + debounce_cnt) * num_rows;
kbc->repoll_dly = KBC_ROW_SCAN_DLY + scan_time_rows + kbc->repeat_cnt;
kbc->repoll_dly = DIV_ROUND_UP(kbc->repoll_dly, KBC_CYCLE_MS);
val = readl(kbc->mmio + KBC_CONTROL_0); if (enable)
val |= KBC_CONTROL_KEYPRESS_INT_EN; else
val &= ~KBC_CONTROL_KEYPRESS_INT_EN;
writel(val, kbc->mmio + KBC_CONTROL_0);
}
if (device_may_wakeup(&pdev->dev)) {
disable_irq(kbc->irq);
timer_delete_sync(&kbc->timer);
tegra_kbc_set_fifo_interrupt(kbc, false);
/* Forcefully clear the interrupt status */
writel(0x7, kbc->mmio + KBC_INT_0); /* * Store the previous resident time of continuous polling mode. * Force the keyboard into interrupt mode.
*/
kbc->cp_to_wkup_dly = readl(kbc->mmio + KBC_TO_CNT_0);
writel(0, kbc->mmio + KBC_TO_CNT_0);
if (device_may_wakeup(&pdev->dev)) {
disable_irq_wake(kbc->irq);
tegra_kbc_setup_wakekeys(kbc, false); /* We will use fifo interrupts for key detection. */
tegra_kbc_set_keypress_interrupt(kbc, false);
/* Restore the resident time of continuous polling mode. */
writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0);
tegra_kbc_set_fifo_interrupt(kbc, true);
if (kbc->keypress_caused_wake && kbc->wakeup_key) { /* * We can't report events directly from the ISR * because timekeeping is stopped when processing * wakeup request and we get a nasty warning when * we try to call do_gettimeofday() in evdev * handler.
*/
input_report_key(kbc->idev, kbc->wakeup_key, 1);
input_sync(kbc->idev);
input_report_key(kbc->idev, kbc->wakeup_key, 0);
input_sync(kbc->idev);
}
} elseif (input_device_enabled(kbc->idev)) {
err = tegra_kbc_start(kbc); if (err) return err;
}
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.