mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-30 11:03:07 -04:00
Replace the #include of <linux/mod_devicetable.h> by the more specific <linux/device-id/*.h> where applicable. For most cases the include can be dropped completely, only a few drivers need one or two headers added. Acked-by: Danilo Krummrich <dakr@kernel.org> Acked-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Acked-by: Bjorn Helgaas <bhelgaas@google.com> Link: https://patch.msgid.link/1a3f2007c5c5dcf555c09a4035ce3ae8ef1b6c49.1782808461.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König (The Capable Hub) <u.kleine-koenig@baylibre.com>
102 lines
2.9 KiB
C
102 lines
2.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* AD5446 SPI I2C driver
|
|
*
|
|
* Copyright 2025 Analog Devices Inc.
|
|
*/
|
|
#include <linux/err.h>
|
|
#include <linux/module.h>
|
|
#include <linux/i2c.h>
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include "ad5446.h"
|
|
|
|
static int ad5622_write(struct ad5446_state *st, unsigned int val)
|
|
{
|
|
struct i2c_client *client = to_i2c_client(st->dev);
|
|
int ret;
|
|
|
|
st->d16 = cpu_to_be16(val);
|
|
|
|
ret = i2c_master_send_dmasafe(client, (char *)&st->d16, sizeof(st->d16));
|
|
if (ret < 0)
|
|
return ret;
|
|
if (ret != sizeof(st->d16))
|
|
return -EIO;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ad5446_i2c_probe(struct i2c_client *i2c)
|
|
{
|
|
const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
|
|
const struct ad5446_chip_info *chip_info;
|
|
|
|
chip_info = i2c_get_match_data(i2c);
|
|
if (!chip_info)
|
|
return -ENODEV;
|
|
|
|
return ad5446_probe(&i2c->dev, id->name, chip_info);
|
|
}
|
|
|
|
/*
|
|
* ad5446_supported_i2c_device_ids:
|
|
* The AD5620/40/60 parts are available in different fixed internal reference
|
|
* voltage options. The actual part numbers may look differently
|
|
* (and a bit cryptic), however this style is used to make clear which
|
|
* parts are supported here.
|
|
*/
|
|
|
|
static const struct ad5446_chip_info ad5602_chip_info = {
|
|
.channel = AD5446_CHANNEL_POWERDOWN(8, 16, 4),
|
|
.write = ad5622_write,
|
|
};
|
|
|
|
static const struct ad5446_chip_info ad5612_chip_info = {
|
|
.channel = AD5446_CHANNEL_POWERDOWN(10, 16, 2),
|
|
.write = ad5622_write,
|
|
};
|
|
|
|
static const struct ad5446_chip_info ad5622_chip_info = {
|
|
.channel = AD5446_CHANNEL_POWERDOWN(12, 16, 0),
|
|
.write = ad5622_write,
|
|
};
|
|
|
|
static const struct i2c_device_id ad5446_i2c_ids[] = {
|
|
{ .name = "ad5301", .driver_data = (kernel_ulong_t)&ad5602_chip_info },
|
|
{ .name = "ad5311", .driver_data = (kernel_ulong_t)&ad5612_chip_info },
|
|
{ .name = "ad5321", .driver_data = (kernel_ulong_t)&ad5622_chip_info },
|
|
{ .name = "ad5602", .driver_data = (kernel_ulong_t)&ad5602_chip_info },
|
|
{ .name = "ad5612", .driver_data = (kernel_ulong_t)&ad5612_chip_info },
|
|
{ .name = "ad5622", .driver_data = (kernel_ulong_t)&ad5622_chip_info },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(i2c, ad5446_i2c_ids);
|
|
|
|
static const struct of_device_id ad5446_i2c_of_ids[] = {
|
|
{ .compatible = "adi,ad5301", .data = &ad5602_chip_info },
|
|
{ .compatible = "adi,ad5311", .data = &ad5612_chip_info },
|
|
{ .compatible = "adi,ad5321", .data = &ad5622_chip_info },
|
|
{ .compatible = "adi,ad5602", .data = &ad5602_chip_info },
|
|
{ .compatible = "adi,ad5612", .data = &ad5612_chip_info },
|
|
{ .compatible = "adi,ad5622", .data = &ad5622_chip_info },
|
|
{ }
|
|
};
|
|
MODULE_DEVICE_TABLE(OF, ad5446_i2c_of_ids);
|
|
|
|
static struct i2c_driver ad5446_i2c_driver = {
|
|
.driver = {
|
|
.name = "ad5446",
|
|
.of_match_table = ad5446_i2c_of_ids,
|
|
},
|
|
.probe = ad5446_i2c_probe,
|
|
.id_table = ad5446_i2c_ids,
|
|
};
|
|
module_i2c_driver(ad5446_i2c_driver);
|
|
|
|
MODULE_AUTHOR("Nuno Sá <nuno.sa@analog.com>");
|
|
MODULE_DESCRIPTION("Analog Devices AD5622 and similar I2C DACs");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_IMPORT_NS("IIO_AD5446");
|