spibusvar.h revision 300710
1278957Simp/*-
2278957Simp * Copyright (c) 2006 M. Warner Losh
3278957Simp * All rights reserved.
4278957Simp *
5278957Simp * Redistribution and use in source and binary forms, with or without
6278957Simp * modification, are permitted provided that the following conditions
7278957Simp * are met:
8278957Simp * 1. Redistributions of source code must retain the above copyright
9278957Simp *    notice, this list of conditions and the following disclaimer.
10278957Simp * 2. Redistributions in binary form must reproduce the above copyright
11278957Simp *    notice, this list of conditions and the following disclaimer in the
12278957Simp *    documentation and/or other materials provided with the distribution.
13278957Simp *
14278957Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15278957Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16278957Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17278957Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18278957Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19278957Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20278957Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21278957Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22278957Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23278957Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24278957Simp * SUCH DAMAGE.
25278957Simp *
26278957Simp * $FreeBSD: head/sys/dev/spibus/spibusvar.h 300710 2016-05-26 06:35:11Z adrian $
27278957Simp */
28160370Simp
29160370Simp#define SPIBUS_IVAR(d) (struct spibus_ivar *) device_get_ivars(d)
30160370Simp#define SPIBUS_SOFTC(d) (struct spibus_softc *) device_get_softc(d)
31160370Simp
32160370Simpstruct spibus_softc
33160370Simp{
34160370Simp	device_t	dev;
35160370Simp};
36160370Simp
37300710Sadrian#define	SPIBUS_MODE_NONE	0
38300710Sadrian#define	SPIBUS_MODE_CPHA	1
39300710Sadrian#define	SPIBUS_MODE_CPOL	2
40300710Sadrian#define	SPIBUS_MODE_CPOL_CPHA	3
41300710Sadrian
42160370Simpstruct spibus_ivar
43160370Simp{
44160370Simp	uint32_t	cs;
45300710Sadrian	uint32_t	mode;
46300710Sadrian	uint32_t	clock;
47160370Simp};
48160370Simp
49160370Simpenum {
50300710Sadrian	SPIBUS_IVAR_CS,		/* chip select that we're on */
51300710Sadrian	SPIBUS_IVAR_MODE,	/* SPI mode (0-3) */
52300710Sadrian	SPIBUS_IVAR_CLOCK,	/* maximum clock freq for device */
53160370Simp};
54160370Simp
55160370Simp#define SPIBUS_ACCESSOR(A, B, T)					\
56228471Sedstatic inline int							\
57160370Simpspibus_get_ ## A(device_t dev, T *t)					\
58160370Simp{									\
59160370Simp	return BUS_READ_IVAR(device_get_parent(dev), dev,		\
60160370Simp	    SPIBUS_IVAR_ ## B, (uintptr_t *) t);			\
61160370Simp}
62160370Simp
63160370SimpSPIBUS_ACCESSOR(cs,		CS,		uint32_t)
64300710SadrianSPIBUS_ACCESSOR(mode,		MODE,		uint32_t)
65300710SadrianSPIBUS_ACCESSOR(clock,		CLOCK,		uint32_t)
66257064Sloos
67257064Sloosextern driver_t spibus_driver;
68257064Sloosextern devclass_t spibus_devclass;
69