Lines Matching refs:mlxsw_i2c

80 struct mlxsw_i2c {  struct
115 mlxsw_i2c_convert_mbox(struct mlxsw_i2c *mlxsw_i2c, u8 *buf) in mlxsw_i2c_convert_mbox() argument
121 mlxsw_i2c->cmd.mb_off_in = tmp & in mlxsw_i2c_convert_mbox()
123 mlxsw_i2c->cmd.mb_size_in = (tmp & GENMASK(31, in mlxsw_i2c_convert_mbox()
128 mlxsw_i2c->cmd.mb_off_out = tmp & in mlxsw_i2c_convert_mbox()
130 mlxsw_i2c->cmd.mb_size_out = (tmp & GENMASK(31, in mlxsw_i2c_convert_mbox()
153 struct mlxsw_i2c *mlxsw_i2c, u8 *p_status) in mlxsw_i2c_wait_go_bit() argument
197 struct mlxsw_i2c *mlxsw_i2c, in mlxsw_i2c_write_cmd() argument
244 struct mlxsw_i2c *mlxsw_i2c, u16 opcode, u32 in_mod) in mlxsw_i2c_write_init_cmd() argument
285 err = mlxsw_i2c_wait_go_bit(client, mlxsw_i2c, &status); in mlxsw_i2c_write_init_cmd()
303 struct mlxsw_i2c *mlxsw_i2c) in mlxsw_i2c_get_mbox() argument
323 mlxsw_i2c_convert_mbox(mlxsw_i2c, &buf[MLXSW_I2C_MBOX_OUT_PARAM_OFF]); in mlxsw_i2c_get_mbox()
334 struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client); in mlxsw_i2c_write() local
336 int off = mlxsw_i2c->cmd.mb_off_in, chunk_size, i, j; in mlxsw_i2c_write()
343 tran_buf = kmalloc(mlxsw_i2c->block_size + MLXSW_I2C_ADDR_BUF_SIZE, in mlxsw_i2c_write()
350 chunk_size = (in_mbox_size > mlxsw_i2c->block_size) ? in mlxsw_i2c_write()
351 mlxsw_i2c->block_size : in_mbox_size; in mlxsw_i2c_write()
355 mlxsw_i2c->block_size * i, chunk_size); in mlxsw_i2c_write()
380 err = mlxsw_i2c_write_cmd(client, mlxsw_i2c, 0); in mlxsw_i2c_write()
388 err = mlxsw_i2c_wait_go_bit(client, mlxsw_i2c, p_status); in mlxsw_i2c_write()
412 struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client); in mlxsw_i2c_cmd() local
416 int off = mlxsw_i2c->cmd.mb_off_out; in mlxsw_i2c_cmd()
426 num = reg_size / mlxsw_i2c->block_size; in mlxsw_i2c_cmd()
427 if (reg_size % mlxsw_i2c->block_size) in mlxsw_i2c_cmd()
430 if (mutex_lock_interruptible(&mlxsw_i2c->cmd.lock) < 0) { in mlxsw_i2c_cmd()
441 mutex_unlock(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_cmd()
447 num = reg_size / mlxsw_i2c->block_size; in mlxsw_i2c_cmd()
449 if (mutex_lock_interruptible(&mlxsw_i2c->cmd.lock) < 0) { in mlxsw_i2c_cmd()
454 err = mlxsw_i2c_write_init_cmd(client, mlxsw_i2c, opcode, in mlxsw_i2c_cmd()
463 chunk_size = (reg_size > mlxsw_i2c->block_size) ? in mlxsw_i2c_cmd()
464 mlxsw_i2c->block_size : reg_size; in mlxsw_i2c_cmd()
492 mutex_unlock(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_cmd()
497 mutex_unlock(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_cmd()
507 struct mlxsw_i2c *mlxsw_i2c = bus_priv; in mlxsw_i2c_cmd_exec() local
509 return mlxsw_i2c_cmd(mlxsw_i2c->dev, opcode, in_mod, in_mbox_size, in mlxsw_i2c_cmd_exec()
530 struct mlxsw_i2c *mlxsw_i2c = bus_priv; in mlxsw_i2c_init() local
534 mlxsw_i2c->core = mlxsw_core; in mlxsw_i2c_init()
544 mlxsw_i2c->bus_info.fw_rev.major = in mlxsw_i2c_init()
546 mlxsw_i2c->bus_info.fw_rev.minor = in mlxsw_i2c_init()
548 mlxsw_i2c->bus_info.fw_rev.subminor = in mlxsw_i2c_init()
560 struct mlxsw_i2c *mlxsw_i2c = bus_priv; in mlxsw_i2c_fini() local
562 mlxsw_i2c->core = NULL; in mlxsw_i2c_fini()
567 struct mlxsw_i2c *mlxsw_i2c; in mlxsw_i2c_work_handler() local
569 mlxsw_i2c = container_of(work, struct mlxsw_i2c, irq_work); in mlxsw_i2c_work_handler()
570 mlxsw_core_irq_event_handlers_call(mlxsw_i2c->core); in mlxsw_i2c_work_handler()
575 struct mlxsw_i2c *mlxsw_i2c = dev; in mlxsw_i2c_irq_handler() local
577 mlxsw_core_schedule_work(&mlxsw_i2c->irq_work); in mlxsw_i2c_irq_handler()
585 static int mlxsw_i2c_irq_init(struct mlxsw_i2c *mlxsw_i2c, u8 addr) in mlxsw_i2c_irq_init() argument
597 if (mlxsw_i2c->pdata && mlxsw_i2c->pdata->irq) in mlxsw_i2c_irq_init()
598 mlxsw_i2c->irq = mlxsw_i2c->pdata->irq; in mlxsw_i2c_irq_init()
600 mlxsw_i2c->irq = MLXSW_I2C_DEFAULT_IRQ; in mlxsw_i2c_irq_init()
602 if (!mlxsw_i2c->irq) in mlxsw_i2c_irq_init()
605 INIT_WORK(&mlxsw_i2c->irq_work, mlxsw_i2c_work_handler); in mlxsw_i2c_irq_init()
606 err = request_irq(mlxsw_i2c->irq, mlxsw_i2c_irq_handler, in mlxsw_i2c_irq_init()
608 mlxsw_i2c); in mlxsw_i2c_irq_init()
610 dev_err(mlxsw_i2c->bus_info.dev, "Failed to request irq: %d\n", in mlxsw_i2c_irq_init()
618 static void mlxsw_i2c_irq_fini(struct mlxsw_i2c *mlxsw_i2c) in mlxsw_i2c_irq_fini() argument
620 if (!IS_REACHABLE(CONFIG_MLXREG_HOTPLUG) || !mlxsw_i2c->irq) in mlxsw_i2c_irq_fini()
622 cancel_work_sync(&mlxsw_i2c->irq_work); in mlxsw_i2c_irq_fini()
623 free_irq(mlxsw_i2c->irq, mlxsw_i2c); in mlxsw_i2c_irq_fini()
639 struct mlxsw_i2c *mlxsw_i2c; in mlxsw_i2c_probe() local
643 mlxsw_i2c = devm_kzalloc(&client->dev, sizeof(*mlxsw_i2c), GFP_KERNEL); in mlxsw_i2c_probe()
644 if (!mlxsw_i2c) in mlxsw_i2c_probe()
656 mlxsw_i2c->block_size = max_t(u16, MLXSW_I2C_BLK_DEF, in mlxsw_i2c_probe()
660 mlxsw_i2c->block_size = MLXSW_I2C_BLK_DEF; in mlxsw_i2c_probe()
663 i2c_set_clientdata(client, mlxsw_i2c); in mlxsw_i2c_probe()
664 mutex_init(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_probe()
679 err = mlxsw_i2c_write_cmd(client, mlxsw_i2c, 1); in mlxsw_i2c_probe()
686 err = mlxsw_i2c_wait_go_bit(client, mlxsw_i2c, &status); in mlxsw_i2c_probe()
701 err = mlxsw_i2c_get_mbox(client, mlxsw_i2c); in mlxsw_i2c_probe()
708 id->name, mlxsw_i2c->cmd.mb_size_in, in mlxsw_i2c_probe()
709 mlxsw_i2c->cmd.mb_off_in, mlxsw_i2c->cmd.mb_size_out, in mlxsw_i2c_probe()
710 mlxsw_i2c->cmd.mb_off_out); in mlxsw_i2c_probe()
713 mlxsw_i2c->bus_info.device_kind = id->name; in mlxsw_i2c_probe()
714 mlxsw_i2c->bus_info.device_name = client->name; in mlxsw_i2c_probe()
715 mlxsw_i2c->bus_info.dev = &client->dev; in mlxsw_i2c_probe()
716 mlxsw_i2c->bus_info.low_frequency = true; in mlxsw_i2c_probe()
717 mlxsw_i2c->dev = &client->dev; in mlxsw_i2c_probe()
718 mlxsw_i2c->pdata = client->dev.platform_data; in mlxsw_i2c_probe()
720 err = mlxsw_i2c_irq_init(mlxsw_i2c, client->addr); in mlxsw_i2c_probe()
724 err = mlxsw_core_bus_device_register(&mlxsw_i2c->bus_info, in mlxsw_i2c_probe()
725 &mlxsw_i2c_bus, mlxsw_i2c, false, in mlxsw_i2c_probe()
735 mlxsw_i2c_irq_fini(mlxsw_i2c); in mlxsw_i2c_probe()
737 mutex_destroy(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_probe()
745 struct mlxsw_i2c *mlxsw_i2c = i2c_get_clientdata(client); in mlxsw_i2c_remove() local
747 mlxsw_core_bus_device_unregister(mlxsw_i2c->core, false); in mlxsw_i2c_remove()
748 mlxsw_i2c_irq_fini(mlxsw_i2c); in mlxsw_i2c_remove()
749 mutex_destroy(&mlxsw_i2c->cmd.lock); in mlxsw_i2c_remove()