xref: /rk3399_rockchip-uboot/drivers/qe/fdt.c (revision 1206c18403ff25814673a4dbfa071ae06bbefaef)
169018ce2SKumar Gala /*
269018ce2SKumar Gala  * Copyright 2008 Freescale Semiconductor, Inc.
369018ce2SKumar Gala  *
469018ce2SKumar Gala  * (C) Copyright 2000
569018ce2SKumar Gala  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
669018ce2SKumar Gala  *
769018ce2SKumar Gala  * See file CREDITS for list of people who contributed to this
869018ce2SKumar Gala  * project.
969018ce2SKumar Gala  *
1069018ce2SKumar Gala  * This program is free software; you can redistribute it and/or
1169018ce2SKumar Gala  * modify it under the terms of the GNU General Public License as
1269018ce2SKumar Gala  * published by the Free Software Foundation; either version 2 of
1369018ce2SKumar Gala  * the License, or (at your option) any later version.
1469018ce2SKumar Gala  *
1569018ce2SKumar Gala  * This program is distributed in the hope that it will be useful,
1669018ce2SKumar Gala  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1769018ce2SKumar Gala  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1869018ce2SKumar Gala  * GNU General Public License for more details.
1969018ce2SKumar Gala  *
2069018ce2SKumar Gala  * You should have received a copy of the GNU General Public License
2169018ce2SKumar Gala  * along with this program; if not, write to the Free Software
2269018ce2SKumar Gala  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2369018ce2SKumar Gala  * MA 02111-1307 USA
2469018ce2SKumar Gala  */
2569018ce2SKumar Gala 
2669018ce2SKumar Gala #include <common.h>
2769018ce2SKumar Gala #include <libfdt.h>
2869018ce2SKumar Gala #include <fdt_support.h>
2969018ce2SKumar Gala #include "qe.h"
3069018ce2SKumar Gala 
3169018ce2SKumar Gala DECLARE_GLOBAL_DATA_PTR;
3269018ce2SKumar Gala 
3369018ce2SKumar Gala /*
3469018ce2SKumar Gala  * If a QE firmware has been uploaded, then add the 'firmware' node under
3569018ce2SKumar Gala  * the 'qe' node.
3669018ce2SKumar Gala  */
3769018ce2SKumar Gala void fdt_fixup_qe_firmware(void *blob)
3869018ce2SKumar Gala {
3969018ce2SKumar Gala 	struct qe_firmware_info *qe_fw_info;
4069018ce2SKumar Gala 	int node, ret;
4169018ce2SKumar Gala 
4269018ce2SKumar Gala 	qe_fw_info = qe_get_firmware_info();
4369018ce2SKumar Gala 	if (!qe_fw_info)
4469018ce2SKumar Gala 		return;
4569018ce2SKumar Gala 
4669018ce2SKumar Gala 	node = fdt_path_offset(blob, "/qe");
4769018ce2SKumar Gala 	if (node < 0)
4869018ce2SKumar Gala 		return;
4969018ce2SKumar Gala 
5069018ce2SKumar Gala 	/* We assume the node doesn't exist yet */
5169018ce2SKumar Gala 	node = fdt_add_subnode(blob, node, "firmware");
5269018ce2SKumar Gala 	if (node < 0)
5369018ce2SKumar Gala 		return;
5469018ce2SKumar Gala 
5569018ce2SKumar Gala 	ret = fdt_setprop(blob, node, "extended-modes",
5669018ce2SKumar Gala 		&qe_fw_info->extended_modes, sizeof(u64));
5769018ce2SKumar Gala 	if (ret < 0)
5869018ce2SKumar Gala 		goto error;
5969018ce2SKumar Gala 
6069018ce2SKumar Gala 	ret = fdt_setprop_string(blob, node, "id", qe_fw_info->id);
6169018ce2SKumar Gala 	if (ret < 0)
6269018ce2SKumar Gala 		goto error;
6369018ce2SKumar Gala 
6469018ce2SKumar Gala 	ret = fdt_setprop(blob, node, "virtual-traps", qe_fw_info->vtraps,
6569018ce2SKumar Gala 		sizeof(qe_fw_info->vtraps));
6669018ce2SKumar Gala 	if (ret < 0)
6769018ce2SKumar Gala 		goto error;
6869018ce2SKumar Gala 
6969018ce2SKumar Gala 	return;
7069018ce2SKumar Gala 
7169018ce2SKumar Gala error:
7269018ce2SKumar Gala 	fdt_del_node(blob, node);
7369018ce2SKumar Gala }
7469018ce2SKumar Gala 
7569018ce2SKumar Gala void ft_qe_setup(void *blob)
7669018ce2SKumar Gala {
7769018ce2SKumar Gala 	do_fixup_by_prop_u32(blob, "device_type", "qe", 4,
7869018ce2SKumar Gala 		"bus-frequency", gd->qe_clk, 1);
7969018ce2SKumar Gala 	do_fixup_by_prop_u32(blob, "device_type", "qe", 4,
80*1206c184SSimon Glass 		"brg-frequency", gd->arch.brg_clk, 1);
8169018ce2SKumar Gala 	do_fixup_by_compat_u32(blob, "fsl,qe",
8269018ce2SKumar Gala 		"clock-frequency", gd->qe_clk, 1);
8369018ce2SKumar Gala 	do_fixup_by_compat_u32(blob, "fsl,qe",
8469018ce2SKumar Gala 		"bus-frequency", gd->qe_clk, 1);
8569018ce2SKumar Gala 	do_fixup_by_compat_u32(blob, "fsl,qe",
86*1206c184SSimon Glass 		"brg-frequency", gd->arch.brg_clk, 1);
873fca8037SAnton Vorontsov 	do_fixup_by_compat_u32(blob, "fsl,qe-gtm",
883fca8037SAnton Vorontsov 		"clock-frequency", gd->qe_clk / 2, 1);
8969018ce2SKumar Gala 	fdt_fixup_qe_firmware(blob);
9069018ce2SKumar Gala }
91