Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  include/linux/mmc/sdio_func.h
0004  *
0005  *  Copyright 2007-2008 Pierre Ossman
0006  */
0007 
0008 #ifndef LINUX_MMC_SDIO_FUNC_H
0009 #define LINUX_MMC_SDIO_FUNC_H
0010 
0011 #include <linux/device.h>
0012 #include <linux/mod_devicetable.h>
0013 
0014 #include <linux/mmc/pm.h>
0015 
0016 struct mmc_card;
0017 struct sdio_func;
0018 
0019 typedef void (sdio_irq_handler_t)(struct sdio_func *);
0020 
0021 /*
0022  * SDIO function CIS tuple (unknown to the core)
0023  */
0024 struct sdio_func_tuple {
0025     struct sdio_func_tuple *next;
0026     unsigned char code;
0027     unsigned char size;
0028     unsigned char data[];
0029 };
0030 
0031 /*
0032  * SDIO function devices
0033  */
0034 struct sdio_func {
0035     struct mmc_card     *card;      /* the card this device belongs to */
0036     struct device       dev;        /* the device */
0037     sdio_irq_handler_t  *irq_handler;   /* IRQ callback */
0038     unsigned int        num;        /* function number */
0039 
0040     unsigned char       class;      /* standard interface class */
0041     unsigned short      vendor;     /* vendor id */
0042     unsigned short      device;     /* device id */
0043 
0044     unsigned        max_blksize;    /* maximum block size */
0045     unsigned        cur_blksize;    /* current block size */
0046 
0047     unsigned        enable_timeout; /* max enable timeout in msec */
0048 
0049     unsigned int        state;      /* function state */
0050 #define SDIO_STATE_PRESENT  (1<<0)      /* present in sysfs */
0051 
0052     u8          *tmpbuf;    /* DMA:able scratch buffer */
0053 
0054     u8          major_rev;  /* major revision number */
0055     u8          minor_rev;  /* minor revision number */
0056     unsigned        num_info;   /* number of info strings */
0057     const char      **info;     /* info strings */
0058 
0059     struct sdio_func_tuple *tuples;
0060 };
0061 
0062 #define sdio_func_present(f)    ((f)->state & SDIO_STATE_PRESENT)
0063 
0064 #define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
0065 
0066 #define sdio_func_id(f)     (dev_name(&(f)->dev))
0067 
0068 #define sdio_get_drvdata(f) dev_get_drvdata(&(f)->dev)
0069 #define sdio_set_drvdata(f,d)   dev_set_drvdata(&(f)->dev, d)
0070 #define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
0071 
0072 /*
0073  * SDIO function device driver
0074  */
0075 struct sdio_driver {
0076     char *name;
0077     const struct sdio_device_id *id_table;
0078 
0079     int (*probe)(struct sdio_func *, const struct sdio_device_id *);
0080     void (*remove)(struct sdio_func *);
0081 
0082     struct device_driver drv;
0083 };
0084 
0085 /**
0086  * SDIO_DEVICE - macro used to describe a specific SDIO device
0087  * @vend: the 16 bit manufacturer code
0088  * @dev: the 16 bit function id
0089  *
0090  * This macro is used to create a struct sdio_device_id that matches a
0091  * specific device. The class field will be set to SDIO_ANY_ID.
0092  */
0093 #define SDIO_DEVICE(vend,dev) \
0094     .class = SDIO_ANY_ID, \
0095     .vendor = (vend), .device = (dev)
0096 
0097 /**
0098  * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
0099  * @dev_class: the 8 bit standard interface code
0100  *
0101  * This macro is used to create a struct sdio_device_id that matches a
0102  * specific standard SDIO function type.  The vendor and device fields will
0103  * be set to SDIO_ANY_ID.
0104  */
0105 #define SDIO_DEVICE_CLASS(dev_class) \
0106     .class = (dev_class), \
0107     .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
0108 
0109 extern int sdio_register_driver(struct sdio_driver *);
0110 extern void sdio_unregister_driver(struct sdio_driver *);
0111 
0112 /**
0113  * module_sdio_driver() - Helper macro for registering a SDIO driver
0114  * @__sdio_driver: sdio_driver struct
0115  *
0116  * Helper macro for SDIO drivers which do not do anything special in module
0117  * init/exit. This eliminates a lot of boilerplate. Each module may only
0118  * use this macro once, and calling it replaces module_init() and module_exit()
0119  */
0120 #define module_sdio_driver(__sdio_driver) \
0121     module_driver(__sdio_driver, sdio_register_driver, \
0122               sdio_unregister_driver)
0123 
0124 /*
0125  * SDIO I/O operations
0126  */
0127 extern void sdio_claim_host(struct sdio_func *func);
0128 extern void sdio_release_host(struct sdio_func *func);
0129 
0130 extern int sdio_enable_func(struct sdio_func *func);
0131 extern int sdio_disable_func(struct sdio_func *func);
0132 
0133 extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
0134 
0135 extern int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler);
0136 extern int sdio_release_irq(struct sdio_func *func);
0137 
0138 extern unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz);
0139 
0140 extern u8 sdio_readb(struct sdio_func *func, unsigned int addr, int *err_ret);
0141 extern u16 sdio_readw(struct sdio_func *func, unsigned int addr, int *err_ret);
0142 extern u32 sdio_readl(struct sdio_func *func, unsigned int addr, int *err_ret);
0143 
0144 extern int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
0145     unsigned int addr, int count);
0146 extern int sdio_readsb(struct sdio_func *func, void *dst,
0147     unsigned int addr, int count);
0148 
0149 extern void sdio_writeb(struct sdio_func *func, u8 b,
0150     unsigned int addr, int *err_ret);
0151 extern void sdio_writew(struct sdio_func *func, u16 b,
0152     unsigned int addr, int *err_ret);
0153 extern void sdio_writel(struct sdio_func *func, u32 b,
0154     unsigned int addr, int *err_ret);
0155 
0156 extern u8 sdio_writeb_readb(struct sdio_func *func, u8 write_byte,
0157     unsigned int addr, int *err_ret);
0158 
0159 extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
0160     void *src, int count);
0161 extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
0162     void *src, int count);
0163 
0164 extern unsigned char sdio_f0_readb(struct sdio_func *func,
0165     unsigned int addr, int *err_ret);
0166 extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
0167     unsigned int addr, int *err_ret);
0168 
0169 extern mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func);
0170 extern int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags);
0171 
0172 extern void sdio_retune_crc_disable(struct sdio_func *func);
0173 extern void sdio_retune_crc_enable(struct sdio_func *func);
0174 
0175 extern void sdio_retune_hold_now(struct sdio_func *func);
0176 extern void sdio_retune_release(struct sdio_func *func);
0177 
0178 #endif /* LINUX_MMC_SDIO_FUNC_H */