MLK-20886-6 imx8qm/qxp: Implement runtime i2c driver binding
authorYe Li <ye.li@nxp.com>
Thu, 31 Jan 2019 06:24:15 +0000 (22:24 -0800)
committerYe Li <ye.li@nxp.com>
Fri, 24 May 2019 11:28:16 +0000 (04:28 -0700)
When a i2c device is binding with drivers, we check whether current
partition ownes the resource. If not owned, the binding to local lpi2c
driver will fail, otherwise binding to virtual i2c driver will fail.

Signed-off-by: Ye Li <ye.li@nxp.com>
(cherry picked from commit 81dd157fd0ba476c994e95a63515cb65164f1e87)

arch/arm/mach-imx/imx8/cpu.c

index 4e028e3..2c5ba8e 100644 (file)
@@ -1726,6 +1726,32 @@ void power_off_pd_devices(const char* permanent_on_devices[], int size)
        }
 }
 
+bool check_owned_udevice(struct udevice *dev)
+{
+       int ret;
+       sc_rsrc_t resource_id;
+       struct ofnode_phandle_args args;
+
+       /* Get the resource id from its power-domain */
+       ret = dev_read_phandle_with_args(dev, "power-domains",
+                                        "#power-domain-cells", 0, 0, &args);
+       if (ret) {
+               printf("no power-domains found\n");
+               return false;
+       }
+
+       /* Get the owner partition for resource*/
+       resource_id = (sc_rsrc_t)ofnode_read_u32_default(args.node, "reg", SC_R_LAST);
+       if (resource_id == SC_R_LAST) {
+               printf("Can't find the resource id for udev %s\n", dev->name);
+               return false;
+       }
+
+       debug("udev %s, resource id %d\n", dev->name, resource_id);
+
+       return check_owned_resource(resource_id);
+}
+
 #ifdef CONFIG_IMX_VSERVICE
 struct udevice * board_imx_vservice_find_mu(struct udevice *dev)
 {
@@ -1816,3 +1842,23 @@ void * board_imx_vservice_get_buffer(struct imx_vservice_channel *node, u32 size
        return NULL;
 }
 #endif
+
+/* imx8qxp i2c1 has lots of devices may used by both M4 and A core
+*   If A core partition does not own the resource, we will start
+*   virtual i2c driver. Otherwise use local i2c driver.
+*/
+int board_imx_virt_i2c_bind(struct udevice *dev)
+{
+       if (check_owned_udevice(dev))
+               return -ENODEV;
+
+       return 0;
+}
+
+int board_imx_lpi2c_bind(struct udevice *dev)
+{
+       if (check_owned_udevice(dev))
+               return 0;
+
+       return -ENODEV;
+}