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.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by John Wehle.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 * Set the channel of the tuner card.
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/ioctl.h>
46 #include <dev/video/meteor/ioctl_meteor.h>
47 #include <dev/video/bktr/ioctl_bt848.h>
53 "usage: cxm_setchannel [-a {on|off}] [-c | -r | -s | -t] [-d unit] [-g geom]\n"
54 " [-m chnl_set] [chnl | freq]\n");
58 main(int argc, char *argv[])
72 unsigned int fraction;
77 struct bktr_capture_area cap;
90 while ((c = getopt(argc, argv, "a:crstg:m:d:")) != -1)
93 if (strcasecmp(optarg, "on") == 0)
95 else if (strcasecmp(optarg, "off") == 0)
104 device = METEOR_INPUT_DEV2;
114 audio = AUDIO_INTERN;
118 device = METEOR_INPUT_DEV_SVIDEO;
123 device = METEOR_INPUT_DEV1;
128 if (sscanf(optarg, "%ux%u", &x_size, &y_size) != 2 ||
129 x_size == 0 || y_size == 0) {
136 channel_set = atoi(optarg);
137 if (channel_set < 0 || channel_set > CHNLSET_MAX) {
151 * A number containing a decimal point is the frequency in
155 if ((ptr = strchr(argv[optind], '.')) != NULL) {
156 freq = strtol(argv[optind], &endptr, 10) * 1000;
163 fraction = strtol(ptr, &endptr, 10);
164 if (!isdigit(*ptr) || *endptr != '\0') {
168 for (i = endptr - ptr; i > 3; i--)
176 * An integer is the channel.
180 channel = atoi(argv[optind]);
182 if (afc == -1 && audio == -1 && !device && x_size == 0 &&
183 y_size == 0 && channel_set == -1 && !channel && !freq) {
188 sprintf(buf, "/dev/cxm%d", unit);
190 tfd = open(buf, O_RDONLY);
192 warn("open() of /dev/cxm%d failed.", unit);
197 if (ioctl(tfd, TVTUNER_SETAFC, &afc) < 0) {
198 warn("ioctl( tfd, TVTUNER_SETAFC ) failed.");
203 if (ioctl(tfd, METEORSINPUT, &device) < 0) {
204 warn("ioctl( tfd, METEORSINPUT ) failed.");
209 if (ioctl(tfd, BT848_SAUDIO, &audio) < 0) {
210 warn("ioctl( tfd, BT848_SAUDIO ) failed.");
214 if (ioctl(tfd, BT848_GAUDIO, &audio) < 0) {
215 warn("ioctl( tfd, BT848_GAUDIO ) failed.");
218 if (x_size && y_size) {
219 memset(&cap, 0, sizeof(cap));
222 if (ioctl(tfd, BT848_SCAPAREA, &cap) < 0) {
223 warn("ioctl( tfd, BT848_SCAPAREA ) failed.");
227 if (channel_set != -1) {
228 if (ioctl(tfd, TVTUNER_SETTYPE, &channel_set) < 0) {
229 warn("ioctl( tfd, TVTUNER_SETTYPE ) failed.");
234 if (ioctl(tfd, TVTUNER_SETCHNL, &channel) < 0) {
235 warn("ioctl( tfd, TVTUNER_SETCHNL ) failed.");
239 if (audio == AUDIO_INTERN) {
240 /* Convert from kHz to MHz * 100 */
243 if (ioctl(tfd, RADIO_SETFREQ, &freq) < 0) {
244 warn("ioctl( tfd, RADIO_SETFREQ ) failed.");
248 /* Convert from kHz to MHz * 16 */
249 freq = (freq * 16) / 1000;
251 if (ioctl(tfd, TVTUNER_SETFREQ, &freq) < 0) {
252 warn("ioctl( tfd, TVTUNER_SETFREQ ) failed.");