Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Fieldbus Device Driver Core
0004  *
0005  */
0006 
0007 #ifndef __FIELDBUS_DEV_H
0008 #define __FIELDBUS_DEV_H
0009 
0010 #include <linux/cdev.h>
0011 #include <linux/wait.h>
0012 
0013 enum fieldbus_dev_type {
0014     FIELDBUS_DEV_TYPE_UNKNOWN = 0,
0015     FIELDBUS_DEV_TYPE_PROFINET,
0016 };
0017 
0018 enum fieldbus_dev_offl_mode {
0019     FIELDBUS_DEV_OFFL_MODE_CLEAR = 0,
0020     FIELDBUS_DEV_OFFL_MODE_FREEZE,
0021     FIELDBUS_DEV_OFFL_MODE_SET
0022 };
0023 
0024 /**
0025  * struct fieldbus_dev - Fieldbus device
0026  * @read_area:      [DRIVER] function to read the process data area of the
0027  *               device. same parameters/return values as
0028  *               the read function in struct file_operations
0029  * @write_area:     [DRIVER] function to write to the process data area of
0030  *               the device. same parameters/return values as
0031  *               the write function in struct file_operations
0032  * @write_area_sz   [DRIVER] size of the writable process data area
0033  * @read_area_sz    [DRIVER] size of the readable process data area
0034  * @card_name       [DRIVER] name of the card, e.g. "ACME Inc. profinet"
0035  * @fieldbus_type   [DRIVER] fieldbus type of this device, e.g.
0036  *                  FIELDBUS_DEV_TYPE_PROFINET
0037  * @enable_get      [DRIVER] function which returns true if the card
0038  *               is enabled, false otherwise
0039  * @fieldbus_id_get [DRIVER] function to retrieve the unique fieldbus id
0040  *               by which this device can be identified;
0041  *               return value follows the snprintf convention
0042  * @simple_enable_set   [DRIVER] (optional) function to enable the device
0043  *               according to its default settings
0044  * @parent      [DRIVER] (optional) the device's parent device
0045  */
0046 struct fieldbus_dev {
0047     ssize_t (*read_area)(struct fieldbus_dev *fbdev, char __user *buf,
0048                  size_t size, loff_t *offset);
0049     ssize_t (*write_area)(struct fieldbus_dev *fbdev,
0050                   const char __user *buf, size_t size,
0051                   loff_t *offset);
0052     size_t write_area_sz, read_area_sz;
0053     const char *card_name;
0054     enum fieldbus_dev_type fieldbus_type;
0055     bool (*enable_get)(struct fieldbus_dev *fbdev);
0056     int (*fieldbus_id_get)(struct fieldbus_dev *fbdev, char *buf,
0057                    size_t max_size);
0058     int (*simple_enable_set)(struct fieldbus_dev *fbdev, bool enable);
0059     struct device *parent;
0060 
0061     /* private data */
0062     int id;
0063     struct cdev cdev;
0064     struct device *dev;
0065     int dc_event;
0066     wait_queue_head_t dc_wq;
0067     bool online;
0068 };
0069 
0070 #if IS_ENABLED(CONFIG_FIELDBUS_DEV)
0071 
0072 /**
0073  * fieldbus_dev_unregister()
0074  *  - unregister a previously registered fieldbus device
0075  * @fb:     Device structure previously registered
0076  **/
0077 void fieldbus_dev_unregister(struct fieldbus_dev *fb);
0078 
0079 /**
0080  * fieldbus_dev_register()
0081  *  - register a device with the fieldbus device subsystem
0082  * @fb:     Device structure filled by the device driver
0083  **/
0084 int __must_check fieldbus_dev_register(struct fieldbus_dev *fb);
0085 
0086 /**
0087  * fieldbus_dev_area_updated()
0088  *  - notify the subsystem that an external fieldbus controller updated
0089  *          the process data area
0090  * @fb:     Device structure
0091  **/
0092 void fieldbus_dev_area_updated(struct fieldbus_dev *fb);
0093 
0094 /**
0095  * fieldbus_dev_online_changed()
0096  *  - notify the subsystem that the fieldbus online status changed
0097  * @fb:     Device structure
0098  **/
0099 void fieldbus_dev_online_changed(struct fieldbus_dev *fb, bool online);
0100 
0101 #else /* IS_ENABLED(CONFIG_FIELDBUS_DEV) */
0102 
0103 static inline void fieldbus_dev_unregister(struct fieldbus_dev *fb) {}
0104 static inline int __must_check fieldbus_dev_register(struct fieldbus_dev *fb)
0105 {
0106     return -ENOTSUPP;
0107 }
0108 
0109 static inline void fieldbus_dev_area_updated(struct fieldbus_dev *fb) {}
0110 static inline void fieldbus_dev_online_changed(struct fieldbus_dev *fb,
0111                            bool online) {}
0112 
0113 #endif /* IS_ENABLED(CONFIG_FIELDBUS_DEV) */
0114 #endif /* __FIELDBUS_DEV_H */