xref: /openbmc/linux/drivers/hsi/hsi_boardinfo.c (revision 2c684d89)
1 /*
2  * HSI clients registration interface
3  *
4  * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5  *
6  * Contact: Carlos Chinea <carlos.chinea@nokia.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 #include <linux/hsi/hsi.h>
23 #include <linux/list.h>
24 #include <linux/slab.h>
25 #include "hsi_core.h"
26 
27 /*
28  * hsi_board_list is only used internally by the HSI framework.
29  * No one else is allowed to make use of it.
30  */
31 LIST_HEAD(hsi_board_list);
32 EXPORT_SYMBOL_GPL(hsi_board_list);
33 
34 /**
35  * hsi_register_board_info - Register HSI clients information
36  * @info: Array of HSI clients on the board
37  * @len: Length of the array
38  *
39  * HSI clients are statically declared and registered on board files.
40  *
41  * HSI clients will be automatically registered to the HSI bus once the
42  * controller and the port where the clients wishes to attach are registered
43  * to it.
44  *
45  * Return -errno on failure, 0 on success.
46  */
47 int __init hsi_register_board_info(struct hsi_board_info const *info,
48 							unsigned int len)
49 {
50 	struct hsi_cl_info *cl_info;
51 
52 	cl_info = kzalloc(sizeof(*cl_info) * len, GFP_KERNEL);
53 	if (!cl_info)
54 		return -ENOMEM;
55 
56 	for (; len; len--, info++, cl_info++) {
57 		cl_info->info = *info;
58 		list_add_tail(&cl_info->list, &hsi_board_list);
59 	}
60 
61 	return 0;
62 }
63