Commit 6fa45a22 authored by Sudip Mukherjee's avatar Sudip Mukherjee Committed by Greg Kroah-Hartman

parport: add device-model to parport subsystem

parport subsystem starts using the device-model. Drivers using the
device-model has to define devmodel as true and should register the
device with parport using parport_register_dev_model().
Tested-by: default avatarJean Delvare <jdelvare@suse.de>
Tested-by: default avatarAlan Cox <gnomes@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarSudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 208250dd
...@@ -2255,7 +2255,7 @@ struct parport *parport_pc_probe_port(unsigned long int base, ...@@ -2255,7 +2255,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
release_region(base+0x3, 5); release_region(base+0x3, 5);
release_region(base, 3); release_region(base, 3);
out4: out4:
parport_put_port(p); parport_del_port(p);
out3: out3:
kfree(priv); kfree(priv);
out2: out2:
...@@ -2294,7 +2294,7 @@ void parport_pc_unregister_port(struct parport *p) ...@@ -2294,7 +2294,7 @@ void parport_pc_unregister_port(struct parport *p)
priv->dma_handle); priv->dma_handle);
#endif #endif
kfree(p->private_data); kfree(p->private_data);
parport_put_port(p); parport_del_port(p);
kfree(ops); /* hope no-one cached it */ kfree(ops); /* hope no-one cached it */
} }
EXPORT_SYMBOL(parport_pc_unregister_port); EXPORT_SYMBOL(parport_pc_unregister_port);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/parport.h> #include <linux/parport.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/sysctl.h> #include <linux/sysctl.h>
#include <linux/device.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
...@@ -558,8 +559,18 @@ int parport_device_proc_unregister(struct pardevice *device) ...@@ -558,8 +559,18 @@ int parport_device_proc_unregister(struct pardevice *device)
static int __init parport_default_proc_register(void) static int __init parport_default_proc_register(void)
{ {
int ret;
parport_default_sysctl_table.sysctl_header = parport_default_sysctl_table.sysctl_header =
register_sysctl_table(parport_default_sysctl_table.dev_dir); register_sysctl_table(parport_default_sysctl_table.dev_dir);
if (!parport_default_sysctl_table.sysctl_header)
return -ENOMEM;
ret = parport_bus_init();
if (ret) {
unregister_sysctl_table(parport_default_sysctl_table.
sysctl_header);
return ret;
}
return 0; return 0;
} }
...@@ -570,6 +581,7 @@ static void __exit parport_default_proc_unregister(void) ...@@ -570,6 +581,7 @@ static void __exit parport_default_proc_unregister(void)
sysctl_header); sysctl_header);
parport_default_sysctl_table.sysctl_header = NULL; parport_default_sysctl_table.sysctl_header = NULL;
} }
parport_bus_exit();
} }
#else /* no sysctl or no procfs*/ #else /* no sysctl or no procfs*/
...@@ -596,11 +608,12 @@ int parport_device_proc_unregister(struct pardevice *device) ...@@ -596,11 +608,12 @@ int parport_device_proc_unregister(struct pardevice *device)
static int __init parport_default_proc_register (void) static int __init parport_default_proc_register (void)
{ {
return 0; return parport_bus_init();
} }
static void __exit parport_default_proc_unregister (void) static void __exit parport_default_proc_unregister (void)
{ {
parport_bus_exit();
} }
#endif #endif
......
This diff is collapsed.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/irqreturn.h> #include <linux/irqreturn.h>
#include <linux/semaphore.h> #include <linux/semaphore.h>
#include <linux/device.h>
#include <asm/ptrace.h> #include <asm/ptrace.h>
#include <uapi/linux/parport.h> #include <uapi/linux/parport.h>
...@@ -145,6 +146,8 @@ struct pardevice { ...@@ -145,6 +146,8 @@ struct pardevice {
unsigned int flags; unsigned int flags;
struct pardevice *next; struct pardevice *next;
struct pardevice *prev; struct pardevice *prev;
struct device dev;
bool devmodel;
struct parport_state *state; /* saved status over preemption */ struct parport_state *state; /* saved status over preemption */
wait_queue_head_t wait_q; wait_queue_head_t wait_q;
unsigned long int time; unsigned long int time;
...@@ -156,6 +159,8 @@ struct pardevice { ...@@ -156,6 +159,8 @@ struct pardevice {
void * sysctl_table; void * sysctl_table;
}; };
#define to_pardevice(n) container_of(n, struct pardevice, dev)
/* IEEE1284 information */ /* IEEE1284 information */
/* IEEE1284 phases. These are exposed to userland through ppdev IOCTL /* IEEE1284 phases. These are exposed to userland through ppdev IOCTL
...@@ -195,7 +200,7 @@ struct parport { ...@@ -195,7 +200,7 @@ struct parport {
* This may unfortulately be null if the * This may unfortulately be null if the
* port has a legacy driver. * port has a legacy driver.
*/ */
struct device bus_dev; /* to link with the bus */
struct parport *physport; struct parport *physport;
/* If this is a non-default mux /* If this is a non-default mux
parport, i.e. we're a clone of a real parport, i.e. we're a clone of a real
...@@ -245,15 +250,26 @@ struct parport { ...@@ -245,15 +250,26 @@ struct parport {
struct parport *slaves[3]; struct parport *slaves[3];
}; };
#define to_parport_dev(n) container_of(n, struct parport, bus_dev)
#define DEFAULT_SPIN_TIME 500 /* us */ #define DEFAULT_SPIN_TIME 500 /* us */
struct parport_driver { struct parport_driver {
const char *name; const char *name;
void (*attach) (struct parport *); void (*attach) (struct parport *);
void (*detach) (struct parport *); void (*detach) (struct parport *);
void (*match_port)(struct parport *);
int (*probe)(struct pardevice *);
struct device_driver driver;
bool devmodel;
struct list_head list; struct list_head list;
}; };
#define to_parport_driver(n) container_of(n, struct parport_driver, driver)
int parport_bus_init(void);
void parport_bus_exit(void);
/* parport_register_port registers a new parallel port at the given /* parport_register_port registers a new parallel port at the given
address (if one does not already exist) and returns a pointer to it. address (if one does not already exist) and returns a pointer to it.
This entails claiming the I/O region, IRQ and DMA. NULL is returned This entails claiming the I/O region, IRQ and DMA. NULL is returned
...@@ -272,10 +288,20 @@ void parport_announce_port (struct parport *port); ...@@ -272,10 +288,20 @@ void parport_announce_port (struct parport *port);
extern void parport_remove_port(struct parport *port); extern void parport_remove_port(struct parport *port);
/* Register a new high-level driver. */ /* Register a new high-level driver. */
extern int parport_register_driver (struct parport_driver *);
int __must_check __parport_register_driver(struct parport_driver *,
struct module *,
const char *mod_name);
/*
* parport_register_driver must be a macro so that KBUILD_MODNAME can
* be expanded
*/
#define parport_register_driver(driver) \
__parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
/* Unregister a high-level driver. */ /* Unregister a high-level driver. */
extern void parport_unregister_driver (struct parport_driver *); extern void parport_unregister_driver (struct parport_driver *);
void parport_unregister_driver(struct parport_driver *);
/* If parport_register_driver doesn't fit your needs, perhaps /* If parport_register_driver doesn't fit your needs, perhaps
* parport_find_xxx does. */ * parport_find_xxx does. */
...@@ -288,6 +314,15 @@ extern irqreturn_t parport_irq_handler(int irq, void *dev_id); ...@@ -288,6 +314,15 @@ extern irqreturn_t parport_irq_handler(int irq, void *dev_id);
/* Reference counting for ports. */ /* Reference counting for ports. */
extern struct parport *parport_get_port (struct parport *); extern struct parport *parport_get_port (struct parport *);
extern void parport_put_port (struct parport *); extern void parport_put_port (struct parport *);
void parport_del_port(struct parport *);
struct pardev_cb {
int (*preempt)(void *);
void (*wakeup)(void *);
void *private;
void (*irq_func)(void *);
unsigned int flags;
};
/* parport_register_device declares that a device is connected to a /* parport_register_device declares that a device is connected to a
port, and tells the kernel all it needs to know. port, and tells the kernel all it needs to know.
...@@ -301,6 +336,10 @@ struct pardevice *parport_register_device(struct parport *port, ...@@ -301,6 +336,10 @@ struct pardevice *parport_register_device(struct parport *port,
void (*irq_func)(void *), void (*irq_func)(void *),
int flags, void *handle); int flags, void *handle);
struct pardevice *
parport_register_dev_model(struct parport *port, const char *name,
const struct pardev_cb *par_dev_cb, int cnt);
/* parport_unregister unlinks a device from the chain. */ /* parport_unregister unlinks a device from the chain. */
extern void parport_unregister_device(struct pardevice *dev); extern void parport_unregister_device(struct pardevice *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment