static int trigger_bulk_read()

in slaves/w1_therm.c [1433:1521]


static int trigger_bulk_read(struct w1_master *dev_master)
{
	struct w1_slave *sl = NULL; /* used to iterate through slaves */
	int max_trying = W1_THERM_MAX_TRY;
	int t_conv = 0;
	int ret = -ENODEV;
	bool strong_pullup = false;

	/*
	 * Check whether there are parasite powered device on the bus,
	 * and compute duration of conversion for these devices
	 * so we can apply a strong pullup if required
	 */
	list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
		if (!sl->family_data)
			goto error;
		if (bulk_read_support(sl)) {
			int t_cur = conversion_time(sl);

			t_conv = t_cur > t_conv ? t_cur : t_conv;
			strong_pullup = strong_pullup ||
					(w1_strong_pullup == 2 ||
					(!SLAVE_POWERMODE(sl) &&
					w1_strong_pullup));
		}
	}

	/*
	 * t_conv is the max conversion time required on the bus
	 * If its 0, no device support the bulk read feature
	 */
	if (!t_conv)
		goto error;

	if (!bus_mutex_lock(&dev_master->bus_mutex)) {
		ret = -EAGAIN;	/* Didn't acquire the mutex */
		goto error;
	}

	while ((max_trying--) && (ret < 0)) { /* ret should be either 0 */

		if (!w1_reset_bus(dev_master)) {	/* Just reset the bus */
			unsigned long sleep_rem;

			w1_write_8(dev_master, W1_SKIP_ROM);

			if (strong_pullup)	/* Apply pullup if required */
				w1_next_pullup(dev_master, t_conv);

			w1_write_8(dev_master, W1_CONVERT_TEMP);

			/* set a flag to instruct that converT pending */
			list_for_each_entry(sl,
				&dev_master->slist, w1_slave_entry) {
				if (bulk_read_support(sl))
					SLAVE_CONVERT_TRIGGERED(sl) = -1;
			}

			if (strong_pullup) { /* some device need pullup */
				sleep_rem = msleep_interruptible(t_conv);
				if (sleep_rem != 0) {
					ret = -EINTR;
					goto mt_unlock;
				}
				mutex_unlock(&dev_master->bus_mutex);
			} else {
				mutex_unlock(&dev_master->bus_mutex);
				sleep_rem = msleep_interruptible(t_conv);
				if (sleep_rem != 0) {
					ret = -EINTR;
					goto set_flag;
				}
			}
			ret = 0;
			goto set_flag;
		}
	}

mt_unlock:
	mutex_unlock(&dev_master->bus_mutex);
set_flag:
	/* set a flag to register convsersion is done */
	list_for_each_entry(sl, &dev_master->slist, w1_slave_entry) {
		if (bulk_read_support(sl))
			SLAVE_CONVERT_TRIGGERED(sl) = 1;
	}
error:
	return ret;
}