2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
9 #include <linux/delay.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/module.h>
12 #include <linux/firmware.h>
13 #include <linux/of_platform.h>
15 #include <lantiq_soc.h>
17 #define XRX200_GPHY_FW_ALIGN (16 * 1024)
19 static dma_addr_t xway_gphy_load(struct platform_device *pdev)
21 const struct firmware *fw;
22 dma_addr_t dev_addr = 0;
27 if (of_property_read_string(pdev->dev.of_node, "firmware", &fw_name)) {
28 dev_err(&pdev->dev, "failed to load firmware filename\n");
32 dev_info(&pdev->dev, "requesting %s\n", fw_name);
33 if (request_firmware(&fw, fw_name, &pdev->dev)) {
34 dev_err(&pdev->dev, "failed to load firmware: %s\n", fw_name);
39 * GPHY cores need the firmware code in a persistent and contiguous
40 * memory area with a 16 kB boundary aligned start address
42 size = fw->size + XRX200_GPHY_FW_ALIGN;
44 fw_addr = dma_alloc_coherent(&pdev->dev, size, &dev_addr, GFP_KERNEL);
46 fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN);
47 dev_addr = ALIGN(dev_addr, XRX200_GPHY_FW_ALIGN);
48 memcpy(fw_addr, fw->data, fw->size);
50 dev_err(&pdev->dev, "failed to alloc firmware memory\n");
57 static int xway_phy_fw_probe(struct platform_device *pdev)
61 unsigned char *phyids;
64 fw_addr = xway_gphy_load(pdev);
67 pp = of_find_property(pdev->dev.of_node, "phys", NULL);
71 for (i = 0; i < pp->length && !ret; i++)
72 ret = xrx200_gphy_boot(&pdev->dev, phyids[i], fw_addr);
78 static const struct of_device_id xway_phy_match[] = {
79 { .compatible = "lantiq,phy-xrx200" },
82 MODULE_DEVICE_TABLE(of, xway_phy_match);
84 static struct platform_driver xway_phy_driver = {
85 .probe = xway_phy_fw_probe,
89 .of_match_table = xway_phy_match,
93 module_platform_driver(xway_phy_driver);
95 MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
96 MODULE_DESCRIPTION("Lantiq XRX200 PHY Firmware Loader");
97 MODULE_LICENSE("GPL");