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. */
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/ioctl.h>
42 #if __FreeBSD_version < 503001
43 # include <machine/ioctl_meteor.h>
44 # include <machine/ioctl_bt848.h>
46 # include <dev/bktr/ioctl_meteor.h>
47 # include <dev/bktr/ioctl_bt848.h>
55 ("Usage: setchannel [-a {on|off}] [-c | -r | -s | -t] "
56 "[-g geom] [-m chnl_set] [chnl | freq]\n"
57 " -a Enable / disable AFC.\n"
58 " -c Select composite input.\n"
59 " -d Select tuner unit number.\n"
60 " -r Select radio input.\n"
61 " -s Select svideo input.\n"
63 " -g Select geometry.\n"
64 " 352x240 or 352x288 = VCD\n"
65 " 480x480 or 480x576 = SVCD\n"
66 " 352x480 or 352x576 = DVD (half D1)\n"
67 " 720x480 or 720x576 = DVD (full D1)\n"
68 " -m Select channel set / system.\n"
69 " 0 = Tuner Default\n"
70 " %u = US Broadcast / NTSC\n"
71 " %u = US Cable / NTSC\n"
72 " %u = Western Europe / PAL\n"
73 " %u = Japan Broadcast / NTSC\n"
74 " %u = Japan Cable / NTSC\n"
75 " %u = Australia / PAL\n"
76 " %u = France / SECAM\n"
78 " freq Frequency in MHz (must include decimal point).\n",
79 CHNLSET_NABCST, CHNLSET_CABLEIRC, CHNLSET_WEUROPE, CHNLSET_JPNBCST,
80 CHNLSET_JPNCABLE, CHNLSET_AUSTRALIA, CHNLSET_FRANCE);
83 #define DEVNAME_BASE "/dev/cxm"
87 main(int argc, char *argv[])
100 unsigned int fraction;
104 unsigned long device;
105 struct bktr_capture_area cap;
118 while ((c = getopt(argc, argv, "a:cd:rg:m:st")) != -1)
122 if (strcasecmp(optarg, "on") == 0)
124 else if (strcasecmp(optarg, "off") == 0)
133 device = METEOR_INPUT_DEV2;
143 audio = AUDIO_INTERN;
147 device = METEOR_INPUT_DEV_SVIDEO;
152 device = METEOR_INPUT_DEV1;
157 if (sscanf(optarg, "%ux%u", &x_size, &y_size) != 2
158 || x_size == 0 || y_size == 0) {
165 channel_set = atoi(optarg);
166 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
180 * A number containing a decimal point is the frequency in MHz.
183 if ((ptr = strchr(argv[optind], '.')) != NULL) {
184 freq = strtol(argv[optind], &endptr, 10) * 1000;
192 fraction = strtol(ptr, &endptr, 10);
193 if (!isdigit(*ptr) || *endptr != '\0') {
198 for (i = endptr - ptr; i > 3; i--)
206 /* An integer is the channel. */
208 channel = atoi(argv[optind]);
211 if (afc == -1 && audio == -1 && !device && x_size == 0 && y_size == 0
212 && channel_set == -1 && !channel && !freq) {
217 sprintf(dev_name, DEVNAME_BASE "%d", unit);
218 tfd = open(dev_name, O_RDONLY);
220 fprintf(stderr, "Can't open %s: %s (%d)\n", dev_name,
221 strerror(errno), errno);
226 if (ioctl(tfd, TVTUNER_SETAFC, &afc) < 0) {
227 perror("ioctl(tfd, TVTUNER_SETAFC) failed.");
232 if (ioctl(tfd, METEORSINPUT, &device) < 0) {
233 perror("ioctl(tfd, METEORSINPUT) failed.");
238 if (ioctl(tfd, BT848_SAUDIO, &audio) < 0) {
239 perror("ioctl(tfd, BT848_SAUDIO) failed.");
243 if (ioctl(tfd, BT848_GAUDIO, &audio) < 0) {
244 perror("ioctl(tfd, BT848_GAUDIO) failed.");
248 if (x_size && y_size) {
249 memset(&cap, 0, sizeof(cap));
252 if (ioctl(tfd, BT848_SCAPAREA, &cap) < 0) {
253 perror("ioctl(tfd, BT848_SCAPAREA) failed.");
258 if (channel_set != -1)
259 if (ioctl(tfd, TVTUNER_SETTYPE, &channel_set) < 0) {
260 perror("ioctl(tfd, TVTUNER_SETTYPE) failed.");
265 if (ioctl(tfd, TVTUNER_SETCHNL, &channel) < 0) {
266 perror("ioctl(tfd, TVTUNER_SETCHNL) failed.");
270 if (audio == AUDIO_INTERN) {
271 /* Convert from kHz to MHz * 100 */
274 if (ioctl(tfd, RADIO_SETFREQ, &freq) < 0) {
275 perror("ioctl(tfd, RADIO_SETFREQ) failed.");
279 /* Convert from kHz to MHz * 16 */
280 freq = (freq * 16) / 1000;
282 if (ioctl(tfd, TVTUNER_SETFREQ, &freq) < 0) {
283 perror("ioctl(tfd, TVTUNER_SETFREQ) failed.");