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)  * max7359_keypad.c - MAX7359 Key Switch Controller Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2009 Samsung Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Kim Kyuwon <q1.kim@samsung.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Based on pxa27x_keypad.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Datasheet: http://www.maxim-ic.com/quick_view2.cfm/qv_pk/5456
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/input/matrix_keypad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define MAX7359_MAX_KEY_ROWS	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define MAX7359_MAX_KEY_COLS	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MAX7359_MAX_KEY_NUM	(MAX7359_MAX_KEY_ROWS * MAX7359_MAX_KEY_COLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define MAX7359_ROW_SHIFT	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * MAX7359 registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define MAX7359_REG_KEYFIFO	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define MAX7359_REG_CONFIG	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define MAX7359_REG_DEBOUNCE	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define MAX7359_REG_INTERRUPT	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define MAX7359_REG_PORTS	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define MAX7359_REG_KEYREP	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MAX7359_REG_SLEEP	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Configuration register bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define MAX7359_CFG_SLEEP	(1 << 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define MAX7359_CFG_INTERRUPT	(1 << 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define MAX7359_CFG_KEY_RELEASE	(1 << 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define MAX7359_CFG_WAKEUP	(1 << 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define MAX7359_CFG_TIMEOUT	(1 << 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Autosleep register values (ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define MAX7359_AUTOSLEEP_8192	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define MAX7359_AUTOSLEEP_4096	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define MAX7359_AUTOSLEEP_2048	0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define MAX7359_AUTOSLEEP_1024	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define MAX7359_AUTOSLEEP_512	0x05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define MAX7359_AUTOSLEEP_256	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) struct max7359_keypad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* matrix key code map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	unsigned short keycodes[MAX7359_MAX_KEY_NUM];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static int max7359_write_reg(struct i2c_client *client, u8 reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int ret = i2c_smbus_write_byte_data(client, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		dev_err(&client->dev, "%s: reg 0x%x, val 0x%x, err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			__func__, reg, val, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int max7359_read_reg(struct i2c_client *client, int reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int ret = i2c_smbus_read_byte_data(client, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			__func__, reg, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /* runs in an IRQ thread -- can (and will!) sleep */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static irqreturn_t max7359_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct max7359_keypad *keypad = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct input_dev *input_dev = keypad->input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int val, row, col, release, code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	val = max7359_read_reg(keypad->client, MAX7359_REG_KEYFIFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	row = val & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	col = (val >> 3) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	release = val & 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	code = MATRIX_SCAN_CODE(row, col, MAX7359_ROW_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	dev_dbg(&keypad->client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		"key[%d:%d] %s\n", row, col, release ? "release" : "press");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	input_event(input_dev, EV_MSC, MSC_SCAN, code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	input_report_key(input_dev, keypad->keycodes[code], !release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	input_sync(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * Let MAX7359 fall into a deep sleep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * If no keys are pressed, enter sleep mode for 8192 ms. And if any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * key is pressed, the MAX7359 returns to normal operating mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static inline void max7359_fall_deepsleep(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	max7359_write_reg(client, MAX7359_REG_SLEEP, MAX7359_AUTOSLEEP_8192);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Let MAX7359 take a catnap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Autosleep just for 256 ms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline void max7359_take_catnap(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	max7359_write_reg(client, MAX7359_REG_SLEEP, MAX7359_AUTOSLEEP_256);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int max7359_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct max7359_keypad *keypad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	max7359_take_catnap(keypad->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static void max7359_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct max7359_keypad *keypad = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	max7359_fall_deepsleep(keypad->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static void max7359_initialize(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	max7359_write_reg(client, MAX7359_REG_CONFIG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		MAX7359_CFG_KEY_RELEASE | /* Key release enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		MAX7359_CFG_WAKEUP); /* Key press wakeup enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* Full key-scan functionality */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	max7359_write_reg(client, MAX7359_REG_DEBOUNCE, 0x1F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* nINT asserts every debounce cycles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	max7359_write_reg(client, MAX7359_REG_INTERRUPT, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	max7359_fall_deepsleep(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int max7359_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	const struct matrix_keymap_data *keymap_data =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	struct max7359_keypad *keypad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (!client->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		dev_err(&client->dev, "The irq number should not be zero\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	/* Detect MAX7359: The initial Keys FIFO value is '0x3F' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	ret = max7359_read_reg(client, MAX7359_REG_KEYFIFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		dev_err(&client->dev, "failed to detect device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	dev_dbg(&client->dev, "keys FIFO is 0x%02x\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	keypad = devm_kzalloc(&client->dev, sizeof(struct max7359_keypad),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			      GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!keypad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		dev_err(&client->dev, "failed to allocate memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		dev_err(&client->dev, "failed to allocate input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	keypad->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	keypad->input_dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	input_dev->name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	input_dev->open = max7359_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	input_dev->close = max7359_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	input_dev->dev.parent = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	input_dev->keycodesize = sizeof(keypad->keycodes[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	input_dev->keycode = keypad->keycodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	input_set_drvdata(input_dev, keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	error = matrix_keypad_build_keymap(keymap_data, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 					   MAX7359_MAX_KEY_ROWS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					   MAX7359_MAX_KEY_COLS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 					   keypad->keycodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 					   input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		dev_err(&client->dev, "failed to build keymap\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	error = devm_request_threaded_irq(&client->dev, client->irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 					  max7359_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 					  IRQF_TRIGGER_LOW | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					  client->name, keypad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		dev_err(&client->dev, "failed to register interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return error;
^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) 	/* Register the input device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	error = input_register_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		dev_err(&client->dev, "failed to register input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Initialize MAX7359 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	max7359_initialize(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	device_init_wakeup(&client->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int max7359_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	max7359_fall_deepsleep(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		enable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static int max7359_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (device_may_wakeup(&client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		disable_irq_wake(client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/* Restore the default setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	max7359_take_catnap(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static SIMPLE_DEV_PM_OPS(max7359_pm, max7359_suspend, max7359_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static const struct i2c_device_id max7359_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	{ "max7359", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) MODULE_DEVICE_TABLE(i2c, max7359_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static struct i2c_driver max7359_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		.name = "max7359",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		.pm   = &max7359_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.probe		= max7359_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.id_table	= max7359_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) module_i2c_driver(max7359_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) MODULE_AUTHOR("Kim Kyuwon <q1.kim@samsung.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) MODULE_DESCRIPTION("MAX7359 Key Switch Controller Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) MODULE_LICENSE("GPL v2");