static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) { mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; if (cpu_is_omap34xx()) { /* * Initially configure the maximum thresholds to a safe value. * The McBSP FIFO usage with these values should not go under * 16 locations. * If the whole FIFO without safety buffer is used, than there * is a possibility that the DMA will be not able to push the * new data on time, causing channel shifts in runtime. */ mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; /* * REVISIT: Set dmap_op_mode to THRESHOLD as default * for mcbsp2 instances. */ if (omap_additional_add(mcbsp->dev)) dev_warn(mcbsp->dev, "Unable to create additional controls\n"); if (mcbsp->id == 2 || mcbsp->id == 3) if (omap_st_add(mcbsp)) dev_warn(mcbsp->dev, "Unable to create sidetone controls\n"); } else { mcbsp->max_tx_thres = -EINVAL; mcbsp->max_rx_thres = -EINVAL; } }
/* * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. * 730 has only 2 McBSP, and both of them are MPU peripherals. */ int omap_mcbsp_init(struct platform_device *pdev) { struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); struct resource *res; int ret = 0; spin_lock_init(&mcbsp->lock); mcbsp->free = true; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); if (!res) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); mcbsp->io_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(mcbsp->io_base)) return PTR_ERR(mcbsp->io_base); mcbsp->phys_base = res->start; mcbsp->reg_cache_size = resource_size(res); res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); if (!res) mcbsp->phys_dma_base = mcbsp->phys_base; else mcbsp->phys_dma_base = res->start; /* * OMAP1, 2 uses two interrupt lines: TX, RX * OMAP2430, OMAP3 SoC have combined IRQ line as well. * OMAP4 and newer SoC only have the combined IRQ line. * Use the combined IRQ if available since it gives better debugging * possibilities. */ mcbsp->irq = platform_get_irq_byname(pdev, "common"); if (mcbsp->irq == -ENXIO) { mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); if (mcbsp->tx_irq == -ENXIO) { mcbsp->irq = platform_get_irq(pdev, 0); mcbsp->tx_irq = 0; } else { mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); mcbsp->irq = 0; } } if (!pdev->dev.of_node) { res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); if (!res) { dev_err(&pdev->dev, "invalid tx DMA channel\n"); return -ENODEV; } mcbsp->dma_req[0] = res->start; mcbsp->dma_data[0].filter_data = &mcbsp->dma_req[0]; res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); if (!res) { dev_err(&pdev->dev, "invalid rx DMA channel\n"); return -ENODEV; } mcbsp->dma_req[1] = res->start; mcbsp->dma_data[1].filter_data = &mcbsp->dma_req[1]; } else { mcbsp->dma_data[0].filter_data = "tx"; mcbsp->dma_data[1].filter_data = "rx"; } mcbsp->dma_data[0].addr = omap_mcbsp_dma_reg_params(mcbsp, 0); mcbsp->dma_data[0].maxburst = 4; mcbsp->dma_data[1].addr = omap_mcbsp_dma_reg_params(mcbsp, 1); mcbsp->dma_data[1].maxburst = 4; mcbsp->fclk = clk_get(&pdev->dev, "fck"); if (IS_ERR(mcbsp->fclk)) { ret = PTR_ERR(mcbsp->fclk); dev_err(mcbsp->dev, "unable to get fck: %d\n", ret); return ret; } mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; if (mcbsp->pdata->buffer_size) { /* * Initially configure the maximum thresholds to a safe value. * The McBSP FIFO usage with these values should not go under * 16 locations. * If the whole FIFO without safety buffer is used, than there * is a possibility that the DMA will be not able to push the * new data on time, causing channel shifts in runtime. */ mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; ret = sysfs_create_group(&mcbsp->dev->kobj, &additional_attr_group); if (ret) { dev_err(mcbsp->dev, "Unable to create additional controls\n"); goto err_thres; } } else { mcbsp->max_tx_thres = -EINVAL; mcbsp->max_rx_thres = -EINVAL; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone"); if (res) { ret = omap_st_add(mcbsp, res); if (ret) { dev_err(mcbsp->dev, "Unable to create sidetone controls\n"); goto err_st; } } return 0; err_st: if (mcbsp->pdata->buffer_size) sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); err_thres: clk_put(mcbsp->fclk); return ret; }
/* * McBSP1 and McBSP3 are directly mapped on 1610 and 1510. * 730 has only 2 McBSP, and both of them are MPU peripherals. */ static int __devinit omap_mcbsp_probe(struct platform_device *pdev) { struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data; struct omap_mcbsp *mcbsp; int id = pdev->id - 1; struct resource *res; int ret = 0; if (!pdata) { dev_err(&pdev->dev, "McBSP device initialized without" "platform data\n"); ret = -EINVAL; goto exit; } dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id); if (id >= omap_mcbsp_count) { dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id); ret = -EINVAL; goto exit; } mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL); if (!mcbsp) { ret = -ENOMEM; goto exit; } spin_lock_init(&mcbsp->lock); mcbsp->id = id + 1; mcbsp->free = true; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); if (!res) { res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(&pdev->dev, "%s:mcbsp%d has invalid memory" "resource\n", __func__, pdev->id); ret = -ENOMEM; goto exit; } } mcbsp->phys_base = res->start; mcbsp->reg_cache_size = resource_size(res); mcbsp->io_base = ioremap(res->start, resource_size(res)); if (!mcbsp->io_base) { ret = -ENOMEM; goto err_ioremap; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); if (!res) mcbsp->phys_dma_base = mcbsp->phys_base; else mcbsp->phys_dma_base = res->start; mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); /* From OMAP4 there will be a single irq line */ if (mcbsp->tx_irq == -ENXIO) mcbsp->tx_irq = platform_get_irq(pdev, 0); res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); if (!res) { dev_err(&pdev->dev, "%s:mcbsp%d has invalid rx DMA channel\n", __func__, pdev->id); ret = -ENODEV; goto err_res; } mcbsp->dma_rx_sync = res->start; res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); if (!res) { dev_err(&pdev->dev, "%s:mcbsp%d has invalid tx DMA channel\n", __func__, pdev->id); ret = -ENODEV; goto err_res; } mcbsp->dma_tx_sync = res->start; mcbsp->fclk = clk_get(&pdev->dev, "fck"); if (IS_ERR(mcbsp->fclk)) { ret = PTR_ERR(mcbsp->fclk); dev_err(&pdev->dev, "unable to get fck: %d\n", ret); goto err_res; } mcbsp->pdata = pdata; mcbsp->dev = &pdev->dev; mcbsp_ptr[id] = mcbsp; platform_set_drvdata(pdev, mcbsp); pm_runtime_enable(mcbsp->dev); mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; if (mcbsp->pdata->buffer_size) { /* * Initially configure the maximum thresholds to a safe value. * The McBSP FIFO usage with these values should not go under * 16 locations. * If the whole FIFO without safety buffer is used, than there * is a possibility that the DMA will be not able to push the * new data on time, causing channel shifts in runtime. */ mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; ret = sysfs_create_group(&mcbsp->dev->kobj, &additional_attr_group); if (ret) { dev_err(mcbsp->dev, "Unable to create additional controls\n"); goto err_thres; } } else { mcbsp->max_tx_thres = -EINVAL; mcbsp->max_rx_thres = -EINVAL; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone"); if (res) { ret = omap_st_add(mcbsp, res); if (ret) { dev_err(mcbsp->dev, "Unable to create sidetone controls\n"); goto err_st; } } return 0; err_st: if (mcbsp->pdata->buffer_size) sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); err_thres: clk_put(mcbsp->fclk); err_res: iounmap(mcbsp->io_base); err_ioremap: kfree(mcbsp); exit: return ret; }
int __devinit omap_mcbsp_init(struct platform_device *pdev) { struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev); struct resource *res; int ret = 0; spin_lock_init(&mcbsp->lock); mcbsp->free = true; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); if (!res) { res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { dev_err(mcbsp->dev, "invalid memory resource\n"); return -ENOMEM; } } if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res), dev_name(&pdev->dev))) { dev_err(mcbsp->dev, "memory region already claimed\n"); return -ENODEV; } mcbsp->phys_base = res->start; mcbsp->reg_cache_size = resource_size(res); mcbsp->io_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!mcbsp->io_base) return -ENOMEM; res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma"); if (!res) mcbsp->phys_dma_base = mcbsp->phys_base; else mcbsp->phys_dma_base = res->start; mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx"); mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx"); if (mcbsp->tx_irq == -ENXIO) { mcbsp->tx_irq = platform_get_irq(pdev, 0); mcbsp->rx_irq = 0; } res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx"); if (!res) { dev_err(&pdev->dev, "invalid rx DMA channel\n"); return -ENODEV; } mcbsp->dma_data[1].name = "Audio Capture"; mcbsp->dma_data[1].dma_req = res->start; mcbsp->dma_data[1].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 1); res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx"); if (!res) { dev_err(&pdev->dev, "invalid tx DMA channel\n"); return -ENODEV; } mcbsp->dma_data[0].name = "Audio Playback"; mcbsp->dma_data[0].dma_req = res->start; mcbsp->dma_data[0].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 0); mcbsp->fclk = clk_get(&pdev->dev, "fck"); if (IS_ERR(mcbsp->fclk)) { ret = PTR_ERR(mcbsp->fclk); dev_err(mcbsp->dev, "unable to get fck: %d\n", ret); return ret; } mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT; if (mcbsp->pdata->buffer_size) { mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10; mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10; ret = sysfs_create_group(&mcbsp->dev->kobj, &additional_attr_group); if (ret) { dev_err(mcbsp->dev, "Unable to create additional controls\n"); goto err_thres; } } else { mcbsp->max_tx_thres = -EINVAL; mcbsp->max_rx_thres = -EINVAL; } res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone"); if (res) { ret = omap_st_add(mcbsp, res); if (ret) { dev_err(mcbsp->dev, "Unable to create sidetone controls\n"); goto err_st; } } return 0; err_st: if (mcbsp->pdata->buffer_size) sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group); err_thres: clk_put(mcbsp->fclk); return ret; }