00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031 #include <ctype.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <getopt.h>
00036 #include <assert.h>
00037 #include <unistd.h>
00038 #include <stdarg.h>
00039
00040 #include "../logger.h"
00041 #include "../device_store.h"
00042 #include "linux_i2c.h"
00043
00069 static char *
00070 i2c_compute_udi (HalDevice * d, int append_num)
00071 {
00072 static char buf[256];
00073
00074 if (append_num == -1)
00075 sprintf (buf, "/org/freedesktop/Hal/devices/i2c_%s",
00076 ds_property_get_string (d, "i2c.product"));
00077 else
00078 sprintf (buf, "/org/freedesktop/Hal/devices/i2c_%s/%d",
00079 ds_property_get_string (d, "i2c.product"),
00080 append_num);
00081
00082 return buf;
00083 }
00084
00085
00086
00087 static void visit_device_i2c_got_parent (HalDevice * parent,
00088 void *data1, void *data2);
00089
00098 void
00099 visit_device_i2c (const char *path, struct sysfs_device *device)
00100 {
00101 int i;
00102 int len;
00103 HalDevice *d;
00104 char attr_name[SYSFS_NAME_LEN];
00105 struct sysfs_attribute *cur;
00106 char *product_name = NULL;
00107 const char *driver;
00108 char *parent_sysfs_path;
00109
00110
00111 d = ds_device_new ();
00112 ds_property_set_string (d, "info.bus", "i2c");
00113 ds_property_set_string (d, "info.category", "i2c");
00114 ds_property_set_string (d, "info.capabilities", "i2c");
00115 ds_property_set_string (d, "linux.sysfs_path", path);
00116 ds_property_set_string (d, "linux.sysfs_path_device", path);
00121 ds_property_set_string (d, "i2c.linux.sysfs_path", path);
00122
00123
00124
00125 driver = drivers_lookup (path);
00126 if (driver != NULL)
00127 ds_property_set_string (d, "linux.driver", driver);
00128
00129 dlist_for_each_data (sysfs_get_device_attributes (device), cur,
00130 struct sysfs_attribute) {
00131
00132 if (sysfs_get_name_from_path (cur->path,
00133 attr_name,
00134 SYSFS_NAME_LEN) != 0)
00135 continue;
00136
00137
00138 len = strlen (cur->value);
00139 for (i = len - 1; isspace (cur->value[i]); --i)
00140 cur->value[i] = '\0';
00141
00142
00143
00144 if (strcmp (attr_name, "name") == 0)
00145 product_name = cur->value;
00146 }
00147
00148 if (product_name == NULL)
00149 product_name = "Unknown";
00150
00151 ds_property_set_string (d, "i2c.product", product_name);
00152
00153
00154
00155 ds_property_set_string (d, "info.product", product_name);
00156
00157 parent_sysfs_path = get_parent_sysfs_path (path);
00158
00159
00160
00161
00162
00163 HAL_INFO (("For device = %s, parent = %s",
00164 ds_property_get_string (d, "linux.sysfs_path"),
00165 parent_sysfs_path));
00166 ds_device_async_find_by_key_value_string
00167 ("linux.sysfs_path_device", parent_sysfs_path, TRUE,
00168 visit_device_i2c_got_parent, (void *) d, NULL,
00169 is_probing ? 0 : HAL_LINUX_HOTPLUG_TIMEOUT);
00170
00171 free (parent_sysfs_path);
00172 }
00173
00181 static void
00182 visit_device_i2c_got_parent (HalDevice * parent, void *data1, void *data2)
00183 {
00184 char *new_udi = NULL;
00185 HalDevice *new_d = NULL;
00186 HalDevice *d = (HalDevice *) data1;
00187
00188 if (parent != NULL) {
00189 ds_property_set_string (d, "info.parent", parent->udi);
00190 } else {
00191
00192 HAL_WARNING (("No parent for I2C device!"));
00193 }
00194
00195
00196
00197
00198 new_udi = rename_and_merge (d, i2c_compute_udi, "i2c");
00199 if (new_udi != NULL) {
00200 new_d = ds_device_find (new_udi);
00201 if (new_d != NULL) {
00202 ds_gdl_add (new_d);
00203 }
00204 }
00205 }
00206
00210 void
00211 linux_i2c_init ()
00212 {
00213
00214 drivers_collect ("i2c");
00215 }
00216
00221 void
00222 linux_i2c_detection_done ()
00223 {
00224 }
00225
00229 void
00230 linux_i2c_shutdown ()
00231 {
00232 }
00233