[PARPORT] Parport utilities collection?


Thomas Sailer (sailer@ife.ee.ethz.ch)
Wed, 12 May 1999 20:51:28 +0200


Below is a small utility to configure Holtek HT6535 parports.
One can do this too via jumpers (strapping options), but
I'm too lazy to reboot the PC when I want to change the modes.

The chip btw is strange in that it _sometimes_ generates
EPP timeouts even when the EPP cycle is less than 1us.

Tom

/*****************************************************************************/

/*
 * htcfg.c -- Configuration utility for Holtek HT6535 parallel ports.
 *
 * Copyright (C) 1999 Thomas Sailer (sailer@ife.ee.ethz.ch)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

/*****************************************************************************/

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/io.h>

int main(int argc, char *argv[])
{
        static const char *portstr[] = {
                "0x378", "0x278", "0x3bc", "disabled",
                "0x268", "0x26c", "0x27c", "disabled"
        };
        static const char *modestr[] = {
                "isa", "ps2", "epp", "ecp"
        };
        int err = 0, c;
        unsigned numid = 0, port = 0, fifoth = 0, mode = 0, i;

        while ((c = getopt(argc, argv, "p:n:m:f:h")) != EOF)
                switch (c) {
                case 'p':
                        i = strtoul(optarg, NULL, 0);
                        switch (i) {
                        case 0x378:
                                port = 0;
                                break;
                        case 0x278:
                                port = 1;
                                break;
                        case 0x3bc:
                                port = 2;
                                break;
                        case 0:
                                port = 3;
                                break;
                        case 0x268:
                                port = 4;
                                break;
                        case 0x26c:
                                port = 5;
                                break;
                        case 0x27c:
                                port = 6;
                                break;
                        default:
                                err++;
                                fprintf(stderr, "invalid port address 0x%x\n", i);
                        }
                        break;

                case 'n':
                        numid = strtoul(optarg, NULL, 0);
                        if (numid > 1) {
                                err++;
                                fprintf(stderr, "invalid chip number %u\n", numid);
                        }
                        break;

                case 'm':
                        if (!strcasecmp(optarg, "isa"))
                                mode = 0;
                        else if (!strcasecmp(optarg, "ps2"))
                                mode = 1;
                        else if (!strcasecmp(optarg, "epp"))
                                mode = 2;
                        else if (!strcasecmp(optarg, "ecp"))
                                mode = 3;
                        else {
                                err++;
                                fprintf(stderr, "invalid parport mode %s\n", optarg);
                        }
                        break;

                case 'f':
                        fifoth = strtoul(optarg, NULL, 0);
                        if (fifoth > 15) {
                                err++;
                                fprintf(stderr, "invalid fifo threshold %u\n", fifoth);
                        }
                        break;

                default:
                        err++;
                        break;
                }
        if (mode == 2 && (port == 2 || port == 5 || port == 6)) {
                fprintf(stderr, "selected base address not supported in EPP mode\n");
                err++;
        }
        if (err) {
                fprintf(stderr, "usage: %s [-p <port>] [-m <mode>] [-n <chipnum>] "
                        "[-f <ecpfifoth>]\n", argv[0]);
                exit(1);
        }
        if (iopl(3)) {
                fprintf(stderr, "this program requires superuser privileges\n");
                exit(1);
        }
        /* enter config mode */
        outb(0x55, 0x2fa);
        outb(0x55, 0x2fa);
        i = 0x55 ^ -numid;
        outb(i, 0x3fa);
        outb(i, 0x3fa);
        /* write config */
        outb(0, 0x3fa);
        outb(fifoth, 0x2fa);
        outb(1, 0x3fa);
        outb(mode, 0x2fa);
        outb(2, 0x3fa);
        outb(port, 0x2fa);
        /* exit config mode */
        outb(0xf, 0x3fa);
        outb(0, 0x2fa);
        printf("HT6535 number %u mode %s port address %s fifo threshold %u\n",
               numid, modestr[mode], portstr[port], fifoth);
        exit(0);
}

-- To unsubscribe, send mail to: linux-parport-request@torque.net --
-- with the single word "unsubscribe" in the body of the message. --



This archive was generated by hypermail 2.0b3 on Wed 12 May 1999 - 14:51:59 EDT