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