12874c5fdSThomas 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> 14e6f6390aSChristophe Leroy #include <linux/of_irq.h> 15be2553ffSOlof Johansson #include <linux/i2c.h> 16be2553ffSOlof Johansson 17be2553ffSOlof Johansson #ifdef CONFIG_I2C_BOARDINFO 18be2553ffSOlof Johansson /* The below is from fsl_soc.c. It's copied because since there are no 19be2553ffSOlof Johansson * official bus bindings at this time it doesn't make sense to share across 20be2553ffSOlof Johansson * the platforms, even though they happen to be common. 21be2553ffSOlof Johansson */ 22be2553ffSOlof Johansson struct i2c_driver_device { 23be2553ffSOlof Johansson char *of_device; 24be2553ffSOlof Johansson char *i2c_type; 25be2553ffSOlof Johansson }; 26be2553ffSOlof Johansson 27be2553ffSOlof Johansson static struct i2c_driver_device i2c_devices[] __initdata = { 28238a871eSJean Delvare {"dallas,ds1338", "ds1338"}, 29be2553ffSOlof Johansson }; 30be2553ffSOlof Johansson 31be2553ffSOlof Johansson static int __init find_i2c_driver(struct device_node *node, 32be2553ffSOlof Johansson struct i2c_board_info *info) 33be2553ffSOlof Johansson { 34be2553ffSOlof Johansson int i; 35be2553ffSOlof Johansson 36be2553ffSOlof Johansson for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) { 37be2553ffSOlof Johansson if (!of_device_is_compatible(node, i2c_devices[i].of_device)) 38be2553ffSOlof Johansson continue; 39*24568549SRussell Currey if (strscpy(info->type, i2c_devices[i].i2c_type, I2C_NAME_SIZE) < 0) 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 59b6ac59d3SQinglang Miao for_each_child_of_node(adap_node, node) { 60be2553ffSOlof Johansson struct i2c_board_info info = {}; 61be2553ffSOlof Johansson const u32 *addr; 62be2553ffSOlof Johansson int len; 63be2553ffSOlof Johansson 64be2553ffSOlof Johansson addr = of_get_property(node, "reg", &len); 65be2553ffSOlof Johansson if (!addr || len < sizeof(int) || 66be2553ffSOlof Johansson *addr > (1 << 10) - 1) { 67e13606d7SDarren Stevens pr_warn("pasemi_register_i2c_devices: invalid i2c device entry\n"); 68be2553ffSOlof Johansson continue; 69be2553ffSOlof Johansson } 70be2553ffSOlof Johansson 71be2553ffSOlof Johansson info.irq = irq_of_parse_and_map(node, 0); 72ef24ba70SMichael Ellerman if (!info.irq) 73be2553ffSOlof Johansson info.irq = -1; 74be2553ffSOlof Johansson 75be2553ffSOlof Johansson if (find_i2c_driver(node, &info) < 0) 76be2553ffSOlof Johansson continue; 77be2553ffSOlof Johansson 78be2553ffSOlof Johansson info.addr = *addr; 79be2553ffSOlof Johansson 80be2553ffSOlof Johansson i2c_register_board_info(PCI_FUNC(pdev->devfn), &info, 81be2553ffSOlof Johansson 1); 82be2553ffSOlof Johansson } 83be2553ffSOlof Johansson } 84be2553ffSOlof Johansson return 0; 85be2553ffSOlof Johansson } 86be2553ffSOlof Johansson device_initcall(pasemi_register_i2c_devices); 87be2553ffSOlof Johansson #endif 88