Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit bbe8ec88 authored by LuK1337's avatar LuK1337 Committed by hmtheboy154
Browse files

drivers: oplus_sensor_devinfo: Add FW backwards compatibility

Change-Id: Ieb26e6bff2d79702f11a8d38c3f651c909e0bb9a
parent 97fe8e5a
Loading
Loading
Loading
Loading
+36 −31
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ extern int pad_als_data_init(void);
extern void pad_als_data_clean(void);

struct sensor_info * g_chip = NULL;
struct sensor_info_old * g_chip_old = NULL;

struct proc_dir_entry *sensor_proc_dir = NULL;
static struct oplus_als_cali_data *gdata = NULL;
@@ -32,11 +33,6 @@ static char* als_rear_feature[] = {
};


__attribute__((weak)) void oplus_device_dir_redirect(struct sensor_info * chip)
{
	pr_info("%s oplus_device_dir_redirect \n", __func__);
};

__attribute__((weak)) unsigned int get_serialID(void)
{
	return 0;
@@ -676,7 +672,6 @@ static void parse_each_virtual_sensor_dts(struct sensor_algorithm *algo, struct
static void oplus_sensor_parse_dts(struct platform_device *pdev)
{
	struct device_node *node = pdev->dev.of_node;
	struct sensor_info * chip = platform_get_drvdata(pdev);
	int rc = 0;
	int value = 0;
	bool is_virtual_sensor = false;
@@ -705,7 +700,11 @@ static void oplus_sensor_parse_dts(struct platform_device *pdev)
		}

		if (!is_virtual_sensor) {
			chip->s_vector[sensor_type].sensor_id = sensor_type;
			if (g_chip) {
				g_chip->s_vector[sensor_type].sensor_id = sensor_type;
			} else if (g_chip_old) {
				g_chip_old->s_vector[sensor_type].sensor_id = sensor_type;
			}
			rc = of_property_read_u32(ch_node, "sensor-index", &value);

			if (rc || value >= SOURCE_NUM) {
@@ -715,22 +714,21 @@ static void oplus_sensor_parse_dts(struct platform_device *pdev)
				sensor_index = value;
			}

			hw = &chip->s_vector[sensor_type].hw[sensor_index];
			if (g_chip) {
				hw = &g_chip->s_vector[sensor_type].hw[sensor_index];
			} else if (g_chip_old) {
				hw = &g_chip_old->s_vector[sensor_type].hw[sensor_index];
			}
			parse_physical_sensor_common_dts(hw, ch_node);
			SENSOR_DEVINFO_DEBUG("chip->s_vector[%d].hw[%d] : sensor-name %d, \
					bus-number %d, sensor-direction %d, \
					irq-number %d\n",
				sensor_type, sensor_index,
				chip->s_vector[sensor_type].hw[sensor_index].sensor_name,
				chip->s_vector[sensor_type].hw[sensor_index].bus_number,
				chip->s_vector[sensor_type].hw[sensor_index].direction,
				chip->s_vector[sensor_type].hw[sensor_index].irq_number);
			parse_each_physical_sensor_dts(hw, ch_node);
		} else {
			chip->a_vector[sensor_type].sensor_id = sensor_type;
			SENSOR_DEVINFO_DEBUG("chip->a_vector[%d].sensor_id : sensor_type %d",
				sensor_type, chip->a_vector[sensor_type].sensor_id, sensor_type);
			algo = &chip->a_vector[sensor_type];
			if (g_chip) {
				g_chip->a_vector[sensor_type].sensor_id = sensor_type;
				algo = &g_chip->a_vector[sensor_type];
			} else if (g_chip_old) {
				g_chip_old->a_vector[sensor_type].sensor_id = sensor_type;
				algo = &g_chip_old->a_vector[sensor_type];
			}
			parse_each_virtual_sensor_dts(algo, ch_node);
		}
	}/*for_each_child_of_node */
@@ -743,8 +741,6 @@ static void oplus_sensor_parse_dts(struct platform_device *pdev)
		gdata->row_coe = value;
	}
	rc = of_property_read_u32(node, "ldo_enable", &g_ldo_enable);

	oplus_device_dir_redirect(chip);
}

static ssize_t als_type_read_proc(struct file *file, char __user *buf,
@@ -753,12 +749,14 @@ static ssize_t als_type_read_proc(struct file *file, char __user *buf,
	char page[256] = {0};
	int len = 0;

	if (!g_chip) {
	if (g_chip) {
		len = sprintf(page, "%d", g_chip->s_vector[OPLUS_LIGHT].hw[0].feature.feature[0]);
	} else if (g_chip_old) {
		len = sprintf(page, "%d", g_chip_old->s_vector[OPLUS_LIGHT].hw[0].feature.feature[0]);
	} else {
		return -ENOMEM;
	}

	len = sprintf(page, "%d", g_chip->s_vector[OPLUS_LIGHT].hw[0].feature.feature[0]);

	if (len > *off) {
		len -= *off;
	} else {
@@ -1360,6 +1358,7 @@ static int sensor_ldo_init(struct device *dev)
static int oplus_devinfo_probe(struct platform_device *pdev)
{
	struct sensor_info * chip = NULL;
	struct sensor_info_old * chip_old = NULL;
	size_t smem_size = 0;
	void *smem_addr = NULL;
	int rc = 0;
@@ -1387,9 +1386,16 @@ static int oplus_devinfo_probe(struct platform_device *pdev)
		return -EPROBE_DEFER; /*return -EPROBE_DEFER if smem not ready*/
	}

	if (smem_size == sizeof(struct sensor_info)) {
		chip = (struct sensor_info *)(smem_addr);

		memset(chip, 0, sizeof(struct sensor_info));
	} else if (smem_size == sizeof(struct sensor_info_old)) {
		chip_old = (struct sensor_info_old *)(smem_addr);
		memset(chip_old, 0, sizeof(struct sensor_info_old));
	} else {
		pr_err("unsupported SMEM_SENSOR size: %d\n", smem_size);
		return -EFAULT;
	}

	if (gdata) {
		printk("%s:just can be call one time\n", __func__);
@@ -1406,12 +1412,11 @@ static int oplus_devinfo_probe(struct platform_device *pdev)

	gdata = data;

	platform_set_drvdata(pdev, chip);
	g_chip = chip;
	g_chip_old = chip_old;

	oplus_sensor_parse_dts(pdev);

	g_chip = chip;

	pr_info("%s success\n", __func__);

	sensor_proc_dir = proc_mkdir("sensor", NULL);
+10 −0
Original line number Diff line number Diff line
@@ -132,6 +132,10 @@ struct sensor_vector {
    struct sensor_hw hw[SOURCE_NUM];
};

struct sensor_vector_old {
    int sensor_id;
    struct sensor_hw hw[SOURCE_NUM - 1];
};

struct sensor_algorithm {
    int sensor_id;
@@ -145,6 +149,12 @@ struct sensor_info {
    struct sensor_algorithm a_vector[SENSOR_ALGO_NUM];
};

struct sensor_info_old {
    int magic_num;
    struct sensor_vector_old s_vector[SENSORS_NUM];
    struct sensor_algorithm a_vector[SENSOR_ALGO_NUM];
};

struct oplus_als_cali_data {
    int red_max_lux;
    int green_max_lux;