htc-i2cpld.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * htc-i2cpld.c
  3. * Chip driver for an unknown CPLD chip found on omap850 HTC devices like
  4. * the HTC Wizard and HTC Herald.
  5. * The cpld is located on the i2c bus and acts as an input/output GPIO
  6. * extender.
  7. *
  8. * Copyright (C) 2009 Cory Maccarrone <darkstar6262@gmail.com>
  9. *
  10. * Based on work done in the linwizard project
  11. * Copyright (C) 2008-2009 Angelo Arrifano <miknix@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/kernel.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/i2c.h>
  33. #include <linux/irq.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/htcpld.h>
  36. #include <linux/gpio.h>
  37. #include <linux/slab.h>
  38. struct htcpld_chip {
  39. spinlock_t lock;
  40. /* chip info */
  41. u8 reset;
  42. u8 addr;
  43. struct device *dev;
  44. struct i2c_client *client;
  45. /* Output details */
  46. u8 cache_out;
  47. struct gpio_chip chip_out;
  48. /* Input details */
  49. u8 cache_in;
  50. struct gpio_chip chip_in;
  51. u16 irqs_enabled;
  52. uint irq_start;
  53. int nirqs;
  54. unsigned int flow_type;
  55. /*
  56. * Work structure to allow for setting values outside of any
  57. * possible interrupt context
  58. */
  59. struct work_struct set_val_work;
  60. };
  61. struct htcpld_data {
  62. /* irq info */
  63. u16 irqs_enabled;
  64. uint irq_start;
  65. int nirqs;
  66. uint chained_irq;
  67. unsigned int int_reset_gpio_hi;
  68. unsigned int int_reset_gpio_lo;
  69. /* htcpld info */
  70. struct htcpld_chip *chip;
  71. unsigned int nchips;
  72. };
  73. /* There does not appear to be a way to proactively mask interrupts
  74. * on the htcpld chip itself. So, we simply ignore interrupts that
  75. * aren't desired. */
  76. static void htcpld_mask(struct irq_data *data)
  77. {
  78. struct htcpld_chip *chip = irq_data_get_irq_chip_data(data);
  79. chip->irqs_enabled &= ~(1 << (data->irq - chip->irq_start));
  80. pr_debug("HTCPLD mask %d %04x\n", data->irq, chip->irqs_enabled);
  81. }
  82. static void htcpld_unmask(struct irq_data *data)
  83. {
  84. struct htcpld_chip *chip = irq_data_get_irq_chip_data(data);
  85. chip->irqs_enabled |= 1 << (data->irq - chip->irq_start);
  86. pr_debug("HTCPLD unmask %d %04x\n", data->irq, chip->irqs_enabled);
  87. }
  88. static int htcpld_set_type(struct irq_data *data, unsigned int flags)
  89. {
  90. struct htcpld_chip *chip = irq_data_get_irq_chip_data(data);
  91. if (flags & ~IRQ_TYPE_SENSE_MASK)
  92. return -EINVAL;
  93. /* We only allow edge triggering */
  94. if (flags & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH))
  95. return -EINVAL;
  96. chip->flow_type = flags;
  97. return 0;
  98. }
  99. static struct irq_chip htcpld_muxed_chip = {
  100. .name = "htcpld",
  101. .irq_mask = htcpld_mask,
  102. .irq_unmask = htcpld_unmask,
  103. .irq_set_type = htcpld_set_type,
  104. };
  105. /* To properly dispatch IRQ events, we need to read from the
  106. * chip. This is an I2C action that could possibly sleep
  107. * (which is bad in interrupt context) -- so we use a threaded
  108. * interrupt handler to get around that.
  109. */
  110. static irqreturn_t htcpld_handler(int irq, void *dev)
  111. {
  112. struct htcpld_data *htcpld = dev;
  113. unsigned int i;
  114. unsigned long flags;
  115. int irqpin;
  116. if (!htcpld) {
  117. pr_debug("htcpld is null in ISR\n");
  118. return IRQ_HANDLED;
  119. }
  120. /*
  121. * For each chip, do a read of the chip and trigger any interrupts
  122. * desired. The interrupts will be triggered from LSB to MSB (i.e.
  123. * bit 0 first, then bit 1, etc.)
  124. *
  125. * For chips that have no interrupt range specified, just skip 'em.
  126. */
  127. for (i = 0; i < htcpld->nchips; i++) {
  128. struct htcpld_chip *chip = &htcpld->chip[i];
  129. struct i2c_client *client;
  130. int val;
  131. unsigned long uval, old_val;
  132. if (!chip) {
  133. pr_debug("chip %d is null in ISR\n", i);
  134. continue;
  135. }
  136. if (chip->nirqs == 0)
  137. continue;
  138. client = chip->client;
  139. if (!client) {
  140. pr_debug("client %d is null in ISR\n", i);
  141. continue;
  142. }
  143. /* Scan the chip */
  144. val = i2c_smbus_read_byte_data(client, chip->cache_out);
  145. if (val < 0) {
  146. /* Throw a warning and skip this chip */
  147. dev_warn(chip->dev, "Unable to read from chip: %d\n",
  148. val);
  149. continue;
  150. }
  151. uval = (unsigned long)val;
  152. spin_lock_irqsave(&chip->lock, flags);
  153. /* Save away the old value so we can compare it */
  154. old_val = chip->cache_in;
  155. /* Write the new value */
  156. chip->cache_in = uval;
  157. spin_unlock_irqrestore(&chip->lock, flags);
  158. /*
  159. * For each bit in the data (starting at bit 0), trigger
  160. * associated interrupts.
  161. */
  162. for (irqpin = 0; irqpin < chip->nirqs; irqpin++) {
  163. unsigned oldb, newb, type = chip->flow_type;
  164. irq = chip->irq_start + irqpin;
  165. /* Run the IRQ handler, but only if the bit value
  166. * changed, and the proper flags are set */
  167. oldb = (old_val >> irqpin) & 1;
  168. newb = (uval >> irqpin) & 1;
  169. if ((!oldb && newb && (type & IRQ_TYPE_EDGE_RISING)) ||
  170. (oldb && !newb && (type & IRQ_TYPE_EDGE_FALLING))) {
  171. pr_debug("fire IRQ %d\n", irqpin);
  172. generic_handle_irq(irq);
  173. }
  174. }
  175. }
  176. /*
  177. * In order to continue receiving interrupts, the int_reset_gpio must
  178. * be asserted.
  179. */
  180. if (htcpld->int_reset_gpio_hi)
  181. gpio_set_value(htcpld->int_reset_gpio_hi, 1);
  182. if (htcpld->int_reset_gpio_lo)
  183. gpio_set_value(htcpld->int_reset_gpio_lo, 0);
  184. return IRQ_HANDLED;
  185. }
  186. /*
  187. * The GPIO set routines can be called from interrupt context, especially if,
  188. * for example they're attached to the led-gpio framework and a trigger is
  189. * enabled. As such, we declared work above in the htcpld_chip structure,
  190. * and that work is scheduled in the set routine. The kernel can then run
  191. * the I2C functions, which will sleep, in process context.
  192. */
  193. static void htcpld_chip_set(struct gpio_chip *chip, unsigned offset, int val)
  194. {
  195. struct i2c_client *client;
  196. struct htcpld_chip *chip_data;
  197. unsigned long flags;
  198. chip_data = container_of(chip, struct htcpld_chip, chip_out);
  199. if (!chip_data)
  200. return;
  201. client = chip_data->client;
  202. if (client == NULL)
  203. return;
  204. spin_lock_irqsave(&chip_data->lock, flags);
  205. if (val)
  206. chip_data->cache_out |= (1 << offset);
  207. else
  208. chip_data->cache_out &= ~(1 << offset);
  209. spin_unlock_irqrestore(&chip_data->lock, flags);
  210. schedule_work(&(chip_data->set_val_work));
  211. }
  212. static void htcpld_chip_set_ni(struct work_struct *work)
  213. {
  214. struct htcpld_chip *chip_data;
  215. struct i2c_client *client;
  216. chip_data = container_of(work, struct htcpld_chip, set_val_work);
  217. client = chip_data->client;
  218. i2c_smbus_read_byte_data(client, chip_data->cache_out);
  219. }
  220. static int htcpld_chip_get(struct gpio_chip *chip, unsigned offset)
  221. {
  222. struct htcpld_chip *chip_data;
  223. int val = 0;
  224. int is_input = 0;
  225. /* Try out first */
  226. chip_data = container_of(chip, struct htcpld_chip, chip_out);
  227. if (!chip_data) {
  228. /* Try in */
  229. is_input = 1;
  230. chip_data = container_of(chip, struct htcpld_chip, chip_in);
  231. if (!chip_data)
  232. return -EINVAL;
  233. }
  234. /* Determine if this is an input or output GPIO */
  235. if (!is_input)
  236. /* Use the output cache */
  237. val = (chip_data->cache_out >> offset) & 1;
  238. else
  239. /* Use the input cache */
  240. val = (chip_data->cache_in >> offset) & 1;
  241. if (val)
  242. return 1;
  243. else
  244. return 0;
  245. }
  246. static int htcpld_direction_output(struct gpio_chip *chip,
  247. unsigned offset, int value)
  248. {
  249. htcpld_chip_set(chip, offset, value);
  250. return 0;
  251. }
  252. static int htcpld_direction_input(struct gpio_chip *chip,
  253. unsigned offset)
  254. {
  255. /*
  256. * No-op: this function can only be called on the input chip.
  257. * We do however make sure the offset is within range.
  258. */
  259. return (offset < chip->ngpio) ? 0 : -EINVAL;
  260. }
  261. static int htcpld_chip_to_irq(struct gpio_chip *chip, unsigned offset)
  262. {
  263. struct htcpld_chip *chip_data;
  264. chip_data = container_of(chip, struct htcpld_chip, chip_in);
  265. if (offset < chip_data->nirqs)
  266. return chip_data->irq_start + offset;
  267. else
  268. return -EINVAL;
  269. }
  270. static void htcpld_chip_reset(struct i2c_client *client)
  271. {
  272. struct htcpld_chip *chip_data = i2c_get_clientdata(client);
  273. if (!chip_data)
  274. return;
  275. i2c_smbus_read_byte_data(
  276. client, (chip_data->cache_out = chip_data->reset));
  277. }
  278. static int __devinit htcpld_setup_chip_irq(
  279. struct platform_device *pdev,
  280. int chip_index)
  281. {
  282. struct htcpld_data *htcpld;
  283. struct device *dev = &pdev->dev;
  284. struct htcpld_core_platform_data *pdata;
  285. struct htcpld_chip *chip;
  286. struct htcpld_chip_platform_data *plat_chip_data;
  287. unsigned int irq, irq_end;
  288. int ret = 0;
  289. /* Get the platform and driver data */
  290. pdata = dev->platform_data;
  291. htcpld = platform_get_drvdata(pdev);
  292. chip = &htcpld->chip[chip_index];
  293. plat_chip_data = &pdata->chip[chip_index];
  294. /* Setup irq handlers */
  295. irq_end = chip->irq_start + chip->nirqs;
  296. for (irq = chip->irq_start; irq < irq_end; irq++) {
  297. irq_set_chip_and_handler(irq, &htcpld_muxed_chip,
  298. handle_simple_irq);
  299. irq_set_chip_data(irq, chip);
  300. #ifdef CONFIG_ARM
  301. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  302. #else
  303. irq_set_probe(irq);
  304. #endif
  305. }
  306. return ret;
  307. }
  308. static int __devinit htcpld_register_chip_i2c(
  309. struct platform_device *pdev,
  310. int chip_index)
  311. {
  312. struct htcpld_data *htcpld;
  313. struct device *dev = &pdev->dev;
  314. struct htcpld_core_platform_data *pdata;
  315. struct htcpld_chip *chip;
  316. struct htcpld_chip_platform_data *plat_chip_data;
  317. struct i2c_adapter *adapter;
  318. struct i2c_client *client;
  319. struct i2c_board_info info;
  320. /* Get the platform and driver data */
  321. pdata = dev->platform_data;
  322. htcpld = platform_get_drvdata(pdev);
  323. chip = &htcpld->chip[chip_index];
  324. plat_chip_data = &pdata->chip[chip_index];
  325. adapter = i2c_get_adapter(pdata->i2c_adapter_id);
  326. if (adapter == NULL) {
  327. /* Eek, no such I2C adapter! Bail out. */
  328. dev_warn(dev, "Chip at i2c address 0x%x: Invalid i2c adapter %d\n",
  329. plat_chip_data->addr, pdata->i2c_adapter_id);
  330. return -ENODEV;
  331. }
  332. if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
  333. dev_warn(dev, "i2c adapter %d non-functional\n",
  334. pdata->i2c_adapter_id);
  335. return -EINVAL;
  336. }
  337. memset(&info, 0, sizeof(struct i2c_board_info));
  338. info.addr = plat_chip_data->addr;
  339. strlcpy(info.type, "htcpld-chip", I2C_NAME_SIZE);
  340. info.platform_data = chip;
  341. /* Add the I2C device. This calls the probe() function. */
  342. client = i2c_new_device(adapter, &info);
  343. if (!client) {
  344. /* I2C device registration failed, contineu with the next */
  345. dev_warn(dev, "Unable to add I2C device for 0x%x\n",
  346. plat_chip_data->addr);
  347. return -ENODEV;
  348. }
  349. i2c_set_clientdata(client, chip);
  350. snprintf(client->name, I2C_NAME_SIZE, "Chip_0x%d", client->addr);
  351. chip->client = client;
  352. /* Reset the chip */
  353. htcpld_chip_reset(client);
  354. chip->cache_in = i2c_smbus_read_byte_data(client, chip->cache_out);
  355. return 0;
  356. }
  357. static void __devinit htcpld_unregister_chip_i2c(
  358. struct platform_device *pdev,
  359. int chip_index)
  360. {
  361. struct htcpld_data *htcpld;
  362. struct htcpld_chip *chip;
  363. /* Get the platform and driver data */
  364. htcpld = platform_get_drvdata(pdev);
  365. chip = &htcpld->chip[chip_index];
  366. if (chip->client)
  367. i2c_unregister_device(chip->client);
  368. }
  369. static int __devinit htcpld_register_chip_gpio(
  370. struct platform_device *pdev,
  371. int chip_index)
  372. {
  373. struct htcpld_data *htcpld;
  374. struct device *dev = &pdev->dev;
  375. struct htcpld_core_platform_data *pdata;
  376. struct htcpld_chip *chip;
  377. struct htcpld_chip_platform_data *plat_chip_data;
  378. struct gpio_chip *gpio_chip;
  379. int ret = 0;
  380. /* Get the platform and driver data */
  381. pdata = dev->platform_data;
  382. htcpld = platform_get_drvdata(pdev);
  383. chip = &htcpld->chip[chip_index];
  384. plat_chip_data = &pdata->chip[chip_index];
  385. /* Setup the GPIO chips */
  386. gpio_chip = &(chip->chip_out);
  387. gpio_chip->label = "htcpld-out";
  388. gpio_chip->dev = dev;
  389. gpio_chip->owner = THIS_MODULE;
  390. gpio_chip->get = htcpld_chip_get;
  391. gpio_chip->set = htcpld_chip_set;
  392. gpio_chip->direction_input = NULL;
  393. gpio_chip->direction_output = htcpld_direction_output;
  394. gpio_chip->base = plat_chip_data->gpio_out_base;
  395. gpio_chip->ngpio = plat_chip_data->num_gpios;
  396. gpio_chip = &(chip->chip_in);
  397. gpio_chip->label = "htcpld-in";
  398. gpio_chip->dev = dev;
  399. gpio_chip->owner = THIS_MODULE;
  400. gpio_chip->get = htcpld_chip_get;
  401. gpio_chip->set = NULL;
  402. gpio_chip->direction_input = htcpld_direction_input;
  403. gpio_chip->direction_output = NULL;
  404. gpio_chip->to_irq = htcpld_chip_to_irq;
  405. gpio_chip->base = plat_chip_data->gpio_in_base;
  406. gpio_chip->ngpio = plat_chip_data->num_gpios;
  407. /* Add the GPIO chips */
  408. ret = gpiochip_add(&(chip->chip_out));
  409. if (ret) {
  410. dev_warn(dev, "Unable to register output GPIOs for 0x%x: %d\n",
  411. plat_chip_data->addr, ret);
  412. return ret;
  413. }
  414. ret = gpiochip_add(&(chip->chip_in));
  415. if (ret) {
  416. int error;
  417. dev_warn(dev, "Unable to register input GPIOs for 0x%x: %d\n",
  418. plat_chip_data->addr, ret);
  419. error = gpiochip_remove(&(chip->chip_out));
  420. if (error)
  421. dev_warn(dev, "Error while trying to unregister gpio chip: %d\n", error);
  422. return ret;
  423. }
  424. return 0;
  425. }
  426. static int __devinit htcpld_setup_chips(struct platform_device *pdev)
  427. {
  428. struct htcpld_data *htcpld;
  429. struct device *dev = &pdev->dev;
  430. struct htcpld_core_platform_data *pdata;
  431. int i;
  432. /* Get the platform and driver data */
  433. pdata = dev->platform_data;
  434. htcpld = platform_get_drvdata(pdev);
  435. /* Setup each chip's output GPIOs */
  436. htcpld->nchips = pdata->num_chip;
  437. htcpld->chip = kzalloc(sizeof(struct htcpld_chip) * htcpld->nchips,
  438. GFP_KERNEL);
  439. if (!htcpld->chip) {
  440. dev_warn(dev, "Unable to allocate memory for chips\n");
  441. return -ENOMEM;
  442. }
  443. /* Add the chips as best we can */
  444. for (i = 0; i < htcpld->nchips; i++) {
  445. int ret;
  446. /* Setup the HTCPLD chips */
  447. htcpld->chip[i].reset = pdata->chip[i].reset;
  448. htcpld->chip[i].cache_out = pdata->chip[i].reset;
  449. htcpld->chip[i].cache_in = 0;
  450. htcpld->chip[i].dev = dev;
  451. htcpld->chip[i].irq_start = pdata->chip[i].irq_base;
  452. htcpld->chip[i].nirqs = pdata->chip[i].num_irqs;
  453. INIT_WORK(&(htcpld->chip[i].set_val_work), &htcpld_chip_set_ni);
  454. spin_lock_init(&(htcpld->chip[i].lock));
  455. /* Setup the interrupts for the chip */
  456. if (htcpld->chained_irq) {
  457. ret = htcpld_setup_chip_irq(pdev, i);
  458. if (ret)
  459. continue;
  460. }
  461. /* Register the chip with I2C */
  462. ret = htcpld_register_chip_i2c(pdev, i);
  463. if (ret)
  464. continue;
  465. /* Register the chips with the GPIO subsystem */
  466. ret = htcpld_register_chip_gpio(pdev, i);
  467. if (ret) {
  468. /* Unregister the chip from i2c and continue */
  469. htcpld_unregister_chip_i2c(pdev, i);
  470. continue;
  471. }
  472. dev_info(dev, "Registered chip at 0x%x\n", pdata->chip[i].addr);
  473. }
  474. return 0;
  475. }
  476. static int __devinit htcpld_core_probe(struct platform_device *pdev)
  477. {
  478. struct htcpld_data *htcpld;
  479. struct device *dev = &pdev->dev;
  480. struct htcpld_core_platform_data *pdata;
  481. struct resource *res;
  482. int ret = 0;
  483. if (!dev)
  484. return -ENODEV;
  485. pdata = dev->platform_data;
  486. if (!pdata) {
  487. dev_warn(dev, "Platform data not found for htcpld core!\n");
  488. return -ENXIO;
  489. }
  490. htcpld = kzalloc(sizeof(struct htcpld_data), GFP_KERNEL);
  491. if (!htcpld)
  492. return -ENOMEM;
  493. /* Find chained irq */
  494. ret = -EINVAL;
  495. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  496. if (res) {
  497. int flags;
  498. htcpld->chained_irq = res->start;
  499. /* Setup the chained interrupt handler */
  500. flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING;
  501. ret = request_threaded_irq(htcpld->chained_irq,
  502. NULL, htcpld_handler,
  503. flags, pdev->name, htcpld);
  504. if (ret) {
  505. dev_warn(dev, "Unable to setup chained irq handler: %d\n", ret);
  506. goto fail;
  507. } else
  508. device_init_wakeup(dev, 0);
  509. }
  510. /* Set the driver data */
  511. platform_set_drvdata(pdev, htcpld);
  512. /* Setup the htcpld chips */
  513. ret = htcpld_setup_chips(pdev);
  514. if (ret)
  515. goto fail;
  516. /* Request the GPIO(s) for the int reset and set them up */
  517. if (pdata->int_reset_gpio_hi) {
  518. ret = gpio_request(pdata->int_reset_gpio_hi, "htcpld-core");
  519. if (ret) {
  520. /*
  521. * If it failed, that sucks, but we can probably
  522. * continue on without it.
  523. */
  524. dev_warn(dev, "Unable to request int_reset_gpio_hi -- interrupts may not work\n");
  525. htcpld->int_reset_gpio_hi = 0;
  526. } else {
  527. htcpld->int_reset_gpio_hi = pdata->int_reset_gpio_hi;
  528. gpio_set_value(htcpld->int_reset_gpio_hi, 1);
  529. }
  530. }
  531. if (pdata->int_reset_gpio_lo) {
  532. ret = gpio_request(pdata->int_reset_gpio_lo, "htcpld-core");
  533. if (ret) {
  534. /*
  535. * If it failed, that sucks, but we can probably
  536. * continue on without it.
  537. */
  538. dev_warn(dev, "Unable to request int_reset_gpio_lo -- interrupts may not work\n");
  539. htcpld->int_reset_gpio_lo = 0;
  540. } else {
  541. htcpld->int_reset_gpio_lo = pdata->int_reset_gpio_lo;
  542. gpio_set_value(htcpld->int_reset_gpio_lo, 0);
  543. }
  544. }
  545. dev_info(dev, "Initialized successfully\n");
  546. return 0;
  547. fail:
  548. kfree(htcpld);
  549. return ret;
  550. }
  551. /* The I2C Driver -- used internally */
  552. static const struct i2c_device_id htcpld_chip_id[] = {
  553. { "htcpld-chip", 0 },
  554. { }
  555. };
  556. MODULE_DEVICE_TABLE(i2c, htcpld_chip_id);
  557. static struct i2c_driver htcpld_chip_driver = {
  558. .driver = {
  559. .name = "htcpld-chip",
  560. },
  561. .id_table = htcpld_chip_id,
  562. };
  563. /* The Core Driver */
  564. static struct platform_driver htcpld_core_driver = {
  565. .driver = {
  566. .name = "i2c-htcpld",
  567. },
  568. };
  569. static int __init htcpld_core_init(void)
  570. {
  571. int ret;
  572. /* Register the I2C Chip driver */
  573. ret = i2c_add_driver(&htcpld_chip_driver);
  574. if (ret)
  575. return ret;
  576. /* Probe for our chips */
  577. return platform_driver_probe(&htcpld_core_driver, htcpld_core_probe);
  578. }
  579. static void __exit htcpld_core_exit(void)
  580. {
  581. i2c_del_driver(&htcpld_chip_driver);
  582. platform_driver_unregister(&htcpld_core_driver);
  583. }
  584. module_init(htcpld_core_init);
  585. module_exit(htcpld_core_exit);
  586. MODULE_AUTHOR("Cory Maccarrone <darkstar6262@gmail.com>");
  587. MODULE_DESCRIPTION("I2C HTC PLD Driver");
  588. MODULE_LICENSE("GPL");