forked from mirrors/linux
		
	powerpc/mpc5xxx: Switch mpc5xxx_get_bus_frequency() to use fwnode
Switch mpc5xxx_get_bus_frequency() to use fwnode in order to help cleaning up other parts of the kernel from OF specific code. No functional change intended. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Chris Packham <chris.packham@alliedtelesis.co.nz> # for i2c-mpc Acked-by: Wolfram Sang <wsa@kernel.org> # for the I2C part Acked-by: Mark Brown <broonie@kernel.org> Acked-by: Marc Kleine-Budde <mkl@pengutronix.de> # for mscan/mpc5xxx_can Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220507100147.5802-2-andriy.shevchenko@linux.intel.com
This commit is contained in:
		
							parent
							
								
									6d056b7254
								
							
						
					
					
						commit
						de06fba62a
					
				
					 11 changed files with 44 additions and 34 deletions
				
			
		|  | @ -11,7 +11,14 @@ | ||||||
| #ifndef __ASM_POWERPC_MPC5xxx_H__ | #ifndef __ASM_POWERPC_MPC5xxx_H__ | ||||||
| #define __ASM_POWERPC_MPC5xxx_H__ | #define __ASM_POWERPC_MPC5xxx_H__ | ||||||
| 
 | 
 | ||||||
| extern unsigned long mpc5xxx_get_bus_frequency(struct device_node *node); | #include <linux/property.h> | ||||||
|  | 
 | ||||||
|  | unsigned long mpc5xxx_fwnode_get_bus_frequency(struct fwnode_handle *fwnode); | ||||||
|  | 
 | ||||||
|  | static inline unsigned long mpc5xxx_get_bus_frequency(struct device *dev) | ||||||
|  | { | ||||||
|  | 	return mpc5xxx_fwnode_get_bus_frequency(dev_fwnode(dev)); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| #endif /* __ASM_POWERPC_MPC5xxx_H__ */ | #endif /* __ASM_POWERPC_MPC5xxx_H__ */ | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -722,7 +722,7 @@ static int mpc52xx_gpt_probe(struct platform_device *ofdev) | ||||||
| 
 | 
 | ||||||
| 	raw_spin_lock_init(&gpt->lock); | 	raw_spin_lock_init(&gpt->lock); | ||||||
| 	gpt->dev = &ofdev->dev; | 	gpt->dev = &ofdev->dev; | ||||||
| 	gpt->ipb_freq = mpc5xxx_get_bus_frequency(ofdev->dev.of_node); | 	gpt->ipb_freq = mpc5xxx_get_bus_frequency(&ofdev->dev); | ||||||
| 	gpt->regs = of_iomap(ofdev->dev.of_node, 0); | 	gpt->regs = of_iomap(ofdev->dev.of_node, 0); | ||||||
| 	if (!gpt->regs) | 	if (!gpt->regs) | ||||||
| 		return -ENOMEM; | 		return -ENOMEM; | ||||||
|  |  | ||||||
|  | @ -1,31 +1,34 @@ | ||||||
| // SPDX-License-Identifier: GPL-2.0
 | // SPDX-License-Identifier: GPL-2.0
 | ||||||
|  | 
 | ||||||
|  | #include <linux/kernel.h> | ||||||
|  | #include <linux/export.h> | ||||||
|  | #include <linux/property.h> | ||||||
|  | 
 | ||||||
|  | #include <asm/mpc5xxx.h> | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * 	mpc5xxx_get_bus_frequency - Find the bus frequency for a device |  * mpc5xxx_fwnode_get_bus_frequency - Find the bus frequency for a firmware node | ||||||
|  * 	@node:	device node |  * @fwnode:	firmware node | ||||||
|  * |  * | ||||||
|  * Returns bus frequency (IPS on MPC512x, IPB on MPC52xx), |  * Returns bus frequency (IPS on MPC512x, IPB on MPC52xx), | ||||||
|  * or 0 if the bus frequency cannot be found. |  * or 0 if the bus frequency cannot be found. | ||||||
|  */ |  */ | ||||||
| 
 | unsigned long mpc5xxx_fwnode_get_bus_frequency(struct fwnode_handle *fwnode) | ||||||
| #include <linux/kernel.h> |  | ||||||
| #include <linux/of_platform.h> |  | ||||||
| #include <linux/export.h> |  | ||||||
| #include <asm/mpc5xxx.h> |  | ||||||
| 
 |  | ||||||
| unsigned long mpc5xxx_get_bus_frequency(struct device_node *node) |  | ||||||
| { | { | ||||||
| 	const unsigned int *p_bus_freq = NULL; | 	struct fwnode_handle *parent; | ||||||
|  | 	u32 bus_freq; | ||||||
|  | 	int ret; | ||||||
| 
 | 
 | ||||||
| 	of_node_get(node); | 	ret = fwnode_property_read_u32(fwnode, "bus-frequency", &bus_freq); | ||||||
| 	while (node) { | 	if (!ret) | ||||||
| 		p_bus_freq = of_get_property(node, "bus-frequency", NULL); | 		return bus_freq; | ||||||
| 		if (p_bus_freq) |  | ||||||
| 			break; |  | ||||||
| 
 | 
 | ||||||
| 		node = of_get_next_parent(node); | 	fwnode_for_each_parent_node(fwnode, parent) { | ||||||
|  | 		ret = fwnode_property_read_u32(parent, "bus-frequency", &bus_freq); | ||||||
|  | 		if (!ret) | ||||||
|  | 			return bus_freq; | ||||||
| 	} | 	} | ||||||
| 	of_node_put(node); |  | ||||||
| 
 | 
 | ||||||
| 	return p_bus_freq ? *p_bus_freq : 0; | 	return 0; | ||||||
| } | } | ||||||
| EXPORT_SYMBOL(mpc5xxx_get_bus_frequency); | EXPORT_SYMBOL(mpc5xxx_fwnode_get_bus_frequency); | ||||||
|  |  | ||||||
|  | @ -683,7 +683,7 @@ static int mpc52xx_ata_probe(struct platform_device *op) | ||||||
| 	struct bcom_task *dmatsk; | 	struct bcom_task *dmatsk; | ||||||
| 
 | 
 | ||||||
| 	/* Get ipb frequency */ | 	/* Get ipb frequency */ | ||||||
| 	ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node); | 	ipb_freq = mpc5xxx_get_bus_frequency(&op->dev); | ||||||
| 	if (!ipb_freq) { | 	if (!ipb_freq) { | ||||||
| 		dev_err(&op->dev, "could not determine IPB bus frequency\n"); | 		dev_err(&op->dev, "could not determine IPB bus frequency\n"); | ||||||
| 		return -ENODEV; | 		return -ENODEV; | ||||||
|  |  | ||||||
|  | @ -239,6 +239,7 @@ static const struct mpc_i2c_divider mpc_i2c_dividers_52xx[] = { | ||||||
| static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | ||||||
| 					  u32 *real_clk) | 					  u32 *real_clk) | ||||||
| { | { | ||||||
|  | 	struct fwnode_handle *fwnode = of_fwnode_handle(node); | ||||||
| 	const struct mpc_i2c_divider *div = NULL; | 	const struct mpc_i2c_divider *div = NULL; | ||||||
| 	unsigned int pvr = mfspr(SPRN_PVR); | 	unsigned int pvr = mfspr(SPRN_PVR); | ||||||
| 	u32 divider; | 	u32 divider; | ||||||
|  | @ -246,12 +247,12 @@ static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | ||||||
| 
 | 
 | ||||||
| 	if (clock == MPC_I2C_CLOCK_LEGACY) { | 	if (clock == MPC_I2C_CLOCK_LEGACY) { | ||||||
| 		/* see below - default fdr = 0x3f -> div = 2048 */ | 		/* see below - default fdr = 0x3f -> div = 2048 */ | ||||||
| 		*real_clk = mpc5xxx_get_bus_frequency(node) / 2048; | 		*real_clk = mpc5xxx_fwnode_get_bus_frequency(fwnode) / 2048; | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	/* Determine divider value */ | 	/* Determine divider value */ | ||||||
| 	divider = mpc5xxx_get_bus_frequency(node) / clock; | 	divider = mpc5xxx_fwnode_get_bus_frequency(fwnode) / clock; | ||||||
| 
 | 
 | ||||||
| 	/*
 | 	/*
 | ||||||
| 	 * We want to choose an FDR/DFSR that generates an I2C bus speed that | 	 * We want to choose an FDR/DFSR that generates an I2C bus speed that | ||||||
|  | @ -266,7 +267,7 @@ static int mpc_i2c_get_fdr_52xx(struct device_node *node, u32 clock, | ||||||
| 			break; | 			break; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	*real_clk = mpc5xxx_get_bus_frequency(node) / div->divider; | 	*real_clk = mpc5xxx_fwnode_get_bus_frequency(fwnode) / div->divider; | ||||||
| 	return (int)div->fdr; | 	return (int)div->fdr; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ static u32 mpc52xx_can_get_clock(struct platform_device *ofdev, | ||||||
| 	else | 	else | ||||||
| 		*mscan_clksrc = MSCAN_CLKSRC_XTAL; | 		*mscan_clksrc = MSCAN_CLKSRC_XTAL; | ||||||
| 
 | 
 | ||||||
| 	freq = mpc5xxx_get_bus_frequency(ofdev->dev.of_node); | 	freq = mpc5xxx_get_bus_frequency(&ofdev->dev); | ||||||
| 	if (!freq) | 	if (!freq) | ||||||
| 		return 0; | 		return 0; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -924,7 +924,7 @@ static int mpc52xx_fec_probe(struct platform_device *op) | ||||||
| 	/* Start with safe defaults for link connection */ | 	/* Start with safe defaults for link connection */ | ||||||
| 	priv->speed = 100; | 	priv->speed = 100; | ||||||
| 	priv->duplex = DUPLEX_HALF; | 	priv->duplex = DUPLEX_HALF; | ||||||
| 	priv->mdio_speed = ((mpc5xxx_get_bus_frequency(np) >> 20) / 5) << 1; | 	priv->mdio_speed = ((mpc5xxx_get_bus_frequency(&op->dev) >> 20) / 5) << 1; | ||||||
| 
 | 
 | ||||||
| 	/* The current speed preconfigures the speed of the MII link */ | 	/* The current speed preconfigures the speed of the MII link */ | ||||||
| 	prop = of_get_property(np, "current-speed", &prop_size); | 	prop = of_get_property(np, "current-speed", &prop_size); | ||||||
|  |  | ||||||
|  | @ -100,8 +100,7 @@ static int mpc52xx_fec_mdio_probe(struct platform_device *of) | ||||||
| 	dev_set_drvdata(dev, bus); | 	dev_set_drvdata(dev, bus); | ||||||
| 
 | 
 | ||||||
| 	/* set MII speed */ | 	/* set MII speed */ | ||||||
| 	out_be32(&priv->regs->mii_speed, | 	out_be32(&priv->regs->mii_speed, ((mpc5xxx_get_bus_frequency(dev) >> 20) / 5) << 1); | ||||||
| 		((mpc5xxx_get_bus_frequency(of->dev.of_node) >> 20) / 5) << 1); |  | ||||||
| 
 | 
 | ||||||
| 	err = of_mdiobus_register(bus, np); | 	err = of_mdiobus_register(bus, np); | ||||||
| 	if (err) | 	if (err) | ||||||
|  |  | ||||||
|  | @ -102,7 +102,7 @@ static int fs_enet_mdio_probe(struct platform_device *ofdev) | ||||||
| 	struct resource res; | 	struct resource res; | ||||||
| 	struct mii_bus *new_bus; | 	struct mii_bus *new_bus; | ||||||
| 	struct fec_info *fec; | 	struct fec_info *fec; | ||||||
| 	int (*get_bus_freq)(struct device_node *); | 	int (*get_bus_freq)(struct device *); | ||||||
| 	int ret = -ENOMEM, clock, speed; | 	int ret = -ENOMEM, clock, speed; | ||||||
| 
 | 
 | ||||||
| 	match = of_match_device(fs_enet_mdio_fec_match, &ofdev->dev); | 	match = of_match_device(fs_enet_mdio_fec_match, &ofdev->dev); | ||||||
|  | @ -136,7 +136,7 @@ static int fs_enet_mdio_probe(struct platform_device *ofdev) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (get_bus_freq) { | 	if (get_bus_freq) { | ||||||
| 		clock = get_bus_freq(ofdev->dev.of_node); | 		clock = get_bus_freq(&ofdev->dev); | ||||||
| 		if (!clock) { | 		if (!clock) { | ||||||
| 			/* Use maximum divider if clock is unknown */ | 			/* Use maximum divider if clock is unknown */ | ||||||
| 			dev_warn(&ofdev->dev, "could not determine IPS clock\n"); | 			dev_warn(&ofdev->dev, "could not determine IPS clock\n"); | ||||||
|  |  | ||||||
|  | @ -437,7 +437,7 @@ static int mpc52xx_spi_probe(struct platform_device *op) | ||||||
| 	ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0); | 	ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0); | ||||||
| 	ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1); | 	ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1); | ||||||
| 	ms->state = mpc52xx_spi_fsmstate_idle; | 	ms->state = mpc52xx_spi_fsmstate_idle; | ||||||
| 	ms->ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node); | 	ms->ipb_freq = mpc5xxx_get_bus_frequency(&op->dev); | ||||||
| 	ms->gpio_cs_count = of_gpio_count(op->dev.of_node); | 	ms->gpio_cs_count = of_gpio_count(op->dev.of_node); | ||||||
| 	if (ms->gpio_cs_count > 0) { | 	if (ms->gpio_cs_count > 0) { | ||||||
| 		master->num_chipselect = ms->gpio_cs_count; | 		master->num_chipselect = ms->gpio_cs_count; | ||||||
|  |  | ||||||
|  | @ -1630,7 +1630,7 @@ mpc52xx_console_setup(struct console *co, char *options) | ||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	uartclk = mpc5xxx_get_bus_frequency(np); | 	uartclk = mpc5xxx_fwnode_get_bus_frequency(of_fwnode_handle(np)); | ||||||
| 	if (uartclk == 0) { | 	if (uartclk == 0) { | ||||||
| 		pr_debug("Could not find uart clock frequency!\n"); | 		pr_debug("Could not find uart clock frequency!\n"); | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
|  | @ -1747,7 +1747,7 @@ static int mpc52xx_uart_of_probe(struct platform_device *op) | ||||||
| 	/* set the uart clock to the input clock of the psc, the different
 | 	/* set the uart clock to the input clock of the psc, the different
 | ||||||
| 	 * prescalers are taken into account in the set_baudrate() methods | 	 * prescalers are taken into account in the set_baudrate() methods | ||||||
| 	 * of the respective chip */ | 	 * of the respective chip */ | ||||||
| 	uartclk = mpc5xxx_get_bus_frequency(op->dev.of_node); | 	uartclk = mpc5xxx_get_bus_frequency(&op->dev); | ||||||
| 	if (uartclk == 0) { | 	if (uartclk == 0) { | ||||||
| 		dev_dbg(&op->dev, "Could not find uart clock frequency!\n"); | 		dev_dbg(&op->dev, "Could not find uart clock frequency!\n"); | ||||||
| 		return -EINVAL; | 		return -EINVAL; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Andy Shevchenko
						Andy Shevchenko