1311734Sian/*-
2311734Sian * Copyright (c) 2017 Ian Lepore <ian@freebsd.org>
3311734Sian * All rights reserved.
4311734Sian *
5311734Sian * Redistribution and use in source and binary forms, with or without
6311734Sian * modification, are permitted provided that the following conditions
7311734Sian * are met:
8311734Sian * 1. Redistributions of source code must retain the above copyright
9311734Sian *    notice, this list of conditions and the following disclaimer.
10311734Sian * 2. Redistributions in binary form must reproduce the above copyright
11311734Sian *    notice, this list of conditions and the following disclaimer in the
12311734Sian *    documentation and/or other materials provided with the distribution.
13311734Sian *
14311734Sian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15311734Sian * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16311734Sian * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17311734Sian * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18311734Sian * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19311734Sian * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20311734Sian * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21311734Sian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22311734Sian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23311734Sian * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24311734Sian *
25311734Sian * $FreeBSD: stable/11/sys/dev/sdhci/sdhci_fdt_gpio.h 314508 2017-03-01 20:22:25Z ian $
26311734Sian */
27311734Sian
28311734Sian/*
29311734Sian * Support routines usable by any SoC sdhci bridge driver that uses gpio pins
30311734Sian * for card detect and/or write protect, and uses FDT data to describe those
31311734Sian * pins.  A bridge driver need only supply a couple 2-line forwarding functions
32311734Sian * to connect the get_present and get_readonly accessors to the corresponding
33311734Sian * driver interface functions, and add setup/teardown calls to its attach and
34311734Sian * detach functions.
35311734Sian */
36311734Sian
37311734Sian#ifndef	_SDHCI_FDT_GPIO_H_
38311734Sian#define	_SDHCI_FDT_GPIO_H_
39311734Sian
40311734Sianstruct sdhci_slot;
41311734Sianstruct sdhci_fdt_gpio;
42311734Sian
43311734Sian/*
44311734Sian * sdhci_fdt_gpio_setup()
45311734Sian * sdhci_fdt_gpio_teardown()
46311734Sian *
47311734Sian * Process FDT properties that use gpio pins and set up interrupt handling (if
48311734Sian * supported by hardware) and accessor functions to read the pins.
49311734Sian *
50311734Sian * Setup cannot fail.  If the properties are not present, the accessors will
51311734Sian * return the values from standard sdhci registers.  If the gpio controller
52311734Sian * can't trigger interrupts on both edges, it configures the slot to use polling
53311734Sian * for card presence detection.  If it can't access the gpio pin at all it sets
54311734Sian * up the get_present() accessor to always return true.  Likewise the
55311734Sian * get_readonly() accessor always returns false if its pin can't be accessed.
56311734Sian */
57311734Sianstruct sdhci_fdt_gpio *sdhci_fdt_gpio_setup(device_t dev, struct sdhci_slot *slot);
58311734Sianvoid sdhci_fdt_gpio_teardown(struct sdhci_fdt_gpio *gpio);
59311734Sian
60311734Sian/*
61311734Sian * sdhci_fdt_gpio_get_present()
62311734Sian * sdhci_fdt_gpio_get_readonly()
63311734Sian *
64311734Sian * Gpio pin state accessor functions.
65311734Sian */
66311734Sianbool sdhci_fdt_gpio_get_present(struct sdhci_fdt_gpio *gpio);
67311734Sianint  sdhci_fdt_gpio_get_readonly(struct sdhci_fdt_gpio *gpio);
68311734Sian
69311734Sian#endif
70