Commit 45aac6dd7afe73be69ab432c06eb97f9920c491f

Authored by Lukasz Majewski
Committed by Stefano Babic
1 parent feeff1567f

imx: Rewrite display5 get_board_id() function to use dm_gpio_* API

The get_board_id() function was using the old gpio_* compatibility layer
to read HW and SW ID numbers encoded on the PCB board.

After this change the new dm_gpio* API is used for this purpose.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

Showing 1 changed file with 21 additions and 32 deletions Side-by-side Diff

board/liebherr/display5/display5.c
... ... @@ -36,60 +36,49 @@
36 36 static u32 cpu_id;
37 37 static u32 unit_id;
38 38  
39   -#define SW0 IMX_GPIO_NR(2, 4)
40   -#define SW1 IMX_GPIO_NR(2, 5)
41   -#define SW2 IMX_GPIO_NR(2, 6)
42   -#define SW3 IMX_GPIO_NR(2, 7)
43   -#define HW0 IMX_GPIO_NR(6, 7)
44   -#define HW1 IMX_GPIO_NR(6, 9)
45   -#define HW2 IMX_GPIO_NR(6, 10)
46   -#define HW3 IMX_GPIO_NR(6, 11)
47   -#define HW4 IMX_GPIO_NR(4, 7)
48   -#define HW5 IMX_GPIO_NR(4, 11)
49   -#define HW6 IMX_GPIO_NR(4, 13)
50   -#define HW7 IMX_GPIO_NR(4, 15)
51   -
52   -int gpio_table_sw_ids[] = {
53   - SW0, SW1, SW2, SW3
  39 +const char *gpio_table_sw_names[] = {
  40 + "GPIO2_4", "GPIO2_5", "GPIO2_6", "GPIO2_7"
54 41 };
55 42  
56 43 const char *gpio_table_sw_ids_names[] = {
57 44 "sw0", "sw1", "sw2", "sw3"
58 45 };
59 46  
60   -int gpio_table_hw_ids[] = {
61   - HW0, HW1, HW2, HW3, HW4, HW5, HW6, HW7
  47 +const char *gpio_table_hw_names[] = {
  48 + "GPIO6_7", "GPIO6_9", "GPIO6_10", "GPIO6_11",
  49 + "GPIO4_7", "GPIO4_11", "GPIO4_13", "GPIO4_15"
62 50 };
63 51  
64 52 const char *gpio_table_hw_ids_names[] = {
65 53 "hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6", "hw7"
66 54 };
67 55  
68   -static int get_board_id(int *ids, const char **c, int size,
69   - bool *valid, u32 *id)
  56 +static int get_board_id(const char **pin_names, const char **ids_names,
  57 + int size, bool *valid, u32 *id)
70 58 {
  59 + struct gpio_desc desc;
71 60 int i, ret, val;
72 61  
73 62 *valid = false;
74 63  
75 64 for (i = 0; i < size; i++) {
76   - ret = gpio_request(ids[i], c[i]);
  65 + memset(&desc, 0, sizeof(desc));
  66 +
  67 + ret = dm_gpio_lookup_name(pin_names[i], &desc);
77 68 if (ret) {
78   - printf("Can't request SWx gpios\n");
  69 + printf("Can't lookup request SWx gpios\n");
79 70 return ret;
80 71 }
81   - }
82 72  
83   - for (i = 0; i < size; i++) {
84   - ret = gpio_direction_input(ids[i]);
  73 + ret = dm_gpio_request(&desc, ids_names[i]);
85 74 if (ret) {
86   - printf("Can't set SWx gpios direction\n");
  75 + printf("Can't lookup request SWx gpios\n");
87 76 return ret;
88 77 }
89   - }
90 78  
91   - for (i = 0; i < size; i++) {
92   - val = gpio_get_value(ids[i]);
  79 + dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN);
  80 +
  81 + val = dm_gpio_get_value(&desc);
93 82 if (val < 0) {
94 83 printf("Can't get SW%d ID\n", i);
95 84 *id = 0;
96 85  
... ... @@ -176,12 +165,12 @@
176 165 /* Setup misc (application specific) stuff */
177 166 SETUP_IOMUX_PADS(misc_pads);
178 167  
179   - get_board_id(gpio_table_sw_ids, &gpio_table_sw_ids_names[0],
180   - ARRAY_SIZE(gpio_table_sw_ids), &sw_ids_valid, &unit_id);
  168 + get_board_id(gpio_table_sw_names, &gpio_table_sw_ids_names[0],
  169 + ARRAY_SIZE(gpio_table_sw_names), &sw_ids_valid, &unit_id);
181 170 debug("SWx unit_id 0x%x\n", unit_id);
182 171  
183   - get_board_id(gpio_table_hw_ids, &gpio_table_hw_ids_names[0],
184   - ARRAY_SIZE(gpio_table_hw_ids), &hw_ids_valid, &cpu_id);
  172 + get_board_id(gpio_table_hw_names, &gpio_table_hw_ids_names[0],
  173 + ARRAY_SIZE(gpio_table_hw_names), &hw_ids_valid, &cpu_id);
185 174 debug("HWx cpu_id 0x%x\n", cpu_id);
186 175  
187 176 if (hw_ids_valid && sw_ids_valid)