Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: adi-axi-adc: set data format

Add support for selecting the data format within the AXI ADC ip.

Add separate complatible string for the custom AD485X IP and implement
the necessary changes.

Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
Link: https://patch.msgid.link/20250214131955.31973-7-antoniu.miclaus@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Antoniu Miclaus and committed by
Jonathan Cameron
7a794e3a 4831509f

+77 -1
+77 -1
drivers/iio/adc/adi-axi-adc.c
··· 46 46 #define ADI_AXI_ADC_REG_CTRL 0x0044 47 47 #define ADI_AXI_ADC_CTRL_DDR_EDGESEL_MASK BIT(1) 48 48 49 + #define ADI_AXI_ADC_REG_CNTRL_3 0x004c 50 + #define AXI_AD485X_CNTRL_3_PACKET_FORMAT_MSK GENMASK(1, 0) 51 + #define AXI_AD485X_PACKET_FORMAT_20BIT 0x0 52 + #define AXI_AD485X_PACKET_FORMAT_24BIT 0x1 53 + #define AXI_AD485X_PACKET_FORMAT_32BIT 0x2 54 + 49 55 #define ADI_AXI_ADC_REG_DRP_STATUS 0x0074 50 56 #define ADI_AXI_ADC_DRP_LOCKED BIT(17) 51 57 ··· 338 332 return 0; 339 333 } 340 334 335 + static int axi_adc_ad485x_data_size_set(struct iio_backend *back, 336 + unsigned int size) 337 + { 338 + struct adi_axi_adc_state *st = iio_backend_get_priv(back); 339 + unsigned int val; 340 + 341 + switch (size) { 342 + /* 343 + * There are two different variants of the AXI AXI_AD485X IP block, a 344 + * 16-bit and a 20-bit variant. 345 + * The 0x0 value (AXI_AD485X_PACKET_FORMAT_20BIT) is corresponding also 346 + * to the 16-bit variant of the IP block. 347 + */ 348 + case 16: 349 + case 20: 350 + val = AXI_AD485X_PACKET_FORMAT_20BIT; 351 + break; 352 + case 24: 353 + val = AXI_AD485X_PACKET_FORMAT_24BIT; 354 + break; 355 + /* 356 + * The 0x2 (AXI_AD485X_PACKET_FORMAT_32BIT) corresponds only to the 357 + * 20-bit variant of the IP block. Setting this value properly is 358 + * ensured by the upper layers of the drivers calling the axi-adc 359 + * functions. 360 + * Also, for 16-bit IP block, the 0x2 (AXI_AD485X_PACKET_FORMAT_32BIT) 361 + * value is handled as maximum size available which is 24-bit for this 362 + * configuration. 363 + */ 364 + case 32: 365 + val = AXI_AD485X_PACKET_FORMAT_32BIT; 366 + break; 367 + default: 368 + return -EINVAL; 369 + } 370 + 371 + return regmap_update_bits(st->regmap, ADI_AXI_ADC_REG_CNTRL_3, 372 + AXI_AD485X_CNTRL_3_PACKET_FORMAT_MSK, 373 + FIELD_PREP(AXI_AD485X_CNTRL_3_PACKET_FORMAT_MSK, val)); 374 + } 375 + 341 376 static struct iio_buffer *axi_adc_request_buffer(struct iio_backend *back, 342 377 struct iio_dev *indio_dev) 343 378 { ··· 535 488 .ops = &adi_axi_adc_ops, 536 489 }; 537 490 491 + static const struct iio_backend_ops adi_ad485x_ops = { 492 + .enable = axi_adc_enable, 493 + .disable = axi_adc_disable, 494 + .data_format_set = axi_adc_data_format_set, 495 + .chan_enable = axi_adc_chan_enable, 496 + .chan_disable = axi_adc_chan_disable, 497 + .request_buffer = axi_adc_request_buffer, 498 + .free_buffer = axi_adc_free_buffer, 499 + .data_sample_trigger = axi_adc_data_sample_trigger, 500 + .iodelay_set = axi_adc_iodelays_set, 501 + .chan_status = axi_adc_chan_status, 502 + .interface_type_get = axi_adc_interface_type_get, 503 + .data_size_set = axi_adc_ad485x_data_size_set, 504 + .debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access), 505 + .debugfs_print_chan_status = 506 + iio_backend_debugfs_ptr(axi_adc_debugfs_print_chan_status), 507 + }; 508 + 509 + static const struct iio_backend_info axi_ad485x = { 510 + .name = "axi-ad485x", 511 + .ops = &adi_ad485x_ops, 512 + }; 513 + 538 514 static int adi_axi_adc_probe(struct platform_device *pdev) 539 515 { 540 516 struct adi_axi_adc_state *st; ··· 615 545 return -ENODEV; 616 546 } 617 547 618 - ret = devm_iio_backend_register(&pdev->dev, &adi_axi_adc_generic, st); 548 + ret = devm_iio_backend_register(&pdev->dev, st->info->backend_info, st); 619 549 if (ret) 620 550 return dev_err_probe(&pdev->dev, ret, 621 551 "failed to register iio backend\n"); ··· 655 585 .backend_info = &adi_axi_adc_generic, 656 586 }; 657 587 588 + static const struct axi_adc_info adi_axi_ad485x = { 589 + .version = ADI_AXI_PCORE_VER(10, 0, 'a'), 590 + .backend_info = &axi_ad485x, 591 + }; 592 + 658 593 static const struct ad7606_platform_data ad7606_pdata = { 659 594 .bus_reg_read = ad7606_bus_reg_read, 660 595 .bus_reg_write = ad7606_bus_reg_write, ··· 676 601 /* Match table for of_platform binding */ 677 602 static const struct of_device_id adi_axi_adc_of_match[] = { 678 603 { .compatible = "adi,axi-adc-10.0.a", .data = &adc_generic }, 604 + { .compatible = "adi,axi-ad485x", .data = &adi_axi_ad485x }, 679 605 { .compatible = "adi,axi-ad7606x", .data = &adc_ad7606 }, 680 606 { /* end of list */ } 681 607 };