xref: /freebsd/sys/dev/sdhci/sdhci_fdt_gpio.h (revision 72c59f1728c12fbdcd316c172708d8f3a60299be)
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  * $FreeBSD$
26  */
27 
28 /*
29  * Support routines usable by any SoC sdhci bridge driver that uses gpio pins
30  * for card detect and/or write protect, and uses FDT data to describe those
31  * pins.  A bridge driver need only supply a couple 2-line forwarding functions
32  * to connect the get_present and get_readonly accessors to the corresponding
33  * driver interface functions, and add setup/teardown calls to its attach and
34  * detach functions.
35  */
36 
37 #ifndef	_SDHCI_FDT_GPIO_H_
38 #define	_SDHCI_FDT_GPIO_H_
39 
40 struct sdhci_slot;
41 struct sdhci_fdt_gpio;
42 
43 /*
44  * sdhci_fdt_gpio_setup()
45  * sdhci_fdt_gpio_teardown()
46  *
47  * Process FDT properties that use gpio pins and set up interrupt handling (if
48  * supported by hardware) and accessor functions to read the pins.
49  *
50  * Setup cannot fail.  If the properties are not present, the accessors will
51  * return the values from standard sdhci registers.  If the gpio controller
52  * can't trigger interrupts on both edges, it configures the slot to use polling
53  * for card presence detection.  If it can't access the gpio pin at all it sets
54  * up the get_present() accessor to always return true.  Likewise the
55  * get_readonly() accessor always returns false if its pin can't be accessed.
56  */
57 struct sdhci_fdt_gpio *sdhci_fdt_gpio_setup(device_t dev, struct sdhci_slot *slot);
58 void sdhci_fdt_gpio_teardown(struct sdhci_fdt_gpio *gpio);
59 
60 /*
61  * sdhci_fdt_gpio_get_present()
62  * sdhci_fdt_gpio_get_readonly()
63  *
64  * Gpio pin state accessor functions.
65  */
66 bool sdhci_fdt_gpio_get_present(struct sdhci_fdt_gpio *gpio);
67 int  sdhci_fdt_gpio_get_readonly(struct sdhci_fdt_gpio *gpio);
68 
69 #endif
70