.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Xilinx XADC driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2013-2014 Analog Devices Inc. |
---|
5 | | - * Author: Lars-Peter Clauen <lars@metafoo.de> |
---|
6 | | - * |
---|
7 | | - * Licensed under the GPL-2. |
---|
| 6 | + * Author: Lars-Peter Clausen <lars@metafoo.de> |
---|
8 | 7 | * |
---|
9 | 8 | * Documentation for the parts can be found at: |
---|
10 | 9 | * - XADC hardmacro: Xilinx UG480 |
---|
.. | .. |
---|
664 | 663 | mutex_lock(&xadc->mutex); |
---|
665 | 664 | |
---|
666 | 665 | if (state) { |
---|
667 | | - /* Only one of the two triggers can be active at the a time. */ |
---|
| 666 | + /* Only one of the two triggers can be active at a time. */ |
---|
668 | 667 | if (xadc->trigger != NULL) { |
---|
669 | 668 | ret = -EBUSY; |
---|
670 | 669 | goto err_out; |
---|
.. | .. |
---|
840 | 839 | |
---|
841 | 840 | static const struct iio_buffer_setup_ops xadc_buffer_ops = { |
---|
842 | 841 | .preenable = &xadc_preenable, |
---|
843 | | - .postenable = &iio_triggered_buffer_postenable, |
---|
844 | | - .predisable = &iio_triggered_buffer_predisable, |
---|
845 | 842 | .postdisable = &xadc_postdisable, |
---|
846 | 843 | }; |
---|
847 | 844 | |
---|
.. | .. |
---|
1095 | 1092 | static int xadc_parse_dt(struct iio_dev *indio_dev, struct device_node *np, |
---|
1096 | 1093 | unsigned int *conf) |
---|
1097 | 1094 | { |
---|
| 1095 | + struct device *dev = indio_dev->dev.parent; |
---|
1098 | 1096 | struct xadc *xadc = iio_priv(indio_dev); |
---|
1099 | 1097 | struct iio_chan_spec *channels, *chan; |
---|
1100 | 1098 | struct device_node *chan_node, *child; |
---|
.. | .. |
---|
1139 | 1137 | *conf |= XADC_CONF0_MUX | XADC_CONF0_CHAN(ext_mux_chan); |
---|
1140 | 1138 | } |
---|
1141 | 1139 | |
---|
1142 | | - channels = kmemdup(xadc_channels, sizeof(xadc_channels), GFP_KERNEL); |
---|
| 1140 | + channels = devm_kmemdup(dev, xadc_channels, |
---|
| 1141 | + sizeof(xadc_channels), GFP_KERNEL); |
---|
1143 | 1142 | if (!channels) |
---|
1144 | 1143 | return -ENOMEM; |
---|
1145 | 1144 | |
---|
.. | .. |
---|
1175 | 1174 | of_node_put(chan_node); |
---|
1176 | 1175 | |
---|
1177 | 1176 | indio_dev->num_channels = num_channels; |
---|
1178 | | - indio_dev->channels = krealloc(channels, sizeof(*channels) * |
---|
1179 | | - num_channels, GFP_KERNEL); |
---|
| 1177 | + indio_dev->channels = devm_krealloc(dev, channels, |
---|
| 1178 | + sizeof(*channels) * num_channels, |
---|
| 1179 | + GFP_KERNEL); |
---|
1180 | 1180 | /* If we can't resize the channels array, just use the original */ |
---|
1181 | 1181 | if (!indio_dev->channels) |
---|
1182 | 1182 | indio_dev->channels = channels; |
---|
.. | .. |
---|
1189 | 1189 | const struct of_device_id *id; |
---|
1190 | 1190 | struct iio_dev *indio_dev; |
---|
1191 | 1191 | unsigned int bipolar_mask; |
---|
1192 | | - struct resource *mem; |
---|
1193 | 1192 | unsigned int conf0; |
---|
1194 | 1193 | struct xadc *xadc; |
---|
1195 | 1194 | int ret; |
---|
.. | .. |
---|
1219 | 1218 | spin_lock_init(&xadc->lock); |
---|
1220 | 1219 | INIT_DELAYED_WORK(&xadc->zynq_unmask_work, xadc_zynq_unmask_worker); |
---|
1221 | 1220 | |
---|
1222 | | - mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1223 | | - xadc->base = devm_ioremap_resource(&pdev->dev, mem); |
---|
| 1221 | + xadc->base = devm_platform_ioremap_resource(pdev, 0); |
---|
1224 | 1222 | if (IS_ERR(xadc->base)) |
---|
1225 | 1223 | return PTR_ERR(xadc->base); |
---|
1226 | 1224 | |
---|
1227 | | - indio_dev->dev.parent = &pdev->dev; |
---|
1228 | | - indio_dev->dev.of_node = pdev->dev.of_node; |
---|
1229 | 1225 | indio_dev->name = "xadc"; |
---|
1230 | 1226 | indio_dev->modes = INDIO_DIRECT_MODE; |
---|
1231 | 1227 | indio_dev->info = &xadc_info; |
---|
1232 | 1228 | |
---|
1233 | 1229 | ret = xadc_parse_dt(indio_dev, pdev->dev.of_node, &conf0); |
---|
1234 | 1230 | if (ret) |
---|
1235 | | - goto err_device_free; |
---|
| 1231 | + return ret; |
---|
1236 | 1232 | |
---|
1237 | 1233 | if (xadc->ops->flags & XADC_FLAGS_BUFFERED) { |
---|
1238 | 1234 | ret = iio_triggered_buffer_setup(indio_dev, |
---|
1239 | 1235 | &iio_pollfunc_store_time, &xadc_trigger_handler, |
---|
1240 | 1236 | &xadc_buffer_ops); |
---|
1241 | 1237 | if (ret) |
---|
1242 | | - goto err_device_free; |
---|
| 1238 | + return ret; |
---|
1243 | 1239 | |
---|
1244 | 1240 | xadc->convst_trigger = xadc_alloc_trigger(indio_dev, "convst"); |
---|
1245 | 1241 | if (IS_ERR(xadc->convst_trigger)) { |
---|
.. | .. |
---|
1326 | 1322 | xadc->threshold[i] = 0xffff; |
---|
1327 | 1323 | else |
---|
1328 | 1324 | xadc->threshold[i] = 0; |
---|
1329 | | - xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i), |
---|
| 1325 | + ret = xadc_write_adc_reg(xadc, XADC_REG_THRESHOLD(i), |
---|
1330 | 1326 | xadc->threshold[i]); |
---|
| 1327 | + if (ret) |
---|
| 1328 | + goto err_free_irq; |
---|
1331 | 1329 | } |
---|
1332 | 1330 | |
---|
1333 | 1331 | /* Go to non-buffered mode */ |
---|
.. | .. |
---|
1355 | 1353 | err_triggered_buffer_cleanup: |
---|
1356 | 1354 | if (xadc->ops->flags & XADC_FLAGS_BUFFERED) |
---|
1357 | 1355 | iio_triggered_buffer_cleanup(indio_dev); |
---|
1358 | | -err_device_free: |
---|
1359 | | - kfree(indio_dev->channels); |
---|
1360 | 1356 | |
---|
1361 | 1357 | return ret; |
---|
1362 | 1358 | } |
---|
.. | .. |
---|
1376 | 1372 | cancel_delayed_work_sync(&xadc->zynq_unmask_work); |
---|
1377 | 1373 | clk_disable_unprepare(xadc->clk); |
---|
1378 | 1374 | kfree(xadc->data); |
---|
1379 | | - kfree(indio_dev->channels); |
---|
1380 | 1375 | |
---|
1381 | 1376 | return 0; |
---|
1382 | 1377 | } |
---|