/*1* i2c-boardinfo.c - collect pre-declarations of I2C devices2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation; either version 2 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.16*/1718#include <linux/kernel.h>19#include <linux/i2c.h>20#include <linux/slab.h>21#include <linux/rwsem.h>2223#include "i2c-core.h"242526/* These symbols are exported ONLY FOR the i2c core.27* No other users will be supported.28*/29DECLARE_RWSEM(__i2c_board_lock);30EXPORT_SYMBOL_GPL(__i2c_board_lock);3132LIST_HEAD(__i2c_board_list);33EXPORT_SYMBOL_GPL(__i2c_board_list);3435int __i2c_first_dynamic_bus_num;36EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num);373839/**40* i2c_register_board_info - statically declare I2C devices41* @busnum: identifies the bus to which these devices belong42* @info: vector of i2c device descriptors43* @len: how many descriptors in the vector; may be zero to reserve44* the specified bus number.45*46* Systems using the Linux I2C driver stack can declare tables of board info47* while they initialize. This should be done in board-specific init code48* near arch_initcall() time, or equivalent, before any I2C adapter driver is49* registered. For example, mainboard init code could define several devices,50* as could the init code for each daughtercard in a board stack.51*52* The I2C devices will be created later, after the adapter for the relevant53* bus has been registered. After that moment, standard driver model tools54* are used to bind "new style" I2C drivers to the devices. The bus number55* for any device declared using this routine is not available for dynamic56* allocation.57*58* The board info passed can safely be __initdata, but be careful of embedded59* pointers (for platform_data, functions, etc) since that won't be copied.60*/61int __init62i2c_register_board_info(int busnum,63struct i2c_board_info const *info, unsigned len)64{65int status;6667down_write(&__i2c_board_lock);6869/* dynamic bus numbers will be assigned after the last static one */70if (busnum >= __i2c_first_dynamic_bus_num)71__i2c_first_dynamic_bus_num = busnum + 1;7273for (status = 0; len; len--, info++) {74struct i2c_devinfo *devinfo;7576devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);77if (!devinfo) {78pr_debug("i2c-core: can't register boardinfo!\n");79status = -ENOMEM;80break;81}8283devinfo->busnum = busnum;84devinfo->board_info = *info;85list_add_tail(&devinfo->list, &__i2c_board_list);86}8788up_write(&__i2c_board_lock);8990return status;91}929394