132cb200fSOleksandr Tymoshenko /*-
232cb200fSOleksandr Tymoshenko * Copyright (C) 2016 Oleksandr Tymoshenko <gonzo@freebsd.org>
332cb200fSOleksandr Tymoshenko * All rights reserved.
432cb200fSOleksandr Tymoshenko *
532cb200fSOleksandr Tymoshenko * Redistribution and use in source and binary forms, with or without
632cb200fSOleksandr Tymoshenko * modification, are permitted provided that the following conditions
732cb200fSOleksandr Tymoshenko * are met:
832cb200fSOleksandr Tymoshenko * 1. Redistributions of source code must retain the above copyright
932cb200fSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer.
1032cb200fSOleksandr Tymoshenko * 2. Redistributions in binary form must reproduce the above copyright
1132cb200fSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer in the
1232cb200fSOleksandr Tymoshenko * documentation and/or other materials provided with the distribution.
1332cb200fSOleksandr Tymoshenko *
1432cb200fSOleksandr Tymoshenko * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1532cb200fSOleksandr Tymoshenko * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1632cb200fSOleksandr Tymoshenko * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1732cb200fSOleksandr Tymoshenko * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1832cb200fSOleksandr Tymoshenko * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1932cb200fSOleksandr Tymoshenko * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2032cb200fSOleksandr Tymoshenko * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2132cb200fSOleksandr Tymoshenko * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2232cb200fSOleksandr Tymoshenko * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2332cb200fSOleksandr Tymoshenko * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2432cb200fSOleksandr Tymoshenko * SUCH DAMAGE.
2532cb200fSOleksandr Tymoshenko *
2632cb200fSOleksandr Tymoshenko */
2732cb200fSOleksandr Tymoshenko
2832cb200fSOleksandr Tymoshenko #include <sys/param.h>
2932cb200fSOleksandr Tymoshenko #include <sys/systm.h>
3032cb200fSOleksandr Tymoshenko #include <sys/bus.h>
3132cb200fSOleksandr Tymoshenko #include <sys/cpu.h>
3232cb200fSOleksandr Tymoshenko #include <sys/kernel.h>
3332cb200fSOleksandr Tymoshenko #include <sys/lock.h>
3432cb200fSOleksandr Tymoshenko #include <sys/malloc.h>
3532cb200fSOleksandr Tymoshenko #include <sys/module.h>
3632cb200fSOleksandr Tymoshenko #include <sys/mutex.h>
3732cb200fSOleksandr Tymoshenko #include <sys/condvar.h>
3832cb200fSOleksandr Tymoshenko #include <sys/sysctl.h>
3932cb200fSOleksandr Tymoshenko #include <sys/selinfo.h>
4032cb200fSOleksandr Tymoshenko #include <sys/poll.h>
4132cb200fSOleksandr Tymoshenko #include <sys/uio.h>
4232cb200fSOleksandr Tymoshenko #include <sys/conf.h>
4332cb200fSOleksandr Tymoshenko
4432cb200fSOleksandr Tymoshenko #include <vm/vm.h>
4532cb200fSOleksandr Tymoshenko #include <vm/pmap.h>
4632cb200fSOleksandr Tymoshenko
4732cb200fSOleksandr Tymoshenko #include <dev/ofw/ofw_bus.h>
4832cb200fSOleksandr Tymoshenko #include <dev/ofw/ofw_bus_subr.h>
4932cb200fSOleksandr Tymoshenko
5032cb200fSOleksandr Tymoshenko #include <dev/evdev/input.h>
5132cb200fSOleksandr Tymoshenko #include <dev/evdev/evdev.h>
5232cb200fSOleksandr Tymoshenko
5332cb200fSOleksandr Tymoshenko #include <machine/bus.h>
5432cb200fSOleksandr Tymoshenko #include <machine/cpu.h>
5532cb200fSOleksandr Tymoshenko #include <machine/intr.h>
5632cb200fSOleksandr Tymoshenko
5732cb200fSOleksandr Tymoshenko #include <arm/broadcom/bcm2835/bcm2835_mbox.h>
5832cb200fSOleksandr Tymoshenko #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
5932cb200fSOleksandr Tymoshenko #include <arm/broadcom/bcm2835/bcm2835_vcbus.h>
6032cb200fSOleksandr Tymoshenko
6132cb200fSOleksandr Tymoshenko #include "mbox_if.h"
6232cb200fSOleksandr Tymoshenko
6332cb200fSOleksandr Tymoshenko #ifdef DEBUG
6432cb200fSOleksandr Tymoshenko #define DPRINTF(fmt, ...) do { \
6532cb200fSOleksandr Tymoshenko printf("%s:%u: ", __func__, __LINE__); \
6632cb200fSOleksandr Tymoshenko printf(fmt, ##__VA_ARGS__); \
6732cb200fSOleksandr Tymoshenko } while (0)
6832cb200fSOleksandr Tymoshenko #else
6932cb200fSOleksandr Tymoshenko #define DPRINTF(fmt, ...)
7032cb200fSOleksandr Tymoshenko #endif
7132cb200fSOleksandr Tymoshenko
7232cb200fSOleksandr Tymoshenko #define FT5406_LOCK(_sc) \
7332cb200fSOleksandr Tymoshenko mtx_lock(&(_sc)->sc_mtx)
7432cb200fSOleksandr Tymoshenko #define FT5406_UNLOCK(_sc) \
7532cb200fSOleksandr Tymoshenko mtx_unlock(&(_sc)->sc_mtx)
7632cb200fSOleksandr Tymoshenko #define FT5406_LOCK_INIT(_sc) \
7732cb200fSOleksandr Tymoshenko mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \
7832cb200fSOleksandr Tymoshenko "ft5406", MTX_DEF)
7932cb200fSOleksandr Tymoshenko #define FT5406_LOCK_DESTROY(_sc) \
8032cb200fSOleksandr Tymoshenko mtx_destroy(&_sc->sc_mtx);
8132cb200fSOleksandr Tymoshenko #define FT5406_LOCK_ASSERT(_sc) \
8232cb200fSOleksandr Tymoshenko mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
8332cb200fSOleksandr Tymoshenko
8432cb200fSOleksandr Tymoshenko #define FT5406_DEVICE_MODE 0
8532cb200fSOleksandr Tymoshenko #define FT5406_GESTURE_ID 1
8632cb200fSOleksandr Tymoshenko #define FT5406_NUM_POINTS 2
8732cb200fSOleksandr Tymoshenko #define FT5406_POINT_XH(n) (0 + 3 + (n)*6)
8832cb200fSOleksandr Tymoshenko #define FT5406_POINT_XL(n) (1 + 3 + (n)*6)
8932cb200fSOleksandr Tymoshenko #define FT5406_POINT_YH(n) (2 + 3 + (n)*6)
9032cb200fSOleksandr Tymoshenko #define FT5406_POINT_YL(n) (3 + 3 + (n)*6)
9132cb200fSOleksandr Tymoshenko #define FT5406_WINDOW_SIZE 64
9232cb200fSOleksandr Tymoshenko
9332cb200fSOleksandr Tymoshenko #define GET_NUM_POINTS(buf) (buf[FT5406_NUM_POINTS])
9432cb200fSOleksandr Tymoshenko #define GET_X(buf, n) (((buf[FT5406_POINT_XH(n)] & 0xf) << 8) | \
9532cb200fSOleksandr Tymoshenko (buf[FT5406_POINT_XL(n)]))
9632cb200fSOleksandr Tymoshenko #define GET_Y(buf, n) (((buf[FT5406_POINT_YH(n)] & 0xf) << 8) | \
9732cb200fSOleksandr Tymoshenko (buf[FT5406_POINT_YL(n)]))
9832cb200fSOleksandr Tymoshenko #define GET_TOUCH_ID(buf, n) ((buf[FT5406_POINT_YH(n)] >> 4) & 0xf)
9932cb200fSOleksandr Tymoshenko
10032cb200fSOleksandr Tymoshenko #define NO_POINTS 99
10132cb200fSOleksandr Tymoshenko #define SCREEN_WIDTH 800
10232cb200fSOleksandr Tymoshenko #define SCREEN_HEIGHT 480
103b5e34627SOleksandr Tymoshenko #define SCREEN_WIDTH_MM 155
104b5e34627SOleksandr Tymoshenko #define SCREEN_HEIGHT_MM 86
105b5e34627SOleksandr Tymoshenko #define SCREEN_RES_X (SCREEN_WIDTH / SCREEN_WIDTH_MM)
106b5e34627SOleksandr Tymoshenko #define SCREEN_RES_Y (SCREEN_HEIGHT / SCREEN_HEIGHT_MM)
107b5e34627SOleksandr Tymoshenko #define MAX_TOUCH_ID (10 - 1)
10832cb200fSOleksandr Tymoshenko
10932cb200fSOleksandr Tymoshenko struct ft5406ts_softc {
11032cb200fSOleksandr Tymoshenko device_t sc_dev;
11132cb200fSOleksandr Tymoshenko struct mtx sc_mtx;
112b5e34627SOleksandr Tymoshenko int sc_tick;
113b5e34627SOleksandr Tymoshenko struct callout sc_callout;
11432cb200fSOleksandr Tymoshenko
11532cb200fSOleksandr Tymoshenko /* mbox buffer (mapped to KVA) */
11632cb200fSOleksandr Tymoshenko uint8_t *touch_buf;
11732cb200fSOleksandr Tymoshenko
11832cb200fSOleksandr Tymoshenko /* initial hook for waiting mbox intr */
11932cb200fSOleksandr Tymoshenko struct intr_config_hook sc_init_hook;
12032cb200fSOleksandr Tymoshenko
12132cb200fSOleksandr Tymoshenko struct evdev_dev *sc_evdev;
122b5e34627SOleksandr Tymoshenko
123b5e34627SOleksandr Tymoshenko uint8_t sc_window[FT5406_WINDOW_SIZE];
124b5e34627SOleksandr Tymoshenko };
125b5e34627SOleksandr Tymoshenko
126b5e34627SOleksandr Tymoshenko static evdev_open_t ft5406ts_ev_open;
127b5e34627SOleksandr Tymoshenko static evdev_close_t ft5406ts_ev_close;
128b5e34627SOleksandr Tymoshenko
129b5e34627SOleksandr Tymoshenko static const struct evdev_methods ft5406ts_evdev_methods = {
130b5e34627SOleksandr Tymoshenko .ev_open = &ft5406ts_ev_open,
131b5e34627SOleksandr Tymoshenko .ev_close = &ft5406ts_ev_close,
13232cb200fSOleksandr Tymoshenko };
13332cb200fSOleksandr Tymoshenko
13432cb200fSOleksandr Tymoshenko static void
ft5406ts_callout(void * data)135b5e34627SOleksandr Tymoshenko ft5406ts_callout(void *data)
13632cb200fSOleksandr Tymoshenko {
13732cb200fSOleksandr Tymoshenko struct ft5406ts_softc *sc = (struct ft5406ts_softc *)data;
13832cb200fSOleksandr Tymoshenko int points;
139b5e34627SOleksandr Tymoshenko int id, i, x, y;
14032cb200fSOleksandr Tymoshenko
141b5e34627SOleksandr Tymoshenko FT5406_LOCK_ASSERT(sc);
14232cb200fSOleksandr Tymoshenko
143b5e34627SOleksandr Tymoshenko memcpy(sc->sc_window, sc->touch_buf, FT5406_WINDOW_SIZE);
14432cb200fSOleksandr Tymoshenko sc->touch_buf[FT5406_NUM_POINTS] = NO_POINTS;
14532cb200fSOleksandr Tymoshenko
146b5e34627SOleksandr Tymoshenko points = GET_NUM_POINTS(sc->sc_window);
14732cb200fSOleksandr Tymoshenko /*
148b5e34627SOleksandr Tymoshenko * No update from VC - do nothing.
14932cb200fSOleksandr Tymoshenko */
15032cb200fSOleksandr Tymoshenko if (points == NO_POINTS)
151b5e34627SOleksandr Tymoshenko goto out;
15232cb200fSOleksandr Tymoshenko
15332cb200fSOleksandr Tymoshenko for (i = 0; i < points; i++) {
154b5e34627SOleksandr Tymoshenko id = GET_TOUCH_ID(sc->sc_window, i);
155b5e34627SOleksandr Tymoshenko x = GET_X(sc->sc_window, i);
156b5e34627SOleksandr Tymoshenko y = GET_Y(sc->sc_window, i);
157b5e34627SOleksandr Tymoshenko
158b5e34627SOleksandr Tymoshenko if (id > MAX_TOUCH_ID) {
159b5e34627SOleksandr Tymoshenko device_printf(sc->sc_dev, "bad touch id: %d", id);
16032cb200fSOleksandr Tymoshenko continue;
16132cb200fSOleksandr Tymoshenko }
162b5e34627SOleksandr Tymoshenko evdev_push_event(sc->sc_evdev, EV_ABS, ABS_MT_SLOT, id);
163b5e34627SOleksandr Tymoshenko evdev_push_event(sc->sc_evdev, EV_ABS, ABS_MT_TRACKING_ID, id);
164b5e34627SOleksandr Tymoshenko evdev_push_event(sc->sc_evdev, EV_ABS, ABS_MT_POSITION_X, x);
165b5e34627SOleksandr Tymoshenko evdev_push_event(sc->sc_evdev, EV_ABS, ABS_MT_POSITION_Y, y);
16632cb200fSOleksandr Tymoshenko }
16732cb200fSOleksandr Tymoshenko evdev_sync(sc->sc_evdev);
168b5e34627SOleksandr Tymoshenko out:
169b5e34627SOleksandr Tymoshenko callout_reset(&sc->sc_callout, sc->sc_tick, ft5406ts_callout, sc);
17032cb200fSOleksandr Tymoshenko }
17132cb200fSOleksandr Tymoshenko
172911aed94SVladimir Kondratyev static int
ft5406ts_ev_close(struct evdev_dev * evdev)173911aed94SVladimir Kondratyev ft5406ts_ev_close(struct evdev_dev *evdev)
174b5e34627SOleksandr Tymoshenko {
175911aed94SVladimir Kondratyev struct ft5406ts_softc *sc = evdev_get_softc(evdev);
176b5e34627SOleksandr Tymoshenko
177b5e34627SOleksandr Tymoshenko FT5406_LOCK_ASSERT(sc);
178b5e34627SOleksandr Tymoshenko
179b5e34627SOleksandr Tymoshenko callout_stop(&sc->sc_callout);
180911aed94SVladimir Kondratyev
181911aed94SVladimir Kondratyev return (0);
182b5e34627SOleksandr Tymoshenko }
183b5e34627SOleksandr Tymoshenko
184b5e34627SOleksandr Tymoshenko static int
ft5406ts_ev_open(struct evdev_dev * evdev)185911aed94SVladimir Kondratyev ft5406ts_ev_open(struct evdev_dev *evdev)
186b5e34627SOleksandr Tymoshenko {
187911aed94SVladimir Kondratyev struct ft5406ts_softc *sc = evdev_get_softc(evdev);
188b5e34627SOleksandr Tymoshenko
189b5e34627SOleksandr Tymoshenko FT5406_LOCK_ASSERT(sc);
190b5e34627SOleksandr Tymoshenko
191b5e34627SOleksandr Tymoshenko callout_reset(&sc->sc_callout, sc->sc_tick, ft5406ts_callout, sc);
192b5e34627SOleksandr Tymoshenko
193b5e34627SOleksandr Tymoshenko return (0);
19432cb200fSOleksandr Tymoshenko }
19532cb200fSOleksandr Tymoshenko
19632cb200fSOleksandr Tymoshenko static void
ft5406ts_init(void * arg)19732cb200fSOleksandr Tymoshenko ft5406ts_init(void *arg)
19832cb200fSOleksandr Tymoshenko {
19932cb200fSOleksandr Tymoshenko struct ft5406ts_softc *sc = arg;
20032cb200fSOleksandr Tymoshenko struct bcm2835_mbox_tag_touchbuf msg;
20132cb200fSOleksandr Tymoshenko uint32_t touchbuf;
20232cb200fSOleksandr Tymoshenko int err;
20332cb200fSOleksandr Tymoshenko
20432cb200fSOleksandr Tymoshenko /* release this hook (continue boot) */
20532cb200fSOleksandr Tymoshenko config_intrhook_disestablish(&sc->sc_init_hook);
20632cb200fSOleksandr Tymoshenko
20732cb200fSOleksandr Tymoshenko memset(&msg, 0, sizeof(msg));
20832cb200fSOleksandr Tymoshenko msg.hdr.buf_size = sizeof(msg);
20932cb200fSOleksandr Tymoshenko msg.hdr.code = BCM2835_MBOX_CODE_REQ;
21032cb200fSOleksandr Tymoshenko msg.tag_hdr.tag = BCM2835_MBOX_TAG_GET_TOUCHBUF;
21132cb200fSOleksandr Tymoshenko msg.tag_hdr.val_buf_size = sizeof(msg.body);
21232cb200fSOleksandr Tymoshenko msg.tag_hdr.val_len = sizeof(msg.body);
21332cb200fSOleksandr Tymoshenko msg.end_tag = 0;
21432cb200fSOleksandr Tymoshenko
21532cb200fSOleksandr Tymoshenko /* call mailbox property */
21632cb200fSOleksandr Tymoshenko err = bcm2835_mbox_property(&msg, sizeof(msg));
21732cb200fSOleksandr Tymoshenko if (err) {
21832cb200fSOleksandr Tymoshenko device_printf(sc->sc_dev, "failed to get touchbuf address\n");
21932cb200fSOleksandr Tymoshenko return;
22032cb200fSOleksandr Tymoshenko }
22132cb200fSOleksandr Tymoshenko
22232cb200fSOleksandr Tymoshenko if (msg.body.resp.address == 0) {
22332cb200fSOleksandr Tymoshenko device_printf(sc->sc_dev, "touchscreen not detected\n");
22432cb200fSOleksandr Tymoshenko return;
22532cb200fSOleksandr Tymoshenko }
22632cb200fSOleksandr Tymoshenko
22740084ac3SKyle Evans touchbuf = VCBUS_TO_ARMC(msg.body.resp.address);
22832cb200fSOleksandr Tymoshenko sc->touch_buf = (uint8_t*)pmap_mapdev(touchbuf, FT5406_WINDOW_SIZE);
22932cb200fSOleksandr Tymoshenko
230b5e34627SOleksandr Tymoshenko /* 60Hz */
231b5e34627SOleksandr Tymoshenko sc->sc_tick = hz * 17 / 1000;
232b5e34627SOleksandr Tymoshenko if (sc->sc_tick == 0)
233b5e34627SOleksandr Tymoshenko sc->sc_tick = 1;
234b5e34627SOleksandr Tymoshenko
23532cb200fSOleksandr Tymoshenko sc->sc_evdev = evdev_alloc();
23632cb200fSOleksandr Tymoshenko evdev_set_name(sc->sc_evdev, device_get_desc(sc->sc_dev));
23732cb200fSOleksandr Tymoshenko evdev_set_phys(sc->sc_evdev, device_get_nameunit(sc->sc_dev));
238b5e34627SOleksandr Tymoshenko evdev_set_id(sc->sc_evdev, BUS_HOST, 0, 0, 0);
239b5e34627SOleksandr Tymoshenko evdev_set_methods(sc->sc_evdev, sc, &ft5406ts_evdev_methods);
240b5e34627SOleksandr Tymoshenko evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_STCOMPAT);
241b5e34627SOleksandr Tymoshenko evdev_set_flag(sc->sc_evdev, EVDEV_FLAG_MT_AUTOREL);
24232cb200fSOleksandr Tymoshenko evdev_support_prop(sc->sc_evdev, INPUT_PROP_DIRECT);
24332cb200fSOleksandr Tymoshenko evdev_support_event(sc->sc_evdev, EV_SYN);
24432cb200fSOleksandr Tymoshenko evdev_support_event(sc->sc_evdev, EV_ABS);
24532cb200fSOleksandr Tymoshenko
2465af73ad5SVladimir Kondratyev evdev_support_abs(sc->sc_evdev, ABS_MT_SLOT, 0,
247b5e34627SOleksandr Tymoshenko MAX_TOUCH_ID, 0, 0, 0);
2485af73ad5SVladimir Kondratyev evdev_support_abs(sc->sc_evdev, ABS_MT_TRACKING_ID, -1,
249b5e34627SOleksandr Tymoshenko MAX_TOUCH_ID, 0, 0, 0);
2505af73ad5SVladimir Kondratyev evdev_support_abs(sc->sc_evdev, ABS_MT_POSITION_X, 0,
251b5e34627SOleksandr Tymoshenko SCREEN_WIDTH, 0, 0, SCREEN_RES_X);
2525af73ad5SVladimir Kondratyev evdev_support_abs(sc->sc_evdev, ABS_MT_POSITION_Y, 0,
253b5e34627SOleksandr Tymoshenko SCREEN_HEIGHT, 0, 0, SCREEN_RES_Y);
25432cb200fSOleksandr Tymoshenko
255b5e34627SOleksandr Tymoshenko err = evdev_register_mtx(sc->sc_evdev, &sc->sc_mtx);
25632cb200fSOleksandr Tymoshenko if (err) {
25732cb200fSOleksandr Tymoshenko evdev_free(sc->sc_evdev);
258b5e34627SOleksandr Tymoshenko sc->sc_evdev = NULL; /* Avoid double free */
25932cb200fSOleksandr Tymoshenko return;
26032cb200fSOleksandr Tymoshenko }
26132cb200fSOleksandr Tymoshenko
26232cb200fSOleksandr Tymoshenko sc->touch_buf[FT5406_NUM_POINTS] = NO_POINTS;
263b5e34627SOleksandr Tymoshenko callout_init_mtx(&sc->sc_callout, &sc->sc_mtx, 0);
26432cb200fSOleksandr Tymoshenko }
26532cb200fSOleksandr Tymoshenko
26632cb200fSOleksandr Tymoshenko static int
ft5406ts_probe(device_t dev)26732cb200fSOleksandr Tymoshenko ft5406ts_probe(device_t dev)
26832cb200fSOleksandr Tymoshenko {
26932cb200fSOleksandr Tymoshenko
270c2c9ef3cSJuraj Lutter if (!ofw_bus_is_compatible(dev, "raspberrypi,firmware-ts"))
27132cb200fSOleksandr Tymoshenko return (ENXIO);
27232cb200fSOleksandr Tymoshenko
27332cb200fSOleksandr Tymoshenko device_set_desc(dev, "FT5406 touchscreen (VC memory interface)");
27432cb200fSOleksandr Tymoshenko
27532cb200fSOleksandr Tymoshenko return (BUS_PROBE_DEFAULT);
27632cb200fSOleksandr Tymoshenko }
27732cb200fSOleksandr Tymoshenko
27832cb200fSOleksandr Tymoshenko static int
ft5406ts_attach(device_t dev)27932cb200fSOleksandr Tymoshenko ft5406ts_attach(device_t dev)
28032cb200fSOleksandr Tymoshenko {
28132cb200fSOleksandr Tymoshenko struct ft5406ts_softc *sc;
28232cb200fSOleksandr Tymoshenko
28332cb200fSOleksandr Tymoshenko /* set self dev */
28432cb200fSOleksandr Tymoshenko sc = device_get_softc(dev);
28532cb200fSOleksandr Tymoshenko sc->sc_dev = dev;
28632cb200fSOleksandr Tymoshenko
28732cb200fSOleksandr Tymoshenko /* register callback for using mbox when interrupts are enabled */
28832cb200fSOleksandr Tymoshenko sc->sc_init_hook.ich_func = ft5406ts_init;
28932cb200fSOleksandr Tymoshenko sc->sc_init_hook.ich_arg = sc;
29032cb200fSOleksandr Tymoshenko
29119de549bSOleksandr Tymoshenko FT5406_LOCK_INIT(sc);
29219de549bSOleksandr Tymoshenko
29332cb200fSOleksandr Tymoshenko if (config_intrhook_establish(&sc->sc_init_hook) != 0) {
29432cb200fSOleksandr Tymoshenko device_printf(dev, "config_intrhook_establish failed\n");
295b5e34627SOleksandr Tymoshenko FT5406_LOCK_DESTROY(sc);
29632cb200fSOleksandr Tymoshenko return (ENOMEM);
29732cb200fSOleksandr Tymoshenko }
29832cb200fSOleksandr Tymoshenko
29932cb200fSOleksandr Tymoshenko return (0);
30032cb200fSOleksandr Tymoshenko }
30132cb200fSOleksandr Tymoshenko
30232cb200fSOleksandr Tymoshenko static int
ft5406ts_detach(device_t dev)30332cb200fSOleksandr Tymoshenko ft5406ts_detach(device_t dev)
30432cb200fSOleksandr Tymoshenko {
30532cb200fSOleksandr Tymoshenko struct ft5406ts_softc *sc;
30632cb200fSOleksandr Tymoshenko
30732cb200fSOleksandr Tymoshenko sc = device_get_softc(dev);
30832cb200fSOleksandr Tymoshenko
30932cb200fSOleksandr Tymoshenko evdev_free(sc->sc_evdev);
31032cb200fSOleksandr Tymoshenko
31132cb200fSOleksandr Tymoshenko FT5406_LOCK_DESTROY(sc);
31232cb200fSOleksandr Tymoshenko
31332cb200fSOleksandr Tymoshenko return (0);
31432cb200fSOleksandr Tymoshenko }
31532cb200fSOleksandr Tymoshenko
31632cb200fSOleksandr Tymoshenko static device_method_t ft5406ts_methods[] = {
31732cb200fSOleksandr Tymoshenko /* Device interface */
31832cb200fSOleksandr Tymoshenko DEVMETHOD(device_probe, ft5406ts_probe),
31932cb200fSOleksandr Tymoshenko DEVMETHOD(device_attach, ft5406ts_attach),
32032cb200fSOleksandr Tymoshenko DEVMETHOD(device_detach, ft5406ts_detach),
32132cb200fSOleksandr Tymoshenko
32232cb200fSOleksandr Tymoshenko DEVMETHOD_END
32332cb200fSOleksandr Tymoshenko };
32432cb200fSOleksandr Tymoshenko
32532cb200fSOleksandr Tymoshenko static driver_t ft5406ts_driver = {
32632cb200fSOleksandr Tymoshenko "ft5406ts",
32732cb200fSOleksandr Tymoshenko ft5406ts_methods,
32832cb200fSOleksandr Tymoshenko sizeof(struct ft5406ts_softc),
32932cb200fSOleksandr Tymoshenko };
33032cb200fSOleksandr Tymoshenko
331*82d4dc06SJohn Baldwin DRIVER_MODULE(ft5406ts, simplebus, ft5406ts_driver, 0, 0);
33276a46b29SOleksandr Tymoshenko MODULE_DEPEND(ft5406ts, evdev, 1, 1, 1);
333