@@ -350,9 +350,9 @@ static ssize_t gpio_direction_store(struct device *dev,
350350 if (!test_bit (FLAG_EXPORT , & desc -> flags ))
351351 status = - EIO ;
352352 else if (sysfs_streq (buf , "high" ))
353- status = gpiod_direction_output (desc , 1 );
353+ status = gpiod_direction_output_raw (desc , 1 );
354354 else if (sysfs_streq (buf , "out" ) || sysfs_streq (buf , "low" ))
355- status = gpiod_direction_output (desc , 0 );
355+ status = gpiod_direction_output_raw (desc , 0 );
356356 else if (sysfs_streq (buf , "in" ))
357357 status = gpiod_direction_input (desc );
358358 else
@@ -1590,7 +1590,7 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
15901590 if (flags & GPIOF_DIR_IN )
15911591 err = gpiod_direction_input (desc );
15921592 else
1593- err = gpiod_direction_output (desc ,
1593+ err = gpiod_direction_output_raw (desc ,
15941594 (flags & GPIOF_INIT_HIGH ) ? 1 : 0 );
15951595
15961596 if (err )
@@ -1756,28 +1756,13 @@ int gpiod_direction_input(struct gpio_desc *desc)
17561756}
17571757EXPORT_SYMBOL_GPL (gpiod_direction_input );
17581758
1759- /**
1760- * gpiod_direction_output - set the GPIO direction to input
1761- * @desc: GPIO to set to output
1762- * @value: initial output value of the GPIO
1763- *
1764- * Set the direction of the passed GPIO to output, such as gpiod_set_value() can
1765- * be called safely on it. The initial value of the output must be specified.
1766- *
1767- * Return 0 in case of success, else an error code.
1768- */
1769- int gpiod_direction_output (struct gpio_desc * desc , int value )
1759+ static int _gpiod_direction_output_raw (struct gpio_desc * desc , int value )
17701760{
17711761 unsigned long flags ;
17721762 struct gpio_chip * chip ;
17731763 int status = - EINVAL ;
17741764 int offset ;
17751765
1776- if (!desc || !desc -> chip ) {
1777- pr_warn ("%s: invalid GPIO\n" , __func__ );
1778- return - EINVAL ;
1779- }
1780-
17811766 /* GPIOs used for IRQs shall not be set as output */
17821767 if (test_bit (FLAG_USED_AS_IRQ , & desc -> flags )) {
17831768 gpiod_err (desc ,
@@ -1840,6 +1825,50 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
18401825 gpiod_dbg (desc , "%s: gpio status %d\n" , __func__ , status );
18411826 return status ;
18421827}
1828+
1829+ /**
1830+ * gpiod_direction_output_raw - set the GPIO direction to output
1831+ * @desc: GPIO to set to output
1832+ * @value: initial output value of the GPIO
1833+ *
1834+ * Set the direction of the passed GPIO to output, such as gpiod_set_value() can
1835+ * be called safely on it. The initial value of the output must be specified
1836+ * as raw value on the physical line without regard for the ACTIVE_LOW status.
1837+ *
1838+ * Return 0 in case of success, else an error code.
1839+ */
1840+ int gpiod_direction_output_raw (struct gpio_desc * desc , int value )
1841+ {
1842+ if (!desc || !desc -> chip ) {
1843+ pr_warn ("%s: invalid GPIO\n" , __func__ );
1844+ return - EINVAL ;
1845+ }
1846+ return _gpiod_direction_output_raw (desc , value );
1847+ }
1848+ EXPORT_SYMBOL_GPL (gpiod_direction_output_raw );
1849+
1850+ /**
1851+ * gpiod_direction_output - set the GPIO direction to input
1852+ * @desc: GPIO to set to output
1853+ * @value: initial output value of the GPIO
1854+ *
1855+ * Set the direction of the passed GPIO to output, such as gpiod_set_value() can
1856+ * be called safely on it. The initial value of the output must be specified
1857+ * as the logical value of the GPIO, i.e. taking its ACTIVE_LOW status into
1858+ * account.
1859+ *
1860+ * Return 0 in case of success, else an error code.
1861+ */
1862+ int gpiod_direction_output (struct gpio_desc * desc , int value )
1863+ {
1864+ if (!desc || !desc -> chip ) {
1865+ pr_warn ("%s: invalid GPIO\n" , __func__ );
1866+ return - EINVAL ;
1867+ }
1868+ if (test_bit (FLAG_ACTIVE_LOW , & desc -> flags ))
1869+ value = !value ;
1870+ return _gpiod_direction_output_raw (desc , value );
1871+ }
18431872EXPORT_SYMBOL_GPL (gpiod_direction_output );
18441873
18451874/**
0 commit comments