1/*	$NetBSD: gemini_lpcvar.h,v 1.3 2011/07/01 19:32:28 dyoung Exp $	*/
2
3#ifndef _ARM_GEMINI_LPCVAR_H
4#define _ARM_GEMINI_LPCVAR_H
5
6#include <sys/types.h>
7#include <sys/device.h>
8#include <sys/bus.h>
9
10#define GEMINI_LPC_LDN_ALL	-1	/* "global" LDN */
11
12typedef void * lpctag_t;
13typedef void * lpcintrtag_t;
14
15typedef struct gemini_lpc_attach_args {
16        lpctag_t	lpc_tag;
17	uint		lpc_ldn;
18	bus_addr_t	lpc_base;
19	bus_addr_t	lpc_addr;
20	bus_size_t	lpc_size;
21        uint		lpc_intr;
22        bus_space_tag_t	lpc_iot;
23} gemini_lpc_attach_args_t;
24
25/* la_flags */
26#define LPC_FL_ENABLED    0x01            /* device is enabled */
27
28typedef struct gemini_lpc_bus_ops {
29	uint8_t	(*lpc_pnp_read)(lpctag_t, int, uint);
30	void	(*lpc_pnp_write)(lpctag_t, int, uint, uint8_t);
31	void	(*lpc_pnp_enter)(lpctag_t);
32	void	(*lpc_pnp_exit)(lpctag_t);
33	void   *(*lpc_intr_establish)(lpctag_t, uint, int, int,
34			int (*)(void *), void *);
35	void	(*lpc_intr_disestablish)(lpctag_t, void *);
36} gemini_lpc_bus_ops_t;
37
38typedef struct gemini_lpc_softc {
39	bus_addr_t			sc_addr;
40	bus_size_t			sc_size;
41	int				sc_intr;
42	bus_space_tag_t			sc_iot;
43	bus_space_handle_t		sc_ioh;
44	void			       *sc_lpchctag;
45	struct gemini_lpc_bus_ops      *sc_bus_ops;
46} gemini_lpc_softc_t;
47
48
49static inline uint8_t
50lpc_pnp_read(lpctag_t tag, int ldn, uint off)
51{
52	gemini_lpc_softc_t *sc = tag;
53	return (*sc->sc_bus_ops->lpc_pnp_read)(tag, ldn, off);
54}
55
56static inline void
57lpc_pnp_write(lpctag_t tag, int ldn, uint off, uint8_t val)
58{
59	gemini_lpc_softc_t *sc = tag;
60	return (*sc->sc_bus_ops->lpc_pnp_write)(tag, ldn, off, val);
61}
62
63static inline void
64lpc_pnp_enter(lpctag_t tag)
65{
66	gemini_lpc_softc_t *sc = tag;
67	return (*sc->sc_bus_ops->lpc_pnp_enter)(tag);
68}
69
70static inline void
71lpc_pnp_exit(lpctag_t tag)
72{
73	gemini_lpc_softc_t *sc = tag;
74	return (*sc->sc_bus_ops->lpc_pnp_exit)(tag);
75}
76
77static inline void *
78lpc_intr_establish(lpctag_t tag, uint intr, int ipl, int ist,
79	int (*func)(void *), void *arg)
80{
81	gemini_lpc_softc_t *sc = tag;
82	void *ih;
83
84	ih = (*sc->sc_bus_ops->lpc_intr_establish)
85		(tag, intr, ipl, ist, func, arg);
86
87	return ih;
88}
89
90static inline void
91lpc_intr_disestablish(lpctag_t tag, void *ih)
92{
93	gemini_lpc_softc_t *sc = tag;
94	return (*sc->sc_bus_ops->lpc_intr_disestablish)(tag, ih);
95}
96
97
98
99
100
101#endif	/* _ARM_GEMINI_LPCVAR_H */
102