1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021-2023 Val Packett <val@packett.cool>
* Copyright (c) 2023 Vladimir Kondratyev <wulf@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _ATOPCASE_VAR_H_
#define _ATOPCASE_VAR_H_
#include "opt_hid.h"
#include <sys/types.h>
#include <sys/bus.h>
#include <sys/taskqueue.h>
#include <contrib/dev/acpica/include/acpi.h>
#include <dev/acpica/acpivar.h>
#include <dev/backlight/backlight.h>
#include <dev/hid/hid.h>
struct atopcase_child {
device_t hidbus;
struct hid_device_info hw;
uint8_t device;
uint8_t name[80];
uint8_t rdesc[ATOPCASE_MSG_SIZE];
size_t rdesc_len;
hid_intr_t *intr_handler;
void *intr_ctx;
bool open;
};
struct atopcase_softc {
device_t sc_dev;
ACPI_HANDLE sc_handle;
int sc_gpe_bit;
int sc_irq_rid;
struct resource *sc_irq_res;
void *sc_irq_ih;
volatile unsigned int sc_intr_cnt;
struct timeout_task sc_task;
struct taskqueue *sc_tq;
bool sc_booted;
bool sc_wait_for_status;
uint8_t sc_hid[HID_PNP_ID_SIZE];
uint8_t sc_vendor[80];
uint8_t sc_product[80];
uint8_t sc_serial[80];
uint16_t sc_vid;
uint16_t sc_pid;
uint16_t sc_ver;
/*
* Writes are complex and async (i.e. 2 responses arrive via interrupt)
* and cannot be interleaved (no new writes until responses arrive).
* they are serialized with sc_write_sx lock.
*/
struct sx sc_write_sx;
/*
* SPI transfers must be separated by a small pause. As they can be
* initiated by both interrupts and users, do ATOPCASE_SPI_PAUSE()
* after each transfer and serialize them with sc_sx or sc_mtx locks
* depending on interupt source (GPE or PIC). Still use sc_write_sx
* lock while polling.
*/
struct sx sc_sx;
struct mtx sc_mtx;
struct atopcase_child sc_kb;
struct atopcase_child sc_tp;
struct cdev *sc_backlight;
uint32_t sc_backlight_level;
uint16_t sc_msg_len;
uint8_t sc_msg[ATOPCASE_MSG_SIZE];
struct atopcase_packet sc_buf;
struct atopcase_packet sc_junk;
};
#ifdef HID_DEBUG
enum atopcase_log_level {
ATOPCASE_LLEVEL_DISABLED = 0,
ATOPCASE_LLEVEL_INFO,
ATOPCASE_LLEVEL_DEBUG, /* for troubleshooting */
ATOPCASE_LLEVEL_TRACE, /* log every packet */
};
extern enum atopcase_log_level atopcase_debug;
#endif
int atopcase_receive_packet(struct atopcase_softc *);
int atopcase_init(struct atopcase_softc *);
int atopcase_destroy(struct atopcase_softc *sc);
int atopcase_intr(struct atopcase_softc *);
void atopcase_intr_setup(device_t, device_t, hid_intr_t, void *,
struct hid_rdesc_info *);
void atopcase_intr_unsetup(device_t, device_t);
int atopcase_intr_start(device_t, device_t);
int atopcase_intr_stop(device_t, device_t);
void atopcase_intr_poll(device_t, device_t);
int atopcase_get_rdesc(device_t, device_t, void *, hid_size_t);
int atopcase_set_report(device_t, device_t, const void *, hid_size_t, uint8_t,
uint8_t);
int atopcase_backlight_update_status(device_t, struct backlight_props *);
int atopcase_backlight_get_status(device_t, struct backlight_props *);
int atopcase_backlight_get_info(device_t, struct backlight_info *);
#endif /* _ATOPCASE_VAR_H_ */
|