1 #ifndef _IPXE_PIT8254_H
2 #define _IPXE_PIT8254_H
6 * 8254 Programmable Interval Timer
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #define PIT8254_CH_IRQ0 0
15 /** PC speaker channel */
16 #define PIT8254_CH_SPKR 2
18 /** Timer frequency (1.193182MHz) */
19 #define PIT8254_HZ 1193182UL
22 #define PIT8254_DATA(channel) ( 0x40 + (channel) )
24 /** Mode/command register */
25 #define PIT8254_CMD 0x43
28 #define PIT8254_CMD_CHANNEL(channel) ( (channel) << 6 )
31 #define PIT8254_CMD_ACCESS_LATCH 0x00 /**< Latch count value command */
32 #define PIT8254_CMD_ACCESS_LO 0x10 /**< Low byte only */
33 #define PIT8254_CMD_ACCESS_HI 0x20 /**< High byte only */
34 #define PIT8254_CMD_ACCESS_LOHI 0x30 /**< Low-byte, high-byte pair */
37 #define PIT8254_CMD_OP_TERMINAL 0x00 /**< Interrupt on terminal count */
38 #define PIT8254_CMD_OP_ONESHOT 0x02 /**< Hardware re-triggerable one-shot */
39 #define PIT8254_CMD_OP_RATE 0x04 /**< Rate generator */
40 #define PIT8254_CMD_OP_SQUARE 0x06 /**< Square wave generator */
41 #define PIT8254_CMD_OP_SWSTROBE 0x08 /**< Software triggered strobe */
42 #define PIT8254_CMD_OP_HWSTROBE 0x0a /**< Hardware triggered strobe */
43 #define PIT8254_CMD_OP_RATE2 0x0c /**< Rate generator (duplicate) */
44 #define PIT8254_CMD_OP_SQUARE2 0x0e /**< Square wave generator (duplicate)*/
47 #define PIT8254_CMD_BINARY 0x00
50 #define PIT8254_CMD_BCD 0x01
52 /** PC speaker control register */
53 #define PIT8254_SPKR 0x61
55 /** PC speaker channel gate */
56 #define PIT8254_SPKR_GATE 0x01
58 /** PC speaker enabled */
59 #define PIT8254_SPKR_ENABLE 0x02
61 /** PC speaker channel output */
62 #define PIT8254_SPKR_OUT 0x20
64 extern void pit8254_speaker_delay ( unsigned int ticks );
67 * Delay for a fixed number of microseconds
69 * @v usecs Number of microseconds for which to delay
71 static inline __attribute__ (( always_inline )) void
72 pit8254_udelay ( unsigned long usecs ) {
74 /* Delays are invariably compile-time constants; force the
75 * multiplication and division to take place at compilation
76 * time rather than runtime.
78 pit8254_speaker_delay ( ( usecs * PIT8254_HZ ) / 1000000 );
81 #endif /* _IPXE_PIT8254_H */