industrialio-buffer.c (651a88798412e216f337d70181127e847f00a4b7) | industrialio-buffer.c (74f582ec127e3b10aec71e8d15f1c14b0f0481ec) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* The industrial I/O core 3 * 4 * Copyright (c) 2008 Jonathan Cameron 5 * 6 * Handling of buffer allocation / resizing. 7 * 8 * Things to look at here. --- 496 unchanged lines hidden (view full) --- 505 size_t len) 506{ 507 int ret; 508 bool state; 509 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 510 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 511 struct iio_buffer *buffer = this_attr->buffer; 512 | 1// SPDX-License-Identifier: GPL-2.0-only 2/* The industrial I/O core 3 * 4 * Copyright (c) 2008 Jonathan Cameron 5 * 6 * Handling of buffer allocation / resizing. 7 * 8 * Things to look at here. --- 496 unchanged lines hidden (view full) --- 505 size_t len) 506{ 507 int ret; 508 bool state; 509 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 510 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); 511 struct iio_buffer *buffer = this_attr->buffer; 512 |
513 ret = strtobool(buf, &state); | 513 ret = kstrtobool(buf, &state); |
514 if (ret < 0) 515 return ret; 516 mutex_lock(&indio_dev->mlock); 517 if (iio_buffer_is_active(buffer)) { 518 ret = -EBUSY; 519 goto error_ret; 520 } 521 ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address); --- 30 unchanged lines hidden (view full) --- 552 const char *buf, 553 size_t len) 554{ 555 int ret; 556 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 557 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 558 bool state; 559 | 514 if (ret < 0) 515 return ret; 516 mutex_lock(&indio_dev->mlock); 517 if (iio_buffer_is_active(buffer)) { 518 ret = -EBUSY; 519 goto error_ret; 520 } 521 ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address); --- 30 unchanged lines hidden (view full) --- 552 const char *buf, 553 size_t len) 554{ 555 int ret; 556 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 557 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 558 bool state; 559 |
560 ret = strtobool(buf, &state); | 560 ret = kstrtobool(buf, &state); |
561 if (ret < 0) 562 return ret; 563 564 mutex_lock(&indio_dev->mlock); 565 if (iio_buffer_is_active(buffer)) { 566 ret = -EBUSY; 567 goto error_ret; 568 } --- 341 unchanged lines hidden (view full) --- 910 scan_mask = iio_scan_mask_match(indio_dev->available_scan_masks, 911 indio_dev->masklength, 912 compound_mask, 913 strict_scanmask); 914 bitmap_free(compound_mask); 915 if (scan_mask == NULL) 916 return -EINVAL; 917 } else { | 561 if (ret < 0) 562 return ret; 563 564 mutex_lock(&indio_dev->mlock); 565 if (iio_buffer_is_active(buffer)) { 566 ret = -EBUSY; 567 goto error_ret; 568 } --- 341 unchanged lines hidden (view full) --- 910 scan_mask = iio_scan_mask_match(indio_dev->available_scan_masks, 911 indio_dev->masklength, 912 compound_mask, 913 strict_scanmask); 914 bitmap_free(compound_mask); 915 if (scan_mask == NULL) 916 return -EINVAL; 917 } else { |
918 scan_mask = compound_mask; | 918 scan_mask = compound_mask; |
919 } 920 921 config->scan_bytes = iio_compute_scan_bytes(indio_dev, 922 scan_mask, scan_timestamp); 923 config->scan_mask = scan_mask; 924 config->scan_timestamp = scan_timestamp; 925 926 return 0; --- 127 unchanged lines hidden (view full) --- 1054 1055 return ret; 1056} 1057 1058static int iio_enable_buffers(struct iio_dev *indio_dev, 1059 struct iio_device_config *config) 1060{ 1061 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); | 919 } 920 921 config->scan_bytes = iio_compute_scan_bytes(indio_dev, 922 scan_mask, scan_timestamp); 923 config->scan_mask = scan_mask; 924 config->scan_timestamp = scan_timestamp; 925 926 return 0; --- 127 unchanged lines hidden (view full) --- 1054 1055 return ret; 1056} 1057 1058static int iio_enable_buffers(struct iio_dev *indio_dev, 1059 struct iio_device_config *config) 1060{ 1061 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); |
1062 struct iio_buffer *buffer; | 1062 struct iio_buffer *buffer, *tmp = NULL; |
1063 int ret; 1064 1065 indio_dev->active_scan_mask = config->scan_mask; 1066 indio_dev->scan_timestamp = config->scan_timestamp; 1067 indio_dev->scan_bytes = config->scan_bytes; | 1063 int ret; 1064 1065 indio_dev->active_scan_mask = config->scan_mask; 1066 indio_dev->scan_timestamp = config->scan_timestamp; 1067 indio_dev->scan_bytes = config->scan_bytes; |
1068 indio_dev->currentmode = config->mode; | 1068 iio_dev_opaque->currentmode = config->mode; |
1069 1070 iio_update_demux(indio_dev); 1071 1072 /* Wind up again */ 1073 if (indio_dev->setup_ops->preenable) { 1074 ret = indio_dev->setup_ops->preenable(indio_dev); 1075 if (ret) { 1076 dev_dbg(&indio_dev->dev, --- 15 unchanged lines hidden (view full) --- 1092 } 1093 1094 if (indio_dev->info->hwfifo_set_watermark) 1095 indio_dev->info->hwfifo_set_watermark(indio_dev, 1096 config->watermark); 1097 1098 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { 1099 ret = iio_buffer_enable(buffer, indio_dev); | 1069 1070 iio_update_demux(indio_dev); 1071 1072 /* Wind up again */ 1073 if (indio_dev->setup_ops->preenable) { 1074 ret = indio_dev->setup_ops->preenable(indio_dev); 1075 if (ret) { 1076 dev_dbg(&indio_dev->dev, --- 15 unchanged lines hidden (view full) --- 1092 } 1093 1094 if (indio_dev->info->hwfifo_set_watermark) 1095 indio_dev->info->hwfifo_set_watermark(indio_dev, 1096 config->watermark); 1097 1098 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { 1099 ret = iio_buffer_enable(buffer, indio_dev); |
1100 if (ret) | 1100 if (ret) { 1101 tmp = buffer; |
1101 goto err_disable_buffers; | 1102 goto err_disable_buffers; |
1103 } |
|
1102 } 1103 | 1104 } 1105 |
1104 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { | 1106 if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { |
1105 ret = iio_trigger_attach_poll_func(indio_dev->trig, 1106 indio_dev->pollfunc); 1107 if (ret) 1108 goto err_disable_buffers; 1109 } 1110 1111 if (indio_dev->setup_ops->postenable) { 1112 ret = indio_dev->setup_ops->postenable(indio_dev); 1113 if (ret) { 1114 dev_dbg(&indio_dev->dev, 1115 "Buffer not started: postenable failed (%d)\n", ret); 1116 goto err_detach_pollfunc; 1117 } 1118 } 1119 1120 return 0; 1121 1122err_detach_pollfunc: | 1107 ret = iio_trigger_attach_poll_func(indio_dev->trig, 1108 indio_dev->pollfunc); 1109 if (ret) 1110 goto err_disable_buffers; 1111 } 1112 1113 if (indio_dev->setup_ops->postenable) { 1114 ret = indio_dev->setup_ops->postenable(indio_dev); 1115 if (ret) { 1116 dev_dbg(&indio_dev->dev, 1117 "Buffer not started: postenable failed (%d)\n", ret); 1118 goto err_detach_pollfunc; 1119 } 1120 } 1121 1122 return 0; 1123 1124err_detach_pollfunc: |
1123 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { | 1125 if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { |
1124 iio_trigger_detach_poll_func(indio_dev->trig, 1125 indio_dev->pollfunc); 1126 } 1127err_disable_buffers: | 1126 iio_trigger_detach_poll_func(indio_dev->trig, 1127 indio_dev->pollfunc); 1128 } 1129err_disable_buffers: |
1130 buffer = list_prepare_entry(tmp, &iio_dev_opaque->buffer_list, buffer_list); |
|
1128 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, 1129 buffer_list) 1130 iio_buffer_disable(buffer, indio_dev); 1131err_run_postdisable: 1132 if (indio_dev->setup_ops->postdisable) 1133 indio_dev->setup_ops->postdisable(indio_dev); 1134err_undo_config: | 1131 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, 1132 buffer_list) 1133 iio_buffer_disable(buffer, indio_dev); 1134err_run_postdisable: 1135 if (indio_dev->setup_ops->postdisable) 1136 indio_dev->setup_ops->postdisable(indio_dev); 1137err_undo_config: |
1135 indio_dev->currentmode = INDIO_DIRECT_MODE; | 1138 iio_dev_opaque->currentmode = INDIO_DIRECT_MODE; |
1136 indio_dev->active_scan_mask = NULL; 1137 1138 return ret; 1139} 1140 1141static int iio_disable_buffers(struct iio_dev *indio_dev) 1142{ 1143 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); --- 13 unchanged lines hidden (view full) --- 1157 */ 1158 1159 if (indio_dev->setup_ops->predisable) { 1160 ret2 = indio_dev->setup_ops->predisable(indio_dev); 1161 if (ret2 && !ret) 1162 ret = ret2; 1163 } 1164 | 1139 indio_dev->active_scan_mask = NULL; 1140 1141 return ret; 1142} 1143 1144static int iio_disable_buffers(struct iio_dev *indio_dev) 1145{ 1146 struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); --- 13 unchanged lines hidden (view full) --- 1160 */ 1161 1162 if (indio_dev->setup_ops->predisable) { 1163 ret2 = indio_dev->setup_ops->predisable(indio_dev); 1164 if (ret2 && !ret) 1165 ret = ret2; 1166 } 1167 |
1165 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { | 1168 if (iio_dev_opaque->currentmode == INDIO_BUFFER_TRIGGERED) { |
1166 iio_trigger_detach_poll_func(indio_dev->trig, 1167 indio_dev->pollfunc); 1168 } 1169 1170 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { 1171 ret2 = iio_buffer_disable(buffer, indio_dev); 1172 if (ret2 && !ret) 1173 ret = ret2; 1174 } 1175 1176 if (indio_dev->setup_ops->postdisable) { 1177 ret2 = indio_dev->setup_ops->postdisable(indio_dev); 1178 if (ret2 && !ret) 1179 ret = ret2; 1180 } 1181 1182 iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask); 1183 indio_dev->active_scan_mask = NULL; | 1169 iio_trigger_detach_poll_func(indio_dev->trig, 1170 indio_dev->pollfunc); 1171 } 1172 1173 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { 1174 ret2 = iio_buffer_disable(buffer, indio_dev); 1175 if (ret2 && !ret) 1176 ret = ret2; 1177 } 1178 1179 if (indio_dev->setup_ops->postdisable) { 1180 ret2 = indio_dev->setup_ops->postdisable(indio_dev); 1181 if (ret2 && !ret) 1182 ret = ret2; 1183 } 1184 1185 iio_free_scan_mask(indio_dev, indio_dev->active_scan_mask); 1186 indio_dev->active_scan_mask = NULL; |
1184 indio_dev->currentmode = INDIO_DIRECT_MODE; | 1187 iio_dev_opaque->currentmode = INDIO_DIRECT_MODE; |
1185 1186 return ret; 1187} 1188 1189static int __iio_update_buffers(struct iio_dev *indio_dev, 1190 struct iio_buffer *insert_buffer, 1191 struct iio_buffer *remove_buffer) 1192{ --- 102 unchanged lines hidden (view full) --- 1295 size_t len) 1296{ 1297 int ret; 1298 bool requested_state; 1299 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1300 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1301 bool inlist; 1302 | 1188 1189 return ret; 1190} 1191 1192static int __iio_update_buffers(struct iio_dev *indio_dev, 1193 struct iio_buffer *insert_buffer, 1194 struct iio_buffer *remove_buffer) 1195{ --- 102 unchanged lines hidden (view full) --- 1298 size_t len) 1299{ 1300 int ret; 1301 bool requested_state; 1302 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 1303 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; 1304 bool inlist; 1305 |
1303 ret = strtobool(buf, &requested_state); | 1306 ret = kstrtobool(buf, &requested_state); |
1304 if (ret < 0) 1305 return ret; 1306 1307 mutex_lock(&indio_dev->mlock); 1308 1309 /* Find out if it is in the list */ 1310 inlist = iio_buffer_is_active(buffer); 1311 /* Already in desired state */ --- 312 unchanged lines hidden (view full) --- 1624 INIT_LIST_HEAD(&buffer->buffer_attr_list); 1625 channels = indio_dev->channels; 1626 if (channels) { 1627 /* new magic */ 1628 for (i = 0; i < indio_dev->num_channels; i++) { 1629 if (channels[i].scan_index < 0) 1630 continue; 1631 | 1307 if (ret < 0) 1308 return ret; 1309 1310 mutex_lock(&indio_dev->mlock); 1311 1312 /* Find out if it is in the list */ 1313 inlist = iio_buffer_is_active(buffer); 1314 /* Already in desired state */ --- 312 unchanged lines hidden (view full) --- 1627 INIT_LIST_HEAD(&buffer->buffer_attr_list); 1628 channels = indio_dev->channels; 1629 if (channels) { 1630 /* new magic */ 1631 for (i = 0; i < indio_dev->num_channels; i++) { 1632 if (channels[i].scan_index < 0) 1633 continue; 1634 |
1635 /* Verify that sample bits fit into storage */ 1636 if (channels[i].scan_type.storagebits < 1637 channels[i].scan_type.realbits + 1638 channels[i].scan_type.shift) { 1639 dev_err(&indio_dev->dev, 1640 "Channel %d storagebits (%d) < shifted realbits (%d + %d)\n", 1641 i, channels[i].scan_type.storagebits, 1642 channels[i].scan_type.realbits, 1643 channels[i].scan_type.shift); 1644 ret = -EINVAL; 1645 goto error_cleanup_dynamic; 1646 } 1647 |
|
1632 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer, 1633 &channels[i]); 1634 if (ret < 0) 1635 goto error_cleanup_dynamic; 1636 scan_el_attrcount += ret; 1637 if (channels[i].type == IIO_TIMESTAMP) 1638 iio_dev_opaque->scan_index_timestamp = 1639 channels[i].scan_index; --- 4 unchanged lines hidden (view full) --- 1644 if (buffer->scan_mask == NULL) { 1645 ret = -ENOMEM; 1646 goto error_cleanup_dynamic; 1647 } 1648 } 1649 } 1650 1651 attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs); | 1648 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer, 1649 &channels[i]); 1650 if (ret < 0) 1651 goto error_cleanup_dynamic; 1652 scan_el_attrcount += ret; 1653 if (channels[i].type == IIO_TIMESTAMP) 1654 iio_dev_opaque->scan_index_timestamp = 1655 channels[i].scan_index; --- 4 unchanged lines hidden (view full) --- 1660 if (buffer->scan_mask == NULL) { 1661 ret = -ENOMEM; 1662 goto error_cleanup_dynamic; 1663 } 1664 } 1665 } 1666 1667 attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs); |
1652 attr = kcalloc(attrn + 1, sizeof(* attr), GFP_KERNEL); | 1668 attr = kcalloc(attrn + 1, sizeof(*attr), GFP_KERNEL); |
1653 if (!attr) { 1654 ret = -ENOMEM; 1655 goto error_free_scan_mask; 1656 } 1657 1658 memcpy(attr, iio_buffer_attrs, sizeof(iio_buffer_attrs)); 1659 if (!buffer->access->set_length) 1660 attr[0] = &dev_attr_length_ro.attr; --- 333 unchanged lines hidden --- | 1669 if (!attr) { 1670 ret = -ENOMEM; 1671 goto error_free_scan_mask; 1672 } 1673 1674 memcpy(attr, iio_buffer_attrs, sizeof(iio_buffer_attrs)); 1675 if (!buffer->access->set_length) 1676 attr[0] = &dev_attr_length_ro.attr; --- 333 unchanged lines hidden --- |