mirror of
https://github.com/torvalds/linux.git
synced 2024-12-05 02:23:16 +00:00
2a3c8f8a44
Several on-running cleanup efforts dominate this time, plus the DMA safety alignment issue identified due to improved understanding of the restrictions as a result of Catalin Marinas' efforts in that area. One immutable branch in here due to MFD and SPMI elements needed for the qcom-rradc driver. Device support * bmi088 - Add support for bmi085 (accelerometer part of IMU) - Add support for bmi090l (accelerometer part of IMU) * mcp4922 - Add support for single channel device MCP4921 * rzg2l-adc - Add compatible and minor tweaks to support RZ/G2UL ADC * sca3300 - Add support for scl3300 including refactoring driver to support multiple device types and cleanup noticed whilst working on driver. * spmi-rradc - New driver for Qualcomm SPMI Round Robin ADC including necessary additional utility functions in SPMI core and related MFD driver. * ti-dac55781 - Add compatible for DAC121C081 which is very similar to existing parts. Features * core - Warn on iio_trigger_get() on an unregistered IIO trigger. * bma400 - Triggered buffer support - Activity and step counting - Misc driver improvements such as devm and header ordering * cm32181 - Add PM support. * cros_ec - Sensor location support * sx9324 - Add precharge resistor setting - Add internal compensation resistor setting - Add CS idle/sleep mode. * sx9360 - Add precharge resistor setting * vl53l0x - Handle reset GPIO, regulator and relax handling of irq type. Cleanup and minor fixes: Treewide changes - Cleanup of error handling in remove functions in many drivers. - Update dt-binding maintainers for a number of ADI bindings. - Several sets of conversion of drivers from device tree specific to generic device properties. Includes fixing up various related header and Kconfig issues. - Drop include of of.h from iio.h and fix up drivers that need to include it directly. - More moves of clusters of drivers into appropriate IIO_XXX namespaces. - Tree wide fix of a long running bug around DMA safety requirements. IIO was using __cacheline_aligned to pad iio_priv() structures. This worked for a long time by coincidence, but correct alignment is ARCH_KMALLOC_MINALIGN. As there is activity around this area, introduce an IIO local IIO_DMA_MINALIGN to allow for changing it in one place rather than every driver in future. Note, there have been no reports of this bug in the wild, and it may not happen on any platforms supported by upstream, so no rush to backport these fixes. Other cleanup * core - Switch to ida_alloc()/free() - Drop unused iio_get_time_res() - Octal permissions and DEVICE_ATTR_* macros. - Cleanup bared unsigned usage. * MAINTAINERS - Add include/dt-bindings/iio/ to the main IIO entry. * ad5380 - Comment syntax fix. * ad74413r - Call to for_each_set_bit_from(), with from value as 0 replaced. * ad7768-1 - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core. * adxl345 - Fix wrong address in dt-binding example. * adxl367 - Drop extra update of FIFO watermark. * at91-sama5d2 - Limit requested watermark to the hwfifo size. * bmg160, bme680 - Typos * cio-dac - Switch to iomap rather than direct use of ioports * kxsd9 - Replace CONFIG_PM guards with new PM macros that let the compiler cleanly remove the unused code and structures when !CONFIG_PM * lsm6dsx - Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS(). Then move to Namespace. * meson_saradc - general cleanup. - Avoid attaching resources to iio_dev->dev - Use same struct device for all error messages - Convert to dev_err_probe() and use local struct device *dev to reduce code complexity. - Use devm_clk_get_optional() instead of hand rolling. - Use regmap_read_poll_timeout() instead of hand rolling. * mma7660 - Drop ACPI_PTR() use that is unhelpful. * mpu3050 - Stop exporting symbols not used outside of module - Switch to new DEFINE_RUNTIME_DEV_PM_OPS() macro and move to Namespace. * ping - Typo fix * qcom-spmi-rradc - Typo fix * sc27xx - Convert to generic struct u32_fract * srf08 - Drop a redundant check on !val * st_lsm6dsx - Limit the requested watermark to the hwfifo size. * stm32-adc - Use generic_handle_domain_irq() instead of opencoding. - Fix handling of ADC disable. * stm32-dac - Use str_enabled_disable() instead of open coding. * stx104 - Switch to iomap rather than direct use of ioports * tsc2046 - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core. * tsl2563 - Replace flush_scheduled_work() with cancel_delayed_work_sync() - Replace cancel_delayed_work() with cancel_delayed_work_sync() * vl53l0x - Make the VDD regulator optional by allowing a dummy regulator. -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmLQBwARHGppYzIzQGtl cm5lbC5vcmcACgkQVIU0mcT0FohMHRAAi3nPM3IchXe886olumRgX5ke75vU+FNT sqQjqlpl6X7j5yNLU+HF6lC7zg3QzDnfWJ3Uo4C7s2sW7zO0997lkFx4jvF3yW9y 0nLDgYm1Y1te/qR84BE355pMEsYEJVZyPI/Z8UfuBh6IfnSDeTE5ZwCvlRMAchtp AX+j1114FQvZ8yfdIlFjlN4vYSxCGgEZzfWYhpch/Jv1y2Q0L17bpv/KWGt1AYaF VugmKoNTM3WzIABBNGWQ4l4ZVVuVpuiVUL90AKv6Qf+yDSqw94tuIM0NZpJ1rqLr 7tH568m7Eewh7zBp88PRB9XDiZVERvzdVQaT22+wlX+Vhn/SKeoK8PPpdLWD1YyG hXB0p+FGKncoKKgK1w9L7qRRNmsQDHowNHYMSjnzeBuyGQyEqwAXzNvvbiCqHh8y 7b8GW+CYo7//wIarg74Xl+/4LwdCGcMUJNuTm1efEgC7yGToY7JD63DNo3sylaII bfoT06/yogaay/rVLZs5n+MvDONaDt4AbTTErG48s0TzqD/O8Ys85AF0IvKwQ80N WMxe4y+gdJ6VuU+ww9+6WdUzxnx+5gt+ZA2iLxZFekOIUi3Tj+q47F+17Jvwyt7U 2wQzdtvNhHPwD5CqYpxD4iH/z5YFCtIHKjmUsVyAWGVbeuSS/QvFzpf39YWxBWO+ W1w6RStUbXo= =IcsE -----END PGP SIGNATURE----- Merge tag 'iio-for-5.20a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next Jonathan writes: IIO new device support, features and minor fixes for 5.20 Several on-running cleanup efforts dominate this time, plus the DMA safety alignment issue identified due to improved understanding of the restrictions as a result of Catalin Marinas' efforts in that area. One immutable branch in here due to MFD and SPMI elements needed for the qcom-rradc driver. Device support * bmi088 - Add support for bmi085 (accelerometer part of IMU) - Add support for bmi090l (accelerometer part of IMU) * mcp4922 - Add support for single channel device MCP4921 * rzg2l-adc - Add compatible and minor tweaks to support RZ/G2UL ADC * sca3300 - Add support for scl3300 including refactoring driver to support multiple device types and cleanup noticed whilst working on driver. * spmi-rradc - New driver for Qualcomm SPMI Round Robin ADC including necessary additional utility functions in SPMI core and related MFD driver. * ti-dac55781 - Add compatible for DAC121C081 which is very similar to existing parts. Features * core - Warn on iio_trigger_get() on an unregistered IIO trigger. * bma400 - Triggered buffer support - Activity and step counting - Misc driver improvements such as devm and header ordering * cm32181 - Add PM support. * cros_ec - Sensor location support * sx9324 - Add precharge resistor setting - Add internal compensation resistor setting - Add CS idle/sleep mode. * sx9360 - Add precharge resistor setting * vl53l0x - Handle reset GPIO, regulator and relax handling of irq type. Cleanup and minor fixes: Treewide changes - Cleanup of error handling in remove functions in many drivers. - Update dt-binding maintainers for a number of ADI bindings. - Several sets of conversion of drivers from device tree specific to generic device properties. Includes fixing up various related header and Kconfig issues. - Drop include of of.h from iio.h and fix up drivers that need to include it directly. - More moves of clusters of drivers into appropriate IIO_XXX namespaces. - Tree wide fix of a long running bug around DMA safety requirements. IIO was using __cacheline_aligned to pad iio_priv() structures. This worked for a long time by coincidence, but correct alignment is ARCH_KMALLOC_MINALIGN. As there is activity around this area, introduce an IIO local IIO_DMA_MINALIGN to allow for changing it in one place rather than every driver in future. Note, there have been no reports of this bug in the wild, and it may not happen on any platforms supported by upstream, so no rush to backport these fixes. Other cleanup * core - Switch to ida_alloc()/free() - Drop unused iio_get_time_res() - Octal permissions and DEVICE_ATTR_* macros. - Cleanup bared unsigned usage. * MAINTAINERS - Add include/dt-bindings/iio/ to the main IIO entry. * ad5380 - Comment syntax fix. * ad74413r - Call to for_each_set_bit_from(), with from value as 0 replaced. * ad7768-1 - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core. * adxl345 - Fix wrong address in dt-binding example. * adxl367 - Drop extra update of FIFO watermark. * at91-sama5d2 - Limit requested watermark to the hwfifo size. * bmg160, bme680 - Typos * cio-dac - Switch to iomap rather than direct use of ioports * kxsd9 - Replace CONFIG_PM guards with new PM macros that let the compiler cleanly remove the unused code and structures when !CONFIG_PM * lsm6dsx - Use new pm_sleep_ptr() and EXPORT_SIMPLE_DEV_PM_OPS(). Then move to Namespace. * meson_saradc - general cleanup. - Avoid attaching resources to iio_dev->dev - Use same struct device for all error messages - Convert to dev_err_probe() and use local struct device *dev to reduce code complexity. - Use devm_clk_get_optional() instead of hand rolling. - Use regmap_read_poll_timeout() instead of hand rolling. * mma7660 - Drop ACPI_PTR() use that is unhelpful. * mpu3050 - Stop exporting symbols not used outside of module - Switch to new DEFINE_RUNTIME_DEV_PM_OPS() macro and move to Namespace. * ping - Typo fix * qcom-spmi-rradc - Typo fix * sc27xx - Convert to generic struct u32_fract * srf08 - Drop a redundant check on !val * st_lsm6dsx - Limit the requested watermark to the hwfifo size. * stm32-adc - Use generic_handle_domain_irq() instead of opencoding. - Fix handling of ADC disable. * stm32-dac - Use str_enabled_disable() instead of open coding. * stx104 - Switch to iomap rather than direct use of ioports * tsc2046 - Drop explicit setting of INDIO_BUFFER_TRIGGERED as now done by the core. * tsl2563 - Replace flush_scheduled_work() with cancel_delayed_work_sync() - Replace cancel_delayed_work() with cancel_delayed_work_sync() * vl53l0x - Make the VDD regulator optional by allowing a dummy regulator. * tag 'iio-for-5.20a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: (244 commits) iio: adc: xilinx-xadc: Drop duplicate NULL check in xadc_parse_dt() iio: adc: xilinx-xadc: Make use of device properties iio: light: cm32181: Add PM support iio: adc: ad778-1: do not explicity set INDIO_BUFFER_TRIGGERED mode iio: adc: ti-tsc2046: do not explicity set INDIO_BUFFER_TRIGGERED mode iio: adc: stm32-adc: disable adc before calibration iio: adc: stm32-adc: make safe adc disable iio: dac: ad5380: align '*' each line and drop unneeded blank line iio: adc: qcom-spmi-rradc: Fix spelling mistake "coherrency" -> "coherency" iio: Don't use bare "unsigned" dt-bindings: iio: dac: mcp4922: expand for mcp4921 support iio: dac: mcp4922: add support to mcp4921 iio: chemical: sps30: Move symbol exports into IIO_SPS30 namespace iio: pressure: bmp280: Move symbol exports to IIO_BMP280 namespace iio: imu: bmi160: Move exported symbols to IIO_BMI160 namespace iio: adc: stm32-adc: Use generic_handle_domain_irq() proximity: vl53l0x: Make VDD regulator actually optional MAINTAINERS: add include/dt-bindings/iio to IIO SUBSYSTEM AND DRIVERS dt-bindings: iio/accel: Fix adi,adxl345/6 example I2C address iio: gyro: bmg160: Fix typo in comment ...
474 lines
12 KiB
C
474 lines
12 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Analog Devices Generic AXI ADC IP core
|
|
* Link: https://wiki.analog.com/resources/fpga/docs/axi_adc_ip
|
|
*
|
|
* Copyright 2012-2020 Analog Devices Inc.
|
|
*/
|
|
|
|
#include <linux/bitfield.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/io.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of_device.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/iio/iio.h>
|
|
#include <linux/iio/sysfs.h>
|
|
#include <linux/iio/buffer.h>
|
|
#include <linux/iio/buffer-dmaengine.h>
|
|
|
|
#include <linux/fpga/adi-axi-common.h>
|
|
#include <linux/iio/adc/adi-axi-adc.h>
|
|
|
|
/*
|
|
* Register definitions:
|
|
* https://wiki.analog.com/resources/fpga/docs/axi_adc_ip#register_map
|
|
*/
|
|
|
|
/* ADC controls */
|
|
|
|
#define ADI_AXI_REG_RSTN 0x0040
|
|
#define ADI_AXI_REG_RSTN_CE_N BIT(2)
|
|
#define ADI_AXI_REG_RSTN_MMCM_RSTN BIT(1)
|
|
#define ADI_AXI_REG_RSTN_RSTN BIT(0)
|
|
|
|
/* ADC Channel controls */
|
|
|
|
#define ADI_AXI_REG_CHAN_CTRL(c) (0x0400 + (c) * 0x40)
|
|
#define ADI_AXI_REG_CHAN_CTRL_LB_OWR BIT(11)
|
|
#define ADI_AXI_REG_CHAN_CTRL_PN_SEL_OWR BIT(10)
|
|
#define ADI_AXI_REG_CHAN_CTRL_IQCOR_EN BIT(9)
|
|
#define ADI_AXI_REG_CHAN_CTRL_DCFILT_EN BIT(8)
|
|
#define ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT BIT(6)
|
|
#define ADI_AXI_REG_CHAN_CTRL_FMT_TYPE BIT(5)
|
|
#define ADI_AXI_REG_CHAN_CTRL_FMT_EN BIT(4)
|
|
#define ADI_AXI_REG_CHAN_CTRL_PN_TYPE_OWR BIT(1)
|
|
#define ADI_AXI_REG_CHAN_CTRL_ENABLE BIT(0)
|
|
|
|
#define ADI_AXI_REG_CHAN_CTRL_DEFAULTS \
|
|
(ADI_AXI_REG_CHAN_CTRL_FMT_SIGNEXT | \
|
|
ADI_AXI_REG_CHAN_CTRL_FMT_EN | \
|
|
ADI_AXI_REG_CHAN_CTRL_ENABLE)
|
|
|
|
struct adi_axi_adc_core_info {
|
|
unsigned int version;
|
|
};
|
|
|
|
struct adi_axi_adc_state {
|
|
struct mutex lock;
|
|
|
|
struct adi_axi_adc_client *client;
|
|
void __iomem *regs;
|
|
};
|
|
|
|
struct adi_axi_adc_client {
|
|
struct list_head entry;
|
|
struct adi_axi_adc_conv conv;
|
|
struct adi_axi_adc_state *state;
|
|
struct device *dev;
|
|
const struct adi_axi_adc_core_info *info;
|
|
};
|
|
|
|
static LIST_HEAD(registered_clients);
|
|
static DEFINE_MUTEX(registered_clients_lock);
|
|
|
|
static struct adi_axi_adc_client *conv_to_client(struct adi_axi_adc_conv *conv)
|
|
{
|
|
return container_of(conv, struct adi_axi_adc_client, conv);
|
|
}
|
|
|
|
void *adi_axi_adc_conv_priv(struct adi_axi_adc_conv *conv)
|
|
{
|
|
struct adi_axi_adc_client *cl = conv_to_client(conv);
|
|
|
|
return (char *)cl + ALIGN(sizeof(struct adi_axi_adc_client),
|
|
IIO_DMA_MINALIGN);
|
|
}
|
|
EXPORT_SYMBOL_NS_GPL(adi_axi_adc_conv_priv, IIO_ADI_AXI);
|
|
|
|
static void adi_axi_adc_write(struct adi_axi_adc_state *st,
|
|
unsigned int reg,
|
|
unsigned int val)
|
|
{
|
|
iowrite32(val, st->regs + reg);
|
|
}
|
|
|
|
static unsigned int adi_axi_adc_read(struct adi_axi_adc_state *st,
|
|
unsigned int reg)
|
|
{
|
|
return ioread32(st->regs + reg);
|
|
}
|
|
|
|
static int adi_axi_adc_config_dma_buffer(struct device *dev,
|
|
struct iio_dev *indio_dev)
|
|
{
|
|
const char *dma_name;
|
|
|
|
if (!device_property_present(dev, "dmas"))
|
|
return 0;
|
|
|
|
if (device_property_read_string(dev, "dma-names", &dma_name))
|
|
dma_name = "rx";
|
|
|
|
return devm_iio_dmaengine_buffer_setup(indio_dev->dev.parent,
|
|
indio_dev, dma_name);
|
|
}
|
|
|
|
static int adi_axi_adc_read_raw(struct iio_dev *indio_dev,
|
|
struct iio_chan_spec const *chan,
|
|
int *val, int *val2, long mask)
|
|
{
|
|
struct adi_axi_adc_state *st = iio_priv(indio_dev);
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
|
|
if (!conv->read_raw)
|
|
return -EOPNOTSUPP;
|
|
|
|
return conv->read_raw(conv, chan, val, val2, mask);
|
|
}
|
|
|
|
static int adi_axi_adc_write_raw(struct iio_dev *indio_dev,
|
|
struct iio_chan_spec const *chan,
|
|
int val, int val2, long mask)
|
|
{
|
|
struct adi_axi_adc_state *st = iio_priv(indio_dev);
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
|
|
if (!conv->write_raw)
|
|
return -EOPNOTSUPP;
|
|
|
|
return conv->write_raw(conv, chan, val, val2, mask);
|
|
}
|
|
|
|
static int adi_axi_adc_update_scan_mode(struct iio_dev *indio_dev,
|
|
const unsigned long *scan_mask)
|
|
{
|
|
struct adi_axi_adc_state *st = iio_priv(indio_dev);
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
unsigned int i, ctrl;
|
|
|
|
for (i = 0; i < conv->chip_info->num_channels; i++) {
|
|
ctrl = adi_axi_adc_read(st, ADI_AXI_REG_CHAN_CTRL(i));
|
|
|
|
if (test_bit(i, scan_mask))
|
|
ctrl |= ADI_AXI_REG_CHAN_CTRL_ENABLE;
|
|
else
|
|
ctrl &= ~ADI_AXI_REG_CHAN_CTRL_ENABLE;
|
|
|
|
adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i), ctrl);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct adi_axi_adc_conv *adi_axi_adc_conv_register(struct device *dev,
|
|
size_t sizeof_priv)
|
|
{
|
|
struct adi_axi_adc_client *cl;
|
|
size_t alloc_size;
|
|
|
|
alloc_size = ALIGN(sizeof(struct adi_axi_adc_client), IIO_DMA_MINALIGN);
|
|
if (sizeof_priv)
|
|
alloc_size += ALIGN(sizeof_priv, IIO_DMA_MINALIGN);
|
|
|
|
cl = kzalloc(alloc_size, GFP_KERNEL);
|
|
if (!cl)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
mutex_lock(®istered_clients_lock);
|
|
|
|
cl->dev = get_device(dev);
|
|
|
|
list_add_tail(&cl->entry, ®istered_clients);
|
|
|
|
mutex_unlock(®istered_clients_lock);
|
|
|
|
return &cl->conv;
|
|
}
|
|
|
|
static void adi_axi_adc_conv_unregister(struct adi_axi_adc_conv *conv)
|
|
{
|
|
struct adi_axi_adc_client *cl = conv_to_client(conv);
|
|
|
|
mutex_lock(®istered_clients_lock);
|
|
|
|
list_del(&cl->entry);
|
|
put_device(cl->dev);
|
|
|
|
mutex_unlock(®istered_clients_lock);
|
|
|
|
kfree(cl);
|
|
}
|
|
|
|
static void devm_adi_axi_adc_conv_release(void *conv)
|
|
{
|
|
adi_axi_adc_conv_unregister(conv);
|
|
}
|
|
|
|
struct adi_axi_adc_conv *devm_adi_axi_adc_conv_register(struct device *dev,
|
|
size_t sizeof_priv)
|
|
{
|
|
struct adi_axi_adc_conv *conv;
|
|
int ret;
|
|
|
|
conv = adi_axi_adc_conv_register(dev, sizeof_priv);
|
|
if (IS_ERR(conv))
|
|
return conv;
|
|
|
|
ret = devm_add_action_or_reset(dev, devm_adi_axi_adc_conv_release,
|
|
conv);
|
|
if (ret)
|
|
return ERR_PTR(ret);
|
|
|
|
return conv;
|
|
}
|
|
EXPORT_SYMBOL_NS_GPL(devm_adi_axi_adc_conv_register, IIO_ADI_AXI);
|
|
|
|
static ssize_t in_voltage_scale_available_show(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
|
struct adi_axi_adc_state *st = iio_priv(indio_dev);
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
size_t len = 0;
|
|
int i;
|
|
|
|
for (i = 0; i < conv->chip_info->num_scales; i++) {
|
|
const unsigned int *s = conv->chip_info->scale_table[i];
|
|
|
|
len += scnprintf(buf + len, PAGE_SIZE - len,
|
|
"%u.%06u ", s[0], s[1]);
|
|
}
|
|
buf[len - 1] = '\n';
|
|
|
|
return len;
|
|
}
|
|
|
|
static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
|
|
|
|
enum {
|
|
ADI_AXI_ATTR_SCALE_AVAIL,
|
|
};
|
|
|
|
#define ADI_AXI_ATTR(_en_, _file_) \
|
|
[ADI_AXI_ATTR_##_en_] = &iio_dev_attr_##_file_.dev_attr.attr
|
|
|
|
static struct attribute *adi_axi_adc_attributes[] = {
|
|
ADI_AXI_ATTR(SCALE_AVAIL, in_voltage_scale_available),
|
|
NULL
|
|
};
|
|
|
|
static umode_t axi_adc_attr_is_visible(struct kobject *kobj,
|
|
struct attribute *attr, int n)
|
|
{
|
|
struct device *dev = kobj_to_dev(kobj);
|
|
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
|
|
struct adi_axi_adc_state *st = iio_priv(indio_dev);
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
|
|
switch (n) {
|
|
case ADI_AXI_ATTR_SCALE_AVAIL:
|
|
if (!conv->chip_info->num_scales)
|
|
return 0;
|
|
return attr->mode;
|
|
default:
|
|
return attr->mode;
|
|
}
|
|
}
|
|
|
|
static const struct attribute_group adi_axi_adc_attribute_group = {
|
|
.attrs = adi_axi_adc_attributes,
|
|
.is_visible = axi_adc_attr_is_visible,
|
|
};
|
|
|
|
static const struct iio_info adi_axi_adc_info = {
|
|
.read_raw = &adi_axi_adc_read_raw,
|
|
.write_raw = &adi_axi_adc_write_raw,
|
|
.attrs = &adi_axi_adc_attribute_group,
|
|
.update_scan_mode = &adi_axi_adc_update_scan_mode,
|
|
};
|
|
|
|
static const struct adi_axi_adc_core_info adi_axi_adc_10_0_a_info = {
|
|
.version = ADI_AXI_PCORE_VER(10, 0, 'a'),
|
|
};
|
|
|
|
static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
|
|
{
|
|
const struct adi_axi_adc_core_info *info;
|
|
struct adi_axi_adc_client *cl;
|
|
struct device_node *cln;
|
|
|
|
info = of_device_get_match_data(dev);
|
|
if (!info)
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0);
|
|
if (!cln) {
|
|
dev_err(dev, "No 'adi,adc-dev' node defined\n");
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
mutex_lock(®istered_clients_lock);
|
|
|
|
list_for_each_entry(cl, ®istered_clients, entry) {
|
|
if (!cl->dev)
|
|
continue;
|
|
|
|
if (cl->dev->of_node != cln)
|
|
continue;
|
|
|
|
if (!try_module_get(cl->dev->driver->owner)) {
|
|
mutex_unlock(®istered_clients_lock);
|
|
of_node_put(cln);
|
|
return ERR_PTR(-ENODEV);
|
|
}
|
|
|
|
get_device(cl->dev);
|
|
cl->info = info;
|
|
mutex_unlock(®istered_clients_lock);
|
|
of_node_put(cln);
|
|
return cl;
|
|
}
|
|
|
|
mutex_unlock(®istered_clients_lock);
|
|
of_node_put(cln);
|
|
|
|
return ERR_PTR(-EPROBE_DEFER);
|
|
}
|
|
|
|
static int adi_axi_adc_setup_channels(struct device *dev,
|
|
struct adi_axi_adc_state *st)
|
|
{
|
|
struct adi_axi_adc_conv *conv = &st->client->conv;
|
|
int i, ret;
|
|
|
|
if (conv->preenable_setup) {
|
|
ret = conv->preenable_setup(conv);
|
|
if (ret)
|
|
return ret;
|
|
}
|
|
|
|
for (i = 0; i < conv->chip_info->num_channels; i++) {
|
|
adi_axi_adc_write(st, ADI_AXI_REG_CHAN_CTRL(i),
|
|
ADI_AXI_REG_CHAN_CTRL_DEFAULTS);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void axi_adc_reset(struct adi_axi_adc_state *st)
|
|
{
|
|
adi_axi_adc_write(st, ADI_AXI_REG_RSTN, 0);
|
|
mdelay(10);
|
|
adi_axi_adc_write(st, ADI_AXI_REG_RSTN, ADI_AXI_REG_RSTN_MMCM_RSTN);
|
|
mdelay(10);
|
|
adi_axi_adc_write(st, ADI_AXI_REG_RSTN,
|
|
ADI_AXI_REG_RSTN_RSTN | ADI_AXI_REG_RSTN_MMCM_RSTN);
|
|
}
|
|
|
|
static void adi_axi_adc_cleanup(void *data)
|
|
{
|
|
struct adi_axi_adc_client *cl = data;
|
|
|
|
put_device(cl->dev);
|
|
module_put(cl->dev->driver->owner);
|
|
}
|
|
|
|
static int adi_axi_adc_probe(struct platform_device *pdev)
|
|
{
|
|
struct adi_axi_adc_conv *conv;
|
|
struct iio_dev *indio_dev;
|
|
struct adi_axi_adc_client *cl;
|
|
struct adi_axi_adc_state *st;
|
|
unsigned int ver;
|
|
int ret;
|
|
|
|
cl = adi_axi_adc_attach_client(&pdev->dev);
|
|
if (IS_ERR(cl))
|
|
return PTR_ERR(cl);
|
|
|
|
ret = devm_add_action_or_reset(&pdev->dev, adi_axi_adc_cleanup, cl);
|
|
if (ret)
|
|
return ret;
|
|
|
|
indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*st));
|
|
if (indio_dev == NULL)
|
|
return -ENOMEM;
|
|
|
|
st = iio_priv(indio_dev);
|
|
st->client = cl;
|
|
cl->state = st;
|
|
mutex_init(&st->lock);
|
|
|
|
st->regs = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(st->regs))
|
|
return PTR_ERR(st->regs);
|
|
|
|
conv = &st->client->conv;
|
|
|
|
axi_adc_reset(st);
|
|
|
|
ver = adi_axi_adc_read(st, ADI_AXI_REG_VERSION);
|
|
|
|
if (cl->info->version > ver) {
|
|
dev_err(&pdev->dev,
|
|
"IP core version is too old. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n",
|
|
ADI_AXI_PCORE_VER_MAJOR(cl->info->version),
|
|
ADI_AXI_PCORE_VER_MINOR(cl->info->version),
|
|
ADI_AXI_PCORE_VER_PATCH(cl->info->version),
|
|
ADI_AXI_PCORE_VER_MAJOR(ver),
|
|
ADI_AXI_PCORE_VER_MINOR(ver),
|
|
ADI_AXI_PCORE_VER_PATCH(ver));
|
|
return -ENODEV;
|
|
}
|
|
|
|
indio_dev->info = &adi_axi_adc_info;
|
|
indio_dev->name = "adi-axi-adc";
|
|
indio_dev->modes = INDIO_DIRECT_MODE;
|
|
indio_dev->num_channels = conv->chip_info->num_channels;
|
|
indio_dev->channels = conv->chip_info->channels;
|
|
|
|
ret = adi_axi_adc_config_dma_buffer(&pdev->dev, indio_dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = adi_axi_adc_setup_channels(&pdev->dev, st);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = devm_iio_device_register(&pdev->dev, indio_dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
dev_info(&pdev->dev, "AXI ADC IP core (%d.%.2d.%c) probed\n",
|
|
ADI_AXI_PCORE_VER_MAJOR(ver),
|
|
ADI_AXI_PCORE_VER_MINOR(ver),
|
|
ADI_AXI_PCORE_VER_PATCH(ver));
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* Match table for of_platform binding */
|
|
static const struct of_device_id adi_axi_adc_of_match[] = {
|
|
{ .compatible = "adi,axi-adc-10.0.a", .data = &adi_axi_adc_10_0_a_info },
|
|
{ /* end of list */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, adi_axi_adc_of_match);
|
|
|
|
static struct platform_driver adi_axi_adc_driver = {
|
|
.driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.of_match_table = adi_axi_adc_of_match,
|
|
},
|
|
.probe = adi_axi_adc_probe,
|
|
};
|
|
module_platform_driver(adi_axi_adc_driver);
|
|
|
|
MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
|
|
MODULE_DESCRIPTION("Analog Devices Generic AXI ADC IP core driver");
|
|
MODULE_LICENSE("GPL v2");
|