[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[microblaze-uclinux] Device Trees
I looked at posting a device tree patch, but it's quite a bit of code
and very similar to code that is in arch/powerpc. Also, the code that I
have targets some of the device tree consolidation work that will go
into 2.6.24, and won't apply well against petalinux.
That said, I think it would be more interesting to see how it is used.
Here is a fragment of the current version of the uartlite driver in the
powerpc trees (at the bottom). Basically, the uartlite is advertised as
a device through the platform bus and through a separate bus which is
bound using a device tree. For archaeological reasons, this is the 'of'
platform bus (standing for open firmware). The devices are advertised
from the system dynamically, based on a flat device tree binary
structure that is parsed at boot time. (see
Documentation/powerpc/booting-without-of.txt)
The binary structure would be typically passed in by u-boot and is
generated from a source file containing something like:
RS232_Uart_1 {
C_BAUDRATE = <2580>;
C_DATA_BITS = <8>;
C_ODD_PARITY = <0>;
C_SPLB_CLK_FREQ_HZ = <7735940>;
C_USE_PARITY = <0>;
compatible = "xps_uartlite_1.00.a\0xps_uartlite";
device_type = "xps_uartlite";
interrupt-parent = <101>;
interrupts = < 3 0 >;
reg = < 84000000 10000 >;
} ;
(The exact set of parameters and how they are generated from an EDK file
was the subject of the previous discussion)
Currently, there is a python script that generates the above source file
from a .mhs file, although in the long term something that is more
tightly integrated with EDK will likely be necessary. Michel Simek has
started working on an EDK-integrated generator:
http://monstr.eu/sites/download/download.php#uboot
Ultimately, this avoids depending as much on #defines for what devices
are available, enabling more generic kernels that can be run on a wider
variety of EDK designs...
Steve
/** ulite_assign: register a uartlite device with the driver
*
* @dev: pointer to device structure
* @id: requested id number. Pass -1 for automatic port assignment
* @base: base address of uartlite registers
* @irq: irq number for uartlite
*
* Returns: 0 on success, <0 otherwise
*/
static int __devinit ulite_assign(struct device *dev, int id, u32 base,
int irq)
{
struct uart_port *port;
int rc;
/* if id = -1; then scan for a free id and use that */
if (id < 0) {
for (id = 0; id < ULITE_NR_UARTS; id++)
if (ulite_ports[id].mapbase == 0)
break;
}
if (id < 0 || id >= ULITE_NR_UARTS) {
dev_err(dev, "%s%i too large\n", ULITE_NAME, id);
return -EINVAL;
}
if ((ulite_ports[id].mapbase) && (ulite_ports[id].mapbase !=
base)) {
dev_err(dev, "cannot assign to %s%i; it is already in
use\n",
ULITE_NAME, id);
return -EBUSY;
}
port = &ulite_ports[id];
spin_lock_init(&port->lock);
port->fifosize = 16;
port->regshift = 2;
port->iotype = UPIO_MEM;
port->iobase = 1; /* mark port in use */
port->mapbase = base;
port->membase = NULL;
port->ops = &ulite_ops;
port->irq = irq;
port->flags = UPF_BOOT_AUTOCONF;
port->dev = dev;
port->type = PORT_UNKNOWN;
port->line = id;
dev_set_drvdata(dev, port);
/* Register the port */
rc = uart_add_one_port(&ulite_uart_driver, port);
if (rc) {
dev_err(dev, "uart_add_one_port() failed; err=%i\n",
rc);
port->mapbase = 0;
dev_set_drvdata(dev, NULL);
return rc;
}
return 0;
}
/** ulite_release: register a uartlite device with the driver
*
* @dev: pointer to device structure
*/
static int __devinit ulite_release(struct device *dev)
{
struct uart_port *port = dev_get_drvdata(dev);
int rc = 0;
if (port) {
rc = uart_remove_one_port(&ulite_uart_driver, port);
dev_set_drvdata(dev, NULL);
port->mapbase = 0;
}
return rc;
}
/* ---------------------------------------------------------------------
* Platform bus binding
*/
static int __devinit ulite_probe(struct platform_device *pdev)
{
struct resource *res, *res2;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
res2 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res2)
return -ENODEV;
return ulite_assign(&pdev->dev, pdev->id, res->start,
res2->start);
}
static int ulite_remove(struct platform_device *pdev)
{
return ulite_release(&pdev->dev);
}
static struct platform_driver ulite_platform_driver = {
.probe = ulite_probe,
.remove = ulite_remove,
.driver = {
.owner = THIS_MODULE,
.name = "uartlite",
},
};
/* ---------------------------------------------------------------------
* OF bus bindings
*/
#if defined(CONFIG_OF)
static int __devinit
ulite_of_probe(struct of_device *op, const struct of_device_id *match)
{
struct resource res;
const unsigned int *id;
int irq, rc;
dev_dbg(&op->dev, "%s(%p, %p)\n", __FUNCTION__, op, match);
rc = of_address_to_resource(op->node, 0, &res);
if (rc) {
dev_err(&op->dev, "invalid address\n");
return rc;
}
irq = irq_of_parse_and_map(op->node, 0);
id = of_get_property(op->node, "port-number", NULL);
return ulite_assign(&op->dev, id ? *id : -1, res.start+3, irq);
}
static int __devexit ulite_of_remove(struct of_device *op)
{
return ulite_release(&op->dev);
}
/* Match table for of_platform binding */
static struct of_device_id __devinit ulite_of_match[] = {
{ .type = "serial", .compatible = "xilinx,uartlite", },
{},
};
MODULE_DEVICE_TABLE(of, ulite_of_match);
static struct of_platform_driver ulite_of_driver = {
.owner = THIS_MODULE,
.name = "uartlite",
.match_table = ulite_of_match,
.probe = ulite_of_probe,
.remove = __devexit_p(ulite_of_remove),
.driver = {
.name = "uartlite",
},
};
/* Registration helpers to keep the number of #ifdefs to a minimum */
static inline int __init ulite_of_register(void)
{
pr_debug("uartlite: calling of_register_platform_driver()\n");
return of_register_platform_driver(&ulite_of_driver);
}
static inline void __exit ulite_of_unregister(void)
{
of_unregister_platform_driver(&ulite_of_driver);
}
#else /* CONFIG_OF */
/* CONFIG_OF not enabled; do nothing helpers */
static inline int __init ulite_of_register(void) { return 0; }
static inline void __exit ulite_of_unregister(void) { }
#endif /* CONFIG_OF */
/* ---------------------------------------------------------------------
* Module setup/teardown
*/
int __init ulite_init(void)
{
int ret;
pr_debug("uartlite: calling uart_register_driver()\n");
ret = uart_register_driver(&ulite_uart_driver);
if (ret)
goto err_uart;
ret = ulite_of_register();
if (ret)
goto err_of;
pr_debug("uartlite: calling platform_driver_register()\n");
ret = platform_driver_register(&ulite_platform_driver);
if (ret)
goto err_plat;
return 0;
err_plat:
ulite_of_unregister();
err_of:
uart_unregister_driver(&ulite_uart_driver);
err_uart:
printk(KERN_ERR "registering uartlite driver failed: err=%i",
ret);
return ret;
}
void __exit ulite_exit(void)
{
platform_driver_unregister(&ulite_platform_driver);
ulite_of_unregister();
uart_unregister_driver(&ulite_uart_driver);
}
module_init(ulite_init);
module_exit(ulite_exit);
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/