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 11 static int rk_key_ofdata_to_platdata(struct udevice *dev) 12 { 13 struct dm_key_uclass_platdata *uc_key; 14 u32 chn[2]; 15 16 uc_key = dev_get_uclass_platdata(dev); 17 if (!uc_key) 18 return -ENXIO; 19 20 uc_key->name = dev_read_string(dev, "label"); 21 uc_key->code = dev_read_u32_default(dev, "linux,code", -ENODATA); 22 23 if (dev_read_u32_array(dev_get_parent(dev), "io-channels", chn, 2)) { 24 printf("%s: read 'io-channels' failed\n", uc_key->name); 25 return -EINVAL; 26 } 27 28 if (dev_read_bool(dev, "rockchip,adc_value")) { 29 uc_key->type = ADC_KEY; 30 uc_key->channel = chn[1]; 31 uc_key->adcval = 32 dev_read_u32_default(dev, "rockchip,adc_value", 0); 33 } else { 34 uc_key->type = GPIO_KEY; 35 if (dev_read_u32_array(dev, "gpios", 36 uc_key->gpios, 37 ARRAY_SIZE(uc_key->gpios))) { 38 printf("%s: read 'gpios' failed\n", uc_key->name); 39 return -EINVAL; 40 } 41 } 42 43 return 0; 44 } 45 46 U_BOOT_DRIVER(rk_key) = { 47 .name = "rk_key", 48 .id = UCLASS_KEY, 49 .ofdata_to_platdata = rk_key_ofdata_to_platdata, 50 }; 51 52 /* Key Bus */ 53 static int rk_key_bus_bind(struct udevice *dev) 54 { 55 return key_bind_children(dev, "rk_key"); 56 } 57 58 static const struct udevice_id rk_key_bus_match[] = { 59 { .compatible = "rockchip,key" }, 60 { }, 61 }; 62 63 U_BOOT_DRIVER(rk_key_bus) = { 64 .name = "rk_key_bus", 65 .id = UCLASS_SIMPLE_BUS, 66 .of_match = rk_key_bus_match, 67 .bind = rk_key_bus_bind, 68 }; 69