Source
54
54
* methods.
55
55
*
56
56
* Return: 0 if OK, -ve on error.
57
57
*/
58
58
static int _read_board_variant_data(struct udevice *dev)
59
59
{
60
60
struct board_gazerbeam_priv *priv = dev_get_priv(dev);
61
61
struct udevice *i2c_bus;
62
62
struct udevice *dummy;
63
63
char *listname;
64
-
int mc4, mc2, sc, con;
64
+
int mc4, mc2, sc, mc2_sc, con;
65
65
int gpio_num;
66
66
int res;
67
67
68
68
res = uclass_get_device_by_seq(UCLASS_I2C, I2C_BUS_SEQ_NO, &i2c_bus);
69
69
if (res) {
70
70
debug("%s: Could not get I2C bus %d (err = %d)\n",
71
71
dev->name, I2C_BUS_SEQ_NO, res);
72
72
return res;
73
73
}
74
74
75
75
if (!i2c_bus) {
76
76
debug("%s: Could not get I2C bus %d\n",
77
77
dev->name, I2C_BUS_SEQ_NO);
78
78
return -EIO;
79
79
}
80
80
81
-
mc2 = !dm_i2c_probe(i2c_bus, MC2_EXPANDER_ADDR, 0, &dummy);
81
+
mc2_sc = !dm_i2c_probe(i2c_bus, MC2_EXPANDER_ADDR, 0, &dummy);
82
82
mc4 = !dm_i2c_probe(i2c_bus, MC4_EXPANDER_ADDR, 0, &dummy);
83
83
84
-
if (mc2 && mc4) {
84
+
if (mc2_sc && mc4) {
85
85
debug("%s: Board hardware configuration inconsistent.\n",
86
86
dev->name);
87
87
return -EINVAL;
88
88
}
89
89
90
-
listname = mc2 ? "var-gpios-mc2" : "var-gpios-mc4";
90
+
listname = mc2_sc ? "var-gpios-mc2" : "var-gpios-mc4";
91
91
92
92
gpio_num = gpio_request_list_by_name(dev, listname, priv->var_gpios,
93
93
ARRAY_SIZE(priv->var_gpios),
94
94
GPIOD_IS_IN);
95
95
if (gpio_num < 0) {
96
96
debug("%s: Requesting gpio list %s failed (err = %d).\n",
97
97
dev->name, listname, gpio_num);
98
98
return gpio_num;
99
99
}
100
100
101
101
sc = dm_gpio_get_value(&priv->var_gpios[SC_GPIO_NO]);
102
102
if (sc < 0) {
103
103
debug("%s: Error while reading 'sc' GPIO (err = %d)",
104
104
dev->name, sc);
105
105
return sc;
106
106
}
107
107
108
-
con = dm_gpio_get_value(&priv->var_gpios[CON_GPIO_NO]);
109
-
if (con < 0) {
110
-
debug("%s: Error while reading 'con' GPIO (err = %d)",
111
-
dev->name, con);
112
-
return con;
113
-
}
108
+
mc2 = mc2_sc ? (sc ? 0 : 1) : 0;
114
109
115
110
if ((sc && mc2) || (sc && mc4) || (!sc && !mc2 && !mc4)) {
116
111
debug("%s: Board hardware configuration inconsistent.\n",
117
112
dev->name);
118
113
return -EINVAL;
119
114
}
120
115
116
+
con = dm_gpio_get_value(&priv->var_gpios[CON_GPIO_NO]);
117
+
if (con < 0) {
118
+
debug("%s: Error while reading 'con' GPIO (err = %d)",
119
+
dev->name, con);
120
+
return con;
121
+
}
122
+
121
123
priv->variant = con ? VAR_CON : VAR_CPU;
122
124
123
125
priv->multichannel = mc4 ? 4 : (mc2 ? 2 : (sc ? 1 : 0));
124
126
125
127
return 0;
126
128
}
127
129
128
130
/**
129
131
* _read_hwversion() - Read the hardware version from the board.
130
132
* @dev: The board device for which to read the hardware version.