| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2017 Tony Lindgren <tony@atomide.com> |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * earlier driver found in the Motorola Linux kernel: |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Copyright (C) 2009-2010 Motorola, Inc. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 11 | | - * published by the Free Software Foundation. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | 9 | */ |
|---|
| 18 | 10 | |
|---|
| 19 | 11 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 23 | 15 | #include <linux/interrupt.h> |
|---|
| 24 | 16 | #include <linux/kernel.h> |
|---|
| 25 | 17 | #include <linux/module.h> |
|---|
| 26 | | -#include <linux/of.h> |
|---|
| 27 | | -#include <linux/of_platform.h> |
|---|
| 18 | +#include <linux/mod_devicetable.h> |
|---|
| 28 | 19 | #include <linux/platform_device.h> |
|---|
| 20 | +#include <linux/property.h> |
|---|
| 29 | 21 | #include <linux/regmap.h> |
|---|
| 30 | 22 | |
|---|
| 31 | 23 | #include <linux/iio/buffer.h> |
|---|
| .. | .. |
|---|
| 90 | 82 | |
|---|
| 91 | 83 | #define CPCAP_ADC_MAX_RETRIES 5 /* Calibration */ |
|---|
| 92 | 84 | |
|---|
| 93 | | -/** |
|---|
| 85 | +/* |
|---|
| 94 | 86 | * struct cpcap_adc_ato - timing settings for cpcap adc |
|---|
| 95 | 87 | * |
|---|
| 96 | 88 | * Unfortunately no cpcap documentation available, please document when |
|---|
| .. | .. |
|---|
| 129 | 121 | bool done; |
|---|
| 130 | 122 | }; |
|---|
| 131 | 123 | |
|---|
| 132 | | -/** |
|---|
| 124 | +/* |
|---|
| 133 | 125 | * enum cpcap_adc_channel - cpcap adc channels |
|---|
| 134 | 126 | */ |
|---|
| 135 | 127 | enum cpcap_adc_channel { |
|---|
| .. | .. |
|---|
| 160 | 152 | CPCAP_ADC_CHANNEL_NUM, |
|---|
| 161 | 153 | }; |
|---|
| 162 | 154 | |
|---|
| 163 | | -/** |
|---|
| 155 | +/* |
|---|
| 164 | 156 | * enum cpcap_adc_timing - cpcap adc timing options |
|---|
| 165 | 157 | * |
|---|
| 166 | 158 | * CPCAP_ADC_TIMING_IMM seems to be immediate with no timings. |
|---|
| .. | .. |
|---|
| 698 | 690 | break; |
|---|
| 699 | 691 | case CPCAP_ADC_BATTI_PI17: |
|---|
| 700 | 692 | index = req->bank_index; |
|---|
| 701 | | - /* fallthrough */ |
|---|
| 693 | + fallthrough; |
|---|
| 702 | 694 | default: |
|---|
| 703 | 695 | req->result += conv_tbl[index].cal_offset; |
|---|
| 704 | 696 | req->result += conv_tbl[index].align_offset; |
|---|
| .. | .. |
|---|
| 963 | 955 | |
|---|
| 964 | 956 | static int cpcap_adc_probe(struct platform_device *pdev) |
|---|
| 965 | 957 | { |
|---|
| 966 | | - const struct of_device_id *match; |
|---|
| 967 | 958 | struct cpcap_adc *ddata; |
|---|
| 968 | 959 | struct iio_dev *indio_dev; |
|---|
| 969 | 960 | int error; |
|---|
| 970 | | - |
|---|
| 971 | | - match = of_match_device(of_match_ptr(cpcap_adc_id_table), |
|---|
| 972 | | - &pdev->dev); |
|---|
| 973 | | - if (!match) |
|---|
| 974 | | - return -EINVAL; |
|---|
| 975 | | - |
|---|
| 976 | | - if (!match->data) { |
|---|
| 977 | | - dev_err(&pdev->dev, "no configuration data found\n"); |
|---|
| 978 | | - |
|---|
| 979 | | - return -ENODEV; |
|---|
| 980 | | - } |
|---|
| 981 | 961 | |
|---|
| 982 | 962 | indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ddata)); |
|---|
| 983 | 963 | if (!indio_dev) { |
|---|
| .. | .. |
|---|
| 986 | 966 | return -ENOMEM; |
|---|
| 987 | 967 | } |
|---|
| 988 | 968 | ddata = iio_priv(indio_dev); |
|---|
| 989 | | - ddata->ato = match->data; |
|---|
| 969 | + ddata->ato = device_get_match_data(&pdev->dev); |
|---|
| 970 | + if (!ddata->ato) |
|---|
| 971 | + return -ENODEV; |
|---|
| 990 | 972 | ddata->dev = &pdev->dev; |
|---|
| 991 | 973 | |
|---|
| 992 | 974 | mutex_init(&ddata->lock); |
|---|
| 993 | 975 | init_waitqueue_head(&ddata->wq_data_avail); |
|---|
| 994 | 976 | |
|---|
| 995 | 977 | indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_SOFTWARE; |
|---|
| 996 | | - indio_dev->dev.parent = &pdev->dev; |
|---|
| 997 | | - indio_dev->dev.of_node = pdev->dev.of_node; |
|---|
| 998 | 978 | indio_dev->channels = cpcap_adc_channels; |
|---|
| 999 | 979 | indio_dev->num_channels = ARRAY_SIZE(cpcap_adc_channels); |
|---|
| 1000 | 980 | indio_dev->name = dev_name(&pdev->dev); |
|---|
| .. | .. |
|---|
| 1016 | 996 | |
|---|
| 1017 | 997 | error = devm_request_threaded_irq(&pdev->dev, ddata->irq, NULL, |
|---|
| 1018 | 998 | cpcap_adc_irq_thread, |
|---|
| 1019 | | - IRQF_TRIGGER_NONE, |
|---|
| 999 | + IRQF_TRIGGER_NONE | IRQF_ONESHOT, |
|---|
| 1020 | 1000 | "cpcap-adc", indio_dev); |
|---|
| 1021 | 1001 | if (error) { |
|---|
| 1022 | 1002 | dev_err(&pdev->dev, "could not get irq: %i\n", |
|---|
| .. | .. |
|---|
| 1037 | 1017 | static struct platform_driver cpcap_adc_driver = { |
|---|
| 1038 | 1018 | .driver = { |
|---|
| 1039 | 1019 | .name = "cpcap_adc", |
|---|
| 1040 | | - .of_match_table = of_match_ptr(cpcap_adc_id_table), |
|---|
| 1020 | + .of_match_table = cpcap_adc_id_table, |
|---|
| 1041 | 1021 | }, |
|---|
| 1042 | 1022 | .probe = cpcap_adc_probe, |
|---|
| 1043 | 1023 | }; |
|---|