The document's goal is to help describe some the basics of setting up the Linux kernel for the AR1020 controller for the SPI or I2C interface of an embedded target.   For detailed instructions on the driver installation and configuration, please see the online AR1020 driver documentation at:

http://www.microchip.com/en_us/technology/mtouch/

Preliminary Steps
-----------------

Please gather/determine the following information before setting up your kernel:

* The interrupt number of the embedded board's GPIO pin that the AR1020 SPI interface is being connected to.  This can often be the trickiest pieces of information to acquire.

* The bus number of the SPI or I2C bus the AR1020 will be connected to.

* The platform specific file path within the kernel tree responsible for setting the SPI or I2C bus.  For example, on the Samsung 6410 board platform, this file is located at "arch/arm/mach-s3c6410/mach-smdk6410.c".

Connecting the SPI controller to an embedded device
---------------------------------------------------

Connect the AR1020 IRQ line to an available GPIO line
Connect the AR1020 +5V line to VDD power
Connect the AR1020 GND line to the board ground
Connect the AR1020 SDI line to the SPI bus's output line
Connect the AR1020 SCK line to the SPI bus's clock line
Connect the AR1020 SDO line to the SPI bus's input line

These connections are for SPI communications only and please see the AR1000 datasheet for other pin connections.

Connecting the I2C controller to an embedded device
---------------------------------------------------

Connect the AR1020 IRQ line to an available GPIO line
Connect the AR1020 +5V line to VDD power
Connect the AR1020 GND line to the board ground
Connect the AR1020 SDA line to the I2C bus's data line
Connect the AR1020 SCL line to the I2C bus's clock line

These connections are for I2C communications only and please see the AR1000 datasheet for other pin connections.

Setting up the Linux kernel source
----------------------------------

The "ar1020-spi.c" and "ar1020-i2c" files should be copied to the "drivers/input/touchscreen" directory.

Modify the "Kconfig" in the "drivers/input/touchscreen" such that it contains the following at the bottom of the file before the "endif" line.

config TOUCHSCREEN_AR1020_SPI
	tristate "Microchip AR1020 SPI touchscreen"
	depends on SPI_MASTER
	help
	  Say Y here if you have a Microchip AR1020 SPI Controller and
	  want to enable support for the built-in touchscreen.

	  To compile this driver as a module, choose M here: the
	  module will be called ar1020-spi.

config TOUCHSCREEN_AR1020_I2C
	tristate "Microchip AR1020 I2C touchscreen"
	depends on I2C
	help
	  Say Y here if you have a Microchip AR1020 I2C Controller and
	  want to enable support for the built-in touchscreen.

	  To compile this driver as a module, choose M here: the
	  module will be called ar1020-i2c.

The "Makefile" in the "drivers/input/touchscreen" should contain the following at the bottom of the file.

obj-$(CONFIG_TOUCHSCREEN_AR1020_SPI)	+= ar1020-spi.o
obj-$(CONFIG_TOUCHSCREEN_AR1020_I2C)	+= ar1020-i2c.o

Next, to include Microchip touch support within the kernel, run "make menuconfig" for a text kernel configuration interface or "make xconfig" for a graphical configuration interface.

Browse to "Device Drivers->Input device support->Touchscreens" in the kernel tree interface and choose either "Microchip AR1020 SPI touchscreen" for the SPI interace or "Microchip AR1020 I2C touchscreen" for the I2C interface as a built-in option.

Setting up board's platform specific settings
---------------------------------------------

The platform specific files will now need to be modified so we may associate the AR1020 driver with the approriate bus and GPIO interrupt.  

For the SPI interface: 

Begin by searching for the keywords "struct spi_board_info" and go to the appropriate area to the current SPI bus that is to be used.

In the relevent section, change the value of the ".modalias" variable to "ar1020-spi". This change will cause the "ar1020_spi_probe" function within the AR1020 kernel driver on system startup.  The ".mode" variable's value will need to be changed to SPI_MODE_1.  Finally, the ".irq" variable's value will need to be changed to the IRQ of the GPIO line.

For the I2C interface:

Begin by searching for the keywords "struct i2c_board_info" and go to the appropriate area to the current I2C bus that is to be used.

For one of this structure's elements, please add the following line:

{ I2C_BOARD_INFO("ar1020_i2c", 0x4d),.irq=116,},

This line will cause the "ar1020_i2c_probe" function within the AR1020 kernel driver on system startup.   The ".irq" variable's value will need to be changed to the IRQ of the GPIO line.

Testing kernel changes
----------------------

We can now compile the kernel (usually using a cross-compiler).  To verify touches are being correctly being seen by the kernel, compile "inputverify.c" using a command similar to or the same as "arm-linux-gcc -o inputverify inputverify.c".  Run the compiled file on the target machine with the device's evdev as a parameter.  For example "./inputverify -p EVDEV -d /dev/input/event1".

Calibrating under Android
-------------------------

To perform a software calibration under the android operating system after the driver has been setup, please compile the source code from the "Calibration" sub-directory and then run on target device.






