From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 06/16] dm: Add README for driver model
Date: Wed, 23 Oct 2013 04:56:45 +0200 [thread overview]
Message-ID: <201310230456.45940.marex@denx.de> (raw)
In-Reply-To: <1382377782-16031-7-git-send-email-sjg@chromium.org>
Dear Simon Glass,
[...]
> +What is going on?
> +-----------------
> +
> +Let's start at the top. The demo command is in common/cmd_demo.c. It does
> +the usual command procesing and then:
> +
> + struct device *demo_dev;
> +
> + ret = uclass_get_device(UCLASS_DEMO, &demo_dev);
Which device will this assign into demo_dev if there are multiple devices
registered with the demo uclass ?
> +UCLASS_DEMO means the class of devices which implement 'demo'. Other
> +classes might be MMC, or GPIO, hashing or serial. The idea is that the
> +devices in the class all share a particular way of working. The class
> +presents a unified view of all these devices to U-Boot.
[...]
> +Declaring Drivers
> +-----------------
> +
> +A driver declaration looks something like this (see
> +drivers/demo/demo-shape.c):
> +
> +static const struct demo_ops simple_ops = {
> + .hello = shape_hello,
> + .status = shape_status,
> +};
> +
> +U_BOOT_DRIVER(demo_shape_drv) = {
> + .name = "demo_shape_drv",
> + .id = UCLASS_DEMO,
> + .ops = &simple_ops,
> + .priv_data_size = sizeof(struct shape_data),
> +};
We are not discussing relocation here yet, right ?
> +This driver has two methods (hello and status) and requires a bit
> +of private data (accessible through dev->priv once the driver has
> +been probed). It is a member of UCLASS_DEMO so will register itself
> +there.
> +
> +In U_BOOT_DRIVER it is also possible to specify special methods for probe,
> +and bind, and these are called at appropriate times. For many drivers
> +it is hoped that only 'probe' and 'remove' will be needed.
> +
> +The U_BOOT_DRIVER macro creates a data structure accessible from C,
> +so driver model can find the drivers that are available.
> +
> +
> +Platform Data
> +-------------
> +
> +Where does the platform data come from? See demo-pdata.c which
> +sets up a table of driver names and their associated platform data.
> +The data can be interpreted by the drivers however they like - it is
> +basically a communication scheme between the board-specific code and
> +the generic drivers, which are intended to work on any board.
> +
> +Drivers can acceess their data via dev->info->platform_data. Here is
> +the declaration for the platform data, which would normally appear
> +in the board file.
> +
> + static const struct dm_demo_cdata red_square = {
> + .colour = "red",
> + .sides = 4.
> + };
> + static const struct driver_info info[] = {
> + {
> + .name = "demo_shape_drv",
> + .platform_data = &red_square,
> + },
> + };
> +
> + demo1 = driver_bind(root, &info[0]);
We need dev_get_platdata() call or something, otherwise someone will shoot
himself in the face with a NULL pointer.
> +Device Tree
> +-----------
> +
> +While platform_data is useful, a more flexible way of providing device
> data is +by using device tree. With device tree we replace the above code
> with the +following device treefragment:
> +
> + red-square {
> + compatible = "demo-shape";
> + colour = "red";
> + sides = <4>;
> + };
> +
> +
> +The easiest way to make this work it to add a platform_data_size member to
> +the driver:
> +
> + .platform_data_auto_alloc_size = sizeof(struct dm_test_pdata),
> +
> +This will be allocated and zeroed before the driver's probe method is
> called. +The driver can then read the information out of the device tree
> and put it +in dev->priv, typically using a ..._parse_dt() function.
Can the driver maybe implement some ofdata_to_pdata() callback?
> +Declaring Uclasses
> +------------------
> +
> +The demo uclass is declared like this:
> +
> +U_BOOT_CLASS(demo) = {
> + .id = UCLASS_DEMO,
> +};
> +
> +It is also possible to specify special methods for probe, etc. The uclass
> +numbering comes from include/dm/uclass.h. To add a new uclass, add to the
> +end of the enum there, then declare your uclass as above.
I wonder if we cannot even automate the numbering here ;-)
[...]
next prev parent reply other threads:[~2013-10-23 2:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-21 17:49 [U-Boot] [PATCH v5 0/16] Driver model implementation, tests, demo and GPIO Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 01/16] sandbox: Make map_to_sysmem() use a constant pointer Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 02/16] sandbox: Correct data sizes and printf() strings in fdtdec.c Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 03/16] sandbox: config: Don't use 64-bit physical memory Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 04/16] sandbox: Build a device tree file for sandbox Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 05/16] Add cmd_process_error() to report and process errors Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 06/16] dm: Add README for driver model Simon Glass
2013-10-23 2:56 ` Marek Vasut [this message]
2013-11-05 20:34 ` Simon Glass
2013-11-05 22:38 ` Marek Vasut
2013-11-06 10:54 ` Pavel Herrmann
2013-10-21 17:49 ` [U-Boot] [PATCH v5 07/16] dm: Add base driver model support Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 08/16] sandbox: config: Enable driver model Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 09/16] dm: Set up driver model after relocation Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 10/16] dm: Add basic tests Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 11/16] dm: Add a 'dm' command for testing Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 12/16] dm: Add a demonstration/example driver Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 13/16] dm: Add GPIO support and tests Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 14/16] sandbox: Convert GPIOs to use driver model Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 15/16] dm: Enable gpio command to support " Simon Glass
2013-10-21 17:49 ` [U-Boot] [PATCH v5 16/16] dm: Remove old driver model documentation Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201310230456.45940.marex@denx.de \
--to=marex@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox