user2699113
user2699113

Reputation: 4509

Linux device driver for banana pi and device tree

I'm trying to write ethernet driver for Linux kernel 4.13.x for Banana Pi M2 ultra. Some time ago so called "device tree" (DT) has been introduced in Linux kernel infrastructure. I have no much experience with using DT while writing device drivers and because of that I've got a few questions.

As far as I know - in case of banana pi system - it is needed to provide some clock source for given peripheral device. It is function of CCU in banana pi to provide such a clock. The CCU is memory mapped resource available at some address in the linux kernel. I'd like to write driver for ethernet which needs some clock from CCU.

I know that physical address of CCU must be mapped via ioremap() or similar function to virtual address.

My question is how can I fetch the virtual address of CCU in my ethernet driver? Is it possible to do via device tree? If yes - how to do this? Or maybe this virtual address can be get another way?

I'm just not sure if it is done (fetching virt address) via DT or just by some procedure or via global pointer.

Any ideas or suggestions?

Upvotes: 3

Views: 538

Answers (1)

Varun
Varun

Reputation: 477

There are examples in Linux kernel for platform drivers. I have worked on i2c and i2s on raspberry pi so I can quote those examples.

In http://elixir.free-electrons.com/linux/v4.3.2/source/drivers/i2c/busses/i2c-bcm2835.c

Look at the probe function, it calls the subsystem api

platform_get_resource(pdev, IORESOURCE_MEM, 0);

This can gives physical address which is ioremap ..

For this it is required to create a device node in device tree as in https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/boot/dts/bcm283x.dtsi

check for i2c0 device node in file bcm283x.dtsi.

The reg key is where physical address is stored

reg = <0x7e205000       0x1000>;

        physical add     size

Hope this help you.

Device tree may be considered analogus to platform data previously

Upvotes: 1

Related Questions