public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kumba <kumba@gentoo.org>
To: linux-kernel@vger.kernel.org
Subject: Can I nest kobjects to create directories under parent directories for my driver?
Date: Mon, 28 Feb 2011 22:31:48 -0500	[thread overview]
Message-ID: <4D6C68A4.3020306@gentoo.org> (raw)

So I'm attempting to write my first kernel driver for an RTC chip (Dallas/Maxim 
DS1685/DS1687), and running into a problem with using sysfs properly.  First 
off, a patch for this specific RTC was sent int to rtc-linux about two years 
ago, but never made it anywhere.  I based off of that and have pretty much 
re-written the thing since then.  It's undergoing a second re-write after some 
initial feedback from the rtc-linux folks.

What I'm trying to do, is, in sysfs, create individual attributes for the bits 
in each control register.  DS1685 defines 6 control registers (4 are the 
standard DS1286-style, and 2 are "extended" in another address bank).

I want to organize it such that:

# ls /sys/devices/platform/rtc-ds1685/
driver@  misc/  modalias  nvram  regs/  rtc/  subsystem@  uevent

And in regs/:
ctrla/  ctrlb/  ctrlc/  ctrld/  ctrl4a/  ctrl4b/

And under each register folder, the available bits for that register.  When 
read, each bit returns either a 0 or a 1, and certain bits can be made writable 
to change their values.

So I started investigating how to do this.  I first got it setup such that the 
ctrla through ctrl4b folders appeared in the top-level folder 
(/sys/devices/platform/rtc-ds1685).  Reading/writing to those worked fine.  But 
when I changed my code to nest those attribute groups under a "regs" kobject, 
any attempt to read or write the registers resulted in an Oops (or unaligned 
access, page fault, etc).

So far, I've determined that by attaching the "regs" kobject to the parent 
dev->kobj, and then attaching each attribute group kobject to the "regs" 
kobject, I lose the reference to the device structure holding all the relevant 
data for the RTC.  Thus, when I try to readb() or writeb() the RTC registers, I 
hit a NULL pointer and its lights out.

So I know I'm doing it wrong.  Question is, how can I do it right?  I've already 
looked into (and tried) ksets.  I'm not setting those up properly because I run 
into the same issue in the custom "show" function I have to write out where I 
don't have a valid reference to the live device structure.

I've gone through the kobject and kset examples, polled through quite a few 
drivers (some in drivers/rtc, some elsewhere), and looked over the sysfs, 
kobject, and device headers.  But because I'm still learning, I'm not 100% what 
I need to look for to accomplish this.  Everything else in the driver mostly 
works.  All this kobject debugging pointed out a few improper uses of spinlocks, 
and I optimized some other bits, but by and large, this thing is about ready to 
ship to rtc-linux for review (again).

I should add, I'm developing this on an SGI O2 (mips), which actually uses one 
of these RTCs.  The O2 currently taps into the rtc-cmos driver, which appears to 
provide baseline functionality.  None of my debugging points at flaws in the 
mips base or in the RTC system, so I'm directing my inquiry here to see if 
anyone has advice I can use to get this working.

Are ksets what I need to use, or can I nest kobjects together to accomplish 
things?  Or is there another way that I need to study up on?


Thanks!

-- 
Joshua Kinard
Gentoo/MIPS
kumba@gentoo.org

"The past tempts us, the present confuses us, the future frightens us.  And our 
lives slip away, moment by moment, lost in that vast, terrible in-between."

--Emperor Turhan, Centauri Republic

             reply	other threads:[~2011-03-01  3:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01  3:31 Kumba [this message]
2011-03-02 20:38 ` Can I nest kobjects to create directories under parent directories for my driver? Greg KH
2011-03-02 21:49   ` Kumba
2011-03-03  6:19     ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D6C68A4.3020306@gentoo.org \
    --to=kumba@gentoo.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox