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: stable/11/sys/dev/spibus/spibusvar.h 332942 2018-04-24 17:00:08Z ian $ 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 49331506Sian#define SPIBUS_CS_HIGH (1U << 31) 50331506Sian 51160370Simpenum { 52300710Sadrian SPIBUS_IVAR_CS, /* chip select that we're on */ 53300710Sadrian SPIBUS_IVAR_MODE, /* SPI mode (0-3) */ 54300710Sadrian SPIBUS_IVAR_CLOCK, /* maximum clock freq for device */ 55160370Simp}; 56160370Simp 57160370Simp#define SPIBUS_ACCESSOR(A, B, T) \ 58228471Sedstatic inline int \ 59160370Simpspibus_get_ ## A(device_t dev, T *t) \ 60160370Simp{ \ 61160370Simp return BUS_READ_IVAR(device_get_parent(dev), dev, \ 62160370Simp SPIBUS_IVAR_ ## B, (uintptr_t *) t); \ 63332942Sian} \ 64332942Sianstatic inline int \ 65332942Sianspibus_set_ ## A(device_t dev, T t) \ 66332942Sian{ \ 67332942Sian return BUS_WRITE_IVAR(device_get_parent(dev), dev, \ 68332942Sian SPIBUS_IVAR_ ## B, (uintptr_t) t); \ 69160370Simp} 70332942Sian 71160370SimpSPIBUS_ACCESSOR(cs, CS, uint32_t) 72300710SadrianSPIBUS_ACCESSOR(mode, MODE, uint32_t) 73300710SadrianSPIBUS_ACCESSOR(clock, CLOCK, uint32_t) 74257064Sloos 75257064Sloosextern driver_t spibus_driver; 76257064Sloosextern devclass_t spibus_devclass; 77331506Sianextern driver_t ofw_spibus_driver; 78331506Sianextern devclass_t ofw_spibus_devclass; 79