| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | |
|---|
| 2 | 3 | /* The industrial I/O core |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2008 Jonathan Cameron |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 7 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 8 | | - * the Free Software Foundation. |
|---|
| 9 | 6 | */ |
|---|
| 10 | 7 | #ifndef _INDUSTRIAL_IO_H_ |
|---|
| 11 | 8 | #define _INDUSTRIAL_IO_H_ |
|---|
| .. | .. |
|---|
| 130 | 127 | |
|---|
| 131 | 128 | ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv, |
|---|
| 132 | 129 | const struct iio_chan_spec *chan, char *buf); |
|---|
| 133 | | -int of_iio_read_mount_matrix(const struct device *dev, const char *propname, |
|---|
| 134 | | - struct iio_mount_matrix *matrix); |
|---|
| 130 | +int iio_read_mount_matrix(struct device *dev, const char *propname, |
|---|
| 131 | + struct iio_mount_matrix *matrix); |
|---|
| 135 | 132 | |
|---|
| 136 | 133 | typedef const struct iio_mount_matrix * |
|---|
| 137 | 134 | (iio_get_mount_matrix_t)(const struct iio_dev *indio_dev, |
|---|
| .. | .. |
|---|
| 491 | 488 | * @currentmode: [DRIVER] current operating mode |
|---|
| 492 | 489 | * @dev: [DRIVER] device structure, should be assigned a parent |
|---|
| 493 | 490 | * and owner |
|---|
| 494 | | - * @event_interface: [INTERN] event chrdevs associated with interrupt lines |
|---|
| 495 | 491 | * @buffer: [DRIVER] any buffer present |
|---|
| 496 | | - * @buffer_list: [INTERN] list of all buffers currently attached |
|---|
| 497 | 492 | * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux |
|---|
| 498 | | - * @mlock: [DRIVER] lock used to prevent simultaneous device state |
|---|
| 493 | + * @mlock: [INTERN] lock used to prevent simultaneous device state |
|---|
| 499 | 494 | * changes |
|---|
| 500 | 495 | * @available_scan_masks: [DRIVER] optional array of allowed bitmasks |
|---|
| 501 | 496 | * @masklength: [INTERN] the length of the mask established from |
|---|
| .. | .. |
|---|
| 509 | 504 | * @pollfunc_event: [DRIVER] function run on events trigger being received |
|---|
| 510 | 505 | * @channels: [DRIVER] channel specification structure table |
|---|
| 511 | 506 | * @num_channels: [DRIVER] number of channels specified in @channels. |
|---|
| 512 | | - * @channel_attr_list: [INTERN] keep track of automatically created channel |
|---|
| 513 | | - * attributes |
|---|
| 514 | | - * @chan_attr_group: [INTERN] group for all attrs in base directory |
|---|
| 515 | 507 | * @name: [DRIVER] name of the device. |
|---|
| 508 | + * @label: [DRIVER] unique name to identify which device this is |
|---|
| 516 | 509 | * @info: [DRIVER] callbacks and constant info from driver |
|---|
| 517 | 510 | * @clock_id: [INTERN] timestamping clock posix identifier |
|---|
| 518 | 511 | * @info_exist_lock: [INTERN] lock to prevent use during removal |
|---|
| .. | .. |
|---|
| 522 | 515 | * @groups: [INTERN] attribute groups |
|---|
| 523 | 516 | * @groupcounter: [INTERN] index of next attribute group |
|---|
| 524 | 517 | * @flags: [INTERN] file ops related flags including busy flag. |
|---|
| 525 | | - * @debugfs_dentry: [INTERN] device specific debugfs dentry. |
|---|
| 526 | | - * @cached_reg_addr: [INTERN] cached register address for debugfs reads. |
|---|
| 518 | + * @priv: [DRIVER] reference to driver's private information |
|---|
| 519 | + * **MUST** be accessed **ONLY** via iio_priv() helper |
|---|
| 527 | 520 | */ |
|---|
| 528 | 521 | struct iio_dev { |
|---|
| 529 | 522 | int id; |
|---|
| .. | .. |
|---|
| 533 | 526 | int currentmode; |
|---|
| 534 | 527 | struct device dev; |
|---|
| 535 | 528 | |
|---|
| 536 | | - struct iio_event_interface *event_interface; |
|---|
| 537 | | - |
|---|
| 538 | 529 | struct iio_buffer *buffer; |
|---|
| 539 | | - struct list_head buffer_list; |
|---|
| 540 | 530 | int scan_bytes; |
|---|
| 541 | 531 | struct mutex mlock; |
|---|
| 542 | 532 | |
|---|
| .. | .. |
|---|
| 553 | 543 | struct iio_chan_spec const *channels; |
|---|
| 554 | 544 | int num_channels; |
|---|
| 555 | 545 | |
|---|
| 556 | | - struct list_head channel_attr_list; |
|---|
| 557 | | - struct attribute_group chan_attr_group; |
|---|
| 558 | 546 | const char *name; |
|---|
| 547 | + const char *label; |
|---|
| 559 | 548 | const struct iio_info *info; |
|---|
| 560 | 549 | clockid_t clock_id; |
|---|
| 561 | 550 | struct mutex info_exist_lock; |
|---|
| .. | .. |
|---|
| 566 | 555 | int groupcounter; |
|---|
| 567 | 556 | |
|---|
| 568 | 557 | unsigned long flags; |
|---|
| 569 | | -#if defined(CONFIG_DEBUG_FS) |
|---|
| 570 | | - struct dentry *debugfs_dentry; |
|---|
| 571 | | - unsigned cached_reg_addr; |
|---|
| 572 | | -#endif |
|---|
| 558 | + void *priv; |
|---|
| 573 | 559 | }; |
|---|
| 574 | 560 | |
|---|
| 575 | 561 | const struct iio_chan_spec |
|---|
| .. | .. |
|---|
| 592 | 578 | * calls iio_device_register() internally. Refer to that function for more |
|---|
| 593 | 579 | * information. |
|---|
| 594 | 580 | * |
|---|
| 595 | | - * If an iio_dev registered with this function needs to be unregistered |
|---|
| 596 | | - * separately, devm_iio_device_unregister() must be used. |
|---|
| 597 | | - * |
|---|
| 598 | 581 | * RETURNS: |
|---|
| 599 | 582 | * 0 on success, negative error number on failure. |
|---|
| 600 | 583 | */ |
|---|
| .. | .. |
|---|
| 602 | 585 | __devm_iio_device_register((dev), (indio_dev), THIS_MODULE) |
|---|
| 603 | 586 | int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev, |
|---|
| 604 | 587 | struct module *this_mod); |
|---|
| 605 | | -void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev); |
|---|
| 606 | 588 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); |
|---|
| 607 | 589 | int iio_device_claim_direct_mode(struct iio_dev *indio_dev); |
|---|
| 608 | 590 | void iio_device_release_direct_mode(struct iio_dev *indio_dev); |
|---|
| .. | .. |
|---|
| 628 | 610 | return indio_dev->clock_id; |
|---|
| 629 | 611 | } |
|---|
| 630 | 612 | |
|---|
| 613 | +int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id); |
|---|
| 614 | + |
|---|
| 631 | 615 | /** |
|---|
| 632 | 616 | * dev_to_iio_dev() - Get IIO device struct from a device struct |
|---|
| 633 | 617 | * @dev: The device embedded in the IIO device |
|---|
| .. | .. |
|---|
| 650 | 634 | return indio_dev ? dev_to_iio_dev(get_device(&indio_dev->dev)) : NULL; |
|---|
| 651 | 635 | } |
|---|
| 652 | 636 | |
|---|
| 637 | +/** |
|---|
| 638 | + * iio_device_set_parent() - assign parent device to the IIO device object |
|---|
| 639 | + * @indio_dev: IIO device structure |
|---|
| 640 | + * @parent: reference to parent device object |
|---|
| 641 | + * |
|---|
| 642 | + * This utility must be called between IIO device allocation |
|---|
| 643 | + * (via devm_iio_device_alloc()) & IIO device registration |
|---|
| 644 | + * (via iio_device_register() and devm_iio_device_register())). |
|---|
| 645 | + * By default, the device allocation will also assign a parent device to |
|---|
| 646 | + * the IIO device object. In cases where devm_iio_device_alloc() is used, |
|---|
| 647 | + * sometimes the parent device must be different than the device used to |
|---|
| 648 | + * manage the allocation. |
|---|
| 649 | + * In that case, this helper should be used to change the parent, hence the |
|---|
| 650 | + * requirement to call this between allocation & registration. |
|---|
| 651 | + **/ |
|---|
| 652 | +static inline void iio_device_set_parent(struct iio_dev *indio_dev, |
|---|
| 653 | + struct device *parent) |
|---|
| 654 | +{ |
|---|
| 655 | + indio_dev->dev.parent = parent; |
|---|
| 656 | +} |
|---|
| 653 | 657 | |
|---|
| 654 | 658 | /** |
|---|
| 655 | 659 | * iio_device_set_drvdata() - Set device driver data |
|---|
| .. | .. |
|---|
| 670 | 674 | * |
|---|
| 671 | 675 | * Returns the data previously set with iio_device_set_drvdata() |
|---|
| 672 | 676 | */ |
|---|
| 673 | | -static inline void *iio_device_get_drvdata(struct iio_dev *indio_dev) |
|---|
| 677 | +static inline void *iio_device_get_drvdata(const struct iio_dev *indio_dev) |
|---|
| 674 | 678 | { |
|---|
| 675 | 679 | return dev_get_drvdata(&indio_dev->dev); |
|---|
| 676 | 680 | } |
|---|
| 677 | 681 | |
|---|
| 678 | 682 | /* Can we make this smaller? */ |
|---|
| 679 | 683 | #define IIO_ALIGN L1_CACHE_BYTES |
|---|
| 680 | | -struct iio_dev *iio_device_alloc(int sizeof_priv); |
|---|
| 684 | +struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv); |
|---|
| 681 | 685 | |
|---|
| 686 | +/* The information at the returned address is guaranteed to be cacheline aligned */ |
|---|
| 682 | 687 | static inline void *iio_priv(const struct iio_dev *indio_dev) |
|---|
| 683 | 688 | { |
|---|
| 684 | | - return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN); |
|---|
| 685 | | -} |
|---|
| 686 | | - |
|---|
| 687 | | -static inline struct iio_dev *iio_priv_to_dev(void *priv) |
|---|
| 688 | | -{ |
|---|
| 689 | | - return (struct iio_dev *)((char *)priv - |
|---|
| 690 | | - ALIGN(sizeof(struct iio_dev), IIO_ALIGN)); |
|---|
| 689 | + return indio_dev->priv; |
|---|
| 691 | 690 | } |
|---|
| 692 | 691 | |
|---|
| 693 | 692 | void iio_device_free(struct iio_dev *indio_dev); |
|---|
| 694 | | -int devm_iio_device_match(struct device *dev, void *res, void *data); |
|---|
| 695 | | -struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv); |
|---|
| 696 | | -void devm_iio_device_free(struct device *dev, struct iio_dev *indio_dev); |
|---|
| 693 | +struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv); |
|---|
| 694 | +__printf(2, 3) |
|---|
| 697 | 695 | struct iio_trigger *devm_iio_trigger_alloc(struct device *dev, |
|---|
| 698 | | - const char *fmt, ...); |
|---|
| 699 | | -void devm_iio_trigger_free(struct device *dev, struct iio_trigger *iio_trig); |
|---|
| 700 | | - |
|---|
| 696 | + const char *fmt, ...); |
|---|
| 701 | 697 | /** |
|---|
| 702 | 698 | * iio_buffer_enabled() - helper function to test if the buffer is enabled |
|---|
| 703 | 699 | * @indio_dev: IIO device structure for device |
|---|
| .. | .. |
|---|
| 714 | 710 | * @indio_dev: IIO device structure for device |
|---|
| 715 | 711 | **/ |
|---|
| 716 | 712 | #if defined(CONFIG_DEBUG_FS) |
|---|
| 717 | | -static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) |
|---|
| 718 | | -{ |
|---|
| 719 | | - return indio_dev->debugfs_dentry; |
|---|
| 720 | | -} |
|---|
| 713 | +struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev); |
|---|
| 721 | 714 | #else |
|---|
| 722 | 715 | static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) |
|---|
| 723 | 716 | { |
|---|