1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2be2553ffSOlof Johansson /* 3be2553ffSOlof Johansson * Copyright (C) 2007 PA Semi, Inc 4be2553ffSOlof Johansson * 5be2553ffSOlof Johansson * Parts based on arch/powerpc/sysdev/fsl_soc.c: 6be2553ffSOlof Johansson * 7be2553ffSOlof Johansson * 2006 (c) MontaVista Software, Inc. 8be2553ffSOlof Johansson */ 9be2553ffSOlof Johansson 10be2553ffSOlof Johansson #include <linux/errno.h> 11be2553ffSOlof Johansson #include <linux/kernel.h> 12be2553ffSOlof Johansson #include <linux/pci.h> 13be2553ffSOlof Johansson #include <linux/of.h> 14be2553ffSOlof Johansson #include <linux/i2c.h> 15be2553ffSOlof Johansson 16be2553ffSOlof Johansson #ifdef CONFIG_I2C_BOARDINFO 17be2553ffSOlof Johansson /* The below is from fsl_soc.c. It's copied because since there are no 18be2553ffSOlof Johansson * official bus bindings at this time it doesn't make sense to share across 19be2553ffSOlof Johansson * the platforms, even though they happen to be common. 20be2553ffSOlof Johansson */ 21be2553ffSOlof Johansson struct i2c_driver_device { 22be2553ffSOlof Johansson char *of_device; 23be2553ffSOlof Johansson char *i2c_type; 24be2553ffSOlof Johansson }; 25be2553ffSOlof Johansson 26be2553ffSOlof Johansson static struct i2c_driver_device i2c_devices[] __initdata = { 27238a871eSJean Delvare {"dallas,ds1338", "ds1338"}, 28be2553ffSOlof Johansson }; 29be2553ffSOlof Johansson 30be2553ffSOlof Johansson static int __init find_i2c_driver(struct device_node *node, 31be2553ffSOlof Johansson struct i2c_board_info *info) 32be2553ffSOlof Johansson { 33be2553ffSOlof Johansson int i; 34be2553ffSOlof Johansson 35be2553ffSOlof Johansson for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) { 36be2553ffSOlof Johansson if (!of_device_is_compatible(node, i2c_devices[i].of_device)) 37be2553ffSOlof Johansson continue; 38238a871eSJean Delvare if (strlcpy(info->type, i2c_devices[i].i2c_type, 39be2553ffSOlof Johansson I2C_NAME_SIZE) >= I2C_NAME_SIZE) 40be2553ffSOlof Johansson return -ENOMEM; 41be2553ffSOlof Johansson return 0; 42be2553ffSOlof Johansson } 43be2553ffSOlof Johansson return -ENODEV; 44be2553ffSOlof Johansson } 45be2553ffSOlof Johansson 46be2553ffSOlof Johansson static int __init pasemi_register_i2c_devices(void) 47be2553ffSOlof Johansson { 48be2553ffSOlof Johansson struct pci_dev *pdev; 49be2553ffSOlof Johansson struct device_node *adap_node; 50be2553ffSOlof Johansson struct device_node *node; 51be2553ffSOlof Johansson 52be2553ffSOlof Johansson pdev = NULL; 53be2553ffSOlof Johansson while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) { 54be2553ffSOlof Johansson adap_node = pci_device_to_OF_node(pdev); 55be2553ffSOlof Johansson 56be2553ffSOlof Johansson if (!adap_node) 57be2553ffSOlof Johansson continue; 58be2553ffSOlof Johansson 59be2553ffSOlof Johansson node = NULL; 60be2553ffSOlof Johansson while ((node = of_get_next_child(adap_node, node))) { 61be2553ffSOlof Johansson struct i2c_board_info info = {}; 62be2553ffSOlof Johansson const u32 *addr; 63be2553ffSOlof Johansson int len; 64be2553ffSOlof Johansson 65be2553ffSOlof Johansson addr = of_get_property(node, "reg", &len); 66be2553ffSOlof Johansson if (!addr || len < sizeof(int) || 67be2553ffSOlof Johansson *addr > (1 << 10) - 1) { 68e13606d7SDarren Stevens pr_warn("pasemi_register_i2c_devices: invalid i2c device entry\n"); 69be2553ffSOlof Johansson continue; 70be2553ffSOlof Johansson } 71be2553ffSOlof Johansson 72be2553ffSOlof Johansson info.irq = irq_of_parse_and_map(node, 0); 73ef24ba70SMichael Ellerman if (!info.irq) 74be2553ffSOlof Johansson info.irq = -1; 75be2553ffSOlof Johansson 76be2553ffSOlof Johansson if (find_i2c_driver(node, &info) < 0) 77be2553ffSOlof Johansson continue; 78be2553ffSOlof Johansson 79be2553ffSOlof Johansson info.addr = *addr; 80be2553ffSOlof Johansson 81be2553ffSOlof Johansson i2c_register_board_info(PCI_FUNC(pdev->devfn), &info, 82be2553ffSOlof Johansson 1); 83be2553ffSOlof Johansson } 84be2553ffSOlof Johansson } 85be2553ffSOlof Johansson return 0; 86be2553ffSOlof Johansson } 87be2553ffSOlof Johansson device_initcall(pasemi_register_i2c_devices); 88be2553ffSOlof Johansson #endif 89