riscv:linux:vout:mipi
authorkeith.zhao <keith.zhao@starfivetech.com>
Wed, 9 Nov 2022 02:43:13 +0000 (18:43 -0800)
committerkeith.zhao <keith.zhao@starfivetech.com>
Wed, 9 Nov 2022 02:43:13 +0000 (18:43 -0800)
add 800*1280 I2C read to detect the status of connection

Signed-off-by: keith <keith.zhao@starfivetech.com>
arch/riscv/boot/dts/starfive/jh7110-visionfive-v2.dtsi
drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c

index 2ac74f8..99ed2a6 100755 (executable)
                };
        };
 
-       panel_radxa@22 {
+       panel_radxa@19 {
                compatible ="starfive_jadard";
-               reg = <0x22>;
+               reg = <0x19>;
                reset-gpio = <&gpio 23 0>;
                enable-gpio = <&gpio 22 0>;
 
index 5332f9f..0b7341c 100755 (executable)
@@ -86,6 +86,49 @@ static inline struct jadard *panel_to_jadard(struct drm_panel *panel)
        return container_of(panel, struct jadard, panel);
 }
 
+static int jadard_i2c_write(struct i2c_client *client, u8 reg, u8 val)
+{
+       struct i2c_msg msg;
+       u8 buf[2];
+       int ret;
+
+       buf[0] = reg;
+       buf[1] = val;
+       msg.addr = client->addr;
+       msg.flags = 0;
+       msg.buf = buf;
+       msg.len = 2;
+
+       ret = i2c_transfer(client->adapter, &msg, 1);
+       if (ret >= 0)
+               return 0;
+
+       return ret;
+}
+
+static int jadard_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
+{
+       struct i2c_msg msg[2];
+       u8 buf[2];
+       int ret;
+
+       buf[0] = reg;
+       msg[0].addr = client->addr;
+       msg[0].flags = 0;
+       msg[0].buf = buf;
+       msg[0].len = 1;
+       msg[1].addr = client->addr;
+       msg[1].flags = I2C_M_RD;
+       msg[1].buf = val;
+       msg[1].len = 1;
+       ret = i2c_transfer(client->adapter, msg, 2);
+
+       if (ret >= 0)
+               return 0;
+
+       return ret;
+}
+
 static int jadard_enable(struct drm_panel *panel)
 {
        struct device *dev = panel->dev;
@@ -468,13 +511,19 @@ static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id
        struct device_node *endpoint, *dsi_host_node;
        struct mipi_dsi_host *host;
        struct device *dev = &client->dev;
-
+       int ret = 0;
        struct mipi_dsi_device_info info = {
                .type = DSI_DRIVER_NAME,
                .channel = 1, //0,
                .node = NULL,
        };
 
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+               dev_warn(&client->dev,
+                        "I2C adapter doesn't support I2C_FUNC_SMBUS_BYTE\n");
+               return -EIO;
+       }
+
        jd_panel = devm_kzalloc(&client->dev, sizeof(struct jadard), GFP_KERNEL);
        if (!jd_panel )
                return -ENOMEM;
@@ -497,6 +546,11 @@ static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id
                return PTR_ERR(jd_panel->enable);
        }
 
+       /*use i2c read to detect whether the panel has connected */
+       ret = jadard_i2c_read(client, 0x00, &reg_value);
+       if (ret < 0)
+               return -ENODEV;
+
        endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
        if (!endpoint)
                return -ENODEV;