122 slave->base_type = 0; |
122 slave->base_type = 0; |
123 slave->base_revision = 0; |
123 slave->base_revision = 0; |
124 slave->base_build = 0; |
124 slave->base_build = 0; |
125 slave->base_fmmu_count = 0; |
125 slave->base_fmmu_count = 0; |
126 |
126 |
127 slave->sii_data = NULL; |
127 slave->sii_words = NULL; |
128 slave->sii_size = 0; |
128 slave->sii_nwords = 0; |
129 |
129 |
130 slave->sii.alias = 0; |
130 slave->sii.alias = 0; |
131 slave->sii.vendor_id = 0; |
131 slave->sii.vendor_id = 0; |
132 slave->sii.product_code = 0; |
132 slave->sii.product_code = 0; |
133 slave->sii.revision_number = 0; |
133 slave->sii.revision_number = 0; |
1031 if (remainder == (char *) data || (*remainder && *remainder != '\n')) { |
1031 if (remainder == (char *) data || (*remainder && *remainder != '\n')) { |
1032 EC_ERR("Invalid alias value! Dropping.\n"); |
1032 EC_ERR("Invalid alias value! Dropping.\n"); |
1033 return -EINVAL; |
1033 return -EINVAL; |
1034 } |
1034 } |
1035 |
1035 |
1036 if (!slave->sii_data || slave->sii_size < 16) { |
1036 if (!slave->sii_words || slave->sii_nwords < 8) { |
1037 EC_ERR("Failed to read SII contents from slave %u.\n", |
1037 EC_ERR("Failed to read SII contents from slave %u.\n", |
1038 slave->ring_position); |
1038 slave->ring_position); |
1039 return -EINVAL; |
1039 return -EINVAL; |
1040 } |
1040 } |
1041 |
1041 |
1042 // copy first 7 words of recent SII contents |
1042 // copy first 7 words of recent SII contents |
1043 memcpy(sii_data, slave->sii_data, 14); |
1043 memcpy(sii_data, (uint8_t *) slave->sii_words, 14); |
1044 |
1044 |
1045 // write new alias address in word 4 |
1045 // write new alias address in word 4 |
1046 EC_WRITE_U16(sii_data + 8, alias); |
1046 EC_WRITE_U16(sii_data + 8, alias); |
1047 |
1047 |
1048 // calculate new checksum over words 0 to 6 |
1048 // calculate new checksum over words 0 to 6 |
1075 struct attribute *attr, /**< attribute */ |
1075 struct attribute *attr, /**< attribute */ |
1076 char *buffer /**< memory to store data */ |
1076 char *buffer /**< memory to store data */ |
1077 ) |
1077 ) |
1078 { |
1078 { |
1079 ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj); |
1079 ec_slave_t *slave = container_of(kobj, ec_slave_t, kobj); |
|
1080 unsigned int sii_size; |
1080 |
1081 |
1081 if (attr == &attr_info) { |
1082 if (attr == &attr_info) { |
1082 return ec_slave_info(slave, buffer); |
1083 return ec_slave_info(slave, buffer); |
1083 } else if (attr == &attr_sii) { |
1084 } else if (attr == &attr_sii) { |
1084 if (slave->sii_data) { |
1085 if (slave->sii_words) { |
1085 if (slave->sii_size > PAGE_SIZE) { |
1086 sii_size = slave->sii_nwords * 2; |
|
1087 if (sii_size > PAGE_SIZE) { |
1086 EC_ERR("SII contents of slave %u exceed 1 page (%u/%u).\n", |
1088 EC_ERR("SII contents of slave %u exceed 1 page (%u/%u).\n", |
1087 slave->ring_position, slave->sii_size, |
1089 slave->ring_position, sii_size, |
1088 (int) PAGE_SIZE); |
1090 (int) PAGE_SIZE); |
1089 } |
1091 } |
1090 else { |
1092 else { |
1091 memcpy(buffer, slave->sii_data, slave->sii_size); |
1093 memcpy(buffer, (uint8_t *) slave->sii_words, sii_size); |
1092 return slave->sii_size; |
1094 return sii_size; |
1093 } |
1095 } |
1094 } |
1096 } |
1095 } else if (attr == &attr_alias) { |
1097 } else if (attr == &attr_alias) { |
1096 return sprintf(buffer, "%u\n", slave->sii.alias); |
1098 return sprintf(buffer, "%u\n", slave->sii.alias); |
1097 } |
1099 } |