summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-05-06 09:30:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-05-06 09:30:50 +0200
commitc19efab88606a974c050aa6caa9ec1803f88bdc9 (patch)
tree552a1520368f3d1500f7ad7d519e8e0d7758f367
parentda1ada40d27c734ec51f1da924b2ecbbd28115c1 (diff)
parent2f24a5c33c9b9034e412b52ec88c1019307c14f0 (diff)
downloadbarebox-c19efab88606a974c050aa6caa9ec1803f88bdc9.tar.gz
barebox-c19efab88606a974c050aa6caa9ec1803f88bdc9.tar.xz
Merge branch 'for-next/param'
Conflicts: drivers/mci/mci-core.c
-rw-r--r--arch/arm/boards/at91sam9m10ihd/hw_version.c6
-rw-r--r--arch/arm/boards/at91sam9x5ek/hw_version.c6
-rw-r--r--arch/arm/boards/sama5d3xek/hw_version.c6
-rw-r--r--arch/arm/mach-imx/iim.c65
-rw-r--r--arch/arm/mach-mxs/ocotp.c34
-rw-r--r--common/console.c26
-rw-r--r--drivers/amba/bus.c9
-rw-r--r--drivers/ata/disk_ata_drive.c21
-rw-r--r--drivers/input/qt1070.c6
-rw-r--r--drivers/mci/mci-core.c46
-rw-r--r--drivers/mtd/core.c13
-rw-r--r--drivers/mtd/nand/nand_base.c22
-rw-r--r--drivers/net/ksz8864rmn.c30
-rw-r--r--drivers/net/phy/mdio_bus.c8
-rw-r--r--drivers/pwm/core.c89
-rw-r--r--drivers/usb/core/usb.c19
-rw-r--r--drivers/usb/gadget/at91_udc.c23
-rw-r--r--drivers/video/fb.c33
-rw-r--r--drivers/video/imx-ipu-fb.c27
-rw-r--r--drivers/video/imx.c26
-rw-r--r--include/ata_drive.h1
-rw-r--r--include/console.h2
-rw-r--r--include/fb.h1
-rw-r--r--include/linux/mtd/mtd.h1
-rw-r--r--include/mci.h2
-rw-r--r--include/net.h7
-rw-r--r--include/param.h66
-rw-r--r--lib/parameter.c302
-rw-r--r--net/eth.c40
-rw-r--r--net/net.c80
-rw-r--r--net/netconsole.c50
31 files changed, 538 insertions, 529 deletions
diff --git a/arch/arm/boards/at91sam9m10ihd/hw_version.c b/arch/arm/boards/at91sam9m10ihd/hw_version.c
index be910dfbc0..8e729013c7 100644
--- a/arch/arm/boards/at91sam9m10ihd/hw_version.c
+++ b/arch/arm/boards/at91sam9m10ihd/hw_version.c
@@ -194,10 +194,8 @@ static void at91sam9m10ihd_devices_detect_one(const char *name)
dev_add_param_fixed(dev, "board", info.board_name);
sprintf(str, "%.2s", info.vendor_country);
dev_add_param_fixed(dev, "country", str);
- sprintf(str, "%d", info.year);
- dev_add_param_fixed(dev, "year", str);
- sprintf(str, "%d", info.week);
- dev_add_param_fixed(dev, "week", str);
+ dev_add_param_int_ro(dev, "year", info.year, "%d");
+ dev_add_param_int_ro(dev, "week", info.week, "%d");
sprintf(str, "%c", info.revision_code);
dev_add_param_fixed(dev, "revision_code", str);
sprintf(str, "%c", info.revision_id);
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index 76d4e1b8fa..91af331194 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -219,10 +219,8 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
dev_add_param_fixed(dev, "board", info.board_name);
sprintf(str, "%.2s", info.vendor_country);
dev_add_param_fixed(dev, "country", str);
- sprintf(str, "%d", info.year);
- dev_add_param_fixed(dev, "year", str);
- sprintf(str, "%d", info.week);
- dev_add_param_fixed(dev, "week", str);
+ dev_add_param_int_ro(dev, "year", info.year, "%d");
+ dev_add_param_int_ro(dev, "week", info.week, "%d");
sprintf(str, "%c", info.revision_code);
dev_add_param_fixed(dev, "revision_code", str);
sprintf(str, "%c", info.revision_id);
diff --git a/arch/arm/boards/sama5d3xek/hw_version.c b/arch/arm/boards/sama5d3xek/hw_version.c
index 79fd63a349..450eb9f8a1 100644
--- a/arch/arm/boards/sama5d3xek/hw_version.c
+++ b/arch/arm/boards/sama5d3xek/hw_version.c
@@ -226,10 +226,8 @@ static void at91sama5d3xek_devices_detect_one(const char *name)
dev_add_param_fixed(dev, "board", bname);
sprintf(str, "%.2s", info.vendor_country);
dev_add_param_fixed(dev, "country", str);
- sprintf(str, "%d", info.year);
- dev_add_param_fixed(dev, "year", str);
- sprintf(str, "%d", info.week);
- dev_add_param_fixed(dev, "week", str);
+ dev_add_param_int_ro(dev, "year", info.year, "%d");
+ dev_add_param_int_ro(dev, "week", info.week, "%d");
sprintf(str, "%c", info.revision_board);
dev_add_param_fixed(dev, "revision_board", str);
sprintf(str, "%c", info.revision_schema);
diff --git a/arch/arm/mach-imx/iim.c b/arch/arm/mach-imx/iim.c
index 69ddc4d6a8..ce2bbafc90 100644
--- a/arch/arm/mach-imx/iim.c
+++ b/arch/arm/mach-imx/iim.c
@@ -33,6 +33,9 @@
static unsigned long mac_addr_base;
+static int iim_write_enable;
+static int iim_sense_enable;
+
struct iim_priv {
struct cdev cdev;
void __iomem *base;
@@ -88,14 +91,9 @@ static ssize_t imx_iim_cdev_read(struct cdev *cdev, void *buf, size_t count,
{
ulong size, i;
struct iim_priv *priv = cdev->priv;
- const char *sense_param;
- unsigned long explicit_sense = 0;
-
- if ((sense_param = dev_get_param(cdev->dev, "explicit_sense_enable")))
- explicit_sense = simple_strtoul(sense_param, NULL, 0);
size = min((loff_t)count, priv->banksize - offset);
- if (explicit_sense) {
+ if (iim_sense_enable) {
for (i = 0; i < size; i++) {
int row_val;
@@ -113,7 +111,6 @@ static ssize_t imx_iim_cdev_read(struct cdev *cdev, void *buf, size_t count,
return size;
}
-#ifdef CONFIG_IMX_IIM_FUSE_BLOW
static int do_fuse_blow(void __iomem *reg_base, unsigned int bank,
unsigned int row, u8 value)
{
@@ -173,22 +170,16 @@ out:
writeb(0, reg_base + IIM_PREG_P);
return ret;
}
-#endif /* CONFIG_IMX_IIM_FUSE_BLOW */
static ssize_t imx_iim_cdev_write(struct cdev *cdev, const void *buf, size_t count,
loff_t offset, ulong flags)
{
ulong size, i;
struct iim_priv *priv = cdev->priv;
- const char *write_param;
- unsigned int blow_enable = 0;
-
- if ((write_param = dev_get_param(cdev->dev, "permanent_write_enable")))
- blow_enable = simple_strtoul(write_param, NULL, 0);
size = min((loff_t)count, priv->banksize - offset);
-#ifdef CONFIG_IMX_IIM_FUSE_BLOW
- if (blow_enable) {
+
+ if (IS_ENABLED(CONFIG_IMX_IIM_FUSE_BLOW) && iim_write_enable) {
for (i = 0; i < size; i++) {
int ret;
@@ -197,9 +188,7 @@ static ssize_t imx_iim_cdev_write(struct cdev *cdev, const void *buf, size_t cou
if (ret < 0)
return ret;
}
- } else
-#endif /* CONFIG_IMX_IIM_FUSE_BLOW */
- {
+ } else {
for (i = 0; i < size; i++)
((u8 *)priv->bankbase)[(offset+i)*4] = ((u8 *)buf)[i];
}
@@ -213,21 +202,6 @@ static struct file_operations imx_iim_ops = {
.lseek = dev_lseek_default,
};
-static int imx_iim_blow_enable_set(struct device_d *dev, struct param_d *param,
- const char *val)
-{
- unsigned long blow_enable;
-
- if (val == NULL)
- return -EINVAL;
-
- blow_enable = simple_strtoul(val, NULL, 0);
- if (blow_enable > 1)
- return -EINVAL;
-
- return dev_param_set_generic(dev, param, blow_enable ? "1" : "0");
-}
-
static int imx_iim_add_bank(struct device_d *dev, void __iomem *base, int num)
{
struct iim_priv *priv;
@@ -254,7 +228,6 @@ static int imx_iim_add_bank(struct device_d *dev, void __iomem *base, int num)
static int imx_iim_probe(struct device_d *dev)
{
struct imx_iim_platform_data *pdata = dev->platform_data;
- int err;
int i;
void __iomem *base;
@@ -267,23 +240,13 @@ static int imx_iim_probe(struct device_d *dev)
imx_iim_add_bank(dev, base, i);
}
-#ifdef CONFIG_IMX_IIM_FUSE_BLOW
- err = dev_add_param(dev, "permanent_write_enable",
- imx_iim_blow_enable_set, NULL, 0);
- if (err < 0)
- return err;
- err = dev_set_param(dev, "permanent_write_enable", "0");
- if (err < 0)
- return err;
-#endif /* CONFIG_IMX_IIM_FUSE_BLOW */
-
- err = dev_add_param(dev, "explicit_sense_enable",
- imx_iim_blow_enable_set, NULL, 0);
- if (err < 0)
- return err;
- err = dev_set_param(dev, "explicit_sense_enable", "1");
- if (err < 0)
- return err;
+
+ if (IS_ENABLED(CONFIG_IMX_IIM_FUSE_BLOW))
+ dev_add_param_bool(dev, "permanent_write_enable",
+ NULL, NULL, &iim_write_enable, NULL);
+
+ dev_add_param_bool(dev, "explicit_sense_enable",
+ NULL, NULL, &iim_sense_enable, NULL);
return 0;
}
diff --git a/arch/arm/mach-mxs/ocotp.c b/arch/arm/mach-mxs/ocotp.c
index 84f38b580f..dd984467ef 100644
--- a/arch/arm/mach-mxs/ocotp.c
+++ b/arch/arm/mach-mxs/ocotp.c
@@ -44,6 +44,7 @@
struct ocotp_priv {
struct cdev cdev;
void __iomem *base;
+ unsigned int write_enable;
};
static int mxs_ocotp_wait_busy(struct ocotp_priv *priv)
@@ -103,18 +104,12 @@ static ssize_t mxs_ocotp_cdev_write(struct cdev *cdev, const void *buf, size_t c
{
struct ocotp_priv *priv = cdev->priv;
void __iomem *base = priv->base;
- const char *write_param;
- unsigned int write_enabled = 0;
unsigned long old_hclk, aligned_offset;
int old_vddio, num_words, num_bytes, i, ret = 0;
u8 *work_buf;
u32 reg;
- write_param = dev_get_param(cdev->dev, "permanent_write_enable");
- if (write_param)
- write_enabled = simple_strtoul(write_param, NULL, 0);
-
- if (!write_param || !write_enabled)
+ if (!priv->write_enable)
return -EPERM;
/* we can only work on u32, so calc some helpers */
@@ -179,21 +174,6 @@ static struct file_operations mxs_ocotp_ops = {
.lseek = dev_lseek_default,
};
-static int mxs_ocotp_write_enable_set(struct device_d *dev, struct param_d *param,
- const char *val)
-{
- unsigned long write_enable;
-
- if (!val)
- return -EINVAL;
-
- write_enable = simple_strtoul(val, NULL, 0);
- if (write_enable > 1)
- return -EINVAL;
-
- return dev_param_set_generic(dev, param, write_enable ? "1" : "0");
-}
-
static int mxs_ocotp_probe(struct device_d *dev)
{
int err;
@@ -212,14 +192,8 @@ static int mxs_ocotp_probe(struct device_d *dev)
if (IS_ENABLED(CONFIG_MXS_OCOTP_WRITABLE)) {
mxs_ocotp_ops.write = mxs_ocotp_cdev_write;
-
- err = dev_add_param(dev, "permanent_write_enable",
- mxs_ocotp_write_enable_set, NULL, 0);
- if (err < 0)
- return err;
- err = dev_set_param(dev, "permanent_write_enable", "0");
- if (err < 0)
- return err;
+ dev_add_param_bool(dev, "permanent_write_enable",
+ NULL, NULL, &priv->write_enable, NULL);
}
return 0;
diff --git a/common/console.c b/common/console.c
index beb37bddc1..a0a06f6300 100644
--- a/common/console.c
+++ b/common/console.c
@@ -99,33 +99,22 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
return 0;
}
-static int console_baudrate_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int console_baudrate_set(struct param_d *param, void *priv)
{
- struct console_device *cdev = to_console_dev(dev);
- int baudrate;
- char baudstr[16];
+ struct console_device *cdev = priv;
unsigned char c;
- if (!val)
- dev_param_set_generic(dev, param, NULL);
-
- baudrate = simple_strtoul(val, NULL, 10);
-
if (cdev->f_active) {
printf("## Switch baudrate to %d bps and press ENTER ...\n",
- baudrate);
+ cdev->baudrate);
mdelay(50);
- cdev->setbrg(cdev, baudrate);
+ cdev->setbrg(cdev, cdev->baudrate);
mdelay(50);
do {
c = getc();
} while (c != '\r' && c != '\n');
} else
- cdev->setbrg(cdev, baudrate);
-
- sprintf(baudstr, "%d", baudrate);
- dev_param_set_generic(dev, param, baudstr);
+ cdev->setbrg(cdev, cdev->baudrate);
return 0;
}
@@ -155,8 +144,9 @@ int console_register(struct console_device *newcdev)
platform_device_register(dev);
if (newcdev->setbrg) {
- dev_add_param(dev, "baudrate", console_baudrate_set, NULL, 0);
- dev_set_param(dev, "baudrate", __stringify(CONFIG_BAUDRATE));
+ newcdev->baudrate = CONFIG_BAUDRATE;
+ dev_add_param_int(dev, "baudrate", console_baudrate_set,
+ NULL, &newcdev->baudrate, "%u", newcdev);
}
dev_add_param(dev, "active", console_std_set, NULL, 0);
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 7d7a6541ac..6106252264 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -153,14 +153,9 @@ int amba_device_add(struct amba_device *dev)
if (ret)
goto err_release;
- if (IS_ENABLED(CONFIG_PARAMETER)) {
- char str[16];
+ dev_add_param_int_ro(&dev->dev, "periphid", dev->periphid, "0x%08x");
- sprintf(str, "0x%08x", dev->periphid);
- dev_add_param_fixed(&dev->dev, "periphid", str);
- }
-
- return ret;
+ return ret;
err_release:
release_region(res);
return ret;
diff --git a/drivers/ata/disk_ata_drive.c b/drivers/ata/disk_ata_drive.c
index 6fe526acc8..2cff584d2a 100644
--- a/drivers/ata/disk_ata_drive.c
+++ b/drivers/ata/disk_ata_drive.c
@@ -325,20 +325,18 @@ on_error:
return rc;
}
-static int ata_set_probe(struct device_d *class_dev, struct param_d *param,
- const char *val)
+static int ata_set_probe(struct param_d *param, void *priv)
{
- struct ata_port *port = container_of(class_dev, struct ata_port, class_dev);
- int ret, probe;
+ struct ata_port *port = priv;
+ int ret;
- if (port->initialized) {
- dev_info(class_dev, "already initialized\n");
+ if (!port->probe)
return 0;
- }
- probe = !!simple_strtoul(val, NULL, 0);
- if (!probe)
+ if (port->initialized) {
+ dev_info(&port->class_dev, "already initialized\n");
return 0;
+ }
ret = ata_port_init(port);
if (ret)
@@ -346,7 +344,7 @@ static int ata_set_probe(struct device_d *class_dev, struct param_d *param,
port->initialized = 1;
- return dev_param_set_generic(class_dev, param, "1");
+ return 0;
}
/**
@@ -367,7 +365,8 @@ int ata_port_register(struct ata_port *port)
if (ret)
return ret;
- dev_add_param(&port->class_dev, "probe", ata_set_probe, NULL, 0);
+ dev_add_param_bool(&port->class_dev, "probe", ata_set_probe,
+ NULL, &port->probe, port);
return ret;
}
diff --git a/drivers/input/qt1070.c b/drivers/input/qt1070.c
index 43ea8823be..7f51da0e3d 100644
--- a/drivers/input/qt1070.c
+++ b/drivers/input/qt1070.c
@@ -239,10 +239,8 @@ static int qt1070_probe(struct device_d *dev)
goto err;
}
- sprintf(buf, "0x%x", fw_version);
- dev_add_param_fixed(dev, "fw_version", buf);
- sprintf(buf, "0x%x", chip_id);
- dev_add_param_fixed(dev, "chip_ip", buf);
+ dev_add_param_int_ro(dev, "fw_version", fw_version, "0x%x");
+ dev_add_param_int_ro(dev, "chip_ip", chip_id, "0x%x");
memcpy(data->code, default_code, sizeof(int) * ARRAY_SIZE(default_code));
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index e74fcecd4d..90ac2a3748 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -34,6 +34,7 @@
#include <asm/byteorder.h>
#include <block.h>
#include <disks.h>
+#include <linux/err.h>
#define MAX_BUFFER_NUMBER 0xffffffff
@@ -1460,46 +1461,23 @@ on_error:
* @param val "0" does nothing, a "1" will probe for a MCI card
* @return 0 on success
*/
-static int mci_set_probe(struct device_d *mci_dev, struct param_d *param,
- const char *val)
+static int mci_set_probe(struct param_d *param, void *priv)
{
- struct mci *mci = mci_dev->priv;
- int rc, probe;
+ struct mci *mci = priv;
+ int rc;
+
+ if (!mci->probe)
+ return 0;
rc = mci_check_if_already_initialized(mci);
if (rc != 0)
return 0;
- if (!val)
- return -EINVAL;
-
- probe = simple_strtoul(val, NULL, 0);
- if (probe != 0) {
- rc = mci_card_probe(mci);
- if (rc != 0)
- return rc;
- }
-
- return dev_param_set_generic(mci_dev, param, val);
-}
-
-/**
- * Add parameter to the MCI device on demand
- * @param mci_dev MCI device instance
- * @return 0 on success
- *
- * This parameter is only available (or usefull) if MCI card probing is delayed
- */
-static int add_mci_parameter(struct device_d *mci_dev)
-{
- int rc;
-
- /* provide a 'probing right now' parameter for the user */
- rc = dev_add_param(mci_dev, "probe", mci_set_probe, NULL, 0);
+ rc = mci_card_probe(mci);
if (rc != 0)
return rc;
- return dev_set_param(mci_dev, "probe", "0");
+ return 0;
}
/**
@@ -1522,8 +1500,10 @@ static int mci_probe(struct device_d *mci_dev)
dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(mci_dev));
- rc = add_mci_parameter(mci_dev);
- if (rc != 0) {
+ mci->param_probe = dev_add_param_bool(mci_dev, "probe",
+ mci_set_probe, NULL, &mci->probe, mci);
+
+ if (IS_ERR(mci->param_probe)) {
dev_dbg(mci->mci_dev, "Failed to add 'probe' parameter to the MCI device\n");
goto on_error;
}
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index e28d9257a9..61744b69dc 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -286,7 +286,6 @@ static struct file_operations mtd_ops = {
int add_mtd_device(struct mtd_info *mtd, char *devname)
{
- char str[16];
struct mtddev_hook *hook;
if (!devname)
@@ -305,14 +304,10 @@ int add_mtd_device(struct mtd_info *mtd, char *devname)
mtd->cdev.mtd = mtd;
if (IS_ENABLED(CONFIG_PARAMETER)) {
- sprintf(str, "%u", mtd->size);
- dev_add_param_fixed(&mtd->class_dev, "size", str);
- sprintf(str, "%u", mtd->erasesize);
- dev_add_param_fixed(&mtd->class_dev, "erasesize", str);
- sprintf(str, "%u", mtd->writesize);
- dev_add_param_fixed(&mtd->class_dev, "writesize", str);
- sprintf(str, "%u", mtd->oobsize);
- dev_add_param_fixed(&mtd->class_dev, "oobsize", str);
+ dev_add_param_int_ro(&mtd->class_dev, "size", mtd->size, "%u");
+ dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u");
+ dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->oobsize, "%u");
+ dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
}
devfs_create(&mtd->cdev);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index c63aaf9dc1..e8103cf562 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -1671,18 +1671,20 @@ EXPORT_SYMBOL(nand_scan_ident);
EXPORT_SYMBOL(nand_scan_tail);
EXPORT_SYMBOL(nand_release);
-static int mtd_set_erasebad(struct device_d *dev, struct param_d *param,
- const char *val)
+static int mtd_set_erasebad(struct param_d *param, void *priv)
{
- struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
- int erasebad;
+ struct mtd_info *mtd = priv;
- erasebad = simple_strtoul(val, NULL, 0);
+ if (!mtd->p_allow_erasebad) {
+ mtd->allow_erasebad = false;
+ return 0;
+ }
- if (erasebad && !mtd->allow_erasebad)
- dev_warn(dev, "Allowing to erase bad blocks. This may be dangerous!\n");
+ if (!mtd->allow_erasebad)
+ dev_warn(&mtd->class_dev,
+ "Allowing to erase bad blocks. This may be dangerous!\n");
- mtd->allow_erasebad = erasebad ? true : false;
+ mtd->allow_erasebad = true;
return 0;
}
@@ -1713,8 +1715,8 @@ int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
return ret;
if (IS_ENABLED(CONFIG_NAND_ALLOW_ERASE_BAD))
- dev_add_param(&mtd->class_dev, "erasebad", mtd_set_erasebad,
- NULL, 0);
+ dev_add_param_bool(&mtd->class_dev, "erasebad", mtd_set_erasebad,
+ NULL, &mtd->p_allow_erasebad, mtd);
dev_add_param(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type, 0);
diff --git a/drivers/net/ksz8864rmn.c b/drivers/net/ksz8864rmn.c
index af3c12489c..ec3e9f78ab 100644
--- a/drivers/net/ksz8864rmn.c
+++ b/drivers/net/ksz8864rmn.c
@@ -49,6 +49,7 @@
struct micrel_switch_priv {
struct cdev cdev;
struct spi_device *spi;
+ unsigned int p_enable;
};
static int micrel_switch_read_reg(struct spi_device *spi, uint8_t reg)
@@ -78,27 +79,15 @@ static void micrel_switch_write_reg(struct spi_device *spi, uint8_t reg, uint8_t
spi_write_then_read(spi, tx, 3, NULL, 0);
}
-static int micrel_switch_enable_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int micrel_switch_enable_set(struct param_d *param, void *_priv)
{
- struct spi_device *spi = (struct spi_device *)dev->type_data;
- int enable;
- char *new;
+ struct micrel_switch_priv *priv = _priv;
+ struct spi_device *spi = priv->spi;
- if (!val)
- return dev_param_set_generic(dev, param, NULL);
-
- enable = simple_strtoul(val, NULL, 0);
-
- if (enable) {
+ if (priv->p_enable)
micrel_switch_write_reg(spi, REG_ID1, 1);
- new = "1";
- } else {
+ else
micrel_switch_write_reg(spi, REG_ID1, 0);
- new = "0";
- }
-
- dev_param_set_generic(dev, param, new);
return 0;
}
@@ -172,8 +161,11 @@ static int micrel_switch_probe(struct device_d *dev)
priv->cdev.dev = dev;
devfs_create(&priv->cdev);
- dev_add_param(dev, "enable", micrel_switch_enable_set, NULL, 0);
- dev_set_param(dev, "enable", "1");
+ dev_add_param_bool(dev, "enable", micrel_switch_enable_set,
+ NULL, &priv->p_enable, priv);
+
+ priv->p_enable = 1;
+ micrel_switch_write_reg(priv->spi, REG_ID1, 1);
return 0;
}
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index e1bb7b1235..6163a50652 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -152,7 +152,6 @@ static int mdio_bus_probe(struct device_d *_dev)
struct phy_driver *drv = to_phy_driver(_dev->driver);
int ret;
- char str[16];
dev->attached_dev->phydev = dev;
@@ -192,11 +191,8 @@ static int mdio_bus_probe(struct device_d *_dev)
if ((dev->supported & SUPPORTED_Autoneg) == 0)
dev->autoneg = AUTONEG_DISABLE;
- sprintf(str, "%d", dev->addr);
- dev_add_param_fixed(&dev->dev, "phy_addr", str);
-
- sprintf(str, "0x%08x", dev->phy_id);
- dev_add_param_fixed(&dev->dev, "phy_id", str);
+ dev_add_param_int_ro(&dev->dev, "phy_addr", dev->addr, "%d");
+ dev_add_param_int_ro(&dev->dev, "phy_id", dev->phy_id, "0x%08x");
dev->cdev.name = asprintf("phy%d", _dev->id);
dev->cdev.size = 64;
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 70ec5901a0..db7d260c00 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -18,6 +18,7 @@
#include <malloc.h>
#include <pwm.h>
#include <linux/list.h>
+#include <linux/err.h>
struct pwm_device {
struct pwm_chip *chip;
@@ -26,22 +27,14 @@ struct pwm_device {
#define FLAG_ENABLED 1
struct list_head node;
struct device_d *dev;
+
+ unsigned int duty_ns;
+ unsigned int period_ns;
+ unsigned int p_enable;
};
static LIST_HEAD(pwm_list);
-static struct pwm_device *dev_to_pwm(struct device_d *dev)
-{
- struct pwm_device *pwm;
-
- list_for_each_entry(pwm, &pwm_list, node) {
- if (pwm->dev == dev)
- return pwm;
- }
-
- return NULL;
-}
-
static struct pwm_device *_find_pwm(const char *devname)
{
struct pwm_device *pwm;
@@ -54,61 +47,25 @@ static struct pwm_device *_find_pwm(const char *devname)
return NULL;
}
-static int set_period_ns(struct device_d *dev, struct param_d *p,
- const char *val)
+static int set_duty_period_ns(struct param_d *p, void *priv)
{
- struct pwm_device *pwm = dev_to_pwm(dev);
- int period_ns;
+ struct pwm_device *pwm = priv;
- if (!val)
- return dev_param_set_generic(dev, p, NULL);
+ pwm_config(pwm, pwm->chip->duty_ns, pwm->chip->period_ns);
- period_ns = simple_strtoul(val, NULL, 0);
- pwm_config(pwm, pwm->chip->duty_ns, period_ns);
- return dev_param_set_generic(dev, p, val);
-}
-
-static int set_duty_ns(struct device_d *dev, struct param_d *p, const char *val)
-{
- struct pwm_device *pwm = dev_to_pwm(dev);
- int duty_ns;
-
- if (!val)
- return dev_param_set_generic(dev, p, NULL);
-
- duty_ns = simple_strtoul(val, NULL, 0);
- pwm_config(pwm, duty_ns, pwm->chip->period_ns);
- return dev_param_set_generic(dev, p, val);
+ return 0;
}
-static int set_enable(struct device_d *dev, struct param_d *p, const char *val)
+static int set_enable(struct param_d *p, void *priv)
{
- struct pwm_device *pwm = dev_to_pwm(dev);
- int enable;
-
- if (!val)
- return dev_param_set_generic(dev, p, NULL);
+ struct pwm_device *pwm = priv;
- enable = !!simple_strtoul(val, NULL, 0);
- if (enable)
+ if (pwm->p_enable)
pwm_enable(pwm);
else
pwm_disable(pwm);
- return dev_param_set_generic(dev, p, enable ? "1" : "0");
-}
-static int pwm_register_vars(struct device_d *dev)
-{
- int ret;
-
- ret = dev_add_param(dev, "duty_ns", set_duty_ns, NULL, 0);
- if (!ret)
- ret = dev_add_param(dev, "period_ns", set_period_ns, NULL, 0);
- if (!ret)
- ret = dev_add_param(dev, "enable", set_enable, NULL, 0);
- if (!ret)
- ret = dev_set_param(dev, "enable", 0);
- return ret;
+ return 0;
}
/**
@@ -121,7 +78,7 @@ static int pwm_register_vars(struct device_d *dev)
int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
{
struct pwm_device *pwm;
- int ret = 0;
+ struct param_d *p;
if (_find_pwm(chip->devname))
return -EBUSY;
@@ -131,9 +88,23 @@ int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
pwm->dev = dev;
list_add_tail(&pwm->node, &pwm_list);
- pwm_register_vars(dev);
- return ret;
+ p = dev_add_param_int(dev, "duty_ns", set_duty_period_ns,
+ NULL, &pwm->chip->duty_ns, "%u", pwm);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
+ p = dev_add_param_int(dev, "period_ns", set_duty_period_ns,
+ NULL, &pwm->chip->period_ns, "%u", pwm);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
+ p = dev_add_param_bool(dev, "enable", set_enable,
+ NULL, &pwm->p_enable, pwm);
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
+ return 0;
}
EXPORT_SYMBOL_GPL(pwmchip_add);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a813be5ca4..9a0723a2ed 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -439,19 +439,20 @@ static int usb_new_device(struct usb_device *dev)
print_usb_device(dev);
register_device(&dev->dev);
- sprintf(str, "%d", dev->descriptor->iManufacturer);
- dev_add_param_fixed(&dev->dev, "iManufacturer", str);
- sprintf(str, "%d", dev->descriptor->iProduct);
- dev_add_param_fixed(&dev->dev, "iProduct", str);
- sprintf(str, "%d", dev->descriptor->iSerialNumber);
+ dev_add_param_int_ro(&dev->dev, "iManufacturer",
+ dev->descriptor->iManufacturer, "%d");
+ dev_add_param_int_ro(&dev->dev, "iProduct",
+ dev->descriptor->iProduct, "%d");
+ dev_add_param_int_ro(&dev->dev, "iSerialNumber",
+ dev->descriptor->iSerialNumber, "%d");
dev_add_param_fixed(&dev->dev, "iSerialNumber", str);
dev_add_param_fixed(&dev->dev, "Manufacturer", dev->mf);
dev_add_param_fixed(&dev->dev, "Product", dev->prod);
dev_add_param_fixed(&dev->dev, "SerialNumber", dev->serial);
- sprintf(str, "%04x", le16_to_cpu(dev->descriptor->idVendor));
- dev_add_param_fixed(&dev->dev, "idVendor", str);
- sprintf(str, "%04x", le16_to_cpu(dev->descriptor->idProduct));
- dev_add_param_fixed(&dev->dev, "idProduct", str);
+ dev_add_param_int_ro(&dev->dev, "idVendor",
+ le16_to_cpu(dev->descriptor->idVendor), "%04x");
+ dev_add_param_int_ro(&dev->dev, "idProduct",
+ le16_to_cpu(dev->descriptor->idProduct), "%04x");
list_add_tail(&dev->list, &usb_device_list);
err = 0;
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 917ec4d006..a11379c933 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1316,17 +1316,9 @@ static struct at91_udc controller = {
static void at91_udc_irq (void *_udc);
-static void at91_update_vbus(struct at91_udc *udc, u32 value)
+static int at91_udc_vbus_set(struct param_d *p, void *priv)
{
- if (value == udc->gpio_vbus_val)
- return;
-
- if (value)
- dev_set_param(udc->dev, "vbus", "1");
- else
- dev_set_param(udc->dev, "vbus", "0");
-
- udc->gpio_vbus_val = value;
+ return -EROFS;
}
int usb_gadget_poll(void)
@@ -1340,11 +1332,10 @@ int usb_gadget_poll(void)
value = gpio_get_value(udc->board.vbus_pin);
value ^= udc->board.vbus_active_low;
- if (!value) {
- at91_update_vbus(udc, value);
+ udc->gpio_vbus_val = value;
+
+ if (!value)
return 0;
- }
- at91_update_vbus(udc, value);
value = at91_udp_read(udc, AT91_UDP_ISR) & (~(AT91_UDP_SOFINT));
if (value)
@@ -1516,8 +1507,8 @@ static int __init at91udc_probe(struct device_d *dev)
udc->vbus = 1;
}
- dev_add_param(dev, "vbus", NULL, NULL, 0);
- dev_set_param(dev, "vbus", "0");
+ dev_add_param_bool(dev, "vbus",
+ at91_udc_vbus_set, NULL, &udc->gpio_vbus_val, udc);
poller_register(&poller);
diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index be2969540d..0e00cb7675 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -28,31 +28,22 @@ static int fb_ioctl(struct cdev* cdev, int req, void *data)
return 0;
}
-static int fb_enable_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int fb_enable_set(struct param_d *param, void *priv)
{
- struct fb_info *info = dev->priv;
+ struct fb_info *info = priv;
int enable;
- char *new;
-
- if (!val)
- return dev_param_set_generic(dev, param, NULL);
- enable = simple_strtoul(val, NULL, 0);
+ enable = info->p_enable;
- if (enable) {
- if (!info->enabled)
- info->fbops->fb_enable(info);
- new = "1";
- } else {
- if (info->enabled)
- info->fbops->fb_disable(info);
- new = "0";
- }
+ if (enable == info->enabled)
+ return 0;
- dev_param_set_generic(dev, param, new);
+ if (enable)
+ info->fbops->fb_enable(info);
+ else
+ info->fbops->fb_disable(info);
- info->enabled = !!enable;
+ info->enabled = enable;
return 0;
}
@@ -165,8 +156,8 @@ static int fb_probe(struct device_d *dev)
{
struct fb_info *info = dev->priv;
- dev_add_param(dev, "enable", fb_enable_set, NULL, 0);
- dev_set_param(dev, "enable", "0");
+ dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
+ &info->p_enable, info);
if (info->num_modes && (info->mode_list != NULL) &&
(info->fbops->fb_activate_var != NULL)) {
diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index db8b8323b0..b2ed7237c7 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -39,6 +39,8 @@ struct ipu_fb_info {
struct fb_info info;
struct fb_info overlay;
struct device_d *dev;
+
+ unsigned int alpha;
};
/* IPU DMA Controller channel definitions. */
@@ -914,27 +916,17 @@ static struct fb_ops ipu_fb_overlay_ops = {
.fb_disable = ipu_fb_overlay_disable_controller,
};
-static int sdc_alpha_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int sdc_alpha_set(struct param_d *param, void *priv)
{
- struct fb_info *info = dev->priv;
+ struct fb_info *info = priv;
struct ipu_fb_info *fbi = info->priv;
- int alpha;
- char alphastr[16];
unsigned int tmp;
- if (!val)
- return dev_param_set_generic(dev, param, NULL);
-
- alpha = simple_strtoul(val, NULL, 0);
- alpha &= 0xff;
+ if (fbi->alpha > 0xff)
+ fbi->alpha = 0xff;
tmp = reg_read(fbi, SDC_GW_CTRL) & 0x00FFFFFFL;
- reg_write(fbi, tmp | ((u32) alpha << 24), SDC_GW_CTRL);
-
- sprintf(alphastr, "%d", alpha);
-
- dev_param_set_generic(dev, param, alphastr);
+ reg_write(fbi, tmp | ((u32) fbi->alpha << 24), SDC_GW_CTRL);
return 0;
}
@@ -968,8 +960,9 @@ static int sdc_fb_register_overlay(struct ipu_fb_info *fbi, void *fb)
return ret;
}
- dev_add_param(&overlay->dev, "alpha", sdc_alpha_set, NULL, 0);
- dev_set_param(&overlay->dev, "alpha", "0");
+ dev_add_param_int(&overlay->dev, "alpha", sdc_alpha_set,
+ NULL, &fbi->alpha, "%u", overlay);
+
return 0;
}
diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index 736e8d08e2..6e2d8d6f73 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -158,6 +158,8 @@ struct imxfb_info {
void (*enable)(int enable);
+ unsigned int alpha;
+
struct fb_info overlay;
};
@@ -421,30 +423,20 @@ static struct fb_ops imxfb_overlay_ops = {
.fb_disable = imxfb_overlay_disable_controller,
};
-static int imxfb_alpha_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int imxfb_alpha_set(struct param_d *param, void *priv)
{
- struct fb_info *overlay = dev->priv;
+ struct fb_info *overlay = priv;
struct imxfb_info *fbi = overlay->priv;
- int alpha;
- char alphastr[16];
unsigned int tmp;
- if (!val)
- return dev_param_set_generic(dev, param, NULL);
-
- alpha = simple_strtoul(val, NULL, 0);
- alpha &= 0xff;
+ if (fbi->alpha > 0xff)
+ fbi->alpha = 0xff;
tmp = readl(fbi->regs + LCDC_LGWCR);
tmp &= ~LGWCR_GWAV(0xff);
- tmp |= LGWCR_GWAV(alpha);
+ tmp |= LGWCR_GWAV(fbi->alpha);
writel(tmp , fbi->regs + LCDC_LGWCR);
- sprintf(alphastr, "%d", alpha);
-
- dev_param_set_generic(dev, param, alphastr);
-
return 0;
}
@@ -508,8 +500,8 @@ static int imxfb_register_overlay(struct imxfb_info *fbi, void *fb)
return ret;
}
- dev_add_param(&overlay->dev, "alpha", imxfb_alpha_set, NULL, 0);
- dev_set_param(&overlay->dev, "alpha", "0");
+ dev_add_param_int(&overlay->dev, "alpha", imxfb_alpha_set,
+ NULL, &fbi->alpha, "%u", overlay);
return 0;
}
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 4f8b6c05fd..049082f0ca 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -95,6 +95,7 @@ struct ata_port {
struct block_device blk;
uint16_t *id;
int initialized;
+ int probe;
};
int ide_port_register(struct device_d *, struct ata_ioports *);
diff --git a/include/console.h b/include/console.h
index c45feb4785..72cf99f55b 100644
--- a/include/console.h
+++ b/include/console.h
@@ -42,6 +42,8 @@ struct console_device {
unsigned char f_caps;
unsigned char f_active;
+
+ unsigned int baudrate;
};
int console_register(struct console_device *cdev);
diff --git a/include/fb.h b/include/fb.h
index c5944184b1..23d6c6d025 100644
--- a/include/fb.h
+++ b/include/fb.h
@@ -102,6 +102,7 @@ struct fb_info {
struct fb_bitfield transp; /* transparency */
int enabled;
+ int p_enable;
};
int register_framebuffer(struct fb_info *info);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 390f4b0767..df04030473 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -208,6 +208,7 @@ struct mtd_info {
/* If true erasing bad blocks is allowed, this is set via a device parameter */
bool allow_erasebad;
+ int p_allow_erasebad;
};
int mtd_erase(struct mtd_info *mtd, struct erase_info *instr);
diff --git a/include/mci.h b/include/mci.h
index cf9582dbe3..eca48a52f4 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -328,6 +328,8 @@ struct mci {
uint64_t capacity; /**< Card's data capacity in bytes */
int ready_for_use; /** true if already probed */
char *ext_csd;
+ int probe;
+ struct param_d *param_probe;
};
int mci_register(struct mci_host*);
diff --git a/include/net.h b/include/net.h
index e4f6f86ad0..bb6b8fa281 100644
--- a/include/net.h
+++ b/include/net.h
@@ -52,6 +52,12 @@ struct eth_device {
struct device_d *parent;
struct list_head list;
+
+ IPaddr_t ipaddr;
+ IPaddr_t serverip;
+ IPaddr_t netmask;
+ IPaddr_t gateway;
+ char ethaddr[6];
};
#define dev_to_edev(d) container_of(d, struct eth_device, dev)
@@ -384,7 +390,6 @@ typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
void eth_set_current(struct eth_device *eth);
struct eth_device *eth_get_current(void);
struct eth_device *eth_get_byname(char *name);
-void net_update_env(void);
/**
* net_receive - Pass a received packet from an ethernet driver to the protocol stack
diff --git a/include/param.h b/include/param.h
index 3a585cd193..4af2d09c4c 100644
--- a/include/param.h
+++ b/include/param.h
@@ -15,6 +15,8 @@ struct param_d {
unsigned int flags;
char *name;
char *value;
+ struct device_d *dev;
+ void *driver_priv;
struct list_head list;
};
@@ -28,18 +30,33 @@ int dev_add_param(struct device_d *dev, const char *name,
const char *(*get)(struct device_d *, struct param_d *p),
unsigned long flags);
+struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, const char *format, void *priv);
+
+struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, void *priv);
+
+struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
+ int value, const char *format);
+
+struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ IPaddr_t *ip, void *priv);
+
int dev_add_param_fixed(struct device_d *dev, char *name, char *value);
-void dev_remove_param(struct device_d *dev, char *name);
+void dev_remove_param(struct param_d *p);
void dev_remove_parameters(struct device_d *dev);
int dev_param_set_generic(struct device_d *dev, struct param_d *p,
const char *val);
-/* Convenience functions to handle a parameter as an ip address */
-int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip);
-IPaddr_t dev_get_param_ip(struct device_d *dev, char *name);
#else
static inline const char *dev_get_param(struct device_d *dev, const char *name)
{
@@ -64,31 +81,50 @@ static inline int dev_add_param(struct device_d *dev, char *name,
return 0;
}
-static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *value)
+static inline struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, const char *format, void *priv)
{
- return 0;
+ return NULL;
}
-static inline void dev_remove_param(struct device_d *dev, char *name) {}
+static inline struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, void *priv)
+{
+ return NULL;
+}
-static inline void dev_remove_parameters(struct device_d *dev) {}
+static inline struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
+ int value, const char *format)
+{
+ return NULL;
+}
-static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p,
- const char *val)
+static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ IPaddr_t *ip, void *priv)
{
- return 0;
+ return NULL;
}
-/* Convenience functions to handle a parameter as an ip address */
-static inline int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip)
+static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *value)
{
return 0;
}
-static inline IPaddr_t dev_get_param_ip(struct device_d *dev, char *name)
+
+static inline void dev_remove_param(struct param_d *p) {}
+
+static inline void dev_remove_parameters(struct device_d *dev) {}
+
+static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p,
+ const char *val)
{
return 0;
}
#endif
#endif /* PARAM_H */
-
diff --git a/lib/parameter.c b/lib/parameter.c
index c00b82438d..e47e8b9148 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -27,6 +27,7 @@
#include <net.h>
#include <malloc.h>
#include <driver.h>
+#include <linux/err.h>
struct param_d *get_param_by_name(struct device_d *dev, const char *name)
{
@@ -58,23 +59,6 @@ const char *dev_get_param(struct device_d *dev, const char *name)
return param->get(dev, param);
}
-#ifdef CONFIG_NET
-IPaddr_t dev_get_param_ip(struct device_d *dev, char *name)
-{
- IPaddr_t ip;
-
- if (string_to_ip(dev_get_param(dev, name), &ip))
- return 0;
-
- return ip;
-}
-
-int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip)
-{
- return dev_set_param(dev, name, ip_to_string(ip));
-}
-#endif
-
/**
* dev_set_param - set a parameter of a device to a new value
* @param dev The device
@@ -139,14 +123,13 @@ static const char *param_get_generic(struct device_d *dev, struct param_d *p)
return p->value ? p->value : "";
}
-static struct param_d *__dev_add_param(struct device_d *dev, const char *name,
+static int __dev_add_param(struct param_d *param, struct device_d *dev, const char *name,
int (*set)(struct device_d *dev, struct param_d *p, const char *val),
const char *(*get)(struct device_d *dev, struct param_d *p),
unsigned long flags)
{
- struct param_d *param;
-
- param = xzalloc(sizeof(*param));
+ if (get_param_by_name(dev, name))
+ return -EEXIST;
if (set)
param->set = set;
@@ -159,9 +142,10 @@ static struct param_d *__dev_add_param(struct device_d *dev, const char *name,
param->name = strdup(name);
param->flags = flags;
+ param->dev = dev;
list_add_tail(&param->list, &dev->parameters);
- return param;
+ return 0;
}
/**
@@ -183,14 +167,15 @@ int dev_add_param(struct device_d *dev, const char *name,
unsigned long flags)
{
struct param_d *param;
+ int ret;
- param = get_param_by_name(dev, name);
- if (param)
- return -EEXIST;
+ param = xzalloc(sizeof(*param));
- param = __dev_add_param(dev, name, set, get, flags);
+ ret = __dev_add_param(param, dev, name, set, get, flags);
+ if (ret)
+ free(param);
- return param ? 0 : -EINVAL;
+ return ret;
}
/**
@@ -202,32 +187,271 @@ int dev_add_param(struct device_d *dev, const char *name,
int dev_add_param_fixed(struct device_d *dev, char *name, char *value)
{
struct param_d *param;
+ int ret;
- param = __dev_add_param(dev, name, NULL, NULL, PARAM_FLAG_RO);
- if (!param)
- return -EINVAL;
+ param = xzalloc(sizeof(*param));
+
+ ret = __dev_add_param(param, dev, name, NULL, NULL, PARAM_FLAG_RO);
+ if (ret) {
+ free(param);
+ return ret;
+ }
param->value = strdup(value);
return 0;
}
+struct param_int {
+ struct param_d param;
+ int *value;
+ const char *format;
+#define PARAM_INT_FLAG_BOOL (1 << 0)
+ unsigned flags;
+ int (*set)(struct param_d *p, void *priv);
+ int (*get)(struct param_d *p, void *priv);
+};
+
+static inline struct param_int *to_param_int(struct param_d *p)
+{
+ return container_of(p, struct param_int, param);
+}
+
+static int param_int_set(struct device_d *dev, struct param_d *p, const char *val)
+{
+ struct param_int *pi = to_param_int(p);
+ int value_save = *pi->value;
+ int ret;
+
+ if (!val)
+ return -EINVAL;
+
+ *pi->value = simple_strtol(val, NULL, 0);
+
+ if (pi->flags & PARAM_INT_FLAG_BOOL)
+ *pi->value = !!*pi->value;
+
+ if (!pi->set)
+ return 0;
+
+ ret = pi->set(p, p->driver_priv);
+ if (ret)
+ *pi->value = value_save;
+
+ return ret;
+}
+
+static const char *param_int_get(struct device_d *dev, struct param_d *p)
+{
+ struct param_int *pi = to_param_int(p);
+ int ret;
+
+ if (pi->get) {
+ ret = pi->get(p, p->driver_priv);
+ if (ret)
+ return NULL;
+ }
+
+ free(p->value);
+ p->value = asprintf(pi->format, *pi->value);
+
+ return p->value;
+}
+
/**
- * dev_remove_param - remove a parameter from a device and free its
- * memory
+ * dev_add_param_int - add an integer parameter to a device
* @param dev The device
* @param name The name of the parameter
+ * @param set set function
+ * @param get get function
+ * @param value pointer to the integer containing the value of the parameter
+ * @param format the printf format used to print the value
+ * @param priv user private data, will be passed to get/set
+ *
+ * The get function can be used as a notifier when the variable is about
+ * to be read.
+ * The set function can be used as a notifer when the variable is about
+ * to be written. Can also be used to limit the value.
*/
-void dev_remove_param(struct device_d *dev, char *name)
+struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, const char *format, void *priv)
{
- struct param_d *p = get_param_by_name(dev, name);
+ struct param_int *pi;
+ struct param_d *p;
+ int ret;
- if (p) {
- p->set(dev, p, NULL);
- list_del(&p->list);
- free(p->name);
- free(p);
+ pi = xzalloc(sizeof(*pi));
+ pi->value = value;
+ pi->format = format;
+ pi->set = set;
+ pi->get = get;
+ p = &pi->param;
+ p->driver_priv = priv;
+
+ ret = __dev_add_param(p, dev, name, param_int_set, param_int_get, 0);
+ if (ret) {
+ free(pi);
+ return ERR_PTR(ret);
+ }
+
+ return &pi->param;
+}
+
+/**
+ * dev_add_param_bool - add an boolean parameter to a device
+ * @param dev The device
+ * @param name The name of the parameter
+ * @param set set function
+ * @param get get function
+ * @param value pointer to the integer containing the value of the parameter
+ * @param priv user private data, will be passed to get/set
+ *
+ * The get function can be used as a notifier when the variable is about
+ * to be read.
+ * The set function can be used as a notifer when the variable is about
+ * to be written. Can also be used to limit the value.
+ */
+struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ int *value, void *priv)
+{
+ struct param_int *pi;
+ struct param_d *p;
+
+ p = dev_add_param_int(dev, name, set, get, value, "%d", priv);
+ if (IS_ERR(p))
+ return p;
+
+ pi = to_param_int(p);
+ pi->flags |= PARAM_INT_FLAG_BOOL;
+
+ return p;
+}
+
+struct param_int_ro {
+ struct param_d param;
+ char *value;
+};
+
+/**
+ * dev_add_param_int_ro - add a read only integer parameter to a device
+ * @param dev The device
+ * @param name The name of the parameter
+ * @param value The value of the parameter
+ * @param format the printf format used to print the value
+ */
+struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
+ int value, const char *format)
+{
+ struct param_int *piro;
+ int ret;
+
+ piro = xzalloc(sizeof(*piro));
+
+ ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, 0);
+ if (ret) {
+ free(piro);
+ return ERR_PTR(ret);
}
+
+ piro->param.value = asprintf(format, value);
+
+ return &piro->param;
+}
+
+#ifdef CONFIG_NET
+struct param_ip {
+ struct param_d param;
+ IPaddr_t *ip;
+ const char *format;
+ int (*set)(struct param_d *p, void *priv);
+ int (*get)(struct param_d *p, void *priv);
+};
+
+static inline struct param_ip *to_param_ip(struct param_d *p)
+{
+ return container_of(p, struct param_ip, param);
+}
+
+static int param_ip_set(struct device_d *dev, struct param_d *p, const char *val)
+{
+ struct param_ip *pi = to_param_ip(p);
+ IPaddr_t ip_save = *pi->ip;
+ int ret;
+
+ if (!val)
+ return -EINVAL;
+
+ ret = string_to_ip(val, pi->ip);
+ if (ret)
+ return ret;
+
+ if (!pi->set)
+ return 0;
+
+ ret = pi->set(p, p->driver_priv);
+ if (ret)
+ *pi->ip = ip_save;
+
+ return ret;
+}
+
+static const char *param_ip_get(struct device_d *dev, struct param_d *p)
+{
+ struct param_ip *pi = to_param_ip(p);
+ int ret;
+
+ if (pi->get) {
+ ret = pi->get(p, p->driver_priv);
+ if (ret)
+ return NULL;
+ }
+
+ free(p->value);
+ p->value = xstrdup(ip_to_string(*pi->ip));
+
+ return p->value;
+}
+
+struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
+ int (*set)(struct param_d *p, void *priv),
+ int (*get)(struct param_d *p, void *priv),
+ IPaddr_t *ip, void *priv)
+{
+ struct param_ip *pi;
+ int ret;
+
+ pi = xzalloc(sizeof(*pi));
+ pi->ip = ip;
+ pi->set = set;
+ pi->get = get;
+ pi->param.driver_priv = priv;
+
+ ret = __dev_add_param(&pi->param, dev, name,
+ param_ip_set, param_ip_get, 0);
+ if (ret) {
+ free(pi);
+ return ERR_PTR(ret);
+ }
+
+ return &pi->param;
+}
+#endif
+
+/**
+ * dev_remove_param - remove a parameter from a device and free its
+ * memory
+ * @param p The parameter
+ */
+void dev_remove_param(struct param_d *p)
+{
+ p->set(p->dev, p, NULL);
+ list_del(&p->list);
+ free(p->name);
+ free(p);
}
/**
diff --git a/net/eth.c b/net/eth.c
index 98ec726b84..4646dd8b89 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -86,7 +86,6 @@ void eth_set_current(struct eth_device *eth)
}
eth_current = eth;
- net_update_env();
}
struct eth_device * eth_get_current(void)
@@ -210,39 +209,16 @@ int eth_rx(void)
static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const char *val)
{
struct eth_device *edev = dev_to_edev(dev);
- u8 ethaddr[6];
-
- if (!val)
- return dev_param_set_generic(dev, param, NULL);
-
- if (string_to_ethaddr(val, ethaddr) < 0)
- return -EINVAL;
-
- dev_param_set_generic(dev, param, val);
-
- edev->set_ethaddr(edev, ethaddr);
-
- if (edev == eth_current)
- net_update_env();
-
- return 0;
-}
-
-static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const char *val)
-{
- struct eth_device *edev = dev_to_edev(dev);
- IPaddr_t ip;
if (!val)
return dev_param_set_generic(dev, param, NULL);
- if (string_to_ip(val, &ip))
+ if (string_to_ethaddr(val, edev->ethaddr) < 0)
return -EINVAL;
dev_param_set_generic(dev, param, val);
- if (edev == eth_current)
- net_update_env();
+ edev->set_ethaddr(edev, edev->ethaddr);
return 0;
}
@@ -267,11 +243,11 @@ int eth_register(struct eth_device *edev)
register_device(&edev->dev);
- dev_add_param(dev, "ipaddr", eth_set_ipaddr, NULL, 0);
+ dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev);
+ dev_add_param_ip(dev, "serverip", NULL, NULL, &edev->serverip, edev);
+ dev_add_param_ip(dev, "gateway", NULL, NULL, &edev->gateway, edev);
+ dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
dev_add_param(dev, "ethaddr", eth_set_ethaddr, NULL, 0);
- dev_add_param(dev, "gateway", eth_set_ipaddr, NULL, 0);
- dev_add_param(dev, "netmask", eth_set_ipaddr, NULL, 0);
- dev_add_param(dev, "serverip", eth_set_ipaddr, NULL, 0);
if (edev->init)
edev->init(edev);
@@ -296,10 +272,8 @@ int eth_register(struct eth_device *edev)
}
}
- if (!eth_current) {
+ if (!eth_current)
eth_current = edev;
- net_update_env();
- }
return 0;
}
diff --git a/net/net.c b/net/net.c
index 639bc2d985..0bd9084dd0 100644
--- a/net/net.c
+++ b/net/net.c
@@ -36,29 +36,9 @@
#include <linux/ctype.h>
#include <linux/err.h>
-static IPaddr_t net_netmask; /* Our subnet mask (0=unknown) */
-static IPaddr_t net_gateway; /* Our gateways IP address */
-
-static unsigned char net_ether[6]; /* Our ethernet address */
-static IPaddr_t net_ip; /* Our IP addr (0 = unknown) */
-static IPaddr_t net_serverip; /* Our IP addr (0 = unknown) */
-
unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets */
static unsigned int net_ip_id;
-void net_update_env(void)
-{
- struct eth_device *edev = eth_get_current();
-
- net_ip = dev_get_param_ip(&edev->dev, "ipaddr");
- net_serverip = dev_get_param_ip(&edev->dev, "serverip");
- net_gateway = dev_get_param_ip(&edev->dev, "gateway");
- net_netmask = dev_get_param_ip(&edev->dev, "netmask");
-
- string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
- net_ether);
-}
-
int net_checksum_ok(unsigned char *ptr, int len)
{
return net_checksum(ptr, len) + 1;
@@ -210,6 +190,7 @@ static void arp_handler(struct arprequest *arp)
static int arp_request(IPaddr_t dest, unsigned char *ether)
{
+ struct eth_device *edev = eth_get_current();
char *pkt;
struct arprequest *arp;
uint64_t arp_start;
@@ -232,7 +213,7 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)
pr_debug("ARP broadcast\n");
memset(et->et_dest, 0xff, 6);
- memcpy(et->et_src, net_ether, 6);
+ memcpy(et->et_src, edev->ethaddr, 6);
et->et_protlen = htons(PROT_ARP);
arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
@@ -243,15 +224,15 @@ static int arp_request(IPaddr_t dest, unsigned char *ether)
arp->ar_pln = 4;
arp->ar_op = htons(ARPOP_REQUEST);
- memcpy(arp->ar_data, net_ether, 6); /* source ET addr */
- net_write_ip(arp->ar_data + 6, net_ip); /* source IP addr */
+ memcpy(arp->ar_data, edev->ethaddr, 6); /* source ET addr */
+ net_write_ip(arp->ar_data + 6, edev->ipaddr); /* source IP addr */
memset(arp->ar_data + 10, 0, 6); /* dest ET addr = 0 */
- if ((dest & net_netmask) != (net_ip & net_netmask)) {
- if (!net_gateway)
+ if ((dest & edev->netmask) != (edev->ipaddr & edev->netmask)) {
+ if (!edev->gateway)
arp_wait_ip = dest;
else
- arp_wait_ip = net_gateway;
+ arp_wait_ip = edev->gateway;
} else {
arp_wait_ip = dest;
}
@@ -310,44 +291,44 @@ static uint16_t net_udp_new_localport(void)
IPaddr_t net_get_serverip(void)
{
- return net_serverip;
+ struct eth_device *edev = eth_get_current();
+
+ return edev->serverip;
}
void net_set_serverip(IPaddr_t ip)
{
struct eth_device *edev = eth_get_current();
- net_serverip = ip;
- dev_set_param_ip(&edev->dev, "serverip", net_serverip);
+ edev->serverip = ip;
}
void net_set_ip(IPaddr_t ip)
{
struct eth_device *edev = eth_get_current();
- net_ip = ip;
- dev_set_param_ip(&edev->dev, "ipaddr", net_ip);
+ edev->ipaddr = ip;
}
IPaddr_t net_get_ip(void)
{
- return net_ip;
+ struct eth_device *edev = eth_get_current();
+
+ return edev->ipaddr;
}
void net_set_netmask(IPaddr_t nm)
{
struct eth_device *edev = eth_get_current();
- net_netmask = nm;
- dev_set_param_ip(&edev->dev, "netmask", net_netmask);
+ edev->netmask = nm;
}
void net_set_gateway(IPaddr_t gw)
{
struct eth_device *edev = eth_get_current();
- net_gateway = gw;
- dev_set_param_ip(&edev->dev, "gateway", net_gateway);
+ edev->gateway = gw;
}
static LIST_HEAD(connection_list);
@@ -362,16 +343,16 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
if (!edev)
return ERR_PTR(-ENETDOWN);
- if (!is_valid_ether_addr(net_ether)) {
+ if (!is_valid_ether_addr(edev->ethaddr)) {
char str[sizeof("xx:xx:xx:xx:xx:xx")];
- random_ether_addr(net_ether);
- ethaddr_to_string(net_ether, str);
+ random_ether_addr(edev->ethaddr);
+ ethaddr_to_string(edev->ethaddr, str);
printf("warning: No MAC address set. Using random address %s\n", str);
dev_set_param(&edev->dev, "ethaddr", str);
}
/* If we don't have an ip only broadcast is allowed */
- if (!net_ip && dest != 0xffffffff)
+ if (!edev->ipaddr && dest != 0xffffffff)
return ERR_PTR(-ENETDOWN);
con = xzalloc(sizeof(*con));
@@ -394,14 +375,14 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
}
con->et->et_protlen = htons(PROT_IP);
- memcpy(con->et->et_src, net_ether, 6);
+ memcpy(con->et->et_src, edev->ethaddr, 6);
con->ip->hl_v = 0x45;
con->ip->tos = 0;
con->ip->frag_off = htons(0x4000); /* No fragmentation */;
con->ip->ttl = 255;
net_copy_ip(&con->ip->daddr, &dest);
- net_copy_ip(&con->ip->saddr, &net_ip);
+ net_copy_ip(&con->ip->saddr, &edev->ipaddr);
list_add_tail(&con->list, &connection_list);
@@ -479,20 +460,21 @@ static int net_answer_arp(unsigned char *pkt, int len)
{
struct arprequest *arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
struct ethernet *et = (struct ethernet *)pkt;
+ struct eth_device *edev = eth_get_current();
unsigned char *packet;
int ret;
debug("%s\n", __func__);
memcpy (et->et_dest, et->et_src, 6);
- memcpy (et->et_src, net_ether, 6);
+ memcpy (et->et_src, edev->ethaddr, 6);
et->et_protlen = htons(PROT_ARP);
arp->ar_op = htons(ARPOP_REPLY);
memcpy(&arp->ar_data[10], &arp->ar_data[0], 6);
net_copy_ip(&arp->ar_data[16], &arp->ar_data[6]);
- memcpy(&arp->ar_data[0], net_ether, 6);
- net_copy_ip(&arp->ar_data[6], &net_ip);
+ memcpy(&arp->ar_data[0], edev->ethaddr, 6);
+ net_copy_ip(&arp->ar_data[6], &edev->ipaddr);
packet = net_alloc_packet();
if (!packet)
@@ -517,6 +499,7 @@ static void net_bad_packet(unsigned char *pkt, int len)
static int net_handle_arp(unsigned char *pkt, int len)
{
+ struct eth_device *edev = eth_get_current();
struct arprequest *arp;
debug("%s: got arp\n", __func__);
@@ -541,9 +524,9 @@ static int net_handle_arp(unsigned char *pkt, int len)
goto bad;
if (arp->ar_pln != 4)
goto bad;
- if (net_ip == 0)
+ if (edev->ipaddr == 0)
return 0;
- if (net_read_ip(&arp->ar_data[16]) != net_ip)
+ if (net_read_ip(&arp->ar_data[16]) != edev->ipaddr)
return 0;
switch (ntohs(arp->ar_op)) {
@@ -600,6 +583,7 @@ static int net_handle_icmp(unsigned char *pkt, int len)
static int net_handle_ip(unsigned char *pkt, int len)
{
struct iphdr *ip = (struct iphdr *)(pkt + ETHER_HDR_SIZE);
+ struct eth_device *edev = eth_get_current();
IPaddr_t tmp;
debug("%s\n", __func__);
@@ -619,7 +603,7 @@ static int net_handle_ip(unsigned char *pkt, int len)
goto bad;
tmp = net_read_ip(&ip->daddr);
- if (net_ip && tmp != net_ip && tmp != 0xffffffff)
+ if (edev->ipaddr && tmp != edev->ipaddr && tmp != 0xffffffff)
return 0;
switch (ip->protocol) {
diff --git a/net/netconsole.c b/net/netconsole.c
index 960de8d437..99891941b7 100644
--- a/net/netconsole.c
+++ b/net/netconsole.c
@@ -43,7 +43,7 @@ struct nc_priv {
int busy;
struct net_connection *con;
- uint16_t port;
+ unsigned int port;
IPaddr_t ip;
};
@@ -123,49 +123,10 @@ static void nc_putc(struct console_device *cdev, char c)
priv->busy = 0;
}
-static int nc_port_set(struct device_d *dev, struct param_d *param,
- const char *val)
+static int nc_port_set(struct param_d *p, void *_priv)
{
- struct nc_priv *priv = g_priv;
- char portstr[16];
- int port;
-
- if (!val)
- dev_param_set_generic(dev, param, NULL);
-
- port = simple_strtoul(val, NULL, 10);
- if (port > 65535)
- return -EINVAL;
-
- priv->port = port;
nc_init();
- sprintf(portstr, "%d", port);
- dev_param_set_generic(dev, param, portstr);
-
- return 0;
-}
-
-static int nc_remoteip_set(struct device_d *dev, struct param_d *param,
- const char *val)
-{
- struct nc_priv *priv = g_priv;
- IPaddr_t ip;
- int ret;
-
- if (!val)
- dev_param_set_generic(dev, param, NULL);
-
- if (string_to_ip(val, &ip))
- return -EINVAL;
-
- priv->ip = ip;
- ret = nc_init();
- if (ret)
- return ret;
-
- dev_param_set_generic(dev, param, val);
-
return 0;
}
@@ -192,9 +153,10 @@ static int netconsole_init(void)
return ret;
}
- dev_add_param(&cdev->class_dev, "ip", nc_remoteip_set, NULL, 0);
- dev_add_param(&cdev->class_dev, "port", nc_port_set, NULL, 0);
- dev_set_param(&cdev->class_dev, "port", "6666");
+ priv->port = 6666;
+
+ dev_add_param_ip(&cdev->class_dev, "ip", NULL, NULL, &priv->ip, NULL);
+ dev_add_param_int(&cdev->class_dev, "port", nc_port_set, NULL, &priv->port, "%u", NULL);
pr_info("registered as %s%d\n", cdev->class_dev.name, cdev->class_dev.id);