Example #1
0
static ssize_t rmi_f09_host_test_enable_store(struct device *dev,
					  struct device_attribute *attr,
					  const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;
	unsigned int new_value;
	int result;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	if (sscanf(buf, "%u", &new_value) != 1) {
		dev_err(dev, "hostTestEnable has an invalid length.\n");
		return -EINVAL;
	}

	if (new_value > 1) {
		dev_err(dev, "Invalid hostTestEnable bit %s.\n", buf);
		return -EINVAL;
		}
	data->query.host_test_enable = new_value;
	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.query_base_addr,
		data->query.host_test_enable);
	if (result < 0) {
		dev_err(dev, "%s: Could not write hostTestEnable to %#06x\n",
				__func__, fn_dev->fd.query_base_addr);
		return result;
	}

	return count;

}
Example #2
0
static ssize_t rmi_f09_run_bist_store(struct device *dev,
				      struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;
	unsigned int new_value;
	int result;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	if (sscanf(buf, "%u", &new_value) != 1) {
		dev_err(dev, "run_bist_store has an invalid len.\n");
		return -EINVAL;
	}

	if (new_value > 1) {
		dev_err(dev, "%s: Invalid run_bist bit %s.", __func__, buf);
		return -EINVAL;
	}
	data->cmd.run_bist = new_value;
	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.command_base_addr,
		data->cmd.run_bist);
	if (result < 0) {
		dev_err(dev, "Could not write run_bist_store to %#06x\n",
				fn_dev->fd.command_base_addr);
		return result;
	}

	return count;

}
Example #3
0
static ssize_t rmi_f09_test_number_control_store(struct device *dev,
				      struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;
	unsigned int new_value;
	int result;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	if (sscanf(buf, "%u", &new_value) != 1) {
		dev_err(dev, "test_number_control_store has aninvalid len.\n");
		return -EINVAL;
	}

	if (new_value > 1) {
		dev_err(dev, "Invalid test_number_control bit %s.", buf);
		return -EINVAL;
	}
	data->data.test_number_control = new_value;
	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.control_base_addr,
		data->data.test_number_control);
	if (result < 0) {
		dev_err(dev, "Could not write test_number_control_store to %#06x\n",
				fn_dev->fd.data_base_addr);
		return result;
	}

	return count;
}
Example #4
0
static ssize_t f17_rezero_store(struct device *dev,
					 struct device_attribute *attr,
					 const char *buf,
					 size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_f17_device_data *data;
	unsigned int new_value;
	int len;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	len = sscanf(buf, "%u", &new_value);
	if (new_value != 0 && new_value != 1) {
		dev_err(dev,
			"%s: Error - rezero is not a valid value 0x%x.\n",
			__func__, new_value);
		return -EINVAL;
	}
	data->commands.rezero = new_value;
	len = rmi_write(fn_dev->rmi_dev, fn_dev->fd.command_base_addr,
		data->commands.rezero);

	if (len < 0) {
		dev_err(dev, "%s : Could not write rezero to 0x%x\n",
				__func__, fn_dev->fd.command_base_addr);
		return -EINVAL;
	}
	return count;
}
Example #5
0
static ssize_t rmi_fn_21_rezero_store(struct device *dev,
				   struct device_attribute *attr,
				   const char *buf, size_t count) {
	unsigned long val;
	int error, result;
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_21_data *f21;
	struct rmi_driver *driver;
	u8 command;

	fn_dev = to_rmi_function_dev(dev);
	f21 = fn_dev->data;
	driver = fn_dev->rmi_dev->driver;

	/* need to convert the string data to an actual value */
	error = strict_strtoul(buf, 10, &val);
	if (error)
		return error;
	/* Do nothing if not set to 1. This prevents accidental commands. */
	if (val != 1)
		return count;

	command = F21_REZERO_CMD;

	/* Write the command to the command register */
	result = rmi_write_block(fn_dev->rmi_dev, fn_dev->fd.command_base_addr,
						&command, 1);
	if (result < 0) {
		dev_err(dev, "%s : Could not write command to 0x%x\n",
				__func__, fn_dev->fd.command_base_addr);
		return result;
	}
	return count;
}
Example #6
0
static ssize_t rmi_fn_34_configid_show(struct device *dev,
                                        struct device_attribute *attr,
                                        char *buf)
{
        struct rmi_function_dev *fn_dev;
        struct rmi_fn_34_data *instance_data;
        u16 control_base_addr;
        u16 query_base_addr;
        union f34_query_regs f34_queries;
        int retval = 0;
        u8 config_control[4];
        u32 configid;

        fn_dev = to_rmi_function_dev(dev);
        instance_data = fn_dev->data;

        control_base_addr = fn_dev->fd.control_base_addr;
        query_base_addr = fn_dev->fd.query_base_addr;

        if (instance_data->inflashprogmode)
                dev_info(dev, "Device is  in flash programming mode.\n");

        /* Get f34 queries */
        retval = rmi_read_block(fn_dev->rmi_dev, query_base_addr+2,
                        f34_queries.regs,
                        ARRAY_SIZE(f34_queries.regs));
        if (retval < 0) {
                dev_err(&fn_dev->rmi_dev->dev,
                        "Failed to read F34 queries (code %d).\n", retval);
                return retval;
        }

        if (!f34_queries.has_config_id) {
                dev_err(dev, "Does not contain config id registers.\n");
                return -EINVAL;
        }


        retval = rmi_read_block(fn_dev->rmi_dev, control_base_addr,
                        config_control,
                        ARRAY_SIZE(config_control));

        if (retval < 0) {
                dev_err(&fn_dev->rmi_dev->dev,
                        "Failed to read F34 queries (code %d).\n", retval);
                return retval;
        }

        configid = (u32)config_control[0] << 24
                        | (u32)config_control[1] << 16
                        | (u32)config_control[2] << 8
                        | (u32)config_control[3] << 0;

        return snprintf(buf, PAGE_SIZE, "%08X\n", configid);
}
Example #7
0
static ssize_t rmi_f09_result_register_count_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	return snprintf(buf, PAGE_SIZE, "%u\n",
			data->query.result_register_count);
}
Example #8
0
static ssize_t rmi_f09_test_number_control_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	return snprintf(buf, PAGE_SIZE, "%u\n",
			data->data.test_number_control);
}
Example #9
0
static ssize_t rmi_f09_run_bist_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	return snprintf(buf, PAGE_SIZE, "%u\n",
			data->cmd.run_bist);
}
Example #10
0
static ssize_t rmi_f09_internal_limits_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	return snprintf(buf, PAGE_SIZE, "%u\n",
			data->query.internal_limits);
}
Example #11
0
static ssize_t rmi_fn_34_bootloaderid_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->bootloaderid);
}
Example #12
0
static ssize_t rmi_f09_status_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *instance_data;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	return snprintf(buf, PAGE_SIZE, "%d\n", instance_data->status);
}
Example #13
0
static ssize_t rmi_f09_control_test2_store(struct device *dev,
				      struct device_attribute *attr,
					const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;
	unsigned int new_low, new_high, new_diff;
	int result;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	if (sscanf(buf, "%u %u %u", &new_low, &new_high, &new_diff) != 3) {
		dev_err(dev, "f09_control_test1_store has an invalid len.\n");
		return -EINVAL;
	}

	// Should we take a look at rmi spec?
	/*if (new_low < 0 || new_low > 1 || new_high < 0 || new_high > 1 ||
			new_diff < 0 || new_diff > 1) {
		dev_err(dev, "Invalid f09_control_test2_diff bit %s.", buf);
		return -EINVAL;
	}*/
	data->control.test2_limit_low = new_low;
	data->control.test2_limit_high = new_high;
	data->control.test2_limit_diff = new_diff;
	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.control_base_addr,
		data->control.test2_limit_low);
	if (result < 0) {
		dev_err(dev, "Could not write f09_control_test2_limit_low to %#06x\n",
				fn_dev->fd.control_base_addr);
		return result;
	}

	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.control_base_addr,
		data->control.test2_limit_high);
	if (result < 0) {
		dev_err(dev, "Could not write f09_control_test2_limit_high to %#06x\n",
				fn_dev->fd.control_base_addr);
		return result;
	}

	result = rmi_write(fn_dev->rmi_dev, fn_dev->fd.control_base_addr,
		data->control.test2_limit_diff);
	if (result < 0) {
		dev_err(dev, "%s : Could not write f09_control_test2_limit_diff to 0x%x\n",
				__func__, fn_dev->fd.control_base_addr);
		return result;
	}

	return count;

}
Example #14
0
static ssize_t f17_rezero_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_f17_device_data *f17;

	fn_dev = to_rmi_function_dev(dev);
	f17 = fn_dev->data;

	return snprintf(buf, PAGE_SIZE, "%u\n",
			f17->commands.rezero);

}
Example #15
0
static ssize_t rmi_fn_34_status_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	instance_data->status = 0;

	return 0;
}
Example #16
0
static ssize_t rmi_f09_control_test2_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *data;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;
	return snprintf(buf, PAGE_SIZE, "%u %u %u\n",
			data->control.test2_limit_low,
			data->control.test2_limit_high,
			data->control.test2_limit_diff);
}
Example #17
0
static ssize_t rmi_f09_status_store(struct device *dev,
				      struct device_attribute *attr,
				const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_09_data *instance_data;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	/* any write to status resets 1 */
	instance_data->status = 0;

	return 0;
}
Example #18
0
static ssize_t rmi_fn_34_sensorid_pullupmask_store(struct device *dev,
                                        struct device_attribute *attr,
                                        const char *buf,
                                        size_t count)
{
        int error;
        unsigned long val;
        u8 data[2];
        struct rmi_function_dev *fn_dev;
        struct rmi_fn_34_data *instance_data;
        u16 data_base_addr;
        u16 pullup_mask;

        fn_dev = to_rmi_function_dev(dev);
        instance_data = fn_dev->data;
        data_base_addr = fn_dev->fd.data_base_addr;

        if (!instance_data->inflashprogmode) {
                dev_err(dev, "Cannot set mask to sensor - not in flash programming mode.\n");
                return -EINVAL;
        }

        /* need to convert the string data to an actual value */
        error = strict_strtoul(buf, 10, &val);

        if (error)
                return error;

        pullup_mask = val;

        /* Write the Block Number data back to the first two Block
         * Data registers (F34_Flash_Data_0 and F34_Flash_Data_1). */
        hstoba(data, (u16)val);

        error = rmi_write_block(fn_dev->rmi_dev, data_base_addr + 2,
                                data, ARRAY_SIZE(data));

        if (error < 0) {
                dev_err(dev, "Could not write snesor id pin mask%u to %#06x.\n",
                      pullup_mask, data_base_addr);
                return error;
        }

        return count;
}
Example #19
0
static ssize_t rmi_fn_34_data_write(struct file *data_file,
				struct kobject *kobj,
				struct bin_attribute *attributes,
				char *buf,
				loff_t pos,
				size_t count)
{
	struct device *dev = container_of(kobj, struct device, kobj);
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	u16 data_base_addr;
	int error;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	data_base_addr = fn_dev->fd.data_base_addr;

	/* Write the data from buf to flash. The app layer will be
	 * blocked at writing to the sysfs file.  When we return the
	 * count (or error if we fail) the app will resume. */

	if (count != instance_data->blocksize) {
		dev_err(dev, "Incorrect F34 block size %d. Expected size %d.\n",
			count, instance_data->blocksize);
		return -EINVAL;
	}

	/* Write the data block - only if the count is non-zero  */
	if (count) {
		error = rmi_write_block(fn_dev->rmi_dev,
				data_base_addr + BLK_NUM_OFF,
				(u8 *)buf, count);

		if (error < 0) {
			dev_err(dev, "%s : Could not write block data to 0x%x\n",
				__func__, data_base_addr + BLK_NUM_OFF);
			return error;
		}
	}

	return count;
}
Example #20
0
/* Data */
static ssize_t rmi_fn_21_force_show(struct device *dev,
					struct device_attribute *attr,
					char *buf) {
	struct rmi_function_dev *fn_dev;
	struct FUNCTION_DATA *data;
	int reg_length;
	int result, size = 0;
	char *temp;
	int i;

	fn_dev = to_rmi_function_dev(dev);
	data = fn_dev->data;

	/* Read current regtype values */
	reg_length = data->query.max_force_sensor_count;
	result = rmi_read_block(fn_dev->rmi_dev, data->data.reg_0__1.address,
			data->data.reg_0__1.force_hi_lo,
			2 * reg_length * sizeof(u8));

	if (result < 0) {
		dev_err(dev, "Could not read regtype at %#06x. Data may be outdated.",
					data->data.reg_0__1.address);
	}
	temp = buf;
	for (i = 0; i < reg_length; i++) {
		result = snprintf(temp, PAGE_SIZE - size, "%d ",
			data->data.reg_0__1.force_hi_lo[i] * (2 << 3)
			+ data->data.reg_0__1.force_hi_lo[i + reg_length]);
		if (result < 0) {
			dev_err(dev, "%s : Could not write output.", __func__);
			return result;
		}
		size += result;
		temp += result;
	}
	result = snprintf(temp, PAGE_SIZE - size, "\n");
	if (result < 0) {
			dev_err(dev, "%s : Could not write output.", __func__);
			return result;
	}
	return size + result;
}
Example #21
0
static ssize_t rmi_fn_34_status_show(struct device *dev,
				struct device_attribute *attr,
				char *buf)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	int retval;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	mutex_lock(&instance_data->attn_mutex);
	retval = f34_read_status(fn_dev);
	mutex_unlock(&instance_data->attn_mutex);

	if (retval < 0)
		return retval;

	return snprintf(buf, PAGE_SIZE, "%u\n", instance_data->status);
}
Example #22
0
static ssize_t rmi_fn_34_bootloaderid_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf,
					size_t count)
{
	int error;
	unsigned long val;
	u8 data[2];
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	u16 data_base_addr;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	/* need to convert the string data to an actual value */
	error = strict_strtoul(buf, 10, &val);

	if (error)
		return error;

	instance_data->bootloaderid = val;

	/* Write the Bootloader ID key data back to the first two Block
	 * Data registers (F34_Flash_Data2.0 and F34_Flash_Data2.1). */
	hstoba(data, (u16)val);
	data_base_addr = fn_dev->fd.data_base_addr;

	error = rmi_write_block(fn_dev->rmi_dev,
				data_base_addr + BLK_NUM_OFF,
				data,
				ARRAY_SIZE(data));

	if (error < 0) {
		dev_err(dev, "%s : Could not write bootloader id to 0x%x\n",
		       __func__, data_base_addr + BLK_NUM_OFF);
		return error;
	}

	return count;
}
Example #23
0
static ssize_t rmi_fn_34_blocknum_store(struct device *dev,
					struct device_attribute *attr,
					const char *buf,
					size_t count)
{
	int error;
	unsigned long val;
	u8 data[2];
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	u16 data_base_addr;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;
	data_base_addr = fn_dev->fd.data_base_addr;

	/* need to convert the string data to an actual value */
	error = strict_strtoul(buf, 10, &val);

	if (error)
		return error;

	instance_data->blocknum = val;

	/* Write the Block Number data back to the first two Block
	 * Data registers (F34_Flash_Data_0 and F34_Flash_Data_1). */
	hstoba(data, (u16)val);

	error = rmi_write_block(fn_dev->rmi_dev, data_base_addr,
				data, ARRAY_SIZE(data));

	if (error < 0) {
		dev_err(dev, "Could not write block number %u to %#06x.\n",
		       instance_data->blocknum, data_base_addr);
		return error;
	}

	return count;
}
Example #24
0
static ssize_t rmi_fn_34_data_read(struct file *data_file,
				struct kobject *kobj,
				struct bin_attribute *attributes,
				char *buf,
				loff_t pos,
				size_t count)
{
	struct device *dev = container_of(kobj, struct device, kobj);
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	u16 data_base_addr;
	int error;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;

	data_base_addr = fn_dev->fd.data_base_addr;

	if (count != instance_data->blocksize) {
		dev_err(dev, "Incorrect F34 block size %d. Expected size %d.\n",
				count, instance_data->blocksize);
		return -EINVAL;
	}

	/* Read the data from flash into buf.  The app layer will be blocked
	 * at reading from the sysfs file.  When we return the count (or
	 * error if we fail) the app will resume. */
	error = rmi_read_block(fn_dev->rmi_dev, data_base_addr + BLK_NUM_OFF,
			(u8 *)buf, count);

	if (error < 0) {
		dev_err(dev, "Could not read data from %#06x\n",
				data_base_addr + BLK_NUM_OFF);
		return error;
	}

	return count;
}
Example #25
0
static ssize_t rmi_fn_34_cmd_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf,
				size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	unsigned long val;
	u16 data_base_addr;
	int error;

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;
	data_base_addr = fn_dev->fd.data_base_addr;

	/* need to convert the string data to an actual value */
	error = strict_strtoul(buf, 10, &val);
	if (error)
		return error;

	/* make sure we are in Flash Prog mode for all cmds except the
	 * Enable Flash Programming cmd - otherwise we are in error */
	if ((val != F34_ENABLE_FLASH_PROG) && !instance_data->inflashprogmode) {
		dev_err(dev, "Cannot send command to sensor - not in flash programming mode.\n");
		return -EINVAL;
	}

	instance_data->cmd = val;

	/* Validate command value and (if necessary) write it to the command
	 * register.
	 */
	switch (instance_data->cmd) {
	case F34_ENABLE_FLASH_PROG:
	case F34_ERASE_ALL:
	case F34_ERASE_CONFIG:
	case F34_WRITE_FW_BLOCK:
	case F34_READ_CONFIG_BLOCK:
	case F34_WRITE_CONFIG_BLOCK:
	case F34_READ_SENSOR_ID:
		/* Reset the status to indicate we are in progress on a cmd. */
		/* The status will change when the ATTN interrupt happens
		   and the status of the cmd that was issued is read from
		   the F34_Flash_Data3 register - result should be 0x80 for
		   success - any other value indicates an error */

		/* Issue the command to the device. */
		error = rmi_write(fn_dev->rmi_dev,
				data_base_addr + instance_data->blocksize +
				BLK_NUM_OFF, instance_data->cmd);

		if (error < 0) {
			dev_err(dev, "Could not write command %#04x to %#06x\n",
				instance_data->cmd,
				data_base_addr + instance_data->blocksize +
				BLK_NUM_OFF);
			return error;
		}

		if (instance_data->cmd == F34_ENABLE_FLASH_PROG)
			instance_data->inflashprogmode = true;

		/* set status to indicate we are in progress */
		instance_data->status = F34_STATUS_IN_PROGRESS;
		break;
	default:
		dev_dbg(dev, "RMI4 F34 - unknown command 0x%02lx.\n", val);
		count = -EINVAL;
		break;
	}

	return count;
}
Example #26
0
static ssize_t rmi_fn_34_rescanPDT_store(struct device *dev,
				     struct device_attribute *attr,
				     const char *buf, size_t count)
{
	struct rmi_function_dev *fn_dev;
	struct rmi_fn_34_data *instance_data;
	struct rmi_device *rmi_dev;
	struct rmi_driver_data *driver_data;
	struct pdt_entry pdt_entry;
	bool fn01found = false;
	bool fn34found = false;
	unsigned int rescan;
	int irq_count = 0;
	int retval = 0;
	int i;

	/* Rescan of the PDT is needed since issuing the Flash Enable cmd
	 * the device registers for Fn$01 and Fn$34 moving around because
	 * of the change from Bootloader mode to Flash Programming mode
	 * may change to a different PDT with only Fn$01 and Fn$34 that
	 * could have addresses for query, control, data, command registers
	 * that differ from the PDT scan done at device initialization. */

	fn_dev = to_rmi_function_dev(dev);
	instance_data = fn_dev->data;
	rmi_dev = fn_dev->rmi_dev;
	driver_data = dev_get_drvdata(&rmi_dev->dev);

	/* Make sure we are only in Flash Programming mode  - DON'T
	 * ALLOW THIS IN UI MODE. */
	if (instance_data->cmd != F34_ENABLE_FLASH_PROG) {
		dev_err(dev, "Not in flash programming mode, cannot rescan PDT.");
		return -EINVAL;
	}

	/* The only good value to write to this is 1, we allow 0, but with
	 * no effect (this is consistent with the way the command bit works. */
	if (sscanf(buf, "%u", &rescan) != 1)
		return -EINVAL;
	if (rescan < 0 || rescan > 1)
		return -EINVAL;

	/* 0 has no effect, so we skip it entirely. */
	if (rescan) {
		/* rescan the PDT - filling in Fn01 and Fn34 addresses -
		 * this is only temporary - the device will need to be reset
		 * to return the PDT to the normal values. */

		/* mini-parse the PDT - we only have to get Fn$01 and Fn$34 and
		   since we are Flash Programming mode we only have page 0. */
		for (i = PDT_START_SCAN_LOCATION; i >= PDT_END_SCAN_LOCATION;
			i -= sizeof(pdt_entry)) {
			retval = rmi_read_block(rmi_dev, i, (u8 *)&pdt_entry,
					       sizeof(pdt_entry));
			if (retval != sizeof(pdt_entry)) {
				dev_err(dev, "Failed to read PDT entry at %#06x, error = %d.",
						retval, i);
				return retval;
			}

			if ((pdt_entry.function_number == 0x00) ||
				(pdt_entry.function_number == 0xff))
				break;

			dev_dbg(dev, "%s: Found F%.2X\n",
				__func__, pdt_entry.function_number);

			/* f01 found - just fill in the new addresses in
			 * the existing fn_dev. */
			if (pdt_entry.function_number == 0x01) {
				struct rmi_function_dev *f01_dev =
					driver_data->f01_dev;
				fn01found = true;
				f01_dev->fd.query_base_addr =
					pdt_entry.query_base_addr;
				f01_dev->fd.command_base_addr =
				  pdt_entry.command_base_addr;
				f01_dev->fd.control_base_addr =
				  pdt_entry.control_base_addr;
				f01_dev->fd.data_base_addr =
				  pdt_entry.data_base_addr;
				f01_dev->fd.function_number =
				  pdt_entry.function_number;
				f01_dev->fd.interrupt_source_count =
				  pdt_entry.interrupt_source_count;
				f01_dev->num_of_irqs =
				  pdt_entry.interrupt_source_count;
				f01_dev->irq_pos = irq_count;

				irq_count += f01_dev->num_of_irqs;

				if (fn34found)
					break;
			}

			/* f34 found - just fill in the new addresses in
			 * the existing fn_dev. */
			if (pdt_entry.function_number == 0x34) {
				fn34found = true;
				fn_dev->fd.query_base_addr =
				  pdt_entry.query_base_addr;
				fn_dev->fd.command_base_addr =
				  pdt_entry.command_base_addr;
				fn_dev->fd.control_base_addr =
				  pdt_entry.control_base_addr;
				fn_dev->fd.data_base_addr =
				  pdt_entry.data_base_addr;
				fn_dev->fd.function_number =
				  pdt_entry.function_number;
				fn_dev->fd.interrupt_source_count =
				  pdt_entry.interrupt_source_count;
				fn_dev->num_of_irqs =
				  pdt_entry.interrupt_source_count;
				fn_dev->irq_pos = irq_count;

				irq_count += fn_dev->num_of_irqs;

				if (fn01found)
					break;
			}

		}

		if (!fn01found || !fn34found) {
			dev_err(dev, "F01 or F34 not found in PDT rescan.\n");
			return -EINVAL;
		}
	}

	return count;
}