sunxi-rsb.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Allwinner Reduced Serial Bus Driver
  3. *
  4. * Copyright (c) 2015 Chen-Yu Tsai
  5. *
  6. * Author: Chen-Yu Tsai <wens@csie.org>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #ifndef _SUNXI_RSB_H
  13. #define _SUNXI_RSB_H
  14. #include <linux/device.h>
  15. #include <linux/regmap.h>
  16. #include <linux/types.h>
  17. struct sunxi_rsb;
  18. /**
  19. * struct sunxi_rsb_device - Basic representation of an RSB device
  20. * @dev: Driver model representation of the device.
  21. * @ctrl: RSB controller managing the bus hosting this device.
  22. * @rtaddr: This device's runtime address
  23. * @hwaddr: This device's hardware address
  24. */
  25. struct sunxi_rsb_device {
  26. struct device dev;
  27. struct sunxi_rsb *rsb;
  28. int irq;
  29. u8 rtaddr;
  30. u16 hwaddr;
  31. };
  32. static inline struct sunxi_rsb_device *to_sunxi_rsb_device(struct device *d)
  33. {
  34. return container_of(d, struct sunxi_rsb_device, dev);
  35. }
  36. static inline void *sunxi_rsb_device_get_drvdata(const struct sunxi_rsb_device *rdev)
  37. {
  38. return dev_get_drvdata(&rdev->dev);
  39. }
  40. static inline void sunxi_rsb_device_set_drvdata(struct sunxi_rsb_device *rdev,
  41. void *data)
  42. {
  43. dev_set_drvdata(&rdev->dev, data);
  44. }
  45. /**
  46. * struct sunxi_rsb_driver - RSB slave device driver
  47. * @driver: RSB device drivers should initialize name and owner field of
  48. * this structure.
  49. * @probe: binds this driver to a RSB device.
  50. * @remove: unbinds this driver from the RSB device.
  51. */
  52. struct sunxi_rsb_driver {
  53. struct device_driver driver;
  54. int (*probe)(struct sunxi_rsb_device *rdev);
  55. int (*remove)(struct sunxi_rsb_device *rdev);
  56. };
  57. static inline struct sunxi_rsb_driver *to_sunxi_rsb_driver(struct device_driver *d)
  58. {
  59. return container_of(d, struct sunxi_rsb_driver, driver);
  60. }
  61. int sunxi_rsb_driver_register(struct sunxi_rsb_driver *rdrv);
  62. /**
  63. * sunxi_rsb_driver_unregister() - unregister an RSB client driver
  64. * @rdrv: the driver to unregister
  65. */
  66. static inline void sunxi_rsb_driver_unregister(struct sunxi_rsb_driver *rdrv)
  67. {
  68. if (rdrv)
  69. driver_unregister(&rdrv->driver);
  70. }
  71. #define module_sunxi_rsb_driver(__sunxi_rsb_driver) \
  72. module_driver(__sunxi_rsb_driver, sunxi_rsb_driver_register, \
  73. sunxi_rsb_driver_unregister)
  74. struct regmap *__devm_regmap_init_sunxi_rsb(struct sunxi_rsb_device *rdev,
  75. const struct regmap_config *config,
  76. struct lock_class_key *lock_key,
  77. const char *lock_name);
  78. /**
  79. * devm_regmap_init_sunxi_rsb(): Initialise managed register map
  80. *
  81. * @rdev: Device that will be interacted with
  82. * @config: Configuration for register map
  83. *
  84. * The return value will be an ERR_PTR() on error or a valid pointer
  85. * to a struct regmap. The regmap will be automatically freed by the
  86. * device management code.
  87. */
  88. #define devm_regmap_init_sunxi_rsb(rdev, config) \
  89. __regmap_lockdep_wrapper(__devm_regmap_init_sunxi_rsb, #config, \
  90. rdev, config)
  91. #endif /* _SUNXI_RSB_H */