cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
1,623 Views
Registered: ‎02-08-2017

Passing device name to gpio function

Jump to solution

I am trying to build driver for my GPIO in xilinx board ZCU102

I can understand that we can define the GPIO pins in device tree file as below

devicetree_sample.png

 

while building the driver we shall use gpiod_get as below

 

gpio_get_fn.png

 

My question is how to know or extract the "dev" parameter to pass it to "gpiod_get" arguments?

 

My background in hardware area so I don't know if it is tough or easy question but anyways I hope I can get your support

0 Kudos
1 Solution

Accepted Solutions
Highlighted
2,079 Views
Registered: ‎03-27-2014

@moibrahim,

 

yes matching compatible fields

 

to access a specific one, you can use the optionnal name field you can provide in the devicetree:

 

dev_U0@address0{
     compatible="gpio-v1.0";
};

dev_U1@address1{
    compatible="gpio-v1.0";
};

probe will be called because compatible values do match. To identify the devices, a quick way to do it would be..

device_probe(struct platform_device *pdev){
struct device_node *node;
...

node = pdev->dev.of_node;
// quick device discrimination int id = of_alias_get_id(node, "dev_U"); if (id < 0) // not specified id = 0; // default if (id == 1) printk(KERN_INFO "talking about device 1\n"); .... }

 

I am pretty sure the devicetree node API (#include <linux/of.h>) provides stuff to retrieve the address value too

 

gw.
Embedded Systems, DSP, cyber

View solution in original post

0 Kudos
6 Replies
Highlighted
1,609 Views
Registered: ‎03-27-2014

@moibrahim,

 

this takes place in device_probe(struct platform_device *pdev) and device_release(struct platform_device *pdev).

 

The generic platform device structure embedds a generic struct *device structure (the "driver data"), which you can retrieve with *pdev->dev. In your custom driver you created a custom device structure, one of the main things your driver should do is customizing the generic device structure. Usually we do it this way:

 

device_probe(struct platform_dev *pdev){

struct my_dev *mdev;
...
mdev->dev = &pdev->dev; platform_set_drvdata(pdev, mdev);
...
}

 

line 2 allows you to work on pdev->dev directly too

gw.
Embedded Systems, DSP, cyber
0 Kudos
Highlighted
Explorer
Explorer
1,593 Views
Registered: ‎02-08-2017

@guillaumebresThanks a lot for your response.


Well, this will turn the question to be how to get "pdev" parameter?

I wanted to walk step be step on controlling my hardware (which is a GPIO controller).

So I thought I can use gpiod_get function to get a structure about my GPIO pins,

struct gpio_desc *gpiod_get(struct device *dev, const char *con_id, enum gpiod_flags flags);


then I can control it for isnstance using

int gpiod_direction_input(struct gpio_desc *desc);

int gpiod_get_value(const struct gpio_desc *desc);



I came accross this simple example for having overview of how the final driver should look like. But I want to walk step by step please as I have to learn it.

0 Kudos
Highlighted
1,566 Views
Registered: ‎03-27-2014
"pdev", platform device parameter, will match whatever you specified from the devicetree. This is specified @line 34 in your example. Any node in the devicetree matching "example" will call a seperate gpio_probe()
gw.
Embedded Systems, DSP, cyber
0 Kudos
Highlighted
Explorer
Explorer
1,562 Views
Registered: ‎02-08-2017

@guillaumebres,

I really apprciate your help. I still need to make it clear please,


@guillaumebres wrote:
 Any node in the devicetree matching "example" will call a seperate gpio_probe()

matching with what in the device tree? (with the "compatible" field value ?)

 

If I have 2 GPIO modules (as in ch 6 of UG1209). How to access specific one?

 

Why can't I access my device simply using its address?

 

Thanks in Advance

0 Kudos
Highlighted
2,080 Views
Registered: ‎03-27-2014

@moibrahim,

 

yes matching compatible fields

 

to access a specific one, you can use the optionnal name field you can provide in the devicetree:

 

dev_U0@address0{
     compatible="gpio-v1.0";
};

dev_U1@address1{
    compatible="gpio-v1.0";
};

probe will be called because compatible values do match. To identify the devices, a quick way to do it would be..

device_probe(struct platform_device *pdev){
struct device_node *node;
...

node = pdev->dev.of_node;
// quick device discrimination int id = of_alias_get_id(node, "dev_U"); if (id < 0) // not specified id = 0; // default if (id == 1) printk(KERN_INFO "talking about device 1\n"); .... }

 

I am pretty sure the devicetree node API (#include <linux/of.h>) provides stuff to retrieve the address value too

 

gw.
Embedded Systems, DSP, cyber

View solution in original post

0 Kudos
Highlighted
Explorer
Explorer
1,508 Views
Registered: ‎02-08-2017

@guillaumebres

Many Thanks for your replies it was very helpful for me.

Now I understand how it should be, but I got other problem here, that I wish you can contribute in.

0 Kudos