max7300.c 2.0 KB

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