1 /***************************************************************************
3 * devinfo_acpi : acpi devices
5 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
6 * Use is subject to license terms.
8 * Licensed under the Academic Free License version 2.1
10 **************************************************************************/
18 #include <sys/utsname.h>
19 #include <libdevinfo.h>
20 #include <sys/mkdev.h>
23 #include <sys/sysevent/dev.h>
24 #include <sys/sysevent/pwrctl.h>
26 #include "../osspec.h"
27 #include "../logger.h"
29 #include "../hald_dbus.h"
30 #include "../device_info.h"
32 #include "../hald_runner.h"
33 #include "devinfo_acpi.h"
35 #define DEVINFO_PROBE_ACPI_TIMEOUT 30000
37 static HalDevice
*devinfo_acpi_add(HalDevice
*, di_node_t
, char *, char *);
38 static HalDevice
*devinfo_power_button_add(HalDevice
*parent
, di_node_t node
,
39 char *devfs_path
, char *device_type
);
40 static void devinfo_battery_rescan_probing_done(HalDevice
*d
, guint32 exit_type
,
41 gint return_code
, char **error
, gpointer userdata1
, gpointer userdata2
);
43 DevinfoDevHandler devinfo_acpi_handler
= {
49 devinfo_acpi_get_prober
52 DevinfoDevHandler devinfo_power_button_handler
= {
53 devinfo_power_button_add
,
62 devinfo_acpi_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
,
65 HalDevice
*d
, *computer
;
67 di_devlink_handle_t devlink_hdl
;
71 char *minor_path
= NULL
;
74 driver_name
= di_driver_name(node
);
75 if ((driver_name
== NULL
) || (strcmp(driver_name
, "acpi_drv") != 0)) {
81 if ((computer
= hal_device_store_find(hald_get_gdl(),
82 "/org/freedesktop/Hal/devices/computer")) ||
83 (computer
= hal_device_store_find(hald_get_tdl(),
84 "/org/freedesktop/Hal/devices/computer"))) {
85 hal_device_property_set_string(computer
,
86 "system.formfactor", "laptop");
87 hal_device_property_set_string(computer
,
88 "power_management.type", "acpi");
90 devinfo_set_default_properties(d
, parent
, node
, devfs_path
);
91 devinfo_add_enqueue(d
, devfs_path
, &devinfo_acpi_handler
);
93 major
= di_driver_major(node
);
94 if ((devlink_hdl
= di_devlink_init(NULL
, 0)) == NULL
) {
98 while ((minor
= di_minor_next(node
, minor
)) != DI_MINOR_NIL
) {
99 dev
= di_minor_devt(minor
);
100 if ((major
!= major(dev
)) ||
101 (di_minor_type(minor
) != DDM_MINOR
) ||
102 (di_minor_spectype(minor
) != S_IFCHR
) ||
103 ((minor_path
= di_devfs_minor_path(minor
)) == NULL
)) {
107 if (hal_device_store_match_key_value_string(hald_get_gdl(),
108 "solaris.devfs_path", minor_path
) == NULL
) {
109 devinfo_acpi_add_minor(d
, node
, minor_path
, dev
);
112 di_devfs_path_free(minor_path
);
114 di_devlink_fini(&devlink_hdl
);
120 devinfo_acpi_add_minor(HalDevice
*parent
, di_node_t node
, char *minor_path
,
125 d
= hal_device_new();
126 devinfo_set_default_properties(d
, parent
, node
, minor_path
);
127 devinfo_add_enqueue(d
, minor_path
, &devinfo_acpi_handler
);
131 devinfo_power_button_add(HalDevice
*parent
, di_node_t node
, char *devfs_path
,
137 driver_name
= di_driver_name(node
);
138 if ((driver_name
== NULL
) || (strcmp(driver_name
, "power") != 0)) {
142 d
= hal_device_new();
144 devinfo_set_default_properties(d
, parent
, node
, devfs_path
);
145 hal_device_add_capability(d
, "button");
146 hal_device_property_set_bool(d
, "button.has_state", FALSE
);
147 hal_device_property_set_string(d
, "info.category", "input");
148 hal_device_property_set_string(d
, "button.type", "power");
149 hal_device_property_set_string(d
, "info.product", "Power Button");
151 devinfo_add_enqueue(d
, devfs_path
, &devinfo_power_button_handler
);
157 devinfo_power_button_event(void)
160 HalDeviceStore
*store
= hald_get_gdl();
162 d
= hal_device_store_match_key_value_string (store
, "button.type",
165 device_send_signal_condition(d
, "ButtonPressed", "power");
170 devinfo_brightness_hotkeys_event(char *subclass
)
174 if ((d
= hal_device_store_find(hald_get_gdl(),
175 "/org/freedesktop/Hal/devices/computer")) ||
176 (d
= hal_device_store_find(hald_get_tdl(),
177 "/org/freedesktop/Hal/devices/computer"))) {
178 if (strcmp(subclass
, ESC_PWRCTL_BRIGHTNESS_UP
) == 0) {
179 device_send_signal_condition(d
, "ButtonPressed",
182 device_send_signal_condition(d
, "ButtonPressed",
189 devinfo_battery_rescan(char *parent_devfs_path
, gchar
*udi
)
193 d
= hal_device_store_find(hald_get_gdl(), udi
);
195 HAL_INFO(("device not found %s", udi
));
199 hald_runner_run(d
, "hald-probe-acpi", NULL
,
200 DEVINFO_PROBE_ACPI_TIMEOUT
, devinfo_battery_rescan_probing_done
,
205 devinfo_lid_event(char *subclass
, gchar
*udi
)
209 d
= hal_device_store_find(hald_get_gdl(), udi
);
211 HAL_INFO(("device not found %s", udi
));
215 hal_device_property_set_bool(d
, "button.state.value",
216 (strcmp(subclass
, ESC_PWRCTL_REMOVE
) == 0));
217 device_send_signal_condition(d
, "ButtonPressed", "lid");
221 devinfo_lid_rescan(HalDevice
*d
)
223 if (hal_device_property_get_bool(d
, "button.workaround")) {
224 /* Set lid state to open for workaround */
225 hal_device_property_set_bool(d
, "button.state.value", FALSE
);
227 hald_runner_run(d
, "hald-probe-acpi", NULL
,
228 DEVINFO_PROBE_ACPI_TIMEOUT
,
229 devinfo_battery_rescan_probing_done
, NULL
, NULL
);
236 devinfo_battery_rescan_probing_done(HalDevice
*d
, guint32 exit_type
,
237 gint return_code
, char **error
, gpointer userdata1
, gpointer userdata2
)
239 /* hald_runner_run() requires this function since cannot pass NULL */
243 devinfo_acpi_get_prober(HalDevice
*d
, int *timeout
)
245 *timeout
= DEVINFO_PROBE_ACPI_TIMEOUT
; /* 30 second timeout */
246 return ("hald-probe-acpi");