11 #include <linux/device.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
15 #include <linux/list.h>
19 #include <linux/module.h>
20 #include <asm/div64.h>
28 static unsigned int ad9834_calc_freqreg(
unsigned long mclk,
unsigned long fout)
36 unsigned long addr,
unsigned long fout)
40 if (fout > (st->
mclk / 2))
43 regval = ad9834_calc_freqreg(st->
mclk, fout);
55 unsigned long addr,
unsigned long phase)
69 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
83 ret = ad9834_write_frequency(st, this_attr->
address, val);
87 ret = ad9834_write_phase(st, this_attr->
address, val);
140 return ret ? ret : len;
148 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
171 }
else if (is_ad9833_7 &&
sysfs_streq(buf,
"square")) {
199 return ret ? ret : len;
202 static ssize_t ad9834_show_out0_wavetype_available(
struct device *dev,
206 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
211 str =
"sine triangle square";
215 str =
"sine triangle";
217 return sprintf(buf,
"%s\n", str);
222 ad9834_show_out0_wavetype_available,
NULL, 0);
224 static ssize_t ad9834_show_out1_wavetype_available(
struct device *dev,
228 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
237 return sprintf(buf,
"%s\n", str);
241 ad9834_show_out1_wavetype_available,
NULL, 0);
265 static struct attribute *ad9834_attributes[] = {
266 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
267 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
268 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
269 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
270 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
271 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
272 &iio_dev_attr_out_altvoltage0_pincontrol_en.dev_attr.attr,
273 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
274 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
275 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
276 &iio_dev_attr_out_altvoltage0_out1_enable.dev_attr.attr,
277 &iio_dev_attr_out_altvoltage0_out0_wavetype.dev_attr.attr,
278 &iio_dev_attr_out_altvoltage0_out1_wavetype.dev_attr.attr,
279 &iio_dev_attr_out_altvoltage0_out0_wavetype_available.dev_attr.attr,
280 &iio_dev_attr_out_altvoltage0_out1_wavetype_available.dev_attr.attr,
284 static struct attribute *ad9833_attributes[] = {
285 &iio_dev_attr_out_altvoltage0_frequency0.dev_attr.attr,
286 &iio_dev_attr_out_altvoltage0_frequency1.dev_attr.attr,
287 &iio_const_attr_out_altvoltage0_frequency_scale.dev_attr.attr,
288 &iio_dev_attr_out_altvoltage0_phase0.dev_attr.attr,
289 &iio_dev_attr_out_altvoltage0_phase1.dev_attr.attr,
290 &iio_const_attr_out_altvoltage0_phase_scale.dev_attr.attr,
291 &iio_dev_attr_out_altvoltage0_frequencysymbol.dev_attr.attr,
292 &iio_dev_attr_out_altvoltage0_phasesymbol.dev_attr.attr,
293 &iio_dev_attr_out_altvoltage0_out_enable.dev_attr.attr,
294 &iio_dev_attr_out_altvoltage0_out0_wavetype.dev_attr.attr,
295 &iio_dev_attr_out_altvoltage0_out0_wavetype_available.dev_attr.attr,
300 .attrs = ad9834_attributes,
304 .attrs = ad9833_attributes,
307 static const struct iio_info ad9834_info = {
308 .attrs = &ad9834_attribute_group,
312 static const struct iio_info ad9833_info = {
313 .attrs = &ad9833_attribute_group,
338 if (indio_dev ==
NULL) {
340 goto error_disable_reg;
342 spi_set_drvdata(spi, indio_dev);
343 st = iio_priv(indio_dev);
348 indio_dev->
dev.parent = &spi->
dev;
353 indio_dev->
info = &ad9833_info;
356 indio_dev->
info = &ad9834_info;
363 st->
xfer.tx_buf = &st->data;
366 spi_message_init(&st->
msg);
367 spi_message_add_tail(&st->
xfer, &st->
msg);
391 goto error_free_device;
396 goto error_free_device;
400 goto error_free_device;
404 goto error_free_device;
408 goto error_free_device;
412 goto error_free_device;
429 struct iio_dev *indio_dev = spi_get_drvdata(spi);
433 if (!IS_ERR(st->
reg)) {
456 .probe = ad9834_probe,
458 .id_table = ad9834_id,