Skip to content

Commit

Permalink
jesd204: core: add printk helpers
Browse files Browse the repository at this point in the history
Roughly adapted from dev_printk() helpers.

Signed-off-by: Alexandru Ardelean <[email protected]>
  • Loading branch information
commodo committed Jul 22, 2020
1 parent 2b1927d commit 90be5cc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
39 changes: 39 additions & 0 deletions drivers/jesd204/jesd204-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,45 @@ struct device *jesd204_dev_to_device(struct jesd204_dev *jdev)
}
EXPORT_SYMBOL_GPL(jesd204_dev_to_device);

static void __jesd204_printk(const char *level, const struct jesd204_dev *jdev,
struct va_format *vaf)
{
const struct device *dev;

if (!jdev) {
printk("%sjesd204: (NULL jesd204 device *): %pV", level, vaf);
return;
}

if (!jdev->dev.parent) {
printk("%sjesd204: %pOF: %pV", level, jdev->np, vaf);
return;
}

dev = &jdev->dev;
dev_printk_emit(level[1] - '0', dev, "jesd204: %pOF,%s,parent=%s: %pV",
jdev->np,
dev_name(dev),
dev_name(dev->parent),
vaf);
}

void jesd204_printk(const char *level, const struct jesd204_dev *jdev,
const char *fmt, ...)
{
struct va_format vaf;
va_list args;

va_start(args, fmt);

vaf.fmt = fmt;
vaf.va = &args;

__jesd204_printk(level, jdev, &vaf);

va_end(args);
}

static int jesd204_dev_alloc_links(struct jesd204_dev_top *jdev_top)
{
struct jesd204_link_opaque *links;
Expand Down
31 changes: 31 additions & 0 deletions include/linux/jesd204/jesd204.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef _JESD204_H_
#define _JESD204_H_

#include <linux/kern_levels.h>

struct jesd204_dev;

enum jesd204_subclass {
Expand Down Expand Up @@ -256,4 +258,33 @@ static inline int jesd204_link_get_device_clock(struct jesd204_link *lnk,

#endif /* #ifdef CONFIG_JESD204 */

#if defined(CONFIG_PRINTK) && defined(CONFIG_JESD204)

__printf(3, 4)
void jesd204_printk(const char *level, const struct jesd204_dev *jdev,
const char *fmt, ...);
#else

static inline __printf(3, 4)
void jesd204_printk(const char *level, const struct jesd204_dev *jdev,
const char *fmt, ...)
{}

#endif /* #ifdef CONFIG_PRINTK */

#define jesd204_emerg(dev, fmt, ...) \
jesd204_printk(KERN_EMERG, dev, fmt, ##__VA_ARGS__)
#define jesd204_crit(dev, fmt, ...) \
jesd204_printk(KERN_CRIT, dev, fmt, ##__VA_ARGS__)
#define jesd204_alert(dev, fmt, ...) \
jesd204_printk(KERN_ALERT, dev, fmt, ##__VA_ARGS__)
#define jesd204_err(dev, fmt, ...) \
jesd204_printk(KERN_ERR, dev, fmt, ##__VA_ARGS__)
#define jesd204_warn(dev, fmt, ...) \
jesd204_printk(KERN_WARNING, dev, fmt, ##__VA_ARGS__)
#define jesd204_notice(dev, fmt, ...) \
jesd204_printk(KERN_NOTICE, dev, fmt, ##__VA_ARGS__)
#define jesd204_info(dev, fmt, ...) \
jesd204_printk(KERN_INFO, dev, fmt, ##__VA_ARGS__)

#endif

0 comments on commit 90be5cc

Please sign in to comment.