4 * Public USB driver interface exposed to platform-specific USB sub-drivers.
8 * Copyright (C) 2001-2004 Kern Sibbald
9 * Copyright (C) 2004-2005 Adam Kropelin
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General
13 * Public License as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the Free
22 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
29 /* Max rate to update volatile data */
30 #define MAX_VOLATILE_POLL_RATE 5
32 /* How often to retry the link (seconds) */
33 #define LINK_RETRY_INTERVAL 5
36 #define VENDOR_APC 0x51D
37 #define VENDOR_MGE 0x463
39 /* Various known USB codes */
40 #define UPS_USAGE 0x840004
41 #define UPS_VOLTAGE 0x840030
42 #define UPS_OUTPUT 0x84001c
43 #define UPS_BATTERY 0x840012
45 /* These are the data_type expected for our know_info */
46 #define T_NONE 0 /* No units */
47 #define T_INDEX 1 /* String index */
48 #define T_CAPACITY 2 /* Capacity (usually %) */
49 #define T_BITS 3 /* Bit field */
50 #define T_UNITS 4 /* Use units/exponent field */
51 #define T_DATE 5 /* Date */
52 #define T_APCDATE 6 /* APC date */
54 /* These are the resulting value types returned */
55 #define V_DOUBLE 1 /* Double */
56 #define V_STRING 2 /* String pointer */
57 #define V_INTEGER 3 /* Integer */
59 /* These are the desired Physical usage values we want */
60 #define P_ANY 0 /* Any value */
61 #define P_OUTPUT 0x84001c /* Output values */
62 #define P_BATTERY 0x840012 /* Battery values */
63 #define P_INPUT 0x84001a /* Input values */
64 #define P_PWSUM 0x840024 /* Power summary */
65 #define P_APC1 0xff860007 /* From AP9612 environmental monitor */
67 /* No Command Index, don't save this value */
71 int ci
; /* Command index */
72 unsigned usage_code
; /* Usage code */
73 unsigned physical
; /* Physical usage */
74 unsigned logical
; /* Logical usage */
75 int data_type
; /* Data type expected */
76 bool isvolatile
; /* Volatile data item */
79 typedef struct s_usb_value
{
80 int value_type
; /* Type of returned value */
81 double dValue
; /* Value if double */
82 int iValue
; /* Integer value */
83 const char *UnitName
; /* Name of units */
84 char sValue
[MAXSTRING
]; /* Value if string */
87 /* Check if the UPS has the given capability */
88 #define UPS_HAS_CAP(ci) (ups->UPS_Cap[ci])
90 /* Platform-specific code needs to call back to these operations */
91 int usb_ups_get_capabilities(UPSINFO
*ups
);
92 int usb_ups_read_static_data(UPSINFO
*ups
);
94 /* Useful helper functions for use by platform-specific code */
95 double pow_ten(int exponent
);
96 int usb_report_event(UPSINFO
*ups
, int ci
, USB_VALUE
*uval
);
98 #endif /* _USB_COMMON_H */