jcs's openbsd hax
openbsd
1/* $OpenBSD: ispivar.h,v 1.1 2025/11/14 01:55:07 jcs Exp $ */
2/*
3 * Intel LPSS SPI controller
4 *
5 * Copyright (c) 2015-2018 joshua stein <jcs@openbsd.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <sys/param.h>
21#include <sys/systm.h>
22#include <sys/kernel.h>
23#include <sys/kthread.h>
24
25#include "acpi.h"
26#if NACPI > 0
27#include <dev/acpi/acpivar.h>
28#include <dev/acpi/acpidev.h>
29#include <dev/acpi/amltypes.h>
30#include <dev/acpi/dsdt.h>
31#endif
32
33#include <dev/pci/pcivar.h>
34
35#include <dev/spi/spivar.h>
36
37/* #define ISPI_DEBUG */
38
39#ifdef ISPI_DEBUG
40#define DPRINTF(x) printf x
41#else
42#define DPRINTF(x)
43#endif
44
45struct ispi_softc {
46 struct device sc_dev;
47
48 bus_space_tag_t sc_iot;
49 bus_space_handle_t sc_ioh;
50
51 void *sc_ih;
52 struct pci_attach_args sc_paa;
53 long sc_ssp_clk;
54 int sc_lpss_reg_offset;
55 int sc_reg_cs_ctrl;
56 int sc_rx_threshold;
57 int sc_tx_threshold;
58 int sc_tx_threshold_hi;
59
60 struct spi_controller sc_spi_tag;
61 struct rwlock sc_buslock;
62 struct spi_config sc_spi_conf;
63
64 int sc_ridx;
65 int sc_widx;
66
67#if NACPI > 0
68 struct acpi_softc *sc_acpi;
69 struct aml_node *sc_devnode;
70#endif
71 u_int32_t sc_caps;
72};
73
74void ispi_init(struct ispi_softc *sc);
75
76int ispi_match(struct device *, void *, void *);
77void ispi_attach(struct device *, struct device *, void *);
78int ispi_activate(struct device *, int);
79int ispi_spi_print(void *aux, const char *pnp);
80
81void ispi_write(struct ispi_softc *sc, int reg, uint32_t val);
82uint32_t ispi_read(struct ispi_softc *sc, int reg);
83
84#if NACPI > 0
85int ispi_acpi_found_hid(struct aml_node *node, void *arg);
86#endif
87
88void ispi_config(void *, struct spi_config *);
89int ispi_acquire_bus(void *, int);
90void ispi_release_bus(void *, int);
91int ispi_transfer(void *, char *, char *, int, int);
92void ispi_start(struct ispi_softc *);
93void ispi_send(struct ispi_softc *);
94void ispi_recv(struct ispi_softc *);
95
96int ispi_intr(void *);
97int ispi_status(struct ispi_softc *);
98int ispi_flush(struct ispi_softc *);
99void ispi_clear_status(struct ispi_softc *);
100int ispi_rx_fifo_empty(struct ispi_softc *);
101int ispi_rx_fifo_overrun(struct ispi_softc *);