xref: /freebsd/sys/dev/mmc/mmcbrvar.h (revision 07da3bb5d56c85325252cd1a9ae32fb5d3536dea)
1114b4164SWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4114b4164SWarner Losh  * Copyright (c) 2006 Bernd Walter.  All rights reserved.
5f86e6000SWarner Losh  * Copyright (c) 2006 M. Warner Losh <imp@FreeBSD.org>
6114b4164SWarner Losh  *
7114b4164SWarner Losh  * Redistribution and use in source and binary forms, with or without
8114b4164SWarner Losh  * modification, are permitted provided that the following conditions
9114b4164SWarner Losh  * are met:
10114b4164SWarner Losh  * 1. Redistributions of source code must retain the above copyright
11114b4164SWarner Losh  *    notice, this list of conditions and the following disclaimer.
12114b4164SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
13114b4164SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
14114b4164SWarner Losh  *    documentation and/or other materials provided with the distribution.
15114b4164SWarner Losh  *
16114b4164SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17114b4164SWarner Losh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18114b4164SWarner Losh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19114b4164SWarner Losh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20114b4164SWarner Losh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21114b4164SWarner Losh  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22114b4164SWarner Losh  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23114b4164SWarner Losh  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24114b4164SWarner Losh  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25114b4164SWarner Losh  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26114b4164SWarner Losh  *
2714eced72SWarner Losh  * Portions of this software may have been developed with reference to
2814eced72SWarner Losh  * the SD Simplified Specification.  The following disclaimer may apply:
2914eced72SWarner Losh  *
3014eced72SWarner Losh  * The following conditions apply to the release of the simplified
3114eced72SWarner Losh  * specification ("Simplified Specification") by the SD Card Association and
3214eced72SWarner Losh  * the SD Group. The Simplified Specification is a subset of the complete SD
3314eced72SWarner Losh  * Specification which is owned by the SD Card Association and the SD
3414eced72SWarner Losh  * Group. This Simplified Specification is provided on a non-confidential
3514eced72SWarner Losh  * basis subject to the disclaimers below. Any implementation of the
3614eced72SWarner Losh  * Simplified Specification may require a license from the SD Card
3714eced72SWarner Losh  * Association, SD Group, SD-3C LLC or other third parties.
3814eced72SWarner Losh  *
3914eced72SWarner Losh  * Disclaimers:
4014eced72SWarner Losh  *
4114eced72SWarner Losh  * The information contained in the Simplified Specification is presented only
4214eced72SWarner Losh  * as a standard specification for SD Cards and SD Host/Ancillary products and
4314eced72SWarner Losh  * is provided "AS-IS" without any representations or warranties of any
4414eced72SWarner Losh  * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
4514eced72SWarner Losh  * Card Association for any damages, any infringements of patents or other
4614eced72SWarner Losh  * right of the SD Group, SD-3C LLC, the SD Card Association or any third
4714eced72SWarner Losh  * parties, which may result from its use. No license is granted by
4814eced72SWarner Losh  * implication, estoppel or otherwise under any patent or other rights of the
4914eced72SWarner Losh  * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
5014eced72SWarner Losh  * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
5114eced72SWarner Losh  * or the SD Card Association to disclose or distribute any technical
5214eced72SWarner Losh  * information, know-how or other confidential information to any third party.
53114b4164SWarner Losh  */
54114b4164SWarner Losh 
55114b4164SWarner Losh #ifndef DEV_MMC_MMCBRVAR_H
56114b4164SWarner Losh #define	DEV_MMC_MMCBRVAR_H
57114b4164SWarner Losh 
587aa65846SMarius Strobl #include <dev/mmc/mmcreg.h>
59aca38eabSMarius Strobl 
60114b4164SWarner Losh #include "mmcbr_if.h"
61114b4164SWarner Losh 
62114b4164SWarner Losh enum mmcbr_device_ivars {
63*07da3bb5SRuslan Bukin     MMCBR_IVAR_BUS_TYPE,
64114b4164SWarner Losh     MMCBR_IVAR_BUS_MODE,
65114b4164SWarner Losh     MMCBR_IVAR_BUS_WIDTH,
66114b4164SWarner Losh     MMCBR_IVAR_CHIP_SELECT,
67114b4164SWarner Losh     MMCBR_IVAR_CLOCK,
68114b4164SWarner Losh     MMCBR_IVAR_F_MIN,
69114b4164SWarner Losh     MMCBR_IVAR_F_MAX,
70114b4164SWarner Losh     MMCBR_IVAR_HOST_OCR,
71114b4164SWarner Losh     MMCBR_IVAR_MODE,
72114b4164SWarner Losh     MMCBR_IVAR_OCR,
73114b4164SWarner Losh     MMCBR_IVAR_POWER_MODE,
74aca38eabSMarius Strobl     MMCBR_IVAR_RETUNE_REQ,
75114b4164SWarner Losh     MMCBR_IVAR_VDD,
760f34084fSMarius Strobl     MMCBR_IVAR_VCCQ,
77bd2bbf24SWarner Losh     MMCBR_IVAR_CAPS,
78c18f1e26SAlexander Motin     MMCBR_IVAR_TIMING,
7972dec079SMarius Strobl     MMCBR_IVAR_MAX_DATA,
8072dec079SMarius Strobl     MMCBR_IVAR_MAX_BUSY_TIMEOUT
81114b4164SWarner Losh };
82114b4164SWarner Losh 
83114b4164SWarner Losh /*
8472dec079SMarius Strobl  * Simplified accessors for bridge devices
85114b4164SWarner Losh  */
86114b4164SWarner Losh #define	MMCBR_ACCESSOR(var, ivar, type)					\
87114b4164SWarner Losh 	__BUS_ACCESSOR(mmcbr, var, MMCBR, ivar, type)
88114b4164SWarner Losh 
MMCBR_ACCESSOR(bus_mode,BUS_MODE,int)89114b4164SWarner Losh MMCBR_ACCESSOR(bus_mode, BUS_MODE, int)
90114b4164SWarner Losh MMCBR_ACCESSOR(bus_width, BUS_WIDTH, int)
91114b4164SWarner Losh MMCBR_ACCESSOR(chip_select, CHIP_SELECT, int)
92114b4164SWarner Losh MMCBR_ACCESSOR(clock, CLOCK, int)
93114b4164SWarner Losh MMCBR_ACCESSOR(f_max, F_MAX, int)
94114b4164SWarner Losh MMCBR_ACCESSOR(f_min, F_MIN, int)
95114b4164SWarner Losh MMCBR_ACCESSOR(host_ocr, HOST_OCR, int)
96114b4164SWarner Losh MMCBR_ACCESSOR(mode, MODE, int)
97114b4164SWarner Losh MMCBR_ACCESSOR(ocr, OCR, int)
98114b4164SWarner Losh MMCBR_ACCESSOR(power_mode, POWER_MODE, int)
99114b4164SWarner Losh MMCBR_ACCESSOR(vdd, VDD, int)
1000f34084fSMarius Strobl MMCBR_ACCESSOR(vccq, VCCQ, int)
101bd2bbf24SWarner Losh MMCBR_ACCESSOR(caps, CAPS, int)
102c18f1e26SAlexander Motin MMCBR_ACCESSOR(timing, TIMING, int)
1033a4a2557SAlexander Motin MMCBR_ACCESSOR(max_data, MAX_DATA, int)
10472dec079SMarius Strobl MMCBR_ACCESSOR(max_busy_timeout, MAX_BUSY_TIMEOUT, u_int)
105114b4164SWarner Losh 
106114b4164SWarner Losh static int __inline
1077f6921aeSMarius Strobl mmcbr_get_retune_req(device_t dev)
1087f6921aeSMarius Strobl {
1097f6921aeSMarius Strobl 	uintptr_t v;
1107f6921aeSMarius Strobl 
1117f6921aeSMarius Strobl 	if (__predict_false(BUS_READ_IVAR(device_get_parent(dev), dev,
1127f6921aeSMarius Strobl 	    MMCBR_IVAR_RETUNE_REQ, &v) != 0))
1137f6921aeSMarius Strobl 		return (retune_req_none);
1147f6921aeSMarius Strobl 	return ((int)v);
1157f6921aeSMarius Strobl }
1167f6921aeSMarius Strobl 
117*07da3bb5SRuslan Bukin static int __inline
mmcbr_get_bus_type(device_t dev)118*07da3bb5SRuslan Bukin mmcbr_get_bus_type(device_t dev)
119*07da3bb5SRuslan Bukin {
120*07da3bb5SRuslan Bukin 	uintptr_t v;
121*07da3bb5SRuslan Bukin 
122*07da3bb5SRuslan Bukin 	if (__predict_false(BUS_READ_IVAR(device_get_parent(dev), dev,
123*07da3bb5SRuslan Bukin 	    MMCBR_IVAR_BUS_TYPE, &v) != 0))
124*07da3bb5SRuslan Bukin 		return (bus_type_default);
125*07da3bb5SRuslan Bukin 	return ((int)v);
126*07da3bb5SRuslan Bukin }
127*07da3bb5SRuslan Bukin 
1287f6921aeSMarius Strobl /*
1297f6921aeSMarius Strobl  * Convenience wrappers for the mmcbr interface
1307f6921aeSMarius Strobl  */
1317f6921aeSMarius Strobl static int __inline
mmcbr_update_ios(device_t dev)132114b4164SWarner Losh mmcbr_update_ios(device_t dev)
133114b4164SWarner Losh {
134b440e965SMarius Strobl 
135114b4164SWarner Losh 	return (MMCBR_UPDATE_IOS(device_get_parent(dev), dev));
136114b4164SWarner Losh }
137114b4164SWarner Losh 
13840fab6e7SWarner Losh static int __inline
mmcbr_tune(device_t dev,bool hs400)139aca38eabSMarius Strobl mmcbr_tune(device_t dev, bool hs400)
140aca38eabSMarius Strobl {
141aca38eabSMarius Strobl 
142aca38eabSMarius Strobl 	return (MMCBR_TUNE(device_get_parent(dev), dev, hs400));
143aca38eabSMarius Strobl }
144aca38eabSMarius Strobl 
145aca38eabSMarius Strobl static int __inline
mmcbr_retune(device_t dev,bool reset)146aca38eabSMarius Strobl mmcbr_retune(device_t dev, bool reset)
147aca38eabSMarius Strobl {
148aca38eabSMarius Strobl 
149aca38eabSMarius Strobl 	return (MMCBR_RETUNE(device_get_parent(dev), dev, reset));
150aca38eabSMarius Strobl }
151aca38eabSMarius Strobl 
152aca38eabSMarius Strobl static int __inline
mmcbr_switch_vccq(device_t dev)1530f34084fSMarius Strobl mmcbr_switch_vccq(device_t dev)
1540f34084fSMarius Strobl {
1550f34084fSMarius Strobl 
1560f34084fSMarius Strobl 	return (MMCBR_SWITCH_VCCQ(device_get_parent(dev), dev));
1570f34084fSMarius Strobl }
1580f34084fSMarius Strobl 
1590f34084fSMarius Strobl static int __inline
mmcbr_get_ro(device_t dev)16040fab6e7SWarner Losh mmcbr_get_ro(device_t dev)
16140fab6e7SWarner Losh {
162b440e965SMarius Strobl 
16340fab6e7SWarner Losh 	return (MMCBR_GET_RO(device_get_parent(dev), dev));
16440fab6e7SWarner Losh }
16540fab6e7SWarner Losh 
166114b4164SWarner Losh #endif /* DEV_MMC_MMCBRVAR_H */
167