I2c touch screen linux

Linux I2C Device Driver-I2C interface touch screen driver on mini2440

1) adapter hardware driver:
The kernel has implemented the mini2440, I2C Adapter Driver, you can see the relevant in the following directory i2c-s3c2410.cCode
Linux-2.6.32.2/Drivers/I2C/busses/i2c-s3c2410.c

2) algorithm with memory configured for I2C
Also implemented in inux-2.6.32.2/Drivers/I2C/busses/i2c-s3c2410.c files.

No changes are required for the above two parts.

/* Resolution definion according to touch screen */
# Define min_x_coordinate 0
# Define max_x_coordinate 1024
# Define min_y_coordinate 0
# Define max_y_coordinate 768

/* Touch Screen Data Structure */
Struct i2c_ts_priv Struct i2c_client * client;
Struct input_dev * input;
Struct delayed_work work;
Int IRQ;
>;

Static void i2c_ts_poscheck (struct work_struct * Work)
Struct i2c_ts_priv * priv = container_of (work, struct i2c_ts_priv, work. Work );
/* Buffer for storing data */
Char Buf [6];
Int number;
Int xpos, ypos;

Memset (BUF, 0, sizeof (BUF ));

/* Now do page read */
If (i2c_master_recv (priv-> client, Buf, 6 )! = 6 )Dev_err (& priv-> client-> Dev, «unable to read I2C Page \ n «);
Goto out;
>

/* Convert coordinate */
Number = Buf [0] & 0x07;
Xpos = (BUF [3] <8) | Buf [2]);
Ypos = (BUF [5] <8) | Buf [4]);

/* Report input event */
If (number! = 0) & (xpos! = 0) & (ypos! = 0 ))Input_report_key (priv-> input, btn_touch, 1 );
Input_report_abs (priv-> input, abs_x, xpos );
Input_report_abs (priv-> input, abs_y, ypos );
Input_sync (priv-> input );
> Else if (number = 0 )Input_report_key (priv-> input, btn_touch, 0 );
Input_sync (priv-> input );
>

Out:
Enable_irq (priv-> IRQ );
>

/* Read finger numbers and coordinate and report input event */
Static irqreturn_t i2c_ts_isr (int irq, void * dev_id)
Struct i2c_ts_priv * priv = dev_id;

/* Disable IRQ */
Disable_irq_nosync (IRQ );
Schedule_delayed_work (& priv-> Work, Hz/100 );
Return irq_handled;
>

Static int i2c_ts_open (struct input_dev * Dev)
Return 0;
>

Static void i2c_ts_close (struct input_dev * Dev)

Читайте также:  Remove apache from linux

Static int i2c_ts_probe (struct i2c_client * client,
Const struct i2c_device_id * IDP)
Struct i2c_ts_priv * priv;
Struct input_dev * input;
Int error;
Char Buf [2];

Priv = kzarloc (sizeof (* priv), gfp_kernel );
If (! Priv )Dev_err (& client-> Dev, «failed to allocate driver data \ n «);
Error =-enomem;
Goto err0;
>

Dev_set_drvdata (& client-> Dev, priv );

Input-> evbit [0] = bit_mask (ev_key) | bit_mask (ev_abs );
Input-> keybit [bit_word (btn_touch)] = bit_mask (btn_touch );

Input_set_abs_params (input, abs_x, min_x_coordinate, max_x_coordinate, 0, 0 );
Input_set_abs_params (input, abs_y, min_y_coordinate, max_y_coordinate, 0, 0 );

Input-> name = client-> name;
Input-> ID. bustype = bus_i2c;
Input-> Dev. Parent = & client-> dev;

Input-> open = i2c_ts_open;
Input-> close = i2c_ts_close;

Input_set_drvdata (input, priv );

Priv-> client = client;
Priv-> input = input;
Init_delayed_work (& priv-> Work, i2c_ts_poscheck );
Priv-> IRQ = client-> IRQ;

Error = input_register_device (input );
If (error)
Goto err1;

Error = request_irq (priv-> IRQ, i2c_ts_isr, ir1__trigger_falling,
Client-> name, priv );
If (error )Dev_err (& client-> Dev, «unable to request touchscreen IRQ. \ n «);
Goto err2;
>

Err2:
Input_unregister_device (input );
Input = NULL;/* so we dont try to free it below */
Err1:
Input_free_device (input );
Kfree (priv );
Err0:
Dev_set_drvdata (& client-> Dev, null );
Return Error;
>

Static int i2c_ts_remove (struct i2c_client * client)
Struct i2c_ts_priv * priv = dev_get_drvdata (& client-> Dev );

Free_irq (priv-> IRQ, priv );
Input_unregister_device (priv-> input );
Kfree (priv );

Dev_set_drvdata (& client-> Dev, null );

Static int i2c_ts_suspend (struct i2c_client * client, pm_message_t mesg)
Struct i2c_ts_priv * priv = dev_get_drvdata (& client-> Dev );
If (device_may_wakeup (& client-> Dev ))
Enable_irq_wake (priv-> IRQ );
Return 0;
>

Static int i2c_ts_resume (struct i2c_client * client)
Struct i2c_ts_priv * priv = dev_get_drvdata (& client-> Dev );
If (device_may_wakeup (& client-> Dev ))
Disable_irq_wake (priv-> IRQ );
Return 0;
>

Читайте также:  Started set console font and keymap astra linux

Static const struct i2c_device_id i2c_ts_id [] = ,
<>
>;
Module_device_table (I2C, i2c_ts_id );

Static struct i2c_driver i2c_ts_driver = . Driver = . Name = «i2c-ts «,
>,
. Probe = i2c_ts_probe,
. Remove = i2c_ts_remove,
. Suspend = i2c_ts_suspend,
. Resume = i2c_ts_resume,
. Id_table = i2c_ts_id,
>;

Static int _ init i2c_ts_init (void)
Return i2c_add_driver (& i2c_ts_driver );
>

Static void _ exit i2c_ts_exit (void)
I2c_del_driver (& i2c_ts_driver );
>

Module_description («I2C touchscreen driver «);
Module_author («Allen «);
Module_license («GPL «);

Module_init (i2c_ts_init );
Module_exit (i2c_ts_exit );

4 ). after completing this step, you also need to create and configure the I2C device where the setup file is located in
linux-2.6.32.2/ARCH/ARM/mach-s3c2440/mach-mini2440.c,
Add the following code:
. .
+/* I2C touch screen devices. */
+/* bus configuration */
+ static struct s3c2410_platform_i2c i2c_touchscreen_cfg _ initdata = +. flags = 0,
+. slave_addr = 0x5c,
+. frequency = 100*1000,
+. sda_delay = 2,
+>;

+/* I2C device name is «i2c_ts», address is 0x5c, interrupt is eint20 */
+ Static struct i2c_board_info touchscreen_i2c_devs [] _ initdata = + + I2c_board_info («i2c-ts», 0x5c ),
+. IRQ = irq_eint20,
+ >,
+ >;
. .

Static void _ init mini2440_machine_init (void)
. .
+/* I2C touch screen devices */
+ Maid (& i2c_touchscreen_cfg );
+ I2c_register_board_info (0, touchscreen_i2c_devs, + array_size (touchscreen_i2c_devs ));
. .
>

Here i2c_board_info («i2c-ts», 0x5c), «i2c-ts» should be consistent with i2c_ts_id In the I2C device driver.
In order to ensure that the I2C device driver is loaded successfully.

This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or complaint, to info-contact@alibabacloud.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.

Читайте также:  Linux mint добавление репозитории

Источник

Adding touch screen driver to Wandboard, i2c device registration

I compiled the driver into Linux kerenl as a built-in module, tried to run on the board but failed. The driver doesn’t appear in /dev/input . I debuged the kerenl code a bit, and found that the code doesn’t reach to driver’s probe function, instead it fails in device binding (i2c device registration). Just then I come to know about Device tree.

I looked into following dts files (which I believe my Wandboard is using), putting little i2c configuration present in the files here.

i2c1: i2c@021a0000 < #address-cells = ; #size-cells = ; compatible = "fsl,imx6q-i2c", "fsl,imx21-i2c"; reg = ; interrupts = ; clocks = ; status = "disabled"; >; i2c2: i2c@021a4000 < #address-cells = ; #size-cells = ; compatible = "fsl,imx6q-i2c", "fsl,imx21-i2c"; reg = ; interrupts = ; clocks = ; status = "disabled"; >; i2c3: i2c@021a8000 < #address-cells = ; #size-cells = ; compatible = "fsl,imx6q-i2c", "fsl,imx21-i2c"; reg = ; interrupts = ; clocks = ; status = "disabled"; >; 
&hdmi < ddc-i2c-bus = ; status = "okay"; >; &i2c1 < clock-frequency = ; pinctrl-names = "default"; pinctrl-0 = ; status = "okay"; >; &i2c2 < clock-frequency = ; pinctrl-names = "default"; pinctrl-0 = ; status = "okay"; codec: sgtl5000@0a < compatible = "fsl,sgtl5000"; reg = ; clocks = ; VDDA-supply = ; VDDIO-supply = ; >; >; 

I see dts note entry for sgtl5000 which is audio codec which then appears as /dev/input/event0 . But I don’t find any entry for ‘prism’ driver, which actually runs perfectly on the board. Neither dts files nor board-files have entry for ‘prism’ driver. But I am sure it’s using ‘device-tree’ approach.

  1. As my Wandboard works fine with ‘prism’ driver and touch device, why I don’t see device node entry for ‘prism’ in dts files ?
  2. Is there any other way for ‘i2c device registration’ other than ‘device-tree’ and ‘earlier board-file’ approach ?
  3. How could I get past with ilitek touch driver not getting i2c-matched/registered problem ?

Источник

Оцените статью
Adblock
detector