Lines Matching +full:dclk +full:- +full:div

1 // SPDX-License-Identifier: GPL-2.0-only
25 #include <linux/dma-map-ops.h>
30 #include <asm/mach-types.h>
107 int irq_base; /* base for cascaded on-chip IRQs */
199 return irq_create_mapping(sachip->irqdomain, hwirq); in sa1111_map_irq()
212 void __iomem *mapbase = sachip->base + SA1111_INTC; in sa1111_irq_handler()
219 desc->irq_data.chip->irq_ack(&desc->irq_data); in sa1111_irq_handler()
228 irqdomain = sachip->irqdomain; in sa1111_irq_handler()
238 /* For level-based interrupts */ in sa1111_irq_handler()
239 desc->irq_data.chip->irq_unmask(&desc->irq_data); in sa1111_irq_handler()
259 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d); in sa1111_mask_irq()
270 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d); in sa1111_unmask_irq()
279 * Attempt to re-trigger the interrupt. The SA1111 contains a register
283 * INTSET to re-trigger the interrupt.
288 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d); in sa1111_retrigger_irq()
301 pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n", in sa1111_retrigger_irq()
302 d->irq); in sa1111_retrigger_irq()
312 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d); in sa1111_type_irq()
319 return -EINVAL; in sa1111_type_irq()
335 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d); in sa1111_wake_irq()
361 struct sa1111 *sachip = d->host_data; in sa1111_irqdomain_map()
365 return -EINVAL; in sa1111_irqdomain_map()
381 void __iomem *irqbase = sachip->base + SA1111_INTC; in sa1111_setup_irq()
387 request_mem_region(sachip->phys + SA1111_INTC, 512, "irq"); in sa1111_setup_irq()
389 ret = irq_alloc_descs(-1, irq_base, SA1111_IRQ_NR, -1); in sa1111_setup_irq()
391 dev_err(sachip->dev, "unable to allocate %u irqs: %d\n", in sa1111_setup_irq()
394 ret = -EINVAL; in sa1111_setup_irq()
398 sachip->irq_base = ret; in sa1111_setup_irq()
419 sachip->irqdomain = irq_domain_add_linear(NULL, SA1111_IRQ_NR, in sa1111_setup_irq()
422 if (!sachip->irqdomain) { in sa1111_setup_irq()
423 irq_free_descs(sachip->irq_base, SA1111_IRQ_NR); in sa1111_setup_irq()
424 return -ENOMEM; in sa1111_setup_irq()
427 irq_domain_associate_many(sachip->irqdomain, in sa1111_setup_irq()
428 sachip->irq_base + IRQ_GPAIN0, in sa1111_setup_irq()
429 IRQ_GPAIN0, SSPROR + 1 - IRQ_GPAIN0); in sa1111_setup_irq()
430 irq_domain_associate_many(sachip->irqdomain, in sa1111_setup_irq()
431 sachip->irq_base + AUDXMTDMADONEA, in sa1111_setup_irq()
433 IRQ_S1_BVD1_STSCHG + 1 - AUDXMTDMADONEA); in sa1111_setup_irq()
438 irq_set_irq_type(sachip->irq, IRQ_TYPE_EDGE_RISING); in sa1111_setup_irq()
439 irq_set_chained_handler_and_data(sachip->irq, sa1111_irq_handler, in sa1111_setup_irq()
442 dev_info(sachip->dev, "Providing IRQ%u-%u\n", in sa1111_setup_irq()
443 sachip->irq_base, sachip->irq_base + SA1111_IRQ_NR - 1); in sa1111_setup_irq()
450 struct irq_domain *domain = sachip->irqdomain; in sa1111_remove_irq()
451 void __iomem *irqbase = sachip->base + SA1111_INTC; in sa1111_remove_irq()
460 irq_set_chained_handler_and_data(sachip->irq, NULL, NULL); in sa1111_remove_irq()
465 release_mem_region(sachip->phys + SA1111_INTC, 512); in sa1111_remove_irq()
469 SA1111_GPIO_PXDDR = (SA1111_GPIO_PADDR - SA1111_GPIO_PADDR),
470 SA1111_GPIO_PXDRR = (SA1111_GPIO_PADRR - SA1111_GPIO_PADDR),
471 SA1111_GPIO_PXDWR = (SA1111_GPIO_PADWR - SA1111_GPIO_PADDR),
472 SA1111_GPIO_PXSDR = (SA1111_GPIO_PASDR - SA1111_GPIO_PADDR),
473 SA1111_GPIO_PXSSR = (SA1111_GPIO_PASSR - SA1111_GPIO_PADDR),
483 void __iomem *reg = sachip->base + SA1111_GPIO; in sa1111_gpio_map_reg()
499 return BIT(offset - 4); in sa1111_gpio_map_bit()
501 return BIT(offset - 10); in sa1111_gpio_map_bit()
531 spin_lock_irqsave(&sachip->lock, flags); in sa1111_gpio_direction_input()
534 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_gpio_direction_input()
547 spin_lock_irqsave(&sachip->lock, flags); in sa1111_gpio_direction_output()
552 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_gpio_direction_output()
573 spin_lock_irqsave(&sachip->lock, flags); in sa1111_gpio_set()
576 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_gpio_set()
584 void __iomem *reg = sachip->base + SA1111_GPIO; in sa1111_gpio_set_multiple()
590 spin_lock_irqsave(&sachip->lock, flags); in sa1111_gpio_set_multiple()
597 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_gpio_set_multiple()
609 sachip->gc.label = "sa1111"; in sa1111_setup_gpios()
610 sachip->gc.parent = sachip->dev; in sa1111_setup_gpios()
611 sachip->gc.owner = THIS_MODULE; in sa1111_setup_gpios()
612 sachip->gc.get_direction = sa1111_gpio_get_direction; in sa1111_setup_gpios()
613 sachip->gc.direction_input = sa1111_gpio_direction_input; in sa1111_setup_gpios()
614 sachip->gc.direction_output = sa1111_gpio_direction_output; in sa1111_setup_gpios()
615 sachip->gc.get = sa1111_gpio_get; in sa1111_setup_gpios()
616 sachip->gc.set = sa1111_gpio_set; in sa1111_setup_gpios()
617 sachip->gc.set_multiple = sa1111_gpio_set_multiple; in sa1111_setup_gpios()
618 sachip->gc.to_irq = sa1111_gpio_to_irq; in sa1111_setup_gpios()
619 sachip->gc.base = -1; in sa1111_setup_gpios()
620 sachip->gc.ngpio = 18; in sa1111_setup_gpios()
622 return devm_gpiochip_add_data(sachip->dev, &sachip->gc, sachip); in sa1111_setup_gpios()
643 spin_lock_irqsave(&sachip->lock, flags); in sa1111_wake()
645 clk_enable(sachip->clk); in sa1111_wake()
650 r = readl_relaxed(sachip->base + SA1111_SKCR); in sa1111_wake()
652 writel_relaxed(r, sachip->base + SA1111_SKCR); in sa1111_wake()
654 writel_relaxed(r, sachip->base + SA1111_SKCR); in sa1111_wake()
666 writel_relaxed(r, sachip->base + SA1111_SKCR); in sa1111_wake()
677 writel_relaxed(0, sachip->base + SA1111_SKPCR); in sa1111_wake()
679 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_wake()
707 writel_relaxed(smcr, sachip->base + SA1111_SMCR); in sa1111_configure_smc()
711 * DMA erratum (Intel StrongARM SA-1111 Microprocessor Companion in sa1111_configure_smc()
714 if (sachip->dev->dma_mask) in sa1111_configure_smc()
715 *sachip->dev->dma_mask &= sa1111_dma_mask[drac >> 2]; in sa1111_configure_smc()
717 sachip->dev->coherent_dma_mask &= sa1111_dma_mask[drac >> 2]; in sa1111_configure_smc()
738 ret = -ENOMEM; in sa1111_init_one_child()
742 device_initialize(&dev->dev); in sa1111_init_one_child()
743 dev_set_name(&dev->dev, "%4.4lx", info->offset); in sa1111_init_one_child()
744 dev->devid = info->devid; in sa1111_init_one_child()
745 dev->dev.parent = sachip->dev; in sa1111_init_one_child()
746 dev->dev.bus = &sa1111_bus_type; in sa1111_init_one_child()
747 dev->dev.release = sa1111_dev_release; in sa1111_init_one_child()
748 dev->res.start = sachip->phys + info->offset; in sa1111_init_one_child()
749 dev->res.end = dev->res.start + 511; in sa1111_init_one_child()
750 dev->res.name = dev_name(&dev->dev); in sa1111_init_one_child()
751 dev->res.flags = IORESOURCE_MEM; in sa1111_init_one_child()
752 dev->mapbase = sachip->base + info->offset; in sa1111_init_one_child()
753 dev->skpcr_mask = info->skpcr_mask; in sa1111_init_one_child()
755 for (i = 0; i < ARRAY_SIZE(info->hwirq); i++) in sa1111_init_one_child()
756 dev->hwirq[i] = info->hwirq[i]; in sa1111_init_one_child()
762 if (info->dma && sachip->dev->dma_mask) { in sa1111_init_one_child()
763 dev->dma_mask = *sachip->dev->dma_mask; in sa1111_init_one_child()
764 dev->dev.dma_mask = &dev->dma_mask; in sa1111_init_one_child()
765 dev->dev.coherent_dma_mask = sachip->dev->coherent_dma_mask; in sa1111_init_one_child()
768 ret = request_resource(parent, &dev->res); in sa1111_init_one_child()
770 dev_err(sachip->dev, "failed to allocate resource for %s\n", in sa1111_init_one_child()
771 dev->res.name); in sa1111_init_one_child()
775 ret = device_add(&dev->dev); in sa1111_init_one_child()
781 release_resource(&dev->res); in sa1111_init_one_child()
783 put_device(&dev->dev); in sa1111_init_one_child()
790 struct sa1111_platform_data *pd = me->platform_data; in __sa1111_probe()
794 int i, ret = -ENODEV; in __sa1111_probe()
797 return -EINVAL; in __sa1111_probe()
801 return -ENOMEM; in __sa1111_probe()
803 sachip->clk = devm_clk_get(me, "SA1111_CLK"); in __sa1111_probe()
804 if (IS_ERR(sachip->clk)) in __sa1111_probe()
805 return PTR_ERR(sachip->clk); in __sa1111_probe()
807 ret = clk_prepare(sachip->clk); in __sa1111_probe()
811 spin_lock_init(&sachip->lock); in __sa1111_probe()
813 sachip->dev = me; in __sa1111_probe()
814 dev_set_drvdata(sachip->dev, sachip); in __sa1111_probe()
816 sachip->pdata = pd; in __sa1111_probe()
817 sachip->phys = mem->start; in __sa1111_probe()
818 sachip->irq = irq; in __sa1111_probe()
824 sachip->base = ioremap(mem->start, PAGE_SIZE * 2); in __sa1111_probe()
825 if (!sachip->base) { in __sa1111_probe()
826 ret = -ENOMEM; in __sa1111_probe()
833 id = readl_relaxed(sachip->base + SA1111_SKID); in __sa1111_probe()
836 ret = -ENODEV; in __sa1111_probe()
852 ret = sa1111_setup_irq(sachip, pd->irq_base); in __sa1111_probe()
856 /* Setup the GPIOs - should really be done after the IRQ setup */ in __sa1111_probe()
877 * We only need to turn on DCLK whenever we want to use the in __sa1111_probe()
881 val = readl_relaxed(sachip->base + SA1111_SKPCR); in __sa1111_probe()
882 writel_relaxed(val | SKPCR_DCLKEN, sachip->base + SA1111_SKPCR); in __sa1111_probe()
895 has_devs &= ~pd->disable_devs; in __sa1111_probe()
906 clk_disable(sachip->clk); in __sa1111_probe()
908 iounmap(sachip->base); in __sa1111_probe()
910 clk_unprepare(sachip->clk); in __sa1111_probe()
917 if (dev->bus != &sa1111_bus_type) in sa1111_remove_one()
919 device_del(&sadev->dev); in sa1111_remove_one()
920 release_resource(&sadev->res); in sa1111_remove_one()
921 put_device(&sadev->dev); in sa1111_remove_one()
927 device_for_each_child(sachip->dev, NULL, sa1111_remove_one); in __sa1111_remove()
931 clk_disable(sachip->clk); in __sa1111_remove()
932 clk_unprepare(sachip->clk); in __sa1111_remove()
934 iounmap(sachip->base); in __sa1111_remove()
970 return -ENOMEM; in sa1111_suspend_noirq()
971 sachip->saved_state = save; in sa1111_suspend_noirq()
973 spin_lock_irqsave(&sachip->lock, flags); in sa1111_suspend_noirq()
978 base = sachip->base; in sa1111_suspend_noirq()
979 save->skcr = readl_relaxed(base + SA1111_SKCR); in sa1111_suspend_noirq()
980 save->skpcr = readl_relaxed(base + SA1111_SKPCR); in sa1111_suspend_noirq()
981 save->skcdr = readl_relaxed(base + SA1111_SKCDR); in sa1111_suspend_noirq()
982 save->skaud = readl_relaxed(base + SA1111_SKAUD); in sa1111_suspend_noirq()
983 save->skpwm0 = readl_relaxed(base + SA1111_SKPWM0); in sa1111_suspend_noirq()
984 save->skpwm1 = readl_relaxed(base + SA1111_SKPWM1); in sa1111_suspend_noirq()
986 writel_relaxed(0, sachip->base + SA1111_SKPWM0); in sa1111_suspend_noirq()
987 writel_relaxed(0, sachip->base + SA1111_SKPWM1); in sa1111_suspend_noirq()
989 base = sachip->base + SA1111_INTC; in sa1111_suspend_noirq()
990 save->intpol0 = readl_relaxed(base + SA1111_INTPOL0); in sa1111_suspend_noirq()
991 save->intpol1 = readl_relaxed(base + SA1111_INTPOL1); in sa1111_suspend_noirq()
992 save->inten0 = readl_relaxed(base + SA1111_INTEN0); in sa1111_suspend_noirq()
993 save->inten1 = readl_relaxed(base + SA1111_INTEN1); in sa1111_suspend_noirq()
994 save->wakepol0 = readl_relaxed(base + SA1111_WAKEPOL0); in sa1111_suspend_noirq()
995 save->wakepol1 = readl_relaxed(base + SA1111_WAKEPOL1); in sa1111_suspend_noirq()
996 save->wakeen0 = readl_relaxed(base + SA1111_WAKEEN0); in sa1111_suspend_noirq()
997 save->wakeen1 = readl_relaxed(base + SA1111_WAKEEN1); in sa1111_suspend_noirq()
1002 val = readl_relaxed(sachip->base + SA1111_SKCR); in sa1111_suspend_noirq()
1003 writel_relaxed(val | SKCR_SLEEP, sachip->base + SA1111_SKCR); in sa1111_suspend_noirq()
1005 clk_disable(sachip->clk); in sa1111_suspend_noirq()
1007 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_suspend_noirq()
1017 * sa1111_resume - Restore the SA1111 device state.
1032 save = sachip->saved_state; in sa1111_resume_noirq()
1040 id = readl_relaxed(sachip->base + SA1111_SKID); in sa1111_resume_noirq()
1062 spin_lock_irqsave(&sachip->lock, flags); in sa1111_resume_noirq()
1064 writel_relaxed(0, sachip->base + SA1111_INTC + SA1111_INTEN0); in sa1111_resume_noirq()
1065 writel_relaxed(0, sachip->base + SA1111_INTC + SA1111_INTEN1); in sa1111_resume_noirq()
1067 base = sachip->base; in sa1111_resume_noirq()
1068 writel_relaxed(save->skcr, base + SA1111_SKCR); in sa1111_resume_noirq()
1069 writel_relaxed(save->skpcr, base + SA1111_SKPCR); in sa1111_resume_noirq()
1070 writel_relaxed(save->skcdr, base + SA1111_SKCDR); in sa1111_resume_noirq()
1071 writel_relaxed(save->skaud, base + SA1111_SKAUD); in sa1111_resume_noirq()
1072 writel_relaxed(save->skpwm0, base + SA1111_SKPWM0); in sa1111_resume_noirq()
1073 writel_relaxed(save->skpwm1, base + SA1111_SKPWM1); in sa1111_resume_noirq()
1075 base = sachip->base + SA1111_INTC; in sa1111_resume_noirq()
1076 writel_relaxed(save->intpol0, base + SA1111_INTPOL0); in sa1111_resume_noirq()
1077 writel_relaxed(save->intpol1, base + SA1111_INTPOL1); in sa1111_resume_noirq()
1078 writel_relaxed(save->inten0, base + SA1111_INTEN0); in sa1111_resume_noirq()
1079 writel_relaxed(save->inten1, base + SA1111_INTEN1); in sa1111_resume_noirq()
1080 writel_relaxed(save->wakepol0, base + SA1111_WAKEPOL0); in sa1111_resume_noirq()
1081 writel_relaxed(save->wakepol1, base + SA1111_WAKEPOL1); in sa1111_resume_noirq()
1082 writel_relaxed(save->wakeen0, base + SA1111_WAKEEN0); in sa1111_resume_noirq()
1083 writel_relaxed(save->wakeen1, base + SA1111_WAKEEN1); in sa1111_resume_noirq()
1085 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_resume_noirq()
1087 sachip->saved_state = NULL; in sa1111_resume_noirq()
1099 * sa1111_probe - probe for a single SA1111 chip.
1103 * before any other SA1111-specific code.
1106 * * %-ENODEV - device not found.
1107 * * %-ENOMEM - memory allocation failure.
1108 * * %-EBUSY - physical address already marked in-use.
1109 * * %-EINVAL - no platform data passed
1110 * * %0 - successful.
1119 return -EINVAL; in sa1111_probe()
1124 return __sa1111_probe(&pdev->dev, mem, irq); in sa1111_probe()
1133 kfree(sachip->saved_state); in sa1111_remove()
1134 sachip->saved_state = NULL; in sa1111_remove()
1149 * the per-machine level, and then have this driver pick
1170 return (struct sa1111 *)dev_get_drvdata(sadev->dev.parent); in sa1111_chip_driver()
1174 * The bits in the opdiv field are non-linear.
1182 skcdr = readl_relaxed(sachip->base + SA1111_SKCDR); in __sa1111_pll_clock()
1192 * sa1111_pll_clock - return the current PLL clock frequency.
1209 * sa1111_select_audio_mode - select I2S or AC link mode
1222 spin_lock_irqsave(&sachip->lock, flags); in sa1111_select_audio_mode()
1224 val = readl_relaxed(sachip->base + SA1111_SKCR); in sa1111_select_audio_mode()
1230 writel_relaxed(val, sachip->base + SA1111_SKCR); in sa1111_select_audio_mode()
1232 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_select_audio_mode()
1237 * sa1111_set_audio_rate - set the audio sample rate
1244 unsigned int div; in sa1111_set_audio_rate() local
1246 if (sadev->devid != SA1111_DEVID_SAC) in sa1111_set_audio_rate()
1247 return -EINVAL; in sa1111_set_audio_rate()
1249 div = (__sa1111_pll_clock(sachip) / 256 + rate / 2) / rate; in sa1111_set_audio_rate()
1250 if (div == 0) in sa1111_set_audio_rate()
1251 div = 1; in sa1111_set_audio_rate()
1252 if (div > 128) in sa1111_set_audio_rate()
1253 div = 128; in sa1111_set_audio_rate()
1255 writel_relaxed(div - 1, sachip->base + SA1111_SKAUD); in sa1111_set_audio_rate()
1262 * sa1111_get_audio_rate - get the audio sample rate
1268 unsigned long div; in sa1111_get_audio_rate() local
1270 if (sadev->devid != SA1111_DEVID_SAC) in sa1111_get_audio_rate()
1271 return -EINVAL; in sa1111_get_audio_rate()
1273 div = readl_relaxed(sachip->base + SA1111_SKAUD) + 1; in sa1111_get_audio_rate()
1275 return __sa1111_pll_clock(sachip) / (256 * div); in sa1111_get_audio_rate()
1284 * sa1111_enable_device - enable an on-chip SA1111 function block
1294 if (sachip->pdata && sachip->pdata->enable) in sa1111_enable_device()
1295 ret = sachip->pdata->enable(sachip->pdata->data, sadev->devid); in sa1111_enable_device()
1298 spin_lock_irqsave(&sachip->lock, flags); in sa1111_enable_device()
1299 val = readl_relaxed(sachip->base + SA1111_SKPCR); in sa1111_enable_device()
1300 writel_relaxed(val | sadev->skpcr_mask, sachip->base + SA1111_SKPCR); in sa1111_enable_device()
1301 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_enable_device()
1308 * sa1111_disable_device - disable an on-chip SA1111 function block
1317 spin_lock_irqsave(&sachip->lock, flags); in sa1111_disable_device()
1318 val = readl_relaxed(sachip->base + SA1111_SKPCR); in sa1111_disable_device()
1319 writel_relaxed(val & ~sadev->skpcr_mask, sachip->base + SA1111_SKPCR); in sa1111_disable_device()
1320 spin_unlock_irqrestore(&sachip->lock, flags); in sa1111_disable_device()
1322 if (sachip->pdata && sachip->pdata->disable) in sa1111_disable_device()
1323 sachip->pdata->disable(sachip->pdata->data, sadev->devid); in sa1111_disable_device()
1330 if (num >= ARRAY_SIZE(sadev->hwirq)) in sa1111_get_irq()
1331 return -EINVAL; in sa1111_get_irq()
1332 return sa1111_map_irq(sachip, sadev->hwirq[num]); in sa1111_get_irq()
1347 return !!(dev->devid & drv->devid); in sa1111_match()
1353 struct sa1111_driver *drv = SA1111_DRV(dev->driver); in sa1111_bus_probe()
1354 int ret = -ENODEV; in sa1111_bus_probe()
1356 if (drv->probe) in sa1111_bus_probe()
1357 ret = drv->probe(sadev); in sa1111_bus_probe()
1364 struct sa1111_driver *drv = SA1111_DRV(dev->driver); in sa1111_bus_remove()
1366 if (drv->remove) in sa1111_bus_remove()
1367 drv->remove(sadev); in sa1111_bus_remove()
1371 .name = "sa1111-rab",
1380 driver->drv.bus = &sa1111_bus_type; in sa1111_driver_register()
1381 return driver_register(&driver->drv); in sa1111_driver_register()
1387 driver_unregister(&driver->drv); in sa1111_driver_unregister()