2121
2222#include <linux/delay.h>
2323#include <linux/device.h>
24+ #include <linux/gpio/consumer.h>
2425#include <linux/hid.h>
2526#include <linux/i2c.h>
2627#include <linux/kernel.h>
@@ -35,8 +36,10 @@ struct i2c_hid_of {
3536 struct i2chid_ops ops ;
3637
3738 struct i2c_client * client ;
39+ struct gpio_desc * reset_gpio ;
3840 struct regulator_bulk_data supplies [2 ];
3941 int post_power_delay_ms ;
42+ int post_reset_delay_ms ;
4043};
4144
4245static int i2c_hid_of_power_up (struct i2chid_ops * ops )
@@ -55,13 +58,18 @@ static int i2c_hid_of_power_up(struct i2chid_ops *ops)
5558 if (ihid_of -> post_power_delay_ms )
5659 msleep (ihid_of -> post_power_delay_ms );
5760
61+ gpiod_set_value_cansleep (ihid_of -> reset_gpio , 0 );
62+ if (ihid_of -> post_reset_delay_ms )
63+ msleep (ihid_of -> post_reset_delay_ms );
64+
5865 return 0 ;
5966}
6067
6168static void i2c_hid_of_power_down (struct i2chid_ops * ops )
6269{
6370 struct i2c_hid_of * ihid_of = container_of (ops , struct i2c_hid_of , ops );
6471
72+ gpiod_set_value_cansleep (ihid_of -> reset_gpio , 1 );
6573 regulator_bulk_disable (ARRAY_SIZE (ihid_of -> supplies ),
6674 ihid_of -> supplies );
6775}
@@ -75,33 +83,43 @@ static int i2c_hid_of_probe(struct i2c_client *client)
7583 int ret ;
7684 u32 val ;
7785
78- ihid_of = devm_kzalloc (& client -> dev , sizeof (* ihid_of ), GFP_KERNEL );
86+ ihid_of = devm_kzalloc (dev , sizeof (* ihid_of ), GFP_KERNEL );
7987 if (!ihid_of )
8088 return - ENOMEM ;
8189
8290 ihid_of -> ops .power_up = i2c_hid_of_power_up ;
8391 ihid_of -> ops .power_down = i2c_hid_of_power_down ;
8492
85- ret = of_property_read_u32 (dev -> of_node , "hid-descr-addr" , & val );
93+ ret = device_property_read_u32 (dev , "hid-descr-addr" , & val );
8694 if (ret ) {
87- dev_err (& client -> dev , "HID register address not provided\n" );
95+ dev_err (dev , "HID register address not provided\n" );
8896 return - ENODEV ;
8997 }
9098 if (val >> 16 ) {
91- dev_err (& client -> dev , "Bad HID register address: 0x%08x\n" ,
92- val );
99+ dev_err (dev , "Bad HID register address: 0x%08x\n" , val );
93100 return - EINVAL ;
94101 }
95102 hid_descriptor_address = val ;
96103
97- if (!device_property_read_u32 (& client -> dev , "post-power-on-delay-ms" ,
98- & val ))
104+ if (!device_property_read_u32 (dev , "post-power-on-delay-ms" , & val ))
99105 ihid_of -> post_power_delay_ms = val ;
100106
107+ /*
108+ * Note this is a kernel internal device-property set by x86 platform code,
109+ * this MUST not be used in devicetree files without first adding it to
110+ * the DT bindings.
111+ */
112+ if (!device_property_read_u32 (dev , "post-reset-deassert-delay-ms" , & val ))
113+ ihid_of -> post_reset_delay_ms = val ;
114+
115+ /* Start out with reset asserted */
116+ ihid_of -> reset_gpio = devm_gpiod_get_optional (dev , "reset" , GPIOD_OUT_HIGH );
117+ if (IS_ERR (ihid_of -> reset_gpio ))
118+ return PTR_ERR (ihid_of -> reset_gpio );
119+
101120 ihid_of -> supplies [0 ].supply = "vdd" ;
102121 ihid_of -> supplies [1 ].supply = "vddl" ;
103- ret = devm_regulator_bulk_get (& client -> dev ,
104- ARRAY_SIZE (ihid_of -> supplies ),
122+ ret = devm_regulator_bulk_get (dev , ARRAY_SIZE (ihid_of -> supplies ),
105123 ihid_of -> supplies );
106124 if (ret )
107125 return ret ;
@@ -116,11 +134,13 @@ static int i2c_hid_of_probe(struct i2c_client *client)
116134 hid_descriptor_address , quirks );
117135}
118136
137+ #ifdef CONFIG_OF
119138static const struct of_device_id i2c_hid_of_match [] = {
120139 { .compatible = "hid-over-i2c" },
121140 {},
122141};
123142MODULE_DEVICE_TABLE (of , i2c_hid_of_match );
143+ #endif
124144
125145static const struct i2c_device_id i2c_hid_of_id_table [] = {
126146 { "hid" , 0 },
0 commit comments