Lines Matching refs:cmt
92 struct sh_cmt_device *cmt; member
245 return ch->cmt->info->read_control(ch->iostart, 0); in sh_cmt_read_cmstr()
247 return ch->cmt->info->read_control(ch->cmt->mapbase, 0); in sh_cmt_read_cmstr()
256 ch->cmt->info->write_control(ch->iostart, 0, value); in sh_cmt_write_cmstr()
257 udelay(ch->cmt->reg_delay); in sh_cmt_write_cmstr()
259 ch->cmt->info->write_control(ch->cmt->mapbase, 0, value); in sh_cmt_write_cmstr()
260 udelay(ch->cmt->reg_delay); in sh_cmt_write_cmstr()
267 return ch->cmt->info->read_control(ch->ioctrl, CMCSR); in sh_cmt_read_cmcsr()
275 ch->cmt->info->write_control(ch->ioctrl, CMCSR, value); in sh_cmt_write_cmcsr()
276 udelay(ch->cmt->reg_delay); in sh_cmt_write_cmcsr()
282 return ch->cmt->info->read_count(ch->ioctrl, CMCNT); in sh_cmt_read_cmcnt()
288 unsigned int cmcnt_delay = DIV_ROUND_UP(3 * ch->cmt->reg_delay, 2); in sh_cmt_write_cmcnt()
291 if (ch->cmt->info->model > SH_CMT_16BIT) { in sh_cmt_write_cmcnt()
299 ch->cmt->info->write_count(ch->ioctrl, CMCNT, value); in sh_cmt_write_cmcnt()
306 u32 old_value = ch->cmt->info->read_count(ch->ioctrl, CMCOR); in sh_cmt_write_cmcor()
309 ch->cmt->info->write_count(ch->ioctrl, CMCOR, value); in sh_cmt_write_cmcor()
310 udelay(ch->cmt->reg_delay); in sh_cmt_write_cmcor()
319 o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->info->overflow_bit; in sh_cmt_get_counter()
327 o1 = sh_cmt_read_cmcsr(ch) & ch->cmt->info->overflow_bit; in sh_cmt_get_counter()
341 raw_spin_lock_irqsave(&ch->cmt->lock, flags); in sh_cmt_start_stop_ch()
350 raw_spin_unlock_irqrestore(&ch->cmt->lock, flags); in sh_cmt_start_stop_ch()
357 dev_pm_syscore_device(&ch->cmt->pdev->dev, true); in sh_cmt_enable()
360 ret = clk_enable(ch->cmt->clk); in sh_cmt_enable()
362 dev_err(&ch->cmt->pdev->dev, "ch%u: cannot enable clock\n", in sh_cmt_enable()
371 if (ch->cmt->info->width == 16) { in sh_cmt_enable()
375 u32 cmtout = ch->cmt->info->model <= SH_CMT_48BIT ? in sh_cmt_enable()
386 dev_err(&ch->cmt->pdev->dev, "ch%u: cannot clear CMCNT\n", in sh_cmt_enable()
397 clk_disable(ch->cmt->clk); in sh_cmt_enable()
412 clk_disable(ch->cmt->clk); in sh_cmt_disable()
414 dev_pm_syscore_device(&ch->cmt->pdev->dev, false); in sh_cmt_disable()
504 dev_warn(&ch->cmt->pdev->dev, "ch%u: too long delay\n", in sh_cmt_clock_event_program_verify()
513 dev_warn(&ch->cmt->pdev->dev, "ch%u: delta out of range\n", in __sh_cmt_set_next()
535 ch->cmt->info->clear_bits); in sh_cmt_interrupt()
583 pm_runtime_get_sync(&ch->cmt->pdev->dev); in sh_cmt_start()
589 pm_runtime_get_sync(&ch->cmt->pdev->dev); in sh_cmt_start()
598 if (ch->cmt->num_channels == 1 && in sh_cmt_start()
620 pm_runtime_put(&ch->cmt->pdev->dev); in sh_cmt_stop()
630 pm_runtime_put(&ch->cmt->pdev->dev); in sh_cmt_stop()
643 if (ch->cmt->num_channels == 1) { in sh_cmt_clocksource_read()
696 dev_pm_genpd_suspend(&ch->cmt->pdev->dev); in sh_cmt_clocksource_suspend()
706 dev_pm_genpd_resume(&ch->cmt->pdev->dev); in sh_cmt_clocksource_resume()
722 cs->mask = CLOCKSOURCE_MASK(ch->cmt->info->width); in sh_cmt_register_clocksource()
725 dev_info(&ch->cmt->pdev->dev, "ch%u: used as clock source\n", in sh_cmt_register_clocksource()
728 clocksource_register_hz(cs, ch->cmt->rate); in sh_cmt_register_clocksource()
742 sh_cmt_set_next(ch, ((ch->cmt->rate + HZ/2) / HZ) - 1); in sh_cmt_clock_event_start()
764 dev_info(&ch->cmt->pdev->dev, "ch%u: used for %s clock events\n", in sh_cmt_clock_event_set_state()
798 dev_pm_genpd_suspend(&ch->cmt->pdev->dev); in sh_cmt_clock_event_suspend()
799 clk_unprepare(ch->cmt->clk); in sh_cmt_clock_event_suspend()
806 clk_prepare(ch->cmt->clk); in sh_cmt_clock_event_resume()
807 dev_pm_genpd_resume(&ch->cmt->pdev->dev); in sh_cmt_clock_event_resume()
817 irq = platform_get_irq(ch->cmt->pdev, ch->index); in sh_cmt_register_clockevent()
823 dev_name(&ch->cmt->pdev->dev), ch); in sh_cmt_register_clockevent()
825 dev_err(&ch->cmt->pdev->dev, "ch%u: failed to request irq %d\n", in sh_cmt_register_clockevent()
844 ced->mult = div_sc(ch->cmt->rate, NSEC_PER_SEC, ced->shift); in sh_cmt_register_clockevent()
850 dev_info(&ch->cmt->pdev->dev, "ch%u: used for clock events\n", in sh_cmt_register_clockevent()
863 ch->cmt->has_clockevent = true; in sh_cmt_register()
870 ch->cmt->has_clocksource = true; in sh_cmt_register()
879 bool clocksource, struct sh_cmt_device *cmt) in sh_cmt_setup_channel() argument
888 ch->cmt = cmt; in sh_cmt_setup_channel()
898 switch (cmt->info->model) { in sh_cmt_setup_channel()
900 ch->ioctrl = cmt->mapbase + 2 + ch->hwidx * 6; in sh_cmt_setup_channel()
904 ch->ioctrl = cmt->mapbase + 0x10 + ch->hwidx * 0x10; in sh_cmt_setup_channel()
908 ch->iostart = cmt->mapbase + ch->hwidx * 0x100; in sh_cmt_setup_channel()
913 value = ioread32(cmt->mapbase + CMCLKE); in sh_cmt_setup_channel()
915 iowrite32(value, cmt->mapbase + CMCLKE); in sh_cmt_setup_channel()
919 if (cmt->info->width == (sizeof(ch->max_match_value) * 8)) in sh_cmt_setup_channel()
922 ch->max_match_value = (1 << cmt->info->width) - 1; in sh_cmt_setup_channel()
927 ret = sh_cmt_register(ch, dev_name(&cmt->pdev->dev), in sh_cmt_setup_channel()
930 dev_err(&cmt->pdev->dev, "ch%u: registration failed\n", in sh_cmt_setup_channel()
939 static int sh_cmt_map_memory(struct sh_cmt_device *cmt) in sh_cmt_map_memory() argument
943 mem = platform_get_resource(cmt->pdev, IORESOURCE_MEM, 0); in sh_cmt_map_memory()
945 dev_err(&cmt->pdev->dev, "failed to get I/O memory\n"); in sh_cmt_map_memory()
949 cmt->mapbase = ioremap(mem->start, resource_size(mem)); in sh_cmt_map_memory()
950 if (cmt->mapbase == NULL) { in sh_cmt_map_memory()
951 dev_err(&cmt->pdev->dev, "failed to remap I/O memory\n"); in sh_cmt_map_memory()
1012 static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev) in sh_cmt_setup() argument
1018 cmt->pdev = pdev; in sh_cmt_setup()
1019 raw_spin_lock_init(&cmt->lock); in sh_cmt_setup()
1022 cmt->info = of_device_get_match_data(&pdev->dev); in sh_cmt_setup()
1023 cmt->hw_channels = cmt->info->channels_mask; in sh_cmt_setup()
1028 cmt->info = (const struct sh_cmt_info *)id->driver_data; in sh_cmt_setup()
1029 cmt->hw_channels = cfg->channels_mask; in sh_cmt_setup()
1031 dev_err(&cmt->pdev->dev, "missing platform data\n"); in sh_cmt_setup()
1036 cmt->clk = clk_get(&cmt->pdev->dev, "fck"); in sh_cmt_setup()
1037 if (IS_ERR(cmt->clk)) { in sh_cmt_setup()
1038 dev_err(&cmt->pdev->dev, "cannot get clock\n"); in sh_cmt_setup()
1039 return PTR_ERR(cmt->clk); in sh_cmt_setup()
1042 ret = clk_prepare(cmt->clk); in sh_cmt_setup()
1047 ret = clk_enable(cmt->clk); in sh_cmt_setup()
1051 rate = clk_get_rate(cmt->clk); in sh_cmt_setup()
1058 if (cmt->info->model >= SH_CMT_48BIT) in sh_cmt_setup()
1059 cmt->reg_delay = DIV_ROUND_UP(2UL * USEC_PER_SEC, rate); in sh_cmt_setup()
1060 cmt->rate = rate / (cmt->info->width == 16 ? 512 : 8); in sh_cmt_setup()
1063 ret = sh_cmt_map_memory(cmt); in sh_cmt_setup()
1068 cmt->num_channels = hweight8(cmt->hw_channels); in sh_cmt_setup()
1069 cmt->channels = kcalloc(cmt->num_channels, sizeof(*cmt->channels), in sh_cmt_setup()
1071 if (cmt->channels == NULL) { in sh_cmt_setup()
1080 for (i = 0, mask = cmt->hw_channels; i < cmt->num_channels; ++i) { in sh_cmt_setup()
1082 bool clocksource = i == 1 || cmt->num_channels == 1; in sh_cmt_setup()
1085 ret = sh_cmt_setup_channel(&cmt->channels[i], i, hwidx, in sh_cmt_setup()
1086 clockevent, clocksource, cmt); in sh_cmt_setup()
1093 clk_disable(cmt->clk); in sh_cmt_setup()
1095 platform_set_drvdata(pdev, cmt); in sh_cmt_setup()
1100 kfree(cmt->channels); in sh_cmt_setup()
1101 iounmap(cmt->mapbase); in sh_cmt_setup()
1103 clk_disable(cmt->clk); in sh_cmt_setup()
1105 clk_unprepare(cmt->clk); in sh_cmt_setup()
1107 clk_put(cmt->clk); in sh_cmt_setup()
1113 struct sh_cmt_device *cmt = platform_get_drvdata(pdev); in sh_cmt_probe() local
1121 if (cmt) { in sh_cmt_probe()
1126 cmt = kzalloc(sizeof(*cmt), GFP_KERNEL); in sh_cmt_probe()
1127 if (cmt == NULL) in sh_cmt_probe()
1130 ret = sh_cmt_setup(cmt, pdev); in sh_cmt_probe()
1132 kfree(cmt); in sh_cmt_probe()
1140 if (cmt->has_clockevent || cmt->has_clocksource) in sh_cmt_probe()