[FE training-materials-updates] Kernel labs: add source code links

Michael Opdenacker michael.opdenacker at free-electrons.com
Tue Feb 4 17:38:28 CET 2014


Repository : git://git.free-electrons.com/training-materials.git

On branch  : master
Link       : http://git.free-electrons.com/training-materials/commit/?id=3741ad1ac4836fd5e473374937807c229307325b

>---------------------------------------------------------------

commit 3741ad1ac4836fd5e473374937807c229307325b
Author: Michael Opdenacker <michael.opdenacker at free-electrons.com>
Date:   Tue Feb 4 17:37:13 2014 +0100

    Kernel labs: add source code links
    
    - Allows to reduce typing work
    - Do this with the \sourcecode{} macro
    
    Signed-off-by: Michael Opdenacker <michael.opdenacker at free-electrons.com>


>---------------------------------------------------------------

3741ad1ac4836fd5e473374937807c229307325b
 common/labs-header.tex                             |    5 +++
 labs/kernel-i2c-input-interface/device-pointers.c  |    6 ++++
 .../input-device-attributes.c                      |    6 ++++
 .../input-notification.c                           |    6 ++++
 .../kernel-i2c-input-interface.tex                 |   35 +++-----------------
 .../private-data-alloc.c                           |    5 +++
 labs/kernel-serial-iomem/kernel-serial-iomem.tex   |    8 ++---
 7 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/common/labs-header.tex b/common/labs-header.tex
index 596f8fa..b03af0e 100644
--- a/common/labs-header.tex
+++ b/common/labs-header.tex
@@ -4,6 +4,11 @@
 \usepackage{listings}
 \usepackage{verbatim}
 
+% Custom free-electrons commands
+
+\newcommand{\sourcecode}[1]{\verbatiminput{../#1}Source code link:
+\url{http://git.free-electrons.com/training-materials/plain/#1}}
+
 \title{\labbooktitle \\ \vspace{1cm} Lab Book}
 \trainingurl{\labbookurl}
 
diff --git a/labs/kernel-i2c-input-interface/device-pointers.c b/labs/kernel-i2c-input-interface/device-pointers.c
new file mode 100644
index 0000000..f1741bd
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/device-pointers.c
@@ -0,0 +1,6 @@
+        nunchuk->i2c_client = client;
+        nunchuk->polled_input = polled_input;
+        polled_input->private = nunchuk;
+        i2c_set_clientdata(client, nunchuk);
+        input = polled_input->input;
+        input->dev.parent = &client->dev;
diff --git a/labs/kernel-i2c-input-interface/input-device-attributes.c b/labs/kernel-i2c-input-interface/input-device-attributes.c
new file mode 100644
index 0000000..b175058
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/input-device-attributes.c
@@ -0,0 +1,6 @@
+        input->name = "Wii Nunchuk";
+        input->id.bustype = BUS_I2C;
+
+        set_bit(EV_KEY, input->evbit);
+        set_bit(BTN_C, input->keybit);
+        set_bit(BTN_Z, input->keybit);
diff --git a/labs/kernel-i2c-input-interface/input-notification.c b/labs/kernel-i2c-input-interface/input-notification.c
new file mode 100644
index 0000000..a1728c1
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/input-notification.c
@@ -0,0 +1,6 @@
+        input_event(nunchuk->polled_input->input,
+                    EV_KEY, BTN_Z, zpressed);
+        input_event(nunchuk->polled_input->input,
+                    EV_KEY, BTN_C, cpressed);
+
+        input_sync(nunchuk->polled_input->input);
diff --git a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
index 5c961b8..895774d 100644
--- a/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
+++ b/labs/kernel-i2c-input-interface/kernel-i2c-input-interface.tex
@@ -117,13 +117,7 @@ this structure:
 
 Then allocate one such instead for each new device:
 
-\begin{verbatim}
-        nunchuk = devm_kzalloc(&client->dev, sizeof(struct nunchuk_dev), GFP_KERNEL);
-        if (!nunchuk) {
-                dev_err(&client->dev, "Failed to allocate memory\n");
-                return -ENOMEM;
-        }
-\end{verbatim}
+\sourcecode{labs/kernel-i2c-input-interface/private-data-alloc.c}
 
 Note that we haven't seen kernel memory allocator routines and flags
 yet.
@@ -141,14 +135,7 @@ all the details later.
 
 Now implement the pointers: 
 
-\begin{verbatim}
-	nunchuk->i2c_client = client;
-	nunchuk->polled_input = polled_input;
-	polled_input->private = nunchuk;
-	i2c_set_clientdata(client, nunchuk);
-	input = polled_input->input;
-	input->dev.parent = &client->dev;
-\end{verbatim}
+\sourcecode{labs/kernel-i2c-input-interface/device-pointers.c}
 
 Make sure you add this code before registering the input device. You
 don't want to enable a device with incomplete information or when it is
@@ -173,14 +160,7 @@ input: Unspecified device as /devices/virtual/input/input0
 Add the below lines of code (still before device registration, of
 course):
 
-\begin{verbatim}
-        input->name = "Wii Nunchuk";
-        input->id.bustype = BUS_I2C;
-
-        set_bit(EV_KEY, input->evbit);
-        set_bit(BTN_C, input->keybit);
-        set_bit(BTN_Z, input->keybit);
-\end{verbatim}
+\sourcecode{labs/kernel-i2c-input-interface/input-device-attributes.c}
 
 Recompile and reload your driver. You should now see in the kernel log
 that the \code{Unspecified device} type is replaced by 
@@ -211,14 +191,7 @@ of \code{return value;}}.
 At the end of the polling routine, the last thing to do is post the events 
 and notify the \code{input} core:
 
-\begin{verbatim}
-        input_event(nunchuk->polled_input->input,
-                    EV_KEY, BTN_Z, zpressed);
-        input_event(nunchuk->polled_input->input,
-                    EV_KEY, BTN_C, cpressed);
-
-        input_sync(nunchuk->polled_input->input);
-\end{verbatim}
+\sourcecode{labs/kernel-i2c-input-interface/input-notification.c}
 
 Now, back to the \code{probe()} function, the last thing to do
 is to declare the new polling function (see the slides if you forgot
diff --git a/labs/kernel-i2c-input-interface/private-data-alloc.c b/labs/kernel-i2c-input-interface/private-data-alloc.c
new file mode 100644
index 0000000..8c54dff
--- /dev/null
+++ b/labs/kernel-i2c-input-interface/private-data-alloc.c
@@ -0,0 +1,5 @@
+        nunchuk = devm_kzalloc(&client->dev, sizeof(struct nunchuk_dev), GFP_KERNEL);
+        if (!nunchuk) {
+                dev_err(&client->dev, "Failed to allocate memory\n");
+                return -ENOMEM;
+        }
diff --git a/labs/kernel-serial-iomem/kernel-serial-iomem.tex b/labs/kernel-serial-iomem/kernel-serial-iomem.tex
index 667fa73..cb40886 100644
--- a/labs/kernel-serial-iomem/kernel-serial-iomem.tex
+++ b/labs/kernel-serial-iomem/kernel-serial-iomem.tex
@@ -51,11 +51,11 @@ Now, open the \code{arch/arm/boot/dts/am335x-bone-common.dtsi}
 file and create declarations for UART2 and UART4 in the pin muxing
 section:
 
-\verbatiminput{../labs/kernel-serial-iomem/uarts-pinctrl.dts}
+\sourcecode{labs/kernel-serial-iomem/uarts-pinctrl.dts}
 
 Then, declare the corresponding devices:
 
-\verbatiminput{../labs/kernel-serial-iomem/uarts.dts}
+\sourcecode{labs/kernel-serial-iomem/uarts.dts}
 
 Note: we are calling these devices with \code{uartfe} instead of
 \code{uart} to avoid conflicts with declarations in
@@ -207,7 +207,7 @@ After these lines, let's add code to initialize the line
 and configure the baud rate. This shows how to get a special
 property from the device tree, in this case \code{clock-frequency}:
 
-\verbatiminput{../labs/kernel-serial-iomem/uart-line-init.c}
+\sourcecode{labs/kernel-serial-iomem/uart-line-init.c}
 
 Declare \code{baud_divisor} and \code{uartclk} as \code{unsigned int}.
 
@@ -215,7 +215,7 @@ Declare \code{baud_divisor} and \code{uartclk} as \code{unsigned int}.
 
 The last thing to do is to request a software reset:
 
-\verbatiminput{../labs/kernel-serial-iomem/uart-line-reset.c}
+\sourcecode{labs/kernel-serial-iomem/uart-line-reset.c}
 
 We are now ready to transmit characters over the serial ports!
 



More information about the training-materials-updates mailing list