Subject: first try on device driver - success but more questions
To: None <tech-kern@netbsd.org>
From: Richard =?iso-8859-1?q?K=E4stner?= <richard.kaestner@kabsi.at>
List: tech-kern
Date: 12/28/2006 21:09:10
It seems, I succeeded with the first steps towards a driver for the Cirrus 
EP9301 - ADC ! (thanks for the hints!)

arm1# dmesg
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 4.99.5 (RFK_02) #18: Thu Dec 28 20:21:06 CET 2006
        
root@sv03.richardkaestner.com:/usr/DATA/NetBSD/evbarm/OBJ/sys/arch/evbarm/compile/RFK_02
total memory = 32768 KB
avail memory = 28736 KB
mainbus0 (root)
cpu0 at mainbus0: ARM920T rev 0 (ARM9TDMI core)
cpu0: DC enabled IC enabled WB enabled EABT
cpu0: 16KB/32B 64-way Instruction cache
cpu0: 16KB/32B 64-way write-back-locking-A Data cache
epsoc0 at mainbus0: Cirrus Logic EP93xx SoC rev E0
epsoc0: fclk 166.02 MHz hclk 66.41 MHz pclk 33.20 MHz
...
eprtc0 at epsoc0 addr 0x80920000-0x8092010b intr 37

**rfk: epadc match
epadc0 at epsoc0 addr 0x80900000-0x80a3ffff
**rfk: epadc attach
**rfk: epadc attach Params: sa_addr='80900000', sa_size='140000'
ohci0: OHCI version 1.0

(those marked with '**rfk' are my 'debugging aids')

And here a small test (derived from 'Pseudo Device Drivers'):
arm1#
**rfk: epadc open
**rfk: epadc ioctl cmd=C0605399 access_ctr=1
**rfk: ADC_RESULT : 0x00000000
**rfk: DEVCFG=0x00000080
**rfk: EP93XX_SYSCON_BASE=0x80930000
**rfk: EP93XX_ADC_BASE=0x80900000
**rfk: Real Offset=0x00030080
**rfk: DevCfg : 0x00040000
**rfk: ChipID : 0x54049213
**rfk: ChipID : 0x00000005
**rfk: epadc close
arm1#
**rfk: epadc open
**rfk: epadc ioctl cmd=C0605399 access_ctr=2
**rfk: ADC_RESULT : 0x00000000
**rfk: DEVCFG=0x00000080
**rfk: EP93XX_SYSCON_BASE=0x80930000
**rfk: EP93XX_ADC_BASE=0x80900000
**rfk: Real Offset=0x00030080
**rfk: DevCfg : 0x00040000
**rfk: ChipID : 0x54049213
**rfk: ChipID : 0x00000005
**rfk: epadc close
(again: all output just simple printf's in epadc_ioctl() )
It obvoiusly worked and gave correct results!!!!


Here come my questions:
1. Can I / how can I access two different IO-spaces in one driver?
  to start the adc, I need to set a bit in DeviceCfg (on chip register) and 
  only thereafter, I may access the adc registers

  as can be seen, I gave the 'epadc' a rather huge size, to be able to access
  ADC-Registers and DeviceCfg: 'epadc0 at epsoc0 addr 0x80900000-0x80a3ffff'
  For me this appears quite brute force - or is it ok, to map the entire IO
  space ? (hard to believe)


  In epadc_attach() I get my 
    struct epadc_softc *sc = (struct epadc_softc*)self;
  which (I think) comes from the kernel configuration, but allows only access
  to the defined bus_space ?

  I think, it would be much cleaner to split IO access by function blocks ...

Thanks in advance!

Richard


-- 
Richard Kaestner

richard.kaestner@ycn.com
richard.kaestner@kabsi.at