xref: /rk3399_rockchip-uboot/drivers/keylad/keylad-uclass.c (revision e15c98ee20b8dd02519a58e16b25e68be6e7b08a)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2025 Rockchip Electronics Co., Ltd
4  */
5 
6 #include <keylad.h>
7 
8 struct udevice *keylad_get_device(void)
9 {
10 	const struct dm_keylad_ops *ops;
11 	struct udevice *dev;
12 	struct uclass *uc;
13 	int ret;
14 
15 	ret = uclass_get(UCLASS_KEYLAD, &uc);
16 	if (ret)
17 		return NULL;
18 
19 	for (uclass_first_device(UCLASS_KEYLAD, &dev);
20 	     dev;
21 	     uclass_next_device(&dev)) {
22 		ops = device_get_ops(dev);
23 		if (!ops || !ops->transfer_fwkey)
24 			continue;
25 
26 		return dev;
27 	}
28 
29 	return NULL;
30 }
31 
32 int keylad_transfer_fwkey(struct udevice *dev, ulong dst,
33 			  enum RK_FW_KEYID fw_keyid, u32 keylen)
34 {
35 	const struct dm_keylad_ops *ops = device_get_ops(dev);
36 
37 	if (!ops || !ops->transfer_fwkey)
38 		return -ENOSYS;
39 
40 	if (dst == 0)
41 		return -EINVAL;
42 
43 	return ops->transfer_fwkey(dev, dst, fw_keyid, keylen);
44 }
45 
46 UCLASS_DRIVER(keylad) = {
47 	.id	= UCLASS_KEYLAD,
48 	.name	= "keylad",
49 };
50