Skip to content

Commit 6848e97

Browse files
committed
Repurposed sppp_power as battery driver, updated config.
We guess battery charge by measuring current voltage and comparing to a discharge graph. /sys/class/power_supply/sppp_power show battery data and DCIN changes create device events.
1 parent 30dbb87 commit 6848e97

File tree

11 files changed

+679
-97
lines changed

11 files changed

+679
-97
lines changed

arch/arm/configs/mx53_efikasb_defconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Automatically generated make config: don't edit
33
# Linux/arm 2.6.38.3 Kernel Configuration
4-
# Mon Jul 14 18:42:37 2014
4+
# Fri Jul 18 15:49:53 2014
55
#
66
CONFIG_ARM=y
77
CONFIG_HAVE_PWM=y
@@ -1268,6 +1268,7 @@ CONFIG_POWER_SUPPLY=y
12681268
# CONFIG_BATTERY_MAX17042 is not set
12691269
# CONFIG_CHARGER_ISP1704 is not set
12701270
# CONFIG_CHARGER_GPIO is not set
1271+
CONFIG_BATTERY_SPPP=y
12711272
CONFIG_HWMON=y
12721273
# CONFIG_HWMON_VID is not set
12731274
# CONFIG_HWMON_DEBUG_CHIP is not set

arch/arm/mach-mx5/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ obj-$(CONFIG_MACH_MX53_EVK) += board-mx53_evk.o
1717
obj-$(CONFIG_MACH_MX53_SMD) += board-mx53_smd.o mx53_smd_pmic_da9053.o
1818
obj-$(CONFIG_MACH_IMX_BLUETOOTH_RFKILL) += imx_bt_rfkill.o
1919
obj-$(CONFIG_MACH_MX53_LOCO) += board-mx53_loco.o mx53_loco_pmic_da9053.o
20-
obj-$(CONFIG_MACH_MX53_EFIKASB) += board-mx53_efikasb.o spppdriver.o sppp_power.o
20+
obj-$(CONFIG_MACH_MX53_EFIKASB) += board-mx53_efikasb.o spppdriver.o
2121
obj-$(CONFIG_MACH_MX53_ARD) += board-mx53_ard.o
2222
obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o
2323
obj-$(CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD) += eukrea_mbimx51-baseboard.o

arch/arm/mach-mx5/board-mx53_efikasb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ struct platform_device mxc_nandv2_mtd_device = {
324324
.num_resources = ARRAY_SIZE(mxc_nand_resources),
325325
};
326326

327+
struct platform_device mxc_battery = {
328+
.name = "sppp_power",
329+
.id = -1,
330+
};
327331

328332
static void mx53_efikasb_usbh1_vbus(bool on)
329333
{
@@ -530,6 +534,9 @@ static void __init mx53_efikasb_board_init(void)
530534
/* NAND */
531535
mxc_register_device(&mxc_nandv2_mtd_device, &efikasb_nand_data);
532536

537+
/* Battery */
538+
mxc_register_device(&mxc_battery, NULL);
539+
533540
/*GPU*/
534541
if (mx53_revision() >= IMX_CHIP_REVISION_2_0)
535542
gpu_data.z160_revision = 1;

arch/arm/mach-mx5/sppp_power.c

Lines changed: 0 additions & 87 deletions
This file was deleted.

arch/arm/mach-mx5/spppdriver.c

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct sppp_device {
4747
struct clk *clk;
4848
};
4949

50-
/* Array od SPPP clients */
50+
/* Array of SPPP clients */
5151
static struct sppp_client *array_of_clients[MAX_CLIENTS] = {NULL};
5252

5353
/* baseint contains the address as a 32 bit integer */
@@ -58,11 +58,48 @@ static struct sppp_device sppp __initdata;
5858

5959
/* Receive structure */
6060
static sppp_rx_t sppp_rx_g;
61+
static uint32_t sppp_status_lstn_ids = 0;
62+
63+
/*
64+
* Private SPPP client functions
65+
*/
66+
static inline int sppp_client_is_registered(struct sppp_client *client)
67+
{
68+
return (client != NULL) &&
69+
(client->id < MAX_CLIENTS) &&
70+
(array_of_clients[client->id] != NULL);
71+
}
72+
73+
static inline void sppp_client_mark_lstn(struct sppp_client *client)
74+
{
75+
sppp_status_lstn_ids |= (1 << client->id);
76+
}
77+
78+
static inline int sppp_client_is_lstn(struct sppp_client *client)
79+
{
80+
return (sppp_status_lstn_ids & (1 << client->id)) != 0;
81+
}
82+
83+
static inline void sppp_clr_lstn(void)
84+
{
85+
sppp_status_lstn_ids = 0;
86+
}
87+
88+
/*
89+
* Public SPPP client API
90+
*/
91+
void sppp_client_status_listen(struct sppp_client *client)
92+
{
93+
if (sppp_client_is_registered(client))
94+
sppp_client_mark_lstn(client);
95+
else
96+
printk(KERN_ERR "Unrecognized / invalid client!");
97+
}
6198

6299
/* Registers an SPPP client with the driver */
63100
void sppp_client_register(struct sppp_client *client)
64101
{
65-
if (client->id <= MAX_CLIENTS)
102+
if (client->id < MAX_CLIENTS)
66103
array_of_clients[client->id] = client;
67104
else
68105
printk(KERN_ERR "Wrong client id\n");
@@ -72,13 +109,28 @@ EXPORT_SYMBOL(sppp_client_register);
72109
/* Removes an SPPP client from the driver */
73110
void sppp_client_remove(struct sppp_client *client)
74111
{
75-
if (client->id <= MAX_CLIENTS)
112+
if (sppp_client_is_registered(client))
76113
array_of_clients[client->id] = NULL;
77114
else
78115
printk(KERN_ERR "Wrong client id\n");
79116
}
80117
EXPORT_SYMBOL(sppp_client_remove);
81118

119+
static void send_status(void)
120+
{
121+
int i;
122+
struct sppp_client *client;
123+
124+
for (i = 0; i < MAX_CLIENTS; ++i) {
125+
client = array_of_clients[i];
126+
if (sppp_client_is_registered(client) &&
127+
sppp_client_is_lstn(client))
128+
client->decode(&sppp_rx_g);
129+
}
130+
131+
sppp_clr_lstn();
132+
}
133+
82134
/* Process, identify and decode packet after full encapulated packet received */
83135
static int decode(void)
84136
{
@@ -135,6 +187,16 @@ static int decode(void)
135187
if (array_of_clients[KEYBOARD] != NULL)
136188
array_of_clients[KEYBOARD]->decode(&sppp_rx_g);
137189
break;
190+
case SPPP_VBAT_ID:
191+
if (array_of_clients[POWER] != NULL)
192+
array_of_clients[POWER]->decode(&sppp_rx_g);
193+
break;
194+
case SPPP_STATUS_ID:
195+
if (sppp_status_lstn_ids != 0) {
196+
send_status();
197+
} else
198+
printk(KERN_ERR "STM status received, but no listeners!");
199+
break;
138200

139201
/* case SPPP_RTC_ID:
140202
if (array_of_clients[RTC] != NULL)
@@ -352,6 +414,26 @@ void _sppp_write(sppp_tx_t *sppp_tx, uint8_t data)
352414
serial_putc(data);
353415
}
354416

417+
void sppp_client_send_start(struct sppp_client *client,
418+
sppp_tx_t *sppp_tx, uint8_t pkg_id)
419+
{
420+
/* TOOD implement */
421+
return;
422+
}
423+
424+
void sppp_client_send_data(struct sppp_client *client,
425+
sppp_tx_t *sppp_tx, uint8_t data)
426+
{
427+
/* TOOD implement */
428+
return;
429+
}
430+
void sppp_client_send_stop(struct sppp_client *client,
431+
sppp_tx_t *sppp_tx)
432+
{
433+
/* TOOD implement */
434+
return;
435+
}
436+
355437
/* Send Start */
356438
void sppp_start(sppp_tx_t *sppp_tx, uint8_t pkg_id)
357439
{

drivers/input/keyboard/sppp_keyboard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void kbd_add_col(int col, int key)
333333
* full scan of the key matix. The keyboard ONLY reports the key deltas
334334
* between two consecutive scans.
335335
*/
336-
static void kbd_decode(sppp_rx_t *packet)
336+
static void kbd_decode(const sppp_rx_t *packet)
337337
{
338338
unsigned char *keys = packet->input;
339339
int keyc = packet->pos;
@@ -416,4 +416,4 @@ module_exit(sppp_kbd_exit);
416416

417417
MODULE_LICENSE("GPL");
418418
MODULE_DESCRIPTION("SPPP keyboard client");
419-
MODULE_AUTHOR("Johan Dams <jdmm@genesi-usa.com>");
419+
MODULE_AUTHOR("Johan Dams <jdmm@genesi-usa.com>");

drivers/input/mouse/sppp_trackpad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static struct sppp_client sppp_trackpad_client;
3737
* have the same sequence number. We use this to correctly identify the message
3838
* start and ending of a multibyte message (streaming data from pointing device)
3939
*/
40-
static void trackpad_decode(sppp_rx_t *packet)
40+
static void trackpad_decode(const sppp_rx_t *packet)
4141
{
4242
static uint8_t ps2_byte[3];
4343
static uint8_t ps2_seq;

drivers/power/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,10 @@ config BATTERY_DA9052
212212
Say Y here to enable support for batteries charger integrated into
213213
DA9052 PMIC.
214214

215+
config BATTERY_SPPP
216+
tristate "Efika MX53 SB Battery"
217+
depends on MACH_MX53_EFIKASB
218+
help
219+
Say Y here to enable support for the Efika MX53 SPPP battery
220+
215221
endif # POWER_SUPPLY

drivers/power/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ obj-$(CONFIG_CHARGER_ISP1704) += isp1704_charger.o
3535
obj-$(CONFIG_CHARGER_TWL4030) += twl4030_charger.o
3636
obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
3737
obj-$(CONFIG_BATTERY_DA9052) += da9052-battery.o
38+
obj-$(CONFIG_BATTERY_SPPP) += sppp_power.o

0 commit comments

Comments
 (0)