misc.c 2.0 KB

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