aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/address.c110
-rw-r--r--drivers/of/platform.c65
2 files changed, 169 insertions, 6 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 95351b2a112c..5edfcb0da37d 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -701,3 +701,113 @@ void __iomem *of_iomap(struct device_node *np, int index)
701 return ioremap(res.start, resource_size(&res)); 701 return ioremap(res.start, resource_size(&res));
702} 702}
703EXPORT_SYMBOL(of_iomap); 703EXPORT_SYMBOL(of_iomap);
704
705/**
706 * of_dma_get_range - Get DMA range info
707 * @np: device node to get DMA range info
708 * @dma_addr: pointer to store initial DMA address of DMA range
709 * @paddr: pointer to store initial CPU address of DMA range
710 * @size: pointer to store size of DMA range
711 *
712 * Look in bottom up direction for the first "dma-ranges" property
713 * and parse it.
714 * dma-ranges format:
715 * DMA addr (dma_addr) : naddr cells
716 * CPU addr (phys_addr_t) : pna cells
717 * size : nsize cells
718 *
719 * It returns -ENODEV if "dma-ranges" property was not found
720 * for this device in DT.
721 */
722int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size)
723{
724 struct device_node *node = of_node_get(np);
725 const __be32 *ranges = NULL;
726 int len, naddr, nsize, pna;
727 int ret = 0;
728 u64 dmaaddr;
729
730 if (!node)
731 return -EINVAL;
732
733 while (1) {
734 naddr = of_n_addr_cells(node);
735 nsize = of_n_size_cells(node);
736 node = of_get_next_parent(node);
737 if (!node)
738 break;
739
740 ranges = of_get_property(node, "dma-ranges", &len);
741
742 /* Ignore empty ranges, they imply no translation required */
743 if (ranges && len > 0)
744 break;
745
746 /*
747 * At least empty ranges has to be defined for parent node if
748 * DMA is supported
749 */
750 if (!ranges)
751 break;
752 }
753
754 if (!ranges) {
755 pr_debug("%s: no dma-ranges found for node(%s)\n",
756 __func__, np->full_name);
757 ret = -ENODEV;
758 goto out;
759 }
760
761 len /= sizeof(u32);
762
763 pna = of_n_addr_cells(node);
764
765 /* dma-ranges format:
766 * DMA addr : naddr cells
767 * CPU addr : pna cells
768 * size : nsize cells
769 */
770 dmaaddr = of_read_number(ranges, naddr);
771 *paddr = of_translate_dma_address(np, ranges);
772 if (*paddr == OF_BAD_ADDR) {
773 pr_err("%s: translation of DMA address(%pad) to CPU address failed node(%s)\n",
774 __func__, dma_addr, np->full_name);
775 ret = -EINVAL;
776 goto out;
777 }
778 *dma_addr = dmaaddr;
779
780 *size = of_read_number(ranges + naddr + pna, nsize);
781
782 pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n",
783 *dma_addr, *paddr, *size);
784
785out:
786 of_node_put(node);
787
788 return ret;
789}
790EXPORT_SYMBOL_GPL(of_dma_get_range);
791
792/**
793 * of_dma_is_coherent - Check if device is coherent
794 * @np: device node
795 *
796 * It returns true if "dma-coherent" property was found
797 * for this device in DT.
798 */
799bool of_dma_is_coherent(struct device_node *np)
800{
801 struct device_node *node = of_node_get(np);
802
803 while (node) {
804 if (of_property_read_bool(node, "dma-coherent")) {
805 of_node_put(node);
806 return true;
807 }
808 node = of_get_next_parent(node);
809 }
810 of_node_put(node);
811 return false;
812}
813EXPORT_SYMBOL_GPL(of_dma_is_coherent);
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 92c060e58b02..d90a02d89f51 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -153,6 +153,64 @@ struct platform_device *of_device_alloc(struct device_node *np,
153EXPORT_SYMBOL(of_device_alloc); 153EXPORT_SYMBOL(of_device_alloc);
154 154
155/** 155/**
156 * of_dma_configure - Setup DMA configuration
157 * @dev: Device to apply DMA configuration
158 *
159 * Try to get devices's DMA configuration from DT and update it
160 * accordingly.
161 *
162 * In case if platform code need to use own special DMA configuration,it
163 * can use Platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE event
164 * to fix up DMA configuration.
165 */
166static void of_dma_configure(struct platform_device *pdev)
167{
168 u64 dma_addr, paddr, size;
169 int ret;
170 struct device *dev = &pdev->dev;
171
172#if defined(CONFIG_MICROBLAZE)
173 pdev->archdata.dma_mask = 0xffffffffUL;
174#endif
175
176 /*
177 * Set default dma-mask to 32 bit. Drivers are expected to setup
178 * the correct supported dma_mask.
179 */
180 dev->coherent_dma_mask = DMA_BIT_MASK(32);
181
182 /*
183 * Set it to coherent_dma_mask by default if the architecture
184 * code has not set it.
185 */
186 if (!dev->dma_mask)
187 dev->dma_mask = &dev->coherent_dma_mask;
188
189 /*
190 * if dma-coherent property exist, call arch hook to setup
191 * dma coherent operations.
192 */
193 if (of_dma_is_coherent(dev->of_node)) {
194 set_arch_dma_coherent_ops(dev);
195 dev_dbg(dev, "device is dma coherent\n");
196 }
197
198 /*
199 * if dma-ranges property doesn't exist - just return else
200 * setup the dma offset
201 */
202 ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size);
203 if (ret < 0) {
204 dev_dbg(dev, "no dma range information to setup\n");
205 return;
206 }
207
208 /* DMA ranges found. Calculate and set dma_pfn_offset */
209 dev->dma_pfn_offset = PFN_DOWN(paddr - dma_addr);
210 dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", dev->dma_pfn_offset);
211}
212
213/**
156 * of_platform_device_create_pdata - Alloc, initialize and register an of_device 214 * of_platform_device_create_pdata - Alloc, initialize and register an of_device
157 * @np: pointer to node to create device for 215 * @np: pointer to node to create device for
158 * @bus_id: name to assign device 216 * @bus_id: name to assign device
@@ -178,12 +236,7 @@ static struct platform_device *of_platform_device_create_pdata(
178 if (!dev) 236 if (!dev)
179 goto err_clear_flag; 237 goto err_clear_flag;
180 238
181#if defined(CONFIG_MICROBLAZE) 239 of_dma_configure(dev);
182 dev->archdata.dma_mask = 0xffffffffUL;
183#endif
184 dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
185 if (!dev->dev.dma_mask)
186 dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
187 dev->dev.bus = &platform_bus_type; 240 dev->dev.bus = &platform_bus_type;
188 dev->dev.platform_data = platform_data; 241 dev->dev.platform_data = platform_data;
189 242