Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

rm print_buffer/a6_generic_show use; add/use a6_reg_get

Change-Id: I0d2c8a7c07778bf74d74442635251f2624d39c0c
commit c9cc636b4e0ddcbbb6dbd14b57870c2c197c5d07 1 parent 03c4a6b
James Sullins jcsullins authored

Showing 1 changed file with 122 additions and 81 deletions. Show diff stats Hide diff stats

  1. +122 81 drivers/misc/a6/a6.c
203 drivers/misc/a6/a6.c
@@ -611,9 +611,6 @@ struct a6_device_state {
611 611 int stop_heartbeat;
612 612 int last_percent;
613 613
614   - /* used for the various generic_show calls, to be removed later */
615   - char *print_buffer;
616   -
617 614 struct switch_dev *dock_switch;
618 615 };
619 616
@@ -2519,11 +2516,10 @@ int32_t format_serno_v2(const struct a6_device_state* state, const uint8_t* val,
2519 2516 return ret;
2520 2517 }
2521 2518
2522   -static ssize_t a6_generic_show(struct device *dev, struct device_attribute *attr, char *buf)
  2519 +static ssize_t a6_get_reg_vals(struct device *dev, struct device_attribute *attr, uint8_t *vals, unsigned num_vals)
2523 2520 {
2524 2521 struct i2c_client *client = to_i2c_client(dev);
2525   - int32_t ret = 0, i = 0;
2526   - uint8_t vals[id_size];
  2522 + int32_t ret = 0;
2527 2523 struct a6_register_desc* reg_desc;
2528 2524 struct a6_device_state* state = i2c_get_clientdata(client);
2529 2525
@@ -2572,11 +2568,37 @@ static ssize_t a6_generic_show(struct device *dev, struct device_attribute *attr
2572 2568
2573 2569 reg_desc = container_of(attr, struct a6_register_desc, dev_attr);
2574 2570
2575   - memset(vals, 0, sizeof(vals));
  2571 + memset(vals, 0, sizeof(vals[0])*num_vals);
2576 2572 ret = a6_i2c_read_reg(client, reg_desc->id, reg_desc->num_ids, vals);
2577   - if (ret < 0) {
2578   - goto err0;
  2573 +
  2574 + // reset busy state
  2575 + mutex_lock(&state->dev_mutex);
  2576 + // decrement busy refcount
  2577 + if (state->busy_count) {
  2578 + state->busy_count--;
  2579 + }
  2580 + if (!state->busy_count) {
  2581 + clear_bit(DEVICE_BUSY_BIT, state->flags);
2579 2582 }
  2583 + mutex_unlock(&state->dev_mutex);
  2584 + wake_up_interruptible(&state->dev_busyq);
  2585 +
  2586 + return ret;
  2587 +}
  2588 +
  2589 +static ssize_t a6_generic_show(struct device *dev, struct device_attribute *attr, char *buf)
  2590 +{
  2591 + int32_t ret = 0, i = 0;
  2592 + uint8_t vals[id_size];
  2593 + struct a6_register_desc* reg_desc;
  2594 + struct i2c_client *client = to_i2c_client(dev);
  2595 + struct a6_device_state* state = i2c_get_clientdata(client);
  2596 +
  2597 + ret = a6_get_reg_vals(dev, attr, vals, id_size);
  2598 +
  2599 + if (ret < 0) return ret;
  2600 +
  2601 + reg_desc = container_of(attr, struct a6_register_desc, dev_attr);
2580 2602
2581 2603 if (reg_desc->format) {
2582 2604 ret = reg_desc->format(state, vals, buf, PAGE_SIZE);
@@ -2620,18 +2642,77 @@ static ssize_t a6_generic_show(struct device *dev, struct device_attribute *attr
2620 2642 }
2621 2643 #endif
2622 2644
2623   -err0:
2624   - // reset busy state
2625   - mutex_lock(&state->dev_mutex);
2626   - // decrement busy refcount
2627   - if (state->busy_count) {
2628   - state->busy_count--;
  2645 + return ret;
  2646 +}
  2647 +
  2648 +static ssize_t a6_reg_get(struct device *dev, unsigned regnum, void *buf)
  2649 +{
  2650 + int32_t ret = 0;
  2651 + uint8_t vals[id_size];
  2652 + struct i2c_client *client = to_i2c_client(dev);
  2653 + struct a6_device_state* state = i2c_get_clientdata(client);
  2654 + struct device_attribute *attr = &a6_register_desc_arr[regnum].dev_attr;
  2655 + int32_t rsense = (int32_t)state->cached_rsense_val;
  2656 +
  2657 + ret = a6_get_reg_vals(dev, attr, vals, id_size);
  2658 +
  2659 + if (ret < 0) {
  2660 + printk(KERN_ERR "%s: a6_get_reg_vals failed for regnum %u\n",
  2661 + __func__, regnum);
  2662 + return ret;
2629 2663 }
2630   - if (!state->busy_count) {
2631   - clear_bit(DEVICE_BUSY_BIT, state->flags);
  2664 +
  2665 + ret = 0;
  2666 +
  2667 + switch (regnum) {
  2668 + case A6_REG_TS2_I2C_FLAGS_2:
  2669 + {
  2670 + uint32_t *out_val = (uint32_t*)buf;
  2671 + *out_val = *vals;
  2672 + }
  2673 + break;
  2674 + case A6_REG_TS2_I2C_BAT_RARC:
  2675 + {
  2676 + int32_t *out_val = (int32_t*)buf;
  2677 + *out_val = *vals;
  2678 + }
  2679 + break;
  2680 + case A6_REG_TS2_I2C_BAT_AVG_CUR_LSB_MSB:
  2681 + case A6_REG_TS2_I2C_BAT_CUR_LSB_MSB:
  2682 + {
  2683 + int32_t *out_val = (int32_t*)buf;
  2684 + *out_val = *(int16_t*)vals;
  2685 + *out_val = (*out_val * 3125) / 2 / rsense;
  2686 + }
  2687 + break;
  2688 + case A6_REG_TS2_I2C_BAT_VOLT_LSB_MSB:
  2689 + {
  2690 + int32_t *out_val = (int32_t*)buf;
  2691 + *out_val = *(int16_t*)vals;
  2692 + *out_val = (*out_val >> 5) * 4800;
  2693 + }
  2694 + break;
  2695 + case A6_REG_TS2_I2C_BAT_FULL40_LSB_MSB:
  2696 + case A6_REG_TS2_I2C_BAT_COULOMB_LSB_MSB:
  2697 + {
  2698 + int32_t *out_val = (int32_t*)buf;
  2699 + *out_val = *(int16_t*)vals;
  2700 + *out_val = (*out_val * 6250) / rsense;
  2701 + }
  2702 + break;
  2703 + case A6_REG_TS2_I2C_BAT_TEMP_LSB_MSB:
  2704 + {
  2705 + int32_t *out_val = (int32_t*)buf;
  2706 + int8_t temp_val = ((int8_t*)vals)[1];
  2707 + *out_val = temp_val * 10;
  2708 + }
  2709 + break;
  2710 + default:
  2711 + {
  2712 + printk(KERN_ERR "%s: Invalid register %u\n", __func__, regnum);
  2713 + ret = -EINVAL;
  2714 + }
2632 2715 }
2633   - mutex_unlock(&state->dev_mutex);
2634   - wake_up_interruptible(&state->dev_busyq);
2635 2716
2636 2717 return ret;
2637 2718 }
@@ -4358,11 +4439,8 @@ struct file_operations a6_pmem_fops = {
4358 4439 static int a6_fish_battery_get_percent(struct device *dev)
4359 4440 {
4360 4441 int temp_val = 0;
4361   - struct a6_device_state *state = (struct a6_device_state*) dev_get_drvdata(dev);
4362 4442
4363   - state->print_buffer[0] = '\0';
4364   - a6_generic_show (dev, &a6_register_desc_arr[9].dev_attr, state->print_buffer);
4365   - sscanf (state->print_buffer, "%d", &temp_val);
  4443 + a6_reg_get (dev, A6_REG_TS2_I2C_BAT_RARC, &temp_val);
4366 4444
4367 4445 return temp_val;
4368 4446 }
@@ -4386,12 +4464,8 @@ static unsigned a6_calc_connected_ps(void)
4386 4464 }
4387 4465
4388 4466 state = (struct a6_device_state*)dev_get_drvdata(psy->dev->parent);
4389   - state->print_buffer[0] = '\0';
4390   -
4391   - a6_generic_show (psy->dev->parent,
4392   - &a6_register_desc_arr[31].dev_attr, state->print_buffer);
4393 4467
4394   - sscanf (state->print_buffer, "%u", &temp_val);
  4468 + a6_reg_get (psy->dev->parent, A6_REG_TS2_I2C_FLAGS_2, &temp_val);
4395 4469
4396 4470 if (state->otg_chg_type == USB_CHG_TYPE__WALLCHARGER) {
4397 4471 connected |= MAX8903B_CONNECTED_PS_AC;
@@ -4474,8 +4548,6 @@ static int a6_fish_battery_get_property(struct power_supply *psy,
4474 4548 {
4475 4549 int temp_val = 0;
4476 4550 unsigned connected;
4477   - struct a6_device_state *state =
4478   - (struct a6_device_state*)dev_get_drvdata(psy->dev->parent);
4479 4551
4480 4552 switch (psp) {
4481 4553 case POWER_SUPPLY_PROP_STATUS:
@@ -4483,12 +4555,8 @@ static int a6_fish_battery_get_property(struct power_supply *psy,
4483 4555 val->intval = POWER_SUPPLY_STATUS_FULL;
4484 4556 } else if (a6_last_ps_connect &&
4485 4557 jiffies > a6_last_ps_connect + A6_BATT_STATS_DELAY) {
4486   - state->print_buffer[0] = '\0';
4487   - a6_generic_show (psy->dev->parent,
4488   - /* TODO use A6_REG_TS2_I2C_BAT_AVG_CUR_LSB_MSB for 11 */
4489   - &a6_register_desc_arr[11].dev_attr,
4490   - state->print_buffer);
4491   - sscanf (state->print_buffer, "%d", &temp_val);
  4558 + a6_reg_get (psy->dev->parent,
  4559 + A6_REG_TS2_I2C_BAT_AVG_CUR_LSB_MSB, &temp_val);
4492 4560 if (temp_val > 0) {
4493 4561 val->intval = POWER_SUPPLY_STATUS_CHARGING;
4494 4562 } else {
@@ -4505,8 +4573,8 @@ static int a6_fish_battery_get_property(struct power_supply *psy,
4505 4573 break;
4506 4574 case POWER_SUPPLY_PROP_HEALTH:
4507 4575 #if 0
4508   - state->print_buffer[0] = '\0';
4509   - a6_generic_show (psy->dev->parent, &a6_register_desc_arr[8].dev_attr, state->print_buffer);
  4576 + /* NOTE: *_BAT_STATUS not supported by a6_reg_get yet */
  4577 + a6_reg_get(psy->dev->parent, A6_REG_TS2_I2C_BAT_STATUS, &temp_uval);
4510 4578 #endif
4511 4579 // TODO: parse temps and set OVERHEAT, parse "age" and set DEAD */
4512 4580
@@ -4522,44 +4590,29 @@ static int a6_fish_battery_get_property(struct power_supply *psy,
4522 4590 val->intval = a6_fish_battery_get_percent(psy->dev->parent);
4523 4591 break;
4524 4592 case POWER_SUPPLY_PROP_CURRENT_NOW:
4525   - state->print_buffer[0] = '\0';
4526   - a6_generic_show (psy->dev->parent,
4527   - &a6_register_desc_arr[A6_REG_TS2_I2C_BAT_CUR_LSB_MSB].dev_attr,
4528   - state->print_buffer);
4529   - sscanf (state->print_buffer, "%d", &temp_val);
  4593 + a6_reg_get(psy->dev->parent,
  4594 + A6_REG_TS2_I2C_BAT_CUR_LSB_MSB, &temp_val);
4530 4595 val->intval = temp_val;
4531 4596 break;
4532 4597 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
4533   - state->print_buffer[0] = '\0';
4534   - a6_generic_show (psy->dev->parent,
4535   - &a6_register_desc_arr[A6_REG_TS2_I2C_BAT_VOLT_LSB_MSB].dev_attr,
4536   - state->print_buffer);
4537   - sscanf (state->print_buffer, "%d", &temp_val);
  4598 + a6_reg_get (psy->dev->parent,
  4599 + A6_REG_TS2_I2C_BAT_VOLT_LSB_MSB, &temp_val);
4538 4600 val->intval = temp_val;
4539 4601 break;
4540 4602 case POWER_SUPPLY_PROP_TEMP:
4541   - state->print_buffer[0] = '\0';
4542   - a6_generic_show (psy->dev->parent,
4543   - &a6_register_desc_arr[A6_REG_TS2_I2C_BAT_TEMP_LSB_MSB].dev_attr,
4544   - state->print_buffer);
4545   - sscanf (state->print_buffer, "%d", &temp_val);
4546   - val->intval = temp_val * 10; /* convert C to .1 C */
  4603 + a6_reg_get (psy->dev->parent,
  4604 + A6_REG_TS2_I2C_BAT_TEMP_LSB_MSB, &temp_val);
  4605 + val->intval = temp_val;
4547 4606 break;
4548 4607 case POWER_SUPPLY_PROP_CHARGE_FULL:
4549   - state->print_buffer[0] = '\0';
4550   - a6_generic_show (psy->dev->parent,
4551   - &a6_register_desc_arr[A6_REG_TS2_I2C_BAT_FULL40_LSB_MSB].dev_attr,
4552   - state->print_buffer);
4553   - sscanf (state->print_buffer, "%d", &temp_val);
4554   - val->intval = temp_val * 1000;
  4608 + a6_reg_get (psy->dev->parent,
  4609 + A6_REG_TS2_I2C_BAT_FULL40_LSB_MSB, &temp_val);
  4610 + val->intval = temp_val;
4555 4611 break;
4556 4612 case POWER_SUPPLY_PROP_CHARGE_NOW:
4557   - state->print_buffer[0] = '\0';
4558   - a6_generic_show (psy->dev->parent,
4559   - &a6_register_desc_arr[A6_REG_TS2_I2C_BAT_COULOMB_LSB_MSB].dev_attr,
4560   - state->print_buffer);
4561   - sscanf (state->print_buffer, "%d", &temp_val);
4562   - val->intval = temp_val * 1000;
  4613 + a6_reg_get (psy->dev->parent,
  4614 + A6_REG_TS2_I2C_BAT_COULOMB_LSB_MSB, &temp_val);
  4615 + val->intval = temp_val;
4563 4616 break;
4564 4617 default:
4565 4618 return -EINVAL;
@@ -4694,9 +4747,7 @@ static void a6_dock_update_state(struct a6_device_state *state)
4694 4747 return;
4695 4748 }
4696 4749
4697   - state->print_buffer[0] = '\0';
4698   - a6_generic_show (&state->i2c_dev->dev, &a6_register_desc_arr[31].dev_attr, state->print_buffer);
4699   - sscanf (state->print_buffer, "%u", &value);
  4750 + a6_reg_get (&state->i2c_dev->dev, A6_REG_TS2_I2C_FLAGS_2, &value);
4700 4751
4701 4752 if (a6_disable_dock_switch) {
4702 4753 dock = 0;
@@ -4748,11 +4799,13 @@ static int a6_i2c_probe(struct i2c_client *client, const struct i2c_device_id *d
4748 4799 struct a6_wake_ops *wake_ops = (struct a6_wake_ops *) plat_data->wake_ops;
4749 4800
4750 4801 if (plat_data == NULL) {
  4802 + /* should this be -ENODEV ? TODO */
4751 4803 return ENODEV;
4752 4804 }
4753 4805
4754 4806 state = kzalloc(sizeof(struct a6_device_state), GFP_KERNEL);
4755 4807 if(!state) {
  4808 + /* should this be -ENOMEM ? TODO */
4756 4809 return ENOMEM;
4757 4810 }
4758 4811
@@ -4767,12 +4820,6 @@ static int a6_i2c_probe(struct i2c_client *client, const struct i2c_device_id *d
4767 4820 goto err1;
4768 4821 }
4769 4822
4770   - state->print_buffer = kzalloc(PAGE_SIZE, GFP_KERNEL);
4771   - if (!state->print_buffer) {
4772   - rc = -ENOMEM;
4773   - goto err2;
4774   - }
4775   -
4776 4823 // store i2c client device in state
4777 4824 state->i2c_dev = client;
4778 4825
@@ -4986,8 +5033,6 @@ static int a6_i2c_probe(struct i2c_client *client, const struct i2c_device_id *d
4986 5033 err4:
4987 5034 destroy_workqueue(state->ka6d_workqueue);
4988 5035 err3:
4989   - kfree(state->print_buffer);
4990   -err2:
4991 5036 kfree(state->a2a_wr_buf);
4992 5037 err1:
4993 5038 kfree(state->a2a_rd_buf);
@@ -5031,10 +5076,6 @@ static int a6_i2c_remove(struct i2c_client *client)
5031 5076 kfree(state->a2a_wr_buf);
5032 5077 }
5033 5078
5034   - if (state->print_buffer) {
5035   - kfree(state->print_buffer);
5036   - }
5037   -
5038 5079 return 0;
5039 5080 }
5040 5081

Git Notes

review

Code-Review+2: Erik Hardesty <dalingrin@gmail.com>
Verified+1: Erik Hardesty <dalingrin@gmail.com>
Submitted-by: Erik Hardesty <dalingrin@gmail.com>
Submitted-at: Thu, 05 Jan 2012 08:32:16 +0300
Reviewed-on: http://review.cyanogenmod.com/10057
Project: CyanogenMod/hp-kernel-tenderloin
Branch: refs/heads/gingerbread

0 comments on commit c9cc636

Please sign in to comment.
Something went wrong with that request. Please try again.