Path: blob/master/arch/powerpc/platforms/pasemi/misc.c
10819 views
/*1* Copyright (C) 2007 PA Semi, Inc2*3* Parts based on arch/powerpc/sysdev/fsl_soc.c:4*5* 2006 (c) MontaVista Software, Inc.6*7* This program is free software; you can redistribute it and/or modify it8* under the terms of the GNU General Public License as published by the9* Free Software Foundation; either version 2 of the License, or (at your10* option) any later version.11*/1213#include <linux/errno.h>14#include <linux/kernel.h>15#include <linux/pci.h>16#include <linux/of.h>17#include <linux/i2c.h>1819#ifdef CONFIG_I2C_BOARDINFO20/* The below is from fsl_soc.c. It's copied because since there are no21* official bus bindings at this time it doesn't make sense to share across22* the platforms, even though they happen to be common.23*/24struct i2c_driver_device {25char *of_device;26char *i2c_type;27};2829static struct i2c_driver_device i2c_devices[] __initdata = {30{"dallas,ds1338", "ds1338"},31};3233static int __init find_i2c_driver(struct device_node *node,34struct i2c_board_info *info)35{36int i;3738for (i = 0; i < ARRAY_SIZE(i2c_devices); i++) {39if (!of_device_is_compatible(node, i2c_devices[i].of_device))40continue;41if (strlcpy(info->type, i2c_devices[i].i2c_type,42I2C_NAME_SIZE) >= I2C_NAME_SIZE)43return -ENOMEM;44return 0;45}46return -ENODEV;47}4849static int __init pasemi_register_i2c_devices(void)50{51struct pci_dev *pdev;52struct device_node *adap_node;53struct device_node *node;5455pdev = NULL;56while ((pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa003, pdev))) {57adap_node = pci_device_to_OF_node(pdev);5859if (!adap_node)60continue;6162node = NULL;63while ((node = of_get_next_child(adap_node, node))) {64struct i2c_board_info info = {};65const u32 *addr;66int len;6768addr = of_get_property(node, "reg", &len);69if (!addr || len < sizeof(int) ||70*addr > (1 << 10) - 1) {71printk(KERN_WARNING72"pasemi_register_i2c_devices: "73"invalid i2c device entry\n");74continue;75}7677info.irq = irq_of_parse_and_map(node, 0);78if (info.irq == NO_IRQ)79info.irq = -1;8081if (find_i2c_driver(node, &info) < 0)82continue;8384info.addr = *addr;8586i2c_register_board_info(PCI_FUNC(pdev->devfn), &info,871);88}89}90return 0;91}92device_initcall(pasemi_register_i2c_devices);93#endif949596