ODROID-N2: keyboard: add gpio power key that is set from boot.ini

Change-Id: Ic3a6152bcedf21e8600993e70394a1b894c1d212
This commit is contained in:
Joy Cho
2019-02-19 10:30:18 +09:00
parent 31f26bacb1
commit f2c1863e66
2 changed files with 77 additions and 4 deletions

View File

@@ -341,6 +341,16 @@
status = "ok";
};
gpio_keypad{
compatible = "amlogic, gpio_keypad";
status = "okay";
scan_period = <20>;
key_num = <1>;
key_name = "power";
key_code = <116>;
reg = <0x0 0xFF800000 0x0 0x400>;
};
}; /* end of / */
&meson_fb {

View File

@@ -19,6 +19,7 @@
#include <linux/input.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
@@ -31,6 +32,9 @@
#define DEFAULT_POLL_MODE 0
#define KEY_JITTER_COUNT 1
#define AO_DEBUG_REG0 ((0x28 << 2))
static unsigned long gpiopower;
struct pin_desc {
int current_status;
struct gpio_desc *desc;
@@ -52,6 +56,23 @@ struct gpio_keypad {
struct input_dev *input_dev;
};
static int __init gpiopower_setup(char *str)
{
int ret;
if (str == NULL) {
gpiopower = 0;
return -EINVAL;
}
ret = kstrtoul(str, 0, &gpiopower);
pr_info("%s gpiopower : %ld\n", __func__, gpiopower);
return 0;
}
__setup("gpiopower=", gpiopower_setup);
static irqreturn_t gpio_irq_handler(int irq, void *data)
{
struct gpio_keypad *keypad;
@@ -148,6 +169,9 @@ static int meson_gpio_kp_probe(struct platform_device *pdev)
int ret, i;
struct input_dev *input_dev;
struct gpio_keypad *keypad;
struct resource *res;
int val, err;
void __iomem *ao_reg;
if (!(pdev->dev.of_node)) {
dev_err(&pdev->dev,
@@ -179,11 +203,50 @@ static int meson_gpio_kp_probe(struct platform_device *pdev)
(keypad->key_size)*sizeof(*(keypad->key)), GFP_KERNEL);
if (!(keypad->key))
return -EINVAL;
if (gpiopower) {
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res) {
ao_reg = ioremap(res->start, res->end - res->start);
} else {
dev_info(&pdev->dev, "Failed to get AO reg\n");
ao_reg = NULL;
}
}
for (i = 0; i < keypad->key_size; i++) {
//get all gpio desc.
desc = devm_gpiod_get_index(&pdev->dev, "key", i, GPIOD_IN);
if (!desc)
return -EINVAL;
if (gpiopower) {
if (gpio_is_valid(gpiopower)) {
err = devm_gpio_request_one(&pdev->dev,
gpiopower, GPIOF_IN, "gpio_keys");
if (err < 0) {
dev_err(&pdev->dev, "Failed to request GPIO %ld, error %d\n",
gpiopower, err);
return -EINVAL;
}
desc = gpio_to_desc(gpiopower);
if (!desc) {
dev_err(&pdev->dev, "Failed to get desc\n");
return -EINVAL;
}
if (ao_reg) {
val = readl((ao_reg + AO_DEBUG_REG0));
val |= (gpiopower << 16);
writel(val, (ao_reg + AO_DEBUG_REG0));
}
} else {
dev_err(&pdev->dev, "invalid gpio %ld\n",
gpiopower);
return -EINVAL;
}
} else {
//get all gpio desc.
desc = devm_gpiod_get_index(&pdev->dev,
"key", i, GPIOD_IN);
if (IS_ERR(desc)) {
dev_err(&pdev->dev, "failed to get gpio index from dts\n");
return -EINVAL;
}
}
keypad->key[i].desc = desc;
//The gpio default is high level.
keypad->key[i].current_status = 1;