Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'next-i2c' of git://aeryn.fluff.org.uk/bjdooks/linux

* 'next-i2c' of git://aeryn.fluff.org.uk/bjdooks/linux:
i2c-ocores: Can add I2C devices to the bus
i2c-s3c2410: move to using platform idtable to match devices
i2c: OMAP3: Better noise suppression for fast/standard modes
i2c: OMAP2/3: Fix scll/sclh calculations
i2c: Blackfin TWI: implement I2C_FUNC_SMBUS_I2C_BLOCK functionality
i2c: Blackfin TWI: fix transfer errors with repeat start
i2c: Blackfin TWI: fix REPEAT START mode doesn't repeat
i2c: Blackfin TWI: make sure we don't end up with a CLKDIV=0

+118 -54
+17
Documentation/i2c/busses/i2c-ocores
··· 20 20 dev.platform_data of the device should also point to a struct 21 21 ocores_i2c_platform_data (see linux/i2c-ocores.h) describing the 22 22 distance between registers and the input clock speed. 23 + There is also a possibility to attach a list of i2c_board_info which 24 + the i2c-ocores driver will add to the bus upon creation. 23 25 24 26 E.G. something like: 25 27 ··· 38 36 }, 39 37 }; 40 38 39 + /* optional board info */ 40 + struct i2c_board_info ocores_i2c_board_info[] = { 41 + { 42 + I2C_BOARD_INFO("tsc2003", 0x48), 43 + .platform_data = &tsc2003_platform_data, 44 + .irq = TSC_IRQ 45 + }, 46 + { 47 + I2C_BOARD_INFO("adv7180", 0x42 >> 1), 48 + .irq = ADV_IRQ 49 + } 50 + }; 51 + 41 52 static struct ocores_i2c_platform_data myi2c_data = { 42 53 .regstep = 2, /* two bytes between registers */ 43 54 .clock_khz = 50000, /* input clock of 50MHz */ 55 + .devices = ocores_i2c_board_info, /* optional table of devices */ 56 + .num_devices = ARRAY_SIZE(ocores_i2c_board_info), /* table size */ 44 57 }; 45 58 46 59 static struct platform_device myi2c = {
+1 -1
drivers/i2c/busses/Kconfig
··· 298 298 config I2C_BLACKFIN_TWI_CLK_KHZ 299 299 int "Blackfin TWI I2C clock (kHz)" 300 300 depends on I2C_BLACKFIN_TWI 301 - range 10 400 301 + range 21 400 302 302 default 50 303 303 help 304 304 The unit of the TWI clock is kHz.
+41 -18
drivers/i2c/busses/i2c-bfin-twi.c
··· 104 104 write_MASTER_CTL(iface, 105 105 read_MASTER_CTL(iface) | STOP); 106 106 else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 107 - iface->cur_msg+1 < iface->msg_num) 108 - write_MASTER_CTL(iface, 109 - read_MASTER_CTL(iface) | RSTART); 107 + iface->cur_msg + 1 < iface->msg_num) { 108 + if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) 109 + write_MASTER_CTL(iface, 110 + read_MASTER_CTL(iface) | RSTART | MDIR); 111 + else 112 + write_MASTER_CTL(iface, 113 + (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 114 + } 110 115 SSYNC(); 111 116 /* Clear status */ 112 117 write_INT_STAT(iface, XMTSERV); ··· 139 134 read_MASTER_CTL(iface) | STOP); 140 135 SSYNC(); 141 136 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 142 - iface->cur_msg+1 < iface->msg_num) { 143 - write_MASTER_CTL(iface, 144 - read_MASTER_CTL(iface) | RSTART); 137 + iface->cur_msg + 1 < iface->msg_num) { 138 + if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) 139 + write_MASTER_CTL(iface, 140 + read_MASTER_CTL(iface) | RSTART | MDIR); 141 + else 142 + write_MASTER_CTL(iface, 143 + (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 145 144 SSYNC(); 146 145 } 147 146 /* Clear interrupt source */ ··· 205 196 /* remove restart bit and enable master receive */ 206 197 write_MASTER_CTL(iface, 207 198 read_MASTER_CTL(iface) & ~RSTART); 208 - write_MASTER_CTL(iface, 209 - read_MASTER_CTL(iface) | MEN | MDIR); 210 199 SSYNC(); 211 200 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 212 201 iface->cur_msg+1 < iface->msg_num) { ··· 229 222 } 230 223 231 224 if (iface->pmsg[iface->cur_msg].len <= 255) 232 - write_MASTER_CTL(iface, 233 - iface->pmsg[iface->cur_msg].len << 6); 225 + write_MASTER_CTL(iface, 226 + (read_MASTER_CTL(iface) & 227 + (~(0xff << 6))) | 228 + (iface->pmsg[iface->cur_msg].len << 6)); 234 229 else { 235 - write_MASTER_CTL(iface, 0xff << 6); 230 + write_MASTER_CTL(iface, 231 + (read_MASTER_CTL(iface) | 232 + (0xff << 6))); 236 233 iface->manual_stop = 1; 237 234 } 238 235 /* remove restart bit and enable master receive */ 239 236 write_MASTER_CTL(iface, 240 237 read_MASTER_CTL(iface) & ~RSTART); 241 - write_MASTER_CTL(iface, read_MASTER_CTL(iface) | 242 - MEN | ((iface->read_write == I2C_SMBUS_READ) ? 243 - MDIR : 0)); 244 238 SSYNC(); 245 239 } else { 246 240 iface->result = 1; ··· 449 441 } 450 442 iface->transPtr = data->block; 451 443 break; 444 + case I2C_SMBUS_I2C_BLOCK_DATA: 445 + if (read_write == I2C_SMBUS_READ) { 446 + iface->readNum = data->block[0]; 447 + iface->cur_mode = TWI_I2C_MODE_COMBINED; 448 + } else { 449 + iface->writeNum = data->block[0]; 450 + iface->cur_mode = TWI_I2C_MODE_STANDARDSUB; 451 + } 452 + iface->transPtr = (u8 *)&data->block[1]; 453 + break; 452 454 default: 453 455 return -1; 454 456 } ··· 582 564 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 583 565 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 584 566 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL | 585 - I2C_FUNC_I2C; 567 + I2C_FUNC_I2C | I2C_FUNC_SMBUS_I2C_BLOCK; 586 568 } 587 569 588 570 static struct i2c_algorithm bfin_twi_algorithm = { ··· 632 614 struct i2c_adapter *p_adap; 633 615 struct resource *res; 634 616 int rc; 617 + unsigned int clkhilow; 635 618 636 619 iface = kzalloc(sizeof(struct bfin_twi_iface), GFP_KERNEL); 637 620 if (!iface) { ··· 694 675 /* Set TWI internal clock as 10MHz */ 695 676 write_CONTROL(iface, ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F); 696 677 678 + /* 679 + * We will not end up with a CLKDIV=0 because no one will specify 680 + * 20kHz SCL or less in Kconfig now. (5 * 1024 / 20 = 0x100) 681 + */ 682 + clkhilow = 5 * 1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ; 683 + 697 684 /* Set Twi interface clock as specified */ 698 - write_CLKDIV(iface, ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) 699 - << 8) | ((5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ) 700 - & 0xFF)); 685 + write_CLKDIV(iface, (clkhilow << 8) | clkhilow); 701 686 702 687 /* Enable TWI */ 703 688 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA);
+5
drivers/i2c/busses/i2c-ocores.c
··· 216 216 struct ocores_i2c_platform_data *pdata; 217 217 struct resource *res, *res2; 218 218 int ret; 219 + int i; 219 220 220 221 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 221 222 if (!res) ··· 271 270 dev_err(&pdev->dev, "Failed to add adapter\n"); 272 271 goto add_adapter_failed; 273 272 } 273 + 274 + /* add in known devices to the bus */ 275 + for (i = 0; i < pdata->num_devices; i++) 276 + i2c_new_device(&i2c->adap, pdata->devices + i); 274 277 275 278 return 0; 276 279
+30 -9
drivers/i2c/busses/i2c-omap.c
··· 333 333 334 334 if (cpu_is_omap2430() || cpu_is_omap34xx()) { 335 335 336 - /* HSI2C controller internal clk rate should be 19.2 Mhz */ 337 - internal_clk = 19200; 336 + /* 337 + * HSI2C controller internal clk rate should be 19.2 Mhz for 338 + * HS and for all modes on 2430. On 34xx we can use lower rate 339 + * to get longer filter period for better noise suppression. 340 + * The filter is iclk (fclk for HS) period. 341 + */ 342 + if (dev->speed > 400 || cpu_is_omap_2430()) 343 + internal_clk = 19200; 344 + else if (dev->speed > 100) 345 + internal_clk = 9600; 346 + else 347 + internal_clk = 4000; 338 348 fclk_rate = clk_get_rate(dev->fclk) / 1000; 339 349 340 350 /* Compute prescaler divisor */ ··· 353 343 354 344 /* If configured for High Speed */ 355 345 if (dev->speed > 400) { 346 + unsigned long scl; 347 + 356 348 /* For first phase of HS mode */ 357 - fsscll = internal_clk / (400 * 2) - 6; 358 - fssclh = internal_clk / (400 * 2) - 6; 349 + scl = internal_clk / 400; 350 + fsscll = scl - (scl / 3) - 7; 351 + fssclh = (scl / 3) - 5; 359 352 360 353 /* For second phase of HS mode */ 361 - hsscll = fclk_rate / (dev->speed * 2) - 6; 362 - hssclh = fclk_rate / (dev->speed * 2) - 6; 354 + scl = fclk_rate / dev->speed; 355 + hsscll = scl - (scl / 3) - 7; 356 + hssclh = (scl / 3) - 5; 357 + } else if (dev->speed > 100) { 358 + unsigned long scl; 359 + 360 + /* Fast mode */ 361 + scl = internal_clk / dev->speed; 362 + fsscll = scl - (scl / 3) - 7; 363 + fssclh = (scl / 3) - 5; 363 364 } else { 364 - /* To handle F/S modes */ 365 - fsscll = internal_clk / (dev->speed * 2) - 6; 366 - fssclh = internal_clk / (dev->speed * 2) - 6; 365 + /* Standard mode */ 366 + fsscll = internal_clk / (dev->speed * 2) - 7; 367 + fssclh = internal_clk / (dev->speed * 2) - 5; 367 368 } 368 369 scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll; 369 370 sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh;
+22 -26
drivers/i2c/busses/i2c-s3c2410.c
··· 51 51 STATE_STOP 52 52 }; 53 53 54 + enum s3c24xx_i2c_type { 55 + TYPE_S3C2410, 56 + TYPE_S3C2440, 57 + }; 58 + 54 59 struct s3c24xx_i2c { 55 60 spinlock_t lock; 56 61 wait_queue_head_t wait; ··· 93 88 static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) 94 89 { 95 90 struct platform_device *pdev = to_platform_device(i2c->dev); 91 + enum s3c24xx_i2c_type type; 96 92 97 - return !strcmp(pdev->name, "s3c2440-i2c"); 93 + type = platform_get_device_id(pdev)->driver_data; 94 + return type == TYPE_S3C2440; 98 95 } 99 96 100 97 /* s3c24xx_i2c_master_complete ··· 976 969 977 970 /* device driver for platform bus bits */ 978 971 979 - static struct platform_driver s3c2410_i2c_driver = { 980 - .probe = s3c24xx_i2c_probe, 981 - .remove = s3c24xx_i2c_remove, 982 - .suspend_late = s3c24xx_i2c_suspend_late, 983 - .resume = s3c24xx_i2c_resume, 984 - .driver = { 985 - .owner = THIS_MODULE, 986 - .name = "s3c2410-i2c", 987 - }, 972 + static struct platform_device_id s3c24xx_driver_ids[] = { 973 + { 974 + .name = "s3c2410-i2c", 975 + .driver_data = TYPE_S3C2410, 976 + }, { 977 + .name = "s3c2440-i2c", 978 + .driver_data = TYPE_S3C2440, 979 + }, { }, 988 980 }; 981 + MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); 989 982 990 - static struct platform_driver s3c2440_i2c_driver = { 983 + static struct platform_driver s3c24xx_i2c_driver = { 991 984 .probe = s3c24xx_i2c_probe, 992 985 .remove = s3c24xx_i2c_remove, 993 986 .suspend_late = s3c24xx_i2c_suspend_late, 994 987 .resume = s3c24xx_i2c_resume, 988 + .id_table = s3c24xx_driver_ids, 995 989 .driver = { 996 990 .owner = THIS_MODULE, 997 - .name = "s3c2440-i2c", 991 + .name = "s3c-i2c", 998 992 }, 999 993 }; 1000 994 1001 995 static int __init i2c_adap_s3c_init(void) 1002 996 { 1003 - int ret; 1004 - 1005 - ret = platform_driver_register(&s3c2410_i2c_driver); 1006 - if (ret == 0) { 1007 - ret = platform_driver_register(&s3c2440_i2c_driver); 1008 - if (ret) 1009 - platform_driver_unregister(&s3c2410_i2c_driver); 1010 - } 1011 - 1012 - return ret; 997 + return platform_driver_register(&s3c24xx_i2c_driver); 1013 998 } 1014 999 subsys_initcall(i2c_adap_s3c_init); 1015 1000 1016 1001 static void __exit i2c_adap_s3c_exit(void) 1017 1002 { 1018 - platform_driver_unregister(&s3c2410_i2c_driver); 1019 - platform_driver_unregister(&s3c2440_i2c_driver); 1003 + platform_driver_unregister(&s3c24xx_i2c_driver); 1020 1004 } 1021 1005 module_exit(i2c_adap_s3c_exit); 1022 1006 1023 1007 MODULE_DESCRIPTION("S3C24XX I2C Bus driver"); 1024 1008 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 1025 1009 MODULE_LICENSE("GPL"); 1026 - MODULE_ALIAS("platform:s3c2410-i2c"); 1027 - MODULE_ALIAS("platform:s3c2440-i2c");
+2
include/linux/i2c-ocores.h
··· 14 14 struct ocores_i2c_platform_data { 15 15 u32 regstep; /* distance between registers */ 16 16 u32 clock_khz; /* input clock in kHz */ 17 + u8 num_devices; /* number of devices in the devices list */ 18 + struct i2c_board_info const *devices; /* devices connected to the bus */ 17 19 }; 18 20 19 21 #endif /* _LINUX_I2C_OCORES_H */