Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Allwinner Reduced Serial Bus Driver
0003  *
0004  * Copyright (c) 2015 Chen-Yu Tsai
0005  *
0006  * Author: Chen-Yu Tsai <wens@csie.org>
0007  *
0008  * This file is licensed under the terms of the GNU General Public
0009  * License version 2.  This program is licensed "as is" without any
0010  * warranty of any kind, whether express or implied.
0011  */
0012 #ifndef _SUNXI_RSB_H
0013 #define _SUNXI_RSB_H
0014 
0015 #include <linux/device.h>
0016 #include <linux/regmap.h>
0017 #include <linux/types.h>
0018 
0019 struct sunxi_rsb;
0020 
0021 /**
0022  * struct sunxi_rsb_device - Basic representation of an RSB device
0023  * @dev:    Driver model representation of the device.
0024  * @ctrl:   RSB controller managing the bus hosting this device.
0025  * @rtaddr: This device's runtime address
0026  * @hwaddr: This device's hardware address
0027  */
0028 struct sunxi_rsb_device {
0029     struct device       dev;
0030     struct sunxi_rsb    *rsb;
0031     int         irq;
0032     u8          rtaddr;
0033     u16         hwaddr;
0034 };
0035 
0036 static inline struct sunxi_rsb_device *to_sunxi_rsb_device(struct device *d)
0037 {
0038     return container_of(d, struct sunxi_rsb_device, dev);
0039 }
0040 
0041 static inline void *sunxi_rsb_device_get_drvdata(const struct sunxi_rsb_device *rdev)
0042 {
0043     return dev_get_drvdata(&rdev->dev);
0044 }
0045 
0046 static inline void sunxi_rsb_device_set_drvdata(struct sunxi_rsb_device *rdev,
0047                         void *data)
0048 {
0049     dev_set_drvdata(&rdev->dev, data);
0050 }
0051 
0052 /**
0053  * struct sunxi_rsb_driver - RSB slave device driver
0054  * @driver: RSB device drivers should initialize name and owner field of
0055  *      this structure.
0056  * @probe:  binds this driver to a RSB device.
0057  * @remove: unbinds this driver from the RSB device.
0058  */
0059 struct sunxi_rsb_driver {
0060     struct device_driver driver;
0061     int (*probe)(struct sunxi_rsb_device *rdev);
0062     void (*remove)(struct sunxi_rsb_device *rdev);
0063 };
0064 
0065 static inline struct sunxi_rsb_driver *to_sunxi_rsb_driver(struct device_driver *d)
0066 {
0067     return container_of(d, struct sunxi_rsb_driver, driver);
0068 }
0069 
0070 int sunxi_rsb_driver_register(struct sunxi_rsb_driver *rdrv);
0071 
0072 /**
0073  * sunxi_rsb_driver_unregister() - unregister an RSB client driver
0074  * @rdrv:   the driver to unregister
0075  */
0076 static inline void sunxi_rsb_driver_unregister(struct sunxi_rsb_driver *rdrv)
0077 {
0078     if (rdrv)
0079         driver_unregister(&rdrv->driver);
0080 }
0081 
0082 #define module_sunxi_rsb_driver(__sunxi_rsb_driver) \
0083     module_driver(__sunxi_rsb_driver, sunxi_rsb_driver_register, \
0084             sunxi_rsb_driver_unregister)
0085 
0086 struct regmap *__devm_regmap_init_sunxi_rsb(struct sunxi_rsb_device *rdev,
0087                         const struct regmap_config *config,
0088                         struct lock_class_key *lock_key,
0089                         const char *lock_name);
0090 
0091 /**
0092  * devm_regmap_init_sunxi_rsb(): Initialise managed register map
0093  *
0094  * @rdev: Device that will be interacted with
0095  * @config: Configuration for register map
0096  *
0097  * The return value will be an ERR_PTR() on error or a valid pointer
0098  * to a struct regmap.  The regmap will be automatically freed by the
0099  * device management code.
0100  */
0101 #define devm_regmap_init_sunxi_rsb(rdev, config)            \
0102     __regmap_lockdep_wrapper(__devm_regmap_init_sunxi_rsb, #config, \
0103                  rdev, config)
0104 
0105 #endif /* _SUNXI_RSB_H */