13
13
#include <linux/clk.h>
14
14
#include <linux/delay.h>
15
15
#include <linux/firmware.h>
16
- #include <linux/gpio.h>
16
+ #include <linux/gpio/consumer .h>
17
17
#include <linux/i2c.h>
18
18
#include <linux/media.h>
19
19
#include <linux/module.h>
20
- #include <linux/of_gpio.h>
21
20
#include <linux/of_graph.h>
22
21
#include <linux/regulator/consumer.h>
23
22
#include <linux/slab.h>
@@ -228,11 +227,6 @@ static const char * const s5k5baf_supply_names[] = {
228
227
};
229
228
#define S5K5BAF_NUM_SUPPLIES ARRAY_SIZE(s5k5baf_supply_names)
230
229
231
- struct s5k5baf_gpio {
232
- int gpio ;
233
- int level ;
234
- };
235
-
236
230
enum s5k5baf_gpio_id {
237
231
STBY ,
238
232
RSET ,
@@ -284,7 +278,7 @@ struct s5k5baf_fw {
284
278
};
285
279
286
280
struct s5k5baf {
287
- struct s5k5baf_gpio gpios [NUM_GPIOS ];
281
+ struct gpio_desc * gpios [NUM_GPIOS ];
288
282
enum v4l2_mbus_type bus_type ;
289
283
u8 nlanes ;
290
284
struct regulator_bulk_data supplies [S5K5BAF_NUM_SUPPLIES ];
@@ -936,16 +930,12 @@ static void s5k5baf_hw_set_test_pattern(struct s5k5baf *state, int id)
936
930
937
931
static void s5k5baf_gpio_assert (struct s5k5baf * state , int id )
938
932
{
939
- struct s5k5baf_gpio * gpio = & state -> gpios [id ];
940
-
941
- gpio_set_value (gpio -> gpio , gpio -> level );
933
+ gpiod_set_value_cansleep (state -> gpios [id ], 1 );
942
934
}
943
935
944
936
static void s5k5baf_gpio_deassert (struct s5k5baf * state , int id )
945
937
{
946
- struct s5k5baf_gpio * gpio = & state -> gpios [id ];
947
-
948
- gpio_set_value (gpio -> gpio , !gpio -> level );
938
+ gpiod_set_value_cansleep (state -> gpios [id ], 0 );
949
939
}
950
940
951
941
static int s5k5baf_power_on (struct s5k5baf * state )
@@ -1799,44 +1789,30 @@ static const struct v4l2_subdev_ops s5k5baf_subdev_ops = {
1799
1789
1800
1790
static int s5k5baf_configure_gpios (struct s5k5baf * state )
1801
1791
{
1802
- static const char * const name [] = { "S5K5BAF_STBY" , "S5K5BAF_RST" };
1792
+ static const char * const name [] = { "stbyn" , "rstn" };
1793
+ static const char * const label [] = { "S5K5BAF_STBY" , "S5K5BAF_RST" };
1803
1794
struct i2c_client * c = v4l2_get_subdevdata (& state -> sd );
1804
- struct s5k5baf_gpio * g = state -> gpios ;
1795
+ struct gpio_desc * gpio ;
1805
1796
int ret , i ;
1806
1797
1807
1798
for (i = 0 ; i < NUM_GPIOS ; ++ i ) {
1808
- int flags = GPIOF_DIR_OUT ;
1809
- if (g [i ].level )
1810
- flags |= GPIOF_INIT_HIGH ;
1811
- ret = devm_gpio_request_one (& c -> dev , g [i ].gpio , flags , name [i ]);
1812
- if (ret < 0 ) {
1813
- v4l2_err (c , "failed to request gpio %s\n" , name [i ]);
1799
+ gpio = devm_gpiod_get (& c -> dev , name [i ], GPIOD_OUT_HIGH );
1800
+ ret = PTR_ERR_OR_ZERO (gpio );
1801
+ if (ret ) {
1802
+ v4l2_err (c , "failed to request gpio %s: %d\n" ,
1803
+ name [i ], ret );
1814
1804
return ret ;
1815
1805
}
1816
- }
1817
- return 0 ;
1818
- }
1819
-
1820
- static int s5k5baf_parse_gpios (struct s5k5baf_gpio * gpios , struct device * dev )
1821
- {
1822
- static const char * const names [] = {
1823
- "stbyn-gpios" ,
1824
- "rstn-gpios" ,
1825
- };
1826
- struct device_node * node = dev -> of_node ;
1827
- enum of_gpio_flags flags ;
1828
- int ret , i ;
1829
1806
1830
- for ( i = 0 ; i < NUM_GPIOS ; ++ i ) {
1831
- ret = of_get_named_gpio_flags ( node , names [ i ], 0 , & flags );
1832
- if ( ret < 0 ) {
1833
- dev_err ( dev , "no %s GPIO pin provided\n" , names [i ]);
1807
+ ret = gpiod_set_consumer_name ( gpio , label [ i ]);
1808
+ if ( ret ) {
1809
+ v4l2_err ( c , "failed to set up name for gpio %s: %d\n" ,
1810
+ name [i ], ret );
1834
1811
return ret ;
1835
1812
}
1836
- gpios [i ].gpio = ret ;
1837
- gpios [i ].level = !(flags & OF_GPIO_ACTIVE_LOW );
1838
- }
1839
1813
1814
+ state -> gpios [i ] = gpio ;
1815
+ }
1840
1816
return 0 ;
1841
1817
}
1842
1818
@@ -1860,10 +1836,6 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
1860
1836
state -> mclk_frequency );
1861
1837
}
1862
1838
1863
- ret = s5k5baf_parse_gpios (state -> gpios , dev );
1864
- if (ret < 0 )
1865
- return ret ;
1866
-
1867
1839
node_ep = of_graph_get_next_endpoint (node , NULL );
1868
1840
if (!node_ep ) {
1869
1841
dev_err (dev , "no endpoint defined at node %pOF\n" , node );
0 commit comments