sdio_func.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * include/linux/mmc/sdio_func.h
  4. *
  5. * Copyright 2007-2008 Pierre Ossman
  6. */
  7. #ifndef LINUX_MMC_SDIO_FUNC_H
  8. #define LINUX_MMC_SDIO_FUNC_H
  9. #include <linux/device.h>
  10. #include <linux/mod_devicetable.h>
  11. #include <linux/mmc/pm.h>
  12. struct mmc_card;
  13. struct sdio_func;
  14. typedef void (sdio_irq_handler_t)(struct sdio_func *);
  15. /*
  16. * SDIO function CIS tuple (unknown to the core)
  17. */
  18. struct sdio_func_tuple {
  19. struct sdio_func_tuple *next;
  20. unsigned char code;
  21. unsigned char size;
  22. unsigned char data[];
  23. };
  24. /*
  25. * SDIO function devices
  26. */
  27. struct sdio_func {
  28. struct mmc_card *card; /* the card this device belongs to */
  29. struct device dev; /* the device */
  30. sdio_irq_handler_t *irq_handler; /* IRQ callback */
  31. unsigned int num; /* function number */
  32. unsigned char class; /* standard interface class */
  33. unsigned short vendor; /* vendor id */
  34. unsigned short device; /* device id */
  35. unsigned max_blksize; /* maximum block size */
  36. unsigned cur_blksize; /* current block size */
  37. unsigned enable_timeout; /* max enable timeout in msec */
  38. unsigned int state; /* function state */
  39. #define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
  40. u8 *tmpbuf; /* DMA:able scratch buffer */
  41. u8 major_rev; /* major revision number */
  42. u8 minor_rev; /* minor revision number */
  43. unsigned num_info; /* number of info strings */
  44. const char **info; /* info strings */
  45. struct sdio_func_tuple *tuples;
  46. };
  47. #define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
  48. #define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
  49. #define sdio_func_id(f) (dev_name(&(f)->dev))
  50. #define sdio_get_drvdata(f) dev_get_drvdata(&(f)->dev)
  51. #define sdio_set_drvdata(f,d) dev_set_drvdata(&(f)->dev, d)
  52. #define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
  53. /*
  54. * SDIO function device driver
  55. */
  56. struct sdio_driver {
  57. char *name;
  58. const struct sdio_device_id *id_table;
  59. int (*probe)(struct sdio_func *, const struct sdio_device_id *);
  60. void (*remove)(struct sdio_func *);
  61. struct device_driver drv;
  62. };
  63. /**
  64. * SDIO_DEVICE - macro used to describe a specific SDIO device
  65. * @vend: the 16 bit manufacturer code
  66. * @dev: the 16 bit function id
  67. *
  68. * This macro is used to create a struct sdio_device_id that matches a
  69. * specific device. The class field will be set to SDIO_ANY_ID.
  70. */
  71. #define SDIO_DEVICE(vend,dev) \
  72. .class = SDIO_ANY_ID, \
  73. .vendor = (vend), .device = (dev)
  74. /**
  75. * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
  76. * @dev_class: the 8 bit standard interface code
  77. *
  78. * This macro is used to create a struct sdio_device_id that matches a
  79. * specific standard SDIO function type. The vendor and device fields will
  80. * be set to SDIO_ANY_ID.
  81. */
  82. #define SDIO_DEVICE_CLASS(dev_class) \
  83. .class = (dev_class), \
  84. .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
  85. extern int sdio_register_driver(struct sdio_driver *);
  86. extern void sdio_unregister_driver(struct sdio_driver *);
  87. /**
  88. * module_sdio_driver() - Helper macro for registering a SDIO driver
  89. * @__sdio_driver: sdio_driver struct
  90. *
  91. * Helper macro for SDIO drivers which do not do anything special in module
  92. * init/exit. This eliminates a lot of boilerplate. Each module may only
  93. * use this macro once, and calling it replaces module_init() and module_exit()
  94. */
  95. #define module_sdio_driver(__sdio_driver) \
  96. module_driver(__sdio_driver, sdio_register_driver, \
  97. sdio_unregister_driver)
  98. /*
  99. * SDIO I/O operations
  100. */
  101. extern void sdio_claim_host(struct sdio_func *func);
  102. extern void sdio_release_host(struct sdio_func *func);
  103. extern int sdio_enable_func(struct sdio_func *func);
  104. extern int sdio_disable_func(struct sdio_func *func);
  105. extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
  106. extern int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler);
  107. extern int sdio_release_irq(struct sdio_func *func);
  108. extern unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz);
  109. extern u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret);
  110. extern u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret);
  111. extern u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret);
  112. extern int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
  113. unsigned int addr, int count);
  114. extern int sdio_readsb(struct sdio_func *func, void *dst,
  115. unsigned int addr, int count);
  116. extern void sdio_writeb(struct sdio_func *func, u8 b,
  117. unsigned int addr, int *err_ret);
  118. extern void sdio_writew(struct sdio_func *func, u16 b,
  119. unsigned int addr, int *err_ret);
  120. extern void sdio_writel(struct sdio_func *func, u32 b,
  121. unsigned int addr, int *err_ret);
  122. extern u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte,
  123. unsigned int addr, int *err_ret);
  124. extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
  125. void *src, int count);
  126. extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
  127. void *src, int count);
  128. extern unsigned char sdio_f0_readb(struct sdio_func *func,
  129. unsigned int addr, int *err_ret);
  130. extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
  131. unsigned int addr, int *err_ret);
  132. extern mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func);
  133. extern int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags);
  134. extern void sdio_retune_crc_disable(struct sdio_func *func);
  135. extern void sdio_retune_crc_enable(struct sdio_func *func);
  136. extern void sdio_retune_hold_now(struct sdio_func *func);
  137. extern void sdio_retune_release(struct sdio_func *func);
  138. #endif /* LINUX_MMC_SDIO_FUNC_H */