1 From 0224cde212df4abf251f89c3724a800b1949a774 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Mon, 22 Oct 2012 07:52:50 +0200
4 Subject: [PATCH 6/6] MIPS: lantiq: adds GPHY firmware loader
6 The internal GPHYs need a firmware blob to function properly. This patch adds
7 the code needed to request the blob and load it to the PHY.
9 Signed-off-by: John Crispin <blogic@openwrt.org>
10 Patchwork: http://patchwork.linux-mips.org/patch/4523
12 arch/mips/lantiq/Kconfig | 4 ++
13 arch/mips/lantiq/xway/Makefile | 2 +
14 arch/mips/lantiq/xway/xrx200_phy_fw.c | 97 +++++++++++++++++++++++++++++++++
15 3 files changed, 103 insertions(+)
16 create mode 100644 arch/mips/lantiq/xway/xrx200_phy_fw.c
18 --- a/arch/mips/lantiq/Kconfig
19 +++ b/arch/mips/lantiq/Kconfig
20 @@ -36,4 +36,8 @@ config PCI_LANTIQ
22 depends on SOC_XWAY && PCI
25 + bool "XRX200 PHY firmware loader"
29 --- a/arch/mips/lantiq/xway/Makefile
30 +++ b/arch/mips/lantiq/xway/Makefile
32 obj-y := prom.o sysctrl.o clk.o reset.o dma.o gptu.o
34 +obj-$(CONFIG_XRX200_PHY_FW) += xrx200_phy_fw.o
36 +++ b/arch/mips/lantiq/xway/xrx200_phy_fw.c
39 + * This program is free software; you can redistribute it and/or modify it
40 + * under the terms of the GNU General Public License version 2 as published
41 + * by the Free Software Foundation.
43 + * Copyright (C) 2012 John Crispin <blogic@openwrt.org>
46 +#include <linux/delay.h>
47 +#include <linux/dma-mapping.h>
48 +#include <linux/module.h>
49 +#include <linux/firmware.h>
50 +#include <linux/of_platform.h>
52 +#include <lantiq_soc.h>
54 +#define XRX200_GPHY_FW_ALIGN (16 * 1024)
56 +static dma_addr_t xway_gphy_load(struct platform_device *pdev)
58 + const struct firmware *fw;
59 + dma_addr_t dev_addr = 0;
60 + const char *fw_name;
64 + if (of_property_read_string(pdev->dev.of_node, "firmware", &fw_name)) {
65 + dev_err(&pdev->dev, "failed to load firmware filename\n");
69 + dev_info(&pdev->dev, "requesting %s\n", fw_name);
70 + if (request_firmware(&fw, fw_name, &pdev->dev)) {
71 + dev_err(&pdev->dev, "failed to load firmware: %s\n", fw_name);
76 + * GPHY cores need the firmware code in a persistent and contiguous
77 + * memory area with a 16 kB boundary aligned start address
79 + size = fw->size + XRX200_GPHY_FW_ALIGN;
81 + fw_addr = dma_alloc_coherent(&pdev->dev, size, &dev_addr, GFP_KERNEL);
83 + fw_addr = PTR_ALIGN(fw_addr, XRX200_GPHY_FW_ALIGN);
84 + dev_addr = ALIGN(dev_addr, XRX200_GPHY_FW_ALIGN);
85 + memcpy(fw_addr, fw->data, fw->size);
87 + dev_err(&pdev->dev, "failed to alloc firmware memory\n");
90 + release_firmware(fw);
94 +static int __devinit xway_phy_fw_probe(struct platform_device *pdev)
97 + struct property *pp;
98 + unsigned char *phyids;
101 + fw_addr = xway_gphy_load(pdev);
104 + pp = of_find_property(pdev->dev.of_node, "phys", NULL);
107 + phyids = pp->value;
108 + for (i = 0; i < pp->length && !ret; i++)
109 + ret = xrx200_gphy_boot(&pdev->dev, phyids[i], fw_addr);
115 +static const struct of_device_id xway_phy_match[] = {
116 + { .compatible = "lantiq,phy-xrx200" },
119 +MODULE_DEVICE_TABLE(of, xway_phy_match);
121 +static struct platform_driver xway_phy_driver = {
122 + .probe = xway_phy_fw_probe,
124 + .name = "phy-xrx200",
125 + .owner = THIS_MODULE,
126 + .of_match_table = xway_phy_match,
130 +module_platform_driver(xway_phy_driver);
132 +MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
133 +MODULE_DESCRIPTION("Lantiq XRX200 PHY Firmware Loader");
134 +MODULE_LICENSE("GPL");