1 /*****************************************************************************
5 *****************************************************************************/
8 * Copyright (C) 2010 R.M. Thomas <rmthomas@sciolus.org>
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The software is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this software; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /*****************************************************************************/
27 /*---------------------------------------------------------------------------*/
29 * THE FOLLOWING PARAMETERS ARE UNDEFINED:
32 * EASYCAP_IS_VIDEODEV_CLIENT
33 * EASYCAP_NEEDS_USBVIDEO_H
34 * EASYCAP_NEEDS_V4L2_DEVICE_H
35 * EASYCAP_NEEDS_V4L2_FOPS
36 * EASYCAP_NEEDS_UNLOCKED_IOCTL
40 * IF REQUIRED THEY MUST BE EXTERNALLY DEFINED, FOR EXAMPLE AS COMPILER
43 /*---------------------------------------------------------------------------*/
45 #if (!defined(EASYCAP_H))
48 /*---------------------------------------------------------------------------*/
50 * THESE ARE NORMALLY DEFINED
52 /*---------------------------------------------------------------------------*/
56 /*---------------------------------------------------------------------------*/
58 * THESE ARE FOR MAINTENANCE ONLY - NORMALLY UNDEFINED:
60 /*---------------------------------------------------------------------------*/
61 #undef EASYCAP_TESTCARD
62 #if (!defined(EASYCAP_NEEDS_ALSA))
63 #undef EASYCAP_TESTTONE
64 #endif /*EASYCAP_NEEDS_ALSA*/
65 /*---------------------------------------------------------------------------*/
66 #include <linux/kernel.h>
67 #include <linux/errno.h>
68 #include <linux/init.h>
69 #include <linux/slab.h>
70 #include <linux/module.h>
71 #include <linux/kref.h>
72 #include <linux/usb.h>
73 #include <linux/uaccess.h>
75 #include <linux/i2c.h>
76 #include <linux/version.h>
77 #include <linux/workqueue.h>
78 #include <linux/poll.h>
81 #include <linux/delay.h>
82 #include <linux/types.h>
84 #if defined(EASYCAP_NEEDS_ALSA)
85 #include <linux/vmalloc.h>
86 #include <linux/sound.h>
87 #include <sound/core.h>
88 #include <sound/pcm.h>
89 #include <sound/pcm_params.h>
90 #include <sound/info.h>
91 #include <sound/initval.h>
92 #include <sound/control.h>
93 #endif /*EASYCAP_NEEDS_ALSA*/
94 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
95 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
96 #include <media/v4l2-dev.h>
97 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
98 #include <media/v4l2-device.h>
99 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
100 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
101 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
102 #include <linux/videodev2.h>
103 #include <linux/soundcard.h>
104 #if defined(EASYCAP_NEEDS_USBVIDEO_H)
105 #include <config/video/usbvideo.h>
106 #endif /*EASYCAP_NEEDS_USBVIDEO_H*/
108 #if (!defined(PAGE_SIZE))
109 #error "PAGE_SIZE not defined"
112 #define STRINGIZE_AGAIN(x) #x
113 #define STRINGIZE(x) STRINGIZE_AGAIN(x)
114 /*---------------------------------------------------------------------------*/
115 /* VENDOR, PRODUCT: Syntek Semiconductor Co., Ltd
117 * EITHER EasyCAP USB 2.0 Video Adapter with Audio, Model No. DC60
118 * with input cabling: AUDIO(L), AUDIO(R), CVBS, S-VIDEO.
120 * OR EasyCAP 4CHANNEL USB 2.0 DVR, Model No. EasyCAP002
121 * with input cabling: MICROPHONE, CVBS1, CVBS2, CVBS3, CVBS4.
123 /*---------------------------------------------------------------------------*/
124 #define USB_EASYCAP_VENDOR_ID 0x05e1
125 #define USB_EASYCAP_PRODUCT_ID 0x0408
127 #define EASYCAP_DRIVER_VERSION "0.9.01"
128 #define EASYCAP_DRIVER_DESCRIPTION "easycapdc60"
130 #define USB_SKEL_MINOR_BASE 192
131 #define DONGLE_MANY 8
133 /*---------------------------------------------------------------------------*/
135 * DEFAULT LUMINANCE, CONTRAST, SATURATION AND HUE
137 /*---------------------------------------------------------------------------*/
138 #define SAA_0A_DEFAULT 0x7F
139 #define SAA_0B_DEFAULT 0x3F
140 #define SAA_0C_DEFAULT 0x2F
141 #define SAA_0D_DEFAULT 0x00
142 /*---------------------------------------------------------------------------*/
144 * VIDEO STREAMING PARAMETERS:
145 * USB 2.0 PROVIDES FOR HIGH-BANDWIDTH ENDPOINTS WITH AN UPPER LIMIT
146 * OF 3072 BYTES PER MICROFRAME for wMaxPacketSize.
148 /*---------------------------------------------------------------------------*/
149 #define VIDEO_ISOC_BUFFER_MANY 16
150 #define VIDEO_ISOC_ORDER 3
151 #define VIDEO_ISOC_FRAMESPERDESC ((unsigned int) 1 << VIDEO_ISOC_ORDER)
152 #define USB_2_0_MAXPACKETSIZE 3072
153 #if (USB_2_0_MAXPACKETSIZE > PAGE_SIZE)
154 #error video_isoc_buffer[.] will not be big enough
156 #define VIDEO_JUNK_TOLERATE VIDEO_ISOC_BUFFER_MANY
157 #define VIDEO_LOST_TOLERATE 50
158 /*---------------------------------------------------------------------------*/
162 /*---------------------------------------------------------------------------*/
163 #define FIELD_BUFFER_SIZE (203 * PAGE_SIZE)
164 #define FRAME_BUFFER_SIZE (405 * PAGE_SIZE)
165 #define FIELD_BUFFER_MANY 4
166 #define FRAME_BUFFER_MANY 6
167 /*---------------------------------------------------------------------------*/
169 * AUDIO STREAMING PARAMETERS
171 /*---------------------------------------------------------------------------*/
172 #define AUDIO_ISOC_BUFFER_MANY 16
173 #define AUDIO_ISOC_ORDER 1
174 #define AUDIO_ISOC_FRAMESPERDESC 32
175 #define AUDIO_ISOC_BUFFER_SIZE (PAGE_SIZE << AUDIO_ISOC_ORDER)
176 /*---------------------------------------------------------------------------*/
180 /*---------------------------------------------------------------------------*/
181 #define AUDIO_FRAGMENT_MANY 32
182 #define PAGES_PER_AUDIO_FRAGMENT 4
183 /*---------------------------------------------------------------------------*/
185 * IT IS ESSENTIAL THAT EVEN-NUMBERED STANDARDS ARE 25 FRAMES PER SECOND,
186 * ODD-NUMBERED STANDARDS ARE 30 FRAMES PER SECOND.
187 * THE NUMBERING OF STANDARDS MUST NOT BE CHANGED WITHOUT DUE CARE. NOT
188 * ONLY MUST THE PARAMETER
190 * BE CHANGED TO CORRESPOND TO THE NEW NUMBER OF STANDARDS, BUT ALSO THE
191 * NUMBERING MUST REMAIN AN UNBROKEN ASCENDING SEQUENCE: DUMMY STANDARDS
192 * MAY NEED TO BE ADDED. APPROPRIATE CHANGES WILL ALWAYS BE REQUIRED IN
193 * ROUTINE fillin_formats() AND POSSIBLY ELSEWHERE. BEWARE.
195 /*---------------------------------------------------------------------------*/
206 #define PAL_BGHIN_SLOW 10
207 #define PAL_Nc_SLOW 12
208 #define SECAM_SLOW 14
209 #define NTSC_N_SLOW 16
210 #define NTSC_N_443_SLOW 18
211 #define NTSC_M_SLOW 11
212 #define NTSC_443_SLOW 13
213 #define NTSC_M_JP_SLOW 15
214 #define PAL_60_SLOW 17
215 #define PAL_M_SLOW 19
216 #define STANDARD_MANY 20
217 /*---------------------------------------------------------------------------*/
221 /*---------------------------------------------------------------------------*/
246 #define SETTINGS_MANY (STANDARD_MANY * \
251 /*---------------------------------------------------------------------------*/
253 * STRUCTURE DEFINITIONS
255 /*---------------------------------------------------------------------------*/
256 struct easycap_dongle {
257 struct easycap *peasycap;
258 struct mutex mutex_video;
259 struct mutex mutex_audio;
261 /*---------------------------------------------------------------------------*/
263 struct list_head list_head;
269 /*---------------------------------------------------------------------------*/
271 struct list_head list_head;
276 /*---------------------------------------------------------------------------*/
277 struct easycap_standard {
279 struct v4l2_standard v4l2_standard;
281 struct easycap_format {
284 struct v4l2_format v4l2_format;
290 int standard_offset_ok;
292 int format_offset_ok;
302 /*---------------------------------------------------------------------------*/
304 * easycap.ilk == 0 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=256
305 * easycap.ilk == 2 => CVBS+S-VIDEO HARDWARE, AUDIO wMaxPacketSize=9
306 * easycap.ilk == 3 => FOUR-CVBS HARDWARE, AUDIO wMaxPacketSize=9
308 /*---------------------------------------------------------------------------*/
310 #define TELLTALE "expectedstring"
315 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
316 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
317 struct video_device video_device;
318 #if defined(EASYCAP_NEEDS_V4L2_DEVICE_H)
319 struct v4l2_device v4l2_device;
320 #endif /*EASYCAP_NEEDS_V4L2_DEVICE_H*/
321 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
322 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
324 unsigned int audio_pages_per_fragment;
325 unsigned int audio_bytes_per_fragment;
326 unsigned int audio_buffer_page_many;
329 #if defined(UPSAMPLE)
336 struct usb_device *pusb_device;
337 struct usb_interface *pusb_interface;
341 int queued[FRAME_BUFFER_MANY];
342 int done[FRAME_BUFFER_MANY];
344 wait_queue_head_t wq_video;
345 wait_queue_head_t wq_audio;
346 wait_queue_head_t wq_trigger;
352 struct inputset inputset[INPUT_MANY];
360 int lost[INPUT_MANY];
363 struct timeval timeval0;
364 struct timeval timeval1;
365 struct timeval timeval2;
366 struct timeval timeval3;
367 struct timeval timeval6;
368 struct timeval timeval7;
369 struct timeval timeval8;
370 long long int dnbydt;
373 int video_altsetting_on;
374 int video_altsetting_off;
375 int video_endpointnumber;
376 int video_isoc_maxframesize;
377 int video_isoc_buffer_size;
378 int video_isoc_framesperdesc;
380 int video_isoc_streaming;
381 int video_isoc_sequence;
386 struct data_buffer video_isoc_buffer[VIDEO_ISOC_BUFFER_MANY];
388 field_buffer[FIELD_BUFFER_MANY][(FIELD_BUFFER_SIZE/PAGE_SIZE)];
390 frame_buffer[FRAME_BUFFER_MANY][(FRAME_BUFFER_SIZE/PAGE_SIZE)];
392 struct list_head urb_video_head;
393 struct list_head *purb_video_head;
399 long long audio_bytes;
404 /*---------------------------------------------------------------------------*/
408 /*---------------------------------------------------------------------------*/
409 int field_fill; /* Field buffer being filled by easycap_complete(). */
410 /* Bumped only by easycap_complete(). */
411 int field_page; /* Page of field buffer page being filled by */
412 /* easycap_complete(). */
413 int field_read; /* Field buffer to be read by field2frame(). */
414 /* Bumped only by easycap_complete(). */
415 int frame_fill; /* Frame buffer being filled by field2frame(). */
416 /* Bumped only by easycap_dqbuf() when */
417 /* field2frame() has created a complete frame. */
418 int frame_read; /* Frame buffer offered to user by DQBUF. */
419 /* Set only by easycap_dqbuf() to trail frame_fill.*/
420 int frame_lock; /* Flag set to 1 by DQBUF and cleared by QBUF */
421 /*---------------------------------------------------------------------------*/
425 /*---------------------------------------------------------------------------*/
433 int frame_buffer_used;
434 int frame_buffer_many;
435 int videofieldamount;
442 int allocation_video_urb;
443 int allocation_video_page;
444 int allocation_video_struct;
445 int registered_video;
446 /*---------------------------------------------------------------------------*/
450 /*---------------------------------------------------------------------------*/
451 #if defined(EASYCAP_NEEDS_ALSA)
452 struct snd_pcm_hardware alsa_hardware;
453 struct snd_card *psnd_card;
454 struct snd_pcm *psnd_pcm;
455 struct snd_pcm_substream *psubstream;
459 #endif /*EASYCAP_NEEDS_ALSA*/
460 /*---------------------------------------------------------------------------*/
464 /*---------------------------------------------------------------------------*/
466 int audio_altsetting_on;
467 int audio_altsetting_off;
468 int audio_endpointnumber;
469 int audio_isoc_maxframesize;
470 int audio_isoc_buffer_size;
471 int audio_isoc_framesperdesc;
473 int audio_isoc_streaming;
480 struct data_buffer audio_isoc_buffer[AUDIO_ISOC_BUFFER_MANY];
482 struct list_head urb_audio_head;
483 struct list_head *purb_audio_head;
484 /*---------------------------------------------------------------------------*/
488 /*---------------------------------------------------------------------------*/
489 int audio_fill; /* Audio buffer being filled by easycap_complete(). */
490 /* Bumped only by easycap_complete(). */
491 int audio_read; /* Audio buffer page being read by easycap_read(). */
492 /* Set by easycap_read() to trail audio_fill by */
494 /*---------------------------------------------------------------------------*/
498 /*---------------------------------------------------------------------------*/
500 int audio_buffer_many;
502 int allocation_audio_urb;
503 int allocation_audio_page;
504 int allocation_audio_struct;
505 int registered_audio;
507 long long int audio_sample;
508 long long int audio_niveau;
509 long long int audio_square;
511 struct data_buffer audio_buffer[];
513 /*---------------------------------------------------------------------------*/
515 * VIDEO FUNCTION PROTOTYPES
517 /*---------------------------------------------------------------------------*/
518 void easycap_complete(struct urb *);
519 int easycap_open(struct inode *, struct file *);
520 int easycap_release(struct inode *, struct file *);
521 long easycap_ioctl_noinode(struct file *, unsigned int,
523 int easycap_ioctl(struct inode *, struct file *, unsigned int,
525 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
526 #if defined(EASYCAP_IS_VIDEODEV_CLIENT)
527 int easycap_open_noinode(struct file *);
528 int easycap_release_noinode(struct file *);
529 int videodev_release(struct video_device *);
530 #endif /*EASYCAP_IS_VIDEODEV_CLIENT*/
531 /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
533 unsigned int easycap_poll(struct file *, poll_table *);
534 int easycap_mmap(struct file *, struct vm_area_struct *);
535 int easycap_usb_probe(struct usb_interface *,
536 const struct usb_device_id *);
537 void easycap_usb_disconnect(struct usb_interface *);
538 void easycap_delete(struct kref *);
540 void easycap_vma_open(struct vm_area_struct *);
541 void easycap_vma_close(struct vm_area_struct *);
542 int easycap_vma_fault(struct vm_area_struct *, struct vm_fault *);
543 int easycap_dqbuf(struct easycap *, int);
544 int submit_video_urbs(struct easycap *);
545 int kill_video_urbs(struct easycap *);
546 int field2frame(struct easycap *);
547 int redaub(struct easycap *, void *, void *,
548 int, int, __u8, __u8, bool);
549 void easycap_testcard(struct easycap *, int);
550 int fillin_formats(void);
551 int reset(struct easycap *);
552 int newinput(struct easycap *, int);
553 int adjust_standard(struct easycap *, v4l2_std_id);
554 int adjust_format(struct easycap *, __u32, __u32, __u32,
556 int adjust_brightness(struct easycap *, int);
557 int adjust_contrast(struct easycap *, int);
558 int adjust_saturation(struct easycap *, int);
559 int adjust_hue(struct easycap *, int);
560 int adjust_volume(struct easycap *, int);
561 /*---------------------------------------------------------------------------*/
563 * AUDIO FUNCTION PROTOTYPES
565 /*---------------------------------------------------------------------------*/
566 #if defined(EASYCAP_NEEDS_ALSA)
567 int easycap_alsa_probe(struct easycap *);
569 void easycap_alsa_complete(struct urb *);
570 int easycap_alsa_open(struct snd_pcm_substream *);
571 int easycap_alsa_close(struct snd_pcm_substream *);
572 int easycap_alsa_hw_params(struct snd_pcm_substream *,
573 struct snd_pcm_hw_params *);
574 int easycap_alsa_vmalloc(struct snd_pcm_substream *, size_t);
575 int easycap_alsa_hw_free(struct snd_pcm_substream *);
576 int easycap_alsa_prepare(struct snd_pcm_substream *);
577 int easycap_alsa_ack(struct snd_pcm_substream *);
578 int easycap_alsa_trigger(struct snd_pcm_substream *, int);
579 snd_pcm_uframes_t easycap_alsa_pointer(struct snd_pcm_substream *);
580 struct page *easycap_alsa_page(struct snd_pcm_substream *, unsigned long);
583 void easyoss_complete(struct urb *);
584 ssize_t easyoss_read(struct file *, char __user *, size_t, loff_t *);
585 int easyoss_open(struct inode *, struct file *);
586 int easyoss_release(struct inode *, struct file *);
587 long easyoss_ioctl_noinode(struct file *, unsigned int,
589 int easyoss_ioctl(struct inode *, struct file *, unsigned int,
591 unsigned int easyoss_poll(struct file *, poll_table *);
592 void easyoss_delete(struct kref *);
593 #endif /*EASYCAP_NEEDS_ALSA*/
594 int easycap_sound_setup(struct easycap *);
595 int submit_audio_urbs(struct easycap *);
596 int kill_audio_urbs(struct easycap *);
597 void easyoss_testtone(struct easycap *, int);
598 int audio_setup(struct easycap *);
599 /*---------------------------------------------------------------------------*/
601 * LOW-LEVEL FUNCTION PROTOTYPES
603 /*---------------------------------------------------------------------------*/
604 int audio_gainget(struct usb_device *);
605 int audio_gainset(struct usb_device *, __s8);
607 int set_interface(struct usb_device *, __u16);
608 int wakeup_device(struct usb_device *);
609 int confirm_resolution(struct usb_device *);
610 int confirm_stream(struct usb_device *);
612 int setup_stk(struct usb_device *, bool);
613 int setup_saa(struct usb_device *, bool);
614 int setup_vt(struct usb_device *);
615 int check_stk(struct usb_device *, bool);
616 int check_saa(struct usb_device *, bool);
617 int ready_saa(struct usb_device *);
618 int merit_saa(struct usb_device *);
619 int check_vt(struct usb_device *);
620 int select_input(struct usb_device *, int, int);
621 int set_resolution(struct usb_device *,
622 __u16, __u16, __u16, __u16);
624 int read_saa(struct usb_device *, __u16);
625 int read_stk(struct usb_device *, __u32);
626 int write_saa(struct usb_device *, __u16, __u16);
627 int wait_i2c(struct usb_device *);
628 int write_000(struct usb_device *, __u16, __u16);
629 int start_100(struct usb_device *);
630 int stop_100(struct usb_device *);
631 int write_300(struct usb_device *);
632 int read_vt(struct usb_device *, __u16);
633 int write_vt(struct usb_device *, __u16, __u16);
634 int regset(struct usb_device *, __u16, __u16);
635 int regget(struct usb_device *, __u16, void *);
636 int isdongle(struct easycap *);
637 /*---------------------------------------------------------------------------*/
638 struct signed_div_result {
639 long long int quotient;
640 unsigned long long int remainder;
641 } signed_div(long long int, long long int);
644 /*---------------------------------------------------------------------------*/
648 /*---------------------------------------------------------------------------*/
649 #define GET(X, Y, Z) do { \
652 rc = regget(X, Y, Z); \
654 JOT(8, ":-(%i\n", __LINE__); return(rc); \
658 #define SET(X, Y, Z) do { \
660 rc = regset(X, Y, Z); \
662 JOT(8, ":-(%i\n", __LINE__); return(rc); \
665 /*---------------------------------------------------------------------------*/
667 * MACROS SAM(...) AND JOM(...) ALLOW DIAGNOSTIC OUTPUT TO BE TAGGED WITH
668 * THE IDENTITY OF THE DONGLE TO WHICH IT APPLIES, BUT IF INVOKED WHEN THE
669 * POINTER peasycap IS INVALID AN Oops IS LIKELY, AND ITS CAUSE MAY NOT BE
670 * IMMEDIATELY OBVIOUS FROM A CASUAL READING OF THE SOURCE CODE. BEWARE.
672 /*---------------------------------------------------------------------------*/
673 extern int easycap_debug;
674 #define SAY(format, args...) do { \
675 printk(KERN_DEBUG "easycap:: %s: " \
676 format, __func__, ##args); \
678 #define SAM(format, args...) do { \
679 printk(KERN_DEBUG "easycap::%i%s: " \
680 format, peasycap->isdongle, __func__, ##args);\
683 #if defined(EASYCAP_DEBUG)
684 #define JOT(n, format, args...) do { \
685 if (n <= easycap_debug) { \
686 printk(KERN_DEBUG "easycap:: %s: " \
687 format, __func__, ##args);\
690 #define JOM(n, format, args...) do { \
691 if (n <= easycap_debug) { \
692 printk(KERN_DEBUG "easycap::%i%s: " \
693 format, peasycap->isdongle, __func__, ##args);\
698 #define JOT(n, format, args...) do {} while (0)
699 #define JOM(n, format, args...) do {} while (0)
700 #endif /*EASYCAP_DEBUG*/
702 #define MICROSECONDS(X, Y) \
703 ((1000000*((long long int)(X.tv_sec - Y.tv_sec))) + \
704 (long long int)(X.tv_usec - Y.tv_usec))
706 /*---------------------------------------------------------------------------*/
708 * (unsigned char *)P pointer to next byte pair
709 * (long int *)X pointer to accumulating count
710 * (long int *)Y pointer to accumulating sum
711 * (long long int *)Z pointer to accumulating sum of squares
713 /*---------------------------------------------------------------------------*/
714 #define SUMMER(P, X, Y, Z) do { \
716 unsigned int u0, u1, u2; \
718 p = (unsigned char *)(P); \
719 u0 = (unsigned int) (*p); \
720 u1 = (unsigned int) (*(p + 1)); \
721 u2 = (unsigned int) ((u1 << 8) | u0); \
723 s = -(long int)(0x7FFF & (~u2)); \
725 s = (long int)(0x7FFF & u2); \
726 *((X)) += (long int) 1; \
727 *((Y)) += (long int) s; \
728 *((Z)) += ((long long int)(s) * (long long int)(s)); \
730 /*---------------------------------------------------------------------------*/