Lines Matching +full:single +full:- +full:master

1 // SPDX-License-Identifier: GPL-2.0-only
3 * w1_ds28e17.c - w1 family 19 (DS28E17) driver
28 MODULE_DESCRIPTION("w1 family 19 driver for DS28E17, 1-wire to I2C master bridge");
29 MODULE_ALIAS("w1-family-" __stringify(W1_FAMILY_DS28E17));
88 struct w1_f19_data *data = sl->family_data; in w1_f19_i2c_busy_wait()
92 if (w1_touch_bit(sl->master, 1) == 0) in w1_f19_i2c_busy_wait()
100 usleep_range(timebases[data->speed] * (data->stretch) * count, in w1_f19_i2c_busy_wait()
101 timebases[data->speed] * (data->stretch) * count in w1_f19_i2c_busy_wait()
106 while ((checks--) > 0) { in w1_f19_i2c_busy_wait()
108 if (w1_touch_bit(sl->master, 1) == 0) in w1_f19_i2c_busy_wait()
111 /* Wait one non-streched byte timeslot. */ in w1_f19_i2c_busy_wait()
112 udelay(timebases[data->speed]); in w1_f19_i2c_busy_wait()
116 dev_warn(&sl->dev, "busy timeout\n"); in w1_f19_i2c_busy_wait()
117 return -ETIMEDOUT; in w1_f19_i2c_busy_wait()
126 dev_warn(&sl->dev, "crc16 mismatch\n"); in w1_f19_error()
128 dev_warn(&sl->dev, "i2c device not responding\n"); in w1_f19_error()
131 dev_warn(&sl->dev, "i2c short write, %d bytes not acknowledged\n", in w1_f19_error()
137 return -ENXIO; in w1_f19_error()
139 return -EAGAIN; in w1_f19_error()
141 return -EIO; in w1_f19_error()
148 /* Utility function: write data to I2C slave, single chunk. */
159 w1_write_block(sl->master, command, command_count); in __w1_f19_i2c_write()
163 w1_write_8(sl->master, w1_buf[0]); in __w1_f19_i2c_write()
166 w1_write_block(sl->master, buffer, count); in __w1_f19_i2c_write()
170 w1_write_block(sl->master, w1_buf, 2); in __w1_f19_i2c_write()
174 return -ETIMEDOUT; in __w1_f19_i2c_write()
177 w1_read_block(sl->master, w1_buf, 2); in __w1_f19_i2c_write()
200 return -EOPNOTSUPP; in w1_f19_i2c_write()
206 * a single onewire command. in w1_f19_i2c_write()
227 if (w1_reset_resume_command(sl->master)) in w1_f19_i2c_write()
228 return -EIO; in w1_f19_i2c_write()
232 remaining -= W1_F19_WRITE_DATA_LIMIT; in w1_f19_i2c_write()
243 if (w1_reset_resume_command(sl->master)) in w1_f19_i2c_write()
244 return -EIO; in w1_f19_i2c_write()
248 remaining -= W1_F19_WRITE_DATA_LIMIT; in w1_f19_i2c_write()
271 return -EOPNOTSUPP; in w1_f19_i2c_read()
280 w1_write_block(sl->master, w1_buf, 5); in w1_f19_i2c_read()
284 return -ETIMEDOUT; in w1_f19_i2c_read()
287 w1_buf[0] = w1_read_8(sl->master); in w1_f19_i2c_read()
296 return w1_read_block(sl->master, buffer, count); in w1_f19_i2c_read()
310 return -EOPNOTSUPP; in w1_f19_i2c_write_read()
317 w1_write_block(sl->master, w1_buf, 3); in w1_f19_i2c_write_read()
320 w1_write_block(sl->master, wbuffer, wcount); in w1_f19_i2c_write_read()
326 w1_write_block(sl->master, w1_buf, 3); in w1_f19_i2c_write_read()
330 return -ETIMEDOUT; in w1_f19_i2c_write_read()
333 w1_read_block(sl->master, w1_buf, 2); in w1_f19_i2c_write_read()
341 return w1_read_block(sl->master, rbuffer, rcount); in w1_f19_i2c_write_read()
345 /* Do an I2C master transfer. */
349 struct w1_slave *sl = (struct w1_slave *) adapter->algo_data; in w1_f19_i2c_master_transfer()
354 mutex_lock(&sl->master->bus_mutex); in w1_f19_i2c_master_transfer()
358 i = -EIO; in w1_f19_i2c_master_transfer()
368 if (i < (num-1) in w1_f19_i2c_master_transfer()
437 i == (num-1)); in w1_f19_i2c_master_transfer()
450 if (w1_reset_resume_command(sl->master)) { in w1_f19_i2c_master_transfer()
451 i = -EIO; in w1_f19_i2c_master_transfer()
459 mutex_unlock(&sl->master->bus_mutex); in w1_f19_i2c_master_transfer()
502 struct w1_f19_data *data = sl->family_data; in w1_f19_get_i2c_speed()
503 int result = -EIO; in w1_f19_get_i2c_speed()
506 mutex_lock(&sl->master->bus_mutex); in w1_f19_get_i2c_speed()
513 w1_write_8(sl->master, W1_F19_READ_CONFIGURATION); in w1_f19_get_i2c_speed()
514 result = w1_read_8(sl->master); in w1_f19_get_i2c_speed()
516 result = -EIO; in w1_f19_get_i2c_speed()
521 data->speed = result; in w1_f19_get_i2c_speed()
525 mutex_unlock(&sl->master->bus_mutex); in w1_f19_get_i2c_speed()
534 struct w1_f19_data *data = sl->family_data; in __w1_f19_set_i2c_speed()
540 return -EIO; in __w1_f19_set_i2c_speed()
544 w1_write_block(sl->master, w1_buf, 2); in __w1_f19_set_i2c_speed()
547 data->speed = speed; in __w1_f19_set_i2c_speed()
549 dev_info(&sl->dev, "i2c speed set to %d kBaud\n", i2c_speeds[speed]); in __w1_f19_set_i2c_speed()
559 mutex_lock(&sl->master->bus_mutex); in w1_f19_set_i2c_speed()
565 mutex_unlock(&sl->master->bus_mutex); in w1_f19_set_i2c_speed()
573 /* I2C speed attribute for a single chip. */
580 /* Read current speed from slave. Updates data->speed. */ in speed_show()
597 return -EINVAL; in speed_store()
599 return -EINVAL; in speed_store()
601 return -EINVAL; in speed_store()
615 return -EINVAL; in speed_store()
628 /* Busy stretch attribute for a single chip. */
633 struct w1_f19_data *data = sl->family_data; in stretch_show()
636 return sprintf(buf, "%d\n", data->stretch); in stretch_show()
643 struct w1_f19_data *data = sl->family_data; in stretch_store()
647 return -EINVAL; in stretch_store()
649 return -EINVAL; in stretch_store()
651 return -EINVAL; in stretch_store()
654 data->stretch = buf[0] & 0x0F; in stretch_store()
686 data = devm_kzalloc(&sl->dev, sizeof(*data), GFP_KERNEL); in w1_f19_add_slave()
688 return -ENOMEM; in w1_f19_add_slave()
689 sl->family_data = data; in w1_f19_add_slave()
707 * We assume 400kBaud, the power-on value. in w1_f19_add_slave()
709 data->speed = 1; in w1_f19_add_slave()
716 data->stretch = i2c_stretch; in w1_f19_add_slave()
719 data->adapter.owner = THIS_MODULE; in w1_f19_add_slave()
720 data->adapter.algo = &w1_f19_i2c_algorithm; in w1_f19_add_slave()
721 data->adapter.algo_data = sl; in w1_f19_add_slave()
722 strcpy(data->adapter.name, "w1-"); in w1_f19_add_slave()
723 strcat(data->adapter.name, sl->name); in w1_f19_add_slave()
724 data->adapter.dev.parent = &sl->dev; in w1_f19_add_slave()
725 data->adapter.quirks = &w1_f19_i2c_adapter_quirks; in w1_f19_add_slave()
727 return i2c_add_adapter(&data->adapter); in w1_f19_add_slave()
732 struct w1_f19_data *family_data = sl->family_data; in w1_f19_remove_slave()
735 i2c_del_adapter(&family_data->adapter); in w1_f19_remove_slave()
738 devm_kfree(&sl->dev, family_data); in w1_f19_remove_slave()
739 sl->family_data = NULL; in w1_f19_remove_slave()