**** BEGIN LOGGING AT Fri Aug 05 02:59:58 2016 Aug 05 17:17:09 ^^ Aug 05 18:36:08 what Aug 05 21:03:28 hmmm Aug 05 22:46:32 m_w, There? Aug 05 22:53:30 chanakya_vc: hey, feeling better? Aug 05 22:55:39 Yeah a lot better. Problem is that the medicines that the docs have prescribed make me very sleepy. m_w Aug 05 22:56:11 making any progress on your project? Aug 05 22:56:22 Yup Aug 05 22:56:43 m_w, Wanted to know if you could guide me to a driver for i2c Aug 05 22:56:52 I mean if there is any example Aug 05 22:57:00 like omap-spi Aug 05 22:57:42 As far I have read on the net, a driver for i2c should be a bit easier than spi to understand. Aug 05 22:59:09 Like I have written the basic functions in the firmware, but I would need to know exactly what I need to do in the driver to complete it and then pick data as I did for SPI Aug 05 22:59:22 okay Aug 05 22:59:44 the i2c drivers are in drivers/i2c Aug 05 23:01:16 you are adding a new i2c bus so drivers/i2c/busses Aug 05 23:02:27 the simplest driver to use as an example would probably be i2c-gpio.c Aug 05 23:02:40 http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-gpio.c Aug 05 23:02:56 Okay m_w . I was reading this though:http://www.linuxjournal.com/article/7136 Aug 05 23:03:51 this is a nice walk through, it is a little dated though Aug 05 23:04:45 as with other subsystems there is documentation within the kernel Aug 05 23:05:13 http://lxr.free-electrons.com/source/Documentation/i2c/ Aug 05 23:06:21 Okay thanks a lot m_w . I think if I work hard enough, I will be able to finish this in the weekend itself. Looks much simpler to me than SPI Aug 05 23:08:01 m_w, http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-gpio.c#L281 Why this need to have a init function? I mean they could have registered in the probe function itself right? Aug 05 23:09:36 Or by calling the macro module_platform_driver() m_w Aug 05 23:09:43 Can be done this way right m_w ? Aug 05 23:09:49 sure Aug 05 23:10:45 the import pieces are defining the adapter and calling i2c_bit_add_numbered_bus Aug 05 23:11:53 the gpio driver is doing a bunch of things specific to bit banging the GPIO which you do not need to be concerned with Aug 05 23:16:37 Okay m_w I got that. Ah the probe function is mostly about setting up the GPIO pins and stuff I guess. Aug 05 23:17:17 So i2c_bit_add_numbered bus would basically be registering the bus with i2c core right? Aug 05 23:17:20 m_w, Aug 05 23:17:25 yes Aug 05 23:17:59 you will need to define a pass a static const struct i2c_algorithm Aug 05 23:18:30 this will point to callback functions the will communicate with the pru Aug 05 23:20:12 .master_xfer is the function that does the magic Aug 05 23:21:26 Okay i2c core basically calls upon this .master_xfer function.And I tell the i2c core that such a function exists via the struct i2c algorithm right m_w ? Aug 05 23:21:42 yes Aug 05 23:24:32 https://www.kernel.org/doc/htmldocs/device-drivers/API-struct-i2c-algorithm.html Aug 05 23:26:36 i2c-gpio.c is a bit style adapter which is more host processor intensive Aug 05 23:27:38 Okay m_w . I was looking for this structure there :P Aug 05 23:27:53 yeah it is not in there Aug 05 23:28:04 sorry Aug 05 23:28:19 Arre np m_w . I think I have got it Aug 05 23:29:20 http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-robotfuzz-osif.c Aug 05 23:29:28 this is a nice short one Aug 05 23:29:43 that uses master_xfer Aug 05 23:30:09 great have at and let me know if you need help along the way Aug 05 23:33:48 m_w, This osif driver has read and write functions. I would not need those right? Aug 05 23:35:12 those are hardware specific Aug 05 23:35:24 be right back rebooting Aug 06 00:29:42 m_w, In this: http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-robotfuzz-osif.c#L134 ,there is no struct i2c_adapter() Aug 06 00:29:52 i2c adapter Aug 06 00:33:02 lemme see Aug 06 00:34:11 it is in the private data struct Aug 06 00:34:17 http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-robotfuzz-osif.c#L35 Aug 06 00:36:35 Okay m_w got that. Ah then there is no call to i2c_bit_add_numbered_bus() here but there is a call to i2c_add_adapter() ? Aug 06 00:37:18 they are using i2c_add_adapter instead Aug 06 00:37:45 Okay so I can use any of the two Aug 06 00:39:08 if you use i2c_add_adapter it will dynamically assign a bus number Aug 06 00:39:10 http://lxr.free-electrons.com/source/drivers/i2c/i2c-core.c#L1651 Aug 06 00:40:38 Okay m_w , a couple of more questions, here we are not calling the platform_set_drv_data()? Aug 06 00:42:41 Like I want to do it the same way I did SPI, declare the pointers in pru_i2c struct and then set the pointers in the probe function. Aug 06 00:43:31 But then I would need to call these pointers in the master_xfer function m_w . Aug 06 00:45:06 this this specific driver they are pointing back the the private data with algo_data Aug 06 00:45:17 http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-robotfuzz-osif.c#L153 Aug 06 00:46:20 here is one of many other i2c drivers that use platform_set_drvdata: Aug 06 00:46:23 http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-mxs.c#L854 Aug 06 00:47:09 Okay so store the private data in .algo adapter and then call it again in xfer_function Aug 06 00:47:39 you could do it that way if you want Aug 06 00:48:30 i2c_get_adapdata(adap) Aug 06 00:51:27 after i2c_set_adapdata(adap, yourstruct) in probe Aug 06 00:53:36 platform_get_drvdata can only be used if pdev is passed to the function Aug 06 00:54:08 you can use it in your remove function Aug 06 01:05:24 Okay m_w . The .algo_adpater way looks easier to me. Aug 06 01:06:14 Last question, what are the buffers that the xfer_function provides me that I would have to write in memory? Like in spi I had rx_buf and tx_buf Aug 06 01:12:35 msg->buf Aug 06 01:13:43 struct i2c_msg right? m_w ? Aug 06 01:13:55 http://lxr.free-electrons.com/source/include/uapi/linux/i2c.h#L68 Aug 06 01:14:20 So for writing the address somewhere I basically write to memory msg->addr? Aug 06 01:15:07 i2c sends the address as part of the transaction Aug 06 01:15:38 it determine the device it is talking to Aug 06 01:16:13 Yes I know that. But My firmware would need to pick up the address separately from the data in the memory Aug 06 01:16:38 like when it starts a transaction, it will first bit bang the address Aug 06 01:16:56 yes it would have to be passed to the pru in another memory location Aug 06 01:17:20 so msg->addr is the buffer with the address I presume Aug 06 01:17:34 m_w, Aug 06 01:17:48 it is the slave address Aug 06 01:18:12 Also in 7 bit addressing I read that the last bit represents whether the master wants to read or write to the slave? Aug 06 01:18:28 But here it is defined in the flags I guess Aug 06 01:19:07 it is part of the i2c_msg struct Aug 06 01:19:36 the flags are stored in another u16 Aug 06 01:20:19 the defines are used to tell what bit corresponds to what flag Aug 06 01:20:53 Yeah so m_w , there I only check if flags==1? If yes the master wants to read data, if false then master wants to write data? Aug 06 01:21:14 yup Aug 06 01:21:46 Okay and this goes right after I have bitbanged the address right? Aug 06 01:22:53 yeah Aug 06 01:23:30 One more thing where do I write the data that I get from the slave? When master says it wants to read? Aug 06 01:23:44 Like I see no receiving buffer Aug 06 01:23:58 in struct i2c_msg Aug 06 01:24:23 it is half duplex so it uses the same buffer I believe Aug 06 01:24:56 Okay. Aug 06 01:26:02 Thanks for your help m_w . Will you be online during the weekend? Aug 06 01:26:13 yeah Aug 06 01:26:53 Okay m_w . I better get busy writing code now. Aug 06 01:27:11 good luck **** ENDING LOGGING AT Sat Aug 06 02:59:58 2016