13.1基于IIC 控制器的触摸屏驱动分析
[root@localhost linux-3.5]# vim arch/arm/mach-exynos/mach-tiny4412.c
1844 &s3c_device_i2c2, //追
/linuxtags/arch/arm/plat-samsung/devs.c
648 #ifdef CONFIG_S3C_DEV_I2C2
649 static struct resource s3c_i2c2_resource[] = {
650 [0] = DEFINE_RES_MEM(S3C_PA_IIC2, SZ_4K),
651 [1] = DEFINE_RES_IRQ(IRQ_IIC2),
652 };
653
********struct platform_device s3c_device_i2c2********
654 struct platform_device s3c_device_i2c2 = {
655 .name = "s3c2410-i2c", //匹配名字?!!!
656 .id = 2,
657 .num_resources = ARRAY_SIZE(s3c_i2c2_resource),
658 .resource = s3c_i2c2_resource,
659 };
660
661 void __init s3c_i2c2_set_platdata(struct s3c2410_platform_i2c *pd)
662 {
663 struct s3c2410_platform_i2c *npd;
664
665 if (!pd) {
666 pd = &default_i2c_data;
667 pd->bus_num = 2;
668 }
669
670 npd = s3c_set_platdata(pd, sizeof(struct s3c2410_platform_i2c),
671 &s3c_device_i2c2);
672
673 if (!npd->cfg_gpio)
674 npd->cfg_gpio = s3c_i2c2_cfg_gpio;
675 }
676 #endif /* CONFIG_S3C_DEV_I2C2 */
[root@localhost linux-3.5]# vim drivers/i2c/busses/i2c-s3c2410.c
1272 /* device driver for platform bus bits */
1273
********struct platform_driver s3c24xx_i2c_driver********
1274 static struct platform_driver s3c24xx_i2c_driver = {
1275 .probe = s3c24xx_i2c_probe, //追 重点看probe!
1276 .remove = s3c24xx_i2c_remove,
1277 .id_table = s3c24xx_driver_ids,//追
1278 .driver = {
1279 .owner = THIS_MODULE,
1280 .name = "s3c-i2c",//名字不匹配,需要看第二种匹配方法了!
1281 .pm = S3C24XX_DEV_PM_OPS,
1282 .of_match_table = of_match_ptr(s3c24xx_i2c_match),
1283 },
1284 };
130 static struct platform_device_id s3c24xx_driver_ids[] = {
131 {
132 .name = "s3c2410-i2c",//通过第二种方法找到了!
133 .driver_data = 0,
134 }, {
135 .name = "s3c2440-i2c",
136 .driver_data = QUIRK_S3C2440,
137 }, {
138 .name = "s3c2440-hdmiphy-i2c",
139 .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO,
140 }, { },
141 };
142 MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
1020 /* s3c24xx_i2c_probe
1021 *
1022 * called by the bus driver when a suitable device is found
1023 */
1024
1025 static int s3c24xx_i2c_probe(struct platform_device *pdev)//重点!!!
1026 {
1027 struct s3c24xx_i2c *i2c; //定义IIC控制器 /追
1028 struct s3c2410_platform_i2c *pdata = NULL;
1029 struct resource *res;
1030 int ret;
1031
1032 if (!pdev->dev.of_node) {
1033 pdata = pdev->dev.platform_data;
1034 if (!pdata) {
1035 dev_err(&pdev->dev, "no platform data\n");
1036 return -EINVAL;
1037 }
1038 }
1039
1040 i2c = devm_kzalloc(&pdev->dev, sizeof(struct s3c24xx_i2c), GFP_KERNEL);
1041 if (!i2c) {
1042 dev_err(&pdev->dev, "no memory for state\n");
1043 return -ENOMEM;
1044 }
1045
1046 i2c->pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1047 if (!i2c->pdata) {
1048 dev_err(&pdev->dev, "no memory for platform data\n");
1049 return -ENOMEM;
1050 }
1058 strlcpy(i2c->adap.name, "s3c2410-i2c", sizeof(i2c->adap.name));
1059 i2c->adap.owner = THIS_MODULE;
1060 i2c->adap.algo = &s3c24xx_i2c_algorithm;//内核实现好的算法
1061 i2c->adap.retries = 2;//
1062 i2c->adap.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
1063 i2c->tx_setup = 50;
1064
1065 init_waitqueue_head(&i2c->wait);
1124 /* initialise the i2c controller */
1125
1126 ret = s3c24xx_i2c_init(i2c);//IIC控制器初始化 //追
////////////注意:1 << 5收发数据时 IIC控制器(一共8个IIC控制器)本身收发到数据的中断,与外部中断两码事
//////////// 57 #define S3C2410_IICCON_IRQEN (1 << 5)
1127 if (ret != 0) {
1128 dev_err(&pdev->dev, "I2C controller init failed\n");
1129 goto err_iomap;
1162 i2c->adap.nr = i2c->pdata->bus_num;//IIC控制器2
1163 i2c->adap.dev.of_node = pdev->dev.of_node;
1164
1165 ret = i2c_add_numbered_adapter(&i2c->adap);
////////////////////////重点!!!由platform_driver里面的probe调用,实现struct i2c_client
1166 if (ret < 0) {
1167 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
1168 goto err_cpufreq;
1169 }
101 struct s3c24xx_i2c {
102 wait_queue_head_t wait;//实现阻塞等待
103 unsigned int quirks;
104 unsigned int suspended:1;
105
106 struct i2c_msg *msg;//关于IIC收发的消息存放的地址 //追
107 unsigned int msg_num;//指向元素个数
108 unsigned int msg_idx;
109 unsigned int msg_ptr;
110
111 unsigned int tx_setup;
112 unsigned int irq;//中断号
113
114 enum s3c24xx_i2c_state state;
115 unsigned long clkrate;
116
117 void __iomem *regs;//
118 struct clk *clk;
119 struct device *dev;
120 struct resource *ioarea;
121 struct i2c_adapter adap;//适配: //追
122
123 struct s3c2410_platform_i2c *pdata;
124 int gpios[2];
125 #ifdef CONFIG_CPU_FREQ
126 struct notifier_block freq_transition;
127 #endif
128 };
539 struct i2c_msg {
540 __u16 addr; /* slave address */
541 __u16 flags;//读写标志
542 #define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
543 #define I2C_M_RD 0x0001 /* read data, from slave to master */
544 #define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_NOSTART */
545 #define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
546 #define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
547 #define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
548 #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte
*/
549 __u16 len; /* msg length *///读/写数据字节长度
550 __u8 *buf; /* pointer to msg data */ //从此空间地址收发消息
551 };
370 /*
371 * i2c_adapter is the structure used to identify a physical i2c bus along
372 * with the access algorithms necessary to access it.
373 */
374 struct i2c_adapter { //IIC算法
375 struct module *owner;
376 unsigned int class; /* classes to allow probing for */
377 const struct i2c_algorithm *algo; /* the algorithm to access the bus //追
*/
378 void *algo_data;
379
380 /* data fields that are valid for all devices */
381 struct rt_mutex bus_lock;
382
383 int timeout; /* in jiffies */
384 int retries;
385 struct device dev; /* the adapter device */
386
387 int nr;
388 char name[48];
389 struct completion dev_released;
390
391 struct mutex userspace_clients_lock;
392 struct list_head userspace_clients;
393 };
353 struct i2c_algorithm { //IIC的读写算法
354 /* If an adapter algorithm can't do I2C-level access, set master_xfer
355 to NULL. If an adapter algorithm can do SMBus access, set
356 smbus_xfer. If set to NULL, the SMBus protocol is simulated
357 using common I2C messages */
358 /* master_xfer should return the number of messages successfully
359 processed, or a negative value on error */
360 int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
361 int num);//主收/主发
362 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
363 unsigned short flags, char read_write,
364 u8 command, int size, union i2c_smbus_data *data);
365
366 /* To determine what the adapter supports */
367 u32 (*functionality) (struct i2c_adapter *);
368 };
注意框架
961 int i2c_add_numbered_adapter(struct i2c_adapter *adap)
962 {
963 int id;
964 int status;
965
966 if (adap->nr == -1) /* -1 means dynamically assign bus id */
967 return i2c_add_adapter(adap);
968 if (adap->nr & ~MAX_IDR_MASK)
969 return -EINVAL;
970
971 retry:
972 if (idr_pre_get(&i2c_adapter_idr, GFP_KERNEL) == 0)
973 return -ENOMEM;
974
975 mutex_lock(&core_lock);
976 /* "above" here means "above or equal to", sigh;
977 * we need the "equal to" result to force the result
978 */
979 status = idr_get_new_above(&i2c_adapter_idr, adap, adap->nr, &id);
980 if (status == 0 && id != adap->nr) {
981 status = -EBUSY;
982 idr_remove(&i2c_adapter_idr, id);
983 }
984 mutex_unlock(&core_lock);
985 if (status == -EAGAIN)
986 goto retry;
987
988 if (status == 0)
989 status = i2c_register_adapter(adap);//追
990 return status;
991 }
835 static int i2c_register_adapter(struct i2c_adapter *adap)
882 /* create pre-declared device nodes */
883 if (adap->nr < __i2c_first_dynamic_bus_num)
884 i2c_scan_static_board_info(adap); //追
795
796 static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
797 {
798 struct i2c_devinfo *devinfo;
799
800 down_read(&__i2c_board_lock);
801 list_for_each_entry(devinfo, &__i2c_board_list, list) {//
802 if (devinfo->busnum == adapter->nr
803 && !i2c_new_device(adapter,//追
804 &devinfo->board_info))
805 dev_err(&adapter->dev,
806 "Can't create device at 0x%02x\n",
807 devinfo->board_info.addr);
808 }
809 up_read(&__i2c_board_lock);
810 }
503 i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
504 {
505 struct i2c_client *client;//追13
506 int status;
220 struct i2c_client { //呵呵哒
221 unsigned short flags; /* div., see below */
222 unsigned short addr; /* chip address - NOTE: 7bit */
223 /* addresses are stored in the */
224 /* _LOWER_ 7 bits */
225 char name[I2C_NAME_SIZE];
226 struct i2c_adapter *adapter; /* the adapter we sit on */
227 struct i2c_driver *driver; /* and our access routines */
228 struct device dev; /* the device structure */
229 int irq; /* irq issued by device */
230 struct list_head detected;
231 };
538 client->dev.parent = &client->adapter->dev;
539 client->dev.bus = &i2c_bus_type; //追
540 client->dev.type = &i2c_client_type;
541 client->dev.of_node = info->of_node;
316 struct bus_type i2c_bus_type = {
317 .name = "i2c",
318 .match = i2c_device_match,
319 .probe = i2c_device_probe,
320 .remove = i2c_device_remove,
321 .shutdown = i2c_device_shutdown,
322 .pm = &i2c_device_pm_ops,
323 };
324 EXPORT_SYMBOL_GPL(i2c_bus_type);
274 struct i2c_board_info {
275 char type[I2C_NAME_SIZE];
276 unsigned short flags;
277 unsigned short addr;//从机地址
278 void *platform_data;
279 struct dev_archdata *archdata;
280 struct device_node *of_node;
281 int irq;
282 };
962// #ifdef CONFIG_TOUCHSCREEN_FT5X0X
963 #include <plat/ft5x0x_touch.h>
964 static struct ft5x0x_i2c_platform_data ft5x0x_pdata = {
965 .gpio_irq = EXYNOS4_GPX1(6),
966 .irq_cfg = S3C_GPIO_SFN(0xf),
967 .screen_max_x = 800,//支持的最大分辨率
968 .screen_max_y = 1280,
969 .pressure_max = 255,//最大压力值
970 };
971 //#endif
[root@localhost linux-3.5]# vim Documentation/i2c/
busses/ functionality instantiating-devices
smbus-protocol upgrading-clients
dev-interface i2c-protocol muxes/ summary
writing-clients
fault-codes i2c-stub old-module-parameters
ten-bit-addresses
[root@localhost linux-3.5]# vim include/linux/i2c.h
161 struct i2c_driver {
162 unsigned int class;
163
164 /* Notifies the driver that a new bus has appeared or is about to be
165 * removed. You should avoid using this, it will be removed in a
166 * near future.
167 */
168 int (*attach_adapter)(struct i2c_adapter *) __deprecated;
169 int (*detach_adapter)(struct i2c_adapter *) __deprecated;
170
171 /* Standard driver model interfaces */
172 int (*probe)(struct i2c_client *, const struct i2c_device_id *);//
173 int (*remove)(struct i2c_client *); //
174
175 /* driver model interfaces that don't relate to enumeration */
176 void (*shutdown)(struct i2c_client *);
177 int (*suspend)(struct i2c_client *, pm_message_t mesg);
178 int (*resume)(struct i2c_client *);
179
180 /* Alert callback, for example for the SMBus alert protocol.
181 * The format and meaning of the data value depends on the protocol.
182 * For the SMBus alert protocol, there is a single bit of data passed
183 * as the alert response's low bit ("event flag").
184 */
185 void (*alert)(struct i2c_client *, unsigned int data);
186
187 /* a ioctl like command that can be used to perform specific functions
188 * with the device.
189 */
190 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
191
192 struct device_driver driver;
193 const struct i2c_device_id *id_table;//
220 struct i2c_client {
221 unsigned short flags; /* div., see below */
222 unsigned short addr; /* chip address - NOTE: 7bit */
223 /* addresses are stored in the */
224 /* _LOWER_ 7 bits */
225 char name[I2C_NAME_SIZE];
226 struct i2c_adapter *adapter; /* the adapter we sit on */
227 struct i2c_driver *driver; /* and our access routines */
228 struct device dev; /* the device structure */
229 int irq; /* irq issued by device */
230 struct list_head detected;
231 };
浙公网安备 33010602011771号