2 * Lantiq XRX200 PHY Firmware Loader
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
9 * Copyright (C) 2012 John Crispin <john@phrozen.org>
12 #include <linux/delay.h>
13 #include <linux/dma-mapping.h>
14 #include <linux/firmware.h>
15 #include <linux/of_platform.h>
17 #include <lantiq_soc.h>
19 #define XRX200_GPHY_FW_ALIGN (16 * 1024)
21 static dma_addr_t
xway_gphy_load(struct platform_device
*pdev
)
23 const struct firmware
*fw
;
24 dma_addr_t dev_addr
= 0;
29 if (of_get_property(pdev
->dev
.of_node
, "firmware1", NULL
) ||
30 of_get_property(pdev
->dev
.of_node
, "firmware2", NULL
)) {
31 switch (ltq_soc_type()) {
33 if (of_property_read_string(pdev
->dev
.of_node
,
34 "firmware1", &fw_name
)) {
36 "failed to load firmware filename\n");
41 if (of_property_read_string(pdev
->dev
.of_node
,
42 "firmware2", &fw_name
)) {
44 "failed to load firmware filename\n");
49 } else if (of_property_read_string(pdev
->dev
.of_node
,
50 "firmware", &fw_name
)) {
51 dev_err(&pdev
->dev
, "failed to load firmware filename\n");
55 dev_info(&pdev
->dev
, "requesting %s\n", fw_name
);
56 if (request_firmware(&fw
, fw_name
, &pdev
->dev
)) {
57 dev_err(&pdev
->dev
, "failed to load firmware: %s\n", fw_name
);
62 * GPHY cores need the firmware code in a persistent and contiguous
63 * memory area with a 16 kB boundary aligned start address
65 size
= fw
->size
+ XRX200_GPHY_FW_ALIGN
;
67 fw_addr
= dma_alloc_coherent(&pdev
->dev
, size
, &dev_addr
, GFP_KERNEL
);
69 fw_addr
= PTR_ALIGN(fw_addr
, XRX200_GPHY_FW_ALIGN
);
70 dev_addr
= ALIGN(dev_addr
, XRX200_GPHY_FW_ALIGN
);
71 memcpy(fw_addr
, fw
->data
, fw
->size
);
73 dev_err(&pdev
->dev
, "failed to alloc firmware memory\n");
80 static int xway_phy_fw_probe(struct platform_device
*pdev
)
84 unsigned char *phyids
;
87 fw_addr
= xway_gphy_load(pdev
);
90 pp
= of_find_property(pdev
->dev
.of_node
, "phys", NULL
);
94 for (i
= 0; i
< pp
->length
&& !ret
; i
++)
95 ret
= xrx200_gphy_boot(&pdev
->dev
, phyids
[i
], fw_addr
);
101 static const struct of_device_id xway_phy_match
[] = {
102 { .compatible
= "lantiq,phy-xrx200" },
106 static struct platform_driver xway_phy_driver
= {
107 .probe
= xway_phy_fw_probe
,
109 .name
= "phy-xrx200",
110 .of_match_table
= xway_phy_match
,
113 builtin_platform_driver(xway_phy_driver
);