0

I wrote a driver on a microzed xilinx embedded Linux to communicate wih FPGA and receive and treat IRQ with an IRQ handler.

The device tree look like that for what we are interested in:

stef@dell00:~$ cat /tmp/devicetree.dts | grep -A 5 FPGA
        FPGA_v1_0_2@43c00000 {
            compatible = "xlnx,FPGA-v1-0-0";
            interrupt-names = "interrupt";
            interrupt-parent = <0x4>;
            interrupts = <0x0 0x20 0x4>;
            reg = <0x43c00000 0x10000>;
            xlnx,data0-width = <0x10>;
--
        FPGA_v1_0_2@43c10000 {
            compatible = "xlnx,FPGA-v1-0-0";
            interrupt-names = "interrupt";
            interrupt-parent = <0x4>;
            interrupts = <0x0 0x21 0x4>;
            reg = <0x43c10000 0x10000>;
            xlnx,data0-width = <0x10>;

So I have two instances of the same driver for treating in parallel FPGA registers and IRQs at the same time (that is the purpose).

The code on the INIT driver functions "could" look like and/or look like that:

static struct platform_driver my_driver = {
    .driver = {
        .name           = "FPGA",    
        .owner          = THIS_MODULE,
        .of_match_table = of_match_ptr(my_dt_ids),
    },
    .probe    = my_probe,
    .remove   = my_remove,
    .shutdown = my_shutdown,
};

with the probe function :

static int my_probe(platform_device * pdev_p)
{
  u32                    baseAddr ; 
  void __iomem         * devm_ior_res_p = NULL ;
  struct resource      * resource_p     = NULL ;
  typdef_struct_mydata * my_device_datas = NULL ; 

  my_device_datas = kzalloc( sizeof(typdef_struct_mydata), GFP_ATOMIC ); 
  platform_set_drvdata( pdev_p, dev_p); 
  resource_p = platform_get_resource(pdev_p, IORESOURCE_MEM, 0);  
  devm_ior_res_p = devm_ioremap_resource(&pdev_p->dev, resource_p); 
  of_property_read_u32( pdev_p->dev.of_node, "xlnx,data0-width", &data-width ) ;
  baseAddr = (u32)devm_ior_res_p;

  // FIXME : do something else at init ....
}

and the compatible link:

static const struct of_device_id my_dt_ids[] = {

    { .compatible = "xlnx,FPGA-v1-0-0", },  
    {}
};

Since the probe function is called, we can work with the base address and related things like registers / irq / etc...

Since the DTB have 2 nodes with 2 different reg adresses and MMU space addresses, we see as expected 2 instances on the /sys FS for one driver loaded (insmod):

root@my_target:/sys/devices/soc0/amba_pl# ls -rlt | grep FPGA

drwxr-xr-x 4 root root    0 Jan  7 15:50 43c10000.FPGA
drwxr-xr-x 4 root root    0 Jan  7 15:50 43c00000.FPGA

My question is: How to distinguish platform device data information of one instance from the other;

For a trivial example, just do a prink of the base address of the 2nd instance from the 1st and vice-versa.

In a general view, how to communicate between the two instances without go on the sysfs userspace API?

I read those articles:

but have not found the solution.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
stefff
  • 61
  • 2
  • 5
  • *"how to communicate ..."* -- First determine if the relationship is peer-to-peer, master-slave, or both subservient to a parent driver. But my first impression is that you may have simply made things more difficult by using two instances for one device, rather than one driver or two different drivers. You haven't clearly described the functionality that needs replication by each instance (e.g. is the FPGA merely the physical implementation for two identical devices?). IOW you may have created a [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – sawdust Jan 23 '21 at 23:39
  • it is not a xy problem, thanks – stefff Feb 19 '21 at 10:20
  • You seem looking for _fwnode graph API_. It has been designed to pass device properties between independent (from Device Tree point of view) nodes. – 0andriy Mar 02 '21 at 11:09
  • May be helpful (there are some links) https://stackoverflow.com/q/58577825/2511795 – 0andriy Mar 02 '21 at 11:25

0 Answers0