From f1253fdf8e763c8cadf0ebaeb3cbaf1f720c7a30 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 08:23:41 +0200 Subject: param: Add dev member to struct param_d This will make it unnecessary to pass the dev pointer around later. Signed-off-by: Sascha Hauer --- include/param.h | 1 + lib/parameter.c | 1 + 2 files changed, 2 insertions(+) diff --git a/include/param.h b/include/param.h index 3a585cd193..2a1b4fac7b 100644 --- a/include/param.h +++ b/include/param.h @@ -15,6 +15,7 @@ struct param_d { unsigned int flags; char *name; char *value; + struct device_d *dev; struct list_head list; }; diff --git a/lib/parameter.c b/lib/parameter.c index c00b82438d..94da79c697 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -159,6 +159,7 @@ 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(¶m->list, &dev->parameters); return param; -- cgit v1.2.3 From c4b7f8ad38efdcc7426339cf413d52094dd677ac Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 18:57:53 +0200 Subject: param: refactor __dev_add_param Let __dev_add_param take a previously allocated struct param_d. This helps when later other users wish to embed a struct param_d in a bigger struct. Signed-off-by: Sascha Hauer --- lib/parameter.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/parameter.c b/lib/parameter.c index 94da79c697..70f035aab3 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -139,14 +139,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; @@ -162,7 +161,7 @@ static struct param_d *__dev_add_param(struct device_d *dev, const char *name, param->dev = dev; list_add_tail(¶m->list, &dev->parameters); - return param; + return 0; } /** @@ -184,14 +183,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; } /** @@ -203,10 +203,15 @@ 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); -- cgit v1.2.3 From 2df33a69bdb7268f0192ad35142948dd633b3f0a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 08:43:00 +0200 Subject: param: Add integer and boolean parameter helpers This adds convenience functions for directly registering integers and bools as device parameter. This way driver no longer have to fiddle with string handling. The format used to print the parameter is passed to the functions to be able to print parameters in a flexible way. Signed-off-by: Sascha Hauer --- include/param.h | 37 +++++++++++++ lib/parameter.c | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) diff --git a/include/param.h b/include/param.h index 2a1b4fac7b..311c6e5ca3 100644 --- a/include/param.h +++ b/include/param.h @@ -16,6 +16,7 @@ struct param_d { char *name; char *value; struct device_d *dev; + void *driver_priv; struct list_head list; }; @@ -29,6 +30,19 @@ 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); + int dev_add_param_fixed(struct device_d *dev, char *name, char *value); void dev_remove_param(struct device_d *dev, char *name); @@ -41,6 +55,7 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p, /* 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) { @@ -65,6 +80,28 @@ static inline int dev_add_param(struct device_d *dev, char *name, return 0; } +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 NULL; +} + +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 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_add_param_fixed(struct device_d *dev, char *name, char *value) { return 0; diff --git a/lib/parameter.c b/lib/parameter.c index 70f035aab3..3e78c96728 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -27,6 +27,7 @@ #include #include #include +#include struct param_d *get_param_by_name(struct device_d *dev, const char *name) { @@ -218,6 +219,166 @@ int dev_add_param_fixed(struct device_d *dev, char *name, char *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) { + ret = pi->set(p, p->driver_priv); + if (ret) { + *pi->value = value_save; + return ret; + } + } + + return 0; +} + +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_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. + */ +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_int *pi; + struct param_d *p; + int ret; + + 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; +} + /** * dev_remove_param - remove a parameter from a device and free its * memory -- cgit v1.2.3 From f80e7c49200368c5df98001a4d4b3deeb17e6a9a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 18:24:37 +0200 Subject: param: Add ip address convenience function Signed-off-by: Sascha Hauer --- include/param.h | 13 ++++++++ lib/parameter.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/include/param.h b/include/param.h index 311c6e5ca3..66c57a9b6d 100644 --- a/include/param.h +++ b/include/param.h @@ -43,6 +43,11 @@ struct param_d *dev_add_param_bool(struct device_d *dev, const char *name, 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); @@ -102,6 +107,14 @@ static inline struct param_d *dev_add_param_int_ro(struct device_d *dev, const c return NULL; } +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 NULL; +} + static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *value) { return 0; diff --git a/lib/parameter.c b/lib/parameter.c index 3e78c96728..bb43610ebf 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -244,18 +244,18 @@ static int param_int_set(struct device_d *dev, struct param_d *p, const char *va return -EINVAL; *pi->value = simple_strtol(val, NULL, 0); + if (pi->flags & PARAM_INT_FLAG_BOOL) *pi->value = !!*pi->value; - if (pi->set) { - ret = pi->set(p, p->driver_priv); - if (ret) { - *pi->value = value_save; - return ret; - } - } + if (!pi->set) + return 0; - 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) @@ -379,6 +379,85 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name, 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 -- cgit v1.2.3 From 7d29b3cd83be22c8c714e5e1b331cf832cf03dd2 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 12:04:10 +0200 Subject: net: ksz8864: Use dev_add_param_bool for enable parameter Signed-off-by: Sascha Hauer --- drivers/net/ksz8864rmn.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) 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; } -- cgit v1.2.3 From 6d0161d02a3a829a12b85bdd3a71cddb714d66f5 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 18:26:10 +0200 Subject: net: store ethernet device parameters in device Rather than storing the parameters globally and trying to keep them in sync with the device parameters, store the parameters in the ethernet device directly. Also, update to dev_add_param_ip(). Signed-off-by: Sascha Hauer --- include/net.h | 7 +++++- net/eth.c | 40 ++++++------------------------ net/net.c | 80 ++++++++++++++++++++++++----------------------------------- 3 files changed, 45 insertions(+), 82 deletions(-) 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/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 #include -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) { -- cgit v1.2.3 From 21a2691f06a9b92cbdf2bc0470f4aa6016620774 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 19:18:38 +0200 Subject: netconsole: use dev_add_param_* helpers For shorter code. Signed-off-by: Sascha Hauer --- net/netconsole.c | 50 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) 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); -- cgit v1.2.3 From a28085859402eecb4b2d9a051b1956e17f29e0aa Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 18:28:40 +0200 Subject: param: remove now unused dev_[gs]et_param_ip Signed-off-by: Sascha Hauer --- include/param.h | 15 --------------- lib/parameter.c | 17 ----------------- 2 files changed, 32 deletions(-) diff --git a/include/param.h b/include/param.h index 66c57a9b6d..3c881d7804 100644 --- a/include/param.h +++ b/include/param.h @@ -57,10 +57,6 @@ 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) { @@ -129,17 +125,6 @@ static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p, { return 0; } - -/* 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) -{ - return 0; -} -static inline IPaddr_t dev_get_param_ip(struct device_d *dev, char *name) -{ - return 0; -} #endif #endif /* PARAM_H */ - diff --git a/lib/parameter.c b/lib/parameter.c index bb43610ebf..97105db7ae 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -59,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 -- cgit v1.2.3 From 7c6c61fe8e66701263ee0b25056e65abcf3843d6 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 09:01:57 +0200 Subject: treewide: Use dev_add_param_int_ro where possible Signed-off-by: Sascha Hauer --- arch/arm/boards/at91sam9m10ihd/hw_version.c | 6 ++---- arch/arm/boards/at91sam9x5ek/hw_version.c | 6 ++---- arch/arm/boards/sama5d3xek/hw_version.c | 6 ++---- drivers/amba/bus.c | 9 ++------- drivers/input/qt1070.c | 6 ++---- drivers/mtd/core.c | 13 ++++--------- drivers/net/phy/mdio_bus.c | 8 ++------ drivers/usb/core/usb.c | 19 ++++++++++--------- 8 files changed, 26 insertions(+), 47 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/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/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/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/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/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; -- cgit v1.2.3 From fff0e0f741875f464b5b023f520a03df75193a76 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 09:11:36 +0200 Subject: mci: Use dev_add_param_int for probe parameter Signed-off-by: Sascha Hauer --- drivers/mci/mci-core.c | 38 ++++++++++---------------------------- include/mci.h | 2 ++ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c index c8598c2dcc..059e635659 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -34,6 +34,7 @@ #include #include #include +#include #define MAX_BUFFER_NUMBER 0xffffffff @@ -1455,43 +1456,22 @@ 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; rc = mci_check_if_already_initialized(mci); if (rc != 0) return 0; - probe = simple_strtoul(val, NULL, 0); - if (probe != 0) { + if (mci->probe) { 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); - if (rc != 0) - return rc; - - return dev_set_param(mci_dev, "probe", "0"); + return 0; } /** @@ -1514,8 +1494,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_int(mci_dev, "probe", + mci_set_probe, NULL, &mci->probe, "%d", 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/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*); -- cgit v1.2.3 From f3b911c82032d718e937bc5b0e80b61097fe5073 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 09:35:23 +0200 Subject: ata: Use dev_add_param_bool for probe parameter Signed-off-by: Sascha Hauer --- drivers/ata/disk_ata_drive.c | 21 ++++++++++----------- include/ata_drive.h | 1 + 2 files changed, 11 insertions(+), 11 deletions(-) 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/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 *); -- cgit v1.2.3 From fb3fcaf2ccb6293b5e1bf36c6809934dcafdc4ad Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 10:30:22 +0200 Subject: fb: Use dev_add_param_bool for enable parameter Signed-off-by: Sascha Hauer --- drivers/video/fb.c | 33 ++++++++++++--------------------- include/fb.h | 1 + 2 files changed, 13 insertions(+), 21 deletions(-) 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/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); -- cgit v1.2.3 From 196345d3fbad74d0c6eda4710533f277951c822b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 11:49:25 +0200 Subject: fb: imxfb: Use dev_add_param_int for alpha parameter Signed-off-by: Sascha Hauer --- drivers/video/imx.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) 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; } -- cgit v1.2.3 From 0a4c7871715eb3cffae98af7cacd24f088d5bdeb Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 11:57:35 +0200 Subject: fb: imx-ipu-fb: Use dev_add_param_int for alpha parameter Signed-off-by: Sascha Hauer --- drivers/video/imx-ipu-fb.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) 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; } -- cgit v1.2.3 From c57fa97ee7e50a8bddf3ad51e94071bdbb6f8a3a Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 10:49:11 +0200 Subject: param: pass param to dev_remove_param Signed-off-by: Sascha Hauer --- include/param.h | 4 ++-- lib/parameter.c | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/param.h b/include/param.h index 3c881d7804..4af2d09c4c 100644 --- a/include/param.h +++ b/include/param.h @@ -50,7 +50,7 @@ struct param_d *dev_add_param_ip(struct device_d *dev, const char *name, 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); @@ -116,7 +116,7 @@ static inline int dev_add_param_fixed(struct device_d *dev, char *name, char *va return 0; } -static inline void dev_remove_param(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) {} diff --git a/lib/parameter.c b/lib/parameter.c index 97105db7ae..e47e8b9148 100644 --- a/lib/parameter.c +++ b/lib/parameter.c @@ -444,19 +444,14 @@ struct param_d *dev_add_param_ip(struct device_d *dev, const char *name, /** * dev_remove_param - remove a parameter from a device and free its * memory - * @param dev The device - * @param name The name of the parameter + * @param p The parameter */ -void dev_remove_param(struct device_d *dev, char *name) +void dev_remove_param(struct param_d *p) { - struct param_d *p = get_param_by_name(dev, name); - - if (p) { - p->set(dev, p, NULL); - list_del(&p->list); - free(p->name); - free(p); - } + p->set(p->dev, p, NULL); + list_del(&p->list); + free(p->name); + free(p); } /** -- cgit v1.2.3 From 3a9f068ccbc4344e7683b20f9a7adddf4aa38bb3 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 10:54:41 +0200 Subject: pwm: Use dev_add_param_int for pwm parameters Signed-off-by: Sascha Hauer Cc: Robert Jarzmik --- drivers/pwm/core.c | 89 ++++++++++++++++++------------------------------------ 1 file changed, 30 insertions(+), 59 deletions(-) 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 #include #include +#include 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); -- cgit v1.2.3 From 3c9b5c1a619065dad673d7d67439f7d192856095 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 11:11:40 +0200 Subject: ARM: i.MX: iim: Use dev_add_param_bool for parameters Signed-off-by: Sascha Hauer --- arch/arm/mach-imx/iim.c | 65 +++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 51 deletions(-) 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; } -- cgit v1.2.3 From ab855df99fb542d5a23a69385441a7808aef7b2d Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 11:25:28 +0200 Subject: console: Use dev_add_param_int for baudrate parameter Signed-off-by: Sascha Hauer --- common/console.c | 26 ++++++++------------------ drivers/mci/mci-core.c | 15 ++++++++------- include/console.h | 2 ++ 3 files changed, 18 insertions(+), 25 deletions(-) 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/mci/mci-core.c b/drivers/mci/mci-core.c index 059e635659..86e8d5de46 100644 --- a/drivers/mci/mci-core.c +++ b/drivers/mci/mci-core.c @@ -1461,15 +1461,16 @@ static int mci_set_probe(struct param_d *param, void *priv) struct mci *mci = priv; int rc; + if (!mci->probe) + return 0; + rc = mci_check_if_already_initialized(mci); if (rc != 0) return 0; - if (mci->probe) { - rc = mci_card_probe(mci); - if (rc != 0) - return rc; - } + rc = mci_card_probe(mci); + if (rc != 0) + return rc; return 0; } @@ -1494,8 +1495,8 @@ static int mci_probe(struct device_d *mci_dev) dev_info(mci->host->hw_dev, "registered as %s\n", dev_name(mci_dev)); - mci->param_probe = dev_add_param_int(mci_dev, "probe", - mci_set_probe, NULL, &mci->probe, "%d", mci); + 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"); 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); -- cgit v1.2.3 From d8ee54fbbf605f93c412a984313d4ed841eba2f9 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 12:19:56 +0200 Subject: mtd: Nand: Use dev_add_param_bool for erasebad parameter Signed-off-by: Sascha Hauer --- drivers/mtd/nand/nand_base.c | 22 ++++++++++++---------- include/linux/mtd/mtd.h | 1 + 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index fa10d9581e..67e913aef4 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1672,18 +1672,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; } @@ -1714,8 +1716,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/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); -- cgit v1.2.3 From a40442cfa4ece00ea7a3d0d973dc86f49d7f3406 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 13:28:42 +0200 Subject: USB gadget at91: Use dev_add_param_bool for vbus parameter Signed-off-by: Sascha Hauer --- drivers/usb/gadget/at91_udc.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) 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); -- cgit v1.2.3 From 2f24a5c33c9b9034e412b52ec88c1019307c14f0 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Sat, 6 Apr 2013 14:07:56 +0200 Subject: ARM: MXS: ocotp: Use dev_add_param_bool for parameter Signed-off-by: Sascha Hauer --- arch/arm/mach-mxs/ocotp.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) 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; -- cgit v1.2.3