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