Re: [RFC PATCH] rtc: add rtc_systohc for ntp use

2008-11-12 Thread Gabriel Paubert
On Tue, Nov 11, 2008 at 12:58:59PM -0800, David Brownell wrote:
 On Tuesday 11 November 2008, David Woodhouse wrote:
  I believe you were also concerned that some device wouldn't want the
  behaviour given by the existing sync_cmos_clock() function and workqueue
  stuff in kernel/ntp.c, where we update the clock precisely half-way
  through the second?
 
 That's a problem, yes.  I've never heard of any RTC that wants
 such delays ... except for the PC's CMOS RTC.

Indeed, they are the oddball, although very frequent. Could it be
made a constant (500msec on x86, 0 on all other architectures) ?

 
 There was some discussion about how to expose that knowledge to
 userspace too.  The hwclock utility always imposes that delay,
 and it shouldn't (except when talking to a PC RTC).
 
  We should probably rip that code out of ntp.c (or just disable it ifdef
  CONFIG_RTC_CLASS), and provide our own version of notify_cmos_timer().
 
 My suggestion for in-kernel code is that struct rtc_device just
 grow a field like unsigned settime_delay_msec which would never
 be initialized except by rtc-cmos (which uses 500) ... and the NTP
 sync code would use that value.

Hmm, I believed that most internal interfaces are now using nanoseconds
for subsecond fields and values; 5 also fits in 32 bits and may 
avoid some unnecessary arithmetic. It is obviously overkill with 32768Hz 
crystals but consistency is nice. 

 
 For out-of-kernel use, that value could be extracted with an ioctl(),
 and used similarly.
 
 
  The workqueue stuff to trigger at half-past the second could be kept as
  a library function which most RTC devices would use, but they'd have the
  option to use their own instead.
 
 I thought the workqueue stuff was primarily there to make sure
 that RTC was always updated in task context -- so it can grab the
 relevant mutex -- and the half-second delay was legacy PC code ...

Please allow configs that only use RTC internally without exposing
the driver to userspace. 

At least that's how I use the RTC, I have some messages on shutdown telling
me that the clock could not be accessed but I don't care since all these 
machines have ntp and the RTC is completely useless for anything else than 
setting the time quite precisely on reboot (on some of the boards I have, 
the RTC interrupt is not even wired, so no alarm, no periodic interrupt).

Gabriel
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH] [RFC] Exposing mmio nvrams greater than 8MB using generic_nvram

2008-11-12 Thread Martyn Welch
I have been looking for a way to access the nvram on our board and expose it
to userspace. The board has a 128kB nvram, the mmio_nvram driver seemed to be
a capable of mapping this device.

generic_nvram seemed initially to be the correct way of exposing the driver
to userspace, however it was hard-coded to assume an nvram of 8kB. The
mmio_nvram driver also didn't provide the functions expected by
generic_nvram.

The patch below extends generic_nvram and mmio_nvram. I realise this is
really not ready yet (I dread to think how this patch could break other's
builds), however I am interested in knowing if this is the correct approach
to take or whether I am missing a much more suitable one.

Martyn
---

 arch/powerpc/boot/dts/gef_sbc610.dts   |6 +
 arch/powerpc/configs/86xx/gef_sbc610_defconfig |4 ++-
 arch/powerpc/include/asm/nvram.h   |3 ++
 arch/powerpc/kernel/setup_32.c |8 ++
 arch/powerpc/platforms/86xx/Kconfig|1 +
 arch/powerpc/platforms/86xx/gef_sbc610.c   |5 
 arch/powerpc/sysdev/mmio_nvram.c   |   32 
 drivers/char/generic_nvram.c   |   24 ++
 8 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/boot/dts/gef_sbc610.dts 
b/arch/powerpc/boot/dts/gef_sbc610.dts
index e78c355..ed230bf 100644
--- a/arch/powerpc/boot/dts/gef_sbc610.dts
+++ b/arch/powerpc/boot/dts/gef_sbc610.dts
@@ -84,6 +84,12 @@
  6 0 0xfd00 0x0080 // IO FPGA (8-bit)
  7 0 0xfd80 0x0080;   // IO FPGA (32-bit)
 
+   [EMAIL PROTECTED],0 {
+   device_type = nvram;
+   compatible = simtek,stk14ca8;
+   reg = 0x3 0x0 0x2;
+   };
+
[EMAIL PROTECTED],0 {
compatible = gef,fpga-regs;
reg = 0x4 0x0 0x40;
diff --git a/arch/powerpc/configs/86xx/gef_sbc610_defconfig 
b/arch/powerpc/configs/86xx/gef_sbc610_defconfig
index b539433..3dfd252 100644
--- a/arch/powerpc/configs/86xx/gef_sbc610_defconfig
+++ b/arch/powerpc/configs/86xx/gef_sbc610_defconfig
@@ -178,7 +178,7 @@ CONFIG_MPIC=y
 # CONFIG_MPIC_WEIRD is not set
 # CONFIG_PPC_I8259 is not set
 # CONFIG_PPC_RTAS is not set
-# CONFIG_MMIO_NVRAM is not set
+CONFIG_MMIO_NVRAM=y
 # CONFIG_PPC_MPC106 is not set
 # CONFIG_PPC_970_NAP is not set
 # CONFIG_PPC_INDIRECT_IO is not set
@@ -991,7 +991,7 @@ CONFIG_UNIX98_PTYS=y
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
 CONFIG_HW_RANDOM=y
-# CONFIG_NVRAM is not set
+CONFIG_NVRAM=y
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
 # CONFIG_RAW_DRIVER is not set
diff --git a/arch/powerpc/include/asm/nvram.h b/arch/powerpc/include/asm/nvram.h
index efde5ac..71df8b2 100644
--- a/arch/powerpc/include/asm/nvram.h
+++ b/arch/powerpc/include/asm/nvram.h
@@ -107,6 +107,9 @@ extern void pmac_xpram_write(int xpaddr, u8 data);
 /* Synchronize NVRAM */
 extern voidnvram_sync(void);
 
+/* Determine NVRAM size */
+extern ssize_t nvram_size(void);
+
 /* Normal access to NVRAM */
 extern unsigned char nvram_read_byte(int i);
 extern void nvram_write_byte(unsigned char c, int i);
diff --git a/arch/powerpc/kernel/setup_32.c b/arch/powerpc/kernel/setup_32.c
index c1a2762..8130b9b 100644
--- a/arch/powerpc/kernel/setup_32.c
+++ b/arch/powerpc/kernel/setup_32.c
@@ -200,6 +200,14 @@ void nvram_write_byte(unsigned char val, int addr)
 }
 EXPORT_SYMBOL(nvram_write_byte);
 
+ssize_t nvram_size(void)
+{
+   if (ppc_md.nvram_size)
+   return ppc_md.nvram_size();
+   return 0;
+}
+EXPORT_SYMBOL(nvram_size);
+
 void nvram_sync(void)
 {
if (ppc_md.nvram_sync)
diff --git a/arch/powerpc/platforms/86xx/Kconfig 
b/arch/powerpc/platforms/86xx/Kconfig
index 8e56939..be4e9f9 100644
--- a/arch/powerpc/platforms/86xx/Kconfig
+++ b/arch/powerpc/platforms/86xx/Kconfig
@@ -34,6 +34,7 @@ config MPC8610_HPCD
 config GEF_SBC610
bool GE Fanuc SBC610
select DEFAULT_UIMAGE
+   select MMIO_NVRAM
select GENERIC_GPIO
select ARCH_REQUIRE_GPIOLIB
select HAS_RAPIDIO
diff --git a/arch/powerpc/platforms/86xx/gef_sbc610.c 
b/arch/powerpc/platforms/86xx/gef_sbc610.c
index fb371f5..2daec46 100644
--- a/arch/powerpc/platforms/86xx/gef_sbc610.c
+++ b/arch/powerpc/platforms/86xx/gef_sbc610.c
@@ -34,6 +34,7 @@
 #include asm/udbg.h
 
 #include asm/mpic.h
+#include asm/nvram.h
 
 #include sysdev/fsl_pci.h
 #include sysdev/fsl_soc.h
@@ -96,6 +97,10 @@ static void __init gef_sbc610_setup_arch(void)
printk(KERN_WARNING Unable to map board registers\n);
of_node_put(regs);
}
+
+#if defined(CONFIG_MMIO_NVRAM)
+   mmio_nvram_init();
+#endif
 }
 
 /* Return the PCB revision */
diff --git a/arch/powerpc/sysdev/mmio_nvram.c b/arch/powerpc/sysdev/mmio_nvram.c
index 7b49633..2073242 100644

Re: [PATCH] [v3] powerpc/4xx: work around CHIP11 errata in a more PAGE_SIZE-friendly way

2008-11-12 Thread Benjamin Herrenschmidt
On Wed, 2008-11-12 at 06:31 -0500, Josh Boyer wrote:
 On Wed, 12 Nov 2008 15:37:43 +1100
 Benjamin Herrenschmidt [EMAIL PROTECTED] wrote:
 
  On Tue, 2008-11-11 at 18:06 -0600, Hollis Blanchard wrote:
   The current CHIP11 errata truncates the device tree memory node, and 
   subtracts
   (hardcoded) 4096 bytes. This breaks kernels with larger PAGE_SIZE, since 
   the
   bootmem allocator assumes that total memory is a multiple of PAGE_SIZE.
   
   Instead, use a device tree memory reservation to reserve only the 256 
   bytes
   actually affected by the errata, leaving the total memory size unaltered.
   
   Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
  
  While I prefer this approach, won't it break kexec ?
 
 Break it how?  Particularly given that kexec doesn't work on 4xx (yet).

Allright, wrong wording. It will make kexec more painful since it will
have to also create that reserved area in the target DT.

 I don't think that's it.  I think it's more that we're opportunistic and
 the wrapper is the easiest place to do this, given that U-Boot itself
 will be doing the reserve for platforms that don't require the
 wrapper.
 
 So we could do the fixup in-kernel, but how do you do that
 deterministically given that U-Boot might have already done it?

Bah, do you know many RAM chip that will chop off the last 4K ?

I still find it a bit tricky to have memory nodes not aligned on nice
fat big boundaries tho.

Cheers,
Ben.


___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] [v3] powerpc/4xx: work around CHIP11 errata in a more PAGE_SIZE-friendly way

2008-11-12 Thread Hollis Blanchard
On Wed, 2008-11-12 at 22:52 +1100, Benjamin Herrenschmidt wrote:
 On Wed, 2008-11-12 at 06:31 -0500, Josh Boyer wrote:
  On Wed, 12 Nov 2008 15:37:43 +1100
  Benjamin Herrenschmidt [EMAIL PROTECTED] wrote:
  
   On Tue, 2008-11-11 at 18:06 -0600, Hollis Blanchard wrote:
The current CHIP11 errata truncates the device tree memory node, and 
subtracts
(hardcoded) 4096 bytes. This breaks kernels with larger PAGE_SIZE, 
since the
bootmem allocator assumes that total memory is a multiple of PAGE_SIZE.

Instead, use a device tree memory reservation to reserve only the 256 
bytes
actually affected by the errata, leaving the total memory size 
unaltered.

Signed-off-by: Hollis Blanchard [EMAIL PROTECTED]
   
   While I prefer this approach, won't it break kexec ?
  
  Break it how?  Particularly given that kexec doesn't work on 4xx (yet).
 
 Allright, wrong wording. It will make kexec more painful since it will
 have to also create that reserved area in the target DT.
 
  I don't think that's it.  I think it's more that we're opportunistic and
  the wrapper is the easiest place to do this, given that U-Boot itself
  will be doing the reserve for platforms that don't require the
  wrapper.
  
  So we could do the fixup in-kernel, but how do you do that
  deterministically given that U-Boot might have already done it?
 
 Bah, do you know many RAM chip that will chop off the last 4K ?

Forget pages. The errata is about the last 256 bytes of physical memory.

 I still find it a bit tricky to have memory nodes not aligned on nice
 fat big boundaries tho.

I don't know what you're referring to. The patch I sent doesn't touch
memory nodes, so they are indeed still aligned on nice fat big
boundaries.

I don't think this is overengineering at all. We can't touch the last
256 bytes, so we mark it reserved, and then we won't. Altering memory
nodes is far more complicated and error-prone.

-- 
Hollis Blanchard
IBM Linux Technology Center

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] powerpc: Fix 460EX/460GT machine check handling

2008-11-12 Thread Benjamin Herrenschmidt
On Wed, 2008-11-12 at 06:27 -0500, Josh Boyer wrote:
 On Wed, 12 Nov 2008 13:02:43 +1100
 Benjamin Herrenschmidt [EMAIL PROTECTED] wrote:
 
  Those cores use the 440A type machine check (ie, they have
  MCSRR0/MCSRR1). They thus need to call the appropriate fixup
  function to hook the right variant of the exception.
  
  Without this, all machine checks become fatal due to loss
  of context when entering the exception handler.
 
 Looks fine to me.  However, what machine checks were you getting that
 caused you to see this that aren't fatal anyway?

PCI aborts from userspace when toying with video card POSTing 
x86emu :-)

Cheers,
Ben.

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] powerpc: Fix 460EX/460GT machine check handling

2008-11-12 Thread Josh Boyer
On Wed, 12 Nov 2008 13:02:43 +1100
Benjamin Herrenschmidt [EMAIL PROTECTED] wrote:

 Those cores use the 440A type machine check (ie, they have
 MCSRR0/MCSRR1). They thus need to call the appropriate fixup
 function to hook the right variant of the exception.
 
 Without this, all machine checks become fatal due to loss
 of context when entering the exception handler.

Looks fine to me.  However, what machine checks were you getting that
caused you to see this that aren't fatal anyway?

josh

 
 Signed-off-by: Benjamin Herrenschmidt [EMAIL PROTECTED]
 ---
 
  arch/powerpc/kernel/cpu_setup_44x.S |7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)
 
 --- linux-work.orig/arch/powerpc/kernel/cpu_setup_44x.S   2008-11-12 
 12:51:24.0 +1100
 +++ linux-work/arch/powerpc/kernel/cpu_setup_44x.S2008-11-12 
 13:01:03.0 +1100
 @@ -34,7 +34,12 @@ _GLOBAL(__setup_cpu_440grx)
   blr
  _GLOBAL(__setup_cpu_460ex)
  _GLOBAL(__setup_cpu_460gt)
 - b   __init_fpu_44x
 + mflrr4
 + bl  __init_fpu_44x
 + bl  __fixup_440A_mcheck
 + mtlrr4
 + blr
 +
  _GLOBAL(__setup_cpu_440gx)
  _GLOBAL(__setup_cpu_440spe)
   b   __fixup_440A_mcheck
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Using gpiolib to power off my system

2008-11-12 Thread Juergen Beisert
Hi list,

I want to use the gpiolib API in a routine that should poweroff the system 
(MPC5200B). I register my poweroff routine in the define_machine() macro as:

[...]
.power_off  = my_power_off,
[...]

In this routine I'm using gpio_request(...), gpio_direction_output(...) and 
gpio_set_value(...)  but nothing happens.

When I set the GPIOs in the hard way (ioremap() + playing with the registers) 
the system switches off as expected.

How to get some useful debug output at this late system state (printk does not 
work anymore)?

Regards,
Juergen
-- 
Dipl.-Ing. Juergen Beisert | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
    Handelsregister: Amtsgericht Hildesheim, HRA 2686
     Vertretung Sued/Muenchen, Germany
   Phone: +49-8766-939 228 |  Fax: +49-5121-206917-9
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH] usb/fsl_qe_udc: Report disconnect before unbinding

2008-11-12 Thread Anton Vorontsov
Gadgets disable endpoints in their disconnect callbacks, so
we must call disconnect before unbinding. This also fixes
muram memory leak, since we free muram in the qe_ep_disable().

But mainly the patch fixes following badness:

[EMAIL PROTECTED]:~# insmod fsl_qe_udc.ko
fsl_qe_udc: Freescale QE/CPM USB Device Controller driver, 1.0
fsl_qe_udc e01006c0.usb: QE USB controller initialized as device
[EMAIL PROTECTED]:~# insmod g_ether.ko
g_ether gadget: using random self ethernet address
g_ether gadget: using random host ethernet address
usb0: MAC be:2d:3c:fa:be:f0
usb0: HOST MAC 62:b8:6a:df:38:66
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
fsl_qe_udc e01006c0.usb: fsl_qe_udc bind to driver g_ether
g_ether gadget: high speed config #1: CDC Ethernet (ECM)
[EMAIL PROTECTED]:~# rmmod g_ether.ko
[ cut here ]
Badness at drivers/usb/gadget/composite.c:871
[...]
NIP [d10c1374] composite_unbind+0x24/0x15c [g_ether]
LR [d10a82f4] usb_gadget_unregister_driver+0x128/0x168 [fsl_qe_udc]
Call Trace:
[cfb93e80] [cfb1f3a0] 0xcfb1f3a0 (unreliable)
[cfb93eb0] [d10a82f4] usb_gadget_unregister_driver+0x128/0x168 [fsl_qe_udc]
[cfb93ed0] [d10c2a3c] usb_composite_unregister+0x3c/0x4c [g_ether]
[cfb93ee0] [c006bde0] sys_delete_module+0x130/0x19c
[cfb93f40] [c00142d8] ret_from_syscall+0x0/0x38
[...]
fsl_qe_udc e01006c0.usb: unregistered gadget driver 'g_ether'

Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
---
 drivers/usb/gadget/fsl_qe_udc.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/fsl_qe_udc.c b/drivers/usb/gadget/fsl_qe_udc.c
index 37c8575..c7de671 100644
--- a/drivers/usb/gadget/fsl_qe_udc.c
+++ b/drivers/usb/gadget/fsl_qe_udc.c
@@ -2382,6 +2382,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver 
*driver)
nuke(loop_ep, -ESHUTDOWN);
spin_unlock_irqrestore(udc_controller-lock, flags);
 
+   /* report disconnect; the driver is already quiesced */
+   driver-disconnect(udc_controller-gadget);
+
/* unbind gadget and unhook driver. */
driver-unbind(udc_controller-gadget);
udc_controller-gadget.dev.driver = NULL;
-- 
1.5.6.3
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH] usb/fsl_usb2_udc: Report disconnect before unbinding

2008-11-12 Thread Anton Vorontsov
Gadgets disable endpoints in their disconnect callbacks, so
we must call disconnect before unbinding.

The patch fixes following badness:

[EMAIL PROTECTED]:~# insmod fsl_usb2_udc.ko
Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)
[EMAIL PROTECTED]:~# insmod g_ether.ko
g_ether gadget: using random self ethernet address
g_ether gadget: using random host ethernet address
usb0: MAC 26:07:ba:c0:44:33
usb0: HOST MAC 96:81:0c:05:4d:e3
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
fsl-usb2-udc: bind to driver g_ether
g_ether gadget: high speed config #1: CDC Ethernet (ECM)
[EMAIL PROTECTED]:~# rmmod g_ether.ko
[ cut here ]
Badness at drivers/usb/gadget/composite.c:871
[...]
NIP [e10c3454] composite_unbind+0x24/0x15c [g_ether]
LR [e10aa454] usb_gadget_unregister_driver+0x13c/0x164 [fsl_usb2_udc]
Call Trace:
[df145e80] [ff94] 0xff94 (unreliable)
[df145eb0] [e10aa454] usb_gadget_unregister_driver+0x13c/0x164 [fsl_usb2_udc]
[df145ed0] [e10c4c40] usb_composite_unregister+0x3c/0x4c [g_ether]
[df145ee0] [c006bcc0] sys_delete_module+0x130/0x19c
[df145f40] [c00142d8] ret_from_syscall+0x0/0x38
[...]
unregistered gadget driver 'g_ether'

Signed-off-by: Anton Vorontsov [EMAIL PROTECTED]
---

This is not a duplicate email, this patch is for other driver. ;-)

 drivers/usb/gadget/fsl_usb2_udc.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/fsl_usb2_udc.c 
b/drivers/usb/gadget/fsl_usb2_udc.c
index 091bb55..b4cd017 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -1836,6 +1836,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver 
*driver)
nuke(loop_ep, -ESHUTDOWN);
spin_unlock_irqrestore(udc_controller-lock, flags);
 
+   /* report disconnect; the driver is already quiesced */
+   driver-disconnect(udc_controller-gadget);
+
/* unbind gadget and unhook driver. */
driver-unbind(udc_controller-gadget);
udc_controller-gadget.dev.driver = NULL;
-- 
1.5.6.3
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] usb/fsl_qe_udc: Report disconnect before unbinding

2008-11-12 Thread Alan Stern
On Wed, 12 Nov 2008, Anton Vorontsov wrote:

 Gadgets disable endpoints in their disconnect callbacks, so
 we must call disconnect before unbinding. This also fixes
 muram memory leak, since we free muram in the qe_ep_disable().

 --- a/drivers/usb/gadget/fsl_qe_udc.c
 +++ b/drivers/usb/gadget/fsl_qe_udc.c
 @@ -2382,6 +2382,9 @@ int usb_gadget_unregister_driver(struct 
 usb_gadget_driver *driver)
   nuke(loop_ep, -ESHUTDOWN);
   spin_unlock_irqrestore(udc_controller-lock, flags);
  
 + /* report disconnect; the driver is already quiesced */
 + driver-disconnect(udc_controller-gadget);
 +
   /* unbind gadget and unhook driver. */
   driver-unbind(udc_controller-gadget);
   udc_controller-gadget.dev.driver = NULL;

Wouldn't it be better to do this before nuking the existing requests?  
The comment is wrong; the gadget driver is _not_ quiesced at this
point.  In fact the disconnect call is what quiesces the driver!

And wouldn't it be better to _skip_ doing this if the gadget wasn't 
connected before?

Alan Stern

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] usb/fsl_qe_udc: Report disconnect before unbinding

2008-11-12 Thread Anton Vorontsov
On Wed, Nov 12, 2008 at 02:38:02PM -0500, Alan Stern wrote:
 On Wed, 12 Nov 2008, Anton Vorontsov wrote:
 
  Gadgets disable endpoints in their disconnect callbacks, so
  we must call disconnect before unbinding. This also fixes
  muram memory leak, since we free muram in the qe_ep_disable().
 
  --- a/drivers/usb/gadget/fsl_qe_udc.c
  +++ b/drivers/usb/gadget/fsl_qe_udc.c
  @@ -2382,6 +2382,9 @@ int usb_gadget_unregister_driver(struct 
  usb_gadget_driver *driver)
  nuke(loop_ep, -ESHUTDOWN);
  spin_unlock_irqrestore(udc_controller-lock, flags);
   
  +   /* report disconnect; the driver is already quiesced */
  +   driver-disconnect(udc_controller-gadget);
  +
  /* unbind gadget and unhook driver. */
  driver-unbind(udc_controller-gadget);
  udc_controller-gadget.dev.driver = NULL;
 
 Wouldn't it be better to do this before nuking the existing requests?  
 The comment is wrong; the gadget driver is _not_ quiesced at this
 point.  In fact the disconnect call is what quiesces the driver!

composite_unbind() says:

/* composite_disconnect() must already have been called
 * by the underlying peripheral controller driver!
 * so there's no i/o concurrency that could affect the
 * state protected by cdev-lock.
 */

Which I read as at disconnect time the controller should
already be disabled, no further i/o can happen. Which means
that we should nuke all pending requests and stop the
controller.

In this comment:
/* report disconnect; the driver is already quiesced */
the driver means the udc driver, not the gadget driver.

FWIW, the PXA27x UDC controller also stops all activity and
completely disables the controller before calling the
disconnect().

 And wouldn't it be better to _skip_ doing this if the gadget wasn't 
 connected before?

Composite framework handles this. If there were no connections,
then the disconnect() is a nop (except the spin lock/unlock pair).

I'm not sure how the controller driver could tell if there
was a connection or not: it doesn't operate these terms.
What the udc controller knows is: how to report bus reset
and how to receive or transmit the data...

Thanks,

-- 
Anton Vorontsov
email: [EMAIL PROTECTED]
irc://irc.freenode.net/bd2
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] [v3] powerpc/4xx: work around CHIP11 errata in a more PAGE_SIZE-friendly way

2008-11-12 Thread Benjamin Herrenschmidt
On Wed, 2008-11-12 at 09:11 -0600, Hollis Blanchard wrote:
 Forget pages. The errata is about the last 256 bytes of physical
 memory.
 
  I still find it a bit tricky to have memory nodes not aligned on
 nice
  fat big boundaries tho.
 
 I don't know what you're referring to. The patch I sent doesn't touch
 memory nodes, so they are indeed still aligned on nice fat big
 boundaries.

My last comment was about the approach of modifying the memory node.

 I don't think this is overengineering at all. We can't touch the last
 256 bytes, so we mark it reserved, and then we won't. Altering memory
 nodes is far more complicated and error-prone.

But your approach is going to be painful for kexec which will have to
duplicate that logic.

Again, why can't we just stick something in the kernel code that
reserves the last page ? It could be in prom.c or it could be called by
affected 4xx platforms by the platform code, whatever, but the reserve
map isn't really meant for that and will not be passed over from kernel
to kernel by kexec.

Ben.

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH] usb/fsl_qe_udc: Report disconnect before unbinding

2008-11-12 Thread Alan Stern
On Wed, 12 Nov 2008, Anton Vorontsov wrote:

 On Wed, Nov 12, 2008 at 11:12:18PM +0300, Anton Vorontsov wrote:
  On Wed, Nov 12, 2008 at 10:59:16PM +0300, Anton Vorontsov wrote:
  [...]
And wouldn't it be better to _skip_ doing this if the gadget wasn't 
connected before?
   
   Composite framework handles this. If there were no connections,
   then the disconnect() is a nop (except the spin lock/unlock pair).
   
   I'm not sure how the controller driver could tell if there
   was a connection or not: it doesn't operate these terms.
   What the udc controller knows is: how to report bus reset
   and how to receive or transmit the data...
  
  It seems I lied. Did you mean something like this patch?
  
  diff --git a/drivers/usb/gadget/fsl_qe_udc.c 
  b/drivers/usb/gadget/fsl_qe_udc.c
  index c7de671..fd44cf4 100644
  --- a/drivers/usb/gadget/fsl_qe_udc.c
  +++ b/drivers/usb/gadget/fsl_qe_udc.c
  @@ -2368,6 +2368,9 @@ int usb_gadget_unregister_driver(struct 
  usb_gadget_driver *driver)
  /* stop usb controller, disable intr */
  qe_usb_disable();
   
  +   if (udc-usb_state == USB_STATE_DEFAULT)
 
 Should be also || usb_state == USB_STATE_ATTACHED, since
 this is the initial value after the usb_gadget_register_driver().
 
 And the _DEFAULT state is we're just after the bus reset (also
 means that we already called the disconnect()).

That sounds right.  Although come to think of it, I guess there really 
is no harm in calling the disconnect method twice in a row.  But it's 
better to do what the other UDC drivers do.

  +   goto skip_quiesce;
  +
  /* in fact, no needed */
  udc_controller-usb_state = USB_STATE_ATTACHED;
  udc_controller-ep0_state = WAIT_FOR_SETUP;
  @@ -2385,6 +2388,7 @@ int usb_gadget_unregister_driver(struct 
  usb_gadget_driver *driver)
  /* report disconnect; the driver is already quiesced */
  driver-disconnect(udc_controller-gadget);

I would update this last comment slightly.  The word driver is
ambiguous, and since this function is named
usb_gadget_unregister_driver(), it looks like you're talking about the
gadget driver.

  +skip_quiesce:
  /* unbind gadget and unhook driver. */
  driver-unbind(udc_controller-gadget);
  udc_controller-gadget.dev.driver = NULL;

Alan Stern

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


patch usb-powerpc-workaround-for-the-ppc440epx-usbh_23-errata.patch added to gregkh-2.6 tree

2008-11-12 Thread gregkh

This is a note to let you know that I've just added the patch titled

Subject: USB: powerpc: Workaround for the PPC440EPX USBH_23 errata [take 3]

to my gregkh-2.6 tree.  Its filename is

usb-powerpc-workaround-for-the-ppc440epx-usbh_23-errata.patch

This tree can be found at 
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/


From [EMAIL PROTECTED]  Wed Nov 12 14:48:36 2008
From: Vitaly Bordug [EMAIL PROTECTED]
Date: Sun, 9 Nov 2008 19:43:30 +0100
Subject: USB: powerpc: Workaround for the PPC440EPX USBH_23 errata [take 3]
To: [EMAIL PROTECTED]
Cc: linuxppc-dev@ozlabs.org linuxppc-dev@ozlabs.org, Mark Miesfeld [EMAIL 
PROTECTED], Stefan Roese [EMAIL PROTECTED], Benjamin Herrenschmidt [EMAIL 
PROTECTED], Alan Stern [EMAIL PROTECTED]
Message-ID: [EMAIL PROTECTED]


A published errata for ppc440epx states, that when running Linux with
both EHCI and OHCI modules loaded, the EHCI module experiences a fatal
error when a high-speed device is connected to the USB2.0, and
functions normally if OHCI module is not loaded.

There used to be recommendation to use only hi-speed or full-speed
devices with specific conditions, when respective module was unloaded.
Later, it was observed that ohci suspend is enough to keep things
going, and it was turned into workaround, as explained below.

Quote from original descriprion:

The 440EPx USB 2.0 Host controller is an EHCI compliant controller.  In
USB 2.0 Host controllers, each EHCI controller has one or more companion
controllers, which may be OHCI or UHCI.  An USB 2.0 Host controller will
contain one or more ports.  For each port, only one of the controllers
is connected at any one time. In the 440EPx, there is only one OHCI
companion controller, and only one USB 2.0 Host port.
All ports on an USB 2.0 controller default to the companion
controller.  If you load only an ohci driver, it will have control of
the ports and any deviceplugged in will operate, although high speed
devices will be forced to operate at full speed.  When an ehci driver
is loaded, it explicitly takes control of the ports.  If there is a
device connected, and / or every time there is a new device connected,
the ehci driver determines if the device is high speed or not.  If it
is high speed, the driver retains control of the port.  If it is not,
the driver explicitly gives the companion controller control of the
port.

The is a software workaround that uses
Initial version of the software workaround was posted to
linux-usb-devel:

http://www.mail-archive.com/[EMAIL PROTECTED]/msg54019.html

and later available from amcc.com:
http://www.amcc.com/Embedded/Downloads/download.html?cat=1family=15ins=2

The patch below is generally based on the latter, but reworked to
powerpc/of_device USB drivers, and uses a few devicetree inquiries to
get rid of (some) hardcoded defines.

Signed-off-by: Vitaly Bordug [EMAIL PROTECTED]
Signed-off-by: Stefan Roese [EMAIL PROTECTED]
Cc: David Brownell [EMAIL PROTECTED]
Signed-off-by: Greg Kroah-Hartman [EMAIL PROTECTED]

---
 arch/powerpc/boot/dts/sequoia.dts |2 -
 drivers/usb/host/ehci-hub.c   |9 ++-
 drivers/usb/host/ehci-ppc-of.c|   45 +-
 drivers/usb/host/ehci.h   |   34 
 drivers/usb/host/ohci-ppc-of.c|   25 +
 5 files changed, 112 insertions(+), 3 deletions(-)

--- a/arch/powerpc/boot/dts/sequoia.dts
+++ b/arch/powerpc/boot/dts/sequoia.dts
@@ -134,7 +134,7 @@
};
 
USB1: [EMAIL PROTECTED] {
-   compatible = ohci-be;
+   compatible = ibm,usb-ohci-440epx, ohci-be;
reg = 0x 0xe400 0x0060;
interrupt-parent = UIC0;
interrupts = 0x15 0x8;
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -120,6 +120,16 @@ struct ehci_hcd {  /* one per controlle
unsignedhas_fsl_port_bug:1; /* FreeScale */
unsignedbig_endian_mmio:1;
unsignedbig_endian_desc:1;
+   unsignedhas_amcc_usb23:1;
+
+   /* required for usb32 quirk */
+   #define OHCI_CTRL_HCFS  (3  6)
+   #define OHCI_USB_OPER   (2  6)
+   #define OHCI_USB_SUSPEND(3  6)
+
+   #define OHCI_HCCTRL_OFFSET  0x4
+   #define OHCI_HCCTRL_LEN 0x4
+   __hc32  *ohci_hcctrl_reg;
 
u8  sbrn;   /* packed release number */
 
@@ -638,6 +648,30 @@ static inline void ehci_writel(const str
 #endif
 }
 
+/*
+ * On certain ppc-44x SoC there is a HW issue, that could only worked around 
with
+ * explicit suspend/operate of OHCI. This function hereby makes sense only on 
that arch.
+ * Other common bits are dependant on has_amcc_usb23 quirk flag.
+ */
+#ifdef CONFIG_44x
+static inline void set_ohci_hcfs(struct ehci_hcd 

[PATCH 0/2] Addition of MWDMA/UDMA modes to MPC5200 ATA driver

2008-11-12 Thread Grant Likely
Hi all,

This is Tim's series for adding UDMA/MWDMA support to the Freescale
MPC5200 ATA device driver.  Tested on Genesi's Efika board.

Jeff, if it is okay by you, I'm going to push this through my mpc5200
powerpc tree (after addressing any comments of course) since it only
affects the MPC5200 PowerPC SoC.

g.

--
Grant Likely, B.Sc. P.Eng.
Secret Lab Technologies Ltd.
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 1/2] powerpc/mpc5200: Bestcomm fixes to ATA support

2008-11-12 Thread Grant Likely
From: Tim Yamin [EMAIL PROTECTED]

1) ata.h has dst_pa in the wrong place (needs to match what the BestComm
   task microcode in bcom_ata_task.c expects); fix it.

2) The BestComm ATA task priority was changed to maximum in bestcomm_priv.h;
   this fixes a deadlock issue I was experiencing when heavy DMA was
   occuring on both the ATA and Ethernet BestComm tasks, e.g. when
   downloading a large file over a LAN to disk.

3) The ATA BestComm driver uses bcom_ata_bd which is bigger than bcom_bd
   and this causes problems because the various bcom_... functions do not
   dereference the correct location. I've introduced bcom_get_bd which
   uses bcom_task.bd_size and this fixes the problem.

Signed-off-by: Tim Yamin [EMAIL PROTECTED]
Signed-off-by: Grant Likely [EMAIL PROTECTED]
---

 arch/powerpc/sysdev/bestcomm/ata.h   |2 +
 arch/powerpc/sysdev/bestcomm/bestcomm.h  |   35 +-
 arch/powerpc/sysdev/bestcomm/bestcomm_priv.h |4 +--
 3 files changed, 31 insertions(+), 10 deletions(-)


diff --git a/arch/powerpc/sysdev/bestcomm/ata.h 
b/arch/powerpc/sysdev/bestcomm/ata.h
index 1098276..0374322 100644
--- a/arch/powerpc/sysdev/bestcomm/ata.h
+++ b/arch/powerpc/sysdev/bestcomm/ata.h
@@ -16,8 +16,8 @@
 
 struct bcom_ata_bd {
u32 status;
-   u32 dst_pa;
u32 src_pa;
+   u32 dst_pa;
 };
 
 extern struct bcom_task *
diff --git a/arch/powerpc/sysdev/bestcomm/bestcomm.h 
b/arch/powerpc/sysdev/bestcomm/bestcomm.h
index c960a8b..dc2b143 100644
--- a/arch/powerpc/sysdev/bestcomm/bestcomm.h
+++ b/arch/powerpc/sysdev/bestcomm/bestcomm.h
@@ -38,7 +38,7 @@ struct bcom_task {
unsigned intflags;
int irq;
 
-   struct bcom_bd  *bd;
+   void*bd;
phys_addr_t bd_pa;
void**cookie;
unsigned short  index;
@@ -140,15 +140,29 @@ bcom_queue_full(struct bcom_task *tsk)
 }
 
 /**
+ * bcom_get_bd - Get a BD from the queue
+ * @tsk: The BestComm task structure
+ * index: Index of the BD to fetch
+ */
+static inline struct bcom_bd
+*bcom_get_bd(struct bcom_task *tsk, unsigned int index)
+{
+   return tsk-bd + index * tsk-bd_size;
+}
+
+/**
  * bcom_buffer_done - Checks if a BestComm 
  * @tsk: The BestComm task structure
  */
 static inline int
 bcom_buffer_done(struct bcom_task *tsk)
 {
+   struct bcom_bd *bd;
if (bcom_queue_empty(tsk))
return 0;
-   return !(tsk-bd[tsk-outdex].status  BCOM_BD_READY);
+
+   bd = bcom_get_bd(tsk, tsk-outdex);
+   return !(bd-status  BCOM_BD_READY);
 }
 
 /**
@@ -160,16 +174,21 @@ bcom_buffer_done(struct bcom_task *tsk)
 static inline struct bcom_bd *
 bcom_prepare_next_buffer(struct bcom_task *tsk)
 {
-   tsk-bd[tsk-index].status = 0; /* cleanup last status */
-   return tsk-bd[tsk-index];
+   struct bcom_bd *bd;
+
+   bd = bcom_get_bd(tsk, tsk-index);
+   bd-status = 0; /* cleanup last status */
+   return bd;
 }
 
 static inline void
 bcom_submit_next_buffer(struct bcom_task *tsk, void *cookie)
 {
+   struct bcom_bd *bd = bcom_get_bd(tsk, tsk-index);
+
tsk-cookie[tsk-index] = cookie;
mb();   /* ensure the bd is really up-to-date */
-   tsk-bd[tsk-index].status |= BCOM_BD_READY;
+   bd-status |= BCOM_BD_READY;
tsk-index = _bcom_next_index(tsk);
if (tsk-flags  BCOM_FLAGS_ENABLE_TASK)
bcom_enable(tsk);
@@ -179,10 +198,12 @@ static inline void *
 bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct bcom_bd 
**p_bd)
 {
void *cookie = tsk-cookie[tsk-outdex];
+   struct bcom_bd *bd = bcom_get_bd(tsk, tsk-outdex);
+
if (p_status)
-   *p_status = tsk-bd[tsk-outdex].status;
+   *p_status = bd-status;
if (p_bd)
-   *p_bd = tsk-bd[tsk-outdex];
+   *p_bd = bd;
tsk-outdex = _bcom_next_outdex(tsk);
return cookie;
 }
diff --git a/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h 
b/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
index 866a291..746f155 100644
--- a/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
+++ b/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
@@ -198,8 +198,8 @@ struct bcom_task_header {
 #define BCOM_IPR_SCTMR_1   2
 #define BCOM_IPR_FEC_RX6
 #define BCOM_IPR_FEC_TX5
-#define BCOM_IPR_ATA_RX4
-#define BCOM_IPR_ATA_TX3
+#define BCOM_IPR_ATA_RX7
+#define BCOM_IPR_ATA_TX7
 #define BCOM_IPR_SCPCI_RX  2
 #define BCOM_IPR_SCPCI_TX  2
 #define BCOM_IPR_PSC3_RX   2

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 2/2] powerpc/mpc5200: Add MDMA/UDMA support to MPC5200 ATA driver

2008-11-12 Thread Grant Likely
From: Tim Yamin [EMAIL PROTECTED]

This patch adds MDMA/UDMA support using BestComm for DMA on the MPC5200
platform.  Based heavily on previous work by Freescale (Bernard Kuhn,
John Rigby) and Domen Puncer.

With this patch, a SanDisk Extreme IV CF card gets read speeds of
approximately 26.70 MB/sec.

Signed-off-by: Tim Yamin [EMAIL PROTECTED]
Signed-off-by: Grant Likely [EMAIL PROTECTED]
---

 arch/powerpc/sysdev/bestcomm/ata.c   |3 
 arch/powerpc/sysdev/bestcomm/bestcomm.c  |7 
 arch/powerpc/sysdev/bestcomm/bestcomm_priv.h |   16 +
 drivers/ata/pata_mpc52xx.c   |  440 +-
 4 files changed, 443 insertions(+), 23 deletions(-)


diff --git a/arch/powerpc/sysdev/bestcomm/ata.c 
b/arch/powerpc/sysdev/bestcomm/ata.c
index 1f5258f..901c9f9 100644
--- a/arch/powerpc/sysdev/bestcomm/ata.c
+++ b/arch/powerpc/sysdev/bestcomm/ata.c
@@ -61,6 +61,9 @@ bcom_ata_init(int queue_len, int maxbufsize)
struct bcom_ata_var *var;
struct bcom_ata_inc *inc;
 
+   /* Prefetch breaks ATA DMA.  Turn it off for ATA DMA */
+   bcom_disable_prefetch();
+
tsk = bcom_task_alloc(queue_len, sizeof(struct bcom_ata_bd), 0);
if (!tsk)
return NULL;
diff --git a/arch/powerpc/sysdev/bestcomm/bestcomm.c 
b/arch/powerpc/sysdev/bestcomm/bestcomm.c
index 446c9ea..378ebd9 100644
--- a/arch/powerpc/sysdev/bestcomm/bestcomm.c
+++ b/arch/powerpc/sysdev/bestcomm/bestcomm.c
@@ -279,7 +279,6 @@ bcom_engine_init(void)
int task;
phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa;
unsigned int tdt_size, ctx_size, var_size, fdt_size;
-   u16 regval;
 
/* Allocate  clear SRAM zones for FDT, TDTs, contexts and vars/incs */
tdt_size = BCOM_MAX_TASKS * sizeof(struct bcom_tdt);
@@ -331,10 +330,8 @@ bcom_engine_init(void)
out_8(bcom_eng-regs-ipr[BCOM_INITIATOR_ALWAYS], BCOM_IPR_ALWAYS);
 
/* Disable COMM Bus Prefetch on the original 5200; it's broken */
-   if ((mfspr(SPRN_SVR)  MPC5200_SVR_MASK) == MPC5200_SVR) {
-   regval = in_be16(bcom_eng-regs-PtdCntrl);
-   out_be16(bcom_eng-regs-PtdCntrl,  regval | 1);
-   }
+   if ((mfspr(SPRN_SVR)  MPC5200_SVR_MASK) == MPC5200_SVR)
+   bcom_disable_prefetch();
 
/* Init lock */
spin_lock_init(bcom_eng-lock);
diff --git a/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h 
b/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
index 746f155..eb0d1c8 100644
--- a/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
+++ b/arch/powerpc/sysdev/bestcomm/bestcomm_priv.h
@@ -241,6 +241,22 @@ extern void bcom_set_initiator(int task, int initiator);
 
 #define TASK_ENABLE 0x8000
 
+/**
+ * bcom_disable_prefetch - Hook to disable bus prefetching
+ *
+ * ATA DMA and the original MPC5200 need this due to silicon bugs.  At the
+ * moment disabling prefetch is a one-way street.  There is no mechanism
+ * in place to turn prefetch back on after it has been disabled.  There is
+ * no reason it couldn't be done, it would just be more complex to implement.
+ */
+static inline void bcom_disable_prefetch(void)
+{
+   u16 regval;
+
+   regval = in_be16(bcom_eng-regs-PtdCntrl);
+   out_be16(bcom_eng-regs-PtdCntrl, regval | 1);
+};
+
 static inline void
 bcom_enable_task(int task)
 {
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index a9e8273..09b7fbb 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -6,6 +6,9 @@
  * Copyright (C) 2006 Sylvain Munaut [EMAIL PROTECTED]
  * Copyright (C) 2003 Mipsys - Benjamin Herrenschmidt
  *
+ * UDMA support based on patches by Freescale (Bernard Kuhn, John Rigby),
+ * Domen Puncer and Tim Yamin.
+ *
  * This file is licensed under the terms of the GNU General Public License
  * version 2. This program is licensed as is without any warranty of any
  * kind, whether express or implied.
@@ -18,27 +21,46 @@
 #include linux/libata.h
 #include linux/of_platform.h
 
+#include asm/cacheflush.h
 #include asm/types.h
 #include asm/prom.h
 #include asm/mpc52xx.h
 
+#include sysdev/bestcomm/bestcomm.h
+#include sysdev/bestcomm/bestcomm_priv.h
+#include sysdev/bestcomm/ata.h
 
 #define DRV_NAME   mpc52xx_ata
 #define DRV_VERSION0.1.2
 
-
 /* Private structures used by the driver */
 struct mpc52xx_ata_timings {
u32 pio1;
u32 pio2;
+   u32 mdma1;
+   u32 mdma2;
+   u32 udma1;
+   u32 udma2;
+   u32 udma3;
+   u32 udma4;
+   u32 udma5;
+   int using_udma;
 };
 
 struct mpc52xx_ata_priv {
unsigned intipb_period;
struct mpc52xx_ata __iomem *ata_regs;
+   phys_addr_t ata_regs_pa;
int ata_irq;
struct mpc52xx_ata_timings  timings[2];
int csel;
+
+   /* DMA */
+   struct bcom_task*dmatsk;
+  

[PATCH 1/4] Add helpers for finding a device node which as a certain property

2008-11-12 Thread Michael Ellerman
This commit adds a routine for finding a device node which has a certain
property, the contents of the property are not taken into account,
merely the presence or absence of the property.

Based on that routine, we add a for_each_ macro for iterating over all
nodes that have a certain property.

Signed-off-by: Michael Ellerman [EMAIL PROTECTED]
---
 drivers/of/base.c  |   34 ++
 include/linux/of.h |6 ++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7c79e94..0c3dcd0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -329,6 +329,40 @@ struct device_node *of_find_compatible_node(struct 
device_node *from,
 EXPORT_SYMBOL(of_find_compatible_node);
 
 /**
+ * of_find_node_with_property - Find a node which has a property with
+ *   the given name.
+ * @from:  The node to start searching from or NULL, the node
+ * you pass will not be searched, only the next one
+ * will; typically, you pass what the previous call
+ * returned. of_node_put() will be called on it
+ * @prop_name: The name of the property to look for.
+ *
+ * Returns a node pointer with refcount incremented, use
+ * of_node_put() on it when done.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+   const char *prop_name)
+{
+   struct device_node *np;
+   struct property *pp;
+
+   read_lock(devtree_lock);
+   np = from ? from-allnext : allnodes;
+   for (; np; np = np-allnext) {
+   for (pp = np-properties; pp != 0; pp = pp-next) {
+   if (of_prop_cmp(pp-name, prop_name) == 0) {
+   goto out;
+   }
+   }
+   }
+out:
+   of_node_put(from);
+   read_unlock(devtree_lock);
+   return np;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  * @matches:   array of of device match structures to search in
  * @node:  the of device structure to match against
diff --git a/include/linux/of.h b/include/linux/of.h
index e2488f5..6a7efa2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -57,6 +57,12 @@ extern struct device_node *of_get_next_child(const struct 
device_node *node,
for (child = of_get_next_child(parent, NULL); child != NULL; \
 child = of_get_next_child(parent, child))
 
+extern struct device_node *of_find_node_with_property(
+   struct device_node *from, const char *prop_name);
+#define for_each_node_with_property(dn, prop_name) \
+   for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+dn = of_find_node_with_property(dn, prop_name))
+
 extern struct property *of_find_property(const struct device_node *np,
 const char *name,
 int *lenp);
-- 
1.5.5

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


[PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch()

2008-11-12 Thread Michael Ellerman
Signed-off-by: Michael Ellerman [EMAIL PROTECTED]
---
 arch/powerpc/platforms/powermac/setup.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/setup.c 
b/arch/powerpc/platforms/powermac/setup.c
index 82c14d2..1293772 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -310,9 +310,7 @@ static void __init pmac_setup_arch(void)
}
 
/* See if newworld or oldworld */
-   for (ic = NULL; (ic = of_find_all_nodes(ic)) != NULL; )
-   if (of_get_property(ic, interrupt-controller, NULL))
-   break;
+   ic = of_find_node_with_property(NULL, interrupt-controller);
if (ic) {
pmac_newworld = 1;
of_node_put(ic);
-- 
1.5.5

___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property

2008-11-12 Thread David Miller
From: Michael Ellerman [EMAIL PROTECTED]
Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)

 + np = from ? from-allnext : allnodes;
 + for (; np; np = np-allnext) {
 + for (pp = np-properties; pp != 0; pp = pp-next) {
 + if (of_prop_cmp(pp-name, prop_name) == 0) {
 + goto out;
 + }
 + }
 + }

We're starting to duplicate a lot of code in this file.

Perhaps split out the locked section of of_find_proeprty() into
a __of_find_property() and use that here and in of_find_property()
as well?

staitc struct property *__of_find_property(const struct device_node *np,
   const char *name,
   int *lenp)
{
struct property *pp;

for (pp = np-properties; pp != 0; pp = pp-next) {
if (of_prop_cmp(pp-name, name) == 0) {
if (lenp != 0)
*lenp = pp-length;
break;
}
}

return pp;
}

struct property *of_find_property(const struct device_node *np,
  const char *name,
  int *lenp)
{
struct property *pp;

if (!np)
return NULL;

read_lock(devtree_lock);
pp = __of_find_property(np, name, lenp);
read_unlock(devtree_lock);

return pp;
}
EXPORT_SYMBOL(of_find_property);
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev


Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property

2008-11-12 Thread Michael Ellerman
On Wed, 2008-11-12 at 22:46 -0800, David Miller wrote:
 From: Michael Ellerman [EMAIL PROTECTED]
 Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)
 
  +   np = from ? from-allnext : allnodes;
  +   for (; np; np = np-allnext) {
  +   for (pp = np-properties; pp != 0; pp = pp-next) {
  +   if (of_prop_cmp(pp-name, prop_name) == 0) {
  +   goto out;
  +   }
  +   }
  +   }
 
 We're starting to duplicate a lot of code in this file.

Agreed.

 Perhaps split out the locked section of of_find_proeprty() into
 a __of_find_property() and use that here and in of_find_property()
 as well?

Yeah I thought about it, but decided it wasn't worth it. But I'll try it
and see how the sizes end up.

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person


signature.asc
Description: This is a digitally signed message part
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev

Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property

2008-11-12 Thread Michael Ellerman
On Thu, 2008-11-13 at 17:49 +1100, Michael Ellerman wrote:
 On Wed, 2008-11-12 at 22:46 -0800, David Miller wrote:
  From: Michael Ellerman [EMAIL PROTECTED]
  Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)
  
   + np = from ? from-allnext : allnodes;
   + for (; np; np = np-allnext) {
   + for (pp = np-properties; pp != 0; pp = pp-next) {
   + if (of_prop_cmp(pp-name, prop_name) == 0) {
   + goto out;
   + }
   + }
   + }
  
  We're starting to duplicate a lot of code in this file.
 
 Agreed.
 
  Perhaps split out the locked section of of_find_proeprty() into
  a __of_find_property() and use that here and in of_find_property()
  as well?
 
 Yeah I thought about it, but decided it wasn't worth it. But I'll try it
 and see how the sizes end up.

With my compiler (4.3.1) it just gets inlined and actually makes the
text 8 bytes larger. We might be using different CFLAGs to sparc though.

I didn't think it made the source significantly clearer to split out the
of_find_property() logic, especially seeing as we don't need the lenp
behaviour in of_find_node_with_property().

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person


signature.asc
Description: This is a digitally signed message part
___
Linuxppc-dev mailing list
Linuxppc-dev@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-dev