1 /*
2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <key.h>
10
gpio_key_ofdata_to_platdata(struct udevice * dev)11 static int gpio_key_ofdata_to_platdata(struct udevice *dev)
12 {
13 struct dm_key_uclass_platdata *uc_key;
14
15 uc_key = dev_get_uclass_platdata(dev);
16 if (!uc_key)
17 return -ENXIO;
18
19 uc_key->type = GPIO_KEY;
20 uc_key->name = dev_read_string(dev, "label");
21 uc_key->code = dev_read_u32_default(dev, "linux,code", -ENODATA);
22 if (uc_key->code < 0) {
23 printf("%s: read 'linux,code' failed\n", uc_key->name);
24 return -EINVAL;
25 }
26
27 if (dev_read_u32_array(dev, "gpios",
28 uc_key->gpios, ARRAY_SIZE(uc_key->gpios))) {
29 printf("%s: read 'gpios' failed\n", uc_key->name);
30 return -EINVAL;
31 }
32
33 return 0;
34 }
35
36 U_BOOT_DRIVER(gpio_key) = {
37 .name = "gpio_key",
38 .id = UCLASS_KEY,
39 .ofdata_to_platdata = gpio_key_ofdata_to_platdata,
40 };
41
42 /* Key Bus */
gpio_key_bus_bind(struct udevice * dev)43 static int gpio_key_bus_bind(struct udevice *dev)
44 {
45 return key_bind_children(dev, "gpio_key");
46 }
47
48 static const struct udevice_id gpio_key_bus_match[] = {
49 { .compatible = "gpio-keys" },
50 { },
51 };
52
53 U_BOOT_DRIVER(gpio_key_bus) = {
54 .name = "gpio_key_bus",
55 .id = UCLASS_SIMPLE_BUS,
56 .of_match = gpio_key_bus_match,
57 .bind = gpio_key_bus_bind,
58 };
59