of_platform.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _LINUX_OF_PLATFORM_H
  2. #define _LINUX_OF_PLATFORM_H
  3. /*
  4. * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
  5. * <benh@kernel.crashing.org>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. */
  13. #ifdef CONFIG_OF_DEVICE
  14. #include <linux/device.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/pm.h>
  17. #include <linux/of_device.h>
  18. #include <linux/platform_device.h>
  19. /**
  20. * struct of_dev_auxdata - lookup table entry for device names & platform_data
  21. * @compatible: compatible value of node to match against node
  22. * @phys_addr: Start address of registers to match against node
  23. * @name: Name to assign for matching nodes
  24. * @platform_data: platform_data to assign for matching nodes
  25. *
  26. * This lookup table allows the caller of of_platform_populate() to override
  27. * the names of devices when creating devices from the device tree. The table
  28. * should be terminated with an empty entry. It also allows the platform_data
  29. * pointer to be set.
  30. *
  31. * The reason for this functionality is that some Linux infrastructure uses
  32. * the device name to look up a specific device, but the Linux-specific names
  33. * are not encoded into the device tree, so the kernel needs to provide specific
  34. * values.
  35. *
  36. * Note: Using an auxdata lookup table should be considered a last resort when
  37. * converting a platform to use the DT. Normally the automatically generated
  38. * device name will not matter, and drivers should obtain data from the device
  39. * node instead of from an anonymouns platform_data pointer.
  40. */
  41. struct of_dev_auxdata {
  42. char *compatible;
  43. resource_size_t phys_addr;
  44. char *name;
  45. void *platform_data;
  46. };
  47. /* Macro to simplify populating a lookup table */
  48. #define OF_DEV_AUXDATA(_compat,_phys,_name,_pdata) \
  49. { .compatible = _compat, .phys_addr = _phys, .name = _name, \
  50. .platform_data = _pdata }
  51. /**
  52. * of_platform_driver - Legacy of-aware driver for platform devices.
  53. *
  54. * An of_platform_driver driver is attached to a basic platform_device on
  55. * the ibm ebus (ibmebus_bus_type).
  56. */
  57. struct of_platform_driver
  58. {
  59. int (*probe)(struct platform_device* dev,
  60. const struct of_device_id *match);
  61. int (*remove)(struct platform_device* dev);
  62. int (*suspend)(struct platform_device* dev, pm_message_t state);
  63. int (*resume)(struct platform_device* dev);
  64. int (*shutdown)(struct platform_device* dev);
  65. struct device_driver driver;
  66. };
  67. #define to_of_platform_driver(drv) \
  68. container_of(drv,struct of_platform_driver, driver)
  69. extern const struct of_device_id of_default_bus_match_table[];
  70. /* Platform drivers register/unregister */
  71. extern struct platform_device *of_device_alloc(struct device_node *np,
  72. const char *bus_id,
  73. struct device *parent);
  74. extern struct platform_device *of_find_device_by_node(struct device_node *np);
  75. #ifdef CONFIG_OF_ADDRESS /* device reg helpers depend on OF_ADDRESS */
  76. /* Platform devices and busses creation */
  77. extern struct platform_device *of_platform_device_create(struct device_node *np,
  78. const char *bus_id,
  79. struct device *parent);
  80. extern int of_platform_bus_probe(struct device_node *root,
  81. const struct of_device_id *matches,
  82. struct device *parent);
  83. extern int of_platform_populate(struct device_node *root,
  84. const struct of_device_id *matches,
  85. const struct of_dev_auxdata *lookup,
  86. struct device *parent);
  87. #endif /* CONFIG_OF_ADDRESS */
  88. #endif /* CONFIG_OF_DEVICE */
  89. #if !defined(CONFIG_OF_ADDRESS)
  90. struct of_dev_auxdata;
  91. static inline int of_platform_populate(struct device_node *root,
  92. const struct of_device_id *matches,
  93. const struct of_dev_auxdata *lookup,
  94. struct device *parent)
  95. {
  96. return -ENODEV;
  97. }
  98. #endif /* !CONFIG_OF_ADDRESS */
  99. #endif /* _LINUX_OF_PLATFORM_H */