Lines Matching +full:client +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2008-2009 Rodolfo Giometti <giometti@linux.it>
6 * Copyright (c) 2008-2009 Eurotech S.p.A. <info@eurotech.it>
15 * single 8-bit register. The upstream "parent" bus fans out to two,
18 * mux can select only one sub-bus at a time; a switch can select any
30 * i2c-virtual_cb.c from Brian Kuschak <bkuschak@yahoo.com>
39 #include <linux/i2c-mux.h>
47 #include <dt-bindings/mux/mux.h>
76 struct i2c_device_identity id; member
86 struct i2c_client *client; member
99 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
106 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
112 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
119 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
125 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
130 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
136 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
141 .id = { .manufacturer_id = I2C_DEVICE_ID_NONE },
146 .id = {
155 .id = {
163 .id = {
172 .id = {
216 struct i2c_client *client, u8 val) in pca954x_reg_write() argument
220 return __i2c_smbus_xfer(adap, client->addr, client->flags, in pca954x_reg_write()
228 if (data->chip->muxtype == pca954x_ismux) in pca954x_regval()
229 return chan | data->chip->enable; in pca954x_regval()
237 struct i2c_client *client = data->client; in pca954x_select_chan() local
243 if (data->last_chan != regval) { in pca954x_select_chan()
244 ret = pca954x_reg_write(muxc->parent, client, regval); in pca954x_select_chan()
245 data->last_chan = ret < 0 ? 0 : regval; in pca954x_select_chan()
254 struct i2c_client *client = data->client; in pca954x_deselect_mux() local
257 idle_state = READ_ONCE(data->idle_state); in pca954x_deselect_mux()
264 data->last_chan = 0; in pca954x_deselect_mux()
265 return pca954x_reg_write(muxc->parent, client, in pca954x_deselect_mux()
266 data->last_chan); in pca954x_deselect_mux()
269 /* otherwise leave as-is */ in pca954x_deselect_mux()
278 struct i2c_client *client = to_i2c_client(dev); in idle_state_show() local
279 struct i2c_mux_core *muxc = i2c_get_clientdata(client); in idle_state_show()
282 return sprintf(buf, "%d\n", READ_ONCE(data->idle_state)); in idle_state_show()
289 struct i2c_client *client = to_i2c_client(dev); in idle_state_store() local
290 struct i2c_mux_core *muxc = i2c_get_clientdata(client); in idle_state_store()
300 (val < 0 || val >= data->chip->nchans)) in idle_state_store()
301 return -EINVAL; in idle_state_store()
303 i2c_lock_bus(muxc->parent, I2C_LOCK_SEGMENT); in idle_state_store()
305 WRITE_ONCE(data->idle_state, val); in idle_state_store()
310 if (data->last_chan || val != MUX_IDLE_DISCONNECT) in idle_state_store()
313 i2c_unlock_bus(muxc->parent, I2C_LOCK_SEGMENT); in idle_state_store()
326 ret = i2c_smbus_read_byte(data->client); in pca954x_irq_handler()
330 pending = (ret >> PCA954X_IRQ_OFFSET) & (BIT(data->chip->nchans) - 1); in pca954x_irq_handler()
331 for_each_set_bit(i, &pending, data->chip->nchans) in pca954x_irq_handler()
332 handle_nested_irq(irq_linear_revmap(data->irq, i)); in pca954x_irq_handler()
340 return -EINVAL; in pca954x_irq_set_type()
345 .name = "i2c-mux-pca954x",
352 struct i2c_client *client = data->client; in pca954x_irq_setup() local
355 if (!data->chip->has_irq || client->irq <= 0) in pca954x_irq_setup()
358 raw_spin_lock_init(&data->lock); in pca954x_irq_setup()
360 data->irq = irq_domain_add_linear(client->dev.of_node, in pca954x_irq_setup()
361 data->chip->nchans, in pca954x_irq_setup()
363 if (!data->irq) in pca954x_irq_setup()
364 return -ENODEV; in pca954x_irq_setup()
366 for (c = 0; c < data->chip->nchans; c++) { in pca954x_irq_setup()
367 irq = irq_create_mapping(data->irq, c); in pca954x_irq_setup()
369 dev_err(&client->dev, "failed irq create map\n"); in pca954x_irq_setup()
370 return -EINVAL; in pca954x_irq_setup()
385 if (data->irq) { in pca954x_cleanup()
386 for (c = 0; c < data->chip->nchans; c++) { in pca954x_cleanup()
387 irq = irq_find_mapping(data->irq, c); in pca954x_cleanup()
390 irq_domain_remove(data->irq); in pca954x_cleanup()
395 static int pca954x_init(struct i2c_client *client, struct pca954x *data) in pca954x_init() argument
399 if (data->idle_state >= 0) in pca954x_init()
400 data->last_chan = pca954x_regval(data, data->idle_state); in pca954x_init()
402 data->last_chan = 0; /* Disconnect multiplexer */ in pca954x_init()
404 ret = i2c_smbus_write_byte(client, data->last_chan); in pca954x_init()
406 data->last_chan = 0; in pca954x_init()
414 static int pca954x_probe(struct i2c_client *client, in pca954x_probe() argument
415 const struct i2c_device_id *id) in pca954x_probe() argument
417 struct i2c_adapter *adap = client->adapter; in pca954x_probe()
418 struct device *dev = &client->dev; in pca954x_probe()
426 return -ENODEV; in pca954x_probe()
431 return -ENOMEM; in pca954x_probe()
434 i2c_set_clientdata(client, muxc); in pca954x_probe()
435 data->client = client; in pca954x_probe()
448 data->chip = device_get_match_data(dev); in pca954x_probe()
449 if (!data->chip) in pca954x_probe()
450 data->chip = &chips[id->driver_data]; in pca954x_probe()
452 if (data->chip->id.manufacturer_id != I2C_DEVICE_ID_NONE) { in pca954x_probe()
453 struct i2c_device_identity id; in pca954x_probe() local
455 ret = i2c_get_device_id(client, &id); in pca954x_probe()
456 if (ret && ret != -EOPNOTSUPP) in pca954x_probe()
460 (id.manufacturer_id != data->chip->id.manufacturer_id || in pca954x_probe()
461 id.part_id != data->chip->id.part_id)) { in pca954x_probe()
462 dev_warn(dev, "unexpected device id %03x-%03x-%x\n", in pca954x_probe()
463 id.manufacturer_id, id.part_id, in pca954x_probe()
464 id.die_revision); in pca954x_probe()
465 return -ENODEV; in pca954x_probe()
469 data->idle_state = MUX_IDLE_AS_IS; in pca954x_probe()
470 if (device_property_read_u32(dev, "idle-state", &data->idle_state)) { in pca954x_probe()
471 if (device_property_read_bool(dev, "i2c-mux-idle-disconnect")) in pca954x_probe()
472 data->idle_state = MUX_IDLE_DISCONNECT; in pca954x_probe()
481 ret = pca954x_init(client, data); in pca954x_probe()
484 return -ENODEV; in pca954x_probe()
492 for (num = 0; num < data->chip->nchans; num++) { in pca954x_probe()
498 if (data->irq) { in pca954x_probe()
499 ret = devm_request_threaded_irq(dev, data->client->irq, in pca954x_probe()
514 num, data->chip->muxtype == pca954x_ismux in pca954x_probe()
515 ? "mux" : "switch", client->name); in pca954x_probe()
524 static void pca954x_remove(struct i2c_client *client) in pca954x_remove() argument
526 struct i2c_mux_core *muxc = i2c_get_clientdata(client); in pca954x_remove()
528 device_remove_file(&client->dev, &dev_attr_idle_state); in pca954x_remove()
536 struct i2c_client *client = to_i2c_client(dev); in pca954x_resume() local
537 struct i2c_mux_core *muxc = i2c_get_clientdata(client); in pca954x_resume()
541 ret = pca954x_init(client, data); in pca954x_resume()
543 dev_err(&client->dev, "failed to verify mux presence\n"); in pca954x_resume()