Lines Matching +full:wire +full:- +full:or
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
25 * The APU bit controls whether an active pullup (controlled slew-rate
26 * transistor) or a passive pullup (Rwpu resistor) will be used to drive
27 * a 1-Wire line from low to high. When APU = 0, active pullup is disabled
29 * only a single slave on the 1-Wire line.
34 "0-disable, 1-enable (default)");
36 /* extra configurations - e.g. 1WS */
42 * The DS2482 registers - there are 3 registers that are addressed by a read
49 #define DS2482_CMD_CHANNEL_SELECT 0xC3 /* Param: Channel byte - DS2482-800 only */
61 #define DS2482_PTR_CODE_CHANNEL 0xD2 /* DS2482-800 only */
69 #define DS2482_REG_CFG_1WS 0x08 /* 1-wire speed */
70 #define DS2482_REG_CFG_SPU 0x04 /* strong pull-up */
72 #define DS2482_REG_CFG_APU 0x01 /* active pull-up */
76 * Write and verify codes for the CHANNEL_SELECT command (DS2482-800 only).
112 /* 1-wire interface(s) */
113 int w1_count; /* 1 or 8 */
116 /* per-device values */
124 * ds2482_calculate_config - Helper to calculate values for configuration register
140 * ds2482_select_register - Sets the read pointer.
143 * Return: -1 on failure, 0 on success
147 if (pdev->read_prt != read_ptr) { in ds2482_select_register()
148 if (i2c_smbus_write_byte_data(pdev->client, in ds2482_select_register()
151 return -1; in ds2482_select_register()
153 pdev->read_prt = read_ptr; in ds2482_select_register()
159 * ds2482_send_cmd - Sends a command without a parameter
164 * Return: -1 on failure, 0 on success
168 if (i2c_smbus_write_byte(pdev->client, cmd) < 0) in ds2482_send_cmd()
169 return -1; in ds2482_send_cmd()
171 pdev->read_prt = DS2482_PTR_CODE_STATUS; in ds2482_send_cmd()
176 * ds2482_send_cmd_data - Sends a command with a parameter
183 * Return: -1 on failure, 0 on success
188 if (i2c_smbus_write_byte_data(pdev->client, cmd, byte) < 0) in ds2482_send_cmd_data()
189 return -1; in ds2482_send_cmd_data()
192 pdev->read_prt = (cmd != DS2482_CMD_WRITE_CONFIG) ? in ds2482_send_cmd_data()
199 * 1-Wire interface code
205 * ds2482_wait_1wire_idle - Waits until the 1-wire interface is idle (not busy)
208 * Return: the last value read from status or -1 (failure)
212 int temp = -1; in ds2482_wait_1wire_idle()
217 temp = i2c_smbus_read_byte(pdev->client); in ds2482_wait_1wire_idle()
224 __func__, pdev->channel); in ds2482_wait_1wire_idle()
230 * ds2482_set_channel - Selects a w1 channel.
231 * The 1-wire interface must be idle before calling this function.
234 * @channel: 0-7
235 * Return: -1 (failure) or 0 (success)
239 if (i2c_smbus_write_byte_data(pdev->client, DS2482_CMD_CHANNEL_SELECT, in ds2482_set_channel()
241 return -1; in ds2482_set_channel()
243 pdev->read_prt = DS2482_PTR_CODE_CHANNEL; in ds2482_set_channel()
244 pdev->channel = -1; in ds2482_set_channel()
245 if (i2c_smbus_read_byte(pdev->client) == ds2482_chan_rd[channel]) { in ds2482_set_channel()
246 pdev->channel = channel; in ds2482_set_channel()
249 return -1; in ds2482_set_channel()
254 * ds2482_w1_touch_bit - Performs the touch-bit function, which writes a 0 or 1 and reads the level.
257 * @bit: The level to write: 0 or non-zero
258 * Return: The level read: 0 or 1
263 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_touch_bit()
264 int status = -1; in ds2482_w1_touch_bit()
266 mutex_lock(&pdev->access_lock); in ds2482_w1_touch_bit()
270 if (pdev->w1_count > 1) in ds2482_w1_touch_bit()
271 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_touch_bit()
278 mutex_unlock(&pdev->access_lock); in ds2482_w1_touch_bit()
284 * ds2482_w1_triplet - Performs the triplet function, which reads two bits and writes a bit.
295 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_triplet()
298 mutex_lock(&pdev->access_lock); in ds2482_w1_triplet()
302 if (pdev->w1_count > 1) in ds2482_w1_triplet()
303 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_triplet()
310 mutex_unlock(&pdev->access_lock); in ds2482_w1_triplet()
317 * ds2482_w1_write_byte - Performs the write byte function.
325 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_write_byte()
327 mutex_lock(&pdev->access_lock); in ds2482_w1_write_byte()
331 if (pdev->w1_count > 1) in ds2482_w1_write_byte()
332 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_write_byte()
337 mutex_unlock(&pdev->access_lock); in ds2482_w1_write_byte()
341 * ds2482_w1_read_byte - Performs the read byte function.
349 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_read_byte()
352 mutex_lock(&pdev->access_lock); in ds2482_w1_read_byte()
356 if (pdev->w1_count > 1) in ds2482_w1_read_byte()
357 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_read_byte()
369 result = i2c_smbus_read_byte(pdev->client); in ds2482_w1_read_byte()
371 mutex_unlock(&pdev->access_lock); in ds2482_w1_read_byte()
378 * ds2482_w1_reset_bus - Sends a reset on the 1-wire interface
381 * Return: 0=Device present, 1=No device present or error
386 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_reset_bus()
390 mutex_lock(&pdev->access_lock); in ds2482_w1_reset_bus()
394 if (pdev->w1_count > 1) in ds2482_w1_reset_bus()
395 ds2482_set_channel(pdev, pchan->channel); in ds2482_w1_reset_bus()
404 /* If the chip did reset since detect, re-config it */ in ds2482_w1_reset_bus()
410 mutex_unlock(&pdev->access_lock); in ds2482_w1_reset_bus()
418 struct ds2482_data *pdev = pchan->pdev; in ds2482_w1_set_pullup()
421 /* if delay is non-zero activate the pullup, in ds2482_w1_set_pullup()
445 int err = -ENODEV; in ds2482_probe()
449 if (!i2c_check_functionality(client->adapter, in ds2482_probe()
452 return -ENODEV; in ds2482_probe()
456 err = -ENOMEM; in ds2482_probe()
460 data->client = client; in ds2482_probe()
465 dev_warn(&client->dev, "DS2482 reset failed.\n"); in ds2482_probe()
472 /* Read the status byte - only reset bit and line should be set */ in ds2482_probe()
475 dev_warn(&client->dev, "DS2482 reset status " in ds2482_probe()
476 "0x%02X - not a DS2482\n", temp1); in ds2482_probe()
480 /* Detect the 8-port version */ in ds2482_probe()
481 data->w1_count = 1; in ds2482_probe()
483 data->w1_count = 8; in ds2482_probe()
489 mutex_init(&data->access_lock); in ds2482_probe()
491 /* Register 1-wire interface(s) */ in ds2482_probe()
492 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_probe()
493 data->w1_ch[idx].pdev = data; in ds2482_probe()
494 data->w1_ch[idx].channel = idx; in ds2482_probe()
497 data->w1_ch[idx].w1_bm.data = &data->w1_ch[idx]; in ds2482_probe()
498 data->w1_ch[idx].w1_bm.read_byte = ds2482_w1_read_byte; in ds2482_probe()
499 data->w1_ch[idx].w1_bm.write_byte = ds2482_w1_write_byte; in ds2482_probe()
500 data->w1_ch[idx].w1_bm.touch_bit = ds2482_w1_touch_bit; in ds2482_probe()
501 data->w1_ch[idx].w1_bm.triplet = ds2482_w1_triplet; in ds2482_probe()
502 data->w1_ch[idx].w1_bm.reset_bus = ds2482_w1_reset_bus; in ds2482_probe()
503 data->w1_ch[idx].w1_bm.set_pullup = ds2482_w1_set_pullup; in ds2482_probe()
505 err = w1_add_master_device(&data->w1_ch[idx].w1_bm); in ds2482_probe()
507 data->w1_ch[idx].pdev = NULL; in ds2482_probe()
515 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_probe()
516 if (data->w1_ch[idx].pdev != NULL) in ds2482_probe()
517 w1_remove_master_device(&data->w1_ch[idx].w1_bm); in ds2482_probe()
530 /* Unregister the 1-wire bridge(s) */ in ds2482_remove()
531 for (idx = 0; idx < data->w1_count; idx++) { in ds2482_remove()
532 if (data->w1_ch[idx].pdev != NULL) in ds2482_remove()
533 w1_remove_master_device(&data->w1_ch[idx].w1_bm); in ds2482_remove()