/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2021-2023 Val Packett <[email protected]>4* Copyright (c) 2023 Vladimir Kondratyev <[email protected]>5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _ATOPCASE_VAR_H_29#define _ATOPCASE_VAR_H_3031#include "opt_hid.h"3233#include <sys/types.h>34#include <sys/bus.h>35#include <sys/taskqueue.h>3637#include <contrib/dev/acpica/include/acpi.h>38#include <dev/acpica/acpivar.h>3940#include <dev/backlight/backlight.h>4142#include <dev/hid/hid.h>4344struct atopcase_child {45device_t hidbus;4647struct hid_device_info hw;4849uint8_t device;50uint8_t name[80];5152uint8_t rdesc[ATOPCASE_MSG_SIZE];53size_t rdesc_len;5455hid_intr_t *intr_handler;56void *intr_ctx;5758bool open;59};6061struct atopcase_softc {62device_t sc_dev;6364ACPI_HANDLE sc_handle;65int sc_gpe_bit;6667int sc_irq_rid;68struct resource *sc_irq_res;69void *sc_irq_ih;70volatile unsigned int sc_intr_cnt;7172struct timeout_task sc_task;73struct taskqueue *sc_tq;7475bool sc_booted;76bool sc_wait_for_status;7778uint8_t sc_hid[HID_PNP_ID_SIZE];79uint8_t sc_vendor[80];80uint8_t sc_product[80];81uint8_t sc_serial[80];82uint16_t sc_vid;83uint16_t sc_pid;84uint16_t sc_ver;8586/*87* Writes are complex and async (i.e. 2 responses arrive via interrupt)88* and cannot be interleaved (no new writes until responses arrive).89* they are serialized with sc_write_sx lock.90*/91struct sx sc_write_sx;92/*93* SPI transfers must be separated by a small pause. As they can be94* initiated by both interrupts and users, do ATOPCASE_SPI_PAUSE()95* after each transfer and serialize them with sc_sx or sc_mtx locks96* depending on interupt source (GPE or PIC). Still use sc_write_sx97* lock while polling.98*/99struct sx sc_sx;100struct mtx sc_mtx;101102struct atopcase_child sc_kb;103struct atopcase_child sc_tp;104105struct cdev *sc_backlight;106uint32_t sc_backlight_level;107108uint16_t sc_msg_len;109uint8_t sc_msg[ATOPCASE_MSG_SIZE];110struct atopcase_packet sc_buf;111struct atopcase_packet sc_junk;112};113114#ifdef HID_DEBUG115enum atopcase_log_level {116ATOPCASE_LLEVEL_DISABLED = 0,117ATOPCASE_LLEVEL_INFO,118ATOPCASE_LLEVEL_DEBUG, /* for troubleshooting */119ATOPCASE_LLEVEL_TRACE, /* log every packet */120};121extern enum atopcase_log_level atopcase_debug;122#endif123124int atopcase_receive_packet(struct atopcase_softc *);125int atopcase_init(struct atopcase_softc *);126int atopcase_destroy(struct atopcase_softc *sc);127int atopcase_intr(struct atopcase_softc *);128void atopcase_intr_setup(device_t, device_t, hid_intr_t, void *,129struct hid_rdesc_info *);130void atopcase_intr_unsetup(device_t, device_t);131int atopcase_intr_start(device_t, device_t);132int atopcase_intr_stop(device_t, device_t);133void atopcase_intr_poll(device_t, device_t);134int atopcase_get_rdesc(device_t, device_t, void *, hid_size_t);135int atopcase_set_report(device_t, device_t, const void *, hid_size_t, uint8_t,136uint8_t);137int atopcase_backlight_update_status(device_t, struct backlight_props *);138int atopcase_backlight_get_status(device_t, struct backlight_props *);139int atopcase_backlight_get_info(device_t, struct backlight_info *);140141#endif /* _ATOPCASE_VAR_H_ */142143144