2 * Copyright (c) 2003, 2004, 2005
3 * John Wehle <john@feith.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 /* Set the channel of the tuner card. */
31 #include <sys/ioctl.h>
32 #include <sys/param.h>
42 #include <dev/bktr/ioctl_meteor.h>
43 #include <dev/bktr/ioctl_bt848.h>
49 ("Usage: setchannel [-a {on|off}] [-c | -r | -s | -t] "
50 "[-g geom] [-m chnl_set] [chnl | freq]\n"
51 " -a Enable / disable AFC.\n"
52 " -c Select composite input.\n"
53 " -d Select tuner unit number.\n"
54 " -r Select radio input.\n"
55 " -s Select svideo input.\n"
57 " -g Select geometry.\n"
58 " 352x240 or 352x288 = VCD\n"
59 " 480x480 or 480x576 = SVCD\n"
60 " 352x480 or 352x576 = DVD (half D1)\n"
61 " 720x480 or 720x576 = DVD (full D1)\n"
62 " -m Select channel set / system.\n"
63 " 0 = Tuner Default\n"
64 " %u = US Broadcast / NTSC\n"
65 " %u = US Cable / NTSC\n"
66 " %u = Western Europe / PAL\n"
67 " %u = Japan Broadcast / NTSC\n"
68 " %u = Japan Cable / NTSC\n"
69 " %u = Australia / PAL\n"
70 " %u = France / SECAM\n"
72 " freq Frequency in MHz (must include decimal point).\n",
73 CHNLSET_NABCST, CHNLSET_CABLEIRC, CHNLSET_WEUROPE, CHNLSET_JPNBCST,
74 CHNLSET_JPNCABLE, CHNLSET_AUSTRALIA, CHNLSET_FRANCE);
77 #define DEVNAME_BASE "/dev/cxm"
81 main(int argc, char *argv[])
94 unsigned int fraction;
99 struct bktr_capture_area cap;
112 while ((c = getopt(argc, argv, "a:cd:rg:m:st")) != -1)
116 if (strcasecmp(optarg, "on") == 0)
118 else if (strcasecmp(optarg, "off") == 0)
127 device = METEOR_INPUT_DEV2;
137 audio = AUDIO_INTERN;
141 device = METEOR_INPUT_DEV_SVIDEO;
146 device = METEOR_INPUT_DEV1;
151 if (sscanf(optarg, "%ux%u", &x_size, &y_size) != 2
152 || x_size == 0 || y_size == 0) {
159 channel_set = atoi(optarg);
160 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
174 * A number containing a decimal point is the frequency in MHz.
177 if ((ptr = strchr(argv[optind], '.')) != NULL) {
178 freq = strtol(argv[optind], &endptr, 10) * 1000;
186 fraction = strtol(ptr, &endptr, 10);
187 if (!isdigit(*ptr) || *endptr != '\0') {
192 for (i = endptr - ptr; i > 3; i--)
200 /* An integer is the channel. */
202 channel = atoi(argv[optind]);
205 if (afc == -1 && audio == -1 && !device && x_size == 0 && y_size == 0
206 && channel_set == -1 && !channel && !freq) {
211 sprintf(dev_name, DEVNAME_BASE "%d", unit);
212 tfd = open(dev_name, O_RDONLY);
214 fprintf(stderr, "Can't open %s: %s (%d)\n", dev_name,
215 strerror(errno), errno);
220 if (ioctl(tfd, TVTUNER_SETAFC, &afc) < 0) {
221 perror("ioctl(tfd, TVTUNER_SETAFC) failed.");
226 if (ioctl(tfd, METEORSINPUT, &device) < 0) {
227 perror("ioctl(tfd, METEORSINPUT) failed.");
232 if (ioctl(tfd, BT848_SAUDIO, &audio) < 0) {
233 perror("ioctl(tfd, BT848_SAUDIO) failed.");
237 if (ioctl(tfd, BT848_GAUDIO, &audio) < 0) {
238 perror("ioctl(tfd, BT848_GAUDIO) failed.");
242 if (x_size && y_size) {
243 memset(&cap, 0, sizeof(cap));
246 if (ioctl(tfd, BT848_SCAPAREA, &cap) < 0) {
247 perror("ioctl(tfd, BT848_SCAPAREA) failed.");
252 if (channel_set != -1)
253 if (ioctl(tfd, TVTUNER_SETTYPE, &channel_set) < 0) {
254 perror("ioctl(tfd, TVTUNER_SETTYPE) failed.");
259 if (ioctl(tfd, TVTUNER_SETCHNL, &channel) < 0) {
260 perror("ioctl(tfd, TVTUNER_SETCHNL) failed.");
264 if (audio == AUDIO_INTERN) {
265 /* Convert from kHz to MHz * 100 */
268 if (ioctl(tfd, RADIO_SETFREQ, &freq) < 0) {
269 perror("ioctl(tfd, RADIO_SETFREQ) failed.");
273 /* Convert from kHz to MHz * 16 */
274 freq = (freq * 16) / 1000;
276 if (ioctl(tfd, TVTUNER_SETFREQ, &freq) < 0) {
277 perror("ioctl(tfd, TVTUNER_SETFREQ) failed.");