master/slave.c
changeset 183 8ae1e011e96c
parent 182 8c0bc99229a9
child 184 2fc86cec12df
equal deleted inserted replaced
182:8c0bc99229a9 183:8ae1e011e96c
    27 ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
    27 ssize_t ec_show_slave_attribute(struct kobject *, struct attribute *, char *);
    28 
    28 
    29 /*****************************************************************************/
    29 /*****************************************************************************/
    30 
    30 
    31 static struct attribute attr_ring_position = {
    31 static struct attribute attr_ring_position = {
    32     .name = "ring_position",
    32     .name = "ring_position", .owner = THIS_MODULE, .mode = S_IRUGO
    33     .owner = THIS_MODULE,
    33 };
    34     .mode = S_IRUGO
    34 
       
    35 static struct attribute attr_station_address = {
       
    36     .name = "station_address", .owner = THIS_MODULE, .mode = S_IRUGO
       
    37 };
       
    38 
       
    39 static struct attribute attr_vendor_name = {
       
    40     .name = "vendor_name", .owner = THIS_MODULE, .mode = S_IRUGO
       
    41 };
       
    42 
       
    43 static struct attribute attr_product_name = {
       
    44     .name = "product_name", .owner = THIS_MODULE, .mode = S_IRUGO
       
    45 };
       
    46 
       
    47 static struct attribute attr_product_desc = {
       
    48     .name = "product_description", .owner = THIS_MODULE, .mode = S_IRUGO
    35 };
    49 };
    36 
    50 
    37 static struct attribute *def_attrs[] = {
    51 static struct attribute *def_attrs[] = {
    38     &attr_ring_position,
    52     &attr_ring_position,
       
    53     &attr_station_address,
       
    54     &attr_vendor_name,
       
    55     &attr_product_name,
       
    56     &attr_product_desc,
    39     NULL,
    57     NULL,
    40 };
    58 };
    41 
    59 
    42 static struct sysfs_ops sysfs_ops = {
    60 static struct sysfs_ops sysfs_ops = {
    43     .show = &ec_show_slave_attribute,
    61     .show = &ec_show_slave_attribute,
   112     INIT_LIST_HEAD(&slave->eeprom_strings);
   130     INIT_LIST_HEAD(&slave->eeprom_strings);
   113     INIT_LIST_HEAD(&slave->eeprom_syncs);
   131     INIT_LIST_HEAD(&slave->eeprom_syncs);
   114     INIT_LIST_HEAD(&slave->eeprom_pdos);
   132     INIT_LIST_HEAD(&slave->eeprom_pdos);
   115     INIT_LIST_HEAD(&slave->sdo_dictionary);
   133     INIT_LIST_HEAD(&slave->sdo_dictionary);
   116 
   134 
   117     for (i = 0; i < 2; i++) {
   135     for (i = 0; i < 4; i++) {
   118         slave->dl_status_link[i] = 0;
   136         slave->dl_link[i] = 0;
   119         slave->dl_status_loop[i] = 0;
   137         slave->dl_loop[i] = 0;
   120         slave->dl_status_comm[i] = 0;
   138         slave->dl_signal[i] = 0;
   121     }
   139     }
   122 
   140 
   123     return 0;
   141     return 0;
   124 }
   142 }
   125 
   143 
   228                slave->ring_position);
   246                slave->ring_position);
   229         return -1;
   247         return -1;
   230     }
   248     }
   231 
   249 
   232     dl_status = EC_READ_U16(command->data);
   250     dl_status = EC_READ_U16(command->data);
   233     for (i = 0; i < 2; i++) {
   251     for (i = 0; i < 4; i++) {
   234         slave->dl_status_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0;
   252         slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0;
   235         slave->dl_status_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0;
   253         slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0;
   236         slave->dl_status_comm[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0;
   254         slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0;
   237     }
   255     }
   238 
   256 
   239     // Read EEPROM data
   257     // Read EEPROM data
   240     if (ec_slave_sii_read16(slave, 0x0004, &slave->sii_alias))
   258     if (ec_slave_sii_read16(slave, 0x0004, &slave->sii_alias))
   241         return -1;
   259         return -1;
  1002     if (!verbosity) return;
  1020     if (!verbosity) return;
  1003 
  1021 
  1004     EC_INFO("  Station address: 0x%04X\n", slave->station_address);
  1022     EC_INFO("  Station address: 0x%04X\n", slave->station_address);
  1005 
  1023 
  1006     EC_INFO("  Data link status:\n");
  1024     EC_INFO("  Data link status:\n");
  1007     for (i = 0; i < 2; i++) {
  1025     for (i = 0; i < 4; i++) {
  1008         EC_INFO("    Port %i: link %s, loop %s, comm %s\n", i,
  1026         EC_INFO("    Port %i: link %s, loop %s, %s\n", i,
  1009                 slave->dl_status_link[i] ? "up" : "down",
  1027                 slave->dl_link[i] ? "up" : "down",
  1010                 slave->dl_status_loop[i] ? "closed" : "open",
  1028                 slave->dl_loop[i] ? "closed" : "open",
  1011                 slave->dl_status_comm[i] ? "up" : "down");
  1029                 slave->dl_signal[i] ? "signal detected" : "no signal");
  1012     }
  1030     }
  1013 
  1031 
  1014     EC_INFO("  Base information:\n");
  1032     EC_INFO("  Base information:\n");
  1015     EC_INFO("    Type %u, revision %i, build %i\n",
  1033     EC_INFO("    Type %u, revision %i, build %i\n",
  1016             slave->base_type, slave->base_revision, slave->base_build);
  1034             slave->base_type, slave->base_revision, slave->base_build);
  1203     ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj);
  1221     ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj);
  1204 
  1222 
  1205     if (attr == &attr_ring_position) {
  1223     if (attr == &attr_ring_position) {
  1206         return sprintf(buffer, "%i\n", slave->ring_position);
  1224         return sprintf(buffer, "%i\n", slave->ring_position);
  1207     }
  1225     }
       
  1226     else if (attr == &attr_station_address) {
       
  1227         return sprintf(buffer, "%i\n", slave->station_address);
       
  1228     }
       
  1229     else if (attr == &attr_vendor_name) {
       
  1230         if (slave->type)
       
  1231             return sprintf(buffer, "%s\n", slave->type->vendor_name);
       
  1232     }
       
  1233     else if (attr == &attr_product_name) {
       
  1234         if (slave->type)
       
  1235             return sprintf(buffer, "%s\n", slave->type->product_name);
       
  1236     }
       
  1237     else if (attr == &attr_product_desc) {
       
  1238         if (slave->type)
       
  1239             return sprintf(buffer, "%s\n", slave->type->description);
       
  1240     }
  1208 
  1241 
  1209     return 0;
  1242     return 0;
  1210 }
  1243 }
  1211 
  1244 
  1212 /*****************************************************************************/
  1245 /*****************************************************************************/