Use ioconf.c for device configuration.

This commit is contained in:
Serge Vakulenko
2015-09-14 20:28:31 -07:00
parent 51e46b333b
commit c6360fb676
40 changed files with 628 additions and 114 deletions

97
sys/include/kconfig.h Normal file
View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 2015 Serge Vakulenko
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*/
/*
* This structure is used to encapsulate the routines for a device driver.
* This allows an "object oriented" approach so a controller device driver
* can support multiple attached devices or a device can be attached to
* different types of controllers.
*/
struct driver {
const char *d_name; /* driver name for vmstat and iostat */
int (*d_init)(); /* routine to probe & initialize device */
};
/*
* This structure describes controllers directly connected to CPU
* and is partially initialized in "ioconf.c" by the 'config' program.
*/
struct conf_ctlr {
struct driver *ctlr_driver; /* controller driver routines */
int ctlr_unit; /* controller number */
char *ctlr_addr; /* address of controller */
int ctlr_pri; /* interrupt priority */
int ctlr_flags; /* flags */
int ctlr_alive; /* true if init routine succeeded */
};
/*
* This structure describes devices connected to an interface
* and is partially initialized in "ioconf.c" by the 'config' program.
*/
struct conf_device {
struct driver *dev_driver; /* device driver routines */
struct driver *dev_cdriver; /* interface driver routines */
int dev_unit; /* device unit number */
int dev_ctlr; /* device interface number */
int dev_drive; /* device address number */
int dev_flags; /* flags */
/* assignment of signals to physical pins */
#define KCONF_MAXPINS 16
char dev_pins[KCONF_MAXPINS];
int dev_alive; /* true if init routine succeeded */
};
/*
* This structure describes optional software services.
*/
struct conf_service {
void (*svc_attach)(); /* routine to initialize service */
};
/* Define special unit types used by the config program */
#define QUES -1 /* -1 means '?' */
#define UNKNOWN -2 /* -2 means not set yet */
#ifdef KERNEL
extern struct conf_ctlr conf_ctlr_init[];
extern struct conf_device conf_device_init[];
extern struct conf_service conf_service_init[];
#endif

View File

@@ -18,17 +18,12 @@
extern const struct devspec ptsdevs[];
extern const struct devspec ptcdevs[];
#ifndef NPTY
#define NPTY 4
#ifndef PTY_NUNITS
#define PTY_NUNITS 4 /* 4 units by default */
#endif
#if NPTY == 1
#undef NPTY
#define NPTY 16 /* crude XXX */
#endif
extern struct tty pt_tty[NPTY];
extern struct tty pt_tty[];
extern int npty;
extern int ptsopen(dev_t dev, int flag, int mode);
extern int ptsclose(dev_t dev, int flag, int mode);

View File

@@ -105,7 +105,7 @@ int loginit (void);
void log (int level, char *fmt, ...);
int logwrt (char *buf, int len, int log);
void logwakeup (int unit);
void cpuidentify (void);
void kconfig (void);
void cninit (void);
void cnidentify (void);
void cnputc (char c);

View File

@@ -21,6 +21,7 @@
#include <sys/kernel.h>
#include <sys/namei.h>
#include <sys/stat.h>
#include <sys/kconfig.h>
#include <sys/rdisk.h>
u_int swapstart, nswap; /* start and size of swap space */
@@ -109,7 +110,7 @@ main()
startup();
printf ("\n%s", version);
cpuidentify();
kconfig();
cnidentify();
/*
@@ -147,6 +148,12 @@ main()
binit();
nchinit();
clkstart();
/* Attach services. */
struct conf_service *svc;
for (svc = conf_service_init; svc->svc_attach != NULL; svc++)
(*svc->svc_attach)();
s = spl0();
rdisk_init();

View File

@@ -8,7 +8,7 @@
*/
#include <sys/pty.h>
#if NPTY > 0
#ifdef PTY_ENABLED
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
@@ -41,16 +41,16 @@ extern int TTYHOG; /* see tty.c */
* pts == /dev/tty[pqrs]?
* ptc == /dev/pty[pqrs]?
*/
struct tty pt_tty[NPTY];
struct tty pt_tty[PTY_NUNITS];
struct pt_ioctl {
int pt_flags;
struct proc *pt_selr, *pt_selw;
u_char pt_send;
u_char pt_ucntl;
} pt_ioctl[NPTY];
} pt_ioctl[PTY_NUNITS];
int npty = NPTY; /* for pstat -t */
int npty = PTY_NUNITS; /* for pstat -t */
#define PF_RCOLL 0x01
#define PF_WCOLL 0x02
@@ -69,7 +69,7 @@ int ptsopen(dev_t dev, int flag, int mode)
#ifdef lint
npty = npty;
#endif
if (minor(dev) >= NPTY)
if (minor(dev) >= PTY_NUNITS)
return (ENXIO);
tp = &pt_tty[minor(dev)];
if ((tp->t_state & TS_ISOPEN) == 0) {
@@ -197,7 +197,7 @@ int ptcopen(dev_t dev, int flag, int mode)
register struct tty *tp;
struct pt_ioctl *pti;
if (minor(dev) >= NPTY)
if (minor(dev) >= PTY_NUNITS)
return (ENXIO);
tp = &pt_tty[minor(dev)];
if (tp->t_oproc)
@@ -519,4 +519,9 @@ int ptyioctl(dev_t dev, u_int cmd, caddr_t data, int flag)
}
return (error);
}
void ptyattach()
{
printf("pty: %d units\n", PTY_NUNITS);
}
#endif

View File

@@ -22,7 +22,7 @@ options "HZ=1000" # Rate of timer interrupt
options "CPU_KHZ=80000" # Oscillator frequency of CPU core
options "BUS_KHZ=80000" # Frequency of peripheral bus
options "BUS_DIV=1" # Bus clock divisor 1/2/4/8
options "NPROC=20"
#options "NPROC=20"
# LED
options "LED_KERNEL_PORT=TRISA" # for kernel activity LED...

View File

@@ -25,7 +25,6 @@ PARAM += -DLED_DISK_PIN=13
PARAM += -DLED_DISK_PORT=TRISC
PARAM += -DLED_KERNEL_PIN=15
PARAM += -DLED_KERNEL_PORT=TRISA
PARAM += -DNPROC=20
PARAM += -DBUS_DIV=1
PARAM += -DBUS_KHZ=80000
PARAM += -DCPU_KHZ=80000
@@ -110,7 +109,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -40,7 +40,7 @@ COMPILE_S = ${CC} -c ${DEFS} $<
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -29,6 +29,7 @@
#include <sys/uio.h>
#include <sys/adc.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
const struct devspec adcdevs[] = {
{ 0, "adc0" }, { 1, "adc1" }, { 2, "adc2" }, { 3, "adc3" },
@@ -146,3 +147,21 @@ int adc_ioctl(dev_t dev, register u_int cmd, caddr_t addr, int flag)
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
adcprobe(config)
struct conf_device *config;
{
int flags = config->dev_flags;
printf("adc: flags %#x\n", flags);
return 1;
}
struct driver adcdriver = {
"adc", adcprobe,
};

View File

@@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -102,7 +102,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -102,7 +102,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -31,6 +31,7 @@ kernel/sys_pipe.c standard
kernel/sys_process.c standard
kernel/syscalls.c standard
kernel/tty.c standard
kernel/tty_pty.c optional pty
kernel/tty_subr.c standard
kernel/tty_tty.c standard
kernel/ufs_alloc.c standard

View File

@@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -29,6 +29,7 @@
#include <sys/uio.h>
#include <sys/glcd.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
const struct devspec glcddevs[] = {
{ 0, "glcd0" },
@@ -665,3 +666,21 @@ int glcd_ioctl (dev_t dev, register u_int cmd, caddr_t addr, int flag)
}
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
glcdprobe(config)
struct conf_device *config;
{
int flags = config->dev_flags;
printf("glcd0: flags %#x\n", flags);
return 1;
}
struct driver glcddriver = {
"glcd", glcdprobe,
};

View File

@@ -28,6 +28,7 @@
#include <sys/gpio.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/kconfig.h>
const struct devspec gpiodevs[] = {
{ 0, "porta" }, { 1, "portb" }, { 2, "portc" }, { 3, "portd" },
@@ -115,28 +116,6 @@ u_int gpio_confmask [NGPIO];
#define PRINTDBG(...) /*empty*/
//#define PRINTDBG printf
/*
* PIC32 port i/o registers.
*/
struct gpioreg {
volatile unsigned tris; /* Mask of inputs */
volatile unsigned trisclr;
volatile unsigned trisset;
volatile unsigned trisinv;
volatile unsigned port; /* Read inputs, write outputs */
volatile unsigned portclr;
volatile unsigned portset;
volatile unsigned portinv;
volatile unsigned lat; /* Read/write outputs */
volatile unsigned latclr;
volatile unsigned latset;
volatile unsigned latinv;
volatile unsigned odc; /* Open drain configuration */
volatile unsigned odcclr;
volatile unsigned odcset;
volatile unsigned odcinv;
};
/*
* If a port address matches a port number,
* clear a given bit in pin mask.
@@ -626,3 +605,30 @@ gpioioctl (dev, cmd, addr, flag)
}
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
gpioprobe(config)
struct conf_device *config;
{
int unit = config->dev_unit;
int flags = config->dev_flags;
char buf[20];
if (unit < 0 || unit >= NGPIO)
return 0;
gpio_confmask[unit] = flags;
gpio_print(unit | MINOR_CONF, buf);
printf("gpio%u: port%c, pins %s", unit,
unit + (unit<8 ? 'A' : 'B'), buf);
return 1;
}
struct driver gpiodriver = {
"gpio", gpioprobe,
};

View File

@@ -29,6 +29,7 @@
#include <sys/uio.h>
#include <sys/adc.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
#include <sys/hx8357.h>
#include <sys/fonts/default.h>
@@ -787,3 +788,21 @@ int hx8357_select (dev_t dev, int rw)
}
return ENODEV;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
hxtftprobe(config)
struct conf_device *config;
{
int flags = config->dev_flags;
printf("hxtft0: flags %#x\n", flags);
return 1;
}
struct driver hxtftdriver = {
"hxtft", hxtftprobe,
};

View File

@@ -20,6 +20,7 @@
#include <sys/mount.h>
#include <sys/systm.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
#include <sys/uart.h>
#include <sys/usb_uart.h>
#ifdef UARTUSB_ENABLED
@@ -141,6 +142,9 @@ struct map swapmap[1] = {
int waittime = -1;
/* CPU package type: 64 pins or 100 pins. */
int cpu_pins;
static int
nodump(dev)
dev_t dev;
@@ -392,7 +396,7 @@ startup()
physmem = BMXDRMSZ;
}
void cpuidentify()
static void cpuidentify()
{
unsigned devid = DEVID, osccon = OSCCON;
static const char pllmult[] = { 15, 16, 17, 18, 19, 20, 21, 24 };
@@ -402,11 +406,26 @@ void cpuidentify()
printf("cpu: ");
switch (devid & 0x0fffffff) {
case 0x04307053: printf("795F512L"); break;
case 0x0430E053: printf("795F512H"); break;
case 0x04341053: printf("695F512L"); break;
case 0x04325053: printf("695F512H"); break;
default: printf("DevID %08x", devid);
case 0x04307053:
cpu_pins = 100;
printf("795F512L");
break;
case 0x0430E053:
cpu_pins = 64;
printf("795F512H");
break;
case 0x04341053:
cpu_pins = 100;
printf("695F512L");
break;
case 0x04325053:
cpu_pins = 64;
printf("695F512H");
break;
default:
/* Assume 100-pin package. */
cpu_pins = 100;
printf("DevID %08x", devid);
}
printf(" %u MHz, bus %u MHz\n", CPU_KHZ/1000, BUS_KHZ/1000);
@@ -443,6 +462,59 @@ void cpuidentify()
}
}
/*
* Check whether the controller has been successfully initialized.
*/
static int
is_controller_alive(driver, unit)
struct driver *driver;
int unit;
{
struct conf_ctlr *ctlr;
/* No controller - that's OK. */
if (driver == 0)
return 1;
for (ctlr = conf_ctlr_init; ctlr->ctlr_driver; ctlr++) {
if (ctlr->ctlr_driver == driver &&
ctlr->ctlr_unit == unit &&
ctlr->ctlr_alive)
{
return 1;
}
}
return 0;
}
/*
* Configure all controllers and devices as specified
* in the kernel configuration file.
*/
void kconfig()
{
struct conf_ctlr *ctlr;
struct conf_device *dev;
cpuidentify();
/* Probe and initialize controllers first. */
for (ctlr = conf_ctlr_init; ctlr->ctlr_driver; ctlr++) {
if ((*ctlr->ctlr_driver->d_init)(ctlr)) {
ctlr->ctlr_alive = 1;
}
}
/* Probe and initialize devices. */
for (dev = conf_device_init; dev->dev_driver; dev++) {
if (is_controller_alive(dev->dev_cdriver, dev->dev_ctlr)) {
if ((*dev->dev_driver->d_init)(dev)) {
dev->dev_alive = 1;
}
}
}
}
/*
* Sit and wait for something to happen...
*/
@@ -942,3 +1014,58 @@ int copyin (caddr_t from, caddr_t to, u_int nbytes)
bcopy(from, to, nbytes);
return 0;
}
/*
* Routines for access to general purpose I/O pins.
*/
static const char pin_name[16] = "?ABCDEFG????????";
void gpio_set_input(int pin)
{
struct gpioreg *port = (struct gpioreg*) &TRISA;
port += (pin >> 4 & 15) - 1;
port->trisset = (1 << (pin & 15));
}
void gpio_set_output(int pin)
{
struct gpioreg *port = (struct gpioreg*) &TRISA;
port += (pin >> 4 & 15) - 1;
port->trisclr = (1 << (pin & 15));
}
void gpio_set(int pin)
{
struct gpioreg *port = (struct gpioreg*) &TRISA;
port += (pin >> 4 & 15) - 1;
port->latset = (1 << (pin & 15));
}
void gpio_clr(int pin)
{
struct gpioreg *port = (struct gpioreg*) &TRISA;
port += (pin >> 4 & 15) - 1;
port->latclr = (1 << (pin & 15));
}
int gpio_get(int pin)
{
struct gpioreg *port = (struct gpioreg*) &TRISA;
port += (pin >> 4 & 15) - 1;
return ((port->port & (1 << (pin & 15))) ? 1 : 0);
}
char gpio_portname(int pin)
{
return pin_name[(pin >> 4) & 15];
}
int gpio_pinno(int pin)
{
return pin & 15;
}

View File

@@ -203,6 +203,26 @@ extern int sd_timo_wait_wdone;
extern int sd_timo_wait_wstop;
extern int sd_timo_wait_widle;
/*
* GPIO pins.
*/
void gpio_set_input(int pin);
void gpio_set_output(int pin);
void gpio_set(int pin);
void gpio_clr(int pin);
int gpio_get(int pin);
char gpio_portname(int pin);
int gpio_pinno(int pin);
/* Convert port name/signal into a pin number. */
#define GPIO_PIN(x,n) (((x)-'A'+1) << 4 | (n))
/*
* CPU package type: 64 pins or 100 pins.
*/
extern int cpu_pins;
#endif /* KERNEL */
#endif /* ENDIAN */

View File

@@ -98,7 +98,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -101,7 +101,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -109,7 +109,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -117,6 +117,7 @@
#else
#define PIC32_R(a) *(volatile unsigned*)(0xBF800000 + (a))
#endif
/*--------------------------------------
* UART registers.
*/
@@ -407,6 +408,30 @@
#define ODCGSET PIC32_R (0x861B8)
#define ODCGINV PIC32_R (0x861BC)
#ifndef __ASSEMBLER__
/*
* PIC32 port i/o registers.
*/
struct gpioreg {
volatile unsigned tris; /* Mask of inputs */
volatile unsigned trisclr;
volatile unsigned trisset;
volatile unsigned trisinv;
volatile unsigned port; /* Read inputs, write outputs */
volatile unsigned portclr;
volatile unsigned portset;
volatile unsigned portinv;
volatile unsigned lat; /* Read/write outputs */
volatile unsigned latclr;
volatile unsigned latset;
volatile unsigned latinv;
volatile unsigned odc; /* Open drain configuration */
volatile unsigned odcclr;
volatile unsigned odcset;
volatile unsigned odcinv;
};
#endif
#define CNCON PIC32_R (0x861C0) /* Interrupt-on-change control */
#define CNCONCLR PIC32_R (0x861C4)
#define CNCONSET PIC32_R (0x861C8)

View File

@@ -95,7 +95,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -30,6 +30,7 @@
#include <sys/uio.h>
#include <sys/pwm.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
/*
* Devices:
@@ -205,3 +206,21 @@ pwm_ioctl (dev, cmd, addr, flag)
}
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
pwmprobe(config)
struct conf_device *config;
{
int flags = config->dev_flags;
printf("pwm: flags %#x\n", flags);
return 1;
}
struct driver pwmdriver = {
"pwm", pwmprobe,
};

View File

@@ -37,6 +37,7 @@
#include <sys/rdisk.h>
#include <sys/spi_bus.h>
#include <sys/debug.h>
#include <sys/kconfig.h>
/*
* Two SD/MMC disks on SPI.
@@ -568,8 +569,8 @@ void sd_preinit (int unit)
spi_brg(fd, SD0_MHZ * 1000);
spi_set(fd, PIC32_SPICON_CKE);
printf ("sd%d: port %s, select pin R%c%d\n", unit,
spi_name(fd), spi_csname(fd), spi_cspin(fd));
//printf ("sd%d: port %s, select pin R%c%d\n", unit,
// spi_name(fd), spi_csname(fd), spi_cspin(fd));
}
int sdinit (int unit, int flag)
@@ -644,3 +645,26 @@ int sdopen(int unit, int flags, int mode)
DEBUG("sd%d: open\n",unit);
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
sdprobe(config)
struct conf_device *config;
{
int unit = config->dev_unit;
int cs;
if (unit < 0 || unit >= NSD)
return 0;
cs = config->dev_pins[0];
printf("sd%u: port SPI%d, pin cs=R%c%d\n", unit,
config->dev_ctlr, gpio_portname(cs), gpio_pinno(cs));
return 1;
}
struct driver sddriver = {
"sd", sdprobe,
};

View File

@@ -13,6 +13,7 @@
#include <machine/sdram.h>
#include <sys/rd_sdramp.h>
#include <sys/rdisk.h>
#include <sys/kconfig.h>
/*
* See rd_sdramp_config.h for sdramp port/pin configuration
@@ -63,32 +64,8 @@ static char swaptemp[CHUNK_SIZE];
m->partitions[n].lbastart = s; \
m->partitions[n].lbalength = l;
//void build_ramdisk_mbr(struct mbr* m);
// FIXME - FOLLOWING shared with gpio.c - needs to be made common
/*
* PIC32 port i/o registers.
*/
struct gpioreg {
volatile unsigned tris; /* Mask of inputs */
volatile unsigned trisclr;
volatile unsigned trisset;
volatile unsigned trisinv;
volatile unsigned port; /* Read inputs, write outputs */
volatile unsigned portclr;
volatile unsigned portset;
volatile unsigned portinv;
volatile unsigned lat; /* Read/write outputs */
volatile unsigned latclr;
volatile unsigned latset;
volatile unsigned latinv;
volatile unsigned odc; /* Open drain configuration */
volatile unsigned odcclr;
volatile unsigned odcset;
volatile unsigned odcinv;
};
struct ocreg {
volatile unsigned con; /* ? */
volatile unsigned conclr;
@@ -397,16 +374,18 @@ int sdramp_size(int unit)
return (1<<SDR_ADDRESS_LINES) / 2 * 4 * SDR_DATA_BYTES;
}
#if 0
// FIXME - this does not supply any more than
// is currently used by the rdisk functions. It does
// not build a completely or valid mbr.
void build_ramdisk_mbr(struct mbr *m)
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
sdrampprobe(config)
struct conf_device *config;
{
bzero(m, 512);
#ifdef RAMDISK_MBR_PARTS
RAMDISK_MBR_PARTS;
#endif
//TODO
return 1;
}
#endif
struct driver sdrampdriver = {
"sdramp", sdrampprobe,
};

View File

@@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -27,6 +27,7 @@
#include <sys/ioctl.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/kconfig.h>
#include <sys/spi.h>
#include <sys/spi_bus.h>
@@ -261,3 +262,60 @@ int spidev_ioctl (dev_t dev, u_int cmd, caddr_t addr, int flag)
}
return 0;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
* SPI ports are always present, if configured.
*/
static int
spiprobe(config)
struct conf_ctlr *config;
{
int channel = config->ctlr_unit - 1;
int sdi, sdo, sck;
static const int sdi_tab[NSPI] = {
GPIO_PIN('C',4), /* SDI1 */
GPIO_PIN('G',7), /* SDI2 */
GPIO_PIN('D',2), /* SDI3: 64pin - RD2, 100pin - RF2 */
GPIO_PIN('F',4), /* SDI4 */
};
static const int sdo_tab[NSPI] = {
GPIO_PIN('D',0), /* SDO1 */
GPIO_PIN('G',8), /* SDO2 */
GPIO_PIN('D',3), /* SDO3: 64pin - RD3, 100pin - RF8 */
GPIO_PIN('F',5), /* SDO4 */
};
static const int sck_tab[NSPI] = {
GPIO_PIN('D',10), /* SCK1 */
GPIO_PIN('G',6), /* SCK2 */
GPIO_PIN('D',1), /* SCK3: 64pin - RD1, 100pin - RD15 */
GPIO_PIN('D',10), /* SCK4 */
};
if (channel < 0 || channel >= NSPI)
return 0;
sdi = sdi_tab[channel];
sdo = sdo_tab[channel];
sck = sck_tab[channel];
if (channel+1 == 3 && cpu_pins > 64) {
/* Port SPI3 has different pin assignment for 100-pin packages. */
sdi = GPIO_PIN('F',2);
sdo = GPIO_PIN('F',8);
sck = GPIO_PIN('D',15);
}
printf ("spi%u: pins sdi=R%c%d/sdo=R%c%d/sck=R%c%d\n", channel+1,
gpio_portname(sdi), gpio_pinno(sdi),
gpio_portname(sdo), gpio_pinno(sdo),
gpio_portname(sck), gpio_pinno(sck));
//TODO
//struct spiio *io = &spitab[channel];
//io->reg = spi_base[channel];
//spi_setup(io, 0, 0);
return 1;
}
struct driver spidriver = {
"spi", spiprobe,
};

View File

@@ -100,7 +100,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -21,6 +21,9 @@
#include <sys/vmmeter.h>
#include <sys/map.h>
#include <sys/conf.h>
#ifdef PTY_ENABLED
# include <sys/pty.h>
#endif
/*
* Errno messages.
@@ -165,7 +168,7 @@ static const struct {
{ "_tk_nout", (int) &tk_nout }, /* iostat */
{ "_total", (int) &total }, /* vmstat */
{ "_u", (int) &u }, /* ps */
#if NPTY > 0
#ifdef PTY_ENABLED
{ "_npty", (int) &npty }, /* pstat */
{ "_pt_tty", (int) &pt_tty }, /* pstat */
#endif

View File

@@ -11,6 +11,7 @@
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/systm.h>
#include <sys/kconfig.h>
#include <sys/uart.h>
#define CONCAT(x,y) x ## y
@@ -745,3 +746,69 @@ char uartgetc(dev_t dev)
splx(s);
return (unsigned char) c;
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
uartprobe(config)
struct conf_device *config;
{
int unit = config->dev_unit - 1;
extern dev_t console_device;
int is_console = (major(console_device) == uart_major &&
minor(console_device) == unit);
int rx, tx;
static const int rx_tab[NUART] = {
GPIO_PIN('D',2), /* U1RX: 64pin - RD2, 100pin - RF2 */
GPIO_PIN('F',4), /* U2RX */
GPIO_PIN('G',7), /* U3RX */
GPIO_PIN('D',9), /* U4RX: 64pin - RD9, 100pin - RD14 */
GPIO_PIN('B',8), /* U5RX: 64pin - RB8, 100pin - RF12 */
GPIO_PIN('G',9), /* U6RX */
};
static const int tx_tab[NUART] = {
GPIO_PIN('D',3), /* U1TX: 64pin - RD3, 100pin - RF8 */
GPIO_PIN('F',5), /* U2TX */
GPIO_PIN('G',8), /* U3TX */
GPIO_PIN('D',1), /* U4TX: 64pin - RD1, 100pin - RD15 */
GPIO_PIN('B',14), /* U5TX: 64pin - RB14, 100pin - RF13 */
GPIO_PIN('G',6), /* U6TX */
};
if (unit < 0 || unit >= NUART)
return 0;
rx = rx_tab[unit];
tx = tx_tab[unit];
if (cpu_pins > 64) {
/* Ports UART1, UART4 and UART5 have different pin assignments
* for 100-pin packages. */
switch (unit + 1) {
case 1:
rx = GPIO_PIN('F',2);
tx = GPIO_PIN('F',8);
break;
case 4:
rx = GPIO_PIN('D',14);
tx = GPIO_PIN('D',15);
break;
case 5:
rx = GPIO_PIN('F',12);
tx = GPIO_PIN('F',13);
break;
}
}
printf("uart%d: pins rx=R%c%d/tx=R%c%d, interrupts %u/%u/%u", unit+1,
gpio_portname(rx), gpio_pinno(rx),
gpio_portname(tx), gpio_pinno(tx),
uirq[unit].er, uirq[unit].rx, uirq[unit].tx);
if (is_console)
printf(", console");
printf("\n");
return 1;
}
struct driver uartdriver = {
"uart", uartprobe,
};

View File

@@ -112,7 +112,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif

View File

@@ -27,6 +27,7 @@
#include <sys/user.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/kconfig.h>
#include <machine/pic32mx.h>
#include <machine/usb_device.h>
#include <machine/usb_function_cdc.h>
@@ -280,6 +281,28 @@ void usbintr (int chan)
cdc_tx_service();
}
/*
* Test to see if device is present.
* Return true if found and initialized ok.
*/
static int
usbprobe(config)
struct conf_device *config;
{
extern dev_t console_device;
int is_console = major(console_device) == usb_major;
printf("uartusb: port USB, interrupt %u", PIC32_VECT_USB);
if (is_console)
printf(", console");
printf("\n");
return 1;
}
struct driver uartusbdriver = {
"uartusb", usbprobe,
};
/*
* USB Callback Functions
*/

View File

@@ -99,7 +99,7 @@ CFILES = $S/kernel/exec_aout.c $S/kernel/exec_conf.c $S/kernel/exec_elf.c \
# ${SYSTEM_LD_HEAD}
# ${SYSTEM_LD} swapxxx.o
# ${SYSTEM_LD_TAIL}
SYSTEM_OBJ = startup.o ${OBJS} #ioconf.o
SYSTEM_OBJ = startup.o ${OBJS} ioconf.o
ifeq (devcfg.c,$(wildcard devcfg.c))
SYSTEM_OBJ += devcfg.o
endif