]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm/mipi_dsi: refactor device creation
authorArchit Taneja <architt@codeaurora.org>
Wed, 19 Aug 2015 10:44:09 +0000 (16:14 +0530)
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 11 Jan 2016 09:54:41 +0000 (09:54 +0000)
Create a helper function mipi_dsi_device_new which takes in struct
mipi_dsi_device_info and the mipi_dsi_host. This will be called by
of_mipi_dsi_device_add.

Instead of calling device_initialize and device_add separately, merge
it into a single device_register call. This will remove the need of
having two separate funcs mipi_dsi_device_alloc and mipi_dsi_device_add.

The reason for creating mipi_dsi_device_new is that it can also be used
as a standalone way for creating a dsi device that isn't available via
DT.

Signed-off-by: Archit Taneja <architt@codeaurora.org>
drivers/gpu/drm/drm_mipi_dsi.c
include/drm/drm_mipi_dsi.h

index 2d5ca8eec13a9611668a90756a756f6f40a0506b..583b3bc10495e67d9a551465b9c5085fe59aa54f 100644 (file)
@@ -102,9 +102,25 @@ static const struct device_type mipi_dsi_device_type = {
        .release = mipi_dsi_dev_release,
 };
 
-static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
+struct mipi_dsi_device_info {
+       char name[DSI_DEV_NAME_SIZE];
+       u32 reg;
+       struct device_node *node;
+};
+
+static struct mipi_dsi_device *
+mipi_dsi_device_new(struct mipi_dsi_host *host,
+                   struct mipi_dsi_device_info *info)
 {
+       struct device *dev = host->dev;
        struct mipi_dsi_device *dsi;
+       int r;
+
+       if (info->reg > 3) {
+               dev_err(dev, "dsi device %s has invalid channel value: %u\n",
+                       info->name, info->reg);
+               return ERR_PTR(-EINVAL);
+       }
 
        dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
        if (!dsi)
@@ -114,61 +130,43 @@ static struct mipi_dsi_device *mipi_dsi_device_alloc(struct mipi_dsi_host *host)
        dsi->dev.bus = &mipi_dsi_bus_type;
        dsi->dev.parent = host->dev;
        dsi->dev.type = &mipi_dsi_device_type;
+       dsi->dev.of_node = info->node;
+       dsi->channel = info->reg;
+       strlcpy(dsi->name, info->name, sizeof(dsi->name));
 
-       device_initialize(&dsi->dev);
+       dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev), info->reg);
 
-       return dsi;
-}
-
-static int mipi_dsi_device_add(struct mipi_dsi_device *dsi)
-{
-       struct mipi_dsi_host *host = dsi->host;
-
-       dev_set_name(&dsi->dev, "%s.%d", dev_name(host->dev),  dsi->channel);
+       r = device_register(&dsi->dev);
+       if (r) {
+               kfree(dsi);
+               return ERR_PTR(r);
+       }
 
-       return device_add(&dsi->dev);
+       return dsi;
 }
 
 static struct mipi_dsi_device *
 of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node)
 {
-       struct mipi_dsi_device *dsi;
        struct device *dev = host->dev;
+       struct mipi_dsi_device_info info = { };
        int ret;
-       u32 reg;
-
-       ret = of_property_read_u32(node, "reg", &reg);
-       if (ret) {
-               dev_err(dev, "device node %s has no valid reg property: %d\n",
-                       node->full_name, ret);
-               return ERR_PTR(-EINVAL);
-       }
 
-       if (reg > 3) {
-               dev_err(dev, "device node %s has invalid reg property: %u\n",
-                       node->full_name, reg);
+       if (of_modalias_node(node, info.name, sizeof(info.name)) < 0) {
+               dev_err(dev, "modalias failure on %s\n", node->full_name);
                return ERR_PTR(-EINVAL);
        }
 
-       dsi = mipi_dsi_device_alloc(host);
-       if (IS_ERR(dsi)) {
-               dev_err(dev, "failed to allocate DSI device %s: %ld\n",
-                       node->full_name, PTR_ERR(dsi));
-               return dsi;
-       }
-
-       dsi->dev.of_node = of_node_get(node);
-       dsi->channel = reg;
-
-       ret = mipi_dsi_device_add(dsi);
+       ret = of_property_read_u32(node, "reg", &info.reg);
        if (ret) {
-               dev_err(dev, "failed to add DSI device %s: %d\n",
+               dev_err(dev, "device node %s has no valid reg property: %d\n",
                        node->full_name, ret);
-               kfree(dsi);
-               return ERR_PTR(ret);
+               return ERR_PTR(-EINVAL);
        }
 
-       return dsi;
+       info.node = of_node_get(node);
+
+       return mipi_dsi_device_new(host, &info);
 }
 
 int mipi_dsi_host_register(struct mipi_dsi_host *host)
index f1d8d0dbb4f162f9ea1c90dda44beedf14e4c175..5a35c6fd9b09d28ed7c0ae18d93963144eb9dbf5 100644 (file)
@@ -139,10 +139,13 @@ enum mipi_dsi_pixel_format {
        MIPI_DSI_FMT_RGB565,
 };
 
+#define DSI_DEV_NAME_SIZE              20
+
 /**
  * struct mipi_dsi_device - DSI peripheral device
  * @host: DSI host for this peripheral
  * @dev: driver model device node for this peripheral
+ * @name: name of the dsi peripheral
  * @channel: virtual channel assigned to the peripheral
  * @format: pixel format for video mode
  * @lanes: number of active data lanes
@@ -152,6 +155,8 @@ struct mipi_dsi_device {
        struct mipi_dsi_host *host;
        struct device dev;
 
+       char name[DSI_DEV_NAME_SIZE];
+
        unsigned int channel;
        unsigned int lanes;
        enum mipi_dsi_pixel_format format;