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