gpio-max7300.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 max7300_probe(struct i2c_client *client,
  29. const struct i2c_device_id *id)
  30. {
  31. struct max7301 *ts;
  32. if (!i2c_check_functionality(client->adapter,
  33. I2C_FUNC_SMBUS_BYTE_DATA))
  34. return -EIO;
  35. ts = devm_kzalloc(&client->dev, sizeof(struct max7301), GFP_KERNEL);
  36. if (!ts)
  37. return -ENOMEM;
  38. ts->read = max7300_i2c_read;
  39. ts->write = max7300_i2c_write;
  40. ts->dev = &client->dev;
  41. return __max730x_probe(ts);
  42. }
  43. static int max7300_remove(struct i2c_client *client)
  44. {
  45. return __max730x_remove(&client->dev);
  46. }
  47. static const struct i2c_device_id max7300_id[] = {
  48. { "max7300", 0 },
  49. { }
  50. };
  51. MODULE_DEVICE_TABLE(i2c, max7300_id);
  52. static struct i2c_driver max7300_driver = {
  53. .driver = {
  54. .name = "max7300",
  55. .owner = THIS_MODULE,
  56. },
  57. .probe = max7300_probe,
  58. .remove = max7300_remove,
  59. .id_table = max7300_id,
  60. };
  61. static int __init max7300_init(void)
  62. {
  63. return i2c_add_driver(&max7300_driver);
  64. }
  65. subsys_initcall(max7300_init);
  66. static void __exit max7300_exit(void)
  67. {
  68. i2c_del_driver(&max7300_driver);
  69. }
  70. module_exit(max7300_exit);
  71. MODULE_AUTHOR("Wolfram Sang");
  72. MODULE_LICENSE("GPL v2");
  73. MODULE_DESCRIPTION("MAX7300 GPIO-Expander");