mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/9] preperation for sh adding
@ 2010-09-02 14:10 Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 1/9] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
                   ` (9 more replies)
  0 siblings, 10 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Hi,

	this is the last updated patch series to prepare the adding of the SH
	architecture

The following changes since commit 0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4:

  menu: simplify usage for clients (2010-08-30 21:06:02 +0200)

are available in the git repository at:
  git://git.jcrosoft.org/barebox.git sh-prepare

Jean-Christophe PLAGNIOL-VILLARD (9):
      types.h: move __kernel_dev_t to include/linux/types.h
      device: fix dev_name
      stm8815: fix the uart device clock match
      arm: move clkdev to drivers/clk
      vsprintf: add %w and %w support to print unit
      at91/clock: switch to %w for clock info printing
      cfi_flash: use %W and IEEE 1541 format
      use %W instead of size_human_readable and use IEEE 1541 format
      clkdev: add print clk info command

 arch/arm/Kconfig                          |    1 -
 arch/arm/Makefile                         |    2 +-
 arch/arm/common/Kconfig                   |    2 -
 arch/arm/common/Makefile                  |    5 --
 arch/arm/configs/nhk8815_defconfig        |    2 +-
 arch/arm/include/asm/clkdev.h             |   15 +------
 arch/arm/include/asm/posix_types.h        |    1 -
 arch/arm/mach-at91/clock.c                |    8 +--
 arch/arm/mach-nomadik/8815.c              |    6 ++-
 arch/arm/mach-nomadik/Kconfig             |    2 +-
 arch/arm/mach-nomadik/clock.c             |    7 +--
 arch/blackfin/include/asm/posix_types.h   |    1 -
 arch/m68k/include/asm/posix_types.h       |    1 -
 arch/ppc/include/asm/posix_types.h        |    1 -
 arch/sandbox/include/asm/posix_types.h    |    1 -
 arch/x86/include/asm/posix_types.h        |    1 -
 commands/Kconfig                          |    7 +++
 commands/bootm.c                          |    7 +--
 common/startup.c                          |    9 ++--
 drivers/Kconfig                           |    1 +
 drivers/Makefile                          |    1 +
 drivers/clk/Kconfig                       |    4 ++
 drivers/clk/Makefile                      |    2 +
 {arch/arm/common => drivers/clk}/clkdev.c |   57 +++++++++++++++++++---
 drivers/nor/cfi_flash.c                   |    4 +-
 include/common.h                          |    1 -
 include/driver.h                          |   12 +++--
 include/linux/clkdev.h                    |   36 ++++++++++++++
 include/linux/kernel.h                    |   20 ++++++++
 include/linux/types.h                     |    2 +
 lib/Makefile                              |    1 -
 lib/display_options.c                     |   60 -----------------------
 lib/driver.c                              |   16 +++----
 lib/vsprintf.c                            |   73 +++++++++++++++++++++++++++++
 34 files changed, 230 insertions(+), 139 deletions(-)
 delete mode 100644 arch/arm/common/Kconfig
 delete mode 100644 arch/arm/common/Makefile
 create mode 100644 drivers/clk/Kconfig
 create mode 100644 drivers/clk/Makefile
 rename {arch/arm/common => drivers/clk}/clkdev.c (75%)
 create mode 100644 include/linux/clkdev.h
 delete mode 100644 lib/display_options.c

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/9] types.h: move __kernel_dev_t to include/linux/types.h
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 2/9] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

no need to have a arch specific type

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/include/asm/posix_types.h      |    1 -
 arch/blackfin/include/asm/posix_types.h |    1 -
 arch/m68k/include/asm/posix_types.h     |    1 -
 arch/ppc/include/asm/posix_types.h      |    1 -
 arch/sandbox/include/asm/posix_types.h  |    1 -
 arch/x86/include/asm/posix_types.h      |    1 -
 include/linux/types.h                   |    2 ++
 7 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/posix_types.h b/arch/arm/include/asm/posix_types.h
index c412486..aee050e 100644
--- a/arch/arm/include/asm/posix_types.h
+++ b/arch/arm/include/asm/posix_types.h
@@ -19,7 +19,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short		__kernel_dev_t;
 typedef unsigned long		__kernel_ino_t;
 typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_nlink_t;
diff --git a/arch/blackfin/include/asm/posix_types.h b/arch/blackfin/include/asm/posix_types.h
index 98397ca..bbf6e9c 100644
--- a/arch/blackfin/include/asm/posix_types.h
+++ b/arch/blackfin/include/asm/posix_types.h
@@ -34,7 +34,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short __kernel_dev_t;
 typedef unsigned long __kernel_ino_t;
 typedef unsigned short __kernel_mode_t;
 typedef unsigned short __kernel_nlink_t;
diff --git a/arch/m68k/include/asm/posix_types.h b/arch/m68k/include/asm/posix_types.h
index c40c41d..d83afe9 100644
--- a/arch/m68k/include/asm/posix_types.h
+++ b/arch/m68k/include/asm/posix_types.h
@@ -27,7 +27,6 @@
 #define __ARCH_M68K_POSIX_TYPES_H
 
 
-typedef unsigned short		__kernel_dev_t;
 typedef unsigned long		__kernel_ino_t;
 typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_nlink_t;
diff --git a/arch/ppc/include/asm/posix_types.h b/arch/ppc/include/asm/posix_types.h
index 9170728..a7af406 100644
--- a/arch/ppc/include/asm/posix_types.h
+++ b/arch/ppc/include/asm/posix_types.h
@@ -7,7 +7,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned int	__kernel_dev_t;
 typedef unsigned int	__kernel_ino_t;
 typedef unsigned int	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h
index 5dcc842..4345141 100644
--- a/arch/sandbox/include/asm/posix_types.h
+++ b/arch/sandbox/include/asm/posix_types.h
@@ -7,7 +7,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short	__kernel_dev_t;
 typedef unsigned long	__kernel_ino_t;
 typedef unsigned short	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
diff --git a/arch/x86/include/asm/posix_types.h b/arch/x86/include/asm/posix_types.h
index a22f301..9278681 100644
--- a/arch/x86/include/asm/posix_types.h
+++ b/arch/x86/include/asm/posix_types.h
@@ -27,7 +27,6 @@
 #define _ASM_X86_POSIX_TYPES_H
 
 typedef unsigned long	__kernel_ino_t;
-typedef unsigned short	__kernel_dev_t;
 typedef unsigned short	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
 typedef long		__kernel_off_t;
diff --git a/include/linux/types.h b/include/linux/types.h
index 96e5708..2145b6d 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -6,6 +6,8 @@
 
 #ifndef __KERNEL_STRICT_NAMES
 
+typedef __u32 __kernel_dev_t;
+
 typedef __kernel_fd_set		fd_set;
 typedef __kernel_dev_t		dev_t;
 typedef __kernel_ino_t		ino_t;
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 2/9] device: fix dev_name
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 1/9] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 3/9] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

dev_name is supposed to return the name of the device plus the id

currently we use %s%d format where in the kernel the use %s.%d
we may think to switch to this format for the device name and keeping the %s%d
for the devfs

this will be usefull to not modify the clock device name as example

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/driver.h |   12 +++++++-----
 lib/driver.c     |   16 +++++++---------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index ee0749d..ab1f850 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -25,7 +25,8 @@
 
 #include <linux/list.h>
 
-#define MAX_DRIVER_NAME 32
+#define MAX_DRIVER_NAME		32
+#define FORMAT_DRIVER_MANE_ID	"%s%d"
 
 #include <param.h>
 
@@ -176,9 +177,11 @@ int get_free_deviceid(const char *name_template);
 
 char *deviceid_from_spec_str(const char *str, char **endp);
 
+extern const char *dev_id(const struct device_d *dev);
+
 static inline const char *dev_name(const struct device_d *dev)
 {
-	return dev->name;
+	return dev_id(dev);
 }
 
 /* linear list over all available devices
@@ -239,11 +242,10 @@ static inline int dev_close_default(struct device_d *dev, struct filep *f)
 }
 
 /* debugging and troubleshooting/diagnostic helpers. */
-extern const char *dev_id(const struct device_d *dev);
 
 #define dev_printf(dev, format, arg...)	\
-	printf("%s@%s: " format , dev_name(dev) , \
-	       dev_id(dev) , ## arg)
+	printf("%s@%s: " format , dev->name , \
+	       dev_name(dev) , ## arg)
 
 #define dev_emerg(dev, format, arg...)		\
 	dev_printf((dev) , format , ## arg)
diff --git a/lib/driver.c b/lib/driver.c
index b600745..03a2817 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -45,11 +45,9 @@ static LIST_HEAD(active);
 struct device_d *get_device_by_name(const char *name)
 {
 	struct device_d *dev;
-	char devname[MAX_DRIVER_NAME + 3];
 
 	for_each_device(dev) {
-		sprintf(devname, "%s%d", dev->name, dev->id);
-		if(!strcmp(name, devname))
+		if(!strcmp(dev_name(dev), name))
 			return dev;
 	}
 
@@ -62,7 +60,7 @@ int get_free_deviceid(const char *name_template)
 	char name[MAX_DRIVER_NAME + 3];
 
 	while (1) {
-		sprintf(name, "%s%d", name_template, i);
+		sprintf(name, FORMAT_DRIVER_MANE_ID, name_template, i);
 		if (!get_device_by_name(name))
 			return i;
 		i++;
@@ -97,7 +95,7 @@ int register_device(struct device_d *new_device)
 
 	new_device->id = get_free_deviceid(new_device->name);
 
-	debug ("register_device: %s\n",new_device->name);
+	debug ("register_device: %s\n", dev_name(new_device));
 
 	if (!new_device->bus) {
 //		dev_err(new_device, "no bus type associated. Needs fixup\n");
@@ -120,7 +118,7 @@ EXPORT_SYMBOL(register_device);
 
 int unregister_device(struct device_d *old_dev)
 {
-	debug("unregister_device: %s:%s\n",old_dev->name, old_dev->id);
+	debug("unregister_device: %s\n", dev_name(old_dev->name));
 
 	if (!list_empty(&old_dev->children)) {
 		errno = -EBUSY;
@@ -164,7 +162,7 @@ struct driver_d *get_driver_by_name(const char *name)
 
 static void noinfo(struct device_d *dev)
 {
-	printf("no info available for %s\n", dev->name);
+	printf("no info available for %s\n", dev_name(dev));
 }
 
 static void noshortinfo(struct device_d *dev)
@@ -237,7 +235,7 @@ static int do_devinfo_subtree(struct device_d *dev, int depth, char edge)
 	for (i = 0; i < depth; i++)
 		printf("|    ");
 
-	printf("%c----%s%d", edge, dev->name, dev->id);
+	printf("%c----%s", edge, dev_name(dev));
 	if (!list_empty(&dev->cdevs)) {
 		printf(" (");
 		list_for_each_entry(cdev, &dev->cdevs, devices_list) {
@@ -264,7 +262,7 @@ const char *dev_id(const struct device_d *dev)
 {
 	static char buf[sizeof(unsigned long) * 2];
 
-	sprintf(buf, "%s%d", dev->name, dev->id);
+	sprintf(buf, FORMAT_DRIVER_MANE_ID, dev->name, dev->id);
 
 	return buf;
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 3/9] stm8815: fix the uart device clock match
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 1/9] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 2/9] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 4/9] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

that use the device name + id to found it's clock
to use the right match as we fix the dev_name macro

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-nomadik/8815.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-nomadik/8815.c b/arch/arm/mach-nomadik/8815.c
index 8598f14..faeded4 100644
--- a/arch/arm/mach-nomadik/8815.c
+++ b/arch/arm/mach-nomadik/8815.c
@@ -50,12 +50,14 @@ void st8815_add_device_sdram(u32 size)
 }
 
 static struct device_d uart0_serial_device = {
+	.id = 0,
 	.name = "uart-pl011",
 	.map_base = NOMADIK_UART0_BASE,
 	.size = 4096,
 };
 
 static struct device_d uart1_serial_device = {
+	.id = 1,
 	.name = "uart-pl011",
 	.map_base = NOMADIK_UART1_BASE,
 	.size = 4096,
@@ -65,12 +67,12 @@ void st8815_register_uart(unsigned id)
 {
 	switch (id) {
 	case 0:
-		nmdk_clk_create(&st8815_clk_48, uart0_serial_device.name);
 		register_device(&uart0_serial_device);
+		nmdk_clk_create(&st8815_clk_48, dev_name(&uart0_serial_device));
 		break;
 	case 1:
-		nmdk_clk_create(&st8815_clk_48, uart1_serial_device.name);
 		register_device(&uart1_serial_device);
+		nmdk_clk_create(&st8815_clk_48, dev_name(&uart0_serial_device));
 		break;
 	}
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 4/9] arm: move clkdev to drivers/clk
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 3/9] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 5/9] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

as refer in this patch "arm & sh: factorised duplicated clkdev.c"

factorise some generic infrastructure to assist looking up struct clks
for the ARM & SH architecture.

as the code is identical at 99% in linux

move it also as preparing for the SH adding

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/Kconfig                   |    1 -
 arch/arm/Makefile                  |    2 +-
 arch/arm/common/Kconfig            |    2 -
 arch/arm/common/Makefile           |    5 -
 arch/arm/common/clkdev.c           |  160 ----------------------------------
 arch/arm/configs/nhk8815_defconfig |    2 +-
 arch/arm/include/asm/clkdev.h      |   15 +---
 arch/arm/mach-nomadik/Kconfig      |    2 +-
 arch/arm/mach-nomadik/clock.c      |    7 +--
 drivers/Kconfig                    |    1 +
 drivers/Makefile                   |    1 +
 drivers/clk/Kconfig                |    4 +
 drivers/clk/Makefile               |    2 +
 drivers/clk/clkdev.c               |  168 ++++++++++++++++++++++++++++++++++++
 include/linux/clkdev.h             |   36 ++++++++
 15 files changed, 217 insertions(+), 191 deletions(-)
 delete mode 100644 arch/arm/common/Kconfig
 delete mode 100644 arch/arm/common/Makefile
 delete mode 100644 arch/arm/common/clkdev.c
 create mode 100644 drivers/clk/Kconfig
 create mode 100644 drivers/clk/Makefile
 create mode 100644 drivers/clk/clkdev.c
 create mode 100644 include/linux/clkdev.h

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 945528c..fa37036 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -58,7 +58,6 @@ config ARCH_S3C24xx
 
 endchoice
 
-source arch/arm/common/Kconfig
 source arch/arm/cpu/Kconfig
 source arch/arm/mach-at91/Kconfig
 source arch/arm/mach-ep93xx/Kconfig
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index e542c03..388dcc9 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -131,7 +131,7 @@ MACH :=
 endif
 
 common-y += $(BOARD) $(MACH)
-common-y += arch/arm/lib/ arch/arm/cpu/ arch/arm/common/
+common-y += arch/arm/lib/ arch/arm/cpu/
 
 lds-$(CONFIG_GENERIC_LINKER_SCRIPT)	:= arch/arm/lib/barebox.lds
 lds-$(CONFIG_BOARD_LINKER_SCRIPT)	:= $(BOARD)/barebox.lds
diff --git a/arch/arm/common/Kconfig b/arch/arm/common/Kconfig
deleted file mode 100644
index e749e45..0000000
--- a/arch/arm/common/Kconfig
+++ /dev/null
@@ -1,2 +0,0 @@
-config COMMON_CLKDEV
-	bool
diff --git a/arch/arm/common/Makefile b/arch/arm/common/Makefile
deleted file mode 100644
index 9cc8834..0000000
--- a/arch/arm/common/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-obj-$(CONFIG_COMMON_CLKDEV)	+= clkdev.o
diff --git a/arch/arm/common/clkdev.c b/arch/arm/common/clkdev.c
deleted file mode 100644
index 4d25356..0000000
--- a/arch/arm/common/clkdev.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- *  arch/arm/common/clkdev.c
- *
- *  Copyright (C) 2008 Russell King.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Helper for the clk API to assist looking up a struct clk.
- */
-
-#include <common.h>
-#include <linux/list.h>
-#include <errno.h>
-#include <linux/err.h>
-#include <linux/clk.h>
-#include <init.h>
-#include <malloc.h>
-#include <stdio.h>
-
-#include <asm/clkdev.h>
-#include <mach/clkdev.h>
-
-static LIST_HEAD(clocks);
-
-/*
- * Find the correct struct clk for the device and connection ID.
- * We do slightly fuzzy matching here:
- *  An entry with a NULL ID is assumed to be a wildcard.
- *  If an entry has a device ID, it must match
- *  If an entry has a connection ID, it must match
- * Then we take the most specific entry - with the following
- * order of precidence: dev+con > dev only > con only.
- */
-static struct clk *clk_find(const char *dev_id, const char *con_id)
-{
-	struct clk_lookup *p;
-	struct clk *clk = NULL;
-	int match, best = 0;
-
-	list_for_each_entry(p, &clocks, node) {
-		match = 0;
-		if (p->dev_id) {
-			if (!dev_id || strcmp(p->dev_id, dev_id))
-				continue;
-			match += 2;
-		}
-		if (p->con_id) {
-			if (!con_id || strcmp(p->con_id, con_id))
-				continue;
-			match += 1;
-		}
-		if (match == 0)
-			continue;
-
-		if (match > best) {
-			clk = p->clk;
-			best = match;
-		}
-	}
-	return clk;
-}
-
-struct clk *clk_get_sys(const char *dev_id, const char *con_id)
-{
-	struct clk *clk;
-
-	clk = clk_find(dev_id, con_id);
-	if (clk && !__clk_get(clk))
-		clk = NULL;
-
-	return clk ? clk : ERR_PTR(-ENOENT);
-}
-EXPORT_SYMBOL(clk_get_sys);
-
-struct clk *clk_get(struct device_d *dev, const char *con_id)
-{
-	const char *dev_id = dev ? dev_name(dev) : NULL;
-
-	return clk_get_sys(dev_id, con_id);
-}
-EXPORT_SYMBOL(clk_get);
-
-void clk_put(struct clk *clk)
-{
-	__clk_put(clk);
-}
-EXPORT_SYMBOL(clk_put);
-
-void clkdev_add(struct clk_lookup *cl)
-{
-	list_add_tail(&cl->node, &clocks);
-}
-EXPORT_SYMBOL(clkdev_add);
-
-#define MAX_DEV_ID	20
-#define MAX_CON_ID	16
-
-struct clk_lookup_alloc {
-	struct clk_lookup cl;
-	char	dev_id[MAX_DEV_ID];
-	char	con_id[MAX_CON_ID];
-};
-
-struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
-	const char *dev_fmt, ...)
-{
-	struct clk_lookup_alloc *cla;
-
-	cla = kzalloc(sizeof(*cla), GFP_KERNEL);
-	if (!cla)
-		return NULL;
-
-	cla->cl.clk = clk;
-	if (con_id) {
-		strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
-		cla->cl.con_id = cla->con_id;
-	}
-
-	if (dev_fmt) {
-		va_list ap;
-
-		va_start(ap, dev_fmt);
-		vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
-		cla->cl.dev_id = cla->dev_id;
-		va_end(ap);
-	}
-
-	return &cla->cl;
-}
-EXPORT_SYMBOL(clkdev_alloc);
-
-int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
-	struct device_d *dev)
-{
-	struct clk *r = clk_get(dev, id);
-	struct clk_lookup *l;
-
-	if (IS_ERR(r))
-		return PTR_ERR(r);
-
-	l = clkdev_alloc(r, alias, alias_dev_name);
-	clk_put(r);
-	if (!l)
-		return -ENODEV;
-	clkdev_add(l);
-	return 0;
-}
-EXPORT_SYMBOL(clk_add_alias);
-
-/*
- * clkdev_drop - remove a clock dynamically allocated
- */
-void clkdev_drop(struct clk_lookup *cl)
-{
-	list_del(&cl->node);
-	kfree(cl);
-}
-EXPORT_SYMBOL(clkdev_drop);
diff --git a/arch/arm/configs/nhk8815_defconfig b/arch/arm/configs/nhk8815_defconfig
index 21d596f..6e28ef2 100644
--- a/arch/arm/configs/nhk8815_defconfig
+++ b/arch/arm/configs/nhk8815_defconfig
@@ -19,7 +19,7 @@ CONFIG_ARM_AMBA=y
 CONFIG_ARCH_NOMADIK=y
 # CONFIG_ARCH_OMAP is not set
 # CONFIG_ARCH_S3C24xx is not set
-CONFIG_COMMON_CLKDEV=y
+CONFIG_CLKDEV_LOOKUP=y
 
 #
 # Processor Type
diff --git a/arch/arm/include/asm/clkdev.h b/arch/arm/include/asm/clkdev.h
index b6ec7c6..ad33945 100644
--- a/arch/arm/include/asm/clkdev.h
+++ b/arch/arm/include/asm/clkdev.h
@@ -12,19 +12,6 @@
 #ifndef __ASM_CLKDEV_H
 #define __ASM_CLKDEV_H
 
-struct clk;
-
-struct clk_lookup {
-	struct list_head	node;
-	const char		*dev_id;
-	const char		*con_id;
-	struct clk		*clk;
-};
-
-struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
-	const char *dev_fmt, ...);
-
-void clkdev_add(struct clk_lookup *cl);
-void clkdev_drop(struct clk_lookup *cl);
+#include <mach/clkdev.h>
 
 #endif
diff --git a/arch/arm/mach-nomadik/Kconfig b/arch/arm/mach-nomadik/Kconfig
index 64894c8..3d6eab6 100644
--- a/arch/arm/mach-nomadik/Kconfig
+++ b/arch/arm/mach-nomadik/Kconfig
@@ -13,7 +13,7 @@ choice
 config MACH_NOMADIK_8815NHK
 	bool "ST 8815 Nomadik Hardware Kit (evaluation board)"
 	select NOMADIK_8815
-	select COMMON_CLKDEV
+	select CLKDEV_LOOKUP
 
 endchoice
 
diff --git a/arch/arm/mach-nomadik/clock.c b/arch/arm/mach-nomadik/clock.c
index c74e0c1..5f34a2c 100644
--- a/arch/arm/mach-nomadik/clock.c
+++ b/arch/arm/mach-nomadik/clock.c
@@ -8,7 +8,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <init.h>
-#include <asm/clkdev.h>
+#include <linux/clkdev.h>
 
 #include "clock.h"
 
@@ -34,11 +34,6 @@ void clk_disable(struct clk *clk)
 }
 EXPORT_SYMBOL(clk_disable);
 
-int __clk_get(struct clk *clk)
-{
-	return 1;
-}
-
 /* Create a clock structure with the given name */
 int nmdk_clk_create(struct clk *clk, const char *dev_id)
 {
diff --git a/drivers/Kconfig b/drivers/Kconfig
index ae9efce..f7154c6 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -9,5 +9,6 @@ source "drivers/mtd/Kconfig"
 source "drivers/ata/Kconfig"
 source "drivers/usb/Kconfig"
 source "drivers/video/Kconfig"
+source "drivers/clk/Kconfig"
 
 endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index bce68bc..706e1c8 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_ATA) += ata/
 obj-$(CONFIG_SPI) += spi/
 obj-$(CONFIG_I2C) += i2c/
 obj-$(CONFIG_VIDEO) += video/
+obj-y	+= clk/
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
new file mode 100644
index 0000000..4168c88
--- /dev/null
+++ b/drivers/clk/Kconfig
@@ -0,0 +1,4 @@
+
+config CLKDEV_LOOKUP
+	bool
+	select HAVE_CLK
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
new file mode 100644
index 0000000..07613fa
--- /dev/null
+++ b/drivers/clk/Makefile
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
new file mode 100644
index 0000000..717fea5
--- /dev/null
+++ b/drivers/clk/clkdev.c
@@ -0,0 +1,168 @@
+/*
+ * drivers/clk/lookup_clkdev.c
+ *
+ *  Copyright (C) 2008 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Helper for the clk API to assist looking up a struct clk.
+ */
+
+#include <common.h>
+#include <linux/list.h>
+#include <errno.h>
+#include <linux/err.h>
+#include <linux/string.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <init.h>
+#include <malloc.h>
+#include <stdio.h>
+
+static LIST_HEAD(clocks);
+
+/*
+ * Find the correct struct clk for the device and connection ID.
+ * We do slightly fuzzy matching here:
+ *  An entry with a NULL ID is assumed to be a wildcard.
+ *  If an entry has a device ID, it must match
+ *  If an entry has a connection ID, it must match
+ * Then we take the most specific entry - with the following
+ * order of precedence: dev+con > dev only > con only.
+ */
+static struct clk *clk_find(const char *dev_id, const char *con_id)
+{
+	struct clk_lookup *p;
+	struct clk *clk = NULL;
+	int match, best = 0;
+
+	list_for_each_entry(p, &clocks, node) {
+		match = 0;
+		if (p->dev_id) {
+			if (!dev_id || strcmp(p->dev_id, dev_id))
+				continue;
+			match += 2;
+		}
+		if (p->con_id) {
+			if (!con_id || strcmp(p->con_id, con_id))
+				continue;
+			match += 1;
+		}
+
+		if (match > best) {
+			clk = p->clk;
+			if (match != 3)
+				best = match;
+			else
+				break;
+		}
+	}
+	return clk;
+}
+
+struct clk *clk_get_sys(const char *dev_id, const char *con_id)
+{
+	struct clk *clk;
+
+	clk = clk_find(dev_id, con_id);
+	if (clk && !__clk_get(clk))
+		clk = NULL;
+
+	return clk ? clk : ERR_PTR(-ENOENT);
+}
+EXPORT_SYMBOL(clk_get_sys);
+
+struct clk *clk_get(struct device_d *dev, const char *con_id)
+{
+	const char *dev_id = dev ? dev_name(dev) : NULL;
+
+	return clk_get_sys(dev_id, con_id);
+}
+EXPORT_SYMBOL(clk_get);
+
+void clk_put(struct clk *clk)
+{
+	__clk_put(clk);
+}
+EXPORT_SYMBOL(clk_put);
+
+void clkdev_add(struct clk_lookup *cl)
+{
+	list_add_tail(&cl->node, &clocks);
+}
+EXPORT_SYMBOL(clkdev_add);
+
+void __init clkdev_add_table(struct clk_lookup *cl, size_t num)
+{
+	while (num--) {
+		list_add_tail(&cl->node, &clocks);
+		cl++;
+	}
+}
+
+#define MAX_DEV_ID	20
+#define MAX_CON_ID	16
+
+struct clk_lookup_alloc {
+	struct clk_lookup cl;
+	char	dev_id[MAX_DEV_ID];
+	char	con_id[MAX_CON_ID];
+};
+
+struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
+	const char *dev_fmt, ...)
+{
+	struct clk_lookup_alloc *cla;
+
+	cla = kzalloc(sizeof(*cla), GFP_KERNEL);
+	if (!cla)
+		return NULL;
+
+	cla->cl.clk = clk;
+	if (con_id) {
+		strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
+		cla->cl.con_id = cla->con_id;
+	}
+
+	if (dev_fmt) {
+		va_list ap;
+
+		va_start(ap, dev_fmt);
+		vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
+		cla->cl.dev_id = cla->dev_id;
+		va_end(ap);
+	}
+
+	return &cla->cl;
+}
+EXPORT_SYMBOL(clkdev_alloc);
+
+int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
+	struct device_d *dev)
+{
+	struct clk *r = clk_get(dev, id);
+	struct clk_lookup *l;
+
+	if (IS_ERR(r))
+		return PTR_ERR(r);
+
+	l = clkdev_alloc(r, alias, alias_dev_name);
+	clk_put(r);
+	if (!l)
+		return -ENODEV;
+	clkdev_add(l);
+	return 0;
+}
+EXPORT_SYMBOL(clk_add_alias);
+
+/*
+ * clkdev_drop - remove a clock dynamically allocated
+ */
+void clkdev_drop(struct clk_lookup *cl)
+{
+	list_del(&cl->node);
+	kfree(cl);
+}
+EXPORT_SYMBOL(clkdev_drop);
diff --git a/include/linux/clkdev.h b/include/linux/clkdev.h
new file mode 100644
index 0000000..ae38e1a
--- /dev/null
+++ b/include/linux/clkdev.h
@@ -0,0 +1,36 @@
+/*
+ *  include/linux/clkdev.h
+ *
+ *  Copyright (C) 2008 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Helper for the clk API to assist looking up a struct clk.
+ */
+#ifndef __CLKDEV_H
+#define __CLKDEV_H
+
+#include <asm/clkdev.h>
+
+struct clk;
+struct device_d;
+
+struct clk_lookup {
+	struct list_head	node;
+	const char		*dev_id;
+	const char		*con_id;
+	struct clk		*clk;
+};
+
+struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
+	const char *dev_fmt, ...);
+
+void clkdev_add(struct clk_lookup *cl);
+void clkdev_drop(struct clk_lookup *cl);
+
+void clkdev_add_table(struct clk_lookup *, size_t);
+int clk_add_alias(const char *, const char *, char *, struct device_d *);
+
+#endif
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 5/9] vsprintf: add %w and %w support to print unit
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 4/9] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 15:29   ` Uwe Kleine-König
  2010-09-02 14:10 ` [PATCH 6/9] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Show a '%w' or %W thing.
This will show a frequency or byte at format xxx[.xxx] [ kMG]
the precision can not excess the base kMG of the current unit
otherwise it will be automatically reduce
if no precision is specified and there is rest we will use a default
precision of 3 as 66.667 M
base will be typically 1000 for Hz or B and 1024 for iB

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/linux/kernel.h |   20 +++++++++++++
 lib/vsprintf.c         |   73 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e9e2f07..b605946 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -5,6 +5,26 @@
 #include <linux/barebox-wrapper.h>
 
 /*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define DIV_ROUND_CLOSEST(x, divisor)(			\
+{							\
+	typeof(divisor) __divisor = divisor;		\
+	(((x) + ((__divisor) / 2)) / (__divisor));	\
+}							\
+)
+
+/*
  * min()/max()/clamp() macros that also do
  * strict type-checking.. See the
  * "unnecessary" pointer comparison.
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6066845..add8bd5 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -254,6 +254,71 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int
 }
 
 /*
+ * Show a '%w' or %W thing.  This will show a frequency or byte
+ * at format xxx[.xxx] [ kMG]
+ * the precision can not excess the base kMG of the current unit
+ * otherwise it will be automatically reduce
+ * if no precision is specified and there is rest we will use a default
+ * precision of 3 as 66.667 M
+ * base will be typically 1000 for Hz or B and 1024 for iB
+ */
+static char *unit_string(char *buf, char *end, long val, int base, int field_width, int precision, int flags)
+{
+	long rest = 0;
+	long integer;
+	long pr = 3;
+	long pr_mul = 1;
+	long unit = 1;
+	char format[] = " kMG";
+	int pow, i;
+
+	for (pow = 0; pow < strlen(format) - 1; pow++) {
+		if (val < unit * base)
+			break;
+		unit *= base;
+	}
+
+	integer = val / unit;
+
+	if (precision != -1) {
+		if (precision > pow * 3)
+			precision = pow * 3;
+		pr = precision;
+	}
+
+	for (i = 0; i < pr; i++) {
+		pr_mul *= 10;
+	}
+
+	if (val % unit) {
+		rest = DIV_ROUND_CLOSEST(pr_mul * (val - (integer * unit)), unit);
+
+		if (rest >= pr_mul) {
+			rest -= pr_mul;
+			integer++;
+		}
+	}
+
+	buf = number(buf, end, integer, 10, field_width, -1, 0);
+
+	if (rest != 0 || precision != -1) {
+		if (buf < end)
+			*buf = '.';
+		buf++;
+		buf = number(buf, end, rest, 10, -1, pr, 0);
+	}
+
+	if (buf < end)
+		*buf = ' ';
+	buf++;
+	if (buf < end && pow != 0)
+		*buf = format[pow];
+	buf++;
+
+	return buf;
+}
+
+/*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
  * specifiers.
@@ -421,6 +486,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 				str = string(str, end, va_arg(args, char *), field_width, precision, flags);
 				continue;
 
+			case 'W':
+				str = unit_string(str, end, va_arg(args, long), 1024, field_width, precision, flags);
+				continue;
+
+			case 'w':
+				str = unit_string(str, end, va_arg(args, long), 1000, field_width, precision, flags);
+				continue;
+
 			case 'p':
 				str = pointer(fmt+1, str, end,
 						va_arg(args, void *),
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 6/9] at91/clock: switch to %w for clock info printing
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 5/9] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 7/9] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-at91/clock.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index 6fd09d5..8d5547b 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -677,12 +677,10 @@ int at91_clock_init(unsigned long main_clock)
 static int at91_clock_display(void)
 {
 	if (pll_overclock)
-		pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
+		pr_info("Clocks: PLLA overclocked, %wHz\n", plla.rate_hz);
 
-	printf("Clocks: CPU %u MHz, master %u MHz, main %u.%03u MHz\n",
-		mck.parent->rate_hz / 1000000, (unsigned) mck.rate_hz / 1000000,
-		(unsigned) main_clk.rate_hz / 1000000,
-		((unsigned) main_clk.rate_hz % 1000000) / 1000);
+	printf("Clocks: CPU %wHz, master %wHz, main %wHz\n",
+		mck.parent->rate_hz, mck.rate_hz, main_clk.rate_hz);
 
 	return 0;
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 7/9] cfi_flash: use %W and IEEE 1541 format
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 6/9] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 8/9] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/nor/cfi_flash.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index fa5e5ee..cbca368 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -713,7 +713,7 @@ static void cfi_info (struct device_d* dev)
 
 	printf ("CFI conformant FLASH (%d x %d)",
 		(info->portwidth << 3), (info->chipwidth << 3));
-	printf ("  Size: %ld MB in %d Sectors\n",
+	printf ("  Size: %WiB in %d Sectors\n",
 		info->size >> 20, info->sector_count);
 	printf ("  ");
 	switch (info->vendor) {
@@ -1036,7 +1036,7 @@ static int cfi_probe (struct device_d *dev)
 	}
 
 	if (info->flash_id == FLASH_UNKNOWN) {
-		printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n",
+		printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %WiB\n",
 			dev->map_base, info->size, info->size << 20);
 		return -ENODEV;
 	}
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 8/9] use %W instead of size_human_readable and use IEEE 1541 format
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 7/9] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 14:10 ` [PATCH 9/9] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/bootm.c      |    7 ++---
 common/startup.c      |    9 +++----
 include/common.h      |    1 -
 lib/Makefile          |    1 -
 lib/display_options.c |   60 -------------------------------------------------
 5 files changed, 7 insertions(+), 71 deletions(-)
 delete mode 100644 lib/display_options.c

diff --git a/commands/bootm.c b/commands/bootm.c
index 11325dc..ea6b5d7 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -552,11 +552,11 @@ print_image_hdr (image_header_t *hdr)
 	printf ("   Image Type:   %s %s %s (%s)\n", image_arch(hdr), image_os(hdr),
 			image_type(hdr), image_compression(hdr));
 #endif
-	printf ("   Data Size:    %d Bytes = %s\n"
+	printf ("   Data Size:    %d Bytes = %WiB\n"
 		"   Load Address: %08x\n"
 		"   Entry Point:  %08x\n",
 			ntohl(hdr->ih_size),
-			size_human_readable(ntohl(hdr->ih_size)),
+			ntohl(hdr->ih_size),
 			ntohl(hdr->ih_load),
 			ntohl(hdr->ih_ep));
 
@@ -567,8 +567,7 @@ print_image_hdr (image_header_t *hdr)
 
 		puts ("   Contents:\n");
 		for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
-			printf ("   Image %d: %8ld Bytes = %s", i, len,
-				size_human_readable (len));
+			printf ("   Image %d: %8ld Bytes = %WiB", i, len, len);
 		}
 	}
 }
diff --git a/common/startup.c b/common/startup.c
index 2ed16fe..ff9da3a 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -52,12 +52,11 @@ static void display_meminfo(void)
 
 	debug("barebox code : 0x%08lX -> 0x%08lX  BSS: -> 0x%08lX\n",
 	       _barebox_start, _bss_start, _bss_end);
-	printf("Malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
-		mstart, mend, size_human_readable(msize));
+	printf("Malloc space: 0x%08lx -> 0x%08lx (size %WiB)\n",
+		mstart, mend, msize);
 #ifdef CONFIG_ARM
-	printf("Stack space : 0x%08lx -> 0x%08lx (size %s)\n",
-		STACK_BASE, STACK_BASE + STACK_SIZE,
-		size_human_readable(STACK_SIZE));
+	printf("Stack space : 0x%08lx -> 0x%08lx (size %WiB)\n",
+		STACK_BASE, STACK_BASE + STACK_SIZE, STACK_SIZE);
 #endif
 }
 
diff --git a/include/common.h b/include/common.h
index 64f49db..fda04d4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -95,7 +95,6 @@ void __noreturn panic(const char *fmt, ...);
 
 /* */
 long int initdram (int);
-char *size_human_readable(ulong size);
 
 /* common/main.c */
 int	run_command	(const char *cmd, int flag);
diff --git a/lib/Makefile b/lib/Makefile
index 8c5df08..e5a82fc 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,5 @@
 obj-y			+= ctype.o
 obj-y			+= rbtree.o
-obj-y			+= display_options.o
 obj-y			+= ldiv.o
 obj-y			+= string.o
 obj-y			+= vsprintf.o
diff --git a/lib/display_options.c b/lib/display_options.c
deleted file mode 100644
index 03f4f22..0000000
--- a/lib/display_options.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-
-/*
- * return a pointer to a string containing the size
- * as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
- */
-char *size_human_readable(ulong size)
-{
-	static char buf[20];
-	ulong m, n;
-	ulong d = 1 << 20;		/* 1 MB */
-	char  c = 'M';
-	char *ptr = buf;
-
-	if (size < d) {			/* print in kB */
-		c = 'k';
-		d = 1 << 10;
-	}
-
-	n = size / d;
-
-	m = (10 * (size - (n * d)) + (d / 2) ) / d;
-
-	if (m >= 10) {
-		m -= 10;
-		n += 1;
-	}
-
-	ptr += sprintf(buf, "%2ld", n);
-	if (m) {
-		ptr += sprintf (ptr,".%ld", m);
-	}
-	sprintf(ptr, " %cB", c);
-
-	return buf;
-}
-EXPORT_SYMBOL(size_human_readable);
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 9/9] clkdev: add print clk info command
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 8/9] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 14:10 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 15:22   ` Uwe Kleine-König
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  9 siblings, 1 reply; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 14:10 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/Kconfig     |    7 +++++++
 drivers/clk/clkdev.c |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 57c9b75..f20c2e1 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -338,4 +338,11 @@ config CMD_I2C
 	  include i2c_probe, i2c_read and i2c_write commands to communicate
 	  on i2c bus.
 
+config CMD_CLOCK_INFO
+	bool
+	depends on LOOKUP_CLKDEV
+	prompt "clock info command"
+	help
+	  shop list of registered clock
+
 endmenu
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 717fea5..d78d3e0 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <linux/list.h>
 #include <errno.h>
 #include <linux/err.h>
@@ -166,3 +167,35 @@ void clkdev_drop(struct clk_lookup *cl)
 	kfree(cl);
 }
 EXPORT_SYMBOL(clkdev_drop);
+
+#ifdef CONFIG_CMD_CLOCK_INFO
+static int do_clock_info(struct command *cmdtp, int argc, char *argv[])
+{
+	struct clk_lookup *p;
+
+	puts("Clocks\n");
+
+	list_for_each_entry(p, &clocks, node)
+		if (!p->dev_id)
+			printf("%s: %wHz\n", p->con_id, clk_get_rate(p->clk));
+
+	puts("Clocks for dev\n");
+
+	list_for_each_entry(p, &clocks, node)
+		if (p->dev_id)
+			printf("%s[%s]: %wHz\n", p->con_id, p->dev_id,
+					       clk_get_rate(p->clk));
+
+	return 0;
+}
+
+static const __maybe_unused char cmd_clock_info_help[] =
+"Print clocks info\n"
+;
+
+BAREBOX_CMD_START(clock_info)
+	.cmd		= do_clock_info,
+	.usage		= "Clocks Info",
+	BAREBOX_CMD_HELP(cmd_clock_info_help)
+BAREBOX_CMD_END
+#endif
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 9/9] clkdev: add print clk info command
  2010-09-02 14:10 ` [PATCH 9/9] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 15:22   ` Uwe Kleine-König
  0 siblings, 0 replies; 26+ messages in thread
From: Uwe Kleine-König @ 2010-09-02 15:22 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Thu, Sep 02, 2010 at 04:10:24PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  commands/Kconfig     |    7 +++++++
>  drivers/clk/clkdev.c |   33 +++++++++++++++++++++++++++++++++
>  2 files changed, 40 insertions(+), 0 deletions(-)
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 57c9b75..f20c2e1 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -338,4 +338,11 @@ config CMD_I2C
>  	  include i2c_probe, i2c_read and i2c_write commands to communicate
>  	  on i2c bus.
>  
> +config CMD_CLOCK_INFO
> +	bool
> +	depends on LOOKUP_CLKDEV
> +	prompt "clock info command"
> +	help
> +	  shop list of registered clock
> +
>  endmenu
> diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
> index 717fea5..d78d3e0 100644
> --- a/drivers/clk/clkdev.c
> +++ b/drivers/clk/clkdev.c
> @@ -11,6 +11,7 @@
>   */
>  
>  #include <common.h>
> +#include <command.h>
>  #include <linux/list.h>
>  #include <errno.h>
>  #include <linux/err.h>
> @@ -166,3 +167,35 @@ void clkdev_drop(struct clk_lookup *cl)
>  	kfree(cl);
>  }
>  EXPORT_SYMBOL(clkdev_drop);
> +
> +#ifdef CONFIG_CMD_CLOCK_INFO
> +static int do_clock_info(struct command *cmdtp, int argc, char *argv[])
> +{
> +	struct clk_lookup *p;
> +
> +	puts("Clocks\n");
"global clocks"?
> +
> +	list_for_each_entry(p, &clocks, node)
> +		if (!p->dev_id)
> +			printf("%s: %wHz\n", p->con_id, clk_get_rate(p->clk));
> +
> +	puts("Clocks for dev\n");
"device specific clocks"?

> +
> +	list_for_each_entry(p, &clocks, node)
> +		if (p->dev_id)
> +			printf("%s[%s]: %wHz\n", p->con_id, p->dev_id,
> +					       clk_get_rate(p->clk));
> +
> +	return 0;
> +}
> +
> +static const __maybe_unused char cmd_clock_info_help[] =
> +"Print clocks info\n"
> +;
> +
> +BAREBOX_CMD_START(clock_info)
> +	.cmd		= do_clock_info,
> +	.usage		= "Clocks Info",
> +	BAREBOX_CMD_HELP(cmd_clock_info_help)
> +BAREBOX_CMD_END
> +#endif
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/9] vsprintf: add %w and %w support to print unit
  2010-09-02 14:10 ` [PATCH 5/9] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 15:29   ` Uwe Kleine-König
  2010-09-02 15:32     ` Uwe Kleine-König
  0 siblings, 1 reply; 26+ messages in thread
From: Uwe Kleine-König @ 2010-09-02 15:29 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hello Jean-Christophe,

On Thu, Sep 02, 2010 at 04:10:20PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Show a '%w' or %W thing.
> This will show a frequency or byte at format xxx[.xxx] [ kMG]
> the precision can not excess the base kMG of the current unit
> otherwise it will be automatically reduce
> if no precision is specified and there is rest we will use a default
> precision of 3 as 66.667 M
> base will be typically 1000 for Hz or B and 1024 for iB
I see this used e.g. as:

	printk("%WiB", somevalue)

right?  hmm, what if somevalue is say 5?  If I understand correctly the
output then is: "5 iB".

> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  include/linux/kernel.h |   20 +++++++++++++
>  lib/vsprintf.c         |   73 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 93 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e9e2f07..b605946 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -5,6 +5,26 @@
>  #include <linux/barebox-wrapper.h>
>  
>  /*
> + * This looks more complex than it should be. But we need to
> + * get the type for the ~ right in round_down (it needs to be
> + * as wide as the result!), and we want to evaluate the macro
> + * arguments just once each.
> + */
> +#define __round_mask(x, y) ((__typeof__(x))((y)-1))
> +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
> +#define round_down(x, y) ((x) & ~__round_mask(x, y))
> +
> +#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> +#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> +#define DIV_ROUND_CLOSEST(x, divisor)(			\
> +{							\
> +	typeof(divisor) __divisor = divisor;		\
> +	(((x) + ((__divisor) / 2)) / (__divisor));	\
> +}							\
> +)
> +
> +/*
>   * min()/max()/clamp() macros that also do
>   * strict type-checking.. See the
>   * "unnecessary" pointer comparison.
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 6066845..add8bd5 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -254,6 +254,71 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int
>  }
>  
>  /*
> + * Show a '%w' or %W thing.  This will show a frequency or byte
> + * at format xxx[.xxx] [ kMG]
> + * the precision can not excess the base kMG of the current unit
> + * otherwise it will be automatically reduce
> + * if no precision is specified and there is rest we will use a default
> + * precision of 3 as 66.667 M
> + * base will be typically 1000 for Hz or B and 1024 for iB
> + */
> +static char *unit_string(char *buf, char *end, long val, int base, int field_width, int precision, int flags)
> +{
> +	long rest = 0;
> +	long integer;
> +	long pr = 3;
> +	long pr_mul = 1;
> +	long unit = 1;
> +	char format[] = " kMG";
> +	int pow, i;
> +
> +	for (pow = 0; pow < strlen(format) - 1; pow++) {
> +		if (val < unit * base)
> +			break;
> +		unit *= base;
> +	}
> +
> +	integer = val / unit;
> +
> +	if (precision != -1) {
> +		if (precision > pow * 3)
> +			precision = pow * 3;
> +		pr = precision;
> +	}
> +
> +	for (i = 0; i < pr; i++) {
> +		pr_mul *= 10;
> +	}
> +
> +	if (val % unit) {
> +		rest = DIV_ROUND_CLOSEST(pr_mul * (val - (integer * unit)), unit);
> +
> +		if (rest >= pr_mul) {
> +			rest -= pr_mul;
> +			integer++;
> +		}
> +	}
> +
> +	buf = number(buf, end, integer, 10, field_width, -1, 0);
> +
> +	if (rest != 0 || precision != -1) {
> +		if (buf < end)
> +			*buf = '.';
> +		buf++;
> +		buf = number(buf, end, rest, 10, -1, pr, 0);
> +	}
> +
> +	if (buf < end)
> +		*buf = ' ';
> +	buf++;
> +	if (buf < end && pow != 0)
> +		*buf = format[pow];
> +	buf++;
> +
> +	return buf;
> +}
> +
> +/*
>   * Show a '%p' thing.  A kernel extension is that the '%p' is followed
>   * by an extra set of alphanumeric characters that are extended format
>   * specifiers.
I think the kernel documents all available formats in a single place.
(Is that here in barebox?  If yes, please add your new formats here,
too.)

> @@ -421,6 +486,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
>  				str = string(str, end, va_arg(args, char *), field_width, precision, flags);
>  				continue;
>  
> +			case 'W':
> +				str = unit_string(str, end, va_arg(args, long), 1024, field_width, precision, flags);
> +				continue;
> +
> +			case 'w':
> +				str = unit_string(str, end, va_arg(args, long), 1000, field_width, precision, flags);
> +				continue;
> +
>  			case 'p':
>  				str = pointer(fmt+1, str, end,
>  						va_arg(args, void *),
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/9] vsprintf: add %w and %w support to print unit
  2010-09-02 15:29   ` Uwe Kleine-König
@ 2010-09-02 15:32     ` Uwe Kleine-König
       [not found]       ` <20100902155421.GB28968@game.jcrosoft.org>
  0 siblings, 1 reply; 26+ messages in thread
From: Uwe Kleine-König @ 2010-09-02 15:32 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hello,

On Thu, Sep 02, 2010 at 05:29:33PM +0200, Uwe Kleine-König wrote:
> Hello Jean-Christophe,
> 
> On Thu, Sep 02, 2010 at 04:10:20PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Show a '%w' or %W thing.
> > This will show a frequency or byte at format xxx[.xxx] [ kMG]
> > the precision can not excess the base kMG of the current unit
> > otherwise it will be automatically reduce
> > if no precision is specified and there is rest we will use a default
> > precision of 3 as 66.667 M
> > base will be typically 1000 for Hz or B and 1024 for iB
> I see this used e.g. as:
> 
> 	printk("%WiB", somevalue)
> 
> right?  hmm, what if somevalue is say 5?  If I understand correctly the
> output then is: "5 iB".
[I forgot to complete this, sorry]

"5 iB" looks ugly, doesn't it?  Do you care enough to fix that?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/9] vsprintf: add %w and %w support to print unit
       [not found]       ` <20100902155421.GB28968@game.jcrosoft.org>
@ 2010-09-02 17:54         ` Uwe Kleine-König
  0 siblings, 0 replies; 26+ messages in thread
From: Uwe Kleine-König @ 2010-09-02 17:54 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Thu, Sep 02, 2010 at 05:54:21PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 17:32 Thu 02 Sep     , Uwe Kleine-König wrote:
> > Hello,
> > 
> > On Thu, Sep 02, 2010 at 05:29:33PM +0200, Uwe Kleine-König wrote:
> > > Hello Jean-Christophe,
> > > 
> > > On Thu, Sep 02, 2010 at 04:10:20PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > Show a '%w' or %W thing.
> > > > This will show a frequency or byte at format xxx[.xxx] [ kMG]
> > > > the precision can not excess the base kMG of the current unit
> > > > otherwise it will be automatically reduce
> > > > if no precision is specified and there is rest we will use a default
> > > > precision of 3 as 66.667 M
> > > > base will be typically 1000 for Hz or B and 1024 for iB
> > > I see this used e.g. as:
> > > 
> > > 	printk("%WiB", somevalue)
> > > 
> > > right?  hmm, what if somevalue is say 5?  If I understand correctly the
> > > output then is: "5 iB".
> > [I forgot to complete this, sorry]
> > 
> > "5 iB" looks ugly, doesn't it?  Do you care enough to fix that?
> After it's everyone preference
> 
> What do you think of
> 100MHz
> 100 MHz
> 
> 1 Hz
> 1Hz
> 
> 100 MiB
> 100MiB
> 
> 1iB
> 1 iB
> 
> so which one?
IMHO iB doesn't make sense.  What should be the difference to a plain B?

And if "%WiB" yields 100MiB for 100*1024**2, it should yield 5B for 5
but neither "5 iB" nor "5iB" nor "5 B".

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 0/9 V2] preperation for sh adding
  2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 preceding siblings ...)
  2010-09-02 14:10 ` [PATCH 9/9] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:40 ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 1/9 V2] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
                     ` (9 more replies)
  9 siblings, 10 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:40 UTC (permalink / raw)
  To: barebox

Hi,

	this version 2
	update the vsprintf by managing the iB internally and the Space
	before the unit as optional

	the others comments was also fix

The following changes since commit 0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4:

  menu: simplify usage for clients (2010-08-30 21:06:02 +0200)

are available in the git repository at:
  git://git.jcrosoft.org/barebox.git sh-prepare

Jean-Christophe PLAGNIOL-VILLARD (9):
      types.h: move __kernel_dev_t to include/linux/types.h
      device: fix dev_name
      stm8815: fix the uart device clock match
      arm: move clkdev to drivers/clk
      vsprintf: add %w and %w support to print unit
      at91/clock: switch to %w for clock info printing
      cfi_flash: use %W and IEEE 1541 format
      use %W instead of size_human_readable and use IEEE 1541 format
      clkdev: add print clk info command

 arch/arm/Kconfig                          |    1 -
 arch/arm/Makefile                         |    2 +-
 arch/arm/common/Kconfig                   |    2 -
 arch/arm/common/Makefile                  |    5 --
 arch/arm/configs/nhk8815_defconfig        |    2 +-
 arch/arm/include/asm/clkdev.h             |   15 +-----
 arch/arm/include/asm/posix_types.h        |    1 -
 arch/arm/mach-at91/clock.c                |    8 +--
 arch/arm/mach-nomadik/8815.c              |    6 +-
 arch/arm/mach-nomadik/Kconfig             |    2 +-
 arch/arm/mach-nomadik/clock.c             |    7 +--
 arch/blackfin/include/asm/posix_types.h   |    1 -
 arch/m68k/include/asm/posix_types.h       |    1 -
 arch/ppc/include/asm/posix_types.h        |    1 -
 arch/sandbox/include/asm/posix_types.h    |    1 -
 arch/x86/include/asm/posix_types.h        |    1 -
 commands/Kconfig                          |    7 ++
 commands/bootm.c                          |    7 +-
 common/startup.c                          |    9 +--
 drivers/Kconfig                           |    1 +
 drivers/Makefile                          |    1 +
 drivers/clk/Kconfig                       |    4 +
 drivers/clk/Makefile                      |    2 +
 {arch/arm/common => drivers/clk}/clkdev.c |   57 +++++++++++++++---
 drivers/nor/cfi_flash.c                   |    8 +-
 include/common.h                          |    1 -
 include/driver.h                          |   12 ++--
 include/linux/clkdev.h                    |   36 +++++++++++
 include/linux/kernel.h                    |   20 ++++++
 include/linux/types.h                     |    2 +
 lib/Makefile                              |    1 -
 lib/display_options.c                     |   60 -------------------
 lib/driver.c                              |   16 ++---
 lib/vsprintf.c                            |   91 +++++++++++++++++++++++++++++
 34 files changed, 250 insertions(+), 141 deletions(-)
 delete mode 100644 arch/arm/common/Kconfig
 delete mode 100644 arch/arm/common/Makefile
 create mode 100644 drivers/clk/Kconfig
 create mode 100644 drivers/clk/Makefile
 rename {arch/arm/common => drivers/clk}/clkdev.c (74%)
 create mode 100644 include/linux/clkdev.h
 delete mode 100644 lib/display_options.c

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/9 V2] types.h: move __kernel_dev_t to include/linux/types.h
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 2/9 V2] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

no need to have a arch specific type

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/include/asm/posix_types.h      |    1 -
 arch/blackfin/include/asm/posix_types.h |    1 -
 arch/m68k/include/asm/posix_types.h     |    1 -
 arch/ppc/include/asm/posix_types.h      |    1 -
 arch/sandbox/include/asm/posix_types.h  |    1 -
 arch/x86/include/asm/posix_types.h      |    1 -
 include/linux/types.h                   |    2 ++
 7 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/arm/include/asm/posix_types.h b/arch/arm/include/asm/posix_types.h
index c412486..aee050e 100644
--- a/arch/arm/include/asm/posix_types.h
+++ b/arch/arm/include/asm/posix_types.h
@@ -19,7 +19,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short		__kernel_dev_t;
 typedef unsigned long		__kernel_ino_t;
 typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_nlink_t;
diff --git a/arch/blackfin/include/asm/posix_types.h b/arch/blackfin/include/asm/posix_types.h
index 98397ca..bbf6e9c 100644
--- a/arch/blackfin/include/asm/posix_types.h
+++ b/arch/blackfin/include/asm/posix_types.h
@@ -34,7 +34,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short __kernel_dev_t;
 typedef unsigned long __kernel_ino_t;
 typedef unsigned short __kernel_mode_t;
 typedef unsigned short __kernel_nlink_t;
diff --git a/arch/m68k/include/asm/posix_types.h b/arch/m68k/include/asm/posix_types.h
index c40c41d..d83afe9 100644
--- a/arch/m68k/include/asm/posix_types.h
+++ b/arch/m68k/include/asm/posix_types.h
@@ -27,7 +27,6 @@
 #define __ARCH_M68K_POSIX_TYPES_H
 
 
-typedef unsigned short		__kernel_dev_t;
 typedef unsigned long		__kernel_ino_t;
 typedef unsigned short		__kernel_mode_t;
 typedef unsigned short		__kernel_nlink_t;
diff --git a/arch/ppc/include/asm/posix_types.h b/arch/ppc/include/asm/posix_types.h
index 9170728..a7af406 100644
--- a/arch/ppc/include/asm/posix_types.h
+++ b/arch/ppc/include/asm/posix_types.h
@@ -7,7 +7,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned int	__kernel_dev_t;
 typedef unsigned int	__kernel_ino_t;
 typedef unsigned int	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
diff --git a/arch/sandbox/include/asm/posix_types.h b/arch/sandbox/include/asm/posix_types.h
index 5dcc842..4345141 100644
--- a/arch/sandbox/include/asm/posix_types.h
+++ b/arch/sandbox/include/asm/posix_types.h
@@ -7,7 +7,6 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short	__kernel_dev_t;
 typedef unsigned long	__kernel_ino_t;
 typedef unsigned short	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
diff --git a/arch/x86/include/asm/posix_types.h b/arch/x86/include/asm/posix_types.h
index a22f301..9278681 100644
--- a/arch/x86/include/asm/posix_types.h
+++ b/arch/x86/include/asm/posix_types.h
@@ -27,7 +27,6 @@
 #define _ASM_X86_POSIX_TYPES_H
 
 typedef unsigned long	__kernel_ino_t;
-typedef unsigned short	__kernel_dev_t;
 typedef unsigned short	__kernel_mode_t;
 typedef unsigned short	__kernel_nlink_t;
 typedef long		__kernel_off_t;
diff --git a/include/linux/types.h b/include/linux/types.h
index 96e5708..2145b6d 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -6,6 +6,8 @@
 
 #ifndef __KERNEL_STRICT_NAMES
 
+typedef __u32 __kernel_dev_t;
+
 typedef __kernel_fd_set		fd_set;
 typedef __kernel_dev_t		dev_t;
 typedef __kernel_ino_t		ino_t;
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 2/9 V2] device: fix dev_name
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 1/9 V2] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 3/9 V2] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

dev_name is supposed to return the name of the device plus the id

currently we use %s%d format where in the kernel the use %s.%d
we may think to switch to this format for the device name and keeping the %s%d
for the devfs

this will be usefull to not modify the clock device name as example

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/driver.h |   12 +++++++-----
 lib/driver.c     |   16 +++++++---------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index ee0749d..ab1f850 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -25,7 +25,8 @@
 
 #include <linux/list.h>
 
-#define MAX_DRIVER_NAME 32
+#define MAX_DRIVER_NAME		32
+#define FORMAT_DRIVER_MANE_ID	"%s%d"
 
 #include <param.h>
 
@@ -176,9 +177,11 @@ int get_free_deviceid(const char *name_template);
 
 char *deviceid_from_spec_str(const char *str, char **endp);
 
+extern const char *dev_id(const struct device_d *dev);
+
 static inline const char *dev_name(const struct device_d *dev)
 {
-	return dev->name;
+	return dev_id(dev);
 }
 
 /* linear list over all available devices
@@ -239,11 +242,10 @@ static inline int dev_close_default(struct device_d *dev, struct filep *f)
 }
 
 /* debugging and troubleshooting/diagnostic helpers. */
-extern const char *dev_id(const struct device_d *dev);
 
 #define dev_printf(dev, format, arg...)	\
-	printf("%s@%s: " format , dev_name(dev) , \
-	       dev_id(dev) , ## arg)
+	printf("%s@%s: " format , dev->name , \
+	       dev_name(dev) , ## arg)
 
 #define dev_emerg(dev, format, arg...)		\
 	dev_printf((dev) , format , ## arg)
diff --git a/lib/driver.c b/lib/driver.c
index b600745..03a2817 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -45,11 +45,9 @@ static LIST_HEAD(active);
 struct device_d *get_device_by_name(const char *name)
 {
 	struct device_d *dev;
-	char devname[MAX_DRIVER_NAME + 3];
 
 	for_each_device(dev) {
-		sprintf(devname, "%s%d", dev->name, dev->id);
-		if(!strcmp(name, devname))
+		if(!strcmp(dev_name(dev), name))
 			return dev;
 	}
 
@@ -62,7 +60,7 @@ int get_free_deviceid(const char *name_template)
 	char name[MAX_DRIVER_NAME + 3];
 
 	while (1) {
-		sprintf(name, "%s%d", name_template, i);
+		sprintf(name, FORMAT_DRIVER_MANE_ID, name_template, i);
 		if (!get_device_by_name(name))
 			return i;
 		i++;
@@ -97,7 +95,7 @@ int register_device(struct device_d *new_device)
 
 	new_device->id = get_free_deviceid(new_device->name);
 
-	debug ("register_device: %s\n",new_device->name);
+	debug ("register_device: %s\n", dev_name(new_device));
 
 	if (!new_device->bus) {
 //		dev_err(new_device, "no bus type associated. Needs fixup\n");
@@ -120,7 +118,7 @@ EXPORT_SYMBOL(register_device);
 
 int unregister_device(struct device_d *old_dev)
 {
-	debug("unregister_device: %s:%s\n",old_dev->name, old_dev->id);
+	debug("unregister_device: %s\n", dev_name(old_dev->name));
 
 	if (!list_empty(&old_dev->children)) {
 		errno = -EBUSY;
@@ -164,7 +162,7 @@ struct driver_d *get_driver_by_name(const char *name)
 
 static void noinfo(struct device_d *dev)
 {
-	printf("no info available for %s\n", dev->name);
+	printf("no info available for %s\n", dev_name(dev));
 }
 
 static void noshortinfo(struct device_d *dev)
@@ -237,7 +235,7 @@ static int do_devinfo_subtree(struct device_d *dev, int depth, char edge)
 	for (i = 0; i < depth; i++)
 		printf("|    ");
 
-	printf("%c----%s%d", edge, dev->name, dev->id);
+	printf("%c----%s", edge, dev_name(dev));
 	if (!list_empty(&dev->cdevs)) {
 		printf(" (");
 		list_for_each_entry(cdev, &dev->cdevs, devices_list) {
@@ -264,7 +262,7 @@ const char *dev_id(const struct device_d *dev)
 {
 	static char buf[sizeof(unsigned long) * 2];
 
-	sprintf(buf, "%s%d", dev->name, dev->id);
+	sprintf(buf, FORMAT_DRIVER_MANE_ID, dev->name, dev->id);
 
 	return buf;
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 3/9 V2] stm8815: fix the uart device clock match
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 1/9 V2] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 2/9 V2] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 4/9 V2] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

that use the device name + id to found it's clock
to use the right match as we fix the dev_name macro

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-nomadik/8815.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-nomadik/8815.c b/arch/arm/mach-nomadik/8815.c
index 8598f14..faeded4 100644
--- a/arch/arm/mach-nomadik/8815.c
+++ b/arch/arm/mach-nomadik/8815.c
@@ -50,12 +50,14 @@ void st8815_add_device_sdram(u32 size)
 }
 
 static struct device_d uart0_serial_device = {
+	.id = 0,
 	.name = "uart-pl011",
 	.map_base = NOMADIK_UART0_BASE,
 	.size = 4096,
 };
 
 static struct device_d uart1_serial_device = {
+	.id = 1,
 	.name = "uart-pl011",
 	.map_base = NOMADIK_UART1_BASE,
 	.size = 4096,
@@ -65,12 +67,12 @@ void st8815_register_uart(unsigned id)
 {
 	switch (id) {
 	case 0:
-		nmdk_clk_create(&st8815_clk_48, uart0_serial_device.name);
 		register_device(&uart0_serial_device);
+		nmdk_clk_create(&st8815_clk_48, dev_name(&uart0_serial_device));
 		break;
 	case 1:
-		nmdk_clk_create(&st8815_clk_48, uart1_serial_device.name);
 		register_device(&uart1_serial_device);
+		nmdk_clk_create(&st8815_clk_48, dev_name(&uart0_serial_device));
 		break;
 	}
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 4/9 V2] arm: move clkdev to drivers/clk
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 3/9 V2] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

as refer in this patch "arm & sh: factorised duplicated clkdev.c"

factorise some generic infrastructure to assist looking up struct clks
for the ARM & SH architecture.

as the code is identical at 99% in linux

move it also as preparing for the SH adding

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/Kconfig                                 |    1 -
 arch/arm/Makefile                                |    2 +-
 arch/arm/common/Kconfig                          |    2 -
 arch/arm/common/Makefile                         |    5 ----
 arch/arm/configs/nhk8815_defconfig               |    2 +-
 arch/arm/include/asm/clkdev.h                    |   15 +------------
 arch/arm/mach-nomadik/Kconfig                    |    2 +-
 arch/arm/mach-nomadik/clock.c                    |    7 +-----
 drivers/Kconfig                                  |    1 +
 drivers/Makefile                                 |    1 +
 drivers/clk/Kconfig                              |    4 +++
 drivers/clk/Makefile                             |    2 +
 {arch/arm/common => drivers/clk}/clkdev.c        |   24 ++++++++++++++-------
 {arch/arm/include/asm => include/linux}/clkdev.h |   12 ++++++++--
 14 files changed, 38 insertions(+), 42 deletions(-)
 delete mode 100644 arch/arm/common/Kconfig
 delete mode 100644 arch/arm/common/Makefile
 create mode 100644 drivers/clk/Kconfig
 create mode 100644 drivers/clk/Makefile
 rename {arch/arm/common => drivers/clk}/clkdev.c (90%)
 copy {arch/arm/include/asm => include/linux}/clkdev.h (72%)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 945528c..fa37036 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -58,7 +58,6 @@ config ARCH_S3C24xx
 
 endchoice
 
-source arch/arm/common/Kconfig
 source arch/arm/cpu/Kconfig
 source arch/arm/mach-at91/Kconfig
 source arch/arm/mach-ep93xx/Kconfig
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index e542c03..388dcc9 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -131,7 +131,7 @@ MACH :=
 endif
 
 common-y += $(BOARD) $(MACH)
-common-y += arch/arm/lib/ arch/arm/cpu/ arch/arm/common/
+common-y += arch/arm/lib/ arch/arm/cpu/
 
 lds-$(CONFIG_GENERIC_LINKER_SCRIPT)	:= arch/arm/lib/barebox.lds
 lds-$(CONFIG_BOARD_LINKER_SCRIPT)	:= $(BOARD)/barebox.lds
diff --git a/arch/arm/common/Kconfig b/arch/arm/common/Kconfig
deleted file mode 100644
index e749e45..0000000
--- a/arch/arm/common/Kconfig
+++ /dev/null
@@ -1,2 +0,0 @@
-config COMMON_CLKDEV
-	bool
diff --git a/arch/arm/common/Makefile b/arch/arm/common/Makefile
deleted file mode 100644
index 9cc8834..0000000
--- a/arch/arm/common/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-obj-$(CONFIG_COMMON_CLKDEV)	+= clkdev.o
diff --git a/arch/arm/configs/nhk8815_defconfig b/arch/arm/configs/nhk8815_defconfig
index 21d596f..6e28ef2 100644
--- a/arch/arm/configs/nhk8815_defconfig
+++ b/arch/arm/configs/nhk8815_defconfig
@@ -19,7 +19,7 @@ CONFIG_ARM_AMBA=y
 CONFIG_ARCH_NOMADIK=y
 # CONFIG_ARCH_OMAP is not set
 # CONFIG_ARCH_S3C24xx is not set
-CONFIG_COMMON_CLKDEV=y
+CONFIG_CLKDEV_LOOKUP=y
 
 #
 # Processor Type
diff --git a/arch/arm/include/asm/clkdev.h b/arch/arm/include/asm/clkdev.h
index b6ec7c6..ad33945 100644
--- a/arch/arm/include/asm/clkdev.h
+++ b/arch/arm/include/asm/clkdev.h
@@ -12,19 +12,6 @@
 #ifndef __ASM_CLKDEV_H
 #define __ASM_CLKDEV_H
 
-struct clk;
-
-struct clk_lookup {
-	struct list_head	node;
-	const char		*dev_id;
-	const char		*con_id;
-	struct clk		*clk;
-};
-
-struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
-	const char *dev_fmt, ...);
-
-void clkdev_add(struct clk_lookup *cl);
-void clkdev_drop(struct clk_lookup *cl);
+#include <mach/clkdev.h>
 
 #endif
diff --git a/arch/arm/mach-nomadik/Kconfig b/arch/arm/mach-nomadik/Kconfig
index 64894c8..3d6eab6 100644
--- a/arch/arm/mach-nomadik/Kconfig
+++ b/arch/arm/mach-nomadik/Kconfig
@@ -13,7 +13,7 @@ choice
 config MACH_NOMADIK_8815NHK
 	bool "ST 8815 Nomadik Hardware Kit (evaluation board)"
 	select NOMADIK_8815
-	select COMMON_CLKDEV
+	select CLKDEV_LOOKUP
 
 endchoice
 
diff --git a/arch/arm/mach-nomadik/clock.c b/arch/arm/mach-nomadik/clock.c
index c74e0c1..5f34a2c 100644
--- a/arch/arm/mach-nomadik/clock.c
+++ b/arch/arm/mach-nomadik/clock.c
@@ -8,7 +8,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <init.h>
-#include <asm/clkdev.h>
+#include <linux/clkdev.h>
 
 #include "clock.h"
 
@@ -34,11 +34,6 @@ void clk_disable(struct clk *clk)
 }
 EXPORT_SYMBOL(clk_disable);
 
-int __clk_get(struct clk *clk)
-{
-	return 1;
-}
-
 /* Create a clock structure with the given name */
 int nmdk_clk_create(struct clk *clk, const char *dev_id)
 {
diff --git a/drivers/Kconfig b/drivers/Kconfig
index ae9efce..f7154c6 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -9,5 +9,6 @@ source "drivers/mtd/Kconfig"
 source "drivers/ata/Kconfig"
 source "drivers/usb/Kconfig"
 source "drivers/video/Kconfig"
+source "drivers/clk/Kconfig"
 
 endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index bce68bc..706e1c8 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_ATA) += ata/
 obj-$(CONFIG_SPI) += spi/
 obj-$(CONFIG_I2C) += i2c/
 obj-$(CONFIG_VIDEO) += video/
+obj-y	+= clk/
diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
new file mode 100644
index 0000000..4168c88
--- /dev/null
+++ b/drivers/clk/Kconfig
@@ -0,0 +1,4 @@
+
+config CLKDEV_LOOKUP
+	bool
+	select HAVE_CLK
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
new file mode 100644
index 0000000..07613fa
--- /dev/null
+++ b/drivers/clk/Makefile
@@ -0,0 +1,2 @@
+
+obj-$(CONFIG_CLKDEV_LOOKUP)	+= clkdev.o
diff --git a/arch/arm/common/clkdev.c b/drivers/clk/clkdev.c
similarity index 90%
rename from arch/arm/common/clkdev.c
rename to drivers/clk/clkdev.c
index 4d25356..717fea5 100644
--- a/arch/arm/common/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -1,5 +1,5 @@
 /*
- *  arch/arm/common/clkdev.c
+ * drivers/clk/lookup_clkdev.c
  *
  *  Copyright (C) 2008 Russell King.
  *
@@ -14,14 +14,13 @@
 #include <linux/list.h>
 #include <errno.h>
 #include <linux/err.h>
+#include <linux/string.h>
 #include <linux/clk.h>
+#include <linux/clkdev.h>
 #include <init.h>
 #include <malloc.h>
 #include <stdio.h>
 
-#include <asm/clkdev.h>
-#include <mach/clkdev.h>
-
 static LIST_HEAD(clocks);
 
 /*
@@ -31,7 +30,7 @@ static LIST_HEAD(clocks);
  *  If an entry has a device ID, it must match
  *  If an entry has a connection ID, it must match
  * Then we take the most specific entry - with the following
- * order of precidence: dev+con > dev only > con only.
+ * order of precedence: dev+con > dev only > con only.
  */
 static struct clk *clk_find(const char *dev_id, const char *con_id)
 {
@@ -51,12 +50,13 @@ static struct clk *clk_find(const char *dev_id, const char *con_id)
 				continue;
 			match += 1;
 		}
-		if (match == 0)
-			continue;
 
 		if (match > best) {
 			clk = p->clk;
-			best = match;
+			if (match != 3)
+				best = match;
+			else
+				break;
 		}
 	}
 	return clk;
@@ -94,6 +94,14 @@ void clkdev_add(struct clk_lookup *cl)
 }
 EXPORT_SYMBOL(clkdev_add);
 
+void __init clkdev_add_table(struct clk_lookup *cl, size_t num)
+{
+	while (num--) {
+		list_add_tail(&cl->node, &clocks);
+		cl++;
+	}
+}
+
 #define MAX_DEV_ID	20
 #define MAX_CON_ID	16
 
diff --git a/arch/arm/include/asm/clkdev.h b/include/linux/clkdev.h
similarity index 72%
copy from arch/arm/include/asm/clkdev.h
copy to include/linux/clkdev.h
index b6ec7c6..ae38e1a 100644
--- a/arch/arm/include/asm/clkdev.h
+++ b/include/linux/clkdev.h
@@ -1,5 +1,5 @@
 /*
- *  arch/arm/include/asm/clkdev.h
+ *  include/linux/clkdev.h
  *
  *  Copyright (C) 2008 Russell King.
  *
@@ -9,10 +9,13 @@
  *
  * Helper for the clk API to assist looking up a struct clk.
  */
-#ifndef __ASM_CLKDEV_H
-#define __ASM_CLKDEV_H
+#ifndef __CLKDEV_H
+#define __CLKDEV_H
+
+#include <asm/clkdev.h>
 
 struct clk;
+struct device_d;
 
 struct clk_lookup {
 	struct list_head	node;
@@ -27,4 +30,7 @@ struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
 void clkdev_add(struct clk_lookup *cl);
 void clkdev_drop(struct clk_lookup *cl);
 
+void clkdev_add_table(struct clk_lookup *, size_t);
+int clk_add_alias(const char *, const char *, char *, struct device_d *);
+
 #endif
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 4/9 V2] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-03 18:34     ` Uwe Kleine-König
  2010-09-02 19:41   ` [PATCH 6/9 V2] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 subsequent siblings)
  9 siblings, 1 reply; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

Show a '%w' or %W thing.  This will show a unit
at format xxx[.xxx][ ][ kMG] with iEEE 1541 support

The precision can not excess the base kMG of the current unit
otherwise it will be automatically reduce

If no precision is specified and there is rest we will use a default
precision of 3 as 66.667 M or 66.667M

%#w or %#W will add a space between the value and the unit

The base will be typically 1000 for Hz or B and 1024 for iB
for 1024 the i is automactically add for val >= 1024

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/linux/kernel.h |   20 ++++++++++
 lib/vsprintf.c         |   91 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e9e2f07..b605946 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -5,6 +5,26 @@
 #include <linux/barebox-wrapper.h>
 
 /*
+ * This looks more complex than it should be. But we need to
+ * get the type for the ~ right in round_down (it needs to be
+ * as wide as the result!), and we want to evaluate the macro
+ * arguments just once each.
+ */
+#define __round_mask(x, y) ((__typeof__(x))((y)-1))
+#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#define round_down(x, y) ((x) & ~__round_mask(x, y))
+
+#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
+#define DIV_ROUND_CLOSEST(x, divisor)(			\
+{							\
+	typeof(divisor) __divisor = divisor;		\
+	(((x) + ((__divisor) / 2)) / (__divisor));	\
+}							\
+)
+
+/*
  * min()/max()/clamp() macros that also do
  * strict type-checking.. See the
  * "unnecessary" pointer comparison.
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6066845..18ba371 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -254,6 +254,88 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int
 }
 
 /*
+ * Show a '%w' or %W thing.  This will show a unit
+ * at format xxx[.xxx][ ][ kMG] with iEEE 1541 support
+ *
+ * The precision can not excess the base kMG of the current unit
+ * otherwise it will be automatically reduce
+ *
+ * If no precision is specified and there is rest we will use a default
+ * precision of 3 as 66.667 M or 66.667M
+ *
+ * %#w or %#W will add a space between the value and the unit
+ *
+ * The base will be typically 1000 for Hz or B and 1024 for iB
+ * for 1024 the i is automactically add for val >= 1024
+ */
+static char *unit_string(char *buf, char *end, long val, int base, int field_width, int precision, int flags)
+{
+	long rest = 0;
+	long integer;
+	long pr = 3;
+	long pr_mul = 1;
+	long unit = 1;
+	char format[] = " kMG";
+	int pow, i;
+
+	for (pow = 0; pow < strlen(format) - 1; pow++) {
+		if (val < unit * base)
+			break;
+		unit *= base;
+	}
+
+	integer = val / unit;
+
+	if (precision != -1) {
+		if (precision > pow * 3)
+			precision = pow * 3;
+		pr = precision;
+	}
+
+	for (i = 0; i < pr; i++) {
+		pr_mul *= 10;
+	}
+
+	if (val % unit) {
+		rest = DIV_ROUND_CLOSEST(pr_mul * (val - (integer * unit)), unit);
+
+		if (rest >= pr_mul) {
+			rest -= pr_mul;
+			integer++;
+		}
+	}
+
+	buf = number(buf, end, integer, 10, field_width, -1, flags & ~LEFT);
+
+	if (rest != 0 || precision != -1) {
+		if (buf < end)
+			*buf = '.';
+		buf++;
+		buf = number(buf, end, rest, 10, -1, pr, flags | ZEROPAD);
+	}
+
+	/* use SPECIAL as SPACE could be used for the interger part */
+	if (flags & SPECIAL) {
+		if (buf < end)
+			*buf = ' ';
+		buf++;
+	}
+
+	if (pow > 0) {
+		if (buf < end)
+			*buf = format[pow];
+		buf++;
+		if (base == 1024) {
+			if (buf < end)
+				*buf = 'i';
+			buf++;
+		}
+	}
+
+	return buf;
+}
+
+/*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
  * specifiers.
@@ -291,6 +373,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
  * %pS output the name of a text symbol
  * %pF output the name of a function pointer
  * %pR output the address range in a struct resource
+ * %W and %w output at unit format with iEEE 1541 support
  *
  * The return value is the number of characters which would
  * be generated for the given input, excluding the trailing
@@ -421,6 +504,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
 				str = string(str, end, va_arg(args, char *), field_width, precision, flags);
 				continue;
 
+			case 'W':
+				str = unit_string(str, end, va_arg(args, long), 1024, field_width, precision, flags);
+				continue;
+
+			case 'w':
+				str = unit_string(str, end, va_arg(args, long), 1000, field_width, precision, flags);
+				continue;
+
 			case 'p':
 				str = pointer(fmt+1, str, end,
 						va_arg(args, void *),
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 6/9 V2] at91/clock: switch to %w for clock info printing
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (4 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 7/9 V2] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-at91/clock.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
index 6fd09d5..c3161d7 100644
--- a/arch/arm/mach-at91/clock.c
+++ b/arch/arm/mach-at91/clock.c
@@ -677,12 +677,10 @@ int at91_clock_init(unsigned long main_clock)
 static int at91_clock_display(void)
 {
 	if (pll_overclock)
-		pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
+		pr_info("Clocks: PLLA overclocked, %#wHz\n", plla.rate_hz);
 
-	printf("Clocks: CPU %u MHz, master %u MHz, main %u.%03u MHz\n",
-		mck.parent->rate_hz / 1000000, (unsigned) mck.rate_hz / 1000000,
-		(unsigned) main_clk.rate_hz / 1000000,
-		((unsigned) main_clk.rate_hz % 1000000) / 1000);
+	printf("Clocks: CPU %#wHz, master %#wHz, main %#wHz\n",
+		mck.parent->rate_hz, mck.rate_hz, main_clk.rate_hz);
 
 	return 0;
 }
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 7/9 V2] cfi_flash: use %W and IEEE 1541 format
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (5 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 6/9 V2] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 8/9 V2] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/nor/cfi_flash.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index fa5e5ee..bb72e39 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -713,8 +713,8 @@ static void cfi_info (struct device_d* dev)
 
 	printf ("CFI conformant FLASH (%d x %d)",
 		(info->portwidth << 3), (info->chipwidth << 3));
-	printf ("  Size: %ld MB in %d Sectors\n",
-		info->size >> 20, info->sector_count);
+	printf ("  Size: %WB in %d Sectors\n",
+		info->size, info->sector_count);
 	printf ("  ");
 	switch (info->vendor) {
 		case CFI_CMDSET_INTEL_STANDARD:
@@ -1036,8 +1036,8 @@ static int cfi_probe (struct device_d *dev)
 	}
 
 	if (info->flash_id == FLASH_UNKNOWN) {
-		printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n",
-			dev->map_base, info->size, info->size << 20);
+		printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %WB\n",
+			dev->map_base, info->size, info->size);
 		return -ENODEV;
 	}
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 8/9 V2] use %W instead of size_human_readable and use IEEE 1541 format
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (6 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 7/9 V2] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-02 19:41   ` [PATCH 9/9 V2] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
  2010-09-16 10:38   ` [PATCH 0/9 V2] preperation for sh adding Sascha Hauer
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/bootm.c      |    7 ++---
 common/startup.c      |    9 +++----
 include/common.h      |    1 -
 lib/Makefile          |    1 -
 lib/display_options.c |   60 -------------------------------------------------
 5 files changed, 7 insertions(+), 71 deletions(-)
 delete mode 100644 lib/display_options.c

diff --git a/commands/bootm.c b/commands/bootm.c
index 11325dc..cbdf55f 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -552,11 +552,11 @@ print_image_hdr (image_header_t *hdr)
 	printf ("   Image Type:   %s %s %s (%s)\n", image_arch(hdr), image_os(hdr),
 			image_type(hdr), image_compression(hdr));
 #endif
-	printf ("   Data Size:    %d Bytes = %s\n"
+	printf ("   Data Size:    %d Bytes = %WB\n"
 		"   Load Address: %08x\n"
 		"   Entry Point:  %08x\n",
 			ntohl(hdr->ih_size),
-			size_human_readable(ntohl(hdr->ih_size)),
+			ntohl(hdr->ih_size),
 			ntohl(hdr->ih_load),
 			ntohl(hdr->ih_ep));
 
@@ -567,8 +567,7 @@ print_image_hdr (image_header_t *hdr)
 
 		puts ("   Contents:\n");
 		for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
-			printf ("   Image %d: %8ld Bytes = %s", i, len,
-				size_human_readable (len));
+			printf ("   Image %d: %8ld Bytes = %WB", i, len, len);
 		}
 	}
 }
diff --git a/common/startup.c b/common/startup.c
index 2ed16fe..8e49bd2 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -52,12 +52,11 @@ static void display_meminfo(void)
 
 	debug("barebox code : 0x%08lX -> 0x%08lX  BSS: -> 0x%08lX\n",
 	       _barebox_start, _bss_start, _bss_end);
-	printf("Malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
-		mstart, mend, size_human_readable(msize));
+	printf("Malloc space: 0x%08lx -> 0x%08lx (size %WB)\n",
+		mstart, mend, msize);
 #ifdef CONFIG_ARM
-	printf("Stack space : 0x%08lx -> 0x%08lx (size %s)\n",
-		STACK_BASE, STACK_BASE + STACK_SIZE,
-		size_human_readable(STACK_SIZE));
+	printf("Stack space : 0x%08lx -> 0x%08lx (size %WB)\n",
+		STACK_BASE, STACK_BASE + STACK_SIZE, STACK_SIZE);
 #endif
 }
 
diff --git a/include/common.h b/include/common.h
index 64f49db..fda04d4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -95,7 +95,6 @@ void __noreturn panic(const char *fmt, ...);
 
 /* */
 long int initdram (int);
-char *size_human_readable(ulong size);
 
 /* common/main.c */
 int	run_command	(const char *cmd, int flag);
diff --git a/lib/Makefile b/lib/Makefile
index 8c5df08..e5a82fc 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,6 +1,5 @@
 obj-y			+= ctype.o
 obj-y			+= rbtree.o
-obj-y			+= display_options.o
 obj-y			+= ldiv.o
 obj-y			+= string.o
 obj-y			+= vsprintf.o
diff --git a/lib/display_options.c b/lib/display_options.c
deleted file mode 100644
index 03f4f22..0000000
--- a/lib/display_options.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * (C) Copyright 2000-2002
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- */
-
-#include <common.h>
-
-/*
- * return a pointer to a string containing the size
- * as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
- */
-char *size_human_readable(ulong size)
-{
-	static char buf[20];
-	ulong m, n;
-	ulong d = 1 << 20;		/* 1 MB */
-	char  c = 'M';
-	char *ptr = buf;
-
-	if (size < d) {			/* print in kB */
-		c = 'k';
-		d = 1 << 10;
-	}
-
-	n = size / d;
-
-	m = (10 * (size - (n * d)) + (d / 2) ) / d;
-
-	if (m >= 10) {
-		m -= 10;
-		n += 1;
-	}
-
-	ptr += sprintf(buf, "%2ld", n);
-	if (m) {
-		ptr += sprintf (ptr,".%ld", m);
-	}
-	sprintf(ptr, " %cB", c);
-
-	return buf;
-}
-EXPORT_SYMBOL(size_human_readable);
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 9/9 V2] clkdev: add print clk info command
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (7 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 8/9 V2] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-02 19:41   ` Jean-Christophe PLAGNIOL-VILLARD
  2010-09-16 10:38   ` [PATCH 0/9 V2] preperation for sh adding Sascha Hauer
  9 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-02 19:41 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/Kconfig     |    7 +++++++
 drivers/clk/clkdev.c |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 57c9b75..fe13f90 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -338,4 +338,11 @@ config CMD_I2C
 	  include i2c_probe, i2c_read and i2c_write commands to communicate
 	  on i2c bus.
 
+config CMD_CLOCK_INFO
+	bool
+	depends on CLKDEV_LOOKUP
+	prompt "clock info command"
+	help
+	  show list of registered clock
+
 endmenu
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 717fea5..49d98df 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -11,6 +11,7 @@
  */
 
 #include <common.h>
+#include <command.h>
 #include <linux/list.h>
 #include <errno.h>
 #include <linux/err.h>
@@ -166,3 +167,35 @@ void clkdev_drop(struct clk_lookup *cl)
 	kfree(cl);
 }
 EXPORT_SYMBOL(clkdev_drop);
+
+#ifdef CONFIG_CMD_CLOCK_INFO
+static int do_clock_info(struct command *cmdtp, int argc, char *argv[])
+{
+	struct clk_lookup *p;
+
+	puts("Global clocks:\n");
+
+	list_for_each_entry(p, &clocks, node)
+		if (!p->dev_id)
+			printf("%s: %#wHz\n", p->con_id, clk_get_rate(p->clk));
+
+	puts("Device specific clocks:\n");
+
+	list_for_each_entry(p, &clocks, node)
+		if (p->dev_id)
+			printf("%s[%s]: %#wHz\n", p->con_id, p->dev_id,
+					       clk_get_rate(p->clk));
+
+	return 0;
+}
+
+static const __maybe_unused char cmd_clock_info_help[] =
+"Print clocks info\n"
+;
+
+BAREBOX_CMD_START(clock_info)
+	.cmd		= do_clock_info,
+	.usage		= "Clocks Info",
+	BAREBOX_CMD_HELP(cmd_clock_info_help)
+BAREBOX_CMD_END
+#endif
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit
  2010-09-02 19:41   ` [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-03 18:34     ` Uwe Kleine-König
  0 siblings, 0 replies; 26+ messages in thread
From: Uwe Kleine-König @ 2010-09-03 18:34 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hello Jean-Christophe,

On Thu, Sep 02, 2010 at 09:41:46PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Show a '%w' or %W thing.  This will show a unit
> at format xxx[.xxx][ ][ kMG] with iEEE 1541 support
> 
> The precision can not excess the base kMG of the current unit
> otherwise it will be automatically reduce
> 
> If no precision is specified and there is rest we will use a default
> precision of 3 as 66.667 M or 66.667M
> 
> %#w or %#W will add a space between the value and the unit
> 
> The base will be typically 1000 for Hz or B and 1024 for iB
> for 1024 the i is automactically add for val >= 1024
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
>  include/linux/kernel.h |   20 ++++++++++
>  lib/vsprintf.c         |   91 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 111 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index e9e2f07..b605946 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -5,6 +5,26 @@
>  #include <linux/barebox-wrapper.h>
>  
>  /*
> + * This looks more complex than it should be. But we need to
> + * get the type for the ~ right in round_down (it needs to be
> + * as wide as the result!), and we want to evaluate the macro
> + * arguments just once each.
> + */
> +#define __round_mask(x, y) ((__typeof__(x))((y)-1))
> +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
> +#define round_down(x, y) ((x) & ~__round_mask(x, y))
> +
> +#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
> +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
> +#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
> +#define DIV_ROUND_CLOSEST(x, divisor)(			\
> +{							\
> +	typeof(divisor) __divisor = divisor;		\
> +	(((x) + ((__divisor) / 2)) / (__divisor));	\
> +}							\
> +)
> +
> +/*
>   * min()/max()/clamp() macros that also do
>   * strict type-checking.. See the
>   * "unnecessary" pointer comparison.
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 6066845..18ba371 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -254,6 +254,88 @@ static char *symbol_string(char *buf, char *end, void *ptr, int field_width, int
>  }
>  
>  /*
> + * Show a '%w' or %W thing.  This will show a unit
s/%W/'%W'/, and you should note here, that %W uses 1024 as base, %w uses
1000.  These formats expect a (signed) long, right?  What about making
this a flag to the usual %d and %u to support all integer types?

Something like: %lWuB to print an unsigned long using the ieee format
(with base 1024)?  (I don't know why you choosed 'w', is it just any
free letter or a 'real' abbreviation?)

> + * at format xxx[.xxx][ ][ kMG] with iEEE 1541 support
> + *
> + * The precision can not excess the base kMG of the current unit
> + * otherwise it will be automatically reduce
s/reduce/reduced./
> + *
> + * If no precision is specified and there is rest we will use a default
> + * precision of 3 as 66.667 M or 66.667M
> + *
> + * %#w or %#W will add a space between the value and the unit
> + *
> + * The base will be typically 1000 for Hz or B and 1024 for iB
> + * for 1024 the i is automactically add for val >= 1024
> + */
> +static char *unit_string(char *buf, char *end, long val, int base, int field_width, int precision, int flags)
> +{
> +	long rest = 0;
> +	long integer;
> +	long pr = 3;
> +	long pr_mul = 1;
> +	long unit = 1;
> +	char format[] = " kMG";
> +	int pow, i;
> +
> +	for (pow = 0; pow < strlen(format) - 1; pow++) {
> +		if (val < unit * base)
> +			break;
> +		unit *= base;
> +	}
> +
> +	integer = val / unit;
> +
> +	if (precision != -1) {
> +		if (precision > pow * 3)
> +			precision = pow * 3;
> +		pr = precision;
> +	}
> +
> +	for (i = 0; i < pr; i++) {
> +		pr_mul *= 10;
> +	}
> +
> +	if (val % unit) {
> +		rest = DIV_ROUND_CLOSEST(pr_mul * (val - (integer * unit)), unit);
> +
> +		if (rest >= pr_mul) {
> +			rest -= pr_mul;
> +			integer++;
> +		}
> +	}
> +
> +	buf = number(buf, end, integer, 10, field_width, -1, flags & ~LEFT);
> +
> +	if (rest != 0 || precision != -1) {
> +		if (buf < end)
> +			*buf = '.';
> +		buf++;
> +		buf = number(buf, end, rest, 10, -1, pr, flags | ZEROPAD);
> +	}
> +
> +	/* use SPECIAL as SPACE could be used for the interger part */
> +	if (flags & SPECIAL) {
> +		if (buf < end)
> +			*buf = ' ';
> +		buf++;
> +	}
> +
> +	if (pow > 0) {
> +		if (buf < end)
> +			*buf = format[pow];
> +		buf++;
> +		if (base == 1024) {
> +			if (buf < end)
> +				*buf = 'i';
> +			buf++;
> +		}
> +	}
> +
> +	return buf;
> +}
> +
> +/*
>   * Show a '%p' thing.  A kernel extension is that the '%p' is followed
>   * by an extra set of alphanumeric characters that are extended format
>   * specifiers.
> @@ -291,6 +373,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
>   * %pS output the name of a text symbol
>   * %pF output the name of a function pointer
>   * %pR output the address range in a struct resource
> + * %W and %w output at unit format with iEEE 1541 support
>   *
>   * The return value is the number of characters which would
>   * be generated for the given input, excluding the trailing
> @@ -421,6 +504,14 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
>  				str = string(str, end, va_arg(args, char *), field_width, precision, flags);
>  				continue;
>  
> +			case 'W':
> +				str = unit_string(str, end, va_arg(args, long), 1024, field_width, precision, flags);
> +				continue;
> +
> +			case 'w':
> +				str = unit_string(str, end, va_arg(args, long), 1000, field_width, precision, flags);
> +				continue;
> +
>  			case 'p':
>  				str = pointer(fmt+1, str, end,
>  						va_arg(args, void *),
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/9 V2] preperation for sh adding
  2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
                     ` (8 preceding siblings ...)
  2010-09-02 19:41   ` [PATCH 9/9 V2] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-16 10:38   ` Sascha Hauer
  9 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2010-09-16 10:38 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hi Jean-Christophe,

Can you integrate the comment from Uwe please? Otherwise it seems ok for
me.

Sascha


On Thu, Sep 02, 2010 at 09:40:46PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> 	this version 2
> 	update the vsprintf by managing the iB internally and the Space
> 	before the unit as optional
> 
> 	the others comments was also fix
> 
> The following changes since commit 0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4:
> 
>   menu: simplify usage for clients (2010-08-30 21:06:02 +0200)
> 
> are available in the git repository at:
>   git://git.jcrosoft.org/barebox.git sh-prepare
> 
> Jean-Christophe PLAGNIOL-VILLARD (9):
>       types.h: move __kernel_dev_t to include/linux/types.h
>       device: fix dev_name
>       stm8815: fix the uart device clock match
>       arm: move clkdev to drivers/clk
>       vsprintf: add %w and %w support to print unit
>       at91/clock: switch to %w for clock info printing
>       cfi_flash: use %W and IEEE 1541 format
>       use %W instead of size_human_readable and use IEEE 1541 format
>       clkdev: add print clk info command
> 
>  arch/arm/Kconfig                          |    1 -
>  arch/arm/Makefile                         |    2 +-
>  arch/arm/common/Kconfig                   |    2 -
>  arch/arm/common/Makefile                  |    5 --
>  arch/arm/configs/nhk8815_defconfig        |    2 +-
>  arch/arm/include/asm/clkdev.h             |   15 +-----
>  arch/arm/include/asm/posix_types.h        |    1 -
>  arch/arm/mach-at91/clock.c                |    8 +--
>  arch/arm/mach-nomadik/8815.c              |    6 +-
>  arch/arm/mach-nomadik/Kconfig             |    2 +-
>  arch/arm/mach-nomadik/clock.c             |    7 +--
>  arch/blackfin/include/asm/posix_types.h   |    1 -
>  arch/m68k/include/asm/posix_types.h       |    1 -
>  arch/ppc/include/asm/posix_types.h        |    1 -
>  arch/sandbox/include/asm/posix_types.h    |    1 -
>  arch/x86/include/asm/posix_types.h        |    1 -
>  commands/Kconfig                          |    7 ++
>  commands/bootm.c                          |    7 +-
>  common/startup.c                          |    9 +--
>  drivers/Kconfig                           |    1 +
>  drivers/Makefile                          |    1 +
>  drivers/clk/Kconfig                       |    4 +
>  drivers/clk/Makefile                      |    2 +
>  {arch/arm/common => drivers/clk}/clkdev.c |   57 +++++++++++++++---
>  drivers/nor/cfi_flash.c                   |    8 +-
>  include/common.h                          |    1 -
>  include/driver.h                          |   12 ++--
>  include/linux/clkdev.h                    |   36 +++++++++++
>  include/linux/kernel.h                    |   20 ++++++
>  include/linux/types.h                     |    2 +
>  lib/Makefile                              |    1 -
>  lib/display_options.c                     |   60 -------------------
>  lib/driver.c                              |   16 ++---
>  lib/vsprintf.c                            |   91 +++++++++++++++++++++++++++++
>  34 files changed, 250 insertions(+), 141 deletions(-)
>  delete mode 100644 arch/arm/common/Kconfig
>  delete mode 100644 arch/arm/common/Makefile
>  create mode 100644 drivers/clk/Kconfig
>  create mode 100644 drivers/clk/Makefile
>  rename {arch/arm/common => drivers/clk}/clkdev.c (74%)
>  create mode 100644 include/linux/clkdev.h
>  delete mode 100644 lib/display_options.c
> 
> Best Regards,
> J.
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2010-09-16 10:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02 14:10 [PATCH 0/9] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 1/9] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 2/9] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 3/9] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 4/9] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 5/9] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 15:29   ` Uwe Kleine-König
2010-09-02 15:32     ` Uwe Kleine-König
     [not found]       ` <20100902155421.GB28968@game.jcrosoft.org>
2010-09-02 17:54         ` Uwe Kleine-König
2010-09-02 14:10 ` [PATCH 6/9] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 7/9] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 8/9] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 14:10 ` [PATCH 9/9] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 15:22   ` Uwe Kleine-König
2010-09-02 19:40 ` [PATCH 0/9 V2] preperation for sh adding Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 1/9 V2] types.h: move __kernel_dev_t to include/linux/types.h Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 2/9 V2] device: fix dev_name Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 3/9 V2] stm8815: fix the uart device clock match Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 4/9 V2] arm: move clkdev to drivers/clk Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 5/9 V2] vsprintf: add %w and %w support to print unit Jean-Christophe PLAGNIOL-VILLARD
2010-09-03 18:34     ` Uwe Kleine-König
2010-09-02 19:41   ` [PATCH 6/9 V2] at91/clock: switch to %w for clock info printing Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 7/9 V2] cfi_flash: use %W and IEEE 1541 format Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 8/9 V2] use %W instead of size_human_readable and use " Jean-Christophe PLAGNIOL-VILLARD
2010-09-02 19:41   ` [PATCH 9/9 V2] clkdev: add print clk info command Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 10:38   ` [PATCH 0/9 V2] preperation for sh adding Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox