VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   30 Branches   50 Tags
author: andy.hu <andy.hu@starfivetech.com> 2023-09-14 11:18:51 +0000 committer: andy.hu <andy.hu@starfivetech.com> 2023-09-14 11:18:51 +0000 commit: bcf6f90f838aa5b98617f0faa6d2b0d90c9041b1 parent: 53d88a219a29f4a30f94f619985d15bbe03ac67a
Commit Summary:
Merge branch 'CR_7358_VF2_5.15_radxa_gsensor_shengyang.chen' into 'vf2-515-devel'
Diffstat:
7 files changed, 264 insertions, 66 deletions
diff --git a/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2.dtsi b/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2.dtsi
index 8ad3183d1358..35db289ec817 100755
--- a/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2.dtsi
+++ b/arch/riscv/boot/dts/starfive/jh7110-visionfive-v2.dtsi
@@ -455,10 +455,9 @@
 		reset-gpios = <&gpio 31 GPIO_ACTIVE_HIGH>;
 	};
 
-
-	panel_10inch@20 {
-		compatible ="panel_10inch";
-		reg = <0x20>;
+	panel_radxa@19 {
+		compatible ="starfive_jadard";
+		reg = <0x19>;
 		reset-gpio = <&gpio 23 0>;
 		enable-gpio = <&gpio 22 0>;
 
@@ -469,20 +468,6 @@
 		};
 	};
 
-        panel_radxa@19 {
-                compatible ="starfive_jadard";
-                reg = <0x19>;
-                reset-gpio = <&gpio 23 0>;
-                enable-gpio = <&gpio 22 0>;
-
-                port {
-                        panel_out2: endpoint {
-                                remote-endpoint = <&dsi2_output>;
-                                };
-                };
-        };
-
-
 };
 
 &i2c5 {
@@ -917,10 +902,7 @@
 				reg = <1>;
 				remote-endpoint = <&panel_out1>;
 			};
-			dsi2_output: endpoint@2 {
-				reg = <2>;
-				remote-endpoint = <&panel_out2>;
-			};
+
 		};
 
 		port@1{
diff --git a/arch/riscv/configs/starfive_visionfive2_defconfig b/arch/riscv/configs/starfive_visionfive2_defconfig
index cfa5c2b3cf0f..ef93c628aa89 100644
--- a/arch/riscv/configs/starfive_visionfive2_defconfig
+++ b/arch/riscv/configs/starfive_visionfive2_defconfig
@@ -337,6 +337,8 @@ CONFIG_RPMSG_VIRTIO=y
 CONFIG_SIFIVE_L2_FLUSH_START=0x40000000
 CONFIG_SIFIVE_L2_FLUSH_SIZE=0x400000000
 CONFIG_STARFIVE_PMU=y
+CONFIG_IIO=y
+CONFIG_IIO_ST_ACCEL_3AXIS=y
 CONFIG_PWM=y
 CONFIG_PWM_STARFIVE_PTC=y
 CONFIG_PHY_M31_DPHY_RX0=y
diff --git a/drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c b/drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
index 7006bfa99a79..7dd9cefd73f8 100755
--- a/drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
+++ b/drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
@@ -29,6 +29,15 @@
 #include <video/display_timing.h>
 #include <video/videomode.h>
 
+
+//accel sc7a20
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/common/st_sensors_i2c.h>
+#include <linux/iio/common/st_sensors.h>
+//#include "st_accel.h"
+
 #define DSI_DRIVER_NAME "starfive-dri"
 
 enum cmd_type {
@@ -79,6 +88,7 @@ struct jadard {
 	struct gpio_desc *reset;
 	struct gpio_desc *enable;
 	bool enable_initialized;
+	int choosemode;
 };
 
 static inline struct jadard *panel_to_jadard(struct drm_panel *panel)
@@ -140,38 +150,42 @@ static int jadard_enable(struct drm_panel *panel)
 	if (jadard->enable_initialized == true)
 		return 0;
 
-	for (i = 0; i < desc->num_init_cmds; i++) {
-		const struct jadard_init_cmd *cmd = &desc->init_cmds[i];
-
-		switch (cmd->type) {
-		case CMD_TYPE_DELAY:
-			msleep(cmd->data[0]);
-			err = 0;
-			break;
-		case CMD_TYPE_DCS:
-			err = mipi_dsi_dcs_write(dsi, cmd->data[0],
-						 cmd->len <= 1 ? NULL : &cmd->data[1],
-						 cmd->len - 1);
-			break;
-		default:
-			err = -EINVAL;
-		}
+	if(jadard->choosemode == 0) {//8inch
+
+		for (i = 0; i < desc->num_init_cmds; i++) {
+			const struct jadard_init_cmd *cmd = &desc->init_cmds[i];
+
+			switch (cmd->type) {
+			case CMD_TYPE_DELAY:
+				msleep(cmd->data[0]);
+				err = 0;
+				break;
+			case CMD_TYPE_DCS:
+				err = mipi_dsi_dcs_write(dsi, cmd->data[0],
+							 cmd->len <= 1 ? NULL : &cmd->data[1],
+							 cmd->len - 1);
+				break;
+			default:
+				err = -EINVAL;
+			}
+
+			if (err < 0) {
+				DRM_DEV_ERROR(dev, "failed to write CMD#0x%x\n", cmd->data[0]);
+				return err;
+			}
 
-		if (err < 0) {
-			DRM_DEV_ERROR(dev, "failed to write CMD#0x%x\n", cmd->data[0]);
-			return err;
 		}
 
-	}
+		err = mipi_dsi_dcs_exit_sleep_mode(dsi);
+		if (err < 0)
+			DRM_DEV_ERROR(dev, "failed to exit sleep mode ret = %d\n", err);
+		msleep(120);
 
-	err = mipi_dsi_dcs_exit_sleep_mode(dsi);
-	if (err < 0)
-		DRM_DEV_ERROR(dev, "failed to exit sleep mode ret = %d\n", err);
-	msleep(120);
+		err =  mipi_dsi_dcs_set_display_on(dsi);
+		if (err < 0)
+			DRM_DEV_ERROR(dev, "failed to set display on ret = %d\n", err);
+	}
 
-	err =  mipi_dsi_dcs_set_display_on(dsi);
-	if (err < 0)
-		DRM_DEV_ERROR(dev, "failed to set display on ret = %d\n", err);
 	jadard->enable_initialized = true ;
 
 	return 0;
@@ -182,15 +196,16 @@ static int jadard_disable(struct drm_panel *panel)
 	struct device *dev = panel->dev;
 	struct jadard *jadard = panel_to_jadard(panel);
 	int ret;
+	if(jadard->choosemode == 0) {//8inch
+		ret = mipi_dsi_dcs_set_display_off(jadard->dsi);
+		if (ret < 0)
+			DRM_DEV_ERROR(dev, "failed to set display off: %d\n", ret);
 
-	ret = mipi_dsi_dcs_set_display_off(jadard->dsi);
-	if (ret < 0)
-		DRM_DEV_ERROR(dev, "failed to set display off: %d\n", ret);
-
-	ret = mipi_dsi_dcs_enter_sleep_mode(jadard->dsi);
-	if (ret < 0)
-		DRM_DEV_ERROR(dev, "failed to enter sleep mode: %d\n", ret);
+		ret = mipi_dsi_dcs_enter_sleep_mode(jadard->dsi);
+		if (ret < 0)
+			DRM_DEV_ERROR(dev, "failed to enter sleep mode: %d\n", ret);
 
+	}
 	jadard->enable_initialized = false;
 
 	return 0;
@@ -463,7 +478,8 @@ static const struct jadard_init_cmd cz101b4001_init_cmds[] = {
 	_INIT_CMD_DELAY(120),
 };
 
-static const struct display_timing jadard_timing = {
+static const struct display_timing jadard_timing[] = {
+	{
 	.pixelclock = { 79200000, 79200000, 79200000 },
 	.hactive = { 800, 800, 800 },
 	.hfront_porch = {  356, 356, 356 },
@@ -474,9 +490,24 @@ static const struct display_timing jadard_timing = {
 	.vback_porch = { 20, 20, 20 },
 	.vsync_len = { 9, 9, 9 },
 	.flags = DISPLAY_FLAGS_DE_LOW,
+	},
+	{
+	 .pixelclock = { 148500000, 148500000, 148500000 },
+	 .hactive = { 1200, 1200, 1200 },
+	 .hfront_porch = {	246, 246, 246 },
+	 .hback_porch = { 5, 5, 5 },
+	 .hsync_len = { 5, 5, 5 },
+	 .vactive = { 1920, 1920, 1920 },
+	 .vfront_porch = { 84, 84, 84 },
+	 .vback_porch = { 20, 20, 20 },
+	 .vsync_len = { 16, 16, 16 },
+	 .flags = DISPLAY_FLAGS_DE_LOW,
+	},
+	{}
 };
 
-static const struct jadard_panel_desc cz101b4001_desc = {
+static const struct jadard_panel_desc cz101b4001_desc[] = {
+	{
 	.mode = {
 		.clock		= 79200,
 
@@ -498,8 +529,36 @@ static const struct jadard_panel_desc cz101b4001_desc = {
 	.format = MIPI_DSI_FMT_RGB888,
 	.init_cmds = cz101b4001_init_cmds,
 	.num_init_cmds = ARRAY_SIZE(cz101b4001_init_cmds),
-	.timings = &jadard_timing,
+	.timings = &jadard_timing[0],
 	.num_timings = 1,
+	},
+	{
+	.mode = {
+		 .clock 	 = 148500,
+
+		 .hdisplay	 = 1200,
+		 .hsync_start	 = 1200 + 246,
+		 .hsync_end  = 1200 + 246 + 5,
+		 .htotal	 = 1200 + 246 + 5 + 5,
+
+		 .vdisplay	 = 1920,
+		 .vsync_start	 = 1920 + 84,
+		 .vsync_end  = 1920 + 84 + 20,
+		 .vtotal	 = 1920 + 84+ 20 + 16,
+
+		 .width_mm	 = 62,
+		 .height_mm  = 110,
+		 .type		 = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
+	 },
+	 .lanes = 4,
+	 .format = MIPI_DSI_FMT_RGB888,
+	 .init_cmds = cz101b4001_init_cmds,//no
+	 .num_init_cmds = ARRAY_SIZE(cz101b4001_init_cmds),//no
+	 //.timings = &starfive_timing,
+	 .timings = &jadard_timing[1],
+	 .num_timings = 1,
+	},
+	{}
 };
 
 static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id)
@@ -511,10 +570,16 @@ 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;
+
+	const struct st_sensor_settings *settings;
+	struct st_sensor_data *adata;
+	struct iio_dev *indio_dev;
+	int err; u8 mode = 1;int ret = 0;
+
+
 	struct mipi_dsi_device_info info = {
 		.type = DSI_DRIVER_NAME,
-		.channel = 2, //0,
+		.channel = 1, //0,
 		.node = NULL,
 	};
 
@@ -527,7 +592,8 @@ static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id
 	jd_panel = devm_kzalloc(&client->dev, sizeof(struct jadard), GFP_KERNEL);
 	if (!jd_panel )
 		return -ENOMEM;
-	desc = of_device_get_match_data(dev);
+
+	desc = &cz101b4001_desc[0];//use 8inch parameter to pre config dsi and phy
 
 	jd_panel ->client = client;
 	i2c_set_clientdata(client, jd_panel);
@@ -549,8 +615,12 @@ static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id
 	/*use i2c read to detect whether the panel has connected */
 	ret = jadard_i2c_read(client, 0x00, &reg_value);
 	if (ret < 0)
+	{
+		dev_info(dev, "no 4lane connect!!!!\n");
 		return -ENODEV;
-
+	}
+	dev_info(dev, "==4lane panel!!! maybe 8inch==\n");
+	jd_panel->choosemode = 0;
 	endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
 	if (!endpoint)
 		return -ENODEV;
@@ -587,6 +657,65 @@ static int panel_probe(struct i2c_client *client, const struct i2c_device_id *id
 
 	mipi_dsi_set_drvdata(jd_panel->dsi, jd_panel);
 
+	//radxa 10inch connect detect
+	gpiod_direction_output(jd_panel->enable, 0);
+	gpiod_set_value(jd_panel->enable, 1);
+	mdelay(100);
+
+	gpiod_direction_output(jd_panel->reset, 0);
+	mdelay(100);
+	gpiod_set_value(jd_panel->reset, 1);
+	mdelay(100);
+	gpiod_set_value(jd_panel->reset, 0);
+	mdelay(100);
+	gpiod_set_value(jd_panel->reset, 1);
+	mdelay(150);
+
+	jd_panel->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+	if(jd_panel->dsi)
+	{
+		//use this command to detect the connected status
+		err = mipi_dsi_dcs_get_power_mode(jd_panel->dsi, &mode);
+		dev_info(dev,"dsi command return %d, mode %d\n", err, mode);
+		if(err == -EIO){
+			dev_info(dev, "raxda 10 inch detected\n");
+			jd_panel->choosemode = 1;
+			desc = &cz101b4001_desc[1];//choose 1200x1920 mode
+			jd_panel->desc = desc;
+			jd_panel->dsi->hs_rate = 980000000;//after this, dsi and phy will config again
+		}else{
+			dev_info(dev, "4lane is radxa 8inch\n");
+			jd_panel->dsi->hs_rate = 490000000;
+		}
+	}
+	jd_panel->dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	//acceleroter SC7A20
+	dev_info(dev, "probe sc7a20 begin\n");
+	settings = st_accel_get_settings("sc7a20");
+	if (!settings) {
+		dev_err(&client->dev, "device name %s not recognized.\n",
+			client->name);
+		return -ENODEV;
+	}
+
+	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	adata = iio_priv(indio_dev);
+	adata->sensor_settings = (struct st_sensor_settings *)settings;
+
+	ret = st_sensors_i2c_configure(indio_dev, client);
+	if (ret < 0)
+		return ret;
+
+	ret = st_sensors_power_enable(indio_dev);
+	if (ret)
+		return ret;
+	st_accel_common_probe(indio_dev);
+	dev_info(dev, "probe sc7a20 end\n");
+
 	return 0;
 error:
 	of_node_put(endpoint);
@@ -642,7 +771,7 @@ static int jadard_dsi_probe(struct mipi_dsi_device *dsi)
 	dsi->mode_flags = MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE ;
 	dsi->format = MIPI_DSI_FMT_RGB888;
 	dsi->lanes = 4;
-	dsi->channel = 2;
+	dsi->channel = 1;
 	dsi->hs_rate = 490000000;
 
 	ret = mipi_dsi_attach(dsi);
diff --git a/drivers/gpu/drm/verisilicon/starfive_drm_dsi.c b/drivers/gpu/drm/verisilicon/starfive_drm_dsi.c
index 0efabb667129..4d0a1f62645d 100644
--- a/drivers/gpu/drm/verisilicon/starfive_drm_dsi.c
+++ b/drivers/gpu/drm/verisilicon/starfive_drm_dsi.c
@@ -748,17 +748,15 @@ static int cdns_dsi_mode2cfg(struct cdns_dsi *dsi,
 					 bpp, DSI_HFP_FRAME_OVERHEAD);
 	//dpi to dsi transfer can not match , reconfig those parms for waveshare
 	//for taobao old mipi panel .should change here : hsa 36 , hbp 108, hfp 288
-	if (output->dev->channel == 0) {//seeed
+	if (mode->vdisplay == 480) {//seeed
 		dsi_cfg->hsa = 117-DSI_HSA_FRAME_OVERHEAD;
 		dsi_cfg->hbp = 115-DSI_HBP_FRAME_OVERHEAD;
 		dsi_cfg->hfp = 209-DSI_HFP_FRAME_OVERHEAD;
-	} else if (output->dev->channel == 2){//raxda 8 inch config
+	} else if (mode->vdisplay == 1280) {//8inch
 		dsi_cfg->hsa = 45-DSI_HSA_FRAME_OVERHEAD;
 		dsi_cfg->hbp = 134-DSI_HBP_FRAME_OVERHEAD;
 		dsi_cfg->hfp = 356-DSI_HFP_FRAME_OVERHEAD;
-
-	}
-	else if (output->dev->channel == 1){//raxda 10 inch config
+	} else if (mode->vdisplay == 1920) {//10inch
 		dsi_cfg->hsa = 405-DSI_HSA_FRAME_OVERHEAD;
 		dsi_cfg->hbp = 403-DSI_HBP_FRAME_OVERHEAD;
 		dsi_cfg->hfp = 396-DSI_HFP_FRAME_OVERHEAD;
@@ -843,11 +841,11 @@ static int cdns_dsi_check_conf(struct cdns_dsi *dsi,
 
 	//phy_cfg->hs_clk_rate = output->phy_opts.mipi_dphy.hs_clk_rate;
 
-	if (output->dev->channel == 0) {
+	if (mode->vdisplay == 480) {
 		phy_cfg->hs_clk_rate = 750000000;//seeed
-	} else if (output->dev->channel == 2){
+	} else if (mode->vdisplay == 1280) {
 		phy_cfg->hs_clk_rate = 490000000;//8 inch
-	} else if (output->dev->channel == 1){
+	} else if (mode->vdisplay == 1920) {
 		phy_cfg->hs_clk_rate = 980000000;//10 inch
 	}
 
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index 8750dea56fcb..b4d570dfa8e2 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -37,6 +37,8 @@ enum st_accel_type {
 	LIS2DE12,
 	LIS2HH12,
 	ST_ACCEL_MAX,
+	LIS302DL,
+	SC7A20,
 };
 
 #define H3LIS331DL_ACCEL_DEV_NAME	"h3lis331dl_accel"
@@ -61,6 +63,9 @@ enum st_accel_type {
 #define LIS3DE_ACCEL_DEV_NAME		"lis3de"
 #define LIS2DE12_ACCEL_DEV_NAME		"lis2de12"
 #define LIS2HH12_ACCEL_DEV_NAME		"lis2hh12"
+#define LIS302DL_ACCEL_DEV_NAME		"lis302dl"
+#define SC7A20_ACCEL_DEV_NAME		"sc7a20"
+
 
 #ifdef CONFIG_IIO_BUFFER
 int st_accel_allocate_ring(struct iio_dev *indio_dev);
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index f1e6ec380667..5d82faf671f5 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -1087,6 +1087,89 @@ static const struct st_sensor_settings st_accel_sensors_settings[] = {
 		.multi_read_bit = true,
 		.bootime = 2,
 	},
+	{
+		/*
+		 * Not an ST part. Register-compatible with the LIS2DH, even
+		 * though the WAI value is different.
+		 */
+		.wai = 0x11,
+		.wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
+		.sensors_supported = {
+			[0] = SC7A20_ACCEL_DEV_NAME,
+		},
+		.ch = (struct iio_chan_spec *)st_accel_12bit_channels,
+		.odr = {
+			.addr = 0x20,
+			.mask = 0xf0,
+			.odr_avl = {
+				{ .hz = 1, .value = 0x01, },
+				{ .hz = 10, .value = 0x02, },
+				{ .hz = 25, .value = 0x03, },
+				{ .hz = 50, .value = 0x04, },
+				{ .hz = 100, .value = 0x05, },
+				{ .hz = 200, .value = 0x06, },
+				{ .hz = 400, .value = 0x07, },
+				{ .hz = 1600, .value = 0x08, },
+			},
+		},
+		.pw = {
+			.addr = 0x20,
+			.mask = 0xf0,
+			.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
+		},
+		.enable_axis = {
+			.addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
+			.mask = ST_SENSORS_DEFAULT_AXIS_MASK,
+		},
+		.fs = {
+			.addr = 0x23,
+			.mask = 0x30,
+			.fs_avl = {
+				[0] = {
+					.num = ST_ACCEL_FS_AVL_2G,
+					.value = 0x00,
+					.gain = IIO_G_TO_M_S_2(1000),
+				},
+				[1] = {
+					.num = ST_ACCEL_FS_AVL_4G,
+					.value = 0x01,
+					.gain = IIO_G_TO_M_S_2(2000),
+				},
+				[2] = {
+					.num = ST_ACCEL_FS_AVL_8G,
+					.value = 0x02,
+					.gain = IIO_G_TO_M_S_2(4000),
+				},
+				[3] = {
+					.num = ST_ACCEL_FS_AVL_16G,
+					.value = 0x03,
+					.gain = IIO_G_TO_M_S_2(12000),
+				},
+			},
+		},
+		.bdu = {
+			.addr = 0x23,
+			.mask = 0x80,
+		},
+		.drdy_irq = {
+			.int1 = {
+				.addr = 0x22,
+				.mask = 0x10,
+			},
+			.addr_ihl = 0x25,
+			.mask_ihl = 0x02,
+			.stat_drdy = {
+				.addr = ST_SENSORS_DEFAULT_STAT_ADDR,
+				.mask = 0x07,
+			},
+		},
+		.sim = {
+			.addr = 0x23,
+			.value = BIT(0),
+		},
+		.multi_read_bit = true,
+		.bootime = 2,
+	},
 };
 
 /* Default accel DRDY is available on INT1 pin */
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index f711756e41e3..966e420c692d 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -107,6 +107,14 @@ static const struct of_device_id st_accel_of_match[] = {
 		.compatible = "st,lis2hh12",
 		.data = LIS2HH12_ACCEL_DEV_NAME,
 	},
+	{
+		.compatible = "st,lis302dl",
+		.data = LIS302DL_ACCEL_DEV_NAME,
+	},
+	{
+		.compatible = "silan,sc7a20",
+		.data = SC7A20_ACCEL_DEV_NAME,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, st_accel_of_match);
@@ -142,6 +150,8 @@ static const struct i2c_device_id st_accel_id_table[] = {
 	{ LIS3DE_ACCEL_DEV_NAME },
 	{ LIS2DE12_ACCEL_DEV_NAME },
 	{ LIS2HH12_ACCEL_DEV_NAME },
+	{ LIS302DL_ACCEL_DEV_NAME },
+	{ SC7A20_ACCEL_DEV_NAME },
 	{},
 };
 MODULE_DEVICE_TABLE(i2c, st_accel_id_table);