Skip to content

Commit

Permalink
Kernel labs: use devm_platform_ioremap_resource
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
  • Loading branch information
michaelopdenacker authored and tpetazzoni committed Oct 29, 2021
1 parent 0e0e401 commit 9591da3
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions labs/kernel-serial-iomem/kernel-serial-iomem.tex
Expand Up @@ -91,40 +91,14 @@ \section{Operate a platform device driver}
Even if we only connect a serial-to-USB dongle to one of them, both
of them are ready to be used!}.

\section{Get base addresses from the device tree}

We are going to read from memory mapped registers and read from them.
The first thing we need is the base physical address for the each
device.

Such information is precisely available in the Device Tree. You can
extract it with the below code:

\begin{verbatim}
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
\end{verbatim}

Add such code to your \code{probe()} routine, with proper error
handling when \code{res == NULL}, and print the start address
(\code{res->start}) to make sure that the address values that
you get match the ones in the device tree.

You can remove the printing instruction as soon as the collected
addresses are correct.

\section{Create a device private structure}

The next step is to start allocating and registering resources,
which eventually will have to be freed and unregistered too.

In the same way as in the nunchuk lab, we now need to create a
structure that will hold device specific information and help
keeping pointers between logical and physical devices.

As the first thing to store will be the base virtual address for
each device (obtained through \kfunc{ioremap}), let's declare this
structure as follows:
each device, let's declare this structure as follows:

\begin{verbatim}
struct serial_dev {
Expand All @@ -147,11 +121,13 @@ \section{Create a device private structure}
return -ENOMEM;
\end{verbatim}

\section{Get a base virtual address for your device registers}

You can now get a virtual address for your device's base physical
address, by calling:

\begin{verbatim}
dev->regs = devm_ioremap_resource(&pdev->dev, res);
dev->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(dev->regs))
return PTR_ERR(dev->regs);
\end{verbatim}
Expand Down

0 comments on commit 9591da3

Please sign in to comment.