From owner-freebsd-hackers@FreeBSD.ORG Thu Nov 24 09:18:19 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D92FC16A41F for ; Thu, 24 Nov 2005 09:18:19 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (vc4-2-0-87.dsl.netrack.net [199.45.160.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id DCC8B43D64 for ; Thu, 24 Nov 2005 09:18:18 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (localhost.village.org [127.0.0.1] (may be forged)) by harmony.bsdimp.com (8.13.3/8.13.3) with ESMTP id jAO9HSoH099115; Thu, 24 Nov 2005 02:17:28 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Thu, 24 Nov 2005 02:17:47 -0700 (MST) Message-Id: <20051124.021747.02300237.imp@bsdimp.com> To: listmember@thiemo.net From: "M. Warner Losh" In-Reply-To: <20051123092045.GA48216@mygiea.ham01.thiemo.net> References: <20051123092045.GA48216@mygiea.ham01.thiemo.net> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (harmony.bsdimp.com [127.0.0.1]); Thu, 24 Nov 2005 02:17:28 -0700 (MST) Cc: freebsd-hackers@freebsd.org Subject: Re: Writing a driver for a card reader controller - how? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Nov 2005 09:18:20 -0000 In message: <20051123092045.GA48216@mygiea.ham01.thiemo.net> Thiemo Nordenholz writes: : I am writing a device driver for a card reader controller which is installed : in my notebook, using the Winbond W83L518D chip. It's FreeBSD 6.0-STABLE : running there now, though I started programming under 5.4-R, and the : symptoms have not changed since then. : : However, when I attach it, it seems to allocate the resources : : port 0-0x7 irq 0 drq 4 on acpi0 : : which seems strange to me -- accessing registers in the respective : SYS_RES_IOPORT seems to work, though. This looks like a problem. It shouldn't be at port 0 or irq 0. There's a resource issue with the ACPI. However, this may be a classic problem instead. If your driver does not filter out pnpid that it gets, then you can wind up with this situation. : Now, as far as I understand the datasheet for the controller, I have to use : another I/O port to access the SD card itself, to check if one is there, and : finally to access it. How I do this, though, I have no idea. The datasheet : lists two configuration registers that "select SD Card interface base : address on 8-byte boundary" - but will my driver have to program an address : into those registers? Does the bus framework somehow handle this? Does even : BIOS do this? Or will I have to write one driver for the controller, have : that act as a bus driver, and attach some SD card driver to that one? Chances are several drivers will be needed to support SD cards. There are a number of layers involved. You have the slot/controller interface which is resposible for sending commands to the card. You have a higher level interface, which different slot controllers can plug into that deals with sending commands to the cards. Finally, you'd likely have a disk layer layered on top of that to prsent bits to the user. : Maybe someone is willing to spend some time having a look at the datasheet : and what I have done so far, and give me a little (or larger) clue-up... In : return, I promise to write some documentation about how I have done it once : it is ready, just in case someone else faces similar problems. A pointer to : some driver programming documentation I have missed so far would be just as : nice, of course. I'd be happy to take a look at the datasheet. : So far, I have tried using fdc and ppc as a guideline (after having found : the spkr driver to be a bit too simple), and I _think_ I am doing just as : those drivers do probing and resource allocation, but somehow they work, and : mine does not. : Link to the datasheet and some more description of what I have done so far : (including my current state of source code) are at : http://projects.thiemo.net/WbcrDriver The probe routine shouldn't allocate resources. Old ISA drivers needed to do this to cope with the vagaries of probing the hardware that may or may not be there. It looks like you have a specific instance in the ACPI space that you can attach to, so there's no need. This should be deferred until attach time. There's no equivalent in FreeBSD to the mmc code that Linux has. There really should be (this is the layering I was describing above). I'm not sure how to best advise moving the device's I/O port address. Not having one to mess with, I'm unsure how you should proceed. I think that the location of '0' might be a default, and that it needs to be set. Can you send me a pointer to the winbond datasheet you are using? IIRC, this chip has an odd API since it appears to be derived from Winbond's superI/O chips with all the 'super' removed except the SD interface. Warner