Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (C) 2015 Pengutronix, Uwe Kleine-König <kernel@pengutronix.de>
0004  */
0005 
0006 #include <linux/device.h>
0007 
0008 #define to_siox_device(_dev)    container_of((_dev), struct siox_device, dev)
0009 struct siox_device {
0010     struct list_head node; /* node in smaster->devices */
0011     struct siox_master *smaster;
0012     struct device dev;
0013 
0014     const char *type;
0015     size_t inbytes;
0016     size_t outbytes;
0017     u8 statustype;
0018 
0019     u8 status_read_clean;
0020     u8 status_written;
0021     u8 status_written_lastcycle;
0022     bool connected;
0023 
0024     /* statistics */
0025     unsigned int watchdog_errors;
0026     unsigned int status_errors;
0027 
0028     struct kernfs_node *status_errors_kn;
0029     struct kernfs_node *watchdog_kn;
0030     struct kernfs_node *watchdog_errors_kn;
0031     struct kernfs_node *connected_kn;
0032 };
0033 
0034 bool siox_device_synced(struct siox_device *sdevice);
0035 bool siox_device_connected(struct siox_device *sdevice);
0036 
0037 struct siox_driver {
0038     int (*probe)(struct siox_device *sdevice);
0039     void (*remove)(struct siox_device *sdevice);
0040     void (*shutdown)(struct siox_device *sdevice);
0041 
0042     /*
0043      * buf is big enough to hold sdev->inbytes - 1 bytes, the status byte
0044      * is in the scope of the framework.
0045      */
0046     int (*set_data)(struct siox_device *sdevice, u8 status, u8 buf[]);
0047     /*
0048      * buf is big enough to hold sdev->outbytes - 1 bytes, the status byte
0049      * is in the scope of the framework
0050      */
0051     int (*get_data)(struct siox_device *sdevice, const u8 buf[]);
0052 
0053     struct device_driver driver;
0054 };
0055 
0056 static inline struct siox_driver *to_siox_driver(struct device_driver *driver)
0057 {
0058     if (driver)
0059         return container_of(driver, struct siox_driver, driver);
0060     else
0061         return NULL;
0062 }
0063 
0064 int __siox_driver_register(struct siox_driver *sdriver, struct module *owner);
0065 
0066 static inline int siox_driver_register(struct siox_driver *sdriver)
0067 {
0068     return __siox_driver_register(sdriver, THIS_MODULE);
0069 }
0070 
0071 static inline void siox_driver_unregister(struct siox_driver *sdriver)
0072 {
0073     return driver_unregister(&sdriver->driver);
0074 }
0075 
0076 /*
0077  * module_siox_driver() - Helper macro for drivers that don't do
0078  * anything special in module init/exit.  This eliminates a lot of
0079  * boilerplate.  Each module may only use this macro once, and
0080  * calling it replaces module_init() and module_exit()
0081  */
0082 #define module_siox_driver(__siox_driver) \
0083     module_driver(__siox_driver, siox_driver_register, \
0084             siox_driver_unregister)