Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_GPIO_CONSUMER_H
3#define __LINUX_GPIO_CONSUMER_H
4
5#include <linux/bug.h>
6#include <linux/err.h>
7#include <linux/kernel.h>
8
9struct device;
10
11/**
12 * Opaque descriptor for a GPIO. These are obtained using gpiod_get() and are
13 * preferable to the old integer-based handles.
14 *
15 * Contrary to integers, a pointer to a gpio_desc is guaranteed to be valid
16 * until the GPIO is released.
17 */
18struct gpio_desc;
19
20/**
21 * Opaque descriptor for a structure of GPIO array attributes. This structure
22 * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be
23 * passed back to get/set array functions in order to activate fast processing
24 * path if applicable.
25 */
26struct gpio_array;
27
28/**
29 * Struct containing an array of descriptors that can be obtained using
30 * gpiod_get_array().
31 */
32struct gpio_descs {
33 struct gpio_array *info;
34 unsigned int ndescs;
35 struct gpio_desc *desc[];
36};
37
38#define GPIOD_FLAGS_BIT_DIR_SET BIT(0)
39#define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
40#define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
41#define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
42#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
43
44/**
45 * Optional flags that can be passed to one of gpiod_* to configure direction
46 * and output value. These values cannot be OR'd.
47 */
48enum gpiod_flags {
49 GPIOD_ASIS = 0,
50 GPIOD_IN = GPIOD_FLAGS_BIT_DIR_SET,
51 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
52 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
53 GPIOD_FLAGS_BIT_DIR_VAL,
54 GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
55 GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
56};
57
58#ifdef CONFIG_GPIOLIB
59
60/* Return the number of GPIOs associated with a device / function */
61int gpiod_count(struct device *dev, const char *con_id);
62
63/* Acquire and dispose GPIOs */
64struct gpio_desc *__must_check gpiod_get(struct device *dev,
65 const char *con_id,
66 enum gpiod_flags flags);
67struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
68 const char *con_id,
69 unsigned int idx,
70 enum gpiod_flags flags);
71struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
72 const char *con_id,
73 enum gpiod_flags flags);
74struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
75 const char *con_id,
76 unsigned int index,
77 enum gpiod_flags flags);
78struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
79 const char *con_id,
80 enum gpiod_flags flags);
81struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
82 const char *con_id,
83 enum gpiod_flags flags);
84void gpiod_put(struct gpio_desc *desc);
85void gpiod_put_array(struct gpio_descs *descs);
86
87struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
88 const char *con_id,
89 enum gpiod_flags flags);
90struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
91 const char *con_id,
92 unsigned int idx,
93 enum gpiod_flags flags);
94struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
95 const char *con_id,
96 enum gpiod_flags flags);
97struct gpio_desc *__must_check
98devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
99 unsigned int index, enum gpiod_flags flags);
100struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
101 const char *con_id,
102 enum gpiod_flags flags);
103struct gpio_descs *__must_check
104devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
105 enum gpiod_flags flags);
106void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
107void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
108void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
109
110int gpiod_get_direction(struct gpio_desc *desc);
111int gpiod_direction_input(struct gpio_desc *desc);
112int gpiod_direction_output(struct gpio_desc *desc, int value);
113int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
114
115/* Value get/set from non-sleeping context */
116int gpiod_get_value(const struct gpio_desc *desc);
117int gpiod_get_array_value(unsigned int array_size,
118 struct gpio_desc **desc_array,
119 struct gpio_array *array_info,
120 unsigned long *value_bitmap);
121void gpiod_set_value(struct gpio_desc *desc, int value);
122int gpiod_set_array_value(unsigned int array_size,
123 struct gpio_desc **desc_array,
124 struct gpio_array *array_info,
125 unsigned long *value_bitmap);
126int gpiod_get_raw_value(const struct gpio_desc *desc);
127int gpiod_get_raw_array_value(unsigned int array_size,
128 struct gpio_desc **desc_array,
129 struct gpio_array *array_info,
130 unsigned long *value_bitmap);
131void gpiod_set_raw_value(struct gpio_desc *desc, int value);
132int gpiod_set_raw_array_value(unsigned int array_size,
133 struct gpio_desc **desc_array,
134 struct gpio_array *array_info,
135 unsigned long *value_bitmap);
136
137/* Value get/set from sleeping context */
138int gpiod_get_value_cansleep(const struct gpio_desc *desc);
139int gpiod_get_array_value_cansleep(unsigned int array_size,
140 struct gpio_desc **desc_array,
141 struct gpio_array *array_info,
142 unsigned long *value_bitmap);
143void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
144int gpiod_set_array_value_cansleep(unsigned int array_size,
145 struct gpio_desc **desc_array,
146 struct gpio_array *array_info,
147 unsigned long *value_bitmap);
148int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
149int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
150 struct gpio_desc **desc_array,
151 struct gpio_array *array_info,
152 unsigned long *value_bitmap);
153void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
154int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
155 struct gpio_desc **desc_array,
156 struct gpio_array *array_info,
157 unsigned long *value_bitmap);
158
159int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
160int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
161
162int gpiod_is_active_low(const struct gpio_desc *desc);
163int gpiod_cansleep(const struct gpio_desc *desc);
164
165int gpiod_to_irq(const struct gpio_desc *desc);
166int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
167
168/* Convert between the old gpio_ and new gpiod_ interfaces */
169struct gpio_desc *gpio_to_desc(unsigned gpio);
170int desc_to_gpio(const struct gpio_desc *desc);
171
172/* Child properties interface */
173struct fwnode_handle;
174
175struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
176 const char *propname, int index,
177 enum gpiod_flags dflags,
178 const char *label);
179struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
180 const char *con_id, int index,
181 enum gpiod_flags flags,
182 const char *label);
183struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
184 struct fwnode_handle *child,
185 const char *con_id, int index,
186 enum gpiod_flags flags,
187 const char *label);
188
189#else /* CONFIG_GPIOLIB */
190
191static inline int gpiod_count(struct device *dev, const char *con_id)
192{
193 return 0;
194}
195
196static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
197 const char *con_id,
198 enum gpiod_flags flags)
199{
200 return ERR_PTR(-ENOSYS);
201}
202static inline struct gpio_desc *__must_check
203gpiod_get_index(struct device *dev,
204 const char *con_id,
205 unsigned int idx,
206 enum gpiod_flags flags)
207{
208 return ERR_PTR(-ENOSYS);
209}
210
211static inline struct gpio_desc *__must_check
212gpiod_get_optional(struct device *dev, const char *con_id,
213 enum gpiod_flags flags)
214{
215 return NULL;
216}
217
218static inline struct gpio_desc *__must_check
219gpiod_get_index_optional(struct device *dev, const char *con_id,
220 unsigned int index, enum gpiod_flags flags)
221{
222 return NULL;
223}
224
225static inline struct gpio_descs *__must_check
226gpiod_get_array(struct device *dev, const char *con_id,
227 enum gpiod_flags flags)
228{
229 return ERR_PTR(-ENOSYS);
230}
231
232static inline struct gpio_descs *__must_check
233gpiod_get_array_optional(struct device *dev, const char *con_id,
234 enum gpiod_flags flags)
235{
236 return NULL;
237}
238
239static inline void gpiod_put(struct gpio_desc *desc)
240{
241 might_sleep();
242
243 /* GPIO can never have been requested */
244 WARN_ON(desc);
245}
246
247static inline void devm_gpiod_unhinge(struct device *dev,
248 struct gpio_desc *desc)
249{
250 might_sleep();
251
252 /* GPIO can never have been requested */
253 WARN_ON(desc);
254}
255
256static inline void gpiod_put_array(struct gpio_descs *descs)
257{
258 might_sleep();
259
260 /* GPIO can never have been requested */
261 WARN_ON(descs);
262}
263
264static inline struct gpio_desc *__must_check
265devm_gpiod_get(struct device *dev,
266 const char *con_id,
267 enum gpiod_flags flags)
268{
269 return ERR_PTR(-ENOSYS);
270}
271static inline
272struct gpio_desc *__must_check
273devm_gpiod_get_index(struct device *dev,
274 const char *con_id,
275 unsigned int idx,
276 enum gpiod_flags flags)
277{
278 return ERR_PTR(-ENOSYS);
279}
280
281static inline struct gpio_desc *__must_check
282devm_gpiod_get_optional(struct device *dev, const char *con_id,
283 enum gpiod_flags flags)
284{
285 return NULL;
286}
287
288static inline struct gpio_desc *__must_check
289devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
290 unsigned int index, enum gpiod_flags flags)
291{
292 return NULL;
293}
294
295static inline struct gpio_descs *__must_check
296devm_gpiod_get_array(struct device *dev, const char *con_id,
297 enum gpiod_flags flags)
298{
299 return ERR_PTR(-ENOSYS);
300}
301
302static inline struct gpio_descs *__must_check
303devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
304 enum gpiod_flags flags)
305{
306 return NULL;
307}
308
309static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
310{
311 might_sleep();
312
313 /* GPIO can never have been requested */
314 WARN_ON(desc);
315}
316
317static inline void devm_gpiod_put_array(struct device *dev,
318 struct gpio_descs *descs)
319{
320 might_sleep();
321
322 /* GPIO can never have been requested */
323 WARN_ON(descs);
324}
325
326
327static inline int gpiod_get_direction(const struct gpio_desc *desc)
328{
329 /* GPIO can never have been requested */
330 WARN_ON(desc);
331 return -ENOSYS;
332}
333static inline int gpiod_direction_input(struct gpio_desc *desc)
334{
335 /* GPIO can never have been requested */
336 WARN_ON(desc);
337 return -ENOSYS;
338}
339static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
340{
341 /* GPIO can never have been requested */
342 WARN_ON(desc);
343 return -ENOSYS;
344}
345static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
346{
347 /* GPIO can never have been requested */
348 WARN_ON(desc);
349 return -ENOSYS;
350}
351
352
353static inline int gpiod_get_value(const struct gpio_desc *desc)
354{
355 /* GPIO can never have been requested */
356 WARN_ON(desc);
357 return 0;
358}
359static inline int gpiod_get_array_value(unsigned int array_size,
360 struct gpio_desc **desc_array,
361 struct gpio_array *array_info,
362 unsigned long *value_bitmap)
363{
364 /* GPIO can never have been requested */
365 WARN_ON(desc_array);
366 return 0;
367}
368static inline void gpiod_set_value(struct gpio_desc *desc, int value)
369{
370 /* GPIO can never have been requested */
371 WARN_ON(desc);
372}
373static inline int gpiod_set_array_value(unsigned int array_size,
374 struct gpio_desc **desc_array,
375 struct gpio_array *array_info,
376 unsigned long *value_bitmap)
377{
378 /* GPIO can never have been requested */
379 WARN_ON(desc_array);
380 return 0;
381}
382static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
383{
384 /* GPIO can never have been requested */
385 WARN_ON(desc);
386 return 0;
387}
388static inline int gpiod_get_raw_array_value(unsigned int array_size,
389 struct gpio_desc **desc_array,
390 struct gpio_array *array_info,
391 unsigned long *value_bitmap)
392{
393 /* GPIO can never have been requested */
394 WARN_ON(desc_array);
395 return 0;
396}
397static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
398{
399 /* GPIO can never have been requested */
400 WARN_ON(desc);
401}
402static inline int gpiod_set_raw_array_value(unsigned int array_size,
403 struct gpio_desc **desc_array,
404 struct gpio_array *array_info,
405 unsigned long *value_bitmap)
406{
407 /* GPIO can never have been requested */
408 WARN_ON(desc_array);
409 return 0;
410}
411
412static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
413{
414 /* GPIO can never have been requested */
415 WARN_ON(desc);
416 return 0;
417}
418static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
419 struct gpio_desc **desc_array,
420 struct gpio_array *array_info,
421 unsigned long *value_bitmap)
422{
423 /* GPIO can never have been requested */
424 WARN_ON(desc_array);
425 return 0;
426}
427static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
428{
429 /* GPIO can never have been requested */
430 WARN_ON(desc);
431}
432static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
433 struct gpio_desc **desc_array,
434 struct gpio_array *array_info,
435 unsigned long *value_bitmap)
436{
437 /* GPIO can never have been requested */
438 WARN_ON(desc_array);
439 return 0;
440}
441static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
442{
443 /* GPIO can never have been requested */
444 WARN_ON(desc);
445 return 0;
446}
447static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
448 struct gpio_desc **desc_array,
449 struct gpio_array *array_info,
450 unsigned long *value_bitmap)
451{
452 /* GPIO can never have been requested */
453 WARN_ON(desc_array);
454 return 0;
455}
456static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
457 int value)
458{
459 /* GPIO can never have been requested */
460 WARN_ON(desc);
461}
462static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
463 struct gpio_desc **desc_array,
464 struct gpio_array *array_info,
465 unsigned long *value_bitmap)
466{
467 /* GPIO can never have been requested */
468 WARN_ON(desc_array);
469 return 0;
470}
471
472static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
473{
474 /* GPIO can never have been requested */
475 WARN_ON(desc);
476 return -ENOSYS;
477}
478
479static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
480{
481 /* GPIO can never have been requested */
482 WARN_ON(desc);
483 return -ENOSYS;
484}
485
486static inline int gpiod_is_active_low(const struct gpio_desc *desc)
487{
488 /* GPIO can never have been requested */
489 WARN_ON(desc);
490 return 0;
491}
492static inline int gpiod_cansleep(const struct gpio_desc *desc)
493{
494 /* GPIO can never have been requested */
495 WARN_ON(desc);
496 return 0;
497}
498
499static inline int gpiod_to_irq(const struct gpio_desc *desc)
500{
501 /* GPIO can never have been requested */
502 WARN_ON(desc);
503 return -EINVAL;
504}
505
506static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
507 const char *name)
508{
509 /* GPIO can never have been requested */
510 WARN_ON(desc);
511 return -EINVAL;
512}
513
514static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
515{
516 return NULL;
517}
518
519static inline int desc_to_gpio(const struct gpio_desc *desc)
520{
521 /* GPIO can never have been requested */
522 WARN_ON(desc);
523 return -EINVAL;
524}
525
526/* Child properties interface */
527struct fwnode_handle;
528
529static inline
530struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
531 const char *propname, int index,
532 enum gpiod_flags dflags,
533 const char *label)
534{
535 return ERR_PTR(-ENOSYS);
536}
537
538static inline
539struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
540 const char *con_id, int index,
541 enum gpiod_flags flags,
542 const char *label)
543{
544 return ERR_PTR(-ENOSYS);
545}
546
547static inline
548struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
549 struct fwnode_handle *fwnode,
550 const char *con_id, int index,
551 enum gpiod_flags flags,
552 const char *label)
553{
554 return ERR_PTR(-ENOSYS);
555}
556
557#endif /* CONFIG_GPIOLIB */
558
559static inline
560struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
561 struct fwnode_handle *fwnode,
562 const char *con_id,
563 enum gpiod_flags flags,
564 const char *label)
565{
566 return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
567 flags, label);
568}
569
570static inline
571struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
572 const char *con_id, int index,
573 struct fwnode_handle *child,
574 enum gpiod_flags flags,
575 const char *label)
576{
577 return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
578 flags, label);
579}
580
581static inline
582struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
583 const char *con_id,
584 struct fwnode_handle *child,
585 enum gpiod_flags flags,
586 const char *label)
587{
588 return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
589}
590
591#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
592struct device_node;
593
594struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
595 const char *propname, int index,
596 enum gpiod_flags dflags,
597 const char *label);
598
599#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
600
601struct device_node;
602
603static inline
604struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
605 const char *propname, int index,
606 enum gpiod_flags dflags,
607 const char *label)
608{
609 return ERR_PTR(-ENOSYS);
610}
611
612#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
613
614#ifdef CONFIG_GPIOLIB
615struct device_node;
616
617struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
618 struct device_node *node,
619 const char *propname, int index,
620 enum gpiod_flags dflags,
621 const char *label);
622
623#else /* CONFIG_GPIOLIB */
624
625struct device_node;
626
627static inline
628struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
629 struct device_node *node,
630 const char *propname, int index,
631 enum gpiod_flags dflags,
632 const char *label)
633{
634 return ERR_PTR(-ENOSYS);
635}
636
637#endif /* CONFIG_GPIOLIB */
638
639struct acpi_gpio_params {
640 unsigned int crs_entry_index;
641 unsigned int line_index;
642 bool active_low;
643};
644
645struct acpi_gpio_mapping {
646 const char *name;
647 const struct acpi_gpio_params *data;
648 unsigned int size;
649
650/* Ignore IoRestriction field */
651#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
652/*
653 * When ACPI GPIO mapping table is in use the index parameter inside it
654 * refers to the GPIO resource in _CRS method. That index has no
655 * distinction of actual type of the resource. When consumer wants to
656 * get GpioIo type explicitly, this quirk may be used.
657 */
658#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
659
660 unsigned int quirks;
661};
662
663#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
664
665struct acpi_device;
666
667int acpi_dev_add_driver_gpios(struct acpi_device *adev,
668 const struct acpi_gpio_mapping *gpios);
669void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
670
671int devm_acpi_dev_add_driver_gpios(struct device *dev,
672 const struct acpi_gpio_mapping *gpios);
673void devm_acpi_dev_remove_driver_gpios(struct device *dev);
674
675#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
676
677struct acpi_device;
678
679static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
680 const struct acpi_gpio_mapping *gpios)
681{
682 return -ENXIO;
683}
684static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
685
686static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
687 const struct acpi_gpio_mapping *gpios)
688{
689 return -ENXIO;
690}
691static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
692
693#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
694
695
696#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
697
698int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
699int gpiod_export_link(struct device *dev, const char *name,
700 struct gpio_desc *desc);
701void gpiod_unexport(struct gpio_desc *desc);
702
703#else /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
704
705static inline int gpiod_export(struct gpio_desc *desc,
706 bool direction_may_change)
707{
708 return -ENOSYS;
709}
710
711static inline int gpiod_export_link(struct device *dev, const char *name,
712 struct gpio_desc *desc)
713{
714 return -ENOSYS;
715}
716
717static inline void gpiod_unexport(struct gpio_desc *desc)
718{
719}
720
721#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
722
723#endif