2019-05-27 09:55:06 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
/*
|
2011-03-20 16:50:52 +03:00
|
|
|
* i2c-boardinfo.c - collect pre-declarations of I2C devices
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
*/
|
|
|
|
|
2011-05-27 18:46:24 +04:00
|
|
|
#include <linux/export.h>
|
2016-02-21 01:33:38 +03:00
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/kernel.h>
|
2017-02-28 07:09:09 +03:00
|
|
|
#include <linux/property.h>
|
2009-06-19 18:58:20 +04:00
|
|
|
#include <linux/rwsem.h>
|
2016-02-21 01:33:38 +03:00
|
|
|
#include <linux/slab.h>
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
|
|
|
|
#include "i2c-core.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* These symbols are exported ONLY FOR the i2c core.
|
|
|
|
* No other users will be supported.
|
|
|
|
*/
|
2009-06-19 18:58:20 +04:00
|
|
|
DECLARE_RWSEM(__i2c_board_lock);
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
EXPORT_SYMBOL_GPL(__i2c_board_lock);
|
|
|
|
|
|
|
|
LIST_HEAD(__i2c_board_list);
|
|
|
|
EXPORT_SYMBOL_GPL(__i2c_board_list);
|
|
|
|
|
|
|
|
int __i2c_first_dynamic_bus_num;
|
|
|
|
EXPORT_SYMBOL_GPL(__i2c_first_dynamic_bus_num);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* i2c_register_board_info - statically declare I2C devices
|
|
|
|
* @busnum: identifies the bus to which these devices belong
|
|
|
|
* @info: vector of i2c device descriptors
|
|
|
|
* @len: how many descriptors in the vector; may be zero to reserve
|
|
|
|
* the specified bus number.
|
|
|
|
*
|
|
|
|
* Systems using the Linux I2C driver stack can declare tables of board info
|
|
|
|
* while they initialize. This should be done in board-specific init code
|
|
|
|
* near arch_initcall() time, or equivalent, before any I2C adapter driver is
|
|
|
|
* registered. For example, mainboard init code could define several devices,
|
|
|
|
* as could the init code for each daughtercard in a board stack.
|
|
|
|
*
|
|
|
|
* The I2C devices will be created later, after the adapter for the relevant
|
|
|
|
* bus has been registered. After that moment, standard driver model tools
|
|
|
|
* are used to bind "new style" I2C drivers to the devices. The bus number
|
|
|
|
* for any device declared using this routine is not available for dynamic
|
|
|
|
* allocation.
|
|
|
|
*
|
|
|
|
* The board info passed can safely be __initdata, but be careful of embedded
|
|
|
|
* pointers (for platform_data, functions, etc) since that won't be copied.
|
|
|
|
*/
|
2016-06-08 02:52:27 +03:00
|
|
|
int i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned len)
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2009-06-19 18:58:20 +04:00
|
|
|
down_write(&__i2c_board_lock);
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
|
|
|
|
/* dynamic bus numbers will be assigned after the last static one */
|
|
|
|
if (busnum >= __i2c_first_dynamic_bus_num)
|
|
|
|
__i2c_first_dynamic_bus_num = busnum + 1;
|
|
|
|
|
|
|
|
for (status = 0; len; len--, info++) {
|
|
|
|
struct i2c_devinfo *devinfo;
|
|
|
|
|
|
|
|
devinfo = kzalloc(sizeof(*devinfo), GFP_KERNEL);
|
|
|
|
if (!devinfo) {
|
|
|
|
pr_debug("i2c-core: can't register boardinfo!\n");
|
|
|
|
status = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
devinfo->busnum = busnum;
|
|
|
|
devinfo->board_info = *info;
|
2017-02-28 07:09:09 +03:00
|
|
|
|
2017-03-01 22:45:51 +03:00
|
|
|
if (info->resources) {
|
|
|
|
devinfo->board_info.resources =
|
|
|
|
kmemdup(info->resources,
|
|
|
|
info->num_resources *
|
|
|
|
sizeof(*info->resources),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!devinfo->board_info.resources) {
|
|
|
|
status = -ENOMEM;
|
2017-11-22 20:52:24 +03:00
|
|
|
kfree(devinfo);
|
2017-03-01 22:45:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
list_add_tail(&devinfo->list, &__i2c_board_list);
|
|
|
|
}
|
|
|
|
|
2009-06-19 18:58:20 +04:00
|
|
|
up_write(&__i2c_board_lock);
|
i2c: Add i2c_board_info and i2c_new_device()
This provides partial support for new-style I2C driver binding. It builds
on "struct i2c_board_info" declarations that identify I2C devices on a given
board. This is needed on systems with I2C devices that can't be fully probed
and/or autoconfigured, such as many embedded Linux configurations where the
way a given I2C device is wired may affect how it must be used.
There are two models for declaring such devices:
* LATE -- using a public function i2c_new_device(). This lets modules
declare I2C devices found *AFTER* a given I2C adapter becomes available.
For example, a PCI card could create adapters giving access to utility
chips on that card, and this would be used to associate those chips with
those adapters.
* EARLY -- from arch_initcall() level code, using a non-exported function
i2c_register_board_info(). This copies the declarations *BEFORE* such
an i2c_adapter becomes available, arranging that i2c_new_device() will
be called later when i2c-core registers the relevant i2c_adapter.
For example, arch/.../.../board-*.c files would declare the I2C devices
along with their platform data, and I2C devices would behave much like
PNPACPI devices. (That is, both enumerate from board-specific tables.)
To match the exported i2c_new_device(), the previously-private function
i2c_unregister_device() is now exported.
Pending later patches using these new APIs, this is effectively a NOP.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
2007-05-02 01:26:31 +04:00
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|