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