2 * Freescale ALSA SoC Machine driver utility
4 * Author: Timur Tabi <timur@freescale.com>
6 * Copyright 2010 Freescale Semiconductor, Inc.
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
13 #include <linux/module.h>
14 #include <linux/of_address.h>
15 #include <sound/soc.h>
17 #include "fsl_utils.h"
20 * fsl_asoc_get_dma_channel - determine the dma channel for a SSI node
22 * @ssi_np: pointer to the SSI device tree node
23 * @name: name of the phandle pointing to the dma channel
24 * @dai: ASoC DAI link pointer to be filled with platform_name
25 * @dma_channel_id: dma channel id to be returned
26 * @dma_id: dma id to be returned
28 * This function determines the dma and channel id for given SSI node. It
29 * also discovers the platform_name for the ASoC DAI link.
31 int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
33 struct snd_soc_dai_link *dai,
34 unsigned int *dma_channel_id,
38 struct device_node *dma_channel_np, *dma_np;
42 dma_channel_np = of_parse_phandle(ssi_np, name, 0);
46 if (!of_device_is_compatible(dma_channel_np, "fsl,ssi-dma-channel")) {
47 of_node_put(dma_channel_np);
51 /* Determine the dev_name for the device_node. This code mimics the
52 * behavior of of_device_make_bus_id(). We need this because ASoC uses
53 * the dev_name() of the device to match the platform (DMA) device with
54 * the CPU (SSI) device. It's all ugly and hackish, but it works (for
57 * dai->platform name should already point to an allocated buffer.
59 ret = of_address_to_resource(dma_channel_np, 0, &res);
61 of_node_put(dma_channel_np);
64 snprintf((char *)dai->platform_name, DAI_NAME_SIZE, "%llx.%s",
65 (unsigned long long) res.start, dma_channel_np->name);
67 iprop = of_get_property(dma_channel_np, "cell-index", NULL);
69 of_node_put(dma_channel_np);
72 *dma_channel_id = be32_to_cpup(iprop);
74 dma_np = of_get_parent(dma_channel_np);
75 iprop = of_get_property(dma_np, "cell-index", NULL);
80 *dma_id = be32_to_cpup(iprop);
83 of_node_put(dma_channel_np);
87 EXPORT_SYMBOL(fsl_asoc_get_dma_channel);
90 * fsl_asoc_xlate_tdm_slot_mask - generate TDM slot TX/RX mask.
92 * @slots: Number of slots in use.
93 * @tx_mask: bitmask representing active TX slots.
94 * @rx_mask: bitmask representing active RX slots.
96 * This function used to generate the TDM slot TX/RX mask. And the TX/RX
97 * mask will use a 0 bit for an active slot as default, and the default
98 * active bits are at the LSB of the mask value.
100 int fsl_asoc_xlate_tdm_slot_mask(unsigned int slots,
101 unsigned int *tx_mask,
102 unsigned int *rx_mask)
108 *tx_mask = ~((1 << slots) - 1);
110 *rx_mask = ~((1 << slots) - 1);
114 EXPORT_SYMBOL_GPL(fsl_asoc_xlate_tdm_slot_mask);
116 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
117 MODULE_DESCRIPTION("Freescale ASoC utility code");
118 MODULE_LICENSE("GPL v2");