xref: /freebsd/sys/dev/sdhci/sdhci_fdt_gpio.h (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1 /*-
2  * Copyright (c) 2017 Ian Lepore <ian@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 /*
27  * Support routines usable by any SoC sdhci bridge driver that uses gpio pins
28  * for card detect and/or write protect, and uses FDT data to describe those
29  * pins.  A bridge driver need only supply a couple 2-line forwarding functions
30  * to connect the get_present and get_readonly accessors to the corresponding
31  * driver interface functions, and add setup/teardown calls to its attach and
32  * detach functions.
33  */
34 
35 #ifndef	_SDHCI_FDT_GPIO_H_
36 #define	_SDHCI_FDT_GPIO_H_
37 
38 struct sdhci_slot;
39 struct sdhci_fdt_gpio;
40 
41 /*
42  * sdhci_fdt_gpio_setup()
43  * sdhci_fdt_gpio_teardown()
44  *
45  * Process FDT properties that use gpio pins and set up interrupt handling (if
46  * supported by hardware) and accessor functions to read the pins.
47  *
48  * Setup cannot fail.  If the properties are not present, the accessors will
49  * return the values from standard sdhci registers.  If the gpio controller
50  * can't trigger interrupts on both edges, it configures the slot to use polling
51  * for card presence detection.  If it can't access the gpio pin at all it sets
52  * up the get_present() accessor to always return true.  Likewise the
53  * get_readonly() accessor always returns false if its pin can't be accessed.
54  */
55 struct sdhci_fdt_gpio *sdhci_fdt_gpio_setup(device_t dev, struct sdhci_slot *slot);
56 void sdhci_fdt_gpio_teardown(struct sdhci_fdt_gpio *gpio);
57 
58 /*
59  * sdhci_fdt_gpio_get_present()
60  * sdhci_fdt_gpio_get_readonly()
61  *
62  * Gpio pin state accessor functions.
63  */
64 bool sdhci_fdt_gpio_get_present(struct sdhci_fdt_gpio *gpio);
65 int  sdhci_fdt_gpio_get_readonly(struct sdhci_fdt_gpio *gpio);
66 
67 #endif
68