Add device tree support of i2c Atmel driver
Subsystems (4)
v3 cover Add device tree support of i2c Atmel driver
Change since v2:
* Register i2c clocks with CLKDEV_DEV_ID instead of CLKDEV_CON_DEV_ID.
* Fix some coding style issue.
* Add Bo Shen patch, which fix the interrupt mode.
* Rename the name of ids table. (from i2c-at91sam9xxx to at91sam9xxx-i2c)
Change since v1:
* Squash the commit [1] which adds the sam9x5 config.
This patcheset adds the device tree support for i2c Atmel driver and the corresping clocks for the at91sam9g45 device.
Raphaël Poggi (2) :
(1) i2c: at91: add support of device tree
(2) at91sam9g45: clock: add i2c clocks
Bo Shen (1):
(1) I2C: at91: fix the method for interrupt
arch/arm/mach-at91/at91sam9g45.c | 4 ++ drivers/i2c/busses/i2c-at91.c | 126 ++++++++++++++++++++++++++++---------- 2 files changed, 98 insertions(+), 32 deletions(-)
[1]: http://lists.infradead.org/pipermail/barebox/2014-August/020493.html
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 1/3 i2c: at91: add support of device tree
--- drivers/i2c/busses/i2c-at91.c | 92 ++++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 19 deletions(-)
drivers/i2c/busses/i2c-at91.c +73 -19
@@ -186,8 +186,8 @@ static int at91_twi_wait_completion(struct at91_twi_dev *dev) dev->transfer_status |= status; -while (!(at91_twi_read (dev,AT91_TWI_SR ) &AT91_TWI_TXCOMP )) { -if (is_timeout (start,AT91_I2C_TIMEOUT )) { +while (!(at91_twi_read (dev,AT91_TWI_SR ) &AT91_TWI_TXCOMP )) { +if (is_timeout (start,AT91_I2C_TIMEOUT )) {dev_warn (&dev->adapter.dev,"timeout waiting for bus ready\n" );return -ETIMEDOUT ; }
@@ -346,41 +346,94 @@ static struct at91_twi_pdata at91sam9g10_config = { .has_unre_flag = false, }; +static struct at91_twi_pdata at91sam9x5_config = { + .clk_max_div =7 , + .clk_offset =4 , + .has_unre_flag = false, +}; +static struct platform_device_id at91_twi_devtypes[] = { { - .name ="i2c-at91rm9200" , + .name ="at91rm9200-i2c" , .driver_data = (unsigned long ) &at91rm9200_config, }, { - .name ="i2c-at91sam9261" , + .name ="at91sam9261-i2c" , .driver_data = (unsigned long ) &at91sam9261_config, }, { - .name ="i2c-at91sam9260" , + .name ="at91sam9260-i2c" , .driver_data = (unsigned long ) &at91sam9260_config, }, { - .name ="i2c-at91sam9g20" , + .name ="at91sam9g20-i2c" , .driver_data = (unsigned long ) &at91sam9g20_config, }, { - .name ="i2c-at91sam9g10" , + .name ="at91sam9g10-i2c" , .driver_data = (unsigned long ) &at91sam9g10_config, }, { + .name ="at91sam9x5-i2c" , + .driver_data = (unsigned long ) &at91sam9x5_config, + }, { +/* sentinel */ + } +}; + +static struct of_device_id at91_twi_dt_ids[] = { + { + .compatible ="atmel,at91rm9200-i2c" , + .data = (unsigned long ) &at91rm9200_config, + } , { + .compatible ="atmel,at91sam9260-i2c" , + .data = (unsigned long ) &at91sam9260_config, + } , { + .compatible ="atmel,at91sam9261-i2c" , + .data = (unsigned long ) &at91sam9261_config, + } , { + .compatible ="atmel,at91sam9g20-i2c" , + .data = (unsigned long ) &at91sam9g20_config, + } , { + .compatible ="atmel,at91sam9g10-i2c" , + .data = (unsigned long ) &at91sam9g10_config, + }, { + .compatible ="atmel,at91sam9x5-i2c" , + .data = (unsigned long ) &at91sam9x5_config, + }, {/* sentinel */ } }; +static struct at91_twi_pdata *at91_twi_get_driver_data (struct device_d *dev) +{ +struct at91_twi_pdata *i2c_data =NULL ; +int rc; + +if (dev->device_node) { +const struct of_device_id *match; + match =of_match_node (at91_twi_dt_ids, dev->device_node); +if (!match) + i2c_data =NULL ; +else + i2c_data = (struct at91_twi_pdata *)match->data; + }else { + rc =dev_get_drvdata (dev, (unsigned long *)&i2c_data); +if (rc) + i2c_data =NULL ; + } + +return i2c_data; +} +static int at91_twi_probe (struct device_d *dev) {struct at91_twi_dev *i2c_at91; -struct at91_twi_pdata *i2c_data; -int rc; +int rc =0 ;u32 bus_clk_rate; i2c_at91 =xzalloc (sizeof (struct at91_twi_dev )); - rc =dev_get_drvdata (dev, (unsigned long *)&i2c_data); -if (rc) - goto out_free; - - i2c_at91->pdata = i2c_data; + i2c_at91->pdata =at91_twi_get_driver_data (dev); +if (!i2c_at91->pdata) { +dev_err (dev,"failed to retrieve driver data\n" ); + rc = -ENODEV ; + } i2c_at91->base =dev_request_mem_region (dev,0 );if (!i2c_at91->base) {
@@ -389,7 +442,7 @@ static int at91_twi_probe(struct device_d *dev) goto out_free; } - i2c_at91->clk =clk_get (dev,"twi_clk" ); + i2c_at91->clk =clk_get (dev,NULL );if (IS_ERR (i2c_at91->clk)) {dev_err (dev,"no clock defined\n" ); rc = -ENODEV ;
@@ -418,17 +471,18 @@ static int at91_twi_probe(struct device_d *dev)return 0 ; out_adap_fail: -clk_disable (i2c_at91->clk); -clk_put (i2c_at91->clk); +clk_disable (i2c_at91->clk); +clk_put (i2c_at91->clk); out_free: -kfree (i2c_at91); -return rc; +kfree (i2c_at91); +return rc; }static struct driver_d at91_twi_driver = { .name ="at91-twi" , .probe = at91_twi_probe, .id_table = at91_twi_devtypes, + .of_compatible =DRV_OF_COMPAT (at91_twi_dt_ids), };device_platform_driver (at91_twi_driver);
Signature · 7 lines
1.7.9.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 2/3 at91sam9g45: clock: add i2c clocks
In reply to Raphaël PoggiAdd the device tree and non device tree at91 i2c clocks.
--- arch/arm/mach-at91/at91sam9g45.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm/mach-at91/at91sam9g45.c +4 -0
@@ -192,6 +192,10 @@ static struct clk_lookup periph_clocks_lookups[] = {CLKDEV_CON_DEV_ID ("mci_clk" ,"atmel_mci1" , &mmc1_clk),CLKDEV_CON_DEV_ID ("spi_clk" ,"atmel_spi0" , &spi0_clk),CLKDEV_CON_DEV_ID ("spi_clk" ,"atmel_spi1" , &spi1_clk), +CLKDEV_DEV_ID ("at91sam9g10-i2c0" , &twi0_clk), +CLKDEV_DEV_ID ("at91sam9g10-i2c1" , &twi1_clk), +CLKDEV_DEV_ID ("fff84000.i2c" , &twi0_clk), +CLKDEV_DEV_ID ("fff88000.i2c" , &twi1_clk),CLKDEV_DEV_ID ("at91rm9200-gpio0" , &pioA_clk),CLKDEV_DEV_ID ("at91rm9200-gpio1" , &pioB_clk), CLKDEV_DEV_ID("at91rm9200-gpio2", &pioC_clk),
Signature · 7 lines
1.7.9.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH v3 2/3] at91sam9g45: clock: add i2c clocks
Quoted 12 lines · Raphaël Poggi
Add the device tree and non device tree at91 i2c clocks.
Signed-off-by Raphaël Poggi <[email protected]>--- arch/arm/mach-at91/at91sam9g45.c | 4 ++++ 1 file changed, 4 insertions(+)arch/arm/mach-at91/at91sam9g45.c +0
-0
arch/arm/mach-at91/at91sam9g45.c static struct clk_lookup periph_clocks_lookups[] = { · line 198
Quoted 7 lines
arch/arm/mach-at91/at91sam9g45.c +4
-0@@ -192,6 +192,10 @@ static struct clk_lookup periph_clocks_lookups[] = {CLKDEV_CON_DEV_ID ("mci_clk" ,"atmel_mci1" , &mmc1_clk),CLKDEV_CON_DEV_ID ("spi_clk" ,"atmel_spi0" , &spi0_clk),CLKDEV_CON_DEV_ID ("spi_clk" ,"atmel_spi1" , &spi1_clk), +CLKDEV_DEV_ID ("at91sam9g10-i2c0" , &twi0_clk), +CLKDEV_DEV_ID ("at91sam9g10-i2c1" , &twi1_clk), +CLKDEV_DEV_ID ("fff84000.i2c" , &twi0_clk), + CLKDEV_DEV_ID("fff88000.i2c", &twi1_clk),
Can you use clkdev_add_physbase()? This way you wouldn't have to register separate clocks for the device tree and non device tree case.
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH v3 3/3 I2C: at91: fix the method for interrupt
In reply to Raphaël PoggiFrom: Bo Shen <[email protected]>
As the i2c-at91 driver won't work in the interrupt mode, so need to poll the interrupts.
--- drivers/i2c/busses/i2c-at91.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/i2c/busses/i2c-at91.c +23 -15
@@ -174,24 +174,32 @@ static void at91_twi_read_next_byte(struct at91_twi_dev *dev)static int at91_twi_wait_completion (struct at91_twi_dev *dev) {uint64_t start =get_time_ns (); -unsigned int status =at91_twi_read (dev,AT91_TWI_SR ); -unsigned int irqstatus =at91_twi_read (dev,AT91_TWI_IMR ); +unsigned int status; +unsigned int irqstatus; + +do { + status =at91_twi_read (dev,AT91_TWI_SR ); + irqstatus =at91_twi_read (dev,AT91_TWI_IMR ); + +if (!(status & irqstatus)) { +if (is_timeout (start,AT91_I2C_TIMEOUT )) { +dev_warn (&dev->adapter.dev,"timeout waiting for bus ready\n" ); +return -ETIMEDOUT ; + }else { +continue ; + } + } -if (irqstatus &AT91_TWI_RXRDY ) -at91_twi_read_next_byte (dev); -else if (irqstatus &AT91_TWI_TXRDY ) -at91_twi_write_next_byte (dev); -else -dev_warn (&dev->adapter.dev,"neither rx and tx are ready\n" ); +if (irqstatus &AT91_TWI_RXRDY ) +at91_twi_read_next_byte (dev); +else if (irqstatus &AT91_TWI_TXRDY ) +at91_twi_write_next_byte (dev); +else +dev_warn (&dev->adapter.dev,"neither rx and tx are ready\n" ); - dev->transfer_status |= status; + dev->transfer_status |= status; -while (!(at91_twi_read (dev,AT91_TWI_SR ) &AT91_TWI_TXCOMP )) { -if (is_timeout (start,AT91_I2C_TIMEOUT )) { -dev_warn (&dev->adapter.dev,"timeout waiting for bus ready\n" ); -return -ETIMEDOUT ; - } - } + }while (!(at91_twi_read (dev,AT91_TWI_SR ) &AT91_TWI_TXCOMP ));at91_disable_twi_interrupts (dev);
Signature · 7 lines
1.7.9.5 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox