Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * STMicroelectronics Key Scanning driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2014 STMicroelectonics Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: Stuart Menefy <stuart.menefy@st.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on sh_keysc.c, copyright 2008 Magnus Damm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input/matrix_keypad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define ST_KEYSCAN_MAXKEYS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define KEYSCAN_CONFIG_OFF		0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define KEYSCAN_CONFIG_ENABLE		0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define KEYSCAN_DEBOUNCE_TIME_OFF	0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define KEYSCAN_MATRIX_STATE_OFF	0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define KEYSCAN_MATRIX_DIM_OFF		0xc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define KEYSCAN_MATRIX_DIM_X_SHIFT	0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define KEYSCAN_MATRIX_DIM_Y_SHIFT	0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct st_keyscan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long last_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned int n_rows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned int n_cols;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned int debounce_us;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static irqreturn_t keyscan_isr(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct st_keyscan *keypad = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned short *keycode = keypad->input_dev->keycode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned long state, change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int bit_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	state = readl(keypad->base + KEYSCAN_MATRIX_STATE_OFF) & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	change = keypad->last_state ^ state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	keypad->last_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	for_each_set_bit(bit_nr, &change, BITS_PER_LONG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		input_report_key(keypad->input_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 				 keycode[bit_nr], state & BIT(bit_nr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	input_sync(keypad->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static int keyscan_start(struct st_keyscan *keypad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	error = clk_enable(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	writel(keypad->debounce_us * (clk_get_rate(keypad->clk) / 1000000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	       keypad->base + KEYSCAN_DEBOUNCE_TIME_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	writel(((keypad->n_cols - 1) << KEYSCAN_MATRIX_DIM_X_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	       ((keypad->n_rows - 1) << KEYSCAN_MATRIX_DIM_Y_SHIFT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	       keypad->base + KEYSCAN_MATRIX_DIM_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	writel(KEYSCAN_CONFIG_ENABLE, keypad->base + KEYSCAN_CONFIG_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void keyscan_stop(struct st_keyscan *keypad)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	writel(0, keypad->base + KEYSCAN_CONFIG_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	clk_disable(keypad->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int keyscan_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct st_keyscan *keypad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return keyscan_start(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static void keyscan_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct st_keyscan *keypad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	keyscan_stop(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int keypad_matrix_key_parse_dt(struct st_keyscan *keypad_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct device *dev = keypad_data->input_dev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	error = matrix_keypad_parse_properties(dev, &keypad_data->n_rows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					       &keypad_data->n_cols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev_err(dev, "failed to parse keypad params\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	of_property_read_u32(np, "st,debounce-us", &keypad_data->debounce_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	dev_dbg(dev, "n_rows=%d n_col=%d debounce=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		keypad_data->n_rows, keypad_data->n_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		keypad_data->debounce_us);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int keyscan_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct st_keyscan *keypad_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (!pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		dev_err(&pdev->dev, "no DT data present\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	keypad_data = devm_kzalloc(&pdev->dev, sizeof(*keypad_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				   GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (!keypad_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	input_dev = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		dev_err(&pdev->dev, "failed to allocate the input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	input_dev->name = pdev->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	input_dev->phys = "keyscan-keys/input0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	input_dev->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	input_dev->open = keyscan_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	input_dev->close = keyscan_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	input_dev->id.bustype = BUS_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	keypad_data->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	error = keypad_matrix_key_parse_dt(keypad_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	error = matrix_keypad_build_keymap(NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 					   keypad_data->n_rows,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 					   keypad_data->n_cols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 					   NULL, input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		dev_err(&pdev->dev, "failed to build keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	input_set_drvdata(input_dev, keypad_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	keypad_data->base = devm_ioremap_resource(&pdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (IS_ERR(keypad_data->base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		return PTR_ERR(keypad_data->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	keypad_data->clk = devm_clk_get(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (IS_ERR(keypad_data->clk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		dev_err(&pdev->dev, "cannot get clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return PTR_ERR(keypad_data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	error = clk_enable(keypad_data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		dev_err(&pdev->dev, "failed to enable clock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	keyscan_stop(keypad_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	keypad_data->irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (keypad_data->irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	error = devm_request_irq(&pdev->dev, keypad_data->irq, keyscan_isr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				 pdev->name, keypad_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		dev_err(&pdev->dev, "failed to request IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		dev_err(&pdev->dev, "failed to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	platform_set_drvdata(pdev, keypad_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	device_set_wakeup_capable(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static int keyscan_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct st_keyscan *keypad = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct input_dev *input = keypad->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	mutex_lock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		enable_irq_wake(keypad->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	else if (input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		keyscan_stop(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	mutex_unlock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static int keyscan_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct st_keyscan *keypad = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct input_dev *input = keypad->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	mutex_lock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		disable_irq_wake(keypad->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	else if (input->users)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		retval = keyscan_start(keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	mutex_unlock(&input->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static SIMPLE_DEV_PM_OPS(keyscan_dev_pm_ops, keyscan_suspend, keyscan_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static const struct of_device_id keyscan_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	{ .compatible = "st,sti-keyscan" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) MODULE_DEVICE_TABLE(of, keyscan_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static struct platform_driver keyscan_device_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.probe		= keyscan_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		.name	= "st-keyscan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		.pm	= &keyscan_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		.of_match_table = of_match_ptr(keyscan_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_platform_driver(keyscan_device_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) MODULE_AUTHOR("Stuart Menefy <stuart.menefy@st.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) MODULE_DESCRIPTION("STMicroelectronics keyscan device driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) MODULE_LICENSE("GPL");