1919#include <linux/gpio/driver.h>
2020#include <linux/iio/iio.h>
2121#include <linux/minmax.h>
22+ #include <linux/moduleparam.h>
2223#include "hid-ids.h"
2324
25+ static bool gpio_mode_enforce ;
26+
27+ module_param (gpio_mode_enforce , bool , 0644 );
28+ MODULE_PARM_DESC (gpio_mode_enforce ,
29+ "Enforce GPIO mode for GP0 thru GP3 (default: false, will be used for IIO)" );
30+
2431/* Commands codes in a raw output report */
2532enum {
2633 MCP2221_I2C_WR_DATA = 0x90 ,
@@ -536,10 +543,10 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
536543 if (ret )
537544 goto exit ;
538545
539- mcp -> rxbuf_idx = 0 ;
540- mcp -> rxbuf = data -> block ;
541- mcp -> txbuf [0 ] = MCP2221_I2C_GET_DATA ;
542- ret = mcp_send_data_req_status ( mcp , mcp -> txbuf , 1 );
546+ ret = mcp_i2c_smbus_read ( mcp , NULL ,
547+ MCP2221_I2C_RD_RPT_START ,
548+ addr , data -> block [0 ] + 1 ,
549+ data -> block );
543550 if (ret )
544551 goto exit ;
545552 } else {
@@ -555,14 +562,14 @@ static int mcp_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
555562 case I2C_SMBUS_I2C_BLOCK_DATA :
556563 if (read_write == I2C_SMBUS_READ ) {
557564 ret = mcp_smbus_write (mcp , addr , command , NULL ,
558- 0 , MCP2221_I2C_WR_NO_STOP , 1 );
565+ 0 , MCP2221_I2C_WR_NO_STOP , 0 );
559566 if (ret )
560567 goto exit ;
561568
562- mcp -> rxbuf_idx = 0 ;
563- mcp -> rxbuf = data -> block ;
564- mcp -> txbuf [0 ] = MCP2221_I2C_GET_DATA ;
565- ret = mcp_send_data_req_status ( mcp , mcp -> txbuf , 1 );
569+ ret = mcp_i2c_smbus_read ( mcp , NULL ,
570+ MCP2221_I2C_RD_RPT_START ,
571+ addr , data -> block [0 ],
572+ & data -> block [ 1 ] );
566573 if (ret )
567574 goto exit ;
568575 } else {
@@ -650,7 +657,7 @@ static int mcp2221_check_gpio_pinfunc(struct mcp2221 *mcp)
650657 int needgpiofix = 0 ;
651658 int ret ;
652659
653- if (IS_ENABLED (CONFIG_IIO ))
660+ if (IS_ENABLED (CONFIG_IIO ) && ! gpio_mode_enforce )
654661 return 0 ;
655662
656663 ret = mcp_gpio_read_sram (mcp );
@@ -1045,7 +1052,8 @@ static void mcp2221_remove(struct hid_device *hdev)
10451052#if IS_REACHABLE (CONFIG_IIO )
10461053 struct mcp2221 * mcp = hid_get_drvdata (hdev );
10471054
1048- cancel_delayed_work_sync (& mcp -> init_work );
1055+ if (!gpio_mode_enforce )
1056+ cancel_delayed_work_sync (& mcp -> init_work );
10491057#endif
10501058}
10511059
@@ -1319,8 +1327,10 @@ static int mcp2221_probe(struct hid_device *hdev,
13191327#endif
13201328
13211329#if IS_REACHABLE (CONFIG_IIO )
1322- INIT_DELAYED_WORK (& mcp -> init_work , mcp_init_work );
1323- schedule_delayed_work (& mcp -> init_work , msecs_to_jiffies (100 ));
1330+ if (!gpio_mode_enforce ) {
1331+ INIT_DELAYED_WORK (& mcp -> init_work , mcp_init_work );
1332+ schedule_delayed_work (& mcp -> init_work , msecs_to_jiffies (100 ));
1333+ }
13241334#endif
13251335
13261336 return 0 ;
0 commit comments