pci: sh7751: Convert to DM and DT probing
Convert the SH7751 PCI driver to DM and add DT probing. Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com> Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org> Cc: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
		
							parent
							
								
									8c2c46350d
								
							
						
					
					
						commit
						72c2f4acd7
					
				|  | @ -6,6 +6,7 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <common.h> | ||||
| #include <dm.h> | ||||
| #include <pci.h> | ||||
| #include <asm/processor.h> | ||||
| #include <asm/io.h> | ||||
|  | @ -71,30 +72,61 @@ | |||
| #define p4_in(addr)	(*addr) | ||||
| #define p4_out(data, addr) (*addr) = (data) | ||||
| 
 | ||||
| /* Double word */ | ||||
| int pci_sh4_read_config_dword(struct pci_controller *hose, | ||||
| 			      pci_dev_t dev, int offset, u32 *value) | ||||
| static int sh7751_pci_addr_valid(pci_dev_t d, uint offset) | ||||
| { | ||||
| 	u32 par_data = 0x80000000 | dev; | ||||
| 
 | ||||
| 	p4_out(par_data | (offset & 0xfc), SH7751_PCIPAR); | ||||
| 	*value = p4_in(SH7751_PCIPDR); | ||||
| 	if (PCI_FUNC(d)) | ||||
| 		return -EINVAL; | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int pci_sh4_write_config_dword(struct pci_controller *hose, | ||||
| 			       pci_dev_t dev, int offset, u32 value) | ||||
| static u32 get_bus_address(struct udevice *dev, pci_dev_t bdf, u32 offset) | ||||
| { | ||||
| 	u32 par_data = 0x80000000 | dev; | ||||
| 	return BIT(31) | (PCI_DEV(bdf) << 8) | (offset & ~3); | ||||
| } | ||||
| 
 | ||||
| 	p4_out(par_data | (offset & 0xfc), SH7751_PCIPAR); | ||||
| 	p4_out(value, SH7751_PCIPDR); | ||||
| static int sh7751_pci_read_config(struct udevice *dev, pci_dev_t bdf, | ||||
| 				  uint offset, ulong *value, | ||||
| 				  enum pci_size_t size) | ||||
| { | ||||
| 	u32 addr, reg; | ||||
| 	int ret; | ||||
| 
 | ||||
| 	ret = sh7751_pci_addr_valid(bdf, offset); | ||||
| 	if (ret) { | ||||
| 		*value = pci_get_ff(size); | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	addr = get_bus_address(dev, bdf, offset); | ||||
| 	p4_out(addr, SH7751_PCIPAR); | ||||
| 	reg = p4_in(SH7751_PCIPDR); | ||||
| 	*value = pci_conv_32_to_size(reg, offset, size); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int pci_sh7751_init(struct pci_controller *hose) | ||||
| static int sh7751_pci_write_config(struct udevice *dev, pci_dev_t bdf, | ||||
| 				      uint offset, ulong value, | ||||
| 				      enum pci_size_t size) | ||||
| { | ||||
| 	u32 addr, reg, old; | ||||
| 	int ret; | ||||
| 
 | ||||
| 	ret = sh7751_pci_addr_valid(bdf, offset); | ||||
| 	if (ret) | ||||
| 		return ret; | ||||
| 
 | ||||
| 	addr = get_bus_address(dev, bdf, offset); | ||||
| 	p4_out(addr, SH7751_PCIPAR); | ||||
| 	old = p4_in(SH7751_PCIPDR); | ||||
| 	reg = pci_conv_size_to_32(old, value, offset, size); | ||||
| 	p4_out(reg, SH7751_PCIPDR); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| static int sh7751_pci_probe(struct udevice *dev) | ||||
| { | ||||
| 	/* Double-check that we're a 7751 or 7751R chip */ | ||||
| 	if (p4_in(SH7751_PCICONF0) != PCI_SH7751_ID | ||||
|  | @ -178,7 +210,23 @@ int pci_sh7751_init(struct pci_controller *hose) | |||
| 	/* Finally, set central function init complete */ | ||||
| 	p4_out((SH7751_PCICR_PREFIX | SH7751_PCICR_CFIN), SH7751_PCICR); | ||||
| 
 | ||||
| 	pci_sh4_init(hose); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| static const struct dm_pci_ops sh7751_pci_ops = { | ||||
| 	.read_config	= sh7751_pci_read_config, | ||||
| 	.write_config	= sh7751_pci_write_config, | ||||
| }; | ||||
| 
 | ||||
| static const struct udevice_id sh7751_pci_ids[] = { | ||||
| 	{ .compatible = "renesas,pci-sh7751" }, | ||||
| 	{ } | ||||
| }; | ||||
| 
 | ||||
| U_BOOT_DRIVER(sh7751_pci) = { | ||||
| 	.name		= "sh7751_pci", | ||||
| 	.id		= UCLASS_PCI, | ||||
| 	.of_match	= sh7751_pci_ids, | ||||
| 	.ops		= &sh7751_pci_ops, | ||||
| 	.probe		= sh7751_pci_probe, | ||||
| }; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue