Add support for SUNIX Multi-I/O board
PATCH 4/4 Add support for SUNIX Multi-I/O board
Driver for SUNIX Multi-I/O card.Based on parport_pc.c, ppdev.c and lp.c by Linus Torvalds, Theodore Ts'o.
--- mfd/sunix/snx_ieee1284.c | 144 +++++++ mfd/sunix/snx_ieee1284_ops.c | 258 +++++++++++++ mfd/sunix/snx_lp.c | 717 +++++++++++++++++++++++++++++++++++ mfd/sunix/snx_lp.h | 119 ++++++ mfd/sunix/snx_parallel.c | 397 +++++++++++++++++++ mfd/sunix/snx_ppdev.c | 454 ++++++++++++++++++++++ mfd/sunix/snx_ppdev.h | 15 + mfd/sunix/snx_share.c | 629 ++++++++++++++++++++++++++++++ 8 files changed, 2733 insertions(+) create mode 100644 mfd/sunix/snx_ieee1284.c create mode 100644 mfd/sunix/snx_ieee1284_ops.c create mode 100644 mfd/sunix/snx_lp.c create mode 100644 mfd/sunix/snx_lp.h create mode 100644 mfd/sunix/snx_parallel.c create mode 100644 mfd/sunix/snx_ppdev.c create mode 100644 mfd/sunix/snx_ppdev.h create mode 100644 mfd/sunix/snx_share.c
mfd/sunix/snx_ieee1284.c new file +144 -0
@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "snx_common.h" + +static void sunix_parport_ieee1284_wakeup (struct snx_parport *port) +{ +up (&port->physport->ieee1284.irq); +} + +static void sunix_timeout_waiting_on_port (struct timer_list *t) +{ +struct snx_parport *port =from_timer (port, t, timer); + +sunix_parport_ieee1284_wakeup (port); +} + +int sunix_parport_wait_event (struct snx_parport *port,signed long timeout) +{ +int ret; + +if (!port->physport->cad->timeout) +return 1 ; + +timer_setup (&port->timer, sunix_timeout_waiting_on_port,0 ); +mod_timer (&port->timer, jiffies + timeout); + + ret =down_interruptible (&port->physport->ieee1284.irq); + +if (!del_timer (&port->timer) && !ret) + ret =1 ; + +return ret; +} + + +int sunix_parport_poll_peripheral (struct snx_parport *port,unsigned char mask, +unsigned char result,int usec) +{ +int count = usec /5 +2 ; +int i; +unsigned char status; + +for (i =0 ; i < count; i++) { + status =sunix_parport_read_status (port); + +if ((status & mask) == result) +return 0 ; + +if (signal_pending (current)) +return -EINTR ; + +if (need_resched ()) +break ; + +if (i >=2 ) +udelay (5 ); + + } + +return 1 ; +} + + +int sunix_parport_wait_peripheral (struct snx_parport *port, +unsigned char mask,unsigned char result) +{ +int ret; +int usec; +unsigned long deadline; +unsigned char status; + + usec = port->physport->spintime;// usecs of fast polling + +if (!port->physport->cad->timeout) + usec =35000 ; + + ret =sunix_parport_poll_peripheral (port, mask, result, usec); + +if (ret !=1 ) +return ret; + +if (!port->physport->cad->timeout) +return 1 ; + + deadline = jiffies + (HZ +24 ) /25 ; + +while (time_before (jiffies, deadline)) { +int ret; + +if (signal_pending (current)) +return -EINTR ; + + ret =sunix_parport_wait_event (port, (HZ +99 ) /100 ); +if (ret <0 ) +return ret; + + status =sunix_parport_read_status (port); +if ((status & mask) == result) +return 0 ; + +if (!ret) +schedule_timeout_interruptible (msecs_to_jiffies (10 )); + } + +return 1 ; +} + + +int sunix_parport_negotiate (struct snx_parport *port,int mode) +{ +if (mode ==IEEE1284_MODE_COMPAT ) +return 0 ; + +return -1 ; +} + + +ssize_t sunix_parport_write (struct snx_parport *port, +const void *buffer,size_t len) +{ +ssize_t ret; + + ret = port->ops->compat_write_data (port, buffer, len,0 ); + +return ret; +} + + +ssize_t sunix_parport_read (struct snx_parport *port,void *buffer,size_t len) +{ +return -ENODEV ; +} + + +long sunix_parport_set_timeout (struct snx_pardevice *dev,long inactivity) +{ +long int old = dev->timeout; + + dev->timeout = inactivity; + +if (dev->port->physport->cad == dev) +sunix_parport_ieee1284_wakeup (dev->port); + +return old; +}
mfd/sunix/snx_ieee1284_ops.c new file +258 -0
258 lines not on this page · raw message
mfd/sunix/snx_lp.c new file +717 -0
717 lines not on this page · raw message
mfd/sunix/snx_lp.h new file +119 -0
119 lines not on this page · raw message
mfd/sunix/snx_parallel.c new file +397 -0
397 lines not on this page · raw message
mfd/sunix/snx_ppdev.c new file +454 -0
454 lines not on this page · raw message
mfd/sunix/snx_ppdev.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include "snx_common.h" + +#define SNX_PP_IOCTL 'p' + +#define SNX_PP_FASTWRITE (1<<2) +#define SNX_PP_FASTREAD (1<<3) +#define SNX_PP_W91284PIC (1<<4) + +struct snx_ppdev_frob_struct { +unsigned char mask; +unsigned char val; +}; + +
mfd/sunix/snx_share.c new file +629 -0
629 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 4 lines · Morris Ku
mfd/sunix/snx_ieee1284_ops.c new file +0
-1--- /dev/null
<snip>
Quoted 19 lines
mfd/sunix/snx_ieee1284_ops.c new file +19
-0+size_t sunix_parport_ieee1284_read_nibble (struct snx_parport *port, +void *buffer,size_t len,int flags) +{ +return 0 ; +} + +size_t sunix_parport_ieee1284_read_byte (struct snx_parport *port, +void *buffer,size_t len,int flags) +{ +return 0 ; +} + +size_t sunix_parport_ieee1284_ecp_write_data (struct snx_parport *port, +const void *buffer,size_t len,int flags) +{ +return 0 ; +} + +size_t sunix_parport_ieee1284_ecp_read_data(struct snx_parport *port,
mfd/sunix/snx_ieee1284_ops.c line 119
Quoted 10 lines
mfd/sunix/snx_ieee1284_ops.c new file +10
-0+void *buffer, size_t len, int flags) +{ + return 0; +} + +size_t sunix_parport_ieee1284_ecp_write_addr (struct snx_parport *port, +const void *buffer,size_t len,int flags) +{ +return 0 ; +}
Why are these all no-ops ?
Quoted 5 lines
mfd/sunix/snx_lp.c new file +0
-0
<snip>
Quoted 1 line
+#undef
SNX_LP_STATS
what is this ?
mfd/sunix/snx_lp.c line 11
Quoted 4 lines
mfd/sunix/snx_lp.c new file +4
-0+static int SNX_PAL_MAJOR ; + +#define SNX_LP_NO SNX_PAR_TOTAL_MAX +#undef SNX_CONFIG_LP_CONSOLE
and this ?
Quoted 1 line
+#ifdef
SNX_CONFIG_PARPORT_1284
dont do #define in the middle of the code.
mfd/sunix/snx_lp.c line 478
Quoted 9 lines
mfd/sunix/snx_lp.c new file +9
-0+static const struct file_operations snx_lp_fops = { + .owner =THIS_MODULE , + .write = snx_lp_write, + .open = snx_lp_open, + .release = snx_lp_release, +#ifdef SNX_CONFIG_PARPORT_1284 + .read = snx_lp_read, +#endif +};
dont reimplement existing standard functionality your own weird way. use the partport subsystem. see: Documentation/parport-lowlevel.txt
mfd/sunix/snx_lp.c line 620
Quoted 5 lines
mfd/sunix/snx_lp.c new file +5
-0+static struct snx_parport_driver snx_lp_driver = { + .name ="lx" , + .attach = snx_lp_attach, + .detach = snx_lp_detach, +};
yet another case of duplication of some standard struct and hard- typecasting ? use struct parport_driver here.
mfd/sunix/snx_lp.c line 649
Quoted 1 line
mfd/sunix/snx_lp.c new file +1
-0+SNX_PAL_MAJOR =register_chrdev (0 ,"lx" , &snx_lp_fops);
dont register your own chardev - use the parport subsystem.
Quoted 4 lines
mfd/sunix/snx_parallel.c new file +0
-1--- /dev/null
<snip>
mfd/sunix/snx_parallel.c line 250
Quoted 11 lines
mfd/sunix/snx_parallel.c new file +11
-0+struct snx_parport *sunix_parport_pc_probe_port (struct sunix_par_port *priv) +{ +struct snx_parport_ops *ops =NULL ; +struct snx_parport *p =NULL ; +struct resource *base_res; +struct resource *ecr_res =NULL ; + +if (!priv) + goto out1; + + ops =kmalloc (sizeof (struct snx_parport_ops ),GFP_KERNEL );
why not kzmalloc ?
Quoted 5 lines
mfd/sunix/snx_ppdev.c new file +0
-0
<snip>
mfd/sunix/snx_ppdev.c line 386
Quoted 11 lines
mfd/sunix/snx_ppdev.c new file +11
-0+static const struct file_operations snx_pp_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .read = snx_pp_read, + .write = snx_pp_write, + .poll = snx_pp_poll, + .unlocked_ioctl = snx_dump_par_ioctl, + + .open = snx_pp_open, + .release = snx_pp_release, +};
don't reimplement existing standard functionality - use the parport subsystem.
Quoted 6 lines
mfd/sunix/snx_ppdev.h new file +0
-0
mfd/sunix/snx_ppdev.h line 8
Quoted 8 lines
mfd/sunix/snx_ppdev.h new file +8
-0@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include "snx_common.h" + +#define SNX_PP_IOCTL 'p' + +#define SNX_PP_FASTWRITE (1<<2) +#define SNX_PP_FASTREAD (1<<3) +#define SNX_PP_W91284PIC (1<<4)
use the BIT() macro
Quoted 64 lines
mfd/sunix/snx_share.c new file +58
-0@@ -0,0 +1,629 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "snx_common.h" +#define SNX_PARPORT_DEFAULT_TIMESLICE (HZ/5) + +unsigned long sunix_parport_default_timeslice =SNX_PARPORT_DEFAULT_TIMESLICE ; +int sunix_parport_default_spintime =DEFAULT_SPIN_TIME ; + +static LIST_HEAD (snx_portlist); +static DEFINE_SPINLOCK (snx_full_list_lock); + +static DEFINE_SPINLOCK (snx_parportlist_lock); + +static LIST_HEAD (snx_all_ports); +static LIST_HEAD (snx_drivers); + +static DEFINE_SEMAPHORE (snx_registration_lock); + +static void sunix_dead_write_lines ( +struct snx_parport *p,unsigned char b) +{} +static unsigned char sunix_dead_read_lines ( +struct snx_parport *p) +{return 0 ; } +static unsigned char sunix_dead_frob_lines ( +struct snx_parport *p,unsigned char b,unsigned char c) +{return 0 ; } +static void sunix_dead_onearg (struct snx_parport *p) +{} +static void sunix_dead_initstate ( +struct snx_pardevice *d,struct snx_parport_state *s) +{} +static void sunix_dead_state ( +struct snx_parport *p,struct snx_parport_state *s) +{} +static size_t sunix_dead_write ( +struct snx_parport *p,const void *b,size_t l,int f) +{return 0 ; } +static size_t sunix_dead_read ( +struct snx_parport *p,void *b,size_t l,int f) +{return 0 ; } + + +static struct snx_parport_ops sunix_dead_ops = { + .write_data = sunix_dead_write_lines, + .read_data = sunix_dead_read_lines, + .write_control = sunix_dead_write_lines, + .read_control = sunix_dead_read_lines, + .frob_control = sunix_dead_frob_lines, + .read_status = sunix_dead_read_lines, + .enable_irq = sunix_dead_onearg, + .disable_irq = sunix_dead_onearg, + .data_forward = sunix_dead_onearg, + .data_reverse = sunix_dead_onearg, + .init_state = sunix_dead_initstate, + .save_state = sunix_dead_state, + .restore_state = sunix_dead_state, + .epp_write_data = sunix_dead_write, + .epp_read_data = sunix_dead_read,
mfd/sunix/snx_share.c line 68
Quoted 10 lines
mfd/sunix/snx_share.c new file +10
-0+ .epp_write_addr = sunix_dead_write, + .epp_read_addr = sunix_dead_read, + .ecp_write_data = sunix_dead_write, + .ecp_read_data = sunix_dead_read, + .ecp_write_addr = sunix_dead_write, + .compat_write_data = sunix_dead_write, + .nibble_read_data = sunix_dead_read, + .byte_read_data = sunix_dead_read, + .owner = NULL, +};
don't reimplement existing standard functionality. use the parport subsystem.
--mtx
Signature · 3 lines
Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Quoted 2 lines · Morris Ku
Driver for SUNIX Multi-I/O card.Based on
parport_pc.c,ppdev.candlp.cby Linus Torvalds, Theodore Ts'o.
Parallel port drivers should live in 'drivers/parport' and 'drivers/char'. LP drivers should live in 'drivers/char'.
Please them there.
Quoted 19 lines
Signed-off-by Morris Ku <[email protected]>--- mfd/sunix/snx_ieee1284.c | 144 +++++++ mfd/sunix/snx_ieee1284_ops.c | 258 +++++++++++++ mfd/sunix/snx_lp.c | 717 +++++++++++++++++++++++++++++++++++ mfd/sunix/snx_lp.h | 119 ++++++ mfd/sunix/snx_parallel.c | 397 +++++++++++++++++++ mfd/sunix/snx_ppdev.c | 454 ++++++++++++++++++++++ mfd/sunix/snx_ppdev.h | 15 + mfd/sunix/snx_share.c | 629 ++++++++++++++++++++++++++++++ 8 files changed, 2733 insertions(+) create mode 100644 mfd/sunix/snx_ieee1284.c create mode 100644 mfd/sunix/snx_ieee1284_ops.c create mode 100644 mfd/sunix/snx_lp.c create mode 100644 mfd/sunix/snx_lp.h create mode 100644 mfd/sunix/snx_parallel.c create mode 100644 mfd/sunix/snx_ppdev.c create mode 100644 mfd/sunix/snx_ppdev.h create mode 100644 mfd/sunix/snx_share.c
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
Please do not drop the list from your recipients.
Quoted 9 lines · Morris Ku 古文俊
Hello , Lee ,
Sunix multi-io card is a composite device,
contains serial and parallel port , before we trying to place the driver in the /drivers/char, but maintainer suggests go to /driver/mfd,so we move to here. this driver is special,it supports more than one interface, so we combine to a single driver.
The MFD subsystem is designed to register child devices. MFD drivers do not contain any true functionality themselves. If this device does multiple things, you can split the functionality into their relevant subsystems and register each of them from here.
There are 10's of examples available. Please take a look around some of the existing drivers to see how their functionality is split.
Quoted 30 lines · Morris Ku
Quoted 3 lines
Driver for SUNIX Multi-I/O card.Based on
parport_pc.c,ppdev.candlp.cby Linus Torvalds, Theodore Ts'o.Parallel port drivers should live in '
drivers/parport' and 'drivers/char'. LP drivers should live in 'drivers/char'.Please them there.
Quoted 19 lines
Signed-off-by Morris Ku <[email protected]>--- mfd/sunix/snx_ieee1284.c | 144 +++++++ mfd/sunix/snx_ieee1284_ops.c | 258 +++++++++++++ mfd/sunix/snx_lp.c | 717 +++++++++++++++++++++++++++++++++++ mfd/sunix/snx_lp.h | 119 ++++++ mfd/sunix/snx_parallel.c | 397 +++++++++++++++++++ mfd/sunix/snx_ppdev.c | 454 ++++++++++++++++++++++ mfd/sunix/snx_ppdev.h | 15 + mfd/sunix/snx_share.c | 629 ++++++++++++++++++++++++++++++ 8 files changed, 2733 insertions(+) create mode 100644 mfd/sunix/snx_ieee1284.c create mode 100644 mfd/sunix/snx_ieee1284_ops.c create mode 100644 mfd/sunix/snx_lp.c create mode 100644 mfd/sunix/snx_lp.h create mode 100644 mfd/sunix/snx_parallel.c create mode 100644 mfd/sunix/snx_ppdev.c create mode 100644 mfd/sunix/snx_ppdev.h create mode 100644 mfd/sunix/snx_share.c
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog