Skip to content

Commit da059ec

Browse files
Peter UjfalusiSamuel Ortiz
authored andcommitted
mfd: twl: Convert module id definitions to enums
Use enum list for the module definitions (TWL4030_MODULE_*) which will ease up future work with the IDs. At the same time group the IDs in block of five so it is easier to find the ID we are looking for (to count the number they stand for). At the same time define TWL_MODULE_LED so client drivers can switch to use it as soon as it is possible. Acked-by: Tero Kristo <t-kristo@ti.com> Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 0e8f139 commit da059ec

2 files changed

Lines changed: 36 additions & 38 deletions

File tree

‎drivers/mfd/twl-core.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@
6666

6767
/* Triton Core internal information (BEGIN) */
6868

69-
/* Last - for index max*/
70-
#define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
71-
7269
#define TWL_NUM_SLAVES 4
7370

7471
#define SUB_CHIP_ID0 0
@@ -184,7 +181,7 @@ struct twl_mapping {
184181
};
185182
static struct twl_mapping *twl_map;
186183

187-
static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
184+
static struct twl_mapping twl4030_map[] = {
188185
/*
189186
* NOTE: don't change this table without updating the
190187
* <linux/i2c/twl.h> defines for TWL4030_MODULE_*
@@ -327,7 +324,7 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
327324
int sid;
328325
struct twl_client *twl;
329326

330-
if (unlikely(mod_no > TWL_MODULE_LAST)) {
327+
if (unlikely(mod_no >= TWL_MODULE_LAST)) {
331328
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
332329
return -EPERM;
333330
}
@@ -369,7 +366,7 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
369366
int sid;
370367
struct twl_client *twl;
371368

372-
if (unlikely(mod_no > TWL_MODULE_LAST)) {
369+
if (unlikely(mod_no >= TWL_MODULE_LAST)) {
373370
pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
374371
return -EPERM;
375372
}

‎include/linux/i2c/twl.h‎

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,47 @@
3939
* address each module uses within a given i2c slave.
4040
*/
4141

42-
/* Slave 0 (i2c address 0x48) */
43-
#define TWL4030_MODULE_USB 0x00
44-
45-
/* Slave 1 (i2c address 0x49) */
46-
#define TWL4030_MODULE_AUDIO_VOICE 0x01
47-
#define TWL4030_MODULE_GPIO 0x02
48-
#define TWL4030_MODULE_INTBR 0x03
49-
#define TWL4030_MODULE_PIH 0x04
50-
#define TWL4030_MODULE_TEST 0x05
51-
52-
/* Slave 2 (i2c address 0x4a) */
53-
#define TWL4030_MODULE_KEYPAD 0x06
54-
#define TWL4030_MODULE_MADC 0x07
55-
#define TWL4030_MODULE_INTERRUPTS 0x08
56-
#define TWL4030_MODULE_LED 0x09
57-
#define TWL4030_MODULE_MAIN_CHARGE 0x0A
58-
#define TWL4030_MODULE_PRECHARGE 0x0B
59-
#define TWL4030_MODULE_PWM0 0x0C
60-
#define TWL4030_MODULE_PWM1 0x0D
61-
#define TWL4030_MODULE_PWMA 0x0E
62-
#define TWL4030_MODULE_PWMB 0x0F
63-
64-
#define TWL5031_MODULE_ACCESSORY 0x10
65-
#define TWL5031_MODULE_INTERRUPTS 0x11
66-
67-
/* Slave 3 (i2c address 0x4b) */
68-
#define TWL4030_MODULE_BACKUP 0x12
69-
#define TWL4030_MODULE_INT 0x13
70-
#define TWL4030_MODULE_PM_MASTER 0x14
71-
#define TWL4030_MODULE_PM_RECEIVER 0x15
72-
#define TWL4030_MODULE_RTC 0x16
73-
#define TWL4030_MODULE_SECURED_REG 0x17
42+
enum twl4030_module_ids {
43+
TWL4030_MODULE_USB = 0, /* Slave 0 (i2c address 0x48) */
44+
TWL4030_MODULE_AUDIO_VOICE, /* Slave 1 (i2c address 0x49) */
45+
TWL4030_MODULE_GPIO,
46+
TWL4030_MODULE_INTBR,
47+
TWL4030_MODULE_PIH,
48+
49+
TWL4030_MODULE_TEST,
50+
TWL4030_MODULE_KEYPAD, /* Slave 2 (i2c address 0x4a) */
51+
TWL4030_MODULE_MADC,
52+
TWL4030_MODULE_INTERRUPTS,
53+
TWL4030_MODULE_LED,
54+
55+
TWL4030_MODULE_MAIN_CHARGE,
56+
TWL4030_MODULE_PRECHARGE,
57+
TWL4030_MODULE_PWM0,
58+
TWL4030_MODULE_PWM1,
59+
TWL4030_MODULE_PWMA,
60+
61+
TWL4030_MODULE_PWMB,
62+
TWL5031_MODULE_ACCESSORY,
63+
TWL5031_MODULE_INTERRUPTS,
64+
TWL4030_MODULE_BACKUP, /* Slave 3 (i2c address 0x4b) */
65+
TWL4030_MODULE_INT,
66+
67+
TWL4030_MODULE_PM_MASTER,
68+
TWL4030_MODULE_PM_RECEIVER,
69+
TWL4030_MODULE_RTC,
70+
TWL4030_MODULE_SECURED_REG,
71+
TWL4030_MODULE_LAST,
72+
};
7473

74+
/* Similar functionalities implemented in TWL4030/6030 */
7575
#define TWL_MODULE_USB TWL4030_MODULE_USB
7676
#define TWL_MODULE_PIH TWL4030_MODULE_PIH
7777
#define TWL_MODULE_MAIN_CHARGE TWL4030_MODULE_MAIN_CHARGE
7878
#define TWL_MODULE_PM_MASTER TWL4030_MODULE_PM_MASTER
7979
#define TWL_MODULE_PM_RECEIVER TWL4030_MODULE_PM_RECEIVER
8080
#define TWL_MODULE_RTC TWL4030_MODULE_RTC
8181
#define TWL_MODULE_PWM TWL4030_MODULE_PWM0
82+
#define TWL_MODULE_LED TWL4030_MODULE_LED
8283

8384
#define TWL6030_MODULE_ID0 0x0D
8485
#define TWL6030_MODULE_ID1 0x0E

0 commit comments

Comments
 (0)