xref: /OK3568_Linux_fs/kernel/drivers/hsi/hsi_boardinfo.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * HSI clients registration interface
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2010 Nokia Corporation. All rights reserved.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Contact: Carlos Chinea <carlos.chinea@nokia.com>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #include <linux/hsi/hsi.h>
10*4882a593Smuzhiyun #include <linux/list.h>
11*4882a593Smuzhiyun #include <linux/slab.h>
12*4882a593Smuzhiyun #include "hsi_core.h"
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /*
15*4882a593Smuzhiyun  * hsi_board_list is only used internally by the HSI framework.
16*4882a593Smuzhiyun  * No one else is allowed to make use of it.
17*4882a593Smuzhiyun  */
18*4882a593Smuzhiyun LIST_HEAD(hsi_board_list);
19*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(hsi_board_list);
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun /**
22*4882a593Smuzhiyun  * hsi_register_board_info - Register HSI clients information
23*4882a593Smuzhiyun  * @info: Array of HSI clients on the board
24*4882a593Smuzhiyun  * @len: Length of the array
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * HSI clients are statically declared and registered on board files.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * HSI clients will be automatically registered to the HSI bus once the
29*4882a593Smuzhiyun  * controller and the port where the clients wishes to attach are registered
30*4882a593Smuzhiyun  * to it.
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  * Return -errno on failure, 0 on success.
33*4882a593Smuzhiyun  */
hsi_register_board_info(struct hsi_board_info const * info,unsigned int len)34*4882a593Smuzhiyun int __init hsi_register_board_info(struct hsi_board_info const *info,
35*4882a593Smuzhiyun 							unsigned int len)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun 	struct hsi_cl_info *cl_info;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	cl_info = kcalloc(len, sizeof(*cl_info), GFP_KERNEL);
40*4882a593Smuzhiyun 	if (!cl_info)
41*4882a593Smuzhiyun 		return -ENOMEM;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	for (; len; len--, info++, cl_info++) {
44*4882a593Smuzhiyun 		cl_info->info = *info;
45*4882a593Smuzhiyun 		list_add_tail(&cl_info->list, &hsi_board_list);
46*4882a593Smuzhiyun 	}
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	return 0;
49*4882a593Smuzhiyun }
50