Source
x
/*
* Cirrus Logic CLPS711X Keypad driver
*
* Copyright (C) 2014 Alexander Shiyan <shc_work@mail.ru>
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*/
struct clps711x_gpio_data {
struct gpio_desc *desc;
DECLARE_BITMAP(last_state, CLPS711X_KEYPAD_COL_COUNT);
};
struct clps711x_keypad_data {
struct regmap *syscon;
int row_count;
unsigned int row_shift;
struct clps711x_gpio_data *gpio_data;
};
static void clps711x_keypad_poll(struct input_polled_dev *dev)
{
const unsigned short *keycodes = dev->input->keycode;
struct clps711x_keypad_data *priv = dev->private;
bool sync = false;
int col, row;
for (col = 0; col < CLPS711X_KEYPAD_COL_COUNT; col++) {
/* Assert column */
regmap_update_bits(priv->syscon, SYSCON_OFFSET,
SYSCON1_KBDSCAN_MASK,
SYSCON1_KBDSCAN(8 + col));
/* Scan rows */
for (row = 0; row < priv->row_count; row++) {
struct clps711x_gpio_data *data = &priv->gpio_data[row];
bool state, state1;
/* Read twice for protection against fluctuations */
do {
state = gpiod_get_value_cansleep(data->desc);
cond_resched();
state1 = gpiod_get_value_cansleep(data->desc);
} while (state != state1);
if (test_bit(col, data->last_state) != state) {
int code = MATRIX_SCAN_CODE(row, col,
priv->row_shift);
if (state) {
set_bit(col, data->last_state);
input_event(dev->input, EV_MSC,
MSC_SCAN, code);
} else {
clear_bit(col, data->last_state);
}
if (keycodes[code])
input_report_key(dev->input,
keycodes[code], state);
sync = true;
}
}
/* Set all columns to low */
regmap_update_bits(priv->syscon, SYSCON_OFFSET,
SYSCON1_KBDSCAN_MASK, SYSCON1_KBDSCAN(1));
}
if (sync)
input_sync(dev->input);
}
static int clps711x_keypad_probe(struct platform_device *pdev)
{
struct clps711x_keypad_data *priv;