]> Git Repo - J-u-boot.git/blob - drivers/pci/pci_ftpci100.c
Merge tag 'u-boot-imx-master-20250127' of https://gitlab.denx.de/u-boot/custodians...
[J-u-boot.git] / drivers / pci / pci_ftpci100.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 #include <pci.h>
4 #include <dm.h>
5 #include <asm/io.h>
6
7 struct ftpci100_data {
8         void *reg_base;
9 };
10
11 /* AHB Control Registers */
12 struct ftpci100_ahbc {
13         u32 iosize;     /* 0x00 - I/O Space Size Signal */
14         u32 prot;       /* 0x04 - AHB Protection */
15         u32 rsved[8];   /* 0x08-0x24 - Reserved */
16         u32 conf;       /* 0x28 - PCI Configuration */
17         u32 data;       /* 0x2c - PCI Configuration DATA */
18 };
19
20 static int ftpci100_read_config(const struct udevice *dev, pci_dev_t bdf,
21                                 uint offset, ulong *valuep,
22                                 enum pci_size_t size)
23 {
24         struct ftpci100_data *priv = dev_get_priv(dev);
25         struct ftpci100_ahbc *regs = priv->reg_base;
26         u32 data;
27
28         out_le32(&regs->conf, PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset));
29         data = in_le32(&regs->data);
30         *valuep = pci_conv_32_to_size(data, offset, size);
31
32         return 0;
33 }
34
35 static int ftpci100_write_config(struct udevice *dev, pci_dev_t bdf,
36                                  uint offset, ulong value,
37                                  enum pci_size_t size)
38 {
39         struct ftpci100_data *priv = dev_get_priv(dev);
40         struct ftpci100_ahbc *regs = priv->reg_base;
41         u32 data;
42
43         out_le32(&regs->conf, PCI_CONF1_ADDRESS(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), offset));
44
45         if (size == PCI_SIZE_32) {
46                 data = value;
47         } else {
48                 u32 old = in_le32(&regs->data);
49
50                 data = pci_conv_size_to_32(old, value, offset, size);
51         }
52
53         out_le32(&regs->data, data);
54
55         return 0;
56 }
57
58 static int ftpci100_probe(struct udevice *dev)
59 {
60         struct ftpci100_data *priv = dev_get_priv(dev);
61         struct pci_region *io, *mem;
62         int count;
63
64         count = pci_get_regions(dev, &io, &mem, NULL);
65         if (count != 2) {
66                 printf("%s: wrong count of regions: %d != 2\n", dev->name, count);
67                 return -EINVAL;
68         }
69
70         priv->reg_base = phys_to_virt(io->phys_start);
71         if (!priv->reg_base)
72                 return -EINVAL;
73
74         return 0;
75 }
76
77 static const struct dm_pci_ops ftpci100_ops = {
78         .read_config    = ftpci100_read_config,
79         .write_config   = ftpci100_write_config,
80 };
81
82 static const struct udevice_id ftpci100_ids[] = {
83         { .compatible = "faraday,ftpci100" },
84         { }
85 };
86
87 U_BOOT_DRIVER(ftpci100_pci) = {
88         .name           = "ftpci100_pci",
89         .id             = UCLASS_PCI,
90         .of_match       = ftpci100_ids,
91         .ops            = &ftpci100_ops,
92         .probe          = ftpci100_probe,
93         .priv_auto      = sizeof(struct ftpci100_data),
94 };
This page took 0.035932 seconds and 4 git commands to generate.