1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2007 PA Semi, Inc
5 * Parts based on arch/powerpc/sysdev/fsl_soc.c:
7 * 2006 (c) MontaVista Software, Inc.
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
14 #include <linux/i2c.h>
16 #ifdef CONFIG_I2C_BOARDINFO
17 /* The below is from fsl_soc.c. It's copied because since there are no
18 * official bus bindings at this time it doesn't make sense to share across
19 * the platforms, even though they happen to be common.
21 struct i2c_driver_device
{
26 static struct i2c_driver_device i2c_devices
[] __initdata
= {
27 {"dallas,ds1338", "ds1338"},
30 static int __init
find_i2c_driver(struct device_node
*node
,
31 struct i2c_board_info
*info
)
35 for (i
= 0; i
< ARRAY_SIZE(i2c_devices
); i
++) {
36 if (!of_device_is_compatible(node
, i2c_devices
[i
].of_device
))
38 if (strlcpy(info
->type
, i2c_devices
[i
].i2c_type
,
39 I2C_NAME_SIZE
) >= I2C_NAME_SIZE
)
46 static int __init
pasemi_register_i2c_devices(void)
49 struct device_node
*adap_node
;
50 struct device_node
*node
;
53 while ((pdev
= pci_get_device(PCI_VENDOR_ID_PASEMI
, 0xa003, pdev
))) {
54 adap_node
= pci_device_to_OF_node(pdev
);
59 for_each_child_of_node(adap_node
, node
) {
60 struct i2c_board_info info
= {};
64 addr
= of_get_property(node
, "reg", &len
);
65 if (!addr
|| len
< sizeof(int) ||
66 *addr
> (1 << 10) - 1) {
67 pr_warn("pasemi_register_i2c_devices: invalid i2c device entry\n");
71 info
.irq
= irq_of_parse_and_map(node
, 0);
75 if (find_i2c_driver(node
, &info
) < 0)
80 i2c_register_board_info(PCI_FUNC(pdev
->devfn
), &info
,
86 device_initcall(pasemi_register_i2c_devices
);