From: Adrian M. <ad...@mc...> - 2004-06-16 23:05:21
|
This is pretty crude stuff and doesn't even work properly in the limited = way=20 it is impolemented so far, but here it is for your perusal. (NB: these ar= e=20 against the maple code in the linuxsh repository). I have been working on rewriting the maple driver to match the driver mod= el in=20 the 2.6 kernel. I've had trouble finding the time to do this properly, so= the=20 results are very limited - but this will give you entries of a sort in sy= sfs=20 if nothing else :) Apologies for the stray bits of code loitering here too. More to follow in the next few days Adrian --- maple.c=092004-06-16 23:52:30.000000000 +0100 +++ tmpspace/linux-2.6.6/drivers/maple/maple.c=092004-06-16 23:54:04.0000= 00000=20 +0100 @@ -1,7 +1,20 @@ /* + *=09 *=09Maple Bus device driver */ =20 +/************************* + * Maple Bus Driver for * + * SEGA Dreamcast =09 * + * Copyright Paul Mundt * + * 2000 - 2004 * + * Sections copyright * + * Adrian McMenamin * + * 2004 * + * Licensed under=09 * + * version 2 of the GPL * + *************************/ + #include <linux/config.h> #include <linux/kernel.h> #include <linux/module.h> @@ -13,6 +26,7 @@ #include <linux/string.h> #include <linux/completion.h> #include <linux/interrupt.h> +#include <linux/device.h> =20 #include <asm/page.h> #include <asm/io.h> @@ -36,15 +50,33 @@ static DECLARE_COMPLETION(kmapled_exited); static int kmapled_pid =3D 0; =20 + struct timer_list maple_timer; =20 unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr; unsigned long maple_pnp_time; =20 +static int maple_bus_match(struct device * dev, struct device_driver * d= rv)=20 +{ +=09pr_info("MAPLE: maple_bus_match called automagically\n"); +=09return 0; +} + + +/* Work with new driver structures for 2.6 */ +struct bus_type maple_bus_type =3D { + .name=09=3D "maple", + .match=09=3D maple_bus_match, +}; + + + + static struct maple_driver maple_dummy_driver =3D { =09.name=09=09=3D "Dummy", }; =20 + static void maple_dump_devinfo(struct maple_devinfo *devinfo) { =09pr_debug(" function: 0x%08x\n", be32_to_cpu(devinfo->function)); @@ -65,7 +97,7 @@ =09struct list_head *lh =3D (void *)driver; =09list_add(lh, &maple_driver_list); =20 -=09MOD_INC_USE_COUNT; +=09/* MOD_INC_USE_COUNT; Redundant under 2.6 module code */ =20 =09pr_info("maple: registered driver: %s (function 0x%lx)\n", =09 driver->name, driver->function); @@ -77,7 +109,7 @@ =09struct list_head *lh =3D (void *)driver; =09list_del(lh); =20 -=09MOD_DEC_USE_COUNT; +=09/* MOD_DEC_USE_COUNT; */ =20 =09pr_info("maple: unregistered driver: %s (function 0x%lx)\n", =09 driver->name, driver->function); @@ -120,6 +152,9 @@ =09=09kfree(dev); =09=09return NULL; =09} +=09/* Setup kernel device */ +=09dev->sys_maple_dev.bus =3D &maple_bus_type; + =20 =09return dev; } @@ -139,6 +174,7 @@ { =09struct list_head *lh =3D (void *)dev; =09list_add_tail(lh, &maple_dev_list); +=09 } =20 =20 @@ -227,6 +263,7 @@ =20 =09pr_info("maple(%d,%d): Connected(function 0x%lx)\n", =09 dev->port, dev->unit, function); +=09 =20 =09list_for_each(lh, &maple_driver_list) { =09=09driver =3D (struct maple_driver *)lh; @@ -244,6 +281,18 @@ =09=09maple_dump_devinfo(&dev->devinfo); =09=09dev->driver =3D &maple_dummy_driver; =09} +=09 + +=09/* Add this device to the sysfs list */ +=09list_add_tail(&dev->sys_maple_dev.bus_list, &maple_bus_type.devices.l= ist); +=09sprintf(dev->sys_maple_dev.bus_id, "maple:%d:%d.0x%lx\n", dev->port,=20 dev->unit, function); +=09sprintf(dev->sys_maple_dev.kobj.name, dev->product_name); +=09dev->sys_maple_dev.bus =3D &maple_bus_type; +=09device_register(&dev->sys_maple_dev); +=09pr_info("MAPLE: device registered\n"); + + + =20 } =20 @@ -456,6 +505,12 @@ =20 =09pr_info("SEGA Dreamcast MAPLE Bus drivers\n"); =20 +=09/* Register with sysfs */ + =09if (bus_register(&maple_bus_type) !=3D 0) +=09=09goto cleanup; +=09pr_info("Maple bus registered\n"); +=20 + =09/* Allocate DMA buffer */ =09maple_sendbuf =3D (void *)__get_dma_pages(GFP_KERNEL, MAPLE_DMA_PAGES= ); =09if (maple_sendbuf =3D=3D NULL) @@ -481,10 +536,10 @@ =20 =09/* Start to scan ports */ =09maple_pnp_time =3D 0; - - /* Initialize hardware */ +=09 +=09/* Initialize hardware */ ctrl_outl(MAPLE_MAGIC, MAPLE_RESET); - ctrl_outl(0, MAPLE_RESET2); +=09ctrl_outl(0, MAPLE_RESET2); ctrl_outl(MAPLE_2MBPS|MAPLE_TIMEOUT(50000), MAPLE_SPEED); =09ctrl_outl(PHYSADDR(maple_sendbuf), MAPLE_DMAADDR); ctrl_outl(1, MAPLE_ENABLE); @@ -494,7 +549,6 @@ maple_timer.expires =3D jiffies + MAPLE_SCANHZ; maple_timer.function =3D maple_timer_handler; add_timer(&maple_timer); - return 0; =20 cleanup: @@ -526,6 +580,9 @@ EXPORT_SYMBOL(maple_register_driver); EXPORT_SYMBOL(maple_unregister_driver); EXPORT_SYMBOL(maple_getcond_callback); +EXPORT_SYMBOL(maple_bus_type); + +MODULE_LICENSE("GPL"); //avoid kernel tainting =20 /* * Local variables: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D --- maple.h=092004-06-16 23:56:32.000000000 +0100 +++ tmpspace/linux-2.6.6/include/linux/maple.h=092004-06-16 22:47:26.0000= 00000=20 +0100 @@ -89,8 +89,10 @@ }; =20 =20 + struct maple_device { =09struct list_head list; +=09struct list_head sysfs_list; =09struct maple_driver *driver; =09struct mapleq *mq; =09void *private_data; @@ -101,8 +103,17 @@ =09unsigned char port, unit; =09char product_name[32]; =09char product_license[64]; +=09 +=09/* 2.6.x kernel compliance */ +=09struct device sys_maple_dev; +=09 }; =20 +extern struct bus_type maple_bus_type; + + + + =20 struct maple_driver { =09struct list_head list; |
From: Paul M. <le...@li...> - 2004-06-17 13:37:28
|
On Thu, Jun 17, 2004 at 12:05:09AM +0100, Adrian McMenamin wrote: > This is pretty crude stuff and doesn't even work properly in the limited = way=20 > it is impolemented so far, but here it is for your perusal. (NB: these ar= e=20 > against the maple code in the linuxsh repository). >=20 For starters, please do all of the sysfs registration and handling in a new maple-sysfs.c, it's ok to have one or two ifdefs in maple.c to hook into it, but it would be preferrable to keep it isolated since sysfs is now under CONFIG_SYSFS, so we may not always want it. If you look at the dma code, it does similar things (though not as a bus), so you may want to look at that. Additionally, you may also want to look at arch/sh/kernel/cpu/bus.c which implements SH-bus as a dummy bus to handle registration of things that have nowhere better to go (or things that could be done as platform device, but have additional requirements, etc.). Ideally, maple will have a similar registration method from a driver point of view. > @@ -1,7 +1,20 @@ > /* > + *=09 > * Maple Bus device driver > */ > =20 > +/************************* > + * Maple Bus Driver for * > + * SEGA Dreamcast * > + * Copyright Paul Mundt * > + * 2000 - 2004 * > + * Sections copyright * > + * Adrian McMenamin * > + * 2004 * > + * Licensed under * > + * version 2 of the GPL * > + *************************/ > + > #include <linux/config.h> > #include <linux/kernel.h> > #include <linux/module.h> I didn't write this, so you can drop my name entirely. I'm not sure who the original author of this is, it's had a bunch of different people hacking on= it at some point or another though. > @@ -65,7 +97,7 @@ > struct list_head *lh =3D (void *)driver; > list_add(lh, &maple_driver_list); > =20 > - MOD_INC_USE_COUNT; > + /* MOD_INC_USE_COUNT; Redundant under 2.6 module code */ > =20 > pr_info("maple: registered driver: %s (function 0x%lx)\n", > driver->name, driver->function); > @@ -77,7 +109,7 @@ > struct list_head *lh =3D (void *)driver; > list_del(lh); > =20 > - MOD_DEC_USE_COUNT; > + /* MOD_DEC_USE_COUNT; */ > =20 > pr_info("maple: unregistered driver: %s (function 0x%lx)\n", > driver->name, driver->function); It's probably worth adding an owner to the maple dev struct and doing __module_get()/__module_put() on that for proper refcounting. Other then that, it looks like a decent start, though much of maple.c needs to be rewritten regardless due to its current inability to handle subdevice= s, general cruftiness of the list management, etc. another good reason to keep the sysfs stuff abstracted in maple-sysfs.c, then we can rewrite maple.c without stepping over any of the sysfs code. |