Lines Matching refs:mlxreg_lc
74 struct mlxreg_lc { struct
412 mlxreg_lc_create_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotplug_device *devs, in mlxreg_lc_create_static_devices() argument
422 dev_err(mlxreg_lc->dev, "Failed to create client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_create_static_devices()
443 mlxreg_lc_destroy_static_devices(struct mlxreg_lc *mlxreg_lc, struct mlxreg_hotplug_device *devs, in mlxreg_lc_destroy_static_devices() argument
458 static int mlxreg_lc_power_on_off(struct mlxreg_lc *mlxreg_lc, u8 action) in mlxreg_lc_power_on_off() argument
463 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, ®val); in mlxreg_lc_power_on_off()
468 regval |= BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_power_on_off()
470 regval &= ~BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_power_on_off()
472 err = regmap_write(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, regval); in mlxreg_lc_power_on_off()
478 static int mlxreg_lc_enable_disable(struct mlxreg_lc *mlxreg_lc, bool action) in mlxreg_lc_enable_disable() argument
491 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_ena, ®val); in mlxreg_lc_enable_disable()
496 regval |= BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_enable_disable()
498 regval &= ~BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_enable_disable()
500 err = regmap_write(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_ena, regval); in mlxreg_lc_enable_disable()
507 mlxreg_lc_sn4800_c16_config_init(struct mlxreg_lc *mlxreg_lc, void *regmap, in mlxreg_lc_sn4800_c16_config_init() argument
513 mlxreg_lc->mux_data = mlxreg_lc_mux_data; in mlxreg_lc_sn4800_c16_config_init()
514 mlxreg_lc->io_data = &mlxreg_lc_regs_io; in mlxreg_lc_sn4800_c16_config_init()
515 mlxreg_lc->led_data = &mlxreg_lc_led; in mlxreg_lc_sn4800_c16_config_init()
516 mlxreg_lc->mux_brdinfo = &mlxreg_lc_mux_brdinfo; in mlxreg_lc_sn4800_c16_config_init()
518 mlxreg_lc->aux_devs = devm_kmemdup(dev, mlxreg_lc_aux_pwr_brdinfo, in mlxreg_lc_sn4800_c16_config_init()
520 if (!mlxreg_lc->aux_devs) in mlxreg_lc_sn4800_c16_config_init()
522 mlxreg_lc->aux_devs_num = ARRAY_SIZE(mlxreg_lc_aux_pwr_brdinfo); in mlxreg_lc_sn4800_c16_config_init()
523 mlxreg_lc->main_devs = devm_kmemdup(dev, mlxreg_lc_main_pwr_brdinfo, in mlxreg_lc_sn4800_c16_config_init()
525 if (!mlxreg_lc->main_devs) in mlxreg_lc_sn4800_c16_config_init()
527 mlxreg_lc->main_devs_num = ARRAY_SIZE(mlxreg_lc_main_pwr_brdinfo); in mlxreg_lc_sn4800_c16_config_init()
533 mlxreg_lc_state_update(struct mlxreg_lc *mlxreg_lc, enum mlxreg_lc_state state, u8 action) in mlxreg_lc_state_update() argument
536 mlxreg_lc->state |= state; in mlxreg_lc_state_update()
538 mlxreg_lc->state &= ~state; in mlxreg_lc_state_update()
542 mlxreg_lc_state_update_locked(struct mlxreg_lc *mlxreg_lc, enum mlxreg_lc_state state, u8 action) in mlxreg_lc_state_update_locked() argument
544 mutex_lock(&mlxreg_lc->lock); in mlxreg_lc_state_update_locked()
547 mlxreg_lc->state |= state; in mlxreg_lc_state_update_locked()
549 mlxreg_lc->state &= ~state; in mlxreg_lc_state_update_locked()
551 mutex_unlock(&mlxreg_lc->lock); in mlxreg_lc_state_update_locked()
560 struct mlxreg_lc *mlxreg_lc = handle; in mlxreg_lc_event_handler() local
563 dev_info(mlxreg_lc->dev, "linecard#%d state %d event kind %d action %d\n", in mlxreg_lc_event_handler()
564 mlxreg_lc->data->slot, mlxreg_lc->state, kind, action); in mlxreg_lc_event_handler()
566 mutex_lock(&mlxreg_lc->lock); in mlxreg_lc_event_handler()
567 if (!(mlxreg_lc->state & MLXREG_LC_INITIALIZED)) in mlxreg_lc_event_handler()
576 mlxreg_lc_state_update(mlxreg_lc, MLXREG_LC_SYNCED, action); in mlxreg_lc_event_handler()
578 if (!(mlxreg_lc->state & MLXREG_LC_POWERED) && action) { in mlxreg_lc_event_handler()
579 err = mlxreg_lc_power_on_off(mlxreg_lc, 1); in mlxreg_lc_event_handler()
584 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED && action) in mlxreg_lc_event_handler()
585 err = mlxreg_lc_enable_disable(mlxreg_lc, 1); in mlxreg_lc_event_handler()
591 if (mlxreg_lc->state & MLXREG_LC_POWERED) { in mlxreg_lc_event_handler()
593 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED) in mlxreg_lc_event_handler()
594 err = mlxreg_lc_enable_disable(mlxreg_lc, 1); in mlxreg_lc_event_handler()
598 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_event_handler()
599 mlxreg_lc->main_devs_num); in mlxreg_lc_event_handler()
604 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED) in mlxreg_lc_event_handler()
605 err = mlxreg_lc_enable_disable(mlxreg_lc, 1); in mlxreg_lc_event_handler()
607 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_event_handler()
608 mlxreg_lc->main_devs_num); in mlxreg_lc_event_handler()
610 mlxreg_lc_state_update(mlxreg_lc, MLXREG_LC_POWERED, action); in mlxreg_lc_event_handler()
617 err = mlxreg_lc_enable_disable(mlxreg_lc, !!action); in mlxreg_lc_event_handler()
622 err = mlxreg_lc_power_on_off(mlxreg_lc, 0); in mlxreg_lc_event_handler()
632 mutex_unlock(&mlxreg_lc->lock); in mlxreg_lc_event_handler()
645 struct mlxreg_lc *mlxreg_lc = handle; in mlxreg_lc_completion_notify() local
650 aux_dev = mlxreg_lc->aux_devs; in mlxreg_lc_completion_notify()
651 for (i = 0; i < mlxreg_lc->aux_devs_num; i++, aux_dev++) { in mlxreg_lc_completion_notify()
656 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, in mlxreg_lc_completion_notify()
657 mlxreg_lc->aux_devs_num); in mlxreg_lc_completion_notify()
662 main_dev = mlxreg_lc->main_devs; in mlxreg_lc_completion_notify()
663 for (i = 0; i < mlxreg_lc->main_devs_num; i++, main_dev++) { in mlxreg_lc_completion_notify()
669 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, ®val); in mlxreg_lc_completion_notify()
673 if (regval & mlxreg_lc->data->mask) { in mlxreg_lc_completion_notify()
674 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_completion_notify()
675 mlxreg_lc->main_devs_num); in mlxreg_lc_completion_notify()
679 mlxreg_lc_state_update_locked(mlxreg_lc, MLXREG_LC_POWERED, 1); in mlxreg_lc_completion_notify()
683 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_sync, ®val); in mlxreg_lc_completion_notify()
688 if (regval & mlxreg_lc->data->mask) { in mlxreg_lc_completion_notify()
689 mlxreg_lc->state |= MLXREG_LC_SYNCED; in mlxreg_lc_completion_notify()
690 mlxreg_lc_state_update_locked(mlxreg_lc, MLXREG_LC_SYNCED, 1); in mlxreg_lc_completion_notify()
691 if (mlxreg_lc->state & ~MLXREG_LC_POWERED) { in mlxreg_lc_completion_notify()
692 err = mlxreg_lc_power_on_off(mlxreg_lc, 1); in mlxreg_lc_completion_notify()
698 mlxreg_lc_state_update_locked(mlxreg_lc, MLXREG_LC_INITIALIZED, 1); in mlxreg_lc_completion_notify()
704 if (mlxreg_lc->state & MLXREG_LC_POWERED) in mlxreg_lc_completion_notify()
705 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_completion_notify()
706 mlxreg_lc->main_devs_num); in mlxreg_lc_completion_notify()
708 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, mlxreg_lc->aux_devs_num); in mlxreg_lc_completion_notify()
714 mlxreg_lc_config_init(struct mlxreg_lc *mlxreg_lc, void *regmap, in mlxreg_lc_config_init() argument
729 err = mlxreg_lc_sn4800_c16_config_init(mlxreg_lc, regmap, data); in mlxreg_lc_config_init()
742 mlxreg_lc->mux_data->handle = mlxreg_lc; in mlxreg_lc_config_init()
743 mlxreg_lc->mux_data->completion_notify = mlxreg_lc_completion_notify; in mlxreg_lc_config_init()
744 mlxreg_lc->mux_brdinfo->platform_data = mlxreg_lc->mux_data; in mlxreg_lc_config_init()
745 mlxreg_lc->mux = platform_device_register_resndata(dev, "i2c-mux-mlxcpld", data->hpdev.nr, in mlxreg_lc_config_init()
746 NULL, 0, mlxreg_lc->mux_data, in mlxreg_lc_config_init()
747 sizeof(*mlxreg_lc->mux_data)); in mlxreg_lc_config_init()
748 if (IS_ERR(mlxreg_lc->mux)) { in mlxreg_lc_config_init()
751 return PTR_ERR(mlxreg_lc->mux); in mlxreg_lc_config_init()
755 if (mlxreg_lc->io_data) { in mlxreg_lc_config_init()
756 mlxreg_lc->io_data->regmap = regmap; in mlxreg_lc_config_init()
757 mlxreg_lc->io_regs = in mlxreg_lc_config_init()
759 mlxreg_lc->io_data, sizeof(*mlxreg_lc->io_data)); in mlxreg_lc_config_init()
760 if (IS_ERR(mlxreg_lc->io_regs)) { in mlxreg_lc_config_init()
764 err = PTR_ERR(mlxreg_lc->io_regs); in mlxreg_lc_config_init()
770 if (mlxreg_lc->led_data) { in mlxreg_lc_config_init()
771 mlxreg_lc->led_data->regmap = regmap; in mlxreg_lc_config_init()
772 mlxreg_lc->led = in mlxreg_lc_config_init()
774 mlxreg_lc->led_data, in mlxreg_lc_config_init()
775 sizeof(*mlxreg_lc->led_data)); in mlxreg_lc_config_init()
776 if (IS_ERR(mlxreg_lc->led)) { in mlxreg_lc_config_init()
780 err = PTR_ERR(mlxreg_lc->led); in mlxreg_lc_config_init()
788 if (mlxreg_lc->io_regs) in mlxreg_lc_config_init()
789 platform_device_unregister(mlxreg_lc->io_regs); in mlxreg_lc_config_init()
791 if (mlxreg_lc->mux) in mlxreg_lc_config_init()
792 platform_device_unregister(mlxreg_lc->mux); in mlxreg_lc_config_init()
797 static void mlxreg_lc_config_exit(struct mlxreg_lc *mlxreg_lc) in mlxreg_lc_config_exit() argument
800 if (mlxreg_lc->led) in mlxreg_lc_config_exit()
801 platform_device_unregister(mlxreg_lc->led); in mlxreg_lc_config_exit()
803 if (mlxreg_lc->io_regs) in mlxreg_lc_config_exit()
804 platform_device_unregister(mlxreg_lc->io_regs); in mlxreg_lc_config_exit()
806 if (mlxreg_lc->mux) in mlxreg_lc_config_exit()
807 platform_device_unregister(mlxreg_lc->mux); in mlxreg_lc_config_exit()
814 struct mlxreg_lc *mlxreg_lc; in mlxreg_lc_probe() local
822 mlxreg_lc = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_lc), GFP_KERNEL); in mlxreg_lc_probe()
823 if (!mlxreg_lc) in mlxreg_lc_probe()
826 mutex_init(&mlxreg_lc->lock); in mlxreg_lc_probe()
829 data->notifier->handle = mlxreg_lc; in mlxreg_lc_probe()
880 mlxreg_lc->par_regmap = par_pdata->regmap; in mlxreg_lc_probe()
881 mlxreg_lc->data = data; in mlxreg_lc_probe()
882 mlxreg_lc->dev = &pdev->dev; in mlxreg_lc_probe()
883 platform_set_drvdata(pdev, mlxreg_lc); in mlxreg_lc_probe()
886 err = mlxreg_lc_config_init(mlxreg_lc, regmap, data); in mlxreg_lc_probe()
913 struct mlxreg_lc *mlxreg_lc = platform_get_drvdata(pdev); in mlxreg_lc_remove() local
915 mlxreg_lc_state_update_locked(mlxreg_lc, MLXREG_LC_INITIALIZED, 0); in mlxreg_lc_remove()
931 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_remove()
932 mlxreg_lc->main_devs_num); in mlxreg_lc_remove()
934 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, mlxreg_lc->aux_devs_num); in mlxreg_lc_remove()
936 mlxreg_lc_config_exit(mlxreg_lc); in mlxreg_lc_remove()