Home | History | Annotate | Line # | Download | only in sdmmc
sdmmcchip.h revision 1.1.4.3
      1 /*	$NetBSD: sdmmcchip.h,v 1.1.4.3 2010/08/11 22:54:11 yamt Exp $	*/
      2 /*	$OpenBSD: sdmmcchip.h,v 1.3 2007/05/31 10:09:01 uwe Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 2006 Uwe Stuehler <uwe (at) openbsd.org>
      6  *
      7  * Permission to use, copy, modify, and distribute this software for any
      8  * purpose with or without fee is hereby granted, provided that the above
      9  * copyright notice and this permission notice appear in all copies.
     10  *
     11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
     12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     18  */
     19 
     20 #ifndef	_SDMMC_CHIP_H_
     21 #define	_SDMMC_CHIP_H_
     22 
     23 #include <sys/device.h>
     24 
     25 #include <machine/bus.h>
     26 
     27 struct sdmmc_command;
     28 
     29 typedef struct sdmmc_chip_functions *sdmmc_chipset_tag_t;
     30 typedef struct sdmmc_spi_chip_functions *sdmmc_spi_chipset_tag_t;
     31 typedef void *sdmmc_chipset_handle_t;
     32 
     33 struct sdmmc_chip_functions {
     34 	/* host controller reset */
     35 	int		(*host_reset)(sdmmc_chipset_handle_t);
     36 
     37 	/* host capabilities */
     38 	uint32_t	(*host_ocr)(sdmmc_chipset_handle_t);
     39 	int		(*host_maxblklen)(sdmmc_chipset_handle_t);
     40 
     41 	/* card detection */
     42 	int		(*card_detect)(sdmmc_chipset_handle_t);
     43 
     44 	/* write protect */
     45 	int		(*write_protect)(sdmmc_chipset_handle_t);
     46 
     47 	/* bus power, clock frequency and width */
     48 	int		(*bus_power)(sdmmc_chipset_handle_t, uint32_t);
     49 	int		(*bus_clock)(sdmmc_chipset_handle_t, int);
     50 	int		(*bus_width)(sdmmc_chipset_handle_t, int);
     51 
     52 	/* command execution */
     53 	void		(*exec_command)(sdmmc_chipset_handle_t,
     54 			    struct sdmmc_command *);
     55 
     56 	/* card interrupt */
     57 	void		(*card_enable_intr)(sdmmc_chipset_handle_t, int);
     58 	void		(*card_intr_ack)(sdmmc_chipset_handle_t);
     59 };
     60 
     61 /* host controller reset */
     62 #define sdmmc_chip_host_reset(tag, handle)				\
     63 	((tag)->host_reset((handle)))
     64 /* host capabilities */
     65 #define sdmmc_chip_host_ocr(tag, handle)				\
     66 	((tag)->host_ocr((handle)))
     67 #define sdmmc_chip_host_maxblklen(tag, handle)				\
     68 	((tag)->host_maxblklen((handle)))
     69 /* card detection */
     70 #define sdmmc_chip_card_detect(tag, handle)				\
     71 	((tag)->card_detect((handle)))
     72 /* write protect */
     73 #define sdmmc_chip_write_protect(tag, handle)				\
     74 	((tag)->write_protect((handle)))
     75 /* bus power, clock frequency and width */
     76 #define sdmmc_chip_bus_power(tag, handle, ocr)				\
     77 	((tag)->bus_power((handle), (ocr)))
     78 #define sdmmc_chip_bus_clock(tag, handle, freq)				\
     79 	((tag)->bus_clock((handle), (freq)))
     80 #define sdmmc_chip_bus_width(tag, handle, width)			\
     81 	((tag)->bus_width((handle), (width)))
     82 /* command execution */
     83 #define sdmmc_chip_exec_command(tag, handle, cmdp)			\
     84 	((tag)->exec_command((handle), (cmdp)))
     85 /* card interrupt */
     86 #define sdmmc_chip_card_enable_intr(tag, handle, enable)		\
     87 	((tag)->card_enable_intr((handle), (enable)))
     88 #define sdmmc_chip_card_intr_ack(tag, handle)				\
     89 	((tag)->card_intr_ack((handle)))
     90 
     91 /* clock frequencies for sdmmc_chip_bus_clock() */
     92 #define SDMMC_SDCLK_OFF		0
     93 #define SDMMC_SDCLK_400K	400
     94 
     95 /* SPI mode */
     96 struct sdmmc_spi_chip_functions {
     97 	/* card initialize */
     98 	void		(*initialize)(sdmmc_chipset_handle_t);
     99 };
    100 #define sdmmc_spi_chip_initialize(tag, handle)				\
    101 	((tag)->initialize((handle)))
    102 
    103 struct sdmmcbus_attach_args {
    104 	const char		*saa_busname;
    105 	sdmmc_chipset_tag_t	saa_sct;
    106 	sdmmc_spi_chipset_tag_t	saa_spi_sct;
    107 	sdmmc_chipset_handle_t	saa_sch;
    108 	bus_dma_tag_t		saa_dmat;
    109 	u_int			saa_clkmin;
    110 	u_int			saa_clkmax;
    111 	uint32_t		saa_caps;	/* see sdmmc_softc.sc_caps */
    112 };
    113 
    114 void	sdmmc_needs_discover(device_t);
    115 void	sdmmc_card_intr(device_t);
    116 void	sdmmc_delay(u_int);
    117 
    118 #endif	/* _SDMMC_CHIP_H_ */
    119