misc.c 2.4 KB

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