-
Notifications
You must be signed in to change notification settings - Fork 920
iio: dac: Add support for AD5676R/AD5696R DACs #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * AD5672R, AD5676, AD5676R, AD5684, AD5684R, AD5684R, AD5685R, AD5686, AD5686R | ||
| * Digital to analog converters driver | ||
| * | ||
| * Copyright 2018 Analog Devices Inc. | ||
| * | ||
| * Licensed under the GPL-2. | ||
| */ | ||
|
|
||
| #include "ad5686.h" | ||
|
|
||
| #include <linux/module.h> | ||
| #include <linux/spi/spi.h> | ||
|
|
||
| static int ad5686_spi_write(struct ad5686_state *st, | ||
| u8 cmd, u8 addr, u16 val) | ||
| { | ||
| struct spi_device *spi = to_spi_device(st->dev); | ||
|
|
||
| st->data[0].d32 = cpu_to_be32(AD5686_CMD(cmd) | | ||
| AD5686_ADDR(addr) | | ||
| val); | ||
|
|
||
| return spi_write(spi, &st->data[0].d8[1], 3); | ||
| } | ||
|
|
||
| static int ad5686_spi_read(struct ad5686_state *st, u8 addr) | ||
| { | ||
| struct spi_transfer t[] = { | ||
| { | ||
| .tx_buf = &st->data[0].d8[1], | ||
| .len = 3, | ||
| .cs_change = 1, | ||
| }, { | ||
| .tx_buf = &st->data[1].d8[1], | ||
| .rx_buf = &st->data[2].d8[1], | ||
| .len = 3, | ||
| }, | ||
| }; | ||
| struct spi_device *spi = to_spi_device(st->dev); | ||
| int ret; | ||
|
|
||
| st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | | ||
| AD5686_ADDR(addr)); | ||
| st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); | ||
|
|
||
| ret = spi_sync_transfer(spi, t, ARRAY_SIZE(t)); | ||
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| return be32_to_cpu(st->data[2].d32); | ||
| } | ||
|
|
||
| static int ad5686_spi_probe(struct spi_device *spi) | ||
| { | ||
| const struct spi_device_id *id = spi_get_device_id(spi); | ||
|
|
||
| return ad5686_probe(&spi->dev, id->driver_data, id->name, | ||
| ad5686_spi_write, ad5686_spi_read); | ||
| } | ||
|
|
||
| static int ad5686_spi_remove(struct spi_device *spi) | ||
| { | ||
| return ad5686_remove(&spi->dev); | ||
| } | ||
|
|
||
| static const struct spi_device_id ad5686_spi_id[] = { | ||
| {"ad5672r", ID_AD5672R}, | ||
| {"ad5676", ID_AD5676}, | ||
| {"ad5676r", ID_AD5676R}, | ||
| {"ad5684", ID_AD5684}, | ||
| {"ad5684r", ID_AD5684R}, | ||
| {"ad5685r", ID_AD5685R}, | ||
| {"ad5686", ID_AD5686}, | ||
| {"ad5686r", ID_AD5686R}, | ||
| {} | ||
| }; | ||
| MODULE_DEVICE_TABLE(spi, ad5686_spi_id); | ||
|
|
||
| static struct spi_driver ad5686_spi_driver = { | ||
| .driver = { | ||
| .name = "ad5686", | ||
| }, | ||
| .probe = ad5686_spi_probe, | ||
| .remove = ad5686_spi_remove, | ||
| .id_table = ad5686_spi_id, | ||
| }; | ||
|
|
||
| module_spi_driver(ad5686_spi_driver); | ||
|
|
||
| MODULE_AUTHOR("Stefan Popa <[email protected]>"); | ||
| MODULE_DESCRIPTION("Analog Devices AD5686 and similar multi-channel DACs"); | ||
| MODULE_LICENSE("GPL v2"); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally there should be a commit that deals with just the separation of the spi part into it's own file ;
then in a subsequent commit, the new chips can be added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about it, but the spi part separation makes sense only in the context of adding support for a family of devices which use the i2c interface.