2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2003, 2004, 2005
5 * John Wehle <john@feith.com>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 /* Set the channel of the tuner card. */
33 #include <sys/ioctl.h>
34 #include <sys/param.h>
44 #include <dev/bktr/ioctl_meteor.h>
45 #include <dev/bktr/ioctl_bt848.h>
51 ("Usage: setchannel [-a {on|off}] [-c | -r | -s | -t] "
52 "[-g geom] [-m chnl_set] [chnl | freq]\n"
53 " -a Enable / disable AFC.\n"
54 " -c Select composite input.\n"
55 " -d Select tuner unit number.\n"
56 " -r Select radio input.\n"
57 " -s Select svideo input.\n"
59 " -g Select geometry.\n"
60 " 352x240 or 352x288 = VCD\n"
61 " 480x480 or 480x576 = SVCD\n"
62 " 352x480 or 352x576 = DVD (half D1)\n"
63 " 720x480 or 720x576 = DVD (full D1)\n"
64 " -m Select channel set / system.\n"
65 " 0 = Tuner Default\n"
66 " %u = US Broadcast / NTSC\n"
67 " %u = US Cable / NTSC\n"
68 " %u = Western Europe / PAL\n"
69 " %u = Japan Broadcast / NTSC\n"
70 " %u = Japan Cable / NTSC\n"
71 " %u = Australia / PAL\n"
72 " %u = France / SECAM\n"
74 " freq Frequency in MHz (must include decimal point).\n",
75 CHNLSET_NABCST, CHNLSET_CABLEIRC, CHNLSET_WEUROPE, CHNLSET_JPNBCST,
76 CHNLSET_JPNCABLE, CHNLSET_AUSTRALIA, CHNLSET_FRANCE);
79 #define DEVNAME_BASE "/dev/cxm"
83 main(int argc, char *argv[])
96 unsigned int fraction;
100 unsigned long device;
101 struct bktr_capture_area cap;
114 while ((c = getopt(argc, argv, "a:cd:rg:m:st")) != -1)
118 if (strcasecmp(optarg, "on") == 0)
120 else if (strcasecmp(optarg, "off") == 0)
129 device = METEOR_INPUT_DEV2;
139 audio = AUDIO_INTERN;
143 device = METEOR_INPUT_DEV_SVIDEO;
148 device = METEOR_INPUT_DEV1;
153 if (sscanf(optarg, "%ux%u", &x_size, &y_size) != 2
154 || x_size == 0 || y_size == 0) {
161 channel_set = atoi(optarg);
162 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
176 * A number containing a decimal point is the frequency in MHz.
179 if ((ptr = strchr(argv[optind], '.')) != NULL) {
180 freq = strtol(argv[optind], &endptr, 10) * 1000;
188 fraction = strtol(ptr, &endptr, 10);
189 if (!isdigit(*ptr) || *endptr != '\0') {
194 for (i = endptr - ptr; i > 3; i--)
202 /* An integer is the channel. */
204 channel = atoi(argv[optind]);
207 if (afc == -1 && audio == -1 && !device && x_size == 0 && y_size == 0
208 && channel_set == -1 && !channel && !freq) {
213 sprintf(dev_name, DEVNAME_BASE "%d", unit);
214 tfd = open(dev_name, O_RDONLY);
216 fprintf(stderr, "Can't open %s: %s (%d)\n", dev_name,
217 strerror(errno), errno);
222 if (ioctl(tfd, TVTUNER_SETAFC, &afc) < 0) {
223 perror("ioctl(tfd, TVTUNER_SETAFC) failed.");
228 if (ioctl(tfd, METEORSINPUT, &device) < 0) {
229 perror("ioctl(tfd, METEORSINPUT) failed.");
234 if (ioctl(tfd, BT848_SAUDIO, &audio) < 0) {
235 perror("ioctl(tfd, BT848_SAUDIO) failed.");
239 if (ioctl(tfd, BT848_GAUDIO, &audio) < 0) {
240 perror("ioctl(tfd, BT848_GAUDIO) failed.");
244 if (x_size && y_size) {
245 memset(&cap, 0, sizeof(cap));
248 if (ioctl(tfd, BT848_SCAPAREA, &cap) < 0) {
249 perror("ioctl(tfd, BT848_SCAPAREA) failed.");
254 if (channel_set != -1)
255 if (ioctl(tfd, TVTUNER_SETTYPE, &channel_set) < 0) {
256 perror("ioctl(tfd, TVTUNER_SETTYPE) failed.");
261 if (ioctl(tfd, TVTUNER_SETCHNL, &channel) < 0) {
262 perror("ioctl(tfd, TVTUNER_SETCHNL) failed.");
266 if (audio == AUDIO_INTERN) {
267 /* Convert from kHz to MHz * 100 */
270 if (ioctl(tfd, RADIO_SETFREQ, &freq) < 0) {
271 perror("ioctl(tfd, RADIO_SETFREQ) failed.");
275 /* Convert from kHz to MHz * 16 */
276 freq = (freq * 16) / 1000;
278 if (ioctl(tfd, TVTUNER_SETFREQ, &freq) < 0) {
279 perror("ioctl(tfd, TVTUNER_SETFREQ) failed.");