Lines Matching +full:2 +full:- +full:wire
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ds2482.c - provides i2c to w1-master bridge(s)
7 * It is a I2C to 1-wire bridge.
8 * There are two variations: -100 and -800, which have 1 or 8 1-wire ports.
10 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4382
26 * The APU bit controls whether an active pullup (controlled slew-rate
28 * a 1-Wire line from low to high. When APU = 0, active pullup is disabled
30 * only a single slave on the 1-Wire line.
35 "0-disable, 1-enable (default)");
37 /* extra configurations - e.g. 1WS */
40 MODULE_PARM_DESC(extra_config, "Extra Configuration settings 1=APU,2=PPM,3=SPU,8=1WS");
43 * The DS2482 registers - there are 3 registers that are addressed by a read
50 #define DS2482_CMD_CHANNEL_SELECT 0xC3 /* Param: Channel byte - DS2482-800 only */
62 #define DS2482_PTR_CODE_CHANNEL 0xD2 /* DS2482-800 only */
70 #define DS2482_REG_CFG_1WS 0x08 /* 1-wire speed */
71 #define DS2482_REG_CFG_SPU 0x04 /* strong pull-up */
73 #define DS2482_REG_CFG_APU 0x01 /* active pull-up */
77 * Write and verify codes for the CHANNEL_SELECT command (DS2482-800 only).
115 /* 1-wire interface(s) */
119 /* per-device values */
127 * ds2482_calculate_config - Helper to calculate values for configuration register
143 * ds2482_select_register - Sets the read pointer.
146 * Return: -1 on failure, 0 on success
150 if (pdev->read_prt != read_ptr) { in ds2482_select_register()
151 if (i2c_smbus_write_byte_data(pdev->client, in ds2482_select_register()
154 return -1; in ds2482_select_register()
156 pdev->read_prt = read_ptr; in ds2482_select_register()
162 * ds2482_send_cmd - Sends a command without a parameter
167 * Return: -1 on failure, 0 on success
171 if (i2c_smbus_write_byte(pdev->client, cmd) < 0) in ds2482_send_cmd()
172 return -1; in ds2482_send_cmd()
174 pdev->read_prt = DS2482_PTR_CODE_STATUS; in ds2482_send_cmd()
179 * ds2482_send_cmd_data - Sends a command with a parameter
186 * Return: -1 on failure, 0 on success
191 if (i2c_smbus_write_byte_data(pdev->client, cmd, byte) < 0) in ds2482_send_cmd_data()
192 return -1; in ds2482_send_cmd_data()
195 pdev->read_prt = (cmd != DS2482_CMD_WRITE_CONFIG) ? in ds2482_send_cmd_data()
202 * 1-Wire interface code
208 * ds2482_wait_1wire_idle - Waits until the 1-wire interface is idle (not busy)
211 * Return: the last value read from status or -1 (failure)
215 int temp = -1; in ds2482_wait_1wire_idle()
220 temp = i2c_smbus_read_byte(pdev->client); in ds2482_wait_1wire_idle()
227 __func__, pdev->channel); in ds2482_wait_1wire_idle()
233 * ds2482_set_channel - Selects a w1 channel.
234 * The 1-wire interface must be idle before calling this function.
237 * @channel: 0-7
238 * Return: -1 (failure) or 0 (success)
242 if (i2c_smbus_write_byte_data(pdev->client, DS2482_CMD_CHANNEL_SELECT, in ds2482_set_channel()
244 return -1; in ds2482_set_channel()
246 pdev->read_prt = DS2482_PTR_CODE_CHANNEL; in ds2482_set_channel()
247 pdev->channel = -1; in ds2482_set_channel()
248 if (i2c_smbus_read_byte(pdev->client) == ds2482_chan_rd[channel]) { in ds2482_set_channel()
249 pdev->channel = channel; in ds2482_set_channel()
252 return -1; in ds2482_set_channel()
257 * ds2482_w1_touch_bit - Performs the touch-bit function, which writes a 0 or 1 and reads the level.
260 * @bit: The level to write: 0 or non-zero
266 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_touch_bit()
267 int status = -1; in ds2482_w1_touch_bit()
269 mutex_lock(&pdev->access_lock); in ds2482_w1_touch_bit()
273 if (pdev->w1_count > 1) in ds2482_w1_touch_bit()
274 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_touch_bit()
281 mutex_unlock(&pdev->access_lock); in ds2482_w1_touch_bit()
287 * ds2482_w1_triplet - Performs the triplet function, which reads two bits and writes a bit.
298 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_triplet()
301 mutex_lock(&pdev->access_lock); in ds2482_w1_triplet()
305 if (pdev->w1_count > 1) in ds2482_w1_triplet()
306 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_triplet()
313 mutex_unlock(&pdev->access_lock); in ds2482_w1_triplet()
320 * ds2482_w1_write_byte - Performs the write byte function.
328 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_write_byte()
330 mutex_lock(&pdev->access_lock); in ds2482_w1_write_byte()
334 if (pdev->w1_count > 1) in ds2482_w1_write_byte()
335 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_write_byte()
340 mutex_unlock(&pdev->access_lock); in ds2482_w1_write_byte()
344 * ds2482_w1_read_byte - Performs the read byte function.
352 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_read_byte()
355 mutex_lock(&pdev->access_lock); in ds2482_w1_read_byte()
359 if (pdev->w1_count > 1) in ds2482_w1_read_byte()
360 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_read_byte()
372 result = i2c_smbus_read_byte(pdev->client); in ds2482_w1_read_byte()
374 mutex_unlock(&pdev->access_lock); in ds2482_w1_read_byte()
381 * ds2482_w1_reset_bus - Sends a reset on the 1-wire interface
389 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_reset_bus()
393 mutex_lock(&pdev->access_lock); in ds2482_w1_reset_bus()
397 if (pdev->w1_count > 1) in ds2482_w1_reset_bus()
398 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_reset_bus()
407 /* If the chip did reset since detect, re-config it */ in ds2482_w1_reset_bus()
413 mutex_unlock(&pdev->access_lock); in ds2482_w1_reset_bus()
421 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_set_pullup()
424 /* if delay is non-zero activate the pullup, in ds2482_w1_set_pullup()
449 int err = -ENODEV; in ds2482_probe()
453 if (!i2c_check_functionality(client->adapter, in ds2482_probe()
456 return -ENODEV; in ds2482_probe()
459 err = -ENOMEM; in ds2482_probe()
463 data->client = client; in ds2482_probe()
468 dev_warn(&client->dev, "DS2482 reset failed.\n"); in ds2482_probe()
475 /* Read the status byte - only reset bit and line should be set */ in ds2482_probe()
478 dev_warn(&client->dev, "DS2482 reset status " in ds2482_probe()
479 "0x%02X - not a DS2482\n", temp1); in ds2482_probe()
483 /* Detect the 8-port version */ in ds2482_probe()
484 data->w1_count = 1; in ds2482_probe()
486 data->w1_count = 8; in ds2482_probe()
492 mutex_init(&data->access_lock); in ds2482_probe()
494 /* Register 1-wire interface(s) */ in ds2482_probe()
495 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_probe()
496 data->w1_ch[idx].pdev = data; in ds2482_probe()
497 data->w1_ch[idx].channel = idx; in ds2482_probe()
500 data->w1_ch[idx].w1_bm.data = &data->w1_ch[idx]; in ds2482_probe()
501 data->w1_ch[idx].w1_bm.read_byte = ds2482_w1_read_byte; in ds2482_probe()
502 data->w1_ch[idx].w1_bm.write_byte = ds2482_w1_write_byte; in ds2482_probe()
503 data->w1_ch[idx].w1_bm.touch_bit = ds2482_w1_touch_bit; in ds2482_probe()
504 data->w1_ch[idx].w1_bm.triplet = ds2482_w1_triplet; in ds2482_probe()
505 data->w1_ch[idx].w1_bm.reset_bus = ds2482_w1_reset_bus; in ds2482_probe()
506 data->w1_ch[idx].w1_bm.set_pullup = ds2482_w1_set_pullup; in ds2482_probe()
508 err = w1_add_master_device(&data->w1_ch[idx].w1_bm); in ds2482_probe()
510 data->w1_ch[idx].pdev = NULL; in ds2482_probe()
518 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_probe()
519 if (data->w1_ch[idx].pdev != NULL) in ds2482_probe()
520 w1_remove_master_device(&data->w1_ch[idx].w1_bm); in ds2482_probe()
533 /* Unregister the 1-wire bridge(s) */ in ds2482_remove()
534 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_remove()
535 if (data->w1_ch[idx].pdev != NULL) in ds2482_remove()
536 w1_remove_master_device(&data->w1_ch[idx].w1_bm); in ds2482_remove()