Commit 36030978f51b596c30188187ffcc8a436cce16f0

Authored by Milo Kim
Committed by Bryan Wu
1 parent 6841a91dc5

leds: lp55xx: add common macros for device attributes

This patch provides common macros for LP5521 and LP5523 device attributes and
functions.

(Device attributes)
LP5521: 'mode', 'load' and 'selftest'
LP5523: 'mode', 'load', 'leds' and 'selftest'

(Permissions)
mode: R/W
load: Write-only
leds: R/W
selftest: Read-only

Couple of lines are duplicate, so use these macros for adding device attributes
in LP5521 and LP5523 drivers.

Signed-off-by: Milo Kim <milo.kim@ti.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

Showing 1 changed file with 47 additions and 0 deletions Side-by-side Diff

drivers/leds/leds-lp55xx-common.h
... ... @@ -29,6 +29,53 @@
29 29 LP55XX_ENGINE_RUN,
30 30 };
31 31  
  32 +#define LP55XX_DEV_ATTR_RW(name, show, store) \
  33 + DEVICE_ATTR(name, S_IRUGO | S_IWUSR, show, store)
  34 +#define LP55XX_DEV_ATTR_RO(name, show) \
  35 + DEVICE_ATTR(name, S_IRUGO, show, NULL)
  36 +#define LP55XX_DEV_ATTR_WO(name, store) \
  37 + DEVICE_ATTR(name, S_IWUSR, NULL, store)
  38 +
  39 +#define show_mode(nr) \
  40 +static ssize_t show_engine##nr##_mode(struct device *dev, \
  41 + struct device_attribute *attr, \
  42 + char *buf) \
  43 +{ \
  44 + return show_engine_mode(dev, attr, buf, nr); \
  45 +}
  46 +
  47 +#define store_mode(nr) \
  48 +static ssize_t store_engine##nr##_mode(struct device *dev, \
  49 + struct device_attribute *attr, \
  50 + const char *buf, size_t len) \
  51 +{ \
  52 + return store_engine_mode(dev, attr, buf, len, nr); \
  53 +}
  54 +
  55 +#define show_leds(nr) \
  56 +static ssize_t show_engine##nr##_leds(struct device *dev, \
  57 + struct device_attribute *attr, \
  58 + char *buf) \
  59 +{ \
  60 + return show_engine_leds(dev, attr, buf, nr); \
  61 +}
  62 +
  63 +#define store_leds(nr) \
  64 +static ssize_t store_engine##nr##_leds(struct device *dev, \
  65 + struct device_attribute *attr, \
  66 + const char *buf, size_t len) \
  67 +{ \
  68 + return store_engine_leds(dev, attr, buf, len, nr); \
  69 +}
  70 +
  71 +#define store_load(nr) \
  72 +static ssize_t store_engine##nr##_load(struct device *dev, \
  73 + struct device_attribute *attr, \
  74 + const char *buf, size_t len) \
  75 +{ \
  76 + return store_engine_load(dev, attr, buf, len, nr); \
  77 +}
  78 +
32 79 struct lp55xx_led;
33 80 struct lp55xx_chip;
34 81