9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <asm/div64.h>
25 static unsigned long ad9832_calc_freqreg(
unsigned long mclk,
unsigned long fout)
27 unsigned long long freqreg = (
u64) fout *
34 unsigned addr,
unsigned long fout)
38 if (fout > (st->
mclk / 2))
41 regval = ad9832_calc_freqreg(st->
mclk, fout);
45 ((regval >> 24) & 0xFF));
48 ((regval >> 16) & 0xFF));
51 ((regval >> 8) & 0xFF));
54 ((regval >> 0) & 0xFF));
60 unsigned long addr,
unsigned long phase)
67 ((phase >> 8) & 0xFF));
80 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
94 ret = ad9832_write_frequency(st, this_attr->
address, val);
100 ret = ad9832_write_phase(st, this_attr->
address, val);
125 if (val < 0 || val > 3) {
154 return ret ? ret : len;
179 static struct attribute *ad9832_attributes[] = {
180 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
181 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
182 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
183 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
184 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
185 &iio_dev_attr_out_altvoltage0_phase2.dev_attr.attr,
186 &iio_dev_attr_out_altvoltage0_phase3.dev_attr.attr,
187 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
188 &iio_dev_attr_out_altvoltage0_pincontrol_en.dev_attr.attr,
189 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
190 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
191 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
196 .attrs = ad9832_attributes,
199 static const struct iio_info ad9832_info = {
200 .attrs = &ad9832_attribute_group,
225 if (indio_dev ==
NULL) {
227 goto error_disable_reg;
229 spi_set_drvdata(spi, indio_dev);
230 st = iio_priv(indio_dev);
235 indio_dev->
dev.parent = &spi->
dev;
237 indio_dev->
info = &ad9832_info;
245 spi_message_init(&st->
msg);
246 spi_message_add_tail(&st->
xfer, &st->
msg);
248 st->
freq_xfer[0].tx_buf = &st->freq_data[0];
251 st->
freq_xfer[1].tx_buf = &st->freq_data[1];
254 st->
freq_xfer[2].tx_buf = &st->freq_data[2];
257 st->
freq_xfer[3].tx_buf = &st->freq_data[3];
282 goto error_free_device;
287 goto error_free_device;
291 goto error_free_device;
295 goto error_free_device;
299 goto error_free_device;
303 goto error_free_device;
307 goto error_free_device;
311 goto error_free_device;
329 struct iio_dev *indio_dev = spi_get_drvdata(spi);
333 if (!IS_ERR(st->
reg)) {
354 .probe = ad9832_probe,
356 .id_table = ad9832_id,