|
@@ -609,3 +609,166 @@ struct omap_device *omap_device_alloc(struct platform_device *pdev,
|
|
|
if (!pdev->num_resources) {
|
|
|
dev_dbg(&pdev->dev, "%s: using %d resources from hwmod\n",
|
|
|
__func__, res_count);
|
|
|
+ omap_device_fill_resources(od, res);
|
|
|
+ } else {
|
|
|
+ dev_dbg(&pdev->dev,
|
|
|
+ "%s: appending %d DMA resources from hwmod\n",
|
|
|
+ __func__, res_count - pdev->num_resources);
|
|
|
+ memcpy(res, pdev->resource,
|
|
|
+ sizeof(struct resource) * pdev->num_resources);
|
|
|
+ _od_fill_dma_resources(od, &res[pdev->num_resources]);
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = platform_device_add_resources(pdev, res, res_count);
|
|
|
+ kfree(res);
|
|
|
+
|
|
|
+ if (ret)
|
|
|
+ goto oda_exit3;
|
|
|
+
|
|
|
+have_everything:
|
|
|
+ if (!pm_lats) {
|
|
|
+ pm_lats = omap_default_latency;
|
|
|
+ pm_lats_cnt = ARRAY_SIZE(omap_default_latency);
|
|
|
+ }
|
|
|
+
|
|
|
+ od->pm_lats_cnt = pm_lats_cnt;
|
|
|
+ od->pm_lats = kmemdup(pm_lats,
|
|
|
+ sizeof(struct omap_device_pm_latency) * pm_lats_cnt,
|
|
|
+ GFP_KERNEL);
|
|
|
+ if (!od->pm_lats)
|
|
|
+ goto oda_exit3;
|
|
|
+
|
|
|
+ pdev->archdata.od = od;
|
|
|
+
|
|
|
+ for (i = 0; i < oh_cnt; i++) {
|
|
|
+ hwmods[i]->od = od;
|
|
|
+ _add_hwmod_clocks_clkdev(od, hwmods[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ return od;
|
|
|
+
|
|
|
+oda_exit3:
|
|
|
+ kfree(hwmods);
|
|
|
+oda_exit2:
|
|
|
+ kfree(od);
|
|
|
+oda_exit1:
|
|
|
+ dev_err(&pdev->dev, "omap_device: build failed (%d)\n", ret);
|
|
|
+
|
|
|
+ return ERR_PTR(ret);
|
|
|
+}
|
|
|
+
|
|
|
+void omap_device_delete(struct omap_device *od)
|
|
|
+{
|
|
|
+ if (!od)
|
|
|
+ return;
|
|
|
+
|
|
|
+ od->pdev->archdata.od = NULL;
|
|
|
+ kfree(od->pm_lats);
|
|
|
+ kfree(od->hwmods);
|
|
|
+ kfree(od);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * omap_device_build - build and register an omap_device with one omap_hwmod
|
|
|
+ * @pdev_name: name of the platform_device driver to use
|
|
|
+ * @pdev_id: this platform_device's connection ID
|
|
|
+ * @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
+ * @pdata: platform_data ptr to associate with the platform_device
|
|
|
+ * @pdata_len: amount of memory pointed to by @pdata
|
|
|
+ * @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
+ * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
|
|
+ * @is_early_device: should the device be registered as an early device or not
|
|
|
+ *
|
|
|
+ * Convenience function for building and registering a single
|
|
|
+ * omap_device record, which in turn builds and registers a
|
|
|
+ * platform_device record. See omap_device_build_ss() for more
|
|
|
+ * information. Returns ERR_PTR(-EINVAL) if @oh is NULL; otherwise,
|
|
|
+ * passes along the return value of omap_device_build_ss().
|
|
|
+ */
|
|
|
+struct platform_device __init *omap_device_build(const char *pdev_name, int pdev_id,
|
|
|
+ struct omap_hwmod *oh, void *pdata,
|
|
|
+ int pdata_len,
|
|
|
+ struct omap_device_pm_latency *pm_lats,
|
|
|
+ int pm_lats_cnt, int is_early_device)
|
|
|
+{
|
|
|
+ struct omap_hwmod *ohs[] = { oh };
|
|
|
+
|
|
|
+ if (!oh)
|
|
|
+ return ERR_PTR(-EINVAL);
|
|
|
+
|
|
|
+ return omap_device_build_ss(pdev_name, pdev_id, ohs, 1, pdata,
|
|
|
+ pdata_len, pm_lats, pm_lats_cnt,
|
|
|
+ is_early_device);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * omap_device_build_ss - build and register an omap_device with multiple hwmods
|
|
|
+ * @pdev_name: name of the platform_device driver to use
|
|
|
+ * @pdev_id: this platform_device's connection ID
|
|
|
+ * @oh: ptr to the single omap_hwmod that backs this omap_device
|
|
|
+ * @pdata: platform_data ptr to associate with the platform_device
|
|
|
+ * @pdata_len: amount of memory pointed to by @pdata
|
|
|
+ * @pm_lats: pointer to a omap_device_pm_latency array for this device
|
|
|
+ * @pm_lats_cnt: ARRAY_SIZE() of @pm_lats
|
|
|
+ * @is_early_device: should the device be registered as an early device or not
|
|
|
+ *
|
|
|
+ * Convenience function for building and registering an omap_device
|
|
|
+ * subsystem record. Subsystem records consist of multiple
|
|
|
+ * omap_hwmods. This function in turn builds and registers a
|
|
|
+ * platform_device record. Returns an ERR_PTR() on error, or passes
|
|
|
+ * along the return value of omap_device_register().
|
|
|
+ */
|
|
|
+struct platform_device __init *omap_device_build_ss(const char *pdev_name, int pdev_id,
|
|
|
+ struct omap_hwmod **ohs, int oh_cnt,
|
|
|
+ void *pdata, int pdata_len,
|
|
|
+ struct omap_device_pm_latency *pm_lats,
|
|
|
+ int pm_lats_cnt, int is_early_device)
|
|
|
+{
|
|
|
+ int ret = -ENOMEM;
|
|
|
+ struct platform_device *pdev;
|
|
|
+ struct omap_device *od;
|
|
|
+
|
|
|
+ if (!ohs || oh_cnt == 0 || !pdev_name)
|
|
|
+ return ERR_PTR(-EINVAL);
|
|
|
+
|
|
|
+ if (!pdata && pdata_len > 0)
|
|
|
+ return ERR_PTR(-EINVAL);
|
|
|
+
|
|
|
+ pdev = platform_device_alloc(pdev_name, pdev_id);
|
|
|
+ if (!pdev) {
|
|
|
+ ret = -ENOMEM;
|
|
|
+ goto odbs_exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Set the dev_name early to allow dev_xxx in omap_device_alloc */
|
|
|
+ if (pdev->id != -1)
|
|
|
+ dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
|
|
|
+ else
|
|
|
+ dev_set_name(&pdev->dev, "%s", pdev->name);
|
|
|
+
|
|
|
+ od = omap_device_alloc(pdev, ohs, oh_cnt, pm_lats, pm_lats_cnt);
|
|
|
+ if (IS_ERR(od))
|
|
|
+ goto odbs_exit1;
|
|
|
+
|
|
|
+ ret = platform_device_add_data(pdev, pdata, pdata_len);
|
|
|
+ if (ret)
|
|
|
+ goto odbs_exit2;
|
|
|
+
|
|
|
+ if (is_early_device)
|
|
|
+ ret = omap_early_device_register(pdev);
|
|
|
+ else
|
|
|
+ ret = omap_device_register(pdev);
|
|
|
+ if (ret)
|
|
|
+ goto odbs_exit2;
|
|
|
+
|
|
|
+ return pdev;
|
|
|
+
|
|
|
+odbs_exit2:
|
|
|
+ omap_device_delete(od);
|
|
|
+odbs_exit1:
|
|
|
+ platform_device_put(pdev);
|
|
|
+odbs_exit:
|
|
|
+
|
|
|
+ pr_err("omap_device: %s: build failed (%d)\n", pdev_name, ret);
|
|
|
+
|
|
|
+ return ERR_PTR(ret);
|