Source
137
137
struct ofnode_phandle_args *args)
138
138
{
139
139
struct dm_gpio_ops *ops = gpio_get_ops(desc->dev);
140
140
141
141
if (ops->xlate)
142
142
return ops->xlate(desc->dev, desc, args);
143
143
else
144
144
return gpio_xlate_offs_flags(desc->dev, desc, args);
145
145
}
146
146
147
-
#if defined(CONFIG_DM_GPIO_HOG)
147
+
#if defined(CONFIG_GPIO_HOG)
148
148
149
149
struct gpio_hog_priv {
150
150
struct gpio_desc gpiod;
151
151
};
152
152
153
153
struct gpio_hog_data {
154
154
int gpiod_flags;
155
155
int value;
156
156
u32 val[2];
157
157
};
174
174
printf("%s: missing gpio-hog state.\n", __func__);
175
175
return -EINVAL;
176
176
}
177
177
ret = dev_read_u32_array(dev, "gpios", plat->val, 2);
178
178
if (ret) {
179
179
printf("%s: wrong gpios property, 2 values needed %d\n",
180
180
__func__, ret);
181
181
return ret;
182
182
}
183
183
nodename = dev_read_string(dev, "line-name");
184
-
if (!nodename)
185
-
nodename = dev_read_name(dev);
186
-
device_set_name(dev, nodename);
184
+
if (nodename)
185
+
device_set_name(dev, nodename);
187
186
188
187
return 0;
189
188
}
190
189
191
190
static int gpio_hog_probe(struct udevice *dev)
192
191
{
193
192
struct gpio_hog_data *plat = dev_get_platdata(dev);
194
193
struct gpio_hog_priv *priv = dev_get_priv(dev);
195
194
int ret;
196
195
197
196
ret = gpio_dev_request_index(dev->parent, dev->name, "gpio-hog",
198
197
plat->val[0], plat->gpiod_flags,
199
198
plat->val[1], &priv->gpiod);
200
199
if (ret < 0) {
201
200
debug("%s: node %s could not get gpio.\n", __func__,
202
201
dev->name);
203
202
return ret;
204
203
}
205
-
dm_gpio_set_dir(&priv->gpiod);
206
-
if (plat->gpiod_flags == GPIOD_IS_OUT)
207
-
dm_gpio_set_value(&priv->gpiod, plat->value);
204
+
205
+
if (plat->gpiod_flags == GPIOD_IS_OUT) {
206
+
ret = dm_gpio_set_value(&priv->gpiod, plat->value);
207
+
if (ret < 0) {
208
+
debug("%s: node %s could not set gpio.\n", __func__,
209
+
dev->name);
210
+
return ret;
211
+
}
212
+
}
208
213
209
214
return 0;
210
215
}
211
216
212
217
int gpio_hog_probe_all(void)
213
218
{
214
219
struct udevice *dev;
215
220
int ret;
221
+
int retval = 0;
216
222
217
223
for (uclass_first_device(UCLASS_NOP, &dev);
218
224
dev;
219
225
uclass_find_next_device(&dev)) {
220
226
if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
221
227
ret = device_probe(dev);
222
-
if (ret)
223
-
return ret;
228
+
if (ret) {
229
+
printf("Failed to probe device %s err: %d\n",
230
+
dev->name, ret);
231
+
retval = ret;
232
+
}
224
233
}
225
234
}
226
235
227
-
return 0;
236
+
return retval;
228
237
}
229
238
230
-
struct gpio_desc *gpio_hog_lookup_name(const char *name)
239
+
int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
231
240
{
232
241
struct udevice *dev;
233
242
243
+
*desc = NULL;
234
244
gpio_hog_probe_all();
235
245
if (!uclass_get_device_by_name(UCLASS_NOP, name, &dev)) {
236
246
struct gpio_hog_priv *priv = dev_get_priv(dev);
237
247
238
-
return &priv->gpiod;
248
+
*desc = &priv->gpiod;
249
+
return 0;
239
250
}
240
251
241
-
return NULL;
252
+
return -ENODEV;
242
253
}
243
254
244
255
U_BOOT_DRIVER(gpio_hog) = {
245
256
.name = "gpio_hog",
246
257
.id = UCLASS_NOP,
247
258
.ofdata_to_platdata = gpio_hog_ofdata_to_platdata,
248
259
.probe = gpio_hog_probe,
249
260
.priv_auto_alloc_size = sizeof(struct gpio_hog_priv),
250
261
.platdata_auto_alloc_size = sizeof(struct gpio_hog_data),
251
262
};
252
263
#else
253
-
struct gpio_desc *gpio_hog_lookup_name(const char *name)
264
+
int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
254
265
{
255
-
return NULL;
266
+
return 0;
256
267
}
257
268
#endif
258
269
259
270
int dm_gpio_request(struct gpio_desc *desc, const char *label)
260
271
{
261
272
struct udevice *dev = desc->dev;
262
273
struct gpio_dev_priv *uc_priv;
263
274
char *str;
264
275
int ret;
265
276
748
759
if (ret < 0)
749
760
return ret;
750
761
else if (ret)
751
762
vector |= bitmask;
752
763
bitmask <<= 1;
753
764
}
754
765
755
766
return vector;
756
767
}
757
768
769
+
/**
770
+
* gpio_request_tail: common work for requesting a gpio.
771
+
*
772
+
* ret: return value from previous work in function which calls
773
+
* this function.
774
+
* This seems bogus (why calling this function instead not
775
+
* calling it and end caller function instead?).
776
+
* Because on error in caller function we want to set some
777
+
* default values in gpio desc and have a common error
778
+
* debug message, which provides this function.
779
+
* nodename: Name of node for which gpio gets requested
780
+
* used for gpio label name.
781
+
* args: pointer to output arguments structure
782
+
* list_name: Name of GPIO list
783
+
* used for gpio label name.
784
+
* index: gpio index in gpio list
785
+
* used for gpio label name.
786
+
* desc: pointer to gpio descriptor, filled from this
787
+
* function.
788
+
* flags: gpio flags to use.
789
+
* add_index: should index added to gpio label name
790
+
* gpio_dev: pointer to gpio device from which the gpio
791
+
* will be requested. If NULL try to get the
792
+
* gpio device with uclass_get_device_by_ofnode()
793
+
*
794
+
* return: In error case this function sets default values in
795
+
* gpio descriptor, also emmits a debug message.
796
+
* On success it returns 0 else the error code from
797
+
* function calls, or the error code passed through
798
+
* ret to this function.
799
+
*
800
+
*/
758
801
static int gpio_request_tail(int ret, const char *nodename,
759
802
struct ofnode_phandle_args *args,
760
803
const char *list_name, int index,
761
804
struct gpio_desc *desc, int flags,
762
-
bool add_index, struct udevice *dev)
805
+
bool add_index, struct udevice *gpio_dev)
763
806
{
764
-
desc->dev = dev;
807
+
desc->dev = gpio_dev;
765
808
desc->offset = 0;
766
809
desc->flags = 0;
767
810
if (ret)
768
811
goto err;
769
812
770
813
if (!desc->dev) {
771
814
ret = uclass_get_device_by_ofnode(UCLASS_GPIO, args->node,
772
815
&desc->dev);
773
816
if (ret) {
774
-
debug("%s: uclass_get_device_by_ofnode failed\n", __func__);
817
+
debug("%s: uclass_get_device_by_ofnode failed\n",
818
+
__func__);
775
819
goto err;
776
820
}
777
821
}
778
822
ret = gpio_find_and_xlate(desc, args);
779
823
if (ret) {
780
824
debug("%s: gpio_find_and_xlate failed\n", __func__);
781
825
goto err;
782
826
}
783
827
ret = dm_gpio_requestf(desc, add_index ? "%s.%s%d" : "%s.%s",
784
828
nodename, list_name, index);
982
1026
args.args_count = 2;
983
1027
args.args[0] = index;
984
1028
args.args[1] = dtflags;
985
1029
986
1030
return gpio_request_tail(0, nodename, &args, list_name, index, desc,
987
1031
flags, 0, dev);
988
1032
}
989
1033
990
1034
static int gpio_post_bind(struct udevice *dev)
991
1035
{
992
-
#if defined(CONFIG_DM_GPIO_HOG)
993
1036
struct udevice *child;
994
1037
ofnode node;
995
-
#endif
996
1038
997
1039
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
998
1040
struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops(dev);
999
1041
static int reloc_done;
1000
1042
1001
1043
if (!reloc_done) {
1002
1044
if (ops->request)
1003
1045
ops->request += gd->reloc_off;
1004
1046
if (ops->free)
1005
1047
ops->free += gd->reloc_off;
1017
1059
ops->set_open_drain += gd->reloc_off;
1018
1060
if (ops->get_function)
1019
1061
ops->get_function += gd->reloc_off;
1020
1062
if (ops->xlate)
1021
1063
ops->xlate += gd->reloc_off;
1022
1064
1023
1065
reloc_done++;
1024
1066
}
1025
1067
#endif
1026
1068
1027
-
#if defined(CONFIG_DM_GPIO_HOG)
1028
-
dev_for_each_subnode(node, dev) {
1029
-
if (ofnode_read_bool(node, "gpio-hog")) {
1030
-
const char *name = ofnode_get_name(node);
1031
-
1032
-
device_bind_driver_to_node(dev, "gpio_hog", name,
1033
-
node, &child);
1069
+
if (IS_ENABLED(CONFIG_GPIO_HOG)) {
1070
+
dev_for_each_subnode(node, dev) {
1071
+
if (ofnode_read_bool(node, "gpio-hog")) {
1072
+
const char *name = ofnode_get_name(node);
1073
+
int ret;
1074
+
1075
+
ret = device_bind_driver_to_node(dev,
1076
+
"gpio_hog",
1077
+
name, node,
1078
+
&child);
1079
+
if (ret)
1080
+
return ret;
1081
+
}
1034
1082
}
1035
1083
}
1036
-
#endif
1037
1084
return 0;
1038
1085
}
1039
1086
1040
1087
UCLASS_DRIVER(gpio) = {
1041
1088
.id = UCLASS_GPIO,
1042
1089
.name = "gpio",
1043
1090
.flags = DM_UC_FLAG_SEQ_ALIAS,
1044
1091
.post_probe = gpio_post_probe,
1045
1092
.post_bind = gpio_post_bind,
1046
1093
.pre_remove = gpio_pre_remove,