aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/synclink_gt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/synclink_gt.c')
-rw-r--r--drivers/char/synclink_gt.c250
1 files changed, 242 insertions, 8 deletions
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 738ec2f4e563..b4d1f4eea435 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: synclink_gt.c,v 4.22 2006/01/09 20:16:06 paulkf Exp $ 2 * $Id: synclink_gt.c,v 4.25 2006/02/06 21:20:33 paulkf Exp $
3 * 3 *
4 * Device driver for Microgate SyncLink GT serial adapters. 4 * Device driver for Microgate SyncLink GT serial adapters.
5 * 5 *
@@ -92,7 +92,7 @@
92 * module identification 92 * module identification
93 */ 93 */
94static char *driver_name = "SyncLink GT"; 94static char *driver_name = "SyncLink GT";
95static char *driver_version = "$Revision: 4.22 $"; 95static char *driver_version = "$Revision: 4.25 $";
96static char *tty_driver_name = "synclink_gt"; 96static char *tty_driver_name = "synclink_gt";
97static char *tty_dev_prefix = "ttySLG"; 97static char *tty_dev_prefix = "ttySLG";
98MODULE_LICENSE("GPL"); 98MODULE_LICENSE("GPL");
@@ -188,6 +188,20 @@ static void hdlcdev_exit(struct slgt_info *info);
188#define SLGT_REG_SIZE 256 188#define SLGT_REG_SIZE 256
189 189
190/* 190/*
191 * conditional wait facility
192 */
193struct cond_wait {
194 struct cond_wait *next;
195 wait_queue_head_t q;
196 wait_queue_t wait;
197 unsigned int data;
198};
199static void init_cond_wait(struct cond_wait *w, unsigned int data);
200static void add_cond_wait(struct cond_wait **head, struct cond_wait *w);
201static void remove_cond_wait(struct cond_wait **head, struct cond_wait *w);
202static void flush_cond_wait(struct cond_wait **head);
203
204/*
191 * DMA buffer descriptor and access macros 205 * DMA buffer descriptor and access macros
192 */ 206 */
193struct slgt_desc 207struct slgt_desc
@@ -269,6 +283,9 @@ struct slgt_info {
269 struct timer_list tx_timer; 283 struct timer_list tx_timer;
270 struct timer_list rx_timer; 284 struct timer_list rx_timer;
271 285
286 unsigned int gpio_present;
287 struct cond_wait *gpio_wait_q;
288
272 spinlock_t lock; /* spinlock for synchronizing with ISR */ 289 spinlock_t lock; /* spinlock for synchronizing with ISR */
273 290
274 struct work_struct task; 291 struct work_struct task;
@@ -379,6 +396,11 @@ static MGSL_PARAMS default_params = {
379#define MASK_OVERRUN BIT4 396#define MASK_OVERRUN BIT4
380 397
381#define GSR 0x00 /* global status */ 398#define GSR 0x00 /* global status */
399#define JCR 0x04 /* JTAG control */
400#define IODR 0x08 /* GPIO direction */
401#define IOER 0x0c /* GPIO interrupt enable */
402#define IOVR 0x10 /* GPIO value */
403#define IOSR 0x14 /* GPIO interrupt status */
382#define TDR 0x80 /* tx data */ 404#define TDR 0x80 /* tx data */
383#define RDR 0x80 /* rx data */ 405#define RDR 0x80 /* rx data */
384#define TCR 0x82 /* tx control */ 406#define TCR 0x82 /* tx control */
@@ -503,6 +525,9 @@ static int tiocmset(struct tty_struct *tty, struct file *file,
503static void set_break(struct tty_struct *tty, int break_state); 525static void set_break(struct tty_struct *tty, int break_state);
504static int get_interface(struct slgt_info *info, int __user *if_mode); 526static int get_interface(struct slgt_info *info, int __user *if_mode);
505static int set_interface(struct slgt_info *info, int if_mode); 527static int set_interface(struct slgt_info *info, int if_mode);
528static int set_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
529static int get_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
530static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *gpio);
506 531
507/* 532/*
508 * driver functions 533 * driver functions
@@ -1112,6 +1137,12 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1112 return get_interface(info, argp); 1137 return get_interface(info, argp);
1113 case MGSL_IOCSIF: 1138 case MGSL_IOCSIF:
1114 return set_interface(info,(int)arg); 1139 return set_interface(info,(int)arg);
1140 case MGSL_IOCSGPIO:
1141 return set_gpio(info, argp);
1142 case MGSL_IOCGGPIO:
1143 return get_gpio(info, argp);
1144 case MGSL_IOCWAITGPIO:
1145 return wait_gpio(info, argp);
1115 case TIOCGICOUNT: 1146 case TIOCGICOUNT:
1116 spin_lock_irqsave(&info->lock,flags); 1147 spin_lock_irqsave(&info->lock,flags);
1117 cnow = info->icount; 1148 cnow = info->icount;
@@ -1762,10 +1793,6 @@ static void rx_async(struct slgt_info *info)
1762 DBGDATA(info, p, count, "rx"); 1793 DBGDATA(info, p, count, "rx");
1763 1794
1764 for(i=0 ; i < count; i+=2, p+=2) { 1795 for(i=0 ; i < count; i+=2, p+=2) {
1765 if (tty && chars) {
1766 tty_flip_buffer_push(tty);
1767 chars = 0;
1768 }
1769 ch = *p; 1796 ch = *p;
1770 icount->rx++; 1797 icount->rx++;
1771 1798
@@ -2158,6 +2185,24 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
2158 } 2185 }
2159} 2186}
2160 2187
2188static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int state)
2189{
2190 struct cond_wait *w, *prev;
2191
2192 /* wake processes waiting for specific transitions */
2193 for (w = info->gpio_wait_q, prev = NULL ; w != NULL ; w = w->next) {
2194 if (w->data & changed) {
2195 w->data = state;
2196 wake_up_interruptible(&w->q);
2197 if (prev != NULL)
2198 prev->next = w->next;
2199 else
2200 info->gpio_wait_q = w->next;
2201 } else
2202 prev = w;
2203 }
2204}
2205
2161/* interrupt service routine 2206/* interrupt service routine
2162 * 2207 *
2163 * irq interrupt number 2208 * irq interrupt number
@@ -2193,6 +2238,22 @@ static irqreturn_t slgt_interrupt(int irq, void *dev_id, struct pt_regs * regs)
2193 } 2238 }
2194 } 2239 }
2195 2240
2241 if (info->gpio_present) {
2242 unsigned int state;
2243 unsigned int changed;
2244 while ((changed = rd_reg32(info, IOSR)) != 0) {
2245 DBGISR(("%s iosr=%08x\n", info->device_name, changed));
2246 /* read latched state of GPIO signals */
2247 state = rd_reg32(info, IOVR);
2248 /* clear pending GPIO interrupt bits */
2249 wr_reg32(info, IOSR, changed);
2250 for (i=0 ; i < info->port_count ; i++) {
2251 if (info->port_array[i] != NULL)
2252 isr_gpio(info->port_array[i], changed, state);
2253 }
2254 }
2255 }
2256
2196 for(i=0; i < info->port_count ; i++) { 2257 for(i=0; i < info->port_count ; i++) {
2197 struct slgt_info *port = info->port_array[i]; 2258 struct slgt_info *port = info->port_array[i];
2198 2259
@@ -2276,6 +2337,8 @@ static void shutdown(struct slgt_info *info)
2276 set_signals(info); 2337 set_signals(info);
2277 } 2338 }
2278 2339
2340 flush_cond_wait(&info->gpio_wait_q);
2341
2279 spin_unlock_irqrestore(&info->lock,flags); 2342 spin_unlock_irqrestore(&info->lock,flags);
2280 2343
2281 if (info->tty) 2344 if (info->tty)
@@ -2650,6 +2713,175 @@ static int set_interface(struct slgt_info *info, int if_mode)
2650 return 0; 2713 return 0;
2651} 2714}
2652 2715
2716/*
2717 * set general purpose IO pin state and direction
2718 *
2719 * user_gpio fields:
2720 * state each bit indicates a pin state
2721 * smask set bit indicates pin state to set
2722 * dir each bit indicates a pin direction (0=input, 1=output)
2723 * dmask set bit indicates pin direction to set
2724 */
2725static int set_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2726{
2727 unsigned long flags;
2728 struct gpio_desc gpio;
2729 __u32 data;
2730
2731 if (!info->gpio_present)
2732 return -EINVAL;
2733 if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
2734 return -EFAULT;
2735 DBGINFO(("%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
2736 info->device_name, gpio.state, gpio.smask,
2737 gpio.dir, gpio.dmask));
2738
2739 spin_lock_irqsave(&info->lock,flags);
2740 if (gpio.dmask) {
2741 data = rd_reg32(info, IODR);
2742 data |= gpio.dmask & gpio.dir;
2743 data &= ~(gpio.dmask & ~gpio.dir);
2744 wr_reg32(info, IODR, data);
2745 }
2746 if (gpio.smask) {
2747 data = rd_reg32(info, IOVR);
2748 data |= gpio.smask & gpio.state;
2749 data &= ~(gpio.smask & ~gpio.state);
2750 wr_reg32(info, IOVR, data);
2751 }
2752 spin_unlock_irqrestore(&info->lock,flags);
2753
2754 return 0;
2755}
2756
2757/*
2758 * get general purpose IO pin state and direction
2759 */
2760static int get_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2761{
2762 struct gpio_desc gpio;
2763 if (!info->gpio_present)
2764 return -EINVAL;
2765 gpio.state = rd_reg32(info, IOVR);
2766 gpio.smask = 0xffffffff;
2767 gpio.dir = rd_reg32(info, IODR);
2768 gpio.dmask = 0xffffffff;
2769 if (copy_to_user(user_gpio, &gpio, sizeof(gpio)))
2770 return -EFAULT;
2771 DBGINFO(("%s get_gpio state=%08x dir=%08x\n",
2772 info->device_name, gpio.state, gpio.dir));
2773 return 0;
2774}
2775
2776/*
2777 * conditional wait facility
2778 */
2779static void init_cond_wait(struct cond_wait *w, unsigned int data)
2780{
2781 init_waitqueue_head(&w->q);
2782 init_waitqueue_entry(&w->wait, current);
2783 w->data = data;
2784}
2785
2786static void add_cond_wait(struct cond_wait **head, struct cond_wait *w)
2787{
2788 set_current_state(TASK_INTERRUPTIBLE);
2789 add_wait_queue(&w->q, &w->wait);
2790 w->next = *head;
2791 *head = w;
2792}
2793
2794static void remove_cond_wait(struct cond_wait **head, struct cond_wait *cw)
2795{
2796 struct cond_wait *w, *prev;
2797 remove_wait_queue(&cw->q, &cw->wait);
2798 set_current_state(TASK_RUNNING);
2799 for (w = *head, prev = NULL ; w != NULL ; prev = w, w = w->next) {
2800 if (w == cw) {
2801 if (prev != NULL)
2802 prev->next = w->next;
2803 else
2804 *head = w->next;
2805 break;
2806 }
2807 }
2808}
2809
2810static void flush_cond_wait(struct cond_wait **head)
2811{
2812 while (*head != NULL) {
2813 wake_up_interruptible(&(*head)->q);
2814 *head = (*head)->next;
2815 }
2816}
2817
2818/*
2819 * wait for general purpose I/O pin(s) to enter specified state
2820 *
2821 * user_gpio fields:
2822 * state - bit indicates target pin state
2823 * smask - set bit indicates watched pin
2824 *
2825 * The wait ends when at least one watched pin enters the specified
2826 * state. When 0 (no error) is returned, user_gpio->state is set to the
2827 * state of all GPIO pins when the wait ends.
2828 *
2829 * Note: Each pin may be a dedicated input, dedicated output, or
2830 * configurable input/output. The number and configuration of pins
2831 * varies with the specific adapter model. Only input pins (dedicated
2832 * or configured) can be monitored with this function.
2833 */
2834static int wait_gpio(struct slgt_info *info, struct gpio_desc __user *user_gpio)
2835{
2836 unsigned long flags;
2837 int rc = 0;
2838 struct gpio_desc gpio;
2839 struct cond_wait wait;
2840 u32 state;
2841
2842 if (!info->gpio_present)
2843 return -EINVAL;
2844 if (copy_from_user(&gpio, user_gpio, sizeof(gpio)))
2845 return -EFAULT;
2846 DBGINFO(("%s wait_gpio() state=%08x smask=%08x\n",
2847 info->device_name, gpio.state, gpio.smask));
2848 /* ignore output pins identified by set IODR bit */
2849 if ((gpio.smask &= ~rd_reg32(info, IODR)) == 0)
2850 return -EINVAL;
2851 init_cond_wait(&wait, gpio.smask);
2852
2853 spin_lock_irqsave(&info->lock, flags);
2854 /* enable interrupts for watched pins */
2855 wr_reg32(info, IOER, rd_reg32(info, IOER) | gpio.smask);
2856 /* get current pin states */
2857 state = rd_reg32(info, IOVR);
2858
2859 if (gpio.smask & ~(state ^ gpio.state)) {
2860 /* already in target state */
2861 gpio.state = state;
2862 } else {
2863 /* wait for target state */
2864 add_cond_wait(&info->gpio_wait_q, &wait);
2865 spin_unlock_irqrestore(&info->lock, flags);
2866 schedule();
2867 if (signal_pending(current))
2868 rc = -ERESTARTSYS;
2869 else
2870 gpio.state = wait.data;
2871 spin_lock_irqsave(&info->lock, flags);
2872 remove_cond_wait(&info->gpio_wait_q, &wait);
2873 }
2874
2875 /* disable all GPIO interrupts if no waiting processes */
2876 if (info->gpio_wait_q == NULL)
2877 wr_reg32(info, IOER, 0);
2878 spin_unlock_irqrestore(&info->lock,flags);
2879
2880 if ((rc == 0) && copy_to_user(user_gpio, &gpio, sizeof(gpio)))
2881 rc = -EFAULT;
2882 return rc;
2883}
2884
2653static int modem_input_wait(struct slgt_info *info,int arg) 2885static int modem_input_wait(struct slgt_info *info,int arg)
2654{ 2886{
2655 unsigned long flags; 2887 unsigned long flags;
@@ -3166,8 +3398,10 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3166 } else { 3398 } else {
3167 port_array[0]->irq_requested = 1; 3399 port_array[0]->irq_requested = 1;
3168 adapter_test(port_array[0]); 3400 adapter_test(port_array[0]);
3169 for (i=1 ; i < port_count ; i++) 3401 for (i=1 ; i < port_count ; i++) {
3170 port_array[i]->init_error = port_array[0]->init_error; 3402 port_array[i]->init_error = port_array[0]->init_error;
3403 port_array[i]->gpio_present = port_array[0]->gpio_present;
3404 }
3171 } 3405 }
3172 } 3406 }
3173} 3407}
@@ -4301,7 +4535,7 @@ static int register_test(struct slgt_info *info)
4301 break; 4535 break;
4302 } 4536 }
4303 } 4537 }
4304 4538 info->gpio_present = (rd_reg32(info, JCR) & BIT5) ? 1 : 0;
4305 info->init_error = rc ? 0 : DiagStatus_AddressFailure; 4539 info->init_error = rc ? 0 : DiagStatus_AddressFailure;
4306 return rc; 4540 return rc;
4307} 4541}