]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
staging: fsl-mc: add support for device type
authorLaurentiu Tudor <laurentiu.tudor@nxp.com>
Fri, 17 Nov 2017 13:38:33 +0000 (15:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 27 Nov 2017 08:20:41 +0000 (09:20 +0100)
The MC bus has different types of devices and this is supported by
device model. This patch adds initial support for device types
(defines them, adds helpers and sets the device type).

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/fsl-mc/bus/fsl-mc-bus.c
drivers/staging/fsl-mc/include/mc.h

index 854bd80dc7401127a60a4ed322759a9aec78974c..aa935f3fda756960b998306dc1a8f5c0db980c90 100644 (file)
@@ -156,6 +156,68 @@ struct bus_type fsl_mc_bus_type = {
 };
 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
 
+struct device_type fsl_mc_bus_dprc_type = {
+       .name = "fsl_mc_bus_dprc"
+};
+
+struct device_type fsl_mc_bus_dpni_type = {
+       .name = "fsl_mc_bus_dpni"
+};
+
+struct device_type fsl_mc_bus_dpio_type = {
+       .name = "fsl_mc_bus_dpio"
+};
+
+struct device_type fsl_mc_bus_dpsw_type = {
+       .name = "fsl_mc_bus_dpsw"
+};
+
+struct device_type fsl_mc_bus_dpbp_type = {
+       .name = "fsl_mc_bus_dpbp"
+};
+
+struct device_type fsl_mc_bus_dpcon_type = {
+       .name = "fsl_mc_bus_dpcon"
+};
+
+struct device_type fsl_mc_bus_dpmcp_type = {
+       .name = "fsl_mc_bus_dpmcp"
+};
+
+struct device_type fsl_mc_bus_dpmac_type = {
+       .name = "fsl_mc_bus_dpmac"
+};
+
+struct device_type fsl_mc_bus_dprtc_type = {
+       .name = "fsl_mc_bus_dprtc"
+};
+
+static struct device_type *fsl_mc_get_device_type(const char *type)
+{
+       static const struct {
+               struct device_type *dev_type;
+               const char *type;
+       } dev_types[] = {
+               { &fsl_mc_bus_dprc_type, "dprc" },
+               { &fsl_mc_bus_dpni_type, "dpni" },
+               { &fsl_mc_bus_dpio_type, "dpio" },
+               { &fsl_mc_bus_dpsw_type, "dpsw" },
+               { &fsl_mc_bus_dpbp_type, "dpbp" },
+               { &fsl_mc_bus_dpcon_type, "dpcon" },
+               { &fsl_mc_bus_dpmcp_type, "dpmcp" },
+               { &fsl_mc_bus_dpmac_type, "dpmac" },
+               { &fsl_mc_bus_dprtc_type, "dprtc" },
+               { NULL, NULL }
+       };
+       int i;
+
+       for (i = 0; dev_types[i].dev_type; i++)
+               if (!strcmp(dev_types[i].type, type))
+                       return dev_types[i].dev_type;
+
+       return NULL;
+}
+
 static int fsl_mc_driver_probe(struct device *dev)
 {
        struct fsl_mc_driver *mc_drv;
@@ -506,6 +568,11 @@ int fsl_mc_device_add(struct fsl_mc_obj_desc *obj_desc,
        mc_dev->dev.parent = parent_dev;
        mc_dev->dev.bus = &fsl_mc_bus_type;
        mc_dev->dev.release = fsl_mc_device_release;
+       mc_dev->dev.type = fsl_mc_get_device_type(obj_desc->type);
+       if (!mc_dev->dev.type) {
+               dev_err(parent_dev, "unknown device type %s\n", obj_desc->type);
+               goto error_cleanup_dev;
+       }
        dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
 
        if (strcmp(obj_desc->type, "dprc") == 0) {
index aafe63a21f4958cf895426a787b694ae0ecd18dd..15db93d71f828544bb6ee53baf1fa939ccc1eb48 100644 (file)
@@ -398,4 +398,59 @@ void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
 
 extern struct bus_type fsl_mc_bus_type;
 
+extern struct device_type fsl_mc_bus_dprc_type;
+extern struct device_type fsl_mc_bus_dpni_type;
+extern struct device_type fsl_mc_bus_dpio_type;
+extern struct device_type fsl_mc_bus_dpsw_type;
+extern struct device_type fsl_mc_bus_dpbp_type;
+extern struct device_type fsl_mc_bus_dpcon_type;
+extern struct device_type fsl_mc_bus_dpmcp_type;
+extern struct device_type fsl_mc_bus_dpmac_type;
+extern struct device_type fsl_mc_bus_dprtc_type;
+
+static inline bool is_fsl_mc_bus_dprc(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dprc_type;
+}
+
+static inline bool is_fsl_mc_bus_dpni(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpni_type;
+}
+
+static inline bool is_fsl_mc_bus_dpio(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpio_type;
+}
+
+static inline bool is_fsl_mc_bus_dpsw(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpsw_type;
+}
+
+static inline bool is_fsl_mc_bus_dpbp(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpbp_type;
+}
+
+static inline bool is_fsl_mc_bus_dpcon(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpcon_type;
+}
+
+static inline bool is_fsl_mc_bus_dpmcp(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpmcp_type;
+}
+
+static inline bool is_fsl_mc_bus_dpmac(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dpmac_type;
+}
+
+static inline bool is_fsl_mc_bus_dprtc(const struct fsl_mc_device *mc_dev)
+{
+       return mc_dev->dev.type == &fsl_mc_bus_dprtc_type;
+}
+
 #endif /* _FSL_MC_H_ */