Blame view
drivers/leds/leds-dac124s085.c
2.55 KB
ac2dd0f11 leds: Add dac124s... |
1 2 3 4 5 6 7 8 9 10 |
/* * Copyright 2008 * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de> * * This file is subject to the terms and conditions of version 2 of * the GNU General Public License. See the file COPYING in the main * directory of this archive for more details. * * LED driver for the DAC124S085 SPI DAC */ |
ac2dd0f11 leds: Add dac124s... |
11 12 13 14 |
#include <linux/leds.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/slab.h> |
ac2dd0f11 leds: Add dac124s... |
15 16 17 18 19 20 |
#include <linux/spi/spi.h> struct dac124s085_led { struct led_classdev ldev; struct spi_device *spi; int id; |
ac2dd0f11 leds: Add dac124s... |
21 22 23 |
char name[sizeof("dac124s085-3")]; struct mutex mutex; |
ac2dd0f11 leds: Add dac124s... |
24 25 26 27 28 29 30 31 32 33 |
}; struct dac124s085 { struct dac124s085_led leds[4]; }; #define REG_WRITE (0 << 12) #define REG_WRITE_UPDATE (1 << 12) #define ALL_WRITE_UPDATE (2 << 12) #define POWER_DOWN_OUTPUT (3 << 12) |
8ec108c03 leds: dac124d085:... |
34 35 |
static int dac124s085_set_brightness(struct led_classdev *ldev, enum led_brightness brightness) |
ac2dd0f11 leds: Add dac124s... |
36 |
{ |
8ec108c03 leds: dac124d085:... |
37 38 |
struct dac124s085_led *led = container_of(ldev, struct dac124s085_led, ldev); |
ac2dd0f11 leds: Add dac124s... |
39 |
u16 word; |
8ec108c03 leds: dac124d085:... |
40 |
int ret; |
ac2dd0f11 leds: Add dac124s... |
41 42 43 |
mutex_lock(&led->mutex); word = cpu_to_le16(((led->id) << 14) | REG_WRITE_UPDATE | |
8ec108c03 leds: dac124d085:... |
44 45 |
(brightness & 0xfff)); ret = spi_write(led->spi, (const u8 *)&word, sizeof(word)); |
ac2dd0f11 leds: Add dac124s... |
46 |
mutex_unlock(&led->mutex); |
ac2dd0f11 leds: Add dac124s... |
47 |
|
8ec108c03 leds: dac124d085:... |
48 |
return ret; |
ac2dd0f11 leds: Add dac124s... |
49 50 51 52 53 54 55 |
} static int dac124s085_probe(struct spi_device *spi) { struct dac124s085 *dac; struct dac124s085_led *led; int i, ret; |
e58603122 leds: convert DAC... |
56 |
dac = devm_kzalloc(&spi->dev, sizeof(*dac), GFP_KERNEL); |
ac2dd0f11 leds: Add dac124s... |
57 58 59 60 61 62 63 64 |
if (!dac) return -ENOMEM; spi->bits_per_word = 16; for (i = 0; i < ARRAY_SIZE(dac->leds); i++) { led = dac->leds + i; led->id = i; |
ac2dd0f11 leds: Add dac124s... |
65 66 |
led->spi = spi; snprintf(led->name, sizeof(led->name), "dac124s085-%d", i); |
ac2dd0f11 leds: Add dac124s... |
67 68 69 70 |
mutex_init(&led->mutex); led->ldev.name = led->name; led->ldev.brightness = LED_OFF; led->ldev.max_brightness = 0xfff; |
8ec108c03 leds: dac124d085:... |
71 |
led->ldev.brightness_set_blocking = dac124s085_set_brightness; |
ac2dd0f11 leds: Add dac124s... |
72 73 74 75 76 77 78 79 80 81 82 83 |
ret = led_classdev_register(&spi->dev, &led->ldev); if (ret < 0) goto eledcr; } spi_set_drvdata(spi, dac); return 0; eledcr: while (i--) led_classdev_unregister(&dac->leds[i].ldev); |
ac2dd0f11 leds: Add dac124s... |
84 85 86 87 88 89 90 |
return ret; } static int dac124s085_remove(struct spi_device *spi) { struct dac124s085 *dac = spi_get_drvdata(spi); int i; |
8ec108c03 leds: dac124d085:... |
91 |
for (i = 0; i < ARRAY_SIZE(dac->leds); i++) |
ac2dd0f11 leds: Add dac124s... |
92 |
led_classdev_unregister(&dac->leds[i].ldev); |
ac2dd0f11 leds: Add dac124s... |
93 |
|
ac2dd0f11 leds: Add dac124s... |
94 95 96 97 98 99 100 101 |
return 0; } static struct spi_driver dac124s085_driver = { .probe = dac124s085_probe, .remove = dac124s085_remove, .driver = { .name = "dac124s085", |
ac2dd0f11 leds: Add dac124s... |
102 103 |
}, }; |
19b955768 leds: convert led... |
104 |
module_spi_driver(dac124s085_driver); |
ac2dd0f11 leds: Add dac124s... |
105 106 107 108 |
MODULE_AUTHOR("Guennadi Liakhovetski <lg@denx.de>"); MODULE_DESCRIPTION("DAC124S085 LED driver"); MODULE_LICENSE("GPL v2"); |
e0626e384 spi: prefix modal... |
109 |
MODULE_ALIAS("spi:dac124s085"); |