the shiny new i2c slave framework
play

The Shiny New I2C Slave Framework Wolfram Sang Consultant/Renesas - PowerPoint PPT Presentation

The Shiny New I2C Slave Framework Wolfram Sang Consultant/Renesas Kernel Team 6.10.2015, ELCE15 Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 1 / 26 A typical I2C bus 1 6.10.2015, ELCE15 The Shiny


  1. The Shiny New I2C Slave Framework Wolfram Sang Consultant/Renesas Kernel Team 6.10.2015, ELCE15 Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 1 / 26

  2. A typical I2C bus 1 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) 1 picture based on this one by Colin M.L. Burnett 2 / 26 V dd R p SDA SCL Linux ADC DAC μ C Master Slave Slave Slave

  3. The new era :) 2 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) 2 picture based on this one by Colin M.L. Burnett 3 / 26 V dd R p SDA SCL Linux ADC DAC Linux Ma./Sl. Slave Slave Ma./Sl.

  4. Finally… At this time, Linux only operates I2C (or SMBus) in master mode; you can’t use these APIs to make a Linux system behave as a slave/device, either to speak a custom protocol or to emulate some other device. Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 4 / 26

  5. Use cases data delivery (sensor like) confjguration (codec like) embedded controllers (e.g. nvec) avoid multi-master Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 5 / 26

  6. Data fmow Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 6 / 26 User Backend Driver Controller kernel driver, I2C slave sysfs, IO registers events char device,...

  7. Driver side We need support from the I2C bus driver activating slave support in the core is not enough usually extension to the I2C master driver no slave only solutions please watch your PM settings a slave always needs to listen Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 7 / 26

  8. Registering a slave priv->slave = slave; 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) } return 0; static int rcar_reg_slave( struct i2c_client *slave) rcar_i2c_write(priv, ICSAR, slave->addr); pm_runtime_forbid(rcar_i2c_priv_to_dev(priv)); return -EAFNOSUPPORT; if (slave->flags & I2C_CLIENT_TEN) return -EBUSY; if (priv->slave) struct rcar_i2c_priv *priv = i2c_get_adapdata(slave->adapter); { 8 / 26 rcar_i2c_write(priv, ICSSR, 0); rcar_i2c_write(priv, ICSIER, SAR | SSR); rcar_i2c_write(priv, ICSCR, SIE | SDBS);

  9. Slave events Handler function ret = i2c_slave_event(slave, event, &val) links driver and backend val carries the data. It is bidirectional. usually called from interrupt context ! Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 9 / 26

  10. Slave events (master writes) Wolfram Sang (wsa@the-dreams.de) 6.10.2015, ELCE15 The Shiny New I2C Slave Framework 10 / 26 I2C_SLAVE_WRITE_RECEIVED val = byte from master, ret = 0/-ERRNO ... S Addr+W A Data A/N P I2C_SLAVE_WRITE_REQUESTED I2C_SLAVE_STOP val = unused, ret = 0 val = unused, ret = 0

  11. Slave events (master reads) Wolfram Sang (wsa@the-dreams.de) 6.10.2015, ELCE15 The Shiny New I2C Slave Framework 11 / 26 I2C_SLAVE_READ_PROCESSED val = byte to master, ret = 0 ... S Addr+R A Data A/N P I2C_SLAVE_READ_REQUESTED I2C_SLAVE_STOP val = byte to master, ret = 0 val = unused, ret = 0

  12. Slave interrupt handler I static bool rcar_i2c_slave_irq( struct rcar_i2c_priv *priv) { u32 ssr_raw, ssr_filtered; u8 value; if (!ssr_filtered) return false; Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 12 / 26 ssr_raw = rcar_i2c_read(priv, ICSSR) & 0xff; ssr_filtered = ssr_raw & rcar_i2c_read(priv, ICSIER);

  13. Slave interrupt handler II /* address detected */ 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) } } rcar_i2c_write(priv, ICSIER, SDR | SSR | SAR); /* dummy read */ rcar_i2c_read(priv, ICRXTX); i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_REQUESTED, &value); rcar_i2c_write(priv, ICRXTX, value); i2c_slave_event(priv->slave, I2C_SLAVE_READ_REQUESTED, &value); if (ssr_raw & STM) { /* read or write request */ if (ssr_filtered & SAR) { 13 / 26 rcar_i2c_write(priv, ICSIER, SDE | SSR | SAR); } else { rcar_i2c_write(priv, ICSSR, ~SAR & 0xff);

  14. Slave interrupt handler III /* master sent stop */ if (ssr_filtered & SSR) { i2c_slave_event(priv->slave, I2C_SLAVE_STOP, &value); } Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 14 / 26 rcar_i2c_write(priv, ICSIER, SAR | SSR); rcar_i2c_write(priv, ICSSR, ~SSR & 0xff);

  15. Slave interrupt handler IV /* master wants to write to us */ if (ssr_filtered & SDR) { int ret; /* Send NACK in case of error */ rcar_i2c_write(priv, ICSCR, SIE | SDBS | (ret < 0 ? FNA : 0)); } Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 15 / 26 value = rcar_i2c_read(priv, ICRXTX); ret = i2c_slave_event(priv->slave, I2C_SLAVE_WRITE_RECEIVED, &value); rcar_i2c_write(priv, ICSSR, ~SDR & 0xff);

  16. Slave interrupt handler V /* master wants to read from us */ if (ssr_filtered & SDE) { i2c_slave_event(priv->slave, I2C_SLAVE_READ_PROCESSED, &value); rcar_i2c_write(priv, ICRXTX, value); } return true; } Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 16 / 26 rcar_i2c_write(priv, ICSSR, ~SDE & 0xff);

  17. Backends are standard i2c drivers are normally matched to i2c clients are HW independent provide a callback to handle slave events Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 17 / 26

  18. Backend driver I case I2C_SLAVE_STOP: 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) } return 0; } break ; default : case I2C_SLAVE_WRITE_RECEIVED: static int i2c_slave_8bit_seconds_slave_cb( struct i2c_client *client, case I2C_SLAVE_WRITE_REQUESTED: break ; *val = get_seconds() & 0xff; /* Always get the most recent value */ case I2C_SLAVE_READ_PROCESSED: case I2C_SLAVE_READ_REQUESTED: switch (event) { { enum i2c_slave_event event, u8 *val) 18 / 26

  19. Backend driver II static int i2c_slave_8bit_seconds_probe( struct i2c_client *client, const struct i2c_device_id *id) { return i2c_slave_register(client, i2c_slave_8bit_seconds_slave_cb); }; static int i2c_slave_8bit_seconds_remove( struct i2c_client *client) { i2c_slave_unregister(client); return 0; } Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 19 / 26

  20. The ”read pointer” problem * Do not increment buffer_idx here, because we don't know if 6.10.2015, ELCE15 The Shiny New I2C Slave Framework Wolfram Sang (wsa@the-dreams.de) ... break ; */ * for details. * this byte will be actually used. Read Linux I2C slave docs /* ... spin_unlock(&eeprom->buffer_lock); *val = eeprom->buffer[eeprom->buffer_idx]; spin_lock(&eeprom->buffer_lock); case I2C_SLAVE_READ_REQUESTED: /* fallthrough */ eeprom->buffer_idx++; /* The previous byte made it to the bus, get next one */ case I2C_SLAVE_READ_PROCESSED: 20 / 26

  21. Current status Drivers: RCar, (Tegra), ((Davinci)) Backend: EEPROM/memory simulator Devicetree: bindings clear \o/ Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 21 / 26

  22. Address spaces Avoid address collisions. Enable loopbacks. Devicetree I2C_TEN_BIT_ADDRESS address space: 0xa000 - 0xa3ff I2C_OWN_SLAVE_ADDRESS address space += 0x1000 Example: reg = <(I2C_OWN_SLAVE_ADDRESS | 0x42)>; Run time instantiation echo slave-24c02 0x1064 > /sys/bus/i2c/devices/i2c-1/new_device Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 22 / 26

  23. Next steps more driver support more backends (if there is a user) no new features (unless there is a use case) Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 23 / 26

  24. Thanks! <3 Renesas for funding this upstream solution Renesas Kernel Team especially Geert and Laurent for thorough review Uwe Kleine-König for in-depth discussions Andrey Danin for the Tegra slave implementation and nvec backend port Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 24 / 26

  25. Demo! At the showcase this evening Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 25 / 26

  26. The End Thank you for your attention! Questions? Comments? right now at the showcase this evening or anytime at this conference wsa@the-dreams.de Wolfram Sang (wsa@the-dreams.de) The Shiny New I2C Slave Framework 6.10.2015, ELCE15 26 / 26

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend