Skip to content

Commit ac1dec0

Browse files
fabiobaltierikartben
authored andcommitted
led: drop led_context.h
led_context.h contains a single struct with max and min period, current drivers that use it have hardcoded values and they set it at init. This data is not used anywhere, and it makes very little sense to use some SRAM for it. Hardcode the limit for each driver and drop the struct and file. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
1 parent 3d024e0 commit ac1dec0

File tree

6 files changed

+23
-120
lines changed

6 files changed

+23
-120
lines changed

drivers/led/ht16k33.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
LOG_MODULE_REGISTER(ht16k33, CONFIG_LED_LOG_LEVEL);
2323

24-
#include "led_context.h"
25-
2624
/* HT16K33 commands and options */
2725
#define HT16K33_CMD_DISP_DATA_ADDR 0x00
2826

@@ -61,6 +59,8 @@ LOG_MODULE_REGISTER(ht16k33, CONFIG_LED_LOG_LEVEL);
6159
#define HT16K33_KEYSCAN_COLS 13
6260
#define HT16K33_KEYSCAN_DATA_SIZE 6
6361

62+
#define HT16K33_MAX_PERIOD 2000U
63+
6464
struct ht16k33_cfg {
6565
struct i2c_dt_spec i2c;
6666
bool irq_enabled;
@@ -71,7 +71,6 @@ struct ht16k33_cfg {
7171

7272
struct ht16k33_data {
7373
const struct device *dev;
74-
struct led_data dev_data;
7574
/* Shadow buffer for the display data RAM */
7675
uint8_t buffer[HT16K33_DISP_DATA_SIZE];
7776
#ifdef CONFIG_HT16K33_KEYSCAN
@@ -95,13 +94,11 @@ static int ht16k33_led_blink(const struct device *dev, uint32_t led,
9594
ARG_UNUSED(led);
9695

9796
const struct ht16k33_cfg *config = dev->config;
98-
struct ht16k33_data *data = dev->data;
99-
struct led_data *dev_data = &data->dev_data;
10097
uint32_t period;
10198
uint8_t cmd;
10299

103100
period = delay_on + delay_off;
104-
if (period < dev_data->min_period || period > dev_data->max_period) {
101+
if (period > HT16K33_MAX_PERIOD) {
105102
return -EINVAL;
106103
}
107104

@@ -281,7 +278,6 @@ static int ht16k33_init(const struct device *dev)
281278
{
282279
const struct ht16k33_cfg *config = dev->config;
283280
struct ht16k33_data *data = dev->data;
284-
struct led_data *dev_data = &data->dev_data;
285281
uint8_t cmd[1 + HT16K33_DISP_DATA_SIZE]; /* 1 byte command + data */
286282
int err;
287283

@@ -294,10 +290,6 @@ static int ht16k33_init(const struct device *dev)
294290

295291
memset(&data->buffer, 0, sizeof(data->buffer));
296292

297-
/* Hardware specific limits */
298-
dev_data->min_period = 0U;
299-
dev_data->max_period = 2000U;
300-
301293
/* System oscillator on */
302294
cmd[0] = HT16K33_CMD_SYSTEM_SETUP | HT16K33_OPT_S;
303295
err = i2c_write_dt(&config->i2c, cmd, 1);

drivers/led/led_context.h

Lines changed: 0 additions & 34 deletions
This file was deleted.

drivers/led/lp3943.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include <zephyr/logging/log.h>
2929
LOG_MODULE_REGISTER(lp3943);
3030

31-
#include "led_context.h"
32-
3331
/* LP3943 Registers */
3432
#define LP3943_INPUT_1 0x00
3533
#define LP3943_INPUT_2 0x01
@@ -44,6 +42,8 @@ LOG_MODULE_REGISTER(lp3943);
4442

4543
#define LP3943_MASK 0x03
4644

45+
#define LP3943_MAX_PERIOD 1600U
46+
4747
enum lp3943_modes {
4848
LP3943_OFF,
4949
LP3943_ON,
@@ -55,10 +55,6 @@ struct lp3943_config {
5555
struct i2c_dt_spec bus;
5656
};
5757

58-
struct lp3943_data {
59-
struct led_data dev_data;
60-
};
61-
6258
static int lp3943_get_led_reg(uint32_t *led, uint8_t *reg)
6359
{
6460
switch (*led) {
@@ -126,15 +122,12 @@ static int lp3943_led_blink(const struct device *dev, uint32_t led,
126122
uint32_t delay_on, uint32_t delay_off)
127123
{
128124
const struct lp3943_config *config = dev->config;
129-
struct lp3943_data *data = dev->data;
130-
struct led_data *dev_data = &data->dev_data;
131125
int ret;
132126
uint16_t period;
133127
uint8_t reg, val, mode;
134128

135129
period = delay_on + delay_off;
136-
137-
if (period < dev_data->min_period || period > dev_data->max_period) {
130+
if (period > LP3943_MAX_PERIOD) {
138131
return -EINVAL;
139132
}
140133

@@ -151,7 +144,7 @@ static int lp3943_led_blink(const struct device *dev, uint32_t led,
151144
reg = LP3943_PSC1;
152145
}
153146

154-
val = (period * 255U) / dev_data->max_period;
147+
val = period * 255U / LP3943_MAX_PERIOD;
155148
if (i2c_reg_write_byte_dt(&config->bus, reg, val)) {
156149
LOG_ERR("LED write failed");
157150
return -EIO;
@@ -245,23 +238,15 @@ static inline int lp3943_led_off(const struct device *dev, uint32_t led)
245238
static int lp3943_led_init(const struct device *dev)
246239
{
247240
const struct lp3943_config *config = dev->config;
248-
struct lp3943_data *data = dev->data;
249-
struct led_data *dev_data = &data->dev_data;
250241

251242
if (!device_is_ready(config->bus.bus)) {
252243
LOG_ERR("I2C device not ready");
253244
return -ENODEV;
254245
}
255246

256-
/* Hardware specific limits */
257-
dev_data->min_period = 0U;
258-
dev_data->max_period = 1600U;
259-
260247
return 0;
261248
}
262249

263-
static struct lp3943_data lp3943_led_data;
264-
265250
static const struct lp3943_config lp3943_led_config = {
266251
.bus = I2C_DT_SPEC_INST_GET(0),
267252
};
@@ -273,6 +258,6 @@ static DEVICE_API(led, lp3943_led_api) = {
273258
.off = lp3943_led_off,
274259
};
275260

276-
DEVICE_DT_INST_DEFINE(0, &lp3943_led_init, NULL, &lp3943_led_data,
261+
DEVICE_DT_INST_DEFINE(0, &lp3943_led_init, NULL, NULL,
277262
&lp3943_led_config, POST_KERNEL, CONFIG_LED_INIT_PRIORITY,
278263
&lp3943_led_api);

drivers/led/lp5562.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#include <zephyr/logging/log.h>
4242
LOG_MODULE_REGISTER(lp5562);
4343

44-
#include "led_context.h"
45-
4644
/* Registers */
4745
#define LP5562_ENABLE 0x00
4846
#define LP5562_OP_MODE 0x01
@@ -170,10 +168,6 @@ struct lp5562_config {
170168
struct gpio_dt_spec enable_gpio;
171169
};
172170

173-
struct lp5562_data {
174-
struct led_data dev_data;
175-
};
176-
177171
/*
178172
* @brief Get the register for the given LED channel used to directly write a
179173
* brightness value instead of using the execution engines.
@@ -280,8 +274,8 @@ static int lp5562_get_engine_reg_shift(enum lp5562_led_sources engine,
280274
* @param prescale Pointer to the prescale value.
281275
* @param step_time Pointer to the step_time value.
282276
*/
283-
static void lp5562_ms_to_prescale_and_step(struct led_data *data, uint32_t ms,
284-
uint8_t *prescale, uint8_t *step_time)
277+
static void lp5562_ms_to_prescale_and_step(uint32_t ms, uint8_t *prescale,
278+
uint8_t *step_time)
285279
{
286280
/*
287281
* One step with the prescaler set to 0 takes 0.49ms. The max value for
@@ -637,17 +631,14 @@ static int lp5562_program_ramp(const struct device *dev,
637631
uint8_t step_count,
638632
enum lp5562_engine_fade_dirs fade_dir)
639633
{
640-
struct lp5562_data *data = dev->data;
641-
struct led_data *dev_data = &data->dev_data;
642634
uint8_t prescale, step_time;
643635

644-
if ((time_per_step < dev_data->min_period) ||
645-
(time_per_step > dev_data->max_period)) {
636+
if (time_per_step < LP5562_MIN_BLINK_PERIOD ||
637+
time_per_step > LP5562_MAX_BLINK_PERIOD) {
646638
return -EINVAL;
647639
}
648640

649-
lp5562_ms_to_prescale_and_step(dev_data, time_per_step,
650-
&prescale, &step_time);
641+
lp5562_ms_to_prescale_and_step(time_per_step, &prescale, &step_time);
651642

652643
return lp5562_program_command(dev, engine, command_index,
653644
LP5562_PROG_COMMAND_RAMP_TIME(prescale, step_time),
@@ -984,8 +975,6 @@ static int lp5562_disable(const struct device *dev)
984975
static int lp5562_led_init(const struct device *dev)
985976
{
986977
const struct lp5562_config *config = dev->config;
987-
struct lp5562_data *data = dev->data;
988-
struct led_data *dev_data = &data->dev_data;
989978
const struct gpio_dt_spec *enable_gpio = &config->enable_gpio;
990979
int ret;
991980

@@ -1010,10 +999,6 @@ static int lp5562_led_init(const struct device *dev)
1010999
return ret;
10111000
}
10121001

1013-
/* Hardware specific limits */
1014-
dev_data->min_period = LP5562_MIN_BLINK_PERIOD;
1015-
dev_data->max_period = LP5562_MAX_BLINK_PERIOD;
1016-
10171002
ret = lp5562_led_update_current(dev);
10181003
if (ret) {
10191004
LOG_ERR("Setting current setting LP5562 LED chip failed.");
@@ -1081,9 +1066,8 @@ static int lp5562_pm_action(const struct device *dev, enum pm_device_action acti
10811066
\
10821067
PM_DEVICE_DT_INST_DEFINE(id, lp5562_pm_action); \
10831068
\
1084-
struct lp5562_data lp5562_data_##id; \
10851069
DEVICE_DT_INST_DEFINE(id, &lp5562_led_init, PM_DEVICE_DT_INST_GET(id), \
1086-
&lp5562_data_##id, \
1070+
NULL, \
10871071
&lp5562_config_##id, POST_KERNEL, \
10881072
CONFIG_LED_INIT_PRIORITY, \
10891073
&lp5562_led_api); \

drivers/led/pca9633.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <zephyr/logging/log.h>
2121
LOG_MODULE_REGISTER(pca9633);
2222

23-
#include "led_context.h"
24-
2523
/* PCA9633 select registers determine the source that drives LED outputs */
2624
#define PCA9633_LED_OFF 0x0 /* LED driver off */
2725
#define PCA9633_LED_ON 0x1 /* LED driver on */
@@ -44,27 +42,24 @@ LOG_MODULE_REGISTER(pca9633);
4442

4543
#define PCA9633_MASK 0x03
4644

45+
#define PCA9633_MIN_PERIOD 41U
46+
#define PCA9633_MAX_PERIOD 10667U
47+
4748
struct pca9633_config {
4849
struct i2c_dt_spec i2c;
4950
bool disable_allcall;
5051
};
5152

52-
struct pca9633_data {
53-
struct led_data dev_data;
54-
};
55-
5653
static int pca9633_led_blink(const struct device *dev, uint32_t led,
5754
uint32_t delay_on, uint32_t delay_off)
5855
{
59-
struct pca9633_data *data = dev->data;
6056
const struct pca9633_config *config = dev->config;
61-
struct led_data *dev_data = &data->dev_data;
6257
uint8_t gdc, gfrq;
6358
uint32_t period;
6459

6560
period = delay_on + delay_off;
6661

67-
if (period < dev_data->min_period || period > dev_data->max_period) {
62+
if (period < PCA9633_MIN_PERIOD || period > PCA9633_MAX_PERIOD) {
6863
return -EINVAL;
6964
}
7065

@@ -179,8 +174,6 @@ static inline int pca9633_led_off(const struct device *dev, uint32_t led)
179174
static int pca9633_led_init(const struct device *dev)
180175
{
181176
const struct pca9633_config *config = dev->config;
182-
struct pca9633_data *data = dev->data;
183-
struct led_data *dev_data = &data->dev_data;
184177

185178
if (!device_is_ready(config->i2c.bus)) {
186179
LOG_ERR("I2C bus is not ready");
@@ -200,9 +193,6 @@ static int pca9633_led_init(const struct device *dev)
200193
LOG_ERR("LED reg update failed");
201194
return -EIO;
202195
}
203-
/* Hardware specific limits */
204-
dev_data->min_period = 41U;
205-
dev_data->max_period = 10667U;
206196

207197
return 0;
208198
}
@@ -219,10 +209,9 @@ static DEVICE_API(led, pca9633_led_api) = {
219209
.i2c = I2C_DT_SPEC_INST_GET(id), \
220210
.disable_allcall = DT_INST_PROP(id, disable_allcall), \
221211
}; \
222-
static struct pca9633_data pca9633_##id##_data; \
223212
\
224213
DEVICE_DT_INST_DEFINE(id, &pca9633_led_init, NULL, \
225-
&pca9633_##id##_data, \
214+
NULL, \
226215
&pca9633_##id##_cfg, POST_KERNEL, \
227216
CONFIG_LED_INIT_PRIORITY, \
228217
&pca9633_led_api);

0 commit comments

Comments
 (0)