title: when to use platform_driver over I2C?
body: <p>I am looking a code xxx device is an IC using I2C to communicate. Somehow it is written using platform device. To communicate with the IC it is using "microp_i2c_write()"(pls refer to the following function write_xxx_register()). I think this code is hard to maintain in different platform. this is a navigation product.</p>
  
  <p>Question:
  1. I believe my question is how can I include the struct i2c_client *client? into this scenario? So this way it is easier to port to different linux/ andriod kernel?
  2. Why &amp; when platform_driver preferred? any particular reason?</p>
  
  <pre><code>static struct platform_driver xxx_device_driver = {
  .probe    = xxx_probe,
  .remove   = __devexit_p(xxx_remove),
  .driver   = {
      .name   = XXX_NAME,
      .owner  = THIS_MODULE,
  }
  };
  
  static void write_xxx_register(uint8_t reg, uint8_t val)
  {
  uint8_t data[BURST_DATA_SIZE];
  
  data[0] = reg;
  data[1] = val;
  microp_i2c_write(OJ_REGISTER_WRITE, data, 2);
   }
  
  static int __devinit XXX_probe(struct platform_device *pdev)
  {
  struct XXX_platform_data *oj = pdev-&gt;dev.platform_data;
  int err;
  int i;
  
  err = -ENOMEM;
  my_oj = oj;
  
  INIT_WORK(&amp;oj-&gt;work, XXX_work_func);
  
  XXX__wq = create_singlethread_workqueue("XXX__wq");
  if (!XXX__wq) {
      err = -ENOMEM;
      goto fail;
  }
  
  oj-&gt;input_dev = input_allocate_device();
  if (!oj-&gt;input_dev) {
      printk(KERN_ERR "Unable to allocate device for OJ\n");
      err = -ENOMEM;
      goto fail;
  }
  
  oj-&gt;input_dev-&gt;name = "XXX_-oj";
  oj-&gt;input_dev-&gt;evbit[0] = BIT_MASK(EV_KEY) |  BIT_MASK(EV_ABS)| BIT_MASK(EV_SYN )|BIT_MASK(EV_REL) ;
  input_set_capability(oj-&gt;input_dev, EV_KEY, BTN_MOUSE);
  input_set_capability(oj-&gt;input_dev, EV_KEY, BTN_TOUCH);
  oj-&gt;input_dev-&gt;relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
  oj-&gt;input_dev-&gt;absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y);
  input_set_abs_params(oj-&gt;input_dev, ABS_X, 8, 4024-8 , 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_Y, 41, 6604-41, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_PRESSURE, 0, 255, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_TOOL_WIDTH, 0, 15, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_HAT0X, 8, 4024-8, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_HAT0Y, 41, 6604-41, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_MT_POSITION_X, 8, 4024-8, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_MT_POSITION_Y, 41, 6604-41, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
  input_set_abs_params(oj-&gt;input_dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
  
  set_bit(EV_SYN, oj-&gt;input_dev-&gt;evbit);
  set_bit(EV_KEY, oj-&gt;input_dev-&gt;evbit);
  set_bit(BTN_TOUCH, oj-&gt;input_dev-&gt;keybit);
  set_bit(EV_ABS, oj-&gt;input_dev-&gt;evbit);
  
  for(i = 0; i &lt; ARRAY_SIZE(keymap); i++)
      set_bit(keymap[i], oj-&gt;input_dev-&gt;keybit);
  
  err = input_register_device(oj-&gt;input_dev);
  if (err) {
      printk(KERN_ERR "Unable to register %s input device\n", oj-&gt;input_dev-&gt;name);
      goto fail;
  }
  
  err = request_irq(my_oj-&gt;irq, XXX_irq_handler,
            IRQF_TRIGGER_NONE, XXX_NAME, oj);
  if (err &lt; 0) {
      err = -ENOMEM;
      printk(KERN_ERR "request_irq failed\n");
      goto fail;
  }
  
  
  normal_th = my_oj-&gt;normal_th;
  xy_ratio = my_oj-&gt;xy_ratio;
  interval = my_oj-&gt;interval;
  polling_delay = my_oj-&gt;mdelay_time;
  debugflag = my_oj-&gt;debugflag;
  ap_code = my_oj-&gt;ap_code;
  
  printk(KERN_INFO "driver loaded\n");
  return 0;
  
  }
  </code></pre>