Date: Mon, 18 Oct 1999 17:02:11 +0900 From: MIHIRA Sanpei Yoshiro <sanpei@sanpei.org> To: freebsd-mobile@FreeBSD.org Subject: [PCCARD] experimental code, pccardc power Message-ID: <199910180802.RAA07485@lavender.yy.cs.keio.ac.jp>
next in thread | raw e-mail | index | archive | help
Hi. I created patch of pccardc power for -current. [from manual page], It turns ON/OFF a power supply of a card in the slot specified in turn OFF a power supply. If a card becomes unstable when it is removed at activate state, this can force it to turn into inactive state first and remove it safely. turn ON a power supply and into active state similar to a card insertion. For example, when I use NOTE-PC on train, I can't have any AC-power supply. I don't use Ethernet-Card on it, so I power down PC-Card without removeal by this funciotn and I can save battery power. This code was obtained from PAO. But I removed inactive state from PAO code. # but I did't remove about inactive state from man page patch... Any comments are welcome. Thank you. MIHIRA Sanpei Yoshiro Yokohama, Japan. --- sys/pccard/cardinfo.h.orig Mon Aug 2 03:12:50 1999 +++ sys/pccard/cardinfo.h Sat Oct 16 21:00:58 1999 @@ -45,6 +45,7 @@ #define PIOCRWFLAG _IOW('P', 7, int) /* Set flags for drv use */ #define PIOCRWMEM _IOWR('P', 8, unsigned long) /* Set mem for drv use */ #define PIOCSPOW _IOW('P', 9, struct power) /* Set power structure */ +#define PIOCSVIR _IOW('P', 10, int) /* Virtual insert/remove */ #define PIOCSBEEP _IOW('P', 11, int) /* Select Beep */ /* * Debug codes. --- sys/pccard/pccard.c.org Sat Oct 16 20:57:27 1999 +++ sys/pccard/pccard.c Sat Oct 16 20:59:42 1999 @@ -941,6 +941,7 @@ struct mem_desc *mp; struct io_desc *ip; int s, err; + int pwval; /* beep is disabled until the 1st call of crdioctl() */ pccard_beep_select(BEEP_ON); @@ -1070,6 +1071,35 @@ else pccard_failure_beep(); return err; + /* + * Virtual removal/insertion + */ + case PIOCSVIR: + pwval = *(int *)data; + /* virtual removal */ + if (!pwval) { + if (slt->state != filled) { + return EINVAL; + } + s = splhigh(); + disable_slot(slt); + slt->laststate = filled; + slt->state = empty; + splx(s); + pccard_remove_beep(); + selwakeup(&slt->selp); + } + /* virtual insertion */ + else { + if (slt->state != empty) { + return EINVAL; + } + slt->insert_seq = 1; + slt->insert_ch = timeout(inserted, (void *)slt, hz/4); + pccard_insert_beep(); + break; + } + break; case PIOCSBEEP: if (pccard_beep_select(*(int *)data)) { return EINVAL; --- usr.sbin/pccard/pccardc/Makefile Sat Aug 28 19:18:20 1999 +++ usr.sbin/pccard/pccardc/Makefile Fri Sep 3 22:34:05 1999 @@ -5,7 +5,7 @@ # PROG= pccardc SRCS= beep.c dumpcis.c enabler.c pccardc.c pccardmem.c printcis.c \ - rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c + rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c power.c MAN8= pccardc.8 CFLAGS+= -I${.CURDIR}/../pccardd --- usr.sbin/pccard/pccardc/pccardc.c Sat Aug 28 19:18:20 1999 +++ usr.sbin/pccard/pccardc/pccardc.c Fri Sep 3 22:33:54 1999 @@ -41,11 +41,13 @@ DECL(enabler_main); DECL(help_main); DECL(pccardmem_main); +DECL(power_main); DECL(rdattr_main); DECL(rdmap_main); DECL(rdreg_main); DECL(wrattr_main); DECL(wrreg_main); struct { char *name; @@ -57,11 +59,13 @@ { "enabler", enabler_main, "Device driver enabler" }, { "help", help_main, "Prints command summary" }, { "pccardmem", pccardmem_main, "Allocate memory for pccard driver" }, + { "power", power_main, "Power on/off slots" }, { "rdattr", rdattr_main, "Read attribute memory" }, { "rdmap", rdmap_main, "Read pcic mappings" }, { "rdreg", rdreg_main, "Read pcic register" }, { "wrattr", wrattr_main, "Write byte to attribute memory" }, { "wrreg", wrreg_main, "Write pcic register" }, { 0, 0 } }; --- usr.sbin/pccard/pccardc/power.c Thu Jan 1 09:00:00 1970 +++ usr.sbin/pccard/pccardc/power.c Wed Sep 1 22:44:02 1999 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 1995 Andrew McRae. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Code cleanup, bug-fix and extension + * by Tatsumi Hosokawa <hosokawa@mt.cs.keio.ac.jp> + */ + +#ifndef lint +static const char rcsid[] = + "$Id: power.c,v 1.3 1999/02/11 05:00:54 kuriyama Exp $"; +#endif /* not lint */ + +#include <ctype.h> +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/ioctl.h> + +#include <pccard/cardinfo.h> + +int +power_main(argc, argv) + int argc; + char *argv[]; +{ + int fd, i, newstat, valid = 1; + char name[64], *p; + + if (argc != 3) + valid = 0; + for (i = 1; i <= 2; i++) { + if (valid) { + for (p = argv[i]; *p; p++) { + if (!isdigit(*p)) { + valid = 0; + break; + } + } + } + } + if (!valid) + errx(1, "Usage: %s power slot newstat", argv[0]); + + sscanf(argv[2], "%d", &newstat); + sprintf(name, CARD_DEVICE, atoi(argv[1])); + fd = open(name, O_RDWR); + if (fd < 0) + err(1, "%s", name); + newstat = newstat ? 1 : 0; + if (ioctl(fd, PIOCSVIR, &newstat) < 0) + err(1, "ioctl (PIOCSVIR)"); + return 0; +} --- usr.sbin/pccard/pccardc/pccardc.8.org Wed Oct 13 00:35:08 1999 +++ usr.sbin/pccard/pccardc/pccardc.8 Wed Oct 13 00:37:11 1999 @@ -54,6 +54,8 @@ Print command summary .It Pa pccardmem Allocate memory for pccard driver +.It Pa power +Power on/off slots .It Pa rdattr Read attribute memory .It Pa rdmap @@ -161,6 +163,21 @@ .Pa pccard_mem in .Xr rc.conf 5 . +.It +.Nm power Ar slot 0|1 +.Pp +It turns ON/OFF a power supply of a card in the slot specified in +.Ar slot . +.Pp +.Bl -tag -width Ds +.It Ar 0 +turn OFF a power supply. If a card becomes unstable when it is removed at +activate state, +this can force it to turn into inactive state first and remove it safely. +.It Ar 1 +turn ON a power supply and into active state similar to a card insertion. +.El +.Pp .It .Nm rdattr Ar slot offs length .Pp To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-mobile" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910180802.RAA07485>