gpio-max7300.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 2009 Wolfram Sang, Pengutronix
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * Check max730x.c for further details.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/mutex.h>
  14. #include <linux/i2c.h>
  15. #include <linux/spi/max7301.h>
  16. #include <linux/slab.h>
  17. static int max7300_i2c_write(struct device *dev, unsigned int reg,
  18. unsigned int val)
  19. {
  20. struct i2c_client *client = to_i2c_client(dev);
  21. return i2c_smbus_write_byte_data(client, reg, val);
  22. }
  23. static int max7300_i2c_read(struct device *dev, unsigned int reg)
  24. {
  25. struct i2c_client *client = to_i2c_client(dev);
  26. return i2c_smbus_read_byte_data(client, reg);
  27. }
  28. static int __devinit max7300_probe(struct i2c_client *client,
  29. const struct i2c_device_id *id)
  30. {
  31. struct max7301 *ts;
  32. int ret;
  33. if (!i2c_check_functionality(client->adapter,
  34. I2C_FUNC_SMBUS_BYTE_DATA))
  35. return -EIO;
  36. ts = kzalloc(sizeof(struct max7301), GFP_KERNEL);
  37. if (!ts)
  38. return -ENOMEM;
  39. ts->read = max7300_i2c_read;
  40. ts->write = max7300_i2c_write;
  41. ts->dev = &client->dev;
  42. ret = __max730x_probe(ts);
  43. if (ret)
  44. kfree(ts);
  45. return ret;
  46. }
  47. static int __devexit max7300_remove(struct i2c_client *client)
  48. {
  49. return __max730x_remove(&client->dev);
  50. }
  51. static const struct i2c_device_id max7300_id[] = {
  52. { "max7300", 0 },
  53. { }
  54. };
  55. MODULE_DEVICE_TABLE(i2c, max7300_id);
  56. static struct i2c_driver max7300_driver = {
  57. .driver = {
  58. .name = "max7300",
  59. .owner = THIS_MODULE,
  60. },
  61. .probe = max7300_probe,
  62. .remove = __devexit_p(max7300_remove),
  63. .id_table = max7300_id,
  64. };
  65. static int __init max7300_init(void)
  66. {
  67. return i2c_add_driver(&max7300_driver);
  68. }
  69. subsys_initcall(max7300_init);
  70. static void __exit max7300_exit(void)
  71. {
  72. i2c_del_driver(&max7300_driver);
  73. }
  74. module_exit(max7300_exit);
  75. MODULE_AUTHOR("Wolfram Sang");
  76. MODULE_LICENSE("GPL v2");
  77. MODULE_DESCRIPTION("MAX7300 GPIO-Expander");